Skip to content

Commit f37ec60

Browse files
committed
Update _markupbase, html/parser from CPython v3.11.2
1 parent b358610 commit f37ec60

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

Lib/_markupbase.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ def __init__(self):
2929
raise RuntimeError(
3030
"_markupbase.ParserBase must be subclassed")
3131

32-
def error(self, message):
33-
raise NotImplementedError(
34-
"subclasses of ParserBase must override error()")
35-
3632
def reset(self):
3733
self.lineno = 1
3834
self.offset = 0
@@ -131,12 +127,11 @@ def parse_declaration(self, i):
131127
# also in data attribute specifications of attlist declaration
132128
# also link type declaration subsets in linktype declarations
133129
# also link attribute specification lists in link declarations
134-
self.error("unsupported '[' char in %s declaration" % decltype)
130+
raise AssertionError("unsupported '[' char in %s declaration" % decltype)
135131
else:
136-
self.error("unexpected '[' char in declaration")
132+
raise AssertionError("unexpected '[' char in declaration")
137133
else:
138-
self.error(
139-
"unexpected %r char in declaration" % rawdata[j])
134+
raise AssertionError("unexpected %r char in declaration" % rawdata[j])
140135
if j < 0:
141136
return j
142137
return -1 # incomplete
@@ -156,7 +151,9 @@ def parse_marked_section(self, i, report=1):
156151
# look for MS Office ]> ending
157152
match= _msmarkedsectionclose.search(rawdata, i+3)
158153
else:
159-
self.error('unknown status keyword %r in marked section' % rawdata[i+3:j])
154+
raise AssertionError(
155+
'unknown status keyword %r in marked section' % rawdata[i+3:j]
156+
)
160157
if not match:
161158
return -1
162159
if report:
@@ -168,7 +165,7 @@ def parse_marked_section(self, i, report=1):
168165
def parse_comment(self, i, report=1):
169166
rawdata = self.rawdata
170167
if rawdata[i:i+4] != '<!--':
171-
self.error('unexpected call to parse_comment()')
168+
raise AssertionError('unexpected call to parse_comment()')
172169
match = _commentclose.search(rawdata, i+4)
173170
if not match:
174171
return -1
@@ -192,7 +189,9 @@ def _parse_doctype_subset(self, i, declstartpos):
192189
return -1
193190
if s != "<!":
194191
self.updatepos(declstartpos, j + 1)
195-
self.error("unexpected char in internal subset (in %r)" % s)
192+
raise AssertionError(
193+
"unexpected char in internal subset (in %r)" % s
194+
)
196195
if (j + 2) == n:
197196
# end of buffer; incomplete
198197
return -1
@@ -209,8 +208,9 @@ def _parse_doctype_subset(self, i, declstartpos):
209208
return -1
210209
if name not in {"attlist", "element", "entity", "notation"}:
211210
self.updatepos(declstartpos, j + 2)
212-
self.error(
213-
"unknown declaration %r in internal subset" % name)
211+
raise AssertionError(
212+
"unknown declaration %r in internal subset" % name
213+
)
214214
# handle the individual names
215215
meth = getattr(self, "_parse_doctype_" + name)
216216
j = meth(j, declstartpos)
@@ -234,14 +234,14 @@ def _parse_doctype_subset(self, i, declstartpos):
234234
if rawdata[j] == ">":
235235
return j
236236
self.updatepos(declstartpos, j)
237-
self.error("unexpected char after internal subset")
237+
raise AssertionError("unexpected char after internal subset")
238238
else:
239239
return -1
240240
elif c.isspace():
241241
j = j + 1
242242
else:
243243
self.updatepos(declstartpos, j)
244-
self.error("unexpected char %r in internal subset" % c)
244+
raise AssertionError("unexpected char %r in internal subset" % c)
245245
# end of buffer reached
246246
return -1
247247

@@ -387,8 +387,9 @@ def _scan_name(self, i, declstartpos):
387387
return name.lower(), m.end()
388388
else:
389389
self.updatepos(declstartpos, i)
390-
self.error("expected name token at %r"
391-
% rawdata[declstartpos:declstartpos+20])
390+
raise AssertionError(
391+
"expected name token at %r" % rawdata[declstartpos:declstartpos+20]
392+
)
392393

393394
# To be overridden -- handlers for unknown objects
394395
def unknown_decl(self, data):

Lib/html/parser.py

-7
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,6 @@ def parse_starttag(self, i):
328328

329329
end = rawdata[k:endpos].strip()
330330
if end not in (">", "/>"):
331-
lineno, offset = self.getpos()
332-
if "\n" in self.__starttag_text:
333-
lineno = lineno + self.__starttag_text.count("\n")
334-
offset = len(self.__starttag_text) \
335-
- self.__starttag_text.rfind("\n")
336-
else:
337-
offset = offset + len(self.__starttag_text)
338331
self.handle_data(rawdata[i:endpos])
339332
return endpos
340333
if end.endswith('/>'):

0 commit comments

Comments
 (0)