[Checkins] SVN: zope.security/trunk/src/zope/security/ Shuffle code around again, to not make the test a self-fulfulling
Christian Theune
ct at gocept.com
Fri Jan 30 04:40:46 EST 2009
Log message for revision 95540:
Shuffle code around again, to not make the test a self-fulfulling
prophecy: trigger the monkey patch (darn, I said it) when someone starts
using security proxies.
Changed:
U zope.security/trunk/src/zope/security/decorator.py
D zope.security/trunk/src/zope/security/location.py
U zope.security/trunk/src/zope/security/proxy.py
U zope.security/trunk/src/zope/security/tests/test_decorator.py
A zope.security/trunk/src/zope/security/tests/test_location.py
-=-
Modified: zope.security/trunk/src/zope/security/decorator.py
===================================================================
--- zope.security/trunk/src/zope/security/decorator.py 2009-01-30 08:56:03 UTC (rev 95539)
+++ zope.security/trunk/src/zope/security/decorator.py 2009-01-30 09:40:45 UTC (rev 95540)
@@ -23,10 +23,18 @@
from zope.proxy import getProxiedObject, ProxyBase
from zope.proxy.decorator import SpecificationDecoratorBase
from zope.security.checker import selectChecker, CombinedChecker
-from zope.security.proxy import Proxy, getChecker
from zope.interface.declarations import ObjectSpecification
+import zope.deferredimport
+# zope.security.proxy depends on this module because of the re-injection of
+# security compatibility with zope.location. To avoid circular import problems
+# and as those two symbols are only needed at run-time, not module-execution
+# time, we import them deferred.
+zope.deferredimport.define(
+ Proxy='zope.security.proxy:Proxy',
+ getChecker='zope.security.proxy:getChecker')
+
class DecoratedSecurityCheckerDescriptor(object):
"""Descriptor for a Decorator that provides a decorated security checker.
@@ -168,8 +176,8 @@
return self
else:
proxied_object = getProxiedObject(inst)
- if type(proxied_object) is Proxy:
- checker = getChecker(proxied_object)
+ if type(proxied_object) is zope.security.decorator.Proxy:
+ checker = zope.security.decorator.getChecker(proxied_object)
else:
checker = getattr(proxied_object, '__Security_checker__', None)
if checker is None:
Deleted: zope.security/trunk/src/zope/security/location.py
===================================================================
--- zope.security/trunk/src/zope/security/location.py 2009-01-30 08:56:03 UTC (rev 95539)
+++ zope.security/trunk/src/zope/security/location.py 2009-01-30 09:40:45 UTC (rev 95540)
@@ -1,52 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2009 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.
-#
-##############################################################################
-"""Make LocationProxies security-aware.
-
-This module does a somewhat hard hack and is intended to be refactored
-at some point, but helps avoiding to have zope.location depend on
-zope.security.
-
-We start with an unlocated class that will be wrapped by a
-LocationProxy:
-
->>> class Unlocated(object):
-... a = 'a'
-
->>> unlocated = Unlocated()
-
-Now we create a location proxy around it:
-
->>> from zope.location.location import LocationProxy
->>> located = LocationProxy(unlocated)
-
-We define a checker for the unlocated object, which will also be
-used by the security proxy as the LocationProxy defines
-__Security_checker__:
-
->>> from zope.security.checker import NamesChecker, defineChecker
->>> unlocatedChecker = NamesChecker(['a'])
->>> defineChecker(Unlocated, unlocatedChecker)
-
->>> from zope.security.proxy import ProxyFactory
->>> secure_located = ProxyFactory(located)
->>> secure_located.a
-'a'
-
-"""
-
-import zope.location.location
-from zope.security.decorator import DecoratedSecurityCheckerDescriptor
-
-zope.location.location.LocationProxy.__Security_checker__ = (
- DecoratedSecurityCheckerDescriptor())
Modified: zope.security/trunk/src/zope/security/proxy.py
===================================================================
--- zope.security/trunk/src/zope/security/proxy.py 2009-01-30 08:56:03 UTC (rev 95539)
+++ zope.security/trunk/src/zope/security/proxy.py 2009-01-30 09:40:45 UTC (rev 95540)
@@ -17,6 +17,8 @@
"""
__docformat__ = 'restructuredtext'
+import zope.location.location
+from zope.security.decorator import DecoratedSecurityCheckerDescriptor
from zope.security._proxy import getChecker, getObject
from zope.security._proxy import _Proxy as Proxy
@@ -71,3 +73,12 @@
# being used for isinstance
return builtin_isinstance(removeSecurityProxy(object), cls)
+
+
+# zope.location was made independent of security. To work together with
+# security, we re-inject the DecoratedSecurityCheckerDescriptor onto the
+# location proxy from here.
+# This is the only sane place we found for doing it: it kicks in as soon
+# as someone starts using security proxies.
+zope.location.location.LocationProxy.__Security_checker__ = (
+ DecoratedSecurityCheckerDescriptor())
Modified: zope.security/trunk/src/zope/security/tests/test_decorator.py
===================================================================
--- zope.security/trunk/src/zope/security/tests/test_decorator.py 2009-01-30 08:56:03 UTC (rev 95539)
+++ zope.security/trunk/src/zope/security/tests/test_decorator.py 2009-01-30 09:40:45 UTC (rev 95540)
@@ -15,15 +15,12 @@
$Id$
"""
+
import unittest
from zope.testing import doctest
+
def test_suite():
suite = doctest.DocTestSuite()
suite.addTest(doctest.DocTestSuite('zope.security.decorator'))
- suite.addTest(doctest.DocTestSuite('zope.security.location'))
return suite
-
-
-if __name__ == '__main__':
- unittest.main()
Added: zope.security/trunk/src/zope/security/tests/test_location.py
===================================================================
--- zope.security/trunk/src/zope/security/tests/test_location.py (rev 0)
+++ zope.security/trunk/src/zope/security/tests/test_location.py 2009-01-30 09:40:45 UTC (rev 95540)
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# Copyright (c) 2003 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.
+#
+##############################################################################
+"""Context Tests
+
+$Id: test_decorator.py 95518 2009-01-29 19:16:15Z ctheune $
+"""
+
+import unittest
+from zope.testing import doctest
+
+
+def test_locationproxy_security():
+ """We start with an unlocated class that will be wrapped by a
+ LocationProxy:
+
+ >>> class Unlocated(object):
+ ... a = 'a'
+
+ >>> unlocated = Unlocated()
+
+ Now we create a location proxy around it:
+
+ >>> from zope.location.location import LocationProxy
+ >>> located = LocationProxy(unlocated)
+
+ We define a checker for the unlocated object, which will also be
+ used by the security proxy as the LocationProxy defines
+ __Security_checker__:
+
+ >>> from zope.security.checker import NamesChecker, defineChecker
+ >>> unlocatedChecker = NamesChecker(['a'])
+ >>> defineChecker(Unlocated, unlocatedChecker)
+
+ >>> from zope.security.proxy import ProxyFactory
+ >>> secure_located = ProxyFactory(located)
+ >>> secure_located.a
+ 'a'
+ """
+
+
+def test_suite():
+ return doctest.DocTestSuite()
Property changes on: zope.security/trunk/src/zope/security/tests/test_location.py
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the Checkins
mailing list