home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
!ibrowse
/
files
/
pylibi-7
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1996-11-14
|
52KB
|
903 lines
This is Info file pylibi, produced by Makeinfo-1.55 from the input file
lib.texi.
This file describes the built-in types, exceptions and functions and the
standard modules that come with the Python system. It assumes basic
knowledge about the Python language. For an informal introduction to
the language, see the Python Tutorial. The Python Reference Manual
gives a more formal definition of the language. (These manuals are not
yet available in INFO or Texinfo format.)
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or CNRI
not be used in advertising or publicity pertaining to distribution of
the software without specific, written prior permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
File: pylibi, Node: formatter, Next: rfc822, Prev: htmllib, Up: Internet and WWW
Standard Module `formatter'
===========================
This module supports two interface definitions, each with mulitple
implementations. The *formatter* interface is used by the `HTMLParser'
class of the `htmllib' module, and the *writer* interface is required
by the formatter interface.
Formatter objects transform an abstract flow of formatting events into
specific output events on writer objects. Formatters manage several
stack structures to allow various properties of a writer object to be
changed and restored; writers need not be able to handle relative
changes nor any sort of "change back" operation. Specific writer
properties which may be controlled via formatter objects are horizontal
alignment, font, and left margin indentations. A mechanism is provided
which supports providing arbitrary, non-exclusive style settings to a
writer as well. Additional interfaces facilitate formatting events
which are not reversible, such as paragraph separation.
Writer objects encapsulate device interfaces. Abstract devices, such
as file formats, are supported as well as physical devices. The
provided implementations all work with abstract devices. The interface
makes available mechanisms for setting the properties which formatter
objects manage and inserting data into the output.
* Menu:
* The Formatter Interface::
* Formatter Implementations::
* The Writer Interface::
* Writer Implementations::
File: pylibi, Node: The Formatter Interface, Next: Formatter Implementations, Prev: formatter, Up: formatter
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:
- data of module formatter: AS_IS
Value which can be used in the font specification passed to the
`push_font()' method described below, or as the new value to any
other `push_PROPERTY()' method. Pushing the `AS_IS' value allows
the corresponding `pop_PROPERTY()' method to be called without
having to track whether the property was changed.
The following attributes are defined for formatter instance objects:
- data of formatter object data: writer
The writer instance with which the formatter interacts.
- Method on formatter object: end_paragraph (BLANKLINES)
Close any open paragraphs and insert at least `blanklines' before
the next paragraph.
- Method on formatter object: add_line_break ()
Add a hard line break if one does not already exist. This does not
break the logical paragraph.
- Method on formatter object: add_hor_rule (*ARGS, **KW)
Insert a horizontal rule in the output. A hard break is inserted
if there is data in the current paragraph, but the logical
paragraph is not broken. The arguments and keywords are passed on
to the writer's `send_line_break()' method.
- Method on formatter object: add_flowing_data (DATA)
Provide data which should be formatted with collapsed whitespaces.
Whitespace from preceeding and successive calls to
`add_flowing_data()' is considered as well when the whitespace
collapse is performed. The data which is passed to this method is
expected to be word-wrapped by the output device. Note that any
word-wrapping still must be performed by the writer object due to
the need to rely on device and font information.
- Method on formatter object: add_literal_data (DATA)
Provide data which should be passed to the writer unchanged.
Whitespace, including newline and tab characters, are considered
legal in the value of `data'.
- Method on formatter object: add_label_data (FORMAT, COUNTER)
Insert a label which should be placed to the left of the current
left margin. This should be used for constructing bulleted or
numbered lists. If the `format' value is a string, it is
interpreted as a format specification for `counter', which should
be an integer. The result of this formatting becomes the value of
the label; if `format' is not a string it is used as the label
value directly. The label value is passed as the only argument to
the writer's `send_label_data()' method. Interpretation of
non-string label values is dependent on the associated writer.
Format specifications are strings which, in combination with a
counter value, are used to compute label values. Each character
in the format string is copied to the label value, with some
characters recognized to indicate a transform on the counter
value. Specifically, the character "`1'" represents the counter
value formatter as an arabic number, the characters "`A'" and
"`a'" represent alphabetic representations of the counter value in
upper and lower case, respectively, and "`I'" and "`i'" represent
the counter value in Roman numerals, in upper and lower case.
Note that the alphabetic and roman transforms require that the
counter value be greater than zero.
- Method on formatter object: flush_softspace ()
Send any pending whitespace buffered from a previous call to
`add_flowing_data()' to the associated writer object. This should
be called before any direct manipulation of the writer object.
- Method on formatter object: push_alignment (ALIGN)
Push a new alignment setting onto the alignment stack. This may be
`AS_IS' if no change is desired. If the alignment value is
changed from the previous setting, the writer's `new_alignment()'
method is called with the `align' value.
- Method on formatter object: pop_alignment ()
Restore the previous alignment.
- Method on formatter object: push_font ((SIZE, ITALIC, BOLD,
TELETYPE))
Change some or all font properties of the writer object.
Properties which are not set to `AS_IS' are set to the values
passed in while others are maintained at their current settings.
The writer's `new_font()' method is called with the fully resolved
font specification.
- Method on formatter object: pop_font ()
Restore the previous font.
- Method on formatter object: push_mar