Scribus
Open source desktop publishing at your fingertips
safe_eval.SafeEvalVisitor Class Reference
Inheritance diagram for safe_eval.SafeEvalVisitor:
Collaboration diagram for safe_eval.SafeEvalVisitor:

Public Member Functions

def __init__ (self)
 
def walk (self, ast)
 
def visit (self, node, args)
 
def visitName (self, node, args)
 
def visitGetattr (self, node, args)
 
def ok (self, node, args)
 
def fail (self, node, args)
 
def trace (self, node)
 

Public Attributes

 errors
 

Detailed Description

Data-driven visitor which walks the AST for some code and makes
sure it doesn't contain any expression/statements which are
declared as restricted in 'unallowed_ast_nodes'. We'll also make
sure that there aren't any attempts to access/lookup restricted
builtin declared in 'unallowed_builtins'. By default we also won't
allow access to lowlevel stuff which can be used to dynamically
access non-local envrioments.

Interface:
  walk(ast) = validate AST and return True if AST is 'safe'

Attributes:
  errors = list of SafeEvalError if walk() returned False

Implementation:

The visitor will automatically generate methods for all of the
available AST node types and redirect them to self.ok or self.fail
reflecting the configuration in 'unallowed_ast_nodes'. While
walking the AST we simply forward the validating step to each of
node callbacks which take care of reporting errors.

The documentation for this class was generated from the following file: