rexec
index
/usr/lib/python2.2/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
       
   Data and non-method functions defined here:
__doc__ = None
__module__ = 'rexec'
ok_file_methods = ('fileno', 'flush', 'isatty', 'read', 'readline', 'readlines', 'seek', 'tell', 'write', 'writelines')
 
class FileDelegate(FileBase)
       
   Methods defined here:
__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)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'rexec'
m = 'close'

Data and non-method functions inherited from FileBase:
ok_file_methods = ('fileno', 'flush', 'isatty', 'read', 'readline', 'readlines', 'seek', 'tell', 'write', 'writelines')
 
class FileWrapper(FileBase)
       
   Methods defined here:
__init__(self, f)
close(self)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'rexec'

Data and non-method functions inherited from FileBase:
ok_file_methods = ('fileno', 'flush', 'isatty', 'read', 'readline', 'readlines', 'seek', 'tell', 'write', 'writelines')
 
class RExec(ihooks._Verbose)
      Restricted Execution environment.
 
   Methods defined here:
__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)

Data and non-method functions defined here:
__doc__ = 'Restricted Execution environment.'
__module__ = 'rexec'
nok_builtin_names = ('open', 'file', 'reload', '__import__')
ok_builtin_modules = ('audioop', 'array', 'binascii', 'cmath', 'errno', 'imageop', 'marshal', 'math', 'md5', 'operator', 'parser', 'regex', 'pcre', 'rotor', 'select', 'sha', '_sre', 'strop', 'struct', 'time')
ok_path = ('.', '/home/ping/python', '/usr/lib/python2.2', '/usr/lib/python2.2/plat-linux2', '/usr/lib/python2.2/lib-tk', '/usr/lib/python2.2/lib-dynload', '/usr/lib/python2.2/site-packages')
ok_posix_names = ('error', 'fstat', 'listdir', 'lstat', 'readlink', 'stat', 'times', 'uname', 'getpid', 'getppid', 'getcwd', 'getuid', 'getgid', 'geteuid', 'getegid')
ok_sys_names = ('ps1', 'ps2', 'copyright', 'version', 'platform', 'exit', 'maxint')

Methods inherited from ihooks._Verbose:
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
class RHooks(ihooks.Hooks)
       
  
Method resolution order:
RHooks
ihooks.Hooks
ihooks._Verbose

Methods defined here:
__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)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'rexec'

Methods inherited from ihooks.Hooks:
get_frozen_object(self, name)
get_suffixes(self)
# imp interface
is_frozen(self, name)
listdir(self, x)
new_module(self, name)
openfile(self, *x)
path_exists(self, x)
path_isabs(self, x)
path_isdir(self, x)
path_isfile(self, x)
path_islink(self, x)
path_join(self, x, y)
path_split(self, x)

Data and non-method functions inherited from ihooks.Hooks:
listdir_error = <class exceptions.OSError>
OS system call failed.
openfile_error = <class exceptions.IOError>
I/O operation failed.

Methods inherited from ihooks._Verbose:
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
Functions
            
test()
 
Data
             TEMPLATE = '\ndef %s(self, *args):\n return apply(getattr(self.mod, self.name).%s, args)\n'
__all__ = ['RExec']
__file__ = '/usr/lib/python2.2/rexec.pyc'
__name__ = 'rexec'