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
  • wokkel/compat.py

    diff -r 9c14d48c54b2 wokkel/compat.py
    a b  
    66from twisted.internet import protocol
    77from twisted.words.protocols.jabber import xmlstream
    88from twisted.words.xish import domish
    9 
    10 def toResponse(stanza, stanzaType=None):
    11     """
    12     Create a response stanza from another stanza.
    13 
    14     This takes the addressing and id attributes from a stanza to create a (new,
    15     empty) response stanza. The addressing attributes are swapped and the id
    16     copied. Optionally, the stanza type of the response can be specified.
    17 
    18     @param stanza: the original stanza
    19     @type stanza: L{domish.Element}
    20     @param stanzaType: optional response stanza type
    21     @type stanzaType: C{str}
    22     @return: the response stanza.
    23     @rtype: L{domish.Element}
    24     """
    25 
    26     toAddr = stanza.getAttribute('from')
    27     fromAddr = stanza.getAttribute('to')
    28     stanzaID = stanza.getAttribute('id')
    29 
    30     response = domish.Element((None, stanza.name))
    31     if toAddr:
    32         response['to'] = toAddr
    33     if fromAddr:
    34         response['from'] = fromAddr
    35     if stanzaID:
    36         response['id'] = stanzaID
    37     if stanzaType:
    38         response['type'] = stanzaType
    39 
    40     return response
    41 
    42 
    439
    4410class BootstrapMixin(object):
    4511    """
  • wokkel/subprotocols.py

    diff -r 9c14d48c54b2 wokkel/subprotocols.py
    a b  
    11# -*- test-case-name: wokkel.test.test_subprotocols -*-
    22#
    3 # Copyright (c) 2001-2007 Twisted Matrix Laboratories.
     3# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
    44# See LICENSE for details.
    55
    66"""
     
    1212from twisted.internet import defer
    1313from twisted.python import log
    1414from twisted.words.protocols.jabber import error, xmlstream
     15from twisted.words.protocols.jabber.xmlstream import toResponse
    1516from twisted.words.xish import xpath
    1617from twisted.words.xish.domish import IElement
    17 
    18 try:
    19     from twisted.words.protocols.jabber.xmlstream import toResponse
    20 except ImportError:
    21     from wokkel.compat import toResponse
    2218
    2319from wokkel.iwokkel import IXMPPHandler, IXMPPHandlerCollection
    2420
  • wokkel/test/test_compat.py

    diff -r 9c14d48c54b2 wokkel/test/test_compat.py
    a b  
    1 # Copyright (c) 2001-2007 Twisted Matrix Laboratories.
    2 # Copyright (c) 2008 Ralph Meijer
     1# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
     2# Copyright (c) 2008-2009 Ralph Meijer
    33# See LICENSE for details.
    44
    55"""
     
    1212from twisted.trial import unittest
    1313from twisted.words.xish import domish, utility
    1414from twisted.words.protocols.jabber import xmlstream
    15 from wokkel.compat import toResponse, BootstrapMixin, XmlStreamServerFactory
     15from wokkel.compat import BootstrapMixin, XmlStreamServerFactory
    1616
    1717class DummyProtocol(protocol.Protocol, utility.EventDispatcher):
    1818    """
     
    7777
    7878        dispatcher.dispatch(None, '//event/myevent')
    7979        self.assertFalse(called)
    80 
    81 
    82 
    83 class ToResponseTest(unittest.TestCase):
    84 
    85     def test_toResponse(self):
    86         """
    87         Test that a response stanza is generated with addressing swapped.
    88         """
    89         stanza = domish.Element(('jabber:client', 'iq'))
    90         stanza['type'] = 'get'
    91         stanza['to'] = 'user1@example.com'
    92         stanza['from'] = 'user2@example.com/resource'
    93         stanza['id'] = 'stanza1'
    94         response = toResponse(stanza, 'result')
    95         self.assertNotIdentical(stanza, response)
    96         self.assertEqual(response['from'], 'user1@example.com')
    97         self.assertEqual(response['to'], 'user2@example.com/resource')
    98         self.assertEqual(response['type'], 'result')
    99         self.assertEqual(response['id'], 'stanza1')
    100 
    101     def test_toResponseNoFrom(self):
    102         """
    103         Test that a response is generated from a stanza without a from address.
    104         """
    105         stanza = domish.Element(('jabber:client', 'iq'))
    106         stanza['type'] = 'get'
    107         stanza['to'] = 'user1@example.com'
    108         response = toResponse(stanza)
    109         self.assertEqual(response['from'], 'user1@example.com')
    110         self.failIf(response.hasAttribute('to'))
    111 
    112     def test_toResponseNoTo(self):
    113         """
    114         Test that a response is generated from a stanza without a to address.
    115         """
    116         stanza = domish.Element(('jabber:client', 'iq'))
    117         stanza['type'] = 'get'
    118         stanza['from'] = 'user2@example.com/resource'
    119         response = toResponse(stanza)
    120         self.failIf(response.hasAttribute('from'))
    121         self.assertEqual(response['to'], 'user2@example.com/resource')
    122 
    123     def test_toResponseNoAddressing(self):
    124         """
    125         Test that a response is generated from a stanza without any addressing.
    126         """
    127         stanza = domish.Element(('jabber:client', 'message'))
    128         stanza['type'] = 'chat'
    129         response = toResponse(stanza)
    130         self.failIf(response.hasAttribute('to'))
    131         self.failIf(response.hasAttribute('from'))
    132 
    133     def test_noID(self):
    134         """
    135         Test that a proper response is generated without id attribute.
    136         """
    137         stanza = domish.Element(('jabber:client', 'message'))
    138         response = toResponse(stanza)
    139         self.failIf(response.hasAttribute('id'))
    140 
    141 
    142     def test_noType(self):
    143         """
    144         Test that a proper response is generated without type attribute.
    145         """
    146         stanza = domish.Element(('jabber:client', 'message'))
    147         response = toResponse(stanza)
    148         self.failIf(response.hasAttribute('type'))
    14980
    15081
    15182
  • wokkel/test/test_disco.py

    diff -r 9c14d48c54b2 wokkel/test/test_disco.py
    a b  
    1010from twisted.internet import defer
    1111from twisted.trial import unittest
    1212from twisted.words.protocols.jabber.jid import JID
     13from twisted.words.protocols.jabber.xmlstream import toResponse
    1314from twisted.words.xish import domish
    1415
    1516from wokkel import data_form, disco
    1617from wokkel.generic import parseXml
    1718from wokkel.subprotocols import XMPPHandler
    1819from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub
    19 
    20 try:
    21     from twisted.words.protocols.jabber.xmlstream import toResponse
    22 except ImportError:
    23     from wokkel.compat import toResponse
    2420
    2521NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'
    2622NS_DISCO_ITEMS = 'http://jabber.org/protocol/disco#items'
  • wokkel/test/test_pubsub.py

    diff -r 9c14d48c54b2 wokkel/test/test_pubsub.py
    a b  
    1 # Copyright (c) 2003-2008 Ralph Meijer
     1# Copyright (c) 2003-2009 Ralph Meijer
    22# See LICENSE for details.
    33
    44"""
     
    1212from twisted.words.xish import domish
    1313from twisted.words.protocols.jabber import error
    1414from twisted.words.protocols.jabber.jid import JID
     15from twisted.words.protocols.jabber.xmlstream import toResponse
    1516
    1617from wokkel import data_form, iwokkel, pubsub, shim
    1718from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub
    18 
    19 try:
    20     from twisted.words.protocols.jabber.xmlstream import toResponse
    21 except ImportError:
    22     from wokkel.compat import toResponse
    2319
    2420NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
    2521NS_PUBSUB_CONFIG = 'http://jabber.org/protocol/pubsub#node_config'
Note: See TracBrowser for help on using the repository browser.