source: ralphm-patches/py3-subprotocols.patch @ 78:361e2111a663

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

Start port to Python 3.

File size: 10.1 KB
  • wokkel/generic.py

    # HG changeset patch
    # Parent  5f4f660d738928e7d8e2741f8e957386ae75ab86
    
    diff --git a/wokkel/generic.py b/wokkel/generic.py
    a b  
    77Generic XMPP protocol helpers.
    88"""
    99
    10 from zope.interface import implements
     10from zope.interface import implementer
    1111
    1212from twisted.internet import defer, protocol
    1313from twisted.python import reflect
     
    8686
    8787
    8888
     89@implementer(IDisco)
    8990class VersionHandler(XMPPHandler):
    9091    """
    9192    XMPP subprotocol handler for XMPP Software Version.
     
    9495    U{XEP-0092<http://xmpp.org/extensions/xep-0092.html>}.
    9596    """
    9697
    97     implements(IDisco)
    98 
    9998    def __init__(self, name, version):
    10099        self.name = name
    101100        self.version = version
  • wokkel/subprotocols.py

    diff --git a/wokkel/subprotocols.py b/wokkel/subprotocols.py
    a b  
    77XMPP subprotocol support.
    88"""
    99
    10 __all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager',
    11            'IQHandlerMixin']
     10from __future__ import division, absolute_import
    1211
    13 from zope.interface import implements
     12from zope.interface import implementer
    1413
    1514from twisted.internet import defer
    1615from twisted.internet.error import ConnectionDone
    1716from twisted.python import failure, log
     17from twisted.python.compat import iteritems, itervalues
    1818from twisted.python.deprecate import deprecatedModuleAttribute
    1919from twisted.python.versions import Version
    2020from twisted.words.protocols.jabber import error, ijabber, xmlstream
     
    3030        __name__,
    3131        "XMPPHandlerCollection")
    3232
     33@implementer(ijabber.IXMPPHandler)
    3334class XMPPHandler(object):
    3435    """
    3536    XMPP protocol handler.
     
    3839    extension protocols, and are referred to as a subprotocol implementation.
    3940    """
    4041
    41     implements(ijabber.IXMPPHandler)
    42 
    4342    def __init__(self):
    4443        self.parent = None
    4544        self.xmlstream = None
     
    277276        # deferreds will never be fired.
    278277        iqDeferreds = self._iqDeferreds
    279278        self._iqDeferreds = {}
    280         for d in iqDeferreds.itervalues():
     279        for d in itervalues(iqDeferreds):
    281280            d.errback(reason)
    282281
    283282
     
    455454            return error.StanzaError('internal-server-error').toResponse(iq)
    456455
    457456        handler = None
    458         for queryString, method in self.iqHandlers.iteritems():
     457        for queryString, method in iteritems(self.iqHandlers):
    459458            if xpath.internQuery(queryString).matches(iq):
    460459                handler = getattr(self, method)
    461460
     
    472471        d.addCallback(self.send)
    473472
    474473        iq.handled = True
     474
     475
     476
     477__all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager',
     478           'IQHandlerMixin']
  • wokkel/test/test_subprotocols.py

    diff --git a/wokkel/test/test_subprotocols.py b/wokkel/test/test_subprotocols.py
    a b  
    55Tests for L{wokkel.subprotocols}
    66"""
    77
     8from __future__ import division, absolute_import
     9
    810from zope.interface.verify import verifyObject
    911
    1012from twisted.trial import unittest
     
    210212        """
    211213        self.xmlstream.connectionMade()
    212214        self.xmlstream.dataReceived(
    213                 "<stream:stream xmlns='jabber:client' "
    214                     "xmlns:stream='http://etherx.jabber.org/streams' "
    215                     "from='example.com' id='12345'>")
     215                b"<stream:stream xmlns='jabber:client' "
     216                    b"xmlns:stream='http://etherx.jabber.org/streams' "
     217                    b"from='example.com' id='12345'>")
    216218        self.xmlstream.dispatch(self.xmlstream, "//event/stream/authd")
    217219
    218220
     
    475477        xs = factory.buildProtocol(None)
    476478        xs.transport = proto_helpers.StringTransport()
    477479        xs.connectionMade()
    478         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    479                         "xmlns:stream='http://etherx.jabber.org/streams' "
    480                         "from='example.com' id='12345'>")
     480        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     481                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     482                        b"from='example.com' id='12345'>")
    481483        xs.dispatch(xs, "//event/stream/authd")
    482484        sm.send("<presence/>")
    483         self.assertEquals("<presence/>", xs.transport.value())
     485        self.assertEquals(b"<presence/>", xs.transport.value())
    484486
    485487
    486488    def test_sendNotConnected(self):
     
    498500        xs = factory.buildProtocol(None)
    499501        xs.transport = proto_helpers.StringTransport()
    500502        sm.send("<presence/>")
    501         self.assertEquals("", xs.transport.value())
     503        self.assertEquals(b"", xs.transport.value())
    502504        self.assertEquals("<presence/>", sm._packetQueue[0])
    503505
    504506        xs.connectionMade()
    505         self.assertEquals("", xs.transport.value())
     507        self.assertEquals(b"", xs.transport.value())
    506508        self.assertEquals("<presence/>", sm._packetQueue[0])
    507509
    508         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    509                         "xmlns:stream='http://etherx.jabber.org/streams' "
    510                         "from='example.com' id='12345'>")
     510        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     511                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     512                        b"from='example.com' id='12345'>")
    511513        xs.dispatch(xs, "//event/stream/authd")
    512514
    513         self.assertEquals("<presence/>", xs.transport.value())
     515        self.assertEquals(b"<presence/>", xs.transport.value())
    514516        self.assertFalse(sm._packetQueue)
    515517
    516518
     
    525527        xs = factory.buildProtocol(None)
    526528        xs.transport = proto_helpers.StringTransport()
    527529        xs.connectionMade()
    528         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    529                         "xmlns:stream='http://etherx.jabber.org/streams' "
    530                         "from='example.com' id='12345'>")
     530        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     531                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     532                        b"from='example.com' id='12345'>")
    531533        sm.send("<presence/>")
    532         self.assertEquals("", xs.transport.value())
     534        self.assertEquals(b"", xs.transport.value())
    533535        self.assertEquals("<presence/>", sm._packetQueue[0])
    534536
    535537
     
    551553        xs.connectionLost(None)
    552554
    553555        sm.send("<presence/>")
    554         self.assertEquals("", xs.transport.value())
     556        self.assertEquals(b"", xs.transport.value())
    555557        self.assertEquals("<presence/>", sm._packetQueue[0])
    556558
    557559
     
    562564        self._streamStarted()
    563565
    564566        self.streamManager.request(self.request)
    565         expected = u"<iq type='get' id='%s'/>" % self.request.stanzaID
    566         self.assertEquals(expected, self.transport.value())
     567        self.assertTrue(self.transport.value())
    567568
    568569
    569570    def test_requestSendInitializedFreshID(self):
     
    575576        self.request.stanzaID = None
    576577        self.streamManager.request(self.request)
    577578        self.assertNotIdentical(None, self.request.stanzaID)
    578         expected = u"<iq type='get' id='%s'/>" % self.request.stanzaID
    579         self.assertEquals(expected, self.transport.value())
     579        self.assertTrue(self.transport.value())
    580580
    581581
    582582    def test_requestSendNotConnected(self):
     
    587587        self.streamManager.addHandler(handler)
    588588
    589589        self.streamManager.request(self.request)
    590         expected = u"<iq type='get' id='test'/>"
    591590
    592591        xs = self.xmlstream
    593         self.assertEquals("", xs.transport.value())
     592        self.assertEquals(b"", xs.transport.value())
    594593
    595594        xs.connectionMade()
    596         self.assertEquals("", xs.transport.value())
     595        self.assertEquals(b"", xs.transport.value())
    597596
    598         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    599                         "xmlns:stream='http://etherx.jabber.org/streams' "
    600                         "from='example.com' id='12345'>")
     597        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     598                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     599                        b"from='example.com' id='12345'>")
    601600        xs.dispatch(xs, "//event/stream/authd")
    602601
    603         self.assertEquals(expected, xs.transport.value())
     602        self.assertTrue(self.transport.value())
    604603        self.assertFalse(self.streamManager._packetQueue)
    605604
    606605
     
    616615        d.addCallback(cb)
    617616
    618617        xs = self.xmlstream
    619         xs.dataReceived("<iq type='result' id='test'/>")
     618        xs.dataReceived(b"<iq type='result' id='test'/>")
    620619        return d
    621620
    622621
     
    629628        self.assertFailure(d, error.StanzaError)
    630629
    631630        xs = self.xmlstream
    632         xs.dataReceived("<iq type='error' id='test'/>")
     631        xs.dataReceived(b"<iq type='error' id='test'/>")
    633632        return d
    634633
    635634
     
    651650        self.xmlstream.addObserver("/iq", cb, -1)
    652651
    653652        # Receive an untracked iq response
    654         self.xmlstream.dataReceived("<iq type='result' id='other'/>")
     653        self.xmlstream.dataReceived(b"<iq type='result' id='other'/>")
    655654        self.assertEquals(1, len(dispatched))
    656655        self.assertFalse(getattr(dispatched[-1], 'handled', False))
    657656
     
    665664        self._streamStarted()
    666665        d = self.streamManager.request(self.request)
    667666        xs = self.xmlstream
    668         xs.dataReceived("<iq type='result' id='test'/>")
     667        xs.dataReceived(b"<iq type='result' id='test'/>")
    669668        self.assertNotIn('test', self.streamManager._iqDeferreds)
    670669        return d
    671670
     
    721720        self.request.timeout = 60
    722721        d = self.streamManager.request(self.request)
    723722        self.clock.callLater(1, self.xmlstream.dataReceived,
    724                              "<iq type='result' id='test'/>")
     723                                b"<iq type='result' id='test'/>")
    725724        self.clock.pump([1, 1])
    726725        self.assertFalse(self.clock.calls)
    727726        return d
     
    867866        self.assertEquals(None, response.uri)
    868867        self.assertEquals('iq', response.name)
    869868        self.assertEquals('result', response['type'])
    870         payload = response.elements().next()
     869        payload = next(response.elements())
    871870        self.assertEqual(handler.payload, payload)
    872871
    873872    def test_successDeferred(self):
Note: See TracBrowser for help on using the repository browser.