[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Change the way traveral and not-found errors are displayed.

Jim Fulton jim at zope.com
Thu Oct 28 14:22:32 EDT 2004


Log message for revision 28275:
  Change the way traveral and not-found errors are displayed.
  Now, the NotFound view is *only* used for NotFound errors,
  spcifically, when the URL is bad.  Traversal errors elsewhere lead to
  system errors.
  

Changed:
  U   Zope3/trunk/src/zope/app/exception/browser/configure.zcml
  A   Zope3/trunk/src/zope/app/publication/ftests.py
  A   Zope3/trunk/src/zope/app/publication/notfound.txt
  U   Zope3/trunk/src/zope/app/publication/publicationtraverse.py
  U   Zope3/trunk/src/zope/app/traversing/api.py

-=-
Modified: Zope3/trunk/src/zope/app/exception/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/exception/browser/configure.zcml	2004-10-28 18:22:29 UTC (rev 28274)
+++ Zope3/trunk/src/zope/app/exception/browser/configure.zcml	2004-10-28 18:22:32 UTC (rev 28275)
@@ -26,7 +26,7 @@
       />
 
   <page
-      for="zope.exceptions.INotFoundError"
+      for="zope.publisher.interfaces.NotFound"
       name="index.html"
       permission="zope.Public"
       template="notfound.pt"

Added: Zope3/trunk/src/zope/app/publication/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/ftests.py	2004-10-28 18:22:29 UTC (rev 28274)
+++ Zope3/trunk/src/zope/app/publication/ftests.py	2004-10-28 18:22:32 UTC (rev 28275)
@@ -0,0 +1,28 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test not found errors
+
+$Id$
+"""
+import unittest
+
+def test_suite():
+    from zope.app.tests import functional
+    return unittest.TestSuite((
+        functional.FunctionalDocFileSuite('notfound.txt'),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+


Property changes on: Zope3/trunk/src/zope/app/publication/ftests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/publication/notfound.txt
===================================================================
--- Zope3/trunk/src/zope/app/publication/notfound.txt	2004-10-28 18:22:29 UTC (rev 28274)
+++ Zope3/trunk/src/zope/app/publication/notfound.txt	2004-10-28 18:22:32 UTC (rev 28275)
@@ -0,0 +1,63 @@
+NotFound errors and traversal errors
+====================================
+
+Not found errors should only be displayed when someone provides a URL
+to an object that doesn't exist, as in:
+
+  >>> print http(r"""
+  ... GET /eek HTTP/1.1
+  ... """)
+  HTTP/1.1 404 Not Found
+  ...
+    The page that you are trying to access is not available
+  ...
+
+On the other hand, if we create a template that refers to something
+that doesn't exist:
+
+
+  >>> print http(r"""
+  ... POST /+/zope.app.zptpage.ZPTPage%3D HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 739
+  ... Content-Type: multipart/form-data; boundary=---------------------------125598457818223697821067764270
+  ... Referer: http://localhost:8081/+/zope.app.zptpage.ZPTPage=
+  ... 
+  ... -----------------------------125598457818223697821067764270
+  ... Content-Disposition: form-data; name="field.source"
+  ... 
+  ... <html><body tal:content="container/eek" /></html>
+  ... -----------------------------125598457818223697821067764270
+  ... Content-Disposition: form-data; name="field.expand.used"
+  ... 
+  ... 
+  ... -----------------------------125598457818223697821067764270
+  ... Content-Disposition: form-data; name="field.evaluateInlineCode.used"
+  ... 
+  ... 
+  ... -----------------------------125598457818223697821067764270
+  ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
+  ... 
+  ... Add
+  ... -----------------------------125598457818223697821067764270
+  ... Content-Disposition: form-data; name="add_input_name"
+  ... 
+  ... test.html
+  ... -----------------------------125598457818223697821067764270--
+  ... """)
+  HTTP/1.1 303 See Other
+  ...
+  Location: http://localhost/@@contents.html
+  ...
+
+
+We get a system error, because the problem is in the template, not in
+the URL:
+
+  >>> print http(r"""
+  ... GET /test.html HTTP/1.1
+  ... """)
+  HTTP/1.1 500 Internal Server Error
+  ...
+    A system error occurred.
+  ...

Modified: Zope3/trunk/src/zope/app/publication/publicationtraverse.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/publicationtraverse.py	2004-10-28 18:22:29 UTC (rev 28274)
+++ Zope3/trunk/src/zope/app/publication/publicationtraverse.py	2004-10-28 18:22:32 UTC (rev 28275)
@@ -24,6 +24,7 @@
 
 from zope.app.traversing.namespace import namespaceLookup
 from zope.app.traversing.namespace import nsParse
+from zope.app.traversing.interfaces import TraversalError
 from zope.publisher.interfaces import IPublishTraverse
 
 class DuplicateNamespaces(Exception):
@@ -41,7 +42,11 @@
             # Process URI segment parameters.
             ns, nm = nsParse(name)
             if ns:
-                ob2 = namespaceLookup(ns, nm, ob, request)
+                try:
+                    ob2 = namespaceLookup(ns, nm, ob, request)
+                except TraversalError:
+                    raise NotFound(ob, name)
+
                 return ProxyFactory(ob2)
 
         if nm == '.':

Modified: Zope3/trunk/src/zope/app/traversing/api.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/api.py	2004-10-28 18:22:29 UTC (rev 28274)
+++ Zope3/trunk/src/zope/app/traversing/api.py	2004-10-28 18:22:32 UTC (rev 28275)
@@ -98,7 +98,6 @@
     except TraversalError:
         raise
     except NotFoundError, v: 
-        import pdb; pdb.set_trace()
         warnings.warn(
             "A %s instance raised a NotFoundError in "
             "traverse.  Raising NotFoundError in this "



More information about the Zope3-Checkins mailing list