[Zope3-checkins] SVN: Zope3/trunk/ Implemented the
`zope:localService` directive, so that you can use it
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Oct 10 05:27:16 EDT 2004
Log message for revision 27880:
Implemented the `zope:localService` directive, so that you can use it
instead of the `zope:content` directive, which we had to use
before. The new directive automatically makes the service implement
`ISimpleService`. I also changed all the local service declarations to
use this new directive.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/adapter/adapter.py
U Zope3/trunk/src/zope/app/adapter/configure.zcml
U Zope3/trunk/src/zope/app/form/browser/addwizard.py
U Zope3/trunk/src/zope/app/form/browser/editwizard.py
U Zope3/trunk/src/zope/app/meta.zcml
U Zope3/trunk/src/zope/app/pluggableauth/__init__.py
U Zope3/trunk/src/zope/app/pluggableauth/configure.zcml
U Zope3/trunk/src/zope/app/principalannotation/configure.zcml
U Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py
U Zope3/trunk/src/zope/app/renderer/metaconfigure.py
U Zope3/trunk/src/zope/app/security/principalregistry.py
A Zope3/trunk/src/zope/app/site/meta.zcml
A Zope3/trunk/src/zope/app/site/metaconfigure.py
A Zope3/trunk/src/zope/app/site/tests/test_directives.py
U Zope3/trunk/src/zope/app/tests/setup.py
U Zope3/trunk/src/zope/app/utility/configure.zcml
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/doc/CHANGES.txt 2004-10-10 09:27:16 UTC (rev 27880)
@@ -10,10 +10,16 @@
New features
+ - Implemented the `zope:localService` directive, so that you can use it
+ instead of the `zope:content` directive, which we had to use
+ before. The new directive automatically makes the service implement
+ `ISimpleService`. I also changed all the local service declarations to
+ use this new directive.
+
- Implemented the `zope:localUtility` directive, so that you can use it
instead of the `zope:content` directive, which we had to use
before. The new directive automatically makes the utility implement
- `ILocalUtility. I also changed all the local utility declarations to
+ `ILocalUtility`. I also changed all the local utility declarations to
use this new directive.
- The `Attribute` and `Method` class of the `zope.interface` have now a
Modified: Zope3/trunk/src/zope/app/adapter/adapter.py
===================================================================
--- Zope3/trunk/src/zope/app/adapter/adapter.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/adapter/adapter.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -261,7 +261,6 @@
zope.interface.implements(
zope.component.interfaces.IAdapterService,
- zope.app.site.interfaces.ISimpleService,
)
serviceType = zapi.servicenames.Adapters
Modified: Zope3/trunk/src/zope/app/adapter/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/adapter/configure.zcml 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/adapter/configure.zcml 2004-10-10 09:27:16 UTC (rev 27880)
@@ -6,13 +6,13 @@
<!-- Adapter Service -->
-<content class=".adapter.LocalAdapterService">
+<localService class=".adapter.LocalAdapterService">
<factory />
<require
permission="zope.ManageServices"
interface="zope.app.registration.interfaces.IRegistry"
/>
-</content>
+</localService>
<content class=".adapter.AdapterRegistration">
<require
Modified: Zope3/trunk/src/zope/app/form/browser/addwizard.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/addwizard.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/form/browser/addwizard.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -135,5 +135,5 @@
)
)
- s = zapi.getGlobalService(zapi.servicenames.Presentation)
- s.provideView(for_, name, IBrowserRequest, class_, layer)
+ s = zapi.getGlobalService(zapi.servicenames.Adapter)
+ s.register((for_, layer or IBrowserRequest), Interface, name, class_)
Modified: Zope3/trunk/src/zope/app/form/browser/editwizard.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/editwizard.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/form/browser/editwizard.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -230,7 +230,7 @@
NamesChecker(("__call__", "__getitem__", "browserDefault"), permission)
)
- s = zapi.getGlobalService(zapi.servicenames.Presentation)
- s.provideView(for_, name, IBrowserRequest, class_, layer)
+ s = zapi.getGlobalService(zapi.servicenames.Adapter)
+ s.register((for_, layer or IBrowserRequest), Interface, name, class_)
Modified: Zope3/trunk/src/zope/app/meta.zcml
===================================================================
--- Zope3/trunk/src/zope/app/meta.zcml 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/meta.zcml 2004-10-10 09:27:16 UTC (rev 27880)
@@ -12,6 +12,7 @@
<include package="zope.app.schema" file="meta.zcml" />
<include package="zope.app.container.browser" file="meta.zcml" />
<include package="zope.app.utility" file="meta.zcml" />
+<include package="zope.app.site" file="meta.zcml" />
<include package="zope.app.site.browser" file="meta.zcml" />
</configure>
Modified: Zope3/trunk/src/zope/app/pluggableauth/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/pluggableauth/__init__.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/pluggableauth/__init__.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -46,7 +46,6 @@
from zope.app.servicenames import Authentication
from zope.app.security.interfaces import ILoginPassword
-from zope.app.site.interfaces import ISimpleService
from zope.app.component.localservice import queryNextService
from interfaces import IUserSchemafied, IPluggableAuthenticationService
@@ -60,8 +59,7 @@
class PluggableAuthenticationService(OrderedContainer):
- implements(IPluggableAuthenticationService, ISimpleService,
- IOrderedContainer)
+ implements(IPluggableAuthenticationService, IOrderedContainer)
def __init__(self, earmark=None):
self.earmark = earmark
Modified: Zope3/trunk/src/zope/app/pluggableauth/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/pluggableauth/configure.zcml 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/pluggableauth/configure.zcml 2004-10-10 09:27:16 UTC (rev 27880)
@@ -2,7 +2,7 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
- <content class=".PluggableAuthenticationService">
+ <localService class=".PluggableAuthenticationService">
<factory
id="zope.app.services.PluggableAuthenticationService"
/>
@@ -24,7 +24,7 @@
permission="zope.ManageServices"
interface="zope.app.site.interfaces.ISimpleService"
/>
- </content>
+ </localService>
<subscriber
for=".interfaces.IPluggableAuthenticationService
Modified: Zope3/trunk/src/zope/app/principalannotation/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/principalannotation/configure.zcml 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/principalannotation/configure.zcml 2004-10-10 09:27:16 UTC (rev 27880)
@@ -7,7 +7,7 @@
id="PrincipalAnnotation"
interface=".interfaces.IPrincipalAnnotationService" />
- <content class=".PrincipalAnnotationService">
+ <localService class=".PrincipalAnnotationService">
<factory
id="zope.app.PrincipalAnnotationService"
/>
@@ -15,7 +15,7 @@
permission="zope.View"
interface=".interfaces.IPrincipalAnnotationService"
/>
- </content>
+ </localService>
<!-- Principal annotations (user data) service -->
Modified: Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -363,7 +363,7 @@
_context.action(
discriminator = ('defaultViewName', for_, IBrowserRequest, name),
callable = handler,
- args = (zapi.servicenames.Presentation.Adapters, 'register',
+ args = (zapi.servicenames.Adapters, 'register',
(for_, IBrowserRequest), IDefaultViewName, '', name,
_context.info)
)
Modified: Zope3/trunk/src/zope/app/renderer/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/renderer/metaconfigure.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/renderer/metaconfigure.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -45,6 +45,6 @@
_context.action(
discriminator = ('view', sourceType, u'', for_, 'default'),
callable = handler,
- args = (zapi.servicenames.Presentation, 'provideView',
- sourceType, u'', for_, factory, 'default')
+ args = (zapi.servicenames.Adapter, 'register',
+ (sourceType,), for_, u'', factory, 'default')
)
Modified: Zope3/trunk/src/zope/app/security/principalregistry.py
===================================================================
--- Zope3/trunk/src/zope/app/security/principalregistry.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/security/principalregistry.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -22,7 +22,6 @@
from zope.app.security.interfaces import ILoginPassword
from zope.app.security.interfaces import IAuthenticationService, IPrincipal
from zope.app.security.interfaces import IUnauthenticatedPrincipal
-from zope.app.site.interfaces import ISimpleService
from zope.app.container.contained import Contained, contained
from warnings import warn
@@ -31,7 +30,7 @@
class PrincipalRegistry(object):
- implements(IAuthenticationService, ISimpleService)
+ implements(IAuthenticationService)
# Methods implementing IAuthenticationService
Added: Zope3/trunk/src/zope/app/site/meta.zcml
===================================================================
--- Zope3/trunk/src/zope/app/site/meta.zcml 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/site/meta.zcml 2004-10-10 09:27:16 UTC (rev 27880)
@@ -0,0 +1,36 @@
+<configure
+ xmlns:meta="http://namespaces.zope.org/meta">
+
+ <meta:directives namespace="http://namespaces.zope.org/zope">
+
+ <meta:complexDirective
+ name="localService"
+ schema="zope.app.component.metadirectives.IClassDirective"
+ handler=".metaconfigure.LocalServiceDirective"
+ >
+
+ <meta:subdirective
+ name="implements"
+ schema="zope.app.component.metadirectives.IImplementsSubdirective"
+ />
+
+ <meta:subdirective
+ name="require"
+ schema="zope.app.component.metadirectives.IRequireSubdirective"
+ />
+
+ <meta:subdirective
+ name="allow"
+ schema="zope.app.component.metadirectives.IAllowSubdirective"
+ />
+
+ <meta:subdirective
+ name="factory"
+ schema="zope.app.component.metadirectives.IFactorySubdirective"
+ />
+
+ </meta:complexDirective>
+
+ </meta:directives>
+
+</configure>
Added: Zope3/trunk/src/zope/app/site/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/site/metaconfigure.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/site/metaconfigure.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Local Service Directive
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+from zope.interface import classImplements
+from zope.app.component.contentdirective import ContentDirective
+
+from interfaces import ISimpleService
+
+
+class LocalServiceDirective(ContentDirective):
+
+ def __init__(self, _context, class_):
+ if not ISimpleService.implementedBy(class_):
+ classImplements(class_, ISimpleService)
+ super(LocalServiceDirective, self).__init__(_context, class_)
Added: Zope3/trunk/src/zope/app/site/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/site/tests/test_directives.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/site/tests/test_directives.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# Copyright (c) 2003 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.
+#
+##############################################################################
+"""Local Service Directive Tests
+
+$Id: tests.py 27873 2004-10-10 07:24:06Z srichter $
+"""
+import unittest
+from StringIO import StringIO
+
+from zope.configuration.xmlconfig import xmlconfig, XMLConfig
+
+import zope.app.security
+import zope.app.site
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.site.interfaces import ISimpleService
+
+def configfile(s):
+ return StringIO("""<configure
+ xmlns='http://namespaces.zope.org/zope'
+ i18n_domain='zope'>
+ %s
+ </configure>
+ """ % s)
+
+class ServiceStub(object):
+ pass
+
+class TestLocalServiceDirective(PlacelessSetup, unittest.TestCase):
+
+ def setUp(self):
+ super(TestLocalServiceDirective, self).setUp()
+ XMLConfig('meta.zcml', zope.app.component)()
+ XMLConfig('meta.zcml', zope.app.site)()
+
+ def testDirective(self):
+ f = configfile('''
+ <localService
+ class="zope.app.site.tests.test_directives.ServiceStub">
+ </localService>
+ ''')
+ xmlconfig(f)
+ self.assert_(ISimpleService.implementedBy(ServiceStub))
+
+
+def test_suite():
+ return unittest.makeSuite(TestLocalServiceDirective)
+
+if __name__ == '__main__':
+ unittest.main(default='test_suite')
Modified: Zope3/trunk/src/zope/app/tests/setup.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/setup.py 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/tests/setup.py 2004-10-10 09:27:16 UTC (rev 27880)
@@ -150,6 +150,7 @@
return zapi.traverse(folder, "++etc++site")
from zope.app.site.service import ServiceRegistration
+from zope.app.site.interfaces import ISimpleService
from zope.app.registration.interfaces import ActiveStatus
def addService(servicemanager, name, service, suffix=''):
@@ -157,6 +158,10 @@
This utility is useful for tests that need to set up services.
"""
+ # Most local services implement ISimpleService in ZCML; therefore make
+ # sure we got it here as well.
+ zope.interface.directlyProvides(service, ISimpleService)
+
default = zapi.traverse(servicemanager, 'default')
default[name+suffix] = service
path = "%s/default/%s" % (zapi.getPath(servicemanager), name+suffix)
Modified: Zope3/trunk/src/zope/app/utility/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/utility/configure.zcml 2004-10-10 09:26:48 UTC (rev 27879)
+++ Zope3/trunk/src/zope/app/utility/configure.zcml 2004-10-10 09:27:16 UTC (rev 27880)
@@ -1,7 +1,7 @@
<configure
xmlns="http://namespaces.zope.org/zope">
- <content class=".LocalUtilityService">
+ <localService class=".LocalUtilityService">
<factory id="zope.app.services.UtilityService" />
@@ -10,7 +10,7 @@
attributes="queryRegistrations"
interface="zope.app.registration.interfaces.IRegistry" />
- </content>
+ </localService>
<content class=".UtilityRegistration">
More information about the Zope3-Checkins
mailing list