]> granicus.if.org Git - python/commitdiff
Patch by Sjoerd Mullender for better compatibility with the version
authorGuido van Rossum <guido@python.org>
Mon, 1 Feb 1999 15:35:13 +0000 (15:35 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 1 Feb 1999 15:35:13 +0000 (15:35 +0000)
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

index e31d0401d827f94d1b4cf965bac27cfba3279cc0..b87d5406d990cef3b4c39703d8d20b90984750c2 100644 (file)
@@ -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):