Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c0bfd0

Browse files
committed
fix <!...!> parsing; added verbose option; don't lowercase entityrefs
1 parent 8421c4e commit 3c0bfd0

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Lib/sgmllib.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
class SGMLParser:
4141

4242
# Interface -- initialize and reset this instance
43-
def __init__(self):
43+
def __init__(self, verbose=0):
44+
self.verbose = verbose
4445
self.reset()
4546

4647
# Interface -- reset this instance. Loses all unprocessed data
@@ -141,7 +142,8 @@ def goahead(self, end):
141142
k = incomplete.match(rawdata, i)
142143
if k < 0: raise RuntimeError, 'no incomplete match ??'
143144
j = i+k
144-
if j == n: break # Really incomplete
145+
if j == n or rawdata[i:i+2] == '<!':
146+
break # Really incomplete
145147
self.handle_data(rawdata[i:j])
146148
i = j
147149
# end while
@@ -234,8 +236,9 @@ def parse_endtag(self, data):
234236

235237
# Example -- report an unbalanced </...> tag.
236238
def report_unbalanced(self, tag):
237-
print '*** Unbalanced </' + tag + '>'
238-
print '*** Stack:', self.stack
239+
if self.verbose:
240+
print '*** Unbalanced </' + tag + '>'
241+
print '*** Stack:', self.stack
239242

240243
# Example -- handle character reference, no need to override
241244
def handle_charref(self, name):
@@ -256,7 +259,6 @@ def handle_charref(self, name):
256259
# Example -- handle entity reference, no need to override
257260
def handle_entityref(self, name):
258261
table = self.entitydefs
259-
name = string.lower(name)
260262
if table.has_key(name):
261263
self.handle_data(table[name])
262264
else:

0 commit comments

Comments
 (0)