[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/apidoc/presentation.
Fixed a bug in getViews(),
where a required interface value of `None`
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Nov 9 17:57:42 EST 2005
Log message for revision 40015:
Fixed a bug in getViews(), where a required interface value of `None`
would not be considered for the results, though it is the most generic
type of adapter. I had already fixed that in the get*Adapters() functions
before.
Generalized and simplified the factory sniffing code a bit more. This
makes the `factory` attribute on any wrapper factory somewhat of a
standard. Eventually we want to formalize this.
Changed:
U Zope3/trunk/src/zope/app/apidoc/presentation.py
U Zope3/trunk/src/zope/app/apidoc/presentation.txt
-=-
Modified: Zope3/trunk/src/zope/app/apidoc/presentation.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/presentation.py 2005-11-09 22:32:47 UTC (rev 40014)
+++ Zope3/trunk/src/zope/app/apidoc/presentation.py 2005-11-09 22:57:41 UTC (rev 40015)
@@ -44,6 +44,13 @@
info = {'path': None, 'url': None, 'template': None, 'resource': None,
'referencable': True}
+ # Always determine the most basic factory
+ # Commonly, factories are wrapped to provide security or location, for
+ # example. If those wrappers play nice, then they provide a `factory`
+ # attribute, that points to the original factory.
+ while hasattr(factory, 'factory'):
+ factory = factory.factory
+
if hasattr(factory, '__name__') and \
factory.__name__.startswith('SimpleViewClass'):
# In the case of a SimpleView, the base is really what we are
@@ -67,13 +74,6 @@
# Those factories are method publisher and security wrapped
info['path'] = getPythonPath(factory.__bases__[0].__bases__[0])
- # Special for views registered with the zope:view directive; the proxy
- # view implements the security wrapping
- elif hasattr(factory, '__class__') and \
- factory.__class__.__name__ == 'ProxyView':
- factory = factory.factory
- info['path'] = factory.__module__ + '.' + factory.__name__
-
# A factory that is a class instance; since we cannot reference instances,
# reference the class.
elif not hasattr(factory, '__name__'):
@@ -83,13 +83,6 @@
elif type(factory) in (type, ClassType):
info['path'] = getPythonPath(factory)
- # Sometimes factories are functions; there are two cases: (1) the factory
- # itself is a function, and (2) the original factory was wrapped by a
- # function; in the latter case the function must have a `factory`
- # attribute that references the original factory
- elif isinstance(factory, FunctionType):
- info['path'] = getPythonPath(getattr(factory, 'factory', factory))
-
# We have tried our best; just get the Python path as good as you can.
else:
info['path'] = getPythonPath(factory)
@@ -124,7 +117,7 @@
reg.required[-1].isOrExtends(type)):
for required_iface in reg.required[:-1]:
- if iface.isOrExtends(required_iface):
+ if required_iface is None or iface.isOrExtends(required_iface):
yield reg
Modified: Zope3/trunk/src/zope/app/apidoc/presentation.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/presentation.txt 2005-11-09 22:32:47 UTC (rev 40014)
+++ Zope3/trunk/src/zope/app/apidoc/presentation.txt 2005-11-09 22:57:41 UTC (rev 40015)
@@ -161,7 +161,42 @@
'template': None,
'url': '__builtin__/Factory'}
+Finally, it sometimes happens that a factory is wrapped and the wrapper is
+wrapped in return:
+ >>> def wrapper1(*args):
+ ... return Factory(*args)
+
+ >>> def wrapper2(*args):
+ ... return wrapper1(*args)
+
+Initially, the documentation is not very helpful:
+
+ >>> info = presentation.getViewFactoryData(wrapper2)
+ >>> pprint(info)
+ {'path': 'None.wrapper2',
+ 'referencable': True,
+ 'resource': None,
+ 'template': None,
+ 'url': 'None/wrapper2'}
+
+However, if those wrappers play nicely, they provide a factory attribute each
+step of the way ...
+
+ >>> wrapper1.factory = Factory
+ >>> wrapper2.factory = wrapper1
+
+and the result is finally our original factory:
+
+ >>> info = presentation.getViewFactoryData(wrapper2)
+ >>> pprint(info)
+ {'path': '__builtin__.Factory',
+ 'referencable': True,
+ 'resource': None,
+ 'template': None,
+ 'url': '__builtin__/Factory'}
+
+
`getPresentationType(iface)`
----------------------------
@@ -229,19 +264,27 @@
>>> regs = list(presentation.getViews(IFoo))
>>> regs.sort()
- >>> regs
+ >>> regs #doctest:+ELLIPSIS
[AdapterRegistration(('IFoo', 'IBrowserRequest'), 'Interface',
'blah', None, ''),
AdapterRegistration(('IFoo', 'IHTTPRequest'), 'Interface',
'foo', None, ''),
AdapterRegistration(('Interface', 'IHTTPRequest'), 'Interface',
- 'bar', None, '')]
+ 'bar', None, ''),
+ AdapterRegistration((None, 'IDefaultBrowserLayer'), 'IAbsoluteURL',
+ '', <class '...browser.absoluteurl.AbsoluteURL'>, ''),
+ AdapterRegistration((None, 'IDefaultBrowserLayer'), 'Interface',
+ 'absolute_url', <class ...absoluteurl.AbsoluteURL'>, '')]
>>> regs = list(presentation.getViews(Interface, IHTTPRequest))
>>> regs.sort()
- >>> regs
+ >>> regs #doctest:+ELLIPSIS
[AdapterRegistration(('Interface', 'IHTTPRequest'), 'Interface',
- 'bar', None, '')]
+ 'bar', None, ''),
+ AdapterRegistration((None, 'IDefaultBrowserLayer'), 'IAbsoluteURL',
+ '', <class '...browser.absoluteurl.AbsoluteURL'>, ''),
+ AdapterRegistration((None, 'IDefaultBrowserLayer'), 'Interface',
+ 'absolute_url', <class ...absoluteurl.AbsoluteURL'>, '')]
`filterViewRegistrations(regs, iface, level=SPECIFC_INTERFACE_LEVEL)`
More information about the Zope3-Checkins
mailing list