def test_reconstructor(self): reconstructor_copy = copyreg._reconstructor try: obj = copyreg._reconstructor(object, object, None) self.assertTrue(type(obj) is object) #set,get, the value is a random int rand = random.Random() value = rand.getrandbits(8) copyreg._reconstructor = value result = copyreg._reconstructor self.assertTrue(result == value, "set or get of the attribute failed!") #the value is a string value2 = "value2" copyreg._reconstructor = value2 result = copyreg._reconstructor self.assertTrue(result == value2, "set or get of the attribute failed!") #the value is a custom type object value3 = testclass() copyreg._reconstructor = value3 result = copyreg._reconstructor self.assertTrue(result == value3, "set or get of the attribute failed!") finally: copyreg._reconstructor = reconstructor_copy
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
def wrapped_delegator_reconstruct(wrapped_cls, wrapped, class_trans, delegation_attr): """""" type_ = delegator_wrap(wrapped_cls, wrapped, class_trans, delegation_attr) # produce an empty object for pickle to pour the # __getstate__ values into, via __setstate__ return copyreg._reconstructor(type_, object, None)
def update_event(self, inp=-1): self.set_output_val(0, copyreg._reconstructor(self.input(0), self.input(1), self.input(2)))