def load_from_dto(instance,exceptions = None,skip_recoverables=False):
    if exceptions == None:
        exceptions = _default_exceptions
    else:
        tmp_exceptions = ()
        for i in exceptions:
            tmp_exceptions = tmp_exceptions + (i,)
        exceptions = tmp_exceptions

    parsed_instances = _InstanceDictionary()

    def fill_tree(current_node,name,current_instance):
        new_node = current_node.append_child(name,current_instance)

        if   new_node.data_type == _Node.BASIC or new_node.data_type == _Node.IGNORABLE:
            return # No information inside a basic data type

        # Don't repeat twice the same instance
        if parsed_instances.has_key(current_instance):
            parsed_instances[current_instance].append(new_node)
            for parsed_node in parsed_instances[current_instance]:
                parsed_node.repeated = True
            return
        else:
            parsed_instances[current_instance] = [new_node]

        if new_node.data_type in (_Node.TUPLE, _Node.LIST):

            # Tuples and lists have elements inside
            # They name will be their number
            for number,value in enumerate(current_instance):
                fill_tree(new_node,number,value)

        elif new_node.data_type == _Node.DICT:

            # Their name will be their key
            # Very important: in dictionaries, the values will be pairs of (key,value)
            for i in current_instance:
                fill_tree(new_node,i,(i,current_instance[i]))

        elif new_node.data_type in (_Node.INSTANCE, _Node.OBJECT, _Node.EXCEPTION, _Node.BUILTIN_E):

            # Elements are the elements which we will take
            elements = [ i for i in dir(current_instance)
                if not i.startswith('__') or not i.endswith('__')]

            for i in elements:
                if new_node.data_type == _Node.EXCEPTION and i == 'message':
                    continue # Deprecated
                element = getattr(current_instance,i)
                fill_tree(new_node,i,element)

        else:
            raise TypeError(
                'Unrecognized type: %s. Configure it at voodoo.mapper.py'
                % new_node.data_type
            )

    first_node = _Node(None,None,None,())
    fill_tree(first_node,None,instance)
    # At this point, instance_tree has been created

    dto_parsed_instances = _InstanceDictionary()

    # Let's create the dto structure
    def load_dto_value(current_node):
        if current_node.data_type == _Node.BASIC:
            return current_node.element

        # Check parsed_instances
        if dto_parsed_instances.has_key(current_node.element):
            return dto_parsed_instances[current_node.element]

        if   current_node.data_type == _Node.TUPLE:

            new_tuple = ()
            for i,element in current_node.children:
                new_tuple = new_tuple + (load_dto_value(element),)
            dto_parsed_instances[current_node.element] = new_tuple
            return new_tuple

        elif current_node.data_type == _Node.LIST:

            new_list = []
            dto_parsed_instances[current_node.element] = new_list
            for i, element in current_node.children:
                new_list.append(load_dto_value(element))
            return new_list

        elif current_node.data_type == _Node.DICT:

            new_dict = {}
            dto_parsed_instances[current_node.element] = new_dict
            for i, element in current_node.children:
                # A dictionary is a set of tuples, where
                # the first element is the key and the
                # second element is the value
                this_tuple = load_dto_value(element)
                key   = this_tuple[0]
                value = this_tuple[1]
                new_dict[key] = value
            return new_dict

        elif current_node.data_type == _Node.BUILTIN_E:
            dto_object = _DtoBuiltin()

            for i, element in current_node.children:
                setattr(dto_object,i,load_dto_value(element))

            builtin_type = getattr(__builtin__, dto_object._old_name)
            inst = builtin_type()

            for i, element in current_node.children:
                try:
                    setattr(inst,i,load_dto_value(element))
                except __HOLE__:
                    pass

            dto_parsed_instances[current_node.element] = inst
            try:
                del inst._old_module
                del inst._old_name
            except AttributeError:
                pass
            return inst

        elif current_node.data_type in (_Node.INSTANCE, _Node.OBJECT, _Node.EXCEPTION):
            if current_node.data_type == _Node.INSTANCE:
                dto_object = _DtoClass()
            elif current_node.data_type == _Node.OBJECT:
                dto_object = _DtoObject()
            else:
                dto_object = _DtoError()

            dto_parsed_instances[current_node.element] = dto_object

            for i, element in current_node.children:
                setattr(dto_object,i,load_dto_value(element))

            old_module = dto_object._old_module
            old_name = dto_object._old_name
            __import__(old_module,globals(),locals(),[])
            the_class = getattr(_sys.modules[old_module],old_name)
            dto_object.__class__ = the_class

            if hasattr(dto_object,'deserialize'):
                dto_object.deserialize()

            del dto_object._old_module
            del dto_object._old_name

            if isinstance(dto_object,_DtoMissing):
                if skip_recoverables:
                    return None
                # it is a DtoMissing
                if dto_object.data_type == str(_thread.LockType):
                    l = _threading.Lock()
                    dto_parsed_instances[current_node.element] = l
                    return l
                elif dto_object.data_type == str(_threading._Condition):
                    c = _threading.Condition()
                    dto_parsed_instances[current_node.element] = c
                    return c
                else:
                    raise TypeError(
                        """No handler for the missing value %s at %s.
                    Check that you don't have a value in _recoverable_exceptions,
                    and no handler in load_from_dto"""
                            % (i,dto_object)
                        )
            return dto_object
        else:
            raise TypeError(
                'Unrecognized type: %s. Configure it at voodoo.mapper.py, load_dto_value'
                % current_node.data_type
            )

    return load_dto_value(first_node.children[0][1])
dataset/ETHPy150Open weblabdeusto/weblabdeusto/server/src/voodoo/mapper.py/load_from_dto