17.1.1 RExec Objects
RExec instances support the following methods:
-
code must either be a string containing a Python expression, or
a compiled code object, which will be evaluated in the restricted
environment's __main__ module. The value of the expression or
code object will be returned.
-
code must either be a string containing one or more lines of
Python code, or a compiled code object, which will be executed in the
restricted environment's __main__ module.
-
Execute the Python code contained in the file filename in the
restricted environment's __main__ module.
Methods whose names begin with "s_" are similar to the functions
beginning with "r_", but the code will be granted access to
restricted versions of the standard I/O streams sys.stdin
,
sys.stderr
, and sys.stdout
.
-
code must be a string containing a Python expression, which will
be evaluated in the restricted environment.
-
code must be a string containing one or more lines of Python code,
which will be executed in the restricted environment.
-
Execute the Python code contained in the file filename in the
restricted environment.
RExec objects must also support various methods which will be
implicitly called by code executing in the restricted environment.
Overriding these methods in a subclass is used to change the policies
enforced by a restricted environment.
r_import( |
modulename[, globals[,
locals[, fromlist]]]) |
-
Import the module modulename, raising an ImportError
exception if the module is considered unsafe.
r_open( |
filename[, mode[, bufsize]]) |
-
Method called when open() is called in the restricted
environment. The arguments are identical to those of open(),
and a file object (or a class instance compatible with file objects)
should be returned. RExec's default behaviour is allow opening
any file for reading, but forbidding any attempt to write a file. See
the example below for an implementation of a less restrictive
r_open().
-
Reload the module object module, re-parsing and re-initializing it.
-
Unload the module object module (remove it from the
restricted environment's
sys.modules
dictionary).
And their equivalents with access to restricted standard I/O streams:
s_import( |
modulename[, globals[,
locals[, fromlist]]]) |
-
Import the module modulename, raising an ImportError
exception if the module is considered unsafe.
-
Reload the module object module, re-parsing and re-initializing it.
-
Unload the module object module.
Release 2.4, documentation updated on 30 November 2004.
See About this document... for information on suggesting changes.