[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ Implement an error view of the AlreadyLocked exception.

Michael Kerrin michael.kerrin at openapp.ie
Wed May 30 14:05:58 EDT 2007


Log message for revision 76001:
  Implement an error view of the AlreadyLocked exception.
  
  Also tidy up some of the views so that they import the IHTTPRequest
  interface from its original location in zope.publisher
  

Changed:
  U   z3c.dav/trunk/src/z3c/dav/exceptions/__init__.py
  U   z3c.dav/trunk/src/z3c/dav/exceptions/configure.zcml
  U   z3c.dav/trunk/src/z3c/dav/exceptions/tests/test_simpleviews.py
  U   z3c.dav/trunk/src/z3c/dav/interfaces.py

-=-
Modified: z3c.dav/trunk/src/z3c/dav/exceptions/__init__.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/exceptions/__init__.py	2007-05-30 17:37:46 UTC (rev 76000)
+++ z3c.dav/trunk/src/z3c/dav/exceptions/__init__.py	2007-05-30 18:05:58 UTC (rev 76001)
@@ -25,6 +25,7 @@
 from zope import interface
 from zope import schema
 from zope import component
+import zope.publisher.interfaces.http
 from zope.app.http.interfaces import IHTTPException
 
 import z3c.dav.interfaces
@@ -165,7 +166,7 @@
 class HTTPForbiddenError(object):
     interface.implements(IHTTPException)
     component.adapts(z3c.dav.interfaces.IForbiddenError,
-                     z3c.dav.interfaces.IHTTPRequest)
+                     zope.publisher.interfaces.http.IHTTPRequest)
 
     def __init__(self, error, request):
         self.error = error
@@ -179,7 +180,7 @@
 class HTTPConflictError(object):
     interface.implements(IHTTPException)
     component.adapts(z3c.dav.interfaces.IConflictError,
-                     z3c.dav.interfaces.IHTTPRequest)
+                     zope.publisher.interfaces.http.IHTTPRequest)
 
     def __init__(self, error, request):
         self.error = error
@@ -193,7 +194,7 @@
 class PreconditionFailed(object):
     interface.implements(IHTTPException)
     component.adapts(z3c.dav.interfaces.IPreconditionFailed,
-                     z3c.dav.interfaces.IHTTPRequest)
+                     zope.publisher.interfaces.http.IHTTPRequest)
 
     def __init__(self, error, request):
         self.error = error
@@ -207,7 +208,7 @@
 class HTTPUnsupportedMediaTypeError(object):
     interface.implements(IHTTPException)
     component.adapts(z3c.dav.interfaces.IUnsupportedMediaType,
-                     z3c.dav.interfaces.IHTTPRequest)
+                     zope.publisher.interfaces.http.IHTTPRequest)
 
     def __init__(self, error, request):
         self.error = error
@@ -221,7 +222,7 @@
 class UnprocessableError(object):
     interface.implements(IHTTPException)
     component.adapts(z3c.dav.interfaces.IUnprocessableError,
-                     z3c.dav.interfaces.IHTTPRequest)
+                     zope.publisher.interfaces.http.IHTTPRequest)
 
     def __init__(self, context, request):
         self.context = context
@@ -232,10 +233,23 @@
         return ""
 
 
+class AlreadyLockedErrorView(object):
+    interface.implements(IHTTPException)
+    component.adapts(z3c.dav.interfaces.IAlreadyLocked,
+                     zope.publisher.interfaces.http.IHTTPRequest)
+
+    def __init__(self, context, request):
+        self.request = request
+
+    def __call__(self):
+        self.request.response.setStatus(423)
+        return ""
+
+
 class BadGateway(object):
     interface.implements(IHTTPException)
     component.adapts(z3c.dav.interfaces.IBadGateway,
-                     z3c.dav.interfaces.IHTTPRequest)
+                     zope.publisher.interfaces.http.IHTTPRequest)
 
     def __init__(self, error, request):
         self.error = error

Modified: z3c.dav/trunk/src/z3c/dav/exceptions/configure.zcml
===================================================================
--- z3c.dav/trunk/src/z3c/dav/exceptions/configure.zcml	2007-05-30 17:37:46 UTC (rev 76000)
+++ z3c.dav/trunk/src/z3c/dav/exceptions/configure.zcml	2007-05-30 18:05:58 UTC (rev 76001)
@@ -159,6 +159,20 @@
      name="index.html"
      />
 
