rest25/library/simplehttpserver.rst => rest262/library/simplehttpserver.rst
f1
2:mod:`SimpleHTTPServer` --- Simple HTTP request handler
3=======================================================
4
5.. module:: SimpleHTTPServer
6   :synopsis: This module provides a basic request handler for HTTP servers.
7.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
8
n9+.. note::
10+   The :mod:`SimpleHTTPServer` module has been merged into :mod:`http.server` in
11+   Python 3.0.  The :term:`2to3` tool will automatically adapt imports when
12+   converting your sources to 3.0.
9
n14+ 
10-The :mod:`SimpleHTTPServer` module defines a request-handler class, interface-
15+The :mod:`SimpleHTTPServer` module defines a single class,
16+:class:`SimpleHTTPRequestHandler`, which is interface-compatible with
11-compatible with :class:`BaseHTTPServer.BaseHTTPRequestHandler`, that serves
17+:class:`BaseHTTPServer.BaseHTTPRequestHandler`.
12-files only from a base directory.
13
14The :mod:`SimpleHTTPServer` module defines the following class:
15
16
17.. class:: SimpleHTTPRequestHandler(request, client_address, server)
18
n19-   This class is used to serve files from the current directory and below, directly
n24+   This class serves files from the current directory and below, directly
20   mapping the directory structure to HTTP requests.
21
22   A lot of the work, such as parsing the request, is done by the base class
23   :class:`BaseHTTPServer.BaseHTTPRequestHandler`.  This class implements the
24   :func:`do_GET` and :func:`do_HEAD` functions.
25
n26-The :class:`SimpleHTTPRequestHandler` defines the following member variables:
n31+   The following are defined as class-level attributes of
32+   :class:`SimpleHTTPRequestHandler`:
27
28
n29-.. attribute:: SimpleHTTPRequestHandler.server_version
n35+   .. attribute:: server_version
30
n31-   This will be ``"SimpleHTTP/" + __version__``, where ``__version__`` is defined
n37+   This will be ``"SimpleHTTP/" + __version__``, where ``__version__`` is
32-   in the module.
38+   defined at the module level.
33
34
n35-.. attribute:: SimpleHTTPRequestHandler.extensions_map
n41+   .. attribute:: extensions_map
36
n37-   A dictionary mapping suffixes into MIME types. The default is signified by an
n43+      A dictionary mapping suffixes into MIME types. The default is
38-   empty string, and is considered to be ``application/octet-stream``. The mapping
44+      signified by an empty string, and is considered to be
45+      ``application/octet-stream``. The mapping is used case-insensitively,
39-   is used case-insensitively, and so should contain only lower-cased keys.
46+      and so should contain only lower-cased keys.
40
n41-The :class:`SimpleHTTPRequestHandler` defines the following methods:
n48+   The :class:`SimpleHTTPRequestHandler` class defines the following methods:
42
43
n44-.. method:: SimpleHTTPRequestHandler.do_HEAD()
n51+   .. method:: do_HEAD()
45
n46-   This method serves the ``'HEAD'`` request type: it sends the headers it would
n53+      This method serves the ``'HEAD'`` request type: it sends the headers it
47-   send for the equivalent ``GET`` request. See the :meth:`do_GET` method for a
54+      would send for the equivalent ``GET`` request. See the :meth:`do_GET`
48-   more complete explanation of the possible headers.
55+      method for a more complete explanation of the possible headers.
49
50
n51-.. method:: SimpleHTTPRequestHandler.do_GET()
n58+   .. method:: do_GET()
52
n53-   The request is mapped to a local file by interpreting the request as a path
n60+      The request is mapped to a local file by interpreting the request as a
54-   relative to the current working directory.
61+      path relative to the current working directory.
55
n56-   If the request was mapped to a directory, the directory is checked for a file
n63+      If the request was mapped to a directory, the directory is checked for a
57-   named ``index.html`` or ``index.htm`` (in that order). If found, the file's
64+      file named ``index.html`` or ``index.htm`` (in that order). If found, the
58-   contents are returned; otherwise a directory listing is generated by calling the
65+      file's contents are returned; otherwise a directory listing is generated
59-   :meth:`list_directory` method. This method uses :func:`os.listdir` to scan the
66+      by calling the :meth:`list_directory` method. This method uses
60-   directory, and returns a ``404`` error response if the :func:`listdir` fails.
67+      :func:`os.listdir` to scan the directory, and returns a ``404`` error
68+      response if the :func:`listdir` fails.
61
n62-   If the request was mapped to a file, it is opened and the contents are returned.
n70+      If the request was mapped to a file, it is opened and the contents are
63-   Any :exc:`IOError` exception in opening the requested file is mapped to a
71+      returned.  Any :exc:`IOError` exception in opening the requested file is
64-   ``404``, ``'File not found'`` error. Otherwise, the content type is guessed by
72+      mapped to a ``404``, ``'File not found'`` error. Otherwise, the content
65-   calling the :meth:`guess_type` method, which in turn uses the *extensions_map*
73+      type is guessed by calling the :meth:`guess_type` method, which in turn
66-   variable.
74+      uses the *extensions_map* variable.
67
n68-   A ``'Content-type:'`` header with the guessed content type is output, followed
n76+      A ``'Content-type:'`` header with the guessed content type is output,
69-   by a ``'Content-Length:'`` header with the file's size and a
77+      followed by a ``'Content-Length:'`` header with the file's size and a
70-   ``'Last-Modified:'`` header with the file's modification time.
78+      ``'Last-Modified:'`` header with the file's modification time.
71
n72-   Then follows a blank line signifying the end of the headers, and then the
n80+      Then follows a blank line signifying the end of the headers, and then the
73-   contents of the file are output. If the file's MIME type starts with ``text/``
81+      contents of the file are output. If the file's MIME type starts with
74-   the file is opened in text mode; otherwise binary mode is used.
82+      ``text/`` the file is opened in text mode; otherwise binary mode is used.
75
n76-   For example usage, see the implementation of the :func:`test` function.
n84+      For example usage, see the implementation of the :func:`test` function.
77
t78-   .. versionadded:: 2.5
t86+      .. versionadded:: 2.5
79-      The ``'Last-Modified'`` header.
87+         The ``'Last-Modified'`` header.
80
81
82.. seealso::
83
84   Module :mod:`BaseHTTPServer`
85      Base class implementation for Web server and request handler.
86
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op