Enable html5lib to work on Python 2.4 once again.
Props to Mark Wielaard http://lists.planetplanet.org/archives/devel/2010-May/002105.html Fixes http://code.google.com/p/html5lib/issues/detail?id=133 Broken by http://code.google.com/p/html5lib/source/diff?spec=svnf685af4b9d933107345857ee10b7d50a40943b76&r=f685af4b9d933107345857ee10b7d50a40943b76&format=side&path=/python/src/html5lib/html5parser.py#sc_svnf685af4b9d933107345857ee10b7d50a40943b76_488
This commit is contained in:
parent
9c08308166
commit
5c7edd7f56
20
planet/vendor/html5lib/html5parser.py
vendored
20
planet/vendor/html5lib/html5parser.py
vendored
@ -14,6 +14,18 @@ except:
|
||||
if element:
|
||||
return True
|
||||
return False
|
||||
|
||||
try:
|
||||
"abc".startswith(("a", "b"))
|
||||
def startswithany(str, prefixes):
|
||||
return str.startswith(prefixes)
|
||||
except:
|
||||
# Python 2.4 doesn't accept a tuple as argument to string startswith
|
||||
def startswithany(str, prefixes):
|
||||
for prefix in prefixes:
|
||||
if str.startswith(prefix):
|
||||
return True
|
||||
return False
|
||||
|
||||
import sys
|
||||
|
||||
@ -485,7 +497,7 @@ class InitialPhase(Phase):
|
||||
publicId = publicId.translate(asciiUpper2Lower)
|
||||
|
||||
if (not correct or token["name"] != "html"
|
||||
or publicId.startswith(
|
||||
or startswithany(publicId,
|
||||
("+//silmaril//dtd html pro v0r11 19970101//",
|
||||
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
|
||||
"-//as//dtd html 3.0 aswedit + extensions//",
|
||||
@ -545,16 +557,16 @@ class InitialPhase(Phase):
|
||||
("-//w3o//dtd w3 html strict 3.0//en//",
|
||||
"-/w3c/dtd html 4.0 transitional/en",
|
||||
"html")
|
||||
or publicId.startswith(
|
||||
or startswithany(publicId,
|
||||
("-//w3c//dtd html 4.01 frameset//",
|
||||
"-//w3c//dtd html 4.01 transitional//")) and
|
||||
systemId == None
|
||||
or systemId and systemId.lower() == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
|
||||
self.parser.compatMode = "quirks"
|
||||
elif (publicId.startswith(
|
||||
elif (startswithany(publicId,
|
||||
("-//w3c//dtd xhtml 1.0 frameset//",
|
||||
"-//w3c//dtd xhtml 1.0 transitional//"))
|
||||
or publicId.startswith(
|
||||
or startswithany(publicId,
|
||||
("-//w3c//dtd html 4.01 frameset//",
|
||||
"-//w3c//dtd html 4.01 transitional//")) and
|
||||
systemId != None):
|
||||
|
Loading…
Reference in New Issue
Block a user