[Zope3-checkins] CVS: Zope3/src/zope/app/component -
globalinterfaceservice.py:1.14
Sidnei da Silva
sidnei at x3ng.com.br
Wed Aug 6 18:17:09 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/component
In directory cvs.zope.org:/tmp/cvs-serv20548/src/zope/app/component
Modified Files:
globalinterfaceservice.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/app/component/globalinterfaceservice.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/component/globalinterfaceservice.py:1.13 Thu Jul 3 18:46:06 2003
+++ Zope3/src/zope/app/component/globalinterfaceservice.py Wed Aug 6 17:16:35 2003
@@ -19,8 +19,12 @@
__metaclass__ = type
from zope.component.exceptions import ComponentLookupError
+from zope.component import getService
from zope.app.interfaces.component import IGlobalInterfaceService
+from zope.app.services.servicenames import Utilities
from zope.interface import implements
+from zope.interface.interfaces import IInterface
+from zope.component.utility import utilityService
class InterfaceService:
implements(IGlobalInterfaceService)
@@ -31,16 +35,22 @@
self.__data = data
def getInterface(self, id):
- if id in self.__data:
- return self.__data[id][0]
- else:
+ iface = self.queryInterface(id, None)
+ if iface is None:
raise ComponentLookupError(id)
+ return iface
def queryInterface(self, id, default=None):
if self.__data.has_key(id):
return self.__data[id][0]
else:
- return default
+ # XXX Should use getService(), but that breaks a few
+ # tests that do too basic setup to get the utilities
+ # service started. I'll fix this later
+ utility = utilityService.queryUtility(IInterface, name=id)
+ if utility is not None:
+ return utility
+ return default
def searchInterface(self, search_string=None, base=None):
return [t[1] for t in self.items(search_string, base)]
@@ -60,6 +70,9 @@
continue
yield id, interface
+ for id, interface in self._queryUtilityInterfaces(base, search_string):
+ yield id, interface
+
def _getAllDocs(self,interface):
docs = [str(interface.__name__).lower(),
str(interface.__doc__).lower()]
@@ -68,6 +81,18 @@
docs.append(str(interface.getDescriptionFor(name).__doc__).lower())
return '\n'.join(docs)
+
+ def _queryUtilityInterfaces(self, interface=None, search_string=None):
+ if interface is None:
+ interface = IInterface
+ # XXX Should use getService(), but that breaks a few
+ # tests that do too basic setup to get the utilities
+ # service started. I'll fix this later
+ matching = utilityService.getUtilitiesFor(interface)
+ if search_string is not None:
+ return [match for match in matching
+ if match[0].find(search_string) > -1]
+ return matching
def provideInterface(self, id, interface):
if not id:
More information about the Zope3-Checkins
mailing list