Debian Codegraph @

tx_xmpp/compat.py

raw
1 # -*- test-case-name: tx_xmpp.test.test.test_compat -*-
2 #
3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
5
6 """
7 Compatibility module to provide backwards compatibility with Twisted features.
8 """
9
10 from twisted.words.protocols.jabber import xmlstream
11
12
13 class IQ(xmlstream.IQ):
14 def __init__(self, *args, **kwargs):
15 # Make sure we have a reactor parameter
16 try:
17 reactor = kwargs["reactor"]
18 except KeyError:
19 from twisted.internet import reactor
20 kwargs["reactor"] = reactor
21
22 # Check if IQ's init accepts the reactor parameter
23 try:
24 xmlstream.IQ.__init__(self, *args, **kwargs)
25 except TypeError:
26 # Guess not. Remove the reactor parameter and try again.
27 del kwargs["reactor"]
28 xmlstream.IQ.__init__(self, *args, **kwargs)
29
30 # Patch the XmlStream instance so that it has a _callLater
31 self._xmlstream._callLater = reactor.callLater
32
33
34 __all__ = ["IQ"]