[Zope3-checkins] SVN: Zope3/trunk/src/z Changed the traversal
framework to use the more-specific new TraversalError
Jim Fulton
jim at zope.com
Tue Oct 26 18:59:30 EDT 2004
Log message for revision 28263:
Changed the traversal framework to use the more-specific new TraversalError
This is part of the long-rand plan to deprecate NotFoundError.
Changed:
U Zope3/trunk/src/zope/app/apidoc/classmodule/browser.py
U Zope3/trunk/src/zope/app/appsetup/bootstrap.py
U Zope3/trunk/src/zope/app/container/browser/contents.py
U Zope3/trunk/src/zope/app/container/tests/test_containertraversable.py
U Zope3/trunk/src/zope/app/container/traversal.py
U Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py
U Zope3/trunk/src/zope/app/fssync/tests/test_committer.py
U Zope3/trunk/src/zope/app/pagetemplate/engine.py
U Zope3/trunk/src/zope/app/schema/browser/traversal.py
U Zope3/trunk/src/zope/app/traversing/adapters.py
U Zope3/trunk/src/zope/app/traversing/api.py
U Zope3/trunk/src/zope/app/traversing/interfaces.py
U Zope3/trunk/src/zope/app/traversing/namespace.py
U Zope3/trunk/src/zope/app/traversing/tests/test_conveniencefunctions.py
U Zope3/trunk/src/zope/app/traversing/tests/test_traverser.py
U Zope3/trunk/src/zwiki/tests/test_traversable.py
U Zope3/trunk/src/zwiki/traversal.py
-=-
Modified: Zope3/trunk/src/zope/app/apidoc/classmodule/browser.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/classmodule/browser.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/apidoc/classmodule/browser.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -26,7 +26,7 @@
from zope.configuration import docutils, xmlconfig
from zope.configuration.config import ConfigurationContext
from zope.configuration.fields import GlobalObject, Tokens
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.interface import implementedBy
from zope.interface.interface import InterfaceClass
from zope.proxy import removeAllProxies
@@ -478,7 +478,7 @@
try:
klass = zapi.traverse(classModule, path.replace('.', '/'))
url = zapi.getView(klass, 'absolute_url', self.request)()
- except NotFoundError:
+ except TraversalError:
# If one of the classes is implemented in C, we will not
# be able to find it.
url = None
Modified: Zope3/trunk/src/zope/app/appsetup/bootstrap.py
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/bootstrap.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/appsetup/bootstrap.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -24,7 +24,7 @@
from transaction import get_transaction
from zope.app.publication.zopepublication import ZopePublication
from zope.interface import implements
-from zope.component.exceptions import ComponentLookupError
+from zope.app.traversing.interfaces import TraversalError
from zope.app import zapi
from zope.app.traversing.api import traverse, traverseName
@@ -195,7 +195,7 @@
"""
try:
service_manager = traverse(root_folder, '++etc++site')
- except ComponentLookupError:
+ except TraversalError:
service_manager = ServiceManager(root_folder)
root_folder.setSiteManager(service_manager)
return service_manager
Modified: Zope3/trunk/src/zope/app/container/browser/contents.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/contents.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/container/browser/contents.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -17,7 +17,7 @@
"""
__docformat__ = 'restructuredtext'
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.security.interfaces import Unauthorized
from zope.security import checkPermission
@@ -301,7 +301,7 @@
for item in items:
try:
obj = zapi.traverse(target, item['target'])
- except NotFoundError:
+ except TraversalError:
pass
else:
if item['action'] == 'cut':
@@ -331,7 +331,7 @@
for item in items:
try:
obj = zapi.traverse(target, item['target'])
- except NotFoundError:
+ except TraversalError:
pass
else:
if item['action'] == 'cut':
@@ -367,7 +367,7 @@
for item in items:
try:
zapi.traverse(self.context, item['target'])
- except NotFoundError:
+ except TraversalError:
pass
else:
return True
Modified: Zope3/trunk/src/zope/app/container/tests/test_containertraversable.py
===================================================================
--- Zope3/trunk/src/zope/app/container/tests/test_containertraversable.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/container/tests/test_containertraversable.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -17,7 +17,7 @@
"""
import unittest
from zope.app.container.traversal import ContainerTraversable
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.app.container.interfaces import IContainer
from zope.testing.cleanup import CleanUp
from zope.interface import implements
@@ -58,7 +58,7 @@
self.failUnless(T.traverse('foo', []) is baz)
self.failUnless(T.traverse('bar', []) is bar)
- self.assertRaises(NotFoundError , T.traverse, 'morebar', [])
+ self.assertRaises(TraversalError , T.traverse, 'morebar', [])
def test_suite():
Modified: Zope3/trunk/src/zope/app/container/traversal.py
===================================================================
--- Zope3/trunk/src/zope/app/container/traversal.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/container/traversal.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -18,7 +18,7 @@
__docformat__ = 'restructuredtext'
from zope.interface import implements
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.interfaces import NotFound
@@ -98,6 +98,6 @@
if v is _marker:
v = getattr(container, name, _marker)
if v is _marker:
- raise NotFoundError, name
+ raise TraversalError, name
return v
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -21,7 +21,7 @@
from zope.component.exceptions import ComponentLookupError
from zope.configuration.xmlconfig import xmlconfig, XMLConfig
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.interface import Interface, implements
from zope.publisher.browser import TestRequest
from zope.schema import TextLine, Int
@@ -111,7 +111,7 @@
v = zapi.queryView(ob, 'add.html', request)
# expect to fail as standard macros are not configured
- self.assertRaises(NotFoundError, v)
+ self.assertRaises(TraversalError, v)
def testEditForm(self):
self.assertEqual(zapi.queryView(ob, 'test', request),
@@ -136,7 +136,7 @@
v = zapi.queryView(ob, 'edit.html', request)
# expect to fail as standard macros are not configured
- self.assertRaises(NotFoundError, v)
+ self.assertRaises(TraversalError, v)
def testEditFormWithMenu(self):
self.assertEqual(zapi.queryView(ob, 'test', request),
@@ -164,7 +164,7 @@
v = zapi.queryView(ob, 'edit.html', request)
# expect to fail as standard macros are not configured
- self.assertRaises(NotFoundError, v)
+ self.assertRaises(TraversalError, v)
def testAddFormWithWidget(self):
self.assertEqual(zapi.queryView(ob, 'test', request),
Modified: Zope3/trunk/src/zope/app/fssync/tests/test_committer.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/tests/test_committer.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/fssync/tests/test_committer.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -23,7 +23,7 @@
from zope.component.service import serviceManager
from zope.app.tests import ztapi
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.interface import implements
from zope.xmlpickle import loads, dumps
@@ -91,7 +91,7 @@
try:
return self[name]
except KeyError:
- raise NotFoundError
+ raise TraversalError
PCname = PretendContainer.__module__ + "." + PretendContainer.__name__
Modified: Zope3/trunk/src/zope/app/pagetemplate/engine.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/engine.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/pagetemplate/engine.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -29,7 +29,7 @@
from zope.tales.tales import ExpressionEngine, Context
from zope.component.exceptions import ComponentLookupError
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.security.untrustedpython import rcompile
from zope.security.proxy import ProxyFactory
from zope.security.untrustedpython.builtins import SafeBuiltins
@@ -222,7 +222,7 @@
KeyError: 'zope.app.pagetemplate.tests.trusted'
(The use of ``KeyError`` is an unfortunate implementation detail; I
- think this should be a ``NotFoundError``.)
+ think this should be a ``TraversalError``.)
Modules which have already been imported by trusted code are
available, wrapped in security proxies::
@@ -362,7 +362,7 @@
try:
return self[name]
except KeyError:
- raise NotFoundError(name)
+ raise TraversalError(name)
def _Engine(engine=None):
Modified: Zope3/trunk/src/zope/app/schema/browser/traversal.py
===================================================================
--- Zope3/trunk/src/zope/app/schema/browser/traversal.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/schema/browser/traversal.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -18,7 +18,7 @@
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.app.schema.interfaces import IMutableSchema
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.publisher.interfaces import NotFound
from zope.app.traversing.interfaces import ITraversable
@@ -71,6 +71,6 @@
def traverse(self, name, furtherPath):
subobj = self._context.get(name, _marker)
if subobj is _marker:
- raise NotFoundError, name
+ raise TraversalError, name
return subobj
Modified: Zope3/trunk/src/zope/app/traversing/adapters.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/adapters.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/traversing/adapters.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -17,7 +17,7 @@
"""
from types import StringTypes, MethodType
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.interface import implements
from zope.app.traversing.interfaces import IPhysicallyLocatable
@@ -49,7 +49,7 @@
# Let exceptions propagate.
return subject[name]
else:
- raise NotFoundError(subject, name)
+ raise TraversalError(subject, name)
class RootPhysicallyLocatable(object):
__doc__ = IPhysicallyLocatable.__doc__
@@ -114,7 +114,7 @@
curr = traversePathElement(curr, name, path, request=request)
return curr
- except NotFoundError:
+ except TraversalError:
if default == _marker:
raise
return default
@@ -137,7 +137,9 @@
'request' is passed in when traversing from presentation code. This
allows paths like @@foo to work.
- Raises NotFoundError if path cannot be found and 'default' was not provided.
+ Raises TraversalError if path cannot be found and 'default' was
+ not provided.
+
"""
if name == '.':
return obj
@@ -161,12 +163,12 @@
traversable = ITraversable(obj, None)
if traversable is None:
- raise NotFoundError('No traversable adapter found', obj)
+ raise TraversalError('No traversable adapter found', obj)
try:
next_item = traversable.traverse(nm, further_path)
obj = next_item
- except NotFoundError:
+ except TraversalError:
if default != _marker:
return default
else:
Modified: Zope3/trunk/src/zope/app/traversing/api.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/api.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/traversing/api.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -74,8 +74,7 @@
'request' is passed in when traversing from presentation code. This
allows paths like @@foo to work.
- Raises NotFoundError if path cannot be found
- Raises TypeError if place is not context wrapped
+ Raises TraversalError if path cannot be found
Note: calling traverse with a path argument taken from an untrusted
source, such as an HTTP request form variable, is a bad idea.
@@ -102,7 +101,9 @@
'request' is passed in when traversing from presentation code. This
allows paths like @@foo to work.
- Raises NotFoundError if path cannot be found and 'default' was not provided.
+ Raises TraversalError if path cannot be found and 'default' was
+ not provided.
+
"""
further_path = []
if default is _marker:
Modified: Zope3/trunk/src/zope/app/traversing/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/interfaces.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/traversing/interfaces.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -17,6 +17,12 @@
"""
from zope.interface import Interface
+from zope.exceptions import NotFoundError
+
+class TraversalError(NotFoundError):
+ """There is no object for the name given to a traversal
+ """
+
class IContainmentRoot(Interface):
"""Marker interface to designate root objects
"""
@@ -66,7 +72,7 @@
"""Get the next item on the path
Should return the item corresponding to 'name' or raise
- NotFoundError where appropriate.
+ TraversalError where appropriate.
furtherPath is a list of names still to be traversed. This method is
allowed to change the contents of furtherPath.
@@ -134,8 +140,7 @@
'request' is passed in when traversing from presentation code. This
allows paths like @@foo to work.
- Raises NotFoundError if path cannot be found
- Raises TypeError if place is not context wrapped
+ Raises TraversalError if path cannot be found
Note: calling traverse with a path argument taken from an untrusted
source, such as an HTTP request form variable, is a bad idea.
@@ -159,7 +164,7 @@
'request' is passed in when traversing from presentation code. This
allows paths like @@foo to work.
- Raises NotFoundError if path cannot be found and 'default' was
+ Raises TraversalError if path cannot be found and 'default' was
not provided.
"""
Modified: Zope3/trunk/src/zope/app/traversing/namespace.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/namespace.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/traversing/namespace.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -17,21 +17,22 @@
"""
import re
+from zope.component.exceptions import ComponentLookupError
import zope.interface
from zope.interface import providedBy, directlyProvides, directlyProvidedBy
from zope import component
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.publisher.interfaces.browser import ISkin
from zope.security.proxy import removeSecurityProxy
from zope.app.publisher.browser import applySkin
from zope.app.traversing.interfaces import ITraversable, IPathAdapter
-class UnexpectedParameters(NotFoundError):
+class UnexpectedParameters(TraversalError):
"Unexpected namespace parameters were provided."
-class ExcessiveWrapping(NotFoundError):
- "Too many levels of acquisition wrapping. We don't believe them."
+class ExcessiveDepth(TraversalError):
+ "Too many levels of containment. We don't believe them."
def namespaceLookup(ns, name, object, request=None):
"""Lookup a value from a namespace
@@ -72,7 +73,7 @@
>>> namespaceLookup('fiz', 'bar', C())
Traceback (most recent call last):
...
- NotFoundError: '++fiz++bar'
+ TraversalError: '++fiz++bar'
We'll get the same thing if we provide a request:
@@ -81,7 +82,7 @@
>>> namespaceLookup('foo', 'bar', C(), request)
Traceback (most recent call last):
...
- NotFoundError: '++foo++bar'
+ TraversalError: '++foo++bar'
We need to provide a view:
@@ -105,7 +106,7 @@
traverser = component.queryAdapter(object, ITraversable, ns)
if traverser is None:
- raise NotFoundError("++%s++%s" % (ns, name))
+ raise TraversalError("++%s++%s" % (ns, name))
return traverser.traverse(name, ())
@@ -158,7 +159,7 @@
def getResource(site, name, request):
resource = queryResource(site, name, request)
if resource is None:
- raise NotFoundError(site, name)
+ raise TraversalError(site, name)
return resource
def queryResource(site, name, request, default=None):
@@ -209,7 +210,7 @@
... def traverse(self, name, remaining):
... v = getattr(self, name, None)
... if v is None:
- ... raise NotFoundError(name)
+ ... raise TraversalError(name)
... return v
... def __repr__(self):
... return 'splat'
@@ -237,7 +238,7 @@
>>> adapter.traverse('d', ())
Traceback (most recent call last):
...
- NotFoundError: (splat, 'd')
+ TraversalError: (splat, 'd')
"""
i = 0
ob = self.context
@@ -251,16 +252,16 @@
next = traversable.traverse(name, path)
if path:
continue
- except NotFoundError:
+ except TraversalError:
pass
else:
return next
ob = getattr(ob, '__parent__', None)
if ob is None:
- raise NotFoundError(self.context, name)
+ raise TraversalError(self.context, name)
- raise ExcessiveWrapping(self.context, name)
+ raise ExcessiveDepth(self.context, name)
class attr(SimpleHandler):
@@ -316,14 +317,18 @@
return applicationController
if name not in ('site', 'Services'):
- raise NotFoundError(ob, name)
+ raise TraversalError(ob, name)
method_name = "getSiteManager"
method = getattr(ob, method_name, None)
if method is None:
- raise NotFoundError(ob, name)
+ raise TraversalError(ob, name)
- return method()
+ try:
+ return method()
+ except ComponentLookupError:
+ raise TraversalError(ob, name)
+
class view(object):
@@ -336,7 +341,7 @@
def traverse(self, name, ignored):
view = component.queryView(self.context, name, self.request)
if view is None:
- raise NotFoundError(self.context, name)
+ raise TraversalError(self.context, name)
return view
@@ -419,7 +424,7 @@
2
>>> try:
... adapter.traverse('bob', ())
- ... except NotFoundError:
+ ... except TraversalError:
... print 'no adapter'
no adapter
@@ -430,7 +435,7 @@
try:
return component.getAdapter(self.context, IPathAdapter, name)
except:
- raise NotFoundError(self.context, name)
+ raise TraversalError(self.context, name)
class debug(view):
Modified: Zope3/trunk/src/zope/app/traversing/tests/test_conveniencefunctions.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/tests/test_conveniencefunctions.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/traversing/tests/test_conveniencefunctions.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -32,7 +32,7 @@
from zope.security.proxy import Proxy
from zope.security.checker import selectChecker
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.app.container.contained import contained
class C(object):
@@ -112,17 +112,17 @@
def testTraverseNameBadValue(self):
from zope.app.traversing.api import traverseName
self.assertRaises(
- NotFoundError,
+ TraversalError,
traverseName,
self.folder, '../root'
)
self.assertRaises(
- NotFoundError,
+ TraversalError,
traverseName,
self.folder, '/root'
)
self.assertRaises(
- NotFoundError,
+ TraversalError,
traverseName,
self.folder, './item'
)
Modified: Zope3/trunk/src/zope/app/traversing/tests/test_traverser.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/tests/test_traverser.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zope/app/traversing/tests/test_traverser.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -31,7 +31,7 @@
from zope.app.traversing.adapters import RootPhysicallyLocatable
from zope.app.container.contained import contained
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.security.interfaces import Unauthorized
from zope.app.servicenames import Adapters
@@ -81,7 +81,7 @@
self.tr = Traverser(root)
def testNoTraversable(self):
- self.assertRaises(NotFoundError, self.tr.traverse,
+ self.assertRaises(TraversalError, self.tr.traverse,
'folder')
class UnrestrictedTraverseTests(PlacefulSetup, unittest.TestCase):
@@ -142,7 +142,7 @@
'notFound')
def testNotFoundNoDefault(self):
- self.assertRaises(NotFoundError, self.tr.traverse, 'foo')
+ self.assertRaises(TraversalError, self.tr.traverse, 'foo')
class RestrictedTraverseTests(PlacefulSetup, unittest.TestCase):
_oldPolicy = None
@@ -227,7 +227,7 @@
def testNotFound(self):
df = DefaultTraversable(C('dummy'))
- self.assertRaises(NotFoundError, df.traverse, 'bar', [])
+ self.assertRaises(TraversalError, df.traverse, 'bar', [])
def test_suite():
loader = unittest.TestLoader()
Modified: Zope3/trunk/src/zwiki/tests/test_traversable.py
===================================================================
--- Zope3/trunk/src/zwiki/tests/test_traversable.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zwiki/tests/test_traversable.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -16,7 +16,7 @@
$Id$
"""
import unittest, sys
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.testing.cleanup import CleanUp
from zwiki.wiki import Wiki
@@ -44,7 +44,7 @@
T = WikiPageTraversable(page1)
self.failUnless(T.traverse('FooBar', []) is page2)
- self.assertRaises(NotFoundError , T.traverse, 'morebar', [])
+ self.assertRaises(TraversalError , T.traverse, 'morebar', [])
def test_suite():
Modified: Zope3/trunk/src/zwiki/traversal.py
===================================================================
--- Zope3/trunk/src/zwiki/traversal.py 2004-10-26 22:59:27 UTC (rev 28262)
+++ Zope3/trunk/src/zwiki/traversal.py 2004-10-26 22:59:30 UTC (rev 28263)
@@ -18,7 +18,7 @@
from zope.component import getDefaultViewName, queryView
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound
-from zope.exceptions import NotFoundError
+from zope.app.traversing.interfaces import TraversalError
from zope.app import zapi
from zope.app.traversing.api import getParent
@@ -78,6 +78,6 @@
if subobj is _marker:
subobj = getattr(self._page, name, _marker)
if subobj is _marker:
- raise NotFoundError, name
+ raise TraversalError, name
return subobj
More information about the Zope3-Checkins
mailing list