MCPcopy Create free account
hub / github.com/ActiveState/code / Event

Class Event

recipes/Python/578138_gprof2dotpy/recipe-578138.py:91–118  ·  view source on GitHub ↗

Describe a kind of event, and its basic operations.

Source from the content-addressed store, hash-verified

89
90
91class Event(object):
92 """Describe a kind of event, and its basic operations."""
93
94 def __init__(self, name, null, aggregator, formatter = str):
95 self.name = name
96 self._null = null
97 self._aggregator = aggregator
98 self._formatter = formatter
99
100 def __eq__(self, other):
101 return self is other
102
103 def __hash__(self):
104 return id(self)
105
106 def null(self):
107 return self._null
108
109 def aggregate(self, val1, val2):
110 """Aggregate two event values."""
111 assert val1 is not None
112 assert val2 is not None
113 return self._aggregator(val1, val2)
114
115 def format(self, val):
116 """Format an event value."""
117 assert val is not None
118 return self._formatter(val)
119
120
121CALLS = Event("Calls", 0, add, times)

Callers 4

recipe-578138.pyFile · 0.70
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected