[XML-SIG] patch to xml/dom/esis_builder.py
J.R. van Ossenbruggen
Jacco.van.Ossenbruggen@cwi.nl
Wed, 02 Jun 1999 16:05:02 +0200
On Tue, Jun 1 1999 "Fred L. Drake" wrote:
> I like this, but have two changes. First, the default convert
> function could be str instead of a lambda; this would be faster since
> str() is implemented in C (or Java in JPython).
Agreed.
> The second change concerns this part of the patch:
>
> > ! name = self.convert(l[0])
> > ! if l[1] == 'IMPLIED':
> > ! # fix this. Needs to be undefined attr
> > ! value = ''
> > ! else:
> > ! value = ESISDecode(l[2])
> > self.attr_store[name] = value
>
> This could be something like this:
>
> if l[1] != 'IMPLIED':
> self.attr_store[self.convert(l[0])] = ESISDecode(l[2])
>
> This does just as much as needed, and doesn't create the bogus
> attribute entry in the dictionary.
You're right again. I was under the impression #IMPLIED attributes
should create a bogus attribute with specified=false. I just reread
the spec to see that this impression was false. Thanks a lot!
Jacco
PS: a new version of the patch with Fred's changes:
Index: esis_builder.py
===================================================================
RCS file: /projects/cvsroot/xml/dom/esis_builder.py,v
retrieving revision 1.5
diff -c -r1.5 esis_builder.py
*** esis_builder.py 1999/03/18 12:38:28 1.5
--- esis_builder.py 1999/06/02 13:04:26
***************
*** 27,37 ****
class EsisBuilder(Builder):
! def __init__(self):
Builder.__init__(self)
self.attr_store = {}
self.id_store = {}
#self.sdata_handler = handle_sdata
def feed(self, data):
for line in string.split(data, '\n'):
--- 27,39 ----
class EsisBuilder(Builder):
! def __init__(self, convert=str):
Builder.__init__(self)
self.attr_store = {}
self.id_store = {}
#self.sdata_handler = handle_sdata
+ # convert may, for example, be used to handle case conversion
+ self.convert = convert
def feed(self, data):
for line in string.split(data, '\n'):
***************
*** 41,46 ****
--- 43,49 ----
text = line[1:]
if event == '(':
+ text = self.convert(text)
element = self.document.createElement(text, self.attr_store)
self.attr_store = {}
self.push(element)
***************
*** 50,58 ****
elif event == 'A':
l = re.split(' ', text, 2)
! name = l[0]
! value = ESISDecode(l[2])
! self.attr_store[name] = value
elif event == '-':
text = self.document.createText(ESISDecode(text))
--- 53,61 ----
elif event == 'A':
l = re.split(' ', text, 2)
! name = self.convert(l[0])
! if l[1] != 'IMPLIED':
! self.attr_store[self.convert(l[0])] = ESISDecode(l[2])
elif event == '-':
text = self.document.createText(ESISDecode(text))