Commit ffbdc730 authored by Boxiang Sun's avatar Boxiang Sun

do not compile code, return None directly

parent a21f7511
......@@ -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):
......
......@@ -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."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment