New sections from Moshe Zadka <moshez@math.huji.ac.il>.
These document CGIHTTPServer, SimpleHTTPServer, and linecache.
This commit is contained in:
parent
d5258681e7
commit
21572fdcb6
|
@ -0,0 +1,61 @@
|
|||
\section{\module{CGIHTTPServer} ---
|
||||
A Do-Something Request Handler}
|
||||
|
||||
|
||||
\declaremodule{standard}{CGIHTTPServer}
|
||||
\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
|
||||
\modulesynopsis{This module provides a request handler for HTTP servers
|
||||
which can run CGI scripts.}
|
||||
|
||||
|
||||
The \module{CGIHTTPServer} module defines a request-handler class,
|
||||
interface compatible with
|
||||
\class{BaseHTTPServer.BaseHTTPRequestHandler} and inherits behaviour
|
||||
from \class{SimpleHTTPServer.SimpleHTTPRequestHandler} but can also
|
||||
run CGI scripts.
|
||||
|
||||
The \module{CGIHTTPServer} module defines the following class:
|
||||
|
||||
\begin{classdesc}{CGIHTTPRequestHandler}{request, client_address, server}
|
||||
This class is used to serve either files or output of CGI scripts from
|
||||
the current directory and below. Note that mapping HTTP hierarchic
|
||||
structure to local directory structure is exactly as in
|
||||
\class{SimpleHTTPServer.SimpleHTTPRequestHandler}.
|
||||
|
||||
The class will however, run the CGI script, instead of serving it as a
|
||||
file, if it guesses it to be a CGI script. Only directory-based CGI
|
||||
are used --- the other common server configuration is to treat special
|
||||
extensions as denoting CGI scripts.
|
||||
|
||||
The \function{do_GET()} and \function{do_HEAD()} functions are
|
||||
modified to run CGI scripts and serve the output, instead of serving
|
||||
files, if the request leads to somewhere below the
|
||||
\code{cgi_directories} path.
|
||||
\end{classdesc}
|
||||
|
||||
The \class{CGIHTTPRequestHandler} defines the following data member:
|
||||
|
||||
\begin{memberdesc}{cgi_directories}
|
||||
This defaults to \code{['/cgi-bin', '/htbin']} and describes
|
||||
directories to treat as containing CGI scripts.
|
||||
\end{memberdesc}
|
||||
|
||||
The \class{CGIHTTPRequestHandler} defines the following methods:
|
||||
|
||||
\begin{methoddesc}{do_POST}{}
|
||||
This method serves the \code{'POST'} request type, only allowed for
|
||||
CGI scripts. Error 501, "Can only POST to CGI scripts", is output
|
||||
when trying to POST to a non-CGI url.
|
||||
\end{methoddesc}
|
||||
|
||||
Note that CGI scripts will be run with UID of user nobody, for security
|
||||
reasons. Problems with the CGI script will be translated to error 403.
|
||||
|
||||
For example usage, see the implementation of the \function{test()}
|
||||
function.
|
||||
|
||||
|
||||
\begin{seealso}
|
||||
\seemodule{BaseHTTPServer}{Base class implementation for Web server
|
||||
and request handler.}
|
||||
\end{seealso}
|
|
@ -0,0 +1,41 @@
|
|||
\section{\module{linecache} ---
|
||||
Treat files like lists of lines}
|
||||
|
||||
\declaremodule{standard}{linecache}
|
||||
\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
|
||||
\modulesynopsis{This module treats files like random-access lists of lines.}
|
||||
|
||||
|
||||
The \module{linecache} module allows one to get any line from any file,
|
||||
while attempting to optimize internally, using a cache, the common case
|
||||
where many lines are read from a file.
|
||||
|
||||
The \module{linecache} module defines the following functions:
|
||||
|
||||
\begin{funcdesc}{getline}{filename, lineno}
|
||||
Get line \var{lineno} from file named \var{filename}. This function
|
||||
will never throw an exception --- it will return \code{''} on errors.
|
||||
|
||||
If a file named \var{filename} is not found, the function will look
|
||||
for it in the module search path.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{clearcache}{}
|
||||
Clear the cache. You might want to use this function if you know that
|
||||
you do not need to read lines from many of files you already read from
|
||||
using this module.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{checkcache}{}
|
||||
Check the cache is still valid. You might want to use this function if
|
||||
you suspect that files you read from using this module might have
|
||||
changed.
|
||||
\end{funcdesc}
|
||||
|
||||
Example:
|
||||
|
||||
\begin{verbatim}
|
||||
>>> import linecache
|
||||
>>> linecache.getline('/etc/passwd', 4)
|
||||
'sys:x:3:3:sys:/dev:/bin/sh\012'
|
||||
\end{verbatim}
|
|
@ -0,0 +1,71 @@
|
|||
\section{\module{SimpleHTTPServer} ---
|
||||
A Do-Something Request Handler}
|
||||
|
||||
\declaremodule{standard}{SimpleHTTPServer}
|
||||
\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
|
||||
\modulesynopsis{This module provides a request handler for HTTP servers.}
|
||||
|
||||
|
||||
The \module{SimpleHTTPServer} module defines a request-handler class,
|
||||
interface compatible with \class{BaseHTTPServer.BaseHTTPRequestHandler}
|
||||
which serves files only from a base directory.
|
||||
|
||||
The \module{SimpleHTTPServer} module defines the following class:
|
||||
|
||||
\begin{classdesc}{SimpleHTTPRequestHandler}{request, client_address, server}
|
||||
This class is used, to serve files from current directory and below,
|
||||
directly mapping the directory structure to HTTP requests.
|
||||
|
||||
A lot of the work is done by the base class
|
||||
\class{BaseHTTPServer.BaseHTTPRequestHandler}, such as parsing the
|
||||
request. This class implements the \function{do_GET()} and
|
||||
\function{do_HEAD()} functions.
|
||||
\end{classdesc}
|
||||
|
||||
The \class{SimpleHTTPRequestHandler} defines the following member
|
||||
variables:
|
||||
|
||||
\begin{memberdesc}{server_version}
|
||||
This will be \code{"SimpleHTTP/" + __version__}, where \code{__version__}
|
||||
is defined in the module.
|
||||
\end{memberdesc}
|
||||
|
||||
\begin{memberdesc}{extensions_map}
|
||||
A dictionary mapping suffixes into MIME types. Default is signified
|
||||
by an empty string, and is considered to be \code{text/plain}.
|
||||
The mapping is used case-insensitively, and so should contain only
|
||||
lower-cased keys.
|
||||
\end{memberdesc}
|
||||
|
||||
The \class{SimpleHTTPRequestHandler} defines the following methods:
|
||||
|
||||
\begin{methoddesc}{do_HEAD}{}
|
||||
This method serves the \code{'HEAD'} request type: it sends the
|
||||
headers it would send for the equivalent \code{GET} request. See the
|
||||
\method{do_GET()} method for more complete explanation of the possible
|
||||
headers.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}{do_GET}{}
|
||||
The request is mapped to a local file by interpreting the request as
|
||||
a path relative to the current working directory.
|
||||
|
||||
If the request was mapped to a directory, a \code{403} respond is output,
|
||||
followed by the explanation \code{'Directory listing not supported'}.
|
||||
Any \exception{IOError} exception in opening the requested file, is mapped
|
||||
to a \code{404}, \code{'File not found'} error. Otherwise, the content
|
||||
type is guessed using the \var{extensions_map} variable.
|
||||
|
||||
A \code{'Content-type:'} with the guessed content type is output, and
|
||||
then a blank line, signifying end of headers, and then the contents of
|
||||
the file. The file is always opened in binary mode.
|
||||
|
||||
For example usage, see the implementation of the \function{test()}
|
||||
function.
|
||||
\end{methoddesc}
|
||||
|
||||
|
||||
\begin{seealso}
|
||||
\seemodule{BaseHTTPServer}{Base class implementation for Web server
|
||||
and request handler.}
|
||||
\end{seealso}
|
Loading…
Reference in New Issue