[Checkins] SVN: Sandbox/janwijbrand/zope.errorview/trunk/s require zope.authentication (should this be an extras_require instead?)

Jan-Wijbrand Kolman janwijbrand at gmail.com
Wed Jan 19 06:44:32 EST 2011


Log message for revision 119696:
  require zope.authentication (should this be an extras_require instead?)

Changed:
  U   Sandbox/janwijbrand/zope.errorview/trunk/setup.py
  A   Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.py
  U   Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.zcml
  U   Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py
  A   Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_browser.py

-=-
Modified: Sandbox/janwijbrand/zope.errorview/trunk/setup.py
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/setup.py	2011-01-19 11:43:52 UTC (rev 119695)
+++ Sandbox/janwijbrand/zope.errorview/trunk/setup.py	2011-01-19 11:44:31 UTC (rev 119696)
@@ -57,6 +57,7 @@
       install_requires=[
           'setuptools',
           'zope.browser',
+          'zope.authentication',
           'zope.component',
           'zope.interface',
           'zope.publisher',

Added: Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.py
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.py	                        (rev 0)
+++ Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.py	2011-01-19 11:44:31 UTC (rev 119696)
@@ -0,0 +1,58 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Exception view for BrowserRequest
+
+$Id: unauthorized.py 100273 2009-05-23 02:20:25Z shane $
+"""
+
+from zope.authentication.interfaces import IAuthentication
+from zope.component import getUtility
+from zope.errorview.http import ExceptionViewBase, ExceptionView
+from zope.errorview.http import UnauthorizedView
+from zope.publisher.browser import BrowserPage
+
+# XXX i18n-ing?
+
+class ExceptionView(ExceptionView):
+
+    def render(self):
+        return u'A system error occurred.'
+
+class NotFoundView(ExceptionViewBase):
+
+    def update(self):
+        self.request.response.setStatus(404)
+
+    def render(self):
+        return u'The requested resource can not be found.'
+
+class UnauthorizedView(UnauthorizedView):
+
+    def update(self):
+        # Set the error status to 403 (Forbidden) in the case when we
+        # don't challenge the user.
+        self.request.response.setStatus(403)
+        # Make sure that the response is not cacheable.
+        self.request.response.setHeader(
+            'Expires', 'Jan, 1 Jan 1970 00:00:00 GMT')
+        self.request.response.setHeader(
+            'Cache-Control', 'no-store, no-cache, must-revalidate')
+        self.request.response.setHeader(
+            'Pragma', 'no-cache')
+        principal = self.request.principal
+        getUtility(IAuthentication).unauthorized(principal.id, self.request)
+
+    def render(self):
+        if self.request.response.getStatus() not in (302, 303):
+            return u'Acces to the requested resource is forbidden.'

Modified: Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.zcml
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.zcml	2011-01-19 11:43:52 UTC (rev 119695)
+++ Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/browser.zcml	2011-01-19 11:44:31 UTC (rev 119696)
@@ -4,4 +4,24 @@
 
   <include package="." file="http.zcml" />
 
+  <page
+    for="zope.interface.common.interfaces.IException"
+    class=".browser.ExceptionView"
+    name="index.html"
+    permission="zope.Public"
+  />
+
+  <page
+    for="zope.security.interfaces.IUnauthorized"
+    class=".browser.UnauthorizedView"
+    name="index.html"
+    permission="zope.Public"
+  />
+
+  <page
+    for="zope.publisher.interfaces.INotFound"
+    class=".browser.NotFondView"
+    name="index.html"
+    permission="zope.Public"
+  />
 </configure>

Modified: Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py	2011-01-19 11:43:52 UTC (rev 119695)
+++ Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py	2011-01-19 11:44:31 UTC (rev 119696)
@@ -11,16 +11,14 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Unauthorized Exception
+"""Exception view for HTTPRequest
 
 $Id: unauthorized.py 100273 2009-05-23 02:20:25Z shane $
 """
 
+from zope.browser.interfaces import ISystemErrorView
 from zope.interface import implements
 from zope.publisher.interfaces.http import IHTTPException
-from zope.browser.interfaces import ISystemErrorView
-from zope.component import getAdapters
-from zope.interface import Interface
 
 class SystemErrorViewMixin:
 
@@ -36,11 +34,16 @@
     def __init__(self, context, request):
         self.context = context
         self.request = request
-        self.response = request.response
 
+    def update(self):
+        self.request.response.setStatus(500)
+
+    def render(self):
+        return u''
+
     def __call__(self):
-        self.response.setStatus(500)
-        return ''
+        self.update()
+        return self.render()
 
     def __str__(self):
         return self()
@@ -50,32 +53,31 @@
 
 class TraversalExceptionView(ExceptionViewBase):
 
-    def __call__(self):
+    def update(self):
         if self.request.method =='MKCOL' and self.request.getTraversalStack():
             # MKCOL with non-existing parent.
             self.request.response.setStatus(409)
         else:
             self.request.response.setStatus(404)
-        return ''
 
 class UnauthorizedView(ExceptionViewBase):
 
-    def __call__(self):
+    def update(self):
         self.request.unauthorized('basic realm="Zope"')
         self.request.response.setStatus(401)
-        return ''
 
 class MethodNotAllowedView(ExceptionViewBase):
 
+    # XXX define an interface for MethodNotAllowedView components.
+
     def allowed(self):
         # XXX how to determine the allowed HTTP methods?  XXX we need
         # a safe way to determine the allow HTTP methods. Or should we
         # let the application handle it?
         return []
 
-    def __call__(self):
+    def update(self):
         error = self.context
         allow = self.allowed()
         self.request.response.setStatus(405)
         self.request.response.setHeader('Allow', ', '.join(allow))
-        return ''

Added: Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_browser.py
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_browser.py	                        (rev 0)
+++ Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_browser.py	2011-01-19 11:44:31 UTC (rev 119696)
@@ -0,0 +1,6 @@
+from unittest import TestCase
+
+class Test(TestCase):
+
+    def test_joop(self):
+        assert True



More information about the checkins mailing list