[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/ Merged
from trunk:
Jim Fulton
jim at zope.com
Sat Jul 10 09:26:04 EDT 2004
Log message for revision 26397:
Merged from trunk:
r26389 | jim | 2004-07-10 08:44:33 -0400 (Sat, 10 Jul 2004) | 3 lines
r26390 | jim | 2004-07-10 08:46:02 -0400 (Sat, 10 Jul 2004) | 4 lines
Added an adapter_hook method to make it easier (and more efficient) to
into interface call.
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/adapter/adapter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/adapter/adapter.py 2004-07-10 13:24:18 UTC (rev 26396)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/adapter/adapter.py 2004-07-10 13:26:04 UTC (rev 26397)
@@ -105,7 +105,7 @@
def __getstate__(self):
state = Persistent.__getstate__(self).copy()
- for name in ('_default', '_null',
+ for name in ('_default', '_null', 'adapter_hook',
'lookup', 'lookup1', 'queryAdapter', 'get',
'subscriptions', 'queryMultiAdapter', 'subscribers'
):
Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py 2004-07-10 13:24:18 UTC (rev 26396)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py 2004-07-10 13:26:04 UTC (rev 26397)
@@ -378,13 +378,25 @@
return value
- def queryAdapter(self, object, interface, name='', default=None):
+ def adapter_hook(self, interface, object, name='', default=None):
+ """Hook function used when calling interfaces.
+
+ When called from Interface.__adapt__, only the interface and
+ object parameters will be passed.
+
+ """
factory = self.lookup1(providedBy(object), interface, name)
if factory is not None:
return factory(object)
return default
+ def queryAdapter(self, object, interface, name='', default=None):
+ # Note that we rarely call queryAdapter directly
+ # We usually end up calling adapter_hook
+ return self.adapter_hook(interface, object, name, default)
+
+
def subscriptions(self, required, provided):
if provided is None:
provided = Null
@@ -483,8 +495,10 @@
except KeyError:
pass
lookup = AdapterLookup(self, surrogates, _remove)
+
for name in ('lookup', 'lookup1', 'queryAdapter', 'get',
- 'subscriptions', 'queryMultiAdapter', 'subscribers'
+ 'adapter_hook', 'subscriptions',
+ 'queryMultiAdapter', 'subscribers',
):
setattr(self, name, getattr(lookup, name))
Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.txt 2004-07-10 13:24:18 UTC (rev 26396)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.txt 2004-07-10 13:26:04 UTC (rev 26397)
@@ -170,8 +170,25 @@
>>> y.context is x
True
+An alternate method that provides the same function as `queryAdapter` is
+`adapter_hook`:
+ >>> y = registry.adapter_hook(IP1, x)
+ >>> y.__class__.__name__
+ 'Y'
+ >>> y.context is x
+ True
+ >>> y = registry.adapter_hook(IP1, x, 'bob')
+ >>> y.__class__.__name__
+ 'Y2'
+ >>> y.context is x
+ True
+The `adapter_hook` simply switches the order of the object and
+interface arguments. It is used to hook into the interface call
+mechanism.
+
+
Default Adapters
----------------
More information about the Zope3-Checkins
mailing list