File: 0003-Port-examples-to-python-3-retaining-compatibility.patch

package info (click to toggle)
telepathy-glib 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,756 kB
  • sloc: ansic: 124,638; xml: 34,410; sh: 4,531; python: 3,528; makefile: 1,722; javascript: 211; cpp: 16
file content (329 lines) | stat: -rw-r--r-- 11,945 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
From: Arusekk <arek_koz@o2.pl>
Date: Mon, 26 Oct 2020 23:05:26 +0100
Subject: Port examples to python 3, retaining compatibility

---
 examples/client/python/contact-list.py         |  2 +-
 examples/client/python/ensure-channel.py       |  6 ++---
 examples/client/python/file-transfer.py        | 17 ++++++-------
 examples/client/python/ft-handler.py           | 11 +++++----
 examples/client/python/stream-tube-accepter.py | 19 ++++++++-------
 examples/client/python/stream-tube-offerer.py  | 33 +++++++++++++-------------
 examples/client/python/text-handler.py         |  7 +++---
 7 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/examples/client/python/contact-list.py b/examples/client/python/contact-list.py
index df854f1..19d0dc4 100755
--- a/examples/client/python/contact-list.py
+++ b/examples/client/python/contact-list.py
@@ -21,7 +21,7 @@ def manager_prepared_cb(manager, result, loop):
            connection.get_contact_list_state() == Tp.ContactListState.SUCCESS:
             contacts = connection.dup_contact_list()
             for contact in contacts:
-                print "%s (%s)" % (contact.get_identifier(), contact.get_contact_groups())
+                print("%s (%s)" % (contact.get_identifier(), contact.get_contact_groups()))
     loop.quit()
 
 if __name__ == '__main__':
diff --git a/examples/client/python/ensure-channel.py b/examples/client/python/ensure-channel.py
index 9e46239..2f8070a 100755
--- a/examples/client/python/ensure-channel.py
+++ b/examples/client/python/ensure-channel.py
@@ -10,9 +10,9 @@ gi.require_version('TelepathyGLib', '0.12')
 from gi.repository import TelepathyGLib
 
 def usage():
-    print "%s ACCOUNT [text|audio|video] CONTACT" % sys.argv[0]
-    print "ACCOUNT is a Telepathy account name, use 'mc-tool list' to list all your accounts"
-    print "CONTACT is a contact id such as badger@gmail.com"
+    print("%s ACCOUNT [text|audio|video] CONTACT" % sys.argv[0])
+    print("ACCOUNT is a Telepathy account name, use 'mc-tool list' to list all your accounts")
+    print("CONTACT is a contact id such as badger@gmail.com")
 
     sys.exit(1)
 
diff --git a/examples/client/python/file-transfer.py b/examples/client/python/file-transfer.py
index f56fa18..7dab553 100755
--- a/examples/client/python/file-transfer.py
+++ b/examples/client/python/file-transfer.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import print_function
 import sys
 import os
 import mimetypes
@@ -13,21 +14,21 @@ gi.require_version('TelepathyGLib', '0.12')
 from gi.repository import TelepathyGLib
 
 def usage():
-    print "%s ACCOUNT CONTACT FILE" % sys.argv[0]
-    print "ACCOUNT is a Telepathy account name, use 'mc-tool list' to list all your accounts"
-    print "CONTACT is a contact id such as badger@nyan.cat"
-    print "FILE is a path to the local file you want sent"
+    print("%s ACCOUNT CONTACT FILE" % sys.argv[0])
+    print("ACCOUNT is a Telepathy account name, use 'mc-tool list' to list all your accounts")
+    print("CONTACT is a contact id such as badger@nyan.cat")
+    print("FILE is a path to the local file you want sent")
 
     sys.exit(1)
 
 def provide_file_cb(channel, result, data):
     if not channel.provide_file_finish(result):
-        print 'failed to provide'
+        print('failed to provide')
 
 def state_changed_cb(channel, pspec, data):
     main_loop, file_path = data
     state, _ = channel.get_state()
-    print 'state is now', state
+    print('state is now', state)
 
     if state == TelepathyGLib.FileTransferState.ACCEPTED:
         file = Gio.File.new_for_path(file_path)
@@ -38,8 +39,8 @@ def create_channel_cb(request, result, data):
         (chan, context) = request.create_and_handle_channel_finish(result)
 
         chan.connect('notify::state', state_changed_cb, data)
