[Checkins] SVN: z3c.componentdebug/trunk/src/z3c/componentdebug/
Fixes for handling utilities
Ross Patterson
me at rpatterson.net
Fri Jun 1 19:27:52 EDT 2007
Log message for revision 76141:
Fixes for handling utilities
Changed:
U z3c.componentdebug/trunk/src/z3c/componentdebug/component.py
U z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt
-=-
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/component.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/component.py 2007-06-01 22:49:26 UTC (rev 76140)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/component.py 2007-06-01 23:27:52 UTC (rev 76141)
@@ -31,15 +31,19 @@
elif iface_y in iface_x.__iro__:
return 1
else:
- return 0
+ # Fallback on the builtin iface sort
+ return cmp(iface_x, iface_y)
def cmpRegistrations(reg_x, reg_y):
- for idx in xrange(max(len(reg.required) for reg in (reg_x, reg_y))):
+ lens = [len(getattr(reg, 'required', ()))
+ for reg in (reg_x, reg_y)]
+ for idx in xrange(min(lens)):
cmp_ = cmpInterfaces(reg_x.required[idx], reg_y.required[idx])
if cmp_:
return cmp_
- else:
- return 0
+ # Fallback on the number of required interfaces or by the provided
+ # interface
+ return cmp(*lens) or cmp(reg_x.provided, reg_y.provided)
class Registrations(list):
@@ -60,7 +64,8 @@
super(Registrations, self).__init__(
reg for reg in getRegistrations(self.methods, context)
if (provided is False or reg.provided is provided)
- and (objects is False or len(reg.required) == self.order)
+ and (objects is False
+ or len(getattr(reg, 'required', ())) == self.order)
and (name is False or reg.name == name))
self.sort(cmp=cmpRegistrations, reverse=True)
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt 2007-06-01 22:49:26 UTC (rev 76140)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt 2007-06-01 23:27:52 UTC (rev 76141)
@@ -17,6 +17,8 @@
>>> bar = Bar()
>>> alsoProvides(bar, IBar)
+register an adapter to be returned::
+
>>> from zope.component import provideAdapter
>>> def getBaz(foo, bar): return 'baz'
>>> provideAdapter(getBaz, (IFoo, IBar), IBaz)
@@ -24,6 +26,17 @@
>>> from zope.component import queryMultiAdapter
>>> queryMultiAdapter((foo, bar), IBaz)
'baz'
+
+register a utility for comparison::
+
+ >>> from zope.component import provideUtility
+ >>> provideUtility('qux', IBaz)
+
+ >>> from zope.component import queryUtility
+ >>> queryUtility(IBaz)
+ 'qux'
+
+Verify inspection of an adapter registration::
>>> from pprint import pprint
>>> from z3c.componentdebug import inspect
@@ -43,6 +56,22 @@
IBaz, '', getBaz, u''),
[<Foo object at ...>, <Bar object at ...>])]
+Verify inspection of a utility::
+
+ >>> registrations = inspect((), IBaz)
+ >>> pprint(registrations)
+ [UtilityRegistration(<BaseGlobalComponents base>, IBaz, u'',
+ 'qux', u'')]
+
+Verify inspection of a all::
+
+ >>> registrations = inspect(provided=IBaz)
+ >>> pprint(registrations)
+ [AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+ IBaz, '', getBaz, u''),
+ UtilityRegistration(<BaseGlobalComponents base>, IBaz, u'',
+ 'qux', u'')]
+
Multiple Registrations
----------------------
More information about the Checkins
mailing list