Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / module-SimpleHTTPServer.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-CGIHTTPServer.html" />
<link rel="prev" href="module-BaseHTTPServer.html" />
<link rel="parent" href="internet.html" />
<link rel="next" href="module-CGIHTTPServer.html" />
<meta name='aesop' content='information' />
<title>11.18 SimpleHTTPServer -- Simple HTTP request handler</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="11.17 BaseHTTPServer "
href="module-BaseHTTPServer.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="11. Internet Protocols and"
href="internet.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="11.19 CGIHTTPServer "
href="module-CGIHTTPServer.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-BaseHTTPServer.html">11.17 BaseHTTPServer </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-CGIHTTPServer.html">11.19 CGIHTTPServer </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00131800000000000000000">
11.18 <tt class="module">SimpleHTTPServer</tt> --
Simple HTTP request handler</A>
</H1>
<P>
<A NAME="module-SimpleHTTPServer"></A>
<P>
The <tt class="module">SimpleHTTPServer</tt> module defines a request-handler class,
interface-compatible with <tt class="class">BaseHTTPServer.BaseHTTPRequestHandler</tt>,
that serves files only from a base directory.
<P>
The <tt class="module">SimpleHTTPServer</tt> module defines the following class:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3605' xml:id='l2h-3605' class="class">SimpleHTTPRequestHandler</tt></b>(</nobr></td>
<td><var>request, client_address, server</var>)</td></tr></table></dt>
<dd>
This class is used to serve files from the current directory and below,
directly mapping the directory structure to HTTP requests.
<P>
A lot of the work, such as parsing the request, is done by the base
class <tt class="class">BaseHTTPServer.BaseHTTPRequestHandler</tt>. 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><tt id='l2h-3606' xml:id='l2h-3606' class="member">server_version</tt></b></dt>
<dd>
This will be <code>"SimpleHTTP/" + __version__</code>, where <code>__version__</code>
is defined in the module.
</dl>
<P>
<dl><dt><b><tt id='l2h-3607' xml:id='l2h-3607' class="member">extensions_map</tt></b></dt>
<dd>
A dictionary mapping suffixes into MIME types. The default is signified
by an empty string, and is considered to be <code>application/octet-stream</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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3608' xml:id='l2h-3608' class="method">do_HEAD</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<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 a more complete explanation of the possible
headers.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3609' xml:id='l2h-3609' class="method">do_GET</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<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, the directory is checked for
a file named <code>index.html</code> or <code>index.htm</code> (in that order).
If found, the file's contents are returned; otherwise a directory
listing is generated by calling the <tt class="method">list_directory()</tt> method.
This method uses <tt class="function">os.listdir()</tt> to scan the directory, and
returns a <code>404</code> error response if the <tt class="function">listdir()</tt> fails.
<P>
If the request was mapped to a file, it is opened and the contents are
returned. 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 by calling the
<tt class="method">guess_type()</tt> method, which in turn uses the
<var>extensions_map</var> variable.
<P>
A <code>'Content-type:'</code> header with the guessed content type is
output, followed by a blank line signifying the end of the headers,
and then the contents of the file are output. If the file's MIME type
starts with <code>text/</code> the file is opened in text mode; otherwise
binary mode is used.
<P>
For example usage, see the implementation of the <tt class="function">test()</tt>
function.
</dl>
<P>
<div class="seealso">
<p class="heading">See Also:</p>
<dl compact="compact" class="seemodule">
<dt>Module <b><tt class="module"><a href="module-BaseHTTPServer.html">BaseHTTPServer</a></tt>:</b>
<dd>Base class implementation for Web server
and request handler.
</dl>
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="11.17 BaseHTTPServer "
href="module-BaseHTTPServer.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="11. Internet Protocols and"
href="internet.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="11.19 CGIHTTPServer "
href="module-CGIHTTPServer.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-BaseHTTPServer.html">11.17 BaseHTTPServer </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-CGIHTTPServer.html">11.19 CGIHTTPServer </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>