nodes: 0, module; 1, function_definition; 2, function_name:get_sh_identity; 3, parameters; 4, block; 5, identifier:self; 6, identifier:item; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, comment:# by default a specific user dict is used; 14, if_statement; 15, expression_statement; 16, return_statement; 17, identifier:identity_field; 18, None; 19, comment:""" Return a Sorting Hat identity using bugzilla user data """; 20, function_name:fill_list_identity; 21, parameters; 22, block; 23, assignment; 24, identifier:field; 25, list; 26, comment:# Basic fields in Sorting Hat; 27, block; 28, assignment; 29, boolean_operator; 30, block; 31, assignment; 32, identifier:identity; 33, identifier:identity; 34, identifier:user_list_data; 35, expression_statement; 36, expression_statement; 37, if_statement; 38, if_statement; 39, return_statement; 40, identifier:identity; 41, dictionary; 42, string; 43, string; 44, string; 45, expression_statement; 46, identifier:user; 47, identifier:item; 48, comparison_operator:'data' in item; 49, comparison_operator:type(item) == dict; 50, expression_statement; 51, identifier:identity; 52, call; 53, comment:""" Fill identity with user data in first item in list """; 54, assignment; 55, comparison_operator:'@' in identity['username']; 56, block; 57, comparison_operator:'name' in user_list_data[0]; 58, block; 59, identifier:identity; 60, string_content:name; 61, string_content:email; 62, string_content:username; 63, assignment; 64, string; 65, identifier:item; 66, call; 67, identifier:dict; 68, assignment; 69, identifier:fill_list_identity; 70, argument_list; 71, subscript; 72, subscript; 73, string; 74, subscript; 75, expression_statement; 76, string; 77, subscript; 78, expression_statement; 79, subscript; 80, None; 81, string_content:data; 82, identifier:type; 83, argument_list; 84, identifier:user; 85, subscript; 86, identifier:identity; 87, identifier:user; 88, identifier:identity; 89, string; 90, subscript; 91, string; 92, string_content:@; 93, identifier:identity; 94, string; 95, assignment; 96, string_content:name; 97, identifier:user_list_data; 98, integer:0; 99, assignment; 100, identifier:identity; 101, identifier:field; 102, identifier:item; 103, subscript; 104, identifier:identity_field; 105, string_content:username; 106, identifier:user_list_data; 107, integer:0; 108, string_content:__text__; 109, string_content:username; 110, subscript; 111, subscript; 112, subscript; 113, subscript; 114, identifier:item; 115, string; 116, identifier:identity; 117, string; 118, identifier:identity; 119, string; 120, identifier:identity; 121, string; 122, subscript; 123, string; 124, string_content:data; 125, string_content:email; 126, string_content:username; 127, string_content:name; 128, identifier:user_list_data; 129, integer:0; 130, string_content:name
code: def get_sh_identity(self, item, identity_field=None):
          """ Return a Sorting Hat identity using bugzilla user data """
  
          def fill_list_identity(identity, user_list_data):
              """ Fill identity with user data in first item in list """
              identity['username'] = user_list_data[0]['__text__']
              if '@' in identity['username']:
                  identity['email'] = identity['username']
              if 'name' in user_list_data[0]:
                  identity['name'] = user_list_data[0]['name']
              return identity
  
          identity = {}
          for field in ['name', 'email', 'username']:
              # Basic fields in Sorting Hat
              identity[field] = None
  
          user = item  # by default a specific user dict is used
          if 'data' in item and type(item) == dict:
              user = item['data'][identity_field]
  
          identity = fill_list_identity(identity, user)
  
          return identity