The rexec Module

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.

Example 14-6. Using the rexec Module
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



Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh

Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net