File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,29 @@ def hasContent(self):
8686 """
8787 raise NotImplementedError
8888
89+ class ActiveFormattingElements (list ):
90+ def append (self , node ):
91+ equalCount = 0
92+ if node != Marker :
93+ for element in self [::- 1 ]:
94+ if element == Marker :
95+ break
96+ if self .nodesEqual (element , node ):
97+ equalCount += 1
98+ if equalCount == 3 :
99+ self .remove (element )
100+ break
101+ list .append (self , node )
102+
103+ def nodesEqual (self , node1 , node2 ):
104+ if not node1 .nameTuple == node2 .nameTuple :
105+ return False
106+
107+ if not node1 .attributes == node2 .attributes :
108+ return False
109+
110+ return True
111+
89112class TreeBuilder (object ):
90113 """Base treebuilder implementation
91114 documentClass - the class to use for the bottommost node of a document
@@ -118,7 +141,7 @@ def __init__(self, namespaceHTMLElements):
118141
119142 def reset (self ):
120143 self .openElements = []
121- self .activeFormattingElements = []
144+ self .activeFormattingElements = ActiveFormattingElements ()
122145
123146 #XXX - rename these to headElement, formElement
124147 self .headPointer = None
Original file line number Diff line number Diff line change @@ -24,7 +24,15 @@ def __getitem__(self, name):
2424 return self .attrs [name ]
2525 def __contains__ (self , name ):
2626 return name in self .attrs .keys ()
27-
27+ def __eq__ (self , other ):
28+ if len (self .keys ()) != len (other .keys ()):
29+ return False
30+ for item in self .keys ():
31+ if item not in other :
32+ return False
33+ if self [item ] != other [item ]:
34+ return False
35+ return True
2836
2937class Element (_base .Node ):
3038 def __init__ (self , element , soup , namespace ):
You can’t perform that action at this time.
0 commit comments