Changeset 165:76a61f5aa343
- Timestamp:
- Jan 22, 2012, 2:51:25 PM (11 years ago)
- Branch:
- default
- Files:
-
- 1 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
LICENSE
r96 r165 1 Copyright (c) 2003-201 1Ralph Meijer.1 Copyright (c) 2003-2012 Ralph Meijer. 2 2 3 3 Permission is hereby granted, free of charge, to any person obtaining -
NEWS
r163 r165 56 56 common code, this fixes a problem with requests without addressing (#73). 57 57 58 Deprecations 59 ------------ 60 61 - wokkel.compat.BootstrapMixin is deprecated in favor of 62 twisted.words.xish.xmlstream.BootstrapMixin (Twisted 8.2.0). 63 - wokkel.compat.XmlStreamServerFactory is deprecated in favor of 64 twisted.words.protocols.jabber.xmlstream.XmlStreamServerFactory (Twisted 65 8.2.0). 66 - wokkel.iwokkel.IXMPPHandler is deprecated in favor of 67 twisted.words.protocols.jabber.ijabber.IXMPPHandler (Twisted 8.1.0). 68 - wokkel.iwokkel.IXMPPHandlerCollection is deprecated in favor of 69 twisted.words.protocols.jabber.ijabber.IXMPPHandlerCollection (Twisted 70 8.1.0). 71 - wokkel.subprotocols.XMPPHandlerCollection is deprecated in favor of 72 twisted.words.protocols.jabber.xmlstream.XMPPHandlerCollection (Twisted 73 8.1.0). 74 58 75 59 76 0.6.3 (2009-08-20) -
debian/control
r143 r165 11 11 Architecture: all 12 12 XB-Python-Version: ${python:Versions} 13 Depends: ${python:Depends}, ${misc:Depends}, python-twisted , python-twisted-words (>= 8.0.0), python-twisted-names, python-dateutil13 Depends: ${python:Depends}, ${misc:Depends}, python-twisted (>= 10.0.0), python-twisted-words (>= 10.0.0), python-twisted-names (>= 10.0.0), python-dateutil 14 14 Description: A set of enhancements to Twisted Words' Jabber/XMPP 15 15 It serves as a testing ground for new features and enhancements which will -
debian/copyright
r96 r165 1 1 This package was debianized by Ralph Meijer <ralphm@ik.nu> on 2 Mon, 24 Aug 2009 15:10:42 +0200.2 Sun, Jan 22 2012 14:27:12 +0100. 3 3 4 It was downloaded from <https:// svn.ik.nu/wokkel/trunk>4 It was downloaded from <https://hg.ik.nu/wokkel> 5 5 6 6 Author: … … 10 10 Copyright: 11 11 12 (C) 2003-201 1Ralph Meijer <ralphm@ik.nu>12 (C) 2003-2012 Ralph Meijer <ralphm@ik.nu> 13 13 14 14 License: -
wokkel/compat.py
r160 r165 13 13 from itertools import count 14 14 15 from twisted.internet import protocol 15 from twisted.python.deprecate import deprecatedModuleAttribute 16 from twisted.python.versions import Version 16 17 from twisted.words.protocols.jabber import xmlstream 17 18 class BootstrapMixin(object): 19 """ 20 XmlStream factory mixin to install bootstrap event observers. 21 22 This mixin is for factories providing 23 L{IProtocolFactory<twisted.internet.interfaces.IProtocolFactory>} to make 24 sure bootstrap event observers are set up on protocols, before incoming 25 data is processed. Such protocols typically derive from 26 L{utility.EventDispatcher}, like L{XmlStream}. 27 28 You can set up bootstrap event observers using C{addBootstrap}. The 29 C{event} and C{fn} parameters correspond with the C{event} and 30 C{observerfn} arguments to L{utility.EventDispatcher.addObserver}. 31 32 @since: 8.2. 33 @ivar bootstraps: The list of registered bootstrap event observers. 34 @type bootstrap: C{list} 35 """ 36 37 def __init__(self): 38 self.bootstraps = [] 39 40 41 def installBootstraps(self, dispatcher): 42 """ 43 Install registered bootstrap observers. 44 45 @param dispatcher: Event dispatcher to add the observers to. 46 @type dispatcher: L{utility.EventDispatcher} 47 """ 48 for event, fn in self.bootstraps: 49 dispatcher.addObserver(event, fn) 50 51 52 def addBootstrap(self, event, fn): 53 """ 54 Add a bootstrap event handler. 55 56 @param event: The event to register an observer for. 57 @type event: C{str} or L{xpath.XPathQuery} 58 @param fn: The observer callable to be registered. 59 """ 60 self.bootstraps.append((event, fn)) 61 62 63 def removeBootstrap(self, event, fn): 64 """ 65 Remove a bootstrap event handler. 66 67 @param event: The event the observer is registered for. 68 @type event: C{str} or L{xpath.XPathQuery} 69 @param fn: The registered observer callable. 70 """ 71 self.bootstraps.remove((event, fn)) 72 73 74 75 class XmlStreamServerFactory(BootstrapMixin, 76 protocol.ServerFactory): 77 """ 78 Factory for Jabber XmlStream objects as a server. 79 80 @since: 8.2. 81 @ivar authenticatorFactory: Factory callable that takes no arguments, to 82 create a fresh authenticator to be associated 83 with the XmlStream. 84 """ 85 86 protocol = xmlstream.XmlStream 87 88 def __init__(self, authenticatorFactory): 89 BootstrapMixin.__init__(self) 90 self.authenticatorFactory = authenticatorFactory 91 92 93 def buildProtocol(self, addr): 94 """ 95 Create an instance of XmlStream. 96 97 A new authenticator instance will be created and passed to the new 98 XmlStream. Registered bootstrap event observers are installed as well. 99 """ 100 authenticator = self.authenticatorFactory() 101 xs = self.protocol(authenticator) 102 xs.factory = self 103 self.installBootstraps(xs) 104 return xs 105 106 18 from twisted.words.protocols.jabber.xmlstream import XmlStreamServerFactory 19 from twisted.words.xish.xmlstream import BootstrapMixin 20 21 deprecatedModuleAttribute( 22 Version("Wokkel", 0, 7, 0), 23 "Use twisted.words.xish.xmlstream.BootstrapMixin instead.", 24 __name__, 25 "BootstrapMixin") 26 27 deprecatedModuleAttribute( 28 Version("Wokkel", 0, 7, 0), 29 "Use twisted.words.protocols.jabber.xmlstream.XmlStreamServerFactory " 30 "instead.", 31 __name__, 32 "XmlStreamServerFactory") 107 33 108 34 class IQ(xmlstream.IQ): … … 142 68 @ivar _container: The L{_ConstantsContainer} subclass this constant belongs 143 69 to; only set once the constant is initialized by that subclass. 70 71 @since: Twisted 12.0.0. 144 72 """ 145 73 def __init__(self): … … 185 113 objects representing named constants for a particular L{_ConstantsContainer} 186 114 subclass. 115 116 @since: Twisted 12.0.0. 187 117 """ 188 118 def __get__(self, oself, cls): … … 212 142 instances. This is initialized via the L{_EnumerantsInitializer} 213 143 descriptor the first time it is accessed. 144 145 @since: Twisted 12.0.0. 214 146 """ 215 147 _constantType = None … … 308 240 subclasses. Do not instantiate L{NamedConstant} elsewhere and do not 309 241 subclass it. 242 243 @since: Twisted 12.0.0. 310 244 """ 311 245 … … 316 250 A L{Names} subclass contains constants which differ only in their names and 317 251 identities. 252 253 @since: Twisted 12.0.0. 318 254 """ 319 255 _constantType = NamedConstant … … 328 264 L{ValueConstant} is only for use in the definition of L{Values} subclasses. 329 265 Do not instantiate L{ValueConstant} elsewhere and do not subclass it. 266 267 @since: Twisted 12.0.0. 330 268 """ 331 269 def __init__(self, value): … … 339 277 A L{Values} subclass contains constants which are associated with arbitrary 340 278 values. 279 280 @since: Twisted 12.0.0. 341 281 """ 342 282 _constantType = ValueConstant -
wokkel/component.py
r96 r165 15 15 from twisted.words.xish import domish 16 16 17 try:18 #from twisted.words.protocols.jabber.xmlstream import XMPPHandler19 from twisted.words.protocols.jabber.xmlstream import XMPPHandlerCollection20 except ImportError:21 #from wokkel.subprotocols import XMPPHandler22 from wokkel.subprotocols import XMPPHandlerCollection23 24 try:25 from twisted.words.protocols.jabber.xmlstream import XmlStreamServerFactory26 except ImportError:27 from wokkel.compat import XmlStreamServerFactory28 29 17 from wokkel.generic import XmlPipe 30 18 from wokkel.subprotocols import StreamManager … … 79 67 80 68 81 class InternalComponent( XMPPHandlerCollection, service.Service):69 class InternalComponent(xmlstream.XMPPHandlerCollection, service.Service): 82 70 """ 83 71 Component service that connects directly to a router. … … 92 80 93 81 def __init__(self, router, domain=None): 94 XMPPHandlerCollection.__init__(self)82 xmlstream.XMPPHandlerCollection.__init__(self) 95 83 96 84 self._router = router … … 138 126 Add a new handler and connect it to the stream. 139 127 """ 140 XMPPHandlerCollection.addHandler(self, handler)128 xmlstream.XMPPHandlerCollection.addHandler(self, handler) 141 129 142 130 if self.xmlstream: … … 323 311 324 312 325 class XMPPComponentServerFactory( XmlStreamServerFactory):313 class XMPPComponentServerFactory(xmlstream.XmlStreamServerFactory): 326 314 """ 327 315 XMPP Component Server factory. … … 341 329 return ListenComponentAuthenticator(self.secret) 342 330 343 XmlStreamServerFactory.__init__(self, authenticatorFactory)331 xmlstream.XmlStreamServerFactory.__init__(self, authenticatorFactory) 344 332 self.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, 345 333 self.makeConnection) -
wokkel/data_form.py
r105 r165 8 8 9 9 Support for Data Forms as described in 10 U{XEP-0004<http:// www.xmpp.org/extensions/xep-0004.html>}, along with support10 U{XEP-0004<http://xmpp.org/extensions/xep-0004.html>}, along with support 11 11 for Field Standardization for Data Forms as described in 12 U{XEP-0068<http:// www.xmpp.org/extensions/xep-0068.html>}.12 U{XEP-0068<http://xmpp.org/extensions/xep-0068.html>}. 13 13 """ 14 14 -
wokkel/disco.py
r155 r165 8 8 9 9 The XMPP service discovery protocol is documented in 10 U{XEP-0030<http:// www.xmpp.org/extensions/xep-0030.html>}.10 U{XEP-0030<http://xmpp.org/extensions/xep-0030.html>}. 11 11 """ 12 12 -
wokkel/formats.py
r96 r165 10 10 11 11 This represents a user's mood, as defined in 12 U{XEP-0107<http:// www.xmpp.org/extensions/xep-0107.html>}.12 U{XEP-0107<http://xmpp.org/extensions/xep-0107.html>}. 13 13 14 14 @ivar value: The mood value. … … 61 61 62 62 This represents a user's mood, as defined in 63 U{XEP-0118<http:// www.xmpp.org/extensions/xep-0118.html>}.63 U{XEP-0118<http://xmpp.org/extensions/xep-0118.html>}. 64 64 65 65 @ivar artist: The artist or performer of the song or piece. -
wokkel/generic.py
r103 r165 15 15 from twisted.words.protocols.jabber.xmlstream import toResponse 16 16 from twisted.words.xish import domish, utility 17 18 try: 19 from twisted.words.xish.xmlstream import BootstrapMixin 20 except ImportError: 21 from wokkel.compat import BootstrapMixin 17 from twisted.words.xish.xmlstream import BootstrapMixin 22 18 23 19 from wokkel.iwokkel import IDisco … … 94 90 95 91 This protocol is described in 96 U{XEP-0092<http:// www.xmpp.org/extensions/xep-0092.html>}.92 U{XEP-0092<http://xmpp.org/extensions/xep-0092.html>}. 97 93 """ 98 94 … … 110 106 111 107 query = response.addElement((NS_VERSION, "query")) 112 name =query.addElement("name", content=self.name)113 version =query.addElement("version", content=self.version)108 query.addElement("name", content=self.name) 109 query.addElement("version", content=self.version) 114 110 self.send(response) 115 111 -
wokkel/iwokkel.py
r160 r165 1 # -*- test-case-name: wokkel.test.test_iwokkel -*- 2 # 1 3 # Copyright (c) Ralph Meijer. 2 4 # See LICENSE for details. … … 6 8 """ 7 9 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 10 __all__ = ['IXMPPHandler', 'IXMPPHandlerCollection', 11 'IPubSubClient', 'IPubSubService', 'IPubSubResource', 12 'IMUCClient', 'IMUCStatuses'] 13 14 from zope.interface import Interface 15 from twisted.python.deprecate import deprecatedModuleAttribute 16 from twisted.python.versions import Version 17 from twisted.words.protocols.jabber.ijabber import IXMPPHandler 18 from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection 19 20 deprecatedModuleAttribute( 21 Version("Wokkel", 0, 7, 0), 22 "Use twisted.words.protocols.jabber.ijabber.IXMPPHandler instead.", 23 __name__, 24 "IXMPPHandler") 25 26 deprecatedModuleAttribute( 27 Version("Wokkel", 0, 7, 0), 28 "Use twisted.words.protocols.jabber.ijabber.IXMPPHandlerCollection " 29 "instead.", 30 __name__, 31 "IXMPPHandlerCollection") 111 32 112 33 … … 143 64 @type nodeIdentifier: C{unicode} 144 65 """ 66 145 67 146 68 … … 250 172 @rtype: L{defer.Deferred} 251 173 """ 174 252 175 253 176 … … 1029 952 1030 953 954 1031 955 class IMUCStatuses(Interface): 1032 956 """ -
wokkel/ping.py
r96 r165 15 15 from twisted.words.protocols.jabber.error import StanzaError 16 16 from 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 17 from twisted.words.protocols.jabber.xmlstream import XMPPHandler 22 18 23 19 from wokkel import disco, iwokkel -
wokkel/pubsub.py
r105 r165 8 8 9 9 This protocol is specified in 10 U{XEP-0060<http:// www.xmpp.org/extensions/xep-0060.html>}.10 U{XEP-0060<http://xmpp.org/extensions/xep-0060.html>}. 11 11 """ 12 12 -
wokkel/server.py
r96 r165 24 24 from zope.interface import implements 25 25 26 from twisted.application import service27 26 from twisted.internet import defer, reactor 28 27 from twisted.names.srvconnect import SRVConnector … … 32 31 33 32 from wokkel.generic import DeferredXmlStreamFactory, XmlPipe 34 from wokkel.compat import XmlStreamServerFactory35 33 36 34 NS_DIALBACK = 'jabber:server:dialback' … … 41 39 42 40 The dialback key is generated using the algorithm described in 43 U{XEP-0185<http:// www.xmpp.org/extensions/xep-0185.html>}. The used41 U{XEP-0185<http://xmpp.org/extensions/xep-0185.html>}. The used 44 42 terminology for the parameters is described in RFC-3920. 45 43 … … 478 476 479 477 480 class XMPPS2SServerFactory( XmlStreamServerFactory):478 class XMPPS2SServerFactory(xmlstream.XmlStreamServerFactory): 481 479 """ 482 480 XMPP Server-to-Server Server factory. … … 493 491 return XMPPServerListenAuthenticator(service) 494 492 495 XmlStreamServerFactory.__init__(self, authenticatorFactory)493 xmlstream.XmlStreamServerFactory.__init__(self, authenticatorFactory) 496 494 self.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, 497 495 self.onConnectionMade) … … 702 700 try: 703 701 sender = jid.internJID(stanzaFrom) 704 recipient =jid.internJID(stanzaTo)702 jid.internJID(stanzaTo) 705 703 except jid.InvalidFormat: 706 704 log.msg("Dropping error stanza with malformed JID") -
wokkel/shim.py
r96 r165 8 8 9 9 This protocol is specified in 10 U{XEP-0131<http:// www.xmpp.org/extensions/xep-0131.html>}.10 U{XEP-0131<http://xmpp.org/extensions/xep-0131.html>}. 11 11 """ 12 12 -
wokkel/subprotocols.py
r101 r165 8 8 """ 9 9 10 __all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager', 11 'IQHandlerMixin'] 12 10 13 from zope.interface import implements 11 14 … … 13 16 from twisted.internet.error import ConnectionDone 14 17 from twisted.python import failure, log 15 from twisted.words.protocols.jabber import error, xmlstream 18 from twisted.python.deprecate import deprecatedModuleAttribute 19 from twisted.python.versions import Version 20 from twisted.words.protocols.jabber import error, ijabber, xmlstream 16 21 from twisted.words.protocols.jabber.xmlstream import toResponse 22 from twisted.words.protocols.jabber.xmlstream import XMPPHandlerCollection 17 23 from twisted.words.xish import xpath 18 24 from twisted.words.xish.domish import IElement 19 25 20 from wokkel.iwokkel import IXMPPHandler, IXMPPHandlerCollection 26 deprecatedModuleAttribute( 27 Version("Wokkel", 0, 7, 0), 28 "Use twisted.words.protocols.jabber.xmlstream.XMPPHandlerCollection " 29 "instead.", 30 __name__, 31 "XMPPHandlerCollection") 21 32 22 33 class XMPPHandler(object): … … 28 39 """ 29 40 30 implements( IXMPPHandler)41 implements(ijabber.IXMPPHandler) 31 42 32 43 def __init__(self): … … 105 116 """ 106 117 return self.parent.request(request) 107 108 109 110 class XMPPHandlerCollection(object):111 """112 Collection of XMPP subprotocol handlers.113 114 This allows for grouping of subprotocol handlers, but is not an115 L{XMPPHandler} itself, so this is not recursive.116 117 @ivar handlers: List of protocol handlers.118 @type handlers: L{list} of objects providing119 L{IXMPPHandler}120 """121 122 implements(IXMPPHandlerCollection)123 124 def __init__(self):125 self.handlers = []126 127 128 def __iter__(self):129 """130 Act as a container for handlers.131 """132 return iter(self.handlers)133 134 135 def addHandler(self, handler):136 """137 Add protocol handler.138 139 Protocol handlers are expected to provide L{IXMPPHandler}.140 """141 self.handlers.append(handler)142 143 144 def removeHandler(self, handler):145 """146 Remove protocol handler.147 """148 self.handlers.remove(handler)149 118 150 119 … … 476 445 477 446 def fromStanzaError(failure, iq): 478 e =failure.trap(error.StanzaError)447 failure.trap(error.StanzaError) 479 448 return failure.value.toResponse(iq) 480 449 -
wokkel/test/test_client.py
r96 r165 13 13 from twisted.words.protocols.jabber.xmlstream import STREAM_AUTHD_EVENT 14 14 from twisted.words.protocols.jabber.xmlstream import INIT_FAILED_EVENT 15 16 try: 17 from twisted.words.protocols.jabber.xmlstream import XMPPHandler 18 except ImportError: 19 from wokkel.subprotocols import XMPPHandler 15 from twisted.words.protocols.jabber.xmlstream import XMPPHandler 20 16 21 17 from wokkel import client 22 from wokkel.test.test_compat import BootstrapMixinTest23 18 24 19 class XMPPClientTest(unittest.TestCase): … … 49 44 50 45 51 class DeferredClientFactoryTest( BootstrapMixinTest):46 class DeferredClientFactoryTest(unittest.TestCase): 52 47 """ 53 48 Tests for L{client.DeferredClientFactory}. … … 104 99 pass 105 100 106 xs =self.factory.buildProtocol(None)101 self.factory.buildProtocol(None) 107 102 self.factory.clientConnectionFailed(self, TestException()) 108 103 self.assertFailure(self.factory.deferred, TestException) -
wokkel/test/test_compat.py
r160 r165 8 8 9 9 from zope.interface import implements 10 from zope.interface.verify import verifyObject 11 from twisted.internet import protocol, task 12 from twisted.internet.interfaces import IProtocolFactory, IReactorTime 10 from twisted.internet import task 11 from twisted.internet.interfaces import IReactorTime 13 12 from twisted.trial import unittest 14 from twisted.words.xish import utility15 13 from twisted.words.protocols.jabber import xmlstream 16 14 17 from wokkel.compat import BootstrapMixin, IQ, XmlStreamServerFactory15 from wokkel.compat import IQ 18 16 from wokkel.compat import NamedConstant, Names, ValueConstant, Values 19 17 20 class DummyProtocol(protocol.Protocol, utility.EventDispatcher): 21 """ 22 I am a protocol with an event dispatcher without further processing. 23 24 This protocol is only used for testing BootstrapMixin to make 25 sure the bootstrap observers are added to the protocol instance. 26 """ 27 28 def __init__(self, *args, **kwargs): 29 self.args = args 30 self.kwargs = kwargs 31 self.observers = [] 32 33 utility.EventDispatcher.__init__(self) 34 35 36 37 class BootstrapMixinTest(unittest.TestCase): 38 """ 39 Tests for L{BootstrapMixin}. 40 41 @ivar factory: Instance of the factory or mixin under test. 42 """ 43 44 def setUp(self): 45 self.factory = BootstrapMixin() 46 47 48 def test_installBootstraps(self): 49 """ 50 Dispatching an event should fire registered bootstrap observers. 51 """ 52 called = [] 53 54 def cb(data): 55 called.append(data) 56 57 dispatcher = DummyProtocol() 58 self.factory.addBootstrap('//event/myevent', cb) 59 self.factory.installBootstraps(dispatcher) 60 61 dispatcher.dispatch(None, '//event/myevent') 62 self.assertEquals(1, len(called)) 63 64 65 def test_addAndRemoveBootstrap(self): 66 """ 67 Test addition and removal of a bootstrap event handler. 68 """ 69 70 called = [] 71 72 def cb(data): 73 called.append(data) 74 75 self.factory.addBootstrap('//event/myevent', cb) 76 self.factory.removeBootstrap('//event/myevent', cb) 77 78 dispatcher = DummyProtocol() 79 self.factory.installBootstraps(dispatcher) 80 81 dispatcher.dispatch(None, '//event/myevent') 82 self.assertFalse(called) 83 84 85 86 class XmlStreamServerFactoryTest(BootstrapMixinTest): 87 """ 88 Tests for L{XmlStreamServerFactory}. 89 """ 90 91 def setUp(self): 92 """ 93 Set up a server factory with a authenticator factory function. 94 """ 95 class TestAuthenticator(object): 96 def __init__(self): 97 self.xmlstreams = [] 98 99 def associateWithStream(self, xs): 100 self.xmlstreams.append(xs) 101 102 def authenticatorFactory(): 103 return TestAuthenticator() 104 105 self.factory = XmlStreamServerFactory(authenticatorFactory) 106 107 108 def test_interface(self): 109 """ 110 L{XmlStreamServerFactory} is a L{Factory}. 111 """ 112 verifyObject(IProtocolFactory, self.factory) 113 114 115 def test_buildProtocolAuthenticatorInstantiation(self): 116 """ 117 The authenticator factory should be used to instantiate the 118 authenticator and pass it to the protocol. 119 120 The default protocol, L{XmlStream} stores the authenticator it is 121 passed, and calls its C{associateWithStream} method. so we use that to 122 check whether our authenticator factory is used and the protocol 123 instance gets an authenticator. 124 """ 125 xs = self.factory.buildProtocol(None) 126 self.assertEquals([xs], xs.authenticator.xmlstreams) 127 128 129 def test_buildProtocolXmlStream(self): 130 """ 131 The protocol factory creates Jabber XML Stream protocols by default. 132 """ 133 xs = self.factory.buildProtocol(None) 134 self.assertIsInstance(xs, xmlstream.XmlStream) 135 136 137 def test_buildProtocolTwice(self): 138 """ 139 Subsequent calls to buildProtocol should result in different instances 140 of the protocol, as well as their authenticators. 141 """ 142 xs1 = self.factory.buildProtocol(None) 143 xs2 = self.factory.buildProtocol(None) 144 self.assertNotIdentical(xs1, xs2) 145 self.assertNotIdentical(xs1.authenticator, xs2.authenticator) 146 147 148 def test_buildProtocolInstallsBootstraps(self): 149 """ 150 The protocol factory installs bootstrap event handlers on the protocol. 151 """ 152 called = [] 153 154 def cb(data): 155 called.append(data) 156 157 self.factory.addBootstrap('//event/myevent', cb) 158 159 xs = self.factory.buildProtocol(None) 160 xs.dispatch(None, '//event/myevent') 161 162 self.assertEquals(1, len(called)) 163 164 165 def test_buildProtocolStoresFactory(self): 166 """ 167 The protocol factory is saved in the protocol. 168 """ 169 xs = self.factory.buildProtocol(None) 170 self.assertIdentical(self.factory, xs.factory) 18 class DeprecationTest(unittest.TestCase): 19 """ 20 Deprecation tests for L{wokkel.compat}. 21 """ 22 23 def lookForDeprecationWarning(self, testmethod, attributeName, newName): 24 """ 25 Importing C{testmethod} emits a deprecation warning. 26 """ 27 warningsShown = self.flushWarnings([testmethod]) 28 self.assertEqual(len(warningsShown), 1) 29 self.assertIdentical(warningsShown[0]['category'], DeprecationWarning) 30 self.assertEqual( 31 warningsShown[0]['message'], 32 "wokkel.compat." + attributeName + " " 33 "was deprecated in Wokkel 0.7.0: Use " + newName + " instead.") 34 35 36 def test_bootstrapMixinTest(self): 37 """ 38 L{compat.BootstrapMixin} is deprecated. 39 """ 40 from wokkel.compat import BootstrapMixin 41 BootstrapMixin 42 self.lookForDeprecationWarning( 43 self.test_bootstrapMixinTest, 44 "BootstrapMixin", 45 "twisted.words.xish.xmlstream.BootstrapMixin") 46 47 48 def test_xmlStreamServerFactory(self): 49 """ 50 L{compat.XmlStreamServerFactory} is deprecated. 51 """ 52 from wokkel.compat import XmlStreamServerFactory 53 XmlStreamServerFactory 54 self.lookForDeprecationWarning( 55 self.test_xmlStreamServerFactory, 56 "XmlStreamServerFactory", 57 "twisted.words.protocols.jabber.xmlstream." 58 "XmlStreamServerFactory") 171 59 172 60 -
wokkel/test/test_component.py
r96 r165 8 8 from zope.interface.verify import verifyObject 9 9 10 from twisted.internet import defer11 10 from twisted.python import failure 12 11 from twisted.trial import unittest 13 from twisted.words.protocols.jabber import ijabber, xmlstream 12 from twisted.words.protocols.jabber import xmlstream 13 from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection 14 14 from twisted.words.protocols.jabber.jid import JID 15 from twisted.words.protocols.jabber.xmlstream import XMPPHandler 15 16 from twisted.words.xish import domish 16 17 try:18 from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection19 from twisted.words.protocols.jabber.xmlstream import XMPPHandler20 except ImportError:21 from wokkel.subprotocols import IXMPPHandlerCollection, XMPPHandler22 17 23 18 from wokkel import component … … 40 35 """ 41 36 verifyObject(IXMPPHandlerCollection, self.component) 42 43 37 44 38 -
wokkel/test/test_generic.py
r102 r165 34 34 iq['to'] = 'example.org' 35 35 iq['type'] = 'get' 36 query =iq.addElement((NS_VERSION, 'query'))36 iq.addElement((NS_VERSION, 'query')) 37 37 self.stub.send(iq) 38 38 -
wokkel/test/test_subprotocols.py
r101 r165 14 14 from twisted.python import failure 15 15 from twisted.words.xish import domish 16 from twisted.words.protocols.jabber import error, xmlstream 17 18 from wokkel import generic, iwokkel, subprotocols 16 from twisted.words.protocols.jabber import error, ijabber, xmlstream 17 18 from wokkel import generic, subprotocols 19 20 class DeprecationTest(unittest.TestCase): 21 """ 22 Deprecation test for L{wokkel.subprotocols}. 23 """ 24 25 def lookForDeprecationWarning(self, testmethod, attributeName, newName): 26 """ 27 Importing C{testmethod} emits a deprecation warning. 28 """ 29 warningsShown = self.flushWarnings([testmethod]) 30 self.assertEqual(len(warningsShown), 1) 31 self.assertIdentical(warningsShown[0]['category'], DeprecationWarning) 32 self.assertEqual( 33 warningsShown[0]['message'], 34 "wokkel.subprotocols." + attributeName + " " 35 "was deprecated in Wokkel 0.7.0: Use " + newName + " instead.") 36 37 38 def test_xmppHandlerCollection(self): 39 """ 40 L{subprotocols.XMPPHandlerCollection} is deprecated. 41 """ 42 from wokkel.subprotocols import XMPPHandlerCollection 43 XMPPHandlerCollection 44 self.lookForDeprecationWarning( 45 self.test_xmppHandlerCollection, 46 "XMPPHandlerCollection", 47 "twisted.words.protocols.jabber.xmlstream." 48 "XMPPHandlerCollection") 49 50 19 51 20 52 class DummyFactory(object): … … 88 120 def test_interface(self): 89 121 """ 90 L{xmlstream.XMPPHandler} implements L{i wokkel.IXMPPHandler}.91 """ 92 verifyObject(i wokkel.IXMPPHandler, subprotocols.XMPPHandler())122 L{xmlstream.XMPPHandler} implements L{ijabber.IXMPPHandler}. 123 """ 124 verifyObject(ijabber.IXMPPHandler, subprotocols.XMPPHandler()) 93 125 94 126 … … 155 187 self.assertIdentical(request, handler.parent.requests[-1]) 156 188 return d 157 158 159 160 class XMPPHandlerCollectionTest(unittest.TestCase):161 """162 Tests for L{subprotocols.XMPPHandlerCollection}.163 """164 165 def setUp(self):166 self.collection = subprotocols.XMPPHandlerCollection()167 168 169 def test_interface(self):170 """171 L{subprotocols.StreamManager} implements L{iwokkel.IXMPPHandlerCollection}.172 """173 verifyObject(iwokkel.IXMPPHandlerCollection, self.collection)174 175 176 def test_addHandler(self):177 """178 Test the addition of a protocol handler.179 """180 handler = DummyXMPPHandler()181 handler.setHandlerParent(self.collection)182 self.assertIn(handler, self.collection)183 self.assertIdentical(self.collection, handler.parent)184 185 186 def test_removeHandler(self):187 """188 Test removal of a protocol handler.189 """190 handler = DummyXMPPHandler()191 handler.setHandlerParent(self.collection)192 handler.disownHandlerParent(self.collection)193 self.assertNotIn(handler, self.collection)194 self.assertIdentical(None, handler.parent)195 189 196 190 … … 319 313 handler = FailureReasonXMPPHandler() 320 314 handler.setHandlerParent(sm) 321 x s = xmlstream.XmlStream(xmlstream.Authenticator())315 xmlstream.XmlStream(xmlstream.Authenticator()) 322 316 sm._disconnected(failure.Failure(Exception("no reason"))) 323 317 self.assertEquals(True, handler.gotFailureReason) -
wokkel/xmppim.py
r141 r165 8 8 9 9 This module provides generic implementations for the protocols defined in 10 U{RFC 3921<http:// www.xmpp.org/rfcs/rfc3921.html>} (XMPP IM).10 U{RFC 3921<http://xmpp.org/rfcs/rfc3921.html>} (XMPP IM). 11 11 12 12 All of it should eventually move to Twisted.
Note: See TracChangeset
for help on using the changeset viewer.