annotate Lib/formatter.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 751c6dd71b5e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11708
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
1 """Generic output formatting.
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
2
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
3 Formatter objects transform an abstract flow of formatting events into
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
4 specific output events on writer objects. Formatters manage several stack
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
5 structures to allow various properties of a writer object to be changed and
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
6 restored; writers need not be able to handle relative changes nor any sort
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
7 of ``change back'' operation. Specific writer properties which may be
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
8 controlled via formatter objects are horizontal alignment, font, and left
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
9 margin indentations. A mechanism is provided which supports providing
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
10 arbitrary, non-exclusive style settings to a writer as well. Additional
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
11 interfaces facilitate formatting events which are not reversible, such as
15867
f5a3d98a35bc Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11708
diff changeset
12 paragraph separation.
11708
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
13
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
14 Writer objects encapsulate device interfaces. Abstract devices, such as
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
15 file formats, are supported as well as physical devices. The provided
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
16 implementations all work with abstract devices. The interface makes
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
17 available mechanisms for setting the properties which formatter objects
15867
f5a3d98a35bc Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11708
diff changeset
18 manage and inserting data into the output.
11708
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
19 """
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 9850
diff changeset
20
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 import sys
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 AS_IS = None
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
3150
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
27 class NullFormatter:
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
28 """A formatter which does nothing.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
29
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
30 If the writer parameter is omitted, a NullWriter instance is created.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
31 No methods of the writer are called by NullFormatter instances.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
32
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
33 Implementations should inherit from this class if implementing a writer
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
34 interface but don't need to inherit any implementation.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
35
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
36 """
3150
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
37
4360
dbf2737d2c81 Add provisions to set the (to be documented!) instance variable
Guido van Rossum <guido@python.org>
parents: 4147
diff changeset
38 def __init__(self, writer=None):
23612
3caee2958387 Replace boolean test with is None
Raymond Hettinger <python@rcn.com>
parents: 23565
diff changeset
39 if writer is None:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
40 writer = NullWriter()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
41 self.writer = writer
3150
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
42 def end_paragraph(self, blankline): pass
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
43 def add_line_break(self): pass
4385
70cc238d563e (formatter.py): Simplify NullFormatter definition of add_hor_rule() to match
Fred Drake <fdrake@acm.org>
parents: 4360
diff changeset
44 def add_hor_rule(self, *args, **kw): pass
70cc238d563e (formatter.py): Simplify NullFormatter definition of add_hor_rule() to match
Fred Drake <fdrake@acm.org>
parents: 4360
diff changeset
45 def add_label_data(self, format, counter, blankline=None): pass
3150
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
46 def add_flowing_data(self, data): pass
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
47 def add_literal_data(self, data): pass
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
48 def flush_softspace(self): pass
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
49 def push_alignment(self, align): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
50 def pop_alignment(self): pass
3150
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
51 def push_font(self, x): pass
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
52 def pop_font(self): pass
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
53 def push_margin(self, margin): pass
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
54 def pop_margin(self): pass
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
55 def set_spacing(self, spacing): pass
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
56 def push_style(self, *styles): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
57 def pop_style(self, n=1): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
58 def assert_line_data(self, flag=1): pass
3150
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
59
490be865aa0d added NullFormatter
Guido van Rossum <guido@python.org>
parents: 3130
diff changeset
60
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 class AbstractFormatter:
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
62 """The standard formatter.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
63
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
64 This implementation has demonstrated wide applicability to many writers,
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
65 and may be used directly in most circumstances. It has been used to
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
66 implement a full-featured World Wide Web browser.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
67
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
68 """
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
4147
30f1c01f3865 Three sets of changes from Grail:
Guido van Rossum <guido@python.org>
parents: 3653
diff changeset
70 # Space handling policy: blank spaces at the boundary between elements
30f1c01f3865 Three sets of changes from Grail:
Guido van Rossum <guido@python.org>
parents: 3653
diff changeset
71 # are handled by the outermost context. "Literal" data is not checked
30f1c01f3865 Three sets of changes from Grail:
Guido van Rossum <guido@python.org>
parents: 3653
diff changeset
72 # to determine context, so spaces in literal data are handled directly
30f1c01f3865 Three sets of changes from Grail:
Guido van Rossum <guido@python.org>
parents: 3653
diff changeset
73 # in all circumstances.
30f1c01f3865 Three sets of changes from Grail:
Guido van Rossum <guido@python.org>
parents: 3653
diff changeset
74
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 def __init__(self, writer):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
76 self.writer = writer # Output device
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
77 self.align = None # Current alignment
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
78 self.align_stack = [] # Alignment stack
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
79 self.font_stack = [] # Font state
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
80 self.margin_stack = [] # Margin state
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
81 self.spacing = None # Vertical spacing state
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
82 self.style_stack = [] # Other state, e.g. color
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
83 self.nospace = 1 # Should leading space be suppressed
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
84 self.softspace = 0 # Should a space be inserted
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
85 self.para_end = 1 # Just ended a paragraph
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
86 self.parskip = 0 # Skipped space between paragraphs?
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
87 self.hard_break = 1 # Have a hard break
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
88 self.have_label = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 def end_paragraph(self, blankline):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
91 if not self.hard_break:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
92 self.writer.send_line_break()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
93 self.have_label = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
94 if self.parskip < blankline and not self.have_label:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
95 self.writer.send_paragraph(blankline - self.parskip)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
96 self.parskip = blankline
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
97 self.have_label = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
98 self.hard_break = self.nospace = self.para_end = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
99 self.softspace = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 def add_line_break(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
102 if not (self.hard_break or self.para_end):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
103 self.writer.send_line_break()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
104 self.have_label = self.parskip = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
105 self.hard_break = self.nospace = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
106 self.softspace = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
108 def add_hor_rule(self, *args, **kw):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
109 if not self.hard_break:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
110 self.writer.send_line_break()
28089
14f65d661084 Get rid of many apply() calls.
Guido van Rossum <guido@python.org>
parents: 23645
diff changeset
111 self.writer.send_hor_rule(*args, **kw)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
112 self.hard_break = self.nospace = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
113 self.have_label = self.para_end = self.softspace = self.parskip = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
115 def add_label_data(self, format, counter, blankline = None):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
116 if self.have_label or not self.hard_break:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
117 self.writer.send_line_break()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
118 if not self.para_end:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
119 self.writer.send_paragraph((blankline and 1) or 0)
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23612
diff changeset
120 if isinstance(format, str):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
121 self.writer.send_label_data(self.format_counter(format, counter))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
122 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
123 self.writer.send_label_data(format)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
124 self.nospace = self.have_label = self.hard_break = self.para_end = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
125 self.softspace = self.parskip = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 def format_counter(self, format, counter):
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 label = ''
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 for c in format:
17801
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
130 if c == '1':
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
131 label = label + ('%d' % counter)
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
132 elif c in 'aA':
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
133 if counter > 0:
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
134 label = label + self.format_letter(c, counter)
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
135 elif c in 'iI':
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
136 if counter > 0:
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
137 label = label + self.format_roman(c, counter)
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
138 else:
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
139 label = label + c
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 return label
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 def format_letter(self, case, counter):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
143 label = ''
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
144 while counter > 0:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
145 counter, x = divmod(counter-1, 26)
17801
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
146 # This makes a strong assumption that lowercase letters
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
147 # and uppercase letters form two contiguous blocks, with
5597d4bcde07 Remove a bare try/except completely -- it just did not make sense!
Fred Drake <fdrake@acm.org>
parents: 16514
diff changeset
148 # letters in order!
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
149 s = chr(ord(case) + x)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
150 label = s + label
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
151 return label
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 def format_roman(self, case, counter):
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 ones = ['i', 'x', 'c', 'm']
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 fives = ['v', 'l', 'd']
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
156 label, index = '', 0
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
157 # This will die of IndexError when counter is too big
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 while counter > 0:
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 counter, x = divmod(counter, 10)
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 if x == 9:
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
161 label = ones[index] + ones[index+1] + label
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 elif x == 4:
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
163 label = ones[index] + fives[index] + label
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 else:
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 if x >= 5:
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 s = fives[index]
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 x = x-5
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 else:
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 s = ''
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 s = s + ones[index]*x
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
171 label = s + label
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 index = index + 1
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
173 if case == 'I':
16514
90c600a819e9 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 15867
diff changeset
174 return label.upper()
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 return label
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23612
diff changeset
177 def add_flowing_data(self, data):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
178 if not data: return
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23612
diff changeset
179 prespace = data[:1].isspace()
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23612
diff changeset
180 postspace = data[-1:].isspace()
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23612
diff changeset
181 data = " ".join(data.split())
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
182 if self.nospace and not data:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
183 return
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
184 elif prespace or self.softspace:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
185 if not data:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
186 if not self.nospace:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
187 self.softspace = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
188 self.parskip = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
189 return
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
190 if not self.nospace:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
191 data = ' ' + data
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
192 self.hard_break = self.nospace = self.para_end = \
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
193 self.parskip = self.have_label = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
194 self.softspace = postspace
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
195 self.writer.send_flowing_data(data)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
196
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 def add_literal_data(self, data):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
198 if not data: return
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
199 if self.softspace:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
200 self.writer.send_flowing_data(" ")
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
201 self.hard_break = data[-1:] == '\n'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
202 self.nospace = self.para_end = self.softspace = \
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
203 self.parskip = self.have_label = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
204 self.writer.send_literal_data(data)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
3130
dcf2a37e73d9 add flush_softspace() interface
Guido van Rossum <guido@python.org>
parents: 2916
diff changeset
206 def flush_softspace(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
207 if self.softspace:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
208 self.hard_break = self.para_end = self.parskip = \
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
209 self.have_label = self.softspace = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
210 self.nospace = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
211 self.writer.send_flowing_data(' ')
3130
dcf2a37e73d9 add flush_softspace() interface
Guido van Rossum <guido@python.org>
parents: 2916
diff changeset
212
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
213 def push_alignment(self, align):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
214 if align and align != self.align:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
215 self.writer.new_alignment(align)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
216 self.align = align
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
217 self.align_stack.append(align)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
218 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
219 self.align_stack.append(self.align)
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
220
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
221 def pop_alignment(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
222 if self.align_stack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
223 del self.align_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
224 if self.align_stack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
225 self.align = align = self.align_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
226 self.writer.new_alignment(align)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
227 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
228 self.align = None
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
229 self.writer.new_alignment(None)
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
230
63528
751c6dd71b5e Merged revisions 77310-77311 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 44847
diff changeset
231 def push_font(self, font):
751c6dd71b5e Merged revisions 77310-77311 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 44847
diff changeset
232 size, i, b, tt = font
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
233 if self.softspace:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
234 self.hard_break = self.para_end = self.softspace = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
235 self.nospace = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
236 self.writer.send_flowing_data(' ')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
237 if self.font_stack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
238 csize, ci, cb, ctt = self.font_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
239 if size is AS_IS: size = csize
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
240 if i is AS_IS: i = ci
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
241 if b is AS_IS: b = cb
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
242 if tt is AS_IS: tt = ctt
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
243 font = (size, i, b, tt)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
244 self.font_stack.append(font)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
245 self.writer.new_font(font)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 def pop_font(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
248 if self.font_stack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
249 del self.font_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
250 if self.font_stack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
251 font = self.font_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
252 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
253 font = None
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
254 self.writer.new_font(font)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 def push_margin(self, margin):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
257 self.margin_stack.append(margin)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
258 fstack = filter(None, self.margin_stack)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
259 if not margin and fstack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
260 margin = fstack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
261 self.writer.new_margin(margin, len(fstack))
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 def pop_margin(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
264 if self.margin_stack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
265 del self.margin_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
266 fstack = filter(None, self.margin_stack)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
267 if fstack:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
268 margin = fstack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
269 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
270 margin = None
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
271 self.writer.new_margin(margin, len(fstack))
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
272
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 def set_spacing(self, spacing):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
274 self.spacing = spacing
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
275 self.writer.new_spacing(spacing)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
276
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
277 def push_style(self, *styles):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
278 if self.softspace:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
279 self.hard_break = self.para_end = self.softspace = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
280 self.nospace = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
281 self.writer.send_flowing_data(' ')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
282 for style in styles:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
283 self.style_stack.append(style)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
284 self.writer.new_styles(tuple(self.style_stack))
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
285
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
286 def pop_style(self, n=1):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
287 del self.style_stack[-n:]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
288 self.writer.new_styles(tuple(self.style_stack))
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
290 def assert_line_data(self, flag=1):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
291 self.nospace = self.hard_break = not flag
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
292 self.para_end = self.parskip = self.have_label = 0
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
293
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
294
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
295 class NullWriter:
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
296 """Minimal writer interface to use in testing & inheritance.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
297
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
298 A writer which only provides the interface definition; no actions are
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
299 taken on any methods. This should be the base class for all writers
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
300 which do not need to inherit any implementation methods.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
301
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
302 """
3653
5309cef8c169 change DumbWriter to derive from NullWriter
Guido van Rossum <guido@python.org>
parents: 3650
diff changeset
303 def __init__(self): pass
4848
52695efdf22c (formatter.py): Add a flush() method to the writer interface. This really
Fred Drake <fdrake@acm.org>
parents: 4385
diff changeset
304 def flush(self): pass
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
305 def new_alignment(self, align): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
306 def new_font(self, font): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
307 def new_margin(self, margin, level): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
308 def new_spacing(self, spacing): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
309 def new_styles(self, styles): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
310 def send_paragraph(self, blankline): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
311 def send_line_break(self): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
312 def send_hor_rule(self, *args, **kw): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
313 def send_label_data(self, data): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
314 def send_flowing_data(self, data): pass
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
315 def send_literal_data(self, data): pass
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
316
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
317
3653
5309cef8c169 change DumbWriter to derive from NullWriter
Guido van Rossum <guido@python.org>
parents: 3650
diff changeset
318 class AbstractWriter(NullWriter):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
319 """A writer which can be used in debugging formatters, but not much else.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
320
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
321 Each method simply announces itself by printing its name and
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
322 arguments on standard output.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
323
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
324 """
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
325
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
326 def new_alignment(self, align):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
327 print "new_alignment(%r)" % (align,)
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
328
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 def new_font(self, font):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
330 print "new_font(%r)" % (font,)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
331
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 def new_margin(self, margin, level):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
333 print "new_margin(%r, %d)" % (margin, level)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
334
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 def new_spacing(self, spacing):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
336 print "new_spacing(%r)" % (spacing,)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 def new_styles(self, styles):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
339 print "new_styles(%r)" % (styles,)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 def send_paragraph(self, blankline):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
342 print "send_paragraph(%r)" % (blankline,)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 def send_line_break(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
345 print "send_line_break()"
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
346
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
347 def send_hor_rule(self, *args, **kw):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
348 print "send_hor_rule()"
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
349
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 def send_label_data(self, data):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
351 print "send_label_data(%r)" % (data,)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
352
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 def send_flowing_data(self, data):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
354 print "send_flowing_data(%r)" % (data,)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 def send_literal_data(self, data):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28089
diff changeset
357 print "send_literal_data(%r)" % (data,)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
359
3653
5309cef8c169 change DumbWriter to derive from NullWriter
Guido van Rossum <guido@python.org>
parents: 3650
diff changeset
360 class DumbWriter(NullWriter):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
361 """Simple writer class which writes output on the file object passed in
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
362 as the file parameter or, if file is omitted, on standard output. The
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
363 output is simply word-wrapped to the number of columns specified by
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
364 the maxcol parameter. This class is suitable for reflowing a sequence
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
365 of paragraphs.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
366
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 19218
diff changeset
367 """
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
368
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 def __init__(self, file=None, maxcol=72):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
370 self.file = file or sys.stdout
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
371 self.maxcol = maxcol
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
372 NullWriter.__init__(self)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
373 self.reset()
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 def reset(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
376 self.col = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
377 self.atbreak = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
378
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 def send_paragraph(self, blankline):
9850
ec80ad25ca86 DumbWriter.send_paragraph(): Fix problem with DumbWriter reported to
Fred Drake <fdrake@acm.org>
parents: 7755
diff changeset
380 self.file.write('\n'*blankline)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
381 self.col = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
382 self.atbreak = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 def send_line_break(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
385 self.file.write('\n')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
386 self.col = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
387 self.atbreak = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
388
3650
5d6fe145f773 Many improvements dure to Fred Drake
Guido van Rossum <guido@python.org>
parents: 3383
diff changeset
389 def send_hor_rule(self, *args, **kw):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
390 self.file.write('\n')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
391 self.file.write('-'*self.maxcol)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
392 self.file.write('\n')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
393 self.col = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
394 self.atbreak = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 def send_literal_data(self, data):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
397 self.file.write(data)
16514
90c600a819e9 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 15867
diff changeset
398 i = data.rfind('\n')
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
399 if i >= 0:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
400 self.col = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
401 data = data[i+1:]
16514
90c600a819e9 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 15867
diff changeset
402 data = data.expandtabs()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
403 self.col = self.col + len(data)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
404 self.atbreak = 0
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 def send_flowing_data(self, data):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
407 if not data: return
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23612
diff changeset
408 atbreak = self.atbreak or data[0].isspace()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
409 col = self.col
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
410 maxcol = self.maxcol
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
411 write = self.file.write
16514
90c600a819e9 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 15867
diff changeset
412 for word in data.split():
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
413 if atbreak:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
414 if col + len(word) >= maxcol:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
415 write('\n')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
416 col = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
417 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
418 write(' ')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
419 col = col + 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
420 write(word)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
421 col = col + len(word)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
422 atbreak = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
423 self.col = col
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23612
diff changeset
424 self.atbreak = data[-1].isspace()
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
425
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
426
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 def test(file = None):
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 w = DumbWriter()
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 f = AbstractFormatter(w)
23612
3caee2958387 Replace boolean test with is None
Raymond Hettinger <python@rcn.com>
parents: 23565
diff changeset
430 if file is not None:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
431 fp = open(file)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 elif sys.argv[1:]:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
433 fp = open(sys.argv[1])
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
435 fp = sys.stdin
44847
a6b190b0cf06 #1726198: replace while 1: fp.readline() with file iteration.
Georg Brandl <georg@python.org>
parents: 34130
diff changeset
436 for line in fp:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
437 if line == '\n':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
438 f.end_paragraph(1)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
439 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6515
diff changeset
440 f.add_flowing_data(line)
2916
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 f.end_paragraph(0)
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
442
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
443
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 if __name__ == '__main__':
764b0fc867a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 test()