[Zope3-checkins] SVN: Zope3/trunk/ Implemented the
`zope:localUtility` directive, so that you can use it
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Oct 10 03:24:06 EDT 2004
Log message for revision 27873:
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
use this new directive.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/cache/configure.zcml
U Zope3/trunk/src/zope/app/catalog/catalog.py
U Zope3/trunk/src/zope/app/catalog/configure.zcml
U Zope3/trunk/src/zope/app/i18n/configure.zcml
U Zope3/trunk/src/zope/app/meta.zcml
U Zope3/trunk/src/zope/app/rdb/configure.zcml
U Zope3/trunk/src/zope/app/schema/configure.zcml
U Zope3/trunk/src/zope/app/schema/tests/fields.zcml
U Zope3/trunk/src/zope/app/schemacontent/configure.zcml
U Zope3/trunk/src/zope/app/securitypolicy/configure.zcml
U Zope3/trunk/src/zope/app/uniqueid/browser/configure.zcml
U Zope3/trunk/src/zope/app/uniqueid/configure.zcml
A Zope3/trunk/src/zope/app/utility/meta.zcml
A Zope3/trunk/src/zope/app/utility/metaconfigure.py
U Zope3/trunk/src/zope/app/utility/tests.py
U Zope3/trunk/src/zope/app/workflow/configure.zcml
U Zope3/trunk/src/zope/app/workflow/stateful/configure.zcml
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/doc/CHANGES.txt 2004-10-10 07:24:06 UTC (rev 27873)
@@ -10,6 +10,12 @@
New features
+ - 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
+ use this new directive.
+
- The `Attribute` and `Method` class of the `zope.interface` have now a
new public `interface` attribute that stores the interface they are
defined in.
Modified: Zope3/trunk/src/zope/app/cache/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/cache/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/cache/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -8,7 +8,7 @@
factory="zope.app.cache.annotationcacheable.AnnotationCacheable"
/>
- <content class=".ram.RAMCache">
+ <localUtility class=".ram.RAMCache">
<factory
id="zope.caching.RAMCache"
/>
@@ -21,15 +21,11 @@
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
- <implements
- interface="zope.app.utility.interfaces.ILocalUtility"
- />
-
<require
permission="zope.ManageServices"
interface="zope.app.cache.interfaces.ram.IRAMCache"
/>
- </content>
+ </localUtility>
<vocabulary
name="Cache Names"
Modified: Zope3/trunk/src/zope/app/catalog/catalog.py
===================================================================
--- Zope3/trunk/src/zope/app/catalog/catalog.py 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/catalog/catalog.py 2004-10-10 07:24:06 UTC (rev 27873)
@@ -26,7 +26,6 @@
from zope.app.container.interfaces import IContainer
from zope.app.catalog.interfaces import ICatalog
from zope.app.uniqueid.interfaces import IUniqueIdUtility
-from zope.app.utility.interfaces import ILocalUtility
from zope.index.interfaces import ISimpleQuery
@@ -48,7 +47,7 @@
class Catalog(BTreeContainer):
- implements(ICatalog, IContainer, IAttributeAnnotatable, ILocalUtility)
+ implements(ICatalog, IContainer, IAttributeAnnotatable)
def clear(self):
for index in self.values():
Modified: Zope3/trunk/src/zope/app/catalog/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/catalog/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/catalog/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -3,7 +3,7 @@
xmlns:browser="http://namespaces.zope.org/browser"
>
-<content class=".catalog.Catalog">
+<localUtility class=".catalog.Catalog">
<factory
id="zope.app.catalog"
/>
@@ -19,7 +19,7 @@
interface="zope.app.container.interfaces.IContainer"
permission="zope.ManageServices"
/>
-</content>
+</localUtility>
<content class=".catalog.ResultSet">
<require
Modified: Zope3/trunk/src/zope/app/i18n/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/i18n/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/i18n/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -16,15 +16,12 @@
provides="zope.i18n.interfaces.IUserPreferredCharsets" />
<!-- Register the Translation Domain as a content object -->
-<content
+<localUtility
class=".translationdomain.TranslationDomain">
<factory
id="zope.app.TranslationService"
/>
<implements
- interface="zope.app.utility.interfaces.ILocalUtility"
- />
- <implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
<allow interface="zope.i18n.interfaces.ITranslationDomain"
@@ -38,7 +35,7 @@
<require permission="zope.ManageServices"
interface=".interfaces.ISyncTranslationDomain"
/>
-</content>
+</localUtility>
<content class=".translationdomain.DomainRegistration">
<require
Modified: Zope3/trunk/src/zope/app/meta.zcml
===================================================================
--- Zope3/trunk/src/zope/app/meta.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/meta.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -11,6 +11,7 @@
<include package="zope.app.pagetemplate" file="meta.zcml" />
<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.browser" file="meta.zcml" />
</configure>
Modified: Zope3/trunk/src/zope/app/rdb/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/rdb/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/rdb/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -29,19 +29,16 @@
/>
</content>
- <content class="zope.app.rdb.ZopeDatabaseAdapter">
+ <localUtility class="zope.app.rdb.ZopeDatabaseAdapter">
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
- <implements
- interface="zope.app.utility.interfaces.ILocalUtility" />
-
<require
permission="zope.app.rdb.Use"
interface="zope.app.rdb.interfaces.IZopeDatabaseAdapter" />
- </content>
+ </localUtility>
<content class="zope.app.rdb.ResultSet">
<!-- require zope.View for all list methods -->
Modified: Zope3/trunk/src/zope/app/schema/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/schema/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/schema/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -1,15 +1,12 @@
<configure xmlns="http://namespaces.zope.org/zope">
- <content class=".schema.SchemaUtility">
+ <localUtility class=".schema.SchemaUtility">
<factory
title="Mutable Schema"
description="A Persistent Schema that can be edited through the web"/>
<implements
- interface="zope.app.utility.interfaces.ILocalUtility" />
-
- <implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
<require
@@ -21,7 +18,7 @@
interface=".interfaces.ISchemaUtility"
set_schema=".interfaces.ISchemaUtility" />
- </content>
+ </localUtility>
<content class=".schema.SchemaRegistration">
<require
Modified: Zope3/trunk/src/zope/app/schema/tests/fields.zcml
===================================================================
--- Zope3/trunk/src/zope/app/schema/tests/fields.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/schema/tests/fields.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -4,6 +4,7 @@
<include package="zope.app.schema" file="meta.zcml" />
<include package="zope.app.component" file="meta.zcml" />
+ <include package="zope.app.utility" file="meta.zcml" />
<include package="zope.app.publisher" file="meta.zcml" />
<include package="zope.app.form.browser" file="meta.zcml" />
<include package="zope.app.security" file="meta.zcml"/>
Modified: Zope3/trunk/src/zope/app/schemacontent/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/schemacontent/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/schemacontent/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -5,7 +5,7 @@
<!-- Content Component Definition -->
- <content class=".content.ContentComponentDefinition">
+ <localUtility class=".content.ContentComponentDefinition">
<factory
id="utility.ContentComponentDefinition"
@@ -13,9 +13,6 @@
description="A Persistent Content Component Definition" />
<implements
- interface="zope.app.utility.interfaces.ILocalUtility" />
-
- <implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
<require
@@ -23,7 +20,7 @@
interface=".interfaces.IContentComponentDefinition"
set_schema=".interfaces.IContentComponentDefinition" />
- </content>
+ </localUtility>
<content class=".content.ContentComponentDefinitionRegistration">
<require
Modified: Zope3/trunk/src/zope/app/securitypolicy/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/securitypolicy/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -58,21 +58,18 @@
<allow interface=".interfaces.IRole" />
</content>
- <content class=".role.PersistentRole">
+ <localUtility class=".role.PersistentRole">
<factory
id="zope.security.role.Role"
/>
<implements
- interface="zope.app.utility.interfaces.ILocalUtility"
- />
- <implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
<require
permission="zope.Security"
interface=".interfaces.IRole"
/>
- </content>
+ </localUtility>
<content class=".role.RoleRegistration">
<require
Modified: Zope3/trunk/src/zope/app/uniqueid/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/browser/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/uniqueid/browser/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -2,6 +2,13 @@
xmlns:zope="http://namespaces.zope.org/zope"
xmlns="http://namespaces.zope.org/browser">
+ <tool
+ interface="zope.app.uniqueid.interfaces.IUniqueIdUtility"
+ title="Unique Id Tool"
+ description="Unique Ids Tools are used to provide system-wide unique ids
+ for documents."
+ />
+
<addMenuItem
title="Unique Id Utility"
description="A utility that provides unique ids to objects"
Modified: Zope3/trunk/src/zope/app/uniqueid/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/uniqueid/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -17,7 +17,7 @@
factory="zope.app.uniqueid.connectionOfPersistent"
/>
- <content class=".UniqueIdUtility">
+ <localUtility class=".UniqueIdUtility">
<factory
id="zope.app.uniqueid.UniqueIdUtility"
/>
@@ -26,10 +26,6 @@
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
- <implements
- interface="zope.app.utility.interfaces.ILocalUtility"
- />
-
<require
permission="zope.Public"
interface=".interfaces.IUniqueIdUtilityQuery"
@@ -44,7 +40,7 @@
interface=".interfaces.IUniqueIdUtilityManage"
/>
- </content>
+ </localUtility>
<subscriber
factory=".removeUniqueIdSubscriber"
Added: Zope3/trunk/src/zope/app/utility/meta.zcml
===================================================================
--- Zope3/trunk/src/zope/app/utility/meta.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/utility/meta.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -0,0 +1,36 @@
+<configure
+ xmlns:meta="http://namespaces.zope.org/meta">
+
+ <meta:directives namespace="http://namespaces.zope.org/zope">
+
+ <meta:complexDirective
+ name="localUtility"
+ schema="zope.app.component.metadirectives.IClassDirective"
+ handler=".metaconfigure.LocalUtilityDirective"
+ >
+
+ <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/utility/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/utility/metaconfigure.py 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/utility/metaconfigure.py 2004-10-10 07:24:06 UTC (rev 27873)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# 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 Utility Directive
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+from zope.interface import classImplements
+from zope.app.component.contentdirective import ContentDirective
+
+from interfaces import ILocalUtility
+
+
+class LocalUtilityDirective(ContentDirective):
+
+ def __init__(self, _context, class_):
+ classImplements(class_, ILocalUtility)
+ super(LocalUtilityDirective, self).__init__(_context, class_)
Modified: Zope3/trunk/src/zope/app/utility/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/utility/tests.py 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/utility/tests.py 2004-10-10 07:24:06 UTC (rev 27873)
@@ -16,13 +16,19 @@
$Id$
"""
import unittest
+from StringIO import StringIO
+
+from zope.component import getService
+from zope.component.exceptions import ComponentLookupError
+from zope.configuration.xmlconfig import xmlconfig, XMLConfig
+from zope.interface import Interface, implements
from zope.testing.doctestunit import DocTestSuite
+
+import zope.app.security
+import zope.app.utility
from zope.app.tests import setup
from zope.app.site.tests import placefulsetup
from zope.app import utility, zapi
-from zope.interface import Interface, implements
-from zope.component import getService
-from zope.component.exceptions import ComponentLookupError
from zope.app.traversing.api import traverse
from zope.app.registration.interfaces import IRegistrationStack
from zope.app.registration.interfaces import UnregisteredStatus
@@ -32,7 +38,17 @@
from zope.app.utility.interfaces import ILocalUtility
from zope.app.dependable.interfaces import IDependable
from zope.app.tests import setup
+from zope.app.tests.placelesssetup import PlacelessSetup
+
+def configfile(s):
+ return StringIO("""<configure
+ xmlns='http://namespaces.zope.org/zope'
+ i18n_domain='zope'>
+ %s
+ </configure>
+ """ % s)
+
class IFo(Interface): pass
class IFoo(IFo):
@@ -81,6 +97,11 @@
"See zope.app.dependable.interfaces.IDependable"
return self._dependents
+
+class UtilityStub(object):
+ pass
+
+
class TestUtilityService(placefulsetup.PlacefulSetup, unittest.TestCase):
def setUp(self):
@@ -213,9 +234,27 @@
self.assertEqual(zapi.getUtility(IFoo, 'u2', sm2).name, 'u22')
+class TestLocalUtilityDirective(PlacelessSetup, unittest.TestCase):
+
+ def setUp(self):
+ super(TestLocalUtilityDirective, self).setUp()
+ XMLConfig('meta.zcml', zope.app.component)()
+ XMLConfig('meta.zcml', zope.app.utility)()
+
+ def testDirective(self):
+ f = configfile('''
+ <localUtility
+ class="zope.app.utility.tests.UtilityStub">
+ </localUtility>
+ ''')
+ xmlconfig(f)
+ self.assert_(ILocalUtility.implementedBy(UtilityStub))
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestUtilityService),
+ unittest.makeSuite(TestLocalUtilityDirective),
DocTestSuite('zope.app.utility.vocabulary',
setUp=setup.placelessSetUp,
tearDown=setup.placelessTearDown)
Modified: Zope3/trunk/src/zope/app/workflow/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/workflow/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/workflow/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -27,13 +27,10 @@
This is only a generic placeholder for
future Process Definition implementations -->
- <content class="zope.app.workflow.definition.ProcessDefinition">
+ <localUtility class="zope.app.workflow.definition.ProcessDefinition">
<factory
id="zope.app.workflow.ProcessDefinition"
/>
- <implements
- interface="zope.app.utility.interfaces.ILocalUtility"
- />
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
@@ -41,7 +38,7 @@
permission="zope.ManageServices"
interface="zope.app.workflow.interfaces.IProcessDefinition"
/>
- </content>
+ </localUtility>
<!-- Process Definition Name Vocabualry -->
Modified: Zope3/trunk/src/zope/app/workflow/stateful/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/workflow/stateful/configure.zcml 2004-10-09 19:40:06 UTC (rev 27872)
+++ Zope3/trunk/src/zope/app/workflow/stateful/configure.zcml 2004-10-10 07:24:06 UTC (rev 27873)
@@ -2,14 +2,11 @@
<!-- Stateful ProcessDefintion -->
-<content
+<localUtility
class=".definition.StatefulProcessDefinition">
<factory
id="zope.app.workflow.StatefulProcessDefinition"
/>
- <implements
- interface="zope.app.utility.interfaces.ILocalUtility"
- />
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
@@ -22,7 +19,7 @@
permission="zope.workflow.ManageProcessDefinitions"
interface="zope.app.container.interfaces.IReadContainer"
/>
-</content>
+</localUtility>
<!-- States Container -->
@@ -93,25 +90,20 @@
<!-- ContentWorkflowsManager -->
-<content
+<localUtility
class=".contentworkflow.ContentWorkflowsManager">
<factory
- id="zope.app.workflow.ContentWorkflowsManager"
- />
-
- <implements
- interface="zope.app.utility.interfaces.ILocalUtility"
+ id="zope.app.workflow.ContentWorkflowsManager"
/>
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
-
<require
- permission="zope.ManageServices"
- interface=".interfaces.IContentWorkflowsManager"
- attributes="cpRegistry"
- />
-</content>
+ permission="zope.ManageServices"
+ interface=".interfaces.IContentWorkflowsManager"
+ attributes="cpRegistry"
+ />
+</localUtility>
<class class=".instance.StatefulProcessInstance">
<require
More information about the Zope3-Checkins
mailing list