[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - IGlobalInterfaceService.py:1.2 IInterfaceService.py:1.2 InterfaceService.py:1.2 configure.zcml:1.7 metaConfigure.py:1.3

Jim Fulton jim@zope.com
Tue, 19 Nov 2002 18:15:15 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv10296

Modified Files:
	configure.zcml metaConfigure.py 
Added Files:
	IGlobalInterfaceService.py IInterfaceService.py 
	InterfaceService.py 
Log Message:
Merged changes from Zope3-Bangalore-TTW-Branch (Deb and Raju)

Defined an interface service to keep track of and provide query of
known interfaces.  

Provided a global interface service implementation.



=== Zope3/lib/python/Zope/App/ComponentArchitecture/IGlobalInterfaceService.py 1.1 => 1.2 ===
--- /dev/null	Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/IGlobalInterfaceService.py	Tue Nov 19 18:15:14 2002
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+$Id$
+"""
+
+from IInterfaceService import IInterfaceService
+
+class IGlobalInterfaceService(IInterfaceService):
+    """Global registry for Interface
+    """
+
+    def provideInterface(id, interface):
+        """Register an interface with a given id
+
+        The id is the full dotted name for the interface.
+        """
+
+__doc__ = IGlobalInterfaceService.__doc__ + __doc__


=== Zope3/lib/python/Zope/App/ComponentArchitecture/IInterfaceService.py 1.1 => 1.2 ===
--- /dev/null	Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/IInterfaceService.py	Tue Nov 19 18:15:14 2002
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+$Id$
+"""
+
+from Interface import Interface
+
+class IInterfaceService(Interface):
+    """
+    """
+
+    def getInterface(id):
+        """Return the interface registered for the given id
+
+        A ComponentLookupError is raised if the interface can't be found.
+        """
+
+    def queryInterface(id, default=None):
+        """Return the interface registered for the given id
+
+        The default is returned if the interface can't be found.
+        """
+
+    def searchInterface(search_string):
+        """Return the interfaces that match the search string.
+        """
+
+    def searchInterfaceIds(search_string):
+        """Return the ids of the interfaces that match the search string.
+        """
+
+
+__doc__ = IInterfaceService.__doc__ + __doc__


=== Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceService.py 1.1 => 1.2 ===
--- /dev/null	Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceService.py	Tue Nov 19 18:15:14 2002
@@ -0,0 +1,93 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+$Id$
+"""
+from IGlobalInterfaceService import IGlobalInterfaceService
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+import string
+
+
+class InterfaceService:
+    __implements__ = IGlobalInterfaceService
+
+    def __init__(self, data=None):
+        if data is None:
+            data = {}
+        self.__data = data
+    
+    def getInterface(self, id):
+        if id in self.__data:
+            return self.__data[id][0]
+        else:
+            raise ComponentLookupError
+
+    def queryInterface(self, id, default=None):
+        if self.__data.has_key(id):
+            return self.__data[id][0]
+        else:
+            return default
+
+    def searchInterface(self, search_string):
+        search_result = []
+
+        for id in self.__data.keys():
+            if search_string:
+                if string.find(string.lower(self.__data[id][1]),
+                               string.lower(search_string)
+                               ) >= 0:
+                    search_result.append(self.__data[id][0])
+            else:
+                search_result.append(self.__data[id][0])
+
+        return search_result
+
+    def searchInterfaceIds(self, search_string):
+        search_result = []
+
+        for id in self.__data.keys():
+            if search_string:
+                if string.find(string.lower(self.__data[id][1]),
+                               string.lower(search_string)
+                               ) >= 0:
+                    search_result.append(id)
+            else:
+                search_result.append(id)
+
+        return search_result
+    
+    def _getAllDocs(self,interface):
+        docs = str(interface.__name__)+'\n'+str(interface.__doc__)
+        for name in interface.names():
+            docs = docs + '\n' + str(interface.getDescriptionFor(name).__doc__)
+        return docs
+    
+    def provideInterface(self, id, interface):
+        self.__data[id]=(interface, self._getAllDocs(interface))
+    
+    _clear = __init__ 
+
+
+
+interfaceService = InterfaceService()
+provideInterface = interfaceService.provideInterface
+getInterface = interfaceService.getInterface
+queryInterface = interfaceService.queryInterface
+searchInterface = interfaceService.searchInterface
+
+_clear = interfaceService._clear
+
+from Zope.Testing.CleanUp import addCleanUp
+addCleanUp(_clear)
+del addCleanUp


=== Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml:1.6	Thu Aug  1 14:42:09 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml	Tue Nov 19 18:15:14 2002
@@ -45,6 +45,13 @@
         name="getServiceManager"
         implementation="
            Zope.App.ComponentArchitecture.hooks.getServiceManager_hook" />
+  
+  <serviceType id='Interfaces'
+               interface='Zope.App.ComponentArchitecture.IInterfaceService.' />
+	   
+  <service serviceType='Interfaces'
+           permission='Zope.Public'
+           component='Zope.App.ComponentArchitecture.InterfaceService.interfaceService' />
 
 </zopeConfigure>
 


=== Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py:1.2	Mon Jun 10 19:27:45 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py	Tue Nov 19 18:15:14 2002
@@ -18,11 +18,8 @@
 from Zope.Configuration import namespace
 from Interface import Interface
 from Zope.Configuration.Action import Action
-
-from Zope.Security.Proxy import Proxy
 from Zope.Security.Checker \
      import InterfaceChecker, CheckerPublic, NamesChecker, Checker
-
 from Zope.ComponentArchitecture.GlobalServiceManager \
      import UndefinedService
 
@@ -35,12 +32,14 @@
 # But these services aren't placeful! And we need to get at things that
 # normal service clients don't need!   Jim
 
-
-
 def handler(serviceName, methodName, *args, **kwargs):
     method=getattr(getService(None, serviceName), methodName)
     method(*args, **kwargs)
 
+# We can't use the handler for serviceType, because serviceType needs
+# the interface service.
+from Zope.App.ComponentArchitecture.InterfaceService import provideInterface
+
 def managerHandler(methodName, *args, **kwargs):
     method=getattr(getServiceManager(None), methodName)
     method(*args, **kwargs)
@@ -55,14 +54,32 @@
             permission = CheckerPublic
         checker = InterfaceChecker(provides, permission)
         factory.append(lambda c: Proxy(c, checker))
-
-    return [
-        Action(
+    actions=[
+         Action(
             discriminator = ('adapter', for_, provides),
             callable = handler,
             args = ('Adapters', 'provideAdapter', for_, provides, factory),
-            )
-        ]
+               ),
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    provides.__module__+'.'+provides.__name__, provides)
+              )
+              ]
+    if for_ is not None:
+        actions.append
+        (
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    for_.__module__+'.'+for_.__name__, for_)
+              )
+         )
+        
+    return actions
+
 
 def utility(_context, provides, component=None, factory=None, permission=None):
     provides = _context.resolve(provides)
@@ -87,9 +104,16 @@
             discriminator = ('utility', provides),
             callable = handler,
             args = ('Utilities', 'provideUtility', provides, component),
-            )
+            ),
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    provides.__module__+'.'+provides.__name__, provides)
+              )                
         ]
 
+
 def factory(_context, component, id=None):
     if id is None:
         id = component
@@ -154,13 +178,18 @@
             callable = handler,
             args = ('Resources','provideResource',
                     name, type, factory, layer),
-            )
+            ),
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    type.__module__+'.'+type.__name__, type)
+              )                
         ]
 
 def view(_context, factory, type, name, for_=None, layer='default',
          permission=None, allowed_interface=None, allowed_attributes=None):
 
-
     if ((allowed_attributes or allowed_interface)
         and (not permission)):
         raise ConfigurationError(
@@ -168,7 +197,6 @@
             "allowed_attributes"
             )
 
-
     if for_ is not None: for_ = _context.resolve(for_)
     type = _context.resolve(type)
 
@@ -186,13 +214,32 @@
 
         factory[-1] = proxyView
 
-    return [
+    actions=[
         Action(
             discriminator = ('view', for_, name, type, layer),
             callable = handler,
             args = ('Views','provideView',for_, name, type, factory, layer),
-            )
-        ]
+            ),
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    type.__module__+'.'+type.__name__, type)
+            )        
+            ]
+    if for_ is not None:
+        actions.append
+        (
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    for_.__module__+'.'+for_.__name__,
+                    for_)
+              )
+         )
+
+    return actions
 
 def defaultView(_context, type, name, for_=None, **__kw):
 
@@ -205,20 +252,45 @@
         for_ = _context.resolve(for_)
     type = _context.resolve(type)
 
-    actions += [Action(
+    actions += [
+        Action(
         discriminator = ('defaultViewName', for_, type, name),
         callable = handler,
         args = ('Views','setDefaultViewName', for_, type, name),
-        )]
+        ),
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    type.__module__+'.'+type.__name__, type)
+            )                
+               ]
+    if for_ is not None:
+        actions.append
+        (
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    for_.__module__+'.'+for_.__name__, for_)
+              )
+         )
 
     return actions
 
 def serviceType(_context, id, interface):
+    interface = _context.resolve(interface)
     return [
         Action(
             discriminator = ('serviceType', id),        
             callable = managerHandler,
-            args = ('defineService', id, _context.resolve(interface)),
+            args = ('defineService', id, interface),
+            ),
+        Action(
+            discriminator = None,
+            callable = provideInterface,
+            args = (interface.__module__+'.'+interface.__name__,
+                    interface)
             )
         ]
 
@@ -272,11 +344,17 @@
         raise TypeError("Commas are not allowed in layer names.")
 
     layers = layers.strip().split()
-    return [
+    actions = [
         Action(
             discriminator = ('skin', name, type),
             callable = handler,
             args = ('Skins','defineSkin',name, type, layers)
-            )
-        ]
-
+              ),
+        Action(
+            discriminator = None,
+            callable = handler,
+            args = ('Interfaces', 'provideInterface',
+                    type.__module__+'.'+type.__name__, type)
+              )             
+             ]
+    return actions