root / trunk / twisted / plugins / twisted_qtstub.py

Revision 19009, 1.4 kB (checked in by exarkun, 3 years ago)

Merge qtreactor-stub-2137

Author: PenguinOfDoom?
Reviewer: glyph
Fixes #2137

This adds a reactor plugin which will attempt to import qtreactor and
warn that the name qt is now deprecated. If qtreactor cannot be
imported it will point to the location from which it can be retrieved.

This also adds a similar backwards-compatibility stub for
twisted.internet.qtreactor for applications which install it themselves
rather than using twistd.

Line 
1 # Copyright (c) 2006 Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Backwards-compatibility plugin for the Qt reactor.
6
7 This provides a Qt reactor plugin named C{qt} which emits a deprecation
8 warning and a pointer to the separately distributed Qt reactor plugins.
9 """
10
11 import warnings
12
13 from twisted.application.reactors import Reactor, NoSuchReactor
14
15 wikiURL = 'http://twistedmatrix.com/trac/wiki/QTReactor'
16 errorMessage = ('qtreactor is no longer a part of Twisted due to licensing '
17                 'issues. Please see %s for details.' % (wikiURL,))
18
19 class QTStub(Reactor):
20     """
21     Reactor plugin which emits a deprecation warning on the successful
22     installation of its reactor or a pointer to further information if an
23     ImportError occurs while attempting to install it.
24     """
25     def __init__(self):
26         super(QTStub, self).__init__(
27             'qt', 'qtreactor', 'QT integration reactor')
28
29
30     def install(self):
31         """
32         Install the Qt reactor with a deprecation warning or try to point
33         the user to further information if it cannot be installed.
34         """
35         try:
36             super(QTStub, self).install()
37         except (ValueError, ImportError):
38             raise NoSuchReactor(errorMessage)
39         else:
40             warnings.warn(
41                 "Please use -r qt3 to import qtreactor",
42                 category=DeprecationWarning)
43
44
45 qt = QTStub()
Note: See TracBrowser for help on using the browser.