Mercurial > cpython-lru_cache-weakref
annotate Doc/library/cgihttpserver.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 | 8b718fc15f3d |
| children | 59db4b3a06b0 |
| rev | line source |
|---|---|
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
1 :mod:`CGIHTTPServer` --- CGI-capable HTTP request handler |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
2 ========================================================= |
|
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 .. module:: CGIHTTPServer |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
5 :synopsis: This module provides a request handler for HTTP servers which can run CGI |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
6 scripts. |
|
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:
46556
diff
changeset
|
9 .. note:: |
|
662d15af52df
Add renaming notices to 3.0 http package members.
Georg Brandl <georg@python.org>
parents:
46556
diff
changeset
|
10 The :mod:`CGIHTTPServer` 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:
46556
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:
46556
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:
46556
diff
changeset
|
13 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
14 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
15 The :mod:`CGIHTTPServer` module defines a request-handler class, interface |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
16 compatible with :class:`BaseHTTPServer.BaseHTTPRequestHandler` and inherits |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
17 behavior from :class:`SimpleHTTPServer.SimpleHTTPRequestHandler` but can also |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
18 run CGI scripts. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
19 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
20 .. note:: |
|
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 This module can run CGI scripts on Unix and Windows systems; on Mac OS it will |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
23 only be able to run Python scripts within the same process as itself. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
24 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
25 .. note:: |
|
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 CGI scripts run by the :class:`CGIHTTPRequestHandler` class cannot execute |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
28 redirects (HTTP code 302), because code 200 (script output follows) is sent |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
29 prior to execution of the CGI script. This pre-empts the status code. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
30 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
31 The :mod:`CGIHTTPServer` module defines the following class: |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
32 |
|
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 .. class:: CGIHTTPRequestHandler(request, client_address, server) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
35 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
36 This class is used to serve either files or output of CGI scripts from the |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
37 current directory and below. Note that mapping HTTP hierarchic structure to |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
38 local directory structure is exactly as in |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
39 :class:`SimpleHTTPServer.SimpleHTTPRequestHandler`. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
40 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
41 The class will however, run the CGI script, instead of serving it as a file, if |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
42 it guesses it to be a CGI script. Only directory-based CGI are used --- the |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
43 other common server configuration is to treat special extensions as denoting CGI |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
44 scripts. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
45 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
46 The :func:`do_GET` and :func:`do_HEAD` functions are modified to run CGI scripts |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
47 and serve the output, instead of serving files, if the request leads to |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
48 somewhere below the ``cgi_directories`` path. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
49 |
|
46556
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
50 The :class:`CGIHTTPRequestHandler` defines the following data member: |
|
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 |
|
46556
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
53 .. attribute:: cgi_directories |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
54 |
|
46556
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
55 This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to |
|
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
56 treat as containing CGI scripts. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
57 |
|
46556
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
58 The :class:`CGIHTTPRequestHandler` defines the following methods: |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
59 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
60 |
|
46556
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
61 .. method:: do_POST() |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
62 |
|
46556
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
63 This method serves the ``'POST'`` request type, only allowed for CGI |
|
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
64 scripts. Error 501, "Can only POST to CGI scripts", is output when trying |
|
8b718fc15f3d
Merged revisions 62490 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42604
diff
changeset
|
65 to POST to a non-CGI url. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
66 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
67 Note that CGI scripts will be run with UID of user nobody, for security reasons. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
68 Problems with the CGI script will be translated to error 403. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
69 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
70 For example usage, see the implementation of the :func:`test` function. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
71 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
72 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
73 .. seealso:: |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
74 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
75 Module :mod:`BaseHTTPServer` |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
76 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
|
77 |
