Exemplo n.º 1
0
    def unpickle_instance(self, elem):

        obj = elem[5]

        # call __init__ if initargs exist
        args = self.pop_initargs()
        if hasattr(obj, '__init__') and args is not None:
            apply(obj.__init__, args)

        # get stateinfo if exists
        state = self.pop_stateinfo()

        # set obj attributes
        if state:
            if hasattr(obj, '__setstate__'):
                obj.__setstate__(state)
            else:
                #obj.__dict__.update(state)
                attr_update(obj, state)
        else:
            while self.val_stk[-1][0] != 'STOP':
                e = self.val_stk.pop()
                setattr(obj, e[1], e[2])

        self.val_stk.pop()  # pop STOP

        return obj
Exemplo n.º 2
0
    def unpickle_instance(self,elem):

        obj = elem[5]

        # call __init__ if initargs exist
        args = self.pop_initargs()
        if hasattr(obj,'__init__') and args is not None:
            apply(obj.__init__,args)

        # get stateinfo if exists
        state = self.pop_stateinfo()

        # set obj attributes
        if state:
            if hasattr(obj,'__setstate__'):
                obj.__setstate__(state)
            else:
                #obj.__dict__.update(state)
                attr_update(obj, state)
        else:
            while self.val_stk[-1][0] != 'STOP':
                e = self.val_stk.pop()
                setattr(obj,e[1],e[2])

        self.val_stk.pop() # pop STOP

        return obj
Exemplo n.º 3
0
def unpickle_instance(node, paranoia):
    """Take a <PyObject> or <.. type="PyObject"> DOM node and unpickle the object."""

    # we must first create an empty obj of the correct	type and place
    # it in visited{} (so we can handle self-refs within the object)
    pyobj = obj_from_node(node, paranoia)
    _save_obj_with_id(node, pyobj)

    # slurp raw thing into a an empty object
    raw = _thing_from_dom(node, _EmptyClass(), paranoia)

    # code below has same ordering as pickle.py

    # pass initargs, if defined
    try:
        args = raw.__getinitargs__
        delattr(raw, '__getinitargs__')  # don't want this in pyobj (below)
        apply(pyobj.__init__, args)
    except:
        pass

    # next, decide what "stuff" is supposed to go into pyobj
    if hasattr(raw, '__getstate__'):
        stuff = raw.__getstate__
    else:
        stuff = raw.__dict__

    # finally, decide how to get the stuff into pyobj
    if hasattr(pyobj, '__setstate__'):
        pyobj.__setstate__(stuff)
    else:
        if type(stuff) is DictType:  # must be a Dict if no __setstate__
            # see note in pickle.py/load_build() about restricted
            # execution -- do the same thing here
            #try:
            #	pyobj.__dict__.update(stuff)
            #except RuntimeError:
            #	for k,v in stuff.items():
            #		setattr(pyobj, k, v)
            attr_update(pyobj, stuff)
        else:
            # subtle -- this can happen either because the class really
            # does violate the pickle protocol, or because PARANOIA was
            # set too high, and we couldn't create the real class, so
            # __setstate__ is missing (and __stateinfo__ isn't a dict)
            raise XMLUnpicklingError, \
                  "Non-DictType without setstate violates pickle protocol."+\
                  "(PARANOIA setting may be too high)"

    return pyobj
Exemplo n.º 4
0
def unpickle_instance(node, paranoia):
    """Take a <PyObject> or <.. type="PyObject"> DOM node and unpickle the object."""

    # we must first create an empty obj of the correct	type and place
    # it in visited{} (so we can handle self-refs within the object)
    pyobj = obj_from_node(node, paranoia)
    _save_obj_with_id(node, pyobj)

    # slurp raw thing into a an empty object
    raw = _thing_from_dom(node, _EmptyClass(), paranoia)

    # code below has same ordering as pickle.py

    # pass initargs, if defined
    try:
        args = raw.__getinitargs__
        delattr(raw,'__getinitargs__') # don't want this in pyobj (below)
        apply(pyobj.__init__,args)
    except:
        pass

    # next, decide what "stuff" is supposed to go into pyobj
    if hasattr(raw,'__getstate__'):
        stuff = raw.__getstate__
    else:
        stuff = raw.__dict__

    # finally, decide how to get the stuff into pyobj
    if hasattr(pyobj,'__setstate__'):
        pyobj.__setstate__(stuff)
    else:
        if type(stuff) is DictType:	 # must be a Dict if no __setstate__
            # see note in pickle.py/load_build() about restricted
            # execution -- do the same thing here
            #try:
            #	pyobj.__dict__.update(stuff)
            #except RuntimeError:
            #	for k,v in stuff.items():
            #		setattr(pyobj, k, v)
            attr_update(pyobj, stuff)
        else:
            # subtle -- this can happen either because the class really
            # does violate the pickle protocol, or because PARANOIA was
            # set too high, and we couldn't create the real class, so
            # __setstate__ is missing (and __stateinfo__ isn't a dict)
            raise XMLUnpicklingError, \
                  "Non-DictType without setstate violates pickle protocol."+\
                  "(PARANOIA setting may be too high)"

    return pyobj