rexec and sys.exit()
Robin Thomas
robin.thomas at starmedia.net
Sun Apr 15 14:51:50 EDT 2001
At 04:34 PM 4/15/01 +0000, Davide Alberani wrote:
>I need to prevent a function (called via r_eval()) to import the sys
>module and then call sys.exit().
Read *all* of the rexec module documentation at
http://www.python.org/doc/current/lib/module-rexec.html
>Sample code:
>
>my_dict = {'exported_var': a_var, ... }
>
>class MyRE(rexec.RExec):
> def r_eval(self, code):
> return eval(code, my_dict)
MyRE.ok_sys_names = () # or some names you wish to allow
>myr = MyRE()
>
>myr.r_eval(function_code)
and don't forget r_exec().
>Now, if function_code contains "import sys ; sys.exit()", the program
>terminates.
With MyRE.ok_sys_names == (), sys.exit will raise an AttributeError.
--
Robin Thomas
Engineering
StarMedia Network, Inc.
robin.thomas at starmedia.net
More information about the Python-list
mailing list