annotate Lib/markupbase.py @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents e1e90b0f1f45
children 500f545a24f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 """Shared support for scanning document type declarations in HTML and XHTML."""
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 import re
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 _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
6 _declstringlit_match = re.compile(r'(\'[^\']*\'|"[^"]*")\s*').match
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8 del re
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9
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 class ParserBase:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 """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
13 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
14
20699
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
15 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
16 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
17 raise RuntimeError(
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
18 "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
19
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
20 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
21 raise NotImplementedError(
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
22 "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
23
20065
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 def reset(self):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 self.lineno = 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 self.offset = 0
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 def getpos(self):
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 """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
30 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
31
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32 # 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
33 # 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
34 # 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
35 # 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
36 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
37 if i >= j:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 rawdata = self.rawdata
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
40 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
41 if nlines:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 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
43 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
44 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
45 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 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
47 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 _decl_otherchars = ''
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 # 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
52 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
53 # 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
54 # 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
55 # declaration ("<!DOCTYPE html...>").
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 j = i + 2
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58 assert rawdata[i:j] == "<!", "unexpected call to parse_declaration"
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 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
60 # 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
61 # 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
62 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
63 # in practice, this should look like: ((name|stringlit) S*)+ '>'
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64 n = len(rawdata)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
65 decltype, 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
66 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68 if decltype == "doctype":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
69 self._decl_otherchars = ''
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
70 while j < n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
71 c = rawdata[j]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
72 if c == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
73 # 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
74 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
75 if decltype == "doctype":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76 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
77 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
78 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
79 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
80 if c in "\"'":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
81 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
82 if not m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
83 return -1 # incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
84 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
85 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
86 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
87 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
88 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
89 elif c == "[":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90 if decltype == "doctype":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
91 j = self._parse_doctype_subset(j + 1, i)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
92 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
93 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
94 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
95 self.error(
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
96 "unexpected %s char in declaration" % `rawdata[j]`)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
97 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
98 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
99 return -1 # incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
100
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
101 # 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
102 # 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
103 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
104 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
105 n = len(rawdata)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106 j = i
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
107 while j < n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
108 c = rawdata[j]
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
109 if c == "<":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
110 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
111 if s == "<":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
112 # 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
113 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
114 if s != "<!":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
115 self.updatepos(declstartpos, j + 1)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
116 self.error("unexpected char in internal subset (in %s)"
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
117 % `s`)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
118 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
119 # 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
120 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
121 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
122 # 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
123 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
124 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
125 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
126 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
127 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
128 continue
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
129 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
130 if j == -1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
131 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
132 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
133 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
134 self.error(
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
135 "unknown declaration %s in internal subset" % `name`)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
136 # 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
137 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
138 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
139 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
140 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
141 elif c == "%":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
142 # parameter entity reference
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
143 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
144 # 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
145 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
146 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
147 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
148 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
149 if rawdata[j] == ";":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
150 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
151 elif c == "]":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
152 j = j + 1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
153 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
154 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
155 if j < n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
156 if rawdata[j] == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
157 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
158 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
159 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
160 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
161 return -1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
162 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
163 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
164 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
165 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
166 self.error("unexpected char %s in internal subset" % `c`)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
167 # 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
168 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
169
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
170 # 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
171 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
172 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
173 if j == -1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
174 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
175 # 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
176 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
177 if '>' in rawdata[j:]:
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
178 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
179 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
180
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 <!ATTLIST declarations
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
182 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
183 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
184 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
185 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
186 if c == "":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
187 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
188 if c == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
189 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
190 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
191 # 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
192 # 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
193 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
194 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
195 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
196 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
197 if c == "":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
198 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
199 if c == "(":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
200 # 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
201 if ")" in rawdata[j:]:
23590
a4bb18212b48 Use string methods where possible, and remove import string
Neal Norwitz <nnorwitz@gmail.com>
parents: 20699
diff changeset
202 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
203 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
204 return -1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
205 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
206 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
207 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
208 # 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
209 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
210 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
211 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
212 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
213 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
214 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
215 if c in "'\"":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
216 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
217 if m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
218 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
219 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
220 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
221 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
222 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
223 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
224 if c == "#":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
225 if rawdata[j:] == "#":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
226 # end of buffer
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
227 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
228 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
229 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
230 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
231 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
232 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
233 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
234 if c == '>':
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
235 # all done
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
236 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
237
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
238 # 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
239 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
240 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
241 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
242 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
243 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
244 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
245 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
246 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
247 # 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
248 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
249 if c == '>':
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
250 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
251 if c in "'\"":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
252 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
253 if not m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
254 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
255 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
256 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
257 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
258 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
259 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
260
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
261 # 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
262 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
263 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
264 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
265 j = i + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
266 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
267 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
268 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
269 return -1
23645
e1e90b0f1f45 Remove uses of the string and types modules:
Walter Dörwald <walter@livinglogic.de>
parents: 23590
diff changeset
270 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
271 j = j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
272 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
273 break
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
274 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
275 j = i
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
276 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
277 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
278 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
279 while 1:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
280 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
281 if not c:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
282 return -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
283 if c in "'\"":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
284 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
285 if m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
286 j = m.end()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
287 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
288 return -1 # incomplete
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
289 elif c == ">":
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
290 return j + 1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
291 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
292 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
293 if j < 0:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
294 return j
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
295
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
296 # 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
297 # 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
298 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
299 rawdata = self.rawdata
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
300 n = len(rawdata)
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
301 if i == n:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
302 return None, -1
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
303 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
304 if m:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
305 s = m.group()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
306 name = s.strip()
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
307 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
308 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
309 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
310 else:
f84691b11402 New base class for the SGMLParser and HTMLParser classes from the sgmllib
Fred Drake <fdrake@acm.org>
parents:
diff changeset
311 self.updatepos(declstartpos, i)
20416
5900a9d80848 Remove extra param from call to self.error().
Fred Drake <fdrake@acm.org>
parents: 20066
diff changeset
312 self.error("expected name token")
20699
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
313
fa0bf6c79e04 Re-arrange things and remove some unused variables/imports to keep pychecker
Fred Drake <fdrake@acm.org>
parents: 20416
diff changeset
314 # 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
315 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
316 pass