⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module-rexec.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</dl>

<P>
<tt class="class">RExec</tt> instances support the following methods:

<P>
<dl><dt><b><a name='l2h-2994'><tt class='method'>r_eval</tt></a></b> (<var>code</var>)
<dd>
<var>code</var> must either be a string containing a Python expression, or
a compiled code object, which will be evaluated in the restricted
environment's <tt class="module">__main__</tt> module.  The value of the expression or
code object will be returned.
</dl>

<P>
<dl><dt><b><a name='l2h-2995'><tt class='method'>r_exec</tt></a></b> (<var>code</var>)
<dd>
<var>code</var> must either be a string containing one or more lines of
Python code, or a compiled code object, which will be executed in the
restricted environment's <tt class="module">__main__</tt> module.
</dl>

<P>
<dl><dt><b><a name='l2h-2996'><tt class='method'>r_execfile</tt></a></b> (<var>filename</var>)
<dd>
Execute the Python code contained in the file <var>filename</var> in the
restricted environment's <tt class="module">__main__</tt> module.
</dl>

<P>
Methods whose names begin with "<tt class="samp">s_</tt>" are similar to the functions
beginning with "<tt class="samp">r_</tt>", but the code will be granted access to
restricted versions of the standard I/O streams <code>sys.stdin</code>,
<code>sys.stderr</code>, and <code>sys.stdout</code>.

<P>
<dl><dt><b><a name='l2h-2997'><tt class='method'>s_eval</tt></a></b> (<var>code</var>)
<dd>
<var>code</var> must be a string containing a Python expression, which will
be evaluated in the restricted environment.  
</dl>

<P>
<dl><dt><b><a name='l2h-2998'><tt class='method'>s_exec</tt></a></b> (<var>code</var>)
<dd>
<var>code</var> must be a string containing one or more lines of Python code,
which will be executed in the restricted environment.  
</dl>

<P>
<dl><dt><b><a name='l2h-2999'><tt class='method'>s_execfile</tt></a></b> (<var>code</var>)
<dd>
Execute the Python code contained in the file <var>filename</var> in the
restricted environment.
</dl>

<P>
<tt class="class">RExec</tt> objects must also support various methods which will be
implicitly called by code executing in the restricted environment.
Overriding these methods in a subclass is used to change the policies
enforced by a restricted environment.

<P>
<dl><dt><b><a name='l2h-3000'><tt class='method'>r_import</tt></a></b> (<var>modulename</var><big>[</big><var>, globals</var><big>[</big><var>,
                             locals</var><big>[</big><var>, fromlist</var><big>]</big><big>]</big><big>]</big>)
<dd>
Import the module <var>modulename</var>, raising an <tt class="exception">ImportError</tt>
exception if the module is considered unsafe.
</dl>

<P>
<dl><dt><b><a name='l2h-3001'><tt class='method'>r_open</tt></a></b> (<var>filename</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><big>]</big>)
<dd>
Method called when <tt class="function">open()</tt> is called in the restricted
environment.  The arguments are identical to those of <tt class="function">open()</tt>,
and a file object (or a class instance compatible with file objects)
should be returned.  <tt class="class">RExec</tt>'s default behaviour is allow opening
any file for reading, but forbidding any attempt to write a file.  See
the example below for an implementation of a less restrictive
<tt class="method">r_open()</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-3002'><tt class='method'>r_reload</tt></a></b> (<var>module</var>)
<dd>
Reload the module object <var>module</var>, re-parsing and re-initializing it.  
</dl>

<P>
<dl><dt><b><a name='l2h-3003'><tt class='method'>r_unload</tt></a></b> (<var>module</var>)
<dd>
Unload the module object <var>module</var> (i.e., remove it from the
restricted environment's <code>sys.modules</code> dictionary).
</dl>

<P>
And their equivalents with access to restricted standard I/O streams:

<P>
<dl><dt><b><a name='l2h-3004'><tt class='method'>s_import</tt></a></b> (<var>modulename</var><big>[</big><var>, globals</var><big>[</big><var>,
                             locals</var><big>[</big><var>, fromlist</var><big>]</big><big>]</big><big>]</big>)
<dd>
Import the module <var>modulename</var>, raising an <tt class="exception">ImportError</tt>
exception if the module is considered unsafe.
</dl>

<P>
<dl><dt><b><a name='l2h-3005'><tt class='method'>s_reload</tt></a></b> (<var>module</var>)
<dd>
Reload the module object <var>module</var>, re-parsing and re-initializing it.  
</dl>

<P>
<dl><dt><b><a name='l2h-3006'><tt class='method'>s_unload</tt></a></b> (<var>module</var>)
<dd>
Unload the module object <var>module</var>.   
</dl>

<P>

<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>

<UL>
<LI><A NAME="tex2html5301"
  HREF="node366.html" tppabs="http://www.python.org/doc/current/lib/node366.html">16.1.1 An example</A>
</UL>
<!--End of Table of Child-Links-->

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="restricted.html" tppabs="http://www.python.org/doc/current/lib/restricted.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="restricted.html" tppabs="http://www.python.org/doc/current/lib/restricted.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A HREF="node366.html" tppabs="http://www.python.org/doc/current/lib/node366.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="restricted.html" tppabs="http://www.python.org/doc/current/lib/restricted.html">16. Restricted Execution</A>
<b class="navlabel">Up:</b> <a class="sectref" href="restricted.html" tppabs="http://www.python.org/doc/current/lib/restricted.html">16. Restricted Execution</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node366.html" tppabs="http://www.python.org/doc/current/lib/node366.html">16.1.1 An example</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -