All pastes #82779 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-07-08 22:33 UTC
rendered paste body
olaf@pc:~/test/python2.4-2.4.3/Lib$ diff /usr/lib/python2.4/sgmllib.py /usr/lib/python2.4/sgmllib_SAVE.py
32c32,37
< endbracket = re.compile('[<>]')
---
> starttag = re.compile(r'<[a-zA-Z][-_.:a-zA-Z0-9]*\s*('
>         r'\s*([a-zA-Z_][-:.a-zA-Z_0-9]*)(\s*=\s*'
>         r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~@]'
>         r'[][\-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*(?=[\s>/<])))?'
>     r')*\s*/?\s*(?=[<>])')
> endtag = re.compile(r'</?[a-zA-Z][-_.:a-zA-Z0-9]*\s*/?\s*(?=[<>])')
36c41
<     r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))?')
---
>     r'(\'[^\']*\'|"[^"]*"|[][\-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))?')
248,249c253
<         # XXX The following should skip matching quotes (' or ")
<         match = endbracket.search(rawdata, i+1)
---
>         match = starttag.match(rawdata, i)
252c256
<         j = match.start(0)
---
>         j = match.end(0)
286c290
<         match = endbracket.search(rawdata, i+1)
---
>         match = endtag.match(rawdata, i)
289c293
<         j = match.start(0)
---
>         j = match.end(0)
olaf@pc:~/test/python2.4-2.4.3/Lib$ diff -u /usr/lib/python2.4/sgmllib.py /usr/lib/python2.4/sgmllib_SAVE.py
--- /usr/lib/python2.4/sgmllib.py       2006-07-09 00:30:42.000000000 +0200
+++ /usr/lib/python2.4/sgmllib_SAVE.py  2006-07-09 00:31:58.000000000 +0200
@@ -29,11 +29,16 @@
 shorttagopen = re.compile('<[a-zA-Z][-.a-zA-Z0-9]*/')
 shorttag = re.compile('<([a-zA-Z][-.a-zA-Z0-9]*)/([^/]*)/')
 piclose = re.compile('>')
-endbracket = re.compile('[<>]')
+starttag = re.compile(r'<[a-zA-Z][-_.:a-zA-Z0-9]*\s*('
+        r'\s*([a-zA-Z_][-:.a-zA-Z_0-9]*)(\s*=\s*'
+        r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~@]'
+        r'[][\-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*(?=[\s>/<])))?'
+    r')*\s*/?\s*(?=[<>])')
+endtag = re.compile(r'</?[a-zA-Z][-_.:a-zA-Z0-9]*\s*/?\s*(?=[<>])')
 tagfind = re.compile('[a-zA-Z][-_.a-zA-Z0-9]*')
 attrfind = re.compile(
     r'\s*([a-zA-Z_][-:.a-zA-Z_0-9]*)(\s*=\s*'
-    r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))?')
+    r'(\'[^\']*\'|"[^"]*"|[][\-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))?')


 class SGMLParseError(RuntimeError):
@@ -245,11 +250,10 @@
             self.finish_shorttag(tag, data)
             self.__starttag_text = rawdata[start_pos:match.end(1) + 1]
             return k
-        # XXX The following should skip matching quotes (' or ")
-        match = endbracket.search(rawdata, i+1)
+        match = starttag.match(rawdata, i)
         if not match:
             return -1
-        j = match.start(0)
+        j = match.end(0)
         # Now parse the data between i+1 and j into a tag and attrs
         attrs = []
         if rawdata[i:i+2] == '<>':
@@ -283,10 +287,10 @@
     # Internal -- parse endtag
     def parse_endtag(self, i):
         rawdata = self.rawdata
-        match = endbracket.search(rawdata, i+1)
+        match = endtag.match(rawdata, i)
         if not match:
             return -1
-        j = match.start(0)
+        j = match.end(0)
         tag = rawdata[i+2:j].strip().lower()
         if rawdata[j] == '>':
             j = j+1