[Checkins] SVN: z3c.componentdebug/trunk/src/z3c/componentdebug/
Fix the ComponentLookupError to inspect only registrations of the
Ross Patterson
me at rpatterson.net
Fri Jun 1 19:46:09 EDT 2007
Log message for revision 76142:
Fix the ComponentLookupError to inspect only registrations of the
right type
Changed:
U z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/api.py
U z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/registry.py
U z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt
-=-
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/api.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/api.py 2007-06-01 23:27:52 UTC (rev 76141)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/api.py 2007-06-01 23:46:09 UTC (rev 76142)
@@ -11,7 +11,8 @@
return origGetAdapterInContext(object, interface, context)
except ComponentLookupError:
raise VerboseComponentLookupError(
- (object,), interface, u'', context)
+ (object,), interface, u'', context,
+ methods=['registeredAdapters'])
origGetAdapter = _api.getAdapter
def getAdapter(object, interface=Interface, name=u'', context=None):
@@ -19,7 +20,8 @@
return origGetAdapter(object, interface, name, context)
except ComponentLookupError:
raise VerboseComponentLookupError(
- (object,), interface, name, context)
+ (object,), interface, name, context,
+ methods=['registeredAdapters'])
origGetMultiAdapter = _api.getMultiAdapter
def getMultiAdapter(objects, interface=Interface, name=u'',
@@ -28,7 +30,8 @@
return origGetMultiAdapter(objects, interface, name, context)
except ComponentLookupError:
raise VerboseComponentLookupError(
- objects, interface, name, context)
+ objects, interface, name, context,
+ methods=['registeredAdapters'])
origGetUtility = _api.getUtility
def getUtility(interface, name='', context=None):
@@ -36,7 +39,8 @@
return origGetUtility(interface, name, context)
except ComponentLookupError:
raise VerboseComponentLookupError(
- False, interface, name, context)
+ False, interface, name, context,
+ methods=['registeredUtilities'])
def patch():
_api.getAdapterInContext = getAdapterInContext
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/registry.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/registry.py 2007-06-01 23:27:52 UTC (rev 76141)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/registry.py 2007-06-01 23:46:09 UTC (rev 76142)
@@ -10,7 +10,8 @@
return origGetUtility(self, provided, name)
except ComponentLookupError:
raise VerboseComponentLookupError(
- False, provided, name, self)
+ False, provided, name, self,
+ methods=['registeredUtilities'])
origGetAdapter = Components.getAdapter
def getAdapter(self, object, interface=Interface, name=u''):
@@ -18,7 +19,8 @@
return origGetAdapter(self, object, interface, name)
except ComponentLookupError:
raise VerboseComponentLookupError(
- (object,), interface, name, self)
+ (object,), interface, name, self,
+ methods=['registeredAdapters'])
origGetMultiAdapter = Components.getMultiAdapter
def getMultiAdapter(self, objects, interface=Interface, name=u''):
@@ -26,7 +28,8 @@
return origGetMultiAdapter(self, objects, interface, name)
except ComponentLookupError:
raise VerboseComponentLookupError(
- objects, interface, name, self)
+ objects, interface, name, self,
+ methods=['registeredAdapters'])
def patch():
Components.getUtility = getUtility
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt 2007-06-01 23:27:52 UTC (rev 76141)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt 2007-06-01 23:46:09 UTC (rev 76142)
@@ -14,6 +14,9 @@
>>> gsm.registerAdapter(lambda x: x, (IFoo,), Interface)
>>> sm.registerAdapter(lambda x: x, (IFoo,), Interface)
+ >>> sm.registerSubscriptionAdapter(
+ ... lambda x: 'qux', (IFoo,), Interface)
+
Check the ComponentLookupError patch for other site managers::
>>> sm.getAdapter(None, Interface)
@@ -29,6 +32,9 @@
>>> sm.getAdapter(foo, Interface)
<Foo object at ...>
+ >>> sm.subscribers([foo], Interface)
+ ['qux']
+
>>> from z3c.componentdebug.lookup.patch import patch
>>> patch()
@@ -48,6 +54,9 @@
Objects with matching registrations:
None: UNMATCHED
+ >>> sm.subscribers([foo], Interface)
+ ['qux']
+
Make sure repr is used instead of str with a request::
>>> from zope import component
@@ -68,6 +77,9 @@
>>> sm.getAdapter(foo, Interface)
<Foo object at ...>
+ >>> sm.subscribers([foo], Interface)
+ ['qux']
+
>>> from z3c.componentdebug.lookup.patch import cleanup
>>> cleanup()
@@ -79,3 +91,6 @@
>>> sm.getAdapter(foo, Interface)
<Foo object at ...>
+
+ >>> sm.subscribers([foo], Interface)
+ ['qux']
More information about the Checkins
mailing list