def test__newobj__(): #the second argument is omitted result = None result = copy_reg.__newobj__(object) Assert(result != None, "The method __newobj__ did not return an object") #the second argument is an int object result = None a = 1 result = copy_reg.__newobj__(int, a) Assert(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 = copy_reg.__newobj__(customtype, c, d, e) Assert(result != None, "The method __newobj__ did not return an object")
def test__newobj__(self): #the second argument is omitted result = None result = copy_reg.__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 = copy_reg.__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 = copy_reg.__newobj__(customtype,c,d,e) self.assertTrue(result != None, "The method __newobj__ did not return an object")
def get_non_persistent_object(self, state, obj): if '_py_constant' in state: return self.simple_resolve(state.pop('_py_constant')) if '_py_type' in state: # Handle the simplified case. klass = self.simple_resolve(state.pop('_py_type')) sub_obj = copy_reg._reconstructor(klass, object, None) elif '_py_persistent_type' in state: # Another simple case for persistent objects that do not want # their own document. klass = self.simple_resolve(state.pop('_py_persistent_type')) sub_obj = copy_reg.__newobj__(klass) 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 len(state): sub_obj_state = self.get_object(state, obj) if isinstance(sub_obj, persistent.Persistent): sub_obj.__setstate__(sub_obj_state) # This is a persistent sub-object -- mark it as such. Otherwise # we risk to store this object in its own collection next time. sub_obj._p_mongo_sub_object = True else: sub_obj.__dict__.update(sub_obj_state) if getattr(sub_obj, '_p_mongo_sub_object', False): sub_obj._p_mongo_doc_object = obj sub_obj._p_jar = self._jar return sub_obj
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 = copy_reg._reconstructor(klass, object, None) 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 = copy_reg.__newobj__(klass) 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 len(state): sub_obj_state = self.get_object(state, obj) if hasattr(sub_obj, '__setstate__'): sub_obj.__setstate__(sub_obj_state) else: sub_obj.__dict__.update(sub_obj_state) if isinstance(sub_obj, persistent.Persistent): # This is a persistent sub-object -- mark it as such. Otherwise # we risk to store this object in its own table next time. setattr(sub_obj, interfaces.SUB_OBJECT_ATTR_NAME, True) 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 get_non_persistent_object(self, state, obj): if '_py_type' in state: # Handle the simplified case. klass = self.simple_resolve(state.pop('_py_type')) sub_obj = copy_reg._reconstructor(klass, object, None) elif '_py_persistent_type' in state: # Another simple case for persistent objects that do not want # their own document. klass = self.simple_resolve(state.pop('_py_persistent_type')) sub_obj = copy_reg.__newobj__(klass) 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 len(state): sub_obj_state = self.get_object(state, obj) if isinstance(sub_obj, persistent.Persistent): sub_obj.__setstate__(sub_obj_state) else: sub_obj.__dict__.update(sub_obj_state) if getattr(sub_obj, '_p_mongo_sub_object', False): sub_obj._p_mongo_doc_object = obj sub_obj._p_jar = self._jar return sub_obj