summaryrefslogtreecommitdiff
path: root/examples/example-client.py
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-07-20 10:13:24 +0100
committerSimon McVittie <smcv@collabora.com>2021-07-20 10:34:20 +0100
commitce5fa75f01a7197908f462a422237af09cb73a73 (patch)
tree725f4360ca7c605119c87ce181743589736ca9a0 /examples/example-client.py
parent2860c6873169ffc0f950b748f1865ad39402840c (diff)
downloaddbus-python-ce5fa75f01a7197908f462a422237af09cb73a73.tar.gz
examples: Convert to Python 3
Python 2 reached EOL more than 18 months ago. For the gconf example, which is only still here because it provides an example of implementing a FallbackObject, use a mock implementation if the deprecated gconf module is no longer available. Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'examples/example-client.py')
-rwxr-xr-xexamples/example-client.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/examples/example-client.py b/examples/example-client.py
index d9ff776..6f7ade2 100755
--- a/examples/example-client.py
+++ b/examples/example-client.py
@@ -1,9 +1,11 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
+
+from __future__ import print_function
usage = """Usage:
-python example-service.py &
-python example-client.py
-python example-client.py --exit-service
+python3 example-service.py &
+python3 example-client.py
+python3 example-client.py --exit-service
"""
# Copyright (C) 2004-2006 Red Hat Inc. <http://www.redhat.com/>
@@ -48,30 +50,30 @@ def main():
dbus_interface = "com.example.SampleInterface")
except dbus.DBusException:
print_exc()
- print usage
+ print(usage)
sys.exit(1)
- print (hello_reply_list)
+ print("client:", hello_reply_list)
# ... or create an Interface wrapper for the remote object
iface = dbus.Interface(remote_object, "com.example.SampleInterface")
hello_reply_tuple = iface.GetTuple()
- print hello_reply_tuple
+ print("client:", hello_reply_tuple)
hello_reply_dict = iface.GetDict()
- print hello_reply_dict
+ print("client:", hello_reply_dict)
# D-Bus exceptions are mapped to Python exceptions
try:
iface.RaiseException()
except dbus.DBusException as e:
- print str(e)
+ print("client:", str(e))
# introspection is automatically supported
- print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
+ print("client:", remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable"))
if sys.argv[1:] == ['--exit-service']:
iface.Exit()