[z3-checkins] r9792 - in
z3/Five/branch/paris-local-sitemanager-branch: . tests
tests/products/FiveTest
dreamcatcher at codespeak.net
dreamcatcher at codespeak.net
Tue Mar 15 15:33:09 MET 2005
Author: dreamcatcher
Date: Tue Mar 15 15:33:08 2005
New Revision: 9792
Modified:
z3/Five/branch/paris-local-sitemanager-branch/configure.zcml
z3/Five/branch/paris-local-sitemanager-branch/fiveconfigure.py
z3/Five/branch/paris-local-sitemanager-branch/fivedirectives.py
z3/Five/branch/paris-local-sitemanager-branch/interfaces.py
z3/Five/branch/paris-local-sitemanager-branch/localsite.py
z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/configure.zcml
z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/localsite.py
z3/Five/branch/paris-local-sitemanager-branch/tests/test_localservice.py
Log:
- Simplify implementation of local services a tad more by moving more framework into Five
- Add a new parameter to the localsitehook directive.
Modified: z3/Five/branch/paris-local-sitemanager-branch/configure.zcml
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/configure.zcml (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/configure.zcml Tue Mar 15 15:33:08 2005
@@ -116,6 +116,12 @@
for="zope.interface.Interface"
/>
+ <adapter
+ for="*"
+ provides="Products.Five.interfaces.IFiveSite"
+ factory=".localsite.FiveSiteAdapter"
+ />
+
<subscriber
factory="zope.app.component.localservice.threadSiteSubscriber"
for="zope.app.publication.interfaces.IBeforeTraverseEvent"
Modified: z3/Five/branch/paris-local-sitemanager-branch/fiveconfigure.py
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/fiveconfigure.py (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/fiveconfigure.py Tue Mar 15 15:33:08 2005
@@ -17,12 +17,16 @@
import glob
import warnings
from zope.interface import classImplements
+from zope.interface.interface import InterfaceClass
from zope.configuration import xmlconfig
+from zope.configuration.exceptions import ConfigurationError
from zope.app.component.interface import provideInterface
+from zope.app.component.metaconfigure import adapter
from zope.app.site.interfaces import IPossibleSite
from viewable import Viewable
from traversable import Traversable
from localsite import FiveSite
+from interfaces import IServiceProvider
from bridge import fromZ2Interface
from browserconfigure import page
@@ -208,7 +212,13 @@
FiveSite.setSiteManager.im_func)
setattr(class_, '__five_possible_site__', True)
-def installFiveSiteHook(_context, class_):
+count = 0
+def next():
+ global count
+ count += 1
+ return count
+
+def installFiveSiteHook(_context, class_, service_provider=None):
_context.action(
discriminator = None,
callable = classFiveSiteHook,
@@ -219,3 +229,14 @@
callable = classImplements,
args=(class_, IPossibleSite)
)
+ if service_provider:
+ if not IServiceProvider.implementedBy(service_provider):
+ raise ConfigurationError('Global object does not implement '
+ 'IServiceProvider: %s' % service_provider)
+ # Generate a marker interface that should be unique, so that
+ # we can register the service provider only for this class.
+ iface = InterfaceClass('I%s' % next())
+ adapter(_context, factory=(service_provider,),
+ provides=IServiceProvider,
+ for_=(iface,))
+ classImplements(class_, iface)
Modified: z3/Five/branch/paris-local-sitemanager-branch/fivedirectives.py
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/fivedirectives.py (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/fivedirectives.py Tue Mar 15 15:33:08 2005
@@ -109,4 +109,7 @@
title=u"Class",
required=True
)
-
+ service_provider = GlobalObject(
+ title=u"Service Provider",
+ required=False
+ )
Modified: z3/Five/branch/paris-local-sitemanager-branch/interfaces.py
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/interfaces.py (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/interfaces.py Tue Mar 15 15:33:08 2005
@@ -31,6 +31,15 @@
"""Five specialization of ISite
"""
+class IServiceProvider(Interface):
+ """Lookup a service for a given context
+ """
+
+ def getService(name):
+ """Given a service name, find the service within the adapted
+ context and return it, or raise a ComponentLookupError.
+ """
+
class IPersistentExtra(Interface):
def bobobase_modification_time():
@@ -232,7 +241,7 @@
"""
Init expected HTTP 1.1 / WebDAV headers which are not
currently set by the base response object automagically.
-
+
Note we set an borg-specific header for ie5 :( Also, we sniff
for a ZServer response object, because we don't want to write
duplicate headers (since ZS writes Date and Connection
@@ -384,18 +393,18 @@
def unrestrictedTraverse(path, default=None, restricted=0):
"""Lookup an object by path,
-
+
path -- The path to the object. May be a sequence of strings or a slash
separated string. If the path begins with an empty path element
(i.e., an empty string or a slash) then the lookup is performed
from the application root. Otherwise, the lookup is relative to
self. Two dots (..) as a path element indicates an upward traversal
to the acquisition parent.
-
+
default -- If provided, this is the value returned if the path cannot
be traversed for any reason (i.e., no object exists at that path or
the object is inaccessible).
-
+
restricted -- If false (default) then no security checking is performed.
If true, then all of the objects along the path are validated with
the security machinery. Usually invoked using restrictedTraverse().
@@ -1235,4 +1244,4 @@
Menu item types are interfaces that define classes of
menu items.
"""
-
+
Modified: z3/Five/branch/paris-local-sitemanager-branch/localsite.py
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/localsite.py (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/localsite.py Tue Mar 15 15:33:08 2005
@@ -12,15 +12,20 @@
from zope.event import notify
from zope.interface import directlyProvides, directlyProvidedBy
+from zope.interface import implements
+from zope.component import getGlobalServices
+from zope.component.interfaces import IServiceService
from zope.component.exceptions import ComponentLookupError
from zope.app.site.interfaces import ISite
from zope.app.site.interfaces import IPossibleSite
from zope.app.publication.zopepublication import BeforeTraverseEvent
+from zope.component.servicenames import Adapters
from interfaces import IFiveSite
from ExtensionClass import Base
from Acquisition import aq_base, aq_inner, aq_parent
from Products.SiteAccess.AccessRule import AccessRule
+from Products.Five.interfaces import IServiceProvider
from ZPublisher.BeforeTraverse import registerBeforeTraverse
from ZPublisher.BeforeTraverse import unregisterBeforeTraverse
@@ -87,3 +92,44 @@
delattr(obj, HOOK_NAME)
directlyProvides(obj, directlyProvidedBy(obj) - ISite)
+
+class LocalService:
+ implements(IServiceService)
+
+ def __init__(self, context):
+ self.context = context
+
+ def getServiceDefinitions(self):
+ """Retrieve all Service Definitions
+
+ Should return a list of tuples (name, interface)
+ """
+ return getGlobalServices().getServiceDefinitions()
+
+ def getInterfaceFor(self, name):
+ """Retrieve the service interface for the given name
+ """
+ return getGlobalServices().getInterfaceFor(name)
+
+ def getService(self, name):
+ """Retrieve a service implementation
+
+ Raises ComponentLookupError if the service can't be found.
+ """
+ if name not in (Adapters,):
+ adapted = IServiceProvider(self.context, None)
+ if adapted is not None:
+ return adapted.getService(name)
+ return getGlobalServices().getService(name)
+
+class FiveSiteAdapter:
+ implements(IFiveSite)
+
+ def __init__(self, context):
+ self.context = context
+
+ def getSiteManager(self):
+ return LocalService(self.context)
+
+ def setSiteManager(self, sm):
+ return
Modified: z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/configure.zcml
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/configure.zcml (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/configure.zcml Tue Mar 15 15:33:08 2005
@@ -420,14 +420,9 @@
<include package="zope.app.form.browser"/>
- <adapter
- for=".interfaces.IDummySite"
- provides="Products.Five.interfaces.IFiveSite"
- factory=".localsite.SimpleFiveSiteAdapter"
- />
-
<five:localsitehook
class=".localsite.DummySite"
+ service_provider=".localsite.ServiceProvider"
/>
</configure>
Modified: z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/localsite.py
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/localsite.py (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/tests/products/FiveTest/localsite.py Tue Mar 15 15:33:08 2005
@@ -1,41 +1,12 @@
from zope.interface import implements
-from zope.component.servicenames import Utilities
from zope.component.exceptions import ComponentLookupError
-from zope.component import getGlobalServices
-from zope.component.interfaces import IServiceService
from zope.component.interfaces import IUtilityService
-from zope.component.exceptions import ComponentLookupError
+from zope.component.servicenames import Utilities
from OFS.Folder import Folder
+from Products.Five.interfaces import IServiceProvider
from Products.FiveTest.interfaces import IDummySite
-class SimpleService:
- implements(IServiceService)
-
- def __init__(self, context):
- self.context = context
-
- def getServiceDefinitions(self):
- """Retrieve all Service Definitions
-
- Should return a list of tuples (name, interface)
- """
- return getGlobalServices().getServiceDefinitions()
-
- def getInterfaceFor(self, name):
- """Retrieve the service interface for the given name
- """
- return getGlobalServices().getInterfaceFor(name)
-
- def getService(self, name):
- """Retrieve a service implementation
-
- Raises ComponentLookupError if the service can't be found.
- """
- if name == Utilities:
- return SimpleLocalUtilityService(self.context)
- return getGlobalServices().getService(name)
-
class SimpleLocalUtilityService:
implements(IUtilityService)
@@ -70,16 +41,16 @@
def getAllUtilitiesRegisteredFor(self, interface):
return ()
-class SimpleFiveSiteAdapter:
+class ServiceProvider:
+ implements(IServiceProvider)
def __init__(self, context):
self.context = context
- def getSiteManager(self):
- return SimpleService(self.context)
-
- def setSiteManager(self, sm):
- return
+ def getService(self, name):
+ if name in (Utilities,):
+ return SimpleLocalUtilityService(self.context)
+ raise ComponentLookupError, name
class DummySite(Folder):
"""A very dummy Site
Modified: z3/Five/branch/paris-local-sitemanager-branch/tests/test_localservice.py
==============================================================================
--- z3/Five/branch/paris-local-sitemanager-branch/tests/test_localservice.py (original)
+++ z3/Five/branch/paris-local-sitemanager-branch/tests/test_localservice.py Tue Mar 15 15:33:08 2005
@@ -312,14 +312,14 @@
clearSite()
def test_getServicesHook(self):
- from Products.FiveTest.localsite import SimpleService
+ from Products.Five.localsite import LocalService
local_sm = getServices(None)
self.failIf(local_sm is serviceManager)
- self.failUnless(isinstance(local_sm, SimpleService))
+ self.failUnless(isinstance(local_sm, LocalService))
local_sm = getServices(self.site)
self.failIf(local_sm is serviceManager)
- self.failUnless(isinstance(local_sm, SimpleService))
+ self.failUnless(isinstance(local_sm, LocalService))
def test_getUtilityService(self):
from Products.FiveTest.localsite import SimpleLocalUtilityService
More information about the z3-checkins
mailing list