File tree 2 files changed +33
-2
lines changed
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,29 @@ def hasContent(self):
86
86
"""
87
87
raise NotImplementedError
88
88
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
+
89
112
class TreeBuilder (object ):
90
113
"""Base treebuilder implementation
91
114
documentClass - the class to use for the bottommost node of a document
@@ -118,7 +141,7 @@ def __init__(self, namespaceHTMLElements):
118
141
119
142
def reset (self ):
120
143
self .openElements = []
121
- self .activeFormattingElements = []
144
+ self .activeFormattingElements = ActiveFormattingElements ()
122
145
123
146
#XXX - rename these to headElement, formElement
124
147
self .headPointer = None
Original file line number Diff line number Diff line change @@ -24,7 +24,15 @@ def __getitem__(self, name):
24
24
return self .attrs [name ]
25
25
def __contains__ (self , name ):
26
26
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
28
36
29
37
class Element (_base .Node ):
30
38
def __init__ (self , element , soup , namespace ):
You can’t perform that action at this time.
0 commit comments