📄 153.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -> Restricted Execution Mode</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> > <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> > <a href="148.html" class="navtitle">9. Other Advanced Topics</a> > <span class="nonavtitle">Restricted Execution Mode</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="152.html" title="Working with Sounds"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=153" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="153.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="154.html" title="Scientific Computing"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A40%3A24+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162148044238006085047159006</font><a href="read6.asp?bookname=0672319942&snode=153&now=5%2F31%2F2002+4%3A40%3A24+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>
Restricted Execution Mode</h3>
<p>Restricted Execution is the basic framework in Python that allows the segregation of trusted and untrusted code. These modules prevent access to critical operations mostly because a program running in trusted mode can create an execution environment in which untrusted code can be executed with limited privileges.</p>
<P>Two modules implement Python support to restricted execution: <TT Class="monofont">rexec</TT> and <A Name="idx1073745386"></a>
<A NAMe="idx1073745387"></a>
<tt class="monofont">Bastion.</tt>
</p>
<p>The <a name="idx1073745388"></a>
<a NamE="idx1073745389"></a>
<tt Class="monofont">rexec</Tt> module implements a basic restricted execution framework by encapsulating, in a class (which is called <tt CLASs="monofont">RExec</tt>), the attributes that specify the capabilities for the code to execute. Code executed in this restricted environment will only have access to modules and functions that are believed to be safe.<a NAME="idx1073745390"></a>
<a naME="idx1073745391"></A>
<A name="idx1073745392"></A>
<A NAme="idx1073745393"></a>
</p>
<p>The idea is to use a program that runs in trusted mode to create an execution environment in which you can define limits to be applied on the execution of the untrusted code.</p>
<p>The <a name="idx1073745394"></a>
<a name="idx1073745395"></a>
<tT clAss="monofont">rexec.RExec()</tT> creates an instance of the <tt clAss="monofont">RExec</tT> class. By doing so, you implement a restricted environment. You can also subclass the <TT Class="monofont">RExec</TT> class, and change any one of the <I>class variables</I> that define the environment by modifying the <tt clASS="monofont">__init__()</Tt> method of the class.</p>
<blOCKQuote>
<p>
<p>
<tt class="monofont">RExec.ok_builtin_modules
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -