Skip to content

Commit

Permalink
Remove the dependency on sourcecodegen.
Browse files Browse the repository at this point in the history
We do not need to convert the ast to source code before passing it to the
RestrictedPython machinery. It takes the result of the 2.7 ast.parse() as well.
  • Loading branch information
sallner authored and hannosch committed May 3, 2017
1 parent c770e88 commit da9f1a0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
1 change: 0 additions & 1 deletion requirements-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pbr==3.0.0
persistent==4.2.2
pytz==2017.2
six==1.10.0
sourcecodegen==0.6.14
transaction==2.1.2
waitress==1.0.2
z3c.pt==3.0
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def _read_file(filename):
'ZODB',
'setuptools',
'six',
'sourcecodegen',
'transaction',
'waitress',
'zExceptions >= 3.4',
Expand Down
13 changes: 4 additions & 9 deletions src/Products/PageTemplates/expression.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ast import NodeTransformer
from ast import NodeTransformer, parse
from types import ClassType
from compiler import parse as ast24_parse

from OFS.interfaces import ITraversable
from zExceptions import NotFound, Unauthorized
Expand All @@ -23,7 +22,6 @@
from chameleon.astutil import Symbol
from chameleon.astutil import Static
from chameleon.codegen import template
from sourcecodegen import generate_code

from z3c.pt import expressions
import collections
Expand Down Expand Up @@ -170,13 +168,10 @@ def rewrite(self, node):

def parse(self, string):
encoded = string.encode('utf-8')
node = ast24_parse(encoded, 'eval').node
node = parse(encoded, mode='eval')
MutatingWalker.walk(node, self.rm)
string = generate_code(node)
decoded = string.decode('utf-8')
value = super(UntrustedPythonExpr, self).parse(decoded)

# Run restricted python transform
self.rt.visit(value)
self.rt.visit(node)

return value
return node
1 change: 0 additions & 1 deletion versions-prod.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pytz = 2017.2
Record = 3.2
RestrictedPython = 3.6.0
six = 1.10.0
sourcecodegen = 0.6.14
transaction = 2.1.2
waitress = 1.0.2
WebOb = 1.7.2
Expand Down

0 comments on commit da9f1a0

Please sign in to comment.