Package spade :: Module pyratemp :: Class PseudoSandbox
[hide private]
[frames] | no frames]

Class PseudoSandbox

source code


A pseudo-eval-sandbox.

- Allow only some of the builtin python-functions
  (see eval_allowed_globals), which are considered "save".
- Forbid names beginning with "_".
  This is to prevent things like '0 .__class__', with which you could
  easily break out of a "sandbox".

Note that this is no real sandbox!
Don't use it for untrusted code!!

Instance Methods [hide private]
 
__init__(self) source code
 
register(self, name, obj)
Add an object to the "allowed eval-globals".
source code
 
compile(self, expr)
Compile a python-eval-expression.
source code
 
eval(self, expr, locals)
Eval a python-eval-expression.
source code
Class Variables [hide private]
  eval_allowed_globals = {'False': False, 'None': None, 'True': ...
Method Details [hide private]

register(self, name, obj)

source code 

Add an object to the "allowed eval-globals".

Mainly useful to add user-defined functions to the pseudo-sandbox.

compile(self, expr)

source code 
Compile a python-eval-expression.

- Use a compile-cache
- Raise an NameError if expr contains a name beginning with '_'.

:Returns: the compiled expr
:Raises: SyntaxError for compile-errors,
         NameError if expr contains a name beginning with '_'

eval(self, expr, locals)

source code 

Eval a python-eval-expression.

Uses the compile-cache.


Class Variable Details [hide private]

eval_allowed_globals

Value:
{'False': False,
 'None': None,
 'True': True,
 'abs': <built-in function abs>,
 'bool': <type 'bool'>,
 'chr': <built-in function chr>,
 'cmp': <built-in function cmp>,
 'complex': <type 'complex'>,
...