[Checkins] SVN: zope.viewlet/trunk/ Removed the dependency on `zope.app.publisher` by moving four simple helper functions into this package and making the interface for describing the ZCML content provider directive explicit.

Hanno Schlichting plone at hannosch.info
Wed Jan 7 14:45:14 EST 2009


Log message for revision 94597:
  Removed the dependency on `zope.app.publisher` by moving four simple helper functions into this package and making the interface for describing the ZCML content provider directive explicit.
  

Changed:
  U   zope.viewlet/trunk/CHANGES.txt
  U   zope.viewlet/trunk/setup.py
  U   zope.viewlet/trunk/src/zope/viewlet/metaconfigure.py
  U   zope.viewlet/trunk/src/zope/viewlet/metadirectives.py

-=-
Modified: zope.viewlet/trunk/CHANGES.txt
===================================================================
--- zope.viewlet/trunk/CHANGES.txt	2009-01-07 18:38:18 UTC (rev 94596)
+++ zope.viewlet/trunk/CHANGES.txt	2009-01-07 19:45:13 UTC (rev 94597)
@@ -2,11 +2,16 @@
 CHANGES
 =======
 
-3.4.3 (unreleased)
+3.5.0 (unreleased)
 ------------------
 
+- Removed the dependency on `zope.app.publisher` by moving four simple helper
+  functions into this package and making the interface for describing the
+  ZCML content provider directive explicit.
+
 - Typo fix in CSSViewlet docstring.
 
+
 3.4.2 (2008-01-24)
 ------------------
 

