The rexec module, shown in Example 14-6, provides versions of exec, eval, and import, which execute code in a restricted execution environment. In this environment, functions that can damage resources on the local machine are no longer available.
File: rexec-example-1.py import rexec r = rexec.RExec() print r.r_eval("1+2+3") print r.r_eval("_ _import_ _(os).remove(file)") 6 Traceback (innermost last): File "rexec-example-1.py", line 5, in ? print r.r_eval("_ _import_ _(os).remove(file)") File "/usr/local/lib/python1.5/rexec.py", line 257, in r_eval return eval(code, m._ _dict_ _) File "", line 0, in ? AttributeError: remove
Core Modules
More Standard Modules
Threads and Processes
Data Representation
File Formats
Mail and News Message Processing
Network Protocols
Internationalization
Multimedia Modules
Data Storage
Tools and Utilities
Platform-Specific Modules
Implementation Support Modules
Other Modules