Repository navigation
Expand file tree
/
Copy pathauthconn.py
More file actions
767 lines (646 loc) · 27.6 KB
/
Copy pathauthconn.py
File metadata and controls
767 lines (646 loc) · 27.6 KB
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#!/usr/bin/python3
## Copyright (C) 2007, 2008, 2009, 2010, 2011, 2013, 2014 Red Hat, Inc.
## Author: Tim Waugh <twaugh@redhat.com>
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import threading
import queue
import time
import config
import cups
import cupspk
import gi
from gi.repository import GLib
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import os
from errordialogs import *
from debug import *
import gettext
gettext.install(domain=config.PACKAGE, localedir=config.localedir)
N_ = lambda x: x
class WorkerTimeoutError(RuntimeError):
pass
class WorkerUnavailableError(RuntimeError):
pass
cups.require("1.9.60")
class AuthDialog(Gtk.Dialog):
AUTH_FIELD={'username': N_("Username:"),
'password': N_("Password:"),
'domain': N_("Domain:")}
def __init__ (self, title=None, parent=None,
flags=Gtk.DialogFlags.MODAL,
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK),
auth_info_required=None,
allow_remember=False):
if title is None:
title = _("Authentication")
if auth_info_required is None:
auth_info_required = ['username', 'password']
Gtk.Dialog.__init__ (self, title, parent, flags, buttons)
self.auth_info_required = auth_info_required
self.set_default_response (Gtk.ResponseType.OK)
self.set_border_width (6)
self.set_resizable (False)
hbox = Gtk.HBox.new (False, 12)
hbox.set_border_width (6)
image = Gtk.Image ()
image.set_from_stock (Gtk.STOCK_DIALOG_AUTHENTICATION,
Gtk.IconSize.DIALOG)
image.set_alignment (0.0, 0.0)
hbox.pack_start (image, False, False, 0)
vbox = Gtk.VBox.new (False, 12)
self.prompt_label = Gtk.Label ()
vbox.pack_start (self.prompt_label, False, False, 0)
num_fields = len (auth_info_required)
grid = Gtk.Grid()
grid.insert_row(num_fields)
grid.insert_column(2)
grid.set_row_spacing (6)
grid.set_column_spacing (6)
self.field_entry = []
for i in range (num_fields):
field = auth_info_required[i]
label = Gtk.Label (label=_(self.AUTH_FIELD.get (field, field)))
label.set_alignment (0, 0.5)
grid.attach (label, 0, i, 1, 1)
entry = Gtk.Entry ()
entry.set_visibility (field != 'password')
grid.attach (entry, 1, i, 1, 1)
self.field_entry.append (entry)
self.field_entry[num_fields - 1].set_activates_default (True)
vbox.pack_start (grid, False, False, 0)
hbox.pack_start (vbox, False, False, 0)
self.vbox.pack_start (hbox, False, False, 0)
if allow_remember:
cb = Gtk.CheckButton.new_with_label (_("Remember password"))
cb.set_active (False)
vbox.pack_start (cb, False, False, 0)
self.remember_checkbox = cb
self.vbox.show_all ()
def set_prompt (self, prompt):
self.prompt_label.set_markup ('<span weight="bold" size="larger">' +
prompt + '</span>')
self.prompt_label.set_use_markup (True)
self.prompt_label.set_alignment (0, 0)
self.prompt_label.set_line_wrap (True)
def set_auth_info (self, auth_info):
for i in range (len (self.field_entry)):
self.field_entry[i].set_text (auth_info[i])
def get_auth_info (self):
return [x.get_text () for x in self.field_entry]
def get_remember_password (self):
try:
return self.remember_checkbox.get_active ()
except AttributeError:
return False
def field_grab_focus (self, field):
i = self.auth_info_required.index (field)
self.field_entry[i].grab_focus ()
###
### An auth-info cache.
###
class _AuthInfoCache:
def __init__ (self):
self.creds = dict() # by (host,port)
def cache_auth_info (self, data, host=None, port=None):
if port is None:
port = 631
self.creds[(host,port)] = data
def lookup_auth_info (self, host=None, port=None):
if port is None:
port = 631
try:
return self.creds[(host,port)]
except KeyError:
return None
def remove_auth_info (self, host=None, port=None):
if port is None:
port = 631
try:
del self.creds[(host,port)]
except KeyError:
return None
global_authinfocache = _AuthInfoCache ()
def _dispatch_worker_op(op, conn, args, kwds):
"""
Execute a worker operation against the worker-owned cups.Connection
or as a standalone callable.
"""
if isinstance(op, str):
fn = getattr(conn, op)
return fn(*args, **kwds)
if hasattr(op, '_op_name') and getattr(op, '_target_conn', None) is not None:
fn = getattr(conn, op._op_name)
return fn(*args, **kwds)
if callable(op):
if getattr(op, '_with_connection', False):
return op(conn, *args, **kwds)
return op(*args, **kwds)
raise TypeError(f"Operation {op!r} is not callable or a valid method name")
class Connection:
def __init__ (self, parent=None, try_as_root=True, lock=False,
host=None, port=None, encryption=None):
if host is not None:
cups.setServer (host)
if port is not None:
cups.setPort (port)
if encryption is not None:
cups.setEncryption (encryption)
self._use_password = ''
self._parent = parent
self._try_as_root = try_as_root
self._use_user = cups.getUser ()
self._server = cups.getServer ()
self._port = cups.getPort()
self._encryption = cups.getEncryption ()
self._prompt_allowed = True
self._operation_stack = []
self._lock = lock
self._gui_event = threading.Event ()
self._auth_lock = threading.Lock ()
self._cancel = False
self._cannot_auth = False
self._worker_lock = threading.Lock()
self._connect ()
def cancel (self):
self._cancel = True
def _begin_operation (self, operation):
debugprint ("%s: Operation += %s" % (self, operation))
self._operation_stack.append (operation)
def _end_operation (self):
debugprint ("%s: Operation ended" % self)
self._operation_stack.pop ()
def _get_prompt_allowed (self, ):
return self._prompt_allowed
def _set_prompt_allowed (self, allowed):
self._prompt_allowed = allowed
def _set_lock (self, whether):
self._lock = whether
def _connect (self, allow_pk=True):
cups.setUser (self._use_user)
self._use_pk = (allow_pk and
(self._server[0] == '/' or self._server == 'localhost')
and os.getuid () != 0)
if self._use_pk:
create_object = cupspk.Connection
else:
create_object = cups.Connection
self._connection = create_object (host=self._server,
port=self._port,
encryption=self._encryption)
if self._use_pk:
self._connection.set_parent(self._parent)
self._user = self._use_user
debugprint ("Connected as user %s" % self._user)
methodtype_lambda = type (self._connection.getPrinters)
methodtype_real = type (self._connection.addPrinter)
for fname in dir (self._connection):
if fname[0] == '_':
continue
fn = getattr (self._connection, fname)
if not type (fn) in [methodtype_lambda, methodtype_real]:
continue
setattr (self, fname, self._make_binding (fname, fn))
def _using_polkit (self):
return isinstance (self._connection, cupspk.Connection)
def _make_binding (self, fname, fn):
binding = lambda *args, **kwds: self._authloop (fname, fn, *args, **kwds)
binding._op_name = fname
binding._target_conn = self
return binding
def run_on_worker (self, op, feedback=None, spinner=None, delay_ms=250, with_connection=False):
"""
Returns a callable wrapper that executes the specified CUPS operation
on the dedicated background worker thread while pumping the GLib
main loop.
:param op: Either a method name string (e.g. 'getServerPPD', 'getPPD'),
a bound Connection method (self.cups.getServerPPD),
or a callable: op(*args, **kwds) or op(conn, *args, **kwds) if with_connection.
:param feedback: Optional DelayedSpinner or WorkerFeedback instance.
:param spinner: Optional VectorSpinner or Gtk.Spinner widget.
:param delay_ms: Milliseconds to delay spinner appearance (default 250ms).
:param with_connection: If True, pass the worker cups.Connection to op.
"""
if feedback is None and spinner is not None:
from vectorspinner import DelayedSpinner
feedback = DelayedSpinner(spinner, delay_ms=delay_ms)
target_op = getattr(op, '_op_name', op)
if with_connection and callable(target_op):
try:
target_op._with_connection = True
except AttributeError:
pass
is_conn_method = False
if isinstance(target_op, str) and hasattr(self._connection, target_op):
is_conn_method = True
elif hasattr(op, '_op_name') and getattr(op, '_target_conn', None) is self:
is_conn_method = True
def wrapper (*args, **kwds):
# Worker-thread re-entry: execute directly on worker connection to avoid deadlock
if hasattr(self, '_worker_thread') and threading.current_thread() == self._worker_thread:
conn = getattr(self, '_worker_conn', None)
if conn is None:
with self._auth_lock:
user = self._use_user
cups.setUser(user)
conn = cups.Connection(host=self._server,
port=self._port,
encryption=self._encryption)
self._worker_conn = conn
return _dispatch_worker_op(target_op, conn, args, kwds)
# Execution on GTK / main thread:
if is_conn_method:
fn = getattr(self._connection, target_op)
return self._authloop(target_op, fn, *args, _on_worker=True,
_feedback=feedback, **kwds)
else:
return self._execute_in_worker(target_op, *args, _feedback=feedback, **kwds)
return wrapper
def _execute_in_worker(self, fname, *args, **kwds):
timeout_val = kwds.pop('_timeout', 30.0)
feedback = kwds.pop('_feedback', None)
if not hasattr(self, '_worker_queue'):
self._worker_lock = getattr(self, '_worker_lock', threading.Lock())
self._worker_state = 'IDLE'
self._worker_conn = None
self._worker_queue = queue.Queue()
self._worker_thread = threading.Thread(target=self._worker_loop, daemon=True)
self._worker_thread.start()
with self._worker_lock:
if getattr(self, '_worker_unresponsive', False):
raise WorkerUnavailableError("Worker is unavailable or busy")
box = []
req_state = {'completed': False, 'timed_out': False}
self._worker_queue.put((fname, args, kwds, box, req_state))
loop = GLib.MainLoop()
source_id = [None]
start_time = time.monotonic()
if feedback is not None:
feedback.start()
def poll():
with self._worker_lock:
is_completed = req_state['completed']
if is_completed:
if loop.is_running():
loop.quit()
source_id[0] = None
return False
if time.monotonic() - start_time > timeout_val:
with self._worker_lock:
if req_state['completed']:
if loop.is_running():
loop.quit()
source_id[0] = None
return False
req_state['timed_out'] = True
self._worker_unresponsive = True
if loop.is_running():
loop.quit()
source_id[0] = None
return False
return True
source_id[0] = GLib.timeout_add(20, poll)
try:
loop.run()
finally:
if source_id[0] is not None:
GLib.source_remove(source_id[0])
source_id[0] = None
if feedback is not None:
feedback.stop()
if req_state['timed_out']:
raise WorkerTimeoutError("CUPS worker timeout")
if not box:
raise WorkerUnavailableError("CUPS worker returned no result")
ok, res, exc = box[0]
if not ok:
raise exc
return res
def _worker_loop(self):
conn = None
conn_user = None
while True:
item = self._worker_queue.get()
if item is None:
break
fname, args, kwds, box, req_state = item
with self._worker_lock:
self._worker_state = 'BUSY'
try:
with self._auth_lock:
target_user = self._use_user
if conn is None or conn_user != target_user:
cups.setUser(target_user)
conn = cups.Connection(host=self._server,
port=self._port,
encryption=self._encryption)
conn_user = target_user
self._worker_conn = conn
cups.setUser(target_user)
res = _dispatch_worker_op(fname, conn, args, kwds)
res_tuple = (True, res, None)
except Exception as e:
res_tuple = (False, None, e)
finally:
with self._worker_lock:
if req_state['timed_out']:
# Clean up temporary files if a file path was returned
if (res_tuple[0] and isinstance(res_tuple[1], str) and
os.path.isabs(res_tuple[1]) and os.path.exists(res_tuple[1])):
try:
os.unlink(res_tuple[1])
except OSError:
pass
conn = None
conn_user = None
self._worker_conn = None
self._worker_unresponsive = False
else:
req_state['completed'] = True
box.append(res_tuple)
self._worker_state = 'IDLE'
# Clear references to avoid retaining connection or data
fn = None
res = None
res_tuple = None
item = None
args = None
kwds = None
box = None
req_state = None
fname = None
self._worker_queue.task_done()
self._worker_conn = None
def _authloop (self, fname, fn, *args, _on_worker=False, _feedback=None, **kwds):
self._passes = 0
# remove signature if dbus is not being used and signature is provided
if not self._using_polkit():
kwds.pop('signature', None)
c = self._connection
retry = False
while True:
try:
auth_stat = self._perform_authentication ()
if auth_stat == 0:
break
if auth_stat < 0 or self._cancel:
if self._cancel and not self._cannot_auth:
raise cups.IPPError (0, _("Operation canceled"))
break
if c != self._connection:
# We have reconnected.
fn = getattr (self._connection, fname)
c = self._connection
cups.setUser (self._use_user)
if _on_worker:
result = self._execute_in_worker (fname, *args, _feedback=_feedback, **kwds)
else:
if fn is None:
fn = getattr (self._connection, fname)
result = fn.__call__ (*args, **kwds)
if fname == 'adminGetServerSettings':
# Special case for a rubbish bit of API.
if result == {}:
# Authentication failed, but we aren't told that.
raise cups.IPPError (cups.IPP_NOT_AUTHORIZED, '')
break
except cups.IPPError as e:
(e, m) = e.args
if self._use_pk and m == 'pkcancel':
raise cups.IPPError (0, _("Operation canceled"))
if not self._cancel and (e == cups.IPP_NOT_AUTHORIZED or
e == cups.IPP_FORBIDDEN or
e == cups.IPP_AUTHENTICATION_CANCELED):
self._failed (e == cups.IPP_FORBIDDEN)
elif not self._cancel and e == cups.IPP_SERVICE_UNAVAILABLE:
debugprint ("Got IPP_SERVICE_UNAVAILABLE")
debugprint (m)
if self._lock:
self._gui_event.clear ()
GLib.timeout_add (1, self._ask_retry_server_error, m)
self._gui_event.wait ()
else:
self._ask_retry_server_error (m)
if self._retry_response == Gtk.ResponseType.OK:
debugprint ("retrying operation...")
retry = True
self._passes -= 1
self._has_failed = True
else:
self._cancel = True
raise
else:
if self._cancel and not self._cannot_auth:
raise cups.IPPError (0, _("Operation canceled"))
debugprint ("%s: %s" % (e, repr (m)))
raise
except cups.HTTPError as e:
(s,) = e.args
if not self._cancel:
self._failed (s == cups.HTTP_FORBIDDEN)
else:
raise
return result
def _ask_retry_server_error (self, message):
try:
msg = (_("CUPS server error (%s)") % self._operation_stack[0])
except IndexError:
msg = _("CUPS server error")
d = Gtk.MessageDialog (transient_for=self._parent,
modal=True, destroy_with_parent=True,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.NONE,
text=msg)
d.format_secondary_text (_("There was an error during the "
"CUPS operation: '%s'.") % message)
d.add_buttons (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
_("Retry"), Gtk.ResponseType.OK)
d.set_default_response (Gtk.ResponseType.OK)
if self._lock:
d.connect ("response", self._on_retry_server_error_response)
else:
self._retry_response = d.run ()
d.destroy ()
def _on_retry_server_error_response (self, dialog, response):
self._retry_response = response
dialog.destroy ()
self._gui_event.set ()
def _failed (self, forbidden=False):
self._has_failed = True
self._forbidden = forbidden
def _password_callback (self, prompt):
debugprint ("Got password callback")
if self._cancel or self._auth_called:
return ''
self._auth_called = True
self._prompt = prompt
with self._auth_lock:
return self._use_password
def _perform_authentication (self):
self._passes += 1
creds = global_authinfocache.lookup_auth_info (host=self._server, port=self._port)
if creds is not None:
if (creds[0] != 'root' or self._try_as_root):
(self._use_user, self._use_password) = creds
del creds
debugprint ("Authentication pass: %d" % self._passes)
if self._passes == 1:
# Haven't yet tried the operation. Set the password
# callback and return > 0 so we try it for the first time.
self._has_failed = False
self._forbidden = False
self._auth_called = False
self._cancel = False
self._cannot_auth = False
self._dialog_shown = False
cups.setPasswordCB (self._password_callback)
debugprint ("Authentication: password callback set")
return 1
debugprint ("Forbidden: %s" % self._forbidden)
if not self._has_failed:
# Tried the operation and it worked. Return 0 to signal to
# break out of the loop.
debugprint ("Authentication: Operation successful")
return 0
# Reset failure flag.
self._has_failed = False
if self._passes >= 2:
# Tried the operation without a password and it failed.
if (self._try_as_root and
self._user != 'root' and
(self._server[0] == '/' or self._forbidden)):
# This is a UNIX domain socket connection so we should
# not have needed a password (or it is not a UDS but
# we got an HTTP_FORBIDDEN response), and so the
# operation must not be something that the current
# user is authorised to do. They need to try as root,
# and supply the password. However, to get the right
# prompt, we need to try as root but with no password
# first.
debugprint ("Authentication: Try as root")
self._use_user = 'root'
self._auth_called = False
try:
self._connect (allow_pk=False)
except RuntimeError:
raise cups.IPPError (cups.IPP_SERVICE_UNAVAILABLE,
'server-error-service-unavailable')
return 1
if not self._prompt_allowed:
debugprint ("Authentication: prompting not allowed")
self._cancel = True
return 1
if not self._auth_called:
# We aren't even getting a chance to supply credentials.
debugprint ("Authentication: giving up")
self._cancel = True
self._cannot_auth = True
return 1
# Reset the flag indicating whether we were given an auth callback.
self._auth_called = False
# If we're previously prompted, explain why we're prompting again.
if self._dialog_shown:
if self._lock:
self._gui_event.clear ()
GLib.timeout_add (1, self._show_not_authorized_dialog)
self._gui_event.wait ()
else:
self._show_not_authorized_dialog ()
if self._lock:
self._gui_event.clear ()
GLib.timeout_add (1, self._perform_authentication_with_dialog)
self._gui_event.wait ()
else:
self._perform_authentication_with_dialog ()
if self._cancel:
debugprint ("cancelled")
return -1
cups.setUser (self._use_user)
debugprint ("Authentication: Reconnect")
try:
self._connect (allow_pk=False)
except RuntimeError:
raise cups.IPPError (cups.IPP_SERVICE_UNAVAILABLE,
'server-error-service-unavailable')
return 1
def _show_not_authorized_dialog (self):
d = Gtk.MessageDialog (transient_for=self._parent,
modal=True, destroy_with_parent=True,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CLOSE)
d.set_title (_("Not authorized"))
d.set_markup ('<span weight="bold" size="larger">' +
_("Not authorized") + '</span>\n\n' +
_("The password may be incorrect."))
if self._lock:
d.connect ("response", self._on_not_authorized_dialog_response)
d.show_all ()
d.show_now ()
else:
d.run ()
d.destroy ()
def _on_not_authorized_dialog_response (self, dialog, response):
self._gui_event.set ()
dialog.destroy ()
def _perform_authentication_with_dialog (self):
# Prompt.
if len (self._operation_stack) > 0:
try:
title = (_("Authentication (%s)") % self._operation_stack[0])
except IndexError:
title = _("Authentication")
d = AuthDialog (title=title,
parent=self._parent)
else:
d = AuthDialog (parent=self._parent)
d.set_prompt ('')
d.set_auth_info (['', ''])
d.field_grab_focus ('username')
d.set_keep_above (True)
d.show_all ()
d.show_now ()
self._dialog_shown = True
if self._lock:
d.connect ("response", self._on_authentication_response)
else:
response = d.run ()
self._on_authentication_response (d, response)
def _on_authentication_response (self, dialog, response):
(user, password) = dialog.get_auth_info ()
with self._auth_lock:
if user != '':
self._use_user = user
self._use_password = password
global_authinfocache.cache_auth_info ((self._use_user,
self._use_password),
host=self._server,
port=self._port)
dialog.destroy ()
if (response == Gtk.ResponseType.CANCEL or
response == Gtk.ResponseType.DELETE_EVENT):
self._cancel = True
if self._lock:
self._gui_event.set ()
if __name__ == '__main__':
# Test it out.
from timedops import TimedOperation
set_debugging (True)
c = TimedOperation (Connection, args=(None,)).run ()
debugprint ("Connected")
c._set_lock (True)
print(TimedOperation (c.getFile,
args=('/admin/conf/cupsd.conf',
'/dev/stdout')).run ())