def freeze(data_structure):
def freeze_helper(data_structure):<EOL><INDENT>if isinstance(data_structure, _primitive_types):<EOL><INDENT>return data_structure<EOL><DEDENT>was_dict = False<EOL>if (<EOL>hasattr(data_structure, "<STR_LIT>") and<EOL>not isinstance(data_structure, (Meta, IDD, WasDict))<EOL>):<EOL><INDENT>data_structure = tuple(object_to_items(data_structure))<EOL>was_dict = True<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>data_structure = data_structure.__dict__<EOL>was_dict = True<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>data_structure = data_structure.items()<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>tlen = -<NUM_LIT:1><EOL>try:<EOL><INDENT>tlen = len(data_structure)<EOL><DEDENT>except:  <EOL><INDENT>pass<EOL><DEDENT>if tlen != -<NUM_LIT:1>:<EOL><INDENT>try:<EOL><INDENT>if was_dict:<EOL><INDENT>return WasDict([<EOL>freeze_helper(x) for x in data_structure<EOL>])<EOL><DEDENT>else:<EOL><INDENT>return tuple([<EOL>freeze_helper(x) for x in data_structure<EOL>])<EOL><DEDENT><DEDENT>except:  <EOL><INDENT>pass<EOL><DEDENT><DEDENT>return data_structure  <EOL><DEDENT>return freeze_helper(data_structure)<EOL>
Freeze tries to convert any data-structure in a hierarchy of tuples.
    Tuples are comparable/sortable/hashable, you can use this with
    with recursive_sort(). freeze has no recursion detection.

    :param   data_structure: The structure to convert.

    >>> recursive_sort(freeze(_TestClass(True)))
    (('a', 'huhu'), ('sub', (('a', 'slot'), ('b', (1, (1, 2, 3), 2, 3)))))
    >>> dump((None, (None, None)))
    (None, (None, None))