From 95eefdfe636d69802833c95c3ebaf7665f6a5eae Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Fri, 8 Sep 2017 09:30:32 -0500 Subject: Respect PURE_PYTHON at runtime. Partial fix for #33. --- src/zope/security/checker.py | 14 +++++++++----- src/zope/security/proxy.py | 13 +++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/zope/security/checker.py b/src/zope/security/checker.py index d617ef4..238f748 100644 --- a/src/zope/security/checker.py +++ b/src/zope/security/checker.py @@ -49,6 +49,7 @@ from zope.security.interfaces import Unauthorized 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 @@ -438,11 +439,14 @@ _defaultChecker = Checker({}) _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 diff --git a/src/zope/security/proxy.py b/src/zope/security/proxy.py index 60dcae8..9e7333d 100644 --- a/src/zope/security/proxy.py +++ b/src/zope/security/proxy.py @@ -17,7 +17,7 @@ import functools 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): @@ -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 -- cgit v1.2.1