[Zodb-checkins] CVS: Zope3/lib/python/Persistence - patch.py:1.2

Jeremy Hylton jeremy@zope.com
Thu, 21 Nov 2002 15:32:12 -0500


Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv10483

Modified Files:
	patch.py 
Log Message:
Flesh out docstring and add some simple functions that map out the
next implementation steps.


=== Zope3/lib/python/Persistence/patch.py 1.1 => 1.2 ===
--- Zope3/lib/python/Persistence/patch.py:1.1	Tue Nov 12 20:30:53 2002
+++ Zope3/lib/python/Persistence/patch.py	Thu Nov 21 15:32:12 2002
@@ -13,6 +13,28 @@
 ##############################################################################
 """Patch references to auto-persistent objects in a module.
 
+When a persistent module is compiled, all classes and functions should
+be converted to persistent classes and functions.  When a module is
+updated, it is compiled and its persistent functions and classes are
+updated in place so that clients of the module see the update.
+
+The specific semantics of the convert and update-in-place operations
+are still being determined.  Here are some rough notes:
+
+- Classes and functions are not converted in place.  New objects are
+  created to replace the builtin functions and classes.
+
+- Every function object is converted to a PersistentFunction.
+
+- Every class is converted to a new class that is created by calling
+  the PersistentClassMetaClass with the name, bases, and dict of the
+  class being converted.
+
+- The conversion operation must preserve object identity.  If an
+  object created by a def or class statement is referenced elsewhere
+  in the module, all references must be replaced with references to
+  the converted object.
+
 Implementation notes:
 
 What semantics do we want for update-in-place in the presence of aliases?
@@ -39,6 +61,7 @@
 from types import *
 
 from Persistence.Class import PersistentClassMetaClass
+from Persistence.Function import PersistentFunction
 
 class FunctionWrapper:
 
@@ -100,5 +123,26 @@
     def persistent_load(self, oid):
         return self._pmemo[oid]
 
-def fixup(new, old):
-    pass
+def convert(module):
+    """Return a copy of module dict with object conversions performed."""
+    f = StringIO()
+    memo = {}
+    p = Pickler(f, module, memo)
+    p.dump(module.__dict__)
+    f.seek(0, 1) # reset file
+    u = Unpickler(
+    
+def update(newdict, olddict):
+    """Modify newdict to preserve identity of persistent objects in olddict.
+
+    If a persistent object is named in olddict and newdict, then 
+    persistent object identity should be preserved.  The object should
+    have the same oid in both dicts, and the object in the newdict
+    should have the new state.
+    """
+
+def fixup(module):
+    olddict = module.__dict__
+    newdict = convert(olddict)
+    update(newdict, olddict)
+    module.__dict__ = newdict