Skip to content

Commit a12ef94

Browse files
committed
added WWW sections
1 parent 7defee7 commit a12ef94

25 files changed

+1090
-8
lines changed

Doc/Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,27 @@ ref.dvi: ref.tex ref1.tex ref2.tex ref3.tex ref4.tex ref5.tex ref6.tex \
3232
LIBFILES = lib.tex \
3333
libal.tex libaifc.tex libamoeba.tex libarray.tex libaudio.tex libaudioop.tex \
3434
libbltin.tex \
35-
libcopy.tex libcrypto.tex \
35+
libcgi.tex libcopy.tex libcrypto.tex \
3636
libdbm.tex \
3737
libexcs.tex \
38-
libfcntl.tex libfl.tex libfm.tex libfuncs.tex \
39-
libgdbm.tex libgetopt.tex libgl.tex libgrp.tex \
38+
libfcntl.tex libfl.tex libfm.tex libftplib.tex libfuncs.tex \
39+
libgdbm.tex libgetopt.tex libgl.tex libgopherlib.tex libgrp.tex \
40+
libhtmllib.tex libhttplib.tex \
4041
libimageop.tex libimgfile.tex libintro.tex \
4142
libjpeg.tex \
4243
libmac.tex libmain.tex libmarshal.tex libmath.tex \
43-
libmd5.tex libmm.tex libmods.tex libmpz.tex \
44+
libmd5.tex libmimetools.tex libmm.tex libmods.tex libmpz.tex \
45+
libnntplib.tex \
4446
libobjs.tex libos.tex \
4547
libpanel.tex libposix.tex libposixfile.tex libppath.tex libpickle.tex \
4648
libpwd.tex \
47-
librand.tex libregex.tex libregsub.tex librgbimg.tex librotor.tex \
48-
libselect.tex libsgi.tex libshelve.tex libsocket.tex libstd.tex libstdwin.tex \
49+
librand.tex libregex.tex libregsub.tex \
50+
librfc822.tex librgbimg.tex librotor.tex \
51+
libselect.tex libsgi.tex libsgmllib.tex \
52+
libshelve.tex libsocket.tex libstd.tex libstdwin.tex \
4953
libstring.tex libstruct.tex libsun.tex libsys.tex \
50-
libthread.tex libtime.tex libtypes.tex \
51-
libunix.tex \
54+
libthread.tex libtime.tex libtypes.tex libtypes2.tex \
55+
libunix.tex liburllib.tex liburlparse.tex \
5256
libwhrandom.tex libwww.tex
5357

5458
lib.dvi: $(LIBFILES)

