bt2: make `_EventConst` a mapping
The `_EventConst` class already implemented the __getitem__() method
to make it easy to access a payload, specific context, common context,
or packet context field (in this order) by name, for example:
print(event['next_prio'])
If two root fields contain fields which share the same name, one of them
has the priority and the other one is not accessible through this
interface.
This patch makes the `_EventConst` class a full mapping protocol,
inheriting `collections.abc.Mapping`. This patch implements the
__iter__() and __len__() methods so as to let `collections.abc.Mapping`
implement __contains__(), keys(), items(), values(), get(), __eq__(),
and __ne__(). Now you can do, for example:
if 'next_prio' in event:
print(event['next_prio'])
__iter__() keeps a set of yielded field names so as to avoid repeating
field names.
__len__() simply reuses __iter__().
`test_event.py` is updated to test the new features.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2485e0df2373005fada0d0732c6269acbce5457c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3343
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
This page took 0.02651 seconds and 4 git commands to generate.