Module rexec
[hide private]
[frames] | no frames]

Module rexec

Restricted execution facilities.

The class RExec exports methods r_exec(), r_eval(), r_execfile(), and
r_import(), which correspond roughly to the built-in operations
exec, eval(), execfile() and import, but executing the code in an
environment that only exposes those built-in operations that are
deemed safe.  To this end, a modest collection of 'fake' modules is
created which mimics the standard modules by the same names.  It is a
policy decision which built-in modules and operations are made
available; this module provides a reasonable default, but derived
classes can change the policies e.g. by overriding or extending class
variables like ok_builtin_modules or methods like make_sys().

XXX To do:
- r_open should allow writing tmp dir
- r_exec etc. with explicit globals/locals? (Use rexec("exec ... in ...")?)

Classes [hide private]
FileBase
FileWrapper
FileDelegate
RHooks
RExec
Basic restricted execution framework.
Functions [hide private]
 
test()
Variables [hide private]
  TEMPLATE = '\ndef %s(self, *args):\n return getattr(sel...

Imports: sys, __builtin__, os, ihooks, imp, RModuleLoader, RModuleImporter


Variables Details [hide private]

TEMPLATE

Value:
'''
def %s(self, *args):
        return getattr(self.mod, self.name).%s(*args)
'''