summaryrefslogtreecommitdiffstats
path: root/Lib/xmllib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-02-01 15:35:13 (GMT)
committerGuido van Rossum <guido@python.org>1999-02-01 15:35:13 (GMT)
commitfe64935cf95e8471d79ff0675c65e4f7376e2b5f (patch)
tree3a99f4d97f5c4477d12af807bf0b4170d0819844 /Lib/xmllib.py
parent79e02231ca663c2dd73b67011ac434f90a5f0561 (diff)
downloadcpython-fe64935cf95e8471d79ff0675c65e4f7376e2b5f.zip
cpython-fe64935cf95e8471d79ff0675c65e4f7376e2b5f.tar.gz
cpython-fe64935cf95e8471d79ff0675c65e4f7376e2b5f.tar.bz2
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.
Diffstat (limited to 'Lib/xmllib.py')
-rw-r--r--Lib/xmllib.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/xmllib.py b/Lib/xmllib.py
index e31d040..b87d540 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):