[Checkins] SVN: z3ext.preferences/tags/1.2.1/ egg 1.2.1

Nikolay Kim fafhrd at datacom.kz
Mon Apr 21 08:35:13 EDT 2008


Log message for revision 85528:
  egg 1.2.1

Changed:
  A   z3ext.preferences/tags/1.2.1/
  D   z3ext.preferences/tags/1.2.1/CHANGES.txt
  A   z3ext.preferences/tags/1.2.1/CHANGES.txt
  U   z3ext.preferences/tags/1.2.1/setup.py
  D   z3ext.preferences/tags/1.2.1/src/z3ext/preferences/utils.py
  A   z3ext.preferences/tags/1.2.1/src/z3ext/preferences/utils.py
  D   z3ext.preferences/tags/1.2.1/src/z3ext/preferences/zcml.py
  A   z3ext.preferences/tags/1.2.1/src/z3ext/preferences/zcml.py

-=-
Copied: z3ext.preferences/tags/1.2.1 (from rev 85523, z3ext.preferences/trunk)

Deleted: z3ext.preferences/tags/1.2.1/CHANGES.txt
===================================================================
--- z3ext.preferences/trunk/CHANGES.txt	2008-04-21 04:12:25 UTC (rev 85523)
+++ z3ext.preferences/tags/1.2.1/CHANGES.txt	2008-04-21 12:35:13 UTC (rev 85528)
@@ -1,62 +0,0 @@
-=======
-CHANGES
-=======
-
-1.2.0 (2008-04-18)
-------------------
-
-- 'schema' field for z3ext:preferenceGroup is required now
-
-- Added adapter for IPrincipal to 'schema' with automatic binding
-
-
-1.1.1 (2008-04-15)
-------------------
-
-- Use 'z3ext.ManagePreference' as default preference permission
-
-
-1.1.0 (2008-04-11)
-------------------
-
-- Added 'for' field to z3ext:preferenceGroup directive
-
-
-1.0.2 (2008-04-07)
-------------------
-
-- Fix UI in navigation
-
-
-1.0.1 (2008-04-04)
-------------------
-
-- Fixed group category layout
-
-
-1.0.0 (2008-03-25)
-------------------
-
-- Tests added
-
-- Code moved to svn.zope.org
-
-
-0.9.2 (2008-02-29)
-------------------
-
-- Use z3c.autoinclude
-
-- Added z3c.baseregistry support
-
-
-0.9.1 (2008-02-20)
-------------------
-
-- Use z3ext.layoutform
-
-
-0.9.0 (2008-02-01)
-------------------
-
-- Initial release

Copied: z3ext.preferences/tags/1.2.1/CHANGES.txt (from rev 85527, z3ext.preferences/trunk/CHANGES.txt)
===================================================================
--- z3ext.preferences/tags/1.2.1/CHANGES.txt	                        (rev 0)
+++ z3ext.preferences/tags/1.2.1/CHANGES.txt	2008-04-21 12:35:13 UTC (rev 85528)
@@ -0,0 +1,68 @@
+=======
+CHANGES
+=======
+
+1.2.1 (2008-04-22)
+------------------
+
+- Added permission checker to directive
+
+
+1.2.0 (2008-04-18)
+------------------
+
+- 'schema' field for z3ext:preferenceGroup is required now
+
+- Added adapter for IPrincipal to 'schema' with automatic binding
+
+
+1.1.1 (2008-04-15)
+------------------
+
+- Use 'z3ext.ManagePreference' as default preference permission
+
+
+1.1.0 (2008-04-11)
+------------------
+
+- Added 'for' field to z3ext:preferenceGroup directive
+
+
+1.0.2 (2008-04-07)
+------------------
+
+- Fix UI in navigation
+
+
+1.0.1 (2008-04-04)
+------------------
+
+- Fixed group category layout
+
+
+1.0.0 (2008-03-25)
+------------------
+
+- Tests added
+
+- Code moved to svn.zope.org
+
+
+0.9.2 (2008-02-29)
+------------------
+
+- Use z3c.autoinclude
+
+- Added z3c.baseregistry support
+
+
+0.9.1 (2008-02-20)
+------------------
+
+- Use z3ext.layoutform
+
+
+0.9.0 (2008-02-01)
+------------------
+
+- Initial release

