Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RestrictedPython-3.6.0
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
RestrictedPython-3.6.0
Commits
ffbdc730
Commit
ffbdc730
authored
Nov 14, 2016
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not compile code, return None directly
parent
a21f7511
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
30 deletions
+33
-30
src/RestrictedPython/Eval.py
src/RestrictedPython/Eval.py
+31
-29
src/RestrictedPython/RCompile.py
src/RestrictedPython/RCompile.py
+2
-1
No files found.
src/RestrictedPython/Eval.py
View file @
ffbdc730
...
...
@@ -56,40 +56,42 @@ class RestrictionCapableEval:
if
PROFILE
:
from
time
import
clock
start
=
clock
()
co
,
err
,
warn
,
used
=
compile_restricted_eval
(
self
.
expr
,
'<string>'
)
if
PROFILE
:
end
=
clock
()
print
'prepRestrictedCode: %d ms for %s'
%
(
(
end
-
start
)
*
1000
,
`self.expr`
)
if
err
:
raise
SyntaxError
,
err
[
0
]
self
.
used
=
tuple
(
used
.
keys
())
self
.
rcode
=
co
# Pyston change: do nothing
# co, err, warn, used = compile_restricted_eval(
# self.expr, '<string>')
# if PROFILE:
# end = clock()
# print 'prepRestrictedCode: %d ms for %s' % (
# (end - start) * 1000, `self.expr`)
# if err:
# raise SyntaxError, err[0]
# self.used = tuple(used.keys())
# self.rcode = co
def
prepUnrestrictedCode
(
self
):
if
self
.
ucode
is
None
:
# Use the standard compiler.
co
=
compile
(
self
.
expr
,
'<string>'
,
'eval'
)
if
self
.
used
is
None
:
# Examine the code object, discovering which names
# the expression needs.
names
=
list
(
co
.
co_names
)
used
=
{}
i
=
0
code
=
co
.
co_code
l
=
len
(
code
)
LOAD_NAME
=
101
HAVE_ARGUMENT
=
90
while
(
i
<
l
):
c
=
ord
(
code
[
i
])
if
c
==
LOAD_NAME
:
name
=
names
[
ord
(
code
[
i
+
1
])
+
256
*
ord
(
code
[
i
+
2
])]
used
[
name
]
=
1
i
=
i
+
3
elif
c
>=
HAVE_ARGUMENT
:
i
=
i
+
3
else
:
i
=
i
+
1
self
.
used
=
tuple
(
used
.
keys
())
# Pyston change: return code directly
# if self.used is None:
# # Examine the code object, discovering which names
# # the expression needs.
# names=list(co.co_names)
# used={}
# i=0
# code=co.co_code
# l=len(code)
# LOAD_NAME=101
# HAVE_ARGUMENT=90
# while(i < l):
# c=ord(code[i])
# if c==LOAD_NAME:
# name=names[ord(code[i+1])+256*ord(code[i+2])]
# used[name]=1
# i=i+3
# elif c >= HAVE_ARGUMENT: i=i+3
# else: i=i+1
# self.used=tuple(used.keys())
self
.
ucode
=
co
def
eval
(
self
,
mapping
):
...
...
src/RestrictedPython/RCompile.py
View file @
ffbdc730
...
...
@@ -101,7 +101,8 @@ def compile_restricted_eval(s, filename='<string>'):
"""Compiles a restricted expression."""
# gen = RExpression(s, filename)
# return compileAndTuplize(gen)
return
compile
(
s
,
filename
,
'eval'
),
(),
[],
{}
# return compile(s, filename, 'eval'), (), [], {}
return
None
def
compile_restricted
(
source
,
filename
,
mode
):
"""Replacement for the builtin compile() function."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment