[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/ Move Permission implementation to zope.security. It's reusable.

Philipp von Weitershausen philikon at philikon.de
Wed Apr 12 18:17:38 EDT 2006


Log message for revision 66918:
  Move Permission implementation to zope.security. It's reusable.
  Also correct imports of IPermission. It's in zope.security.interfaces,
  not in zope.app.security.interfaces.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/app/onlinehelp/tests/test_helpdirectives.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menu.txt
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/browser/tests/test_directives.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/configure.zcml
  U   Zope3/branches/jim-adapter/src/zope/app/security/fields.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/metaconfigure.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/permission.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/tests/__init__.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectclass.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectsubclass.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/vocabulary.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/ftests.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/granting.txt
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/principalpermission.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/rolepermission.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationprincipalpermissionmanager.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationrolepermissionmanager.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_principalpermissionmanager.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_rolepermissionmanager.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_securitydirectives.py
  U   Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py
  U   Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_xmlimportexport.py
  A   Zope3/branches/jim-adapter/src/zope/security/permission.py
  A   Zope3/branches/jim-adapter/src/zope/security/tests/test_permission.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/onlinehelp/tests/test_helpdirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/onlinehelp/tests/test_helpdirectives.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/onlinehelp/tests/test_helpdirectives.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -26,6 +26,8 @@
 from zope.traversing.interfaces import ITraverser, ITraversable
 from zope.traversing.adapters import Traverser, DefaultTraversable
 from zope.location.traversing import LocationPhysicallyLocatable
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 
 import zope.app.component
 import zope.app.security
@@ -36,8 +38,6 @@
 from zope.app.onlinehelp.onlinehelptopic import RESTOnlineHelpTopic
 from zope.app.onlinehelp.onlinehelptopic import STXOnlineHelpTopic
 from zope.app.onlinehelp.onlinehelptopic import ZPTOnlineHelpTopic
-from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
 from zope.app.testing import ztapi, placelesssetup
 
 

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menu.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menu.txt	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menu.txt	2006-04-12 22:17:35 UTC (rev 66918)
@@ -117,9 +117,9 @@
 item itself, or (2) the filter returns ``False``, in which case the menu
 item should also not be shown. 
 
+  >>> from zope.security.interfaces import IPermission
+  >>> from zope.security.permission import Permission
   >>> from zope.app.testing import ztapi
-  >>> from zope.app.security.interfaces import IPermission
-  >>> from zope.app.security.permission import Permission
   >>> perm = Permission('perm', 'Permission')
   >>> ztapi.provideUtility(IPermission, perm, 'perm')
 

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/tests/test_directives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/tests/test_directives.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/tests/test_directives.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -30,6 +30,8 @@
 from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.interfaces.browser import IBrowserSkinType, IDefaultSkin
 from zope.security.proxy import removeSecurityProxy, ProxyFactory
+from zope.security.permission import Permission 
+from zope.security.interfaces import IPermission 
 from zope.testing.doctestunit import DocTestSuite
 from zope.traversing.adapters import DefaultTraversable
 from zope.traversing.interfaces import ITraversable
@@ -41,8 +43,6 @@
 from zope.app.publisher.browser.i18nfileresource import I18nFileResource
 from zope.app.publisher.browser.menu import getFirstMenuItem
 from zope.app.publisher.interfaces.browser import IMenuItemType
-from zope.app.security.permission import Permission 
-from zope.app.security.interfaces import IPermission 
 from zope.app.testing import placelesssetup, ztapi
 
 tests_path = os.path.join(

Modified: Zope3/branches/jim-adapter/src/zope/app/security/configure.zcml
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/configure.zcml	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/configure.zcml	2006-04-12 22:17:35 UTC (rev 66918)
@@ -32,11 +32,11 @@
         id="zope.app.security.Permission"
         />
     <allow
-        interface=".interfaces.IPermission"
+        interface="zope.security.interfaces.IPermission"
         />
     <require
         permission="zope.Security"
-        set_schema=".interfaces.IPermission"
+        set_schema="zope.security.interfaces.IPermission"
         />
   </localUtility>
 
@@ -52,8 +52,8 @@
      handler=".permission.unsetIdOnDeactivation"
      />
 
-  <class class=".permission.Permission">
-    <allow interface=".interfaces.IPermission" />
+  <class class="zope.security.permission.Permission">
+    <allow interface="zope.security.interfaces.IPermission" />
   </class>
 
   <class class=".principalregistry.Principal">

Modified: Zope3/branches/jim-adapter/src/zope/app/security/fields.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/fields.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/fields.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -19,7 +19,7 @@
 from zope import schema
 from zope.interface import implements
 from zope.schema.interfaces import IFromUnicode
-from zope.app.security.permission import checkPermission
+from zope.security.permission import checkPermission
 
 class Permission(schema.Id):
     r"""This field describes a permission.

Modified: Zope3/branches/jim-adapter/src/zope/app/security/metaconfigure.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/metaconfigure.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/metaconfigure.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -21,8 +21,8 @@
 from zope.security.checker import CheckerPublic
 from zope.security.management import setSecurityPolicy
 from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 
-from zope.app.security.permission import Permission
 from zope.app.security import principalregistry
 from zope.app.security import interfaces
 

Modified: Zope3/branches/jim-adapter/src/zope/app/security/permission.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/permission.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/permission.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -17,24 +17,15 @@
 """
 from persistent import Persistent
 from zope.interface import implements
-from zope.component import queryUtility, getUtilitiesFor
-from zope.schema.interfaces import ValidationError
-from zope.security.checker import CheckerPublic
 from zope.location import Location
 from zope.security.interfaces import IPermission
 
 from zope.app.i18n import ZopeMessageFactory as _
 NULL_ID = _('<permission not activated>')
 
-class Permission(object):
-    implements(IPermission)
+#BBB XXX
+#from zope.security.permission import Permission, checkPermission, allPermissions
 
-    def __init__(self, id, title="", description=""):
-        self.id = id
-        self.title = title
-        self.description = description
-
-
 class LocalPermission(Persistent, Location):
     implements(IPermission)
 
@@ -99,47 +90,3 @@
     u'<permission not activated>'
     """
     permission.id = NULL_ID
-
-
-def checkPermission(context, permission_id):
-    """Check whether a given permission exists in the provided context.
-
-    >>> from zope.app.testing.placelesssetup import setUp, tearDown
-    >>> setUp()
-
-    >>> from zope.app.testing.ztapi import provideUtility
-    >>> provideUtility(IPermission, Permission('x'), 'x')
-
-    >>> checkPermission(None, 'x')
-    >>> checkPermission(None, 'y')
-    Traceback (most recent call last):
-    ...
-    ValueError: ('Undefined permission id', 'y')
-
-    >>> tearDown()
-    """
-    if permission_id is CheckerPublic:
-        return
-    if not queryUtility(IPermission, permission_id, context=context):
-        raise ValueError("Undefined permission id", permission_id)
-
-def allPermissions(context=None):
-    """Get the ids of all defined permissions
-
-    >>> from zope.app.testing.placelesssetup import setUp, tearDown
-    >>> setUp()
-
-    >>> from zope.app.testing.ztapi import provideUtility
-    >>> provideUtility(IPermission, Permission('x'), 'x')
-    >>> provideUtility(IPermission, Permission('y'), 'y')
-
-    >>> ids = list(allPermissions(None))
-    >>> ids.sort()
-    >>> ids
-    [u'x', u'y']
-
-    >>> tearDown()
-    """
-    for id, permission in getUtilitiesFor(IPermission, context):
-        if id != u'zope.Public':
-            yield id

Modified: Zope3/branches/jim-adapter/src/zope/app/security/tests/__init__.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/tests/__init__.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/tests/__init__.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -15,9 +15,9 @@
 
 $Id$
 """
-from zope.app import zapi
-from zope.app.security.permission import Permission
-from zope.app.security.interfaces import IPermission
+import zope.component
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 
 def addCheckerPublic():
     """Add the CheckerPublic permission as 'zope.Public'"""
@@ -29,5 +29,5 @@
             it allows security computation to be bypassed.
             """
             )
-    gsm = zapi.getGlobalSiteManager()
+    gsm = zope.component.getGlobalSiteManager()
     gsm.registerUtility(perm, IPermission, perm.id)

Modified: Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -20,15 +20,14 @@
 from zope.interface import Interface, Attribute
 from zope.testing import doctest
 from zope.configuration import xmlconfig
+from zope.security.checker import moduleChecker
+from zope.security.permission import Permission
 
 import zope.app.security
-from zope.security.checker import moduleChecker
 from zope.app.testing import ztapi
 from zope.app.testing.placelesssetup import setUp, tearDown, PlacelessSetup
 from zope.app.security import metaconfigure
 from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
-from zope.configuration import xmlconfig
 from zope.app.security import fields
 
 def pprint(ob, width=70):

Modified: Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectclass.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectclass.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectclass.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -18,10 +18,10 @@
 import unittest
 from zope.interface import implements
 from zope.security.checker import selectChecker
+from zope.security.permission import Permission
 from zope.app.testing import ztapi
 from zope.app.testing.placelesssetup import PlacelessSetup
 
-from zope.app.security.permission import Permission
 from zope.app.security.interfaces import IPermission
 from zope.app.security.protectclass import protectName, protectLikeUnto
 from zope.app.security.protectclass import protectSetAttribute

Modified: Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectsubclass.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectsubclass.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/tests/test_protectsubclass.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -17,11 +17,11 @@
 """
 import unittest
 from zope.security.checker import selectChecker
+from zope.security.permission import Permission
 from zope.app.testing import ztapi
 from zope.app.testing.placelesssetup import PlacelessSetup
 
 from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
 from zope.app.security.protectclass import protectName
 
 class Test(PlacelessSetup, unittest.TestCase):

Modified: Zope3/branches/jim-adapter/src/zope/app/security/vocabulary.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/vocabulary.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/security/vocabulary.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -58,7 +58,7 @@
     the special permission 'zope.Public':
 
         >>> from zope.app.security.interfaces import IPermission
-        >>> from zope.app.security.permission import Permission
+        >>> from zope.security.permission import Permission
         >>> from zope.app.testing import ztapi
         >>> ztapi.provideUtility(IPermission, Permission('zope.Public'),
         ...     'zope.Public')

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/ftests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/ftests.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/ftests.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -18,9 +18,9 @@
 import unittest
 
 import zope.component
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 from zope.app.testing import functional
-from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
 from zope.app.securitypolicy.role import Role
 from zope.app.securitypolicy.interfaces import IRole
 

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/granting.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/granting.txt	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/granting.txt	2006-04-12 22:17:35 UTC (rev 66918)
@@ -15,8 +15,8 @@
 
   - Permissions
 
-    >>> from zope.app.security.permission import Permission
-    >>> from zope.app.security.interfaces import IPermission
+    >>> from zope.security.permission import Permission
+    >>> from zope.security.interfaces import IPermission
     >>> ztapi.provideUtility(IPermission, Permission(u'permission1',
     ...                      u'Permission 1'), u'permission1')
     >>> ztapi.provideUtility(IPermission, Permission(u'permission2',

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -22,10 +22,10 @@
 from zope.i18nmessageid import Message
 from zope.publisher.browser import TestRequest, BrowserView
 from zope.exceptions.interfaces import UserError
+from zope.security.permission import Permission
+from zope.security.interfaces import IPermission
 
 from zope.app.testing import ztapi
-from zope.app.security.permission import Permission
-from zope.app.security.interfaces import IPermission
 from zope.app.component.testing import PlacefulSetup
 
 from zope.app.securitypolicy.role import Role

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/principalpermission.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/principalpermission.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/principalpermission.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -17,12 +17,11 @@
 """
 
 from zope.interface import implements
-from zope.app.securitypolicy.interfaces import IPrincipalPermissionManager
+from zope.security.permission import allPermissions
 
 from zope.app.security.settings import Allow, Deny, Unset
 from zope.app.security.principal import checkPrincipal
-from zope.app.security.permission import allPermissions
-
+from zope.app.securitypolicy.interfaces import IPrincipalPermissionManager
 from zope.app.securitypolicy.securitymap import SecurityMap
 from zope.app.securitypolicy.securitymap import AnnotationSecurityMap
 

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/rolepermission.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/rolepermission.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/rolepermission.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -17,8 +17,8 @@
 """
 from zope.interface import implements
 
+from zope.security.permission import allPermissions
 from zope.app.security.settings import Allow, Deny, Unset
-from zope.app.security.permission import allPermissions
 from zope.app.securitypolicy.role import checkRole
 
 from zope.app.securitypolicy.interfaces import IRolePermissionManager

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationprincipalpermissionmanager.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationprincipalpermissionmanager.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationprincipalpermissionmanager.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -20,14 +20,14 @@
 from zope.interface import implements
 from zope.annotation.attribute import AttributeAnnotations
 from zope.annotation.interfaces import IAttributeAnnotatable, IAnnotations
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 
 from zope.app.testing import ztapi
 from zope.app.security.principalregistry import principalRegistry
 from zope.app.security.settings import Allow, Deny, Unset
 from zope.app.testing.placelesssetup import PlacelessSetup
 
-from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
 from zope.app.securitypolicy.principalpermission \
     import AnnotationPrincipalPermissionManager
 

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationrolepermissionmanager.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationrolepermissionmanager.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_annotationrolepermissionmanager.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -18,10 +18,10 @@
 import unittest
 from zope.interface import implements
 from zope.annotation.interfaces import IAttributeAnnotatable
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 
 from zope.app.testing import ztapi
-from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
 from zope.app.security.settings import Allow, Deny
 from zope.app.component.testing import PlacefulSetup
 

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_principalpermissionmanager.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_principalpermissionmanager.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_principalpermissionmanager.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -17,14 +17,12 @@
 """
 import unittest
 
-from zope.app import zapi
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
+
 from zope.app.testing import ztapi
 from zope.app.testing.placelesssetup import PlacelessSetup
-
-from zope.app.security.interfaces import IPermission
 from zope.app.security.interfaces import IAuthentication
-from zope.app.security.permission import Permission
-
 from zope.app.security.settings import Allow, Deny, Unset
 from zope.app.security.principalregistry import principalRegistry
 

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_rolepermissionmanager.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_rolepermissionmanager.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_rolepermissionmanager.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -17,15 +17,12 @@
 """
 import unittest
 
-from zope.app.testing.placelesssetup import PlacelessSetup
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 
-from zope.app import zapi
+from zope.app.testing.placelesssetup import PlacelessSetup
 from zope.app.testing import ztapi
-
-from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
 from zope.app.security.settings import Allow, Deny
-
 from zope.app.securitypolicy.role import Role
 from zope.app.securitypolicy.interfaces import IRole
 from zope.app.securitypolicy.rolepermission \

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_securitydirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_securitydirectives.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/tests/test_securitydirectives.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -17,17 +17,15 @@
 """
 import unittest
 
+import zope.component
 from zope.configuration import xmlconfig
 from zope.configuration.config import ConfigurationConflictError
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 
-from zope.app import zapi
 from zope.app.testing import ztapi
-
 from zope.app.testing.placelesssetup import PlacelessSetup
-
-from zope.app.security.interfaces import IPermission
 from zope.app.security.interfaces import IAuthentication
-from zope.app.security.permission import Permission
 from zope.app.security.settings import Allow
 from zope.app.security.principalregistry import principalRegistry
 
@@ -61,7 +59,7 @@
         context = xmlconfig.file("role.zcml",
                                  zope.app.securitypolicy.tests)
 
-        role = zapi.getUtility(IRole, "zope.Everyperson")
+        role = zope.component.getUtility(IRole, "zope.Everyperson")
         self.failUnless(role.id.endswith('Everyperson'))
         self.assertEqual(role.title, 'Tout le monde')
         self.assertEqual(role.description,

Modified: Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -23,12 +23,11 @@
 from zope.schema import Text, Int
 from zope.security.checker import CheckerPublic
 from zope.security.management import newInteraction, endInteraction
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
 from zope.annotation.interfaces import IAttributeAnnotatable
 from zope.component.testing import events, clearEvents
 
-from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
-
 from zope.app.workflow.tests.workflowsetup import WorkflowSetup
 from zope.app.workflow.interfaces import IProcessDefinition
 from zope.app.workflow.instance import createProcessInstance

Modified: Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_xmlimportexport.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_xmlimportexport.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_xmlimportexport.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -19,26 +19,26 @@
 from StringIO import StringIO
 
 import zope.component
+from zope.interface import implements, classImplements, Interface
+from zope.interface.verify import verifyClass
+from zope.schema import TextLine
 from zope.annotation.attribute import AttributeAnnotations
 from zope.annotation.interfaces import IAnnotatable, IAnnotations
 from zope.annotation.interfaces import IAttributeAnnotatable
 from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter
 from zope.dublincore.interfaces import IZopeDublinCore
+from zope.security.interfaces import IPermission
+from zope.security.permission import Permission
+from zope.security.checker import CheckerPublic
 
-from zope.app.security.interfaces import IPermission
 from zope.app.workflow.interfaces import IProcessDefinitionExportHandler
 from zope.app.workflow.interfaces import IProcessDefinitionImportHandler
-from zope.app.security.permission import Permission
 from zope.app.site.tests.placefulsetup import PlacefulSetup
 from zope.app.workflow.stateful.definition import StatefulProcessDefinition
 from zope.app.workflow.stateful.definition import State, Transition
 from zope.app.workflow.stateful.xmlimportexport import XMLExportHandler
 from zope.app.workflow.stateful.xmlimportexport import XMLImportHandler
 from zope.app.testing import ztapi
-from zope.interface import implements, classImplements, Interface
-from zope.interface.verify import verifyClass
-from zope.schema import TextLine
-from zope.security.checker import CheckerPublic
 
 class ISchema(Interface):
 

Copied: Zope3/branches/jim-adapter/src/zope/security/permission.py (from rev 66899, Zope3/branches/jim-adapter/src/zope/app/security/permission.py)
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/permission.py	2006-04-12 18:09:30 UTC (rev 66899)
+++ Zope3/branches/jim-adapter/src/zope/security/permission.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
+"""Permissions
+
+$Id$
+"""
+from zope.interface import implements
+from zope.component import queryUtility, getUtilitiesFor
+from zope.security.checker import CheckerPublic
+from zope.security.interfaces import IPermission
+
+class Permission(object):
+    implements(IPermission)
+
+    def __init__(self, id, title="", description=""):
+        self.id = id
+        self.title = title
+        self.description = description
+
+def checkPermission(context, permission_id):
+    """Check whether a given permission exists in the provided context.
+
+    >>> from zope.component import provideUtility
+    >>> provideUtility(Permission('x'), IPermission, 'x')
+
+    >>> checkPermission(None, 'x')
+    >>> checkPermission(None, 'y')
+    Traceback (most recent call last):
+    ...
+    ValueError: ('Undefined permission id', 'y')
+    """
+    if permission_id is CheckerPublic:
+        return
+    if not queryUtility(IPermission, permission_id, context=context):
+        raise ValueError("Undefined permission id", permission_id)
+
+def allPermissions(context=None):
+    """Get the ids of all defined permissions
+
+    >>> from zope.component import provideUtility
+    >>> provideUtility(Permission('x'), IPermission, 'x')
+    >>> provideUtility(Permission('y'), IPermission, 'y')
+
+    >>> ids = list(allPermissions(None))
+    >>> ids.sort()
+    >>> ids
+    [u'x', u'y']
+    """
+    for id, permission in getUtilitiesFor(IPermission, context):
+        if id != u'zope.Public':
+            yield id

Added: Zope3/branches/jim-adapter/src/zope/security/tests/test_permission.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/security/tests/test_permission.py	2006-04-12 21:47:00 UTC (rev 66917)
+++ Zope3/branches/jim-adapter/src/zope/security/tests/test_permission.py	2006-04-12 22:17:35 UTC (rev 66918)
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Test permissions
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+from zope.component.testing import setUp, tearDown
+
+__docformat__ = "reStructuredText"
+
+def test_suite():
+    return unittest.TestSuite([
+        DocTestSuite('zope.security.permission',
+                     setUp=setUp, tearDown=tearDown),
+        ])
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: Zope3/branches/jim-adapter/src/zope/security/tests/test_permission.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list