-    except GObject.GError, e:
-        print "Failed to create channel: %s" % e
+    except GObject.GError as e:
+        print("Failed to create channel: %s" % e)
         sys.exit(1)
 
 if __name__ == '__main__':
diff --git a/examples/client/python/ft-handler.py b/examples/client/python/ft-handler.py
index fe6f24f..04604b3 100644
--- a/examples/client/python/ft-handler.py
+++ b/examples/client/python/ft-handler.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import print_function
 import sys
 
 import gi
@@ -11,18 +12,18 @@ gi.require_version('TelepathyGLib', '0.12')
 from gi.repository import TelepathyGLib
 
 def usage():
-    print "%s FILE" % sys.argv[0]
-    print "FILE is a path to the location you want the file saved to"
+    print("%s FILE" % sys.argv[0])
+    print("FILE is a path to the location you want the file saved to")
 
     sys.exit(1)
 
 def state_changed_cb(channel, pspec, data):
     state, _ = channel.get_state()
-    print 'State is now:', state
+    print('State is now:', state)
 
 def accept_cb(channel, result, data):
     if not channel.accept_file_finish(result):
-        print 'Failed to accept file'
+        print('Failed to accept file')
 
 def handle_channels_cb(handler, account, connection, channels, requests,
                        user_action_time, context, filename):
