A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/114912.html below:

rexec and sys.exit()

rexec and sys.exit() 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4