How to get all registered "browser: resource" in Plone

How can I get all registered browser:resource and browser:resourceDirectory from the component registry?

I looked in different places trying to figure out which components are created by the zcml browser:resource directive and found Products.Five.browser.metaconfigure with a call to registerAdapter :

 handler('registerAdapter', factory, (layer,), Interface, name, _context.info) 

This means that it will register an adapter that requires (layer,) and provides an Interface , but calling the following does not work (it returns a component that is not a browser resource):

 from zope.publisher.interfaces.browser import IDefaultBrowserLayer zope.component.getAdapters((IDefaultBrowserLayer,), Interface) 

I'm not sure, but it seems that getAdapters needs an instance. I do not want to request zope.component, but to register registered adapters.

I found a lookupAll(required, provided) method in zope.interface.interfaces that looks the way I want, but I could not find where it was implemented, so I don’t know what to call it.

+4
source share
1 answer

zope.component.getAdapters() needs to pass an instance. zope.interface.registry.Components.getAdapters() method calls:

 list(map(providedBy, objects)) 

where providedBy is zope.interface.declarations.providedBy() . All that IDefaultBrowserLayer provides is ... zope.interface.IInterface and zope.interface.ISpecification .

You will need to pass a dummy object that provides an IDefaultBrowserLayer instead of directly accessing the interface.

 from zope.publisher.interfaces.browser import IDefaultBrowserLayer import zope.component import zope.interface class dummy(object): zope.interface.classProvides(IDefaultBrowserLayer) zope.component.getAdapters((dummy,), zope.interface.Interface) 
+2
source

Source: https://habr.com/ru/post/1496803/


All Articles