[Zope3-checkins] CVS: Zope3/src/zope/app/services - module.zcml:1.1.2.1 configure.zcml:1.44.2.1 folder.py:1.11.6.1 module.py:1.11.2.1
Fred L. Drake, Jr.
fred@zope.com
Sat, 28 Jun 2003 10:44:35 -0400
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv6318/src/zope/app/services
Modified Files:
Tag: fdrake-local-modules-branch
configure.zcml folder.py module.py
Added Files:
Tag: fdrake-local-modules-branch
module.zcml
Log Message:
Checkpoint: changes to local modules started with Jim on Thursday.
These are not yet ready to land on the trunk.
=== Added File Zope3/src/zope/app/services/module.zcml ===
<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:event='http://namespaces.zope.org/event'
xmlns:fssync='http://namespaces.zope.org/fssync'
>
<content class="zope.app.services.module.Manager">
<require
permission="zope.ManageCode"
interface="zope.app.interfaces.services.module.IModuleManager"
/>
</content>
<fssync:adapter
class=".module.Manager"
factory=".module.ModuleAdapter"
/>
<adapter
for="zope.app.interfaces.services.folder.ISiteManagementFolder"
provides="zope.app.interfaces.file.IFileFactory"
name=".py"
factory=".module.ModuleFactory"
permission="zope.ManageContent"
/>
<!-- Enable import of persistent modules -->
<event:subscribe
subscriber=".module.installPersistentModuleImporter"
event_types="zope.app.interfaces.event.IProcessStartingEvent"
/>
</zopeConfigure>
=== Zope3/src/zope/app/services/configure.zcml 1.44 => 1.44.2.1 ===
--- Zope3/src/zope/app/services/configure.zcml:1.44 Thu Jun 26 15:11:49 2003
+++ Zope3/src/zope/app/services/configure.zcml Sat Jun 28 10:44:04 2003
@@ -295,22 +295,6 @@
/>
</content>
-<!-- Modules -->
-
- <content class="zope.app.services.module.Manager">
- <require
- permission="zope.ManageCode"
- interface="zodb.code.interfaces.IPersistentModuleManager"
- />
- <require
- permission="zope.ManageCode"
- attributes="beforeDeleteHook"
- />
- <implements
- interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
- />
- </content>
-
<!-- Page Folder -->
<content class="zope.app.services.pagefolder.PageFolder">
@@ -498,11 +482,6 @@
/>
<fssync:adapter
- class=".module.Manager"
- factory=".module.ModuleAdapter"
- />
-
-<fssync:adapter
class=".cache.CacheRegistration"
factory=".registration.ComponentRegistrationAdapter"
/>
@@ -536,21 +515,10 @@
permission="zope.ManageContent"
/>
-<adapter
- for="zope.app.interfaces.services.folder.ISiteManagementFolder"
- provides="zope.app.interfaces.file.IFileFactory"
- name=".py"
- factory=".module.ModuleFactory"
- permission="zope.ManageContent"
- />
-
<!-- Local Interface Service -->
<include file="interface.zcml" />
-<!-- Enable import of persistent modules -->
-<event:subscribe
- subscriber=".module.installPersistentModuleImporter"
- event_types="zope.app.interfaces.event.IProcessStartingEvent"
- />
+<!-- Local Module Support -->
+<include file="module.zcml" />
</zopeConfigure>
=== Zope3/src/zope/app/services/folder.py 1.11 => 1.11.6.1 ===
--- Zope3/src/zope/app/services/folder.py:1.11 Sat Jun 21 17:22:12 2003
+++ Zope3/src/zope/app/services/folder.py Sat Jun 28 10:44:04 2003
@@ -33,6 +33,17 @@
class SiteManagementFolder(RegistrationManagerContainer, BTreeContainer):
implements(ISiteManagementFolder)
+ def findModule(self, name):
+ # Used by the persistent modules import hook
+ manager = self.get(name)
+ if manager is None:
+ manager = self.get(name + ".py")
+ if manager is None:
+ if name not in sys.modules:
+ raise ImportError, name
+ return sys.modules[name]
+ else:
+ return manager.getModule()
class SiteManagementFolders(BTreeContainer):
implements(ISiteManagementFolders)
=== Zope3/src/zope/app/services/module.py 1.11 => 1.11.2.1 ===
--- Zope3/src/zope/app/services/module.py:1.11 Thu Jun 26 15:11:49 2003
+++ Zope3/src/zope/app/services/module.py Sat Jun 28 10:44:04 2003
@@ -17,61 +17,24 @@
"""
from persistence import Persistent
-from zodb.code.module import PersistentModuleManager
-from zodb.code.interfaces import IPersistentModuleManager
+from zodb.code.module import PersistentModule, compileModule
from zodb.code.interfaces import IPersistentModuleImportRegistry
from zodb.code.interfaces import IPersistentModuleUpdateRegistry
-from zope.component import getServiceManager
-from zope.context import ContextMethod
-
from zope.interface import implements
+from zope.app import zapi
from zope.app.event import function
from zope.app.fssync.classes import ObjectEntryAdapter, AttrMapping
+from zope.app.interfaces.annotation import IAttributeAnnotatable
from zope.app.interfaces.fssync import IObjectFile
from zope.app.interfaces.file import IFileFactory
-from zope.app.interfaces.container import IDeleteNotifiable
-from zope.app.context import ContextWrapper
-
-
-class Registry(Persistent):
-
- # This is a wrapper around the module service, which is actually
- # the service manager. The service manager is found via context,
- # but the PersistentModuleManager doesn't know about context. To
- # make it behave contextually, this Registry class collaborates
- # with the Manager class below to delegate to the registry found
- # via context.
-
- implements(IPersistentModuleImportRegistry,
- IPersistentModuleUpdateRegistry)
-
- def __init__(self):
- self._v_module_service = None
+from zope.app.interfaces.services.module import IModuleManager
- def setModuleService(self, ms):
- # This method is called by methods of Manager below
- self._v_module_service = ms
-
- # The next three methods are called by the persistent module manager
-
- def findModule(self, name):
- return self._v_module_service.findModule(name)
-
- def setModule(self, name, module):
- return self._v_module_service.setModule(name, module)
-
- def delModule(self, name):
- return self._v_module_service.delModule(name)
-
- def __getstate__(self):
- # So pickling this object doesn't include the module service
- return {}
class Manager(Persistent):
- implements(IPersistentModuleManager, IDeleteNotifiable)
+ implements(IModuleManager, IAttributeAnnotatable)
# The registry for the manager is the ServiceManager.
# The association between this manager and the registry
@@ -85,32 +48,34 @@
# occurred less often. Best would be to do it only when the
# object is unpickled.
- def __init__(self):
- self._registry = Registry()
- self._manager = PersistentModuleManager(self._registry)
-
- def new(self, name, source):
- self._registry.setModuleService(getServiceManager(self))
- self._manager.new(name, source)
-
- def update(self, source):
- self._registry.setModuleService(getServiceManager(self))
- self._manager.update(source)
-
- def remove(self):
- self._registry.setModuleService(getServiceManager(self))
- self._manager.remove()
-
- new = ContextMethod(new)
- update = ContextMethod(update)
- remove = ContextMethod(remove)
-
- name = property(lambda self: self._manager.name)
- source = property(lambda self: self._manager.source)
-
- def beforeDeleteHook(self, obj, container):
- obj.remove()
- beforeDeleteHook = ContextMethod(beforeDeleteHook)
+ zapi.ContextAwareDescriptors()
+
+ def __init__(self, name, source):
+ self._source = None
+ self.name = name
+ self.source = source
+
+ def execute(self):
+ try:
+ mod = self._module
+ except AttributeError:
+ mod = self._module = PersistentModule(self.name)
+ folder = zapi.getWrapperContainer(self)
+ compileModule(mod, folder, self.source)
+ self._recompile = False
+
+ def getModule(self):
+ if self._recompile:
+ self._execute()
+ return self._module
+
+ def _get_source(self):
+ return self._source
+ def _set_source(self, source):
+ if self._source != source:
+ self._source = source
+ self._recompile = True
+ source = property(_get_source, _set_source)
class ModuleAdapter(ObjectEntryAdapter):
@@ -137,9 +102,9 @@
def __call__(self, name, content_type, data):
assert name.endswith(".py")
name = name[:-3]
- m = Manager()
- m = ContextWrapper(m, self.context)
- m.new(name, data)
+ m = Manager(name, data)
+ m = zapi.ContextWrapper(m, self.context)
+ m.execute()
return m