Commit 4ba7be10 authored by Guido van Rossum's avatar Guido van Rossum

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.
parent 95825d04
...@@ -89,6 +89,31 @@ class XMLParser: ...@@ -89,6 +89,31 @@ class XMLParser:
# Interface -- initialize and reset this instance # Interface -- initialize and reset this instance
def __init__(self): def __init__(self):
self.reset() 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 # Interface -- reset this instance. Loses all unprocessed data
def reset(self): def reset(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment