Mercurial > cpython-lru_cache-weakref
annotate Doc/library/simplehttpserver.rst @ 46581:3d9ddce2da85 legacy-trunk
minor wording changes, rewrap a few lines
| author | Skip Montanaro <skip@pobox.com> |
|---|---|
| date | Sun, 27 Apr 2008 20:53:57 +0000 |
| parents | 66c8bd1bedf3 |
| children | 662d15af52df |
| 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 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
9 |
|
46581
3d9ddce2da85
minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents:
46555
diff
changeset
|
10 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
|
11 :class:`SimpleHTTPRequestHandler`, which is interface-compatible with |
|
3d9ddce2da85
minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents:
46555
diff
changeset
|
12 :class:`BaseHTTPServer.BaseHTTPRequestHandler`. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
13 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
14 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
|
15 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
16 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
17 .. class:: SimpleHTTPRequestHandler(request, client_address, server) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
18 |
|
46581
3d9ddce2da85
minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents:
46555
diff
changeset
|
19 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
|
20 mapping the directory structure to HTTP requests. |
|
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 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
|
23 :class:`BaseHTTPServer.BaseHTTPRequestHandler`. This class implements the |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
24 :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
|
25 |
|
46581
3d9ddce2da85
minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents:
46555
diff
changeset
|
26 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
|
27 :class:`SimpleHTTPRequestHandler`: |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
28 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
29 |
|
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
|
30 .. attribute:: server_version |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
31 |
|
46581
3d9ddce2da85
minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents:
46555
diff
changeset
|
32 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
|
33 defined at the module level. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
34 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
35 |
|
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
|
36 .. attribute:: extensions_map |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
37 |
|
46581
3d9ddce2da85
minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents:
46555
diff
changeset
|
38 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
|
39 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
|
40 ``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
|
41 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
|
42 |
|
46581
3d9ddce2da85
minor wording changes, rewrap a few lines
Skip Montanaro <skip@pobox.com>
parents:
46555
diff
changeset
|
43 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
|
44 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
45 |
|
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
|
46 .. method:: do_HEAD() |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
47 |
|
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
|
48 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
|
49 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
|
50 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
|
51 |
|
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 .. method:: do_GET() |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
54 |
|
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
|
55 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
|
56 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
|
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 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
|
59 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
|
60 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
|
61 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
|
62 :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
|
63 response if the :func:`listdir` fails. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
64 |
|
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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 uses the *extensions_map* variable. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
70 |
|
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
|
71 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
|
72 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
|
73 ``'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
|
74 |
|
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
|
75 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
|
76 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
|
77 ``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
|
78 |
|
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
|
79 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
|
80 |
|
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
|
81 .. 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
|
82 The ``'Last-Modified'`` header. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
83 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
84 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
85 .. seealso:: |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
86 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
87 Module :mod:`BaseHTTPServer` |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
88 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
|
89 |
