[Zope3-checkins] CVS: Zope3/src/zodb/code - module.py:1.17

Jim Fulton jim@zope.com
Mon, 30 Jun 2003 12:22:26 -0400


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

Modified Files:
	module.py 
Log Message:
Factored out compilation logic so we can use it without using
the default management strategy.


=== Zope3/src/zodb/code/module.py 1.16 => 1.17 ===
--- Zope3/src/zodb/code/module.py:1.16	Fri Jun 27 13:19:03 2003
+++ Zope3/src/zodb/code/module.py	Mon Jun 30 12:22:26 2003
@@ -101,6 +101,24 @@
     mgr.new(name, source)
     return mgr
 
+
+def compileModule(module, registry, source):
+    # Try to prevent compilation errors from files without trailing
+    # newlines.
+    if source and source[-1] != "\n":
+        source += "\n"
+    module._p_changed = True
+    moddict = module.__dict__
+    old_names = NameFinder(module)
+    moddict[__persistent_module_registry__] = registry
+    # XXX need to be able to replace sys.std{in,out,err} at this point
+    exec source in moddict
+    # XXX and restore them here.
+    del moddict[__persistent_module_registry__]
+    new_names = NameFinder(module)
+    replacements = new_names.replacements(old_names)
+    convert(module, replacements)
+
 class PersistentModuleManager(Persistent):
 
     implements(IPersistentModuleManager)
@@ -138,17 +156,7 @@
     def update(self, source):
         # Try to prevent compilation errors from files without trailing
         # newlines.
-        if source and source[-1] != "\n":
-            source += "\n"
-        self._module._p_changed = True
-        moddict = self._module.__dict__
-        old_names = NameFinder(self._module)
-        moddict[__persistent_module_registry__] = self._registry
-        exec source in moddict
-        del moddict[__persistent_module_registry__]
-        new_names = NameFinder(self._module)
-        replacements = new_names.replacements(old_names)
-        convert(self._module, replacements)
+        compileModule(self._module, self._registry, source)
         self.source = source
 
     def remove(self):