Skip to content

Commit 137b9fb

Browse files
committed
Change the error type raised by Clipboard.synchronized_changes()
Re: dictation-toolbox#390. TimeoutError is now used, as in the PR. An exception class with that name has been introduced for Python 2 in dragonfly.error for compati- bility reasons.
1 parent bac354d commit 137b9fb

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

dragonfly/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#---------------------------------------------------------------------------
2626
from .config import Config, Section, Item
2727
from .error import DragonflyError, GrammarError
28+
if sys.version_info[0] == 2: # Don't override the Python 3 class.
29+
from .error import TimeoutError
2830

2931
#---------------------------------------------------------------------------
3032
from .engines import (get_engine, EngineError, MimicFailure,

dragonfly/error.py

+6
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ class DragonflyError(Exception):
2424
pass
2525

2626

27+
# Used by the clipboard classes in Python 2.
28+
# Python 3 has its own TimeoutError class.
29+
class TimeoutError(Exception):
30+
pass
31+
32+
2733
class GrammarError(Exception):
2834
pass

dragonfly/windows/base_clipboard.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
import re
3434
import time
3535

36-
from six import text_type, binary_type, integer_types
36+
from six import PY2, text_type, binary_type, integer_types
37+
38+
# Import our TimeoutError substitute for Python 2, needed below.
39+
if PY2:
40+
from dragonfly.error import TimeoutError
3741

3842

3943
#===========================================================================
@@ -163,7 +167,7 @@ def synchronized_changes(cls, timeout, step=0.001, formats=None,
163167
"""
164168
Context manager for synchronizing local and system clipboard
165169
changes. This takes the same arguments as the
166-
:meth:`wait_for_change` method. A ``RuntimeError`` is raised if
170+
:meth:`wait_for_change` method. A ``TimeoutError`` is raised if
167171
the system clipboard does not change.
168172
169173
Arguments:
@@ -204,7 +208,7 @@ def synchronized_changes(cls, timeout, step=0.001, formats=None,
204208
initial_clipboard)
205209
if not changed:
206210
message = "Timed out waiting for clipboard to change"
207-
raise RuntimeError(message)
211+
raise TimeoutError(message)
208212

209213
#-----------------------------------------------------------------------
210214

dragonfly/windows/win32_clipboard.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@
3434
import threading
3535
import time
3636

37-
from six import integer_types, reraise
37+
from six import PY2, integer_types, reraise
3838

3939
import pywintypes
4040
import win32clipboard
4141
import win32con
4242

4343
from dragonfly.windows.base_clipboard import BaseClipboard
4444

45+
# Import our TimeoutError substitute for Python 2, needed below.
46+
if PY2:
47+
from dragonfly.error import TimeoutError
48+
49+
4550
#===========================================================================
4651

4752
class win32_clipboard_ctx(object):
@@ -231,7 +236,7 @@ def synchronized_changes(cls, timeout, step=0.001, formats=None,
231236
initial_clipboard, seq_no)
232237
if not changed:
233238
message = "Timed out waiting for clipboard to change"
234-
raise RuntimeError(message)
239+
raise TimeoutError(message)
235240

236241
#-----------------------------------------------------------------------
237242

0 commit comments

Comments
 (0)