Esempio n. 1
0
 def test__newobj__(self):
     
     #the second argument is omitted
     result = None
     result = copyreg.__newobj__(object)
     self.assertTrue(result != None,
         "The method __newobj__ did not return an object")
                     
     #the second argument is an int object
     result = None
     a = 1
     result = copyreg.__newobj__(int,a)
     self.assertTrue(result != None,
         "The method __newobj__ did not return an object")
         
     #the method accept multiple arguments
     reseult = None
     class customtype(object):
         def __new__(cls,b,c,d):
             return object.__new__(cls)
         def __init__(self):
             pass
     c = True
     d = "argu"
     e = 3
     result = copyreg.__newobj__(customtype,c,d,e)
     self.assertTrue(result != None,
         "The method __newobj__ did not return an object")
Esempio n. 2
0
    def get_non_persistent_object(self, state, obj):
        if '_py_constant' in state:
            return self.simple_resolve(state['_py_constant'])

        # this method must NOT change the passed in state dict
        state = dict(state)
        if '_py_type' in state:
            # Handle the simplified case.
            klass = self.simple_resolve(state.pop('_py_type'))
            sub_obj = copyreg._reconstructor(klass, object, None)
            self._set_object_state(state, sub_obj, obj)
        elif interfaces.PY_TYPE_ATTR_NAME in state:
            # Another simple case for persistent objects that do not want
            # their own document.
            klass = self.simple_resolve(state.pop(
                interfaces.PY_TYPE_ATTR_NAME))
            sub_obj = copyreg.__newobj__(klass)
            self._set_object_state(state, sub_obj, obj)
        else:
            factory = self.simple_resolve(state.pop('_py_factory'))
            factory_args = self.get_object(state.pop('_py_factory_args'), obj)
            sub_obj = factory(*factory_args)
            # if there is anything left over in `state`, set it below
            # otherwise setting a {} state seems to clean out the object
            # but this is such an edge case of an edge case....
            if state:
                self._set_object_state(state, sub_obj, obj)

        if getattr(sub_obj, interfaces.SUB_OBJECT_ATTR_NAME, False):
            setattr(sub_obj, interfaces.DOC_OBJECT_ATTR_NAME, obj)
            sub_obj._p_jar = self._jar
        return sub_obj
Esempio n. 3
0
 def update_event(self, inp=-1):
     self.set_output_val(0, copyreg.__newobj__(self.input(0)))