Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 65571 Details for
Bug 99300
Twisted 2.0.1 NOW released (2005-05-25)
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
This patch enables jellying of new style classes in python
jelly.patch (text/plain), 2.50 KB, created by
Matthew Sherborne
on 2005-08-09 20:10:52 UTC
(
hide
)
Description:
This patch enables jellying of new style classes in python
Filename:
MIME Type:
Creator:
Matthew Sherborne
Created:
2005-08-09 20:10:52 UTC
Size:
2.50 KB
patch
obsolete
>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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 99300
:
65571
|
65575
|
72359