mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-03-26 18:22:55 -07:00
python: backport 'EventListener: add __repr__ method'
When the object is not stateful, this repr method prints what you'd expect. In cases where there are pending events, the output is augmented to illustrate that. The object itself has no idea if it's "active" or not, so it cannot convey that information. Signed-off-by: John Snow <jsnow@redhat.com> cherry picked from commit python-qemu-qmp@8a6f2e136dae395fec8aa5fd77487cfe12d9e05e Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
@@ -497,6 +497,21 @@ class EventListener:
|
||||
#: Optional, secondary event filter.
|
||||
self.event_filter: Optional[EventFilter] = event_filter
|
||||
|
||||
def __repr__(self) -> str:
|
||||
args: List[str] = []
|
||||
if self.names:
|
||||
args.append(f"names={self.names!r}")
|
||||
if self.event_filter:
|
||||
args.append(f"event_filter={self.event_filter!r}")
|
||||
|
||||
if self._queue.qsize():
|
||||
state = f"<pending={self._queue.qsize()}>"
|
||||
else:
|
||||
state = ''
|
||||
|
||||
argstr = ", ".join(args)
|
||||
return f"{type(self).__name__}{state}({argstr})"
|
||||
|
||||
@property
|
||||
def history(self) -> Tuple[Message, ...]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user