[Zope-CVS] SVN: book/trunk/exceptionview/ This is the code that
goes with the "Exception Views" chapter.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Aug 23 11:47:35 EDT 2004
Log message for revision 27227:
This is the code that goes with the "Exception Views" chapter.
Changed:
A book/trunk/exceptionview/
A book/trunk/exceptionview/__init__.py
A book/trunk/exceptionview/browser.py
A book/trunk/exceptionview/configure.zcml
A book/trunk/exceptionview/error.pt
A book/trunk/exceptionview/ftests.py
A book/trunk/exceptionview/interfaces.py
-=-
Added: book/trunk/exceptionview/__init__.py
===================================================================
--- book/trunk/exceptionview/__init__.py 2004-08-23 15:11:13 UTC (rev 27226)
+++ book/trunk/exceptionview/__init__.py 2004-08-23 15:47:34 UTC (rev 27227)
@@ -0,0 +1 @@
+# Make this directory a package
Added: book/trunk/exceptionview/browser.py
===================================================================
--- book/trunk/exceptionview/browser.py 2004-08-23 15:11:13 UTC (rev 27226)
+++ book/trunk/exceptionview/browser.py 2004-08-23 15:47:34 UTC (rev 27227)
@@ -0,0 +1,32 @@
+##############################################################################
+#
+# Copyright (c) 2004 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-raising View
+
+$Id$
+"""
+from book.exceptionview.interfaces import PaymentException
+
+class PaymentExceptionView(object):
+ """This is a view for `IPaymentException` exceptions."""
+
+ def __call__(self, *args, **kw):
+ self.request.response.setStatus(402)
+ return self.index(*args, **kw)
+
+
+class RaiseExceptionView(object):
+ """The view that raises the exception"""
+
+ def raisePaymentException(self):
+ raise PaymentException, 'An application error occured'
Added: book/trunk/exceptionview/configure.zcml
===================================================================
--- book/trunk/exceptionview/configure.zcml 2004-08-23 15:11:13 UTC (rev 27226)
+++ book/trunk/exceptionview/configure.zcml 2004-08-23 15:47:34 UTC (rev 27227)
@@ -0,0 +1,21 @@
+<configure
+ xmlns="http://namespaces.zope.org/browser"
+ i18n_domain="exceptionview">
+
+ <page
+ name="index.html"
+ template="error.pt"
+ for=".interfaces.IPaymentException"
+ class=".browser.PaymentExceptionView"
+ permission="zope.Public"
+ />
+
+ <page
+ name="raiseError.html"
+ for="zope.app.folder.interfaces.IFolder"
+ class=".browser.RaiseExceptionView"
+ attribute="raisePaymentException"
+ permission="zope.View"
+ />
+
+</configure>
Added: book/trunk/exceptionview/error.pt
===================================================================
--- book/trunk/exceptionview/error.pt 2004-08-23 15:11:13 UTC (rev 27226)
+++ book/trunk/exceptionview/error.pt 2004-08-23 15:47:34 UTC (rev 27227)
@@ -0,0 +1,12 @@
+ <html metal:use-macro="context/@@standard_macros/dialog">
+ <body>
+ <div metal:fill-slot="body">
+
+ <h1>402 - Payment Required</h1>
+
+ <p>Before you can use this feature of the site, you have to make a
+ payment to Stephan Richter.</p>
+
+ </div>
+ </body>
+ </html>
Added: book/trunk/exceptionview/ftests.py
===================================================================
--- book/trunk/exceptionview/ftests.py 2004-08-23 15:11:13 UTC (rev 27226)
+++ book/trunk/exceptionview/ftests.py 2004-08-23 15:47:34 UTC (rev 27227)
@@ -0,0 +1,40 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Functional tests for Payment Exception view
+
+$Id$
+"""
+import unittest
+
+from zope.app.tests.functional import BrowserTestCase
+
+
+class Test(BrowserTestCase):
+
+ def test_PaymentErrorView(self):
+ response = self.publish("/raiseError.html", handle_errors=True)
+
+ self.assertEqual(response.getStatus(), 402)
+ body = response.getBody()
+ self.assert_('402 - Payment Required' in body)
+ self.assert_('payment to Stephan Richter' in body)
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ unittest.main(defaultTest='test_suite')
Added: book/trunk/exceptionview/interfaces.py
===================================================================
--- book/trunk/exceptionview/interfaces.py 2004-08-23 15:11:13 UTC (rev 27226)
+++ book/trunk/exceptionview/interfaces.py 2004-08-23 15:47:34 UTC (rev 27227)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Interfaces
+
+$Id$
+"""
+from zope.interface import implements
+from zope.interface.common.interfaces import IException
+
+class IPaymentException(IException):
+ """This is an exception that can be raised by my application."""
+
+class PaymentException(Exception):
+ implements(IPaymentException)
+
+ # We really do nothing here.
More information about the Zope-CVS
mailing list