[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.5 service.py:1.4

Jim Fulton jim@zope.com
Mon, 30 Dec 2002 07:50:27 -0500


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv13482

Modified Files:
	configure.zcml service.py 
Log Message:
- Reformmated service module.

- Added implementation of keys, values, items, and __len__ for service
  managers. This was necessary, since the claim to be service
  managers. Note that we *only* expose Packages in the enumeration
  interface, at least for now.

- Changed the security assertions to cover (all of) IReadContainer.



=== Zope3/src/zope/app/services/configure.zcml 1.4 => 1.5 ===
--- Zope3/src/zope/app/services/configure.zcml:1.4	Thu Dec 26 17:11:54 2002
+++ Zope3/src/zope/app/services/configure.zcml	Mon Dec 30 07:50:27 2002
@@ -182,7 +182,7 @@
   <content class="zope.app.services.service.ServiceManager">
     <require
         permission="zope.View"
-        interface="zope.app.interfaces.container.ISimpleReadContainer" />
+        interface="zope.app.interfaces.container.IReadContainer" />
     <require
         permission="zope.ManageServices"
         interface="zope.app.interfaces.services.service.IServiceManager" />


=== Zope3/src/zope/app/services/service.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/services/service.py:1.3	Sat Dec 28 09:13:28 2002
+++ Zope3/src/zope/app/services/service.py	Mon Dec 30 07:50:27 2002
@@ -11,135 +11,53 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
-
-Revision information:
-$Id$
-"""
+"""Service manager implementation
 
-from zope.app.interfaces.services.service import IServiceManagerContainer
-from zope.component.interfaces import IServiceService
-from zope.component.exceptions import ComponentLookupError
 
-_marker = object()
+A service manager has a number of roles:
 
-class ServiceManagerContainer:
+  - A service service
 
-    __implements__ =  IServiceManagerContainer
+  - A place to do TTW development or to manage database-based code
 
-    def hasServiceManager(self):
-        '''See interface IReadServiceManagerContainer'''
-        return hasattr(self, '_ServiceManagerContainer__sm')
-
-    def getServiceManager(self):
-        '''See interface IReadServiceManagerContainer'''
-
-        try:
-            return self.__sm
-        except AttributeError:
-            raise ComponentLookupError('no service manager defined')
-
-    def queryServiceManager(self, default=None):
-        '''See interface IReadServiceManagerContainer'''
-
-        return getattr(self, '_ServiceManagerContainer__sm', default)
-
-    def setServiceManager(self, sm):
-        '''See interface IWriteServiceManagerContainer'''
-
-        if IServiceService.isImplementedBy(sm):
-            self.__sm = sm
-        else:
-            raise ValueError('setServiceManager requires an IServiceService')
-
-    #
-    ############################################################
-
-
-
-"""
-$Id$
-"""
-
-from zope.app.interfaces.services.service import IServiceConfiguration
-from zope.app.interfaces.services.service import IBindingAware
-from zope.app.services.configuration import ConfigurationStatusProperty
-from zope.app.services.configuration import NamedComponentConfiguration
-from zope.proxy.context import ContextMethod
-from zope.component import getServiceManager
-
-class ServiceConfiguration(NamedComponentConfiguration):
-
-    __doc__ = IServiceConfiguration.__doc__
-
-    __implements__ = (IServiceConfiguration,
-                      NamedComponentConfiguration.__implements__)
-
-    status = ConfigurationStatusProperty('Services')
-
-    label = "Service"
-
-    def __init__(self, *args, **kw):
-        super(ServiceConfiguration, self).__init__(*args, **kw)
-
-    def getInterface(self):
-        service_manager = getServiceManager(self)
-        return service_manager.getInterfaceFor(self.name)
-
-    getInterface = ContextMethod(getInterface)
-
-    def activated(self):
-        service = self.getComponent()
-        if IBindingAware.isImplementedBy(service):
-            service.bound(self.name)
-
-    activated = ContextMethod(activated)
-
-    def deactivated(self):
-        service = self.getComponent()
-        if IBindingAware.isImplementedBy(service):
-            service.unbound(self.name)
-
-    deactivated = ContextMethod(deactivated)
-
-__doc__ = ServiceConfiguration.__doc__  + __doc__
-
-
-
-
-"""XXX I need a summary line.
-
-In addition, a ServiceManager acts as a registry for persistent
-modules.  The Zope import hook uses the ServiceManager to search for
-modules.
+  - A registry for persistent modules.  The Zope import hook uses the
+    ServiceManager to search for modules.
 
 $Id$
 """
 
 import sys
 
-from zope.app.component.nextservice \
-     import getNextServiceManager, getNextService
+from zodb.code.module import PersistentModule
+from zodb.code.module import PersistentModuleRegistry
+
+from zope.component import getServiceManager
 from zope.component.exceptions import ComponentLookupError
+from zope.component.interfaces import IServiceService
 
-from zope.app.interfaces.container import IReadContainer
 from zope.proxy.context import ContextMethod
 from zope.proxy.context import ContextWrapper
 from zope.proxy.introspection import removeAllProxies
 
-from zope.app.services.package import Packages
+from zope.app.component.nextservice import getNextService
+from zope.app.component.nextservice import getNextServiceManager
+
+from zope.app.interfaces.container import IReadContainer
+from zope.app.interfaces.services.service import IBindingAware
+from zope.app.interfaces.services.service import INameResolver
+from zope.app.interfaces.services.service import IServiceConfiguration
 from zope.app.interfaces.services.service import IServiceManager
+from zope.app.interfaces.services.service import IServiceManagerContainer
 
+from zope.app.services.configuration import ConfigurationStatusProperty
 from zope.app.services.configuration import NameComponentConfigurable
+from zope.app.services.configuration import NamedComponentConfiguration
 
-from zodb.code.module import PersistentModuleRegistry
-from zodb.code.module import PersistentModule
-from zope.app.interfaces.services.service import INameResolver
+from zope.app.services.package import Packages
 
 ModuleType = type(INameResolver)
 ModuleType = ModuleType, PersistentModule
 
-
 class ServiceManager(PersistentModuleRegistry, NameComponentConfigurable):
 
     __implements__ = (IServiceManager, IReadContainer,
@@ -247,6 +165,23 @@
 
         return self.get(key) is not None
 
+    # Enumeration methods. We'll only expose Packages for now:
+    def keys(self):
+        return ['Packages']
+
+    def values(self):
+        return map(self.get, self.keys())
+
+    values = ContextMethod(values)
+
+    def items(self):
+        return [(key, self.get(key)) for key in self.keys()]
+
+    items = ContextMethod(items)
+
+    def __len__(self):
+        return 1
+
     def findModule(wrapped_self, name):
         # override to pass call up to next service manager
         mod = super(ServiceManager,
@@ -306,3 +241,67 @@
                     return a
             mod += '.' + last
     resolve = ContextMethod(resolve)
+
+class ServiceConfiguration(NamedComponentConfiguration):
+
+    __doc__ = IServiceConfiguration.__doc__
+
+    __implements__ = (IServiceConfiguration,
+                      NamedComponentConfiguration.__implements__)
+
+    status = ConfigurationStatusProperty('Services')
+
+    label = "Service"
+
+    def __init__(self, *args, **kw):
+        super(ServiceConfiguration, self).__init__(*args, **kw)
+
+    def getInterface(self):
+        service_manager = getServiceManager(self)
+        return service_manager.getInterfaceFor(self.name)
+
+    getInterface = ContextMethod(getInterface)
+
+    def activated(self):
+        service = self.getComponent()
+        if IBindingAware.isImplementedBy(service):
+            service.bound(self.name)
+
+    activated = ContextMethod(activated)
+
+    def deactivated(self):
+        service = self.getComponent()
+        if IBindingAware.isImplementedBy(service):
+            service.unbound(self.name)
+
+    deactivated = ContextMethod(deactivated)
+
+class ServiceManagerContainer:
+
+    __implements__ =  IServiceManagerContainer
+
+    def hasServiceManager(self):
+        '''See interface IReadServiceManagerContainer'''
+        return hasattr(self, '_ServiceManagerContainer__sm')
+
+    def getServiceManager(self):
+        '''See interface IReadServiceManagerContainer'''
+
+        try:
+            return self.__sm
+        except AttributeError:
+            raise ComponentLookupError('no service manager defined')
+
+    def queryServiceManager(self, default=None):
+        '''See interface IReadServiceManagerContainer'''
+
+        return getattr(self, '_ServiceManagerContainer__sm', default)
+
+    def setServiceManager(self, sm):
+        '''See interface IWriteServiceManagerContainer'''
+
+        if IServiceService.isImplementedBy(sm):
+            self.__sm = sm
+        else:
+            raise ValueError('setServiceManager requires an IServiceService')
+