[z3-checkins] r18721 - in z3/Five/branch/regebro-sitemanager: doc site

regebro at codespeak.net regebro at codespeak.net
Mon Oct 17 17:33:11 CEST 2005


Author: regebro
Date: Mon Oct 17 17:33:06 2005
New Revision: 18721

Added:
   z3/Five/branch/regebro-sitemanager/site/interfaces.py   (contents, props changed)
Modified:
   z3/Five/branch/regebro-sitemanager/doc/local_sites.txt
   z3/Five/branch/regebro-sitemanager/site/localsite.py
   z3/Five/branch/regebro-sitemanager/site/metaconfigure.py
Log:
Now using a new interface for the extended LocalUtilityManager interface.


Modified: z3/Five/branch/regebro-sitemanager/doc/local_sites.txt
==============================================================================
--- z3/Five/branch/regebro-sitemanager/doc/local_sites.txt	(original)
+++ z3/Five/branch/regebro-sitemanager/doc/local_sites.txt	Mon Oct 17 17:33:06 2005
@@ -106,7 +106,7 @@
    implementation as well.
    
    LocalSite will get the local utility service by adapting the context (that 
-   is your site object) to ILocalUtilityService. We recommend that you keep 
+   is your site object) to IFiveUtilityService. We recommend that you keep 
    that functionality if you make your own site manager.
    
 4. Lastly, you will need a local utility service.
@@ -115,9 +115,9 @@
    It simply keeps the utilities as objects in a folder called 'utilities' in
    your site root.
    
-   If you want to create your own, it needs to implement ILocalUtilityService,
+   If you want to create your own, it needs to implement IFiveUtilityService,
    and it needs to be registered as an adapter between your class and 
-   ILocalUtilityService. Of course, five:localsite will register this for you:
+   IFiveUtilityService. Of course, five:localsite will register this for you:
    
      <five:localsite class=".module.BaseSiteClass"
                      utility_service=".module.MyUtilityService" />
@@ -125,8 +125,11 @@
    or, if your class already implements IPossibleSite, you can also use:
    
      <adapter for=".interfaces.IBaseSiteClass"
-              provides="zope.app.utility.interfaces.ILocalUtilityService"
+              provides="zope.app.utility.interfaces.IFiveUtilityService"
               fatory=".utilityservice.MyUtilityService" />
    
+   IFiveUtilityService is an extension of ILocalUtilityService, with a 
+   registerUtility() method for simple registration. We hope that Zope 3
+   will implement something similar in the future.
 
-Thats it, more or less.
\ No newline at end of file
+That's it, I think.
\ No newline at end of file

Added: z3/Five/branch/regebro-sitemanager/site/interfaces.py
==============================================================================
--- (empty file)
+++ z3/Five/branch/regebro-sitemanager/site/interfaces.py	Mon Oct 17 17:33:06 2005
@@ -0,0 +1,34 @@
+##############################################################################
+#
+# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Five interfaces
+
+$Id: interfaces.py 18584 2005-10-14 17:13:27Z regebro $
+"""
+from zope.app.utility.interfaces import ILocalUtilityService
+
+class IFiveUtilityService(ILocalUtilityService):
+    """Extends ILocalUtilityService with a method to register utilities"""
+    
+    def registerUtility(self, interface, utility, name=''):
+        """Registers a utility in the local context"""
+        # I think you are *really* supposed to:
+        # 1. Check if there is a "registrations" object for utilities.
+        # 2. If not create one.
+        # 3. Get it.
+        # 4. Create a registration object for the utility.
+        # 5. Register the registration object in the registrations.
+        # But that is quite complex, and Jim sais he wants to change that
+        # anyway, and in any case the way you would normally do this in Zope3
+        # and Five would probably differ anyway, so, here is this new 
+        # Five-only, easy to use method!

Modified: z3/Five/branch/regebro-sitemanager/site/localsite.py
==============================================================================
--- z3/Five/branch/regebro-sitemanager/site/localsite.py	(original)
+++ z3/Five/branch/regebro-sitemanager/site/localsite.py	Mon Oct 17 17:33:06 2005
@@ -15,7 +15,6 @@
 from zope.interface import implements
 from zope.component import getGlobalServices
 from zope.component.interfaces import IServiceService, IUtilityService
-from zope.app.utility.interfaces import ILocalUtilityService
 from zope.component.exceptions import ComponentLookupError
 from zope.component.servicenames import Utilities
 from zope.app.site.interfaces import ISite
@@ -29,6 +28,8 @@
 from ZPublisher.BeforeTraverse import registerBeforeTraverse
 from ZPublisher.BeforeTraverse import unregisterBeforeTraverse
 
+from interfaces import IFiveUtilityService
+
 def serviceServiceAdapter(ob):
     """An adapter * -> IServiceService.
 
@@ -103,11 +104,11 @@
         Raises ComponentLookupError if the service can't be found.
         """
         if name in (Utilities,):
-            return ILocalUtilityService(self.context)
+            return IFiveUtilityService(self.context)
         return getGlobalServices().getService(name)
 
 class SimpleLocalUtilityService:
-    implements(ILocalUtilityService)
+    implements(IFiveUtilityService)
 
     def __init__(self, context):
         self.context = context

Modified: z3/Five/branch/regebro-sitemanager/site/metaconfigure.py
==============================================================================
--- z3/Five/branch/regebro-sitemanager/site/metaconfigure.py	(original)
+++ z3/Five/branch/regebro-sitemanager/site/metaconfigure.py	Mon Oct 17 17:33:06 2005
@@ -22,9 +22,9 @@
 from zope.interface.interface import InterfaceClass
 from zope.configuration.exceptions import ConfigurationError
 from zope.app.component.metaconfigure import adapter
-from zope.app.utility.interfaces import ILocalUtilityService
 from zope.app.site.interfaces import IPossibleSite, ISite
 
+from interfaces import IFiveUtilityService
 from localsite import FiveSite, SimpleLocalUtilityService
 
 def classSiteHook(class_, site_class):
@@ -64,15 +64,15 @@
     if utility_service is None:
         utility_service = SimpleLocalUtilityService
     else:
-        if not ILocalUtilityService.implementedBy(utility_service):
+        if not IFiveUtilityService.implementedBy(utility_service):
             raise ConfigurationError('utility_service does not implement '
-                                     'ILocalUtilityService: %s' % utility_service)
+                                     'IFiveUtilityService: %s' % utility_service)
         
     # Generate a marker interface that should be unique, so that
     # we can register the utility service only for this class.
     iface = InterfaceClass('IFiveSite%s' % next())
     adapter(_context, factory=(utility_service,),
-            provides=ILocalUtilityService,
+            provides=IFiveUtilityService,
             for_=(iface,))
     _context.action(
         discriminator = (class_, 'UtilityMarker'),


More information about the z3-checkins mailing list