root/trunk/twisted/plugins/twisted_qtstub.py

Revision 19009, 1.4 KB (checked in by exarkun, 4 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"""
5Backwards-compatibility plugin for the Qt reactor.
6
7This provides a Qt reactor plugin named C{qt} which emits a deprecation
8warning and a pointer to the separately distributed Qt reactor plugins.
9"""
10
11import warnings
12
13from twisted.application.reactors import Reactor, NoSuchReactor
14
15wikiURL = 'http://twistedmatrix.com/trac/wiki/QTReactor'
16errorMessage = ('qtreactor is no longer a part of Twisted due to licensing '
17                'issues. Please see %s for details.' % (wikiURL,))
18
19class 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
45qt = QTStub()
Note: See TracBrowser for help on using the browser.