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:
parent
2d26741fc5
commit
cb0e438040
1 changed files with 15 additions and 0 deletions
|
|
@ -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, ...]:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue