# HG changeset patch # Parent ebdb7afc619efdbb2a6ec82470a7e635634efbad diff -r ebdb7afc619e wokkel/disco.py --- a/wokkel/disco.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/disco.py Sun Feb 20 16:28:57 2011 +0100 @@ -12,12 +12,13 @@ from twisted.internet import defer from twisted.words.protocols.jabber import error, jid +from twisted.words.protocols.jabber.xmlstream import XMPPHandler from twisted.words.xish import domish from wokkel import data_form from wokkel.compat import IQ from wokkel.iwokkel import IDisco -from wokkel.subprotocols import IQHandlerMixin, XMPPHandler +from wokkel.subprotocols import IQHandlerMixin NS_DISCO = 'http://jabber.org/protocol/disco' NS_DISCO_INFO = NS_DISCO + '#info' diff -r ebdb7afc619e wokkel/generic.py --- a/wokkel/generic.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/generic.py Sun Feb 20 16:28:57 2011 +0100 @@ -22,7 +22,6 @@ from wokkel import disco from wokkel.iwokkel import IDisco -from wokkel.subprotocols import XMPPHandler IQ_GET = '/iq[@type="get"]' IQ_SET = '/iq[@type="set"]' @@ -68,7 +67,7 @@ -class FallbackHandler(XMPPHandler): +class FallbackHandler(xmlstream.XMPPHandler): """ XMPP subprotocol handler that catches unhandled iq requests. @@ -89,7 +88,7 @@ -class VersionHandler(XMPPHandler): +class VersionHandler(xmlstream.XMPPHandler): """ XMPP subprotocol handler for XMPP Software Version. diff -r ebdb7afc619e wokkel/iwokkel.py --- a/wokkel/iwokkel.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/iwokkel.py Sun Feb 20 16:28:57 2011 +0100 @@ -5,110 +5,7 @@ Wokkel interfaces. """ -from zope.interface import Attribute, Interface - -class IXMPPHandler(Interface): - """ - Interface for XMPP protocol handlers. - - Objects that provide this interface can be added to a stream manager to - handle of (part of) an XMPP extension protocol. - """ - - parent = Attribute("""XML stream manager for this handler""") - xmlstream = Attribute("""The managed XML stream""") - - def setHandlerParent(parent): - """ - Set the parent of the handler. - - @type parent: L{IXMPPHandlerCollection} - """ - - - def disownHandlerParent(parent): - """ - Remove the parent of the handler. - - @type parent: L{IXMPPHandlerCollection} - """ - - - def makeConnection(xs): - """ - A connection over the underlying transport of the XML stream has been - established. - - At this point, no traffic has been exchanged over the XML stream - given in C{xs}. - - This should setup L{xmlstream} and call L{connectionMade}. - - @type xs: L{XmlStream} - """ - - - def connectionMade(): - """ - Called after a connection has been established. - - This method can be used to change properties of the XML Stream, its - authenticator or the stream manager prior to stream initialization - (including authentication). - """ - - - def connectionInitialized(): - """ - The XML stream has been initialized. - - At this point, authentication was successful, and XML stanzas can be - exchanged over the XML stream L{xmlstream}. This method can be - used to setup observers for incoming stanzas. - """ - - - def connectionLost(reason): - """ - The XML stream has been closed. - - Subsequent use of L{parent.send} will result in data being queued - until a new connection has been established. - - @type reason: L{twisted.python.failure.Failure} - """ - - - -class IXMPPHandlerCollection(Interface): - """ - Collection of handlers. - - Contain several handlers and manage their connection. - """ - - def __iter__(): - """ - Get an iterator over all child handlers. - """ - - - def addHandler(handler): - """ - Add a child handler. - - @type handler: L{IXMPPHandler} - """ - - - def removeHandler(handler): - """ - Remove a child handler. - - @type handler: L{IXMPPHandler} - """ - - +from zope.interface import Interface class IDisco(Interface): """ diff -r ebdb7afc619e wokkel/ping.py --- a/wokkel/ping.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/ping.py Sun Feb 20 16:28:57 2011 +0100 @@ -14,11 +14,7 @@ from twisted.words.protocols.jabber.error import StanzaError from twisted.words.protocols.jabber.xmlstream import IQ, toResponse - -try: - from twisted.words.protocols.xmlstream import XMPPHandler -except ImportError: - from wokkel.subprotocols import XMPPHandler +from twisted.words.protocols.jabber.xmlstream import XMPPHandler from wokkel import disco, iwokkel diff -r ebdb7afc619e wokkel/pubsub.py --- a/wokkel/pubsub.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/pubsub.py Sun Feb 20 16:28:57 2011 +0100 @@ -15,11 +15,12 @@ from twisted.internet import defer from twisted.python import log from twisted.words.protocols.jabber import jid, error +from twisted.words.protocols.jabber.xmlstream import XMPPHandler from twisted.words.xish import domish from wokkel import disco, data_form, generic, shim from wokkel.compat import IQ -from wokkel.subprotocols import IQHandlerMixin, XMPPHandler +from wokkel.subprotocols import IQHandlerMixin from wokkel.iwokkel import IPubSubClient, IPubSubService, IPubSubResource # Iq get and set XPath queries diff -r ebdb7afc619e wokkel/subprotocols.py --- a/wokkel/subprotocols.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/subprotocols.py Sun Feb 20 16:28:57 2011 +0100 @@ -7,134 +7,29 @@ XMPP subprotocol support. """ -from zope.interface import implements - from twisted.internet import defer -from twisted.python import log +from twisted.python import deprecate, log, versions from twisted.words.protocols.jabber import error, xmlstream from twisted.words.protocols.jabber.xmlstream import toResponse +from twisted.words.protocols.jabber.xmlstream import XMPPHandler +from twisted.words.protocols.jabber.xmlstream import XMPPHandlerCollection from twisted.words.xish import xpath from twisted.words.xish.domish import IElement -from wokkel.iwokkel import IXMPPHandler, IXMPPHandlerCollection +_deprecatedVersion = versions.Version("wokkel", 0, 7, 0) -class XMPPHandler(object): - """ - XMPP protocol handler. +deprecate.deprecatedModuleAttribute( + _deprecatedVersion, + "use twisted.words.protocols.jabber.xmlstream.XMPPHandler instead.", + __name__, + 'XMPPHandler') - Classes derived from this class implement (part of) one or more XMPP - extension protocols, and are referred to as a subprotocol implementation. - """ - - implements(IXMPPHandler) - - def __init__(self): - self.parent = None - self.xmlstream = None - - - def setHandlerParent(self, parent): - self.parent = parent - self.parent.addHandler(self) - - - def disownHandlerParent(self, parent): - self.parent.removeHandler(self) - self.parent = None - - - def makeConnection(self, xs): - self.xmlstream = xs - self.connectionMade() - - - def connectionMade(self): - """ - Called after a connection has been established. - - Can be overridden to perform work before stream initialization. - """ - - - def connectionInitialized(self): - """ - The XML stream has been initialized. - - Can be overridden to perform work after stream initialization, e.g. to - set up observers and start exchanging XML stanzas. - """ - - - def connectionLost(self, reason): - """ - The XML stream has been closed. - - This method can be extended to inspect the C{reason} argument and - act on it. - """ - self.xmlstream = None - - - def send(self, obj): - """ - Send data over the managed XML stream. - - @note: The stream manager maintains a queue for data sent using this - method when there is no current initialized XML stream. This - data is then sent as soon as a new stream has been established - and initialized. Subsequently, L{connectionInitialized} will be - called again. If this queueing is not desired, use C{send} on - C{self.xmlstream}. - - @param obj: data to be sent over the XML stream. This is usually an - object providing L{domish.IElement}, or serialized XML. See - L{xmlstream.XmlStream} for details. - """ - self.parent.send(obj) - - - -class XMPPHandlerCollection(object): - """ - Collection of XMPP subprotocol handlers. - - This allows for grouping of subprotocol handlers, but is not an - L{XMPPHandler} itself, so this is not recursive. - - @ivar handlers: List of protocol handlers. - @type handlers: L{list} of objects providing - L{IXMPPHandler} - """ - - implements(IXMPPHandlerCollection) - - def __init__(self): - self.handlers = [] - - - def __iter__(self): - """ - Act as a container for handlers. - """ - return iter(self.handlers) - - - def addHandler(self, handler): - """ - Add protocol handler. - - Protocol handlers are expected to provide L{IXMPPHandler}. - """ - self.handlers.append(handler) - - - def removeHandler(self, handler): - """ - Remove protocol handler. - """ - self.handlers.remove(handler) - - +deprecate.deprecatedModuleAttribute( + _deprecatedVersion, + "use twisted.words.protocols.jabber.xmlstream.XMPPHandlerCollection " + "instead.", + __name__, + 'XMPPHandlerCollection') class StreamManager(XMPPHandlerCollection): """ diff -r ebdb7afc619e wokkel/test/test_disco.py --- a/wokkel/test/test_disco.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/test/test_disco.py Sun Feb 20 16:28:57 2011 +0100 @@ -11,12 +11,11 @@ from twisted.trial import unittest from twisted.words.protocols.jabber.error import StanzaError from twisted.words.protocols.jabber.jid import JID -from twisted.words.protocols.jabber.xmlstream import toResponse +from twisted.words.protocols.jabber.xmlstream import XMPPHandler, toResponse from twisted.words.xish import domish, utility from wokkel import data_form, disco from wokkel.generic import parseXml -from wokkel.subprotocols import XMPPHandler from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info' diff -r ebdb7afc619e wokkel/test/test_subprotocols.py --- a/wokkel/test/test_subprotocols.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/test/test_subprotocols.py Sun Feb 20 16:28:57 2011 +0100 @@ -5,15 +5,13 @@ Tests for L{wokkel.subprotocols} """ -from zope.interface.verify import verifyObject - from twisted.trial import unittest from twisted.test import proto_helpers from twisted.internet import defer from twisted.words.xish import domish from twisted.words.protocols.jabber import error, xmlstream -from wokkel import iwokkel, subprotocols +from wokkel import subprotocols class DummyFactory(object): """ @@ -28,7 +26,7 @@ -class DummyXMPPHandler(subprotocols.XMPPHandler): +class DummyXMPPHandler(xmlstream.XMPPHandler): """ Dummy XMPP subprotocol handler to count the methods are called on it. """ @@ -55,100 +53,6 @@ -class XMPPHandlerTest(unittest.TestCase): - """ - Tests for L{subprotocols.XMPPHandler}. - """ - - def test_interface(self): - """ - L{xmlstream.XMPPHandler} implements L{iwokkel.IXMPPHandler}. - """ - verifyObject(iwokkel.IXMPPHandler, subprotocols.XMPPHandler()) - - - def test_send(self): - """ - Test that data is passed on for sending by the stream manager. - """ - class DummyStreamManager(object): - def __init__(self): - self.outlist = [] - - def send(self, data): - self.outlist.append(data) - - handler = subprotocols.XMPPHandler() - handler.parent = DummyStreamManager() - handler.send('') - self.assertEquals([''], handler.parent.outlist) - - - def test_makeConnection(self): - """ - Test that makeConnection saves the XML stream and calls connectionMade. - """ - class TestXMPPHandler(subprotocols.XMPPHandler): - def connectionMade(self): - self.doneMade = True - - handler = TestXMPPHandler() - xs = xmlstream.XmlStream(xmlstream.Authenticator()) - handler.makeConnection(xs) - self.assertTrue(handler.doneMade) - self.assertIdentical(xs, handler.xmlstream) - - - def test_connectionLost(self): - """ - Test that connectionLost forgets the XML stream. - """ - handler = subprotocols.XMPPHandler() - xs = xmlstream.XmlStream(xmlstream.Authenticator()) - handler.makeConnection(xs) - handler.connectionLost(Exception()) - self.assertIdentical(None, handler.xmlstream) - - - -class XMPPHandlerCollectionTest(unittest.TestCase): - """ - Tests for L{subprotocols.XMPPHandlerCollection}. - """ - - def setUp(self): - self.collection = subprotocols.XMPPHandlerCollection() - - - def test_interface(self): - """ - L{subprotocols.StreamManager} implements L{iwokkel.IXMPPHandlerCollection}. - """ - verifyObject(iwokkel.IXMPPHandlerCollection, self.collection) - - - def test_addHandler(self): - """ - Test the addition of a protocol handler. - """ - handler = DummyXMPPHandler() - handler.setHandlerParent(self.collection) - self.assertIn(handler, self.collection) - self.assertIdentical(self.collection, handler.parent) - - - def test_removeHandler(self): - """ - Test removal of a protocol handler. - """ - handler = DummyXMPPHandler() - handler.setHandlerParent(self.collection) - handler.disownHandlerParent(self.collection) - self.assertNotIn(handler, self.collection) - self.assertIdentical(None, handler.parent) - - - class StreamManagerTest(unittest.TestCase): """ Tests for L{subprotocols.StreamManager}. diff -r ebdb7afc619e wokkel/xmppim.py --- a/wokkel/xmppim.py Sun Feb 20 16:25:18 2011 +0100 +++ b/wokkel/xmppim.py Sun Feb 20 16:28:57 2011 +0100 @@ -13,11 +13,11 @@ """ from twisted.words.protocols.jabber.jid import JID +from twisted.words.protocols.jabber.xmlstream import XMPPHandler from twisted.words.xish import domish from wokkel.compat import IQ from wokkel.generic import ErrorStanza, Stanza -from wokkel.subprotocols import XMPPHandler NS_XML = 'http://www.w3.org/XML/1998/namespace' NS_ROSTER = 'jabber:iq:roster'