[Zope3-checkins] CVS: Zope3/src/zope/app/services - adapter.py:1.20.6.1 field.py:1.8.6.1 folder.py:1.11.6.2 module.py:1.11.2.2 module.zcml:1.1.2.2 registration.py:1.3.2.1 service.py:1.27.6.1 view.py:1.28.2.1
Jim Fulton
jim@zope.com
Mon, 30 Jun 2003 07:16:21 -0400
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv6099/src/zope/app/services
Modified Files:
Tag: fdrake-local-modules-branch
adapter.py field.py folder.py module.py module.zcml
registration.py service.py view.py
Log Message:
Checkpointing to branch. Will make detailed comments in merge.
=== Zope3/src/zope/app/services/adapter.py 1.20 => 1.20.6.1 ===
--- Zope3/src/zope/app/services/adapter.py:1.20 Sun Jun 22 20:31:31 2003
+++ Zope3/src/zope/app/services/adapter.py Mon Jun 30 07:15:50 2003
@@ -18,19 +18,18 @@
__metaclass__ = type
import sys
+from zope.app import zapi
from zope.interface.adapter import AdapterRegistry
from persistence import Persistent
from persistence.dict import PersistentDict
from zope.interface import implements
from zope.component.interfaces import IAdapterService
from zope.component.exceptions import ComponentLookupError
-from zope.component import getServiceManager
from zope.app.services.servicenames import Adapters
from zope.app.interfaces.services.registration import IRegistry
from zope.app.services.registration import RegistrationStack
from zope.app.services.registration import SimpleRegistration
from zope.app.context import ContextWrapper
-from zope.context import ContextMethod
from zope.app.component.nextservice import getNextService
from zope.app.interfaces.services.service import ISimpleService
@@ -57,7 +56,7 @@
registration.adapterName,
default)
- queryRegistrationsFor = ContextMethod(queryRegistrationsFor)
+ queryRegistrationsFor = zapi.ContextMethod(queryRegistrationsFor)
def queryRegistrations(self,
forInterface, providedInterface, adapterName,
@@ -73,7 +72,7 @@
return ContextWrapper(registry, self)
- queryRegistrations = ContextMethod(queryRegistrations)
+ queryRegistrations = zapi.ContextMethod(queryRegistrations)
def createRegistrationsFor(self, registration):
"See IRegistry"
@@ -82,7 +81,7 @@
registration.forInterface, registration.providedInterface,
registration.adapterName)
- createRegistrationsFor = ContextMethod(createRegistrationsFor)
+ createRegistrationsFor = zapi.ContextMethod(createRegistrationsFor)
def createRegistrations(self, forInterface, providedInterface, name):
@@ -98,7 +97,7 @@
return ContextWrapper(registry, self)
- createRegistrations = ContextMethod(createRegistrations)
+ createRegistrations = zapi.ContextMethod(createRegistrations)
def getAdapter(self, object, interface, name=''):
"See IAdapterService"
@@ -107,7 +106,7 @@
raise ComponentLookupError(object, interface)
return adapter
- getAdapter = ContextMethod(getAdapter)
+ getAdapter = zapi.ContextMethod(getAdapter)
def getNamedAdapter(self, object, interface, name):
"See IAdapterService"
@@ -116,7 +115,7 @@
raise ComponentLookupError(object, interface)
return adapter
- getNamedAdapter = ContextMethod(getNamedAdapter)
+ getNamedAdapter = zapi.ContextMethod(getNamedAdapter)
def queryAdapter(self, object, interface, default=None, name=''):
"""see IAdapterService interface"""
@@ -151,7 +150,7 @@
return self.queryNamedAdapter(object, interface, name, default)
- queryAdapter = ContextMethod(queryAdapter)
+ queryAdapter = zapi.ContextMethod(queryAdapter)
def queryNamedAdapter(self, object, interface, name, default=None):
adapters = self._byName.get(name)
@@ -172,7 +171,7 @@
return adapters.queryNamedAdapter(object, interface, name, default)
- queryNamedAdapter = ContextMethod(queryNamedAdapter)
+ queryNamedAdapter = zapi.ContextMethod(queryNamedAdapter)
# XXX need to add name support
def getRegisteredMatching(self,
@@ -211,11 +210,11 @@
self.factoryName = factoryName
def getAdapter(self, object):
- sm = getServiceManager(self)
- factory = sm.resolve(self.factoryName)
+ folder = zapi.getWrapperContainer(zapi.getWrapperContainer(self))
+ factory = folder.resolve(self.factoryName)
return factory(object)
- getAdapter = ContextMethod(getAdapter)
+ getAdapter = zapi.ContextMethod(getAdapter)
# XXX Pickle backward compatability
AdapterConfiguration = AdapterRegistration
=== Zope3/src/zope/app/services/field.py 1.8 => 1.8.6.1 ===
--- Zope3/src/zope/app/services/field.py:1.8 Sat Jun 7 01:31:58 2003
+++ Zope3/src/zope/app/services/field.py Mon Jun 30 07:15:50 2003
@@ -17,13 +17,11 @@
"""
__metaclass__ = type
+from zope.app import zapi
from zope.schema import Field
from zope.schema.interfaces import ValidationError
-from zope.app.traversing import traverse
from zope.exceptions import NotFoundError
from zope.app.interfaces.services.field import IComponentPath
-from zope.app.interfaces.services.field import IComponentLocation
-from zope.component import getServiceManager, getAdapter
from zope.app.interfaces.services.module import IModuleService
from zope.interface import implements
@@ -44,57 +42,10 @@
raise ValidationError("Not an absolute path", value)
try:
- component = traverse(self.context, value)
+ component = zapi.traverse(self.context, value)
except NotFoundError:
raise ValidationError("Path for non-existent object", value)
if not self.type.isImplementedBy(component):
raise ValidationError("Wrong component type", value)
-class ComponentLocation(Field):
-
- implements(IComponentLocation)
-
- _type = unicode
-
- def __init__(self, type, *args, **kw):
- self.type = type
- super(ComponentLocation, self).__init__(*args, **kw)
-
- def _validate(self, value):
- super(ComponentLocation, self)._validate(value)
- component = locateComponent(value, self.context, self.type)
-
-
-def locateComponent(location, context, interface=None):
- '''Locate a component by traversal, or by a dotted module name.
-
- If 'interface' is given, check that the located componenent implements
- the given interface.
- '''
- if location.startswith('/'):
- try:
- component = traverse(context, location)
- except NotFoundError:
- raise ValidationError('Path for non-existent object', location)
- else:
- # Assume location is a dotted module name
- if location.startswith('.'):
- # Catch the error of thinking that this is just like
- # a leading dot in zcml.
- raise ValidationError(
- "Module name must not start with a '.'", location)
- # XXX Need to be careful here. Jim was going to look
- # at whether a checkedResolve method is needed.
- servicemanager = getServiceManager(context)
- resolver = getAdapter(servicemanager, IModuleService)
- try:
- component = resolver.resolve(location)
- except ImportError:
- raise ValidationError("Cannot resolve module name", location)
-
- if interface is not None and not interface.isImplementedBy(component):
- raise ValidationError(
- 'Component must be %s' % interface, location)
-
- return component
=== Zope3/src/zope/app/services/folder.py 1.11.6.1 => 1.11.6.2 ===
--- Zope3/src/zope/app/services/folder.py:1.11.6.1 Sat Jun 28 10:44:04 2003
+++ Zope3/src/zope/app/services/folder.py Mon Jun 30 07:15:50 2003
@@ -30,20 +30,11 @@
from zope.context import ContextMethod
from zope.interface import implements
+
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.2.1 => 1.11.2.2 ===
--- Zope3/src/zope/app/services/module.py:1.11.2.1 Sat Jun 28 10:44:04 2003
+++ Zope3/src/zope/app/services/module.py Mon Jun 30 07:15:50 2003
@@ -36,25 +36,24 @@
implements(IModuleManager, IAttributeAnnotatable)
- # The registry for the manager is the ServiceManager.
- # The association between this manager and the registry
- # is static, but the static association can't be stored
- # explicitly in Zope.
-
- # XXX There is no locking, but every call to setModuleService()
- # for a particular instance should have the same manager argument.
-
- # XXX It would be nice if the lookup via getServiceManager()
- # occurred less often. Best would be to do it only when the
- # object is unpickled.
-
zapi.ContextAwareDescriptors()
def __init__(self, name, source):
- self._source = None
self.name = name
+ self._source = None
self.source = source
+ def __setstate__(self, state):
+ manager = state.get('_manager')
+ if manager is None:
+ return Persistent.__setstate__(self, state)
+
+ # We need to conver an old-style manager
+ self._module = manager._module
+ self.name = manager.name
+ self._source = manager.source
+ self._recompile = False
+
def execute(self):
try:
mod = self._module
@@ -66,7 +65,7 @@
def getModule(self):
if self._recompile:
- self._execute()
+ self.execute()
return self._module
def _get_source(self):
@@ -78,6 +77,10 @@
source = property(_get_source, _set_source)
+# Hack to allow unpickling of old Managers to get far enough for __setstate__
+# to do it's magic:
+Registry = Manager
+
class ModuleAdapter(ObjectEntryAdapter):
implements(IObjectFile)
@@ -108,7 +111,8 @@
return m
-# Installer function that can be called from ZCML:
+# Installer function that can be called from ZCML.
+# This installs an import hook necessary to support persistent modules.
def installPersistentModuleImporter(event):
from zodb.code.module import PersistentModuleImporter
=== Zope3/src/zope/app/services/module.zcml 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/services/module.zcml:1.1.2.1 Sat Jun 28 10:44:04 2003
+++ Zope3/src/zope/app/services/module.zcml Mon Jun 30 07:15:50 2003
@@ -8,6 +8,7 @@
<require
permission="zope.ManageCode"
interface="zope.app.interfaces.services.module.IModuleManager"
+ set_schema="zope.app.interfaces.services.module.IModuleManager"
/>
</content>
=== Zope3/src/zope/app/services/registration.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zope/app/services/registration.py:1.3 Tue Jun 24 18:38:26 2003
+++ Zope3/src/zope/app/services/registration.py Mon Jun 30 07:15:50 2003
@@ -28,26 +28,8 @@
from zope.app.interfaces.container import IAddNotifiable, IDeleteNotifiable
from zope.app.interfaces.container import IZopeWriteContainer
from zope.app.interfaces.dependable import IDependable, DependencyError
-
-from zope.app.interfaces.services.registration import IRegistrationManager
-from zope.app.interfaces.services.registration import IRegistrationStack
-from zope.app.interfaces.services.registration \
- import INameComponentRegistry
-from zope.app.interfaces.services.registration import INamedRegistration
-from zope.app.interfaces.services.registration import IRegistration
-from zope.app.interfaces.services.registration \
- import INamedComponentRegistration
-from zope.app.interfaces.services.registration import INameRegistry
-from zope.app.interfaces.services.registration \
- import INamedComponentRegistration, IComponentRegistration
-from zope.app.interfaces.services.registration import IRegistered
-from zope.app.interfaces.services.registration \
- import NoRegistrationManagerError
-from zope.app.interfaces.services.registration import NoLocalServiceError
-
-from zope.app.interfaces.services.registration import UnregisteredStatus
-from zope.app.interfaces.services.registration import ActiveStatus
-from zope.app.interfaces.services.registration import RegisteredStatus
+from zope.app.interfaces.services import registration as interfaces
+from zope.app.interfaces.services.module import IModuleManager
from zope.proxy import removeAllProxies
from zope.security.checker import InterfaceChecker
from zope.security.proxy import Proxy, trustedRemoveSecurityProxy
@@ -68,11 +50,11 @@
if registry:
if registry.active() == registration:
- return ActiveStatus
+ return interfaces.ActiveStatus
if registry.registered(registration):
- return RegisteredStatus
+ return interfaces.RegisteredStatus
- return UnregisteredStatus
+ return interfaces.UnregisteredStatus
def __set__(self, inst, value):
registration = inst
@@ -82,13 +64,13 @@
registry = service and service.queryRegistrationsFor(registration)
- if value == UnregisteredStatus:
+ if value == interfaces.UnregisteredStatus:
if registry:
registry.unregister(registration)
else:
if not service:
- raise NoLocalServiceError(
+ raise interfaces.NoLocalServiceError(
"This registration change cannot be performed because "
"there isn't a corresponding %s service defined in this "
"site. To proceed, first add a local %s service."
@@ -97,13 +79,13 @@
if registry is None:
registry = service.createRegistrationsFor(registration)
- if value == RegisteredStatus:
+ if value == interfaces.RegisteredStatus:
if registry.active() == registration:
registry.deactivate(registration)
else:
registry.register(registration)
- elif value == ActiveStatus:
+ elif value == interfaces.ActiveStatus:
if not registry.registered(registration):
registry.register(registration)
registry.activate(registration)
@@ -123,7 +105,7 @@
service manager to an object implementing IRegistration
"""
- implements(IRegistrationStack)
+ implements(interfaces.IRegistrationStack)
_data = ()
@@ -312,7 +294,7 @@
IDeleteNotifiable.
"""
- implements(IRegistration, IDeleteNotifiable,
+ implements(interfaces.IRegistration, IDeleteNotifiable,
# We are including this here because we want all of the
# subclasses to get it and we don't really need to be
# flexible about the policy here. At least we don't
@@ -344,22 +326,22 @@
objectstatus = registration.status
- if objectstatus == ActiveStatus:
+ if objectstatus == interfaces.ActiveStatus:
try:
objectpath = zapi.getPath(registration)
except: # XXX
objectpath = str(registration)
raise DependencyError("Can't delete active registration (%s)"
% objectpath)
- elif objectstatus == RegisteredStatus:
- registration.status = UnregisteredStatus
+ elif objectstatus == interfaces.RegisteredStatus:
+ registration.status = interfaces.UnregisteredStatus
class NamedRegistration(SimpleRegistration):
"""Named registration
"""
- implements(INamedRegistration)
+ implements(interfaces.INamedRegistration)
def __init__(self, name):
self.name = name
@@ -377,7 +359,7 @@
# SimpleRegistration implements IDeleteNotifiable, so we don't need
# it below.
- implements(IComponentRegistration, IAddNotifiable)
+ implements(interfaces.IComponentRegistration, IAddNotifiable)
def __init__(self, component_path, permission=None):
self.componentPath = component_path
@@ -441,7 +423,7 @@
objectpath = zapi.getPath(registration)
dependents.addDependent(objectpath)
# Also update usage, if supported
- adapter = zapi.queryAdapter(component, IRegistered)
+ adapter = zapi.queryAdapter(component, interfaces.IRegistered)
if adapter is not None:
adapter.addUsage(zapi.getPath(registration))
@@ -454,7 +436,7 @@
objectpath = zapi.getPath(registration)
dependents.removeDependent(objectpath)
# Also update usage, if supported
- adapter = zapi.queryAdapter(component, IRegistered)
+ adapter = zapi.queryAdapter(component, interfaces.IRegistered)
if adapter is not None:
adapter.removeUsage(zapi.getPath(registration))
@@ -463,7 +445,7 @@
This configures components that live in folders, by name.
"""
- implements(INamedComponentRegistration)
+ implements(interfaces.INamedComponentRegistration)
def __init__(self, name, component_path, permission=None):
NamedRegistration.__init__(self, name)
@@ -473,7 +455,7 @@
class NameRegistry:
"""Mixin for implementing INameRegistry
"""
- implements(INameRegistry)
+ implements(interfaces.INameRegistry)
def __init__(self, *args, **kw):
self._bindings = {}
@@ -514,7 +496,7 @@
class NameComponentRegistry(NameRegistry):
"""Mixin for implementing INameComponentRegistry
"""
- implements(INameComponentRegistry)
+ implements(interfaces.INameComponentRegistry)
def queryActiveComponent(wrapped_self, name, default=None):
"""See INameComponentRegistry"""
@@ -536,7 +518,7 @@
data is represented.
"""
- implements(IRegistered)
+ implements(interfaces.IRegistered)
# We want to use this key:
# key = "zope.app.services.registration.Registered"
@@ -555,7 +537,7 @@
Manages registrations within a package.
"""
- implements(IRegistrationManager, IDeleteNotifiable)
+ implements(interfaces.IRegistrationManager, IDeleteNotifiable)
def __init__(self):
self._data = ()
@@ -692,6 +674,8 @@
"""Mix-in to implement IRegistrationManagerContainer
"""
+ implements(interfaces.IRegistrationManagerContainer)
+
def __init__(self):
super(RegistrationManagerContainer, self).__init__()
self.setObject('RegistrationManager', RegistrationManager())
@@ -700,11 +684,13 @@
"""Delete an item, but not if it's the last registration manager
"""
item = self[name]
- if IRegistrationManager.isImplementedBy(item):
+ if interfaces.IRegistrationManager.isImplementedBy(item):
# Check to make sure it's not the last one
if len([i for i in self.values()
- if IRegistrationManager.isImplementedBy(i)]) < 2:
- raise NoRegistrationManagerError(
+ if interfaces.IRegistrationManager.isImplementedBy(i)
+ ]
+ ) < 2:
+ raise interfaces.NoRegistrationManagerError(
"Can't delete the last registration manager")
super(RegistrationManagerContainer, self).__delitem__(name)
@@ -714,13 +700,52 @@
# Get the registration manager for this folder
for name in self:
item = self[name]
- if IRegistrationManager.isImplementedBy(item):
+ if interfaces.IRegistrationManager.isImplementedBy(item):
# We found one. Get it in context
return zapi.ContextWrapper(item, self, name=name)
else:
- raise NoRegistrationManagerError(
+ raise interfaces.NoRegistrationManagerError(
"Couldn't find an registration manager")
getRegistrationManager = zapi.ContextMethod(getRegistrationManager)
+
+ def findModule(self, name):
+ # Used by the persistent modules import hook
+
+ # Look for a .py file first:
+ manager = self.get(name+'.py')
+ if manager is not None:
+ # found an item with that name, make sure it's a module(manager):
+ if IModuleManager.isImplementedBy(manager):
+ return manager.getModule()
+
+ # Look for the module in this folder:
+ manager = self.get(name)
+ if manager is not None:
+ # found an item with that name, make sure it's a module(manager):
+ if IModuleManager.isImplementedBy(manager):
+ return manager.getModule()
+
+
+ # See if out container is a RegistrationManagerContainer:
+ c = zapi.getWrapperContainer(self)
+ if interfaces.IRegistrationManagerContainer.isImplementedBy(c):
+ return c.findModule(name)
+
+ # Use sys.modules in leu of module service:
+ module = sys.modules.get(name)
+ if module is not None:
+ return module
+
+ raise ImportError(name)
+
+ findModule = zapi.ContextMethod(findModule)
+
+ def resolve(self, name):
+ l = name.rfind('.')
+ mod = self.findModule(name[:l])
+ return getattr(mod, name[l+1:])
+
+ resolve = zapi.ContextMethod(resolve)
from zope.xmlpickle import dumps, loads
=== Zope3/src/zope/app/services/service.py 1.27 => 1.27.6.1 ===
--- Zope3/src/zope/app/services/service.py:1.27 Sun Jun 22 20:31:31 2003
+++ Zope3/src/zope/app/services/service.py Mon Jun 30 07:15:50 2003
@@ -49,10 +49,6 @@
from zope.app.interfaces.services.service import IServiceRegistration
from zope.app.interfaces.services.service import IServiceManager
-# Declare a tuple of all types we consider to be modules
-# (used as 2nd argument to isinstance() in method resolve() below)
-ModuleType = type(IModuleService), PersistentModule
-
from zope.app.services.registration import NameComponentRegistry
from zope.app.services.registration import NamedComponentRegistration
from zope.app.services.folder import SiteManagementFolders
@@ -62,7 +58,7 @@
class ServiceManager(PersistentModuleRegistry, NameComponentRegistry):
- implements(IServiceManager, IContainer, IModuleService)
+ implements(IServiceManager, IContainer)
def __init__(self):
PersistentModuleRegistry.__init__(self)
@@ -262,37 +258,6 @@
return mod
__import = ContextMethod(__import)
-
- def resolve(wrapped_self, name):
-
- name = name.strip()
-
- if name.endswith('.') or name.endswith('+'):
- name = name[:-1]
- repeat = 1
- else:
- repeat = 0
-
- names = name.split('.')
- last = names[-1]
- mod = '.'.join(names[:-1])
-
- if not mod:
- return wrapped_self.__import(name)
-
- while 1:
- m = wrapped_self.__import(mod)
- try:
- a = getattr(m, last)
- except AttributeError:
- if not repeat:
- return wrapped_self.__import(name)
-
- else:
- if not repeat or (not isinstance(a, ModuleType)):
- return a
- mod += '.' + last
- resolve = ContextMethod(resolve)
class ServiceRegistration(NamedComponentRegistration):
=== Zope3/src/zope/app/services/view.py 1.28 => 1.28.2.1 ===
--- Zope3/src/zope/app/services/view.py:1.28 Tue Jun 24 11:38:04 2003
+++ Zope3/src/zope/app/services/view.py Mon Jun 30 07:15:50 2003
@@ -18,6 +18,7 @@
from __future__ import generators
+from zope.app import zapi
from persistence import Persistent
from persistence.dict import PersistentDict
@@ -28,8 +29,8 @@
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.interfaces.services.interface import IInterfaceBasedRegistry
-from zope.app.interfaces.services.registration \
- import IRegistry, IRegistration, ActiveStatus
+from zope.app.interfaces.services.registration import ActiveStatus
+from zope.app.interfaces.services.registration import IRegistry, IRegistration
from zope.app.services.registration import RegistrationStack
from zope.app.services.registration import SimpleRegistration
from zope.app.services.servicenames import Views
@@ -278,8 +279,8 @@
self.permission = permission
def getView(self, object, request):
- sm = zapi.getServiceManager(self)
- factory = sm.resolve(self.class_)
+ folder = zapi.getWrapperContainer(zapi.getWrapperContainer(self))
+ factory = folder.resolve(self.class_)
return factory(object, request)
getView = zapi.ContextMethod(getView)