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

📄 module-simplehttpserver.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.15 SimpleHTTPServer -- Simple HTTP request handler</title>
<META NAME="description" CONTENT="11.15 SimpleHTTPServer -- Simple HTTP request handler">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-CGIHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-CGIHTTPServer.html">
<LINK REL="previous" href="module-BaseHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-BaseHTTPServer.html">
<LINK REL="up" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">
<LINK REL="next" href="module-CGIHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-CGIHTTPServer.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-BaseHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-BaseHTTPServer.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="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.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="module-CGIHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-CGIHTTPServer.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="module-BaseHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-BaseHTTPServer.html">11.14 BaseHTTPServer  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-CGIHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-CGIHTTPServer.html">11.16 CGIHTTPServer  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION00131500000000000000000">
11.15 <tt class="module">SimpleHTTPServer</tt> --
         Simple HTTP request handler</A>
</H1>

<P>


<P>
The <tt class="module">SimpleHTTPServer</tt> module defines a request-handler class,
interface compatible with <tt class="class">BaseHTTPServer.BaseHTTPRequestHandler</tt>
which serves files only from a base directory.

<P>
The <tt class="module">SimpleHTTPServer</tt> module defines the following class:

<P>
<dl><dt><b><a name='l2h-2259'><tt class='class'>SimpleHTTPRequestHandler</tt></a></b> (<var>request, client_address, server</var>)
<dd>
This class is used, to serve files from current directory and below,
directly mapping the directory structure to HTTP requests.

<P>
A lot of the work is done by the base class
<tt class="class">BaseHTTPServer.BaseHTTPRequestHandler</tt>, such as parsing the
request.  This class implements the <tt class="function">do_GET()</tt> and
<tt class="function">do_HEAD()</tt> functions.
</dl>

<P>
The <tt class="class">SimpleHTTPRequestHandler</tt> defines the following member
variables:

<P>
<dl><dt><b><a name='l2h-2260'><tt class='member'>server_version</tt></a></b>
<dd>
This will be <code>"SimpleHTTP/" + __version__</code>, where <code>__version__</code>
is defined in the module.
</dl>

<P>
<dl><dt><b><a name='l2h-2261'><tt class='member'>extensions_map</tt></a></b>
<dd>
A dictionary mapping suffixes into MIME types. Default is signified
by an empty string, and is considered to be <code>text/plain</code>.
The mapping is used case-insensitively, and so should contain only
lower-cased keys.
</dl>

<P>
The <tt class="class">SimpleHTTPRequestHandler</tt> defines the following methods:

<P>
<dl><dt><b><a name='l2h-2262'><tt class='method'>do_HEAD</tt></a></b> ()
<dd>
This method serves the <code>'HEAD'</code> request type: it sends the
headers it would send for the equivalent <code>GET</code> request. See the
<tt class="method">do_GET()</tt> method for more complete explanation of the possible
headers.
</dl>

<P>
<dl><dt><b><a name='l2h-2263'><tt class='method'>do_GET</tt></a></b> ()
<dd>
The request is mapped to a local file by interpreting the request as
a path relative to the current working directory.

<P>
If the request was mapped to a directory, a <code>403</code> respond is output,
followed by the explanation <code>'Directory listing not supported'</code>.
Any <tt class="exception">IOError</tt> exception in opening the requested file, is mapped
to a <code>404</code>, <code>'File not found'</code> error. Otherwise, the content
type is guessed using the <var>extensions_map</var> variable.

<P>
A <code>'Content-type:'</code> with the guessed content type is output, and
then a blank line, signifying end of headers, and then the contents of
the file. The file is always opened in binary mode.

<P>
For example usage, see the implementation of the <tt class="function">test()</tt>
function.
</dl>

<P>
<div class='seealso'>
  <p class='heading'><b>See Also:</b></p>

  <dl compact class="seemodule">
    <dt>Module <b><tt class='module'><a href="module-BaseHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-BaseHTTPServer.html">BaseHTTPServer</a></tt>:</b>
    <dd>Base class implementation for Web server
                             and request handler.
  </dl>
</div>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-BaseHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-BaseHTTPServer.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="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.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="module-CGIHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-CGIHTTPServer.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="module-BaseHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-BaseHTTPServer.html">11.14 BaseHTTPServer  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-CGIHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-CGIHTTPServer.html">11.16 CGIHTTPServer  </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 + -