source: ralphm-patches/compat-pre-twisted-8.0.0.patch @ 5:231bc3e8b810

Last change on this file since 5:231bc3e8b810 was 5:231bc3e8b810, checked in by Ralph Meijer <ralphm@…>, 13 years ago

A gazillion changes.

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