[Zope3-checkins] CVS: Zope3/src/zope/app/services - servicecontainer.py:1.4

Guido van Rossum guido@python.org
Wed, 11 Jun 2003 13:44:35 -0400


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

Modified Files:
	servicecontainer.py 
Log Message:
Some cleanup.  There really is no reason not to use a class variable
initialized to None for the __sm attribute, so we won't hve to do
hasattr() tests.


=== Zope3/src/zope/app/services/servicecontainer.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/services/servicecontainer.py:1.3	Tue Jun  3 10:30:23 2003
+++ Zope3/src/zope/app/services/servicecontainer.py	Wed Jun 11 13:44:34 2003
@@ -11,39 +11,45 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""ServiceManagerContainer implementation.
+
+$Id$
+"""
 
 from zope.component.exceptions import ComponentLookupError
-from zope.app.interfaces.services.service import IServiceManagerContainer  
+from zope.app.interfaces.services.service import IServiceManagerContainer
 from zope.component.interfaces import IServiceService
 from zope.interface import implements
 
 class ServiceManagerContainer:
 
+    """Implement access to the service manager (++etc++site).
+
+    This is a mix-in that implements the IServiceManagerContainer
+    interface; for example, it is used by the Folder implementation.
+    """
+
     implements(IServiceManagerContainer)
 
+    __sm = None
+
     def hasServiceManager(self):
-        '''See interface IReadServiceManagerContainer'''
-        return hasattr(self, '_ServiceManagerContainer__sm')
+        return self.__sm is not None
 
     def getServiceManager(self):
-        '''See interface IReadServiceManagerContainer'''
-
-        try:
+        if self.__sm is not None:
             return self.__sm
-        except AttributeError:
+        else:
             raise ComponentLookupError('no service manager defined')
 
     def queryServiceManager(self, default=None):
-        '''See interface IReadServiceManagerContainer'''
-
-        return getattr(self, '_ServiceManagerContainer__sm', default)
+        if self.__sm is not None:
+            return self.__sm
+        else:
+            return default
 
     def setServiceManager(self, sm):
-        '''See interface IWriteServiceManagerContainer'''
-
         if IServiceService.isImplementedBy(sm):
             self.__sm = sm
         else:
             raise ValueError('setServiceManager requires an IServiceService')
-
-