Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/patches/jelly.patch
blob: ce6bff2f8be9fc53e23158629d418de540ee53ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--- ../../exe0.3/exe/webui/jelly.orig.py	2005-04-12 12:27:58.347586248 +1200
+++ /usr/lib/python2.3/site-packages/twisted/spread/jelly.py	2005-04-12 13:27:36.427635400 +1200
@@ -140,6 +140,20 @@
 unjellyableRegistry = {}
 unjellyableFactoryRegistry = {}
 
+def _newInstance(cls, dct={}):
+    """Make a new instance of a class
+    without calling its __init__ method.
+    dct will be used to update inst.__dict__
+    Supports new and old classes
+    """
+    if not isinstance(cls, types.ClassType):
+        inst = cls.__new__(cls)
+        inst.__dict__.update(dct) # Copy 'instance' behaviour
+    else:
+        inst = instance(cls, dct)
+    return inst
+
+
 def _maybeClass(classnamep):
     try:
         object
@@ -560,12 +574,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 +711,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