summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2015-05-29 08:27:25 -0500
committerJason Madden <jamadden@gmail.com>2015-05-29 08:27:25 -0500
commitec3e21fe1df341a077c986eb2d3856224842db45 (patch)
treeec66bacb1fc5a692db607c09736f3d78aa594984 /src
parent762a931cf5cca67d514c2e926a3196d62184d092 (diff)
downloadzope-pagetemplate-ec3e21fe1df341a077c986eb2d3856224842db45.tar.gz
Add PyPy support.
PyPy doesn't support assigning to __builtins__, even in eval(), so this means that zope.untrusted.builtins is not helpful, even though it can be installed. Therefore, HAVE_UNTRUSTED must always be False under PyPy, just like under Python 3. Minor doctest renormalization to deal with the changed class name of the proxy. A pure-Python proxy can't lie about its type, so use __class__ in one doctest.
Diffstat (limited to 'src')
-rw-r--r--src/zope/pagetemplate/engine.py18
-rw-r--r--src/zope/pagetemplate/tests/test_engine.py3
2 files changed, 17 insertions, 4 deletions
diff --git a/src/zope/pagetemplate/engine.py b/src/zope/pagetemplate/engine.py
index df307e7..b8f695d 100644
--- a/src/zope/pagetemplate/engine.py
+++ b/src/zope/pagetemplate/engine.py
@@ -36,6 +36,16 @@ try:
except ImportError:
HAVE_UNTRUSTED = False
+# PyPy doesn't support assigning to '__builtins__', even when
+# using eval() (http://pypy.readthedocs.org/en/latest/cpython_differences.html),
+# so don't try to use it. It won't work.
+if HAVE_UNTRUSTED:
+ import platform
+ if platform.python_implementation() == 'PyPy':
+ HAVE_UNTRUSTED = False
+ del rcompile
+ del SafeBuiltins
+
from zope.tales.expressions import PathExpr, StringExpr, NotExpr, DeferExpr
from zope.tales.expressions import SimpleModuleImporter
from zope.tales.pythonexpr import PythonExpr
@@ -161,7 +171,7 @@ class ZopeContext(ZopeContextBase):
...
>>> zc = ZopeContext(ExpressionEngine, {})
>>> out = zc.evaluateMacro(expression)
- >>> type(out)
+ >>> out.__class__
<type 'list'>
The method does some trivial checking to make sure we are getting
@@ -320,9 +330,9 @@ class ZopeEngine(ZopeBaseEngine):
wrapped in security proxies if the 'untrusted' extra is installed::
>>> r = context.evaluate('python: {12: object()}.values')
- >>> str(type(r).__name__) == (
- ... '_Proxy' if HAVE_UNTRUSTED else
- ... 'builtin_function_or_method')
+ >>> str(type(r).__name__) in (
+ ... ('_Proxy',) if HAVE_UNTRUSTED else
+ ... ('builtin_function_or_method', 'method'))
True
>>> r = context.evaluate('python: {12: object()}[12].__class__')
diff --git a/src/zope/pagetemplate/tests/test_engine.py b/src/zope/pagetemplate/tests/test_engine.py
index 097a597..ab3b5ca 100644
--- a/src/zope/pagetemplate/tests/test_engine.py
+++ b/src/zope/pagetemplate/tests/test_engine.py
@@ -94,6 +94,9 @@ def test_suite():
(re.compile(r"<class 'zope.security._proxy._Proxy'>"),
"<type 'zope.security._proxy._Proxy'>"),
(re.compile(r"<class 'list'>"), "<type 'list'>"),
+ # PyPy/pure-Python implementation
+ (re.compile(r"<class 'zope.security.proxy.ProxyPy'>"),
+ "<type 'zope.security._proxy._Proxy'>"),
])
suite = unittest.TestSuite()