Index: jelly.py =================================================================== --- jelly.py (.../tags/release-2.0.0/twisted/spread/jelly.py) (revision 14239) +++ jelly.py (.../trunk/twisted/spread/jelly.py) (revision 14239) @@ -140,6 +140,20 @@ unjellyableRegistry = {} unjellyableFactoryRegistry = {} +def _newInstance(cls, state): + """Make a new instance of a class without calling its __init__ method. + 'state' will be used to update inst.__dict__ . Supports both new- and + old-style classes. + """ + if not isinstance(cls, types.ClassType): + # new-style + inst = cls.__new__(cls) + inst.__dict__.update(state) # Copy 'instance' behaviour + else: + inst = instance(cls, state) + return inst + + def _maybeClass(classnamep): try: object @@ -535,6 +549,10 @@ inst = _Dummy() # XXX chomp, chomp inst.__class__ = regClass method = inst.unjellyFor + elif isinstance(regClass, type): + # regClass.__new__ does not call regClass.__init__ + inst = regClass.__new__(regClass) + method = inst.unjellyFor else: method = regClass # this is how it ought to be done val = method(self, obj) @@ -560,12 +578,12 @@ if not self.taster.isClassAllowed(clz): raise InsecureJelly("Class %s not allowed." % jelType) if hasattr(clz, "__setstate__"): - ret = instance(clz, {}) + ret = _newInstance(clz, {}) state = self.unjelly(obj[1]) ret.__setstate__(state) else: state = self.unjelly(obj[1]) - ret = instance(clz, state) + ret = _newInstance(clz, state) if hasattr(clz, 'postUnjelly'): self.postCallbacks.append(ret.postUnjelly) return ret @@ -697,12 +715,12 @@ if type(clz) is not types.ClassType: raise InsecureJelly("Instance found with non-class class.") if hasattr(clz, "__setstate__"): - inst = instance(clz, {}) + inst = _newInstance(clz, {}) state = self.unjelly(rest[1]) inst.__setstate__(state) else: state = self.unjelly(rest[1]) - inst = instance(clz, state) + inst = _newInstance(clz, state) if hasattr(clz, 'postUnjelly'): self.postCallbacks.append(inst.postUnjelly) return inst