annotate Lib/htmllib.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 0bf08de339a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
1 """HTML 2.0 parser.
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
3 See the HTML 2.0 specification:
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
4 http://www.w3.org/hypertext/WWW/MarkUp/html-spec/html-spec_toc.html
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
5 """
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
47433
0bf08de339a0 Deprecate htmllib and sgmllib for 3.0.
Georg Brandl <georg@python.org>
parents: 47177
diff changeset
7 from warnings import warnpy3k
0bf08de339a0 Deprecate htmllib and sgmllib for 3.0.
Georg Brandl <georg@python.org>
parents: 47177
diff changeset
8 warnpy3k("the htmllib module has been removed in Python 3.0",
0bf08de339a0 Deprecate htmllib and sgmllib for 3.0.
Georg Brandl <georg@python.org>
parents: 47177
diff changeset
9 stacklevel=2)
0bf08de339a0 Deprecate htmllib and sgmllib for 3.0.
Georg Brandl <georg@python.org>
parents: 47177
diff changeset
10 del warnpy3k
0bf08de339a0 Deprecate htmllib and sgmllib for 3.0.
Georg Brandl <georg@python.org>
parents: 47177
diff changeset
11
33435
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
12 import sgmllib
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
14 from formatter import AS_IS
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
33435
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
16 __all__ = ["HTMLParser", "HTMLParseError"]
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
17
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
18
33435
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
19 class HTMLParseError(sgmllib.SGMLParseError):
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
20 """Error raised when an HTML document can't be parsed."""
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
21
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
22
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
23 class HTMLParser(sgmllib.SGMLParser):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
24 """This is the basic HTML parser class.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
25
30797
7e9314926dbe Docstring fix: XHTML 1.0 entities are supported
Andrew M. Kuchling <amk@amk.ca>
parents: 30418
diff changeset
26 It supports all entity names required by the XHTML 1.0 Recommendation.
7e9314926dbe Docstring fix: XHTML 1.0 entities are supported
Andrew M. Kuchling <amk@amk.ca>
parents: 30418
diff changeset
27 It also defines handlers for all HTML 2.0 and many HTML 3.0 and 3.2
7e9314926dbe Docstring fix: XHTML 1.0 entities are supported
Andrew M. Kuchling <amk@amk.ca>
parents: 30418
diff changeset
28 elements.
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
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: 17795
diff changeset
30 """
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
31
47177
454d38c1f47e revert creation of the html.entities and html.parser modules
Fred Drake <fdrake@acm.org>
parents: 47143
diff changeset
32 from htmlentitydefs import entitydefs
3125
90566c9c189f entity definitions from HTML 2.0 std
Guido van Rossum <guido@python.org>
parents: 3119
diff changeset
33
3119
1071d16c930c added verbose option; added ismap/align/width/height to handle_image args
Guido van Rossum <guido@python.org>
parents: 3065
diff changeset
34 def __init__(self, formatter, verbose=0):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
35 """Creates an instance of the HTMLParser class.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
36
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
37 The formatter parameter is the formatter instance associated with
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
38 the parser.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
39
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
40 """
33435
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
41 sgmllib.SGMLParser.__init__(self, verbose)
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
42 self.formatter = formatter
30418
c68eb4d4b787 Patch #793021: Implement htmllib.HTMLParser.reset. Fixes #711632.
Martin v. Löwis <martin@v.loewis.de>
parents: 23565
diff changeset
43
33435
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
44 def error(self, message):
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
45 raise HTMLParseError(message)
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
46
30418
c68eb4d4b787 Patch #793021: Implement htmllib.HTMLParser.reset. Fixes #711632.
Martin v. Löwis <martin@v.loewis.de>
parents: 23565
diff changeset
47 def reset(self):
33435
30697f446286 clean up the API a little; exceptions are defined by this module
Fred Drake <fdrake@acm.org>
parents: 30797
diff changeset
48 sgmllib.SGMLParser.reset(self)
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
49 self.savedata = None
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
50 self.isindex = 0
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
51 self.title = None
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
52 self.base = None
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
53 self.anchor = None
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
54 self.anchorlist = []
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
55 self.nofill = 0
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
56 self.list_stack = []
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
57
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
58 # ------ Methods used internally; some may be overridden
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
59
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
60 # --- Formatter interface, taking care of 'savedata' mode;
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
61 # shouldn't need to be overridden
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
62
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
63 def handle_data(self, data):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
64 if self.savedata is not None:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
65 self.savedata = self.savedata + data
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
66 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
67 if self.nofill:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
68 self.formatter.add_literal_data(data)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
69 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
70 self.formatter.add_flowing_data(data)
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
71
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
72 # --- Hooks to save data; shouldn't need to be overridden
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
73
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
74 def save_bgn(self):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
75 """Begins saving character data in a buffer instead of sending it
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
76 to the formatter object.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
77
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
78 Retrieve the stored data via the save_end() method. Use of the
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
79 save_bgn() / save_end() pair may not be nested.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
80
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
81 """
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
82 self.savedata = ''
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
83
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
84 def save_end(self):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
85 """Ends buffering character data and returns all data saved since
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
86 the preceding call to the save_bgn() method.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
87
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
88 If the nofill flag is false, whitespace is collapsed to single
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
89 spaces. A call to this method without a preceding call to the
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
90 save_bgn() method will raise a TypeError exception.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
91
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
92 """
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
93 data = self.savedata
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
94 self.savedata = None
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
95 if not self.nofill:
16492
fc4ace0242cb String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16160
diff changeset
96 data = ' '.join(data.split())
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
97 return data
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
98
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
99 # --- Hooks for anchors; should probably be overridden
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
100
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
101 def anchor_bgn(self, href, name, type):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
102 """This method is called at the start of an anchor region.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
103
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
104 The arguments correspond to the attributes of the <A> tag with
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
105 the same names. The default implementation maintains a list of
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
106 hyperlinks (defined by the HREF attribute for <A> tags) within
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
107 the document. The list of hyperlinks is available as the data
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
108 attribute anchorlist.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
109
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
110 """
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
111 self.anchor = href
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
112 if self.anchor:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
113 self.anchorlist.append(href)
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
114
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
115 def anchor_end(self):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
116 """This method is called at the end of an anchor region.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
117
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
118 The default implementation adds a textual footnote marker using an
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
119 index into the list of hyperlinks created by the anchor_bgn()method.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
120
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
121 """
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
122 if self.anchor:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
123 self.handle_data("[%d]" % len(self.anchorlist))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
124 self.anchor = None
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
125
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
126 # --- Hook for images; should probably be overridden
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
127
3119
1071d16c930c added verbose option; added ismap/align/width/height to handle_image args
Guido van Rossum <guido@python.org>
parents: 3065
diff changeset
128 def handle_image(self, src, alt, *args):
23565
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
129 """This method is called to handle images.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
130
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
131 The default implementation simply passes the alt value to the
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
132 handle_data() method.
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
133
1a67fbc7a066 Patch 560023 adding docstrings. 2.2 Candidate (after verifying modules were not updated after 2.2).
Raymond Hettinger <python@rcn.com>
parents: 17795
diff changeset
134 """
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
135 self.handle_data(alt)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
136
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
137 # --------- Top level elememts
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
138
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
139 def start_html(self, attrs): pass
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
140 def end_html(self): pass
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
141
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
142 def start_head(self, attrs): pass
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
143 def end_head(self): pass
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
144
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
145 def start_body(self, attrs): pass
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
146 def end_body(self): pass
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
147
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
148 # ------ Head elements
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
149
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
150 def start_title(self, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
151 self.save_bgn()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
152
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
153 def end_title(self):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
154 self.title = self.save_end()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
155
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
156 def do_base(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
157 for a, v in attrs:
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
158 if a == 'href':
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
159 self.base = v
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
160
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
161 def do_isindex(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
162 self.isindex = 1
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
163
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
164 def do_link(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
165 pass
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
166
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
167 def do_meta(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
168 pass
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
169
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
170 def do_nextid(self, attrs): # Deprecated
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
171 pass
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
172
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
173 # ------ Body elements
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
174
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
175 # --- Headings
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
176
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
177 def start_h1(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
178 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
179 self.formatter.push_font(('h1', 0, 1, 0))
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
180
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
181 def end_h1(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
182 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
183 self.formatter.pop_font()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
184
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
185 def start_h2(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
186 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
187 self.formatter.push_font(('h2', 0, 1, 0))
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
188
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
189 def end_h2(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
190 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
191 self.formatter.pop_font()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
192
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
193 def start_h3(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
194 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
195 self.formatter.push_font(('h3', 0, 1, 0))
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
196
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
197 def end_h3(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
198 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
199 self.formatter.pop_font()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
200
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
201 def start_h4(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
202 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
203 self.formatter.push_font(('h4', 0, 1, 0))
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
204
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
205 def end_h4(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
206 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
207 self.formatter.pop_font()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
208
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
209 def start_h5(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
210 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
211 self.formatter.push_font(('h5', 0, 1, 0))
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
212
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
213 def end_h5(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
214 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
215 self.formatter.pop_font()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
216
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
217 def start_h6(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
218 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
219 self.formatter.push_font(('h6', 0, 1, 0))
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
220
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
221 def end_h6(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
222 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
223 self.formatter.pop_font()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
224
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
225 # --- Block Structuring Elements
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
226
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
227 def do_p(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
228 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
229
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
230 def start_pre(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
231 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
232 self.formatter.push_font((AS_IS, AS_IS, AS_IS, 1))
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
233 self.nofill = self.nofill + 1
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
234
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
235 def end_pre(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
236 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
237 self.formatter.pop_font()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
238 self.nofill = max(0, self.nofill - 1)
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
239
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
240 def start_xmp(self, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
241 self.start_pre(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
242 self.setliteral('xmp') # Tell SGML parser
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
243
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
244 def end_xmp(self):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
245 self.end_pre()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
246
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
247 def start_listing(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
248 self.start_pre(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
249 self.setliteral('listing') # Tell SGML parser
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
250
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
251 def end_listing(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
252 self.end_pre()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
253
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
254 def start_address(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
255 self.formatter.end_paragraph(0)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
256 self.formatter.push_font((AS_IS, 1, AS_IS, AS_IS))
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
257
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
258 def end_address(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
259 self.formatter.end_paragraph(0)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
260 self.formatter.pop_font()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
261
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
262 def start_blockquote(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
263 self.formatter.end_paragraph(1)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
264 self.formatter.push_margin('blockquote')
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
265
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
266 def end_blockquote(self):
2933
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
267 self.formatter.end_paragraph(1)
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
268 self.formatter.pop_margin()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
269
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
270 # --- List Elements
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
271
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
272 def start_ul(self, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
273 self.formatter.end_paragraph(not self.list_stack)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
274 self.formatter.push_margin('ul')
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
275 self.list_stack.append(['ul', '*', 0])
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
276
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
277 def end_ul(self):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
278 if self.list_stack: del self.list_stack[-1]
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
279 self.formatter.end_paragraph(not self.list_stack)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
280 self.formatter.pop_margin()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
281
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
282 def do_li(self, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
283 self.formatter.end_paragraph(0)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
284 if self.list_stack:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
285 [dummy, label, counter] = top = self.list_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
286 top[2] = counter = counter+1
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
287 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
288 label, counter = '*', 0
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
289 self.formatter.add_label_data(label, counter)
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
290
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
291 def start_ol(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
292 self.formatter.end_paragraph(not self.list_stack)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
293 self.formatter.push_margin('ol')
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
294 label = '1.'
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
295 for a, v in attrs:
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
296 if a == 'type':
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
297 if len(v) == 1: v = v + '.'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
298 label = v
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
299 self.list_stack.append(['ol', label, 0])
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
300
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
301 def end_ol(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
302 if self.list_stack: del self.list_stack[-1]
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
303 self.formatter.end_paragraph(not self.list_stack)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
304 self.formatter.pop_margin()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
305
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
306 def start_menu(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
307 self.start_ul(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
308
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
309 def end_menu(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
310 self.end_ul()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
311
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
312 def start_dir(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
313 self.start_ul(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
314
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
315 def end_dir(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
316 self.end_ul()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
317
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
318 def start_dl(self, attrs):
2933
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
319 self.formatter.end_paragraph(1)
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
320 self.list_stack.append(['dl', '', 0])
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
321
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
322 def end_dl(self):
2933
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
323 self.ddpop(1)
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
324 if self.list_stack: del self.list_stack[-1]
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
325
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
326 def do_dt(self, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
327 self.ddpop()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
328
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
329 def do_dd(self, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
330 self.ddpop()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
331 self.formatter.push_margin('dd')
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
332 self.list_stack.append(['dd', '', 0])
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
333
2933
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
334 def ddpop(self, bl=0):
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
335 self.formatter.end_paragraph(bl)
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
336 if self.list_stack:
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
337 if self.list_stack[-1][0] == 'dd':
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
338 del self.list_stack[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
339 self.formatter.pop_margin()
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
340
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
341 # --- Phrase Markup
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
342
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
343 # Idiomatic Elements
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
344
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
345 def start_cite(self, attrs): self.start_i(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
346 def end_cite(self): self.end_i()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
347
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
348 def start_code(self, attrs): self.start_tt(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
349 def end_code(self): self.end_tt()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
350
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
351 def start_em(self, attrs): self.start_i(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
352 def end_em(self): self.end_i()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
353
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
354 def start_kbd(self, attrs): self.start_tt(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
355 def end_kbd(self): self.end_tt()
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
356
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
357 def start_samp(self, attrs): self.start_tt(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
358 def end_samp(self): self.end_tt()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
359
2933
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
360 def start_strong(self, attrs): self.start_b(attrs)
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
361 def end_strong(self): self.end_b()
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
362
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
363 def start_var(self, attrs): self.start_i(attrs)
2933
7e1265312dd4 change blank line insertion at a few places and fix recursion bug for </var>
Guido van Rossum <guido@python.org>
parents: 2917
diff changeset
364 def end_var(self): self.end_i()
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
365
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
366 # Typographic Elements
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
367
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
368 def start_i(self, attrs):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
369 self.formatter.push_font((AS_IS, 1, AS_IS, AS_IS))
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
370 def end_i(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
371 self.formatter.pop_font()
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
372
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
373 def start_b(self, attrs):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
374 self.formatter.push_font((AS_IS, AS_IS, 1, AS_IS))
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
375 def end_b(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
376 self.formatter.pop_font()
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
377
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
378 def start_tt(self, attrs):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
379 self.formatter.push_font((AS_IS, AS_IS, AS_IS, 1))
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
380 def end_tt(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
381 self.formatter.pop_font()
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
382
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
383 def start_a(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
384 href = ''
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
385 name = ''
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
386 type = ''
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
387 for attrname, value in attrs:
16492
fc4ace0242cb String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16160
diff changeset
388 value = value.strip()
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
389 if attrname == 'href':
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
390 href = value
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
391 if attrname == 'name':
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
392 name = value
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
393 if attrname == 'type':
16492
fc4ace0242cb String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16160
diff changeset
394 type = value.lower()
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
395 self.anchor_bgn(href, name, type)
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
396
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
397 def end_a(self):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
398 self.anchor_end()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
399
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
400 # --- Line Break
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
401
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
402 def do_br(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
403 self.formatter.add_line_break()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
404
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
405 # --- Horizontal Rule
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
406
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
407 def do_hr(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
408 self.formatter.add_hor_rule()
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
409
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
410 # --- Image
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
411
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
412 def do_img(self, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
413 align = ''
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
414 alt = '(image)'
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
415 ismap = ''
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
416 src = ''
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
417 width = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
418 height = 0
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
419 for attrname, value in attrs:
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
420 if attrname == 'align':
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
421 align = value
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
422 if attrname == 'alt':
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
423 alt = value
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
424 if attrname == 'ismap':
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
425 ismap = value
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
426 if attrname == 'src':
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
427 src = value
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
428 if attrname == 'width':
16492
fc4ace0242cb String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16160
diff changeset
429 try: width = int(value)
17795
6e008c619855 int() of a string is only expected to through ValueError, so do not use
Fred Drake <fdrake@acm.org>
parents: 16492
diff changeset
430 except ValueError: pass
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
431 if attrname == 'height':
16492
fc4ace0242cb String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16160
diff changeset
432 try: height = int(value)
17795
6e008c619855 int() of a string is only expected to through ValueError, so do not use
Fred Drake <fdrake@acm.org>
parents: 16492
diff changeset
433 except ValueError: pass
3119
1071d16c930c added verbose option; added ismap/align/width/height to handle_image args
Guido van Rossum <guido@python.org>
parents: 3065
diff changeset
434 self.handle_image(src, alt, ismap, align, width, height)
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
435
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
436 # --- Really Old Unofficial Deprecated Stuff
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
437
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
438 def do_plaintext(self, attrs):
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
439 self.start_pre(attrs)
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
440 self.setnomoretags() # Tell SGML parser
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
441
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
442 # --- Unhandled tags
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
443
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
444 def unknown_starttag(self, tag, attrs):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
445 pass
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
446
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
447 def unknown_endtag(self, tag):
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
448 pass
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
449
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
450
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
451 def test(args = None):
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
452 import sys, formatter
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
453
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
454 if not args:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
455 args = sys.argv[1:]
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
456
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
457 silent = args and args[0] == '-s'
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
458 if silent:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
459 del args[0]
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
460
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
461 if args:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
462 file = args[0]
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
463 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
464 file = 'test.html'
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
465
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
466 if file == '-':
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
467 f = sys.stdin
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
468 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
469 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
470 f = open(file, 'r')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
471 except IOError, msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
472 print file, ":", msg
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
473 sys.exit(1)
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
474
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
475 data = f.read()
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
476
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
477 if f is not sys.stdin:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
478 f.close()
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 10828
diff changeset
479
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
480 if silent:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
481 f = formatter.NullFormatter()
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
482 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6521
diff changeset
483 f = formatter.AbstractFormatter(formatter.DumbWriter())
3384
c71a7a4f5f8e improved test()
Guido van Rossum <guido@python.org>
parents: 3149
diff changeset
484
2917
9fad029f838f new formatter module; redid htmllib module to use it
Guido van Rossum <guido@python.org>
parents: 2898
diff changeset
485 p = HTMLParser(f)
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
486 p.feed(data)
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
487 p.close()
2442
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
488
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
489
a5e95f9de900 added html parser and supporting cast
Guido van Rossum <guido@python.org>
parents:
diff changeset
490 if __name__ == '__main__':
2898
56e628a77c8d major rewrite using different formatting paradigm
Guido van Rossum <guido@python.org>
parents: 2771
diff changeset
491 test()