Lines Matching refs:self

55     def __init__(self, tree=None, tokenizer=tokenizer.HTMLTokenizer,  argument
70 self.strict = strict
74 self.tree = tree(namespaceHTMLElements)
75 self.tokenizer_class = tokenizer
76 self.errors = []
78 self.phases = dict([(name, cls(self, self.tree)) for name, cls in
81 def _parse(self, stream, innerHTML=False, container="div", argument
84 self.innerHTMLMode = innerHTML
85 self.container = container
86 self.tokenizer = self.tokenizer_class(stream, encoding=encoding,
89 parser=self, **kwargs)
90 self.reset()
94 self.mainLoop()
97 self.reset()
99 def reset(self): argument
100 self.tree.reset()
101 self.firstStartTag = False
102 self.errors = []
103 self.log = [] # only used with debug mode
105 self.compatMode = "no quirks"
107 if self.innerHTMLMode:
108 self.innerHTML = self.container.lower()
110 if self.innerHTML in cdataElements:
111 self.tokenizer.state = self.tokenizer.rcdataState
112 elif self.innerHTML in rcdataElements:
113 self.tokenizer.state = self.tokenizer.rawtextState
114 elif self.innerHTML == 'plaintext':
115 self.tokenizer.state = self.tokenizer.plaintextState
120 self.phase = self.phases["beforeHtml"]
121 self.phase.insertHtmlElement()
122 self.resetInsertionMode()
124 self.innerHTML = False
125 self.phase = self.phases["initial"]
127 self.lastPhase = None
129 self.beforeRCDataPhase = None
131 self.framesetOK = True
134 def documentEncoding(self): argument
140 if not hasattr(self, 'tokenizer'):
142 return self.tokenizer.stream.charEncoding[0]
144 def isHTMLIntegrationPoint(self, element): argument
154 def isMathMLTextIntegrationPoint(self, element): argument
157 def mainLoop(self): argument
166 for token in self.normalizedTokens():
169 currentNode = self.tree.openElements[-1] if self.tree.openElements else None
176 self.parseError(new_token["data"], new_token.get("datavars", {}))
179 if (len(self.tree.openElements) == 0 or
180 currentNodeNamespace == self.tree.defaultNamespace or
181 (self.isMathMLTextIntegrationPoint(currentNode) and
188 (self.isHTMLIntegrationPoint(currentNode) and
190 phase = self.phase
192 phase = self.phases["inForeignContent"]
209 self.parseError("non-void-element-with-trailing-solidus",
216 phases.append(self.phase)
217 reprocess = self.phase.processEOF()
219 assert self.phase not in phases
221 def normalizedTokens(self): argument
222 for token in self.tokenizer:
223 yield self.normalizeToken(token)
225 def parse(self, stream, encoding=None, parseMeta=True, useChardet=True): argument
235 self._parse(stream, innerHTML=False, encoding=encoding,
237 return self.tree.getDocument()
239 def parseFragment(self, stream, container="div", encoding=None, argument
253 self._parse(stream, True, container=container, encoding=encoding)
254 return self.tree.getFragment()
256 def parseError(self, errorcode="XXX-undefined-error", datavars={}): argument
258 self.errors.append((self.tokenizer.stream.position(), errorcode, datavars))
259 if self.strict:
262 def normalizeToken(self, token): argument
270 def adjustMathMLAttributes(self, token): argument
277 def adjustSVGAttributes(self, token): argument
348 def adjustForeignAttributes(self, token): argument
357 def reparseTokenNormal(self, token): argument
358 self.parser.phase()
360 def resetInsertionMode(self): argument
380 for node in self.tree.openElements[::-1]:
383 if node == self.tree.openElements[0]:
384 assert self.innerHTML
386 nodeName = self.innerHTML
390 assert self.innerHTML
392 if not last and node.namespace != self.tree.defaultNamespace:
396 new_phase = self.phases[newModes[nodeName]]
399 new_phase = self.phases["inBody"]
402 self.phase = new_phase
404 def parseRCDataRawtext(self, token, contentType): argument
410 self.tree.insertElement(token)
413 self.tokenizer.state = self.tokenizer.rawtextState
415 self.tokenizer.state = self.tokenizer.rcdataState
417 self.originalPhase = self.phase
419 self.phase = self.phases["text"]
428 def wrapped(self, *args, **kwargs): argument
438 self.parser.log.append((self.parser.tokenizer.state.__name__,
439 self.parser.phase.__class__.__name__,
440 self.__class__.__name__,
443 return function(self, *args, **kwargs)
445 return function(self, *args, **kwargs)
458 def __init__(self, parser, tree): argument
459 self.parser = parser
460 self.tree = tree
462 def processEOF(self): argument
465 def processComment(self, token): argument
468 self.tree.insertComment(token, self.tree.openElements[-1])
470 def processDoctype(self, token): argument
471 self.parser.parseError("unexpected-doctype")
473 def processCharacters(self, token): argument
474 self.tree.insertText(token["data"])
476 def processSpaceCharacters(self, token): argument
477 self.tree.insertText(token["data"])
479 def processStartTag(self, token): argument
480 return self.startTagHandler[token["name"]](token)
482 def startTagHtml(self, token): argument
483 if not self.parser.firstStartTag and token["name"] == "html":
484 self.parser.parseError("non-html-root")
488 if attr not in self.tree.openElements[0].attributes:
489 self.tree.openElements[0].attributes[attr] = value
490 self.parser.firstStartTag = False
492 def processEndTag(self, token): argument
493 return self.endTagHandler[token["name"]](token)
496 def processSpaceCharacters(self, token): argument
499 def processComment(self, token): argument
500 self.tree.insertComment(token, self.tree.document)
502 def processDoctype(self, token): argument
510 self.parser.parseError("unknown-doctype")
515 self.tree.insertDoctype(token)
586 self.parser.compatMode = "quirks"
594 self.parser.compatMode = "limited quirks"
596 self.parser.phase = self.parser.phases["beforeHtml"]
598 def anythingElse(self): argument
599 self.parser.compatMode = "quirks"
600 self.parser.phase = self.parser.phases["beforeHtml"]
602 def processCharacters(self, token): argument
603 self.parser.parseError("expected-doctype-but-got-chars")
604 self.anythingElse()
607 def processStartTag(self, token): argument
608 self.parser.parseError("expected-doctype-but-got-start-tag",
610 self.anythingElse()
613 def processEndTag(self, token): argument
614 self.parser.parseError("expected-doctype-but-got-end-tag",
616 self.anythingElse()
619 def processEOF(self): argument
620 self.parser.parseError("expected-doctype-but-got-eof")
621 self.anythingElse()
626 def insertHtmlElement(self): argument
627 self.tree.insertRoot(impliedTagToken("html", "StartTag"))
628 self.parser.phase = self.parser.phases["beforeHead"]
631 def processEOF(self): argument
632 self.insertHtmlElement()
635 def processComment(self, token): argument
636 self.tree.insertComment(token, self.tree.document)
638 def processSpaceCharacters(self, token): argument
641 def processCharacters(self, token): argument
642 self.insertHtmlElement()
645 def processStartTag(self, token): argument
647 self.parser.firstStartTag = True
648 self.insertHtmlElement()
651 def processEndTag(self, token): argument
653 self.parser.parseError("unexpected-end-tag-before-html",
656 self.insertHtmlElement()
660 def __init__(self, parser, tree): argument
661 Phase.__init__(self, parser, tree)
663 self.startTagHandler = utils.MethodDispatcher([
664 ("html", self.startTagHtml),
665 ("head", self.startTagHead)
667 self.startTagHandler.default = self.startTagOther
669 self.endTagHandler = utils.MethodDispatcher([
670 (("head", "body", "html", "br"), self.endTagImplyHead)
672 self.endTagHandler.default = self.endTagOther
674 def processEOF(self): argument
675 self.startTagHead(impliedTagToken("head", "StartTag"))
678 def processSpaceCharacters(self, token): argument
681 def processCharacters(self, token): argument
682 self.startTagHead(impliedTagToken("head", "StartTag"))
685 def startTagHtml(self, token): argument
686 return self.parser.phases["inBody"].processStartTag(token)
688 def startTagHead(self, token): argument
689 self.tree.insertElement(token)
690 self.tree.headPointer = self.tree.openElements[-1]
691 self.parser.phase = self.parser.phases["inHead"]
693 def startTagOther(self, token): argument
694 self.startTagHead(impliedTagToken("head", "StartTag"))
697 def endTagImplyHead(self, token): argument
698 self.startTagHead(impliedTagToken("head", "StartTag"))
701 def endTagOther(self, token): argument
702 self.parser.parseError("end-tag-after-implied-root",
706 def __init__(self, parser, tree): argument
707 Phase.__init__(self, parser, tree)
709 self.startTagHandler = utils.MethodDispatcher([
710 ("html", self.startTagHtml),
711 ("title", self.startTagTitle),
712 (("noscript", "noframes", "style"), self.startTagNoScriptNoFramesStyle),
713 ("script", self.startTagScript),
715 self.startTagBaseLinkCommand),
716 ("meta", self.startTagMeta),
717 ("head", self.startTagHead)
719 self.startTagHandler.default = self.startTagOther
721 self. endTagHandler = utils.MethodDispatcher([
722 ("head", self.endTagHead),
723 (("br", "html", "body"), self.endTagHtmlBodyBr)
725 self.endTagHandler.default = self.endTagOther
728 def processEOF(self): argument
729 self.anythingElse()
732 def processCharacters(self, token): argument
733 self.anythingElse()
736 def startTagHtml(self, token): argument
737 return self.parser.phases["inBody"].processStartTag(token)
739 def startTagHead(self, token): argument
740 self.parser.parseError("two-heads-are-not-better-than-one")
742 def startTagBaseLinkCommand(self, token): argument
743 self.tree.insertElement(token)
744 self.tree.openElements.pop()
747 def startTagMeta(self, token): argument
748 self.tree.insertElement(token)
749 self.tree.openElements.pop()
753 if self.parser.tokenizer.stream.charEncoding[1] == "tentative":
755 self.parser.tokenizer.stream.changeEncoding(attributes["charset"])
766 self.parser.tokenizer.stream.changeEncoding(codec)
768 def startTagTitle(self, token): argument
769 self.parser.parseRCDataRawtext(token, "RCDATA")
771 def startTagNoScriptNoFramesStyle(self, token): argument
773 self.parser.parseRCDataRawtext(token, "RAWTEXT")
775 def startTagScript(self, token): argument
776 self.tree.insertElement(token)
777 self.parser.tokenizer.state = self.parser.tokenizer.scriptDataState
778 self.parser.originalPhase = self.parser.phase
779 self.parser.phase = self.parser.phases["text"]
781 def startTagOther(self, token): argument
782 self.anythingElse()
785 def endTagHead(self, token): argument
786 node = self.parser.tree.openElements.pop()
788 self.parser.phase = self.parser.phases["afterHead"]
790 def endTagHtmlBodyBr(self, token): argument
791 self.anythingElse()
794 def endTagOther(self, token): argument
795 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
797 def anythingElse(self): argument
798 self.endTagHead(impliedTagToken("head"))
805 def __init__(self, parser, tree): argument
806 Phase.__init__(self, parser, tree)
808 self.startTagHandler = utils.MethodDispatcher([
809 ("html", self.startTagHtml),
810 ("body", self.startTagBody),
811 ("frameset", self.startTagFrameset),
814 self.startTagFromHead),
815 ("head", self.startTagHead)
817 self.startTagHandler.default = self.startTagOther
818 self.endTagHandler = utils.MethodDispatcher([(("body", "html", "br"),
819 self.endTagHtmlBodyBr)])
820 self.endTagHandler.default = self.endTagOther
822 def processEOF(self): argument
823 self.anythingElse()
826 def processCharacters(self, token): argument
827 self.anythingElse()
830 def startTagHtml(self, token): argument
831 return self.parser.phases["inBody"].processStartTag(token)
833 def startTagBody(self, token): argument
834 self.parser.framesetOK = False
835 self.tree.insertElement(token)
836 self.parser.phase = self.parser.phases["inBody"]
838 def startTagFrameset(self, token): argument
839 self.tree.insertElement(token)
840 self.parser.phase = self.parser.phases["inFrameset"]
842 def startTagFromHead(self, token): argument
843 self.parser.parseError("unexpected-start-tag-out-of-my-head",
845 self.tree.openElements.append(self.tree.headPointer)
846 self.parser.phases["inHead"].processStartTag(token)
847 for node in self.tree.openElements[::-1]:
849 self.tree.openElements.remove(node)
852 def startTagHead(self, token): argument
853 self.parser.parseError("unexpected-start-tag", {"name": token["name"]})
855 def startTagOther(self, token): argument
856 self.anythingElse()
859 def endTagHtmlBodyBr(self, token): argument
860 self.anythingElse()
863 def endTagOther(self, token): argument
864 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
866 def anythingElse(self): argument
867 self.tree.insertElement(impliedTagToken("body", "StartTag"))
868 self.parser.phase = self.parser.phases["inBody"]
869 self.parser.framesetOK = True
874 def __init__(self, parser, tree): argument
875 Phase.__init__(self, parser, tree)
878 self.processSpaceCharactersNonPre = self.processSpaceCharacters
880 self.startTagHandler = utils.MethodDispatcher([
881 ("html", self.startTagHtml),
884 self.startTagProcessInHead),
885 ("body", self.startTagBody),
886 ("frameset", self.startTagFrameset),
891 self.startTagCloseP),
892 (headingElements, self.startTagHeading),
893 (("pre", "listing"), self.startTagPreListing),
894 ("form", self.startTagForm),
895 (("li", "dd", "dt"), self.startTagListItem),
896 ("plaintext", self.startTagPlaintext),
897 ("a", self.startTagA),
899 "strong", "tt", "u"), self.startTagFormatting),
900 ("nobr", self.startTagNobr),
901 ("button", self.startTagButton),
902 (("applet", "marquee", "object"), self.startTagAppletMarqueeObject),
903 ("xmp", self.startTagXmp),
904 ("table", self.startTagTable),
906 self.startTagVoidFormatting),
907 (("param", "source", "track"), self.startTagParamSource),
908 ("input", self.startTagInput),
909 ("hr", self.startTagHr),
910 ("image", self.startTagImage),
911 ("isindex", self.startTagIsIndex),
912 ("textarea", self.startTagTextarea),
913 ("iframe", self.startTagIFrame),
914 (("noembed", "noframes", "noscript"), self.startTagRawtext),
915 ("select", self.startTagSelect),
916 (("rp", "rt"), self.startTagRpRt),
917 (("option", "optgroup"), self.startTagOpt),
918 (("math"), self.startTagMath),
919 (("svg"), self.startTagSvg),
922 "tr"), self.startTagMisplaced)
924 self.startTagHandler.default = self.startTagOther
926 self.endTagHandler = utils.MethodDispatcher([
927 ("body", self.endTagBody),
928 ("html", self.endTagHtml),
932 "section", "summary", "ul"), self.endTagBlock),
933 ("form", self.endTagForm),
934 ("p", self.endTagP),
935 (("dd", "dt", "li"), self.endTagListItem),
936 (headingElements, self.endTagHeading),
938 "strike", "strong", "tt", "u"), self.endTagFormatting),
939 (("applet", "marquee", "object"), self.endTagAppletMarqueeObject),
940 ("br", self.endTagBr),
942 self.endTagHandler.default = self.endTagOther
944 def isMatchingFormattingElement(self, node1, node2): argument
958 def addFormattingElement(self, token): argument
959 self.tree.insertElement(token)
960 element = self.tree.openElements[-1]
963 for node in self.tree.activeFormattingElements[::-1]:
966 elif self.isMatchingFormattingElement(node, element):
971 self.tree.activeFormattingElements.remove(matchingElements[-1])
972 self.tree.activeFormattingElements.append(element)
975 def processEOF(self): argument
979 for node in self.tree.openElements[::-1]:
981 self.parser.parseError("expected-closing-tag-but-got-eof")
985 def processSpaceCharactersDropNewline(self, token): argument
989 self.processSpaceCharacters = self.processSpaceCharactersNonPre
991 self.tree.openElements[-1].name in ("pre", "listing", "textarea")
992 and not self.tree.openElements[-1].hasContent()):
995 self.tree.reconstructActiveFormattingElements()
996 self.tree.insertText(data)
998 def processCharacters(self, token): argument
1002 self.tree.reconstructActiveFormattingElements()
1003 self.tree.insertText(token["data"])
1005 if (self.parser.framesetOK and
1008 self.parser.framesetOK = False
1010 def processSpaceCharacters(self, token): argument
1011 self.tree.reconstructActiveFormattingElements()
1012 self.tree.insertText(token["data"])
1014 def startTagProcessInHead(self, token): argument
1015 return self.parser.phases["inHead"].processStartTag(token)
1017 def startTagBody(self, token): argument
1018 self.parser.parseError("unexpected-start-tag", {"name": "body"})
1019 if (len(self.tree.openElements) == 1
1020 or self.tree.openElements[1].name != "body"):
1021 assert self.parser.innerHTML
1023 self.parser.framesetOK = False
1025 if attr not in self.tree.openElements[1].attributes:
1026 self.tree.openElements[1].attributes[attr] = value
1028 def startTagFrameset(self, token): argument
1029 self.parser.parseError("unexpected-start-tag", {"name": "frameset"})
1030 if (len(self.tree.openElements) == 1 or self.tree.openElements[1].name != "body"):
1031 assert self.parser.innerHTML
1032 elif not self.parser.framesetOK:
1035 if self.tree.openElements[1].parent:
1036 self.tree.openElements[1].parent.removeChild(self.tree.openElements[1])
1037 while self.tree.openElements[-1].name != "html":
1038 self.tree.openElements.pop()
1039 self.tree.insertElement(token)
1040 self.parser.phase = self.parser.phases["inFrameset"]
1042 def startTagCloseP(self, token): argument
1043 if self.tree.elementInScope("p", variant="button"):
1044 self.endTagP(impliedTagToken("p"))
1045 self.tree.insertElement(token)
1047 def startTagPreListing(self, token): argument
1048 if self.tree.elementInScope("p", variant="button"):
1049 self.endTagP(impliedTagToken("p"))
1050 self.tree.insertElement(token)
1051 self.parser.framesetOK = False
1052 self.processSpaceCharacters = self.processSpaceCharactersDropNewline
1054 def startTagForm(self, token): argument
1055 if self.tree.formPointer:
1056 self.parser.parseError("unexpected-start-tag", {"name": "form"})
1058 if self.tree.elementInScope("p", variant="button"):
1059 self.endTagP(impliedTagToken("p"))
1060 self.tree.insertElement(token)
1061 self.tree.formPointer = self.tree.openElements[-1]
1063 def startTagListItem(self, token): argument
1064 self.parser.framesetOK = False
1070 for node in reversed(self.tree.openElements):
1072 self.parser.phase.processEndTag(
1079 if self.tree.elementInScope("p", variant="button"):
1080 self.parser.phase.processEndTag(
1083 self.tree.insertElement(token)
1085 def startTagPlaintext(self, token): argument
1086 if self.tree.elementInScope("p", variant="button"):
1087 self.endTagP(impliedTagToken("p"))
1088 self.tree.insertElement(token)
1089 self.parser.tokenizer.state = self.parser.tokenizer.plaintextState
1091 def startTagHeading(self, token): argument
1092 if self.tree.elementInScope("p", variant="button"):
1093 self.endTagP(impliedTagToken("p"))
1094 if self.tree.openElements[-1].name in headingElements:
1095 self.parser.parseError("unexpected-start-tag", {"name": token["name"]})
1096 self.tree.openElements.pop()
1097 self.tree.insertElement(token)
1099 def startTagA(self, token): argument
1100 afeAElement = self.tree.elementInActiveFormattingElements("a")
1102 self.parser.parseError("unexpected-start-tag-implies-end-tag",
1104 self.endTagFormatting(impliedTagToken("a"))
1105 if afeAElement in self.tree.openElements:
1106 self.tree.openElements.remove(afeAElement)
1107 if afeAElement in self.tree.activeFormattingElements:
1108 self.tree.activeFormattingElements.remove(afeAElement)
1109 self.tree.reconstructActiveFormattingElements()
1110 self.addFormattingElement(token)
1112 def startTagFormatting(self, token): argument
1113 self.tree.reconstructActiveFormattingElements()
1114 self.addFormattingElement(token)
1116 def startTagNobr(self, token): argument
1117 self.tree.reconstructActiveFormattingElements()
1118 if self.tree.elementInScope("nobr"):
1119 self.parser.parseError("unexpected-start-tag-implies-end-tag",
1121 self.processEndTag(impliedTagToken("nobr"))
1123 self.tree.reconstructActiveFormattingElements()
1124 self.addFormattingElement(token)
1126 def startTagButton(self, token): argument
1127 if self.tree.elementInScope("button"):
1128 self.parser.parseError("unexpected-start-tag-implies-end-tag",
1130 self.processEndTag(impliedTagToken("button"))
1133 self.tree.reconstructActiveFormattingElements()
1134 self.tree.insertElement(token)
1135 self.parser.framesetOK = False
1137 def startTagAppletMarqueeObject(self, token): argument
1138 self.tree.reconstructActiveFormattingElements()
1139 self.tree.insertElement(token)
1140 self.tree.activeFormattingElements.append(Marker)
1141 self.parser.framesetOK = False
1143 def startTagXmp(self, token): argument
1144 if self.tree.elementInScope("p", variant="button"):
1145 self.endTagP(impliedTagToken("p"))
1146 self.tree.reconstructActiveFormattingElements()
1147 self.parser.framesetOK = False
1148 self.parser.parseRCDataRawtext(token, "RAWTEXT")
1150 def startTagTable(self, token): argument
1151 if self.parser.compatMode != "quirks":
1152 if self.tree.elementInScope("p", variant="button"):
1153 self.processEndTag(impliedTagToken("p"))
1154 self.tree.insertElement(token)
1155 self.parser.framesetOK = False
1156 self.parser.phase = self.parser.phases["inTable"]
1158 def startTagVoidFormatting(self, token): argument
1159 self.tree.reconstructActiveFormattingElements()
1160 self.tree.insertElement(token)
1161 self.tree.openElements.pop()
1163 self.parser.framesetOK = False
1165 def startTagInput(self, token): argument
1166 framesetOK = self.parser.framesetOK
1167 self.startTagVoidFormatting(token)
1171 self.parser.framesetOK = framesetOK
1173 def startTagParamSource(self, token): argument
1174 self.tree.insertElement(token)
1175 self.tree.openElements.pop()
1178 def startTagHr(self, token): argument
1179 if self.tree.elementInScope("p", variant="button"):
1180 self.endTagP(impliedTagToken("p"))
1181 self.tree.insertElement(token)
1182 self.tree.openElements.pop()
1184 self.parser.framesetOK = False
1186 def startTagImage(self, token): argument
1188 self.parser.parseError("unexpected-start-tag-treated-as",
1190 self.processStartTag(impliedTagToken("img", "StartTag",
1194 def startTagIsIndex(self, token): argument
1195 self.parser.parseError("deprecated-tag", {"name": "isindex"})
1196 if self.tree.formPointer:
1201 self.processStartTag(impliedTagToken("form", "StartTag",
1203 self.processStartTag(impliedTagToken("hr", "StartTag"))
1204 self.processStartTag(impliedTagToken("label", "StartTag"))
1210 self.processCharacters(
1218 self.processStartTag(impliedTagToken("input", "StartTag",
1221 self.processEndTag(impliedTagToken("label"))
1222 self.processStartTag(impliedTagToken("hr", "StartTag"))
1223 self.processEndTag(impliedTagToken("form"))
1225 def startTagTextarea(self, token): argument
1226 self.tree.insertElement(token)
1227 self.parser.tokenizer.state = self.parser.tokenizer.rcdataState
1228 self.processSpaceCharacters = self.processSpaceCharactersDropNewline
1229 self.parser.framesetOK = False
1231 def startTagIFrame(self, token): argument
1232 self.parser.framesetOK = False
1233 self.startTagRawtext(token)
1235 def startTagRawtext(self, token): argument
1237 self.parser.parseRCDataRawtext(token, "RAWTEXT")
1239 def startTagOpt(self, token): argument
1240 if self.tree.openElements[-1].name == "option":
1241 self.parser.phase.processEndTag(impliedTagToken("option"))
1242 self.tree.reconstructActiveFormattingElements()
1243 self.parser.tree.insertElement(token)
1245 def startTagSelect(self, token): argument
1246 self.tree.reconstructActiveFormattingElements()
1247 self.tree.insertElement(token)
1248 self.parser.framesetOK = False
1249 if self.parser.phase in (self.parser.phases["inTable"],
1250 self.parser.phases["inCaption"],
1251 self.parser.phases["inColumnGroup"],
1252 self.parser.phases["inTableBody"],
1253 self.parser.phases["inRow"],
1254 self.parser.phases["inCell"]):
1255 self.parser.phase = self.parser.phases["inSelectInTable"]
1257 self.parser.phase = self.parser.phases["inSelect"]
1259 def startTagRpRt(self, token): argument
1260 if self.tree.elementInScope("ruby"):
1261 self.tree.generateImpliedEndTags()
1262 if self.tree.openElements[-1].name != "ruby":
1263 self.parser.parseError()
1264 self.tree.insertElement(token)
1266 def startTagMath(self, token): argument
1267 self.tree.reconstructActiveFormattingElements()
1268 self.parser.adjustMathMLAttributes(token)
1269 self.parser.adjustForeignAttributes(token)
1271 self.tree.insertElement(token)
1275 self.tree.openElements.pop()
1278 def startTagSvg(self, token): argument
1279 self.tree.reconstructActiveFormattingElements()
1280 self.parser.adjustSVGAttributes(token)
1281 self.parser.adjustForeignAttributes(token)
1283 self.tree.insertElement(token)
1287 self.tree.openElements.pop()
1290 def startTagMisplaced(self, token): argument
1297 self.parser.parseError("unexpected-start-tag-ignored", {"name": token["name"]})
1299 def startTagOther(self, token): argument
1300 self.tree.reconstructActiveFormattingElements()
1301 self.tree.insertElement(token)
1303 def endTagP(self, token): argument
1304 if not self.tree.elementInScope("p", variant="button"):
1305 self.startTagCloseP(impliedTagToken("p", "StartTag"))
1306 self.parser.parseError("unexpected-end-tag", {"name": "p"})
1307 self.endTagP(impliedTagToken("p", "EndTag"))
1309 self.tree.generateImpliedEndTags("p")
1310 if self.tree.openElements[-1].name != "p":
1311 self.parser.parseError("unexpected-end-tag", {"name": "p"})
1312 node = self.tree.openElements.pop()
1314 node = self.tree.openElements.pop()
1316 def endTagBody(self, token): argument
1317 if not self.tree.elementInScope("body"):
1318 self.parser.parseError()
1320 elif self.tree.openElements[-1].name != "body":
1321 for node in self.tree.openElements[2:]:
1328 self.parser.parseError(
1332 self.parser.phase = self.parser.phases["afterBody"]
1334 def endTagHtml(self, token): argument
1336 if self.tree.elementInScope("body"):
1337 self.endTagBody(impliedTagToken("body"))
1340 def endTagBlock(self, token): argument
1343 self.processSpaceCharacters = self.processSpaceCharactersNonPre
1344 inScope = self.tree.elementInScope(token["name"])
1346 self.tree.generateImpliedEndTags()
1347 if self.tree.openElements[-1].name != token["name"]:
1348 self.parser.parseError("end-tag-too-early", {"name": token["name"]})
1350 node = self.tree.openElements.pop()
1352 node = self.tree.openElements.pop()
1354 def endTagForm(self, token): argument
1355 node = self.tree.formPointer
1356 self.tree.formPointer = None
1357 if node is None or not self.tree.elementInScope(node):
1358 self.parser.parseError("unexpected-end-tag",
1361 self.tree.generateImpliedEndTags()
1362 if self.tree.openElements[-1] != node:
1363 self.parser.parseError("end-tag-too-early-ignored",
1365 self.tree.openElements.remove(node)
1367 def endTagListItem(self, token): argument
1372 if not self.tree.elementInScope(token["name"], variant=variant):
1373 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
1375 self.tree.generateImpliedEndTags(exclude=token["name"])
1376 if self.tree.openElements[-1].name != token["name"]:
1377 self.parser.parseError(
1380 node = self.tree.openElements.pop()
1382 node = self.tree.openElements.pop()
1384 def endTagHeading(self, token): argument
1386 if self.tree.elementInScope(item):
1387 self.tree.generateImpliedEndTags()
1389 if self.tree.openElements[-1].name != token["name"]:
1390 self.parser.parseError("end-tag-too-early", {"name": token["name"]})
1393 if self.tree.elementInScope(item):
1394 item = self.tree.openElements.pop()
1396 item = self.tree.openElements.pop()
1399 def endTagFormatting(self, token): argument
1421 formattingElement = self.tree.elementInActiveFormattingElements(
1424 (formattingElement in self.tree.openElements and
1425 not self.tree.elementInScope(formattingElement.name))):
1429 self.endTagOther(token)
1436 elif formattingElement not in self.tree.openElements:
1437 self.parser.parseError("adoption-agency-1.2", {"name": token["name"]})
1438 self.tree.activeFormattingElements.remove(formattingElement)
1445 elif not self.tree.elementInScope(formattingElement.name):
1446 self.parser.parseError("adoption-agency-4.4", {"name": token["name"]})
1455 if formattingElement != self.tree.openElements[-1]:
1456 self.parser.parseError("adoption-agency-1.3", {"name": token["name"]})
1464 afeIndex = self.tree.openElements.index(formattingElement)
1466 for element in self.tree.openElements[afeIndex:]:
1480 element = self.tree.openElements.pop()
1482 element = self.tree.openElements.pop()
1483 self.tree.activeFormattingElements.remove(element)
1487 commonAncestor = self.tree.openElements[afeIndex - 1]
1494 bookmark = self.tree.activeFormattingElements.index(formattingElement)
1500 index = self.tree.openElements.index(node)
1505 node = self.tree.openElements[index]
1506 if node not in self.tree.activeFormattingElements:
1507 self.tree.openElements.remove(node)
1514 bookmark = self.tree.activeFormattingElements.index(node) + 1
1518 self.tree.activeFormattingElements[
1519 self.tree.activeFormattingElements.index(node)] = clone
1520 self.tree.openElements[
1521 self.tree.openElements.index(node)] = clone
1539 parent, insertBefore = self.tree.getTableMisnestedNodePosition()
1554 self.tree.activeFormattingElements.remove(formattingElement)
1555 self.tree.activeFormattingElements.insert(bookmark, clone)
1558 self.tree.openElements.remove(formattingElement)
1559 self.tree.openElements.insert(
1560 self.tree.openElements.index(furthestBlock) + 1, clone)
1562 def endTagAppletMarqueeObject(self, token): argument
1563 if self.tree.elementInScope(token["name"]):
1564 self.tree.generateImpliedEndTags()
1565 if self.tree.openElements[-1].name != token["name"]:
1566 self.parser.parseError("end-tag-too-early", {"name": token["name"]})
1568 if self.tree.elementInScope(token["name"]):
1569 element = self.tree.openElements.pop()
1571 element = self.tree.openElements.pop()
1572 self.tree.clearActiveFormattingElements()
1574 def endTagBr(self, token): argument
1575 self.parser.parseError("unexpected-end-tag-treated-as",
1577 self.tree.reconstructActiveFormattingElements()
1578 self.tree.insertElement(impliedTagToken("br", "StartTag"))
1579 self.tree.openElements.pop()
1581 def endTagOther(self, token): argument
1582 for node in self.tree.openElements[::-1]:
1584 self.tree.generateImpliedEndTags(exclude=token["name"])
1585 if self.tree.openElements[-1].name != token["name"]:
1586 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
1587 while self.tree.openElements.pop() != node:
1592 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
1596 def __init__(self, parser, tree): argument
1597 Phase.__init__(self, parser, tree)
1598 self.startTagHandler = utils.MethodDispatcher([])
1599 self.startTagHandler.default = self.startTagOther
1600 self.endTagHandler = utils.MethodDispatcher([
1601 ("script", self.endTagScript)])
1602 self.endTagHandler.default = self.endTagOther
1604 def processCharacters(self, token): argument
1605 self.tree.insertText(token["data"])
1607 def processEOF(self): argument
1608 self.parser.parseError("expected-named-closing-tag-but-got-eof",
1609 {"name": self.tree.openElements[-1].name})
1610 self.tree.openElements.pop()
1611 self.parser.phase = self.parser.originalPhase
1614 def startTagOther(self, token): argument
1617 def endTagScript(self, token): argument
1618 node = self.tree.openElements.pop()
1620 self.parser.phase = self.parser.originalPhase
1624 def endTagOther(self, token): argument
1625 self.tree.openElements.pop()
1626 self.parser.phase = self.parser.originalPhase
1630 def __init__(self, parser, tree): argument
1631 Phase.__init__(self, parser, tree)
1632 self.startTagHandler = utils.MethodDispatcher([
1633 ("html", self.startTagHtml),
1634 ("caption", self.startTagCaption),
1635 ("colgroup", self.startTagColgroup),
1636 ("col", self.startTagCol),
1637 (("tbody", "tfoot", "thead"), self.startTagRowGroup),
1638 (("td", "th", "tr"), self.startTagImplyTbody),
1639 ("table", self.startTagTable),
1640 (("style", "script"), self.startTagStyleScript),
1641 ("input", self.startTagInput),
1642 ("form", self.startTagForm)
1644 self.startTagHandler.default = self.startTagOther
1646 self.endTagHandler = utils.MethodDispatcher([
1647 ("table", self.endTagTable),
1649 "tfoot", "th", "thead", "tr"), self.endTagIgnore)
1651 self.endTagHandler.default = self.endTagOther
1654 def clearStackToTableContext(self): argument
1656 while self.tree.openElements[-1].name not in ("table", "html"):
1659 self.tree.openElements.pop()
1663 def processEOF(self): argument
1664 if self.tree.openElements[-1].name != "html":
1665 self.parser.parseError("eof-in-table")
1667 assert self.parser.innerHTML
1670 def processSpaceCharacters(self, token): argument
1671 originalPhase = self.parser.phase
1672 self.parser.phase = self.parser.phases["inTableText"]
1673 self.parser.phase.originalPhase = originalPhase
1674 self.parser.phase.processSpaceCharacters(token)
1676 def processCharacters(self, token): argument
1677 originalPhase = self.parser.phase
1678 self.parser.phase = self.parser.phases["inTableText"]
1679 self.parser.phase.originalPhase = originalPhase
1680 self.parser.phase.processCharacters(token)
1682 def insertText(self, token): argument
1685 self.tree.insertFromTable = True
1686 self.parser.phases["inBody"].processCharacters(token)
1687 self.tree.insertFromTable = False
1689 def startTagCaption(self, token): argument
1690 self.clearStackToTableContext()
1691 self.tree.activeFormattingElements.append(Marker)
1692 self.tree.insertElement(token)
1693 self.parser.phase = self.parser.phases["inCaption"]
1695 def startTagColgroup(self, token): argument
1696 self.clearStackToTableContext()
1697 self.tree.insertElement(token)
1698 self.parser.phase = self.parser.phases["inColumnGroup"]
1700 def startTagCol(self, token): argument
1701 self.startTagColgroup(impliedTagToken("colgroup", "StartTag"))
1704 def startTagRowGroup(self, token): argument
1705 self.clearStackToTableContext()
1706 self.tree.insertElement(token)
1707 self.parser.phase = self.parser.phases["inTableBody"]
1709 def startTagImplyTbody(self, token): argument
1710 self.startTagRowGroup(impliedTagToken("tbody", "StartTag"))
1713 def startTagTable(self, token): argument
1714 self.parser.parseError("unexpected-start-tag-implies-end-tag",
1716 self.parser.phase.processEndTag(impliedTagToken("table"))
1717 if not self.parser.innerHTML:
1720 def startTagStyleScript(self, token): argument
1721 return self.parser.phases["inHead"].processStartTag(token)
1723 def startTagInput(self, token): argument
1726 self.parser.parseError("unexpected-hidden-input-in-table")
1727 self.tree.insertElement(token)
1729 self.tree.openElements.pop()
1731 self.startTagOther(token)
1733 def startTagForm(self, token): argument
1734 self.parser.parseError("unexpected-form-in-table")
1735 if self.tree.formPointer is None:
1736 self.tree.insertElement(token)
1737 self.tree.formPointer = self.tree.openElements[-1]
1738 self.tree.openElements.pop()
1740 def startTagOther(self, token): argument
1741self.parser.parseError("unexpected-start-tag-implies-table-voodoo", {"name": token["name"]})
1743 self.tree.insertFromTable = True
1744 self.parser.phases["inBody"].processStartTag(token)
1745 self.tree.insertFromTable = False
1747 def endTagTable(self, token): argument
1748 if self.tree.elementInScope("table", variant="table"):
1749 self.tree.generateImpliedEndTags()
1750 if self.tree.openElements[-1].name != "table":
1751 self.parser.parseError("end-tag-too-early-named",
1753 "expectedName": self.tree.openElements[-1].name})
1754 while self.tree.openElements[-1].name != "table":
1755 self.tree.openElements.pop()
1756 self.tree.openElements.pop()
1757 self.parser.resetInsertionMode()
1760 assert self.parser.innerHTML
1761 self.parser.parseError()
1763 def endTagIgnore(self, token): argument
1764 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
1766 def endTagOther(self, token): argument
1767self.parser.parseError("unexpected-end-tag-implies-table-voodoo", {"name": token["name"]})
1769 self.tree.insertFromTable = True
1770 self.parser.phases["inBody"].processEndTag(token)
1771 self.tree.insertFromTable = False
1774 def __init__(self, parser, tree): argument
1775 Phase.__init__(self, parser, tree)
1776 self.originalPhase = None
1777 self.characterTokens = []
1779 def flushCharacters(self): argument
1780 data = "".join([item["data"] for item in self.characterTokens])
1783 self.parser.phases["inTable"].insertText(token)
1785 self.tree.insertText(data)
1786 self.characterTokens = []
1788 def processComment(self, token): argument
1789 self.flushCharacters()
1790 self.parser.phase = self.originalPhase
1793 def processEOF(self): argument
1794 self.flushCharacters()
1795 self.parser.phase = self.originalPhase
1798 def processCharacters(self, token): argument
1801 self.characterTokens.append(token)
1803 def processSpaceCharacters(self, token): argument
1805 self.characterTokens.append(token)
1808 def processStartTag(self, token): argument
1809 self.flushCharacters()
1810 self.parser.phase = self.originalPhase
1813 def processEndTag(self, token): argument
1814 self.flushCharacters()
1815 self.parser.phase = self.originalPhase
1820 def __init__(self, parser, tree): argument
1821 Phase.__init__(self, parser, tree)
1823 self.startTagHandler = utils.MethodDispatcher([
1824 ("html", self.startTagHtml),
1826 "thead", "tr"), self.startTagTableElement)
1828 self.startTagHandler.default = self.startTagOther
1830 self.endTagHandler = utils.MethodDispatcher([
1831 ("caption", self.endTagCaption),
1832 ("table", self.endTagTable),
1834 "thead", "tr"), self.endTagIgnore)
1836 self.endTagHandler.default = self.endTagOther
1838 def ignoreEndTagCaption(self): argument
1839 return not self.tree.elementInScope("caption", variant="table")
1841 def processEOF(self): argument
1842 self.parser.phases["inBody"].processEOF()
1844 def processCharacters(self, token): argument
1845 return self.parser.phases["inBody"].processCharacters(token)
1847 def startTagTableElement(self, token): argument
1848 self.parser.parseError()
1850 ignoreEndTag = self.ignoreEndTagCaption()
1851 self.parser.phase.processEndTag(impliedTagToken("caption"))
1855 def startTagOther(self, token): argument
1856 return self.parser.phases["inBody"].processStartTag(token)
1858 def endTagCaption(self, token): argument
1859 if not self.ignoreEndTagCaption():
1861 self.tree.generateImpliedEndTags()
1862 if self.tree.openElements[-1].name != "caption":
1863 self.parser.parseError("expected-one-end-tag-but-got-another",
1865 "expectedName": self.tree.openElements[-1].name})
1866 while self.tree.openElements[-1].name != "caption":
1867 self.tree.openElements.pop()
1868 self.tree.openElements.pop()
1869 self.tree.clearActiveFormattingElements()
1870 self.parser.phase = self.parser.phases["inTable"]
1873 assert self.parser.innerHTML
1874 self.parser.parseError()
1876 def endTagTable(self, token): argument
1877 self.parser.parseError()
1878 ignoreEndTag = self.ignoreEndTagCaption()
1879 self.parser.phase.processEndTag(impliedTagToken("caption"))
1883 def endTagIgnore(self, token): argument
1884 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
1886 def endTagOther(self, token): argument
1887 return self.parser.phases["inBody"].processEndTag(token)
1892 def __init__(self, parser, tree): argument
1893 Phase.__init__(self, parser, tree)
1895 self.startTagHandler = utils.MethodDispatcher([
1896 ("html", self.startTagHtml),
1897 ("col", self.startTagCol)
1899 self.startTagHandler.default = self.startTagOther
1901 self.endTagHandler = utils.MethodDispatcher([
1902 ("colgroup", self.endTagColgroup),
1903 ("col", self.endTagCol)
1905 self.endTagHandler.default = self.endTagOther
1907 def ignoreEndTagColgroup(self): argument
1908 return self.tree.openElements[-1].name == "html"
1910 def processEOF(self): argument
1911 if self.tree.openElements[-1].name == "html":
1912 assert self.parser.innerHTML
1915 ignoreEndTag = self.ignoreEndTagColgroup()
1916 self.endTagColgroup(impliedTagToken("colgroup"))
1920 def processCharacters(self, token): argument
1921 ignoreEndTag = self.ignoreEndTagColgroup()
1922 self.endTagColgroup(impliedTagToken("colgroup"))
1926 def startTagCol(self, token): argument
1927 self.tree.insertElement(token)
1928 self.tree.openElements.pop()
1930 def startTagOther(self, token): argument
1931 ignoreEndTag = self.ignoreEndTagColgroup()
1932 self.endTagColgroup(impliedTagToken("colgroup"))
1936 def endTagColgroup(self, token): argument
1937 if self.ignoreEndTagColgroup():
1939 assert self.parser.innerHTML
1940 self.parser.parseError()
1942 self.tree.openElements.pop()
1943 self.parser.phase = self.parser.phases["inTable"]
1945 def endTagCol(self, token): argument
1946 self.parser.parseError("no-end-tag", {"name": "col"})
1948 def endTagOther(self, token): argument
1949 ignoreEndTag = self.ignoreEndTagColgroup()
1950 self.endTagColgroup(impliedTagToken("colgroup"))
1956 def __init__(self, parser, tree): argument
1957 Phase.__init__(self, parser, tree)
1958 self.startTagHandler = utils.MethodDispatcher([
1959 ("html", self.startTagHtml),
1960 ("tr", self.startTagTr),
1961 (("td", "th"), self.startTagTableCell),
1963 self.startTagTableOther)
1965 self.startTagHandler.default = self.startTagOther
1967 self.endTagHandler = utils.MethodDispatcher([
1968 (("tbody", "tfoot", "thead"), self.endTagTableRowGroup),
1969 ("table", self.endTagTable),
1971 "tr"), self.endTagIgnore)
1973 self.endTagHandler.default = self.endTagOther
1976 def clearStackToTableBodyContext(self): argument
1977 while self.tree.openElements[-1].name not in ("tbody", "tfoot",
1981 self.tree.openElements.pop()
1982 if self.tree.openElements[-1].name == "html":
1983 assert self.parser.innerHTML
1986 def processEOF(self): argument
1987 self.parser.phases["inTable"].processEOF()
1989 def processSpaceCharacters(self, token): argument
1990 return self.parser.phases["inTable"].processSpaceCharacters(token)
1992 def processCharacters(self, token): argument
1993 return self.parser.phases["inTable"].processCharacters(token)
1995 def startTagTr(self, token): argument
1996 self.clearStackToTableBodyContext()
1997 self.tree.insertElement(token)
1998 self.parser.phase = self.parser.phases["inRow"]
2000 def startTagTableCell(self, token): argument
2001 self.parser.parseError("unexpected-cell-in-table-body",
2003 self.startTagTr(impliedTagToken("tr", "StartTag"))
2006 def startTagTableOther(self, token): argument
2008 if (self.tree.elementInScope("tbody", variant="table") or
2009 self.tree.elementInScope("thead", variant="table") or
2010 self.tree.elementInScope("tfoot", variant="table")):
2011 self.clearStackToTableBodyContext()
2012 self.endTagTableRowGroup(
2013 impliedTagToken(self.tree.openElements[-1].name))
2017 assert self.parser.innerHTML
2018 self.parser.parseError()
2020 def startTagOther(self, token): argument
2021 return self.parser.phases["inTable"].processStartTag(token)
2023 def endTagTableRowGroup(self, token): argument
2024 if self.tree.elementInScope(token["name"], variant="table"):
2025 self.clearStackToTableBodyContext()
2026 self.tree.openElements.pop()
2027 self.parser.phase = self.parser.phases["inTable"]
2029 self.parser.parseError("unexpected-end-tag-in-table-body",
2032 def endTagTable(self, token): argument
2033 if (self.tree.elementInScope("tbody", variant="table") or
2034 self.tree.elementInScope("thead", variant="table") or
2035 self.tree.elementInScope("tfoot", variant="table")):
2036 self.clearStackToTableBodyContext()
2037 self.endTagTableRowGroup(
2038 impliedTagToken(self.tree.openElements[-1].name))
2042 assert self.parser.innerHTML
2043 self.parser.parseError()
2045 def endTagIgnore(self, token): argument
2046 self.parser.parseError("unexpected-end-tag-in-table-body",
2049 def endTagOther(self, token): argument
2050 return self.parser.phases["inTable"].processEndTag(token)
2054 def __init__(self, parser, tree): argument
2055 Phase.__init__(self, parser, tree)
2056 self.startTagHandler = utils.MethodDispatcher([
2057 ("html", self.startTagHtml),
2058 (("td", "th"), self.startTagTableCell),
2060 "tr"), self.startTagTableOther)
2062 self.startTagHandler.default = self.startTagOther
2064 self.endTagHandler = utils.MethodDispatcher([
2065 ("tr", self.endTagTr),
2066 ("table", self.endTagTable),
2067 (("tbody", "tfoot", "thead"), self.endTagTableRowGroup),
2069 self.endTagIgnore)
2071 self.endTagHandler.default = self.endTagOther
2074 def clearStackToTableRowContext(self): argument
2075 while self.tree.openElements[-1].name not in ("tr", "html"):
2076 self.parser.parseError("unexpected-implied-end-tag-in-table-row",
2077 {"name": self.tree.openElements[-1].name})
2078 self.tree.openElements.pop()
2080 def ignoreEndTagTr(self): argument
2081 return not self.tree.elementInScope("tr", variant="table")
2084 def processEOF(self): argument
2085 self.parser.phases["inTable"].processEOF()
2087 def processSpaceCharacters(self, token): argument
2088 return self.parser.phases["inTable"].processSpaceCharacters(token)
2090 def processCharacters(self, token): argument
2091 return self.parser.phases["inTable"].processCharacters(token)
2093 def startTagTableCell(self, token): argument
2094 self.clearStackToTableRowContext()
2095 self.tree.insertElement(token)
2096 self.parser.phase = self.parser.phases["inCell"]
2097 self.tree.activeFormattingElements.append(Marker)
2099 def startTagTableOther(self, token): argument
2100 ignoreEndTag = self.ignoreEndTagTr()
2101 self.endTagTr(impliedTagToken("tr"))
2106 def startTagOther(self, token): argument
2107 return self.parser.phases["inTable"].processStartTag(token)
2109 def endTagTr(self, token): argument
2110 if not self.ignoreEndTagTr():
2111 self.clearStackToTableRowContext()
2112 self.tree.openElements.pop()
2113 self.parser.phase = self.parser.phases["inTableBody"]
2116 assert self.parser.innerHTML
2117 self.parser.parseError()
2119 def endTagTable(self, token): argument
2120 ignoreEndTag = self.ignoreEndTagTr()
2121 self.endTagTr(impliedTagToken("tr"))
2127 def endTagTableRowGroup(self, token): argument
2128 if self.tree.elementInScope(token["name"], variant="table"):
2129 self.endTagTr(impliedTagToken("tr"))
2132 self.parser.parseError()
2134 def endTagIgnore(self, token): argument
2135 self.parser.parseError("unexpected-end-tag-in-table-row",
2138 def endTagOther(self, token): argument
2139 return self.parser.phases["inTable"].processEndTag(token)
2143 def __init__(self, parser, tree): argument
2144 Phase.__init__(self, parser, tree)
2145 self.startTagHandler = utils.MethodDispatcher([
2146 ("html", self.startTagHtml),
2148 "thead", "tr"), self.startTagTableOther)
2150 self.startTagHandler.default = self.startTagOther
2152 self.endTagHandler = utils.MethodDispatcher([
2153 (("td", "th"), self.endTagTableCell),
2154 (("body", "caption", "col", "colgroup", "html"), self.endTagIgnore),
2155 (("table", "tbody", "tfoot", "thead", "tr"), self.endTagImply)
2157 self.endTagHandler.default = self.endTagOther
2160 def closeCell(self): argument
2161 if self.tree.elementInScope("td", variant="table"):
2162 self.endTagTableCell(impliedTagToken("td"))
2163 elif self.tree.elementInScope("th", variant="table"):
2164 self.endTagTableCell(impliedTagToken("th"))
2167 def processEOF(self): argument
2168 self.parser.phases["inBody"].processEOF()
2170 def processCharacters(self, token): argument
2171 return self.parser.phases["inBody"].processCharacters(token)
2173 def startTagTableOther(self, token): argument
2174 if (self.tree.elementInScope("td", variant="table") or
2175 self.tree.elementInScope("th", variant="table")):
2176 self.closeCell()
2180 assert self.parser.innerHTML
2181 self.parser.parseError()
2183 def startTagOther(self, token): argument
2184 return self.parser.phases["inBody"].processStartTag(token)
2186 def endTagTableCell(self, token): argument
2187 if self.tree.elementInScope(token["name"], variant="table"):
2188 self.tree.generateImpliedEndTags(token["name"])
2189 if self.tree.openElements[-1].name != token["name"]:
2190 self.parser.parseError("unexpected-cell-end-tag",
2193 node = self.tree.openElements.pop()
2197 self.tree.openElements.pop()
2198 self.tree.clearActiveFormattingElements()
2199 self.parser.phase = self.parser.phases["inRow"]
2201 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
2203 def endTagIgnore(self, token): argument
2204 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
2206 def endTagImply(self, token): argument
2207 if self.tree.elementInScope(token["name"], variant="table"):
2208 self.closeCell()
2212 self.parser.parseError()
2214 def endTagOther(self, token): argument
2215 return self.parser.phases["inBody"].processEndTag(token)
2218 def __init__(self, parser, tree): argument
2219 Phase.__init__(self, parser, tree)
2221 self.startTagHandler = utils.MethodDispatcher([
2222 ("html", self.startTagHtml),
2223 ("option", self.startTagOption),
2224 ("optgroup", self.startTagOptgroup),
2225 ("select", self.startTagSelect),
2226 (("input", "keygen", "textarea"), self.startTagInput),
2227 ("script", self.startTagScript)
2229 self.startTagHandler.default = self.startTagOther
2231 self.endTagHandler = utils.MethodDispatcher([
2232 ("option", self.endTagOption),
2233 ("optgroup", self.endTagOptgroup),
2234 ("select", self.endTagSelect)
2236 self.endTagHandler.default = self.endTagOther
2239 def processEOF(self): argument
2240 if self.tree.openElements[-1].name != "html":
2241 self.parser.parseError("eof-in-select")
2243 assert self.parser.innerHTML
2245 def processCharacters(self, token): argument
2248 self.tree.insertText(token["data"])
2250 def startTagOption(self, token): argument
2252 if self.tree.openElements[-1].name == "option":
2253 self.tree.openElements.pop()
2254 self.tree.insertElement(token)
2256 def startTagOptgroup(self, token): argument
2257 if self.tree.openElements[-1].name == "option":
2258 self.tree.openElements.pop()
2259 if self.tree.openElements[-1].name == "optgroup":
2260 self.tree.openElements.pop()
2261 self.tree.insertElement(token)
2263 def startTagSelect(self, token): argument
2264 self.parser.parseError("unexpected-select-in-select")
2265 self.endTagSelect(impliedTagToken("select"))
2267 def startTagInput(self, token): argument
2268 self.parser.parseError("unexpected-input-in-select")
2269 if self.tree.elementInScope("select", variant="select"):
2270 self.endTagSelect(impliedTagToken("select"))
2273 assert self.parser.innerHTML
2275 def startTagScript(self, token): argument
2276 return self.parser.phases["inHead"].processStartTag(token)
2278 def startTagOther(self, token): argument
2279 self.parser.parseError("unexpected-start-tag-in-select",
2282 def endTagOption(self, token): argument
2283 if self.tree.openElements[-1].name == "option":
2284 self.tree.openElements.pop()
2286 self.parser.parseError("unexpected-end-tag-in-select",
2289 def endTagOptgroup(self, token): argument
2291 if (self.tree.openElements[-1].name == "option" and
2292 self.tree.openElements[-2].name == "optgroup"):
2293 self.tree.openElements.pop()
2295 if self.tree.openElements[-1].name == "optgroup":
2296 self.tree.openElements.pop()
2299 self.parser.parseError("unexpected-end-tag-in-select",
2302 def endTagSelect(self, token): argument
2303 if self.tree.elementInScope("select", variant="select"):
2304 node = self.tree.openElements.pop()
2306 node = self.tree.openElements.pop()
2307 self.parser.resetInsertionMode()
2310 assert self.parser.innerHTML
2311 self.parser.parseError()
2313 def endTagOther(self, token): argument
2314 self.parser.parseError("unexpected-end-tag-in-select",
2318 def __init__(self, parser, tree): argument
2319 Phase.__init__(self, parser, tree)
2321 self.startTagHandler = utils.MethodDispatcher([
2323 self.startTagTable)
2325 self.startTagHandler.default = self.startTagOther
2327 self.endTagHandler = utils.MethodDispatcher([
2329 self.endTagTable)
2331 self.endTagHandler.default = self.endTagOther
2333 def processEOF(self): argument
2334 self.parser.phases["inSelect"].processEOF()
2336 def processCharacters(self, token): argument
2337 return self.parser.phases["inSelect"].processCharacters(token)
2339 def startTagTable(self, token): argument
2340self.parser.parseError("unexpected-table-element-start-tag-in-select-in-table", {"name": token["na…
2341 self.endTagOther(impliedTagToken("select"))
2344 def startTagOther(self, token): argument
2345 return self.parser.phases["inSelect"].processStartTag(token)
2347 def endTagTable(self, token): argument
2348self.parser.parseError("unexpected-table-element-end-tag-in-select-in-table", {"name": token["name…
2349 if self.tree.elementInScope(token["name"], variant="table"):
2350 self.endTagOther(impliedTagToken("select"))
2353 def endTagOther(self, token): argument
2354 return self.parser.phases["inSelect"].processEndTag(token)
2366 def __init__(self, parser, tree): argument
2367 Phase.__init__(self, parser, tree)
2369 def adjustSVGTagNames(self, token): argument
2410 def processCharacters(self, token): argument
2413 elif (self.parser.framesetOK and
2415 self.parser.framesetOK = False
2416 Phase.processCharacters(self, token)
2418 def processStartTag(self, token): argument
2419 currentNode = self.tree.openElements[-1]
2420 if (token["name"] in self.breakoutElements or
2423 self.parser.parseError("unexpected-html-element-in-foreign-content",
2425 while (self.tree.openElements[-1].namespace !=
2426 self.tree.defaultNamespace and
2427 not self.parser.isHTMLIntegrationPoint(self.tree.openElements[-1]) and
2428 not self.parser.isMathMLTextIntegrationPoint(self.tree.openElements[-1])):
2429 self.tree.openElements.pop()
2434 self.parser.adjustMathMLAttributes(token)
2436 self.adjustSVGTagNames(token)
2437 self.parser.adjustSVGAttributes(token)
2438 self.parser.adjustForeignAttributes(token)
2440 self.tree.insertElement(token)
2442 self.tree.openElements.pop()
2445 def processEndTag(self, token): argument
2446 nodeIndex = len(self.tree.openElements) - 1
2447 node = self.tree.openElements[-1]
2449 self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
2454 if self.parser.phase == self.parser.phases["inTableText"]:
2455 self.parser.phase.flushCharacters()
2456 self.parser.phase = self.parser.phase.originalPhase
2457 while self.tree.openElements.pop() != node:
2458 assert self.tree.openElements
2463 node = self.tree.openElements[nodeIndex]
2464 if node.namespace != self.tree.defaultNamespace:
2467 new_token = self.parser.phase.processEndTag(token)
2472 def __init__(self, parser, tree): argument
2473 Phase.__init__(self, parser, tree)
2475 self.startTagHandler = utils.MethodDispatcher([
2476 ("html", self.startTagHtml)
2478 self.startTagHandler.default = self.startTagOther
2480 self.endTagHandler = utils.MethodDispatcher([("html", self.endTagHtml)])
2481 self.endTagHandler.default = self.endTagOther
2483 def processEOF(self): argument
2487 def processComment(self, token): argument
2490 self.tree.insertComment(token, self.tree.openElements[0])
2492 def processCharacters(self, token): argument
2493 self.parser.parseError("unexpected-char-after-body")
2494 self.parser.phase = self.parser.phases["inBody"]
2497 def startTagHtml(self, token): argument
2498 return self.parser.phases["inBody"].processStartTag(token)
2500 def startTagOther(self, token): argument
2501 self.parser.parseError("unexpected-start-tag-after-body",
2503 self.parser.phase = self.parser.phases["inBody"]
2506 def endTagHtml(self, name): argument
2507 if self.parser.innerHTML:
2508 self.parser.parseError("unexpected-end-tag-after-body-innerhtml")
2510 self.parser.phase = self.parser.phases["afterAfterBody"]
2512 def endTagOther(self, token): argument
2513 self.parser.parseError("unexpected-end-tag-after-body",
2515 self.parser.phase = self.parser.phases["inBody"]
2520 def __init__(self, parser, tree): argument
2521 Phase.__init__(self, parser, tree)
2523 self.startTagHandler = utils.MethodDispatcher([
2524 ("html", self.startTagHtml),
2525 ("frameset", self.startTagFrameset),
2526 ("frame", self.startTagFrame),
2527 ("noframes", self.startTagNoframes)
2529 self.startTagHandler.default = self.startTagOther
2531 self.endTagHandler = utils.MethodDispatcher([
2532 ("frameset", self.endTagFrameset)
2534 self.endTagHandler.default = self.endTagOther
2536 def processEOF(self): argument
2537 if self.tree.openElements[-1].name != "html":
2538 self.parser.parseError("eof-in-frameset")
2540 assert self.parser.innerHTML
2542 def processCharacters(self, token): argument
2543 self.parser.parseError("unexpected-char-in-frameset")
2545 def startTagFrameset(self, token): argument
2546 self.tree.insertElement(token)
2548 def startTagFrame(self, token): argument
2549 self.tree.insertElement(token)
2550 self.tree.openElements.pop()
2552 def startTagNoframes(self, token): argument
2553 return self.parser.phases["inBody"].processStartTag(token)
2555 def startTagOther(self, token): argument
2556 self.parser.parseError("unexpected-start-tag-in-frameset",
2559 def endTagFrameset(self, token): argument
2560 if self.tree.openElements[-1].name == "html":
2562 self.parser.parseError("unexpected-frameset-in-frameset-innerhtml")
2564 self.tree.openElements.pop()
2565 if (not self.parser.innerHTML and
2566 self.tree.openElements[-1].name != "frameset"):
2569 self.parser.phase = self.parser.phases["afterFrameset"]
2571 def endTagOther(self, token): argument
2572 self.parser.parseError("unexpected-end-tag-in-frameset",
2577 def __init__(self, parser, tree): argument
2578 Phase.__init__(self, parser, tree)
2580 self.startTagHandler = utils.MethodDispatcher([
2581 ("html", self.startTagHtml),
2582 ("noframes", self.startTagNoframes)
2584 self.startTagHandler.default = self.startTagOther
2586 self.endTagHandler = utils.MethodDispatcher([
2587 ("html", self.endTagHtml)
2589 self.endTagHandler.default = self.endTagOther
2591 def processEOF(self): argument
2595 def processCharacters(self, token): argument
2596 self.parser.parseError("unexpected-char-after-frameset")
2598 def startTagNoframes(self, token): argument
2599 return self.parser.phases["inHead"].processStartTag(token)
2601 def startTagOther(self, token): argument
2602 self.parser.parseError("unexpected-start-tag-after-frameset",
2605 def endTagHtml(self, token): argument
2606 self.parser.phase = self.parser.phases["afterAfterFrameset"]
2608 def endTagOther(self, token): argument
2609 self.parser.parseError("unexpected-end-tag-after-frameset",
2613 def __init__(self, parser, tree): argument
2614 Phase.__init__(self, parser, tree)
2616 self.startTagHandler = utils.MethodDispatcher([
2617 ("html", self.startTagHtml)
2619 self.startTagHandler.default = self.startTagOther
2621 def processEOF(self): argument
2624 def processComment(self, token): argument
2625 self.tree.insertComment(token, self.tree.document)
2627 def processSpaceCharacters(self, token): argument
2628 return self.parser.phases["inBody"].processSpaceCharacters(token)
2630 def processCharacters(self, token): argument
2631 self.parser.parseError("expected-eof-but-got-char")
2632 self.parser.phase = self.parser.phases["inBody"]
2635 def startTagHtml(self, token): argument
2636 return self.parser.phases["inBody"].processStartTag(token)
2638 def startTagOther(self, token): argument
2639 self.parser.parseError("expected-eof-but-got-start-tag",
2641 self.parser.phase = self.parser.phases["inBody"]
2644 def processEndTag(self, token): argument
2645 self.parser.parseError("expected-eof-but-got-end-tag",
2647 self.parser.phase = self.parser.phases["inBody"]
2651 def __init__(self, parser, tree): argument
2652 Phase.__init__(self, parser, tree)
2654 self.startTagHandler = utils.MethodDispatcher([
2655 ("html", self.startTagHtml),
2656 ("noframes", self.startTagNoFrames)
2658 self.startTagHandler.default = self.startTagOther
2660 def processEOF(self): argument
2663 def processComment(self, token): argument
2664 self.tree.insertComment(token, self.tree.document)
2666 def processSpaceCharacters(self, token): argument
2667 return self.parser.phases["inBody"].processSpaceCharacters(token)
2669 def processCharacters(self, token): argument
2670 self.parser.parseError("expected-eof-but-got-char")
2672 def startTagHtml(self, token): argument
2673 return self.parser.phases["inBody"].processStartTag(token)
2675 def startTagNoFrames(self, token): argument
2676 return self.parser.phases["inHead"].processStartTag(token)
2678 def startTagOther(self, token): argument
2679 self.parser.parseError("expected-eof-but-got-start-tag",
2682 def processEndTag(self, token): argument
2683 self.parser.parseError("expected-eof-but-got-end-tag",