source: ralphm-patches/deprecate_xmpphandler.patch @ 47:f6d222b68f1c

Last change on this file since 47:f6d222b68f1c was 47:f6d222b68f1c, checked in by Ralph Meijer <ralphm@…>, 9 years ago

Many new patches, upstreamed affiliations and worked on pubsub item.
Upstreamed pubsub_manage_affiliations

File size: 14.7 KB
  • wokkel/disco.py

    # HG changeset patch
    # Parent ebdb7afc619efdbb2a6ec82470a7e635634efbad
    
    diff -r ebdb7afc619e wokkel/disco.py
    a b  
    1212
    1313from twisted.internet import defer
    1414from twisted.words.protocols.jabber import error, jid
     15from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    1516from twisted.words.xish import domish
    1617
    1718from wokkel import data_form
    1819from wokkel.compat import IQ
    1920from wokkel.iwokkel import IDisco
    20 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
     21from wokkel.subprotocols import IQHandlerMixin
    2122
    2223NS_DISCO = 'http://jabber.org/protocol/disco'
    2324NS_DISCO_INFO = NS_DISCO + '#info'
  • wokkel/generic.py

    diff -r ebdb7afc619e wokkel/generic.py
    a b  
    2222
    2323from wokkel import disco
    2424from wokkel.iwokkel import IDisco
    25 from wokkel.subprotocols import XMPPHandler
    2625
    2726IQ_GET = '/iq[@type="get"]'
    2827IQ_SET = '/iq[@type="set"]'
     
    6867
    6968
    7069
    71 class FallbackHandler(XMPPHandler):
     70class FallbackHandler(xmlstream.XMPPHandler):
    7271    """
    7372    XMPP subprotocol handler that catches unhandled iq requests.
    7473
     
    8988
    9089
    9190
    92 class VersionHandler(XMPPHandler):
     91class VersionHandler(xmlstream.XMPPHandler):
    9392    """
    9493    XMPP subprotocol handler for XMPP Software Version.
    9594
  • wokkel/iwokkel.py

    diff -r ebdb7afc619e wokkel/iwokkel.py
    a b  
    55Wokkel interfaces.
    66"""
    77
    8 from zope.interface import Attribute, Interface
    9 
    10 class IXMPPHandler(Interface):
    11     """
    12     Interface for XMPP protocol handlers.
    13 
    14     Objects that provide this interface can be added to a stream manager to
    15     handle of (part of) an XMPP extension protocol.
    16     """
    17 
    18     parent = Attribute("""XML stream manager for this handler""")
    19     xmlstream = Attribute("""The managed XML stream""")
    20 
    21     def setHandlerParent(parent):
    22         """
    23         Set the parent of the handler.
    24 
    25         @type parent: L{IXMPPHandlerCollection}
    26         """
    27 
    28 
    29     def disownHandlerParent(parent):
    30         """
    31         Remove the parent of the handler.
    32 
    33         @type parent: L{IXMPPHandlerCollection}
    34         """
    35 
    36 
    37     def makeConnection(xs):
    38         """
    39         A connection over the underlying transport of the XML stream has been
    40         established.
    41 
    42         At this point, no traffic has been exchanged over the XML stream
    43         given in C{xs}.
    44 
    45         This should setup L{xmlstream} and call L{connectionMade}.
    46 
    47         @type xs: L{XmlStream<twisted.words.protocols.jabber.XmlStream>}
    48         """
    49 
    50 
    51     def connectionMade():
    52         """
    53         Called after a connection has been established.
    54 
    55         This method can be used to change properties of the XML Stream, its
    56         authenticator or the stream manager prior to stream initialization
    57         (including authentication).
    58         """
    59 
    60 
    61     def connectionInitialized():
    62         """
    63         The XML stream has been initialized.
    64 
    65         At this point, authentication was successful, and XML stanzas can be
    66         exchanged over the XML stream L{xmlstream}. This method can be
    67         used to setup observers for incoming stanzas.
    68         """
    69 
    70 
    71     def connectionLost(reason):
    72         """
    73         The XML stream has been closed.
    74 
    75         Subsequent use of L{parent.send} will result in data being queued
    76         until a new connection has been established.
    77 
    78         @type reason: L{twisted.python.failure.Failure}
    79         """
    80 
    81 
    82 
    83 class IXMPPHandlerCollection(Interface):
    84     """
    85     Collection of handlers.
    86 
    87     Contain several handlers and manage their connection.
    88     """
    89 
    90     def __iter__():
    91         """
    92         Get an iterator over all child handlers.
    93         """
    94 
    95 
    96     def addHandler(handler):
    97         """
    98         Add a child handler.
    99 
    100         @type handler: L{IXMPPHandler}
    101         """
    102 
    103 
    104     def removeHandler(handler):
    105         """
    106         Remove a child handler.
    107 
    108         @type handler: L{IXMPPHandler}
    109         """
    110 
    111 
     8from zope.interface import Interface
    1129
    11310class IDisco(Interface):
    11411    """
  • wokkel/ping.py

    diff -r ebdb7afc619e wokkel/ping.py
    a b  
    1414
    1515from twisted.words.protocols.jabber.error import StanzaError
    1616from twisted.words.protocols.jabber.xmlstream import IQ, toResponse
    17 
    18 try:
    19     from twisted.words.protocols.xmlstream import XMPPHandler
    20 except ImportError:
    21     from wokkel.subprotocols import XMPPHandler
     17from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    2218
    2319from wokkel import disco, iwokkel
    2420
  • wokkel/pubsub.py

    diff -r ebdb7afc619e wokkel/pubsub.py
    a b  
    1515from twisted.internet import defer
    1616from twisted.python import log
    1717from twisted.words.protocols.jabber import jid, error
     18from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    1819from twisted.words.xish import domish
    1920
    2021from wokkel import disco, data_form, generic, shim
    2122from wokkel.compat import IQ
    22 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
     23from wokkel.subprotocols import IQHandlerMixin
    2324from wokkel.iwokkel import IPubSubClient, IPubSubService, IPubSubResource
    2425
    2526# Iq get and set XPath queries
  • wokkel/subprotocols.py

    diff -r ebdb7afc619e wokkel/subprotocols.py
    a b  
    77XMPP subprotocol support.
    88"""
    99
    10 from zope.interface import implements
    11 
    1210from twisted.internet import defer
    13 from twisted.python import log
     11from twisted.python import deprecate, log, versions
    1412from twisted.words.protocols.jabber import error, xmlstream
    1513from twisted.words.protocols.jabber.xmlstream import toResponse
     14from twisted.words.protocols.jabber.xmlstream import XMPPHandler
     15from twisted.words.protocols.jabber.xmlstream import XMPPHandlerCollection
    1616from twisted.words.xish import xpath
    1717from twisted.words.xish.domish import IElement
    1818
    19 from wokkel.iwokkel import IXMPPHandler, IXMPPHandlerCollection
     19_deprecatedVersion = versions.Version("wokkel", 0, 7, 0)
    2020
    21 class XMPPHandler(object):
    22     """
    23     XMPP protocol handler.
     21deprecate.deprecatedModuleAttribute(
     22        _deprecatedVersion,
     23        "use twisted.words.protocols.jabber.xmlstream.XMPPHandler instead.",
     24        __name__,
     25        'XMPPHandler')
    2426
    25     Classes derived from this class implement (part of) one or more XMPP
    26     extension protocols, and are referred to as a subprotocol implementation.
    27     """
    28 
    29     implements(IXMPPHandler)
    30 
    31     def __init__(self):
    32         self.parent = None
    33         self.xmlstream = None
    34 
    35 
    36     def setHandlerParent(self, parent):
    37         self.parent = parent
    38         self.parent.addHandler(self)
    39 
    40 
    41     def disownHandlerParent(self, parent):
    42         self.parent.removeHandler(self)
    43         self.parent = None
    44 
    45 
    46     def makeConnection(self, xs):
    47         self.xmlstream = xs
    48         self.connectionMade()
    49 
    50 
    51     def connectionMade(self):
    52         """
    53         Called after a connection has been established.
    54 
    55         Can be overridden to perform work before stream initialization.
    56         """
    57 
    58 
    59     def connectionInitialized(self):
    60         """
    61         The XML stream has been initialized.
    62 
    63         Can be overridden to perform work after stream initialization, e.g. to
    64         set up observers and start exchanging XML stanzas.
    65         """
    66 
    67 
    68     def connectionLost(self, reason):
    69         """
    70         The XML stream has been closed.
    71 
    72         This method can be extended to inspect the C{reason} argument and
    73         act on it.
    74         """
    75         self.xmlstream = None
    76 
    77 
    78     def send(self, obj):
    79         """
    80         Send data over the managed XML stream.
    81 
    82         @note: The stream manager maintains a queue for data sent using this
    83                method when there is no current initialized XML stream. This
    84                data is then sent as soon as a new stream has been established
    85                and initialized. Subsequently, L{connectionInitialized} will be
    86                called again. If this queueing is not desired, use C{send} on
    87                C{self.xmlstream}.
    88 
    89         @param obj: data to be sent over the XML stream. This is usually an
    90                     object providing L{domish.IElement}, or serialized XML. See
    91                     L{xmlstream.XmlStream} for details.
    92         """
    93         self.parent.send(obj)
    94 
    95 
    96 
    97 class XMPPHandlerCollection(object):
    98     """
    99     Collection of XMPP subprotocol handlers.
    100 
    101     This allows for grouping of subprotocol handlers, but is not an
    102     L{XMPPHandler} itself, so this is not recursive.
    103 
    104     @ivar handlers: List of protocol handlers.
    105     @type handlers: L{list} of objects providing
    106                       L{IXMPPHandler}
    107     """
    108 
    109     implements(IXMPPHandlerCollection)
    110 
    111     def __init__(self):
    112         self.handlers = []
    113 
    114 
    115     def __iter__(self):
    116         """
    117         Act as a container for handlers.
    118         """
    119         return iter(self.handlers)
    120 
    121 
    122     def addHandler(self, handler):
    123         """
    124         Add protocol handler.
    125 
    126         Protocol handlers are expected to provide L{IXMPPHandler}.
    127         """
    128         self.handlers.append(handler)
    129 
    130 
    131     def removeHandler(self, handler):
    132         """
    133         Remove protocol handler.
    134         """
    135         self.handlers.remove(handler)
    136 
    137 
     27deprecate.deprecatedModuleAttribute(
     28        _deprecatedVersion,
     29        "use twisted.words.protocols.jabber.xmlstream.XMPPHandlerCollection "
     30            "instead.",
     31        __name__,
     32        'XMPPHandlerCollection')
    13833
    13934class StreamManager(XMPPHandlerCollection):
    14035    """
  • wokkel/test/test_disco.py

    diff -r ebdb7afc619e wokkel/test/test_disco.py
    a b  
    1111from twisted.trial import unittest
    1212from twisted.words.protocols.jabber.error import StanzaError
    1313from twisted.words.protocols.jabber.jid import JID
    14 from twisted.words.protocols.jabber.xmlstream import toResponse
     14from twisted.words.protocols.jabber.xmlstream import XMPPHandler, toResponse
    1515from twisted.words.xish import domish, utility
    1616
    1717from wokkel import data_form, disco
    1818from wokkel.generic import parseXml
    19 from wokkel.subprotocols import XMPPHandler
    2019from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub
    2120
    2221NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'
  • wokkel/test/test_subprotocols.py

    diff -r ebdb7afc619e wokkel/test/test_subprotocols.py
    a b  
    55Tests for L{wokkel.subprotocols}
    66"""
    77
    8 from zope.interface.verify import verifyObject
    9 
    108from twisted.trial import unittest
    119from twisted.test import proto_helpers
    1210from twisted.internet import defer
    1311from twisted.words.xish import domish
    1412from twisted.words.protocols.jabber import error, xmlstream
    1513
    16 from wokkel import iwokkel, subprotocols
     14from wokkel import subprotocols
    1715
    1816class DummyFactory(object):
    1917    """
     
    2826
    2927
    3028
    31 class DummyXMPPHandler(subprotocols.XMPPHandler):
     29class DummyXMPPHandler(xmlstream.XMPPHandler):
    3230    """
    3331    Dummy XMPP subprotocol handler to count the methods are called on it.
    3432    """
     
    5553
    5654
    5755
    58 class XMPPHandlerTest(unittest.TestCase):
    59     """
    60     Tests for L{subprotocols.XMPPHandler}.
    61     """
    62 
    63     def test_interface(self):
    64         """
    65         L{xmlstream.XMPPHandler} implements L{iwokkel.IXMPPHandler}.
    66         """
    67         verifyObject(iwokkel.IXMPPHandler, subprotocols.XMPPHandler())
    68 
    69 
    70     def test_send(self):
    71         """
    72         Test that data is passed on for sending by the stream manager.
    73         """
    74         class DummyStreamManager(object):
    75             def __init__(self):
    76                 self.outlist = []
    77 
    78             def send(self, data):
    79                 self.outlist.append(data)
    80 
    81         handler = subprotocols.XMPPHandler()
    82         handler.parent = DummyStreamManager()
    83         handler.send('<presence/>')
    84         self.assertEquals(['<presence/>'], handler.parent.outlist)
    85 
    86 
    87     def test_makeConnection(self):
    88         """
    89         Test that makeConnection saves the XML stream and calls connectionMade.
    90         """
    91         class TestXMPPHandler(subprotocols.XMPPHandler):
    92             def connectionMade(self):
    93                 self.doneMade = True
    94 
    95         handler = TestXMPPHandler()
    96         xs = xmlstream.XmlStream(xmlstream.Authenticator())
    97         handler.makeConnection(xs)
    98         self.assertTrue(handler.doneMade)
    99         self.assertIdentical(xs, handler.xmlstream)
    100 
    101 
    102     def test_connectionLost(self):
    103         """
    104         Test that connectionLost forgets the XML stream.
    105         """
    106         handler = subprotocols.XMPPHandler()
    107         xs = xmlstream.XmlStream(xmlstream.Authenticator())
    108         handler.makeConnection(xs)
    109         handler.connectionLost(Exception())
    110         self.assertIdentical(None, handler.xmlstream)
    111 
    112 
    113 
    114 class XMPPHandlerCollectionTest(unittest.TestCase):
    115     """
    116     Tests for L{subprotocols.XMPPHandlerCollection}.
    117     """
    118 
    119     def setUp(self):
    120         self.collection = subprotocols.XMPPHandlerCollection()
    121 
    122 
    123     def test_interface(self):
    124         """
    125         L{subprotocols.StreamManager} implements L{iwokkel.IXMPPHandlerCollection}.
    126         """
    127         verifyObject(iwokkel.IXMPPHandlerCollection, self.collection)
    128 
    129 
    130     def test_addHandler(self):
    131         """
    132         Test the addition of a protocol handler.
    133         """
    134         handler = DummyXMPPHandler()
    135         handler.setHandlerParent(self.collection)
    136         self.assertIn(handler, self.collection)
    137         self.assertIdentical(self.collection, handler.parent)
    138 
    139 
    140     def test_removeHandler(self):
    141         """
    142         Test removal of a protocol handler.
    143         """
    144         handler = DummyXMPPHandler()
    145         handler.setHandlerParent(self.collection)
    146         handler.disownHandlerParent(self.collection)
    147         self.assertNotIn(handler, self.collection)
    148         self.assertIdentical(None, handler.parent)
    149 
    150 
    151 
    15256class StreamManagerTest(unittest.TestCase):
    15357    """
    15458    Tests for L{subprotocols.StreamManager}.
  • wokkel/xmppim.py

    diff -r ebdb7afc619e wokkel/xmppim.py
    a b  
    1313"""
    1414
    1515from twisted.words.protocols.jabber.jid import JID
     16from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    1617from twisted.words.xish import domish
    1718
    1819from wokkel.compat import IQ
    1920from wokkel.generic import ErrorStanza, Stanza
    20 from wokkel.subprotocols import XMPPHandler
    2121
    2222NS_XML = 'http://www.w3.org/XML/1998/namespace'
    2323NS_ROSTER = 'jabber:iq:roster'
Note: See TracBrowser for help on using the repository browser.