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

Skip to content

Commit 5baaf66

Browse files
2 fixes plus one extension:
- Actually count the linefeeds in a the CDATA content. - Don't call the endtag handler for an unmatched endtag (this makes the base class simpler since it doesn't have to deal with unopened endtags). - If the __init__ method is called with keyword argument translate_attribute_references=0, don't attempt to translate character and entity references in attribute values.
1 parent 8bcfb8a commit 5baaf66

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Lib/xmllib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class XMLParser:
9090
__accept_missing_endtag_name = 0
9191
__map_case = 0
9292
__accept_utf8 = 0
93+
__translate_attribute_references = 1
9394

9495
# Interface -- initialize and reset this instance
9596
def __init__(self, **kw):
@@ -102,6 +103,8 @@ def __init__(self, **kw):
102103
self.__map_case = kw['map_case']
103104
if kw.has_key('accept_utf8'):
104105
self.__accept_utf8 = kw['accept_utf8']
106+
if kw.has_key('translate_attribute_references'):
107+
self.__translate_attribute_references = kw['translate_attribute_references']
105108
self.reset()
106109

107110
def __fixelements(self):
@@ -171,6 +174,8 @@ def close(self):
171174

172175
# Interface -- translate references
173176
def translate_references(self, data, all = 1):
177+
if not self.__translate_attribute_references:
178+
return data
174179
i = 0
175180
while 1:
176181
res = amp.search(data, i)
@@ -277,7 +282,7 @@ def goahead(self, end):
277282
if cdataopen.match(rawdata, i):
278283
k = self.parse_cdata(i)
279284
if k < 0: break
280-
self.lineno = self.lineno + string.count(rawdata[i:i], '\n')
285+
self.lineno = self.lineno + string.count(rawdata[i:k], '\n')
281286
i = k
282287
continue
283288
res = xmldecl.match(rawdata, i)
@@ -691,11 +696,6 @@ def finish_endtag(self, tag):
691696
found = i
692697
if found == -1:
693698
self.syntax_error('unopened end tag')
694-
method = self.elements.get(tag, (None, None))[1]
695-
if method is not None:
696-
self.handle_endtag(tag, method)
697-
else:
698-
self.unknown_endtag(tag)
699699
return
700700
while len(self.stack) > found:
701701
if found < len(self.stack) - 1:

0 commit comments

Comments
 (0)