Changeset 53:fd2b3f70b221 in ralphm-patches


Ignore:
Timestamp:
Aug 3, 2011, 9:48:58 AM (9 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Small cleanups for request handling.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • disco-addressing.patch

    r47 r53  
    11# HG changeset patch
    2 # Parent ec507e96d825c087430df236727e6f6161d8af12
     2# Parent 038fd78ebd5cdc8d25d00e4bc33a0c263eed277a
    33Reimplement _DiscoRequest as generic.Request.
    44
     
    66Fixes: #73.
    77
    8 diff -r ec507e96d825 wokkel/disco.py
    9 --- a/wokkel/disco.py   Fri Mar 04 09:49:28 2011 +0100
    10 +++ b/wokkel/disco.py   Mon Mar 07 19:08:18 2011 +0100
    11 @@ -14,7 +14,7 @@
     8diff -r 038fd78ebd5c wokkel/disco.py
     9--- a/wokkel/disco.py   Wed Aug 03 09:14:08 2011 +0200
     10+++ b/wokkel/disco.py   Wed Aug 03 09:26:08 2011 +0200
     11@@ -14,8 +14,7 @@
    1212 from twisted.words.protocols.jabber import error, jid
    1313 from twisted.words.xish import domish
    1414 
    1515-from wokkel import data_form
     16-from wokkel.compat import IQ
    1617+from wokkel import data_form, generic
    17  from wokkel.compat import IQ
    1818 from wokkel.iwokkel import IDisco
    1919 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
    20 @@ -346,26 +346,56 @@
     20 
     21@@ -346,26 +345,57 @@
    2122 
    2223 
     
    6061+    def __init__(self, verb=None, nodeIdentifier='',
    6162+                       recipient=None, sender=None):
    62 +        generic.Request.__init__(self, 'get', recipient, sender)
     63+        generic.Request.__init__(self, recipient=recipient, sender=sender,
     64+                                       stanzaType='get')
    6365+        self.verb = verb
    6466+        self.nodeIdentifier = nodeIdentifier
     
    177179         return d
    178180 
    179 diff -r ec507e96d825 wokkel/generic.py
    180 --- a/wokkel/generic.py Fri Mar 04 09:49:28 2011 +0100
    181 +++ b/wokkel/generic.py Mon Mar 07 19:08:18 2011 +0100
     181diff -r 038fd78ebd5c wokkel/generic.py
     182--- a/wokkel/generic.py Wed Aug 03 09:14:08 2011 +0200
     183+++ b/wokkel/generic.py Wed Aug 03 09:26:08 2011 +0200
    182184@@ -20,7 +20,6 @@
    183185 except ImportError:
     
    205207     stanzaID = None
    206208     stanzaType = None
    207 diff -r ec507e96d825 wokkel/test/test_disco.py
    208 --- a/wokkel/test/test_disco.py Fri Mar 04 09:49:28 2011 +0100
    209 +++ b/wokkel/test/test_disco.py Mon Mar 07 19:08:18 2011 +0100
     209diff -r 038fd78ebd5c wokkel/test/test_disco.py
     210--- a/wokkel/test/test_disco.py Wed Aug 03 09:14:08 2011 +0200
     211+++ b/wokkel/test/test_disco.py Wed Aug 03 09:26:08 2011 +0200
    210212@@ -477,9 +477,14 @@
    211213         Set up stub and protocol for testing.
  • request-stanza.patch

    r47 r53  
    11# HG changeset patch
    2 # Parent cddd993198e15f928c472d299e3351b8802e3608
     2# Parent 02050b16f4310d9875ae26fbe70ec31415a5d829
    33Add base class for IQ get/set request stanzas: Request.
    44
    5 diff -r cddd993198e1 wokkel/generic.py
    6 --- a/wokkel/generic.py Fri Mar 04 09:48:19 2011 +0100
    7 +++ b/wokkel/generic.py Fri Mar 04 09:49:28 2011 +0100
    8 @@ -236,6 +236,27 @@
     5diff -r 02050b16f431 wokkel/generic.py
     6--- a/wokkel/generic.py Wed Aug 03 09:00:34 2011 +0200
     7+++ b/wokkel/generic.py Wed Aug 03 09:14:08 2011 +0200
     8@@ -236,6 +236,34 @@
    99         self.exception = error.exceptionFromStanza(element)
    1010 
    1111 
    1212+class Request(Stanza):
     13+    """
     14+    IQ request stanza.
     15+
     16+    This is a base class for IQ get or set stanzas, to be used with
     17+    L{wokkel.subprotocols.StreamManager.request}.
     18+    """
     19+
    1320+    stanzaKind = 'iq'
    1421+    stanzaType = 'get'
    1522+    timeout = None
    1623+
    17 +    def __init__(self, stanzaType='get', recipient=None, sender=None):
     24+    def __init__(self, recipient=None, sender=None, stanzaType='get'):
    1825+        Stanza.__init__(self, recipient=recipient, sender=sender)
    1926+        self.stanzaType = stanzaType
     
    3441     protocol = xmlstream.XmlStream
    3542 
    36 diff -r cddd993198e1 wokkel/test/test_generic.py
    37 --- a/wokkel/test/test_generic.py       Fri Mar 04 09:48:19 2011 +0100
    38 +++ b/wokkel/test/test_generic.py       Fri Mar 04 09:49:28 2011 +0100
     43diff -r 02050b16f431 wokkel/test/test_generic.py
     44--- a/wokkel/test/test_generic.py       Wed Aug 03 09:00:34 2011 +0200
     45+++ b/wokkel/test/test_generic.py       Wed Aug 03 09:14:08 2011 +0200
    3946@@ -7,6 +7,7 @@
    4047 
  • request-tracking.patch

    r47 r53  
    11# HG changeset patch
    2 # Parent 60dcf9e2441bb510f1da17e6bc4401ef7b6db0e9
     2# Parent 6f36a7f92973d3843a42b4c80791715e694b66a3
    33Add iq request (set/get) tracking for StreamManager.
    44
     
    2020    from the moment request is sent over the wire.
    2121
    22 diff -r 60dcf9e2441b wokkel/subprotocols.py
    23 --- a/wokkel/subprotocols.py    Mon Feb 28 21:04:37 2011 +0100
    24 +++ b/wokkel/subprotocols.py    Fri Mar 04 09:45:24 2011 +0100
     22diff -r 6f36a7f92973 wokkel/subprotocols.py
     23--- a/wokkel/subprotocols.py    Thu Jul 28 20:14:02 2011 +0200
     24+++ b/wokkel/subprotocols.py    Wed Aug 03 09:45:01 2011 +0200
    2525@@ -156,11 +156,23 @@
    2626     @type _initialized: C{bool}
     
    7373         for p in self._packetQueue:
    7474             xs.send(p)
    75 @@ -268,6 +291,34 @@
     75@@ -268,6 +291,31 @@
    7676         for e in list(self):
    7777             e.connectionLost(reason)
     
    9090+        Handle iq response by firing associated deferred.
    9191+        """
    92 +        if getattr(iq, 'handled', False):
    93 +            return
    94 +
    9592+        try:
    9693+            d = self._iqDeferreds[iq["id"]]
     
    108105     def send(self, obj):
    109106         """
    110 @@ -285,6 +336,68 @@
     107@@ -285,6 +333,68 @@
    111108             self._packetQueue.append(obj)
    112109 
     
    141138+        if (request.stanzaKind != 'iq' or
    142139+            request.stanzaType not in ('get', 'set')):
    143 +            return defer.fail(Exception("Not a request"))
     140+            return defer.fail(ValueError("Not a request"))
    144141+
    145142+        element = request.toElement()
     
    154151+        self._iqDeferreds[element['id']] = d
    155152+
    156 +        timeout = request.timeout or self.timeout
     153+        timeout = getattr(request, 'timeout', self.timeout)
    157154+
    158155+        if timeout is not None:
     
    177174 class IQHandlerMixin(object):
    178175     """
    179 diff -r 60dcf9e2441b wokkel/test/test_subprotocols.py
    180 --- a/wokkel/test/test_subprotocols.py  Mon Feb 28 21:04:37 2011 +0100
    181 +++ b/wokkel/test/test_subprotocols.py  Fri Mar 04 09:45:24 2011 +0100
     176diff -r 6f36a7f92973 wokkel/test/test_subprotocols.py
     177--- a/wokkel/test/test_subprotocols.py  Thu Jul 28 20:14:02 2011 +0200
     178+++ b/wokkel/test/test_subprotocols.py  Wed Aug 03 09:45:01 2011 +0200
    182179@@ -9,12 +9,13 @@
    183180 
     
    196193 class DummyFactory(object):
    197194     """
    198 @@ -164,20 +165,48 @@
     195@@ -164,20 +165,46 @@
    199196 
    200197 
    201198 
    202199+class IQGetStanza(generic.Stanza):
    203 +    timeout = None
    204 +
    205200+    stanzaKind = 'iq'
    206201+    stanzaType = 'get'
     
    248243         self.assertEquals([], sm.handlers)
    249244         self.assertEquals(sm._connected,
    250 @@ -407,6 +436,7 @@
     245@@ -407,6 +434,7 @@
    251246         self.assertEquals(0, handler.nestedHandler.doneLost)
    252247 
     
    256251         """
    257252         Test removal of protocol handler.
    258 @@ -418,6 +448,7 @@
     253@@ -418,6 +446,7 @@
    259254         self.assertNotIn(handler, sm)
    260255         self.assertIdentical(None, handler.parent)
     
    264259         """
    265260         Test send when the stream has been initialized.
    266 @@ -509,6 +540,194 @@
     261@@ -509,6 +538,228 @@
    267262         self.assertEquals("<presence/>", sm._packetQueue[0])
    268263 
     
    449444+        d = self.streamManager.request(self.request)
    450445+
    451 +        xs = self.xmlstream
    452446+        self.xmlstream.connectionLost(failure.Failure(ConnectionDone()))
    453447+        self.assertFailure(d, ConnectionDone)
     
    456450+
    457451+
     452+    def test_requestNotIQ(self):
     453+        """
     454+        The request stanza must be an iq.
     455+        """
     456+        stanza = generic.Stanza()
     457+        stanza.stanzaKind = 'message'
     458+
     459+        d = self.streamManager.request(stanza)
     460+        self.assertFailure(d, ValueError)
     461+
     462+
     463+    def test_requestNotResult(self):
     464+        """
     465+        The request stanza cannot be of type 'result'.
     466+        """
     467+        stanza = generic.Stanza()
     468+        stanza.stanzaKind = 'iq'
     469+        stanza.stanzaType = 'result'
     470+
     471+        d = self.streamManager.request(stanza)
     472+        self.assertFailure(d, ValueError)
     473+
     474+
     475+    def test_requestNotError(self):
     476+        """
     477+        The request stanza cannot be of type 'error'.
     478+        """
     479+        stanza = generic.Stanza()
     480+        stanza.stanzaKind = 'iq'
     481+        stanza.stanzaType = 'error'
     482+
     483+        d = self.streamManager.request(stanza)
     484+        self.assertFailure(d, ValueError)
     485+
     486+
    458487 
    459488 class DummyIQHandler(subprotocols.IQHandlerMixin):
  • request-xmpphandler.patch

    r47 r53  
    11# HG changeset patch
    2 # Parent b05489ad4987a5e6263513c26048be801f7ce42b
     2# Parent 4d60ea3a5ab59d48e5080c913f6aeea9af55fccb
    33Add request method to XMPPHandler, passing up to its StreamManager.
    44
    5 diff -r b05489ad4987 wokkel/subprotocols.py
    6 --- a/wokkel/subprotocols.py    Fri Mar 04 09:45:25 2011 +0100
    7 +++ b/wokkel/subprotocols.py    Fri Mar 04 09:48:19 2011 +0100
     5diff -r 4d60ea3a5ab5 wokkel/subprotocols.py
     6--- a/wokkel/subprotocols.py    Wed Aug 03 09:45:01 2011 +0200
     7+++ b/wokkel/subprotocols.py    Wed Aug 03 09:46:32 2011 +0200
    88@@ -94,6 +94,18 @@
    99         self.parent.send(obj)
     
    2525 class XMPPHandlerCollection(object):
    2626     """
    27 diff -r b05489ad4987 wokkel/test/test_subprotocols.py
    28 --- a/wokkel/test/test_subprotocols.py  Fri Mar 04 09:45:25 2011 +0100
    29 +++ b/wokkel/test/test_subprotocols.py  Fri Mar 04 09:48:19 2011 +0100
     27diff -r 4d60ea3a5ab5 wokkel/test/test_subprotocols.py
     28--- a/wokkel/test/test_subprotocols.py  Wed Aug 03 09:45:01 2011 +0200
     29+++ b/wokkel/test/test_subprotocols.py  Wed Aug 03 09:46:32 2011 +0200
    3030@@ -71,6 +71,15 @@
    3131 
     
    5858+            def request(self, request):
    5959+                self.requests.append(request)
    60 +                d = defer.succeed(None)
     60+                return defer.succeed(None)
    6161+
    6262+        handler = subprotocols.XMPPHandler()
     
    7272 class XMPPHandlerCollectionTest(unittest.TestCase):
    7373     """
    74 @@ -165,15 +195,6 @@
     74@@ -165,13 +195,6 @@
    7575 
    7676 
    7777 
    7878-class IQGetStanza(generic.Stanza):
    79 -    timeout = None
    80 -
    8179-    stanzaKind = 'iq'
    8280-    stanzaType = 'get'
Note: See TracChangeset for help on using the changeset viewer.