source: wokkel/compat.py @ 239:882edbd9efc6

Last change on this file since 239:882edbd9efc6 was 204:c13df6bb0135, checked in by Ralph Meijer <ralphm@…>, 6 years ago

imported patch py3-muc.patch

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