[Zope3-checkins]
SVN: Zope3/trunk/src/zope/app/publisher/browser/menu.
When a view cannot be found, it raises a `TraversalError`; since
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Nov 16 12:55:10 EST 2005
Log message for revision 40164:
When a view cannot be found, it raises a `TraversalError`; since
`MenuItem.available()` did not handle those errors, this error ended up
uncaught. If used in a traversal (which is usually the case), then error
was then masked as a traversal error of the menu itself, which was very
confusing. Now, `available()` catches `LookupError`s (a superclass of
`TraversalError`) and returns `False`.
So the result for the end user is: If someone created a menu item for a
non-existent view, it is always ignored, instead of breaking the menu code
in very unexpected ways.
Changed:
U Zope3/trunk/src/zope/app/publisher/browser/menu.py
U Zope3/trunk/src/zope/app/publisher/browser/menu.txt
-=-
Modified: Zope3/trunk/src/zope/app/publisher/browser/menu.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/menu.py 2005-11-16 17:16:26 UTC (rev 40163)
+++ Zope3/trunk/src/zope/app/publisher/browser/menu.py 2005-11-16 17:55:09 UTC (rev 40164)
@@ -34,7 +34,6 @@
from zope.app.publisher.interfaces.browser import IBrowserSubMenuItem
from zope.app.publisher.interfaces.browser import IMenuItemType
-
class BrowserMenu(object):
"""Browser Menu"""
implements(IBrowserMenu)
@@ -114,7 +113,7 @@
try:
view = traverser.traverseRelativeURL(
self.request, self.context, path)
- except (Unauthorized, Forbidden):
+ except (Unauthorized, Forbidden, LookupError):
return False
else:
# we're assuming that view pages are callable
Modified: Zope3/trunk/src/zope/app/publisher/browser/menu.txt
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/menu.txt 2005-11-16 17:16:26 UTC (rev 40163)
+++ Zope3/trunk/src/zope/app/publisher/browser/menu.txt 2005-11-16 17:55:09 UTC (rev 40164)
@@ -51,18 +51,20 @@
>>> class Content(object):
... zope.interface.implements(IContent, IBrowserPublisher)
- ...
+ ...
... def foo(self):
... pass
- ...
+ ...
... def browserDefault(self, r):
... return self, ()
- ...
+ ...
... def publishTraverse(self, request, name):
... if name.startswith('fb'):
... raise Forbidden, name
... if name.startswith('ua'):
... raise Unauthorized, name
+ ... if name.startswith('le'):
+ ... raise LookupError, name
... return self.foo
We also implemented the ``IBrowserPublisher`` interface, because we want to
@@ -134,7 +136,7 @@
Now, we are not setting any user. This means that the menu item should be
available.
-
+
>>> from zope.security.management import newInteraction, endInteraction
>>> endInteraction()
>>> newInteraction()
@@ -154,7 +156,7 @@
>>> item.permission = None
- All views starting with 'f' are forbidden, the ones with 'u' are
+ All views starting with 'fb' are forbidden, the ones with 'ua' are
unauthorized and all others are allowed.
>>> item.action = u'fb'
@@ -167,10 +169,20 @@
>>> item.available()
True
+Also, sometimes a menu item might be registered for a view that does not
+exist. In those cases the traversal mechanism raises a `TraversalError`, which
+is a special type of `LookupError`. All actions starting with `le` should
+raise this error:
+
+ >>> item.action = u'le'
+ >>> item.available()
+ False
+
Now let's test filtering. If the filter is specified, it is assumed to be
a TALES obejct.
>>> from zope.app.pagetemplate.engine import Engine
+ >>> item.action = u'a'
>>> item.filter = Engine.compile('not:context')
>>> item.available()
False
More information about the Zope3-Checkins
mailing list