nodes: 0, module; 1, function_definition; 2, function_name:recursive_sort; 3, parameters; 4, block; 5, identifier:data_structure; 6, expression_statement; 7, comment:# We don't sory primitve types; 8, if_statement; 9, return_statement; 10, comment:"""Sort a recursive data_structure.
  
      :param   data_structure: The structure to convert.
  
      data_structure must be already sortable or you must use freeze() or dump().
      The function will work with many kinds of input. Dictionaries will be
      converted to lists of tuples.
  
      >>> _py2_to_py3(vformat(recursive_sort(dump(
      ...     [3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}]
      ... ))))
      (["<class 'dict'>",
        (('a',
          'b'),
         ('b',
          'a'),
         ('c',
          'c'))],
       1,
       3)
      >>> recursive_sort([3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}])
      ((('a', 'b'), ('b', 'a'), ('c', 'c')), 1, 3)
      >>> recursive_sort(_TestClass())
      (('a', 'huhu'),)
      """; 11, not_operator; 12, block; 13, identifier:data_structure; 14, call; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, expression_statement; 19, comment:# If item has a length we sort it; 20, try_statement; 21, if_statement; 22, identifier:isinstance; 23, argument_list; 24, assignment; 25, assignment; 26, not_operator; 27, block; 28, assignment; 29, block; 30, except_clause; 31, comparison_operator:tlen != -1; 32, comment:# Well there are classes out in the wild that answer to len; 33, comment:# but have no indexer.; 34, block; 35, identifier:data_structure; 36, identifier:_primitive_types; 37, identifier:is_meta; 38, call; 39, identifier:was_dict; 40, call; 41, parenthesized_expression; 42, expression_statement; 43, if_statement; 44, comment:# Itemize if possible; 45, try_statement; 46, identifier:tlen; 47, unary_operator; 48, expression_statement; 49, comment:# pragma: no cover; 50, block; 51, identifier:tlen; 52, unary_operator; 53, try_statement; 54, identifier:isinstance; 55, argument_list; 56, identifier:isinstance; 57, argument_list; 58, boolean_operator; 59, assignment; 60, not_operator; 61, comment:# Dictize if possible (support objects); 62, block; 63, block; 64, except_clause; 65, integer:1; 66, assignment; 67, pass_statement; 68, integer:1; 69, block; 70, except_clause; 71, identifier:data_structure; 72, identifier:Meta; 73, identifier:data_structure; 74, identifier:WasDict; 75, identifier:is_meta; 76, identifier:was_dict; 77, identifier:was_dict; 78, call; 79, identifier:was_dict; 80, try_statement; 81, expression_statement; 82, block; 83, identifier:tlen; 84, call; 85, if_statement; 86, comment:# pragma: no cover; 87, block; 88, identifier:isinstance; 89, argument_list; 90, block; 91, except_clause; 92, assignment; 93, pass_statement; 94, identifier:len; 95, argument_list; 96, identifier:was_dict; 97, block; 98, elif_clause; 99, else_clause; 100, pass_statement; 101, identifier:data_structure; 102, identifier:dict; 103, expression_statement; 104, expression_statement; 105, block; 106, identifier:data_structure; 107, call; 108, identifier:data_structure; 109, return_statement; 110, identifier:is_meta; 111, block; 112, block; 113, assignment; 114, assignment; 115, pass_statement; 116, attribute; 117, argument_list; 118, call; 119, return_statement; 120, return_statement; 121, identifier:data_structure; 122, attribute; 123, identifier:was_dict; 124, True; 125, identifier:data_structure; 126, identifier:items; 127, identifier:tuple; 128, argument_list; 129, binary_operator:data_structure[0:-1] + [
                          recursive_sort(
                              data_structure[-1]
                          )
                      ]; 130, call; 131, identifier:data_structure; 132, identifier:__dict__; 133, call; 134, subscript; 135, list; 136, identifier:tuple; 137, argument_list; 138, identifier:sorted; 139, argument_list; 140, identifier:data_structure; 141, slice; 142, call; 143, call; 144, list_comprehension; 145, keyword_argument; 146, integer:0; 147, unary_operator; 148, identifier:recursive_sort; 149, argument_list; 150, identifier:sorted; 151, argument_list; 152, tuple; 153, for_in_clause; 154, identifier:key; 155, identifier:TraversalBasedReprCompare; 156, integer:1; 157, subscript; 158, list_comprehension; 159, keyword_argument; 160, call; 161, call; 162, identifier:x; 163, identifier:data_structure; 164, identifier:data_structure; 165, unary_operator; 166, call; 167, for_in_clause; 168, identifier:key; 169, identifier:TraversalBasedReprCompare; 170, identifier:recursive_sort; 171, argument_list; 172, identifier:recursive_sort; 173, argument_list; 174, integer:1; 175, identifier:recursive_sort; 176, argument_list; 177, identifier:x; 178, identifier:data_structure; 179, subscript; 180, subscript; 181, identifier:x; 182, identifier:x; 183, integer:0; 184, identifier:x; 185, integer:1
code: def recursive_sort(data_structure):
      """Sort a recursive data_structure.
  
      :param   data_structure: The structure to convert.
  
      data_structure must be already sortable or you must use freeze() or dump().
      The function will work with many kinds of input. Dictionaries will be
      converted to lists of tuples.
  
      >>> _py2_to_py3(vformat(recursive_sort(dump(
      ...     [3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}]
      ... ))))
      (["<class 'dict'>",
        (('a',
          'b'),
         ('b',
          'a'),
         ('c',
          'c'))],
       1,
       3)
      >>> recursive_sort([3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}])
      ((('a', 'b'), ('b', 'a'), ('c', 'c')), 1, 3)
      >>> recursive_sort(_TestClass())
      (('a', 'huhu'),)
      """
      # We don't sory primitve types
      if not isinstance(data_structure, _primitive_types):
          is_meta = isinstance(data_structure, Meta)
          was_dict = isinstance(data_structure, WasDict)
          if not (is_meta or was_dict):
              was_dict = isinstance(data_structure, dict)
              if not was_dict:
                  # Dictize if possible (support objects)
                  try:
                      data_structure = data_structure.__dict__
                      was_dict = True
                  except:
                      pass
              # Itemize if possible
              try:
                  data_structure = data_structure.items()
              except:
                  pass
          tlen = -1
          # If item has a length we sort it
          try:
              tlen = len(data_structure)
          except:  # pragma: no cover
              pass
          if tlen != -1:
              # Well there are classes out in the wild that answer to len
              # but have no indexer.
              try:
                  if was_dict:
                      return tuple(sorted(
                          [
                              (
                                  recursive_sort(x[0]),
                                  recursive_sort(x[1]),
                              )
                              for x in data_structure
                          ],
                          key=TraversalBasedReprCompare
                      ))
                  elif is_meta:
                      return data_structure[0:-1] + [
                          recursive_sort(
                              data_structure[-1]
                          )
                      ]
                  else:
                      return tuple(sorted(
                          [recursive_sort(
                              x,
                          ) for x in data_structure],
                          key=TraversalBasedReprCompare,
                      ))
              except:  # pragma: no cover
                  pass
      return data_structure