[Zope3-Users] zope.app.renderer renderer lookup
Christian Lück
christian.lueck at ruhr-uni-bochum.de
Tue Sep 16 22:50:15 EDT 2008
Hi,
I don't know how to get the renderers in zope.app.renderer.
getMultiAdapter fails with a ComponentLookupError. Here is a minimal
example driven by the debugger:
(zope-sandbox)clueck at aeolos:~/tools/quotationtool$
bin/quotationtool-debug
...
>>> import zope.interface
>>> import zope.component
>>> import zope.app.renderer
Get a factory for plaintext sources
>>> source_factory =
zope.component.getUtility(zope.component.interfaces.IFactory, name =
'zope.source.plaintext')
>>> source_factory
<zope.app.renderer.SourceFactory object at 0xb68b9b2c>
>>> list(source_factory.getInterfaces())
[<InterfaceClass zope.app.renderer.plaintext.IPlainTextSource>,
<InterfaceClass zope.app.renderer.interfaces.ISource>, <InterfaceClass
zope.interface.Interface>]
We have the factory. That even means that zope.app.renderer is
configured (registered).
Now let's make a source object.
>>> text = u"Hello World!\nZope is cool..."
>>> source = source_factory(text)
>>> source
u'Hello World!\nZope is cool...'
>>> list(zope.interface.providedBy(source))
[<InterfaceClass zope.app.renderer.plaintext.IPlainTextSource>]
>>> list(zope.interface.directlyProvidedBy(source))
[<InterfaceClass zope.app.renderer.plaintext.IPlainTextSource>]
It's a Source object with a IPlainTextSource interfaces directly slammed on
Now let's try to get the renderer
>>> from zope.testbrowser.browser import Browser
>>> request = Browser()
>>> request
<zope.testbrowser.browser.Browser object at 0xb74e308c>
>>> renderer = zope.component.getMultiAdapter((source, request),
zope.app.renderer.interfaces.IHTMLRenderer, name='')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"/home/clueck/.buildout-eggs/tmpyxUXwG/zope.component-3.4.0-py2.5.egg/zope/component/_api.py",
line 103, in getMultiAdapter
ComponentLookupError: ((u'Hello World!\nZope is cool...',
<zope.testbrowser.browser.Browser object at 0xb74e308c>),
<InterfaceClass zope.app.renderer.interfaces.IHTMLRenderer>, '')
Damn it!
>>> renderer = zope.component.getMultiAdapter((source, request),)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"/home/clueck/.buildout-eggs/tmpyxUXwG/zope.component-3.4.0-py2.5.egg/zope/component/_api.py",
line 103, in getMultiAdapter
ComponentLookupError: ((u'Hello World!\nZope is cool...',
<zope.testbrowser.browser.Browser object at 0xb74e308c>),
<InterfaceClass zope.interface.Interface>, u'')
>>> from zope.publisher.interfaces.browser import IBrowserView
>>> renderer = zope.component.getMultiAdapter((source, request),
IBrowserView, name='')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"/home/clueck/.buildout-eggs/tmpyxUXwG/zope.component-3.4.0-py2.5.egg/zope/component/_api.py",
line 103, in getMultiAdapter
ComponentLookupError: ((u'Hello World!\nZope is cool...',
<zope.testbrowser.browser.Browser object at 0xb74e308c>),
<InterfaceClass zope.publisher.interfaces.browser.IBrowserView>, '')
Does a proxy cause this?
>>> from zope.security.proxy import removeSecurityProxy
>>> renderer =
zope.component.getMultiAdapter((removeSecurityProxy(source), request),
IBrowserView, name='')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"/home/clueck/.buildout-eggs/tmpyxUXwG/zope.component-3.4.0-py2.5.egg/zope/component/_api.py",
line 103, in getMultiAdapter
ComponentLookupError: ((u'Hello World!\nZope is cool...',
<zope.testbrowser.browser.Browser object at 0xb74e308c>),
<InterfaceClass zope.publisher.interfaces.browser.IBrowserView>, '')
>>> from zope.proxy import removeAllProxies
>>> renderer =
zope.component.getMultiAdapter((removeAllProxies(source), request),
IBrowserView, name = '')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"/home/clueck/.buildout-eggs/tmpyxUXwG/zope.component-3.4.0-py2.5.egg/zope/component/_api.py",
line 103, in getMultiAdapter
ComponentLookupError: ((u'Hello World!\nZope is cool...',
<zope.testbrowser.browser.Browser object at 0xb74e308c>),
<InterfaceClass zope.publisher.interfaces.browser.IBrowserView>, '')
>>>
What's the problem with that? The adapter query should consider directly
provided interfaces, too, shouldn't it?
The renderers (for plaintext, rest and stx) are configured as
BrowserViews, aren't they?
Regards,
Christian
More information about the Zope3-users
mailing list