[Zope3-checkins] CVS: Zope3/src/zope/component - interfaces.py:1.12
utility.py:1.5
Sidnei da Silva
sidnei at x3ng.com.br
Wed Aug 6 18:17:27 EDT 2003
Update of /cvs-repository/Zope3/src/zope/component
In directory cvs.zope.org:/tmp/cvs-serv20548/src/zope/component
Modified Files:
interfaces.py utility.py
Log Message:
Finally got my own mini-geddon.
Changes:
- Spiced up a bit the Utility service getRegisteredMatching to allow querying by interface and name.
- Added getUtilitiesFor(interface) to the utility service, to allow querying for a list of utilities that provide an interface.
- Made the local and global interface services delegate to the utility service when querying for available interfaces. This is done by querying for utilities that provide IInterface. In the future (read: later this week) this will allow us to have persistent interfaces registered as local utilities, a.k.a. TTW Schema.
- Added tests for all of this, and run the test suite twice to make sure :)
=== Zope3/src/zope/component/interfaces.py 1.11 => 1.12 ===
--- Zope3/src/zope/component/interfaces.py:1.11 Tue Aug 5 10:25:13 2003
+++ Zope3/src/zope/component/interfaces.py Wed Aug 6 17:16:51 2003
@@ -80,7 +80,7 @@
called with the requested interface. If the method returns a
non-None value, that value will be returned. Otherwise, if the
object already implements the interface, the object will be
- returned.
+ returned.
"""
@@ -110,7 +110,7 @@
called with the requested interface. If the method returns a
non-None value, that value will be returned. Otherwise, if the
object already implements the interface, the object will be
- returned.
+ returned.
"""
@@ -188,7 +188,7 @@
the view type and the skin name. The nearest one to the
object is found. If a matching view cannot be found, raises
ComponentLookupError.
-
+
If context is not specified, attempts to use wrapping around
object to specify a context.
@@ -357,6 +357,13 @@
"""
+ def getUtilitiesFor(interface):
+ """Look up the registered utilities that provide an interface.
+
+ If none is found, return an empty list
+
+ """
+
class IContextDependent(Interface):
context = Attribute(
@@ -375,7 +382,7 @@
called with the requested interface. If the method returns a
non-None value, that value will be returned. Otherwise, if the
object already implements the interface, the object will be
- returned.
+ returned.
If a matching adapter cannot be found, raises
ComponentLookupError.
@@ -401,7 +408,7 @@
called with the requested interface. If the method returns a
non-None value, that value will be returned. Otherwise, if the
object already implements the interface, the object will be
- returned.
+ returned.
If a matching adapter cannot be found, returns the default.
=== Zope3/src/zope/component/utility.py 1.4 => 1.5 ===
--- Zope3/src/zope/component/utility.py:1.4 Wed Jun 4 05:09:45 2003
+++ Zope3/src/zope/component/utility.py Wed Aug 6 17:16:51 2003
@@ -53,9 +53,9 @@
def getUtility(self, interface, name=''):
"""See IUtilityService interface"""
c = self.queryUtility(interface, None, name)
- if c is None:
- raise ComponentLookupError(interface)
- return c
+ if c is not None:
+ return c
+ raise ComponentLookupError(interface)
def queryUtility(self, interface, default=None, name=''):
"""See IUtilityService interface"""
@@ -65,19 +65,40 @@
return default
c = registry.get(interface)
- if c is None:
- c = default
+ if c is not None:
+ return c
- return c
+ return default
+
+ def getRegisteredMatching(self, interface=None, name=None):
+ L = []
+ for reg_name in self.__utilities:
+ for iface, c in self.__utilities[reg_name].getRegisteredMatching():
+ if not c:
+ continue
+ if interface and not iface is interface:
+ continue
+ if name is not None and reg_name.find(name) < 0:
+ continue
+ L.append((iface, reg_name, c))
+ return L
+
+ def getUtilitiesFor(self, interface=None):
+ utilities = {}
+ for name in self.__utilities:
+ for iface, util in self.__utilities[name].getRegisteredMatching():
+ if not util:
+ continue
+ if interface and not iface is interface:
+ continue
+ utilities[(name, util)] = None
+
+ return utilities.keys()
_clear = __init__
# the global utility service instance (see component.zcml )
utilityService = GlobalUtilityService()
-
-
-
-
_clear = utilityService._clear
# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
More information about the Zope3-Checkins
mailing list