From fe64935cf95e8471d79ff0675c65e4f7376e2b5f Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 1 Feb 1999 15:35:13 +0000 Subject: [PATCH] Patch by Sjoerd Mullender for better compatibility with the version from Python 1.5.1: If after __init__ finishes no new elements variable was created, this patch will search the instance's namespace for all attributes whose name start with start_ or end_ and put their value in a new elements instance variable. --- Lib/xmllib.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Lib/xmllib.py b/Lib/xmllib.py index e31d0401d82..b87d5406d99 100644 --- a/Lib/xmllib.py +++ b/Lib/xmllib.py @@ -89,6 +89,31 @@ class XMLParser: # Interface -- initialize and reset this instance def __init__(self): self.reset() + if self.elements is XMLParser.elements: + self.__fixelements() + + def __fixelements(self): + self.elements = {} + self.__fixdict(self.__dict__) + self.__fixclass(self.__class__) + + def __fixclass(self, kl): + self.__fixdict(kl.__dict__) + for k in kl.__bases__: + self.__fixclass(k) + + def __fixdict(self, dict): + for key, val in dict.items(): + if key[:6] == 'start_': + key = key[6:] + start, end = self.elements.get(key, (None, None)) + if start is None: + self.elements[key] = val, end + elif key[:4] == 'end_': + key = key[4:] + start, end = self.elements.get(key, (None, None)) + if end is None: + self.elements[key] = start, val # Interface -- reset this instance. Loses all unprocessed data def reset(self):