nodes: 0, module; 1, function_definition; 2, function_name:clean_field_dict; 3, parameters; 4, block; 5, identifier:field_dict; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, for_statement; 12, return_statement; 13, identifier:cleaner; 14, attribute; 15, identifier:time_zone; 16, None; 17, comment:r"""Normalize field values by stripping whitespace from strings, localizing datetimes to a timezone, etc
  
      >>> (sorted(clean_field_dict({'_state': object(), 'x': 1, 'y': "\t  Wash Me! \n" }).items()) ==
      ... [('x', 1), ('y', 'Wash Me!')])
      True
      """; 18, assignment; 19, comparison_operator:time_zone is None; 20, block; 21, pattern_list; 22, call; 23, block; 24, identifier:d; 25, identifier:str; 26, identifier:strip; 27, identifier:d; 28, dictionary; 29, identifier:time_zone; 30, None; 31, expression_statement; 32, identifier:k; 33, identifier:v; 34, identifier:viewitems; 35, argument_list; 36, if_statement; 37, if_statement; 38, assignment; 39, identifier:field_dict; 40, comparison_operator:k == '_state'; 41, block; 42, call; 43, block; 44, elif_clause; 45, else_clause; 46, identifier:tz; 47, identifier:DEFAULT_TZ; 48, identifier:k; 49, string; 50, continue_statement; 51, identifier:isinstance; 52, argument_list; 53, expression_statement; 54, call; 55, block; 56, block; 57, string_content:_state; 58, identifier:v; 59, identifier:basestring; 60, assignment; 61, identifier:isinstance; 62, argument_list; 63, expression_statement; 64, expression_statement; 65, subscript; 66, call; 67, identifier:v; 68, tuple; 69, assignment; 70, assignment; 71, identifier:d; 72, identifier:k; 73, identifier:cleaner; 74, argument_list; 75, attribute; 76, attribute; 77, subscript; 78, call; 79, subscript; 80, identifier:v; 81, call; 82, identifier:datetime; 83, identifier:datetime; 84, identifier:datetime; 85, identifier:date; 86, identifier:d; 87, identifier:k; 88, attribute; 89, argument_list; 90, identifier:d; 91, identifier:k; 92, identifier:str; 93, argument_list; 94, identifier:tz; 95, identifier:localize; 96, identifier:v; 97, identifier:v
code: def clean_field_dict(field_dict, cleaner=str.strip, time_zone=None):
      r"""Normalize field values by stripping whitespace from strings, localizing datetimes to a timezone, etc
  
      >>> (sorted(clean_field_dict({'_state': object(), 'x': 1, 'y': "\t  Wash Me! \n" }).items()) ==
      ... [('x', 1), ('y', 'Wash Me!')])
      True
      """
      d = {}
      if time_zone is None:
          tz = DEFAULT_TZ
      for k, v in viewitems(field_dict):
          if k == '_state':
              continue
          if isinstance(v, basestring):
              d[k] = cleaner(str(v))
          elif isinstance(v, (datetime.datetime, datetime.date)):
              d[k] = tz.localize(v)
          else:
              d[k] = v
      return d