Skip to content

Commit

Permalink
Fixed our HTMLParser patches for python 2.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Jun 22, 2012
1 parent a54a8ba commit 6bc1b22
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django/utils/html_parser.py
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
import HTMLParser as _HTMLParser import HTMLParser as _HTMLParser
import re import re


tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')


class HTMLParser(_HTMLParser.HTMLParser): class HTMLParser(_HTMLParser.HTMLParser):
""" """
Expand Down Expand Up @@ -33,10 +34,10 @@ def parse_starttag(self, i):


# Now parse the data between i+1 and j into a tag and attrs # Now parse the data between i+1 and j into a tag and attrs
attrs = [] attrs = []
match = _HTMLParser.tagfind.match(rawdata, i + 1) match = tagfind.match(rawdata, i + 1)
assert match, 'unexpected call to parse_starttag()' assert match, 'unexpected call to parse_starttag()'
k = match.end() k = match.end()
self.lasttag = tag = rawdata[i + 1:k].lower() self.lasttag = tag = match.group(1).lower()


while k < endpos: while k < endpos:
m = _HTMLParser.attrfind.match(rawdata, k) m = _HTMLParser.attrfind.match(rawdata, k)
Expand All @@ -48,6 +49,7 @@ def parse_starttag(self, i):
elif attrvalue[:1] == '\'' == attrvalue[-1:] or \ elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
attrvalue[:1] == '"' == attrvalue[-1:]: attrvalue[:1] == '"' == attrvalue[-1:]:
attrvalue = attrvalue[1:-1] attrvalue = attrvalue[1:-1]
if attrvalue:
attrvalue = self.unescape(attrvalue) attrvalue = self.unescape(attrvalue)
attrs.append((attrname.lower(), attrvalue)) attrs.append((attrname.lower(), attrvalue))
k = m.end() k = m.end()
Expand Down

0 comments on commit 6bc1b22

Please sign in to comment.