summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPhilipp Hahn <hahn@univention.de>2018-09-21 15:35:03 +0200
committerMichal Privoznik <mprivozn@redhat.com>2018-09-24 09:06:00 +0200
commit26350dc97d12e937ea863a48e0dc676c676583ab (patch)
tree1f8d9690703ccbee43400d3390a43fecfa2ee7d3 /examples
parent37e56947cc916573816f62dbc1080785697c6a0d (diff)
downloadlibvirt-python-26350dc97d12e937ea863a48e0dc676c676583ab.tar.gz
event-test.py: Add class for event descriptions
Signed-off-by: Philipp Hahn <hahn@univention.de>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/event-test.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/event-test.py b/examples/event-test.py
index 91a7cb7..d2d2c60 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -456,6 +456,31 @@ def virEventLoopNativeStart():
##########################################################################
# Everything that now follows is a simple demo of domain lifecycle events
##########################################################################
+class Description(object):
+ __slots__ = ('desc', 'args')
+
+ def __init__(self, *args, **kwargs):
+ self.desc = kwargs.get('desc')
+ self.args = args
+
+ def __str__(self): # type: () -> str
+ return self.desc
+
+ def __getitem__(self, item): # type: (int) -> str
+ try:
+ data = self.args[item]
+ except IndexError:
+ return self.__class__(desc=str(item))
+
+ if isinstance(data, str):
+ return self.__class__(desc=data)
+ elif isinstance(data, (list, tuple)):
+ desc, args = data
+ return self.__class__(*args, desc=desc)
+
+ raise TypeError(args)
+
+
def domEventToString(event):
domEventStrings = ( "Defined",
"Undefined",