mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
fix <!...!> parsing; added verbose option; don't lowercase entityrefs
This commit is contained in:
parent
8421c4e833
commit
3c0bfd0dee
1 changed files with 7 additions and 5 deletions
|
@ -40,7 +40,8 @@ commentclose = regex.compile('--[ \t\n]*>')
|
||||||
class SGMLParser:
|
class SGMLParser:
|
||||||
|
|
||||||
# Interface -- initialize and reset this instance
|
# Interface -- initialize and reset this instance
|
||||||
def __init__(self):
|
def __init__(self, verbose=0):
|
||||||
|
self.verbose = verbose
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
# Interface -- reset this instance. Loses all unprocessed data
|
# Interface -- reset this instance. Loses all unprocessed data
|
||||||
|
@ -141,7 +142,8 @@ class SGMLParser:
|
||||||
k = incomplete.match(rawdata, i)
|
k = incomplete.match(rawdata, i)
|
||||||
if k < 0: raise RuntimeError, 'no incomplete match ??'
|
if k < 0: raise RuntimeError, 'no incomplete match ??'
|
||||||
j = i+k
|
j = i+k
|
||||||
if j == n: break # Really incomplete
|
if j == n or rawdata[i:i+2] == '<!':
|
||||||
|
break # Really incomplete
|
||||||
self.handle_data(rawdata[i:j])
|
self.handle_data(rawdata[i:j])
|
||||||
i = j
|
i = j
|
||||||
# end while
|
# end while
|
||||||
|
@ -234,8 +236,9 @@ class SGMLParser:
|
||||||
|
|
||||||
# Example -- report an unbalanced </...> tag.
|
# Example -- report an unbalanced </...> tag.
|
||||||
def report_unbalanced(self, tag):
|
def report_unbalanced(self, tag):
|
||||||
print '*** Unbalanced </' + tag + '>'
|
if self.verbose:
|
||||||
print '*** Stack:', self.stack
|
print '*** Unbalanced </' + tag + '>'
|
||||||
|
print '*** Stack:', self.stack
|
||||||
|
|
||||||
# Example -- handle character reference, no need to override
|
# Example -- handle character reference, no need to override
|
||||||
def handle_charref(self, name):
|
def handle_charref(self, name):
|
||||||
|
@ -256,7 +259,6 @@ class SGMLParser:
|
||||||
# Example -- handle entity reference, no need to override
|
# Example -- handle entity reference, no need to override
|
||||||
def handle_entityref(self, name):
|
def handle_entityref(self, name):
|
||||||
table = self.entitydefs
|
table = self.entitydefs
|
||||||
name = string.lower(name)
|
|
||||||
if table.has_key(name):
|
if table.has_key(name):
|
||||||
self.handle_data(table[name])
|
self.handle_data(table[name])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue