Skip to content

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/html5lib/html5parser.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ def any(iterable):
1414
if element:
1515
return True
1616
return False
17+
18+
try:
19+
"abc".startswith(("a", "b"))
20+
def startswithany(str, prefixes):
21+
return str.startswith(prefixes)
22+
except:
23+
# Python 2.4 doesn't accept a tuple as argument to string startswith
24+
def startswithany(str, prefixes):
25+
for prefix in prefixes:
26+
if str.startswith(prefix):
27+
return True
28+
return False
1729

1830
import sys
1931

@@ -485,7 +497,7 @@ def processDoctype(self, token):
485497
publicId = publicId.translate(asciiUpper2Lower)
486498

487499
if (not correct or token["name"] != "html"
488-
or publicId.startswith(
500+
or startswithany(publicId,
489501
("+//silmaril//dtd html pro v0r11 19970101//",
490502
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
491503
"-//as//dtd html 3.0 aswedit + extensions//",
@@ -545,16 +557,16 @@ def processDoctype(self, token):
545557
("-//w3o//dtd w3 html strict 3.0//en//",
546558
"-/w3c/dtd html 4.0 transitional/en",
547559
"html")
548-
or publicId.startswith(
560+
or startswithany(publicId,
549561
("-//w3c//dtd html 4.01 frameset//",
550562
"-//w3c//dtd html 4.01 transitional//")) and
551563
systemId == None
552564
or systemId and systemId.lower() == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
553565
self.parser.compatMode = "quirks"
554-
elif (publicId.startswith(
566+
elif (startswithany(publicId,
555567
("-//w3c//dtd xhtml 1.0 frameset//",
556568
"-//w3c//dtd xhtml 1.0 transitional//"))
557-
or publicId.startswith(
569+
or startswithany(publicId,
558570
("-//w3c//dtd html 4.01 frameset//",
559571
"-//w3c//dtd html 4.01 transitional//")) and
560572
systemId != None):

0 commit comments

Comments
 (0)