Doc/lib.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
\input{libpickle}
7171
\input{libshelve}
7272
\input{libcopy}
73+
\input{libtypes2} % types is already taken :-(
7374

7475
\input{libunix} % UNIX ONLY
7576
\input{libdbm}
@@ -86,6 +87,7 @@
8687
\input{libthread}
8788

8889
\input{libwww} % WWW EXTENSIONS
90+
\input{libcgi}
8991
\input{libftplib}
9092
\input{libgopherlib}
9193
\input{libhtmllib}

Doc/lib/lib.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
\input{libpickle}
7171
\input{libshelve}
7272
\input{libcopy}
73+
\input{libtypes2} % types is already taken :-(
7374

7475
\input{libunix} % UNIX ONLY
7576
\input{libdbm}
@@ -86,6 +87,7 @@
8687
\input{libthread}
8788

8889
\input{libwww} % WWW EXTENSIONS
90+
\input{libcgi}
8991
\input{libftplib}
9092
\input{libgopherlib}
9193
\input{libhtmllib}

Doc/lib/libcgi.tex

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
\section{Built-in module \sectcode{cgi}}
2+
\stmodindex{cgi}
3+
\indexii{WWW}{server}
4+
\indexii{CGI}{protocol}
5+
\indexii{HTTP}{protocol}
6+
\indexii{MIME}{headers}
7+
\index{URL}
8+
9+
This module makes it easy to write Python scripts that run in a WWW
10+
server using the Common Gateway Interface. It was written by Michael
11+
McLay and subsequently modified by Steve Majewski and Guido van
12+
Rossum.
13+
14+
When a WWW server finds that a URL contains a reference to a file in a
15+
particular subdirectory (usually \code{/cgibin}), it runs the file as
16+
a subprocess. Information about the request such as the full URL, the
17+
originating host etc., is passed to the subprocess in the shell
18+
environment; additional input from the client may be read from
19+
standard input. Standard output from the subprocess is sent back
20+
across the network to the client as the response from the request.
21+
The CGI protocol describes what the environment variables passed to
22+
the subprocess mean and how the output should be formatted. The
23+
official reference documentation for the CGI protocol can be found on
24+
the World-Wide Web at
25+
\code{<URL:http://hoohoo.ncsa.uiuc.edu/cgi/overview.html>}. The
26+
\code{cgi} module was based on version 1.1 of the protocol and should
27+
also work with version 1.0.
28+
29+
The \code{cgi} module defines several classes that make it easy to
30+
access the information passed to the subprocess from a Python script;
31+
in particular, it knows how to parse the input sent by an HTML
32+
``form'' using either a POST or a GET request (these are alternatives
33+
for submitting forms in the HTTP protocol).
34+
35+
The formatting of the output is so trivial that no additional support
36+
is needed. All you need to do is print a minimal set of MIME headers
37+
describing the output format, followed by a blank line and your actual
38+
output. E.g. if you want to generate HTML, your script could start as
39+
follows:
40+
41+
\begin{verbatim}
42+
# Header -- one or more lines:
43+
print "Content-type: text/html"
44+
# Blank line separating header from body:
45+
print
46+
# Body, in HTML format:
47+
print "<TITLE>The Amazing SPAM Homepage!</TITLE>"
48+
# etc...
49+
\end{verbatim}
50+
51+
The server will add some header lines of its own, but it won't touch
52+
the output following the header.
53+
54+
The \code{cgi} module defines the following functions:
55+
56+
\begin{funcdesc}{parse}{}
57+
Read and parse the form submitted to the script and return a
58+
dictionary containing the form's fields. This should be called at
59+
most once per script invocation, as it may consume standard input (if
60+
the form was submitted through a POST request). The keys in the
61+
resulting dictionary are the field names used in the submission; the
62+
values are {\em lists} of the field values (since field name may be
63+
used multiple times in a single form). As a side effect, it sets
64+
\code{environ['QUERY_STRING']} to the raw query string, if it isn't
65+
already set.
66+
\end{funcdesc}
67+
68+
\begin{funcdesc}{print_environ_usage}{}
69+
Print a piece of HTML listing the environment variables that may be
70+
set by the CGI protocol.
71+
This is mainly useful when learning about writing CGI scripts.
72+
\end{funcdesc}
73+
74+
\begin{funcdesc}{print_environ}{}
75+
Print a piece of HTML text showing the entire contents of the shell
76+
environment. This is mainly useful when debugging a CGI script.
77+
\end{funcdesc}
78+
79+
\begin{funcdesc}{print_form}{form}
80+
Print a piece of HTML text showing the contents of the \var{form}.
81+
This is mainly useful when debugging a CGI script.
82+
\end{funcdesc}
83+
84+
\begin{funcdesc}{escape}{string}
85+
Convert special characters in \var{string} to HTML escapes. In
86+
particular, ``\code{\&}'' is replaced with ``\code{\&amp;}'',
87+
``\code{<}'' is replaced with ``\code{\&lt;}'', and ``\code{>}'' is
88+
replaced with ``\code{\&gt;}''. This is useful when printing (almost)
89+
arbitrary text in an HTML context. Note that for inclusion in quoted
90+
tag attributes (e.g. \code{<A HREF="...">}), some additional
91+
characters would have to be converted --- in particular the string
92+
quote. There is currently no function that does this.
93+
\end{funcdesc}
94+
95+
The module defines the following classes. Since the base class
96+
initializes itself by calling \code{parse()}, at most one instance of
97+
at most one of these classes should be created per script invocation:
98+
99+
\begin{funcdesc}{FormContentDict}{}
100+
This class behaves like a (read-only) dictionary and has the same keys
101+
and values as the dictionary returned by \code{parse()} (i.e. each
102+
field name maps to a list of values). Additionally, it initializes
103+
its data member \code{query_string} to the raw query sent from the
104+
server.
105+
\end{funcdesc}
106+
107+
\begin{funcdesc}{SvFormContentDict}{}
108+
This class, derived from \code{FormContentDict}, is a little more
109+
user-friendly when you are expecting that each field name is only used
110+
once in the form. When you access for a particular field (using
111+
\code{form[fieldname]}), it will return the string value of that item
112+
if it is unique, or raise \code{IndexError} if the field was specified
113+
more than once in the form. (If the field wasn't specified at all,
114+
\code{KeyError} is raised.) To access fields that are specified
115+
multiple times, use \code{form.getlist(fieldname)}. The
116+
\code{values()} and \code{items()} methods return mixed lists --
117+
containing strings for singly-defined fields, and lists of strings for
118+
multiply-defined fields.
119+
\end{funcdesc}
120+
121+
(It currently defines some more classes, but these are experimental
122+
and/or obsolescent, and are thus not documented --- see the source for
123+
more informations.)
124+
125+
The module defines the following variable:
126+
127+
\begin{datadesc}{environ}
128+
The shell environment, exactly as received from the http server. See
129+
the CGI documentation for a description of the various fields.
130+
\end{datadesc}

Doc/lib/libftplib.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\section{Built-in module \sectcode{ftplib}}
2+
\stmodindex{ftplib}
3+
To be provided.

Doc/lib/libgopherlib.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\section{Built-in module \sectcode{gopherlib}}
2+
\stmodindex{gopherlib}
3+
To be provided.

Doc/lib/libhtmllib.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\section{Built-in module \sectcode{htmllib}}
2+
\stmodindex{htmllib}
3+
To be provided.

Doc/lib/libhttplib.tex

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
\section{Built-in module \sectcode{httplib}}
2+
\stmodindex{httplib}
3+
\index{HTTP}
4+
5+
This module defines a class which implements the client side of the
6+
HTTP protocol. It is normally not used directly --- the module
7+
\code{urlllib} module uses it to handle URLs that use HTTP.
8+
\stmodindex{urllib}
9+
10+
The module defines one class, \code{HTTP}. An \code{HTTP} instance
11+
represents one transaction with an HTTP server. It should be
12+
instantiated passing it a host and optional port number. If no port
13+
number is passed, the port is extracted from the host string if it has
14+
the form \code{host:port}, else the default HTTP port (80) is used.
15+
If no host is passed, no connection is made, and the \code{connect}
16+
method should be used to connect to a server.
17+
18+
Once an \code{HTTP} instance has been connected to an HTTP server, it
19+
should be used as follows:
20+
21+
\begin{enumerate}
22+
23+
\item[1.] Make exactly one call to the \code{putrequest()} method.
24+
25+
\item[2.] Make zero or more calls to the \code{putheader()} method.
26+
27+
\item[3.] Call the \code{endheaders()} method (this can be omitted if
28+
step 4. makes no calls).
29+
30+
\item[4.] Optional calls to the \code{send()} method.
31+
32+
\item[5.] Call the \code{getreply()} method.
33+
34+
\item[6.] Call the \code{getfile()} method and read the data off the
35+
file object that it returns.
36+
37+
\end{enumerate}
38+
39+
\code{HTTP} instances have the following methods:
40+
41+
\begin{funcdesc}{set_debuglevel}{level}
42+
Set the debugging level (the amount of debugging output printed).
43+
The default debug level is \code{0}, meaning no debugging output is
44+
printed.
45+
\end{funcdesc}
46+
47+
\begin{funcdesc}{connect}{host\optional{\, port}}
48+
Connect to the server given by \var{host} and \var{port}. See the
49+
intro for the default port. This should be called directly only if
50+
the instance was instantiated without passing a host.
51+
\end{funcdesc}
52+
53+
\begin{funcdesc}{send}{data}
54+
Send data to the server. This should be used directly only after the
55+
\code{endheaders()} method has been called and before
56+
\code{getreply()} has been called.
57+
\end{funcdesc}
58+
59+
\begin{funcdesc}{putrequest}{request\, selector}
60+
This should be the first call after the connection to the server has
61+
been made. It sends a line to the server consisting of the
62+
\var{request} string, the \var{selector} string, and the HTTP version
63+
(\code{HTTP/1.0}).
64+
\end{funcdesc}
65+
66+
\begin{funcdesc}{putheader}{header\, argument\optional{\, ...}}
67+
Send an RFC-822 style header to the server. It sends a line to the
68+
server consisting of the header, a colon and a space, and the first
69+
argument. If more arguments are given, continuation lines are sent,
70+
each consisting of a tab and an argument.
71+
\end{funcdesc}
72+
73+
\begin{funcdesc}{endheaders}{}
74+
Send a blank line to the server, signalling the end of the headers.
75+
\end{funcdesc}
76+
77+
\begin{funcdesc}{getreply}{}
78+
Complete the request by shutting down the sending end of the socket,
79+
read the reply from the server, and return a triple (\var{replycode},
80+
\var{message}, \var{headers}). Here \var{replycode} is the integer
81+
reply code from the request (e.g. \code{200} if the request was
82+
handled properly); \var{message} is the message string corresponding
83+
to the reply code; and \var{header} is an instance of the class
84+
\code{rfc822.Message} containing the headers received from the server.
85+
See the description of the \code{rfc822} module.
86+
\stmodindex{rfc822}
87+
\end{funcdesc}
88+
89+
\begin{funcdesc}{getfile}{}
90+
Return a file object from which the data returned by the server can be
91+
read, using the \code{read()}, \code{readline()} or \code{readlines()}
92+
methods.
93+
\end{funcdesc}

Doc/lib/libmimetools.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\section{Built-in module \sectcode{mimetools}}
2+
\stmodindex{mimetools}
3+
To be provided.

Doc/lib/libnntplib.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\section{Built-in module \sectcode{nntplib}}
2+
\stmodindex{nntplib}
3+
To be provided.

0 commit comments

Comments
 (0)