[Zodb-checkins] CVS: Zope3/src/zodb/code - class_.py:1.15.4.1 patch.py:1.9.6.1

Jim Fulton jim at zope.com
Fri May 2 16:43:21 EDT 2003


Update of /cvs-repository/Zope3/src/zodb/code
In directory cvs.zope.org:/tmp/cvs-serv8709/src/zodb/code

Modified Files:
      Tag: interfacegeddon2-branch
	class_.py patch.py 
Log Message:
Merged interfacegeddon changes into second interfacegeddon branch in
preparation for the final merge.


=== Zope3/src/zodb/code/class_.py 1.15 => 1.15.4.1 ===
--- Zope3/src/zodb/code/class_.py:1.15	Thu May  1 15:34:59 2003
+++ Zope3/src/zodb/code/class_.py	Fri May  2 15:42:50 2003
@@ -236,6 +236,7 @@
     # GHOST instead of UPTODATE.  See __getnewargs__().
 
     def __new__(meta, name, bases, dict, state=UPTODATE):
+
         if "__dict__" in dict:
             del dict["__dict__"]
         cls = super(PersistentClassMetaClass, meta).__new__(
@@ -273,7 +274,9 @@
         # and its instances have separate versions.
         extend_meth("__getstate__", meta.__getstate__)
         extend_meth("__setstate__", meta.__setstate__)
-        extend_attr("__implements__", meta.__implements__)
+
+        # Don't need this with interface geddon
+        # extend_attr("__implements__", meta.__implements__)
 
         cls._pc_init = True
         return cls


=== Zope3/src/zodb/code/patch.py 1.9 => 1.9.6.1 ===
--- Zope3/src/zodb/code/patch.py:1.9	Thu May  1 15:34:59 2003
+++ Zope3/src/zodb/code/patch.py	Fri May  2 15:42:50 2003
@@ -93,6 +93,7 @@
 
 from zodb.code.class_ import PersistentClassMetaClass, PersistentDescriptor
 from zodb.code.function import PersistentFunction
+from pickle import REDUCE, BUILD
 
 class Wrapper:
     """Implement pickling reduce protocol for update-able object.
@@ -134,10 +135,10 @@
     def unwrap(self, bases, dict):
         return PersistentClassMetaClass(self._obj.__name__, bases, dict)
 
-def registerWrapper(atype, wrapper, unwrap_thunk):
+def registerWrapper(atype, wrapper, unwrap_args, getstate=None):
     """Register a patch wrapper for an external object type."""
     Pickler.dispatch[atype] = Pickler.save_external
-    Pickler.external[atype] = wrapper, unwrap_thunk
+    Pickler.external[atype] = wrapper, unwrap_args, getstate
 
 marker = object()
 
@@ -222,10 +223,8 @@
     def save_type(self, atype):
         if atype.__module__ == self._module_name:
             self.save_reduce(self.wrap(TypeWrapper, atype),
-                             (atype.__bases__, atype.__dict__))
-            memo_len = len(self.memo)
-            self.write(self.put(memo_len))
-            self.memo[id(atype)] = memo_len, None
+                             (atype.__bases__, atype.__dict__),
+                             obj=atype)
         else:
             if isinstance(atype, PersistentClassMetaClass):
                 self.save_pers(self.persistent_id(atype, True))
@@ -240,10 +239,8 @@
         modname = whichmodule(func, func.__name__)
         if modname == self._module_name or modname == "__main__":
             self.save_reduce(self.wrap(FunctionWrapper, func),
-                             (func.func_defaults, func.func_dict))
-            memo_len = len(self.memo)
-            self.write(self.put(memo_len))
-            self.memo[id(func)] = memo_len, None
+                             (func.func_defaults, func.func_dict),
+                             obj=func)
         else:
             self.save_global(func)
 
@@ -256,11 +253,14 @@
         if obj.__module__ == self._module_name:
             # Save an external type registered through registerWrapper
             objtype = type(obj)
-            wrapper, unwrap_thunk = self.external[objtype]
-            self.save_reduce(self.wrap(wrapper, obj), unwrap_thunk(obj))
-            memo_len = len(self.memo)
-            self.write(self.put(memo_len))
-            self.memo[id(obj)] = memo_len, None
+            wrapper, unwrap_args, getstate = self.external[objtype]
+            if getstate is not None:
+                self.save_reduce(self.wrap(wrapper, obj), unwrap_args(obj),
+                                 getstate(obj),
+                                 obj=obj)
+            else:
+                self.save_reduce(self.wrap(wrapper, obj), unwrap_args(obj),
+                                 obj=obj)
         else:
             # In general, we don't know how to pickle this object,
             # so pickle it by reference to the original.
@@ -343,13 +343,28 @@
                                            "returned by %s must be a "
                                            "tuple" % reduce)
 
-            self.save_reduce(callable, arg_tup, state)
-            memo_len = len(self.memo)
-            self.write(self.put(memo_len))
-            self.memo[d] = (memo_len, obj)
+            self.save_reduce(callable, arg_tup, state, obj=obj)
             return
 
         f(self, obj)
+
+    def save_reduce(self, callable, arg_tup, state = None, obj = None):
+        write = self.write
+        save = self.save
+
+        save(callable)
+        save(arg_tup)
+        write(REDUCE)
+
+        if obj is not None:
+            memo_len = len(self.memo)
+            self.write(self.put(memo_len))
+            self.memo[id(obj)] = (memo_len, obj)
+            
+
+        if state is not None:
+            save(state)
+            write(BUILD)
 
 class Unpickler(pickle.Unpickler):
 




More information about the Zodb-checkins mailing list