17.1.6 Examples

AST_Objects.html | module-parser.html | node464.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 17.1.6 Examples
The parser modules allows operations to be performed on the parse tree
of Python source code before the bytecode is generated, and provides
for inspection of the parse tree for information gathering purposes.
Two examples are presented. The simple example demonstrates emulation
of the compile()built-in function and
the complex example shows the use of a parse tree for information
discovery.


17.1.5 AST Objects

AST_Errors.html | module-parser.html | AST_Examples.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 17.1.5 AST Objects
Ordered and equality comparisons are supported between AST objects.
Pickling of AST objects (using the pickle (module-pickle.html) module) is also
supported.
AST objects have the following methods:


11.22.1 Example basic HTTP client

module-asyncore.html | module-asyncore.html | netdata.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.22.1 Example basic HTTP client
As a basic example, below is a very basic HTTP client that uses the
dispatcher class to implement its socket handling:
```text

class http_client(asyncore.dispatcher):
def __init__(self, host,path):
asyncore.dispatcher.__init__(self)
self.path = path
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect( (host, 80) )
self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % self.path

def handle_connect(self):
pass

def handle_read(self):
data = self.recv(8192)
print data

def writable(self):
return (len(self.buffer) > 0)

def handle_write(self):
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
```


3.5.1 atexit Example

module-atexit.html | module-atexit.html | module-types.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.5.1 atexit Example
The following simple example demonstrates how a module can initialize
a counter from a file when it is imported and save the counter's
updated value automatically when the program terminates without
relying on the application making an explicit call into this module at
termination.


13.12.5 AttributesImpl Objects

input-source-objects.html | module-xml.sax.xmlreader.html | attributes-ns-impl-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.12.5 AttributesImpl Objects
AttributesImpl objects implement a portion of the mapping
protocol, and the methods copy(), get(),
has_key(), items(), keys(), and
values(). The following methods are also provided:


13.12.6 AttributesNSImpl Objects

attributes-impl-objects.html | module-xml.sax.xmlreader.html | module-xmllib.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.12.6 AttributesNSImpl Objects


14.4.1 AU_read Objects

module-sunau.html | module-sunau.html | au-write-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 14.4.1 AU_read Objects
AU_read objects, as returned by open() above, have the
following methods:
The following two methods define a term ``position'' which is compatible
between them, and is otherwise implementation dependent.
The following two functions are defined for compatibility with the
aifc (module-aifc.html), and don't do anything interesting.


14.4.2 AU_write Objects

au-read-objects.html | module-sunau.html | module-wave.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 14.4.2 AU_write Objects
AU_write objects, as returned by open() above, have the
following methods:


21.1.1 Audio Device Objects

module-sunaudiodev.html | module-sunaudiodev.html | module-sunaudiodev-constants.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 21.1.1 Audio Device Objects
The audio device objects are returned by open() define the
following methods (except `control` objects which only provide
getinfo(), setinfo(), fileno(), and
drain()):
The audio device supports asynchronous notification of various events,
through the SIGPOLL signal. Here's an example of how you might enable
this in Python:
```text

def handle_sigpoll(signum, frame):
print 'I got a SIGPOLL update'

import fcntl, signal, STROPTS

signal.signal(signal.SIGPOLL, handle_sigpoll)
fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG)
```


11.5.3 BaseHandler Objects

opener-director-objects.html | module-urllib2.html | http-redirect-handler.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.5.3 BaseHandler Objects
BaseHandler objects provide a couple of methods that are
directly useful, and others that are meant to be used by derived
classes. These are intended for direct use:
The following members and methods should only be used by classes
derived from BaseHandler:


11.20.4 Binary Objects

datetime-objects.html | module-xmlrpclib.html | fault-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.20.4 Binary Objects
This class may initialized from string data (which may include NULs).
It has the following methods, supported mainly for internal use by the
marshalling/unmarshalling code:
It also supports certain of Python's built-in operators through a
_cmp__ method.


12.14.1 Notes

module-binhex.html | module-binhex.html | module-quopri.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.14.1 Notes
There is an alternative, more powerful interface to the coder and
decoder, see the source for details.
If you code or decode textfiles on non-Macintosh platforms they will
still use the Macintosh newline convention (carriage-return as end of
line).


5.8.1 Example

module-bisect.html | module-bisect.html | module-array.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 5.8.1 Example
The bisect() function is generally useful for categorizing
numeric data. This example uses bisect() to look up a
letter grade for an exam total (say) based on a set of ordered numeric
breakpoints: 85 and up is an `A', 75..84 is a `B', etc.


typesnumeric.html | typesnumeric.html | typeiter.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 2.2.4.1 Bit-string Operations on Integer Types
Plain and long integer types support additional operations that make
sense only for bit-strings. Negative numbers are treated as their 2's
complement value (for long integers, this assumes a sufficiently large
number of bits that no overflow occurs during the operation).
The priorities of the binary bit-wise operations are all lower than
the numeric operations and higher than the comparisons; the unary
operation "~" has the same priority as the other unary numeric
operations ("+" and "-").
This table lists the bit-string operations sorted in ascending
priority (operations in the same box have the same priority):
Notes:
(1): Negative shift counts are illegal and cause a
ValueError to be raised.
(2): A left shift by n bits is equivalent to
multiplication by `pow(2, n )` without overflow check.
(3): A right shift by n bits is equivalent to
division by `pow(2, n )` without overflow check.


2.2.9.5 Code Objects

typesmethods.html | typesother.html | bltin-type-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 2.2.9.5 Code Objects
Code objects are used by the implementation to represent
``pseudo-compiled'' executable Python code such as a function body.
They differ from function objects because they don't contain a
reference to their global execution environment. Code objects are
returned by the built-in compile() function and can be
extracted from function objects through their func_code
attribute.
A code object can be executed or evaluated by passing it (instead of a
source string) to the exec statement or the built-in
eval() function.
See the Python Reference Manual (../ref/ref.html) for more
information.


2.2.9.8 The Ellipsis Object

bltin-null-object.html | typesother.html | typesinternal.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 2.2.9.8 The Ellipsis Object
This object is used by extended slice notation (see the
Python Reference Manual (../ref/ref.html)). It supports no
special operations. There is exactly one ellipsis object, named
Ellipsis (a built-in name).
It is written as `Ellipsis`.


2.2.8 File Objects

