annotate Lib/markupbase.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 9c60fd12664f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35386
38824b6e3600 add note about "markupbase" not being intended for direct use
Fred Drake <fdrake@acm.org>
parents: 32603
diff changeset
1 """Shared support for scanning document type declarations in HTML and XHTML.
38824b6e3600 add note about "markupbase" not being intended for direct use
Fred Drake <fdrake@acm.org>
parents: 32603
diff changeset
2
38824b6e3600 add note about "markupbase" not being intended for direct use
Fred Drake <fdrake@acm.org>
parents: 32603
diff changeset
3 This module is used as a foundation for the HTMLParser and sgmllib
38824b6e3600 add note about "markupbase" not being intended for direct use
Fred Drake <fdrake@acm.org>
parents: 32603
diff changeset
4 modules (indirectly, for htmllib as well). It has no documented
38824b6e3600 add note about "markupbase" not being intended for direct use
Fred Drake <fdrake@acm.org>
parents: 32603
diff changeset
5 public API and should not be used directly.
38824b6e3600 add note about "markupbase" not being intended for direct use
Fred Drake <fdrake@acm.org>
parents: 32603
diff changeset
6
38824b6e3600 add note about "markupbase" not being intended for direct use
Fred Drake <fdrake@acm.org>
parents: 32603
diff changeset
7 """
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 import re
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 _declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*\s*').match
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 _declstringlit_match = re.compile(r'(\'[^\']*\'|"[^"]*")\s*').match
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
13 _commentclose = re.compile(r'--\s*>')
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
14 _markedsectionclose = re.compile(r']\s*]\s*>')
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
15
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
16 # An analysis of the MS-Word extensions is available at
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
17 # http://www.planetpublish.com/xmlarena/xap/Thursday/WordtoXML.pdf
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
18
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
19 _msmarkedsectionclose = re.compile(r']\s*>')
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 del re
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 class ParserBase:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 """Parser base class which provides some common support methods used
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 by the SGML/HTML and XHTML parsers."""
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27
20699
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
28 def __init__(self):
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
29 if self.__class__ is ParserBase:
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
30 raise RuntimeError(
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
31 "markupbase.ParserBase must be subclassed")
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
32
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
33 def error(self, message):
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
34 raise NotImplementedError(
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
35 "subclasses of ParserBase must override error()")
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
36
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 def reset(self):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38 self.lineno = 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 self.offset = 0
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41 def getpos(self):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 """Return current line number and offset."""
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43 return self.lineno, self.offset
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 # Internal -- update line number and offset. This should be
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 # called for each piece of data exactly once, in order -- in other
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 # words the concatenation of all the input strings to this
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 # function should be exactly the entire input.
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 def updatepos(self, i, j):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 if i >= j:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52 rawdata = self.rawdata
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
53 nlines = rawdata.count("\n", i, j)
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54 if nlines:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
55 self.lineno = self.lineno + nlines
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
56 pos = rawdata.rindex("\n", i, j) # Should not fail
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 self.offset = j-(pos+1)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 self.offset = self.offset + j-i
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62 _decl_otherchars = ''
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
63
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64 # Internal -- parse declaration (for use by subclasses).
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
65 def parse_declaration(self, i):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66 # This is some sort of declaration; in "HTML as
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 # deployed," this should only be the document type
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68 # declaration ("<!DOCTYPE html...>").
28774
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28446
diff changeset
69 # ISO 8879:1986, however, has more complex
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
70 # declaration syntax for elements in <!...>, including:
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
71 # --comment--
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
72 # [marked section]
28774
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28446
diff changeset
73 # name in the following list: ENTITY, DOCTYPE, ELEMENT,
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28446
diff changeset
74 # ATTLIST, NOTATION, SHORTREF, USEMAP,
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
75 # LINKTYPE, LINK, IDLINK, USELINK, SYSTEM
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
77 j = i + 2
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
78 assert rawdata[i:j] == "<!", "unexpected call to parse_declaration"
36914
f1eaae7f962d Bug #1442874: handle "<!>", the empty SGML comment
Georg Brandl <georg@python.org>
parents: 35386
diff changeset
79 if rawdata[j:j+1] == ">":
f1eaae7f962d Bug #1442874: handle "<!>", the empty SGML comment
Georg Brandl <georg@python.org>
parents: 35386
diff changeset
80 # the empty comment <!>
f1eaae7f962d Bug #1442874: handle "<!>", the empty SGML comment
Georg Brandl <georg@python.org>
parents: 35386
diff changeset
81 return j + 1
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
82 if rawdata[j:j+1] in ("-", ""):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
83 # Start of comment followed by buffer boundary,
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
84 # or just a buffer boundary.
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
85 return -1
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
86 # A simple, practical version could look like: ((name|stringlit) S*) + '>'
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
87 n = len(rawdata)
36914
f1eaae7f962d Bug #1442874: handle "<!>", the empty SGML comment
Georg Brandl <georg@python.org>
parents: 35386
diff changeset
88 if rawdata[j:j+2] == '--': #comment
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
89 # Locate --.*-- as the body of the comment
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
90 return self.parse_comment(i)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
91 elif rawdata[j] == '[': #marked section
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
92 # Locate [statusWord [...arbitrary SGML...]] as the body of the marked section
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
93 # Where statusWord is one of TEMP, CDATA, IGNORE, INCLUDE, RCDATA
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
94 # Note that this is extended by Microsoft Office "Save as Web" function
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
95 # to include [if...] and [endif].
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
96 return self.parse_marked_section(i)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
97 else: #all other declaration elements
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
98 decltype, j = self._scan_name(j, i)
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
99 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
100 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
101 if decltype == "doctype":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
102 self._decl_otherchars = ''
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
103 while j < n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
104 c = rawdata[j]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
105 if c == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106 # end of declaration syntax
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
107 data = rawdata[i+2:j]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
108 if decltype == "doctype":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
109 self.handle_decl(data)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
110 else:
74069
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 38627
diff changeset
111 # According to the HTML5 specs sections "8.2.4.44 Bogus
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 38627
diff changeset
112 # comment state" and "8.2.4.45 Markup declaration open
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 38627
diff changeset
113 # state", a comment token should be emitted.
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 38627
diff changeset
114 # Calling unknown_decl provides more flexibility though.
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
115 self.unknown_decl(data)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
116 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
117 if c in "\"'":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
118 m = _declstringlit_match(rawdata, j)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
119 if not m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
120 return -1 # incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
121 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
122 elif c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
123 name, j = self._scan_name(j, i)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
124 elif c in self._decl_otherchars:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
125 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
126 elif c == "[":
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
127 # this could be handled in a separate doctype parser
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
128 if decltype == "doctype":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
129 j = self._parse_doctype_subset(j + 1, i)
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
130 elif decltype in ("attlist", "linktype", "link", "element"):
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
131 # must tolerate []'d groups in a content model in an element declaration
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
132 # also in data attribute specifications of attlist declaration
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
133 # also link type declaration subsets in linktype declarations
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
134 # also link attribute specification lists in link declarations
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
135 self.error("unsupported '[' char in %s declaration" % decltype)
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
136 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
137 self.error("unexpected '[' char in declaration")
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
138 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
139 self.error(
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28774
diff changeset
140 "unexpected %r char in declaration" % rawdata[j])
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
141 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
142 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
143 return -1 # incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
144
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
145 # Internal -- parse a marked section
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
146 # Override this to handle MS-word extension syntax <![if word]>content<![endif]>
38627
98e81af40007 Normalized a few cases of whitespace in function declarations.
Martin Blais <blais@furius.ca>
parents: 36914
diff changeset
147 def parse_marked_section(self, i, report=1):
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
148 rawdata= self.rawdata
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
149 assert rawdata[i:i+3] == '<![', "unexpected call to parse_marked_section()"
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
150 sectName, j = self._scan_name( i+3, i )
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
151 if j < 0:
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
152 return j
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
153 if sectName in ("temp", "cdata", "ignore", "include", "rcdata"):
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
154 # look for standard ]]> ending
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
155 match= _markedsectionclose.search(rawdata, i+3)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
156 elif sectName in ("if", "else", "endif"):
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
157 # look for MS Office ]> ending
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
158 match= _msmarkedsectionclose.search(rawdata, i+3)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
159 else:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28774
diff changeset
160 self.error('unknown status keyword %r in marked section' % rawdata[i+3:j])
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
161 if not match:
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
162 return -1
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
163 if report:
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
164 j = match.start(0)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
165 self.unknown_decl(rawdata[i+3: j])
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
166 return match.end(0)
28774
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28446
diff changeset
167
28446
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
168 # Internal -- parse comment, return length or -1 if not terminated
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
169 def parse_comment(self, i, report=1):
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
170 rawdata = self.rawdata
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
171 if rawdata[i:i+4] != '<!--':
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
172 self.error('unexpected call to parse_comment()')
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
173 match = _commentclose.search(rawdata, i+4)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
174 if not match:
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
175 return -1
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
176 if report:
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
177 j = match.start(0)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
178 self.handle_comment(rawdata[i+4: j])
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
179 return match.end(0)
500f545a24f0 Patch #545300: Support marked sections.
Martin v. Löwis <martin@v.loewis.de>
parents: 23645
diff changeset
180
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
181 # Internal -- scan past the internal subset in a <!DOCTYPE declaration,
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
182 # returning the index just past any whitespace following the trailing ']'.
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
183 def _parse_doctype_subset(self, i, declstartpos):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
184 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
185 n = len(rawdata)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
186 j = i
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
187 while j < n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
188 c = rawdata[j]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
189 if c == "<":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
190 s = rawdata[j:j+2]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
191 if s == "<":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
192 # end of buffer; incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
193 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
194 if s != "<!":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
195 self.updatepos(declstartpos, j + 1)
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28774
diff changeset
196 self.error("unexpected char in internal subset (in %r)" % s)
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
197 if (j + 2) == n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
198 # end of buffer; incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
199 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
200 if (j + 4) > n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
201 # end of buffer; incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
202 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
203 if rawdata[j:j+4] == "<!--":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
204 j = self.parse_comment(j, report=0)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
205 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
206 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
207 continue
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
208 name, j = self._scan_name(j + 2, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
209 if j == -1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
210 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
211 if name not in ("attlist", "element", "entity", "notation"):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
212 self.updatepos(declstartpos, j + 2)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
213 self.error(
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28774
diff changeset
214 "unknown declaration %r in internal subset" % name)
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
215 # handle the individual names
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
216 meth = getattr(self, "_parse_doctype_" + name)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
217 j = meth(j, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
218 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
219 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
220 elif c == "%":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
221 # parameter entity reference
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
222 if (j + 1) == n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
223 # end of buffer; incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
224 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
225 s, j = self._scan_name(j + 1, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
226 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
227 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
228 if rawdata[j] == ";":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
229 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
230 elif c == "]":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
231 j = j + 1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
232 while j < n and rawdata[j].isspace():
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
233 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
234 if j < n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
235 if rawdata[j] == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
236 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
237 self.updatepos(declstartpos, j)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
238 self.error("unexpected char after internal subset")
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
239 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
240 return -1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
241 elif c.isspace():
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
242 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
243 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
244 self.updatepos(declstartpos, j)
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28774
diff changeset
245 self.error("unexpected char %r in internal subset" % c)
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
246 # end of buffer reached
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
247 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
248
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
249 # Internal -- scan past <!ELEMENT declarations
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
250 def _parse_doctype_element(self, i, declstartpos):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
251 name, j = self._scan_name(i, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
252 if j == -1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
253 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
254 # style content model; just skip until '>'
20699
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
255 rawdata = self.rawdata
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
256 if '>' in rawdata[j:]:
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
257 return rawdata.find(">", j) + 1
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
258 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
259
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
260 # Internal -- scan past <!ATTLIST declarations
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
261 def _parse_doctype_attlist(self, i, declstartpos):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
262 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
263 name, j = self._scan_name(i, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
264 c = rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
265 if c == "":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
266 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
267 if c == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
268 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
269 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
270 # scan a series of attribute descriptions; simplified:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
271 # name type [value] [#constraint]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
272 name, j = self._scan_name(j, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
273 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
274 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
275 c = rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
276 if c == "":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
277 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
278 if c == "(":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
279 # an enumerated type; look for ')'
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
280 if ")" in rawdata[j:]:
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
281 j = rawdata.find(")", j) + 1
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
282 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
283 return -1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
284 while rawdata[j:j+1].isspace():
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
285 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
286 if not rawdata[j:]:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
287 # end of buffer, incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
288 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
289 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
290 name, j = self._scan_name(j, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
291 c = rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
292 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
293 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
294 if c in "'\"":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
295 m = _declstringlit_match(rawdata, j)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
296 if m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
297 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
298 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
299 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
300 c = rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
301 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
302 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
303 if c == "#":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
304 if rawdata[j:] == "#":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
305 # end of buffer
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
306 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
307 name, j = self._scan_name(j + 1, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
308 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
309 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
310 c = rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
311 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
312 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
313 if c == '>':
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
314 # all done
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
315 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
316
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
317 # Internal -- scan past <!NOTATION declarations
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
318 def _parse_doctype_notation(self, i, declstartpos):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
319 name, j = self._scan_name(i, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
320 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
321 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
322 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
323 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
324 c = rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
325 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
326 # end of buffer; incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
327 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
328 if c == '>':
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
329 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
330 if c in "'\"":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
331 m = _declstringlit_match(rawdata, j)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
332 if not m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
333 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
334 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
335 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
336 name, j = self._scan_name(j, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
337 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
338 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
339
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
340 # Internal -- scan past <!ENTITY declarations
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
341 def _parse_doctype_entity(self, i, declstartpos):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
342 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
343 if rawdata[i:i+1] == "%":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
344 j = i + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
345 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
346 c = rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
347 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
348 return -1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
349 if c.isspace():
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
350 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
351 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
352 break
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
353 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
354 j = i
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
355 name, j = self._scan_name(j, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
356 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
357 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
358 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
359 c = self.rawdata[j:j+1]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
360 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
361 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
362 if c in "'\"":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
363 m = _declstringlit_match(rawdata, j)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
364 if m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
365 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
366 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
367 return -1 # incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
368 elif c == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
369 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
370 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
371 name, j = self._scan_name(j, declstartpos)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
372 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
373 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
374
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
375 # Internal -- scan a name token and the new position and the token, or
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
376 # return -1 if we've reached the end of the buffer.
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
377 def _scan_name(self, i, declstartpos):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
378 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
379 n = len(rawdata)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
380 if i == n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
381 return None, -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
382 m = _declname_match(rawdata, i)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
383 if m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
384 s = m.group()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
385 name = s.strip()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
386 if (i + len(s)) == n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
387 return None, -1 # end of buffer
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
388 return name.lower(), m.end()
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
389 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
390 self.updatepos(declstartpos, i)
32603
799bcdff2cdc [Patch #965175] Incorporate a suggestion for a better error message
Andrew M. Kuchling <amk@amk.ca>
parents: 31515
diff changeset
391 self.error("expected name token at %r"
799bcdff2cdc [Patch #965175] Incorporate a suggestion for a better error message
Andrew M. Kuchling <amk@amk.ca>
parents: 31515
diff changeset
392 % rawdata[declstartpos:declstartpos+20])
20699
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
393
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
394 # To be overridden -- handlers for unknown objects
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
395 def unknown_decl(self, data):
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
396 pass