Skip to content

Commit

Permalink
fix compile module
Browse files Browse the repository at this point in the history
  • Loading branch information
loechel committed Sep 28, 2016
1 parent 90e90f7 commit e58ad7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/RestrictedPython/__init__.py
Expand Up @@ -13,20 +13,20 @@
"""RestrictedPython package."""

# Old API --> Old Import Locations
#from RestrictedPython.RCompile import compile_restricted
#from RestrictedPython.RCompile import compile_restricted_eval
#from RestrictedPython.RCompile import compile_restricted_exec
#from RestrictedPython.RCompile import compile_restricted_function
from RestrictedPython.RCompile import compile_restricted
from RestrictedPython.RCompile import compile_restricted_eval
from RestrictedPython.RCompile import compile_restricted_exec
from RestrictedPython.RCompile import compile_restricted_function

# new API Style
from RestrictedPython.compile import compile_restricted
from RestrictedPython.compile import compile_restricted_eval
from RestrictedPython.compile import compile_restricted_exec
from RestrictedPython.compile import compile_restricted_function
#from RestrictedPython.compile import compile_restricted
#from RestrictedPython.compile import compile_restricted_eval
#from RestrictedPython.compile import compile_restricted_exec
#from RestrictedPython.compile import compile_restricted_function

from RestrictedPython.PrintCollector import PrintCollector

#from RestrictedPython.Eval import RestrictionCapableEval
from RestrictedPython.Eval import RestrictionCapableEval

from RestrictedPython.Guards import safe_builtins
from RestrictedPython.Utilities import utility_builtins
Expand Down
20 changes: 15 additions & 5 deletions src/RestrictedPython/compile.py
Expand Up @@ -15,8 +15,8 @@ def compile_restricted_eval(
if policy is None:
# Unrestricted Source Checks
return compile(source, filename, flags=flags, dont_inherit=dont_inherit)
c_ast = ast.parse(source, filename, mode)
r_ast = policy(errors, wanings, used_names).visit(c_ast)
c_ast = ast.parse(source, filename, 'eval')
r_ast = policy(errors, warnings, used_names).visit(c_ast)
try:
byte_code = compile(r_ast, filename, mode='eval', flags=flags,
dont_inherit=dont_inherit)
Expand All @@ -38,8 +38,8 @@ def compile_restricted_exec(
if policy is None:
# Unrestricted Source Checks
return compile(source, filename, flags=flags, dont_inherit=dont_inherit)
c_ast = ast.parse(source, filename, mode)
r_ast = policy(errors, wanings, used_names).visit(c_ast)
c_ast = ast.parse(source, filename, 'exec')
r_ast = policy(errors, warnings, used_names).visit(c_ast)
try:
byte_code = compile(r_ast, filename, mode='exec', flags=flags,
dont_inherit=dont_inherit)
Expand All @@ -54,6 +54,16 @@ def compile_restricted_function(
flags=0,
dont_inherit=0,
policy=RestrictingNodeTransformer):
"""Compiles a restricted code object for a function.
The function can be reconstituted using the 'new' module:
new.function(<code>, <globals>)
The globalize argument, if specified, is a list of variable names to be
treated as globals (code is generated as if each name in the list
appeared in a global statement at the top of the function).
"""
byte_code = None
errors = []
warnings = []
Expand All @@ -62,7 +72,7 @@ def compile_restricted_function(
# Unrestricted Source Checks
return compile(source, filename, flags=flags, dont_inherit=dont_inherit)
c_ast = ast.parse(source, filename, mode)
r_ast = policy(errors, wanings, used_names).visit(c_ast)
r_ast = policy(errors, warnings, used_names).visit(c_ast)
try:
byte_code = compile(r_ast, filename, mode='single', flags=flags,
dont_inherit=dont_inherit)
Expand Down

0 comments on commit e58ad7c

Please sign in to comment.