[XML-SIG] patch to xml/dom/esis_builder.py

J.R. van Ossenbruggen Jacco.van.Ossenbruggen@cwi.nl
Tue, 01 Jun 1999 16:02:36 +0200


Hi all,

I use the xml package in a mixed SGML/XML environment.  I directly
process XML but use SP to convert SGML to ESIS first.  This works
fine, except for two minor modifications I needed to make to
esis_builder.py.  

The first modification prevents a crash on "#IMPLIED" attributes, in
which case the current version fails to notice that the third argument
(the value of the attr) is missing.  The second modification provides
an optional argument to EsisBuilder.__init__, which allows me to pass
string.lower or string.upper functions to do the necessary case
conversions (SGML names are not case sensitive and converted to
uppercase by SP, XML names are not changed when converted to ESIS).

I include the relevant patch below.  I think the changes could be
useful for more people, and as far as I know,do not break any existing
code.  I'd be grateful if they are included in the main distribution.

Let me know what you think,

	Jacco


---
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/01 12:09:09
***************
*** 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=lambda x:x):
          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,57 ****
  
              elif event == 'A':
                  l = re.split(' ', text, 2)
!                 name = l[0]
!                 value = ESISDecode(l[2])
                  self.attr_store[name] = value
  
              elif event == '-':
--- 53,64 ----
  
              elif event == 'A':
                  l = re.split(' ', text, 2)
!                 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
  
              elif event == '-':