[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security - Checker.py:1.1.4.6 Proxy.py:1.1.4.2
Jim Fulton
jim@zope.com
Fri, 7 Jun 2002 10:41:59 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Security
In directory cvs.zope.org:/tmp/cvs-serv12187/lib/python/Zope/Security
Modified Files:
Tag: Zope-3x-branch
Checker.py Proxy.py
Log Message:
Merging in Zope3InWonderland-branch, which implemented the following
proposals (see
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/OldProposals):
- RenameAllowToRequire
- GroupClassRelatedDirectivesInClassDirective
- ViewInterfaceAndSimplification
- ConsistentUseOfSpacesAsDelimitersInZCMLAttributes
- TwoArgumentViewConstructors
- ImplementsInZCML
- SimpleViewCreationInZCML
- RemoveGetView
- ReplaceProtectWithAllow
- ViewMethodsAsViews
- MergeProtectionAndComponentDefinitions
There were also various security fixes resulting of better integration
of security with components.
=== Zope3/lib/python/Zope/Security/Checker.py 1.1.4.5 => 1.1.4.6 ===
if checker is None:
+ checker = getattr(object, '__Security_checker__', None)
+
+ if checker is None:
+
checker = selectChecker(object)
if checker is None:
return object
@@ -111,9 +115,12 @@
def proxy(self, value):
'See Zope.Security.IChecker.IChecker'
# Now we need to create a proxy
- checker = selectChecker(value)
+
+ checker = getattr(value, '__Security_checker__', None)
if checker is None:
- return value
+ checker = selectChecker(value)
+ if checker is None:
+ return value
return Proxy(value, checker)
@@ -138,6 +145,9 @@
return Checker(data.get)
+def InterfaceChecker(interface, permission_id=CheckerPublic):
+ return NamesChecker(interface.names(1), permission_id)
+
def MultiChecker(specs):
"""Create a checker from a sequence of specifications
@@ -203,8 +213,6 @@
def getCheckerForInstancesOf(class_):
return _checkers.get(class_)
-
-
def defineChecker(type_, checker):
"""Define a checker for a given type of object
@@ -214,8 +222,8 @@
"""
if type_ in _checkers:
raise DuplicationError(type_)
- _checkers[type_] = checker
-
+ _checkers[type_] = checker
+
NoProxy = object()
@@ -268,6 +276,7 @@
'isImplementedBy', 'extends'])
BasicTypes = {
+ object: NoProxy,
int: NoProxy,
float: NoProxy,
long: NoProxy,
=== Zope3/lib/python/Zope/Security/Proxy.py 1.1.4.1 => 1.1.4.2 ===
from _Proxy import getObject, getChecker
from _Proxy import _Proxy as Proxy
-from Checker import ProxyFactory
+from Checker import ProxyFactory, Checker as _trustedChecker
+def trustedRemoveSecurityProxy(object):
+ if ((type(object) is Proxy) and
+ isinstance(getChecker(object), _trustedChecker)
+ ):
+ return getObject(object)
+
+ return object
+
+
+def getTestProxyItems(proxy):
+ """Try to get checker names and permissions for testing
+
+ If this succeeds, a sorted sequence of items is returned,
+ otherwise, None is retirned.
+ """
+ checker = getChecker(proxy)
+ func = checker.getPermission_func()
+ dict = getattr(func, '__self__', None)
+ if dict is None:
+ return None
+ items = dict.items()
+ items.sort()
+ return items
+