[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager - IServiceManager.py:1.9 ServiceManager.py:1.16

Steve Alexander steve@cat-box.net
Wed, 18 Dec 2002 15:23:37 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager
In directory cvs.zope.org:/tmp/cvs-serv12654/lib/python/Zope/App/OFS/Services/ServiceManager

Modified Files:
	IServiceManager.py ServiceManager.py 
Log Message:
SteveA and Marius G.

We refactored the NamedComponentConfiguration and ComponentConfiguration.
Now, we have NamedConfiguration and NamedComponentConfiguration.

NamedConfigurable is now split into two parts, as appropriate to that
refactoring.

Cleaned up various extraneous imports, and changed various 
self --> wrapped_self. (Interestingly, this act revealed one ContextMethod
that did not in fact need to be a ContextMethod.)
 


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceManager.py 1.8 => 1.9 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceManager.py:1.8	Thu Dec 12 10:28:17 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceManager.py	Wed Dec 18 15:23:05 2002
@@ -16,11 +16,13 @@
 $Id$
 """
 from Zope.ComponentArchitecture.IServiceService import IServiceService
-from Zope.App.OFS.Services.ConfigurationInterfaces import INameConfigurable
+from Zope.App.OFS.Services.ConfigurationInterfaces \
+        import INameComponentConfigurable
 from IComponentManager import IComponentManager
 from Interface.Attribute import Attribute
 
-class IServiceManager(IServiceService, IComponentManager, INameConfigurable):
+class IServiceManager(IServiceService, IComponentManager,
+                      INameComponentConfigurable):
     """Service Managers act as containers for Services.
 
     If a Service Manager is asked for a service, it checks for those it
@@ -30,4 +32,4 @@
     services.
     """
 
-    Packages = Attribute("""Package container""")
+    Packages = Attribute("Package container")


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py 1.15 => 1.16 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py:1.15	Thu Dec 12 10:28:17 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py	Wed Dec 18 15:23:05 2002
@@ -22,29 +22,19 @@
 
 import sys
 
-from Zope.Exceptions import NotFoundError, ZopeError
-
-from Zope.App.ComponentArchitecture.IServiceManagerContainer \
-     import IServiceManagerContainer
-from Zope.ComponentArchitecture import getService, queryAdapter
 from Zope.App.ComponentArchitecture.NextService \
      import getNextServiceManager, getNextService
-from Zope.ComponentArchitecture.GlobalServiceManager import UndefinedService
-from Zope.ComponentArchitecture.GlobalServiceManager import InvalidService
 from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
 
 from Zope.App.OFS.Container.IContainer import ISimpleReadContainer
-from Zope.App.OFS.Content.Folder.Folder import Folder
 from Zope.ContextWrapper import ContextMethod
 from Zope.Proxy.ContextWrapper import ContextWrapper
-from Zope.App.OFS.Container.BTreeContainer import BTreeContainer
 from Zope.Proxy.ProxyIntrospection import removeAllProxies
 
 from Packages import Packages
 from IServiceManager import IServiceManager
 
-from Zope.App.OFS.Services.Configuration import ConfigurationRegistry
-from Zope.App.OFS.Services.Configuration import NameConfigurable
+from Zope.App.OFS.Services.Configuration import NameComponentConfigurable
 
 from Persistence.Module import PersistentModuleRegistry
 from Persistence.Module import PersistentModule
@@ -54,43 +44,40 @@
 ModuleType = ModuleType, PersistentModule
 
 
-class ServiceManager(PersistentModuleRegistry, NameConfigurable):
+class ServiceManager(PersistentModuleRegistry, NameComponentConfigurable):
 
     __implements__ = (IServiceManager, ISimpleReadContainer,
                       PersistentModuleRegistry.__implements__,
-                      NameConfigurable.__implements__,
+                      NameComponentConfigurable.__implements__,
                       INameResolver)
 
     def __init__(self):
         super(ServiceManager, self).__init__()
-        NameConfigurable.__init__(self)
+        NameComponentConfigurable.__init__(self)
         self.Packages = Packages()
 
-
-    def getServiceDefinitions(self):
+    def getServiceDefinitions(wrapped_self):
         "See Zope.ComponentArchitecture.IServiceService.IServiceService"
 
         # Get the services defined here and above us, if any (as held
         # in a ServiceInterfaceService, presumably)
-        sm = getNextServiceManager(self)
+        sm = getNextServiceManager(wrapped_self)
         if sm is not None:
             serviceDefs = sm.getServiceDefinitions()
         else: serviceDefs = {}
 
         return serviceDefs
-
     getServiceDefinitions = ContextMethod(getServiceDefinitions)
 
-    def queryService(self, name, default=None):
+    def queryService(wrapped_self, name, default=None):
         "See Zope.ComponentArchitecture.IServiceService.IServiceService"
         try:
-            return self.getService(name)
+            return wrapped_self.getService(name)
         except ComponentLookupError:
             return default
-
     queryService = ContextMethod(queryService)
 
-    def getService(self, name):
+    def getService(wrapped_self, name):
         "See Zope.ComponentArchitecture.IServiceService.IServiceService"
 
         # This is rather tricky. Normally, getting a service requires
@@ -100,42 +87,40 @@
         # services, so we'll
 
         if name == 'Services':
-            return self # We are the service service
+            return wrapped_self # We are the service service
 
-        if not getattr(self, '_v_calling', 0):
+        if not getattr(wrapped_self, '_v_calling', 0):
 
-            self._v_calling = 1
+            wrapped_self._v_calling = 1
             try:
-                service = self.queryActiveComponent(name)
+                service = wrapped_self.queryActiveComponent(name)
                 if service is not None:
                     return service
 
             finally:
-                self._v_calling = 0
-
-        return getNextService(self, name)
+                wrapped_self._v_calling = 0
 
+        return getNextService(wrapped_self, name)
     getService = ContextMethod(getService)
 
 
-    def getInterfaceFor(self, service_type):
+    def getInterfaceFor(wrapped_self, service_type):
         "See Zope.ComponentArchitecture.IServiceService.IServiceService"
-        for type, interface in self.getServiceDefinitions():
+        for type, interface in wrapped_self.getServiceDefinitions():
             if type == service_type:
                 return interface
 
         raise NameError(service_type)
-
     getInterfaceFor = ContextMethod(getInterfaceFor)
 
     ############################################################
     # Implementation methods for interface
     # Zope.App.OFS.Services.ServiceManager.IComponentManager.
 
-    def queryComponent(self, type=None, filter=None, all=0):
-        Packages = ContextWrapper(self.Packages, self, name='Packages')
+    def queryComponent(wrapped_self, type=None, filter=None, all=0):
+        Packages = ContextWrapper(wrapped_self.Packages, wrapped_self,
+                                  name='Packages')
         return Packages.queryComponent(type, filter, all)
-
     queryComponent = ContextMethod(queryComponent)
 
     #
@@ -154,18 +139,17 @@
 
         return result
 
-    def get(self, key, default=None):
+    def get(wrapped_self, key, default=None):
         "See Interface.Common.Mapping.IReadMapping"
 
         if key == 'Packages':
-            return self.Packages
+            return wrapped_self.Packages
 
-        directives = self.queryConfigurations(key)
+        directives = wrapped_self.queryConfigurations(key)
         if directives and directives[0] is not None:
-            return self.queryService(key, default)
+            return wrapped_self.queryService(key, default)
 
         return default
-
     get = ContextMethod(get)
 
     def __contains__(self, key):
@@ -173,13 +157,14 @@
 
         return self.get(key) is not None
 
-    def findModule(self, name):
+    def findModule(wrapped_self, name):
         # override to pass call up to next service manager
-        mod = super(ServiceManager, removeAllProxies(self)).findModule(name)
+        mod = super(ServiceManager,
+                    removeAllProxies(wrapped_self)).findModule(name)
         if mod is not None:
             return mod
 
-        sm = getNextServiceManager(self)
+        sm = getNextServiceManager(wrapped_self)
         try:
             findModule = sm.findModule
         except AttributeError:
@@ -188,22 +173,20 @@
             # direct way to ask if sm is the global service manager.
             return None
         return findModule(name)
-
     findModule = ContextMethod(findModule)
 
-    def __import(self, module_name):
+    def __import(wrapped_self, module_name):
 
-        mod = self.findModule(module_name)
+        mod = wrapped_self.findModule(module_name)
         if mod is None:
             mod = sys.modules.get(module_name)
             if mod is None:
                 raise ImportError(module_name)
 
         return mod
-
     __import = ContextMethod(__import)
 
-    def resolve(self, name):
+    def resolve(wrapped_self, name):
 
         name = name.strip()
 
@@ -218,20 +201,19 @@
         mod='.'.join(names[:-1])
 
         if not mod:
-            return self.__import(name)
+            return wrapped_self.__import(name)
 
         while 1:
-            m = self.__import(mod)
+            m = wrapped_self.__import(mod)
             try:
                 a=getattr(m, last)
             except AttributeError:
                 if not repeat:
-                    return self.__import(name)
+                    return wrapped_self.__import(name)
 
             else:
                 if not repeat or (not isinstance(a, ModuleType)):
                     return a
             mod += '.' + last
-
     resolve = ContextMethod(resolve)