[Zope3-checkins] CVS: Zope3/src/zope/app/apidoc/utilitymodule -
__init__.py:1.6 browser.py:1.4 configure.zcml:1.3 tests.py:1.4
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Apr 17 10:33:24 EDT 2004
Update of /cvs-repository/Zope3/src/zope/app/apidoc/utilitymodule
In directory cvs.zope.org:/tmp/cvs-serv16769/src/zope/app/apidoc/utilitymodule
Modified Files:
__init__.py browser.py configure.zcml tests.py
Log Message:
Get rid of getRegisteredMatching() and make use of registration objects.
=== Zope3/src/zope/app/apidoc/utilitymodule/__init__.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/apidoc/utilitymodule/__init__.py:1.5 Sun Mar 28 18:41:16 2004
+++ Zope3/src/zope/app/apidoc/utilitymodule/__init__.py Sat Apr 17 10:33:21 2004
@@ -32,12 +32,15 @@
implements(ILocation)
- def __init__(self, parent, name, interface, component):
+ def __init__(self, parent, reg):
"""Initialize Utility object."""
self.__parent__ = parent
- self.__name__ = name or NONAME
- self.interface = interface
- self.component = component
+ self.__name__ = reg.name or NONAME
+ self.registration = reg
+ self.interface = reg.provided
+ self.component = reg.component
+ # Handle local and global utility registrations
+ self.doc = hasattr(reg, 'doc') and reg.doc or ''
class UtilityInterface(ReadContainerBase):
@@ -77,25 +80,26 @@
def get(self, key, default=None):
"""See zope.app.container.interfaces.IReadContainer"""
- service = zapi.getService(self, 'Utilities')
+ service = zapi.getService(self, Utilities)
if key == NONAME:
key = ''
- util = service.queryUtility(self.interface, default, key)
- if util != default:
- util = Utility(self, key, self.interface, util)
+ utils = [Utility(self, reg)
+ for reg in service.registrations()
+ if reg.name == key and reg.provided == self.interface]
- return util
+ return utils and utils[0] or default
def items(self):
"""See zope.app.container.interfaces.IReadContainer"""
- service = zapi.getService(self, 'Utilities')
+ service = zapi.getService(self, Utilities)
items = []
while service is not None:
- items += service.getRegisteredMatching(self.interface)
+ items += [(reg.name or NONAME, Utility(self, reg))
+ for reg in service.registrations()
+ if self.interface == reg.provided]
service = queryNextService(service, Utilities)
- items = [(name or NONAME, self.get(name)) for iface, name, c in items]
items.sort()
return items
@@ -151,13 +155,12 @@
service = zapi.getService(self, Utilities)
ifaces = {}
while service is not None:
- matches = service.getRegisteredMatching()
- for iface, name, c in matches:
- path = getPythonPath(iface)
- ifaces[path] = self.get(path)
+ for reg in service.registrations():
+ path = getPythonPath(reg.provided)
+ ifaces[path] = UtilityInterface(self, path, reg.provided)
service = queryNextService(service, Utilities)
items = ifaces.items()
- items.sort()
+ items.sort(lambda x, y: cmp(x[0].split('.')[-1], y[0].split('.')[-1]))
return items
=== Zope3/src/zope/app/apidoc/utilitymodule/browser.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/apidoc/utilitymodule/browser.py:1.3 Mon Mar 29 21:01:17 2004
+++ Zope3/src/zope/app/apidoc/utilitymodule/browser.py Sat Apr 17 10:33:21 2004
@@ -33,12 +33,17 @@
Examples::
+ >>> def makeRegistration(name):
+ ... return type('RegistrationStub', (),
+ ... {'name': name, 'provided': None,
+ ... 'component': None, 'doc': ''})()
+
>>> details = UtilityDetails()
- >>> details.context = Utility(None, 'myname', None, None)
+ >>> details.context = Utility(None, makeRegistration('myname'))
>>> details.getName()
'myname'
- >>> details.context = Utility(None, NONAME, None, None)
+ >>> details.context = Utility(None, makeRegistration(NONAME))
>>> details.getName()
'no name'
"""
@@ -76,6 +81,12 @@
>>> from zope.app.apidoc.utilitymodule import Utility
>>> from zope.app.apidoc.tests import pprint
+ >>> def makeRegistration(name, component):
+ ... return type(
+ ... 'RegistrationStub', (),
+ ... {'name': name, 'provided': None,
+ ... 'component': component, 'doc': ''})()
+
>>> class Foo(object):
... pass
@@ -83,12 +94,12 @@
... pass
>>> details = UtilityDetails()
- >>> details.context = Utility(None, '', None, Foo())
+ >>> details.context = Utility(None, makeRegistration('', Foo()))
>>> pprint(details.getComponent())
[('path', 'zope.app.apidoc.utilitymodule.browser.Foo'),
('url', 'zope/app/apidoc/utilitymodule/browser/Foo')]
- >>> details.context = Utility(None, '', None, Bar())
+ >>> details.context = Utility(None, makeRegistration('', Bar()))
>>> pprint(details.getComponent())
[('path', 'zope.app.apidoc.utilitymodule.browser.Bar'),
('url', 'zope/app/apidoc/utilitymodule/browser/Bar')]
@@ -117,6 +128,11 @@
>>> from zope.app.apidoc.tests import Root
>>> menu = Menu()
+ >>> def makeRegistration(name):
+ ... return type('RegistrationStub', (),
+ ... {'name': name, 'provided': None,
+ ... 'component': None, 'doc': ''})()
+
Get menu title and link for a utility interface
>>> uiface = UtilityInterface(Root(), 'foo.bar.iface', None)
@@ -128,7 +144,7 @@
Get menu title and link for a utility with a name
- >>> util = Utility(uiface, 'FooBar', None, None)
+ >>> util = Utility(uiface, makeRegistration('FooBar'))
>>> node = Node(util)
>>> menu.getMenuTitle(node)
'FooBar'
@@ -137,7 +153,7 @@
Get menu title and link for a utility without a name
- >>> util = Utility(uiface, None, None, None)
+ >>> util = Utility(uiface, makeRegistration(None))
>>> node = Node(util)
>>> menu.getMenuTitle(node)
'no name'
=== Zope3/src/zope/app/apidoc/utilitymodule/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/apidoc/utilitymodule/configure.zcml:1.2 Wed Mar 3 05:38:32 2004
+++ Zope3/src/zope/app/apidoc/utilitymodule/configure.zcml Sat Apr 17 10:33:21 2004
@@ -8,7 +8,7 @@
</class>
<class class=".Utility">
- <allow attributes="interface component" />
+ <allow attributes="registration interface component doc" />
</class>
<class class=".UtilityInterface">
=== Zope3/src/zope/app/apidoc/utilitymodule/tests.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/apidoc/utilitymodule/tests.py:1.3 Sun Mar 28 18:41:35 2004
+++ Zope3/src/zope/app/apidoc/utilitymodule/tests.py Sat Apr 17 10:33:21 2004
@@ -52,11 +52,18 @@
def tearDown():
placelesssetup.tearDown()
+def makeRegistration(name, interface, component):
+ return type('RegistrationStub', (),
+ {'name': name, 'provided': interface,
+ 'component': component, 'doc': ''})()
+
def getDetailsView():
utils = UtilityModule()
utils.__parent__ = Root
utils.__name__ = 'Utility'
- util = Utility(utils, 'Classes', IDocumentationModule, ClassModule())
+ util = Utility(
+ utils,
+ makeRegistration('Classes', IDocumentationModule, ClassModule()))
details = UtilityDetails()
details.context = util
details.request = TestRequest()
More information about the Zope3-Checkins
mailing list