+  <view
+     for="z3c.dav.interfaces.IAlreadyLocked"
+     type="zope.publisher.interfaces.http.IHTTPRequest"
+     name="index.html"
+     permission="zope.Public"
+     factory="z3c.dav.exceptions.AlreadyLockedErrorView"
+     />
+
+  <defaultView
+     for="z3c.dav.interfaces.IAlreadyLocked"
+     type="zope.publisher.interfaces.http.IHTTPRequest"
+     name="index.html"
+     />
+
   <adapter
      factory=".browser.default_template"
      name="default"

Modified: z3c.dav/trunk/src/z3c/dav/exceptions/tests/test_simpleviews.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/exceptions/tests/test_simpleviews.py	2007-05-30 17:37:46 UTC (rev 76000)
+++ z3c.dav/trunk/src/z3c/dav/exceptions/tests/test_simpleviews.py	2007-05-30 18:05:58 UTC (rev 76001)
@@ -18,7 +18,6 @@
 __docformat__ = 'restructuredtext'
 
 import unittest
-from cStringIO import StringIO
 from zope.app.testing.placelesssetup import PlacelessSetup
 from zope import component
 from zope import interface
@@ -27,13 +26,12 @@
 import z3c.dav.interfaces
 import z3c.dav.exceptions
 import z3c.dav.exceptions.browser
-from z3c.dav.publisher import WebDAVRequest
-from test_multiviews import TestRequest
+from zope.publisher.browser import TestRequest
 
 class TestExceptionViews(PlacelessSetup, unittest.TestCase):
 
     def test_unprocessable(self):
-        request = WebDAVRequest(StringIO(""), {})
+        request = TestRequest()
         error = z3c.dav.interfaces.UnprocessableError(None)
         view = z3c.dav.exceptions.UnprocessableError(error, request)
 
@@ -43,7 +41,7 @@
         self.assertEqual(result, "")
 
     def test_precondition(self):
-        request = WebDAVRequest(StringIO(""), {})
+        request = TestRequest()
         error = z3c.dav.interfaces.PreconditionFailed(None)
         view = z3c.dav.exceptions.PreconditionFailed(error, request)
 
@@ -53,7 +51,7 @@
         self.assertEqual(result, "")
 
     def test_badgateway(self):
-        request = WebDAVRequest(StringIO(""), {})
+        request = TestRequest()
         error = z3c.dav.interfaces.BadGateway(None, request)
         view = z3c.dav.exceptions.BadGateway(error, request)
 
@@ -63,7 +61,7 @@
         self.assertEqual(result, "")
 
     def test_conflicterror(self):
-        request = WebDAVRequest(StringIO(""), {})
+        request = TestRequest()
         error = z3c.dav.interfaces.ConflictError(None, request)
         view = z3c.dav.exceptions.HTTPConflictError(error, request)
 
@@ -73,7 +71,7 @@
         self.assertEqual(result, "")
 
     def test_forbiddenerror(self):
-        request = WebDAVRequest(StringIO(""), {})
+        request = TestRequest()
         error = z3c.dav.interfaces.ForbiddenError(None, request)
         view = z3c.dav.exceptions.HTTPForbiddenError(error, request)
 
@@ -83,7 +81,7 @@
         self.assertEqual(result, "")
 
     def test_unsupportedmediatype(self):
-        request = WebDAVRequest(StringIO(""), {})
+        request = TestRequest()
         error = z3c.dav.interfaces.UnsupportedMediaType(None, request)
         view = z3c.dav.exceptions.HTTPUnsupportedMediaTypeError(
             error, request)
@@ -93,7 +91,17 @@
         self.assertEqual(request.response.getStatus(), 415)
         self.assertEqual(result, "")
 
+    def test_alreadylocked(self):
+        request = TestRequest()
+        error = z3c.dav.interfaces.AlreadyLocked(None, "Alread locked")
+        view = z3c.dav.exceptions.AlreadyLockedErrorView(error, request)
 
+        result = view()
+
+        self.assertEqual(request.response.getStatus(), 423)
+        self.assertEqual(result, "")
+
+
 class TestDAVErrors(unittest.TestCase):
 
     def test_conflict_error(self):

Modified: z3c.dav/trunk/src/z3c/dav/interfaces.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/interfaces.py	2007-05-30 17:37:46 UTC (rev 76000)
+++ z3c.dav/trunk/src/z3c/dav/interfaces.py	2007-05-30 18:05:58 UTC (rev 76001)
@@ -201,7 +201,11 @@
         self.propertyname = None
         self.message = None
 
+    def __str__(self):
+        # This stops zope.app.error.error from failing in getPrintable
+        return "%r: %r" %(self.resource, self.message)
 
+
 class IWebDAVErrors(IFiniteSequence, IException):
     """
     List-like container of all exceptions that occured during the process



More information about the Checkins mailing list