Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libsimplehttp.tex @ 28646:193b8aec00ce legacy-trunk
Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to
work. This includes some more code that used to be part of pgen in
the main parser; I'm okay with that. I'll see if the Windows build
needs work next.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Apr 2003 14:55:42 +0000 |
| parents | d7864345b1c8 |
| children | 6aa31d75c4f9 |
| rev | line source |
|---|---|
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 \section{\module{SimpleHTTPServer} --- |
|
15140
fb9958933b25
Better synopsis based on suggestion from Ka-Ping Yee <ping@lfw.org>.
Fred Drake <fdrake@acm.org>
parents:
10982
diff
changeset
|
2 Simple HTTP request handler} |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 \declaremodule{standard}{SimpleHTTPServer} |
|
15467
d7864345b1c8
Update Moshe Zadka's email address to one works and might last a while.
Fred Drake <fdrake@acm.org>
parents:
15140
diff
changeset
|
5 \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il} |
|
15140
fb9958933b25
Better synopsis based on suggestion from Ka-Ping Yee <ping@lfw.org>.
Fred Drake <fdrake@acm.org>
parents:
10982
diff
changeset
|
6 \modulesynopsis{This module provides a basic request handler for HTTP |
|
fb9958933b25
Better synopsis based on suggestion from Ka-Ping Yee <ping@lfw.org>.
Fred Drake <fdrake@acm.org>
parents:
10982
diff
changeset
|
7 servers.} |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 The \module{SimpleHTTPServer} module defines a request-handler class, |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 interface compatible with \class{BaseHTTPServer.BaseHTTPRequestHandler} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 which serves files only from a base directory. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 The \module{SimpleHTTPServer} module defines the following class: |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 \begin{classdesc}{SimpleHTTPRequestHandler}{request, client_address, server} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 This class is used, to serve files from current directory and below, |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 directly mapping the directory structure to HTTP requests. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 A lot of the work is done by the base class |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 \class{BaseHTTPServer.BaseHTTPRequestHandler}, such as parsing the |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 request. This class implements the \function{do_GET()} and |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 \function{do_HEAD()} functions. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 \end{classdesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 The \class{SimpleHTTPRequestHandler} defines the following member |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 variables: |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 \begin{memberdesc}{server_version} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 This will be \code{"SimpleHTTP/" + __version__}, where \code{__version__} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
31 is defined in the module. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 \end{memberdesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 \begin{memberdesc}{extensions_map} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 A dictionary mapping suffixes into MIME types. Default is signified |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 by an empty string, and is considered to be \code{text/plain}. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 The mapping is used case-insensitively, and so should contain only |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
38 lower-cased keys. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 \end{memberdesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 The \class{SimpleHTTPRequestHandler} defines the following methods: |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 \begin{methoddesc}{do_HEAD}{} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 This method serves the \code{'HEAD'} request type: it sends the |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 headers it would send for the equivalent \code{GET} request. See the |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
46 \method{do_GET()} method for more complete explanation of the possible |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
47 headers. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 \end{methoddesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
49 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
50 \begin{methoddesc}{do_GET}{} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
51 The request is mapped to a local file by interpreting the request as |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
52 a path relative to the current working directory. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
53 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
54 If the request was mapped to a directory, a \code{403} respond is output, |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
55 followed by the explanation \code{'Directory listing not supported'}. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
56 Any \exception{IOError} exception in opening the requested file, is mapped |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
57 to a \code{404}, \code{'File not found'} error. Otherwise, the content |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 type is guessed using the \var{extensions_map} variable. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
59 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
60 A \code{'Content-type:'} with the guessed content type is output, and |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
61 then a blank line, signifying end of headers, and then the contents of |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
62 the file. The file is always opened in binary mode. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
63 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 For example usage, see the implementation of the \function{test()} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
65 function. |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 \end{methoddesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
67 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
68 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
69 \begin{seealso} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
70 \seemodule{BaseHTTPServer}{Base class implementation for Web server |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
71 and request handler.} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
72 \end{seealso} |
