Skip to content

Commit

Permalink
Start of PyPy support.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Mar 11, 2013
1 parent f421e5b commit 8cce64b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/zope/security/__init__.py
Expand Up @@ -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

4 changes: 4 additions & 0 deletions src/zope/security/_compat.py
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/zope/security/checker.py
Expand Up @@ -50,8 +50,8 @@
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
Expand Down Expand Up @@ -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.
Expand Down
27 changes: 15 additions & 12 deletions src/zope/security/proxy.py
Expand Up @@ -19,6 +19,7 @@
import sys

from zope.proxy import PyProxyBase
from zope.security._compat import PYPY
from zope.security.interfaces import ForbiddenAttribute


Expand Down Expand Up @@ -272,28 +273,27 @@ def __repr__(self):
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
"""
Expand All @@ -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)
6 changes: 3 additions & 3 deletions src/zope/security/tests/test_proxy.py
Expand Up @@ -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
Expand All @@ -1904,7 +1904,7 @@ def test_LocationProxy_gets_a_security_checker_when_importing_z_s_proxy(
# 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__'))

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -3,7 +3,7 @@ envlist =
# Jython support pending 2.7 support, due 2012-07-15 or so. See:
# http://fwierzbicki.blogspot.com/2012/03/adconion-to-fund-jython-27.html
# py26,py27,pypy,jython,py32,py33,coverage,docs
py26,py27,py32,py33,coverage,docs
py26,py27,pypy,py32,py33,coverage,docs

[testenv]
deps =
Expand Down

0 comments on commit 8cce64b

Please sign in to comment.