rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
handlers.setDefaultValue(self.processAnythingElse)
handlers.setDefaultValue(self.startTagOther)
def processStartTag(self, name, attributes): handlers = utils.MethodDispatcher([ ("caption", self.startTagCaption), ("colgroup", self.startTagColgroup), ("col", self.startTagCol), (("tbody", "tfoot", "thead"), self.startTagRowGroup), (("td", "th", "tr"), self.startTagImplyTbody), ("table", self.startTagTable) ]) # XXX ...
assert False
self.clearStackToTableContext() self.parser.insertElement(name, attributes) self.switchInsertionMode("inTableBody")
def startTagRowGroup(self, name, attributes={}): # XXX need a better name... emit tokens... assert False
def startTagTable(self, name, attributes): self.parser.parseError() assert False
def startTagImplyTbody(self, name, attributes): self.startTagRowGroup("tbody") # XXX assert False
def self.startTagTableOther(self, name, attributes):
def startTagTableOther(self, name, attributes):
def self.startTagTableOther(self, name, attributes): if self.parser.elementInScope("td") or \ self.parser.elementInScope("th"): self.closeCell() self.parser.processStartTag(name, attributes) else: # innerHTML case self.parser.parseError()
node = self.parser.openElements[-1]
node = self.parser.openElements[-1].name
def endTagTableCell(self, name): if self.parser.elementInScope(name): self.parser.generateImpliedEndTags() node = self.parser.openElements[-1] if node != name: self.parser.parseError() node = self.parser.openElements.pop() while node != name node = self.parser.openElements.pop() self.parser.clearActiveFormattingElement...
while self.parser.elementInScope("select"): self.parser.openElements.pop() self.parser.resetInsertionMode()
if self.parser.elementInScope(name, True): if self.parser.openElements[-1].name != "select": node = self.parser.openElements.pop() while node != "select" node = self.parser.openElements.pop() self.parser.resetInsertionMode() else: self.parser.parseError()
def endTagSelect(self, name="select"): # XXX innerHTML case ...
if self.parser.elementInScope(name, True): self.endTagSelect() self.parser.processEndTag(name)
def endTagTableElements(self, name): self.parser.parseError() # XXX table elements in scope blah...
if not self.innerHTML and \ self.parser.openElements[-1].name == "frameset": self.parser.switchInsertionMode("afterFrameset")
def endTagFrameset(self, name): if self.parser.openElements[-1].name == "html": # innerHTML case self.parser.parseError() else: self.parser.openElements.pop() # XXX innerHTML case part two...
self.parser.switchInsertionMode("inBody") self.parser.processStartTag(name, attributes)
InBody(self.parser).processStartTag(name, attributes)
def startTagNoframes(self, name, attributes): self.parser.switchInsertionMode("inBody") self.parser.processStartTag(name, attributes)
def addFormattingElement(self, name, attributes): self.parser.insertElement(name, attributes) self.parser.activeFormattingElements.append( self.parser.openElements[-1]) def processNonSpaceCharacters(self, data): self.parser.reconstructActiveFormattingElements() self.parser.insertText(data) def processStartTag(self...
def __init__(self, parser): InsertionMode.__init__(self, parser) self.processStartTagHandler = utils.MethodDispatcher([
def anythingElse(self): self.parser.insertElement("body", {}) self.parser.switchInsertionMode("inBody")
handlers.default = self.startTagOther handlers[name](name, attributes) def startTagScript(self, name, attributes): self.parser.phase.insertionModes["inHead"](self.parser).\ processStartTag(name, attributes) def startTagFromHead(self, name, attributes): self.parser.parseError() self.parser.phase.insertionModes["inHead...
self.processStartTagHandler.default = self.startTagOther self.processEndTagHandler = utils.MethodDispatcher([
def processStartTag(self, name, attributes): handlers=utils.MethodDispatcher([ ("script", self.startTagScript), (("base", "link", "meta", "style", "title"), self.startTagFromHead), ("body", self.startTagBody), (("address", "blockquote", "center", "dir", "div", "dl", "fieldset", "listing", "menu", "ol", "p", "pre", "ul"...
handlers.default = self.endTagOther handlers[name](name)
self.processEndTagHandler.default = self.endTagOther def addFormattingElement(self, name, attributes): self.parser.insertElement(name, attributes) self.parser.activeFormattingElements.append( self.parser.openElements[-1]) def processNonSpaceCharacters(self, data): self.parser.reconstructActiveFormattingElements()...
def processEndTag(self, name): handlers = utils.MethodDispatcher([ ("p",self.endTagP), ("body",self.endTagBody), ("html",self.endTagHtml), (("address", "blockquote", "center", "div", "dl", "fieldset", "listing", "menu", "ol", "pre", "ul"), self.endTagBlock), ("form", self.endTagForm), (("dd", "dt", "li"), self.endTagLi...
assert False
def processComment(self, data): assert False # XXX Can this even occur? self.parser.document.appendChild(CommentNode(data))
if item.name == name:
if item == Marker: break elif item.name == name:
def elementInActiveFormattingElements(self, name): """Check if an element eists between the end of the active formatting elements and the last marker. If it does, return it, else return false"""
elif item == Marker: break
def elementInActiveFormattingElements(self, name): """Check if an element eists between the end of the active formatting elements and the last marker. If it does, return it, else return false"""
self.generateImpliedEndTags()
self.generateImpliedEndTags(exclude)
def generateImpliedEndTags(self, exclude=None): name = self.openElements[-1].name if (name in frozenset(("dd", "dt", "li", "p", "td", "th", "tr")) and name != exclude): self.phase.processEndTag(name) self.generateImpliedEndTags()
self.parser.switchInsertionMode("inTable") self.parser.processEndTag(name) self.parser.switchInsertionMode("inRow")
InTable(self.parser).processEndTag(name)
def endTagOther(self, name): self.parser.switchInsertionMode("inTable") self.parser.processEndTag(name) self.parser.switchInsertionMode("inRow")
element = self.createElement(name, dict(attributes))
element = self.createElement(name, attributes)
def insertElement(self, name, attributes, parent=None): # XXX dict() should not be needed element = self.createElement(name, dict(attributes)) if parent is None: if self.openElements: self.openElements[-1].appendChild(element) self.openElements.append(element) else: # XXX Haven't implemented this yet as spec is vaugely...
def finishCollectingCharacters(self, name, endTag=False): self.parser.openElements[-1].appendChild(TextNode( "".join(self.characterBuffer))) self.characterBuffer = [] self.collectingCharacters == False if not self.collectionStartTag == name or not endTag: self.parser.parseError()
def finishCollectingCharacters(self, name, endTag=False): self.parser.openElements[-1].appendChild(TextNode( "".join(self.characterBuffer))) self.characterBuffer = [] self.collectingCharacters == False if not self.collectionStartTag == name or not endTag: self.parser.parseError()
def finishCollectingCharacters(self, name, endTag=False): InsertionMode.finishCollectingCharacters(self,name) if self.parser.openElements[-1].name == "script": if not endTag or not name == "script": self.parser.openElements[-1].append("already excecuted") if self.parser.innerHTML: self.parser.openElements[-1].append("...
def finishCollectingCharacters(self, name, endTag=False): InsertionMode.finishCollectingCharacters(self,name) if self.parser.openElements[-1].name == "script": # XXX append() -> appendChild() ? if not endTag or not name == "script": self.parser.openElements[-1].append("already excecuted") if self.parser.innerHTML: self...
if self.collectingCharacters: self.finishCollectingCharacters(name)
def processStartTag(self, name, attributes): if self.collectingCharacters: self.finishCollectingCharacters(name)
if self.collectingCharacters: self.finishCollectingCharacters(name, True)
def processEndTag(self, name): if self.collectingCharacters: self.finishCollectingCharacters(name, True) handlers = utils.MethodDispatcher([ ("head", self.endTagHead), ("html", self.endTagHtml), (("title", "style", "script"), self.endTagTitleStyleScript) ]) handlers.setDefaultValue(self.endTagOther) handlers[name](name...
self.parser.openElements.pop()
if self.parser.openElements[-1] == name: self.parser.openElements.pop() else: self.parser.parseError()
def endTagTitleStyleScript(self, name): self.parser.openElements.pop()
furthestBlock.childNodes.remove(furthestBlock)
furthestBlock.parent.removeChild(furthestBlock)
def endTagFormatting(self, name): """The much-feared adoption agency algorithm""" # XXX I don't like while True + break... too much # possibility of infinite loops while True: # Step 1 paragraph 1 afeElement = self.parser.elementInActiveFormattingElements(name) if not afeElement or (afeElement in self.parser.openElemen...
lastNode.parent.childNodes.remove(lastNode)
lastNode.parent.removeChild(lastNode)
def endTagFormatting(self, name): """The much-feared adoption agency algorithm""" # XXX I don't like while True + break... too much # possibility of infinite loops while True: # Step 1 paragraph 1 afeElement = self.parser.elementInActiveFormattingElements(name) if not afeElement or (afeElement in self.parser.openElemen...
furthestBlock.childNodes.remove(node)
furthestBlock.removeChild(node)
def endTagFormatting(self, name): """The much-feared adoption agency algorithm""" # XXX I don't like while True + break... too much # possibility of infinite loops while True: # Step 1 paragraph 1 afeElement = self.parser.elementInActiveFormattingElements(name) if not afeElement or (afeElement in self.parser.openElemen...
data = consumeChar()
data = self.consumeChar()
def beforeAttributeValueState(self): data = consumeChar() if data in spaceCharacters: pass elif data == u"\"": self.changeState("attributeValueDoubleQuoted") elif data == u"&": self.changeState("attributeValueUnQuoted") self.characterQueue.append(data); elif data == u"'": self.changeState("attributeValueSingleQuoted") ...
self.currentToken[-1][1] += data
self.currentToken.attributes[-1][1] += data
def beforeAttributeValueState(self): data = consumeChar() if data in spaceCharacters: pass elif data == u"\"": self.changeState("attributeValueDoubleQuoted") elif data == u"&": self.changeState("attributeValueUnQuoted") self.characterQueue.append(data); elif data == u"'": self.changeState("attributeValueSingleQuoted") ...
for node in furthestBlock.childNodes: clone.appendChild(node) furthestBlock.removeChild(node)
clone.childNodes.extend(furthestBlock.childNodes) furthestBlock.childNodes = []
def endTagFormatting(self, name): """The much-feared adoption agency algorithm""" # XXX I don't like while True + break... too much # possibility of infinite loops while True: # Step 1 paragraph 1 afeElement = self.parser.elementInActiveFormattingElements(name) if not afeElement or (afeElement in self.parser.openElemen...
treedump = treedump.split("\n")
treedump = treedump.split("\n")[1:]
def convertTreeDump(treedump): """convert the output of str(document) to the format used in the testcases""" treedump = treedump.split("\n") rv = [] for line in treedump: if line.startswith("#document"): pass else: rv.append(line[3:]) return "\n".join(rv)
if line.startswith(" pass else: rv.append(line[3:])
rv.append(line[3:])
def convertTreeDump(treedump): """convert the output of str(document) to the format used in the testcases""" treedump = treedump.split("\n") rv = [] for line in treedump: if line.startswith("#document"): pass else: rv.append(line[3:]) return "\n".join(rv)
def processNonWhitespaceCharacter(self, data):
def processNonSpaceCharacter(self, data):
def processNonWhitespaceCharacter(self, data): if self.collectingCharacters: self.characterBuffer += data else: self.anythingElse() self.parser.processCharacter(data)
def appendToHead(element):
def startTagHead(self, name, attributes): self.parser.insertElement(name, attributes) self.parser.headPointer = self.parser.openElements[-1] self.parser.switchInsertionMode('inHead') def appendToHead(self, element):
def appendToHead(element): if self.headPointer is not None: self.parser.headPointer.appendChild(element) else: assert self.innerHTML self.parser.openElements[-1].append(element)
self.insertionModes["inHead"](self.parser).processStartTag(name, attributes)
self.parser.insertionModes["inHead"](self.parser).processStartTag(name, attributes)
def startTagFromHead(self, name, attributes): self.parser.parseError() self.insertionModes["inHead"](self.parser).processStartTag(name, attributes)
self.addFormattingElement(self, name, attributes)
self.addFormattingElement(name, attributes)
def startTagA(self, name, attributes): afeAElement = self.parser.elementInActiveFormattingElements("a") if afeAElement: self.parser.parseError() self.endTagA("a") if afeAElement in self.parser.openElements: self.parser.openElements.remove(afeAElement) if afeAElement in self.parser.activeFormattingElements: self.parser....
self.addFormattingElement(self, name, attributes)
self.addFormattingElement(name, attributes)
def startTagFormatting(self, name, attributes): self.parser.reconstructActiveFormattingElements() self.addFormattingElement(self, name, attributes)
while node != name
while node.name != name:
def endTagTableCell(self, name): if self.parser.elementInScope(name): self.parser.generateImpliedEndTags() node = self.parser.openElements[-1].name if node != name: self.parser.parseError() node = self.parser.openElements.pop() while node != name node = self.parser.openElements.pop() self.parser.clearActiveFormattingEl...
while node != "select"
while node.name != "select":
def endTagSelect(self, name="select"): if self.parser.elementInScope(name, True): if self.parser.openElements[-1].name != "select": node = self.parser.openElements.pop() while node != "select" node = self.parser.openElements.pop() self.parser.resetInsertionMode() else: # innerHTML case self.parser.parseError()
EOFReached = False while entitiesStartingWith("".join(charStack)):
while (charStack[-1] != EOF and entitiesStartingWith("".join(charStack))):
def entitiesStartingWith(name): return [e for e in filteredEntityList if e.startswith(name)]
if charStack[-1] == EOF: EOFReached = True
entityName = None for entityLength in xrange(len(charStack)-1,1,-1): possibleEntityName = "".join(charStack[:entityLength]) if possibleEntityName in entities: entityName = possibleEntityName
def entitiesStartingWith(name): return [e for e in filteredEntityList if e.startswith(name)]
if EOFReached:
if entityName is not None: char = entities[entityName] if not charStack[-1] == ";": self.parser.parseError() self.characterQueue.extend(charStack[entityLength:]) else:
def entitiesStartingWith(name): return [e for e in filteredEntityList if e.startswith(name)]
else: possibleEntityName = "".join(charStack)[:-1] if possibleEntityName in entities: char = entities[possibleEntityName] if not charStack[-1] == ";": self.parser.parseError() self.characterQueue.append(charStack[-1]) else: self.parser.parseError() self.characterQueue.extend(charStack)
def entitiesStartingWith(name): return [e for e in filteredEntityList if e.startswith(name)]
self.openElements[-1].appendChild(clone) self.openElements.append(clone) self.activeFormattingElements[i] = clone if clone == self.activeFormattingElements[-1]:
element = self.insertElement(clone.name, clone.attributes) self.activeFormattingElements[i] = element if element == self.activeFormattingElements[-1]:
def reconstructActiveFormattingElements(self): # This covers the ", if any" case mentioned often in the drafts, before # you have to reconstruct the active formatting elements. if not self.activeFormattingElements: return
- processStartTag(tagname, attributes[]) - processEndTag(tagname, attributes[])
- processStartTag(tagname, attributes{}) - processEndTag(tagname)
def __init__(self, data=None): self.data = data
self.parser.processStartTag(self.currentToken.name, self.currentToken.attributes)
attrsDict = dict(self.currentToken.attributes[::-1]) self.parser.processStartTag(self.currentToken.name, attrsDict)
def emitCurrentToken(self): """This method is a generic handler for emitting the StartTagToken, EndTagToken, CommentToken and DoctypeToken. It also sets the state to "data" because that's what's needed after a token has been emitted. """
self.parser.processEndTag(self.currentToken.name, self.currentToken.attributes)
self.parser.processEndTag(self.currentToken.name)
def emitCurrentToken(self): """This method is a generic handler for emitting the StartTagToken, EndTagToken, CommentToken and DoctypeToken. It also sets the state to "data" because that's what's needed after a token has been emitted. """
assert self.contentModelFlag != contentModelFlags['PCDATA']
assert self.contentModelFlag == contentModelFlags["PCDATA"]
def bogusCommentState(self): assert self.contentModelFlag != contentModelFlags['PCDATA']
assert self.contentModelFlag != contentModelFlags['PCDATA']
assert self.contentModelFlag == contentModelFlags["PCDATA"]
def markupDeclerationOpenState(self): assert self.contentModelFlag != contentModelFlags['PCDATA']
self.parser.switchInsertionMode("inColgroup")
self.parser.switchInsertionMode("inColumnGroup")
def startTagColgroup(self, name="colgroup", attributes={}): self.clearStackToTableContext() self.parser.insertElement(name, attributes) self.parser.switchInsertionMode("inColgroup")
while self.parser.openElements[-1].name in ("tbody", "tfoot", "thead", "html"):
while self.parser.openElements[-1].name not in ("tbody", "tfoot", "thead", "html"):
def clearStackToTableBodyContext(self): while self.parser.openElements[-1].name in ("tbody", "tfoot", "thead", "html"): self.parser.openElements.pop() self.parser.parseError()
while self.parser.openElements[-1].name in ("tr", "html"):
while self.parser.openElements[-1].name not in ("tr", "html"):
def clearStackToTableRowContext(self): while self.parser.openElements[-1].name in ("tr", "html"): self.parser.openElements.pop() self.parser.parseError()
if self.parser.innerHTML == False\ or len(self.tree.openElements) > 1:
if self.parser.innerHTML == True and len(self.tree.openElements) > 1:
def processEOF(self): self.tree.generateImpliedEndTags() if self.parser.innerHTML == False\ or len(self.tree.openElements) > 1: # XXX No need to check for "body" because our EOF handling is not # per specification. (Specification needs an update.) self.parser.parseError() # Stop parsing
self.parser.parseError()
self.parser.parseError("No DOCTYPE seen.")
def processCharacters(self, data): self.parser.parseError() self.parser.phase = self.parser.phases["rootElement"] self.parser.phase.processCharacters(data)
self.anytingElse()
self.anythingElse()
def startTagOther(self, name, attributes): self.anytingElse() self.parser.processStartTag(name, attributes)
self.parser.insertElement("body", [])
self.parser.insertElement("body", {})
def anythingElse(self): self.parser.insertElement("body", []) self.parser.switchInsertionMode("inBody")
if self.parser.elementInScope(p):
if self.parser.elementInScope("p"):
def startTagTable(self, name, attributes): if self.parser.elementInScope(p): self.processEndTag("p") self.parser.insertElement(name, attributes) self.parser.switchInsertionMode("inTable")
self.switchInsertionMode("inTableBody")
self.parser.switchInsertionMode("inTableBody")
def startTagRowGroup(self, name, attributes={}): self.clearStackToTableContext() self.parser.insertElement(name, attributes) self.switchInsertionMode("inTableBody")
while self.parser.openElements[:-1].name in ("tbody", "tfoot", "thead",
while self.parser.openElements[-1].name in ("tbody", "tfoot", "thead",
def clearStackToTableBodyContext(self): while self.parser.openElements[:-1].name in ("tbody", "tfoot", "thead", "html"): self.parser.openElements.pop() self.parser.parseError()
while self.parser.openElements[:-1].name in ("tr", "html"):
while self.parser.openElements[-1].name in ("tr", "html"):
def clearStackToTableRowContext(self): while self.parser.openElements[:-1].name in ("tr", "html"): self.parser.openElements.pop() self.parser.parseError()
def startTagTableCell(name, attributes):
def startTagTableCell(self, name, attributes):
def startTagTableCell(name, attributes): self.clearStackToTableRowContext() self.parser.insertElement(name, attributes) self.parser.switchInsertionMode("inCell") self.parser.activeFormattingElements.append(Marker)
def startTagTableOther(name, attributes):
def startTagTableOther(self, name, attributes):
def startTagTableOther(name, attributes): self.endTagTr() # XXX check if it wasn't ignored... innerHTML case ... reprocess # current. see also endTagTable
def startTagOther(self, name):
def startTagOther(self, name, attributes):
def startTagOther(self, name): self.parser.switchInsertionMode("inTable") self.parser.processStartTag(self, name)
self.parser.processStartTag(self, name)
self.parser.processStartTag(name, attributes)
def startTagOther(self, name): self.parser.switchInsertionMode("inTable") self.parser.processStartTag(self, name)
and charStack[-1] in (spaceCharacters | frozenset((u">", u"/", u"<", EOF))):
and not charStack[-1] in (spaceCharacters | frozenset((u">", u"/", u"<", EOF))):
def closeTagOpenState(self): if (self.contentModelFlag in (contentModelFlags["RCDATA"], contentModelFlags["CDATA"])): charStack = []
self.parser.parseError()
self.parser.document.appendChild(CommentNode(data))
def processComment(self, data): self.parser.parseError()
def processComment(self, data): self.parser.document.appendChild(CommentNode(data))
def processEndTag(self, name): self.parser.switchPhase("rootElement") self.parser.processEndTag(name)
def processDoctype(self, name, error): self.parser.parseError()
def processDoctype(self, name, error): self.parser.parseError()
def processComment(self, data): self.parser.document.appendChild(CommentNode(data))
def processEndTag(self, name): self.insertHtmlElement() self.parser.phase.processEndTag(name)
def processDoctype(self, name, error): self.parser.parseError()
def processCharacter(self, data): self.insertionMode.processCharacter(data)
def processComment(self, data): self.parser.document.appendChild(CommentNode(data))
def processComment(self, data): self.parser.document.appendChild(CommentNode(data))
print "end tag tr"
def endTagTr(self, name="tr"): if self.parser.elementInScope("tr", True): print "end tag tr" self.clearStackToTableRowContext() self.parser.openElements.pop() self.parser.switchInsertionMode("inTableBody") else: # innerHTML case self.parser.parseError()
if self.parser.elementInScope(name):
if self.parser.elementInScope(name, True):
def endTagTableCell(self, name): if self.parser.elementInScope(name): self.parser.generateImpliedEndTags(name) if self.parser.openElements[-1].name != name: self.parser.parseError() node = self.parser.openElements.pop() while node.name != name: node = self.parser.openElements.pop() self.parser.clearActiveFormattingElem...
node = self.parser.openElements.pop() while node.name != name:
while True:
def endTagTableCell(self, name): if self.parser.elementInScope(name): self.parser.generateImpliedEndTags(name) if self.parser.openElements[-1].name != name: self.parser.parseError() node = self.parser.openElements.pop() while node.name != name: node = self.parser.openElements.pop() self.parser.clearActiveFormattingElem...
self.generateImpliedEndTags()
self.parser.generateImpliedEndTags()
def endTagTable(self, name): if self.parser.elementInScope("table", True): self.generateImpliedEndTags() if self.parser.openElements[-1].name == "table": self.parser.parseError() while self.parser.openElements[-1].name != "table": self.parser.openElements.pop() self.parser.resetInsertionMode() else: self.parser.parseEr...
if self.elementInScope("tbody", True) or \ self.elementInScope("thead", True) or \ self.elementInScope("tfoot", True):
if self.parser.elementInScope("tbody", True) or \ self.parser.elementInScope("thead", True) or \ self.parser.elementInScope("tfoot", True):
def endTagTable(self, name): # XXX AT Any ideas on how to share this with startTagTableOther? if self.elementInScope("tbody", True) or \ self.elementInScope("thead", True) or \ self.elementInScope("tfoot", True): self.clearStackToTableBodyContext() self.endTagTableRowGroup(self.parser.openElements[-1]) else: # innerHTM...
if self.parser.elementInScope(name):
if self.parser.elementInScope(name, True):
def endTagImply(self, name): if self.parser.elementInScope(name): self.closeCell() # XXX The thing below still causes issues ...: self.parser.processEndTag(name) else: # sometimes innerHTML case self.parser.parseError()
if self.parser.headPointer is not None:
if self.parser.openElements[-1] in ("title", "style", "script"):
def processNonSpaceCharacter(self, data): if self.parser.headPointer is not None: self.parser.openElements[-1].appendChild(TextNode(data)) else: self.parser.switchInsertionMode("afterHead") self.parser.processCharacter(data) """ if self.collectingCharacters: self.characterBuffer += data else: self.anythingElse() self.p...
_dictEntries = []
def __init__(self, items=()): _dictEntries = [] for name,value in items: if type(name) in (list, tuple, frozenset, set): for item in name: _dictEntries.append((item, value)) else: _dictEntries.append((name, value)) dict.__init__(self, _dictEntries) self.default = None
_dictEntries.append((item, value))
self[item] = value
def __init__(self, items=()): _dictEntries = [] for name,value in items: if type(name) in (list, tuple, frozenset, set): for item in name: _dictEntries.append((item, value)) else: _dictEntries.append((name, value)) dict.__init__(self, _dictEntries) self.default = None
_dictEntries.append((name, value)) dict.__init__(self, _dictEntries)
self[name] = value
def __init__(self, items=()): _dictEntries = [] for name,value in items: if type(name) in (list, tuple, frozenset, set): for item in name: _dictEntries.append((item, value)) else: _dictEntries.append((name, value)) dict.__init__(self, _dictEntries) self.default = None
for line in Node.printTree(self, -1)[2:].split('\n'): print line
tree = str(self) for child in self.childNodes: tree += child.printTree(2) return tree
def printTree(self): for line in Node.printTree(self, -1)[2:].split('\n'): print line
if node == target:
if node.name == target:
def elementInScope(self, target, tableVariant=False): # AT Use reverse instead of [::-1] when we can rely on Python 2.4 # AT How about while True and simply set node to [-1] and set it to # [-2] at the end... for node in self.openElements[::-1]: if node == target: return True elif node.name == "table": return False eli...
while True: name = self.openElements[-1].name if name in frozenset(("dd", "dt", "li", "p", "td", "th", "tr")) and name != exclude: self.phase.processEndTag(name) else: break
name = self.openElements[-1].name if name != exclude and name in frozenset(("dd", "dt", "li", "p", "td", "th", "tr")): self.processEndTag(name) self.generateImpliedEndTags()
def generateImpliedEndTags(self, exclude=None): while True: name = self.openElements[-1].name if name in frozenset(("dd", "dt", "li", "p", "td", "th", "tr")) and name != exclude: self.phase.processEndTag(name) else: break # XXX AT: # name = self.openElements[-1].name # while name in frozenset(("dd", "dt", "li", "p", "t...
handlers = {"html":self.createHeadNode}
handlers = {"html":self.endTagHtml}
def processEndTag(self, name): handlers = {"html":self.createHeadNode} handlers.get(name, self.endTagOther)(name)
if self.headPointer is not None:
if self.parser.headPointer is not None:
def appendToHead(self, element): if self.headPointer is not None: self.parser.headPointer.appendChild(element) else: assert self.innerHTML self.parser.openElements[-1].append(element)
stateFlags = {"title":"RCDATA", "style":"CDATA"}
cmFlags = {"title":"RCDATA", "style":"CDATA"}
def startTagTitleStyle(self, name, attributes): stateFlags = {"title":"RCDATA", "style":"CDATA"} element = self.parser.createElement(name, attributes) self.appendToHead(element) self.parser.tokenizer.state = self.parser.tokenizer.states[stateFlags[name]] # We have to start collecting characters self.collectingCharacter...
self.parser.tokenizer.state = self.parser.tokenizer.states[stateFlags[name]]
self.parser.tokenizer.contentModelFlag = contentModelFlags[cmFlags[name]]
def startTagTitleStyle(self, name, attributes): stateFlags = {"title":"RCDATA", "style":"CDATA"} element = self.parser.createElement(name, attributes) self.appendToHead(element) self.parser.tokenizer.state = self.parser.tokenizer.states[stateFlags[name]] # We have to start collecting characters self.collectingCharacter...
self.parser.tokenizer.state = self.parser.tokenizer.states["CDATA"]
self.parser.tokenizer.contentModelFlag = contentModelFlags["CDATA"]
def startTagScript(self, name, attributes): element = self.parser.createElement(name, attributes) element._flags.append("parser-inserted") # XXX Should this be moved to after we finish collecting characters self.appendToHead(element) self.parser.tokenizer.state = self.parser.tokenizer.states["CDATA"]
self.insertionModes["inHead"](self.parser).processStartTag(name,
self.parser.phase.insertionModes["inHead"](self.parser).processStartTag(name,
def startTagScript(self, name, attributes): self.insertionModes["inHead"](self.parser).processStartTag(name, attributes)
self.parser.insertionModes["inHead"](self.parser).processStartTag(name,
self.parser.phase.insertionModes["inHead"](self.parser).processStartTag(name,
def startTagFromHead(self, name, attributes): self.parser.parseError() self.parser.insertionModes["inHead"](self.parser).processStartTag(name, attributes)
assert self.parser.innerHtml
assert self.parser.innerHTML
def startTagBody(self, name, attributes): self.parser.parseError() if len(self.parser.openElements)==1 or self.parser.openElements[1].name != "body": assert self.parser.innerHtml else: for attr, value in attributes.iteritems(): if attr not in self.parser.openElements[1].attributes: self.parser.openElements[1].attribute...
assert self.innerHtml
assert self.innerHTML
def endTagBody(self, name): if self.parser.openElements[1].name != "body": assert self.innerHtml self.parser.parseError() else: if self.parser.openElements[-1].name != "body": assert self.innerHtml self.parser.switchInsertionMode("afterBody")
def endTagHtml(self, name, attributes): self.bodyEndTag(name) if not self.parser.innerHtml: self.endTagHtml(name)
def endTagHtml(self, name): self.endTagBody(name) if not self.parser.innerHTML: self.parser.processEndTag(name)
def endTagHtml(self, name, attributes): self.bodyEndTag(name) if not self.parser.innerHtml: self.endTagHtml(name)
try: stream = HTMLInputStream("tests/utf-8-bom.html") c = stream.readChar() while c: line, col = stream.position() if c == u"\n": print "Line %s, Column %s: Line Feed" % (line, col) else: print "Line %s, Column %s: %s" % (line, col, c.encode('utf-8')) c = stream.readChar() print "EOF" except IOError: print "The file d...
stream = HTMLInputStream("../tests/utf-8-bom.html") c = stream.char() while c: line, col = stream.position() if c == u"\n": print "Line %s, Column %s: Line Feed" % (line, col) else: print "Line %s, Column %s: %s" % (line, col, c.encode('utf-8')) c = stream.char() print "EOF"
def charsUntil(self, characters, opposite = False): """ Returns a string of characters from the stream up to but not including any character in characters or EOF. characters can be any container that supports the in method being called on it. """ charStack = [self.char()]
We also concatanate all consecutive character tokens into a single token""" expectedTokens = concatanateCharacterTokens(expectedTokens) recievedTokens = concatanateCharacterTokens(recievedTokens)
""" return expectedTokens == recievedTokens
def tokensMatch(expectedTokens, recievedTokens): """Test whether the test has passed or failed For brevity in the tests, the test has passed if the sequence of expected tokens appears anywhere in the sequqnce of returned tokens. We also concatanate all consecutive character tokens into a single token""" expectedToke...
assert False
self.endTagColgroup() if not self.parser.innerHTML: self.parser.processStartTag(name, attributes)
def startTagOther(self, name, attributes): # XXX assert False
def endTagColGroup(self, name):
def endTagColgroup(self, name="colgroup"):
def endTagColGroup(self, name): if self.parser.openElements[-1].name == "html": # innerHTML case self.parser.parseError() else: self.parser.openElements.pop() self.parser.switchInsertionMode("inTable")
assert False
self.endTagColgroup() if not self.parser.innerHTML: self.parser.processEndTag(name)
def endTagOther(self, name): # XXX assert False
if self.elementInScope("tbody", True) or \ self.elementInScope("thead", True) or \ self.elementInScope("tfoot", True):
if self.parser.elementInScope("tbody", True) or \ self.parser.elementInScope("thead", True) or \ self.parser.elementInScope("tfoot", True):
def startTagTableOther(self, name, attributes): # XXX AT Any ideas on how to share this with endTagTable? if self.elementInScope("tbody", True) or \ self.elementInScope("thead", True) or \ self.elementInScope("tfoot", True): self.clearStackToTableBodyContext() self.endTagTableRowGroup(self.parser.openElements[-1]) else...
self.endTagTableRowGroup(self.parser.openElements[-1])
self.endTagTableRowGroup(self.parser.openElements[-1].name) self.parser.processStartTag(name, attributes)
def startTagTableOther(self, name, attributes): # XXX AT Any ideas on how to share this with endTagTable? if self.elementInScope("tbody", True) or \ self.elementInScope("thead", True) or \ self.elementInScope("tfoot", True): self.clearStackToTableBodyContext() self.endTagTableRowGroup(self.parser.openElements[-1]) else...