source: wokkel/compat.py @ 200:ab43d6940b65

Last change on this file since 200:ab43d6940b65 was 200:ab43d6940b65, checked in by Ralph Meijer <ralphm@…>, 6 years ago

imported patch py3-compat.patch

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