Changes in [74:355afce3af27:83:255aae0cf8c5] in ralphm-patches


Ignore:
Files:
20 added
8 edited

Legend:

Unmodified
Added
Removed
  • async-observer.patch

    r73 r79  
    11# HG changeset patch
    2 # Parent ed052dd5cb7a57faf1693f78457401fd820fdd79
     2# Parent 56607e5ddb53e3fafbecb41118bd220dea9310c7
    33
    44diff --git a/wokkel/subprotocols.py b/wokkel/subprotocols.py
     
    260260+        observer(self, element)
    261261+        self.assertTrue(element.handled)
    262 +        self.assertEqual(1, len(self.output))
     262+        self.assertEquals(1, len(self.output))
    263263+        exc = error.exceptionFromStanza(self.output[-1])
    264 +        self.assertEqual(u'service-unavailable', exc.condition)
     264+        self.assertEquals(u'service-unavailable', exc.condition)
    265265+
    266266+
     
    277277+        observer(self, element)
    278278+        self.assertTrue(element.handled)
    279 +        self.assertEqual(1, len(self.output))
     279+        self.assertEquals(1, len(self.output))
    280280+        exc = error.exceptionFromStanza(self.output[-1])
    281 +        self.assertEqual(u'forbidden', exc.condition)
     281+        self.assertEquals(u'forbidden', exc.condition)
    282282+
    283283+
     
    297297+        observer(self, element)
    298298+        self.assertTrue(element.handled)
    299 +        self.assertEqual(1, len(self.output))
     299+        self.assertEquals(1, len(self.output))
    300300+        exc = error.exceptionFromStanza(self.output[-1])
    301 +        self.assertEqual(u'internal-server-error', exc.condition)
    302 +        self.assertEqual(1, len(self.flushLoggedErrors()))
     301+        self.assertEquals(u'internal-server-error', exc.condition)
     302+        self.assertEquals(1, len(self.flushLoggedErrors()))
    303303+
    304304+
     
    318318+        observer(self, element)
    319319+        self.assertTrue(element.handled)
    320 +        self.assertEqual(1, len(self.output))
     320+        self.assertEquals(1, len(self.output))
    321321+        exc = error.exceptionFromStanza(self.output[-1])
    322 +        self.assertEqual(u'internal-server-error', exc.condition)
    323 +        self.assertEqual(1, len(self.flushLoggedErrors()))
     322+        self.assertEquals(u'internal-server-error', exc.condition)
     323+        self.assertEquals(1, len(self.flushLoggedErrors()))
    324324+
    325325+
     
    340340+        observer(self, element)
    341341+        self.assertTrue(element.handled)
    342 +        self.assertEqual(0, len(self.output))
    343 +        self.assertEqual(1, len(self.flushLoggedErrors()))
     342+        self.assertEquals(0, len(self.output))
     343+        self.assertEquals(1, len(self.flushLoggedErrors()))
    344344+
    345345+
  • c2s_server_factory.patch

    r72 r80  
    11# HG changeset patch
    22# Parent 49294b2cf829414b42141731b5130d91474c0443
     3# Parent  0a68c01ed5b5f429eed343df521bc706fe88afd1
    34Add factory for accepting client connections.
    45
     
    5253+        Make sure each stanza has a sender address.
    5354+        """
    54 +        if element.uri:
     55+        if element.uri != self.xmlstream.namespace:
    5556+            return
    5657+
     
    106107--- a/wokkel/generic.py
    107108+++ b/wokkel/generic.py
    108 @@ -628,3 +628,65 @@
     109@@ -480,3 +480,64 @@
    109110     standard full stop.
    110111     """
     
    135136+        Called when the stream has been initialized.
    136137+        """
    137 +        self.xmlstream.addObserver('/*[@xmlns="%s"]' %
    138 +                                       self.xmlstream.namespace,
    139 +                                   stripNamespace, priority=1)
    140138+        self.xmlstream.addObserver('/*', self.onStanza, priority=-1)
    141139+
     
    157155+
    158156+        if (element.name not in ('iq', 'message', 'presence') or
    159 +            element.uri is not None):
     157+            element.uri != self.xmlstream.namespace):
    160158+            return
    161159+
    162 +        if not element.getAttribute('to'):
     160+        stanza = Stanza.fromElement(element)
     161+
     162+        if not stanza.recipient:
    163163+            exc = error.StanzaError('service-unavailable')
    164 +            self.send(exc.toResponse(element))
     164+            self.send(exc.toResponse(stanza.element))
    165165+        else:
    166 +            self.xmlstream.avatar.send(element)
     166+            self.xmlstream.avatar.send(stanza.element)
    167167+
    168168+
     
    316316--- a/wokkel/test/test_generic.py
    317317+++ b/wokkel/test/test_generic.py
    318 @@ -681,3 +681,105 @@
     318@@ -728,3 +728,91 @@
    319319         name = u"example.com."
    320320         result = generic.prepareIDNName(name)
     
    351351+        self.protocol.connectionInitialized()
    352352+
    353 +        element = domish.Element((None, u'message'))
     353+        element = domish.Element((u'jabber:client', u'message'))
    354354+        element[u'to'] = u'other@example.org'
    355355+        self.stub.send(element)
     
    365365+        self.protocol.connectionInitialized()
    366366+
    367 +        element = domish.Element((None, u'message'))
     367+        element = domish.Element((u'jabber:client', u'message'))
    368368+        self.stub.send(element)
    369369+
    370370+        self.assertEqual(0, len(self.avatar.sent))
    371371+        self.assertEqual(1, len(self.stub.output))
    372 +
    373 +
    374 +    def test_onStanzaClientNamespace(self):
    375 +        """
    376 +        Stanzas with an explicit namespace are delivered.
    377 +        """
    378 +        self.protocol.connectionInitialized()
    379 +
    380 +        element = domish.Element(('jabber:client', u'message'))
    381 +        element[u'to'] = u'other@example.org'
    382 +        self.stub.send(element)
    383 +
    384 +        self.assertEqual(1, len(self.avatar.sent))
    385 +        self.assertEqual(0, len(self.stub.output))
    386372+
    387373+
  • c2s_stanza_handlers.patch

    r73 r82  
    11# HG changeset patch
    22# Parent 70ce9e97aa58780ac7f75a177fe8c0d2aaf1bfc6
     3# Parent  92b3f7089a61a8998999b67562917675732f8a4e
    34Add c2s protocol handlers for iq, message and presence stanzas.
    45
     
    4849 from wokkel.subprotocols import IQHandlerMixin
    4950 
    50 @@ -2031,3 +2031,418 @@
     51@@ -2031,3 +2031,411 @@
    5152         d = self.sessionManager.probePresence(user)
    5253         d.addCallback(cb)
     
    255256+    def __init__(self, *args, **kwargs):
    256257+        super(FakeUserSession, self).__init__(*args, **kwargs)
    257 +        self.probePresenceCalls = 0
    258258+        self.broadcastPresenceCalls = []
    259259+
    260260+
    261 +    def probePresence(self):
    262 +        self.probePresenceCalls += 1
    263 +
    264 +
    265 +    def broadcastPresence(self, presence, available):
    266 +        self.broadcastPresenceCalls.append((presence, available))
     261+    def broadcastPresence(self, presence):
     262+        self.broadcastPresenceCalls.append(presence)
    267263+
    268264+
     
    317313+
    318314+        self.assertTrue(self.protocol.availableReceived(stanza))
    319 +        self.assertEqual(1, self.session.probePresenceCalls)
    320315+        self.assertEqual(1, len(self.session.broadcastPresenceCalls))
    321 +        presence, available = self.session.broadcastPresenceCalls[-1]
     316+        presence = self.session.broadcastPresenceCalls[-1]
    322317+        self.assertIdentical(stanza, presence)
    323 +        self.assertTrue(available)
     318+        self.assertTrue(presence.available)
    324319+
    325320+
     
    345340+
    346341+        self.assertTrue(self.protocol.unavailableReceived(stanza))
    347 +        self.assertEqual(0, self.session.probePresenceCalls)
    348342+        self.assertEqual(1, len(self.session.broadcastPresenceCalls))
    349 +        presence, available = self.session.broadcastPresenceCalls[-1]
     343+        presence = self.session.broadcastPresenceCalls[-1]
    350344+        self.assertIdentical(stanza, presence)
    351 +        self.assertFalse(available)
     345+        self.assertFalse(presence.available)
    352346+
    353347+
     
    530524 
    531525     @asyncObserver
    532 @@ -1689,3 +1697,246 @@
     526@@ -1693,3 +1701,240 @@
    533527             presence = ProbePresence(recipient=entity,
    534528                                      sender=user.entity)
     
    720714+        else:
    721715+            session = self.xmlstream.avatar
    722 +            sendProbe = not session.presence
    723 +
    724 +            session.broadcastPresence(presence, available=True)
    725 +
    726 +            if sendProbe:
    727 +                session.probePresence()
    728 +
     716+            session.broadcastPresence(presence)
    729717+            return True
    730718+
     
    736724+        else:
    737725+            session = self.xmlstream.avatar
    738 +            session.broadcastPresence(presence, available=False)
     726+            session.broadcastPresence(presence)
    739727+            return True
    740728+
  • listening-authenticator-stream-features.patch

    r72 r79  
    11# HG changeset patch
    22# Parent 840b96390047670c5209195300f902689c18b12f
     3# Parent  146ff13d66e54c535445adf4a19a3ef07a0a6f57
    34Add FeatureListeningAuthenticator.
    45
     
    910--- a/wokkel/generic.py
    1011+++ b/wokkel/generic.py
    11 @@ -10,7 +10,7 @@
     12@@ -14,6 +14,7 @@
    1213 from zope.interface import implements
    1314 
    1415 from twisted.internet import defer, protocol
    15 -from twisted.python import reflect
    16 +from twisted.python import log, reflect
     16+from twisted.python import log
    1717 from twisted.python.deprecate import deprecated
    1818 from twisted.python.versions import Version
    19  from twisted.words.protocols.jabber import error, jid, xmlstream
    20 @@ -18,7 +18,7 @@
     19 from twisted.words.protocols.jabber import error, xmlstream
     20@@ -21,7 +22,7 @@
    2121 from twisted.words.xish import domish, utility
    2222 from twisted.words.xish.xmlstream import BootstrapMixin
     
    2424-from wokkel.iwokkel import IDisco
    2525+from wokkel.iwokkel import IDisco, IReceivingInitializer
     26 from wokkel.stanza import Stanza, ErrorStanza, Request
    2627 from wokkel.subprotocols import XMPPHandler
    2728 
    28  IQ_GET = '/iq[@type="get"]'
    29 @@ -27,6 +27,8 @@
     29@@ -31,6 +32,8 @@
    3030 NS_VERSION = 'jabber:iq:version'
    3131 VERSION = IQ_GET + '/query[@xmlns="' + NS_VERSION + '"]'
     
    3636     """
    3737     Parse serialized XML into a DOM structure.
    38 @@ -332,6 +334,290 @@
     38@@ -180,6 +183,290 @@
    3939 
    4040 
     
    414414 
    415415 NS_VERSION = 'jabber:iq:version'
    416 @@ -276,6 +281,334 @@
     416@@ -300,6 +305,334 @@
    417417 
    418418 
  • message-stanza.patch

    r73 r75  
    11# HG changeset patch
    2 # Parent a94e14d79311f8efde3bd001ce4b5c8bafbb8094
     2# Parent 5df04f703f9024cd3a73d51117df93e7f56fdd7a
    33Parse message stanzas into Message objects.
    44
     
    359359+
    360360+            self.onMessage(message.element)
    361 +            return True
     361+            return getattr(message, "handled", False)
  • series

    r73 r79  
     1py3-iwokkel.patch #+py3
     2py3-subprotocols.patch #+py3
     3py3-generic.patch #+py3
     4py3-dataforms.patch #+py3
     5py3-test-helpers.patch #+py3
     6py3-disco.patch #+py3
     7py3-ping.patch #+py3
     8py3-compat.patch #+py3
     9py3-shim.patch #+py3
     10py3-pubsub.patch #+py3
     11py3-xmppim.patch #+py3
     12py3-muc.patch #+py3
     13py3-component.patch #+py3
     14py3-server.patch #+py3
     15py3-examples.patch #+py3
     16minimum-Twisted.patch #+py3
     17
     18delay-keyerror.patch
     19
    120async-observer.patch
     21stanza-module.patch
     22response-tracking.patch
     23
    224message-stanza.patch
    325server-stream-manager.patch
     
    628listening-authenticator-stream-features.patch #+c2s
    729client_listen_authenticator.patch #+c2s
     30receiving_tls_initializer.patch
    831c2s_server_factory.patch #+c2s
    932
  • server-stream-manager.patch

    r74 r83  
    11# HG changeset patch
    2 # Parent 71082c22f73200a0b8b4b5c6e5d2773f9f68dd4d
     2# Parent 3f3fe954b1975c2d9115e0fa8177ae7b28a708a8
    33Generalize StreamManager and add ServerStreamManager.
    44
     
    5656--- a/wokkel/subprotocols.py
    5757+++ b/wokkel/subprotocols.py
    58 @@ -120,7 +120,7 @@
     58@@ -118,7 +118,7 @@
    5959 
    6060 
     
    6565     Business logic representing a managed XMPP connection.
    6666 
    67 @@ -131,43 +131,39 @@
     67@@ -129,43 +129,39 @@
    6868 
    6969     @ivar xmlstream: currently managed XML stream
     
    116116             from twisted.internet import reactor
    117117         self._reactor = reactor
    118 @@ -193,7 +189,7 @@
     118@@ -191,7 +187,7 @@
    119119             handler.connectionInitialized()
    120120 
     
    125125         Called when the transport connection has been established.
    126126 
    127 @@ -211,13 +207,17 @@
     127@@ -209,13 +205,17 @@
    128128             xs.rawDataInFn = logDataIn
    129129             xs.rawDataOutFn = logDataOut
     
    144144         Called when the stream has been initialized.
    145145 
    146 @@ -240,21 +240,8 @@
     146@@ -238,21 +238,8 @@
    147147             e.connectionInitialized()
    148148 
     
    167167         Called when the stream has been closed.
    168168 
    169 @@ -464,6 +451,60 @@
     169@@ -379,6 +366,60 @@
    170170 
    171171 
     
    298298--- a/wokkel/test/test_subprotocols.py
    299299+++ b/wokkel/test/test_subprotocols.py
    300 @@ -189,20 +189,7 @@
     300@@ -189,22 +189,7 @@
    301301 
    302302 
     
    315315-        self.xmlstream.transport = self.transport
    316316-
    317 -        self.request = IQGetStanza()
     317-        self.request = IQGetStanza(recipient=JID('other@example.org'),
     318-                                   sender=JID('user@example.org'))
     319-
    318320+class BaseStreamManagerTestsMixin(object):
    319321 
     
    588590         self.assertFailure(d, ConnectionDone)
    589591         self.assertFalse(self.clock.calls)
    590 @@ -778,6 +753,56 @@
     592@@ -778,6 +753,58 @@
    591593 
    592594 
     
    605607+        self.xmlstream.transport = self.transport
    606608+
    607 +        self.request = IQGetStanza()
     609+        self.request = IQGetStanza(recipient=JID('other@example.org'),
     610+                                   sender=JID('user@example.org'))
    608611+
    609612+
     
    638641+                                   self.streamManager.makeConnection)
    639642+
    640 +        self.request = IQGetStanza()
     643+        self.request = IQGetStanza(recipient=JID('other@example.org'),
     644+                                   sender=JID('user@example.org'))
    641645+
    642646+
  • session_manager.patch

    r73 r82  
    11# HG changeset patch
    2 # Parent 60135baa4e422ab203c780c9093c374481b17a7a
     2# Parent d800a4363f602f6ff344181f0d20b5809157b0b1
     3# Parent  55eb3f11240d719a97e32eabf3ce03fe346cb8bf
    34
    45diff --git a/wokkel/ewokkel.py b/wokkel/ewokkel.py
     
    4243--- a/wokkel/generic.py
    4344+++ b/wokkel/generic.py
    44 @@ -7,6 +7,8 @@
    45  Generic XMPP protocol helpers.
    46  """
     45@@ -11,6 +11,8 @@
     46            'DeferredXmlStreamFactory', 'prepareIDNName',
     47            'Stanza', 'Request', 'ErrorStanza']
    4748 
    4849+import copy
     
    5152 
    5253 from twisted.internet import defer, protocol
    53 @@ -66,6 +68,24 @@
    54      return rootElement
     54@@ -53,6 +55,24 @@
     55     return results and results[0] or None
    5556 
    5657 
     
    7677 class FallbackHandler(XMPPHandler):
    7778     """
    78 @@ -168,10 +188,23 @@
    79      """
    80      Abstract representation of a stanza.
    81  
    82 +    @ivar recipient: The receiving entity.
    83 +    @type recipient: L{jid.JID}
    84 +
    85      @ivar sender: The sending entity.
    86      @type sender: L{jid.JID}
    87 -    @ivar recipient: The receiving entity.
    88 -    @type recipient: L{jid.JID}
    89 +
    90 +    @ivar stanzaKind: One of C{'message'}, C{'presence'}, C{'iq'}.
    91 +    @type stanzaKind: L{unicode}.
    92 +
    93 +    @ivar stanzaID: The optional stanza identifier.
    94 +    @type stanzaID: L{unicode}.
    95 +
    96 +    @ivar stanzaType: The optional stanza type.
    97 +    @type stanzaType: L{unicode}.
    98 +
    99 +    @ivar element: The serialized XML of this stanza.
    100 +    @type element: L{domish.Element}.
    101      """
    102  
    103      recipient = None
    104 @@ -179,6 +212,8 @@
    105      stanzaKind = None
    106      stanzaID = None
    107      stanzaType = None
    108 +    element = None
    109 +
    110  
    111      def __init__(self, recipient=None, sender=None):
    112          self.recipient = recipient
    113 @@ -217,6 +252,7 @@
    114              self.sender = jid.internJID(element['from'])
    115          if element.hasAttribute('to'):
    116              self.recipient = jid.internJID(element['to'])
    117 +        self.stanzaKind = element.name
    118          self.stanzaType = element.getAttribute('type')
    119          self.stanzaID = element.getAttribute('id')
    120  
    121 @@ -242,6 +278,7 @@
    122  
    123      def toElement(self):
    124          element = domish.Element((None, self.stanzaKind))
    125 +        self.element = element
    126          if self.sender is not None:
    127              element['from'] = self.sender.full()
    128          if self.recipient is not None:
    12979diff --git a/wokkel/iwokkel.py b/wokkel/iwokkel.py
    13080--- a/wokkel/iwokkel.py
     
    297247+
    298248+
    299 +    def test_getRoster(self):
     249+    def test_getRosterReceived(self):
    300250+        """
    301251+        The returned roster is gotten from the session user.
     
    305255+
    306256+        request = xmppim.RosterRequest()
    307 +        d = self.service.getRoster(request)
     257+        d = self.service.getRosterReceived(request)
    308258+        d.addCallback(gotRoster)
    309259+        return d
    310260+
    311261+
    312 +    def test_getRosterInterested(self):
     262+    def test_getRosterReceivedInterested(self):
    313263+        """
    314264+        Requesting the roster marks the session as interested in roster pushes.
     
    318268+
    319269+        request = xmppim.RosterRequest()
    320 +        d = self.service.getRoster(request)
     270+        d = self.service.getRosterReceived(request)
    321271+        d.addCallback(gotRoster)
    322272+        return d
     
    724674+
    725675+
    726 +    def getRoster(self, request):
     676+    def getRosterReceived(self, request):
    727677+        """
    728678+        Return the roster of the user associated with this session.
     
    737687     """
    738688     A message stanza.
    739 @@ -1175,3 +1244,448 @@
     689@@ -1175,3 +1244,452 @@
    740690 
    741691             self.onMessage(message.element)
    742              return True
     692             return getattr(message, "handled", False)
    743693+
    744694+
     
    821771+
    822772+
    823 +    def probePresence(self):
    824 +        self.user.probePresence(self)
    825 +
    826 +
    827 +    def broadcastPresence(self, presence, available):
    828 +        if available:
     773+    def broadcastPresence(self, presence):
     774+        doProbe = presence.available and not self.presence
     775+
     776+        if presence.available:
    829777+            self.presence = presence
    830778+        else:
    831779+            self.presence = None
    832 +            # TODO: unset probeSent on user?
    833 +            # TODO: save last unavailable presence?
    834780+
    835781+        self.user.broadcastPresence(presence)
     782+
     783+        if doProbe:
     784+            self.user.probePresence(self)
    836785+
    837786+
     
    875824+
    876825+    def bindResource(self, session, resource):
     826+        if not self.sessions:
     827+            self.probeSent = False
     828+
    877829+        if resource is None:
    878830+            resource = randbytes.secureRandom(8).encode('hex')
     
    952904+    def deliverPresence(self, stanza):
    953905+        if not stanza.recipient.resource:
    954 +            # record
     906+            # TODO: record presence in self.contactPresences for future probes
    955907+
    956908+            for session in self.sessions.itervalues():
     
    983935+        Broadcast presence to all subscribed contacts and myself.
    984936+        """
     937+        # TODO: set probeSent to False when last session becomes unavailable
     938+        # TODO: save last unavailable presence?
    985939+        subscribers = yield self.roster.getSubscribers()
    986940+        self.realm.server.multicast(presence, subscribers)
Note: See TracChangeset for help on using the changeset viewer.