[Checkins] SVN: zope.app.exception/branches/icemac_no_formlib/ removed zope.formlib dependency by using z3c.template

Michael Howitz mh at gocept.com
Tue Apr 7 14:34:20 EDT 2009


Log message for revision 98984:
  removed zope.formlib dependency by using z3c.template
  

Changed:
  U   zope.app.exception/branches/icemac_no_formlib/CHANGES.txt
  U   zope.app.exception/branches/icemac_no_formlib/setup.py
  U   zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/configure.zcml
  U   zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/tests/test_unauthorized.py
  U   zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/unauthorized.py
  U   zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/ftesting.zcml

-=-
Modified: zope.app.exception/branches/icemac_no_formlib/CHANGES.txt
===================================================================
--- zope.app.exception/branches/icemac_no_formlib/CHANGES.txt	2009-04-07 18:33:36 UTC (rev 98983)
+++ zope.app.exception/branches/icemac_no_formlib/CHANGES.txt	2009-04-07 18:34:20 UTC (rev 98984)
@@ -1,10 +1,11 @@
 CHANGES
 =======
 
-3.5.1 (unreleased)
+3.6.0 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- Got rid of ``zope.formlib`` dependency by using ``z3c.template`` for
+  the named template of the ``Unauthorized`` view.
 
 
 3.5.0 (2009-04-06)

Modified: zope.app.exception/branches/icemac_no_formlib/setup.py
===================================================================
--- zope.app.exception/branches/icemac_no_formlib/setup.py	2009-04-07 18:33:36 UTC (rev 98983)
+++ zope.app.exception/branches/icemac_no_formlib/setup.py	2009-04-07 18:34:20 UTC (rev 98984)
@@ -21,7 +21,7 @@
 def read(*rnames):
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
-version = '3.5.1dev'
+version = '3.6.0dev'
 
 setup(name='zope.app.exception',
       version=version,
@@ -61,8 +61,7 @@
       ]),
       install_requires=['setuptools',
                         'zope.app.pagetemplate',
-                        # This is a dependency we can avaid:
-                        'zope.formlib',
+                        'z3c.template',
                         'zope.interface',
                         'zope.publisher',
                         ],

Modified: zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/configure.zcml
===================================================================
--- zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/configure.zcml	2009-04-07 18:33:36 UTC (rev 98983)
+++ zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/configure.zcml	2009-04-07 18:34:20 UTC (rev 98984)
@@ -1,5 +1,6 @@
 <zope:configure
    xmlns:zope="http://namespaces.zope.org/zope"
+   xmlns:z3c="http://namespaces.zope.org/z3c"
    xmlns="http://namespaces.zope.org/browser">
 
   <page
@@ -17,7 +18,11 @@
       class=".unauthorized.Unauthorized"
       />
 
-  <zope:adapter factory=".unauthorized.default_template" name="default" />
+  <z3c:template
+     for=".unauthorized.Unauthorized"
+     template="unauthorized.pt"
+     name="default"
+      />
 
   <page
       for="zope.exceptions.interfaces.IUserError"

Modified: zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/tests/test_unauthorized.py
===================================================================
--- zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/tests/test_unauthorized.py	2009-04-07 18:33:36 UTC (rev 98983)
+++ zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/tests/test_unauthorized.py	2009-04-07 18:34:20 UTC (rev 98984)
@@ -17,13 +17,14 @@
 """
 from unittest import TestCase, main, makeSuite
 from zope import component, interface
-import zope.formlib.namedtemplate
+import z3c.template.interfaces
 from zope.publisher.browser import TestRequest
 from zope.authentication.interfaces import IAuthentication
 from zope.security.interfaces import IPrincipal
 from zope.app.testing import ztapi
 from zope.app.exception.browser.unauthorized import Unauthorized
 from zope.app.testing.placelesssetup import PlacelessSetup
+import zope.publisher.interfaces.browser
 
 class DummyPrincipal(object):
     interface.implements(IPrincipal)  # this is a lie
@@ -47,13 +48,14 @@
 
 class DummyTemplate (object):
 
-    def __init__(self, context):
+    def __init__(self, context, request):
         self.context = context
 
-    component.adapts(Unauthorized)
-    interface.implements(zope.formlib.namedtemplate.INamedTemplate)
+    component.adapts(Unauthorized,
+                     zope.publisher.interfaces.browser.IDefaultBrowserLayer)
+    interface.implements(z3c.template.interfaces.IContentTemplate)
 
-    def __call__(self):
+    def __call__(self, view):
         return 'You are not authorized'
 
 class Test(PlacelessSetup, TestCase):
@@ -83,7 +85,7 @@
 
         # Make sure the response status was set
         self.assertEqual(request.response.getStatus(), 403)
-        
+
         # check headers that work around squid "negative_ttl"
         self.assertEqual(request.response.getHeader('Expires'),
                          'Mon, 26 Jul 1997 05:00:00 GMT')
@@ -105,9 +107,9 @@
         request = TestRequest()
         request.setPrincipal(DummyPrincipal(23))
         u = Unauthorized(exception, request)
-        
+
         self.auth.status = 303
-        
+
         res = u()
 
         # Make sure that the template was not rendered

Modified: zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/unauthorized.py
===================================================================
--- zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/unauthorized.py	2009-04-07 18:33:36 UTC (rev 98983)
+++ zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/browser/unauthorized.py	2009-04-07 18:34:20 UTC (rev 98984)
@@ -20,8 +20,9 @@
 from zope.authentication.interfaces import IAuthentication
 from zope.publisher.browser import BrowserPage
 from zope.formlib import namedtemplate
-from zope.component import getUtility
+import zope.component
 from zope.app.pagetemplate import ViewPageTemplateFile
+import z3c.template.interfaces
 
 class Unauthorized(BrowserPage):
 
@@ -36,12 +37,10 @@
         self.request.response.setHeader('Pragma', 'no-cache')
 
         principal = self.request.principal
-        auth = getUtility(IAuthentication)
+        auth = zope.component.getUtility(IAuthentication)
         auth.unauthorized(principal.id, self.request)
         if self.request.response.getStatus() not in (302, 303):
-            return self.template()
-
-    template = namedtemplate.NamedTemplate('default')
-
-default_template = namedtemplate.NamedTemplateImplementation(
-    ViewPageTemplateFile('unauthorized.pt'), Unauthorized)
+            template = zope.component.getMultiAdapter(
+                (self, self.request), z3c.template.interfaces.IContentTemplate,
+                name='default')
+            return template(self)

Modified: zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/ftesting.zcml
===================================================================
--- zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/ftesting.zcml	2009-04-07 18:33:36 UTC (rev 98983)
+++ zope.app.exception/branches/icemac_no_formlib/src/zope/app/exception/ftesting.zcml	2009-04-07 18:34:20 UTC (rev 98984)
@@ -9,6 +9,7 @@
   <!-- used for functional testing setup -->
 
   <include package="zope.app.securitypolicy" file="meta.zcml" />
+  <include package="z3c.template" file="meta.zcml" />
 
   <include package="zope.app.zcmlfiles" />
   <include package="zope.app.authentication" />



More information about the Checkins mailing list