@@ -33,7 +34,7 @@ def handle_channels_cb(handler, account, connection, channels, requests,
 
         chan.connect('notify::state', state_changed_cb, None)
 
-        print 'Handling FileTransfer channel:', chan.get_identifier()
+        print('Handling FileTransfer channel:', chan.get_identifier())
 
         file = Gio.File.new_for_path(filename)
         chan.accept_file_async(file, 0, accept_cb, None)
diff --git a/examples/client/python/stream-tube-accepter.py b/examples/client/python/stream-tube-accepter.py
index b5ed677..b956b48 100755
--- a/examples/client/python/stream-tube-accepter.py
+++ b/examples/client/python/stream-tube-accepter.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+from __future__ import print_function
 import os
 
 import gi
@@ -8,20 +9,20 @@ gi.require_version('TelepathyGLib', '0.12')
 from gi.repository import TelepathyGLib as Tp
 
 def tube_conn_closed(tube, error):
-    print "Tube connection has been closed", error.message
+    print("Tube connection has been closed", error.message)
 
 def tube_accept_cb(tube, result, loop):
     try:
         tube_conn = tube.accept_finish(result)
-    except GObject.GError, e:
-        print "Failed to accept tube: %s" % e
+    except GObject.GError as e:
+        print("Failed to accept tube: %s" % e)
         sys.exit(1)
 
     tube_conn.connect('closed', tube_conn_closed)
 
     contact = tube_conn.get_contact();
 
-    print "Got IOStream to", contact.get_identifier()
+    print("Got IOStream to", contact.get_identifier())
 
     conn = tube_conn.get_socket_connection();
 
@@ -30,14 +31,14 @@ def tube_accept_cb(tube, result, loop):
     in_stream = Gio.DataInputStream (base_stream=conn.get_input_stream())
     out_stream = conn.get_output_stream()
 
-    print "Sending: Ping"
+    print("Sending: Ping")
     out_stream.write("Ping\n", None)
 
     buf, len = in_stream.read_line_utf8(None)
-    print "Received:", buf
+    print("Received:", buf)
 
 def tube_invalidated_cb(tube, domain, code, message, loop):
-    print "tube has been invalidated:", message
+    print("tube has been invalidated:", message)
     loop.quit()
 
 def handle_channels_cb(handler, account, connection, channels, requests,
@@ -46,7 +47,7 @@ def handle_channels_cb(handler, account, connection, channels, requests,
         if not isinstance(channel, Tp.StreamTubeChannel):
             continue
 
-        print "Accepting tube"
+        print("Accepting tube")
 
         channel.connect('invalidated', tube_invalidated_cb, loop)
 
@@ -71,5 +72,5 @@ if __name__ == '__main__':
 
     handler.register()
 
-    print "Waiting for tube offer"
+    print("Waiting for tube offer")
     loop.run()
diff --git a/examples/client/python/stream-tube-offerer.py b/examples/client/python/stream-tube-offerer.py
index 69b5332..b88f180 100755
--- a/examples/client/python/stream-tube-offerer.py
+++ b/examples/client/python/stream-tube-offerer.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+from __future__ import print_function
 import sys
 import os
 
@@ -9,31 +10,31 @@ gi.require_version('TelepathyGLib', '0.12')
 from gi.repository import TelepathyGLib as Tp
 
 def usage():
-    print "%s ACCOUNT CONTACT" % sys.argv[0]
-    print "ACCOUNT is a Telepathy account name, use 'mc-tool list' to list all your accounts"
-    print "CONTACT is a contact id such as badger@nyan.cat"
+    print("%s ACCOUNT CONTACT" % sys.argv[0])
+    print("ACCOUNT is a Telepathy account name, use 'mc-tool list' to list all your accounts")
+    print("CONTACT is a contact id such as badger@nyan.cat")
 
     sys.exit(1)
 
 def offer_channel_cb(tube, result, loop):
     try:
         tube.offer_finish(result)
-        print "tube offered"
+        print("tube offered")
 
-    except GObject.GError, e:
-        print "Failed to offer tube: %s" % e
+    except GObject.GError as e:
+        print("Failed to offer tube: %s" % e)
         sys.exit(1)
 
 def tube_conn_closed(tube, error):
-    print "Tube connection has been closed", error.message
+    print("Tube connection has been closed", error.message)
 
 def channel_close_cb(tube, result, loop):
     try:
         tube.close_finish(result)
-        print "tube channel closed"
+        print("tube channel closed")
 
-    except GObject.GError, e:
-        print "Failed to close tube channel: %s" % e
+    except GObject.GError as e:
+        print("Failed to close tube channel: %s" % e)
         sys.exit(1)
 
 def tube_incoming_cb(tube, tube_conn, loop):
@@ -41,7 +42,7 @@ def tube_incoming_cb(tube, tube_conn, loop):
 
     contact = tube_conn.get_contact();
 
-    print "Got IOStream from", contact.get_identifier()
+    print("Got IOStream from", contact.get_identifier())
 
     conn = tube_conn.get_socket_connection();
 
@@ -51,15 +52,15 @@ def tube_incoming_cb(tube, tube_conn, loop):
     out_stream = conn.get_output_stream()
 
     buf, len = in_stream.read_line_utf8(None)
-    print "Received:", buf
+    print("Received:", buf)
 
-    print "Sending: Pong"
+    print("Sending: Pong")
     out_stream.write("Pong\n", None)
 
     tube.close_async(channel_close_cb, contact)
 
 def tube_invalidated_cb(tube, domain, code, message, loop):
-    print "tube has been invalidated:", message
+    print("tube has been invalidated:", message)
     loop.quit()
 
 def create_channel_cb(request, result, loop):
@@ -71,8 +72,8 @@ def create_channel_cb(request, result, loop):
 
         chan.offer_async({}, offer_channel_cb, loop)
 
-    except GObject.GError, e:
-        print "Failed to create channel: %s" % e
+    except GObject.GError as e:
+        print("Failed to create channel: %s" % e)
         sys.exit(1)
 
 if __name__ == '__main__':
diff --git a/examples/client/python/text-handler.py b/examples/client/python/text-handler.py
index 7a1d6e8..a0b33a4 100755
--- a/examples/client/python/text-handler.py
+++ b/examples/client/python/text-handler.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+from __future__ import print_function
 import gi
 
 from gi.repository import GObject
@@ -12,9 +13,9 @@ def echo_message(channel, msg, pending):
     text, flags = msg.to_text()
 
     if pending:
-        print "pending: %s" % (text)
+        print("pending: %s" % (text))
     else:
-        print "received: %s" % (text)
+        print("received: %s" % (text))
 
     reply = TelepathyGLib.ClientMessage.new_text(
         TelepathyGLib.ChannelTextMessageType.NORMAL, text.upper())
@@ -42,7 +43,7 @@ def handle_channels_cb(handler, account, connection, channels, requests,
         if not isinstance(channel, TelepathyGLib.TextChannel):
             continue
 
-        print "Handling text channel with", channel.get_identifier()
+        print("Handling text channel with", channel.get_identifier())
 
         channel.connect('message-received', message_received_cb)