nodes: 0, module; 1, function_definition; 2, function_name:export; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:source; 15, None; 16, comment:"""Export a set of unique identities.
  
          Method to export unique identities from the registry. Identities schema
          will follow Sorting Hat JSON format.
  
          When source parameter is given, only those unique identities which have
          one or more identities from the given source will be exported.
  
          :param source: source of the identities to export
  
          :returns: a JSON formatted str
          """; 17, assignment; 18, assignment; 19, identifier:uid; 20, identifier:uids; 21, block; 22, assignment; 23, assignment; 24, call; 25, identifier:uidentities; 26, dictionary; 27, identifier:uids; 28, call; 29, expression_statement; 30, expression_statement; 31, expression_statement; 32, expression_statement; 33, expression_statement; 34, identifier:blacklist; 35, list_comprehension; 36, identifier:obj; 37, dictionary; 38, attribute; 39, argument_list; 40, attribute; 41, argument_list; 42, assignment; 43, assignment; 44, call; 45, assignment; 46, assignment; 47, attribute; 48, for_in_clause; 49, pair; 50, pair; 51, pair; 52, pair; 53, pair; 54, identifier:json; 55, identifier:dumps; 56, identifier:obj; 57, keyword_argument; 58, keyword_argument; 59, keyword_argument; 60, keyword_argument; 61, identifier:api; 62, identifier:unique_identities; 63, attribute; 64, keyword_argument; 65, identifier:enrollments; 66, list_comprehension; 67, identifier:u; 68, call; 69, attribute; 70, argument_list; 71, subscript; 72, identifier:u; 73, subscript; 74, identifier:enrollments; 75, identifier:mb; 76, identifier:excluded; 77, identifier:mb; 78, call; 79, string; 80, call; 81, string; 82, identifier:source; 83, string; 84, identifier:blacklist; 85, string; 86, dictionary; 87, string; 88, identifier:uidentities; 89, identifier:default; 90, attribute; 91, identifier:indent; 92, integer:4; 93, identifier:separators; 94, tuple; 95, identifier:sort_keys; 96, True; 97, identifier:self; 98, identifier:db; 99, identifier:source; 100, identifier:source; 101, call; 102, for_in_clause; 103, attribute; 104, argument_list; 105, subscript; 106, identifier:sort; 107, keyword_argument; 108, identifier:uidentities; 109, attribute; 110, subscript; 111, string; 112, attribute; 113, argument_list; 114, string_content:time; 115, identifier:str; 116, argument_list; 117, string_content:source; 118, string_content:blacklist; 119, string_content:organizations; 120, string_content:uidentities; 121, identifier:self; 122, identifier:_json_encoder; 123, string; 124, string; 125, attribute; 126, argument_list; 127, identifier:rol; 128, call; 129, identifier:uid; 130, identifier:to_dict; 131, identifier:u; 132, string; 133, identifier:key; 134, lambda; 135, identifier:uid; 136, identifier:uuid; 137, identifier:uidentities; 138, attribute; 139, string_content:enrollments; 140, identifier:api; 141, identifier:blacklist; 142, attribute; 143, call; 144, string_content:,; 145, string_content::; 146, identifier:rol; 147, identifier:to_dict; 148, attribute; 149, argument_list; 150, string_content:identities; 151, lambda_parameters; 152, subscript; 153, identifier:uid; 154, identifier:uuid; 155, identifier:self; 156, identifier:db; 157, attribute; 158, argument_list; 159, identifier:api; 160, identifier:enrollments; 161, attribute; 162, keyword_argument; 163, identifier:x; 164, identifier:x; 165, string; 166, attribute; 167, identifier:now; 168, identifier:self; 169, identifier:db; 170, identifier:uuid; 171, attribute; 172, string_content:id; 173, identifier:datetime; 174, identifier:datetime; 175, identifier:uid; 176, identifier:uuid
code: def export(self, source=None):
          """Export a set of unique identities.
  
          Method to export unique identities from the registry. Identities schema
          will follow Sorting Hat JSON format.
  
          When source parameter is given, only those unique identities which have
          one or more identities from the given source will be exported.
  
          :param source: source of the identities to export
  
          :returns: a JSON formatted str
          """
          uidentities = {}
  
          uids = api.unique_identities(self.db, source=source)
  
          for uid in uids:
              enrollments = [rol.to_dict()
                             for rol in api.enrollments(self.db, uuid=uid.uuid)]
  
              u = uid.to_dict()
              u['identities'].sort(key=lambda x: x['id'])
  
              uidentities[uid.uuid] = u
              uidentities[uid.uuid]['enrollments'] = enrollments
  
          blacklist = [mb.excluded for mb in api.blacklist(self.db)]
  
          obj = {'time': str(datetime.datetime.now()),
                 'source': source,
                 'blacklist': blacklist,
                 'organizations': {},
                 'uidentities': uidentities}
  
          return json.dumps(obj, default=self._json_encoder,
                            indent=4, separators=(',', ': '),
                            sort_keys=True)