Chris Withers wrote:
> Jacob Holm wrote:
>>> Can someone confirm to me whether or not manually specifying the 
>>> context as I have in the example above would work, or would I need 
>>> to do:
>>>  >>> adapter1 = getAdapter(a,ISomething,context=siteA)
>>>  >>> adapter2 = getAdapter(b,ISomething,context=siteB)
>> In general, using "context=a" should give the same result as 
>> "context=siteA".
> Why? What actually makes this work?

If you provide a context in the zope.component.getAdapter call, it is 
used with zope.component.getSiteManager to find the "site manager" to 
use for the actual lookup.  In this case getSiteManager does the actual 
lookup by adapting context to zope.component.interfaces.IComponentLookup 
using the global registry.  In a normal setup, this will find the 
SiteManagerAdapter from (used to be in  This adapter simply traverses __parent__ pointers 
until it finds an object providing zope.location.interfaces.ISite.

Depending on your setup it may actually be a different implementation of 
getSiteManager that is used, since it is marked with @hookable.  The 
common replacement is, which in this case 
does exactly the same global IComponentLookup adapter lookup I described 

If you are not using, you need to provide your own global 
IComponentLookup adapter to get it working.  (Or hook the getSiteManager 
function yourself)

This is a bit more complex than I remembered, but the result is that in 
a normal setup passing "context=A" will give the same result as 
"context=siteA", assuming that siteA can be found from A by following 
__parent__ pointers.

Hope this helps

- Jacob
Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to