Thank you much Phillip!

On Sep 15, 2007, at 7:04 PM, Philipp von Weitershausen wrote:

Chris McDonough wrote:
I'm having a bit of trouble debugging a failed browser view lookup. It has something to do with environment, because lookups for the view work in one of my sandboxes, and fail in another, even though both seemingly has the same ZCML and code. Does anyone have any scripts already written that, say, at "zopectl run" time dump the various component registries to a human-consumable format so problems like this can be debugged more simply?

>>> from zope.component import getSiteManager
>>> reg = getSiteManager()
>>> from pprint import pprint
>>> for info in reg.registeredAdapters():
... pprint((info.required, info.provided, info.factory,

This will probably drown you with information, though. One step would be to constrain the output only to browser views, in other words, 2-way multi-adapters whose second required interface is or extends IBrowserRequest:

>>> from zope.publisher.interfaces.browser import IBrowserRequest
>>> for info in reg.registeredAdapters():
...     if (len(info.required) == 2 and
...         info.required[1].isOrExtends(IBrowserRequest)):
...         pprint((info.required, info.provided, info.factory,

For better findability, you might want to search by name now. This is left up to the skilled reader as an exercise ;)

In my experience, failed adapter lookups are mostly due to

* configuration simply not getting loaded,

* things being registered for one thing but objects providing another (this can be especially confusing if the two things that are separate have similar or equal names, therefore making you believe they're the same. Python's "is" operator will do wonders).

* in case of browser views, missing layers applied to the request.

-- -- Professional Zope documentation and training

Zope3-users mailing list

Reply via email to