#NEWLINE# def dto_generator( instance , exceptions = None ) : #NEWLINE# #INDENT# if ( exceptions == None ) : #NEWLINE# #INDENT# exceptions = _default_exceptions #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tmp_exceptions = ( ) #NEWLINE# for i in exceptions : #NEWLINE# #INDENT# tmp_exceptions = ( instance + ( i , ) ) #NEWLINE# #UNINDENT# exceptions = tmp_exceptions #NEWLINE# #UNINDENT# parsed_instances = _InstanceDictionary ( ) #NEWLINE# def fill_tree( current_node , name , current_instance ) : #NEWLINE# #INDENT# ' fill_tree(current_node, name, current_instance)\n\n        current_node     -> The current _Node.\n        name             -> The name of current_instance\n        current_instance -> The instance itself\n\n        fill_tree will check if current_instance is not an exception\n        and if it\'s not, it will add current_instance into current_node\n        with name "name". After this, it will go through all information\n        inside current_instance, and calling fill_tree with them.\n        ' #NEWLINE# for exce in exceptions : #NEWLINE# #INDENT# if issubclass ( type ( current_instance ) , exce ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# if ( type ( current_instance ) in _recoverable_exceptions ) : #NEWLINE# #INDENT# current_instance = _DtoMissing ( name , current_instance ) #NEWLINE# #UNINDENT# new_node = current_node . append_child ( name , current_instance ) #NEWLINE# if ( new_node . data_type in ( _Node . BASIC , _Node . IGNORABLE ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if parsed_instances . has_key ( current_instance ) : #NEWLINE# #INDENT# parsed_instances [ current_instance ] . append ( new_node ) #NEWLINE# for parsed_instance in parsed_instances [ current_instance ] : #NEWLINE# #INDENT# parsed_instance . repeated = True #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parsed_instances [ current_instance ] = [ new_node ] #NEWLINE# #UNINDENT# if ( new_node . data_type in ( _Node . TUPLE , _Node . LIST ) ) : #NEWLINE# #INDENT# for ( number , value ) in enumerate ( current_instance ) : #NEWLINE# #INDENT# fill_tree ( new_node , number , value ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( new_node . data_type == _Node . DICT ) : #NEWLINE# #INDENT# for i in current_instance : #NEWLINE# #INDENT# fill_tree ( new_node , i , ( i , current_instance [ i ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( new_node . data_type in ( _Node . INSTANCE , _Node . OBJECT , _Node . EXCEPTION , _Node . BUILTIN_E ) ) : #NEWLINE# #INDENT# elements = [ i for i in dir ( current_instance ) if ( ( not i . startswith ( '__' ) ) or ( not i . endswith ( '__' ) ) ) ] #NEWLINE# for i in elements : #NEWLINE# #INDENT# if hasattr ( current_instance . __class__ , i ) : #NEWLINE# #INDENT# data_type = getattr ( current_instance . __class__ , i ) #NEWLINE# if ( type ( data_type ) == property ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# if ( isinstance ( current_instance , Exception ) and ( i == 'message' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# element = getattr ( current_instance , i ) #NEWLINE# fill_tree ( new_node , i , element ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( ( 'Unrecognized type: %s. Configure it at voodoo.mapper.py' % new_node . data_type ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# first_node = _Node ( None , None , None , ( ) ) #NEWLINE# fill_tree ( first_node , None , instance ) #NEWLINE# dto_parsed_instances = _InstanceDictionary ( ) #NEWLINE# def get_dto_value( current_node ) : #NEWLINE# #INDENT# if ( current_node . data_type == _Node . IGNORABLE ) : #NEWLINE# #INDENT# return ( 'Unable to serialize this data type <%s>, so it was replaced by this str' % type ( current_node ) ) #NEWLINE# #UNINDENT# if ( current_node . data_type == _Node . BASIC ) : #NEWLINE# #INDENT# return current_node . element #NEWLINE# #UNINDENT# if dto_parsed_instances . has_key ( current_node . element ) : #NEWLINE# #INDENT# return dto_parsed_instances [ current_node . element ] #NEWLINE# #UNINDENT# if ( current_node . data_type == _Node . TUPLE ) : #NEWLINE# #INDENT# new_tuple = ( ) #NEWLINE# for ( i , element ) in current_node . children : #NEWLINE# #INDENT# new_tuple = ( new_tuple + ( get_dto_value ( element ) , ) ) #NEWLINE# #UNINDENT# dto_parsed_instances [ current_node . element ] = new_tuple #NEWLINE# return new_tuple #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( current_node . data_type == _Node . LIST ) : #NEWLINE# #INDENT# new_list = [ ] #NEWLINE# dto_parsed_instances [ current_node . element ] = new_list #NEWLINE# for ( i , element ) in current_node . children : #NEWLINE# #INDENT# new_list . append ( get_dto_value ( element ) ) #NEWLINE# #UNINDENT# return new_list #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( current_node . data_type == _Node . DICT ) : #NEWLINE# #INDENT# new_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# dto_parsed_instances [ current_node . element ] = new_dict #NEWLINE# for ( i , element ) in current_node . children : #NEWLINE# #INDENT# this_tuple = get_dto_value ( element ) #NEWLINE# key = this_tuple [ 0 ] #NEWLINE# value = this_tuple [ 1 ] #NEWLINE# new_dict [ key ] = value #NEWLINE# #UNINDENT# return new_dict #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( current_node . data_type in ( _Node . INSTANCE , _Node . OBJECT , _Node . EXCEPTION , _Node . BUILTIN_E ) ) : #NEWLINE# #INDENT# if ( current_node . data_type == _Node . EXCEPTION ) : #NEWLINE# #INDENT# new_instance = _DtoError ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( current_node . data_type == _Node . INSTANCE ) : #NEWLINE# #INDENT# new_instance = _DtoClass ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( current_node . data_type == _Node . BUILTIN_E ) : #NEWLINE# #INDENT# new_instance = _DtoBuiltin ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# new_instance = _DtoObject ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# dto_parsed_instances [ current_node . element ] = new_instance #NEWLINE# for ( i , element ) in current_node . children : #NEWLINE# #INDENT# setattr ( new_instance , i , get_dto_value ( element ) ) #NEWLINE# #UNINDENT# new_instance . _old_name = current_node . element . __class__ . __name__ #NEWLINE# new_instance . _old_doc = current_node . element . __class__ . __doc__ #NEWLINE# new_instance . _old_module = current_node . element . __class__ . __module__ #NEWLINE# return new_instance #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( ( 'Unrecognized type: %s. Configure it at voodoo.mapper.py, get_dto_value' % current_node . data_type ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return get_dto_value ( first_node . children [ 0 ] [ 1 ] )