diff options
author | Guido van Rossum <guido@python.org> | 1999-02-02 17:54:38 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-02-02 17:54:38 (GMT) |
commit | cc2c291b7fdb2eb4a46bdce264931bd5adeaff38 (patch) | |
tree | 81f5115b9e5fc27bea455587f368a558bdcdbe6d /Lib | |
parent | 7e3535cbbd1d5e4b0d182557d91ac2c60bc1ef81 (diff) | |
download | cpython-cc2c291b7fdb2eb4a46bdce264931bd5adeaff38.zip cpython-cc2c291b7fdb2eb4a46bdce264931bd5adeaff38.tar.gz cpython-cc2c291b7fdb2eb4a46bdce264931bd5adeaff38.tar.bz2 |
Patch by Sjoerd Mullender to placate /F:
Fix leaking of instances by removing the elements variable that we
created on closing the parser. The elements variable is now created
in the reset() method, so that the sequence close(); reset();
... works.
Also, add the name of the entity reference that wasn't found to the
error message.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/xmllib.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/xmllib.py b/Lib/xmllib.py index b87d540..92b55b7 100644 --- a/Lib/xmllib.py +++ b/Lib/xmllib.py @@ -88,11 +88,11 @@ class XMLParser: # Interface -- initialize and reset this instance def __init__(self): + self.__fixed = 0 self.reset() - if self.elements is XMLParser.elements: - self.__fixelements() def __fixelements(self): + self.__fixed = 1 self.elements = {} self.__fixdict(self.__dict__) self.__fixclass(self.__class__) @@ -127,6 +127,10 @@ class XMLParser: self.__seen_starttag = 0 self.__use_namespaces = 0 self.__namespaces = {'xml':None} # xml is implicitly declared + # backward compatipibility hack: if elements not overridden, + # fill it in ourselves + if self.elements is XMLParser.elements: + self.__fixelements() # For derived classes only -- enter literal mode (CDATA) till EOF def setnomoretags(self): @@ -147,6 +151,10 @@ class XMLParser: # Interface -- handle the remaining data def close(self): self.goahead(1) + if self.__fixed: + self.__fixed = 0 + # remove self.elements so that we don't leak + del self.elements # Interface -- translate references def translate_references(self, data, all = 1): @@ -179,7 +187,7 @@ class XMLParser: data = pre + self.entitydefs[str] + post i = res.start(0) # rescan substituted text else: - self.syntax_error('reference to unknown entity') + self.syntax_error("reference to unknown entity `&%s;'" % str) # can't do it, so keep the entity ref in data = pre + '&' + str + ';' + post i = res.start(0) + len(str) + 2 @@ -327,7 +335,7 @@ class XMLParser: n = len(rawdata) i = res.start(0) else: - self.syntax_error('reference to unknown entity') + self.syntax_error("reference to unknown entity `&%s;'" % name) self.unknown_entityref(name) self.lineno = self.lineno + string.count(res.group(0), '\n') continue |