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 zope.site.site (used to be in 
zope.app.component).  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 zope.site.hooks.getSiteManager, which in this case 
does exactly the same global IComponentLookup adapter lookup I described 
above.

If you are not using zope.site, 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  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to