Changeset 194:f1b586df427b for wokkel


Ignore:
Timestamp:
Oct 3, 2016, 8:49:10 AM (4 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
rebase_source:
77cb4411a2525cb7b972b664a751e11c11b7cf65
Message:

imported patch py3-subprotocols.patch

Location:
wokkel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wokkel/generic.py

    r185 r194  
    88"""
    99
    10 from zope.interface import implements
     10from zope.interface import implementer
    1111
    1212from twisted.internet import defer, protocol
     
    8787
    8888
     89@implementer(IDisco)
    8990class VersionHandler(XMPPHandler):
    9091    """
     
    9495    U{XEP-0092<http://xmpp.org/extensions/xep-0092.html>}.
    9596    """
    96 
    97     implements(IDisco)
    9897
    9998    def __init__(self, name, version):
  • wokkel/subprotocols.py

    r166 r194  
    88"""
    99
    10 __all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager',
    11            'IQHandlerMixin']
    12 
    13 from zope.interface import implements
     10from __future__ import division, absolute_import
     11
     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
     
    3131        "XMPPHandlerCollection")
    3232
     33@implementer(ijabber.IXMPPHandler)
    3334class XMPPHandler(object):
    3435    """
     
    3839    extension protocols, and are referred to as a subprotocol implementation.
    3940    """
    40 
    41     implements(ijabber.IXMPPHandler)
    4241
    4342    def __init__(self):
     
    278277        iqDeferreds = self._iqDeferreds
    279278        self._iqDeferreds = {}
    280         for d in iqDeferreds.itervalues():
     279        for d in itervalues(iqDeferreds):
    281280            d.errback(reason)
    282281
     
    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)
     
    473472
    474473        iq.handled = True
     474
     475
     476
     477__all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager',
     478           'IQHandlerMixin']
  • wokkel/test/test_subprotocols.py

    r165 r194  
    55Tests for L{wokkel.subprotocols}
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from zope.interface.verify import verifyObject
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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())
    597 
    598         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    599                         "xmlns:stream='http://etherx.jabber.org/streams' "
    600                         "from='example.com' id='12345'>")
     595        self.assertEquals(b"", xs.transport.value())
     596
     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
     
    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
     
    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
     
    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))
     
    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
     
    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)
     
    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
Note: See TracChangeset for help on using the changeset viewer.