Modified: zope.viewlet/trunk/setup.py
===================================================================
--- zope.viewlet/trunk/setup.py	2009-01-07 18:38:18 UTC (rev 94596)
+++ zope.viewlet/trunk/setup.py	2009-01-07 19:45:13 UTC (rev 94597)
@@ -22,7 +22,7 @@
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
 setup(name='zope.viewlet',
-      version = '3.4.3dev',
+      version = '3.5.0dev',
       author='Zope Corporation and Contributors',
       author_email='zope3-dev at zope.org',
       description='Zope Viewlets',
@@ -62,7 +62,6 @@
       install_requires=[
           'setuptools',
           'zope.app.pagetemplate',
-          'zope.app.publisher',
           'zope.component',
           'zope.configuration',
           'zope.contentprovider',

Modified: zope.viewlet/trunk/src/zope/viewlet/metaconfigure.py
===================================================================
--- zope.viewlet/trunk/src/zope/viewlet/metaconfigure.py	2009-01-07 18:38:18 UTC (rev 94596)
+++ zope.viewlet/trunk/src/zope/viewlet/metaconfigure.py	2009-01-07 19:45:13 UTC (rev 94597)
@@ -23,12 +23,12 @@
 from zope.configuration.exceptions import ConfigurationError
 from zope.interface import Interface, classImplements
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from zope.publisher.interfaces.browser import IBrowserPublisher
 from zope.publisher.interfaces.browser import IBrowserView
 from zope.component import zcml
+from zope.component.interface import provideInterface
 from zope.viewlet import viewlet, manager, interfaces
 
-from zope.app.publisher.browser import viewmeta
-
 def viewletManagerDirective(
     _context, name, permission,
     for_=Interface, layer=IDefaultBrowserLayer, view=IBrowserView,
@@ -39,7 +39,7 @@
     required = {}
 
     # Get the permission; mainly to correctly handle CheckerPublic.
-    permission = viewmeta._handle_permission(_context, permission)
+    permission = _handle_permission(_context, permission)
 
     # If class is not given we use the basic viewlet manager.
     if class_ is None:
@@ -66,19 +66,19 @@
 
     # Register the ``provides`` interface and register fields in the security
     # dictionary
-    viewmeta._handle_allowed_interface(
+    _handle_allowed_interface(
         _context, (provides,), permission, required)
 
     # Register the allowed interface and add the field's security entries
-    viewmeta._handle_allowed_interface(
+    _handle_allowed_interface(
         _context, allowed_interface, permission, required)
 
     # Register single allowed attributes in the security dictionary
-    viewmeta._handle_allowed_attributes(
+    _handle_allowed_attributes(
         _context, allowed_attributes, permission, required)
 
     # Register interfaces
-    viewmeta._handle_for(_context, for_)
+    _handle_for(_context, for_)
     zcml.interface(_context, view)
 
     # Create a checker for the viewlet manager
@@ -104,7 +104,7 @@
     required = {}
 
     # Get the permission; mainly to correctly handle CheckerPublic.
-    permission = viewmeta._handle_permission(_context, permission)
+    permission = _handle_permission(_context, permission)
 
     # Either the class or template must be specified.
     if not (class_ or template):
@@ -162,19 +162,19 @@
                                                attributes=kwargs)
 
     # Set up permission mapping for various accessible attributes
-    viewmeta._handle_allowed_interface(
+    _handle_allowed_interface(
         _context, allowed_interface, permission, required)
-    viewmeta._handle_allowed_attributes(
+    _handle_allowed_attributes(
         _context, allowed_attributes, permission, required)
-    viewmeta._handle_allowed_attributes(
+    _handle_allowed_attributes(
         _context, kwargs.keys(), permission, required)
-    viewmeta._handle_allowed_attributes(
+    _handle_allowed_attributes(
         _context,
         (attribute, 'browserDefault', 'update', 'render', 'publishTraverse'),
         permission, required)
 
     # Register the interfaces.
-    viewmeta._handle_for(_context, for_)
+    _handle_for(_context, for_)
     zcml.interface(_context, view)
 
     # Create the security checker for the new class
@@ -187,3 +187,38 @@
         args = ('registerAdapter',
                 new_class, (for_, layer, view, manager), interfaces.IViewlet,
                  name, _context.info),)
+
+def _handle_permission(_context, permission):
+    if permission == 'zope.Public':
+        permission = checker.CheckerPublic
+
+    return permission
+
+def _handle_allowed_interface(_context, allowed_interface, permission,
+                              required):
+    # Allow access for all names defined by named interfaces
+    if allowed_interface:
+        for i in allowed_interface:
+            _context.action(
+                discriminator = None,
+                callable = provideInterface,
+                args = (None, i)
+                )
+
+            for name in i:
+                required[name] = permission
+
+def _handle_allowed_attributes(_context, allowed_attributes, permission,
+                               required):
+    # Allow access for all named attributes
+    if allowed_attributes:
+        for name in allowed_attributes:
+            required[name] = permission
+
+def _handle_for(_context, for_):
+    if for_ is not None:
+        _context.action(
+            discriminator = None,
+            callable = provideInterface,
+            args = ('', for_)
+            )

Modified: zope.viewlet/trunk/src/zope/viewlet/metadirectives.py
===================================================================
--- zope.viewlet/trunk/src/zope/viewlet/metadirectives.py	2009-01-07 18:38:18 UTC (rev 94596)
+++ zope.viewlet/trunk/src/zope/viewlet/metadirectives.py	2009-01-07 19:45:13 UTC (rev 94597)
@@ -20,14 +20,15 @@
 import zope.configuration.fields
 import zope.schema
 from zope.publisher.interfaces import browser
+from zope.security.zcml import Permission
 from zope.i18nmessageid import MessageFactory
+from zope.interface import Interface
 _ = MessageFactory('zope')
 
-from zope.app.publisher.browser import metadirectives
 from zope.viewlet import interfaces
 
 
-class IContentProvider(metadirectives.IPagesDirective):
+class IContentProvider(Interface):
     """A directive to register a simple content provider.
 
     Content providers are registered by their context (`for` attribute), the
@@ -52,7 +53,59 @@
                       "provider."),
         required=True)
 
+    for_ = zope.configuration.fields.GlobalObject(
+        title=u"The interface or class this view is for.",
+        required=False
+        )
 
+    permission = Permission(
+        title=u"Permission",
+        description=u"The permission needed to use the view.",
+        required=True
+        )
+
+    class_ = zope.configuration.fields.GlobalObject(
+        title=_("Class"),
+        description=_("A class that provides attributes used by the view."),
+        required=False,
+        )
+
+    layer = zope.configuration.fields.GlobalInterface(
+        title=_("The layer the view is in."),
+        description=_("""
+        A skin is composed of layers. It is common to put skin
+        specific views in a layer named after the skin. If the 'layer'
+        attribute is not supplied, it defaults to 'default'."""),
+        required=False,
+        )
+
+    allowed_interface = zope.configuration.fields.Tokens(
+        title=_("Interface that is also allowed if user has permission."),
+        description=_("""
+        By default, 'permission' only applies to viewing the view and
+        any possible sub views. By specifying this attribute, you can
+        make the permission also apply to everything described in the
+        supplied interface.
+
+        Multiple interfaces can be provided, separated by
+        whitespace."""),
+        required=False,
+        value_type=zope.configuration.fields.GlobalInterface(),
+        )
+
+    allowed_attributes = zope.configuration.fields.Tokens(
+        title=_("View attributes that are also allowed if the user"
+                " has permission."),
+        description=_("""
+        By default, 'permission' only applies to viewing the view and
+        any possible sub views. By specifying 'allowed_attributes',
+        you can make the permission also apply to the extra attributes
+        on the view object."""),
+        required=False,
+        value_type=zope.configuration.fields.PythonIdentifier(),
+        )
+
+
 class ITemplatedContentProvider(IContentProvider):
     """A directive for registering a content provider that uses a page
     template to provide its content."""



More information about the Checkins mailing list