[Checkins] SVN: grok/trunk/ Use grokcore.security.

Philipp von Weitershausen philikon at philikon.de
Sun Aug 3 15:11:48 EDT 2008


Log message for revision 89307:
  Use grokcore.security.
  

Changed:
  U   grok/trunk/setup.py
  U   grok/trunk/src/grok/__init__.py
  U   grok/trunk/src/grok/components.py
  U   grok/trunk/src/grok/directive.py
  U   grok/trunk/src/grok/meta.py
  U   grok/trunk/src/grok/meta.zcml
  U   grok/trunk/src/grok/testing.py
  U   grok/trunk/src/grok/util.py
  U   grok/trunk/versions.cfg

-=-
Modified: grok/trunk/setup.py
===================================================================
--- grok/trunk/setup.py	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/setup.py	2008-08-03 19:11:43 UTC (rev 89307)
@@ -37,6 +37,7 @@
     install_requires=['setuptools',
                       'martian >= 0.10',
                       'grokcore.component >= 1.5',
+                      'grokcore.security',
                       'simplejson',
                       'pytz',
                       'ZODB3',

Modified: grok/trunk/src/grok/__init__.py
===================================================================
--- grok/trunk/src/grok/__init__.py	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/src/grok/__init__.py	2008-08-03 19:11:43 UTC (rev 89307)
@@ -25,6 +25,10 @@
 from grokcore.component.directive import (
     context, name, title, description, provides, global_utility, direct)
 
+from grokcore.security import Permission
+from grokcore.security import Public
+from grokcore.security import require
+
 from zope.event import notify
 from zope.app.component.hooks import getSite
 from zope.lifecycleevent import (
@@ -48,13 +52,13 @@
 from grok.components import Site, LocalUtility, Annotation
 from grok.components import Application, Form, AddForm, EditForm, DisplayForm
 from grok.components import Indexes
-from grok.components import Permission, Role, Public
+from grok.components import Role
 from grok.components import RESTProtocol, IRESTLayer
 from grok.interfaces import IRESTSkinType
 from grok.components import ViewletManager, Viewlet
 
 from grok.directive import (
-    template, templatedir, local_utility, permissions, require, site,
+    template, templatedir, local_utility, permissions, site,
     layer, viewletmanager, view, traversable, order, skin)
 
 # BBB These two functions are meant for test fixtures and should be

Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/src/grok/components.py	2008-08-03 19:11:43 UTC (rev 89307)
@@ -25,7 +25,6 @@
 from zope import component
 from zope import interface
 from zope.interface.common import idatetime
-from zope.security.permission import Permission
 from zope.securitypolicy.role import Role
 from zope.publisher.browser import BrowserPage
 from zope.publisher.interfaces import NotFound
@@ -644,11 +643,7 @@
 
 Indexes = IndexesClass('Indexes')
 
-class Permission(Permission):
-    pass
 
-Public = 'zope.Public'
-
 class Role(Role):
     pass
 

Modified: grok/trunk/src/grok/directive.py
===================================================================
--- grok/trunk/src/grok/directive.py	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/src/grok/directive.py	2008-08-03 19:11:43 UTC (rev 89307)
@@ -108,48 +108,6 @@
         return cmp(self.order, other.order)
 
 
-class RequireDirectiveStore(StoreMultipleTimes):
-
-    def get(self, directive, component, default):
-        permissions = getattr(component, directive.dotted_name(), default)
-        if (permissions is default) or not permissions:
-            return default
-        if len(permissions) > 1:
-            raise GrokError('grok.require was called multiple times in '
-                            '%r. It may only be set once for a class.'
-                            % component, component)
-        return permissions[0]
-
-    def pop(self, locals_, directive):
-        return locals_[directive.dotted_name()].pop()
-
-class require(martian.Directive):
-    scope = martian.CLASS
-    store = RequireDirectiveStore()
-
-    def validate(self, value):
-        if util.check_subclass(value, components.Permission):
-            return
-        if util.not_unicode_or_ascii(value):
-            raise GrokImportError(
-                "You can only pass unicode, ASCII, or a subclass "
-                "of grok.Permission to the '%s' directive." % self.name)
-
-    def factory(self, value):
-        if util.check_subclass(value, components.Permission):
-            return grok.name.bind().get(value)
-        return value
-
-    def __call__(self, func):
-        # grok.require can be used both as a class-level directive and
-        # as a decorator for methods.  Therefore we return a decorator
-        # here, which may be used for methods, or simply ignored when
-        # used as a directive.
-        frame = sys._getframe(1)
-        permission = self.store.pop(frame.f_locals, self)
-        self.set(func, [permission])
-        return func
-
 class site(martian.Directive):
     scope = martian.CLASS
     store = martian.ONCE

Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/src/grok/meta.py	2008-08-03 19:11:43 UTC (rev 89307)
@@ -26,7 +26,6 @@
 
 from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
 from zope.viewlet.interfaces import IViewletManager, IViewlet
-from zope.security.interfaces import IPermission
 from zope.securitypolicy.interfaces import IRole
 from zope.securitypolicy.rolepermission import rolePermissionManager
 
@@ -55,6 +54,7 @@
 from grok.interfaces import IViewletManager as IGrokViewletManager
 
 from grokcore.component.scan import determine_module_component
+from grokcore.security.meta import PermissionGrokker
 
 
 def default_view_name(factory, module=None, **data):
@@ -448,32 +448,6 @@
                                  name=name)
 
 
-class PermissionGrokker(martian.ClassGrokker):
-    martian.component(grok.Permission)
-    martian.priority(1500)
-    martian.directive(grok.name)
-    martian.directive(grok.title, get_default=default_fallback_to_name)
-    martian.directive(grok.description)
-
-    def execute(self, factory, config, name, title, description, **kw):
-        if not name:
-            raise GrokError(
-                "A permission needs to have a dotted name for its id. Use "
-                "grok.name to specify one.", factory)
-        # We can safely convert to unicode, since the directives make sure
-        # it is either unicode already or ASCII.
-        permission = factory(unicode(name), unicode(title),
-                             unicode(description))
-
-        config.action(
-            discriminator=('utility', IPermission, name),
-            callable=component.provideUtility,
-            args=(permission, IPermission, name),
-            order=-1 # need to do this early in the process
-            )
-        return True
-
-
 class RoleGrokker(martian.ClassGrokker):
     martian.component(grok.Role)
     martian.priority(martian.priority.bind().get(PermissionGrokker()) - 1)

Modified: grok/trunk/src/grok/meta.zcml
===================================================================
--- grok/trunk/src/grok/meta.zcml	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/src/grok/meta.zcml	2008-08-03 19:11:43 UTC (rev 89307)
@@ -7,6 +7,7 @@
 
   <!-- Load the grokkers -->
   <include package="grokcore.component" file="meta.zcml" />
+  <include package="grokcore.security" file="meta.zcml" />
   <grok:grok package=".meta" />
 
 </configure>

Modified: grok/trunk/src/grok/testing.py
===================================================================
--- grok/trunk/src/grok/testing.py	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/src/grok/testing.py	2008-08-03 19:11:43 UTC (rev 89307)
@@ -42,6 +42,7 @@
 def grok(module_name):
     config = ConfigurationMachine()
     zcml.do_grok('grokcore.component.meta', config)
+    zcml.do_grok('grokcore.security.meta', config)
     zcml.do_grok('grok.meta', config)
     zcml.do_grok('grok.templatereg', config)
     zcml.do_grok(module_name, config)

Modified: grok/trunk/src/grok/util.py
===================================================================
--- grok/trunk/src/grok/util.py	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/src/grok/util.py	2008-08-03 19:11:43 UTC (rev 89307)
@@ -13,7 +13,6 @@
 ##############################################################################
 """Grok utility functions.
 """
-
 import urllib
 
 import grok
@@ -22,12 +21,9 @@
 from zope import interface
 from zope.traversing.browser.interfaces import IAbsoluteURL
 from zope.traversing.browser.absoluteurl import _safe as SAFE_URL_CHARACTERS
-
 from zope.security.checker import NamesChecker, defineChecker
-from zope.security.interfaces import IPermission
 
-from martian.error import GrokError
-from martian.util import methods_from_class
+from grokcore.security.util import check_permission
 
 def make_checker(factory, view_factory, permission, method_names=None):
     """Make a checker for a view_factory associated with factory.
@@ -45,17 +41,6 @@
         checker = NamesChecker(method_names, permission)
     defineChecker(view_factory, checker)
 
-def check_permission(factory, permission):
-    """Check whether a permission is defined.
-
-    If not, raise error for factory.
-    """
-    if component.queryUtility(IPermission,
-                              name=permission) is None:
-       raise GrokError('Undefined permission %r in %r. Use '
-                       'grok.Permission first.'
-                       % (permission, factory), factory)
-
 def url(request, obj, name=None, data={}):
     url = component.getMultiAdapter((obj, request), IAbsoluteURL)()
     if name is not None:

Modified: grok/trunk/versions.cfg
===================================================================
--- grok/trunk/versions.cfg	2008-08-03 19:01:32 UTC (rev 89306)
+++ grok/trunk/versions.cfg	2008-08-03 19:11:43 UTC (rev 89307)
@@ -7,6 +7,7 @@
 docutils = 0.4
 martian = 0.10
 grokcore.component = 1.5.1
+grokcore.security = 1.0
 mechanize = 0.1.7b
 pytz = 2007k
 simplejson = 1.7.1



More information about the Checkins mailing list