mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
checkin of myformat.sty. Change "\renewcommand{\indexsubitem}{(...)}" to "\setindexsubitem{(...)}" everywhere. Some other minor nits that I happened to come across.
This commit is contained in:
parent
dc8af0acc1
commit
1947991c2f
241 changed files with 1022 additions and 1020 deletions
|
@ -23,7 +23,7 @@ second's worth occupies 2*2*44100 bytes, i.e.\ 176,400 bytes.
|
||||||
|
|
||||||
Module \code{aifc} defines the following function:
|
Module \code{aifc} defines the following function:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module aifc)}
|
\setindexsubitem{(in module aifc)}
|
||||||
\begin{funcdesc}{open}{file\, mode}
|
\begin{funcdesc}{open}{file\, mode}
|
||||||
Open an AIFF or AIFF-C file and return an object instance with
|
Open an AIFF or AIFF-C file and return an object instance with
|
||||||
methods that are described below. The argument file is either a
|
methods that are described below. The argument file is either a
|
||||||
|
@ -38,7 +38,7 @@ samples you are going to write in total and use
|
||||||
Objects returned by \code{aifc.open()} when a file is opened for
|
Objects returned by \code{aifc.open()} when a file is opened for
|
||||||
reading have the following methods:
|
reading have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(aifc object method)}
|
\setindexsubitem{(aifc object method)}
|
||||||
\begin{funcdesc}{getnchannels}{}
|
\begin{funcdesc}{getnchannels}{}
|
||||||
Return the number of audio channels (1 for mono, 2 for stereo).
|
Return the number of audio channels (1 for mono, 2 for stereo).
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
|
@ -25,7 +25,7 @@ documented upper limit.)
|
||||||
|
|
||||||
The module defines the following functions:
|
The module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module al)}
|
\setindexsubitem{(in module al)}
|
||||||
|
|
||||||
\begin{funcdesc}{openport}{name\, direction\optional{\, config}}
|
\begin{funcdesc}{openport}{name\, direction\optional{\, config}}
|
||||||
The name and direction arguments are strings. The optional config
|
The name and direction arguments are strings. The optional config
|
||||||
|
@ -59,7 +59,7 @@ as returned by \code{al.queryparams}.
|
||||||
Configuration objects (returned by \code{al.newconfig()} have the
|
Configuration objects (returned by \code{al.newconfig()} have the
|
||||||
following methods:
|
following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(audio configuration object method)}
|
\setindexsubitem{(audio configuration object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{getqueuesize}{}
|
\begin{funcdesc}{getqueuesize}{}
|
||||||
Return the queue size.
|
Return the queue size.
|
||||||
|
@ -106,7 +106,7 @@ Set the maximum value for floating sample formats.
|
||||||
Port objects (returned by \code{al.openport()} have the following
|
Port objects (returned by \code{al.openport()} have the following
|
||||||
methods:
|
methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(audio port object method)}
|
\setindexsubitem{(audio port object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{closeport}{}
|
\begin{funcdesc}{closeport}{}
|
||||||
Close the port.
|
Close the port.
|
||||||
|
@ -167,7 +167,7 @@ the C header file \file{<audio.h>} except that the name prefix
|
||||||
\samp{AL_} is omitted. Read the module source for a complete list of
|
\samp{AL_} is omitted. Read the module source for a complete list of
|
||||||
the defined names. Suggested use:
|
the defined names. Suggested use:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import al
|
import al
|
||||||
from AL import *
|
from AL import *
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -10,7 +10,7 @@ the exception \code{amoeba.error = 'amoeba.error'}.
|
||||||
|
|
||||||
The module \code{amoeba} defines the following items:
|
The module \code{amoeba} defines the following items:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module amoeba)}
|
\setindexsubitem{(in module amoeba)}
|
||||||
\begin{funcdesc}{name_append}{path\, cap}
|
\begin{funcdesc}{name_append}{path\, cap}
|
||||||
Stores a capability in the Amoeba directory tree.
|
Stores a capability in the Amoeba directory tree.
|
||||||
Arguments are the pathname (a string) and the capability (a capability
|
Arguments are the pathname (a string) and the capability (a capability
|
||||||
|
@ -77,15 +77,15 @@ and
|
||||||
\emph{a2c}(U).
|
\emph{a2c}(U).
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> amoeba.name_lookup('/profile/cap')
|
>>> amoeba.name_lookup('/profile/cap')
|
||||||
aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a
|
aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The following methods are defined for capability objects.
|
The following methods are defined for capability objects.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(capability method)}
|
\setindexsubitem{(capability method)}
|
||||||
\begin{funcdesc}{dir_list}{}
|
\begin{funcdesc}{dir_list}{}
|
||||||
Returns a list of the names of the entries in an Amoeba directory.
|
Returns a list of the names of the entries in an Amoeba directory.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
|
@ -9,7 +9,7 @@ will be used. Both modules provide the same interface:
|
||||||
|
|
||||||
% not the best solution, but it's what you get for documenting both
|
% not the best solution, but it's what you get for documenting both
|
||||||
% at the same time.
|
% at the same time.
|
||||||
\renewcommand{\indexsubitem}{(in modules anydbm, dumbdbm)}
|
\setindexsubitem{(in modules anydbm, dumbdbm)}
|
||||||
|
|
||||||
\begin{funcdesc}{open}{filename\optional{\, flag\, mode}}
|
\begin{funcdesc}{open}{filename\optional{\, flag\, mode}}
|
||||||
Open the database file \var{filename} and return a corresponding object.
|
Open the database file \var{filename} and return a corresponding object.
|
||||||
|
|
|
@ -36,7 +36,7 @@ See also built-in module \code{struct}.
|
||||||
|
|
||||||
The module defines the following function:
|
The module defines the following function:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module array)}
|
\setindexsubitem{(in module array)}
|
||||||
|
|
||||||
\begin{funcdesc}{array}{typecode\optional{\, initializer}}
|
\begin{funcdesc}{array}{typecode\optional{\, initializer}}
|
||||||
Return a new array whose items are restricted by \var{typecode}, and
|
Return a new array whose items are restricted by \var{typecode}, and
|
||||||
|
@ -124,9 +124,9 @@ numbers. The string is guaranteed to be able to be converted back to
|
||||||
an array with the same type and value using reverse quotes
|
an array with the same type and value using reverse quotes
|
||||||
(\code{``}). Examples:
|
(\code{``}). Examples:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
array('l')
|
array('l')
|
||||||
array('c', 'hello world')
|
array('c', 'hello world')
|
||||||
array('l', [1, 2, 3, 4, 5])
|
array('l', [1, 2, 3, 4, 5])
|
||||||
array('d', [1.0, 2.0, 3.14])
|
array('d', [1.0, 2.0, 3.14])
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -13,7 +13,7 @@ otherwise the sample size (in bytes) is always a parameter of the operation.
|
||||||
|
|
||||||
The module defines the following variables and functions:
|
The module defines the following variables and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module audioop)}
|
\setindexsubitem{(in module audioop)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised on all errors, such as unknown number of bytes
|
This exception is raised on all errors, such as unknown number of bytes
|
||||||
per sample, etc.
|
per sample, etc.
|
||||||
|
@ -201,7 +201,7 @@ distinction between mono and stereo fragments, i.e.\ all samples are
|
||||||
treated equal. If this is a problem the stereo fragment should be split
|
treated equal. If this is a problem the stereo fragment should be split
|
||||||
into two mono fragments first and recombined later. Here is an example
|
into two mono fragments first and recombined later. Here is an example
|
||||||
of how to do that:
|
of how to do that:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def mul_stereo(sample, width, lfactor, rfactor):
|
def mul_stereo(sample, width, lfactor, rfactor):
|
||||||
lsample = audioop.tomono(sample, width, 1, 0)
|
lsample = audioop.tomono(sample, width, 1, 0)
|
||||||
rsample = audioop.tomono(sample, width, 0, 1)
|
rsample = audioop.tomono(sample, width, 0, 1)
|
||||||
|
@ -210,7 +210,7 @@ def mul_stereo(sample, width, lfactor, rfactor):
|
||||||
lsample = audioop.tostereo(lsample, width, 1, 0)
|
lsample = audioop.tostereo(lsample, width, 1, 0)
|
||||||
rsample = audioop.tostereo(rsample, width, 0, 1)
|
rsample = audioop.tostereo(rsample, width, 0, 1)
|
||||||
return audioop.add(lsample, rsample, width)
|
return audioop.add(lsample, rsample, width)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
If you use the ADPCM coder to build network packets and you want your
|
If you use the ADPCM coder to build network packets and you want your
|
||||||
protocol to be stateless (i.e.\ to be able to tolerate packet loss)
|
protocol to be stateless (i.e.\ to be able to tolerate packet loss)
|
||||||
|
@ -231,7 +231,7 @@ They are primarily meant to do echo cancellation. A reasonably
|
||||||
fast way to do this is to pick the most energetic piece of the output
|
fast way to do this is to pick the most energetic piece of the output
|
||||||
sample, locate that in the input sample and subtract the whole output
|
sample, locate that in the input sample and subtract the whole output
|
||||||
sample from the input sample:
|
sample from the input sample:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def echocancel(outputdata, inputdata):
|
def echocancel(outputdata, inputdata):
|
||||||
pos = audioop.findmax(outputdata, 800) # one tenth second
|
pos = audioop.findmax(outputdata, 800) # one tenth second
|
||||||
out_test = outputdata[pos*2:]
|
out_test = outputdata[pos*2:]
|
||||||
|
@ -244,4 +244,4 @@ def echocancel(outputdata, inputdata):
|
||||||
postfill = '\0'*(len(inputdata)-len(prefill)-len(outputdata))
|
postfill = '\0'*(len(inputdata)-len(prefill)-len(outputdata))
|
||||||
outputdata = prefill + audioop.mul(outputdata,2,-factor) + postfill
|
outputdata = prefill + audioop.mul(outputdata,2,-factor) + postfill
|
||||||
return audioop.add(inputdata, outputdata, 2)
|
return audioop.add(inputdata, outputdata, 2)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -12,7 +12,7 @@ output produced by the \file{uuencode} program. For example, the
|
||||||
string \code{'www.python.org'} is encoded as the string
|
string \code{'www.python.org'} is encoded as the string
|
||||||
\code{'d3d3LnB5dGhvbi5vcmc=\e n'}.
|
\code{'d3d3LnB5dGhvbi5vcmc=\e n'}.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module base64)}
|
\setindexsubitem{(in module base64)}
|
||||||
|
|
||||||
\begin{funcdesc}{decode}{input, output}
|
\begin{funcdesc}{decode}{input, output}
|
||||||
Decode the contents of the \var{input} file and write the resulting
|
Decode the contents of the \var{input} file and write the resulting
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
\index{URL}
|
\index{URL}
|
||||||
\index{httpd}
|
\index{httpd}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module BaseHTTPServer)}
|
\setindexsubitem{(in module BaseHTTPServer)}
|
||||||
|
|
||||||
This module defines two classes for implementing HTTP servers
|
This module defines two classes for implementing HTTP servers
|
||||||
(web servers). Usually, this module isn't used directly, but is used
|
(web servers). Usually, this module isn't used directly, but is used
|
||||||
|
@ -21,13 +21,13 @@ subclass. It creates and listens at the web socket, dispatching the
|
||||||
requests to a handler. Code to create and run the server looks like
|
requests to a handler. Code to create and run the server looks like
|
||||||
this:
|
this:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def run(server_class=BaseHTTPServer.HTTPServer,
|
def run(server_class=BaseHTTPServer.HTTPServer,
|
||||||
handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
|
handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
server_address = ('', 8000)
|
server_address = ('', 8000)
|
||||||
httpd = server_class(server_address, handler_class)
|
httpd = server_class(server_address, handler_class)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The \code{HTTPServer} class builds on the \code{TCPServer} class by
|
The \code{HTTPServer} class builds on the \code{TCPServer} class by
|
||||||
storing the server address as instance
|
storing the server address as instance
|
||||||
|
@ -49,7 +49,7 @@ from the request. For example, for the request \code{SPAM}, the
|
||||||
the relevant information is stored into instance variables of the
|
the relevant information is stored into instance variables of the
|
||||||
handler.
|
handler.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(BaseHTTPRequestHandler instance variable)}
|
\setindexsubitem{(BaseHTTPRequestHandler instance variable)}
|
||||||
|
|
||||||
\code{BaseHTTPRequestHandler} has the following instance variables:
|
\code{BaseHTTPRequestHandler} has the following instance variables:
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ Proper adherance to the HTTP protocol must be used when writing
|
||||||
to this stream.
|
to this stream.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(BaseHTTPRequestHandler class variable)}
|
\setindexsubitem{(BaseHTTPRequestHandler class variable)}
|
||||||
|
|
||||||
\code{BaseHTTPRequestHandler} has the following class variables:
|
\code{BaseHTTPRequestHandler} has the following class variables:
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ error response, and \var{longmessage} as the \var{explain} key
|
||||||
(see the \code{error_message_format} class variable).
|
(see the \code{error_message_format} class variable).
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(BaseHTTPRequestHandler method)}
|
\setindexsubitem{(BaseHTTPRequestHandler method)}
|
||||||
|
|
||||||
A \code{BaseHTTPRequestHandler} instance has the following methods:
|
A \code{BaseHTTPRequestHandler} instance has the following methods:
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
\section{Standard Module \sectcode{Bastion}}
|
\section{Standard Module \sectcode{Bastion}}
|
||||||
\label{module-Bastion}
|
\label{module-Bastion}
|
||||||
\stmodindex{Bastion}
|
\stmodindex{Bastion}
|
||||||
\renewcommand{\indexsubitem}{(in module Bastion)}
|
\setindexsubitem{(in module Bastion)}
|
||||||
|
|
||||||
% I'm concerned that the word 'bastion' won't be understood by people
|
% I'm concerned that the word 'bastion' won't be understood by people
|
||||||
% for whom English is a second language, making the module name
|
% for whom English is a second language, making the module name
|
||||||
|
|
|
@ -9,7 +9,7 @@ decoded), on other platforms only the data fork is handled.
|
||||||
|
|
||||||
The \code{binhex} module defines the following functions:
|
The \code{binhex} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module binhex)}
|
\setindexsubitem{(in module binhex)}
|
||||||
|
|
||||||
\begin{funcdesc}{binhex}{input\, output}
|
\begin{funcdesc}{binhex}{input\, output}
|
||||||
Convert a binary file with filename \var{input} to binhex file
|
Convert a binary file with filename \var{input} to binhex file
|
||||||
|
@ -54,7 +54,7 @@ Jansen.
|
||||||
|
|
||||||
The \code{uu} module defines the following functions:
|
The \code{uu} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module uu)}
|
\setindexsubitem{(in module uu)}
|
||||||
|
|
||||||
\begin{funcdesc}{encode}{in_file\, out_file\optional{\, name\, mode}}
|
\begin{funcdesc}{encode}{in_file\, out_file\optional{\, name\, mode}}
|
||||||
Uuencode file \var{in_file} into file \var{out_file}. The uuencoded
|
Uuencode file \var{in_file} into file \var{out_file}. The uuencoded
|
||||||
|
@ -82,7 +82,7 @@ bit-manipuation of large amounts of data is slow in python.
|
||||||
|
|
||||||
The \code{binascii} module defines the following functions:
|
The \code{binascii} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module binascii)}
|
\setindexsubitem{(in module binascii)}
|
||||||
|
|
||||||
\begin{funcdesc}{a2b_uu}{string}
|
\begin{funcdesc}{a2b_uu}{string}
|
||||||
Convert a single line of uuencoded data back to binary and return the
|
Convert a single line of uuencoded data back to binary and return the
|
||||||
|
|
|
@ -29,7 +29,7 @@ track.
|
||||||
|
|
||||||
Module \code{cd} defines the following functions and constants:
|
Module \code{cd} defines the following functions and constants:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module cd)}
|
\setindexsubitem{(in module cd)}
|
||||||
|
|
||||||
\begin{funcdesc}{createparser}{}
|
\begin{funcdesc}{createparser}{}
|
||||||
Create and return an opaque parser object. The methods of the parser
|
Create and return an opaque parser object. The methods of the parser
|
||||||
|
@ -115,7 +115,7 @@ objects (see below).
|
||||||
Player objects (returned by \code{cd.open()}) have the following
|
Player objects (returned by \code{cd.open()}) have the following
|
||||||
methods:
|
methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(CD player object method)}
|
\setindexsubitem{(CD player object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{allowremoval}{}
|
\begin{funcdesc}{allowremoval}{}
|
||||||
Unlocks the eject button on the CD-ROM drive permitting the user to
|
Unlocks the eject button on the CD-ROM drive permitting the user to
|
||||||
|
@ -235,7 +235,7 @@ Pauses the CD if it is playing, and makes it play if it is paused.
|
||||||
Parser objects (returned by \code{cd.createparser()}) have the
|
Parser objects (returned by \code{cd.createparser()}) have the
|
||||||
following methods:
|
following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(CD parser object method)}
|
\setindexsubitem{(CD parser object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{addcallback}{type\, func\, arg}
|
\begin{funcdesc}{addcallback}{type\, func\, arg}
|
||||||
Adds a callback for the parser. The parser has callbacks for eight
|
Adds a callback for the parser. The parser has callbacks for eight
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
\indexii{MIME}{headers}
|
\indexii{MIME}{headers}
|
||||||
\index{URL}
|
\index{URL}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module cgi)}
|
\setindexsubitem{(in module cgi)}
|
||||||
|
|
||||||
Support module for CGI (Common Gateway Interface) scripts.
|
Support module for CGI (Common Gateway Interface) scripts.
|
||||||
|
|
||||||
|
@ -40,20 +40,20 @@ by a blank line. The first section contains a number of headers,
|
||||||
telling the client what kind of data is following. Python code to
|
telling the client what kind of data is following. Python code to
|
||||||
generate a minimal header section looks like this:
|
generate a minimal header section looks like this:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
print "Content-type: text/html" # HTML is following
|
print "Content-type: text/html" # HTML is following
|
||||||
print # blank line, end of headers
|
print # blank line, end of headers
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The second section is usually HTML, which allows the client software
|
The second section is usually HTML, which allows the client software
|
||||||
to display nicely formatted text with header, in-line images, etc.
|
to display nicely formatted text with header, in-line images, etc.
|
||||||
Here's Python code that prints a simple piece of HTML:
|
Here's Python code that prints a simple piece of HTML:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
print "<TITLE>CGI script output</TITLE>"
|
print "<TITLE>CGI script output</TITLE>"
|
||||||
print "<H1>This is my first CGI script</H1>"
|
print "<H1>This is my first CGI script</H1>"
|
||||||
print "Hello, world!"
|
print "Hello, world!"
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
(It may not be fully legal HTML according to the letter of the
|
(It may not be fully legal HTML according to the letter of the
|
||||||
standard, but any browser will understand it.)
|
standard, but any browser will understand it.)
|
||||||
|
@ -77,7 +77,7 @@ dictionary. For instance, the following code (which assumes that the
|
||||||
\code{Content-type} header and blank line have already been printed) checks that
|
\code{Content-type} header and blank line have already been printed) checks that
|
||||||
the fields \code{name} and \code{addr} are both set to a non-empty string:
|
the fields \code{name} and \code{addr} are both set to a non-empty string:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
form = cgi.FieldStorage()
|
form = cgi.FieldStorage()
|
||||||
form_ok = 0
|
form_ok = 0
|
||||||
if form.has_key("name") and form.has_key("addr"):
|
if form.has_key("name") and form.has_key("addr"):
|
||||||
|
@ -88,7 +88,7 @@ if not form_ok:
|
||||||
print "Please fill in the name and addr fields."
|
print "Please fill in the name and addr fields."
|
||||||
return
|
return
|
||||||
...further form processing here...
|
...further form processing here...
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Here the fields, accessed through \code{form[key]}, are themselves instances
|
Here the fields, accessed through \code{form[key]}, are themselves instances
|
||||||
of \code{FieldStorage} (or \code{MiniFieldStorage}, depending on the form encoding).
|
of \code{FieldStorage} (or \code{MiniFieldStorage}, depending on the form encoding).
|
||||||
|
@ -101,7 +101,7 @@ name), use the \code{type()} function to determine whether you have a single
|
||||||
instance or a list of instances. For example, here's code that
|
instance or a list of instances. For example, here's code that
|
||||||
concatenates any number of username fields, separated by commas:
|
concatenates any number of username fields, separated by commas:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
username = form["username"]
|
username = form["username"]
|
||||||
if type(username) is type([]):
|
if type(username) is type([]):
|
||||||
# Multiple username fields specified
|
# Multiple username fields specified
|
||||||
|
@ -116,7 +116,7 @@ if type(username) is type([]):
|
||||||
else:
|
else:
|
||||||
# Single username field specified
|
# Single username field specified
|
||||||
usernames = username.value
|
usernames = username.value
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
If a field represents an uploaded file, the value attribute reads the
|
If a field represents an uploaded file, the value attribute reads the
|
||||||
entire file in memory as a string. This may not be what you want. You can
|
entire file in memory as a string. This may not be what you want. You can
|
||||||
|
@ -124,7 +124,7 @@ test for an uploaded file by testing either the filename attribute or the
|
||||||
file attribute. You can then read the data at leasure from the file
|
file attribute. You can then read the data at leasure from the file
|
||||||
attribute:
|
attribute:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
fileitem = form["userfile"]
|
fileitem = form["userfile"]
|
||||||
if fileitem.file:
|
if fileitem.file:
|
||||||
# It's an uploaded file; count lines
|
# It's an uploaded file; count lines
|
||||||
|
@ -133,7 +133,7 @@ if fileitem.file:
|
||||||
line = fileitem.file.readline()
|
line = fileitem.file.readline()
|
||||||
if not line: break
|
if not line: break
|
||||||
linecount = linecount + 1
|
linecount = linecount + 1
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The file upload draft standard entertains the possibility of uploading
|
The file upload draft standard entertains the possibility of uploading
|
||||||
multiple files from one field (using a recursive \code{multipart/*}
|
multiple files from one field (using a recursive \code{multipart/*}
|
||||||
|
@ -267,9 +267,9 @@ Make sure that your script is readable and executable by ``others''; the
|
||||||
that the first line of the script contains \code{\#!} starting in column 1
|
that the first line of the script contains \code{\#!} starting in column 1
|
||||||
followed by the pathname of the Python interpreter, for instance:
|
followed by the pathname of the Python interpreter, for instance:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
#!/usr/local/bin/python
|
#!/usr/local/bin/python
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Make sure the Python interpreter exists and is executable by ``others''.
|
Make sure the Python interpreter exists and is executable by ``others''.
|
||||||
|
|
||||||
|
@ -289,11 +289,11 @@ If you need to load modules from a directory which is not on Python's
|
||||||
default module search path, you can change the path in your script,
|
default module search path, you can change the path in your script,
|
||||||
before importing other modules, e.g.:
|
before importing other modules, e.g.:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(0, "/usr/home/joe/lib/python")
|
sys.path.insert(0, "/usr/home/joe/lib/python")
|
||||||
sys.path.insert(0, "/usr/local/lib/python")
|
sys.path.insert(0, "/usr/local/lib/python")
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
(This way, the directory inserted last will be searched first!)
|
(This way, the directory inserted last will be searched first!)
|
||||||
|
|
||||||
|
@ -327,9 +327,9 @@ Give it the right mode etc, and send it a request. If it's installed
|
||||||
in the standard \file{cgi-bin} directory, it should be possible to send it a
|
in the standard \file{cgi-bin} directory, it should be possible to send it a
|
||||||
request by entering a URL into your browser of the form:
|
request by entering a URL into your browser of the form:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
http://yourhostname/cgi-bin/cgi.py?name=Joe+Blow&addr=At+Home
|
http://yourhostname/cgi-bin/cgi.py?name=Joe+Blow&addr=At+Home
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
If this gives an error of type 404, the server cannot find the script
|
If this gives an error of type 404, the server cannot find the script
|
||||||
-- perhaps you need to install it in a different directory. If it
|
-- perhaps you need to install it in a different directory. If it
|
||||||
|
@ -345,9 +345,9 @@ The next step could be to call the \code{cgi} module's \code{test()}
|
||||||
function from your script: replace its main code with the single
|
function from your script: replace its main code with the single
|
||||||
statement
|
statement
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
cgi.test()
|
cgi.test()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This should produce the same results as those gotten from installing
|
This should produce the same results as those gotten from installing
|
||||||
the \file{cgi.py} file itself.
|
the \file{cgi.py} file itself.
|
||||||
|
@ -380,7 +380,7 @@ Here are the rules:
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
print "Content-type: text/html"
|
print "Content-type: text/html"
|
||||||
|
@ -391,7 +391,7 @@ try:
|
||||||
except:
|
except:
|
||||||
print "\n\n<PRE>"
|
print "\n\n<PRE>"
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Notes: The assignment to \code{sys.stderr} is needed because the traceback
|
Notes: The assignment to \code{sys.stderr} is needed because the traceback
|
||||||
prints to \code{sys.stderr}.
|
prints to \code{sys.stderr}.
|
||||||
|
@ -402,13 +402,13 @@ If you suspect that there may be a problem in importing the traceback
|
||||||
module, you can use an even more robust approach (which only uses
|
module, you can use an even more robust approach (which only uses
|
||||||
built-in modules):
|
built-in modules):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import sys
|
import sys
|
||||||
sys.stderr = sys.stdout
|
sys.stderr = sys.stdout
|
||||||
print "Content-type: text/plain"
|
print "Content-type: text/plain"
|
||||||
print
|
print
|
||||||
...your code here...
|
...your code here...
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This relies on the Python interpreter to print the traceback. The
|
This relies on the Python interpreter to print the traceback. The
|
||||||
content type of the output is set to plain text, which disables all
|
content type of the output is set to plain text, which disables all
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-cmath}
|
\label{module-cmath}
|
||||||
|
|
||||||
\bimodindex{cmath}
|
\bimodindex{cmath}
|
||||||
\renewcommand{\indexsubitem}{(in module cmath)}
|
\setindexsubitem{(in module cmath)}
|
||||||
This module is always available.
|
This module is always available.
|
||||||
It provides access to mathematical functions for complex numbers.
|
It provides access to mathematical functions for complex numbers.
|
||||||
The functions are:
|
The functions are:
|
||||||
|
|
|
@ -7,7 +7,7 @@ objects.
|
||||||
|
|
||||||
The \code{code} module defines the following functions:
|
The \code{code} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module code)}
|
\setindexsubitem{(in module code)}
|
||||||
|
|
||||||
\begin{funcdesc}{compile_command}{source, \optional{filename\optional{, symbol}}}
|
\begin{funcdesc}{compile_command}{source, \optional{filename\optional{, symbol}}}
|
||||||
This function is useful for programs that want to emulate Python's
|
This function is useful for programs that want to emulate Python's
|
||||||
|
|
|
@ -11,7 +11,7 @@ The \code{commands} module is only usable on systems which support
|
||||||
|
|
||||||
The \code{commands} module defines the following functions:
|
The \code{commands} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module commands)}
|
\setindexsubitem{(in module commands)}
|
||||||
\begin{funcdesc}{getstatusoutput}{cmd}
|
\begin{funcdesc}{getstatusoutput}{cmd}
|
||||||
Execute the string \var{cmd} in a shell with \code{os.popen()} and return
|
Execute the string \var{cmd} in a shell with \code{os.popen()} and return
|
||||||
a 2-tuple (status, output). \var{cmd} is actually run as
|
a 2-tuple (status, output). \var{cmd} is actually run as
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
\section{Standard Module \sectcode{copy}}
|
\section{Standard Module \sectcode{copy}}
|
||||||
\label{module-copy}
|
\label{module-copy}
|
||||||
\stmodindex{copy}
|
\stmodindex{copy}
|
||||||
\renewcommand{\indexsubitem}{(copy function)}
|
\setindexsubitem{(copy function)}
|
||||||
\ttindex{copy}
|
\ttindex{copy}
|
||||||
\ttindex{deepcopy}
|
\ttindex{deepcopy}
|
||||||
|
|
||||||
|
@ -9,12 +9,12 @@ This module provides generic (shallow and deep) copying operations.
|
||||||
|
|
||||||
Interface summary:
|
Interface summary:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
x = copy.copy(y) # make a shallow copy of y
|
x = copy.copy(y) # make a shallow copy of y
|
||||||
x = copy.deepcopy(y) # make a deep copy of y
|
x = copy.deepcopy(y) # make a deep copy of y
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
For module specific errors, \code{copy.error} is raised.
|
For module specific errors, \code{copy.error} is raised.
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ to control pickling: they can define methods called
|
||||||
\code{__setstate__()}. See the description of module \code{pickle}
|
\code{__setstate__()}. See the description of module \code{pickle}
|
||||||
for information on these methods.
|
for information on these methods.
|
||||||
\refstmodindex{pickle}
|
\refstmodindex{pickle}
|
||||||
\renewcommand{\indexsubitem}{(copy protocol)}
|
\setindexsubitem{(copy protocol)}
|
||||||
\ttindex{__getinitargs__}
|
\ttindex{__getinitargs__}
|
||||||
\ttindex{__getstate__}
|
\ttindex{__getstate__}
|
||||||
\ttindex{__setstate__}
|
\ttindex{__setstate__}
|
||||||
|
|
|
@ -12,7 +12,7 @@ future as well. It provides configuration information about object
|
||||||
constructors which are not classes. Such constructors may be factory
|
constructors which are not classes. Such constructors may be factory
|
||||||
functions or class instances.
|
functions or class instances.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module copy_reg)}
|
\setindexsubitem{(in module copy_reg)}
|
||||||
|
|
||||||
\begin{funcdesc}{constructor}{object}
|
\begin{funcdesc}{constructor}{object}
|
||||||
Declares \var{object} to be a valid constructor.
|
Declares \var{object} to be a valid constructor.
|
||||||
|
|
|
@ -9,7 +9,7 @@ allowing Python scripts to accept typed passwords from the user, or
|
||||||
attempting to crack \UNIX{} passwords with a dictionary.
|
attempting to crack \UNIX{} passwords with a dictionary.
|
||||||
\index{crypt(3)}
|
\index{crypt(3)}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module crypt)}
|
\setindexsubitem{(in module crypt)}
|
||||||
\begin{funcdesc}{crypt}{word\, salt}
|
\begin{funcdesc}{crypt}{word\, salt}
|
||||||
\var{word} will usually be a user's password. \var{salt} is a
|
\var{word} will usually be a user's password. \var{salt} is a
|
||||||
2-character string which will be used to select one of 4096 variations
|
2-character string which will be used to select one of 4096 variations
|
||||||
|
|
|
@ -14,7 +14,7 @@ using the GNU GDBM library.
|
||||||
|
|
||||||
The module defines the following constant and functions:
|
The module defines the following constant and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module dbm)}
|
\setindexsubitem{(in module dbm)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
Raised on dbm-specific errors, such as I/O errors. \code{KeyError} is
|
Raised on dbm-specific errors, such as I/O errors. \code{KeyError} is
|
||||||
raised for general mapping errors like specifying an incorrect key.
|
raised for general mapping errors like specifying an incorrect key.
|
||||||
|
|
|
@ -11,10 +11,10 @@ this module takes as an input is defined in the file
|
||||||
|
|
||||||
Example: Given the function myfunc
|
Example: Given the function myfunc
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def myfunc(alist):
|
def myfunc(alist):
|
||||||
return len(alist)
|
return len(alist)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
the following command can be used to get the disassembly of \code{myfunc()}:
|
the following command can be used to get the disassembly of \code{myfunc()}:
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ the following command can be used to get the disassembly of \code{myfunc()}:
|
||||||
|
|
||||||
The \code{dis} module defines the following functions:
|
The \code{dis} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module dis)}
|
\setindexsubitem{(in module dis)}
|
||||||
|
|
||||||
\begin{funcdesc}{dis}{\optional{bytesource}}
|
\begin{funcdesc}{dis}{\optional{bytesource}}
|
||||||
Disassemble the \var{bytesource} object. \var{bytesource} can denote
|
Disassemble the \var{bytesource} object. \var{bytesource} can denote
|
||||||
|
@ -107,7 +107,7 @@ Sequence of byte codes of boolean operations.
|
||||||
The Python compiler currently generates the following byte code
|
The Python compiler currently generates the following byte code
|
||||||
instructions.
|
instructions.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(byte code insns)}
|
\setindexsubitem{(byte code insns)}
|
||||||
|
|
||||||
\begin{opcodedesc}{STOP_CODE}{}
|
\begin{opcodedesc}{STOP_CODE}{}
|
||||||
Indicates end-of-code to the compiler, not used by the interpreter.
|
Indicates end-of-code to the compiler, not used by the interpreter.
|
||||||
|
@ -507,5 +507,5 @@ default parameters, which are found below TOS.
|
||||||
Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it
|
Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it
|
||||||
is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3,
|
is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3,
|
||||||
\code{slice(TOS2, TOS1, TOS)} is pushed.
|
\code{slice(TOS2, TOS1, TOS)} is pushed.
|
||||||
See the \code{slice()} built-in function.
|
See the \code{slice()}\bifuncindex{slice} built-in function.
|
||||||
\end{opcodedesc}
|
\end{opcodedesc}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
\section{Standard Module \sectcode{errno}}
|
\section{Standard Module \sectcode{errno}}
|
||||||
\stmodindex{errno}
|
\stmodindex{errno}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module errno)}
|
\setindexsubitem{(in module errno)}
|
||||||
|
|
||||||
This module makes available standard errno system symbols.
|
This module makes available standard errno system symbols.
|
||||||
The value of each symbol is the corresponding integer value.
|
The value of each symbol is the corresponding integer value.
|
||||||
|
|
|
@ -52,7 +52,7 @@ situation in which the interpreter raises the same exception; but
|
||||||
beware that there is nothing to prevent user code from raising an
|
beware that there is nothing to prevent user code from raising an
|
||||||
inappropriate error.
|
inappropriate error.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(built-in exception base class)}
|
\setindexsubitem{(built-in exception base class)}
|
||||||
|
|
||||||
The following exceptions are only used as base classes for other
|
The following exceptions are only used as base classes for other
|
||||||
exceptions. When string-based standard exceptions are used, they
|
exceptions. When string-based standard exceptions are used, they
|
||||||
|
@ -87,7 +87,7 @@ index used on a mapping or sequence is invalid: \code{IndexError},
|
||||||
\code{KeyError}.
|
\code{KeyError}.
|
||||||
\end{excdesc}
|
\end{excdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(built-in exception)}
|
\setindexsubitem{(built-in exception)}
|
||||||
|
|
||||||
The following exceptions are the exceptions that are actually raised.
|
The following exceptions are the exceptions that are actually raised.
|
||||||
They are class objects, except when the \code{-X} option is used to
|
They are class objects, except when the \code{-X} option is used to
|
||||||
|
|
|
@ -11,7 +11,7 @@ file or socket object.
|
||||||
|
|
||||||
The module defines the following functions:
|
The module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module struct)}
|
\setindexsubitem{(in module struct)}
|
||||||
|
|
||||||
\begin{funcdesc}{fcntl}{fd\, op\optional{\, arg}}
|
\begin{funcdesc}{fcntl}{fd\, op\optional{\, arg}}
|
||||||
Perform the requested operation on file descriptor \code{\var{fd}}.
|
Perform the requested operation on file descriptor \code{\var{fd}}.
|
||||||
|
@ -56,7 +56,7 @@ script, found in the \file{Tools/scripts} directory.
|
||||||
|
|
||||||
Examples (all on a SVR4 compliant system):
|
Examples (all on a SVR4 compliant system):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import struct, FCNTL
|
import struct, FCNTL
|
||||||
|
|
||||||
file = open(...)
|
file = open(...)
|
||||||
|
@ -64,7 +64,7 @@ rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1)
|
||||||
|
|
||||||
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
|
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
|
||||||
rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
|
rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Note that in the first example the return value variable \code{rv} will
|
Note that in the first example the return value variable \code{rv} will
|
||||||
hold an integer value; in the second example it will hold a string
|
hold an integer value; in the second example it will hold a string
|
||||||
|
|
|
@ -41,7 +41,7 @@ Module \code{fl} defines the following functions. For more information
|
||||||
about what they do, see the description of the equivalent C function
|
about what they do, see the description of the equivalent C function
|
||||||
in the FORMS documentation:
|
in the FORMS documentation:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module fl)}
|
\setindexsubitem{(in module fl)}
|
||||||
\begin{funcdesc}{make_form}{type\, width\, height}
|
\begin{funcdesc}{make_form}{type\, width\, height}
|
||||||
Create a form with given type, width and height. This returns a
|
Create a form with given type, width and height. This returns a
|
||||||
\dfn{form} object, whose methods are described below.
|
\dfn{form} object, whose methods are described below.
|
||||||
|
@ -146,7 +146,7 @@ kinds of FORMS object also have some methods specific to that kind;
|
||||||
these methods are listed here.
|
these methods are listed here.
|
||||||
|
|
||||||
\begin{flushleft}
|
\begin{flushleft}
|
||||||
\renewcommand{\indexsubitem}{(form object method)}
|
\setindexsubitem{(form object method)}
|
||||||
\begin{funcdesc}{show_form}{placement\, bordertype\, name}
|
\begin{funcdesc}{show_form}{placement\, bordertype\, name}
|
||||||
Show the form.
|
Show the form.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
@ -389,7 +389,7 @@ documentation:
|
||||||
Besides methods specific to particular kinds of FORMS objects, all
|
Besides methods specific to particular kinds of FORMS objects, all
|
||||||
FORMS objects also have the following methods:
|
FORMS objects also have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(FORMS object method)}
|
\setindexsubitem{(FORMS object method)}
|
||||||
\begin{funcdesc}{set_call_back}{function\, argument}
|
\begin{funcdesc}{set_call_back}{function\, argument}
|
||||||
Set the object's callback function and argument. When the object
|
Set the object's callback function and argument. When the object
|
||||||
needs interaction, the callback function will be called with two
|
needs interaction, the callback function will be called with two
|
||||||
|
@ -468,10 +468,10 @@ the C header file \file{<forms.h>} except that the name prefix
|
||||||
\samp{FL_} is omitted. Read the module source for a complete list of
|
\samp{FL_} is omitted. Read the module source for a complete list of
|
||||||
the defined names. Suggested use:
|
the defined names. Suggested use:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import fl
|
import fl
|
||||||
from FL import *
|
from FL import *
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\section{Standard Module \sectcode{flp}}
|
\section{Standard Module \sectcode{flp}}
|
||||||
\label{module-flp}
|
\label{module-flp}
|
||||||
|
|
|
@ -14,7 +14,7 @@ details of font info; individual glyph metrics; and printer matching.
|
||||||
|
|
||||||
It supports the following operations:
|
It supports the following operations:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module fm)}
|
\setindexsubitem{(in module fm)}
|
||||||
\begin{funcdesc}{init}{}
|
\begin{funcdesc}{init}{}
|
||||||
Initialization function.
|
Initialization function.
|
||||||
Calls \code{fminit()}.
|
Calls \code{fminit()}.
|
||||||
|
@ -50,7 +50,7 @@ Returns the current font search path.
|
||||||
|
|
||||||
Font handle objects support the following operations:
|
Font handle objects support the following operations:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(font handle method)}
|
\setindexsubitem{(font handle method)}
|
||||||
\begin{funcdesc}{scalefont}{factor}
|
\begin{funcdesc}{scalefont}{factor}
|
||||||
Returns a handle for a scaled version of this font.
|
Returns a handle for a scaled version of this font.
|
||||||
Calls \code{fmscalefont(\var{fh}, \var{factor})}.
|
Calls \code{fmscalefont(\var{fh}, \var{factor})}.
|
||||||
|
|
|
@ -18,7 +18,7 @@ special to this module. See module \code{glob}\refstmodindex{glob}
|
||||||
for pathname expansion (\code{glob} uses \code{fnmatch()} to
|
for pathname expansion (\code{glob} uses \code{fnmatch()} to
|
||||||
match filename segments).
|
match filename segments).
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module fnmatch)}
|
\setindexsubitem{(in module fnmatch)}
|
||||||
|
|
||||||
\begin{funcdesc}{fnmatch}{filename, pattern}
|
\begin{funcdesc}{fnmatch}{filename, pattern}
|
||||||
Test whether the \var{filename} string matches the \var{pattern}
|
Test whether the \var{filename} string matches the \var{pattern}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-formatter}
|
\label{module-formatter}
|
||||||
\stmodindex{formatter}
|
\stmodindex{formatter}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module formatter)}
|
\setindexsubitem{(in module formatter)}
|
||||||
|
|
||||||
This module supports two interface definitions, each with mulitple
|
This module supports two interface definitions, each with mulitple
|
||||||
implementations. The \emph{formatter} interface is used by the
|
implementations. The \emph{formatter} interface is used by the
|
||||||
|
@ -47,14 +47,14 @@ be called without having to track whether the property was changed.
|
||||||
|
|
||||||
The following attributes are defined for formatter instance objects:
|
The following attributes are defined for formatter instance objects:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(formatter object data)}
|
\setindexsubitem{(formatter object data)}
|
||||||
|
|
||||||
\begin{datadesc}{writer}
|
\begin{datadesc}{writer}
|
||||||
The writer instance with which the formatter interacts.
|
The writer instance with which the formatter interacts.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(formatter object method)}
|
\setindexsubitem{(formatter object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{end_paragraph}{blanklines}
|
\begin{funcdesc}{end_paragraph}{blanklines}
|
||||||
Close any open paragraphs and insert at least \code{blanklines}
|
Close any open paragraphs and insert at least \code{blanklines}
|
||||||
|
@ -187,7 +187,7 @@ Two implementations of formatter objects are provided by this module.
|
||||||
Most applications may use one of these classes without modification or
|
Most applications may use one of these classes without modification or
|
||||||
subclassing.
|
subclassing.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module formatter)}
|
\setindexsubitem{(in module formatter)}
|
||||||
|
|
||||||
\begin{funcdesc}{NullFormatter}{\optional{writer\code{ = None}}}
|
\begin{funcdesc}{NullFormatter}{\optional{writer\code{ = None}}}
|
||||||
A formatter which does nothing. If \code{writer} is omitted, a
|
A formatter which does nothing. If \code{writer} is omitted, a
|
||||||
|
@ -215,7 +215,7 @@ Note that while most applications can use the \code{AbstractFormatter}
|
||||||
class as a formatter, the writer must typically be provided by the
|
class as a formatter, the writer must typically be provided by the
|
||||||
application.
|
application.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(writer object method)}
|
\setindexsubitem{(writer object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{flush}{}
|
\begin{funcdesc}{flush}{}
|
||||||
Flush any buffered output or device control events.
|
Flush any buffered output or device control events.
|
||||||
|
@ -307,7 +307,7 @@ Three implementations of the writer object interface are provided as
|
||||||
examples by this module. Most applications will need to derive new
|
examples by this module. Most applications will need to derive new
|
||||||
writer classes from the \code{NullWriter} class.
|
writer classes from the \code{NullWriter} class.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module formatter)}
|
\setindexsubitem{(in module formatter)}
|
||||||
|
|
||||||
\begin{funcdesc}{NullWriter}{}
|
\begin{funcdesc}{NullWriter}{}
|
||||||
A writer which only provides the interface definition; no actions are
|
A writer which only provides the interface definition; no actions are
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\stmodindex{ftplib}
|
\stmodindex{ftplib}
|
||||||
\indexii{FTP}{protocol}
|
\indexii{FTP}{protocol}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module ftplib)}
|
\setindexsubitem{(in module ftplib)}
|
||||||
|
|
||||||
This module defines the class \code{FTP} and a few related items. The
|
This module defines the class \code{FTP} and a few related items. The
|
||||||
\code{FTP} class implements the client side of the FTP protocol. You
|
\code{FTP} class implements the client side of the FTP protocol. You
|
||||||
|
@ -14,7 +14,7 @@ more information on FTP (File Transfer Protocol), see Internet \rfc{959}.
|
||||||
|
|
||||||
Here's a sample session using the \code{ftplib} module:
|
Here's a sample session using the \code{ftplib} module:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> from ftplib import FTP
|
>>> from ftplib import FTP
|
||||||
>>> ftp = FTP('ftp.cwi.nl') # connect to host, default port
|
>>> ftp = FTP('ftp.cwi.nl') # connect to host, default port
|
||||||
>>> ftp.login() # user anonymous, passwd user@hostname
|
>>> ftp.login() # user anonymous, passwd user@hostname
|
||||||
|
@ -27,7 +27,7 @@ dr-xr-srwt 105 ftp-usr pdmaint 1536 Mar 21 14:32 ..
|
||||||
.
|
.
|
||||||
.
|
.
|
||||||
>>> ftp.quit()
|
>>> ftp.quit()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The module defines the following items:
|
The module defines the following items:
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ not begin with a digit in the range 1--5.
|
||||||
|
|
||||||
FTP instances have the following methods:
|
FTP instances have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(FTP object method)}
|
\setindexsubitem{(FTP object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{set_debuglevel}{level}
|
\begin{funcdesc}{set_debuglevel}{level}
|
||||||
Set the instance's debugging level. This controls the amount of
|
Set the instance's debugging level. This controls the amount of
|
||||||
|
|
|
@ -5,7 +5,7 @@ The Python interpreter has a number of functions built into it that
|
||||||
are always available. They are listed here in alphabetical order.
|
are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(built-in function)}
|
\setindexsubitem{(built-in function)}
|
||||||
|
|
||||||
\begin{funcdesc}{__import__}{name\optional{, globals\optional{, locals\optional{, fromlist}}}}
|
\begin{funcdesc}{__import__}{name\optional{, globals\optional{, locals\optional{, fromlist}}}}
|
||||||
This function is invoked by the \code{import} statement. It
|
This function is invoked by the \code{import} statement. It
|
||||||
|
@ -135,14 +135,14 @@ class instances are callable if they have an attribute \code{__call__}.
|
||||||
and for class instances, methods are not included.
|
and for class instances, methods are not included.
|
||||||
The resulting list is sorted alphabetically. For example:
|
The resulting list is sorted alphabetically. For example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import sys
|
>>> import sys
|
||||||
>>> dir()
|
>>> dir()
|
||||||
['sys']
|
['sys']
|
||||||
>>> dir(sys)
|
>>> dir(sys)
|
||||||
['argv', 'exit', 'modules', 'path', 'stderr', 'stdin', 'stdout']
|
['argv', 'exit', 'modules', 'path', 'stderr', 'stdin', 'stdout']
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{divmod}{a\, b}
|
\begin{funcdesc}{divmod}{a\, b}
|
||||||
|
@ -166,12 +166,12 @@ class instances are callable if they have an attribute \code{__call__}.
|
||||||
called. The return value is the result of the evaluated expression.
|
called. The return value is the result of the evaluated expression.
|
||||||
Syntax errors are reported as exceptions. Example:
|
Syntax errors are reported as exceptions. Example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> x = 1
|
>>> x = 1
|
||||||
>>> print eval('x+1')
|
>>> print eval('x+1')
|
||||||
2
|
2
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This function can also be used to execute arbitrary code objects
|
This function can also be used to execute arbitrary code objects
|
||||||
(e.g.\ created by \code{compile()}). In this case pass a code
|
(e.g.\ created by \code{compile()}). In this case pass a code
|
||||||
|
@ -448,7 +448,7 @@ there's no reliable way to determine whether this is the case.}
|
||||||
greater than \var{stop}. \var{step} must not be zero (or else an
|
greater than \var{stop}. \var{step} must not be zero (or else an
|
||||||
exception is raised). Example:
|
exception is raised). Example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> range(10)
|
>>> range(10)
|
||||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||||
>>> range(1, 11)
|
>>> range(1, 11)
|
||||||
|
@ -464,7 +464,7 @@ there's no reliable way to determine whether this is the case.}
|
||||||
>>> range(1, 0)
|
>>> range(1, 0)
|
||||||
[]
|
[]
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{raw_input}{\optional{prompt}}
|
\begin{funcdesc}{raw_input}{\optional{prompt}}
|
||||||
|
@ -473,13 +473,13 @@ there's no reliable way to determine whether this is the case.}
|
||||||
converts it to a string (stripping a trailing newline), and returns that.
|
converts it to a string (stripping a trailing newline), and returns that.
|
||||||
When \EOF{} is read, \code{EOFError} is raised. Example:
|
When \EOF{} is read, \code{EOFError} is raised. Example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> s = raw_input('--> ')
|
>>> s = raw_input('--> ')
|
||||||
--> Monty Python's Flying Circus
|
--> Monty Python's Flying Circus
|
||||||
>>> s
|
>>> s
|
||||||
"Monty Python's Flying Circus"
|
"Monty Python's Flying Circus"
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
If the \code{readline} module was loaded, then
|
If the \code{readline} module was loaded, then
|
||||||
\code{raw_input()} will use it to provide elaborate
|
\code{raw_input()} will use it to provide elaborate
|
||||||
|
@ -604,10 +604,10 @@ built-in types.
|
||||||
\obindex{type}
|
\obindex{type}
|
||||||
For instance:
|
For instance:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import types
|
>>> import types
|
||||||
>>> if isinstance(x, types.StringType): print "It's a string"
|
>>> if isinstance(x, types.StringType): print "It's a string"
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{vars}{\optional{object}}
|
\begin{funcdesc}{vars}{\optional{object}}
|
||||||
|
|
|
@ -15,7 +15,7 @@ Printing a \code{gdbm} object doesn't print the keys and values, and the
|
||||||
|
|
||||||
The module defines the following constant and functions:
|
The module defines the following constant and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module gdbm)}
|
\setindexsubitem{(in module gdbm)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
Raised on \code{gdbm}-specific errors, such as I/O errors. \code{KeyError} is
|
Raised on \code{gdbm}-specific errors, such as I/O errors. \code{KeyError} is
|
||||||
raised for general mapping errors like specifying an incorrect key.
|
raised for general mapping errors like specifying an incorrect key.
|
||||||
|
@ -57,12 +57,12 @@ method returns the starting key.
|
||||||
Returns the key that follows \var{key} in the traversal. The
|
Returns the key that follows \var{key} in the traversal. The
|
||||||
following code prints every key in the database \code{db}, without having to
|
following code prints every key in the database \code{db}, without having to
|
||||||
create a list in memory that contains them all:
|
create a list in memory that contains them all:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
k=db.firstkey()
|
k=db.firstkey()
|
||||||
while k!=None:
|
while k!=None:
|
||||||
print k
|
print k
|
||||||
k=db.nextkey(k)
|
k=db.nextkey(k)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{reorganize}{}
|
\begin{funcdesc}{reorganize}{}
|
||||||
|
|
|
@ -45,7 +45,7 @@ be mixed.
|
||||||
|
|
||||||
An example using only \UNIX{} style options:
|
An example using only \UNIX{} style options:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import getopt, string
|
>>> import getopt, string
|
||||||
>>> args = string.split('-a -b -cfoo -d bar a1 a2')
|
>>> args = string.split('-a -b -cfoo -d bar a1 a2')
|
||||||
>>> args
|
>>> args
|
||||||
|
@ -56,11 +56,11 @@ An example using only \UNIX{} style options:
|
||||||
>>> args
|
>>> args
|
||||||
['a1', 'a2']
|
['a1', 'a2']
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Using long option names is equally easy:
|
Using long option names is equally easy:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
|
>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
|
||||||
>>> args = string.split(s)
|
>>> args = string.split(s)
|
||||||
>>> args
|
>>> args
|
||||||
|
@ -72,7 +72,7 @@ Using long option names is equally easy:
|
||||||
>>> args
|
>>> args
|
||||||
['a1', 'a2']
|
['a1', 'a2']
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The exception
|
The exception
|
||||||
\code{getopt.error}
|
\code{getopt.error}
|
||||||
|
|
|
@ -41,15 +41,15 @@ All (short, long, unsigned) integer arguments or return values that are
|
||||||
only used to specify the length of an array argument are omitted.
|
only used to specify the length of an array argument are omitted.
|
||||||
For example, the C call
|
For example, the C call
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
lmdef(deftype, index, np, props)
|
lmdef(deftype, index, np, props)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
is translated to Python as
|
is translated to Python as
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
lmdef(deftype, index, props)
|
lmdef(deftype, index, props)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\item
|
\item
|
||||||
Output arguments are omitted from the argument list; they are
|
Output arguments are omitted from the argument list; they are
|
||||||
|
@ -60,22 +60,22 @@ because of the previous rule) and an output argument, the return value
|
||||||
comes first in the tuple.
|
comes first in the tuple.
|
||||||
Examples: the C call
|
Examples: the C call
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
getmcolor(i, &red, &green, &blue)
|
getmcolor(i, &red, &green, &blue)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
is translated to Python as
|
is translated to Python as
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
red, green, blue = getmcolor(i)
|
red, green, blue = getmcolor(i)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
The following functions are non-standard or have special argument
|
The following functions are non-standard or have special argument
|
||||||
conventions:
|
conventions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module gl)}
|
\setindexsubitem{(in module gl)}
|
||||||
\begin{funcdesc}{varray}{argument}
|
\begin{funcdesc}{varray}{argument}
|
||||||
%JHXXX the argument-argument added
|
%JHXXX the argument-argument added
|
||||||
Equivalent to but faster than a number of
|
Equivalent to but faster than a number of
|
||||||
|
@ -160,7 +160,7 @@ No method is provided to detect buffer overrun.
|
||||||
|
|
||||||
Here is a tiny but complete example GL program in Python:
|
Here is a tiny but complete example GL program in Python:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import gl, GL, time
|
import gl, GL, time
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -182,7 +182,7 @@ def main():
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\section{Standard Modules \sectcode{GL} and \sectcode{DEVICE}}
|
\section{Standard Modules \sectcode{GL} and \sectcode{DEVICE}}
|
||||||
\nodename{GL and DEVICE}
|
\nodename{GL and DEVICE}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
\section{Standard Module \sectcode{glob}}
|
\section{Standard Module \sectcode{glob}}
|
||||||
\label{module-glob}
|
\label{module-glob}
|
||||||
\stmodindex{glob}
|
\stmodindex{glob}
|
||||||
\renewcommand{\indexsubitem}{(in module glob)}
|
\setindexsubitem{(in module glob)}
|
||||||
|
|
||||||
The \code{glob} module finds all the pathnames matching a specified
|
The \code{glob} module finds all the pathnames matching a specified
|
||||||
pattern according to the rules used by the \UNIX{} shell. No tilde
|
pattern according to the rules used by the \UNIX{} shell. No tilde
|
||||||
|
@ -25,7 +25,7 @@ For example, consider a directory containing only the following files:
|
||||||
will produce the following results. Notice how any leading components
|
will produce the following results. Notice how any leading components
|
||||||
of the path are preserved.
|
of the path are preserved.
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import glob
|
>>> import glob
|
||||||
>>> glob.glob('./[0-9].*')
|
>>> glob.glob('./[0-9].*')
|
||||||
['./1.gif', './2.txt']
|
['./1.gif', './2.txt']
|
||||||
|
@ -33,4 +33,4 @@ of the path are preserved.
|
||||||
['1.gif', 'card.gif']
|
['1.gif', 'card.gif']
|
||||||
>>> glob.glob('?.gif')
|
>>> glob.glob('?.gif')
|
||||||
['1.gif']
|
['1.gif']
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\stmodindex{gopherlib}
|
\stmodindex{gopherlib}
|
||||||
\indexii{Gopher}{protocol}
|
\indexii{Gopher}{protocol}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module gopherlib)}
|
\setindexsubitem{(in module gopherlib)}
|
||||||
|
|
||||||
This module provides a minimal implementation of client side of the
|
This module provides a minimal implementation of client side of the
|
||||||
the Gopher protocol. It is used by the module \code{urllib} to handle
|
the Gopher protocol. It is used by the module \code{urllib} to handle
|
||||||
|
|
|
@ -19,7 +19,7 @@ A \code{KeyError} exception is raised if the entry asked for cannot be found.
|
||||||
|
|
||||||
It defines the following items:
|
It defines the following items:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module grp)}
|
\setindexsubitem{(in module grp)}
|
||||||
\begin{funcdesc}{getgrgid}{gid}
|
\begin{funcdesc}{getgrgid}{gid}
|
||||||
Return the group database entry for the given numeric group ID.
|
Return the group database entry for the given numeric group ID.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
|
@ -12,7 +12,7 @@ or decompressing the data so it looks like an ordinary file object.
|
||||||
object, though it's not possible to use the \code{seek()} and
|
object, though it's not possible to use the \code{seek()} and
|
||||||
\code{tell()} methods to access the file randomly.
|
\code{tell()} methods to access the file randomly.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module gzip)}
|
\setindexsubitem{(in module gzip)}
|
||||||
\begin{funcdesc}{open}{fileobj\optional{\, filename\optional{\, mode\, compresslevel}}}
|
\begin{funcdesc}{open}{fileobj\optional{\, filename\optional{\, mode\, compresslevel}}}
|
||||||
Returns a new \code{GzipFile} object on top of \var{fileobj}, which
|
Returns a new \code{GzipFile} object on top of \var{fileobj}, which
|
||||||
can be a regular file, a \code{StringIO} object, or any object which
|
can be a regular file, a \code{StringIO} object, or any object which
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
\index{HTML}
|
\index{HTML}
|
||||||
\index{hypertext}
|
\index{hypertext}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module htmllib)}
|
\setindexsubitem{(in module htmllib)}
|
||||||
|
|
||||||
This module defines a class which can serve as a base for parsing text
|
This module defines a class which can serve as a base for parsing text
|
||||||
files formatted in the HyperText Mark-up Language (HTML). The class
|
files formatted in the HyperText Mark-up Language (HTML). The class
|
||||||
|
@ -40,10 +40,10 @@ incomplete elements are saved in a buffer. To force processing of all
|
||||||
unprocessed data, call the \method{close()} method.
|
unprocessed data, call the \method{close()} method.
|
||||||
|
|
||||||
For example, to parse the entire contents of a file, use:
|
For example, to parse the entire contents of a file, use:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
parser.feed(open('myfile.html').read())
|
parser.feed(open('myfile.html').read())
|
||||||
parser.close()
|
parser.close()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\item
|
\item
|
||||||
The interface to define semantics for HTML tags is very simple: derive
|
The interface to define semantics for HTML tags is very simple: derive
|
||||||
|
@ -71,7 +71,7 @@ handlers for all HTML 2.0 and many HTML 3.0 and 3.2 elements.
|
||||||
In addition to tag methods, the \class{HTMLParser} class provides some
|
In addition to tag methods, the \class{HTMLParser} class provides some
|
||||||
additional methods and instance variables for use within tag methods.
|
additional methods and instance variables for use within tag methods.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(HTMLParser attribute)}
|
\setindexsubitem{(HTMLParser attribute)}
|
||||||
|
|
||||||
\begin{datadesc}{formatter}
|
\begin{datadesc}{formatter}
|
||||||
This is the formatter instance associated with the parser.
|
This is the formatter instance associated with the parser.
|
||||||
|
@ -85,7 +85,7 @@ as within a \code{<PRE>} element. The default value is false. This
|
||||||
affects the operation of \method{handle_data()} and \method{save_end()}.
|
affects the operation of \method{handle_data()} and \method{save_end()}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(HTMLParser method)}
|
\setindexsubitem{(HTMLParser method)}
|
||||||
|
|
||||||
\begin{funcdesc}{anchor_bgn}{href\, name\, type}
|
\begin{funcdesc}{anchor_bgn}{href\, name\, type}
|
||||||
This method is called at the start of an anchor region. The arguments
|
This method is called at the start of an anchor region. The arguments
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\stmodindex{httplib}
|
\stmodindex{httplib}
|
||||||
\index{HTTP}
|
\index{HTTP}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module httplib)}
|
\setindexsubitem{(in module httplib)}
|
||||||
|
|
||||||
This module defines a class which implements the client side of the
|
This module defines a class which implements the client side of the
|
||||||
HTTP protocol. It is normally not used directly --- the module
|
HTTP protocol. It is normally not used directly --- the module
|
||||||
|
@ -20,11 +20,11 @@ method should be used to connect to a server. For example, the
|
||||||
following calls all create instances that connect to the server at the
|
following calls all create instances that connect to the server at the
|
||||||
same host and port:
|
same host and port:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> h1 = httplib.HTTP('www.cwi.nl')
|
>>> h1 = httplib.HTTP('www.cwi.nl')
|
||||||
>>> h2 = httplib.HTTP('www.cwi.nl:80')
|
>>> h2 = httplib.HTTP('www.cwi.nl:80')
|
||||||
>>> h3 = httplib.HTTP('www.cwi.nl', 80)
|
>>> h3 = httplib.HTTP('www.cwi.nl', 80)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Once an \code{HTTP} instance has been connected to an HTTP server, it
|
Once an \code{HTTP} instance has been connected to an HTTP server, it
|
||||||
should be used as follows:
|
should be used as follows:
|
||||||
|
@ -51,7 +51,7 @@ file object that it returns.
|
||||||
|
|
||||||
\code{HTTP} instances have the following methods:
|
\code{HTTP} instances have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(HTTP method)}
|
\setindexsubitem{(HTTP method)}
|
||||||
|
|
||||||
\begin{funcdesc}{set_debuglevel}{level}
|
\begin{funcdesc}{set_debuglevel}{level}
|
||||||
Set the debugging level (the amount of debugging output printed).
|
Set the debugging level (the amount of debugging output printed).
|
||||||
|
@ -112,7 +112,7 @@ methods.
|
||||||
|
|
||||||
Here is an example session:
|
Here is an example session:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import httplib
|
>>> import httplib
|
||||||
>>> h = httplib.HTTP('www.cwi.nl')
|
>>> h = httplib.HTTP('www.cwi.nl')
|
||||||
>>> h.putrequest('GET', '/index.html')
|
>>> h.putrequest('GET', '/index.html')
|
||||||
|
@ -125,4 +125,4 @@ Here is an example session:
|
||||||
>>> data = f.read() # Get the raw HTML
|
>>> data = f.read() # Get the raw HTML
|
||||||
>>> f.close()
|
>>> f.close()
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -9,7 +9,7 @@ by \code{gl.lrectwrite} and the \code{imgfile} module.
|
||||||
|
|
||||||
The module defines the following variables and functions:
|
The module defines the following variables and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module imageop)}
|
\setindexsubitem{(in module imageop)}
|
||||||
|
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised on all errors, such as unknown number of bits
|
This exception is raised on all errors, such as unknown number of bits
|
||||||
|
|
|
@ -9,7 +9,7 @@ is enough in some cases. Currently, colormap files are not supported.
|
||||||
|
|
||||||
The module defines the following variables and functions:
|
The module defines the following variables and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module imgfile)}
|
\setindexsubitem{(in module imgfile)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised on all errors, such as unsupported file type, etc.
|
This exception is raised on all errors, such as unsupported file type, etc.
|
||||||
\end{excdesc}
|
\end{excdesc}
|
||||||
|
|
|
@ -7,7 +7,7 @@ file or byte stream.
|
||||||
|
|
||||||
The \code{imghdr} module defines the following function:
|
The \code{imghdr} module defines the following function:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module imghdr)}
|
\setindexsubitem{(in module imghdr)}
|
||||||
|
|
||||||
\begin{funcdesc}{what}{filename\optional{\, h}}
|
\begin{funcdesc}{what}{filename\optional{\, h}}
|
||||||
Tests the image data contained in the file named by \var{filename},
|
Tests the image data contained in the file named by \var{filename},
|
||||||
|
@ -54,8 +54,8 @@ the test succeeded, or \code{None} if it failed.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import imghdr
|
>>> import imghdr
|
||||||
>>> imghdr.what('/tmp/bass.gif')
|
>>> imghdr.what('/tmp/bass.gif')
|
||||||
'gif'
|
'gif'
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -7,7 +7,7 @@ This module provides an interface to the mechanisms used to implement
|
||||||
the \code{import} statement. It defines the following constants and
|
the \code{import} statement. It defines the following constants and
|
||||||
functions:
|
functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module imp)}
|
\setindexsubitem{(in module imp)}
|
||||||
|
|
||||||
\begin{funcdesc}{get_magic}{}
|
\begin{funcdesc}{get_magic}{}
|
||||||
Return the magic string value used to recognize byte-compiled code
|
Return the magic string value used to recognize byte-compiled code
|
||||||
|
@ -206,7 +206,7 @@ up to Python 1.4 (i.e., no hierarchical module names). (This
|
||||||
\code{imp.find_module()} has been extended and
|
\code{imp.find_module()} has been extended and
|
||||||
\code{imp.load_module()} has been added in 1.4.)
|
\code{imp.load_module()} has been added in 1.4.)
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import imp import sys
|
import imp import sys
|
||||||
|
|
||||||
def __import__(name, globals=None, locals=None, fromlist=None):
|
def __import__(name, globals=None, locals=None, fromlist=None):
|
||||||
|
@ -227,7 +227,7 @@ def __import__(name, globals=None, locals=None, fromlist=None):
|
||||||
# Since we may exit via an exception, close fp explicitly.
|
# Since we may exit via an exception, close fp explicitly.
|
||||||
if fp:
|
if fp:
|
||||||
fp.close()
|
fp.close()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
A more complete example that implements hierarchical module names and
|
A more complete example that implements hierarchical module names and
|
||||||
includes a \code{reload()} function can be found in the standard
|
includes a \code{reload()} function can be found in the standard
|
||||||
|
|
|
@ -10,7 +10,7 @@ documentation provided with the software.
|
||||||
|
|
||||||
The \code{jpeg} module defines these functions:
|
The \code{jpeg} module defines these functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module jpeg)}
|
\setindexsubitem{(in module jpeg)}
|
||||||
\begin{funcdesc}{compress}{data\, w\, h\, b}
|
\begin{funcdesc}{compress}{data\, w\, h\, b}
|
||||||
Treat data as a pixmap of width \var{w} and height \var{h}, with \var{b} bytes per
|
Treat data as a pixmap of width \var{w} and height \var{h}, with \var{b} bytes per
|
||||||
pixel. The data is in SGI GL order, so the first pixel is in the
|
pixel. The data is in SGI GL order, so the first pixel is in the
|
||||||
|
|
|
@ -16,7 +16,7 @@ available.
|
||||||
|
|
||||||
The \code{locale} module defines the following functions:
|
The \code{locale} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module locale)}
|
\setindexsubitem{(in module locale)}
|
||||||
|
|
||||||
\begin{funcdesc}{setlocale}{category\optional{\, value}}
|
\begin{funcdesc}{setlocale}{category\optional{\, value}}
|
||||||
If \var{value} is specified, modifies the locale setting for the
|
If \var{value} is specified, modifies the locale setting for the
|
||||||
|
@ -31,10 +31,10 @@ If no \var{value} is specified, the current setting for the
|
||||||
|
|
||||||
\code{setlocale()} is not thread safe on most systems. Applications
|
\code{setlocale()} is not thread safe on most systems. Applications
|
||||||
typically start with a call of
|
typically start with a call of
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import locale
|
import locale
|
||||||
locale.setlocale(locale.LC_ALL,"")
|
locale.setlocale(locale.LC_ALL,"")
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
This sets the locale for all categories to the user's default setting
|
This sets the locale for all categories to the user's default setting
|
||||||
(typically specified in the \code{LANG} environment variable). If the
|
(typically specified in the \code{LANG} environment variable). If the
|
||||||
locale is not changed thereafter, using multithreading should not
|
locale is not changed thereafter, using multithreading should not
|
||||||
|
@ -182,9 +182,9 @@ Exception raised when \code{setlocale()} fails.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import locale
|
>>> import locale
|
||||||
>>> locale.open(locale.LC_ALL,"de") #setting locale to German
|
>>> locale.open(locale.LC_ALL,"de") #setting locale to German
|
||||||
>>> locale.strcoll("f\344n","foo") #comparing a string containing an umlaut
|
>>> locale.strcoll("f\344n","foo") #comparing a string containing an umlaut
|
||||||
>>> can.close()
|
>>> can.close()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-mailbox}
|
\label{module-mailbox}
|
||||||
\stmodindex{mailbox}
|
\stmodindex{mailbox}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module mailbox)}
|
\setindexsubitem{(in module mailbox)}
|
||||||
|
|
||||||
This module defines a number of classes that allow easy and uniform
|
This module defines a number of classes that allow easy and uniform
|
||||||
access to mail messages in a (unix) mailbox.
|
access to mail messages in a (unix) mailbox.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
\section{Standard Module \sectcode{mailcap}}
|
\section{Standard Module \sectcode{mailcap}}
|
||||||
\label{module-mailcap}
|
\label{module-mailcap}
|
||||||
\stmodindex{mailcap}
|
\stmodindex{mailcap}
|
||||||
\renewcommand{\indexsubitem}{(in module mailcap)}
|
\setindexsubitem{(in module mailcap)}
|
||||||
|
|
||||||
Mailcap files are used to configure how MIME-aware applications such
|
Mailcap files are used to configure how MIME-aware applications such
|
||||||
as mail readers and Web browsers react to files with different MIME
|
as mail readers and Web browsers react to files with different MIME
|
||||||
|
@ -69,9 +69,9 @@ will override settings in the system mailcap files
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
An example usage:
|
An example usage:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import mailcap
|
>>> import mailcap
|
||||||
>>> d=mailcap.getcaps()
|
>>> d=mailcap.getcaps()
|
||||||
>>> mailcap.findmatch(d, 'video/mpeg', filename='/tmp/tmp1223')
|
>>> mailcap.findmatch(d, 'video/mpeg', filename='/tmp/tmp1223')
|
||||||
('xmpeg /tmp/tmp1223', {'view': 'xmpeg %s'})
|
('xmpeg /tmp/tmp1223', {'view': 'xmpeg %s'})
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -54,7 +54,7 @@ operating on strings.
|
||||||
|
|
||||||
The module defines these functions:
|
The module defines these functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module marshal)}
|
\setindexsubitem{(in module marshal)}
|
||||||
|
|
||||||
\begin{funcdesc}{dump}{value\, file}
|
\begin{funcdesc}{dump}{value\, file}
|
||||||
Write the value on the open file. The value must be a supported
|
Write the value on the open file. The value must be a supported
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-math}
|
\label{module-math}
|
||||||
|
|
||||||
\bimodindex{math}
|
\bimodindex{math}
|
||||||
\renewcommand{\indexsubitem}{(in module math)}
|
\setindexsubitem{(in module math)}
|
||||||
This module is always available.
|
This module is always available.
|
||||||
It provides access to the mathematical functions defined by the \C{}
|
It provides access to the mathematical functions defined by the \C{}
|
||||||
standard.
|
standard.
|
||||||
|
|
|
@ -14,23 +14,23 @@ so far using the \code{digest()} method.
|
||||||
For example, to obtain the digest of the string {\tt"Nobody inspects
|
For example, to obtain the digest of the string {\tt"Nobody inspects
|
||||||
the spammish repetition"}:
|
the spammish repetition"}:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import md5
|
>>> import md5
|
||||||
>>> m = md5.new()
|
>>> m = md5.new()
|
||||||
>>> m.update("Nobody inspects")
|
>>> m.update("Nobody inspects")
|
||||||
>>> m.update(" the spammish repetition")
|
>>> m.update(" the spammish repetition")
|
||||||
>>> m.digest()
|
>>> m.digest()
|
||||||
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
|
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
More condensed:
|
More condensed:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> md5.new("Nobody inspects the spammish repetition").digest()
|
>>> md5.new("Nobody inspects the spammish repetition").digest()
|
||||||
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
|
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\renewcommand{\indexsubitem}{(in module md5)}
|
\setindexsubitem{(in module md5)}
|
||||||
|
|
||||||
\begin{funcdesc}{new}{\optional{arg}}
|
\begin{funcdesc}{new}{\optional{arg}}
|
||||||
Return a new md5 object. If \var{arg} is present, the method call
|
Return a new md5 object. If \var{arg} is present, the method call
|
||||||
|
@ -44,7 +44,7 @@ For backward compatibility reasons, this is an alternative name for the
|
||||||
|
|
||||||
An md5 object has the following methods:
|
An md5 object has the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(md5 method)}
|
\setindexsubitem{(md5 method)}
|
||||||
\begin{funcdesc}{update}{arg}
|
\begin{funcdesc}{update}{arg}
|
||||||
Update the md5 object with the string \var{arg}. Repeated calls are
|
Update the md5 object with the string \var{arg}. Repeated calls are
|
||||||
equivalent to a single call with the concatenation of all the
|
equivalent to a single call with the concatenation of all the
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-mimetools}
|
\label{module-mimetools}
|
||||||
\stmodindex{mimetools}
|
\stmodindex{mimetools}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module mimetools)}
|
\setindexsubitem{(in module mimetools)}
|
||||||
|
|
||||||
This module defines a subclass of the class \code{rfc822.Message} and
|
This module defines a subclass of the class \code{rfc822.Message} and
|
||||||
a number of utility functions that are useful for the manipulation for
|
a number of utility functions that are useful for the manipulation for
|
||||||
|
@ -52,7 +52,7 @@ file \var{output}. The block size is currently fixed at 8192.
|
||||||
The \code{mimetools.Message} class defines the following methods in
|
The \code{mimetools.Message} class defines the following methods in
|
||||||
addition to the \code{rfc822.Message} class:
|
addition to the \code{rfc822.Message} class:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(mimetool.Message method)}
|
\setindexsubitem{(mimetool.Message method)}
|
||||||
|
|
||||||
\begin{funcdesc}{getplist}{}
|
\begin{funcdesc}{getplist}{}
|
||||||
Return the parameter list of the \code{Content-type} header. This is
|
Return the parameter list of the \code{Content-type} header. This is
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
\section{Standard Module \sectcode{mimify}}
|
\section{Standard Module \sectcode{mimify}}
|
||||||
\stmodindex{mimify}
|
\stmodindex{mimify}
|
||||||
\renewcommand{\indexsubitem}{(in module mimify)}
|
\setindexsubitem{(in module mimify)}
|
||||||
|
|
||||||
The mimify module defines two functions to convert mail messages to
|
The mimify module defines two functions to convert mail messages to
|
||||||
and from MIME format. The mail message can be either a simple message
|
and from MIME format. The mail message can be either a simple message
|
||||||
|
|
|
@ -24,7 +24,7 @@ You create an mpz-number by calling the function called \code{mpz} (see
|
||||||
below for an exact description). An mpz-number is printed like this:
|
below for an exact description). An mpz-number is printed like this:
|
||||||
\code{mpz(\var{value})}.
|
\code{mpz(\var{value})}.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module mpz)}
|
\setindexsubitem{(in module mpz)}
|
||||||
\begin{funcdesc}{mpz}{value}
|
\begin{funcdesc}{mpz}{value}
|
||||||
Create a new mpz-number. \var{value} can be an integer, a long,
|
Create a new mpz-number. \var{value} can be an integer, a long,
|
||||||
another mpz-number, or even a string. If it is a string, it is
|
another mpz-number, or even a string. If it is a string, it is
|
||||||
|
@ -69,7 +69,7 @@ return mpz-numbers.
|
||||||
|
|
||||||
An mpz-number has one method:
|
An mpz-number has one method:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(mpz method)}
|
\setindexsubitem{(mpz method)}
|
||||||
\begin{funcdesc}{binary}{}
|
\begin{funcdesc}{binary}{}
|
||||||
Convert this mpz-number to a binary string, where the number has been
|
Convert this mpz-number to a binary string, where the number has been
|
||||||
stored as an array of radix-256 digits, least significant digit first.
|
stored as an array of radix-256 digits, least significant digit first.
|
||||||
|
|
|
@ -28,20 +28,20 @@ To import module \code{ham} from package \code{spam} and use function
|
||||||
\code{hamneggs()} from that module, you can use any of the following
|
\code{hamneggs()} from that module, you can use any of the following
|
||||||
possibilities:
|
possibilities:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import spam.ham # *not* "import spam" !!!
|
import spam.ham # *not* "import spam" !!!
|
||||||
spam.ham.hamneggs()
|
spam.ham.hamneggs()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
from spam import ham
|
from spam import ham
|
||||||
ham.hamneggs()
|
ham.hamneggs()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
from spam.ham import hamneggs
|
from spam.ham import hamneggs
|
||||||
hamneggs()
|
hamneggs()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\code{import spam} creates an
|
\code{import spam} creates an
|
||||||
empty package named \code{spam} if one does not already exist, but it does
|
empty package named \code{spam} if one does not already exist, but it does
|
||||||
|
@ -52,9 +52,9 @@ The only submodule that is guaranteed to be imported is
|
||||||
\code{spam.__init__} is a submodule of package spam. It can refer to
|
\code{spam.__init__} is a submodule of package spam. It can refer to
|
||||||
spam's namespace as \code{__} (two underscores):
|
spam's namespace as \code{__} (two underscores):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
__.spam_inited = 1 # Set a package-level variable
|
__.spam_inited = 1 # Set a package-level variable
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Additional initialization code (setting up variables, importing other
|
Additional initialization code (setting up variables, importing other
|
||||||
submodules) can be performed in \file{spam/__init__.py}.
|
submodules) can be performed in \file{spam/__init__.py}.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\stmodindex{nntplib}
|
\stmodindex{nntplib}
|
||||||
\indexii{NNTP}{protocol}
|
\indexii{NNTP}{protocol}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module nntplib)}
|
\setindexsubitem{(in module nntplib)}
|
||||||
|
|
||||||
This module defines the class \code{NNTP} which implements the client
|
This module defines the class \code{NNTP} which implements the client
|
||||||
side of the NNTP protocol. It can be used to implement a news reader
|
side of the NNTP protocol. It can be used to implement a news reader
|
||||||
|
@ -14,7 +14,7 @@ Here are two small examples of how it can be used. To list some
|
||||||
statistics about a newsgroup and print the subjects of the last 10
|
statistics about a newsgroup and print the subjects of the last 10
|
||||||
articles:
|
articles:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> s = NNTP('news.cwi.nl')
|
>>> s = NNTP('news.cwi.nl')
|
||||||
>>> resp, count, first, last, name = s.group('comp.lang.python')
|
>>> resp, count, first, last, name = s.group('comp.lang.python')
|
||||||
>>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
|
>>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
|
||||||
|
@ -35,12 +35,12 @@ Group comp.lang.python has 59 articles, range 3742 to 3803
|
||||||
>>> s.quit()
|
>>> s.quit()
|
||||||
'205 news.cwi.nl closing connection. Goodbye.'
|
'205 news.cwi.nl closing connection. Goodbye.'
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
To post an article from a file (this assumes that the article has
|
To post an article from a file (this assumes that the article has
|
||||||
valid headers):
|
valid headers):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> s = NNTP('news.cwi.nl')
|
>>> s = NNTP('news.cwi.nl')
|
||||||
>>> f = open('/tmp/article')
|
>>> f = open('/tmp/article')
|
||||||
>>> s.post(f)
|
>>> s.post(f)
|
||||||
|
@ -48,7 +48,7 @@ valid headers):
|
||||||
>>> s.quit()
|
>>> s.quit()
|
||||||
'205 news.cwi.nl closing connection. Goodbye.'
|
'205 news.cwi.nl closing connection. Goodbye.'
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The module itself defines the following items:
|
The module itself defines the following items:
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ is the server's response: a string beginning with a three-digit code.
|
||||||
If the server's response indicates an error, the method raises one of
|
If the server's response indicates an error, the method raises one of
|
||||||
the above exceptions.
|
the above exceptions.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(NNTP object method)}
|
\setindexsubitem{(NNTP object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{getwelcome}{}
|
\begin{funcdesc}{getwelcome}{}
|
||||||
Return the welcome message sent by the server in reply to the initial
|
Return the welcome message sent by the server in reply to the initial
|
||||||
|
|
|
@ -11,7 +11,7 @@ leading and trailing \samp{__} are also provided for convenience.
|
||||||
|
|
||||||
The \code{operator} module defines the following functions:
|
The \code{operator} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module operator)}
|
\setindexsubitem{(in module operator)}
|
||||||
|
|
||||||
\begin{funcdesc}{add}{a, b}
|
\begin{funcdesc}{add}{a, b}
|
||||||
Return \var{a} \code{+} \var{b}, for \var{a} and \var{b} numbers.
|
Return \var{a} \code{+} \var{b}, for \var{a} and \var{b} numbers.
|
||||||
|
@ -188,10 +188,10 @@ Delete the slice of \var{a} from index \var{b} to index \var{c}\code{-1}.
|
||||||
Example: Build a dictionary that maps the ordinals from \code{0} to
|
Example: Build a dictionary that maps the ordinals from \code{0} to
|
||||||
\code{256} to their character equivalents.
|
\code{256} to their character equivalents.
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import operator
|
>>> import operator
|
||||||
>>> d = {}
|
>>> d = {}
|
||||||
>>> keys = range(256)
|
>>> keys = range(256)
|
||||||
>>> vals = map(chr, keys)
|
>>> vals = map(chr, keys)
|
||||||
>>> map(operator.setitem, [d]*len(keys), keys, vals)
|
>>> map(operator.setitem, [d]*len(keys), keys, vals)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -26,7 +26,7 @@ directly from the OS dependent built-in module, so there should be
|
||||||
In addition to whatever the correct OS dependent module exports, the
|
In addition to whatever the correct OS dependent module exports, the
|
||||||
following variables and functions are always exported by \code{os}:
|
following variables and functions are always exported by \code{os}:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module os)}
|
\setindexsubitem{(in module os)}
|
||||||
|
|
||||||
\begin{datadesc}{name}
|
\begin{datadesc}{name}
|
||||||
The name of the OS dependent module imported. The following names
|
The name of the OS dependent module imported. The following names
|
||||||
|
|
|
@ -15,7 +15,7 @@ to interface with the
|
||||||
The module is too large to document here in its entirety.
|
The module is too large to document here in its entirety.
|
||||||
One interesting function:
|
One interesting function:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module panel)}
|
\setindexsubitem{(in module panel)}
|
||||||
\begin{funcdesc}{defpanellist}{filename}
|
\begin{funcdesc}{defpanellist}{filename}
|
||||||
Parses a panel description file containing S-expressions written by the
|
Parses a panel description file containing S-expressions written by the
|
||||||
\emph{Panel Editor}
|
\emph{Panel Editor}
|
||||||
|
|
|
@ -89,7 +89,7 @@ to convert AST objects to other representations such as parse trees
|
||||||
and compiled code objects, but there are also functions which serve to
|
and compiled code objects, but there are also functions which serve to
|
||||||
query the type of parse tree represented by an AST object.
|
query the type of parse tree represented by an AST object.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module parser)}
|
\setindexsubitem{(in module parser)}
|
||||||
|
|
||||||
|
|
||||||
\subsection{Creating AST Objects}
|
\subsection{Creating AST Objects}
|
||||||
|
@ -289,30 +289,30 @@ bytecode generation, the simplest operation is to do nothing. For
|
||||||
this purpose, using the \module{parser} module to produce an
|
this purpose, using the \module{parser} module to produce an
|
||||||
intermediate data structure is equivelent to the code
|
intermediate data structure is equivelent to the code
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> code = compile('a + 5', 'eval')
|
>>> code = compile('a + 5', 'eval')
|
||||||
>>> a = 5
|
>>> a = 5
|
||||||
>>> eval(code)
|
>>> eval(code)
|
||||||
10
|
10
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The equivelent operation using the \module{parser} module is somewhat
|
The equivelent operation using the \module{parser} module is somewhat
|
||||||
longer, and allows the intermediate internal parse tree to be retained
|
longer, and allows the intermediate internal parse tree to be retained
|
||||||
as an AST object:
|
as an AST object:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import parser
|
>>> import parser
|
||||||
>>> ast = parser.expr('a + 5')
|
>>> ast = parser.expr('a + 5')
|
||||||
>>> code = parser.compileast(ast)
|
>>> code = parser.compileast(ast)
|
||||||
>>> a = 5
|
>>> a = 5
|
||||||
>>> eval(code)
|
>>> eval(code)
|
||||||
10
|
10
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
An application which needs both AST and code objects can package this
|
An application which needs both AST and code objects can package this
|
||||||
code into readily available functions:
|
code into readily available functions:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import parser
|
import parser
|
||||||
|
|
||||||
def load_suite(source_string):
|
def load_suite(source_string):
|
||||||
|
@ -324,7 +324,7 @@ def load_expression(source_string):
|
||||||
ast = parser.expr(source_string)
|
ast = parser.expr(source_string)
|
||||||
code = parser.compileast(ast)
|
code = parser.compileast(ast)
|
||||||
return ast, code
|
return ast, code
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\subsubsection{Information Discovery}
|
\subsubsection{Information Discovery}
|
||||||
|
|
||||||
|
@ -367,16 +367,16 @@ Consider the simplest case of interest when searching for docstrings:
|
||||||
a module consisting of a docstring and nothing else. (See file
|
a module consisting of a docstring and nothing else. (See file
|
||||||
\file{docstring.py}.)
|
\file{docstring.py}.)
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
"""Some documentation.
|
"""Some documentation.
|
||||||
"""
|
"""
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Using the interpreter to take a look at the parse tree, we find a
|
Using the interpreter to take a look at the parse tree, we find a
|
||||||
bewildering mass of numbers and parentheses, with the documentation
|
bewildering mass of numbers and parentheses, with the documentation
|
||||||
buried deep in nested tuples.
|
buried deep in nested tuples.
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import parser
|
>>> import parser
|
||||||
>>> import pprint
|
>>> import pprint
|
||||||
>>> ast = parser.suite(open('docstring.py').read())
|
>>> ast = parser.suite(open('docstring.py').read())
|
||||||
|
@ -404,7 +404,7 @@ buried deep in nested tuples.
|
||||||
(4, ''))),
|
(4, ''))),
|
||||||
(4, ''),
|
(4, ''),
|
||||||
(0, ''))
|
(0, ''))
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The numbers at the first element of each node in the tree are the node
|
The numbers at the first element of each node in the tree are the node
|
||||||
types; they map directly to terminal and non-terminal symbols in the
|
types; they map directly to terminal and non-terminal symbols in the
|
||||||
|
@ -444,7 +444,7 @@ form, allowing a simple variable representation to be
|
||||||
the pattern matching, returning a boolean and a dictionary of variable
|
the pattern matching, returning a boolean and a dictionary of variable
|
||||||
name to value mappings. (See file \file{example.py}.)
|
name to value mappings. (See file \file{example.py}.)
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
from types import ListType, TupleType
|
from types import ListType, TupleType
|
||||||
|
|
||||||
def match(pattern, data, vars=None):
|
def match(pattern, data, vars=None):
|
||||||
|
@ -462,13 +462,13 @@ def match(pattern, data, vars=None):
|
||||||
if not same:
|
if not same:
|
||||||
break
|
break
|
||||||
return same, vars
|
return same, vars
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Using this simple representation for syntactic variables and the symbolic
|
Using this simple representation for syntactic variables and the symbolic
|
||||||
node types, the pattern for the candidate docstring subtrees becomes
|
node types, the pattern for the candidate docstring subtrees becomes
|
||||||
fairly readable. (See file \file{example.py}.)
|
fairly readable. (See file \file{example.py}.)
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import symbol
|
import symbol
|
||||||
import token
|
import token
|
||||||
|
|
||||||
|
@ -495,18 +495,18 @@ DOCSTRING_STMT_PATTERN = (
|
||||||
)))))))))))))))),
|
)))))))))))))))),
|
||||||
(token.NEWLINE, '')
|
(token.NEWLINE, '')
|
||||||
))
|
))
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Using the \function{match()} function with this pattern, extracting the
|
Using the \function{match()} function with this pattern, extracting the
|
||||||
module docstring from the parse tree created previously is easy:
|
module docstring from the parse tree created previously is easy:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
|
>>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
|
||||||
>>> found
|
>>> found
|
||||||
1
|
1
|
||||||
>>> vars
|
>>> vars
|
||||||
{'docstring': '"""Some documentation.\012"""'}
|
{'docstring': '"""Some documentation.\012"""'}
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Once specific data can be extracted from a location where it is
|
Once specific data can be extracted from a location where it is
|
||||||
expected, the question of where information can be expected
|
expected, the question of where information can be expected
|
||||||
|
@ -569,7 +569,7 @@ grammar, but the method which recursively creates new information
|
||||||
objects requires further examination. Here is the relevant part of
|
objects requires further examination. Here is the relevant part of
|
||||||
the \class{SuiteInfoBase} definition from \file{example.py}:
|
the \class{SuiteInfoBase} definition from \file{example.py}:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
class SuiteInfoBase:
|
class SuiteInfoBase:
|
||||||
_docstring = ''
|
_docstring = ''
|
||||||
_name = ''
|
_name = ''
|
||||||
|
@ -599,7 +599,7 @@ class SuiteInfoBase:
|
||||||
elif cstmt[0] == symbol.classdef:
|
elif cstmt[0] == symbol.classdef:
|
||||||
name = cstmt[2][1]
|
name = cstmt[2][1]
|
||||||
self._class_info[name] = ClassInfo(cstmt)
|
self._class_info[name] = ClassInfo(cstmt)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
After initializing some internal state, the constructor calls the
|
After initializing some internal state, the constructor calls the
|
||||||
\method{_extract_info()} method. This method performs the bulk of the
|
\method{_extract_info()} method. This method performs the bulk of the
|
||||||
|
@ -620,13 +620,13 @@ def square(x): "Square an argument."; return x ** 2
|
||||||
while the long form uses an indented block and allows nested
|
while the long form uses an indented block and allows nested
|
||||||
definitions:
|
definitions:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def make_power(exp):
|
def make_power(exp):
|
||||||
"Make a function that raises an argument to the exponent `exp'."
|
"Make a function that raises an argument to the exponent `exp'."
|
||||||
def raiser(x, y=exp):
|
def raiser(x, y=exp):
|
||||||
return x ** y
|
return x ** y
|
||||||
return raiser
|
return raiser
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
When the short form is used, the code block may contain a docstring as
|
When the short form is used, the code block may contain a docstring as
|
||||||
the first, and possibly only, \constant{small_stmt} element. The
|
the first, and possibly only, \constant{small_stmt} element. The
|
||||||
|
@ -662,7 +662,7 @@ the real extraction algorithm remains common to all forms of code
|
||||||
blocks. A high-level function can be used to extract the complete set
|
blocks. A high-level function can be used to extract the complete set
|
||||||
of information from a source file. (See file \file{example.py}.)
|
of information from a source file. (See file \file{example.py}.)
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def get_docs(fileName):
|
def get_docs(fileName):
|
||||||
source = open(fileName).read()
|
source = open(fileName).read()
|
||||||
import os
|
import os
|
||||||
|
@ -671,7 +671,7 @@ def get_docs(fileName):
|
||||||
ast = parser.suite(source)
|
ast = parser.suite(source)
|
||||||
tup = parser.ast2tuple(ast)
|
tup = parser.ast2tuple(ast)
|
||||||
return ModuleInfo(tup, basename)
|
return ModuleInfo(tup, basename)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This provides an easy-to-use interface to the documentation of a
|
This provides an easy-to-use interface to the documentation of a
|
||||||
module. If information is required which is not extracted by the code
|
module. If information is required which is not extracted by the code
|
||||||
|
@ -703,7 +703,7 @@ to may change between Python versions.
|
||||||
|
|
||||||
This module also provides one additional data object:
|
This module also provides one additional data object:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module symbol)}
|
\setindexsubitem{(in module symbol)}
|
||||||
|
|
||||||
|
|
||||||
\begin{datadesc}{sym_name}
|
\begin{datadesc}{sym_name}
|
||||||
|
@ -731,7 +731,7 @@ versions.
|
||||||
This module also provides one data object and some functions. The
|
This module also provides one data object and some functions. The
|
||||||
functions mirror definitions in the Python C header files.
|
functions mirror definitions in the Python C header files.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module token)}
|
\setindexsubitem{(in module token)}
|
||||||
|
|
||||||
|
|
||||||
\begin{datadesc}{tok_name}
|
\begin{datadesc}{tok_name}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\stmodindex{pdb}
|
\stmodindex{pdb}
|
||||||
\index{debugging}
|
\index{debugging}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module pdb)}
|
\setindexsubitem{(in module pdb)}
|
||||||
|
|
||||||
The module \code{pdb} defines an interactive source code debugger for
|
The module \code{pdb} defines an interactive source code debugger for
|
||||||
Python programs. It supports setting
|
Python programs. It supports setting
|
||||||
|
@ -29,7 +29,7 @@ specific modules).
|
||||||
The debugger's prompt is ``\code{(Pdb) }''.
|
The debugger's prompt is ``\code{(Pdb) }''.
|
||||||
Typical usage to run a program under control of the debugger is:
|
Typical usage to run a program under control of the debugger is:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import pdb
|
>>> import pdb
|
||||||
>>> import mymodule
|
>>> import mymodule
|
||||||
>>> pdb.run('mymodule.test()')
|
>>> pdb.run('mymodule.test()')
|
||||||
|
@ -40,7 +40,7 @@ Typical usage to run a program under control of the debugger is:
|
||||||
NameError: 'spam'
|
NameError: 'spam'
|
||||||
> <string>(1)?()
|
> <string>(1)?()
|
||||||
(Pdb)
|
(Pdb)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\code{pdb.py} can also be invoked as
|
\code{pdb.py} can also be invoked as
|
||||||
a script to debug other scripts. For example:
|
a script to debug other scripts. For example:
|
||||||
|
@ -48,7 +48,7 @@ a script to debug other scripts. For example:
|
||||||
|
|
||||||
Typical usage to inspect a crashed program is:
|
Typical usage to inspect a crashed program is:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import pdb
|
>>> import pdb
|
||||||
>>> import mymodule
|
>>> import mymodule
|
||||||
>>> mymodule.test()
|
>>> mymodule.test()
|
||||||
|
@ -63,7 +63,7 @@ NameError: spam
|
||||||
> ./mymodule.py(3)test2()
|
> ./mymodule.py(3)test2()
|
||||||
-> print spam
|
-> print spam
|
||||||
(Pdb)
|
(Pdb)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The module defines the following functions; each enters the debugger
|
The module defines the following functions; each enters the debugger
|
||||||
in a slightly different way:
|
in a slightly different way:
|
||||||
|
@ -224,10 +224,10 @@ The exclamation point can be omitted unless the first word
|
||||||
of the statement resembles a debugger command.
|
of the statement resembles a debugger command.
|
||||||
To set a global variable, you can prefix the assignment
|
To set a global variable, you can prefix the assignment
|
||||||
command with a ``\code{global}'' command on the same line, e.g.:
|
command with a ``\code{global}'' command on the same line, e.g.:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
(Pdb) global list_options; list_options = ['-l']
|
(Pdb) global list_options; list_options = ['-l']
|
||||||
(Pdb)
|
(Pdb)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\item[q(uit)]
|
\item[q(uit)]
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
\indexii{flattening}{objects}
|
\indexii{flattening}{objects}
|
||||||
\indexii{pickling}{objects}
|
\indexii{pickling}{objects}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module pickle)}
|
\setindexsubitem{(in module pickle)}
|
||||||
|
|
||||||
The \code{pickle} module implements a basic but powerful algorithm for
|
The \code{pickle} module implements a basic but powerful algorithm for
|
||||||
``pickling'' (a.k.a.\ serializing, marshalling or flattening) nearly
|
``pickling'' (a.k.a.\ serializing, marshalling or flattening) nearly
|
||||||
|
@ -94,7 +94,7 @@ There are some restrictions on the pickling of class instances.
|
||||||
First of all, the class must be defined at the top level in a module.
|
First of all, the class must be defined at the top level in a module.
|
||||||
Furthermore, all its instance variables must be picklable.
|
Furthermore, all its instance variables must be picklable.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(pickle protocol)}
|
\setindexsubitem{(pickle protocol)}
|
||||||
|
|
||||||
When a pickled class instance is unpickled, its \code{__init__()} method
|
When a pickled class instance is unpickled, its \code{__init__()} method
|
||||||
is normally \emph{not} invoked. \strong{Note:} This is a deviation
|
is normally \emph{not} invoked. \strong{Note:} This is a deviation
|
||||||
|
@ -144,35 +144,35 @@ definition is not pickled, but re-imported by the unpickling process.
|
||||||
Therefore, the restriction that the class must be defined at the top
|
Therefore, the restriction that the class must be defined at the top
|
||||||
level in a module applies to pickled classes as well.
|
level in a module applies to pickled classes as well.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module pickle)}
|
\setindexsubitem{(in module pickle)}
|
||||||
|
|
||||||
The interface can be summarized as follows.
|
The interface can be summarized as follows.
|
||||||
|
|
||||||
To pickle an object \code{x} onto a file \code{f}, open for writing:
|
To pickle an object \code{x} onto a file \code{f}, open for writing:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p = pickle.Pickler(f)
|
p = pickle.Pickler(f)
|
||||||
p.dump(x)
|
p.dump(x)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
A shorthand for this is:
|
A shorthand for this is:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
pickle.dump(x, f)
|
pickle.dump(x, f)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
To unpickle an object \code{x} from a file \code{f}, open for reading:
|
To unpickle an object \code{x} from a file \code{f}, open for reading:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
u = pickle.Unpickler(f)
|
u = pickle.Unpickler(f)
|
||||||
x = u.load()
|
x = u.load()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
A shorthand is:
|
A shorthand is:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
x = pickle.load(f)
|
x = pickle.load(f)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The \code{Pickler} class only calls the method \code{f.write()} with a
|
The \code{Pickler} class only calls the method \code{f.write()} with a
|
||||||
string argument. The \code{Unpickler} calls the methods \code{f.read()}
|
string argument. The \code{Unpickler} calls the methods \code{f.read()}
|
||||||
|
|
|
@ -28,7 +28,7 @@ for type errors, while errors reported by the system calls raise
|
||||||
|
|
||||||
Module \code{posix} defines the following data items:
|
Module \code{posix} defines the following data items:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(data in module posix)}
|
\setindexsubitem{(data in module posix)}
|
||||||
\begin{datadesc}{environ}
|
\begin{datadesc}{environ}
|
||||||
A dictionary representing the string environment at the time
|
A dictionary representing the string environment at the time
|
||||||
the interpreter was started.
|
the interpreter was started.
|
||||||
|
@ -50,7 +50,7 @@ a mapping object that behaves almost like a dictionary but invokes
|
||||||
\code{putenv()} automatically called whenever an item is changed.
|
\code{putenv()} automatically called whenever an item is changed.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(exception in module posix)}
|
\setindexsubitem{(exception in module posix)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised when a \POSIX{} function returns a
|
This exception is raised when a \POSIX{} function returns a
|
||||||
\POSIX{}-related error (e.g., not for illegal argument types). Its
|
\POSIX{}-related error (e.g., not for illegal argument types). Its
|
||||||
|
@ -64,7 +64,7 @@ names for the error codes defined by the underlying operating system.
|
||||||
|
|
||||||
It defines the following functions and constants:
|
It defines the following functions and constants:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module posix)}
|
\setindexsubitem{(in module posix)}
|
||||||
\begin{funcdesc}{chdir}{path}
|
\begin{funcdesc}{chdir}{path}
|
||||||
Change the current working directory to \var{path}.
|
Change the current working directory to \var{path}.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
|
@ -21,7 +21,7 @@ the same as a standard file object.
|
||||||
|
|
||||||
The posixfile module defines the following constants:
|
The posixfile module defines the following constants:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module posixfile)}
|
\setindexsubitem{(in module posixfile)}
|
||||||
\begin{datadesc}{SEEK_SET}
|
\begin{datadesc}{SEEK_SET}
|
||||||
offset is calculated from the start of the file
|
offset is calculated from the start of the file
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
@ -36,7 +36,7 @@ offset is calculated from the end of the file
|
||||||
|
|
||||||
The posixfile module defines the following functions:
|
The posixfile module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module posixfile)}
|
\setindexsubitem{(in module posixfile)}
|
||||||
|
|
||||||
\begin{funcdesc}{open}{filename\optional{\, mode\optional{\, bufsize}}}
|
\begin{funcdesc}{open}{filename\optional{\, mode\optional{\, bufsize}}}
|
||||||
Create a new posixfile object with the given filename and mode. The
|
Create a new posixfile object with the given filename and mode. The
|
||||||
|
@ -52,7 +52,7 @@ The posixfile module defines the following functions:
|
||||||
|
|
||||||
The posixfile object defines the following additional methods:
|
The posixfile object defines the following additional methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(posixfile method)}
|
\setindexsubitem{(posixfile method)}
|
||||||
\begin{funcdesc}{lock}{fmt\, \optional{len\optional{\, start\optional{\, whence}}}}
|
\begin{funcdesc}{lock}{fmt\, \optional{len\optional{\, start\optional{\, whence}}}}
|
||||||
Lock the specified section of the file that the file object is
|
Lock the specified section of the file that the file object is
|
||||||
referring to. The format is explained
|
referring to. The format is explained
|
||||||
|
@ -146,7 +146,7 @@ by the same call.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
from posixfile import *
|
from posixfile import *
|
||||||
|
|
||||||
file = open('/tmp/test', 'w')
|
file = open('/tmp/test', 'w')
|
||||||
|
@ -154,4 +154,4 @@ file.lock('w|')
|
||||||
...
|
...
|
||||||
file.lock('u')
|
file.lock('u')
|
||||||
file.close()
|
file.close()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -8,7 +8,7 @@ This module implements some useful functions on \POSIX{} pathnames.
|
||||||
module \code{os} and use \code{os.path}.
|
module \code{os} and use \code{os.path}.
|
||||||
\refstmodindex{os}
|
\refstmodindex{os}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module posixpath)}
|
\setindexsubitem{(in module posixpath)}
|
||||||
|
|
||||||
\begin{funcdesc}{basename}{p}
|
\begin{funcdesc}{basename}{p}
|
||||||
Return the base name of pathname
|
Return the base name of pathname
|
||||||
|
|
|
@ -19,7 +19,7 @@ to adjust the width constraint.
|
||||||
|
|
||||||
The \code{pprint} module defines one class:
|
The \code{pprint} module defines one class:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module pprint)}
|
\setindexsubitem{(in module pprint)}
|
||||||
|
|
||||||
% First the implementation class:
|
% First the implementation class:
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ l/lib/python1.4/test', '/usr/local/lib/python1.4/sunos5', '/usr/local/lib/python
|
||||||
PrettyPrinter instances (returned by \code{PrettyPrinter()} above)
|
PrettyPrinter instances (returned by \code{PrettyPrinter()} above)
|
||||||
have the following methods.
|
have the following methods.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(PrettyPrinter method)}
|
\setindexsubitem{(PrettyPrinter method)}
|
||||||
|
|
||||||
\begin{funcdesc}{pformat}{object}
|
\begin{funcdesc}{pformat}{object}
|
||||||
Return the formatted representation of \var{object}. This takes into
|
Return the formatted representation of \var{object}. This takes into
|
||||||
|
|
|
@ -106,10 +106,10 @@ rapidly perform profiling on an existing application.
|
||||||
To profile an application with a main entry point of \samp{foo()}, you
|
To profile an application with a main entry point of \samp{foo()}, you
|
||||||
would add the following to your module:
|
would add the following to your module:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import profile
|
import profile
|
||||||
profile.run("foo()")
|
profile.run("foo()")
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The above action would cause \samp{foo()} to be run, and a series of
|
The above action would cause \samp{foo()} to be run, and a series of
|
||||||
informative lines (the profile) to be printed. The above approach is
|
informative lines (the profile) to be printed. The above approach is
|
||||||
|
@ -118,10 +118,10 @@ save the results of a profile into a file for later examination, you
|
||||||
can supply a file name as the second argument to the \code{run()}
|
can supply a file name as the second argument to the \code{run()}
|
||||||
function:
|
function:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import profile
|
import profile
|
||||||
profile.run("foo()", 'fooprof')
|
profile.run("foo()", 'fooprof')
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\code{profile.py} can also be invoked as
|
\code{profile.py} can also be invoked as
|
||||||
a script to profile another script. For example:
|
a script to profile another script. For example:
|
||||||
|
@ -131,10 +131,10 @@ When you wish to review the profile, you should use the methods in the
|
||||||
\code{pstats} module. Typically you would load the statistics data as
|
\code{pstats} module. Typically you would load the statistics data as
|
||||||
follows:
|
follows:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import pstats
|
import pstats
|
||||||
p = pstats.Stats('fooprof')
|
p = pstats.Stats('fooprof')
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The class \code{Stats} (the above code just created an instance of
|
The class \code{Stats} (the above code just created an instance of
|
||||||
this class) has a variety of methods for manipulating and printing the
|
this class) has a variety of methods for manipulating and printing the
|
||||||
|
@ -142,9 +142,9 @@ data that was just read into \samp{p}. When you ran
|
||||||
\code{profile.run()} above, what was printed was the result of three
|
\code{profile.run()} above, what was printed was the result of three
|
||||||
method calls:
|
method calls:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.strip_dirs().sort_stats(-1).print_stats()
|
p.strip_dirs().sort_stats(-1).print_stats()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The first method removed the extraneous path from all the module
|
The first method removed the extraneous path from all the module
|
||||||
names. The second method sorted all the entries according to the
|
names. The second method sorted all the entries according to the
|
||||||
|
@ -152,18 +152,18 @@ standard module/line/name string that is printed (this is to comply
|
||||||
with the semantics of the old profiler). The third method printed out
|
with the semantics of the old profiler). The third method printed out
|
||||||
all the statistics. You might try the following sort calls:
|
all the statistics. You might try the following sort calls:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.sort_stats('name')
|
p.sort_stats('name')
|
||||||
p.print_stats()
|
p.print_stats()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The first call will actually sort the list by function name, and the
|
The first call will actually sort the list by function name, and the
|
||||||
second call will print out the statistics. The following are some
|
second call will print out the statistics. The following are some
|
||||||
interesting calls to experiment with:
|
interesting calls to experiment with:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.sort_stats('cumulative').print_stats(10)
|
p.sort_stats('cumulative').print_stats(10)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This sorts the profile by cumulative time in a function, and then only
|
This sorts the profile by cumulative time in a function, and then only
|
||||||
prints the ten most significant lines. If you want to understand what
|
prints the ten most significant lines. If you want to understand what
|
||||||
|
@ -172,26 +172,26 @@ algorithms are taking time, the above line is what you would use.
|
||||||
If you were looking to see what functions were looping a lot, and
|
If you were looking to see what functions were looping a lot, and
|
||||||
taking a lot of time, you would do:
|
taking a lot of time, you would do:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.sort_stats('time').print_stats(10)
|
p.sort_stats('time').print_stats(10)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
to sort according to time spent within each function, and then print
|
to sort according to time spent within each function, and then print
|
||||||
the statistics for the top ten functions.
|
the statistics for the top ten functions.
|
||||||
|
|
||||||
You might also try:
|
You might also try:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.sort_stats('file').print_stats('__init__')
|
p.sort_stats('file').print_stats('__init__')
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This will sort all the statistics by file name, and then print out
|
This will sort all the statistics by file name, and then print out
|
||||||
statistics for only the class init methods ('cause they are spelled
|
statistics for only the class init methods ('cause they are spelled
|
||||||
with \code{__init__} in them). As one final example, you could try:
|
with \code{__init__} in them). As one final example, you could try:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.sort_stats('time', 'cum').print_stats(.5, 'init')
|
p.sort_stats('time', 'cum').print_stats(.5, 'init')
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This line sorts statistics with a primary key of time, and a secondary
|
This line sorts statistics with a primary key of time, and a secondary
|
||||||
key of cumulative time, and then prints out some of the statistics.
|
key of cumulative time, and then prints out some of the statistics.
|
||||||
|
@ -202,19 +202,19 @@ maintained, and that sub-sub-list is printed.
|
||||||
If you wondered what functions called the above functions, you could
|
If you wondered what functions called the above functions, you could
|
||||||
now (\samp{p} is still sorted according to the last criteria) do:
|
now (\samp{p} is still sorted according to the last criteria) do:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.print_callers(.5, 'init')
|
p.print_callers(.5, 'init')
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
and you would get a list of callers for each of the listed functions.
|
and you would get a list of callers for each of the listed functions.
|
||||||
|
|
||||||
If you want more functionality, you're going to have to read the
|
If you want more functionality, you're going to have to read the
|
||||||
manual, or guess what the following functions do:
|
manual, or guess what the following functions do:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
p.print_callees()
|
p.print_callees()
|
||||||
p.add('fooprof')
|
p.add('fooprof')
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\section{What Is Deterministic Profiling?}
|
\section{What Is Deterministic Profiling?}
|
||||||
\nodename{Deterministic Profiling}
|
\nodename{Deterministic Profiling}
|
||||||
|
@ -251,7 +251,7 @@ of algorithms to be directly compared to iterative implementations.
|
||||||
|
|
||||||
\section{Reference Manual}
|
\section{Reference Manual}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(profiler function)}
|
\setindexsubitem{(profiler function)}
|
||||||
|
|
||||||
The primary entry point for the profiler is the global function
|
The primary entry point for the profiler is the global function
|
||||||
\code{profile.run()}. It is typically used to create any profile
|
\code{profile.run()}. It is typically used to create any profile
|
||||||
|
@ -273,7 +273,7 @@ function automatically prints a simple profiling report, sorted by the
|
||||||
standard name string (file/line/function-name) that is presented in
|
standard name string (file/line/function-name) that is presented in
|
||||||
each line. The following is a typical output from such a call:
|
each line. The following is a typical output from such a call:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
main()
|
main()
|
||||||
2706 function calls (2004 primitive calls) in 4.504 CPU seconds
|
2706 function calls (2004 primitive calls) in 4.504 CPU seconds
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ ncalls tottime percall cumtime percall filename:lineno(function)
|
||||||
2 0.006 0.003 0.953 0.477 pobject.py:75(save_objects)
|
2 0.006 0.003 0.953 0.477 pobject.py:75(save_objects)
|
||||||
43/3 0.533 0.012 0.749 0.250 pobject.py:99(evaluate)
|
43/3 0.533 0.012 0.749 0.250 pobject.py:99(evaluate)
|
||||||
...
|
...
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
The first line indicates that this profile was generated by the call:\\
|
The first line indicates that this profile was generated by the call:\\
|
||||||
\code{profile.run('main()')}, and hence the exec'ed string is
|
\code{profile.run('main()')}, and hence the exec'ed string is
|
||||||
|
@ -348,7 +348,7 @@ need to be combined with data in an existing \code{Stats} object, the
|
||||||
|
|
||||||
\subsection{The \sectcode{Stats} Class}
|
\subsection{The \sectcode{Stats} Class}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(Stats method)}
|
\setindexsubitem{(Stats method)}
|
||||||
|
|
||||||
\begin{funcdesc}{strip_dirs}{}
|
\begin{funcdesc}{strip_dirs}{}
|
||||||
This method for the \code{Stats} class removes all leading path information
|
This method for the \code{Stats} class removes all leading path information
|
||||||
|
@ -447,17 +447,17 @@ Python 1.5b1, this uses the Perl-style regular expression syntax
|
||||||
defined by the \code{re} module). If several restrictions are
|
defined by the \code{re} module). If several restrictions are
|
||||||
provided, then they are applied sequentially. For example:
|
provided, then they are applied sequentially. For example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
print_stats(.1, "foo:")
|
print_stats(.1, "foo:")
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
would first limit the printing to first 10\% of list, and then only
|
would first limit the printing to first 10\% of list, and then only
|
||||||
print functions that were part of filename \samp{.*foo:}. In
|
print functions that were part of filename \samp{.*foo:}. In
|
||||||
contrast, the command:
|
contrast, the command:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
print_stats("foo:", .1)
|
print_stats("foo:", .1)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
would limit the list to all functions having file names \samp{.*foo:},
|
would limit the list to all functions having file names \samp{.*foo:},
|
||||||
and then proceed to only print the first 10\% of them.
|
and then proceed to only print the first 10\% of them.
|
||||||
|
@ -487,10 +487,10 @@ returned by earlier methods. All standard methods in this class
|
||||||
return the instance that is being processed, so that the commands can
|
return the instance that is being processed, so that the commands can
|
||||||
be strung together. For example:
|
be strung together. For example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
pstats.Stats('foofile').strip_dirs().sort_stats('cum') \
|
pstats.Stats('foofile').strip_dirs().sort_stats('cum') \
|
||||||
.print_stats().ignore()
|
.print_stats().ignore()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
would perform all the indicated functions, but it would not return
|
would perform all the indicated functions, but it would not return
|
||||||
the final reference to the \code{Stats} instance.%
|
the final reference to the \code{Stats} instance.%
|
||||||
|
@ -551,27 +551,27 @@ function, and socking away the results. The following procedure can
|
||||||
be used to obtain this constant for a given platform (see discussion
|
be used to obtain this constant for a given platform (see discussion
|
||||||
in section Limitations above).
|
in section Limitations above).
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import profile
|
import profile
|
||||||
pr = profile.Profile()
|
pr = profile.Profile()
|
||||||
pr.calibrate(100)
|
pr.calibrate(100)
|
||||||
pr.calibrate(100)
|
pr.calibrate(100)
|
||||||
pr.calibrate(100)
|
pr.calibrate(100)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The argument to calibrate() is the number of times to try to do the
|
The argument to calibrate() is the number of times to try to do the
|
||||||
sample calls to get the CPU times. If your computer is \emph{very}
|
sample calls to get the CPU times. If your computer is \emph{very}
|
||||||
fast, you might have to do:
|
fast, you might have to do:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
pr.calibrate(1000)
|
pr.calibrate(1000)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
or even:
|
or even:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
pr.calibrate(10000)
|
pr.calibrate(10000)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The object of this exercise is to get a fairly consistent result.
|
The object of this exercise is to get a fairly consistent result.
|
||||||
When you have a consistent answer, you are ready to use that number in
|
When you have a consistent answer, you are ready to use that number in
|
||||||
|
@ -584,7 +584,7 @@ The following shows how the trace_dispatch() method in the Profile
|
||||||
class should be modified to install the calibration constant on a Sun
|
class should be modified to install the calibration constant on a Sun
|
||||||
Sparcstation 1000:
|
Sparcstation 1000:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def trace_dispatch(self, frame, event, arg):
|
def trace_dispatch(self, frame, event, arg):
|
||||||
t = self.timer()
|
t = self.timer()
|
||||||
t = t[0] + t[1] - self.t - .00053 # Calibration constant
|
t = t[0] + t[1] - self.t - .00053 # Calibration constant
|
||||||
|
@ -596,14 +596,14 @@ def trace_dispatch(self, frame, event, arg):
|
||||||
r = self.timer()
|
r = self.timer()
|
||||||
self.t = r[0] + r[1] - t # put back unrecorded delta
|
self.t = r[0] + r[1] - t # put back unrecorded delta
|
||||||
return
|
return
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Note that if there is no calibration constant, then the line
|
Note that if there is no calibration constant, then the line
|
||||||
containing the callibration constant should simply say:
|
containing the callibration constant should simply say:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
t = t[0] + t[1] - self.t # no calibration constant
|
t = t[0] + t[1] - self.t # no calibration constant
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
You can also achieve the same results using a derived class (and the
|
You can also achieve the same results using a derived class (and the
|
||||||
profiler will actually run equally fast!!), but the above method is
|
profiler will actually run equally fast!!), but the above method is
|
||||||
|
@ -632,9 +632,9 @@ timer function is used, then the basic class has an option for that in
|
||||||
the constructor for the class. Consider passing the name of a
|
the constructor for the class. Consider passing the name of a
|
||||||
function to call into the constructor:
|
function to call into the constructor:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
pr = profile.Profile(your_time_func)
|
pr = profile.Profile(your_time_func)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The resulting profiler will call \code{your_time_func()} instead of
|
The resulting profiler will call \code{your_time_func()} instead of
|
||||||
\code{os.times()}. The function should return either a single number
|
\code{os.times()}. The function should return either a single number
|
||||||
|
@ -664,7 +664,7 @@ stats, and is quite useful when there is \emph{no} recursion in the
|
||||||
user's code. It is also a lot more accurate than the old profiler, as
|
user's code. It is also a lot more accurate than the old profiler, as
|
||||||
it does not charge all its overhead time to the user's code.
|
it does not charge all its overhead time to the user's code.
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
class OldProfile(Profile):
|
class OldProfile(Profile):
|
||||||
|
|
||||||
def trace_dispatch_exception(self, frame, t):
|
def trace_dispatch_exception(self, frame, t):
|
||||||
|
@ -714,7 +714,7 @@ class OldProfile(Profile):
|
||||||
callers[func_caller]
|
callers[func_caller]
|
||||||
nc = nc + callers[func_caller]
|
nc = nc + callers[func_caller]
|
||||||
self.stats[nor_func] = nc, nc, tt, ct, nor_callers
|
self.stats[nor_func] = nc, nc, tt, ct, nor_callers
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\subsection{HotProfile Class}
|
\subsection{HotProfile Class}
|
||||||
|
|
||||||
|
@ -725,7 +725,7 @@ function, so it runs very quickly (re: very low overhead). In truth,
|
||||||
the basic profiler is so fast, that is probably not worth the savings
|
the basic profiler is so fast, that is probably not worth the savings
|
||||||
to give up the data, but this class still provides a nice example.
|
to give up the data, but this class still provides a nice example.
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
class HotProfile(Profile):
|
class HotProfile(Profile):
|
||||||
|
|
||||||
def trace_dispatch_exception(self, frame, t):
|
def trace_dispatch_exception(self, frame, t):
|
||||||
|
@ -761,4 +761,4 @@ class HotProfile(Profile):
|
||||||
nc, tt = self.timings[func]
|
nc, tt = self.timings[func]
|
||||||
nor_func = self.func_normalize(func)
|
nor_func = self.func_normalize(func)
|
||||||
self.stats[nor_func] = nc, nc, tt, 0, {}
|
self.stats[nor_func] = nc, nc, tt, 0, {}
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -19,7 +19,7 @@ A \code{KeyError} exception is raised if the entry asked for cannot be found.
|
||||||
|
|
||||||
It defines the following items:
|
It defines the following items:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module pwd)}
|
\setindexsubitem{(in module pwd)}
|
||||||
\begin{funcdesc}{getpwuid}{uid}
|
\begin{funcdesc}{getpwuid}{uid}
|
||||||
Return the password database entry for the given numeric user ID.
|
Return the password database entry for the given numeric user ID.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
|
@ -18,7 +18,7 @@ Python.
|
||||||
|
|
||||||
The \code{Queue} module defines the following exception:
|
The \code{Queue} module defines the following exception:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module Queue)}
|
\setindexsubitem{(in module Queue)}
|
||||||
|
|
||||||
\begin{excdesc}{Empty}
|
\begin{excdesc}{Empty}
|
||||||
Exception raised when non-blocking get (e.g. \code{get_nowait()}) is
|
Exception raised when non-blocking get (e.g. \code{get_nowait()}) is
|
||||||
|
@ -35,7 +35,7 @@ other queue organizations (e.g. stack) but the inheritable interface
|
||||||
is not described here. See the source code for details. The public
|
is not described here. See the source code for details. The public
|
||||||
interface methods are:
|
interface methods are:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(__init__ method)}
|
\setindexsubitem{(__init__ method)}
|
||||||
|
|
||||||
\begin{funcdesc}{__init__}{maxsize}
|
\begin{funcdesc}{__init__}{maxsize}
|
||||||
Constructor for the class. \var{maxsize} is an integer that sets the
|
Constructor for the class. \var{maxsize} is an integer that sets the
|
||||||
|
@ -45,41 +45,41 @@ queue items are consumed. If \var{maxsize} is less than or equal to
|
||||||
zero, the queue size is infinite.
|
zero, the queue size is infinite.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(qsize method)}
|
\setindexsubitem{(qsize method)}
|
||||||
|
|
||||||
\begin{funcdesc}{qsize}{}
|
\begin{funcdesc}{qsize}{}
|
||||||
Returns the approximate size of the queue. Because of multithreading
|
Returns the approximate size of the queue. Because of multithreading
|
||||||
semantics, this number is not reliable.
|
semantics, this number is not reliable.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(empty method)}
|
\setindexsubitem{(empty method)}
|
||||||
|
|
||||||
\begin{funcdesc}{empty}{}
|
\begin{funcdesc}{empty}{}
|
||||||
Returns 1 if the queue is empty, 0 otherwise. Because of
|
Returns 1 if the queue is empty, 0 otherwise. Because of
|
||||||
multithreading semantics, this is not reliable.
|
multithreading semantics, this is not reliable.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(full method)}
|
\setindexsubitem{(full method)}
|
||||||
|
|
||||||
\begin{funcdesc}{full}{}
|
\begin{funcdesc}{full}{}
|
||||||
Returns 1 if the queue is full, 0 otherwise. Because of
|
Returns 1 if the queue is full, 0 otherwise. Because of
|
||||||
multithreading semantics, this is not reliable.
|
multithreading semantics, this is not reliable.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(put method)}
|
\setindexsubitem{(put method)}
|
||||||
|
|
||||||
\begin{funcdesc}{put}{item}
|
\begin{funcdesc}{put}{item}
|
||||||
Puts \var{item} into the queue.
|
Puts \var{item} into the queue.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(get method)}
|
\setindexsubitem{(get method)}
|
||||||
|
|
||||||
\begin{funcdesc}{get}{}
|
\begin{funcdesc}{get}{}
|
||||||
Gets and returns an item from the queue, blocking if necessary until
|
Gets and returns an item from the queue, blocking if necessary until
|
||||||
one is available.
|
one is available.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(get_nowait method)}
|
\setindexsubitem{(get_nowait method)}
|
||||||
|
|
||||||
\begin{funcdesc}{get_nowait}{}
|
\begin{funcdesc}{get_nowait}{}
|
||||||
Gets and returns an item from the queue if one is immediately
|
Gets and returns an item from the queue if one is immediately
|
||||||
|
|
|
@ -11,7 +11,7 @@ are many such characters, as when sending a graphics file.
|
||||||
\indexii{quoted printable}{encoding}
|
\indexii{quoted printable}{encoding}
|
||||||
\index{MIME!quoted-printable encoding}
|
\index{MIME!quoted-printable encoding}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module quopri)}
|
\setindexsubitem{(in module quopri)}
|
||||||
|
|
||||||
\begin{funcdesc}{decode}{input\, output}
|
\begin{funcdesc}{decode}{input\, output}
|
||||||
Decode the contents of the \var{input} file and write the resulting
|
Decode the contents of the \var{input} file and write the resulting
|
||||||
|
|
|
@ -8,7 +8,7 @@ given library's implementation. While still supported for
|
||||||
compatibility, the \code{rand} module is now considered obsolete; if
|
compatibility, the \code{rand} module is now considered obsolete; if
|
||||||
possible, use the \code{whrandom} module instead.
|
possible, use the \code{whrandom} module instead.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module rand)}
|
\setindexsubitem{(in module rand)}
|
||||||
|
|
||||||
\begin{funcdesc}{choice}{seq}
|
\begin{funcdesc}{choice}{seq}
|
||||||
Returns a random element from the sequence \var{seq}.
|
Returns a random element from the sequence \var{seq}.
|
||||||
|
|
|
@ -19,7 +19,7 @@ after the corresponding variables in the distribution's equation, as
|
||||||
used in common mathematical practice; most of these equations can be
|
used in common mathematical practice; most of these equations can be
|
||||||
found in any statistics text.
|
found in any statistics text.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module random)}
|
\setindexsubitem{(in module random)}
|
||||||
\begin{funcdesc}{betavariate}{alpha\, beta}
|
\begin{funcdesc}{betavariate}{alpha\, beta}
|
||||||
Beta distribution. Conditions on the parameters are \code{alpha>-1}
|
Beta distribution. Conditions on the parameters are \code{alpha>-1}
|
||||||
and \code{beta>-1}.
|
and \code{beta>-1}.
|
||||||
|
|
|
@ -258,7 +258,7 @@ for the current locale.
|
||||||
|
|
||||||
The module defines the following functions and constants, and an exception:
|
The module defines the following functions and constants, and an exception:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module re)}
|
\setindexsubitem{(in module re)}
|
||||||
|
|
||||||
\begin{funcdesc}{compile}{pattern\optional{\, flags}}
|
\begin{funcdesc}{compile}{pattern\optional{\, flags}}
|
||||||
Compile a regular expression pattern into a regular expression
|
Compile a regular expression pattern into a regular expression
|
||||||
|
@ -313,10 +313,10 @@ leftmost such \code{\#} through the end of the line are ignored.
|
||||||
|
|
||||||
The sequence
|
The sequence
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
prog = re.compile(pat)
|
prog = re.compile(pat)
|
||||||
result = prog.match(str)
|
result = prog.match(str)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
is equivalent to
|
is equivalent to
|
||||||
|
|
||||||
|
@ -365,14 +365,14 @@ expression will be used several times in a single program.
|
||||||
1.5 release, \var{maxsplit} was ignored. This has been fixed in
|
1.5 release, \var{maxsplit} was ignored. This has been fixed in
|
||||||
later releases.)
|
later releases.)
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> re.split('[\W]+', 'Words, words, words.')
|
>>> re.split('[\W]+', 'Words, words, words.')
|
||||||
['Words', 'words', 'words', '']
|
['Words', 'words', 'words', '']
|
||||||
>>> re.split('([\W]+)', 'Words, words, words.')
|
>>> re.split('([\W]+)', 'Words, words, words.')
|
||||||
['Words', ', ', 'words', ', ', 'words', '.', '']
|
['Words', ', ', 'words', ', ', 'words', '.', '']
|
||||||
>>> re.split('[\W]+', 'Words, words, words.', 1)
|
>>> re.split('[\W]+', 'Words, words, words.', 1)
|
||||||
['Words', 'words, words.']
|
['Words', 'words, words.']
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
This function combines and extends the functionality of
|
This function combines and extends the functionality of
|
||||||
the old \code{regsub.split()} and \code{regsub.splitx()}.
|
the old \code{regsub.split()} and \code{regsub.splitx()}.
|
||||||
|
@ -387,13 +387,13 @@ it is called for every non-overlapping occurance of \var{pattern}.
|
||||||
The function takes a single match object argument, and returns the
|
The function takes a single match object argument, and returns the
|
||||||
replacement string. For example:
|
replacement string. For example:
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> def dashrepl(matchobj):
|
>>> def dashrepl(matchobj):
|
||||||
... if matchobj.group(0) == '-': return ' '
|
... if matchobj.group(0) == '-': return ' '
|
||||||
... else: return '-'
|
... else: return '-'
|
||||||
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
|
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
|
||||||
'pro--gram files'
|
'pro--gram files'
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The pattern may be a string or a
|
The pattern may be a string or a
|
||||||
regex object; if you need to specify
|
regex object; if you need to specify
|
||||||
|
@ -428,7 +428,7 @@ Perform the same operation as \code{sub()}, but return a tuple
|
||||||
Compiled regular expression objects support the following methods and
|
Compiled regular expression objects support the following methods and
|
||||||
attributes:
|
attributes:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(re method)}
|
\setindexsubitem{(re method)}
|
||||||
\begin{funcdesc}{match}{string\optional{\, pos}\optional{\, endpos}}
|
\begin{funcdesc}{match}{string\optional{\, pos}\optional{\, endpos}}
|
||||||
If zero or more characters at the beginning of \var{string} match
|
If zero or more characters at the beginning of \var{string} match
|
||||||
this regular expression, return a corresponding
|
this regular expression, return a corresponding
|
||||||
|
@ -469,7 +469,7 @@ Identical to the \code{sub()} function, using the compiled pattern.
|
||||||
Identical to the \code{subn()} function, using the compiled pattern.
|
Identical to the \code{subn()} function, using the compiled pattern.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(regex attribute)}
|
\setindexsubitem{(regex attribute)}
|
||||||
|
|
||||||
\begin{datadesc}{flags}
|
\begin{datadesc}{flags}
|
||||||
The flags argument used when the regex object was compiled, or 0 if no
|
The flags argument used when the regex object was compiled, or 0 if no
|
||||||
|
|
|
@ -186,7 +186,7 @@ the string.
|
||||||
|
|
||||||
The module defines these functions, and an exception:
|
The module defines these functions, and an exception:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module regex)}
|
\setindexsubitem{(in module regex)}
|
||||||
|
|
||||||
\begin{funcdesc}{match}{pattern\, string}
|
\begin{funcdesc}{match}{pattern\, string}
|
||||||
Return how many characters at the beginning of \var{string} match
|
Return how many characters at the beginning of \var{string} match
|
||||||
|
@ -215,16 +215,16 @@ The module defines these functions, and an exception:
|
||||||
|
|
||||||
The sequence
|
The sequence
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
prog = regex.compile(pat)
|
prog = regex.compile(pat)
|
||||||
result = prog.match(str)
|
result = prog.match(str)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
is equivalent to
|
is equivalent to
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
result = regex.match(pat, str)
|
result = regex.match(pat, str)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
but the version using \code{compile()} is more efficient when multiple
|
but the version using \code{compile()} is more efficient when multiple
|
||||||
regular expressions are used concurrently in a single program. (The
|
regular expressions are used concurrently in a single program. (The
|
||||||
|
@ -274,7 +274,7 @@ equivalents.
|
||||||
\noindent
|
\noindent
|
||||||
Compiled regular expression objects support these methods:
|
Compiled regular expression objects support these methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(regex method)}
|
\setindexsubitem{(regex method)}
|
||||||
\begin{funcdesc}{match}{string\optional{\, pos}}
|
\begin{funcdesc}{match}{string\optional{\, pos}}
|
||||||
Return how many characters at the beginning of \var{string} match
|
Return how many characters at the beginning of \var{string} match
|
||||||
the compiled regular expression. Return \code{-1} if the string
|
the compiled regular expression. Return \code{-1} if the string
|
||||||
|
@ -319,7 +319,7 @@ identifying groups by their group name.
|
||||||
\noindent
|
\noindent
|
||||||
Compiled regular expressions support these data attributes:
|
Compiled regular expressions support these data attributes:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(regex attribute)}
|
\setindexsubitem{(regex attribute)}
|
||||||
|
|
||||||
\begin{datadesc}{regs}
|
\begin{datadesc}{regs}
|
||||||
When the last call to the \code{match()} or \code{search()} method found a
|
When the last call to the \code{match()} or \code{search()} method found a
|
||||||
|
|
|
@ -18,7 +18,7 @@ expressions to \module{re} style regular expressions. (For more
|
||||||
conversion help, see the URL
|
conversion help, see the URL
|
||||||
\url{http://starship.skyport.net/crew/amk/regex/regex-to-re.html}.)
|
\url{http://starship.skyport.net/crew/amk/regex/regex-to-re.html}.)
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module regsub)}
|
\setindexsubitem{(in module regsub)}
|
||||||
|
|
||||||
\begin{funcdesc}{sub}{pat\, repl\, str}
|
\begin{funcdesc}{sub}{pat\, repl\, str}
|
||||||
Replace the first occurrence of pattern \var{pat} in string
|
Replace the first occurrence of pattern \var{pat} in string
|
||||||
|
|
|
@ -11,7 +11,7 @@ children.
|
||||||
|
|
||||||
A single exception is defined for errors:
|
A single exception is defined for errors:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module resource)}
|
\setindexsubitem{(in module resource)}
|
||||||
|
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
The functions described below may raise this error if the underlying
|
The functions described below may raise this error if the underlying
|
||||||
|
|
|
@ -1,60 +1,60 @@
|
||||||
\section{Standard Module \sectcode{rexec}}
|
\section{Standard Module \sectcode{rexec}}
|
||||||
\label{module-rexec}
|
\label{module-rexec}
|
||||||
\stmodindex{rexec}
|
\stmodindex{rexec}
|
||||||
\renewcommand{\indexsubitem}{(in module rexec)}
|
\setindexsubitem{(in module rexec)}
|
||||||
|
|
||||||
This module contains the \code{RExec} class, which supports
|
This module contains the \class{RExec} class, which supports
|
||||||
\code{r_exec()}, \code{r_eval()}, \code{r_execfile()}, and
|
\code{r_exec()}, \code{r_eval()}, \code{r_execfile()}, and
|
||||||
\code{r_import()} methods, which are restricted versions of the standard
|
\code{r_import()} methods, which are restricted versions of the standard
|
||||||
Python functions \code{exec()}, \code{eval()}, \code{execfile()}, and
|
Python functions \code{exec()}, \code{eval()}, \code{execfile()}, and
|
||||||
the \code{import} statement.
|
the \code{import} statement.
|
||||||
Code executed in this restricted environment will
|
Code executed in this restricted environment will
|
||||||
only have access to modules and functions that are deemed safe; you
|
only have access to modules and functions that are deemed safe; you
|
||||||
can subclass \code{RExec} to add or remove capabilities as desired.
|
can subclass \class{RExec} to add or remove capabilities as desired.
|
||||||
|
|
||||||
\emph{Note:} The \code{RExec} class can prevent code from performing
|
\emph{Note:} The \class{RExec} class can prevent code from performing
|
||||||
unsafe operations like reading or writing disk files, or using TCP/IP
|
unsafe operations like reading or writing disk files, or using TCP/IP
|
||||||
sockets. However, it does not protect against code using extremely
|
sockets. However, it does not protect against code using extremely
|
||||||
large amounts of memory or CPU time.
|
large amounts of memory or CPU time.
|
||||||
|
|
||||||
\begin{funcdesc}{RExec}{\optional{hooks\optional{\, verbose}}}
|
\begin{funcdesc}{RExec}{\optional{hooks\optional{\, verbose}}}
|
||||||
Returns an instance of the \code{RExec} class.
|
Returns an instance of the \class{RExec} class.
|
||||||
|
|
||||||
\var{hooks} is an instance of the \code{RHooks} class or a subclass of it.
|
\var{hooks} is an instance of the \code{RHooks} class or a subclass of it.
|
||||||
If it is omitted or \code{None}, the default \code{RHooks} class is
|
If it is omitted or \code{None}, the default \code{RHooks} class is
|
||||||
instantiated.
|
instantiated.
|
||||||
Whenever the RExec module searches for a module (even a built-in one)
|
Whenever the \module{RExec} module searches for a module (even a
|
||||||
or reads a module's code, it doesn't actually go out to the file
|
built-in one) or reads a module's code, it doesn't actually go out to
|
||||||
system itself. Rather, it calls methods of an RHooks instance that
|
the file system itself. Rather, it calls methods of an \class{RHooks}
|
||||||
was passed to or created by its constructor. (Actually, the RExec
|
instance that was passed to or created by its constructor. (Actually,
|
||||||
object doesn't make these calls---they are made by a module loader
|
the \class{RExec} object doesn't make these calls --- they are made by
|
||||||
object that's part of the RExec object. This allows another level of
|
a module loader object that's part of the \class{RExec} object. This
|
||||||
flexibility, e.g. using packages.)
|
allows another level of flexibility, e.g. using packages.)
|
||||||
|
|
||||||
By providing an alternate RHooks object, we can control the
|
By providing an alternate \class{RHooks} object, we can control the
|
||||||
file system accesses made to import a module, without changing the
|
file system accesses made to import a module, without changing the
|
||||||
actual algorithm that controls the order in which those accesses are
|
actual algorithm that controls the order in which those accesses are
|
||||||
made. For instance, we could substitute an RHooks object that passes
|
made. For instance, we could substitute an \class{RHooks} object that
|
||||||
all filesystem requests to a file server elsewhere, via some RPC
|
passes all filesystem requests to a file server elsewhere, via some
|
||||||
mechanism such as ILU. Grail's applet loader uses this to support
|
RPC mechanism such as ILU. Grail's applet loader uses this to support
|
||||||
importing applets from a URL for a directory.
|
importing applets from a URL for a directory.
|
||||||
|
|
||||||
If \var{verbose} is true, additional debugging output may be sent to
|
If \var{verbose} is true, additional debugging output may be sent to
|
||||||
standard output.
|
standard output.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
The RExec class has the following class attributes, which are used by the
|
The \class{RExec} class has the following class attributes, which are
|
||||||
\code{__init__} method. Changing them on an existing instance won't
|
used by the \code{__init__()} method. Changing them on an existing
|
||||||
have any effect; instead, create a subclass of \code{RExec} and assign
|
instance won't have any effect; instead, create a subclass of
|
||||||
them new values in the class definition. Instances of the new class
|
\class{RExec} and assign them new values in the class definition.
|
||||||
will then use those new values. All these attributes are tuples of
|
Instances of the new class will then use those new values. All these
|
||||||
strings.
|
attributes are tuples of strings.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(RExec object attribute)}
|
\setindexsubitem{(RExec object attribute)}
|
||||||
\begin{datadesc}{nok_builtin_names}
|
\begin{datadesc}{nok_builtin_names}
|
||||||
Contains the names of built-in functions which will \emph{not} be
|
Contains the names of built-in functions which will \emph{not} be
|
||||||
available to programs running in the restricted environment. The
|
available to programs running in the restricted environment. The
|
||||||
value for \code{RExec} is \code{('open',} \code{'reload',}
|
value for \class{RExec} is \code{('open',} \code{'reload',}
|
||||||
\code{'__import__')}. (This gives the exceptions, because by far the
|
\code{'__import__')}. (This gives the exceptions, because by far the
|
||||||
majority of built-in functions are harmless. A subclass that wants to
|
majority of built-in functions are harmless. A subclass that wants to
|
||||||
override this variable should probably start with the value from the
|
override this variable should probably start with the value from the
|
||||||
|
@ -65,7 +65,7 @@ added to this module.)
|
||||||
|
|
||||||
\begin{datadesc}{ok_builtin_modules}
|
\begin{datadesc}{ok_builtin_modules}
|
||||||
Contains the names of built-in modules which can be safely imported.
|
Contains the names of built-in modules which can be safely imported.
|
||||||
The value for \code{RExec} is \code{('audioop',} \code{'array',}
|
The value for \class{RExec} is \code{('audioop',} \code{'array',}
|
||||||
\code{'binascii',} \code{'cmath',} \code{'errno',} \code{'imageop',}
|
\code{'binascii',} \code{'cmath',} \code{'errno',} \code{'imageop',}
|
||||||
\code{'marshal',} \code{'math',} \code{'md5',} \code{'operator',}
|
\code{'marshal',} \code{'math',} \code{'md5',} \code{'operator',}
|
||||||
\code{'parser',} \code{'regex',} \code{'rotor',} \code{'select',}
|
\code{'parser',} \code{'regex',} \code{'rotor',} \code{'select',}
|
||||||
|
@ -77,7 +77,7 @@ class as a starting point.
|
||||||
\begin{datadesc}{ok_path}
|
\begin{datadesc}{ok_path}
|
||||||
Contains the directories which will be searched when an \code{import}
|
Contains the directories which will be searched when an \code{import}
|
||||||
is performed in the restricted environment.
|
is performed in the restricted environment.
|
||||||
The value for \code{RExec} is the same as \code{sys.path} (at the time
|
The value for \class{RExec} is the same as \code{sys.path} (at the time
|
||||||
the module is loaded) for unrestricted code.
|
the module is loaded) for unrestricted code.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ the module is loaded) for unrestricted code.
|
||||||
% Should this be called ok_os_names?
|
% Should this be called ok_os_names?
|
||||||
Contains the names of the functions in the \code{os} module which will be
|
Contains the names of the functions in the \code{os} module which will be
|
||||||
available to programs running in the restricted environment. The
|
available to programs running in the restricted environment. The
|
||||||
value for \code{RExec} is \code{('error',} \code{'fstat',}
|
value for \class{RExec} is \code{('error',} \code{'fstat',}
|
||||||
\code{'listdir',} \code{'lstat',} \code{'readlink',} \code{'stat',}
|
\code{'listdir',} \code{'lstat',} \code{'readlink',} \code{'stat',}
|
||||||
\code{'times',} \code{'uname',} \code{'getpid',} \code{'getppid',}
|
\code{'times',} \code{'uname',} \code{'getpid',} \code{'getppid',}
|
||||||
\code{'getcwd',} \code{'getuid',} \code{'getgid',} \code{'geteuid',}
|
\code{'getcwd',} \code{'getuid',} \code{'getgid',} \code{'geteuid',}
|
||||||
|
@ -95,13 +95,13 @@ value for \code{RExec} is \code{('error',} \code{'fstat',}
|
||||||
\begin{datadesc}{ok_sys_names}
|
\begin{datadesc}{ok_sys_names}
|
||||||
Contains the names of the functions and variables in the \code{sys}
|
Contains the names of the functions and variables in the \code{sys}
|
||||||
module which will be available to programs running in the restricted
|
module which will be available to programs running in the restricted
|
||||||
environment. The value for \code{RExec} is \code{('ps1',}
|
environment. The value for \class{RExec} is \code{('ps1',}
|
||||||
\code{'ps2',} \code{'copyright',} \code{'version',} \code{'platform',}
|
\code{'ps2',} \code{'copyright',} \code{'version',} \code{'platform',}
|
||||||
\code{'exit',} \code{'maxint')}.
|
\code{'exit',} \code{'maxint')}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
RExec instances support the following methods:
|
\class{RExec} instances support the following methods:
|
||||||
\renewcommand{\indexsubitem}{(RExec object method)}
|
\setindexsubitem{(RExec object method)}
|
||||||
|
|
||||||
\begin{funcdesc}{r_eval}{code}
|
\begin{funcdesc}{r_eval}{code}
|
||||||
\var{code} must either be a string containing a Python expression, or
|
\var{code} must either be a string containing a Python expression, or
|
||||||
|
@ -141,7 +141,7 @@ Execute the Python code contained in the file \var{filename} in the
|
||||||
restricted environment.
|
restricted environment.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\code{RExec} objects must also support various methods which will be
|
\class{RExec} objects must also support various methods which will be
|
||||||
implicitly called by code executing in the restricted environment.
|
implicitly called by code executing in the restricted environment.
|
||||||
Overriding these methods in a subclass is used to change the policies
|
Overriding these methods in a subclass is used to change the policies
|
||||||
enforced by a restricted environment.
|
enforced by a restricted environment.
|
||||||
|
@ -155,7 +155,7 @@ exception if the module is considered unsafe.
|
||||||
Method called when \code{open()} is called in the restricted
|
Method called when \code{open()} is called in the restricted
|
||||||
environment. The arguments are identical to those of \code{open()},
|
environment. The arguments are identical to those of \code{open()},
|
||||||
and a file object (or a class instance compatible with file objects)
|
and a file object (or a class instance compatible with file objects)
|
||||||
should be returned. \code{RExec}'s default behaviour is allow opening
|
should be returned. \class{RExec}'s default behaviour is allow opening
|
||||||
any file for reading, but forbidding any attempt to write a file. See
|
any file for reading, but forbidding any attempt to write a file. See
|
||||||
the example below for an implementation of a less restrictive
|
the example below for an implementation of a less restrictive
|
||||||
\code{r_open()}.
|
\code{r_open()}.
|
||||||
|
@ -173,7 +173,7 @@ restricted environment's \code{sys.modules} dictionary).
|
||||||
And their equivalents with access to restricted standard I/O streams:
|
And their equivalents with access to restricted standard I/O streams:
|
||||||
|
|
||||||
\begin{funcdesc}{s_import}{modulename\optional{\, globals, locals, fromlist}}
|
\begin{funcdesc}{s_import}{modulename\optional{\, globals, locals, fromlist}}
|
||||||
Import the module \var{modulename}, raising an \code{ImportError}
|
Import the module \var{modulename}, raising an \exception{ImportError}
|
||||||
exception if the module is considered unsafe.
|
exception if the module is considered unsafe.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
|
@ -189,10 +189,11 @@ Unload the module object \var{module}.
|
||||||
\subsection{An example}
|
\subsection{An example}
|
||||||
|
|
||||||
Let us say that we want a slightly more relaxed policy than the
|
Let us say that we want a slightly more relaxed policy than the
|
||||||
standard RExec class. For example, if we're willing to allow files in
|
standard \class{RExec} class. For example, if we're willing to allow
|
||||||
\file{/tmp} to be written, we can subclass the \code{RExec} class:
|
files in \file{/tmp} to be written, we can subclass the \class{RExec}
|
||||||
|
class:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
class TmpWriterRExec(rexec.RExec):
|
class TmpWriterRExec(rexec.RExec):
|
||||||
def r_open(self, file, mode='r', buf=-1):
|
def r_open(self, file, mode='r', buf=-1):
|
||||||
if mode in ('r', 'rb'):
|
if mode in ('r', 'rb'):
|
||||||
|
@ -206,7 +207,7 @@ class TmpWriterRExec(rexec.RExec):
|
||||||
raise IOError, "'..' in filename forbidden"
|
raise IOError, "'..' in filename forbidden"
|
||||||
else: raise IOError, "Illegal open() mode"
|
else: raise IOError, "Illegal open() mode"
|
||||||
return open(file, mode, buf)
|
return open(file, mode, buf)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Notice that the above code will occasionally forbid a perfectly valid
|
Notice that the above code will occasionally forbid a perfectly valid
|
||||||
filename; for example, code in the restricted environment won't be
|
filename; for example, code in the restricted environment won't be
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-rfc822}
|
\label{module-rfc822}
|
||||||
\stmodindex{rfc822}
|
\stmodindex{rfc822}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module rfc822)}
|
\setindexsubitem{(in module rfc822)}
|
||||||
|
|
||||||
This module defines a class, \code{Message}, which represents a
|
This module defines a class, \code{Message}, which represents a
|
||||||
collection of ``email headers'' as defined by the Internet standard
|
collection of ``email headers'' as defined by the Internet standard
|
||||||
|
|
|
@ -9,7 +9,7 @@ is enough in some cases. Currently, colormap files are not supported.
|
||||||
|
|
||||||
The module defines the following variables and functions:
|
The module defines the following variables and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module rgbimg)}
|
\setindexsubitem{(in module rgbimg)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised on all errors, such as unsupported file type, etc.
|
This exception is raised on all errors, such as unsupported file type, etc.
|
||||||
\end{excdesc}
|
\end{excdesc}
|
||||||
|
|
|
@ -24,7 +24,7 @@ order.
|
||||||
|
|
||||||
The available functions in this module are:
|
The available functions in this module are:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module rotor)}
|
\setindexsubitem{(in module rotor)}
|
||||||
\begin{funcdesc}{newrotor}{key\optional{\, numrotors}}
|
\begin{funcdesc}{newrotor}{key\optional{\, numrotors}}
|
||||||
Return a rotor object. \var{key} is a string containing the encryption key
|
Return a rotor object. \var{key} is a string containing the encryption key
|
||||||
for the object; it can contain arbitrary binary data. The key will be used
|
for the object; it can contain arbitrary binary data. The key will be used
|
||||||
|
@ -35,7 +35,7 @@ if it is omitted, a default value of 6 will be used.
|
||||||
|
|
||||||
Rotor objects have the following methods:
|
Rotor objects have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(rotor method)}
|
\setindexsubitem{(rotor method)}
|
||||||
\begin{funcdesc}{setkey}{key}
|
\begin{funcdesc}{setkey}{key}
|
||||||
Sets the rotor's key to \var{key}.
|
Sets the rotor's key to \var{key}.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
@ -63,7 +63,7 @@ string containing the ciphertext.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
An example usage:
|
An example usage:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import rotor
|
>>> import rotor
|
||||||
>>> rt = rotor.newrotor('key', 12)
|
>>> rt = rotor.newrotor('key', 12)
|
||||||
>>> rt.encrypt('bar')
|
>>> rt.encrypt('bar')
|
||||||
|
@ -79,7 +79,7 @@ An example usage:
|
||||||
>>> rt.decrypt('\357\375$')
|
>>> rt.decrypt('\357\375$')
|
||||||
'l(\315'
|
'l(\315'
|
||||||
>>> del rt
|
>>> del rt
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
The module's code is not an exact simulation of the original Enigma device;
|
The module's code is not an exact simulation of the original Enigma device;
|
||||||
it implements the rotor encryption scheme differently from the original. The
|
it implements the rotor encryption scheme differently from the original. The
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
This module provides access to the function \code{select} available in
|
This module provides access to the function \code{select} available in
|
||||||
most \UNIX{} versions. It defines the following:
|
most \UNIX{} versions. It defines the following:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module select)}
|
\setindexsubitem{(in module select)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
The exception raised when an error occurs. The accompanying value is
|
The exception raised when an error occurs. The accompanying value is
|
||||||
a pair containing the numeric error code from \code{errno} and the
|
a pair containing the numeric error code from \code{errno} and the
|
||||||
|
|
|
@ -36,7 +36,7 @@ spaces, tabs, and newlines are allowed between the trailing
|
||||||
The \code{SGMLParser} class must be instantiated without arguments.
|
The \code{SGMLParser} class must be instantiated without arguments.
|
||||||
It has the following interface methods:
|
It has the following interface methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(SGMLParser method)}
|
\setindexsubitem{(SGMLParser method)}
|
||||||
|
|
||||||
\begin{funcdesc}{reset}{}
|
\begin{funcdesc}{reset}{}
|
||||||
Reset the instance. Loses all unprocessed data. This is called
|
Reset the instance. Loses all unprocessed data. This is called
|
||||||
|
|
|
@ -13,7 +13,7 @@ sub-objects. The keys are ordinary strings.
|
||||||
To summarize the interface (\code{key} is a string, \code{data} is an
|
To summarize the interface (\code{key} is a string, \code{data} is an
|
||||||
arbitrary object):
|
arbitrary object):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import shelve
|
import shelve
|
||||||
|
|
||||||
d = shelve.open(filename) # open, with (g)dbm filename -- no suffix
|
d = shelve.open(filename) # open, with (g)dbm filename -- no suffix
|
||||||
|
@ -28,7 +28,7 @@ flag = d.has_key(key) # true if the key exists
|
||||||
list = d.keys() # a list of all existing keys (slow!)
|
list = d.keys() # a list of all existing keys (slow!)
|
||||||
|
|
||||||
d.close() # close it
|
d.close() # close it
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Restrictions:
|
Restrictions:
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ communication. Use locks instead.
|
||||||
|
|
||||||
The variables defined in the \module{signal} module are:
|
The variables defined in the \module{signal} module are:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module signal)}
|
\setindexsubitem{(in module signal)}
|
||||||
\begin{datadesc}{SIG_DFL}
|
\begin{datadesc}{SIG_DFL}
|
||||||
This is one of two standard signal handling options; it will simply
|
This is one of two standard signal handling options; it will simply
|
||||||
perform the default function for the signal. For example, on most
|
perform the default function for the signal. For example, on most
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
In earlier versions of Python (up to and including 1.5a3), scripts or
|
In earlier versions of Python (up to and including 1.5a3), scripts or
|
||||||
modules that needed to use site-specific modules would place
|
modules that needed to use site-specific modules would place
|
||||||
\code{import site} somewhere near the top of their code. This is no
|
\samp{import site} somewhere near the top of their code. This is no
|
||||||
longer necessary.
|
longer necessary.
|
||||||
|
|
||||||
This will append site-specific paths to to the module search path.
|
This will append site-specific paths to to the module search path.
|
||||||
|
@ -42,29 +42,29 @@ set to \file{/usr/local}. The Python 1.5 library is then installed in
|
||||||
files, \file{foo.pth} and \file{bar.pth}. Assume \file{foo.pth}
|
files, \file{foo.pth} and \file{bar.pth}. Assume \file{foo.pth}
|
||||||
contains the following:
|
contains the following:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
# foo package configuration
|
# foo package configuration
|
||||||
|
|
||||||
foo
|
foo
|
||||||
bar
|
bar
|
||||||
bletch
|
bletch
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
and \file{bar.pth} contains:
|
and \file{bar.pth} contains:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
# bar package configuration
|
# bar package configuration
|
||||||
|
|
||||||
bar
|
bar
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
Then the following directories are added to \code{sys.path}, in this
|
Then the following directories are added to \code{sys.path}, in this
|
||||||
order:
|
order:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
/usr/local/python1.5/site-packages/bar
|
/usr/local/python1.5/site-packages/bar
|
||||||
/usr/local/python1.5/site-packages/foo
|
/usr/local/python1.5/site-packages/foo
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
||||||
Note that \file{bletch} is omitted because it doesn't exist; the
|
Note that \file{bletch} is omitted because it doesn't exist; the
|
||||||
\file{bar} directory precedes the \file{foo} directory because
|
\file{bar} directory precedes the \file{foo} directory because
|
||||||
|
|
|
@ -47,7 +47,7 @@ method.
|
||||||
|
|
||||||
The module \code{socket} exports the following constants and functions:
|
The module \code{socket} exports the following constants and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module socket)}
|
\setindexsubitem{(in module socket)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised for socket- or address-related errors.
|
This exception is raised for socket- or address-related errors.
|
||||||
The accompanying value is either a string telling what went wrong or a
|
The accompanying value is either a string telling what went wrong or a
|
||||||
|
@ -190,7 +190,7 @@ Socket objects have the following methods. Except for
|
||||||
\code{makefile()} these correspond to \UNIX{} system calls applicable to
|
\code{makefile()} these correspond to \UNIX{} system calls applicable to
|
||||||
sockets.
|
sockets.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(socket method)}
|
\setindexsubitem{(socket method)}
|
||||||
\begin{funcdesc}{accept}{}
|
\begin{funcdesc}{accept}{}
|
||||||
Accept a connection.
|
Accept a connection.
|
||||||
The socket must be bound to an address and listening for connections.
|
The socket must be bound to an address and listening for connections.
|
||||||
|
@ -343,7 +343,7 @@ Also note that the server does not \code{send}/\code{receive} on the
|
||||||
socket it is listening on but on the new socket returned by
|
socket it is listening on but on the new socket returned by
|
||||||
\code{accept}.
|
\code{accept}.
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
# Echo server program
|
# Echo server program
|
||||||
from socket import *
|
from socket import *
|
||||||
HOST = '' # Symbolic name meaning the local host
|
HOST = '' # Symbolic name meaning the local host
|
||||||
|
@ -358,9 +358,9 @@ while 1:
|
||||||
if not data: break
|
if not data: break
|
||||||
conn.send(data)
|
conn.send(data)
|
||||||
conn.close()
|
conn.close()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
# Echo client program
|
# Echo client program
|
||||||
from socket import *
|
from socket import *
|
||||||
HOST = 'daring.cwi.nl' # The remote host
|
HOST = 'daring.cwi.nl' # The remote host
|
||||||
|
@ -371,7 +371,7 @@ s.send('Hello, world')
|
||||||
data = s.recv(1024)
|
data = s.recv(1024)
|
||||||
s.close()
|
s.close()
|
||||||
print 'Received', `data`
|
print 'Received', `data`
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\begin{seealso}
|
\begin{seealso}
|
||||||
\seemodule{SocketServer}{classes that simplify writing network servers}
|
\seemodule{SocketServer}{classes that simplify writing network servers}
|
||||||
|
|
|
@ -37,7 +37,7 @@ many requests.
|
||||||
Server classes have the same external methods and attributes, no
|
Server classes have the same external methods and attributes, no
|
||||||
matter what network protocol they use:
|
matter what network protocol they use:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(SocketServer protocol)}
|
\setindexsubitem{(SocketServer protocol)}
|
||||||
|
|
||||||
%XXX should data and methods be intermingled, or separate?
|
%XXX should data and methods be intermingled, or separate?
|
||||||
% how should the distinction between class and instance variables be
|
% how should the distinction between class and instance variables be
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-soundex}
|
\label{module-soundex}
|
||||||
\bimodindex{soundex}
|
\bimodindex{soundex}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module soundex)}
|
\setindexsubitem{(in module soundex)}
|
||||||
The soundex algorithm takes an English word, and returns an
|
The soundex algorithm takes an English word, and returns an
|
||||||
easily-computed hash of it; this hash is intended to be the same for
|
easily-computed hash of it; this hash is intended to be the same for
|
||||||
words that sound alike. This module provides an interface to the
|
words that sound alike. This module provides an interface to the
|
||||||
|
|
|
@ -11,7 +11,7 @@ calls, consult your local man pages.
|
||||||
|
|
||||||
The \code{stat} module defines the following functions:
|
The \code{stat} module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module stat)}
|
\setindexsubitem{(in module stat)}
|
||||||
|
|
||||||
\begin{funcdesc}{S_ISDIR}{mode}
|
\begin{funcdesc}{S_ISDIR}{mode}
|
||||||
Return non-zero if the mode was gotten from a directory.
|
Return non-zero if the mode was gotten from a directory.
|
||||||
|
@ -86,7 +86,7 @@ Time of creation.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import os, sys
|
import os, sys
|
||||||
from stat import *
|
from stat import *
|
||||||
|
|
||||||
|
@ -108,4 +108,4 @@ def f(file):
|
||||||
print 'frobbed', file
|
print 'frobbed', file
|
||||||
|
|
||||||
if __name__ == '__main__': process(sys.argv[1], f)
|
if __name__ == '__main__': process(sys.argv[1], f)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
|
|
|
@ -36,7 +36,7 @@ of STDWIN for C programmers (aforementioned CWI report).
|
||||||
|
|
||||||
The following functions are defined in the \code{stdwin} module:
|
The following functions are defined in the \code{stdwin} module:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module stdwin)}
|
\setindexsubitem{(in module stdwin)}
|
||||||
\begin{funcdesc}{open}{title}
|
\begin{funcdesc}{open}{title}
|
||||||
Open a new window whose initial title is given by the string argument.
|
Open a new window whose initial title is given by the string argument.
|
||||||
Return a window object; window object methods are described below.%
|
Return a window object; window object methods are described below.%
|
||||||
|
@ -118,14 +118,14 @@ Return the pixel value corresponding to the given color name.
|
||||||
Return the default foreground color for unknown color names.
|
Return the default foreground color for unknown color names.
|
||||||
Hint: the following code tests whether you are on a machine that
|
Hint: the following code tests whether you are on a machine that
|
||||||
supports more than two colors:
|
supports more than two colors:
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
if stdwin.fetchcolor('black') <> \
|
if stdwin.fetchcolor('black') <> \
|
||||||
stdwin.fetchcolor('red') <> \
|
stdwin.fetchcolor('red') <> \
|
||||||
stdwin.fetchcolor('white'):
|
stdwin.fetchcolor('white'):
|
||||||
print 'color machine'
|
print 'color machine'
|
||||||
else:
|
else:
|
||||||
print 'monochrome machine'
|
print 'monochrome machine'
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{setfgcolor}{pixel}
|
\begin{funcdesc}{setfgcolor}{pixel}
|
||||||
|
@ -316,7 +316,7 @@ Window objects are created by \code{stdwin.open()}. They are closed
|
||||||
by their \code{close()} method or when they are garbage-collected.
|
by their \code{close()} method or when they are garbage-collected.
|
||||||
Window objects have the following methods:
|
Window objects have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(window method)}
|
\setindexsubitem{(window method)}
|
||||||
|
|
||||||
\begin{funcdesc}{begindrawing}{}
|
\begin{funcdesc}{begindrawing}{}
|
||||||
Return a drawing object, whose methods (described below) allow drawing
|
Return a drawing object, whose methods (described below) allow drawing
|
||||||
|
@ -467,7 +467,7 @@ No drawing object may exist when
|
||||||
is called.
|
is called.
|
||||||
Drawing objects have the following methods:
|
Drawing objects have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(drawing method)}
|
\setindexsubitem{(drawing method)}
|
||||||
|
|
||||||
\begin{funcdesc}{box}{rect}
|
\begin{funcdesc}{box}{rect}
|
||||||
Draw a box just inside a rectangle.
|
Draw a box just inside a rectangle.
|
||||||
|
@ -605,7 +605,7 @@ A menu object represents a menu.
|
||||||
The menu is destroyed when the menu object is deleted.
|
The menu is destroyed when the menu object is deleted.
|
||||||
The following methods are defined:
|
The following methods are defined:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(menu method)}
|
\setindexsubitem{(menu method)}
|
||||||
|
|
||||||
\begin{funcdesc}{additem}{text\, shortcut}
|
\begin{funcdesc}{additem}{text\, shortcut}
|
||||||
Add a menu item with given text.
|
Add a menu item with given text.
|
||||||
|
@ -643,7 +643,7 @@ Bitmaps are currently not available on the Macintosh.
|
||||||
|
|
||||||
The following methods are defined:
|
The following methods are defined:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(bitmap method)}
|
\setindexsubitem{(bitmap method)}
|
||||||
|
|
||||||
\begin{funcdesc}{getsize}{}
|
\begin{funcdesc}{getsize}{}
|
||||||
Return a tuple representing the width and height of the bitmap.
|
Return a tuple representing the width and height of the bitmap.
|
||||||
|
@ -669,7 +669,7 @@ A text-edit object represents a text-edit block.
|
||||||
For semantics, see the STDWIN documentation for C programmers.
|
For semantics, see the STDWIN documentation for C programmers.
|
||||||
The following methods exist:
|
The following methods exist:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(text-edit method)}
|
\setindexsubitem{(text-edit method)}
|
||||||
|
|
||||||
\begin{funcdesc}{arrow}{code}
|
\begin{funcdesc}{arrow}{code}
|
||||||
Pass an arrow event to the text-edit block.
|
Pass an arrow event to the text-edit block.
|
||||||
|
@ -756,7 +756,7 @@ left corner of the window.
|
||||||
The window will be correctly redrawn when covered and re-exposed.
|
The window will be correctly redrawn when covered and re-exposed.
|
||||||
The program quits when the close icon or menu item is requested.
|
The program quits when the close icon or menu item is requested.
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
import stdwin
|
import stdwin
|
||||||
from stdwinevents import *
|
from stdwinevents import *
|
||||||
|
|
||||||
|
@ -773,7 +773,7 @@ def main():
|
||||||
break
|
break
|
||||||
|
|
||||||
main()
|
main()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\section{Standard Module \sectcode{stdwinevents}}
|
\section{Standard Module \sectcode{stdwinevents}}
|
||||||
\stmodindex{stdwinevents}
|
\stmodindex{stdwinevents}
|
||||||
|
@ -784,10 +784,10 @@ and selection types (\code{WS_PRIMARY} etc.).
|
||||||
Read the file for details.
|
Read the file for details.
|
||||||
Suggested usage is
|
Suggested usage is
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> from stdwinevents import *
|
>>> from stdwinevents import *
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\section{Standard Module \sectcode{rect}}
|
\section{Standard Module \sectcode{rect}}
|
||||||
\stmodindex{rect}
|
\stmodindex{rect}
|
||||||
|
@ -798,9 +798,9 @@ A rectangle is defined as in module
|
||||||
a pair of points, where a point is a pair of integers.
|
a pair of points, where a point is a pair of integers.
|
||||||
For example, the rectangle
|
For example, the rectangle
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
(10, 20), (90, 80)
|
(10, 20), (90, 80)
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
is a rectangle whose left, top, right and bottom edges are 10, 20, 90
|
is a rectangle whose left, top, right and bottom edges are 10, 20, 90
|
||||||
and 80, respectively.
|
and 80, respectively.
|
||||||
|
@ -809,7 +809,7 @@ Note that the positive vertical axis points down (as in
|
||||||
|
|
||||||
The module defines the following objects:
|
The module defines the following objects:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module rect)}
|
\setindexsubitem{(in module rect)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
The exception raised by functions in this module when they detect an
|
The exception raised by functions in this module when they detect an
|
||||||
error.
|
error.
|
||||||
|
@ -821,7 +821,7 @@ detail.
|
||||||
The rectangle returned when some operations return an empty result.
|
The rectangle returned when some operations return an empty result.
|
||||||
This makes it possible to quickly check whether a result is empty:
|
This makes it possible to quickly check whether a result is empty:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import rect
|
>>> import rect
|
||||||
>>> r1 = (10, 20), (90, 80)
|
>>> r1 = (10, 20), (90, 80)
|
||||||
>>> r2 = (0, 0), (10, 20)
|
>>> r2 = (0, 0), (10, 20)
|
||||||
|
@ -829,7 +829,7 @@ This makes it possible to quickly check whether a result is empty:
|
||||||
>>> if r3 is rect.empty: print 'Empty intersection'
|
>>> if r3 is rect.empty: print 'Empty intersection'
|
||||||
Empty intersection
|
Empty intersection
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{funcdesc}{is_empty}{r}
|
\begin{funcdesc}{is_empty}{r}
|
||||||
|
|
|
@ -10,7 +10,7 @@ classes and some useful string functions. See the module
|
||||||
|
|
||||||
The constants defined in this module are are:
|
The constants defined in this module are are:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(data in module string)}
|
\setindexsubitem{(data in module string)}
|
||||||
\begin{datadesc}{digits}
|
\begin{datadesc}{digits}
|
||||||
The string \code{'0123456789'}.
|
The string \code{'0123456789'}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
@ -54,7 +54,7 @@ The constants defined in this module are are:
|
||||||
|
|
||||||
The functions defined in this module are:
|
The functions defined in this module are:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module string)}
|
\setindexsubitem{(in module string)}
|
||||||
|
|
||||||
\begin{funcdesc}{atof}{s}
|
\begin{funcdesc}{atof}{s}
|
||||||
Convert a string to a floating point number. The string must have
|
Convert a string to a floating point number. The string must have
|
||||||
|
|
|
@ -13,7 +13,7 @@ See also built-in module \code{array}.
|
||||||
|
|
||||||
The module defines the following exception and functions:
|
The module defines the following exception and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module struct)}
|
\setindexsubitem{(in module struct)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
Exception raised on various occasions; argument is a string
|
Exception raised on various occasions; argument is a string
|
||||||
describing what is wrong.
|
describing what is wrong.
|
||||||
|
@ -120,7 +120,7 @@ byte-swapping); use the appropriate choice of \code{'<'} or
|
||||||
Examples (all using native byte order, size and alignment, on a
|
Examples (all using native byte order, size and alignment, on a
|
||||||
big-endian machine):
|
big-endian machine):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> from struct import *
|
>>> from struct import *
|
||||||
>>> pack('hhl', 1, 2, 3)
|
>>> pack('hhl', 1, 2, 3)
|
||||||
'\000\001\000\002\000\000\000\003'
|
'\000\001\000\002\000\000\000\003'
|
||||||
|
@ -129,7 +129,7 @@ big-endian machine):
|
||||||
>>> calcsize('hhl')
|
>>> calcsize('hhl')
|
||||||
8
|
8
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
Hint: to align the end of a structure to the alignment requirement of
|
Hint: to align the end of a structure to the alignment requirement of
|
||||||
a particular type, end the format with the code for that type with a
|
a particular type, end the format with the code for that type with a
|
||||||
|
|
|
@ -14,7 +14,7 @@ description can be gotten with \samp{man audio}.
|
||||||
|
|
||||||
The module defines the following variables and functions:
|
The module defines the following variables and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module sunaudiodev)}
|
\setindexsubitem{(in module sunaudiodev)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised on all errors. The argument is a string
|
This exception is raised on all errors. The argument is a string
|
||||||
describing what went wrong.
|
describing what went wrong.
|
||||||
|
@ -36,7 +36,7 @@ The audio device objects are returned by \code{open} define the
|
||||||
following methods (except \code{control} objects which only provide
|
following methods (except \code{control} objects which only provide
|
||||||
getinfo, setinfo and drain):
|
getinfo, setinfo and drain):
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(audio device method)}
|
\setindexsubitem{(audio device method)}
|
||||||
|
|
||||||
\begin{funcdesc}{close}{}
|
\begin{funcdesc}{close}{}
|
||||||
This method explicitly closes the device. It is useful in situations
|
This method explicitly closes the device. It is useful in situations
|
||||||
|
|
|
@ -6,7 +6,7 @@ This module provides access to some variables used or maintained by the
|
||||||
interpreter and to functions that interact strongly with the interpreter.
|
interpreter and to functions that interact strongly with the interpreter.
|
||||||
It is always available.
|
It is always available.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module sys)}
|
\setindexsubitem{(in module sys)}
|
||||||
|
|
||||||
\begin{datadesc}{argv}
|
\begin{datadesc}{argv}
|
||||||
The list of command line arguments passed to a Python script.
|
The list of command line arguments passed to a Python script.
|
||||||
|
@ -81,10 +81,10 @@ installed; by default, this is also \code{"/usr/local"}. This can be
|
||||||
set at build time with the \code{--exec-prefix} argument to the
|
set at build time with the \code{--exec-prefix} argument to the
|
||||||
\code{configure} script. Specifically, all configuration files
|
\code{configure} script. Specifically, all configuration files
|
||||||
(e.g. the \code{config.h} header file) are installed in the directory
|
(e.g. the \code{config.h} header file) are installed in the directory
|
||||||
\code{sys.exec_prefix+"/lib/python\emph{VER}/config"}, and shared library
|
\code{sys.exec_prefix+"/lib/python\var{version}/config"}, and shared library
|
||||||
modules are installed in
|
modules are installed in
|
||||||
\code{sys.exec_prefix+"/lib/python\emph{VER}/lib-dynload"},
|
\code{sys.exec_prefix+"/lib/python\var{version}/lib-dynload"},
|
||||||
where \emph{VER} is equal to \code{sys.version[:3]}.
|
where \var{version} is equal to \code{sys.version[:3]}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{funcdesc}{exit}{n}
|
\begin{funcdesc}{exit}{n}
|
||||||
|
@ -162,10 +162,10 @@ independent Python files are installed; by default, this is the string
|
||||||
\code{"/usr/local"}. This can be set at build time with the
|
\code{"/usr/local"}. This can be set at build time with the
|
||||||
\code{--prefix} argument to the \code{configure} script. The main
|
\code{--prefix} argument to the \code{configure} script. The main
|
||||||
collection of Python library modules is installed in the directory
|
collection of Python library modules is installed in the directory
|
||||||
\code{sys.prefix+"/lib/python\emph{VER}"} while the platform
|
\code{sys.prefix+"/lib/python\var{version}"} while the platform
|
||||||
independent header files (all except \code{config.h}) are stored in
|
independent header files (all except \code{config.h}) are stored in
|
||||||
\code{sys.prefix+"/include/python\emph{VER}"},
|
\code{sys.prefix+"/include/python\var{version}"},
|
||||||
where \emph{VER} is equal to \code{sys.version[:3]}.
|
where \var{version} is equal to \code{sys.version[:3]}.
|
||||||
|
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ of the \code{syslog} facility.
|
||||||
|
|
||||||
The module defines the following functions:
|
The module defines the following functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module syslog)}
|
\setindexsubitem{(in module syslog)}
|
||||||
|
|
||||||
\begin{funcdesc}{syslog}{\optional{priority\,} message}
|
\begin{funcdesc}{syslog}{\optional{priority\,} message}
|
||||||
Send the string \var{message} to the system logger.
|
Send the string \var{message} to the system logger.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
\indexii{temporary}{file name}
|
\indexii{temporary}{file name}
|
||||||
\indexii{temporary}{file}
|
\indexii{temporary}{file}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module tempfile)}
|
\setindexsubitem{(in module tempfile)}
|
||||||
|
|
||||||
This module generates temporary file names. It is not \UNIX{} specific,
|
This module generates temporary file names. It is not \UNIX{} specific,
|
||||||
but it may require some help on non-\UNIX{} systems.
|
but it may require some help on non-\UNIX{} systems.
|
||||||
|
|
|
@ -45,7 +45,7 @@ The \code{spam} module defines the following functions:
|
||||||
% Redefine the ``indexsubitem'' macro to point to this module
|
% Redefine the ``indexsubitem'' macro to point to this module
|
||||||
% (alternatively, you can put this at the top of the file):
|
% (alternatively, you can put this at the top of the file):
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module spam)}
|
\setindexsubitem{(in module spam)}
|
||||||
|
|
||||||
% ---- 3.2. ----
|
% ---- 3.2. ----
|
||||||
% For each function, use a ``funcdesc'' block. This has exactly two
|
% For each function, use a ``funcdesc'' block. This has exactly two
|
||||||
|
@ -101,12 +101,12 @@ failure.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> import spam
|
>>> import spam
|
||||||
>>> can = spam.open('/etc/passwd')
|
>>> can = spam.open('/etc/passwd')
|
||||||
>>> can.empty()
|
>>> can.empty()
|
||||||
>>> can.close()
|
>>> can.close()
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
% ==== 5. ====
|
% ==== 5. ====
|
||||||
% If your module defines new object types (for a built-in module) or
|
% If your module defines new object types (for a built-in module) or
|
||||||
|
@ -120,7 +120,7 @@ Example:
|
||||||
Spam objects (returned by \code{open()} above) have the following
|
Spam objects (returned by \code{open()} above) have the following
|
||||||
methods.
|
methods.
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(spam method)}
|
\setindexsubitem{(spam method)}
|
||||||
|
|
||||||
\begin{funcdesc}{empty}{}
|
\begin{funcdesc}{empty}{}
|
||||||
Empty the can into the trash.
|
Empty the can into the trash.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
\indexii{\POSIX{}}{I/O control}
|
\indexii{\POSIX{}}{I/O control}
|
||||||
\indexii{tty}{I/O control}
|
\indexii{tty}{I/O control}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module termios)}
|
\setindexsubitem{(in module termios)}
|
||||||
|
|
||||||
This module provides an interface to the \POSIX{} calls for tty I/O
|
This module provides an interface to the \POSIX{} calls for tty I/O
|
||||||
control. For a complete description of these calls, see the \POSIX{} or
|
control. For a complete description of these calls, see the \POSIX{} or
|
||||||
|
@ -77,7 +77,7 @@ Note the technique using a separate \code{termios.tcgetattr()} call
|
||||||
and a \code{try \ldots{} finally} statement to ensure that the old tty
|
and a \code{try \ldots{} finally} statement to ensure that the old tty
|
||||||
attributes are restored exactly no matter what happens:
|
attributes are restored exactly no matter what happens:
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
def getpass(prompt = "Password: "):
|
def getpass(prompt = "Password: "):
|
||||||
import termios, TERMIOS, sys
|
import termios, TERMIOS, sys
|
||||||
fd = sys.stdin.fileno()
|
fd = sys.stdin.fileno()
|
||||||
|
@ -90,14 +90,14 @@ def getpass(prompt = "Password: "):
|
||||||
finally:
|
finally:
|
||||||
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
|
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
|
||||||
return passwd
|
return passwd
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
%
|
%
|
||||||
\section{Standard Module \sectcode{TERMIOS}}
|
\section{Standard Module \sectcode{TERMIOS}}
|
||||||
\stmodindex{TERMIOS}
|
\stmodindex{TERMIOS}
|
||||||
\indexii{\POSIX{}}{I/O control}
|
\indexii{\POSIX{}}{I/O control}
|
||||||
\indexii{tty}{I/O control}
|
\indexii{tty}{I/O control}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module TERMIOS)}
|
\setindexsubitem{(in module TERMIOS)}
|
||||||
|
|
||||||
This module defines the symbolic constants required to use the
|
This module defines the symbolic constants required to use the
|
||||||
\code{termios} module (see the previous section). See the \POSIX{} or
|
\code{termios} module (see the previous section). See the \POSIX{} or
|
||||||
|
|
|
@ -20,7 +20,7 @@ IRIX, Solaris 2.x, as well as on systems that have a \POSIX{} thread
|
||||||
|
|
||||||
It defines the following constant and functions:
|
It defines the following constant and functions:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module thread)}
|
\setindexsubitem{(in module thread)}
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
Raised on thread-specific errors.
|
Raised on thread-specific errors.
|
||||||
\end{excdesc}
|
\end{excdesc}
|
||||||
|
@ -64,7 +64,7 @@ another thread is created.
|
||||||
|
|
||||||
Lock objects have the following methods:
|
Lock objects have the following methods:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(lock method)}
|
\setindexsubitem{(lock method)}
|
||||||
\begin{funcdesc}{acquire}{\optional{waitflag}}
|
\begin{funcdesc}{acquire}{\optional{waitflag}}
|
||||||
Without the optional argument, this method acquires the lock
|
Without the optional argument, this method acquires the lock
|
||||||
unconditionally, if necessary waiting until it is released by another
|
unconditionally, if necessary waiting until it is released by another
|
||||||
|
|
|
@ -58,7 +58,7 @@ state to be filled in.
|
||||||
|
|
||||||
The module defines the following functions and data items:
|
The module defines the following functions and data items:
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module time)}
|
\setindexsubitem{(in module time)}
|
||||||
|
|
||||||
\begin{datadesc}{altzone}
|
\begin{datadesc}{altzone}
|
||||||
The offset of the local DST timezone, in seconds west of the 0th
|
The offset of the local DST timezone, in seconds west of the 0th
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
\label{module-traceback}
|
\label{module-traceback}
|
||||||
\stmodindex{traceback}
|
\stmodindex{traceback}
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(in module traceback)}
|
\setindexsubitem{(in module traceback)}
|
||||||
|
|
||||||
This module provides a standard interface to format and print stack
|
This module provides a standard interface to format and print stack
|
||||||
traces of Python programs. It exactly mimics the behavior of the
|
traces of Python programs. It exactly mimics the behavior of the
|
||||||
|
|
|
@ -25,7 +25,7 @@ The following values are considered false:
|
||||||
\index{false}
|
\index{false}
|
||||||
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\renewcommand{\indexsubitem}{(Built-in object)}
|
\setindexsubitem{(Built-in object)}
|
||||||
|
|
||||||
\item \code{None}
|
\item \code{None}
|
||||||
\ttindex{None}
|
\ttindex{None}
|
||||||
|
@ -409,13 +409,13 @@ If the right argument is a dictionary (or any kind of mapping), then
|
||||||
the formats in the string must have a parenthesized key into that
|
the formats in the string must have a parenthesized key into that
|
||||||
dictionary inserted immediately after the \code{\%} character, and
|
dictionary inserted immediately after the \code{\%} character, and
|
||||||
each format formats the corresponding entry from the mapping. E.g.
|
each format formats the corresponding entry from the mapping. E.g.
|
||||||
\bcode\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> count = 2
|
>>> count = 2
|
||||||
>>> language = 'Python'
|
>>> language = 'Python'
|
||||||
>>> print '%(language)s has %(count)03d quote types.' % vars()
|
>>> print '%(language)s has %(count)03d quote types.' % vars()
|
||||||
Python has 002 quote types.
|
Python has 002 quote types.
|
||||||
>>>
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}
|
||||||
In this case no * specifiers may occur in a format (since they
|
In this case no * specifiers may occur in a format (since they
|
||||||
require a sequential parameter list).
|
require a sequential parameter list).
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ The following operations are defined on mutable sequence types (where
|
||||||
\indexii{subscript}{assignment}
|
\indexii{subscript}{assignment}
|
||||||
\indexii{slice}{assignment}
|
\indexii{slice}{assignment}
|
||||||
\stindex{del}
|
\stindex{del}
|
||||||
\renewcommand{\indexsubitem}{(list method)}
|
\setindexsubitem{(list method)}
|
||||||
\ttindex{append}
|
\ttindex{append}
|
||||||
\ttindex{count}
|
\ttindex{count}
|
||||||
\ttindex{index}
|
\ttindex{index}
|
||||||
|
@ -538,7 +538,7 @@ mapping, \var{k} is a key and \var{x} is an arbitrary object):
|
||||||
\indexiii{operations on}{dictionary}{type}
|
\indexiii{operations on}{dictionary}{type}
|
||||||
\stindex{del}
|
\stindex{del}
|
||||||
\bifuncindex{len}
|
\bifuncindex{len}
|
||||||
\renewcommand{\indexsubitem}{(dictionary method)}
|
\setindexsubitem{(dictionary method)}
|
||||||
\ttindex{keys}
|
\ttindex{keys}
|
||||||
\ttindex{has_key}
|
\ttindex{has_key}
|
||||||
|
|
||||||
|
@ -681,7 +681,7 @@ device or writing a file opened for reading.
|
||||||
Files have the following methods:
|
Files have the following methods:
|
||||||
|
|
||||||
|
|
||||||
\renewcommand{\indexsubitem}{(file method)}
|
\setindexsubitem{(file method)}
|
||||||
|
|
||||||
\begin{funcdesc}{close}{}
|
\begin{funcdesc}{close}{}
|
||||||
Close the file. A closed file cannot be read or written anymore.
|
Close the file. A closed file cannot be read or written anymore.
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue