[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - IGlobalInterfaceService.py:1.2.18.1 IInterfaceService.py:1.3.8.1 InterfaceField.py:1.3.8.1 InterfaceService.py:1.2.18.1 configure.zcml:1.8.8.1 meta.zcml:1.1.32.1 metaConfigure.py:1.4.14.1
Jim Fulton
jim@zope.com
Thu, 12 Dec 2002 10:12:31 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv20910
Modified Files:
Tag: AdapterAndView-branch
IGlobalInterfaceService.py IInterfaceService.py
InterfaceField.py InterfaceService.py configure.zcml meta.zcml
metaConfigure.py
Log Message:
- Added an interface directive for registering interfaces directly
- Added a "type" field to interface fields to limit interfaces to
those that extend a type.
- Changed the provideInterface in the global InterfaceService to
accept a false id, in which case it computes the id from the
interface module and name.
- Updated the widget to reflect the changes.
=== Zope3/lib/python/Zope/App/ComponentArchitecture/IGlobalInterfaceService.py 1.2 => 1.2.18.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/IGlobalInterfaceService.py:1.2 Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/IGlobalInterfaceService.py Thu Dec 12 10:12:00 2002
@@ -25,6 +25,10 @@
"""Register an interface with a given id
The id is the full dotted name for the interface.
+
+ If the id is false, the id will be computed from the interface
+ module and name.
+
"""
__doc__ = IGlobalInterfaceService.__doc__ + __doc__
=== Zope3/lib/python/Zope/App/ComponentArchitecture/IInterfaceService.py 1.3 => 1.3.8.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/IInterfaceService.py:1.3 Wed Dec 4 04:54:04 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/IInterfaceService.py Thu Dec 12 10:12:00 2002
@@ -33,12 +33,22 @@
The default is returned if the interface can't be found.
"""
- def searchInterface(search_string):
- """Return the interfaces that match the search string.
+ def searchInterface(search_string='', base=None):
+ """Return the interfaces that match the search criteria
+
+ If a search string is given, only interfaces that contain the
+ string in their documentation will be returned.
+
+ If base is given, only interfaces that equal or extend base
+ will be returned.
+
"""
- def searchInterfaceIds(search_string):
- """Return the ids of the interfaces that match the search string.
+ def searchInterfaceIds(search_string='', base=None):
+ """Return the ids of the interfaces that match the search criteria.
+
+ See searchInterface
+
"""
=== Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceField.py 1.3 => 1.3.8.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceField.py:1.3 Thu Dec 5 08:27:02 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceField.py Thu Dec 12 10:12:00 2002
@@ -17,7 +17,7 @@
"""
from Zope.Schema.IField import IValueSet
-from Zope.Schema import ValueSet
+from Zope.Schema import ValueSet, Field
from Interface import Interface
from Interface.IInterface import IInterface
from Zope.Schema.Exceptions import ValidationError
@@ -25,11 +25,22 @@
class IInterfaceField(IValueSet):
u"""Fields with Interfaces as values
"""
+
+ type = Field(title=u"Base type",
+ description=u"All values must extend (or be) this type",
+ default=Interface,
+ )
class InterfaceField(ValueSet):
__doc__ = IInterfaceField.__doc__
__implements__ = IInterfaceField
+ type = Interface
+
+ def __init__(self, type=Interface, *args, **kw):
+ super(InterfaceField, self).__init__(*args, **kw)
+ self.validate(type)
+ self.type = type
def _validate(self, value):
super(InterfaceField, self)._validate(value)
@@ -37,4 +48,7 @@
if not IInterface.isImplementedBy(value):
raise ValidationError("Not an interface", value)
+ if not value.extends(self.type, 0):
+ raise ValidationError("Does not extend", value, self.type)
+
=== Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceService.py 1.2 => 1.2.18.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceService.py:1.2 Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/InterfaceService.py Thu Dec 12 10:12:00 2002
@@ -16,8 +16,6 @@
"""
from IGlobalInterfaceService import IGlobalInterfaceService
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
-import string
-
class InterfaceService:
__implements__ = IGlobalInterfaceService
@@ -39,41 +37,44 @@
else:
return default
- def searchInterface(self, search_string):
- search_result = []
+ def searchInterfaceIds(self, search_string='', base=None):
+ result = []
+
+ data = self.__data
+ search_string = search_string.lower()
- for id in self.__data.keys():
+ for id in data:
+ interface, doc = data[id]
+
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])
+ if doc.find(search_string) < 0:
+ continue
- return search_result
+ if base is not None and not interface.extends(base, 0):
+ continue
- def searchInterfaceIds(self, search_string):
- search_result = []
+ result.append(id)
- 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 result
- return search_result
+ def searchInterface(self, search_string='', base=None):
+ data = self.__data
+ return [data[id][0]
+ for id in self.searchInterfaceIds(search_string, base)]
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
+ docs = [str(interface.__name__).lower(),
+ str(interface.__doc__).lower()]
+
+ for name in interface:
+ docs.append(str(interface.getDescriptionFor(name).__doc__).lower())
+
+ return '\n'.join(docs)
def provideInterface(self, id, interface):
+ if not id:
+ id = "%s.%s" % (interface.__module__, interface.__name__)
+
self.__data[id]=(interface, self._getAllDocs(interface))
_clear = __init__
=== Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml 1.8 => 1.8.8.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml:1.8 Wed Dec 4 04:54:04 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml Thu Dec 12 10:12:00 2002
@@ -55,6 +55,8 @@
component=
'Zope.App.ComponentArchitecture.InterfaceService.interfaceService' />
+ <interface interface="Interface.Interface" />
+
<include package="Zope.App.ComponentArchitecture.Browser" />
</zopeConfigure>
=== Zope3/lib/python/Zope/App/ComponentArchitecture/meta.zcml 1.1 => 1.1.32.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/meta.zcml:1.1 Mon Jun 17 14:31:24 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/meta.zcml Thu Dec 12 10:12:00 2002
@@ -2,6 +2,9 @@
<directives namespace="http://namespaces.zope.org/zope">
+ <directive name="interface" attributes="interface"
+ handler="Zope.App.ComponentArchitecture.metaConfigure.interface" />
+
<directive name="adapter" attributes="factory provides for permission"
handler="Zope.App.ComponentArchitecture.metaConfigure.adapter" />
=== Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py 1.4 => 1.4.14.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py:1.4 Mon Nov 25 10:23:20 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py Thu Dec 12 10:12:00 2002
@@ -52,6 +52,17 @@
method=getattr(getServiceManager(None), methodName)
method(*args, **kwargs)
+def interface(_context, interface):
+ interface = _context.resolve(interface)
+ return [
+ Action(
+ discriminator = None,
+ callable = handler,
+ args = ('Interfaces', 'provideInterface', '', interface)
+ ),
+ ]
+
+
def adapter(_context, factory, provides, for_=None, permission=None):
if for_ is not None: for_ = _context.resolve(for_)
provides = _context.resolve(provides)
@@ -72,8 +83,7 @@
Action(
discriminator = None,
callable = handler,
- args = ('Interfaces', 'provideInterface',
- provides.__module__+'.'+provides.__name__, provides)
+ args = ('Interfaces', 'provideInterface', '', provides)
)
]
if for_ is not None:
@@ -82,8 +92,7 @@
Action(
discriminator = None,
callable = handler,
- args = ('Interfaces', 'provideInterface',
- for_.__module__+'.'+for_.__name__, for_)
+ args = ('Interfaces', 'provideInterface', '', for_)
)
)