Modified: z3ext.preferences/tags/1.2.1/setup.py
===================================================================
--- z3ext.preferences/trunk/setup.py	2008-04-21 04:12:25 UTC (rev 85523)
+++ z3ext.preferences/tags/1.2.1/setup.py	2008-04-21 12:35:13 UTC (rev 85528)
@@ -21,7 +21,7 @@
 def read(*rnames):
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
-version='1.2.1dev'
+version='1.2.1'
 
 
 setup(name = 'z3ext.preferences',

Deleted: z3ext.preferences/tags/1.2.1/src/z3ext/preferences/utils.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/utils.py	2008-04-21 04:12:25 UTC (rev 85523)
+++ z3ext.preferences/tags/1.2.1/src/z3ext/preferences/utils.py	2008-04-21 12:35:13 UTC (rev 85528)
@@ -1,67 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 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.
-#
-##############################################################################
-"""
-
-$Id$
-
-  >>> from zope import interface
-  >>> from zope.security.interfaces import IPrincipal, IGroup
-  >>> class P(object):
-  ...   interface.implements(IPrincipal)
-
-  >>> class Prefs(object):
-  ...     __principal__ = None
-
-  >>> prefs = Prefs()
-  >>> prefs.__principal__ = P()
-
-  >>> import utils
-  >>> print utils.isUser(prefs)
-  True
-  >>> print utils.isGroup(prefs)
-  False
-
-  >>> interface.directlyProvides(prefs.__principal__, IGroup)
-  >>> print utils.isUser(prefs)
-  False
-  >>> print utils.isGroup(prefs)
-  True
-  >>> print utils.isMemberAwareGroup(prefs)
-  False
-"""
-
-from zope import interface
-from zope.security.interfaces import IPrincipal, IGroup, IMemberAwareGroup
-
-
-def isUser(group):
-    principal = group.__principal__
-    return IPrincipal.providedBy(principal) and not IGroup.providedBy(principal)
-
-
-def isGroup(group):
-    return IGroup.providedBy(group.__principal__)
-
-
-def isMemberAwareGroup(group):
-    return IMemberAwareGroup.providedBy(group.__principal__)
-
-
-class PrincipalChecker(object):
-
-    def __init__(self, iface):
-        self.iface = iface
-
-    def __call__(self, group):
-        return self.iface.providedBy(group.__principal__)

Copied: z3ext.preferences/tags/1.2.1/src/z3ext/preferences/utils.py (from rev 85527, z3ext.preferences/trunk/src/z3ext/preferences/utils.py)
===================================================================
--- z3ext.preferences/tags/1.2.1/src/z3ext/preferences/utils.py	                        (rev 0)
+++ z3ext.preferences/tags/1.2.1/src/z3ext/preferences/utils.py	2008-04-21 12:35:13 UTC (rev 85528)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""
+
+$Id$
+
+  >>> from zope import interface
+  >>> from zope.security.interfaces import IPrincipal, IGroup
+  >>> class P(object):
+  ...   interface.implements(IPrincipal)
+
+  >>> class Prefs(object):
+  ...     __principal__ = None
+
+  >>> prefs = Prefs()
+  >>> prefs.__principal__ = P()
+
+  >>> import utils
+  >>> print utils.isUser(prefs)
+  True
+  >>> print utils.isGroup(prefs)
+  False
+
+  >>> interface.directlyProvides(prefs.__principal__, IGroup)
+  >>> print utils.isUser(prefs)
+  False
+  >>> print utils.isGroup(prefs)
+  True
+  >>> print utils.isMemberAwareGroup(prefs)
+  False
+"""
+
+from zope import interface
+from zope.security import checkPermission
+from zope.security.interfaces import IPrincipal, IGroup, IMemberAwareGroup
+
+
+def isUser(group):
+    principal = group.__principal__
+    return IPrincipal.providedBy(principal) and not IGroup.providedBy(principal)
+
+
+def isGroup(group):
+    return IGroup.providedBy(group.__principal__)
+
+
+def isMemberAwareGroup(group):
+    return IMemberAwareGroup.providedBy(group.__principal__)
+
+
+class PrincipalChecker(object):
+
+    def __init__(self, iface):
+        self.iface = iface
+
+    def __call__(self, group):
+        return self.iface.providedBy(group.__principal__)
+
+
+class PermissionChecker(object):
+
+    def __init__(self, permission):
+        self.permission = permission
+
+    def __call__(self, prefs):
+        return checkPermission(self.permission, prefs)

Deleted: z3ext.preferences/tags/1.2.1/src/z3ext/preferences/zcml.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/zcml.py	2008-04-21 04:12:25 UTC (rev 85523)
+++ z3ext.preferences/tags/1.2.1/src/z3ext/preferences/zcml.py	2008-04-21 12:35:13 UTC (rev 85528)
@@ -1,252 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2008 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.
-#
-##############################################################################
-""" z3ext:preferenceGroup directive implementation
-
-$Id$
-"""
-from zope import interface
-from zope.schema import Int
-from zope.component import getUtility, queryUtility, getGlobalSiteManager
-from zope.schema.interfaces import IField
-
-from zope.security.zcml import Permission
-from zope.security.checker import Checker, CheckerPublic
-from zope.security.interfaces import IPrincipal
-
-from zope.interface.common.mapping import IEnumerableMapping
-
-from zope.component.zcml import utility, adapter
-from zope.component.interface import provideInterface
-
-from zope.configuration import fields
-from zope.configuration.exceptions import ConfigurationError
-
-from zope.app.security.protectclass import \
-    protectName, protectSetAttribute, protectLikeUnto
-
-from interfaces import IPreferenceGroup
-from preference import PreferenceGroup
-from preferencetype import PreferenceType
-from utils import PrincipalChecker
-
-
-class IPreferenceGroupDirective(interface.Interface):
-    """Register a preference group."""
-
-    id = fields.PythonIdentifier(
-        title=u"Id",
-        description=u"""
-            Id of the preference group used to access the group. The id should
-            be a valid path in the preferences tree.""",
-        required=True)
-
-    for_ = fields.GlobalInterface(
-        title=u"For",
-        description=u"Principal interface to use this preference for.",
-        required=False)
-
-    schema = fields.GlobalInterface(
-        title=u"Schema",
-        description=u"Schema of the preference group used defining the "
-                    u"preferences of the group.",
-        required=True)
-
-    title = fields.MessageID(
-        title=u"Title",
-        description=u"Title of the preference group used in UIs.",
-        required=True)
-
-    description = fields.MessageID(
-        title=u"Description",
-        description=u"Description of the preference group used in UIs.",
-        required=False)
-
-    class_ = fields.GlobalObject(
-        title=u"Class",
-        description=u"Custom IPreferenceGroup implementation.",
-        required=False)
-
-    provides = fields.Tokens(
-	title = u'Provides',
-        required = False,
-        value_type = fields.GlobalInterface())
-
-    permission = Permission(
-        title = u'Permission',
-        description = u'Default access permission.',
-        required = False)
-
-    tests = fields.Tokens(
-	title = u"Tests",
-        description = u'Tests for check availability.',
-        value_type = fields.GlobalObject(),
-	required = False)
-
-    order = Int(
-        title = u'Order',
-        default = 999999,
-        required = False)
-
-
-class PreferenceGroupAdapter(object):
-
-    def __init__(self, name):
-        self.name = name
-
-    def __call__(self, principal, context=None):
-        prefs = getUtility(IPreferenceGroup, self.name)
-        return prefs.__bind__(principal, context)
-
-
-class PreferenceGroupDirective(object):
-
-    def __init__(self, _context, id, schema, title,
-                 for_=None, description=u'', class_=None, provides=[],
-                 permission='z3ext.ModifyPreference', tests=(), order = 9999):
-
-        Class = PreferenceType(str(id), schema, class_, title, description)
-        Class.order = order
-
-        if interface.interfaces.IInterface.providedBy(for_):
-            tests = tests + (PrincipalChecker(for_),)
-
-        group = Class(tests)
-
-        utility(_context, IPreferenceGroup, group, name=id)
-        adapter(_context, (PreferenceGroupAdapter(id),), schema,
-                (for_ or IPrincipal,))
-        adapter(_context, (PreferenceGroupAdapter(id),), schema,
-                (for_ or IPrincipal, interface.Interface))
-
-        interface.classImplements(Class, *provides)
-
-        self._class = Class
-        self._context = _context
-        self._permission = permission
-
-        self.require(_context, permission, interface=(IPreferenceGroup, schema))
-        self.require(_context, 'z3ext.ModifyPreference', set_schema=(schema,))
-        self.require(_context, CheckerPublic,
-                     interface=(IEnumerableMapping,), attributes=('isAvailable',))
-
-        schema.setTaggedValue('preferenceID', id)
-
-        _context.action(
-            discriminator=('z3ext:preferences', schema),
-            callable=addSubgroup, args=(group,))
-
-    def require(self, _context,
-                permission=None, attributes=None, interface=None,
-                like_class=None, set_attributes=None, set_schema=None):
-        """Require a permission to access a specific aspect"""
-        if like_class:
-            self.__mimic(_context, like_class)
-
-        if not (interface or attributes or set_attributes or set_schema):
-            if like_class:
-                return
-            raise ConfigurationError("Nothing required")
-
-        if not permission:
-            raise ConfigurationError("No permission specified")
-
-        if interface:
-            for i in interface:
-                if i:
-                    self.__protectByInterface(i, permission)
-
-        if attributes:
-            self.__protectNames(attributes, permission)
-
-        if set_attributes:
-            self.__protectSetAttributes(set_attributes, permission)
-
-        if set_schema:
-            for s in set_schema:
-                self.__protectSetSchema(s, permission)
-
-    def __mimic(self, _context, class_):
-        """Base security requirements on those of the given class"""
-        _context.action(
-            discriminator=('z3ext:preferences:mimic', self._class),
-            callable=protectLikeUnto,
-            args=(self._class, class_),
-            )
-
-    def allow(self, _context, attributes=None, interface=None):
-        """Like require, but with permission_id zope.Public"""
-        return self.require(_context, self._permission, attributes, interface)
-
-    def __protectByInterface(self, interface, permission_id):
-        "Set a permission on names in an interface."
-        for n, d in interface.namesAndDescriptions(1):
-            self.__protectName(n, permission_id)
-
-        self._context.action(
-            discriminator = None,
-            callable = provideInterface,
-            args = (interface.__module__+'.'+interface.getName(), interface))
-
-    def __protectName(self, name, permission_id):
-        "Set a permission on a particular name."
-        self._context.action(
-            discriminator = ('z3ext:preferences:protectName', object()),
-            callable = protectName,
-            args = (self._class, name, permission_id))
-
-    def __protectNames(self, names, permission_id):
-        "Set a permission on a bunch of names."
-        for name in names:
-            self.__protectName(name, permission_id)
-
-    def __protectSetAttributes(self, names, permission_id):
-        "Set a permission on a bunch of names."
-        for name in names:
-            self._context.action(
-                discriminator = (
-                    'z3ext:preferences:protectSetAttribute', object()),
-                callable = protectSetAttribute,
-                args = (self._class, name, permission_id))
-
-    def __protectSetSchema(self, schema, permission_id):
-        "Set a permission on a bunch of names."
-        _context = self._context
-
-        for name in schema:
-            field = schema[name]
-            if IField.providedBy(field) and not field.readonly:
-                _context.action(
-                    discriminator = (
-                        'z3ext:preferences:protectSetAttribute', object()),
-                    callable = protectSetAttribute,
-                    args = (self._class, name, permission_id))
-
-        _context.action(
-            discriminator = None,
-            callable = provideInterface,
-            args = (schema.__module__+'.'+schema.getName(), schema))
-
-
-def addSubgroup(group):
-    if '.' in group.__id__:
-        parentId = group.__id__.split('.')[0]
-    else:
-        parentId = ''
-
-    parent = queryUtility(IPreferenceGroup, parentId)
-    if parent is None:
-        parent = getGlobalSiteManager().getUtility(IPreferenceGroup, parentId)
-
-    parent.add(group.__name__)
-    group.__parent__ = parent

Copied: z3ext.preferences/tags/1.2.1/src/z3ext/preferences/zcml.py (from rev 85527, z3ext.preferences/trunk/src/z3ext/preferences/zcml.py)
===================================================================
--- z3ext.preferences/tags/1.2.1/src/z3ext/preferences/zcml.py	                        (rev 0)
+++ z3ext.preferences/tags/1.2.1/src/z3ext/preferences/zcml.py	2008-04-21 12:35:13 UTC (rev 85528)
@@ -0,0 +1,258 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+""" z3ext:preferenceGroup directive implementation
+
+$Id$
+"""
+from zope import interface
+from zope.schema import Int
+from zope.component import getUtility, queryUtility, getGlobalSiteManager
+from zope.schema.interfaces import IField
+from zope.location.interfaces import ILocation
+
+from zope.security.zcml import Permission
+from zope.security.checker import Checker, CheckerPublic
+from zope.security.interfaces import IPrincipal
+
+from zope.interface.common.mapping import IEnumerableMapping
+
+from zope.component.zcml import utility, adapter
+from zope.component.interface import provideInterface
+
+from zope.configuration import fields
+from zope.configuration.exceptions import ConfigurationError
+
+from zope.app.security.protectclass import \
+    protectName, protectSetAttribute, protectLikeUnto
+
+from interfaces import IPreferenceGroup
+from preference import PreferenceGroup
+from preferencetype import PreferenceType
+from utils import PrincipalChecker, PermissionChecker
+
+
+class IPreferenceGroupDirective(interface.Interface):
+    """Register a preference group."""
+
+    id = fields.PythonIdentifier(
+        title=u"Id",
+        description=u"""
+            Id of the preference group used to access the group. The id should
+            be a valid path in the preferences tree.""",
+        required=True)
+
+    for_ = fields.GlobalInterface(
+        title=u"For",
+        description=u"Principal interface to use this preference for.",
+        required=False)
+
+    schema = fields.GlobalInterface(
+        title=u"Schema",
+        description=u"Schema of the preference group used defining the "
+                    u"preferences of the group.",
+        required=True)
+
+    title = fields.MessageID(
+        title=u"Title",
+        description=u"Title of the preference group used in UIs.",
+        required=True)
+
+    description = fields.MessageID(
+        title=u"Description",
+        description=u"Description of the preference group used in UIs.",
+        required=False)
+
+    class_ = fields.GlobalObject(
+        title=u"Class",
+        description=u"Custom IPreferenceGroup implementation.",
+        required=False)
+
+    provides = fields.Tokens(
+	title = u'Provides',
+        required = False,
+        value_type = fields.GlobalInterface())
+
+    permission = Permission(
+        title = u'Permission',
+        description = u'Default access permission.',
+        required = False)
+
+    tests = fields.Tokens(
+	title = u"Tests",
+        description = u'Tests for check availability.',
+        value_type = fields.GlobalObject(),
+	required = False)
+
+    order = Int(
+        title = u'Order',
+        default = 999999,
+        required = False)
+
+
+class PreferenceGroupAdapter(object):
+
+    def __init__(self, name):
+        self.name = name
+
+    def __call__(self, principal, context=None):
+        prefs = getUtility(IPreferenceGroup, self.name)
+        return prefs.__bind__(principal, context)
+
+
+class PreferenceGroupDirective(object):
+
+    def __init__(self, _context, id, schema, title,
+                 for_=None, description=u'', class_=None, provides=[],
+                 permission='z3ext.ModifyPreference', tests=(), order = 9999):
+
+        Class = PreferenceType(str(id), schema, class_, title, description)
+        Class.order = order
+
+        if interface.interfaces.IInterface.providedBy(for_):
+            tests = tests + (PrincipalChecker(for_),)
+
+        tests = tuple(tests) + (PermissionChecker(permission),)
+
+        group = Class(tests)
+
+        utility(_context, IPreferenceGroup, group, name=id)
+        adapter(_context, (PreferenceGroupAdapter(id),), schema,
+                (for_ or IPrincipal,))
+        adapter(_context, (PreferenceGroupAdapter(id),), schema,
+                (for_ or IPrincipal, interface.Interface))
+
+        interface.classImplements(Class, *provides)
+
+        self._class = Class
+        self._context = _context
+        self._permission = permission
+
+        self.require(_context, permission,
+                     interface=(IPreferenceGroup, schema), set_schema=(schema,))
+        self.require(_context, CheckerPublic,
+                     interface=(IEnumerableMapping, ILocation),
+                     attributes=('isAvailable',
+                                 '__id__', '__schema__',
+                                 '__title__', '__description__'))
+
+        schema.setTaggedValue('preferenceID', id)
+
+        _context.action(
+            discriminator=('z3ext:preferences', schema),
+            callable=addSubgroup, args=(group,))
+
+    def require(self, _context,
+                permission=None, attributes=None, interface=None,
+                like_class=None, set_attributes=None, set_schema=None):
+        """Require a permission to access a specific aspect"""
+        if like_class:
+            self.__mimic(_context, like_class)
+
+        if not (interface or attributes or set_attributes or set_schema):
+            if like_class:
+                return
+            raise ConfigurationError("Nothing required")
+
+        if not permission:
+            raise ConfigurationError("No permission specified")
+
+        if interface:
+            for i in interface:
+                if i:
+                    self.__protectByInterface(i, permission)
+
+        if attributes:
+            self.__protectNames(attributes, permission)
+
+        if set_attributes:
+            self.__protectSetAttributes(set_attributes, permission)
+
+        if set_schema:
+            for s in set_schema:
+                self.__protectSetSchema(s, permission)
+
+    def __mimic(self, _context, class_):
+        """Base security requirements on those of the given class"""
+        _context.action(
+            discriminator=('z3ext:preferences:mimic', self._class),
+            callable=protectLikeUnto,
+            args=(self._class, class_),
+            )
+
+    def allow(self, _context, attributes=None, interface=None):
+        """Like require, but with permission_id zope.Public"""
+        return self.require(_context, self._permission, attributes, interface)
+
+    def __protectByInterface(self, interface, permission_id):
+        "Set a permission on names in an interface."
+        for n, d in interface.namesAndDescriptions(1):
+            self.__protectName(n, permission_id)
+
+        self._context.action(
+            discriminator = None,
+            callable = provideInterface,
+            args = (interface.__module__+'.'+interface.getName(), interface))
+
+    def __protectName(self, name, permission_id):
+        "Set a permission on a particular name."
+        self._context.action(
+            discriminator = ('z3ext:preferences:protectName', object()),
+            callable = protectName,
+            args = (self._class, name, permission_id))
+
+    def __protectNames(self, names, permission_id):
+        "Set a permission on a bunch of names."
+        for name in names:
+            self.__protectName(name, permission_id)
+
+    def __protectSetAttributes(self, names, permission_id):
+        "Set a permission on a bunch of names."
+        for name in names:
+            self._context.action(
+                discriminator = (
+                    'z3ext:preferences:protectSetAttribute', object()),
+                callable = protectSetAttribute,
+                args = (self._class, name, permission_id))
+
+    def __protectSetSchema(self, schema, permission_id):
+        "Set a permission on a bunch of names."
+        _context = self._context
+
+        for name in schema:
+            field = schema[name]
+            if IField.providedBy(field) and not field.readonly:
+                _context.action(
+                    discriminator = (
+                        'z3ext:preferences:protectSetAttribute', object()),
+                    callable = protectSetAttribute,
+                    args = (self._class, name, permission_id))
+
+        _context.action(
+            discriminator = None,
+            callable = provideInterface,
+            args = (schema.__module__+'.'+schema.getName(), schema))
+
+
+def addSubgroup(group):
+    if '.' in group.__id__:
+        parentId = group.__id__.split('.')[0]
+    else:
+        parentId = ''
+
+    parent = queryUtility(IPreferenceGroup, parentId)
+    if parent is None:
+        parent = getGlobalSiteManager().getUtility(IPreferenceGroup, parentId)
+
+    parent.add(group.__name__)
+    group.__parent__ = parent



More information about the Checkins mailing list