[Zope3-checkins] CVS: Zope3/src/zope/app/services - interface.py:1.6

Jeremy Hylton jeremy@zope.com
Sun, 22 Jun 2003 15:00:00 -0400


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv7030/src/zope/app/services

Modified Files:
	interface.py 
Log Message:
Create placeholder for LocalInterfaceService

The code just delegates to the global service for now.


=== Zope3/src/zope/app/services/interface.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/services/interface.py:1.5	Sat May  3 12:32:59 2003
+++ Zope3/src/zope/app/services/interface.py	Sun Jun 22 14:59:59 2003
@@ -11,12 +11,24 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Interfaces for persistent modules."""
+"""Code about services and interfaces.
+
+This module contains code for interfaces in persistent modules, and
+for the local interface service.
+"""
 
 from persistence import Persistent
 from zodb.code.patch import registerWrapper, Wrapper
 from zope.interface.interface import InterfaceClass
 
+from zope.app.component.nextservice import getNextService
+from zope.app.interfaces.services.service import ISimpleService
+from zope.app.interfaces.component import IInterfaceService
+from zope.app import zapi
+from zope.app.services.servicenames import Interfaces
+from zope.component import ComponentLookupError
+from zope.interface import implements
+
 class PersistentInterfaceClass(Persistent, InterfaceClass):
     pass
 
@@ -30,8 +42,39 @@
     def unwrap(self):
         return PersistentInterfaceClass(self._obj.__name__)
 
-def register():
+def register(): # XXX has been refactored on a branch
     registerWrapper(InterfaceClass, PersistentInterfaceWrapper,
                     lambda iface: (),
                     lambda iface: iface.__dict__,
                     )
+
+class LocalInterfaceService(object):
+    """I need a doc string."""
+    
+    implements(IInterfaceService,
+               ISimpleService)
+
+    # All the methods defined here are context methods
+    zapi.ContextAwareDescriptors()
+    
+    def getInterface(self, id):
+        # Return the interface registered for the given id
+        i = self.queryInterface(id)
+        if i is None:
+            raise ComponentLookupError(id)
+        return i
+
+    def queryInterface(self, id, default=None):
+        # Return the interface registered for the given id
+        next = getNextService(self, Interfaces)
+        return next.queryInterface(id, default)
+
+    def searchInterface(self, search_string="", base=None):
+        # Return the interfaces that match the search criteria
+        next = getNextService(self, Interfaces)
+        return next.searchInterface(search_string, base)
+
+    def searchInterfaceIds(self, search_string="", base=None):
+        # Return the ids of the interfaces that match the search criteria.
+        next = getNextService(self, Interfaces)
+        return next.searchInterfaceIds(search_string, base)