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
Show 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:
...
@@ -56,40 +56,42 @@ class RestrictionCapableEval:
if
PROFILE
:
if
PROFILE
:
from
time
import
clock
from
time
import
clock
start
=
clock
()
start
=
clock
()
co
,
err
,
warn
,
used
=
compile_restricted_eval
(
# Pyston change: do nothing
self
.
expr
,
'<string>'
)
# co, err, warn, used = compile_restricted_eval(
if
PROFILE
:
# self.expr, '<string>')
end
=
clock
()
# if PROFILE:
print
'prepRestrictedCode: %d ms for %s'
%
(
# end = clock()
(
end
-
start
)
*
1000
,
`self.expr`
)
# print 'prepRestrictedCode: %d ms for %s' % (
if
err
:
# (end - start) * 1000, `self.expr`)
raise
SyntaxError
,
err
[
0
]
# if err:
self
.
used
=
tuple
(
used
.
keys
())
# raise SyntaxError, err[0]
self
.
rcode
=
co
# self.used = tuple(used.keys())
# self.rcode = co
def
prepUnrestrictedCode
(
self
):
def
prepUnrestrictedCode
(
self
):
if
self
.
ucode
is
None
:
if
self
.
ucode
is
None
:
# Use the standard compiler.
# Use the standard compiler.
co
=
compile
(
self
.
expr
,
'<string>'
,
'eval'
)
co
=
compile
(
self
.
expr
,
'<string>'
,
'eval'
)
if
self
.
used
is
None
:
# Pyston change: return code directly
# Examine the code object, discovering which names
# if self.used is None:
# the expression needs.
# # Examine the code object, discovering which names
names
=
list
(
co
.
co_names
)
# # the expression needs.
used
=
{}
# names=list(co.co_names)
i
=
0
# used={}
code
=
co
.
co_code
# i=0
l
=
len
(
code
)
# code=co.co_code
LOAD_NAME
=
101
# l=len(code)
HAVE_ARGUMENT
=
90
# LOAD_NAME=101
while
(
i
<
l
):
# HAVE_ARGUMENT=90
c
=
ord
(
code
[
i
])
# while(i < l):
if
c
==
LOAD_NAME
:
# c=ord(code[i])
name
=
names
[
ord
(
code
[
i
+
1
])
+
256
*
ord
(
code
[
i
+
2
])]
# if c==LOAD_NAME:
used
[
name
]
=
1
# name=names[ord(code[i+1])+256*ord(code[i+2])]
i
=
i
+
3
# used[name]=1
elif
c
>=
HAVE_ARGUMENT
:
i
=
i
+
3
# i=i+3
else
:
i
=
i
+
1
# elif c >= HAVE_ARGUMENT: i=i+3
self
.
used
=
tuple
(
used
.
keys
())
# else: i=i+1
# self.used=tuple(used.keys())
self
.
ucode
=
co
self
.
ucode
=
co
def
eval
(
self
,
mapping
):
def
eval
(
self
,
mapping
):
...
...
src/RestrictedPython/RCompile.py
View file @
ffbdc730
...
@@ -101,7 +101,8 @@ def compile_restricted_eval(s, filename='<string>'):
...
@@ -101,7 +101,8 @@ def compile_restricted_eval(s, filename='<string>'):
"""Compiles a restricted expression."""
"""Compiles a restricted expression."""
# gen = RExpression(s, filename)
# gen = RExpression(s, filename)
# return compileAndTuplize(gen)
# return compileAndTuplize(gen)
return
compile
(
s
,
filename
,
'eval'
),
(),
[],
{}
# return compile(s, filename, 'eval'), (), [], {}
return
None
def
compile_restricted
(
source
,
filename
,
mode
):
def
compile_restricted
(
source
,
filename
,
mode
):
"""Replacement for the builtin compile() function."""
"""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