Commits

Laurence Rowe committed 1497ce0 Draft

Degrok.

Comments (0)

Files changed (8)

       zip_safe=False,
       install_requires=[
         'Zope2 >= 2.12.4',
-        'five.grok',
         'setuptools',
         'zope.event',
         'zope.interface',

src/infrae/wsgi/authenticator.py

 # Copyright (c) 2011-2012 Infrae. All rights reserved.
 # See also LICENSE.txt
 
-from five import grok
+from zope.component import adapter
 from zope.interface import Interface
+from zope.interface import implementer
 from infrae.wsgi.interfaces import IRequest, IAuthenticator
 
 from ZPublisher.BaseRequest import UNSPECIFIED_ROLES, old_validation
 from zExceptions import Unauthorized
 
 
-class ZopeAuthenticator(grok.MultiAdapter):
+@adapter(Interface, IRequest)
+@implementer(IAuthenticator)
+class ZopeAuthenticator(object):
     """After traversing, authenticate using Zope method.
     """
-    grok.adapts(Interface, IRequest)
-    grok.provides(IAuthenticator)
-    grok.implements(IAuthenticator)
 
     def __init__(self, context, request):
         self.context = context

src/infrae/wsgi/configure.zcml

 <configure
-   xmlns="http://namespaces.zope.org/zope"
-   xmlns:grok="http://namespaces.zope.org/grok">
+  xmlns="http://namespaces.zope.org/zope"
+  xmlns:browser="http://namespaces.zope.org/browser">
 
-  <include package="five.grok" />
+  <include package="Products.Five"/>
 
-  <!-- Grok this package -->
-  <grok:grok package="." />
+  <browser:view
+    class=".debugging.DebugThreads"
+    for="*"
+    name="debugzope.html"
+    permission="zope2.ViewManagementScreens"
+    />
+
+  <browser:page
+    class=".log.ErrorLogView"
+    for="*"
+    name="errorlog.html"
+    permission="zope2.ViewManagementScreens"
+    template="log_templates/errorlogview.pt"
+    />
+
+  <adapter factory=".authenticator.ZopeAuthenticator"/>
+
+
+  <!--
+    The default Zope 3 folder traverser is register in Zope
+    2.13.13. We register the Zope 2 one for Zope 2 folder, to prevent
+    a broken ZMI.
+    -->
+
+  <adapter
+    factory="ZPublisher.BaseRequest.DefaultPublishTraverse"
+    for="OFS.interfaces.IObjectManager
+         infrae.wsgi.interfaces.IRequest"
+    provides="zope.publisher.interfaces.browser.IBrowserPublisher"
+    />
+
+  <adapter factory=".traverser.Traverser"/>
+
+  <adapter factory=".virtualhosting.VirtualHosting"/>
+
+  <!-- Error views -->
+
+  <browser:view
+    class=".errors.NotFound"
+    for="zope.publisher.interfaces.INotFound"
+    layer="zope.publisher.interfaces.browser.IBrowserRequest"
+    name="error.html"
+    permission="zope.Public"
+    />
+
+  <browser:view
+    class=".errors.Forbidden"
+    for="zope.security.interfaces.IForbidden"
+    layer="zope.publisher.interfaces.browser.IBrowserRequest"
+    name="error.html"
+    permission="zope.Public"
+    />
+
+<!-- browser:view needs an interface for @for
+
+  <browser:view
+    class=".errors.BadRequest"
+    for="zExceptions.BadRequest"
+    layer="zope.publisher.interfaces.browser.IBrowserRequest"
+    name="error.html"
+    permission="zope.Public"
+    />
+-->
+
+  <adapter
+    factory=".errors.BadRequest"
+    for="zExceptions.BadRequest
+         zope.publisher.interfaces.browser.IBrowserRequest"
+    name="error.html"
+    provides="zope.interface.Interface"
+    />
+
+  <browser:view
+    class=".errors.Error"
+    for="zope.interface.common.interfaces.IException"
+    layer="zope.publisher.interfaces.browser.IBrowserRequest"
+    name="error.html"
+    permission="zope.Public"
+    />
 
 </configure>

src/infrae/wsgi/debugging.py

 # Copyright (c) 2012  Infrae. All rights reserved.
 # See also LICENSE.txt
 
-from five import grok
-from zope.interface import Interface
+from zope.publisher.browser import BrowserView
 
 import thread
 import sys
     return '\n'.join(res)
 
 
-class DebugThreads(grok.View):
-    grok.context(Interface)
-    grok.name('debugzope.html')
-    grok.require('zope2.ViewManagementScreens')
+class DebugThreads(BrowserView):
 
-    def render(self):
+    def __call__(self):
         return u'<html><body><pre>%s</pre></body></html>' % dump_threads()
 
 

src/infrae/wsgi/errors.py

 # Copyright (c) 2010-2012 Infrae. All rights reserved.
 # See also LICENSE.txt
 
-from five import grok
 from zope.interface import providedBy
-from zope.publisher.interfaces import INotFound
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.security.interfaces import IForbidden
+from zope.publisher.browser import BrowserView
 
 from AccessControl import ClassSecurityInfo
 from App.class_init import InitializeClass
 import Acquisition
-import zExceptions
 
-grok.layer(IBrowserRequest)
 
 HTML_TEMPLATE = u"""
 <html>
 </html>
 """
 
+
 class DefaultError(Acquisition.Implicit):
     """Wrapper for errors. The are the context, with all acquisition
     and Zope Component Architecture working.
 InitializeClass(DefaultError)
 
 
-class NotFound(grok.View):
-    grok.name('error.html')
-    grok.context(INotFound)
+class NotFound(BrowserView):
 
-    def update(self):
-        self.response.setStatus(404)
-
-    def render(self):
+    def __call__(self):
+        self.request.response.setStatus(404)
         return HTML_TEMPLATE % (
-            self.__class__.__name__, 'Page not found: %s' %
+            'NotFound', 'Page not found: %s' %
             str(self.context.error))
 
 
-class Forbidden(grok.View):
-    grok.name('error.html')
-    grok.context(IForbidden)
+class Forbidden(BrowserView):
 
-    def update(self):
-        self.response.setStatus(403)
+    def __call__(self):
+        self.request.response.setStatus(403)
+        return HTML_TEMPLATE % (
+            'Forbidden', str(self.context.error))
 
-    def render(self):
+
+class BadRequest(BrowserView):
+
+    def __call__(self):
+        self.request.response.setStatus(400)
         return HTML_TEMPLATE % (
-            self.__class__.__name__, str(self.context.error))
+            'BadRequest', str(self.context.error))
 
 
-class BadRequest(grok.View):
-    grok.name('error.html')
-    grok.context(zExceptions.BadRequest)
+class Error(BrowserView):
 
-    def update(self):
-        self.response.setStatus(400)
-
-    def render(self):
-        return HTML_TEMPLATE % (
-            self.__class__.__name__, 'Bad request: %s' %
-            str(self.context.error))
-
-
-class Error(grok.View):
-    grok.name('error.html')
-    grok.context(Exception)
-
-    def update(self):
-        self.response.setStatus(500)
-
-    def render(self):
+    def __call__(self):
+        self.request.response.setStatus(500)
         return HTML_TEMPLATE % (
             self.context.error.__class__.__name__, str(self.context.error))

src/infrae/wsgi/log.py

 
 from zExceptions.ExceptionFormatter import format_exception
 from zope.browser.interfaces import IView
-from zope.interface import Interface
-from five import grok
-import App.config
+from zope.publisher.browser import BrowserPage
 
 from infrae.wsgi.utils import reconstruct_url_from_environ
 
         (object_name(data), reconstruct_url_from_environ(environ)))
 
 
-class ErrorLogView(grok.View):
-    grok.context(Interface)
-    grok.name('errorlog.html')
-    grok.require('zope2.ViewManagementScreens')
+class ErrorLogView(BrowserPage):
 
-    def update(self):
+    def __call__(self):
         if 'ignore_errors_update' in self.request.form:
             reporter.ignore_errors = self.request.form.get(
                 'ignore_errors', [])
         self.errors = reporter.get_last_errors()
         self.debug_mode = self.request.response.debug_mode
 
+        return self.index()
+
 
 class ErrorSupplement(object):
     """Add more information about an error on a view in a traceback.

src/infrae/wsgi/traverser.py

 # Copyright (c) 2011-2012 Infrae. All rights reserved.
 # See also LICENSE.txt
 
-from five import grok
+from zope.component import adapter
 from zope.component import queryMultiAdapter
 from zope.interface import Interface
+from zope.interface import implementer
 from zope.publisher.interfaces import NotFound
 from zope.publisher.interfaces.browser import IBrowserPublisher
 
 from AccessControl.ZopeSecurityPolicy import getRoles
 from ZPublisher.BaseRequest import UNSPECIFIED_ROLES, DefaultPublishTraverse
 from ZPublisher.BaseRequest import quote
-from OFS.interfaces import IObjectManager
 import zExceptions
 
 from infrae.wsgi.interfaces import IRequest, ITraverser
 
 
-class ObjectManagerPublishTraverse(DefaultPublishTraverse, grok.MultiAdapter):
-    """The default Zope 3 folder traverser is register in Zope
-    2.13.13. We register the Zope 2 one for Zope 2 folder, to prevent
-    a broken ZMI.
-    """
-    grok.adapts(IObjectManager, IRequest)
-    grok.provides(IBrowserPublisher)
-
-
 def query_adapter(content, request, iface):
     """Query an adapter if needed.
     """
     return adapter
 
 
-class Traverser(grok.MultiAdapter):
-    grok.adapts(Interface, IRequest)
-    grok.provides(ITraverser)
-    grok.implements(ITraverser)
+@adapter(Interface, IRequest)
+@implementer(ITraverser)
+class Traverser(object):
 
     def __init__(self, context, request):
         self.request = request

src/infrae/wsgi/virtualhosting.py

 import urlparse
 from urllib import quote
 
-from five import grok
+from zope.component import adapter
 from zope.interface import Interface
+from zope.interface import implementer
 
 import zExceptions
 
 from infrae.wsgi.utils import split_path_info, traverse
 
 
-class VirtualHosting(grok.MultiAdapter):
-    grok.adapts(Interface, IRequest)
-    grok.provides(IVirtualHosting)
-    grok.implements(IVirtualHosting)
+@adapter(Interface, IRequest)
+@implementer(IVirtualHosting)
+class VirtualHosting(object):
 
     def __init__(self, context, request):
         self.context = context