annotate Doc/library/simplehttpserver.rst @ 47310:662d15af52df legacy-trunk

Add renaming notices to 3.0 http package members.
author Georg Brandl <georg@python.org>
date Mon, 26 May 2008 15:01:48 +0000
parents 3d9ddce2da85
children 84fefbf1d6c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
1
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
2 :mod:`SimpleHTTPServer` --- Simple HTTP request handler
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
3 =======================================================
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
4
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
5 .. module:: SimpleHTTPServer
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
6 :synopsis: This module provides a basic request handler for HTTP servers.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
7 .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
8
47310
662d15af52df Add renaming notices to 3.0 http package members.
Georg Brandl <georg@python.org>
parents: 46581
diff changeset
9 .. note::
662d15af52df Add renaming notices to 3.0 http package members.
Georg Brandl <georg@python.org>
parents: 46581
diff changeset
10 The :mod:`SimpleHTTPServer` module has been merged into :mod:`http.server` in
662d15af52df Add renaming notices to 3.0 http package members.
Georg Brandl <georg@python.org>
parents: 46581
diff changeset
11 Python 3.0. The :term:`2to3` tool will automatically adapt imports when
662d15af52df Add renaming notices to 3.0 http package members.
Georg Brandl <georg@python.org>
parents: 46581
diff changeset
12 converting your sources to 3.0.
662d15af52df Add renaming notices to 3.0 http package members.
Georg Brandl <georg@python.org>
parents: 46581
diff changeset
13
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
14
46581
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
15 The :mod:`SimpleHTTPServer` module defines a single class,
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
16 :class:`SimpleHTTPRequestHandler`, which is interface-compatible with
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
17 :class:`BaseHTTPServer.BaseHTTPRequestHandler`.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
18
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
19 The :mod:`SimpleHTTPServer` module defines the following class:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
20
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
21
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
22 .. class:: SimpleHTTPRequestHandler(request, client_address, server)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
23
46581
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
24 This class serves files from the current directory and below, directly
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
25 mapping the directory structure to HTTP requests.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
26
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
27 A lot of the work, such as parsing the request, is done by the base class
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
28 :class:`BaseHTTPServer.BaseHTTPRequestHandler`. This class implements the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
29 :func:`do_GET` and :func:`do_HEAD` functions.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
30
46581
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
31 The following are defined as class-level attributes of
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
32 :class:`SimpleHTTPRequestHandler`:
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
33
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
34
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
35 .. attribute:: server_version
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
36
46581
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
37 This will be ``"SimpleHTTP/" + __version__``, where ``__version__`` is
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
38 defined at the module level.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
39
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
40
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
41 .. attribute:: extensions_map
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
42
46581
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
43 A dictionary mapping suffixes into MIME types. The default is
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
44 signified by an empty string, and is considered to be
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
45 ``application/octet-stream``. The mapping is used case-insensitively,
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
46 and so should contain only lower-cased keys.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
47
46581
3d9ddce2da85 minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents: 46555
diff changeset
48 The :class:`SimpleHTTPRequestHandler` class defines the following methods:
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
49
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
50
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
51 .. method:: do_HEAD()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
52
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
53 This method serves the ``'HEAD'`` request type: it sends the headers it
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
54 would send for the equivalent ``GET`` request. See the :meth:`do_GET`
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
55 method for a more complete explanation of the possible headers.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
56
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
57
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
58 .. method:: do_GET()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
59
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
60 The request is mapped to a local file by interpreting the request as a
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
61 path relative to the current working directory.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
62
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
63 If the request was mapped to a directory, the directory is checked for a
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
64 file named ``index.html`` or ``index.htm`` (in that order). If found, the
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
65 file's contents are returned; otherwise a directory listing is generated
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
66 by calling the :meth:`list_directory` method. This method uses
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
67 :func:`os.listdir` to scan the directory, and returns a ``404`` error
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
68 response if the :func:`listdir` fails.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
69
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
70 If the request was mapped to a file, it is opened and the contents are
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
71 returned. Any :exc:`IOError` exception in opening the requested file is
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
72 mapped to a ``404``, ``'File not found'`` error. Otherwise, the content
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
73 type is guessed by calling the :meth:`guess_type` method, which in turn
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
74 uses the *extensions_map* variable.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
75
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
76 A ``'Content-type:'`` header with the guessed content type is output,
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
77 followed by a ``'Content-Length:'`` header with the file's size and a
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
78 ``'Last-Modified:'`` header with the file's modification time.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
79
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
80 Then follows a blank line signifying the end of the headers, and then the
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
81 contents of the file are output. If the file's MIME type starts with
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
82 ``text/`` the file is opened in text mode; otherwise binary mode is used.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
83
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
84 For example usage, see the implementation of the :func:`test` function.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
85
46555
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
86 .. versionadded:: 2.5
66c8bd1bedf3 reformat some documentation of classes so methods and attributes are under the class directive
Benjamin Peterson <benjamin@python.org>
parents: 42604
diff changeset
87 The ``'Last-Modified'`` header.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
88
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
89
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
90 .. seealso::
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
91
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
92 Module :mod:`BaseHTTPServer`
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
93 Base class implementation for Web server and request handler.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
94