summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephan Richter <stephan.richter@gmail.com>2013-03-11 00:08:02 -0400
committerStephan Richter <stephan.richter@gmail.com>2013-03-11 00:08:02 -0400
commit8cce64bbef274d776ac4856843ebe25b7d9cb51f (patch)
treec50da2740ff97cc4d9e4cf5bd8b68aa7750e808c /src
parentf421e5b218f080f580d2b490b04575dc787165c3 (diff)
downloadzope-security-8cce64bbef274d776ac4856843ebe25b7d9cb51f.tar.gz
Start of PyPy support.
Diffstat (limited to 'src')
-rw-r--r--src/zope/security/__init__.py6
-rw-r--r--src/zope/security/_compat.py4
-rw-r--r--src/zope/security/checker.py8
-rw-r--r--src/zope/security/proxy.py27
-rw-r--r--src/zope/security/tests/test_proxy.py6
5 files changed, 34 insertions, 17 deletions
diff --git a/src/zope/security/__init__.py b/src/zope/security/__init__.py
index 45c660a..5f079f6 100644
--- a/src/zope/security/__init__.py
+++ b/src/zope/security/__init__.py
@@ -16,3 +16,9 @@
"""
from zope.security.management import checkPermission
from zope.security.checker import canWrite, canAccess
+
+# We need the injection of DecoratedSecurityCheckerDescriptor into
+# zope.location's LocationProxy as soon someone uses security proxies by
+# importing zope.security.proxy:
+import zope.security.decorator
+
diff --git a/src/zope/security/_compat.py b/src/zope/security/_compat.py
index 414c290..6de4758 100644
--- a/src/zope/security/_compat.py
+++ b/src/zope/security/_compat.py
@@ -13,9 +13,13 @@
##############################################################################
""" Python 2 / 3 compatibility
"""
+import platform
import sys
import types
+py_impl = getattr(platform, 'python_implementation', lambda: None)
+PYPY = py_impl() == 'PyPy'
+
if sys.version_info[0] < 3: #pragma NO COVER
from StringIO import StringIO
diff --git a/src/zope/security/checker.py b/src/zope/security/checker.py
index 5f1d7df..061cc44 100644
--- a/src/zope/security/checker.py
+++ b/src/zope/security/checker.py
@@ -50,8 +50,8 @@ from zope.security._definitions import thread_local
from zope.security._compat import CLASS_TYPES
from zope.security._compat import PYTHON2
from zope.security._compat import _u
-from zope.security._proxy import _Proxy as Proxy
-from zope.security._proxy import getChecker
+from zope.security.proxy import Proxy
+from zope.security.proxy import getChecker
try:
from zope.exceptions import DuplicationError
@@ -98,6 +98,10 @@ def ProxyFactory(object, checker=None):
directlyProvides(ProxyFactory, ISecurityProxyFactory)
+# This import represents part of the API for the proxy module
+from . import proxy
+proxy.ProxyFactory = ProxyFactory
+
def canWrite(obj, name):
"""Check whether the interaction may write an attribute named name on obj.
diff --git a/src/zope/security/proxy.py b/src/zope/security/proxy.py
index 9457ab1..8291045 100644
--- a/src/zope/security/proxy.py
+++ b/src/zope/security/proxy.py
@@ -19,6 +19,7 @@ import functools
import sys
from zope.proxy import PyProxyBase
+from zope.security._compat import PYPY
from zope.security.interfaces import ForbiddenAttribute
@@ -272,28 +273,27 @@ for name in ['__iadd__',
meth = getattr(PyProxyBase, name)
setattr(ProxyPy, name, _check_name_inplace(meth))
+def getCheckerPy(proxy):
+ return proxy._checker
+
+def getObjectPy(proxy):
+ # Aem, if this works, how is the Python implementation providing any
+ # security?
+ return proxy._wrapped
+
try:
from zope.security._proxy import _Proxy
except ImportError: #pragma NO COVER PyPy
- #getChecker = getCheckerPy
- #getObject = getObjectPy
+ getChecker = getCheckerPy
+ getObject = getObjectPy
Proxy = ProxyPy
else: #pragma NO COVER CPython
from zope.security._proxy import getChecker
from zope.security._proxy import getObject
Proxy = _Proxy
-# We need the injection of DecoratedSecurityCheckerDescriptor into
-# zope.location's LocationProxy as soon someone uses security proxies by
-# importing zope.security.proxy:
-import zope.security.decorator
-
-
removeSecurityProxy = getObject
-# This import represents part of the API for this module
-from zope.security.checker import ProxyFactory
-
def getTestProxyItems(proxy):
"""Return a sorted sequence of checker names and permissions for testing
"""
@@ -309,7 +309,10 @@ def isinstance(object, cls):
"""
global builtin_isinstance
if builtin_isinstance is None:
- builtin_isinstance = __builtins__['isinstance']
+ if PYPY:
+ builtin_isinstance = getattr(__builtins__, 'isinstance')
+ else:
+ builtin_isinstance = __builtins__['isinstance']
# The removeSecurityProxy call is OK here because it is *only*
# being used for isinstance
return builtin_isinstance(removeSecurityProxy(object), cls)
diff --git a/src/zope/security/tests/test_proxy.py b/src/zope/security/tests/test_proxy.py
index 38663cc..7c15d52 100644
--- a/src/zope/security/tests/test_proxy.py
+++ b/src/zope/security/tests/test_proxy.py
@@ -1887,13 +1887,13 @@ def test_using_mapping_slots_hack():
class LocationProxySecurityCheckerTests(unittest.TestCase):
- def test_LocationProxy_gets_a_security_checker_when_importing_z_s_proxy(
+ def test_LocationProxy_gets_a_security_checker_when_importing_z_security(
self):
# Regression test for a problem introduced in 3.8.1 and fixed in
# 3.8.3. For details see change log.
import sys
from zope.location.location import LocationProxy
- import zope.security.proxy
+ import zope.security
from zope.security._compat import reload
# This attribute is set when zope.security.decorator is imported, to
# show that it will be set too, if zope.security.proxy is imported
@@ -1904,7 +1904,7 @@ class LocationProxySecurityCheckerTests(unittest.TestCase):
# After deleting zope.security.decorator and reloading
# zope.security.proxy the attribute is set again:
del sys.modules["zope.security.decorator"]
- reload(zope.security.proxy)
+ reload(zope.security)
self.assertTrue(
hasattr(LocationProxy, '__Security_checker__'))