MCPcopy Index your code
hub / github.com/python/cpython / EventCollector

Class EventCollector

Lib/test/test_htmlparser.py:23–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22
23class EventCollector(html.parser.HTMLParser):
24
25 def __init__(self, *args, autocdata=False, **kw):
26 self.autocdata = autocdata
27 self.events = []
28 self.append = self.events.append
29 html.parser.HTMLParser.__init__(self, *args, **kw)
30 if autocdata:
31 self._set_support_cdata(False)
32
33 def get_events(self):
34 # Normalize the list of events so that buffer artefacts don't
35 # separate runs of contiguous characters.
36 L = []
37 prevtype = None
38 for event in self.events:
39 type = event[0]
40 if type == prevtype == "data":
41 L[-1] = ("data", L[-1][1] + event[1])
42 else:
43 L.append(event)
44 prevtype = type
45 self.events = L
46 return L
47
48 # structure markup
49
50 def handle_starttag(self, tag, attrs):
51 self.append(("starttag", tag, attrs))
52 if self.autocdata and tag == 'svg':
53 self._set_support_cdata(True)
54
55 def handle_startendtag(self, tag, attrs):
56 self.append(("startendtag", tag, attrs))
57
58 def handle_endtag(self, tag):
59 self.append(("endtag", tag))
60 if self.autocdata and tag == 'svg':
61 self._set_support_cdata(False)
62
63 # all other markup
64
65 def handle_comment(self, data):
66 self.append(("comment", data))
67
68 def handle_charref(self, data):
69 self.append(("charref", data))
70
71 def handle_data(self, data):
72 self.append(("data", data))
73
74 def handle_decl(self, data):
75 self.append(("decl", data))
76
77 def handle_entityref(self, data):
78 self.append(("entityref", data))
79
80 def handle_pi(self, data):

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…