[Zope3-checkins] CVS: Zope3/src/zodb/code - interfaces.py:1.4 module.py:1.6
Jeremy Hylton
jeremy@zope.com
Tue, 31 Dec 2002 13:28:49 -0500
Update of /cvs-repository/Zope3/src/zodb/code
In directory cvs.zope.org:/tmp/cvs-serv11137/zodb/code
Modified Files:
interfaces.py module.py
Log Message:
Add ManagedRegistry class to persistent modules.
Add modules() to registry interface.
=== Zope3/src/zodb/code/interfaces.py 1.3 => 1.4 ===
--- Zope3/src/zodb/code/interfaces.py:1.3 Mon Dec 30 12:21:28 2002
+++ Zope3/src/zodb/code/interfaces.py Tue Dec 31 13:28:48 2002
@@ -18,6 +18,9 @@
def findModule(name):
"""Return module registered under name or None."""
+ def modules():
+ """Return a list of module names in the registry."""
+
class IPersistentModuleUpdateRegistry(IPersistentModuleImportRegistry):
def setModule(name, module):
=== Zope3/src/zodb/code/module.py 1.5 => 1.6 ===
--- Zope3/src/zodb/code/module.py:1.5 Mon Dec 30 17:52:00 2002
+++ Zope3/src/zodb/code/module.py Tue Dec 31 13:28:48 2002
@@ -268,25 +268,63 @@
return name[:i]
class PersistentModuleRegistry(Persistent):
+ """A collection of persistent modules.
+
+ The registry is similar in purpose to sys.modules. A persistent
+ module manager stores its modules in a registry, and the importer
+ looks for them there.
+ """
__implements__ = (IPersistentModuleImportRegistry,
IPersistentModuleUpdateRegistry)
def __init__(self):
- self.__modules = {}
+ self._modules = {}
def findModule(self, name):
assert self._p_state != GHOST
- return self.__modules.get(name)
+ return self._modules.get(name)
def setModule(self, name, module):
- if name in self.__modules:
+ if name in self._modules:
# The name is already in use.
# XXX should raise a better error
raise ValueError, name
self._p_changed = True
- self.__modules[name] = module
+ self._modules[name] = module
def delModule(self, name):
self._p_changed = True
- del self.__modules[name]
+ del self._modules[name]
+
+ def modules(self):
+ """Return a list of the modules in the registry."""
+ return self._modules.keys()
+
+class ManagedRegistry(PersistentModuleRegistry):
+ """A collection of persistent modules and their managers.
+
+ An extension of the persistent module registry that also collects
+ the managers. For persistent modules to be useful, the managers
+ must be stored in the database. This registry stores managers
+ as well as their modules, so that all objects related to the modules
+ in the registry are reachable from the registry.
+ """
+
+ def __init__(self):
+ super(ManagedRegistry, self).__init__()
+ self._mgrs = {}
+
+ def newModule(self, name, source):
+ mgr = PersistentModuleManager(self)
+ mgr.new(name, source)
+ self._p_changed = True
+ self._mgrs[name] = mgr
+
+ def updateModule(self, name, source):
+ self._mgrs[name].update(source)
+
+ def removeModule(self, name):
+ self._mgrs[name].remove()
+ self._p_changed = True
+ del self._mgrs[name]