Skip to content

Commit

Permalink
Respect PURE_PYTHON at runtime. Partial fix for #33.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Sep 8, 2017
1 parent d8565d6 commit 95eefdf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Changes
- Simplify the internal ``_compat.py`` module now that we only run on
newer Python versions. See `PR 32 <https://github.com/zopefoundation/zope.security/pull/32>`_.

- Respect ``PURE_PYTHON`` at runtime. See `issue 33
<https://github.com/zopefoundation/zope.security/issues/33>`_.

4.1.1 (2017-05-17)
------------------

Expand Down
14 changes: 9 additions & 5 deletions src/zope/security/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
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 PURE_PYTHON
from zope.security.proxy import Proxy
from zope.security.proxy import getChecker

Expand Down Expand Up @@ -438,11 +439,14 @@ def undefineChecker(type_):
_available_by_default = []

# Get optimized versions
try:
import zope.security._zope_security_checker
except (ImportError, AttributeError): #pragma NO COVER PyPy / PURE_PYTHON
pass
else:
_c_available = not PURE_PYTHON
if _c_available:
try:
import zope.security._zope_security_checker
except (ImportError, AttributeError): #pragma NO COVER PyPy / PURE_PYTHON
_c_available = False

if _c_available:
from zope.security._zope_security_checker import _checkers, selectChecker
from zope.security._zope_security_checker import NoProxy, Checker
from zope.security._zope_security_checker import _defaultChecker
Expand Down
13 changes: 9 additions & 4 deletions src/zope/security/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys

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

def _check_name(meth, wrap_result=True):
Expand Down Expand Up @@ -346,9 +346,14 @@ def getObjectPy(proxy):
return proxy
return super(PyProxyBase, proxy).__getattribute__('_wrapped')

try:
from zope.security._proxy import _Proxy
except (ImportError, AttributeError): #pragma NO COVER PyPy / PURE_PYTHON
_c_available = not PURE_PYTHON
if _c_available:
try:
from zope.security._proxy import _Proxy
except (ImportError, AttributeError): #pragma NO COVER PyPy / PURE_PYTHON
_c_available = False

if not _c_available:
getChecker = getCheckerPy
getObject = getObjectPy
Proxy = ProxyPy
Expand Down

0 comments on commit 95eefdf

Please sign in to comment.