[Patches] xmllib patch to call handle_special

Burton Radons loth@pacificcoast.net
Sun, 18 Jun 2000 01:42:02 -0700


This is a multi-part message in MIME format.
--------------2F1517A45791ABCEA5F35B38
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

handle_special is not being called in xmllib, in spite of the
documentation stating otherwise.  This patch adds parser_special, a
dummy handle_special, and modifies goahead, as well as add a few
directly related globals.

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under copyright,
patent or other rights or interests ("claims").  To the extent that I
have any such claims, I hereby grant to CNRI a nonexclusive,
irrevocable, royalty-free, worldwide license to reproduce, distribute,
perform and/or display publicly, prepare derivative versions, and
otherwise use this contribution as part of the Python software and its
related documentation, or any derivative versions thereof, at no cost to
CNRI or its licensed users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or
not to incorporate this contribution in the Python software and its
related documentation.  I further grant CNRI permission to use my name
and other identifying information provided to CNRI by me for use in
connection with the Python software and its related documentation.

- Burton Radons (loth@pacificcoast.net)
--------------2F1517A45791ABCEA5F35B38
Content-Type: text/plain; charset=us-ascii;
 name="xmllib.py.diff"
Content-Disposition: inline;
 filename="xmllib.py.diff"
Content-Transfer-Encoding: 7bit

*** xmllib.py~	Sun Jun 18 01:36:47 2000
--- xmllib.py	Sun Jun 18 01:15:12 2000
***************
*** 37,42 ****
--- 37,44 ----
  endbracket = re.compile(_opS + '>')
  endbracketfind = re.compile('(?:[^>\'"]|'+_QStr+')*>')
  tagfind = re.compile(_Name)
+ specialopen = re.compile('<!(?!DOCTYPE)')
+ specialclose = re.compile('>')
  cdataopen = re.compile(r'<!\[CDATA\[')
  cdataclose = re.compile(r'\]\]>')
  # this matches one of the following:
***************
*** 280,285 ****
--- 282,293 ----
                      self.lineno = self.lineno + string.count(rawdata[i:i], '\n')
                      i = k
                      continue
+                 if specialopen.match(rawdata, i):
+                     k = self.parse_special(i)
+                     if k < 0: break
+                     self.lineno = self.lineno + string.count(rawdata[i:i], '\n')
+                     i = k
+                     continue
                  res = xmldecl.match(rawdata, i)
                  if res:
                      if not self.__at_start:
***************
*** 476,481 ****
--- 484,503 ----
          self.handle_cdata(rawdata[i+9:res.start(0)])
          return res.end(0)
  
+     # Internal -- handle <!...> tag, return length or -1 if not terminated
+     def parse_special(self, i):
+         rawdata = self.rawdata
+         if rawdata[i:i+2] <> '<!':
+             raise RuntimeError, 'unexpected call to parse_special'
+         res = specialclose.search(rawdata, i+2)
+         if res is None:
+             return -1
+         if not self.__accept_utf8 and \
+            illegal.search(rawdata, i+2, res.start(0)):
+             self.syntax_error('illegal character in special')
+         self.handle_special(rawdata[i+2: res.start(0)])
+         return res.end(0)
+ 
      __xml_namespace_attributes = {'ns':None, 'src':None, 'prefix':None}
      # Internal -- handle a processing instruction tag
      def parse_proc(self, i):
***************
*** 755,760 ****
--- 777,786 ----
  
      # Example -- handle cdata, could be overridden
      def handle_cdata(self, data):
+         pass
+ 
+     # Example -- handle special, could be overridden
+     def handle_special(self, data):
          pass
  
      # Example -- handle comment, could be overridden

--------------2F1517A45791ABCEA5F35B38--