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

Jim Fulton jim at zope.com
Tue Sep 2 17:47:21 EDT 2003


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

Modified Files:
	servicecontainer.py 
Log Message:
Added ISite, which is a marker interface indicating that an object is
a site.

When an object is made into a site, ISite is declared for it.

Change to test whether something is a site by testing whether 
it (declares it) implements ISite.


=== Zope3/src/zope/app/services/servicecontainer.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/services/servicecontainer.py:1.4	Wed Jun 11 13:44:34 2003
+++ Zope3/src/zope/app/services/servicecontainer.py	Tue Sep  2 16:46:50 2003
@@ -17,39 +17,73 @@
 """
 
 from zope.component.exceptions import ComponentLookupError
-from zope.app.interfaces.services.service import IServiceManagerContainer
+from zope.app.interfaces.services.service import IPossibleSite, ISite
 from zope.component.interfaces import IServiceService
-from zope.interface import implements
+from zope.app import zapi
+import zope.interface
 
 class ServiceManagerContainer:
 
     """Implement access to the service manager (++etc++site).
 
-    This is a mix-in that implements the IServiceManagerContainer
+    This is a mix-in that implements the IPossibleSite
     interface; for example, it is used by the Folder implementation.
     """
 
-    implements(IServiceManagerContainer)
+    zope.interface.implements(IPossibleSite)
 
     __sm = None
 
-    def hasServiceManager(self):
-        return self.__sm is not None
-
-    def getServiceManager(self):
+    def getSiteManager(self):
         if self.__sm is not None:
             return self.__sm
         else:
-            raise ComponentLookupError('no service manager defined')
+            raise ComponentLookupError('no site manager defined')
 
-    def queryServiceManager(self, default=None):
-        if self.__sm is not None:
-            return self.__sm
-        else:
-            return default
+    def setSiteManager(self, sm):
+        if ISite.isImplementedBy(self):
+            raise TypeError("Already a site")
 
-    def setServiceManager(self, sm):
         if IServiceService.isImplementedBy(sm):
             self.__sm = sm
         else:
-            raise ValueError('setServiceManager requires an IServiceService')
+            raise ValueError('setSiteManager requires an IServiceService')
+
+        zope.interface.directlyProvides(self, ISite)
+
+
+
+
+from zope.app.event.function import Subscriber
+from transaction import get_transaction
+from zope.component.exceptions import ComponentLookupError
+
+def fixup(event):
+        database = event.database
+        connection = database.open()
+        app = connection.root().get('Application')
+        if app is None:
+            # No old data
+            return
+        fixfolder(app)
+        get_transaction().commit()
+        connection.close()
+
+fixup = Subscriber(fixup)
+
+def fixfolder(folder):
+    if ISite.isImplementedBy(folder):
+        # No need to do more, the conversion already happened!
+        return
+    try:
+        sm = folder.getSiteManager()
+    except ComponentLookupError:
+        pass # nothing to do
+    else:
+        zope.interface.directlyProvides(folder, ISite)
+
+    for item in folder.values():
+        if IPossibleSite.isImplementedBy(item):
+            fixfolder(item)
+                
+                




More information about the Zope3-Checkins mailing list