rexec
index
/usr/lib/python1.5/rexec.py
 

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 ...")?)

   
Modules
                        
__builtin__
ihooks
os
sys

   
Classes
                        
FileBase
FileDelegate
FileWrapper
ihooks.Hooks(ihooks._Verbose)
RHooks
ihooks._Verbose
RExec

   
class FileBase
              

   
class FileDelegate(FileBase)
              
__init__(self, mod, name)
close(self, *args)
fileno(self, *args)
flush(self, *args)
isatty(self, *args)
read(self, *args)
readline(self, *args)
readlines(self, *args)
seek(self, *args)
tell(self, *args)
write(self, *args)
writelines(self, *args)

   
class FileWrapper(FileBase)
              
__init__(self, f)
close(self)

   
class RExec(ihooks._Verbose)
            Restricted Execution environment.
              
__init__(self, hooks=None, verbose=0)
add_module(self, mname)
copy_except(self, src, exceptions)
copy_none(self, src)
copy_only(self, src, names)
is_builtin(self, mname)
load_dynamic(self, name, filename, file)
make_builtin(self)
make_delegate_files(self)
make_initial_modules(self)
make_main(self)
make_osname(self)
make_sys(self)
r_eval(self, code)
r_exc_info(self)
r_exec(self, code)
r_execfile(self, file)
r_import(self, mname, globals={}, locals={}, fromlist=[])
r_open(self, file, mode='r', buf=-1)
r_reload(self, m)
r_unload(self, m)
reset_files(self)
restore_files(self)
s_apply(self, func, args=(), kw=None)
s_eval(self, *args)
s_exec(self, *args)
s_execfile(self, *args)
s_import(self, *args)
s_reload(self, *args)
s_unload(self, *args)
save_files(self)
set_files(self)
set_trusted_path(self)

   
class RHooks(ihooks.Hooks)
              
__init__(self, *args)
add_module(self, name)
default_path(self)
init_builtin(self, name)
init_frozen(self, name)
is_builtin(self, name)
load_compiled(self, *args)
load_dynamic(self, name, filename, file)
load_package(self, *args)
load_source(self, *args)
modules_dict(self)
set_rexec(self, rexec)

   
Constants
                        
TEMPLATE = '\012def %s(self, *args):\012 ...d, self.name).%s, args)\012'