Back to module index
Go to module by name
formatter
Generic output formatting.
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.
Classes
AbstractFormatter
The standard formatter.
This implementation has demonstrated wide applicability to many writers,
and may be used directly in most circumstances. It has been used to
implement a full-featured World Wide Web browser.
add_flowing_data(self, data)
add_hor_rule(self, *args, **kw)
add_label_data(self, format, counter, blankline=None)
add_line_break(self)
add_literal_data(self, data)
assert_line_data(self, flag=1)
end_paragraph(self, blankline)
flush_softspace(self)
format_counter(self, format, counter)
format_letter(self, case, counter)
format_roman(self, case, counter)
pop_alignment(self)
pop_font(self)
pop_margin(self)
pop_style(self, n=1)
push_alignment(self, align)
push_font(self, font)
push_margin(self, margin)
push_style(self, *styles)
set_spacing(self, spacing)
AbstractWriter
A writer which can be used in debugging formatters, but not much else.
Each method simply announces itself by printing its name and
arguments on standard output.
flush(self)
new_alignment(self, align)
new_font(self, font)
new_margin(self, margin, level)
new_spacing(self, spacing)
new_styles(self, styles)
send_flowing_data(self, data)
send_hor_rule(self, *args, **kw)
send_label_data(self, data)
send_line_break(self)
send_literal_data(self, data)
send_paragraph(self, blankline)
DumbWriter
Simple writer class which writes output on the file object passed in
as the file parameter or, if file is omitted, on standard output. The
output is simply word-wrapped to the number of columns specified by
the maxcol parameter. This class is suitable for reflowing a sequence
of paragraphs.
flush(self)
new_alignment(self, align)
new_font(self, font)
new_margin(self, margin, level)
new_spacing(self, spacing)
new_styles(self, styles)
reset(self)
send_flowing_data(self, data)
send_hor_rule(self, *args, **kw)
send_label_data(self, data)
send_line_break(self)
send_literal_data(self, data)
send_paragraph(self, blankline)
NullFormatter
A formatter which does nothing.
If the writer parameter is omitted, a NullWriter instance is created.
No methods of the writer are called by NullFormatter instances.
Implementations should inherit from this class if implementing a writer
interface but don't need to inherit any implementation.
add_flowing_data(self, data)
add_hor_rule(self, *args, **kw)
add_label_data(self, format, counter, blankline=None)
add_line_break(self)
add_literal_data(self, data)
assert_line_data(self, flag=1)
end_paragraph(self, blankline)
flush_softspace(self)
pop_alignment(self)
pop_font(self)
pop_margin(self)
pop_style(self, n=1)
push_alignment(self, align)
push_font(self, x)
push_margin(self, margin)
push_style(self, *styles)
set_spacing(self, spacing)
NullWriter
Minimal writer interface to use in testing & inheritance.
A writer which only provides the interface definition; no actions are
taken on any methods. This should be the base class for all writers
which do not need to inherit any implementation methods.
flush(self)
new_alignment(self, align)
new_font(self, font)
new_margin(self, margin, level)
new_spacing(self, spacing)
new_styles(self, styles)
send_flowing_data(self, data)
send_hor_rule(self, *args, **kw)
send_label_data(self, data)
send_line_break(self)
send_literal_data(self, data)
send_paragraph(self, blankline)
Functions
test
test(file=None)
Other members
AS_IS = None
Modules
sys
warnings