source: ralphm-patches/compat-pre-twisted-8.0.0.patch @ 1:7fc86463b39f

Last change on this file since 1:7fc86463b39f was 1:7fc86463b39f, checked in by Ralph Meijer <ralphm@…>, 12 years ago

Add patches.

File size: 7.4 KB
RevLine 
[1]1diff -r 9c14d48c54b2 wokkel/compat.py
2--- a/wokkel/compat.py  Wed Feb 04 14:41:26 2009 +0100
3+++ b/wokkel/compat.py  Wed Feb 04 14:42:14 2009 +0100
4@@ -6,40 +6,6 @@
5 from twisted.internet import protocol
6 from twisted.words.protocols.jabber import xmlstream
7 from twisted.words.xish import domish
8-
9-def toResponse(stanza, stanzaType=None):
10-    """
11-    Create a response stanza from another stanza.
12-
13-    This takes the addressing and id attributes from a stanza to create a (new,
14-    empty) response stanza. The addressing attributes are swapped and the id
15-    copied. Optionally, the stanza type of the response can be specified.
16-
17-    @param stanza: the original stanza
18-    @type stanza: L{domish.Element}
19-    @param stanzaType: optional response stanza type
20-    @type stanzaType: C{str}
21-    @return: the response stanza.
22-    @rtype: L{domish.Element}
23-    """
24-
25-    toAddr = stanza.getAttribute('from')
26-    fromAddr = stanza.getAttribute('to')
27-    stanzaID = stanza.getAttribute('id')
28-
29-    response = domish.Element((None, stanza.name))
30-    if toAddr:
31-        response['to'] = toAddr
32-    if fromAddr:
33-        response['from'] = fromAddr
34-    if stanzaID:
35-        response['id'] = stanzaID
36-    if stanzaType:
37-        response['type'] = stanzaType
38-
39-    return response
40-
41-
42 
43 class BootstrapMixin(object):
44     """
45diff -r 9c14d48c54b2 wokkel/subprotocols.py
46--- a/wokkel/subprotocols.py    Wed Feb 04 14:41:26 2009 +0100
47+++ b/wokkel/subprotocols.py    Wed Feb 04 14:42:14 2009 +0100
48@@ -1,6 +1,6 @@
49 # -*- test-case-name: wokkel.test.test_subprotocols -*-
50 #
51-# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
52+# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
53 # See LICENSE for details.
54 
55 """
56@@ -12,13 +12,9 @@
57 from twisted.internet import defer
58 from twisted.python import log
59 from twisted.words.protocols.jabber import error, xmlstream
60+from twisted.words.protocols.jabber.xmlstream import toResponse
61 from twisted.words.xish import xpath
62 from twisted.words.xish.domish import IElement
63-
64-try:
65-    from twisted.words.protocols.jabber.xmlstream import toResponse
66-except ImportError:
67-    from wokkel.compat import toResponse
68 
69 from wokkel.iwokkel import IXMPPHandler, IXMPPHandlerCollection
70 
71diff -r 9c14d48c54b2 wokkel/test/test_compat.py
72--- a/wokkel/test/test_compat.py        Wed Feb 04 14:41:26 2009 +0100
73+++ b/wokkel/test/test_compat.py        Wed Feb 04 14:42:14 2009 +0100
74@@ -1,5 +1,5 @@
75-# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
76-# Copyright (c) 2008 Ralph Meijer
77+# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
78+# Copyright (c) 2008-2009 Ralph Meijer
79 # See LICENSE for details.
80 
81 """
82@@ -12,7 +12,7 @@
83 from twisted.trial import unittest
84 from twisted.words.xish import domish, utility
85 from twisted.words.protocols.jabber import xmlstream
86-from wokkel.compat import toResponse, BootstrapMixin, XmlStreamServerFactory
87+from wokkel.compat import BootstrapMixin, XmlStreamServerFactory
88 
89 class DummyProtocol(protocol.Protocol, utility.EventDispatcher):
90     """
91@@ -77,75 +77,6 @@
92 
93         dispatcher.dispatch(None, '//event/myevent')
94         self.assertFalse(called)
95-
96-
97-
98-class ToResponseTest(unittest.TestCase):
99-
100-    def test_toResponse(self):
101-        """
102-        Test that a response stanza is generated with addressing swapped.
103-        """
104-        stanza = domish.Element(('jabber:client', 'iq'))
105-        stanza['type'] = 'get'
106-        stanza['to'] = 'user1@example.com'
107-        stanza['from'] = 'user2@example.com/resource'
108-        stanza['id'] = 'stanza1'
109-        response = toResponse(stanza, 'result')
110-        self.assertNotIdentical(stanza, response)
111-        self.assertEqual(response['from'], 'user1@example.com')
112-        self.assertEqual(response['to'], 'user2@example.com/resource')
113-        self.assertEqual(response['type'], 'result')
114-        self.assertEqual(response['id'], 'stanza1')
115-
116-    def test_toResponseNoFrom(self):
117-        """
118-        Test that a response is generated from a stanza without a from address.
119-        """
120-        stanza = domish.Element(('jabber:client', 'iq'))
121-        stanza['type'] = 'get'
122-        stanza['to'] = 'user1@example.com'
123-        response = toResponse(stanza)
124-        self.assertEqual(response['from'], 'user1@example.com')
125-        self.failIf(response.hasAttribute('to'))
126-
127-    def test_toResponseNoTo(self):
128-        """
129-        Test that a response is generated from a stanza without a to address.
130-        """
131-        stanza = domish.Element(('jabber:client', 'iq'))
132-        stanza['type'] = 'get'
133-        stanza['from'] = 'user2@example.com/resource'
134-        response = toResponse(stanza)
135-        self.failIf(response.hasAttribute('from'))
136-        self.assertEqual(response['to'], 'user2@example.com/resource')
137-
138-    def test_toResponseNoAddressing(self):
139-        """
140-        Test that a response is generated from a stanza without any addressing.
141-        """
142-        stanza = domish.Element(('jabber:client', 'message'))
143-        stanza['type'] = 'chat'
144-        response = toResponse(stanza)
145-        self.failIf(response.hasAttribute('to'))
146-        self.failIf(response.hasAttribute('from'))
147-
148-    def test_noID(self):
149-        """
150-        Test that a proper response is generated without id attribute.
151-        """
152-        stanza = domish.Element(('jabber:client', 'message'))
153-        response = toResponse(stanza)
154-        self.failIf(response.hasAttribute('id'))
155-
156-
157-    def test_noType(self):
158-        """
159-        Test that a proper response is generated without type attribute.
160-        """
161-        stanza = domish.Element(('jabber:client', 'message'))
162-        response = toResponse(stanza)
163-        self.failIf(response.hasAttribute('type'))
164 
165 
166 
167diff -r 9c14d48c54b2 wokkel/test/test_disco.py
168--- a/wokkel/test/test_disco.py Wed Feb 04 14:41:26 2009 +0100
169+++ b/wokkel/test/test_disco.py Wed Feb 04 14:42:14 2009 +0100
170@@ -10,17 +10,13 @@
171 from twisted.internet import defer
172 from twisted.trial import unittest
173 from twisted.words.protocols.jabber.jid import JID
174+from twisted.words.protocols.jabber.xmlstream import toResponse
175 from twisted.words.xish import domish
176 
177 from wokkel import data_form, disco
178 from wokkel.generic import parseXml
179 from wokkel.subprotocols import XMPPHandler
180 from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub
181-
182-try:
183-    from twisted.words.protocols.jabber.xmlstream import toResponse
184-except ImportError:
185-    from wokkel.compat import toResponse
186 
187 NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'
188 NS_DISCO_ITEMS = 'http://jabber.org/protocol/disco#items'
189diff -r 9c14d48c54b2 wokkel/test/test_pubsub.py
190--- a/wokkel/test/test_pubsub.py        Wed Feb 04 14:41:26 2009 +0100
191+++ b/wokkel/test/test_pubsub.py        Wed Feb 04 14:42:14 2009 +0100
192@@ -1,4 +1,4 @@
193-# Copyright (c) 2003-2008 Ralph Meijer
194+# Copyright (c) 2003-2009 Ralph Meijer
195 # See LICENSE for details.
196 
197 """
198@@ -12,14 +12,10 @@
199 from twisted.words.xish import domish
200 from twisted.words.protocols.jabber import error
201 from twisted.words.protocols.jabber.jid import JID
202+from twisted.words.protocols.jabber.xmlstream import toResponse
203 
204 from wokkel import data_form, iwokkel, pubsub, shim
205 from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub
206-
207-try:
208-    from twisted.words.protocols.jabber.xmlstream import toResponse
209-except ImportError:
210-    from wokkel.compat import toResponse
211 
212 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
213 NS_PUBSUB_CONFIG = 'http://jabber.org/protocol/pubsub#node_config'
Note: See TracBrowser for help on using the repository browser.