Ignore:
Timestamp:
Jul 6, 2009, 9:26:47 AM (12 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@175
Message:

Make IQ timeouts work for InternalComponents?.

This introduces wokkel.compat.IQ to work with older Twisted versions, too.

Author: ralphm.
Fixes #53.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/compat.py

    r53 r63  
    11# -*- test-case-name: wokkel.test.test_compat -*-
    22#
    3 # Copyright (c) 2001-2008 Twisted Matrix Laboratories.
     3# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
    44# See LICENSE for details.
    55
    66from twisted.internet import protocol
    77from twisted.words.protocols.jabber import xmlstream
    8 from twisted.words.xish import domish
    98
    109class BootstrapMixin(object):
     
    9594        self.installBootstraps(xs)
    9695        return xs
     96
     97
     98
     99class IQ(xmlstream.IQ):
     100    def __init__(self, *args, **kwargs):
     101        # Make sure we have a reactor parameter
     102        try:
     103            reactor = kwargs['reactor']
     104        except KeyError:
     105            from twisted.internet import reactor
     106        kwargs['reactor'] = reactor
     107
     108        # Check if IQ's init accepts the reactor parameter
     109        try:
     110            xmlstream.IQ.__init__(self, *args, **kwargs)
     111        except TypeError:
     112            # Guess not. Remove the reactor parameter and try again.
     113            del kwargs['reactor']
     114            xmlstream.IQ.__init__(self, *args, **kwargs)
     115
     116            # Patch the XmlStream instance so that it has a _callLater
     117            self._xmlstream._callLater = reactor.callLater
Note: See TracChangeset for help on using the changeset viewer.