typesmapping.html | types.html | typesother.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 2.2.8 File Objects
File objectsare implemented using C's `stdio`
package and can be created with the built-in constructor
file()described in section
2.1 (built-in-funcs.html#built-in-funcs), ``Built-in Functions.''2.10 (#foot2691)They are also returned
by some other built-in functions and methods, such as
os.popen() and os.fdopen() and the
makefile() method of socket objects.
When a file operation fails for an I/O-related reason, the exception
IOError is raised. This includes situations where the
operation is not defined for some reason, like seek() on a tty
device or writing a file opened for reading.
Files have the following methods:
Files support the iterator protocol. Each iteration returns the same
result as `file .readline()`, and iteration ends when the
readline() method returns an empty string.
File objects also offer a number of other interesting attributes.
These are not required for file-like objects, but should be
implemented if they make sense for the particular object.


2.2.9.7 The Null Object

bltin-type-objects.html | typesother.html | bltin-ellipsis-object.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 2.2.9.7 The Null Object
This object is returned by functions that don't explicitly return a
value. It supports no special operations. There is exactly one null
object, named `None` (a built-in name).
It is written as `None`.


2.2.9.6 Type Objects

bltin-code-objects.html | typesother.html | bltin-null-object.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 2.2.9.6 Type Objects
Type objects represent the various object types. An object's type is
accessed by the built-in function type(). There are no special
operations on types. The standard module types defines names
for all standard built-in types.
Types are written like this: `<type 'int'>`.


11.20.2 Boolean Objects

server-objects.html | module-xmlrpclib.html | datetime-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.20.2 Boolean Objects
This class may be initialized from any Python value; the instance
returned depends only on its truth value. It supports various Python
operators through __cmp__(), __repr__(),
__int__(), and __nonzero__() methods, all
implemented in the obvious ways.
It also has the following method, supported mainly for internal use by
the unmarshalling code:


2.2.2 Boolean Operations

truth.html | types.html | comparisons.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 2.2.2 Boolean Operations
These are the Boolean operations, ordered by ascending priority:
Notes:
(1): These only evaluate their second argument if needed for their outcome.
(2): "not" has a lower priority than non-Boolean operators, so
`not a == b` is interpreted as `not ( a == b )`, and `a == not b` is a syntax error.


11.1.1 Browser Controller Objects

module-webbrowser.html | module-webbrowser.html | module-cgi.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.1.1 Browser Controller Objects
Browser controllers provide two methods which parallel two of the
module-level convenience functions:


7.12.1 Hash, BTree and Record Objects

module-bsddb.html | module-bsddb.html | module-zlib.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 7.12.1 Hash, BTree and Record Objects
Once instantiated, hash, btree and record objects support the following
methods:
Example:


2.1 Built-in Functions

builtin.html | builtin.html | types.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 2.1 Built-in Functions
The Python interpreter has a number of functions built into it that
are always available. They are listed here in alphabetical order.


intro.html | lib.html | built-in-funcs.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 2. Built-in Functions, Types, and Exceptions
Names for built-in exceptions and functions are found in a separate
symbol table. This table is searched last when the interpreter looks
up the meaning of a name, so local and global
user-defined names can override built-in names. Built-in types are
described together here for easy reference.2.1 (#foot91)
The tables in this chapter document the priorities of operators by
listing them in order of ascending priority (within a table) and
grouping operators that have the same priority in the same box.
Binary operators of the same priority group from left to right.
(Unary operators group from right to left, but there you have no real
choice.) See chapter 5 of the Python
Reference Manual (../ref/ref.html) for the complete picture on operator priorities.
---
#### Footnotes


18.10.1 Python Byte Code Instructions

module-dis.html | module-dis.html | module-distutils.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 18.10.1 Python Byte Code Instructions
The Python compiler currently generates the following byte code
instructions.
Unary Operations take the top of the stack, apply the operation, and
push the result back on the stack.
Binary operations remove the top of the stack (TOS) and the second top-most
stack item (TOS1) from the stack. They perform the operation, and put the
result back on the stack.
In-place operations are like binary operations, in that they remove TOS and
TOS1, and push the result back on the stack, but the operation is done
in-place when TOS1 supports it, and the resulting TOS may be (but does not
have to be) the original TOS1.
The slice opcodes take up to three parameters.
Slice assignment needs even an additional parameter. As any statement,
they put nothing on the stack.
All of the following opcodes expect arguments. An argument is two
bytes, with the more significant byte last.


11.5.17 CacheFTPHandler Objects

ftp-handler-objects.html | module-urllib2.html | gopher-handler.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.5.17 CacheFTPHandler Objects
CacheFTPHandler objects are FTPHandler objects with
the following additional methods:


20.3.2 Parser Objects

player-objects.html | module-cd.html | module-fl.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 20.3.2 Parser Objects
Parser objects (returned by createparser()) have the
following methods:


11.2.1 Introduction

module-cgi.html | module-cgi.html | node295.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.2.1 Introduction
A CGI script is invoked by an HTTP server, usually to process user
input submitted through an HTML `<FORM>` or `<ISINDEX>` element.
Most often, CGI scripts live in the server's special cgi-bin
directory. The HTTP server places all sorts of information about the
request (such as the client's hostname, the requested URL, the query
string, and lots of other goodies) in the script's shell environment,
executes the script, and sends the script's output back to the client.
The script's input is connected to the client too, and sometimes the
form data is read this way; at other times the form data is passed via
the ``query string'' part of the URL. This module is intended
to take care of the different cases and provide a simpler interface to
the Python script. It also provides a number of utilities that help
in debugging scripts, and the latest addition is support for file
uploads from a form (if your browser supports it -- Grail 0.3 and
Netscape 2.0 do).
The output of a CGI script should consist of two sections, separated
by a blank line. The first section contains a number of headers,
telling the client what kind of data is following. Python code to
generate a minimal header section looks like this:
```text

print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
```
The second section is usually HTML, which allows the client software
to display nicely formatted text with header, in-line images, etc.
Here's Python code that prints a simple piece of HTML:
```text

print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>"
print "Hello, world!"
```


11.2.6 Caring about security

node298.html | module-cgi.html | node300.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.2.6 Caring about security
There's one important rule: if you invoke an external program (via the
os.system() or os.popen() functions. or others
with similar functionality), make very sure you don't pass arbitrary
strings received from the client to the shell. This is a well-known
security hole whereby clever hackers anywhere on the Web can exploit a
gullible CGI script to invoke arbitrary shell commands. Even parts of
the URL or field names cannot be trusted, since the request doesn't
have to come from your form!
To be on the safe side, if you must pass a string gotten from a form
to a shell command, you should make sure the string contains only
alphanumeric characters, dashes, underscores, and periods.


5.14.1 Cmd Objects

module-cmd.html | module-cmd.html | module-shlex.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 5.14.1 Cmd Objects
A Cmd instance has the following methods:
Instances of Cmd subclasses have some public instance variables:


4.8.1.1 Codec Objects

node113.html | node113.html | stream-writer-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 4.8.1.1 Codec Objects
The Codec class defines these methods which also define the
function interfaces of the stateless encoder and decoder:
The StreamWriter and StreamReader classes provide
generic working interfaces which can be used to implement new
encodings submodules very easily. See encodings.utf_8 for an
example on how this is done.


2.2.3 Comparisons

boolean.html | types.html | typesnumeric.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 2.2.3 Comparisons
Comparison operations are supported by all objects. They all have the
same priority (which is higher than that of the Boolean operations).
Comparisons can be chained arbitrarily; for example, `x < y <= z` is equivalent to `x < y and y <= z`, except that y is evaluated only once (but
in both cases z is not evaluated at all when `x < y` is found to be false).
This table summarizes the comparison operations:
Notes:
(1): `<>` and `!=` are alternate spellings for the same operator.
(I couldn't choose between ABC and C! :-)
`!=` is the preferred spelling; `<>` is obsolescent.
Objects of different types, except different numeric types, never
compare equal; such objects are ordered consistently but arbitrarily
(so that sorting a heterogeneous array yields a consistent result).
Furthermore, some types (for example, file objects) support only a
degenerate notion of comparison where any two objects of that type are
unequal. Again, such objects are ordered arbitrarily but
consistently.
Instances of a class normally compare as non-equal unless the class
defines the __cmp__() method. Refer to the
Python Reference Manual (../ref/customization.html) for
information on the use of this method to effect object comparisons.
Implementation note: Objects of different types except
numbers are ordered by their type names; objects of the same types
that don't support proper comparison are ordered by their address.
Two more operations with the same syntactic priority,
"in"and "not in", are supported
only by sequence types (below).


19. Python compiler package

module-distutils.html | lib.html | module-compiler.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 19. Python compiler package
The Python compiler package is a tool for analyzing Python source code
and generating Python bytecode. The compiler contains libraries to
generate an abstract syntax tree from Python source code and to
generate Python bytecode from the tree.
The compiler (module-compiler.html) package is a Python source to bytecode
translator written in Python. It uses the built-in parser and
standard parser (module-parser.html) module to generated a concrete syntax
tree. This tree is used to generate an abstract syntax tree (AST) and
then Python bytecode.
The full functionality of the package duplicates the builtin compiler
provided with the Python interpreter. It is intended to match its
behavior almost exactly. Why implement another compiler that does the
same thing? The package is useful for a variety of purposes. It can
be modified more easily than the builtin compiler. The AST it
generates is useful for analyzing Python source code.
This chapter explains how the various components of the
compiler (module-compiler.html) package work. It blends reference material with
a tutorial.
The following modules are part of the compiler (module-compiler.html) package:
compiler (module-compiler.html)
compiler.ast (module-compiler.ast.html)
compiler.visitor (module-compiler.visitor.html)


7.17.1 Completer Objects

module-rlcompleter.html | module-rlcompleter.html | unix.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 7.17.1 Completer Objects
Completer objects have the following method:


7.5.3 Condition Objects

rlock-objects.html | module-threading.html | semaphore-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 7.5.3 Condition Objects
A condition variable is always associated with some kind of lock;
this can be passed in or one will be created by default. (Passing
one in is useful when several condition variables must share the
same lock.)
A condition variable has acquire() and release()
methods that call the corresponding methods of the associated lock.
It also has a wait() method, and notify() and
notifyAll() methods. These three must only be called when
the calling thread has acquired the lock.
The wait() method releases the lock, and then blocks until it
is awakened by a notify() or notifyAll() call for
the same condition variable in another thread. Once awakened, it
re-acquires the lock and returns. It is also possible to specify a
timeout.
The notify() method wakes up one of the threads waiting for
the condition variable, if any are waiting. The notifyAll()
method wakes up all threads waiting for the condition variable.
Note: the notify() and notifyAll() methods don't
release the lock; this means that the thread or threads awakened will
not return from their wait() call immediately, but only when
the thread that called notify() or notifyAll()
finally relinquishes ownership of the lock.
Tip: the typical programming style using condition variables uses the
lock to synchronize access to some shared state; threads that are
interested in a particular change of state call wait()
repeatedly until they see the desired state, while threads that modify
the state call notify() or notifyAll() when they
change the state in such a way that it could possibly be a desired
state for one of the waiters. For example, the following code is a
generic producer-consumer situation with unlimited buffer capacity:
```text

# Consume one item
cv.acquire()
while not an_item_is_available():
cv.wait()
get_an_available_item()
cv.release()

# Produce one item
cv.acquire()
make_an_item_available()
cv.notify()
cv.release()
```
To choose between notify() and notifyAll(), consider
whether one state change can be interesting for only one or several
waiting threads. E.g. in a typical producer-consumer situation,
adding one item to the buffer only needs to wake up one consumer
thread.


5.10.1 ConfigParser Objects

module-ConfigParser.html | module-ConfigParser.html | module-fileinput.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 5.10.1 ConfigParser Objects
ConfigParser instances have the following methods:


3.22.2 Interactive Console Objects

interpreter-objects.html | module-code.html | module-codeop.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.22.2 Interactive Console Objects
The InteractiveConsole class is a subclass of
InteractiveInterpreter, and so offers all the methods of the
interpreter objects as well as the following additions.


13.10.1 ContentHandler Objects

module-xml.sax.handler.html | module-xml.sax.handler.html | dtd-handler-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.10.1 ContentHandler Objects
Users are expected to subclass ContentHandler to support their
application. The following methods are called by the parser on the
appropriate events in the input document:


Contents

front.html | lib.html | intro.html | Python Library Reference | modindex.html | genindex.html
---
## Contents
Table of Contents
- Front Matter (front.html)
  1. Introduction (intro.html)
  2. Built-in Functions, Types, and Exceptions (builtin.html)
  - 2.1 Built-in Functions (built-in-funcs.html)
  2.2 Built-in Types (types.html)
  - 2.2.1 Truth Value Testing (truth.html)
  2.2.2 Boolean Operations (boolean.html)
  2.2.3 Comparisons (comparisons.html)
  2.2.4 Numeric Types (typesnumeric.html)
  2.2.5 Iterator Types (typeiter.html)
  2.2.6 Sequence Types (typesseq.html)
  2.2.7 Mapping Types (typesmapping.html)
  2.2.8 File Objects (bltin-file-objects.html)
  2.2.9 Other Built-in Types (typesother.html)
  2.2.10 Special Attributes (specialattrs.html)
  2.3 Built-in Exceptions (module-exceptions.html)
  3. Python Runtime Services (python.html)
  - 3.1 sys -- System-specific parameters and functions (module-sys.html)
  3.2 gc -- Garbage Collector interface (module-gc.html)
  3.3 weakref -- Weak references (module-weakref.html)
  - 3.3.1 Weak Reference Objects (weakref-objects.html)
  3.3.2 Example (weakref-example.html)
  3.3.3 Weak References in Extension Types (weakref-extension.html)
  3.4 fpectl -- Floating point exception control (module-fpectl.html)
  - 3.4.1 Example (fpectl-example.html)
  3.4.2 Limitations and other considerations (node41.html)
  3.5 atexit -- Exit handlers (module-atexit.html)
  - 3.5.1 atexit Example (atexit-example.html)
  3.6 types -- Names for all built-in types (module-types.html)
  3.7 UserDict -- Class wrapper for dictionary objects (module-UserDict.html)
  3.8 UserList -- Class wrapper for list objects (module-UserList.html)
  3.9 UserString -- Class wrapper for string objects (module-UserString.html)
  3.10 operator -- Standard operators as functions. (module-operator.html)
  - 3.10.1 Mapping Operators to Functions (operator-map.html)
  3.11 inspect -- Inspect live objects (module-inspect.html)
  - 3.11.1 Types and members (inspect-types.html)
  3.11.2 Retrieving source code (inspect-source.html)
  3.11.3 Classes and functions (inspect-classes-functions.html)
  3.11.4 The interpreter stack (inspect-stack.html)
  3.12 traceback -- Print or retrieve a stack traceback (module-traceback.html)
  - 3.12.1 Traceback Example (traceback-example.html)
  3.13 linecache -- Random access to text lines (module-linecache.html)
  3.14 pickle -- Python object serialization (module-pickle.html)
  - 3.14.1 Relationship to other Python modules (node59.html)
  3.14.2 Data stream format (node60.html)
  3.14.3 Usage (node61.html)
  3.14.4 What can be pickled and unpickled? (node62.html)
  3.14.5 The pickle protocol (pickle-protocol.html)
  3.14.6 Security (pickle-sec.html)
  3.14.7 Example (pickle-example.html)
  3.15 cPickle -- A faster pickle (module-cPickle.html)
  3.16 copy_reg -- Register pickle support functions (module-copyreg.html)
  3.17 shelve -- Python object persistence (module-shelve.html)
  3.18 copy -- Shallow and deep copy operations (module-copy.html)
  3.19 marshal -- Internal Python object serialization (module-marshal.html)
  3.20 warnings -- Warning control (module-warnings.html)
  - 3.20.1 Warning Categories (warning-categories.html)
  3.20.2 The Warnings Filter (warning-filter.html)
  3.20.3 Available Functions (warning-functions.html)
  3.21 imp -- Access the import internals (module-imp.html)
  - 3.21.1 Examples (examples-imp.html)
  3.22 code -- Interpreter base classes (module-code.html)
  - 3.22.1 Interactive Interpreter Objects (interpreter-objects.html)
  3.22.2 Interactive Console Objects (console-objects.html)
  3.23 codeop -- Compile Python code (module-codeop.html)
  3.24 pprint -- Data pretty printer (module-pprint.html)
  - 3.24.1 PrettyPrinter Objects (node85.html)
  3.25 repr -- Alternate repr() implementation (module-repr.html)
  - 3.25.1 Repr Objects (Repr-objects.html)
  3.25.2 Subclassing Repr Objects (subclassing-reprs.html)
  3.26 new -- Creation of runtime internal objects (module-new.html)
  3.27 site -- Site-specific configuration hook (module-site.html)
  3.28 user -- User-specific configuration hook (module-user.html)
  3.29 __builtin__ -- Built-in functions (module-builtin.html)
  3.30 __main__ -- Top-level script environment (module-main.html)
  4. String Services (strings.html)
  - 4.1 string -- Common string operations (module-string.html)
  4.2 re -- Regular expression operations (module-re.html)
  - 4.2.1 Regular Expression Syntax (re-syntax.html)
  4.2.2 Matching vs. Searching (matching-searching.html)
  4.2.3 Module Contents (node99.html)
  4.2.4 Regular Expression Objects (re-objects.html)
  4.2.5 Match Objects (match-objects.html)
  4.2.6 Examples (node102.html)
  4.3 struct -- Interpret strings as packed binary data (module-struct.html)
  4.4 difflib -- Helpers for computing deltas (module-difflib.html)
  - 4.4.1 SequenceMatcher Objects (sequence-matcher.html)
  4.4.2 SequenceMatcher Examples (sequencematcher-examples.html)
  4.4.3 Differ Objects (differ-objects.html)
  4.4.4 Differ Example (differ-examples.html)
  4.5 fpformat -- Floating point conversions (module-fpformat.html)
  4.6 StringIO -- Read and write strings as files (module-StringIO.html)
  4.7 cStringIO -- Faster version of StringIO (module-cStringIO.html)
  4.8 codecs -- Codec registry and base classes (module-codecs.html)
  - 4.8.1 Codec Base Classes (node113.html)
  4.9 unicodedata -- Unicode Database (module-unicodedata.html)
  5. Miscellaneous Services (misc.html)
  - 5.1 pydoc -- Documentation generator and online help system (module-pydoc.html)
  5.2 doctest -- Test docstrings represent reality (module-doctest.html)
  - 5.2.1 Normal Usage (node123.html)
  5.2.2 Which Docstrings Are Examined? (node124.html)
  5.2.3 What's the Execution Context? (node125.html)
  5.2.4 What About Exceptions? (node126.html)
  5.2.5 Advanced Usage (node127.html)
  5.2.6 How are Docstring Examples Recognized? (node128.html)
  5.2.7 Warnings (node129.html)
  5.2.8 Soapbox (node130.html)
  5.3 unittest -- Unit testing framework (module-unittest.html)
  - 5.3.1 Organizing test code (organizing-tests.html)
  5.3.2 Re-using old test code (legacy-unit-tests.html)
  5.3.3 Classes and functions (unittest-contents.html)
  5.3.4 TestCase Objects (testcase-objects.html)
  5.3.5 TestSuite Objects (testsuite-objects.html)
  5.3.6 TestResult Objects (testresult-objects.html)
  5.3.7 TestLoader Objects (testloader-objects.html)
  5.4 math -- Mathematical functions (module-math.html)
  5.5 cmath -- Mathematical functions for complex numbers (module-cmath.html)
  5.6 random -- Generate pseudo-random numbers (module-random.html)
  5.7 whrandom -- Pseudo-random number generator (module-whrandom.html)
  5.8 bisect -- Array bisection algorithm (module-bisect.html)
  - 5.8.1 Example (bisect-example.html)
  5.9 array -- Efficient arrays of numeric values (module-array.html)
  5.10 ConfigParser -- Configuration file parser (module-ConfigParser.html)
  - 5.10.1 ConfigParser Objects (ConfigParser-objects.html)
  5.11 fileinput -- Iterate over lines from multiple input streams (module-fileinput.html)
  5.12 xreadlines -- Efficient iteration over a file (module-xreadlines.html)
  5.13 calendar -- General calendar-related functions (module-calendar.html)
  5.14 cmd -- Support for line-oriented command interpreters (module-cmd.html)
  - 5.14.1 Cmd Objects (Cmd-objects.html)
  5.15 shlex -- Simple lexical analysis (module-shlex.html)
  - 5.15.1 shlex Objects (shlex-objects.html)
  6. Generic Operating System Services (allos.html)
  - 6.1 os -- Miscellaneous operating system interfaces (module-os.html)
  - 6.1.1 Process Parameters (os-procinfo.html)
  6.1.2 File Object Creation (os-newstreams.html)
  6.1.3 File Descriptor Operations (os-fd-ops.html)
  6.1.4 Files and Directories (os-file-dir.html)
  6.1.5 Process Management (os-process.html)
  6.1.6 Miscellaneous System Information (os-path.html)
  6.2 os.path -- Common pathname manipulations (module-os.path.html)
  6.3 dircache -- Cached directory listings (module-dircache.html)
  6.4 stat -- Interpreting stat() results (module-stat.html)
  6.5 statcache -- An optimization of os.stat() (module-statcache.html)
  6.6 statvfs -- Constants used with os.statvfs() (module-statvfs.html)
  6.7 filecmp -- File and Directory Comparisons (module-filecmp.html)
  - 6.7.1 The dircmp class (dircmp-objects.html)
  6.8 popen2 -- Subprocesses with accessible I/O streams (module-popen2.html)
  - 6.8.1 Popen3 and Popen4 Objects (popen3-objects.html)
  6.9 time -- Time access and conversions (module-time.html)
  6.10 sched -- Event scheduler (module-sched.html)
  - 6.10.1 Scheduler Objects (scheduler-objects.html)
  6.11 mutex -- Mutual exclusion support (module-mutex.html)
  - 6.11.1 Mutex Objects (mutex-objects.html)
  6.12 getpass -- Portable password input (module-getpass.html)
  6.13 curses -- Terminal handling for character-cell displays (module-curses.html)
  - 6.13.1 Functions (curses-functions.html)
  6.13.2 Window Objects (curses-window-objects.html)
  6.13.3 Constants (node181.html)
  6.14 curses.textpad -- Text input widget for curses programs (module-curses.textpad.html)
  - 6.14.1 Textbox objects (curses-textpad-objects.html)
  6.15 curses.wrapper -- Terminal handler for curses programs (module-curses.wrapper.html)
  6.16 curses.ascii -- Utilities for ASCII characters (module-curses.ascii.html)
  6.17 curses.panel -- A panel stack extension for curses. (module-curses.panel.html)
  - 6.17.1 Functions (cursespanel-functions.html)
  6.17.2 Panel Objects (curses-panel-objects.html)
  6.18 getopt -- Parser for command line options (module-getopt.html)
  6.19 tempfile -- Generate temporary file names (module-tempfile.html)
  6.20 errno -- Standard errno system symbols (module-errno.html)
  6.21 glob -- Unix style pathname pattern expansion (module-glob.html)
  6.22 fnmatch -- Unix filename pattern matching (module-fnmatch.html)
  6.23 shutil -- High-level file operations (module-shutil.html)
  - 6.23.1 Example (shutil-example.html)
  6.24 locale -- Internationalization services (module-locale.html)
  - 6.24.1 Background, details, hints, tips and caveats (node197.html)
  6.24.2 For extension writers and programs that embed Python (embedding-locale.html)
  6.25 gettext -- Multilingual internationalization services (module-gettext.html)
  - 6.25.1 GNU gettext API (node200.html)
  6.25.2 Class-based API (node201.html)
  6.25.3 Internationalizing your programs and modules (node206.html)
  6.25.4 Acknowledgements (node211.html)
  7. Optional Operating System Services (someos.html)
  - 7.1 signal -- Set handlers for asynchronous events (module-signal.html)
  - 7.1.1 Example (node214.html)
  7.2 socket -- Low-level networking interface (module-socket.html)
  - 7.2.1 Socket Objects (socket-objects.html)
  7.2.2 SSL Objects (ssl-objects.html)
  7.2.3 Example (socket-example.html)
  7.3 select -- Waiting for I/O completion (module-select.html)
  - 7.3.1 Polling Objects (poll-objects.html)
  7.4 thread -- Multiple threads of control (module-thread.html)
  7.5 threading -- Higher-level threading interface (module-threading.html)
  - 7.5.1 Lock Objects (lock-objects.html)
  7.5.2 RLock Objects (rlock-objects.html)
  7.5.3 Condition Objects (condition-objects.html)
  7.5.4 Semaphore Objects (semaphore-objects.html)
  7.5.5 Event Objects (event-objects.html)
  7.5.6 Thread Objects (thread-objects.html)
  7.5.7 Timer Objects (timer-objects.html)
  7.6 Queue -- A synchronized queue class (module-Queue.html)
  - 7.6.1 Queue Objects (QueueObjects.html)
  7.7 mmap --
  Memory-mapped file support (module-mmap.html)
  7.8 anydbm -- Generic access to DBM-style databases (module-anydbm.html)
  7.9 dumbdbm -- Portable DBM implementation (module-dumbdbm.html)
  7.10 dbhash -- DBM-style interface to the BSD database library (module-dbhash.html)
  - 7.10.1 Database Objects (dbhash-objects.html)
  7.11 whichdb -- Guess which DBM module created a database (module-whichdb.html)
  7.12 bsddb -- Interface to Berkeley DB library (module-bsddb.html)
  - 7.12.1 Hash, BTree and Record Objects (bsddb-objects.html)
  7.13 zlib -- Compression compatible with gzip (module-zlib.html)
  7.14 gzip -- Support for gzip files (module-gzip.html)
  7.15 zipfile -- Work with ZIP archives (module-zipfile.html)
  - 7.15.1 ZipFile Objects (zipfile-objects.html)
  7.15.2 PyZipFile Objects (pyzipfile-objects.html)
  7.15.3 ZipInfo Objects (zipinfo-objects.html)
  7.16 readline -- GNU readline interface (module-readline.html)
  - 7.16.1 Example (readline-example.html)
  7.17 rlcompleter -- Completion function for GNU readline (module-rlcompleter.html)
  - 7.17.1 Completer Objects (completer-objects.html)
  8. Unix Specific Services (unix.html)
  - 8.1 posix -- The most common POSIX system calls (module-posix.html)
  - 8.1.1 Large File Support (posix-large-files.html)
  8.1.2 Module Contents (posix-contents.html)
  8.2 pwd -- The password database (module-pwd.html)
  8.3 grp -- The group database (module-grp.html)
  8.4 crypt -- Function to check Unix passwords (module-crypt.html)
  8.5 dl -- Call C functions in shared objects (module-dl.html)
  - 8.5.1 Dl Objects (dl-objects.html)
  8.6 dbm -- Simple ``database'' interface (module-dbm.html)
  8.7 gdbm -- GNU's reinterpretation of dbm (module-gdbm.html)
  8.8 termios -- POSIX style tty control (module-termios.html)
  - 8.8.1 Example (node263.html)
  8.9 TERMIOS -- Constants used with the termios module (module-TERMIOSuppercase.html)
  8.10 tty -- Terminal control functions (module-tty.html)
  8.11 pty -- Pseudo-terminal utilities (module-pty.html)
  8.12 fcntl -- The fcntl() and ioctl() system calls (module-fcntl.html)
  8.13 pipes -- Interface to shell pipelines (module-pipes.html)
  - 8.13.1 Template Objects (template-objects.html)
  8.14 posixfile -- File-like objects with locking support (module-posixfile.html)
  8.15 resource -- Resource usage information (module-resource.html)
  - 8.15.1 Resource Limits (node272.html)
  8.15.2 Resource Usage (node273.html)
  8.16 nis -- Interface to Sun's NIS (Yellow Pages) (module-nis.html)
  8.17 syslog -- Unix syslog library routines (module-syslog.html)
  8.18 commands -- Utilities for running commands (module-commands.html)
  9. The Python Debugger (module-pdb.html)
  - 9.1 Debugger Commands (debugger-commands.html)
  9.2 How It Works (debugger-hooks.html)
  10. The Python Profiler (profile.html)
  - 10.1 Introduction to the profiler (node281.html)
  10.2 How Is This Profiler Different From The Old Profiler? (node282.html)
  10.3 Instant Users Manual (profile-instant.html)
  10.4 What Is Deterministic Profiling? (node284.html)
  10.5 Reference Manual (module-profile.html)
  - 10.5.1 The Stats Class (profile-stats.html)
  10.6 Limitations (profile-limits.html)
  10.7 Calibration (profile-calibration.html)
  10.8 Extensions -- Deriving Better Profilers (node289.html)
  11. Internet Protocols and Support (internet.html)
  - 11.1 webbrowser -- Convenient Web-browser controller (module-webbrowser.html)
  - 11.1.1 Browser Controller Objects (browser-controllers.html)
  11.2 cgi -- Common Gateway Interface support. (module-cgi.html)
  - 11.2.1 Introduction (cgi-intro.html)
  11.2.2 Using the cgi module (node295.html)
  11.2.3 Higher Level Interface (node296.html)
  11.2.4 Old classes (node297.html)
  11.2.5 Functions (node298.html)
  11.2.6 Caring about security (cgi-security.html)
  11.2.7 Installing your CGI script on a Unix system (node300.html)
  11.2.8 Testing your CGI script (node301.html)
  11.2.9 Debugging CGI scripts (node302.html)
  11.2.10 Common problems and solutions (node303.html)
  11.3 cgitb -- Traceback manager for CGI scripts (module-cgitb.html)
  11.4 urllib -- Open arbitrary resources by URL (module-urllib.html)
  - 11.4.1 URLopener Objects (urlopener-objs.html)
  11.4.2 Examples (node307.html)
  11.5 urllib2 -- extensible library for opening URLs (module-urllib2.html)
  - 11.5.1 Request Objects (request-objects.html)
  11.5.2 OpenerDirector Objects (opener-director-objects.html)
  11.5.3 BaseHandler Objects (base-handler-objects.html)
  11.5.4 HTTPRedirectHandler Objects (http-redirect-handler.html)
  11.5.5 ProxyHandler Objects (proxy-handler.html)
  11.5.6 HTTPPasswordMgr Objects (http-password-mgr.html)
  11.5.7 AbstractBasicAuthHandler Objects (abstract-basic-auth-handler.html)
  11.5.8 HTTPBasicAuthHandler Objects (http-basic-auth-handler.html)
  11.5.9 ProxyBasicAuthHandler Objects (proxy-basic-auth-handler.html)
  11.5.10 AbstractDigestAuthHandler Objects (abstract-digest-auth-handler.html)
  11.5.11 HTTPDigestAuthHandler Objects (http-digest-auth-handler.html)
  11.5.12 ProxyDigestAuthHandler Objects (proxy-digest-auth-handler.html)
  11.5.13 HTTPHandler Objects (http-handler-objects.html)
  11.5.14 HTTPSHandler Objects (https-handler-objects.html)
  11.5.15 FileHandler Objects (file-handler-objects.html)
  11.5.16 FTPHandler Objects (ftp-handler-objects.html)
  11.5.17 CacheFTPHandler Objects (cacheftp-handler-objects.html)
  11.5.18 GopherHandler Objects (gopher-handler.html)
  11.5.19 UnknownHandler Objects (unknown-handler-objects.html)
  11.6 httplib -- HTTP protocol client (module-httplib.html)
  - 11.6.1 HTTPConnection Objects (httpconnection-objects.html)
  11.6.2 HTTPResponse Objects (httpresponse-objects.html)
  11.6.3 Examples (httplib-examples.html)
  11.7 ftplib -- FTP protocol client (module-ftplib.html)
  - 11.7.1 FTP Objects (ftp-objects.html)
  11.8 gopherlib -- Gopher protocol client (module-gopherlib.html)
  11.9 poplib -- POP3 protocol client (module-poplib.html)
  - 11.9.1 POP3 Objects (pop3-objects.html)
  11.9.2 POP3 Example (pop3-example.html)
  11.10 imaplib -- IMAP4 protocol client (module-imaplib.html)
  - 11.10.1 IMAP4 Objects (imap4-objects.html)
  11.10.2 IMAP4 Example (imap4-example.html)
  11.11 nntplib -- NNTP protocol client (module-nntplib.html)
  - 11.11.1 NNTP Objects (nntp-objects.html)
  11.12 smtplib -- SMTP protocol client (module-smtplib.html)
  - 11.12.1 SMTP Objects (SMTP-objects.html)
  11.12.2 SMTP Example (SMTP-example.html)
  11.13 telnetlib -- Telnet client (module-telnetlib.html)
  - 11.13.1 Telnet Objects (telnet-objects.html)
  11.13.2 Telnet Example (telnet-example.html)
  11.14 urlparse -- Parse URLs into components (module-urlparse.html)
  11.15 SocketServer -- A framework for network servers (module-SocketServer.html)
  11.16 BaseHTTPServer -- Basic HTTP server (module-BaseHTTPServer.html)
  11.17 SimpleHTTPServer -- Simple HTTP request handler (module-SimpleHTTPServer.html)
  11.18 CGIHTTPServer -- CGI-capable HTTP request handler (module-CGIHTTPServer.html)
  11.19 Cookie -- HTTP state management (module-Cookie.html)
  - 11.19.1 Cookie Objects (cookie-objects.html)
  11.19.2 Morsel Objects (morsel-objects.html)
  11.19.3 Example (cookie-example.html)
  11.20 xmlrpclib -- XML-RPC client access (module-xmlrpclib.html)
  - 11.20.1 Server Objects (server-objects.html)
  11.20.2 Boolean Objects (boolean-objects.html)
  11.20.3 DateTime Objects (datetime-objects.html)
  11.20.4 Binary Objects (binary-objects.html)
  11.20.5 Fault Objects (fault-objects.html)
  11.20.6 ProtocolError Objects (protocol-error-objects.html)
  11.20.7 Convenience Functions (node365.html)
  11.20.8 Example of Client Usage (xmlrpc-client-example.html)
  11.21 SimpleXMLRPCServer -- Basic XML-RPC server (module-SimpleXMLRPCServer.html)
  - 11.21.1 SimpleXMLRPCServer Objects (simple-xmlrpc-servers.html)
  11.22 asyncore -- Asynchronous socket handler (module-asyncore.html)
  - 11.22.1 Example basic HTTP client (asyncore-example.html)
  12. Internet Data Handling (netdata.html)
  - 12.1 formatter -- Generic output formatting (module-formatter.html)
  - 12.1.1 The Formatter Interface (formatter-interface.html)
  12.1.2 Formatter Implementations (formatter-impls.html)
  12.1.3 The Writer Interface (writer-interface.html)
  12.1.4 Writer Implementations (writer-impls.html)
  12.2 email -- An email and MIME handling package (module-email.html)
  - 12.2.1 Representing an email message (module-email.Message.html)
  12.2.2 Parsing email messages (module-email.Parser.html)
  12.2.3 Generating MIME documents (module-email.Generator.html)
  12.2.4 Creating email and MIME objects from scratch (node383.html)
  12.2.5 Encoders (module-email.Encoders.html)
  12.2.6 Exception classes (module-email.Errors.html)
  12.2.7 Miscellaneous utilities (module-email.Utils.html)
  12.2.8 Iterators (module-email.Iterators.html)
  12.2.9 Differences from mimelib (node388.html)
  12.2.10 Examples (node389.html)
  12.3 mailcap -- Mailcap file handling. (module-mailcap.html)
  12.4 mailbox -- Read various mailbox formats (module-mailbox.html)
  - 12.4.1 Mailbox Objects (mailbox-objects.html)
  12.5 mhlib -- Access to MH mailboxes (module-mhlib.html)
  - 12.5.1 MH Objects (mh-objects.html)
  12.5.2 Folder Objects (mh-folder-objects.html)
  12.5.3 Message Objects (mh-message-objects.html)
  12.6 mimetools -- Tools for parsing MIME messages (module-mimetools.html)
  - 12.6.1 Additional Methods of Message Objects (mimetools-message-objects.html)
  12.7 mimetypes -- Map filenames to MIME types (module-mimetypes.html)
  - 12.7.1 MimeTypes Objects (mimetypes-objects.html)
  12.8 MimeWriter -- Generic MIME file writer (module-MimeWriter.html)
  - 12.8.1 MimeWriter Objects (MimeWriter-objects.html)
  12.9 mimify -- MIME processing of mail messages (module-mimify.html)
  12.10 multifile -- Support for files containing distinct parts (module-multifile.html)
  - 12.10.1 MultiFile Objects (MultiFile-objects.html)
  12.10.2 MultiFile Example (multifile-example.html)
  12.11 rfc822 -- Parse RFC 2822 mail headers (module-rfc822.html)
  - 12.11.1 Message Objects (message-objects.html)
  12.11.2 AddressList Objects (addresslist-objects.html)
  12.12 base64 -- Encode and decode MIME base64 data (module-base64.html)
  12.13 binascii -- Convert between binary and ASCII (module-binascii.html)
  12.14 binhex -- Encode and decode binhex4 files (module-binhex.html)
  - 12.14.1 Notes (binhex-notes.html)
  12.15 quopri -- Encode and decode MIME quoted-printable data (module-quopri.html)
  12.16 uu -- Encode and decode uuencode files (module-uu.html)
  12.17 xdrlib -- Encode and decode XDR data (module-xdrlib.html)
  - 12.17.1 Packer Objects (xdr-packer-objects.html)
  12.17.2 Unpacker Objects (xdr-unpacker-objects.html)
  12.17.3 Exceptions (xdr-exceptions.html)
  12.18 netrc -- netrc file processing (module-netrc.html)
  - 12.18.1 netrc Objects (netrc-objects.html)
  12.19 robotparser -- Parser for robots.txt (module-robotparser.html)
  13. Structured Markup Processing Tools (markup.html)
  - 13.1 HTMLParser -- Simple HTML and XHTML parser (module-HTMLParser.html)
  - 13.1.1 Example HTML Parser (htmlparser-example.html)
  13.2 sgmllib -- Simple SGML parser (module-sgmllib.html)
  13.3 htmllib -- A parser for HTML documents (module-htmllib.html)
  - 13.3.1 HTMLParser Objects (html-parser-objects.html)
  13.4 htmlentitydefs -- Definitions of HTML general entities (module-htmlentitydefs.html)
  13.5 xml.parsers.expat -- Fast XML parsing using Expat (module-xml.parsers.expat.html)
  - 13.5.1 XMLParser Objects (xmlparser-objects.html)
  13.5.2 ExpatError Exceptions (expaterror-objects.html)
  13.5.3 Example (expat-example.html)
  13.5.4 Content Model Descriptions (expat-content-models.html)
  13.5.5 Expat error constants (expat-errors.html)
  13.6 xml.dom -- The Document Object Model API (module-xml.dom.html)
  - 13.6.1 Module Contents (node437.html)
  13.6.2 Objects in the DOM (node438.html)
  13.6.3 Conformance (dom-conformance.html)
  13.7 xml.dom.minidom -- Lightweight DOM implementation (module-xml.dom.minidom.html)
  - 13.7.1 DOM objects (dom-objects.html)
  13.7.2 DOM Example (dom-example.html)
  13.7.3 minidom and the DOM standard (minidom-and-dom.html)
  13.8 xml.dom.pulldom -- Support for building partial DOM trees (module-xml.dom.pulldom.html)
  - 13.8.1 DOMEventStream Objects (domeventstream-objects.html)
  13.9 xml.sax -- Support for SAX2 parsers (module-xml.sax.html)
  - 13.9.1 SAXException Objects (sax-exception-objects.html)
  13.10 xml.sax.handler -- Base classes for SAX handlers (module-xml.sax.handler.html)
  - 13.10.1 ContentHandler Objects (content-handler-objects.html)
  13.10.2 DTDHandler Objects (dtd-handler-objects.html)
  13.10.3 EntityResolver Objects (entity-resolver-objects.html)
  13.10.4 ErrorHandler Objects (sax-error-handler.html)
  13.11 xml.sax.saxutils -- SAX Utilities (module-xml.sax.saxutils.html)
  13.12 xml.sax.xmlreader -- Interface for XML parsers (module-xml.sax.xmlreader.html)
  - 13.12.1 XMLReader Objects (xmlreader-objects.html)
  13.12.2 IncrementalParser Objects (incremental-parser-objects.html)
  13.12.3 Locator Objects (locator-objects.html)
  13.12.4 InputSource Objects (input-source-objects.html)
  13.12.5 AttributesImpl Objects (attributes-impl-objects.html)
  13.12.6 AttributesNSImpl Objects (attributes-ns-impl-objects.html)
  13.13 xmllib -- A parser for XML documents (module-xmllib.html)
  - 13.13.1 XML Namespaces (xml-namespace.html)
  14. Multimedia Services (mmedia.html)
  - 14.1 audioop -- Manipulate raw audio data (module-audioop.html)
  14.2 imageop -- Manipulate raw image data (module-imageop.html)
  14.3 aifc -- Read and write AIFF and AIFC files (module-aifc.html)
  14.4 sunau -- Read and write Sun AU files (module-sunau.html)
  - 14.4.1 AU_read Objects (au-read-objects.html)
  14.4.2 AU_write Objects (au-write-objects.html)
  14.5 wave -- Read and write WAV files (module-wave.html)
  - 14.5.1 Wave_read Objects (Wave-read-objects.html)
  14.5.2 Wave_write Objects (Wave-write-objects.html)
  14.6 chunk -- Read IFF chunked data (module-chunk.html)
  14.7 colorsys -- Conversions between color systems (module-colorsys.html)
  14.8 rgbimg -- Read and write ``SGI RGB'' files (module-rgbimg.html)
  14.9 imghdr -- Determine the type of an image (module-imghdr.html)
  14.10 sndhdr -- Determine type of sound file (module-sndhdr.html)
  15. Cryptographic Services (crypto.html)
  - 15.1 hmac -- Keyed-Hashing for Message Authentication (module-hmac.html)
  15.2 md5 -- MD5 message digest algorithm (module-md5.html)
  15.3 sha -- SHA message digest algorithm (module-sha.html)
  15.4 mpz -- GNU arbitrary magnitude integers (module-mpz.html)
  15.5 rotor -- Enigma-like encryption and decryption (module-rotor.html)
  16. Graphical User Interfaces with Tk (tkinter.html)
  - 16.1 Tkinter -- Python interface to Tcl/Tk (module-Tkinter.html)
  - 16.1.1 Tkinter Modules (node500.html)
  16.1.2 Tkinter Life Preserver (node501.html)
  16.1.3 A (Very) Quick Look at Tcl/Tk (node504.html)
  16.1.4 Mapping Basic Tk into Tkinter (tkinter-basic-mapping.html)
  16.1.5 How Tk and Tkinter are Related (node506.html)
  16.1.6 Handy Reference (node507.html)
  16.2 Tix -- Extension widgets for Tk (module-Tix.html)
  - 16.2.1 Using Tix (node517.html)
  16.2.2 Tix Widgets (node518.html)
  16.2.3 Tix Commands (node527.html)
  16.3 ScrolledText -- Scrolled Text Widget (module-ScrolledText.html)
  16.4 turtle -- Turtle graphics for Tk (module-turtle.html)
  - 16.4.1 Pen and RawPen Objects (pen-rawpen-objects.html)
  16.5 Idle (idle.html)
  - 16.5.1 Menus (node532.html)
  16.5.2 Basic editing and navigation (node537.html)
  16.5.3 Syntax colors (node540.html)
  16.6 Other Graphical User Interface Packages (other-gui-packages.html)
  17. Restricted Execution (restricted.html)
  - 17.1 rexec -- Restricted execution framework (module-rexec.html)
  - 17.1.1 RExec Objects (rexec-objects.html)
  17.1.2 Defining restricted environments (rexec-extension.html)
  17.1.3 An example (node547.html)
  17.2 Bastion -- Restricting access to objects (module-Bastion.html)
  18. Python Language Services (language.html)
  - 18.1 parser -- Access Python parse trees (module-parser.html)
  - 18.1.1 Creating AST Objects (node551.html)
  18.1.2 Converting AST Objects (node552.html)
  18.1.3 Queries on AST Objects (node553.html)
  18.1.4 Exceptions and Error Handling (node554.html)
  18.1.5 AST Objects (node555.html)
  18.1.6 Examples (node556.html)
  18.2 symbol -- Constants used with Python parse trees (module-symbol.html)
  18.3 token -- Constants used with Python parse trees (module-token.html)
  18.4 keyword -- Testing for Python keywords (module-keyword.html)
  18.5 tokenize -- Tokenizer for Python source (module-tokenize.html)
  18.6 tabnanny -- Detection of ambiguous indentation (module-tabnanny.html)
  18.7 pyclbr -- Python class browser support (module-pyclbr.html)
  - 18.7.1 Class Descriptor Objects (pyclbr-class-objects.html)
  18.8 py_compile -- Compile Python source files (module-pycompile.html)
  18.9 compileall -- Byte-compile Python libraries (module-compileall.html)
  18.10 dis -- Disassembler for Python byte code (module-dis.html)
  - 18.10.1 Python Byte Code Instructions (bytecodes.html)
  18.11 distutils -- Building and installing Python modules (module-distutils.html)
  19. Python compiler package (compiler.html)
  - 19.1 The basic interface (module-compiler.html)
  19.2 Limitations (node573.html)
  19.3 Python Abstract Syntax (node574.html)
  - 19.3.1 AST Nodes (module-compiler.ast.html)
  19.3.2 Assignment nodes (node576.html)
  19.3.3 Examples (node577.html)
  19.4 Using Visitors to Walk ASTs (module-compiler.visitor.html)
  19.5 Bytecode Generation (node579.html)
  20. SGI IRIX Specific Services (sgi.html)
  - 20.1 al -- Audio functions on the SGI (module-al.html)
  - 20.1.1 Configuration Objects (al-config-objects.html)
  20.1.2 Port Objects (al-port-objects.html)
  20.2 AL -- Constants used with the al module (module-al-constants.html)
  20.3 cd -- CD-ROM access on SGI systems (module-cd.html)
  - 20.3.1 Player Objects (player-objects.html)
  20.3.2 Parser Objects (cd-parser-objects.html)
  20.4 fl -- FORMS library for graphical user interfaces (module-fl.html)
  - 20.4.1 Functions Defined in Module fl (node589.html)
  20.4.2 Form Objects (form-objects.html)
  20.4.3 FORMS Objects (forms-objects.html)
  20.5 FL -- Constants used with the fl module (module-fl-constants.html)
  20.6 flp -- Functions for loading stored FORMS designs (module-flp.html)
  20.7 fm -- Font Manager interface (module-fm.html)
  20.8 gl -- Graphics Library interface (module-gl.html)
  20.9 DEVICE -- Constants used with the gl module (module-DEVICE.html)
  20.10 GL -- Constants used with the gl module (module-gl-constants.html)
  20.11 imgfile -- Support for SGI imglib files (module-imgfile.html)
  20.12 jpeg -- Read and write JPEG files (module-jpeg.html)
  21. SunOS Specific Services (sunos.html)
  - 21.1 sunaudiodev -- Access to Sun audio hardware (module-sunaudiodev.html)
  - 21.1.1 Audio Device Objects (audio-device-objects.html)
  21.2 SUNAUDIODEV -- Constants used with sunaudiodev (module-sunaudiodev-constants.html)
  22. MS Windows Specific Services (node604.html)
  - 22.1 msvcrt - Useful routines from the MS VC++ runtime (module-msvcrt.html)
  - 22.1.1 File Operations (msvcrt-files.html)
  22.1.2 Console I/O (msvcrt-console.html)
  22.1.3 Other Functions (msvcrt-other.html)
  22.2 _winreg - Windows registry access (module--winreg.html)
  - 22.2.1 Registry Handle Objects (handle-object.html)
  22.3 winsound -- Sound-playing interface for Windows (module-winsound.html)
  A. Undocumented Modules (undoc.html)
  - A.1 Frameworks (node613.html)
  A.2 Miscellaneous useful utilities (node614.html)
  A.3 Platform specific modules (node615.html)
  A.4 Multimedia (node616.html)
  A.5 Obsolete (obsolete-modules.html)
  A.6 SGI-specific Extension modules (node618.html)
  B. Reporting Bugs (reporting-bugs.html)
  C. History and License (node620.html)
  - C.1 History of the software (node621.html)
  C.2 Terms and conditions for accessing or otherwise using Python (node622.html)
  Module Index (modindex.html)
  About this document ... (about.html)
End of Table of Contents


4.2.3 Module Contents

matching-searching.html | module-re.html | re-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 4.2.3 Module Contents
The module defines the following functions and constants, and an exception:


17.1.2 Converting AST Objects

Creating_ASTs.html | module-parser.html | Querying_ASTs.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 17.1.2 Converting AST Objects
AST objects, regardless of the input used to create them, may be
converted to parse trees represented as list- or tuple- trees, or may
be compiled into executable code objects. Parse trees may be
extracted with or without line numbering information.


11.19.3 Example

morsel-objects.html | module-Cookie.html | module-xmlrpclib.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.19.3 Example
The following example demonstrates how to use the Cookie module.


11.19.1 Cookie Objects

module-Cookie.html | module-Cookie.html | morsel-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.19.1 Cookie Objects


17.1.1 Creating AST Objects

module-parser.html | module-parser.html | Converting_ASTs.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 17.1.1 Creating AST Objects
AST objects may be created from source code or from a parse tree.
When creating an AST object from source, different functions are used
to create the `'eval'` and `'exec'` forms.


15. Cryptographic Services

module-sndhdr.html | lib.html | module-hmac.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 15. Cryptographic Services
The modules described in this chapter implement various algorithms of
a cryptographic nature. They are available at the discretion of the
installation. Here's an overview:
hmac (module-hmac.html) | Keyed-Hashing for Message Authentication (HMAC)
implementation for Python.
md5 (module-md5.html) | RSA's MD5 message digest algorithm.
sha (module-sha.html) | NIST's secure hash algorithm, SHA.
mpz (module-mpz.html) | Interface to the GNU MP library for arbitrary
precision arithmetic.
rotor (module-rotor.html) | Enigma-like encryption and decryption.


6.13.1 Functions

module-curses.html | module-curses.html | curses-window-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 6.13.1 Functions
The module curses defines the following exception:
Note:
Whenever x or y arguments to a function
or a method are optional, they default to the current cursor location.
Whenever attr is optional, it defaults to A_NORMAL.
The module curses defines the following functions:


6.17.2 Panel Objects

cursespanel-functions.html | module-curses.panel.html | module-getopt.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 6.17.2 Panel Objects
Panel objects, as returned by new_panel() above, are windows
with a stacking order. There's always a window associated with a
panel which determines the content, while the panel methods are
responsible for the window's depth in the panel stack.
Panel objects have the following methods:


6.14.1 Textbox objects

module-curses.textpad.html | module-curses.textpad.html | module-curses.wrapper.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 6.14.1 Textbox objects
You can instantiate a Textbox object as follows:
Textbox objects have the following methods:


6.13.2 Window Objects

curses-functions.html | module-curses.html | node181.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 6.13.2 Window Objects
Window objects, as returned by initscr() and
newwin() above, have the
following methods:


6.17.1 Functions

module-curses.panel.html | module-curses.panel.html | curses-panel-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 6.17.1 Functions
The module curses.panel defines the following functions:


11.20.3 DateTime Objects

boolean-objects.html | module-xmlrpclib.html | binary-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.20.3 DateTime Objects
This class may initialized from date in seconds since the epoch, a
time tuple, or an ISO 8601 time/date string. It has the following
methods, supported mainly for internal use by the
marshalling/unmarshalling code:
It also supports certain of Python's built-in operators through
_cmp__ and __repr__ methods.


7.10.1 Database Objects

module-dbhash.html | module-dbhash.html | module-whichdb.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 7.10.1 Database Objects
The database objects returned by open() provide the methods
common to all the DBM-style databases. The following methods are
available in addition to the standard methods.


9.1 Debugger Commands

module-pdb.html | module-pdb.html | debugger-hooks.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 9.1 Debugger Commands
The debugger recognizes the following commands. Most commands can be
abbreviated to one or two letters; e.g. "h(elp)" means that
either "h" or "help" can be used to enter the help
command (but not "he" or "hel", nor "H" or
"Help" or "HELP"). Arguments to commands must be
separated by whitespace (spaces or tabs). Optional arguments are
enclosed in square brackets ("[]") in the command syntax; the
square brackets must not be typed. Alternatives in the command syntax
are separated by a vertical bar ("|").
Entering a blank line repeats the last command entered. Exception: if
the last command was a "list" command, the next 11 lines are
listed.
Commands that the debugger doesn't recognize are assumed to be Python
statements and are executed in the context of the program being
debugged. Python statements can also be prefixed with an exclamation
point ("!"). This is a powerful way to inspect the program
being debugged; it is even possible to change a variable or call a
function. When an
exception occurs in such a statement, the exception name is printed
but the debugger's state is not changed.
Multiple commands may be entered on a single line, separated by
";;". (A single ";" is not used as it is
the separator for multiple commands in a line that is passed to
the Python parser.)
No intelligence is applied to separating the commands;
the input is split at the first ";;" pair, even if it is in
the middle of a quoted string.
The debugger supports aliases. Aliases can have parameters which
allows one a certain level of adaptability to the context under
examination.
If a file .pdbrc
exists in the user's home directory or in the current directory, it is
read in and executed as if it had been typed at the debugger prompt.
This is particularly useful for aliases. If both files exist, the one
in the home directory is read first and aliases defined there can be
overridden by the local file.
h(elp) [command]: Without argument, print the list of available commands. With a
command as argument, print help about that command. "help
pdb" displays the full documentation file; if the environment variable
PAGER is defined, the file is piped through that command
instead. Since the command argument must be an identifier,
"help exec" must be entered to get help on the "!" command.
w(here): Print a stack trace, with the most recent frame at the bottom. An
arrow indicates the current frame, which determines the context of
most commands.
d(own): Move the current frame one level down in the stack trace
(to an newer frame).
u(p): Move the current frame one level up in the stack trace
(to a older frame).
b(reak) [[filename:]lineno`|`function[, condition]]: With a lineno argument, set a break there in the current
file. With a function argument, set a break at the first
executable statement within that function.
The line number may be prefixed with a filename and a colon,
to specify a breakpoint in another file (probably one that
hasn't been loaded yet). The file is searched on `sys.path`.
Note that each breakpoint is assigned a number to which all the other
breakpoint commands refer.
If a second argument is present, it is an expression which must
evaluate to true before the breakpoint is honored.
Without argument, list all breaks, including for each breakpoint,
the number of times that breakpoint has been hit, the current
ignore count, and the associated condition if any.
tbreak [[filename:]lineno`|`function[, condition]]: Temporary breakpoint, which is removed automatically when it is
first hit. The arguments are the same as break.
cl(ear) [bpnumber [bpnumber ...]]: With a space separated list of breakpoint numbers, clear those
breakpoints. Without argument, clear all breaks (but first
ask confirmation).
disable [bpnumber [bpnumber ...]]: Disables the breakpoints given as a space separated list of
breakpoint numbers. Disabling a breakpoint means it cannot cause
the program to stop execution, but unlike clearing a breakpoint, it
remains in the list of breakpoints and can be (re-)enabled.
enable [bpnumber [bpnumber ...]]: Enables the breakpoints specified.
ignore bpnumber [count]: Sets the ignore count for the given breakpoint number. If
count is omitted, the ignore count is set to 0. A breakpoint
becomes active when the ignore count is zero. When non-zero,
the count is decremented each time the breakpoint is reached
and the breakpoint is not disabled and any associated condition
evaluates to true.
condition bpnumber [condition]: Condition is an expression which must evaluate to true before
the breakpoint is honored. If condition is absent, any existing
condition is removed; i.e., the breakpoint is made unconditional.
s(tep): Execute the current line, stop at the first possible occasion
(either in a function that is called or on the next line in the
current function).
n(ext): Continue execution until the next line in the current function
is reached or it returns. (The difference between "next" and
"step" is that "step" stops inside a called function, while
"next" executes called functions at (nearly) full speed, only
stopping at the next line in the current function.)
r(eturn): Continue execution until the current function returns.
c(ont(inue)): Continue execution, only stop when a breakpoint is encountered.
l(ist) [first[, last]]: List source code for the current file. Without arguments, list 11
lines around the current line or continue the previous listing. With
one argument, list 11 lines around at that line. With two arguments,
list the given range; if the second argument is less than the first,
it is interpreted as a count.
a(rgs): Print the argument list of the current function.
p expression: Evaluate the expression in the current context and print its
value. (Note: "print" can also be used, but is not a debugger
command -- this executes the Python print statement.)
alias [name [command]]: Creates an alias called name that executes command. The
command must not be enclosed in quotes. Replaceable parameters
can be indicated by "%1", "%2", and so on, while "%*" is
replaced by all the parameters. If no command is given, the current
alias for name is shown. If no arguments are given, all
aliases are listed.
Aliases may be nested and can contain anything that can be
legally typed at the pdb prompt. Note that internal pdb commands
can be overridden by aliases. Such a command is
then hidden until the alias is removed. Aliasing is recursively
applied to the first word of the command line; all other words
in the line are left alone.
As an example, here are two useful aliases (especially when placed
in the .pdbrc file):
```text

#Print instance variables (usage "pi classInst")
alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k]
#Print instance variables in self
alias ps pi self
```
unalias name: Deletes the specified alias.
[!]statement: Execute the (one-line) statement in the context of
the current stack frame.
The exclamation point can be omitted unless the first word
of the statement resembles a debugger command.
To set a global variable, you can prefix the assignment
command with a "global" command on the same line, e.g.:
```text

(Pdb) global list_options; list_options = ['-l']
(Pdb)
```
q(uit): Quit from the debugger.
The program being executed is aborted.


9.2 How It Works

debugger-commands.html | module-pdb.html | profile.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 9.2 How It Works
Some changes were made to the interpreter:
- `sys.settrace( func )` sets the global trace function
- there can also a local trace function (see later)
Trace functions have three arguments: frame, event, and
arg. frame is the current stack frame. event is a
string: `'call'`, `'line'`, `'return'` or
`'exception'`. arg depends on the event type.
The global trace function is invoked (with event set to
`'call'`) whenever a new local scope is entered; it should return
a reference to the local trace function to be used that scope, or
`None` if the scope shouldn't be traced.
The local trace function should return a reference to itself (or to
another function for further tracing in that scope), or `None` to
turn off tracing in that scope.
Instance methods are accepted (and very useful!) as trace functions.
The events have the following meaning:
`'call'`: A function is called (or some other code block entered). The global
trace function is called; arg is `None`;
the return value specifies the local trace function.
`'line'`: The interpreter is about to execute a new line of code (sometimes
multiple line events on one line exist). The local trace function is
called; arg is `None`; the return value specifies the new
local trace function.
`'return'`: A function (or other code block) is about to return. The local trace
function is called; arg is the value that will be returned. The
trace function's return value is ignored.
`'exception'`: An exception has occurred. The local trace function is called;
arg is a triple `( exception , value , traceback )`; the return value specifies the new local trace
function.
Note that as an exception is propagated down the chain of callers, an
`'exception'` event is generated at each level.
For more information on code and frame objects, refer to the
Python Reference Manual (../ref/ref.html).


10.4 What Is Deterministic Profiling?

profile-instant.html | profile.html | module-profile.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 10.4 What Is Deterministic Profiling?
Deterministic profiling is meant to reflect the fact that all
function call, function return, and exception events
are monitored, and precise timings are made for the intervals between
these events (during which time the user's code is executing). In
contrast, statistical profiling (which is not done by this
module) randomly samples the effective instruction pointer, and
deduces where time is being spent. The latter technique traditionally
involves less overhead (as the code does not need to be instrumented),
but provides only relative indications of where time is being spent.
In Python, since there is an interpreter active during execution, the
presence of instrumented code is not required to do deterministic
profiling. Python automatically provides a hook (optional
callback) for each event. In addition, the interpreted nature of
Python tends to add so much overhead to execution, that deterministic
profiling tends to only add small processing overhead in typical
applications. The result is that deterministic profiling is not that
expensive, yet provides extensive run time statistics about the
execution of a Python program.
Call count statistics can be used to identify bugs in code (surprising
counts), and to identify possible inline-expansion points (high call
counts). Internal time statistics can be used to identify ``hot
loops'' that should be carefully optimized. Cumulative time
statistics should be used to identify high level errors in the
selection of algorithms. Note that the unusual handling of cumulative
times in this profiler allows statistics for recursive implementations
of algorithms to be directly compared to iterative implementations.


4.4.4 Differ Example

differ-objects.html | module-difflib.html | module-fpformat.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 4.4.4 Differ Example
This example compares two texts. First we set up the texts, sequences
of individual single-line strings ending with newlines (such sequences
can also be obtained from the readlines() method of file-like
objects):
```text

>>> text1 = ''' 1. Beautiful is better than ugly.
... 2. Explicit is better than implicit.
... 3. Simple is better than complex.
... 4. Complex is better than complicated.
... '''.splitlines(1)
>>> len(text1)
4
>>> text1[0][-1]
'\n'
>>> text2 = ''' 1. Beautiful is better than ugly.
... 3. Simple is better than complex.
... 4. Complicated is better than complex.
... 5. Flat is better than nested.
... '''.splitlines(1)
```
Next we instantiate a Differ object:
```text

>>> d = Differ()
```
Note that when instantiating a Differ object we may pass
functions to filter out line and character ``junk.'' See the
Differ() constructor for details.
Finally, we compare the two:
```text

>>> result = list(d.compare(text1, text2))
```
`result` is a list of strings, so let's pretty-print it:
```text

>>> from pprint import pprint
>>> pprint(result)
[' 1. Beautiful is better than ugly.\n',
'- 2. Explicit is better than implicit.\n',
'- 3. Simple is better than complex.\n',
'+ 3. Simple is better than complex.\n',
'? ++ \n',
'- 4. Complex is better than complicated.\n',
'? ^ ---- ^ \n',
'+ 4. Complicated is better than complex.\n',
'? ++++ ^ ^ \n',
'+ 5. Flat is better than nested.\n']
```
As a single multi-line string it looks like this:


4.4.3 Differ Objects

sequencematcher-examples.html | module-difflib.html | differ-examples.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 4.4.3 Differ Objects
Note that Differ-generated deltas make no claim to be
minimal diffs. To the contrary, minimal diffs are often
counter-intuitive, because they synch up anywhere possible, sometimes
accidental matches 100 pages apart. Restricting synch points to
contiguous matches preserves some notion of locality, at the
occasional cost of producing a longer diff.
The Differ class has this constructor:
Differ objects are used (deltas generated) via a single
method:


4.4.2 Examples

sequence-matcher.html | module-difflib.html | module-fpformat.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 4.4.2 Examples
This example compares two strings, considering blanks to be ``junk:''
```text

>>> s = SequenceMatcher(lambda x: x == " ",
... "private Thread currentThread;",
... "private volatile Thread currentThread;")
```
ratio() returns a float in [0, 1], measuring the similarity
of the sequences. As a rule of thumb, a ratio() value over
0.6 means the sequences are close matches:
```text

>>> print round(s.ratio(), 3)
0.866
```
If you're only interested in where the sequences match,
get_matching_blocks() is handy:
```text

>>> for block in s.get_matching_blocks():
... print "a[%d] and b[%d] match for %d elements" % block
a[0] and b[0] match for 8 elements
a[8] and b[17] match for 6 elements
a[14] and b[23] match for 15 elements
a[29] and b[38] match for 0 elements
```
Note that the last tuple returned by get_matching_blocks() is
always a dummy, `(len( a ), len( b ), 0)`, and this is
the only case in which the last tuple element (number of elements
matched) is `0`.
If you want to know how to change the first sequence into the second,
use get_opcodes():
```text

>>> for opcode in s.get_opcodes():
... print "%6s a[%d:%d] b[%d:%d]" % opcode
equal a[0:8] b[0:8]
insert a[8:8] b[8:17]
equal a[8:14] b[17:23]
equal a[14:29] b[23:38]
```
See Tools/scripts/ndiff.py from the Python source distribution
for a fancy human-friendly file differencer, which uses
SequenceMatcher both to view files as sequences of lines, and
lines as sequences of characters.


6.7.1 The dircmp class

module-filecmp.html | module-filecmp.html | module-popen2.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 6.7.1 The dircmp class
dircmp instances are built using this constructor:
The dircmp class provides the following methods:
The dircmp offers a number of interesting attributes that may
be used to get various bits of information about the directory trees
being compared.
Note that via __getattr__() hooks, all attributes are
computed lazilly, so there is no speed penalty if only those
attributes which are lightweight to compute are used.


8.5.1 Dl Objects

module-dl.html | module-dl.html | module-dbm.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 8.5.1 Dl Objects
Dl objects, as returned by open() above, have the
following methods:


13.6.3.2 Accessor Methods

dom-type-mapping.html | dom-conformance.html | module-xml.dom.minidom.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.3.2 Accessor Methods
The mapping from OMG IDL to Python defines accessor functions for IDL
attribute declarations in much the way the Java mapping
does. Mapping the IDL declarations
```text

readonly attribute string someValue;
attribute string anotherValue;
```
yields three accessor functions: a ``get'' method for
someValue (_get_someValue()), and ``get'' and
``set'' methods for
anotherValue (_get_anotherValue() and
_set_anotherValue()). The mapping, in particular, does not
require that the IDL attributes are accessible as normal Python
attributes: `object .someValue` is not required to
work, and may raise an AttributeError.
The Python DOM API, however, does require that normal attribute
access work. This means that the typical surrogates generated by
Python IDL compilers are not likely to work, and wrapper objects may
be needed on the client if the DOM objects are accessed via CORBA.
While this does require some additional consideration for CORBA DOM
clients, the implementers with experience using DOM over CORBA from
Python do not consider this a problem. Attributes that are declared
readonly may not restrict write access in all DOM
implementations.


13.6.2.7 Attr Objects

dom-element-objects.html | node438.html | dom-attributelist-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.7 Attr Objects
Attr inherits from Node, so inherits all its
attributes.


13.6.2.8 NamedNodeMap Objects

dom-attr-objects.html | node438.html | dom-comment-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.8 NamedNodeMap Objects
NamedNodeMap does not inherit from Node.
There are also experimental methods that give this class more mapping
behavior. You can use them or you can use the standardized
getAttribute*() family of methods on the Element
objects.


13.6.2.9 Comment Objects

dom-attributelist-objects.html | node438.html | dom-text-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.9 Comment Objects
Comment represents a comment in the XML document. It is a
subclass of Node, but cannot have child nodes.


13.6.3 Conformance

dom-exceptions.html | module-xml.dom.html | dom-type-mapping.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.6.3 Conformance
This section describes the conformance requirements and relationships
between the Python DOM API, the W3C DOM recommendations, and the OMG
IDL mapping for Python.


13.6.2.5 Document Objects

dom-documenttype-objects.html | node438.html | dom-element-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.5 Document Objects
A Document represents an entire XML document, including its
constituent elements, attributes, processing instructions, comments
etc. Remeber that it inherits properties from Node.


13.6.2.4 DocumentType Objects

dom-nodelist-objects.html | node438.html | dom-document-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.4 DocumentType Objects
Information about the notations and entities declared by a document
(including the external subset if the parser uses it and can provide
the information) is available from a DocumentType object. The
DocumentType for a document is available from the
Document object's doctype attribute; if there is no
`DOCTYPE` declaration for the document, the document's
doctype attribute will be set to `None` instead of an
instance of this interface.
DocumentType is a specialization of Node, and adds the
following attributes:


13.6.2.6 Element Objects

dom-document-objects.html | node438.html | dom-attr-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.6 Element Objects
Element is a subclass of Node, so inherits all the
attributes of that class.


13.7.2 DOM Example

dom-objects.html | module-xml.dom.minidom.html | minidom-and-dom.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.7.2 DOM Example
This example program is a fairly realistic example of a simple
program. In this particular case, we do not take much advantage
of the flexibility of the DOM.
```text
import xml.dom.minidom

document = """\
<slideshow>
<title>Demo slideshow</title>
<slide><title>Slide title</title>
<point>This is a demo</point>
<point>Of a program for processing slides</point>
</slide>

<slide><title>Another demo slide</title>
<point>It is important</point>
<point>To have more than</point>
<point>one slide</point>
</slide>
</slideshow>
"""

dom = xml.dom.minidom.parseString(document)

def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc

def handleSlideshow(slideshow):
print "<html>"
handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
slides = slideshow.getElementsByTagName("slide")
handleToc(slides)
handleSlides(slides)
print "</html>"

def handleSlides(slides):
for slide in slides:
handleSlide(slide)

def handleSlide(slide):
handleSlideTitle(slide.getElementsByTagName("title")[0])
handlePoints(slide.getElementsByTagName("point"))

def handleSlideshowTitle(title):
print "<title>%s</title>" % getText(title.childNodes)

def handleSlideTitle(title):
print "<h2>%s</h2>" % getText(title.childNodes)

def handlePoints(points):
print "<ul>"
for point in points:
handlePoint(point)
print "</ul>"

def handlePoint(point):
print "<li>%s</li>" % getText(point.childNodes)

def handleToc(slides):
for slide in slides:
title = slide.getElementsByTagName("title")[0]
print "<p>%s</p>" % getText(title.childNodes)

handleSlideshow(dom)
```
Download as text. (minidom-example.txt)


13.6.2.12 Exceptions

dom-pi-objects.html | node438.html | dom-conformance.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.12 Exceptions
New in version 2.1.
The DOM Level 2 recommendation defines a single exception,
DOMException, and a number of constants that allow
applications to determine what sort of error occurred.
DOMException instances carry a code attribute
that provides the appropriate value for the specific exception.
The Python DOM interface provides the constants, but also expands the
set of exceptions so that a specific exception exists for each of the
exception codes defined by the DOM. The implementations must raise
the appropriate specific exception, each of which carries the
appropriate value for the code attribute.
The exception codes defined in the DOM recommendation map to the
exceptions described above according to this table:


13.6.2.1 DOMImplementation Objects

node438.html | node438.html | dom-node-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.1 DOMImplementation Objects
The DOMImplementation interface provides a way for
applications to determine the availability of particular features in
the DOM they are using. DOM Level 2 added the ability to create new
Document and DocumentType objects using the
DOMImplementation as well.


13.6.2.2 Node Objects

dom-implementation-objects.html | node438.html | dom-nodelist-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.2 Node Objects
All of the components of an XML document are subclasses of
Node.


13.6.2.3 NodeList Objects

dom-node-objects.html | node438.html | dom-documenttype-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.3 NodeList Objects
A NodeList represents a sequence of nodes. These objects are
used in two ways in the DOM Core recommendation: the
Element objects provides one as it's list of child nodes, and
the getElementsByTagName() and
getElementsByTagNameNS() methods of Node return
objects with this interface to represent query results.
The DOM Level 2 recommendation defines one method and one attribute
for these objects:
In addition, the Python DOM interface requires that some additional
support is provided to allow NodeList objects to be used as
Python sequences. All NodeList implementations must include
support for __len__() and __getitem__(); this allows
iteration over the NodeList in for statements and
proper support for the len() built-in function.
If a DOM implementation supports modification of the document, the
NodeList implementation must also support the
__setitem__() and __delitem__() methods.


13.7.1 DOM objects

module-xml.dom.minidom.html | module-xml.dom.minidom.html | dom-example.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.7.1 DOM objects
The definition of the DOM API for Python is given as part of the
xml.dom (module-xml.dom.html) module documentation. This section lists the
differences between the API and xml.dom.minidom (module-xml.dom.minidom.html).
The following standard DOM methods have special considerations with
xml.dom.minidom (module-xml.dom.minidom.html):


13.6.2.11 ProcessingInstruction Objects

dom-text-objects.html | node438.html | dom-exceptions.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.11 ProcessingInstruction Objects
Represents a processing instruction in the XML document; this inherits
from the Node interface and cannot have child nodes.


13.6.2.10 Text and CDATASection Objects

dom-comment-objects.html | node438.html | dom-pi-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.2.10 Text and CDATASection Objects
The Text interface represents text in the XML document. If
the parser and DOM implementation support the DOM's XML extension,
portions of the text enclosed in CDATA marked sections are stored in
CDATASection objects. These two interfaces are identical, but
provide different values for the nodeType attribute.
These interfaces extend the Node interface. They cannot have
child nodes.
Note:
The use of a CDATASection node does not
indicate that the node represents a complete CDATA marked section,
only that the content of the node was part of a CDATA section. A
single CDATA section may be represented by more than one node in the
document tree. There is no way to determine whether two adjacent
CDATASection nodes represent different CDATA marked sections.


13.6.3.1 Type Mapping

dom-conformance.html | dom-conformance.html | dom-accessor-methods.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
### 13.6.3.1 Type Mapping
The primitive IDL types used in the DOM specification are mapped to
Python types according to the following table.
Additionally, the DOMString defined in the recommendation is
mapped to a Python string or Unicode string. Applications should
be able to handle Unicode whenever a string is returned from the DOM.
The IDL null value is mapped to `None`, which may be
accepted or provided by the implementation whenever null is
allowed by the API.


13.8.1 DOMEventStream Objects

module-xml.dom.pulldom.html | module-xml.dom.pulldom.html | module-xml.sax.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.8.1 DOMEventStream Objects


13.10.2 DTDHandler Objects

content-handler-objects.html | module-xml.sax.handler.html | entity-resolver-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.10.2 DTDHandler Objects
DTDHandler instances provide the following methods:


node197.html | module-locale.html | module-gettext.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 6.24.2 For extension writers and programs that embed Python
Extension modules should never call setlocale(), except to
find out what the current locale is. But since the return value can
only be used portably to restore it, that is not very useful (except
perhaps to find out whether or not the locale is "C").
When Python is embedded in an application, if the application sets the
locale to something specific before initializing Python, that is
generally okay, and Python will use whatever locale is set,
except that the LC_NUMERIC locale should always be
"C".
The setlocale() function in the locale module
gives the Python programmer the impression that you can manipulate the
LC_NUMERIC locale setting, but this not the case at the C
level: C code will always find that the LC_NUMERIC locale
setting is "C". This is because too much would break when the
decimal point character is set to something else than a period
(e.g. the Python parser would break). Caveat: threads that run
without holding Python's global interpreter lock may occasionally find
that the numeric locale setting differs; this is because the only
portable way to implement this feature is to set the numeric locale
settings to what the user requests, extract the relevant
characteristics, and then restore the "C" numeric locale.


13.10.3 EntityResolver Objects

dtd-handler-objects.html | module-xml.sax.handler.html | sax-error-handler.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.10.3 EntityResolver Objects


7.5.5 Event Objects

semaphore-examples.html | module-threading.html | thread-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 7.5.5 Event Objects
This is one of the simplest mechanisms for communication between
threads: one thread signals an event and one or more other threads
are waiting for it.
An event object manages an internal flag that can be set to true with
the set() method and reset to false with the clear() method. The
wait() method blocks until the flag is true.


3.21.1 Examples

module-imp.html | module-imp.html | module-code.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.21.1 Examples
The following function emulates what was the standard import statement
up to Python 1.4 (no hierarchical module names). (This
implementation wouldn't work in that version, since
find_module() has been extended and
load_module() has been added in 1.4.)
```text

import imp
import sys

def __import__(name, globals=None, locals=None, fromlist=None):
# Fast path: see if the module has already been imported.
try:
return sys.modules[name]
except KeyError:
pass

# If any of the following calls raises an exception,
# there's a problem we can't handle -- let the caller handle it.

fp, pathname, description = imp.find_module(name)

try:
return imp.load_module(name, fp, pathname, description)
finally:
# Since we may exit via an exception, close fp explicitly.
if fp:
fp.close()
```


13.5.4 Content Model Descriptions

expat-example.html | module-xml.parsers.expat.html | expat-errors.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.5.4 Content Model Descriptions
Content modules are described using nested tuples. Each tuple
contains four values: the type, the quantifier, the name, and a tuple
of children. Children are simply additional content module
descriptions.
The values of the first two fields are constants defined in the
`model` object of the xml.parsers.expat module. These
constants can be collected in two groups: the model type group and the
quantifier group.
The constants in the model type group are:
The constants in the quantifier group are:


13.5.5 Expat error constants

expat-content-models.html | module-xml.parsers.expat.html | module-xml.dom.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.5.5 Expat error constants
The following constants are provided in the `errors` object of
the xml.parsers.expat (module-xml.parsers.expat.html) module. These constants are useful
in interpreting some of the attributes of the ExpatError
exception objects raised when an error has occurred.
The `errors` object has the following attributes:


13.5.3 Example

expaterror-objects.html | module-xml.parsers.expat.html | expat-content-models.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.5.3 Example
The following program defines three handlers that just print out their
arguments.
```text

import xml.parsers.expat

# 3 handler functions
def start_element(name, attrs):
print 'Start element:', name, attrs
def end_element(name):
print 'End element:', name
def char_data(data):
print 'Character data:', repr(data)

p = xml.parsers.expat.ParserCreate()

p.StartElementHandler = start_element
p.EndElementHandler = end_element
p.CharacterDataHandler = char_data

p.Parse("""<?xml version="1.0"?>
<parent id="top"><child1 name="paul">Text goes here</child1>
<child2 name="fred">More text</child2>
</parent>""")
```
The output from this program is:
```text

Start element: parent {'id': 'top'}
Start element: child1 {'name': 'paul'}
Character data: 'Text goes here'
End element: child1
Character data: '\n'
Start element: child2 {'name': 'fred'}
Character data: 'More text'
End element: child2
Character data: '\n'
End element: parent
```


13.5.2 ExpatError Exceptions

xmlparser-objects.html | module-xml.parsers.expat.html | expat-example.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.5.2 ExpatError Exceptions
ExpatError exceptions have a number of interesting
attributes:


11.20.5 Fault Objects

binary-objects.html | module-xmlrpclib.html | protocol-error-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.20.5 Fault Objects
A Fault object encapsulates the content of an XML-RPC fault tag.
Fault objects have the following members:


11.5.15 FileHandler Objects

https-handler-objects.html | module-urllib2.html | ftp-handler-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.5.15 FileHandler Objects


18.4.1 Functions Defined in Module fl

module-fl.html | module-fl.html | form-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 18.4.1 Functions Defined in Module fl
Module fl defines the following functions. For more
information about what they do, see the description of the equivalent
C function in the FORMS documentation:


20.4.2 Form Objects

node589.html | module-fl.html | forms-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 20.4.2 Form Objects
Form objects (returned by make_form() above) have the
following methods. Each method corresponds to a C function whose
name is prefixed with "fl_"; and whose first argument is a form
pointer; please refer to the official FORMS documentation for
descriptions.
All the add_*() methods return a Python object representing
the FORMS object. Methods of FORMS objects are described below. Most
kinds of FORMS object also have some methods specific to that kind;
these methods are listed here.
Form objects have the following data attributes; see the FORMS
documentation:


12.1.2 Formatter Implementations

formatter-interface.html | module-formatter.html | writer-interface.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.1.2 Formatter Implementations
Two implementations of formatter objects are provided by this module.
Most applications may use one of these classes without modification or
subclassing.


12.1.1 The Formatter Interface

module-formatter.html | module-formatter.html | formatter-impls.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.1.1 The Formatter Interface
Interfaces to create formatters are dependent on the specific
formatter class being instantiated. The interfaces described below
are the required interfaces which all formatters must support once
initialized.
One data element is defined at the module level:
The following attributes are defined for formatter instance objects:


20.4.3 FORMS Objects

form-objects.html | module-fl.html | module-fl-constants.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 20.4.3 FORMS Objects
Besides methods specific to particular kinds of FORMS objects, all
FORMS objects also have the following methods:
FORMS objects have these data attributes; see the FORMS documentation:


3.4.1 Example

module-fpectl.html | module-fpectl.html | node41.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.4.1 Example
The following example demonstrates how to start up and test operation of
the fpectl module.
```text

>>> import fpectl
>>> import fpetest
>>> fpectl.turnon_sigfpe()
>>> fpetest.test()
overflow PASS
FloatingPointError: Overflow

div by 0 PASS
FloatingPointError: Division by zero
[ more output from test elided ]
>>> import math
>>> math.exp(1000)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
FloatingPointError: in math_1
```