Skip to content

Commit f3a281d

Browse files
committed
Ignores void elements' children in the PullDOM treewalker
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40620
1 parent 917094a commit f3a281d

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/treewalkers/pulldom.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77

88
class TreeWalker(_base.TreeWalker):
99
def walk(self, stream):
10+
ignore_until = None
1011
previous = None
1112
for event in stream:
12-
if previous is not None:
13+
if previous is not None and \
14+
(ignore_until is None or previous[1] is ignore_until):
15+
if previous[1] is ignore_until:
16+
ignore_until = None
1317
for token in self.tokens(previous, event):
1418
yield token
19+
if token["type"] == "EmptyTag":
20+
ignore_until = previous[1]
1521
previous = event
16-
for token in self.tokens(previous, None):
17-
yield token
22+
if ignore_until is None or previous[1] is ignore_until:
23+
for token in self.tokens(previous, None):
24+
yield token
25+
elif ignore_until is not None:
26+
raise ValueError("Illformed DOM event stream: void element without END_ELEMENT")
1827

1928
def tokens(self, event, next):
2029
type, node = event

0 commit comments

Comments
 (0)