Skip to content

Commit

Permalink
Allow a custom NodeTransformer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Sep 22, 2016
1 parent 7925823 commit 661fbf6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/RestrictedPython/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@


def compile_restricted(
source, filename='<unknown>', mode='exec', flags=0, dont_inherit=0):
"""Replacement for the built-in compile() function."""
source, filename='<unknown>', mode='exec', flags=0, dont_inherit=0,
policy=RestrictingNodeTransformer):
"""Replacement for the built-in compile() function.
policy ... `ast.NodeTransformer` class defining the restrictions.
"""
c_ast = ast.parse(source, filename, mode)
r_ast = RestrictingNodeTransformer().visit(c_ast)
r_ast = policy().visit(c_ast)
return compile(r_ast, filename, mode, flags, dont_inherit)

0 comments on commit 661fbf6

Please sign in to comment.