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.
This commit is contained in:
Guido van Rossum 1999-02-01 15:35:13 +00:00
parent 79e02231ca
commit fe64935cf9
1 changed files with 25 additions and 0 deletions

View 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):