Changeset 165:76a61f5aa343


Ignore:
Timestamp:
Jan 22, 2012, 2:51:25 PM (7 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Cleanups leading up to Wokkel 0.7.0.

As we now depend on Twisted 10.0.0 or higher, the following classes and
interfaces were deprecated:

This also resolves all Pyflakes warnings, changes links for www.xmpp.org to
xmpp.org and fixes the copyright notice in LICENSE to include 2012.

Files:
1 added
22 edited

Legend:

Unmodified
Added
Removed
  • LICENSE

    r96 r165  
    1 Copyright (c) 2003-2011 Ralph Meijer.
     1Copyright (c) 2003-2012 Ralph Meijer.
    22
    33Permission is hereby granted, free of charge, to any person obtaining
  • NEWS

    r163 r165  
    5656   common code, this fixes a problem with requests without addressing (#73).
    5757
     58Deprecations
     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
    5875
    59760.6.3 (2009-08-20)
  • debian/control

    r143 r165  
    1111Architecture: all
    1212XB-Python-Version: ${python:Versions}
    13 Depends: ${python:Depends}, ${misc:Depends}, python-twisted, python-twisted-words (>= 8.0.0), python-twisted-names, python-dateutil
     13Depends: ${python:Depends}, ${misc:Depends}, python-twisted (>= 10.0.0), python-twisted-words (>= 10.0.0), python-twisted-names (>= 10.0.0), python-dateutil
    1414Description: A set of enhancements to Twisted Words' Jabber/XMPP
    1515 It serves as a testing ground for new features and enhancements which will
  • debian/copyright

    r96 r165  
    11This package was debianized by Ralph Meijer <ralphm@ik.nu> on
    2 Mon, 24 Aug 2009 15:10:42 +0200.
     2Sun, Jan 22 2012 14:27:12 +0100.
    33
    4 It was downloaded from <https://svn.ik.nu/wokkel/trunk>
     4It was downloaded from <https://hg.ik.nu/wokkel>
    55
    66Author:
     
    1010Copyright:
    1111
    12     (C) 2003-2011 Ralph Meijer <ralphm@ik.nu>
     12    (C) 2003-2012 Ralph Meijer <ralphm@ik.nu>
    1313
    1414License:
  • wokkel/compat.py

    r160 r165  
    1313from itertools import count
    1414
    15 from twisted.internet import protocol
     15from twisted.python.deprecate import deprecatedModuleAttribute
     16from twisted.python.versions import Version
    1617from 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 
     18from twisted.words.protocols.jabber.xmlstream import XmlStreamServerFactory
     19from twisted.words.xish.xmlstream import BootstrapMixin
     20
     21deprecatedModuleAttribute(
     22        Version("Wokkel", 0, 7, 0),
     23        "Use twisted.words.xish.xmlstream.BootstrapMixin instead.",
     24        __name__,
     25        "BootstrapMixin")
     26
     27deprecatedModuleAttribute(
     28        Version("Wokkel", 0, 7, 0),
     29        "Use twisted.words.protocols.jabber.xmlstream.XmlStreamServerFactory "
     30                "instead.",
     31        __name__,
     32        "XmlStreamServerFactory")
    10733
    10834class IQ(xmlstream.IQ):
     
    14268    @ivar _container: The L{_ConstantsContainer} subclass this constant belongs
    14369        to; only set once the constant is initialized by that subclass.
     70
     71    @since: Twisted 12.0.0.
    14472    """
    14573    def __init__(self):
     
    185113    objects representing named constants for a particular L{_ConstantsContainer}
    186114    subclass.
     115
     116    @since: Twisted 12.0.0.
    187117    """
    188118    def __get__(self, oself, cls):
     
    212142        instances.  This is initialized via the L{_EnumerantsInitializer}
    213143        descriptor the first time it is accessed.
     144
     145    @since: Twisted 12.0.0.
    214146    """
    215147    _constantType = None
     
    308240    subclasses.  Do not instantiate L{NamedConstant} elsewhere and do not
    309241    subclass it.
     242
     243    @since: Twisted 12.0.0.
    310244    """
    311245
     
    316250    A L{Names} subclass contains constants which differ only in their names and
    317251    identities.
     252
     253    @since: Twisted 12.0.0.
    318254    """
    319255    _constantType = NamedConstant
     
    328264    L{ValueConstant} is only for use in the definition of L{Values} subclasses.
    329265    Do not instantiate L{ValueConstant} elsewhere and do not subclass it.
     266
     267    @since: Twisted 12.0.0.
    330268    """
    331269    def __init__(self, value):
     
    339277    A L{Values} subclass contains constants which are associated with arbitrary
    340278    values.
     279
     280    @since: Twisted 12.0.0.
    341281    """
    342282    _constantType = ValueConstant
  • wokkel/component.py

    r96 r165  
    1515from twisted.words.xish import domish
    1616
    17 try:
    18     #from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    19     from twisted.words.protocols.jabber.xmlstream import XMPPHandlerCollection
    20 except ImportError:
    21     #from wokkel.subprotocols import XMPPHandler
    22     from wokkel.subprotocols import XMPPHandlerCollection
    23 
    24 try:
    25     from twisted.words.protocols.jabber.xmlstream import XmlStreamServerFactory
    26 except ImportError:
    27     from wokkel.compat import XmlStreamServerFactory
    28 
    2917from wokkel.generic import XmlPipe
    3018from wokkel.subprotocols import StreamManager
     
    7967
    8068
    81 class InternalComponent(XMPPHandlerCollection, service.Service):
     69class InternalComponent(xmlstream.XMPPHandlerCollection, service.Service):
    8270    """
    8371    Component service that connects directly to a router.
     
    9280
    9381    def __init__(self, router, domain=None):
    94         XMPPHandlerCollection.__init__(self)
     82        xmlstream.XMPPHandlerCollection.__init__(self)
    9583
    9684        self._router = router
     
    138126        Add a new handler and connect it to the stream.
    139127        """
    140         XMPPHandlerCollection.addHandler(self, handler)
     128        xmlstream.XMPPHandlerCollection.addHandler(self, handler)
    141129
    142130        if self.xmlstream:
     
    323311
    324312
    325 class XMPPComponentServerFactory(XmlStreamServerFactory):
     313class XMPPComponentServerFactory(xmlstream.XmlStreamServerFactory):
    326314    """
    327315    XMPP Component Server factory.
     
    341329            return ListenComponentAuthenticator(self.secret)
    342330
    343         XmlStreamServerFactory.__init__(self, authenticatorFactory)
     331        xmlstream.XmlStreamServerFactory.__init__(self, authenticatorFactory)
    344332        self.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT,
    345333                          self.makeConnection)
  • wokkel/data_form.py

    r105 r165  
    88
    99Support for Data Forms as described in
    10 U{XEP-0004<http://www.xmpp.org/extensions/xep-0004.html>}, along with support
     10U{XEP-0004<http://xmpp.org/extensions/xep-0004.html>}, along with support
    1111for Field Standardization for Data Forms as described in
    12 U{XEP-0068<http://www.xmpp.org/extensions/xep-0068.html>}.
     12U{XEP-0068<http://xmpp.org/extensions/xep-0068.html>}.
    1313"""
    1414
  • wokkel/disco.py

    r155 r165  
    88
    99The XMPP service discovery protocol is documented in
    10 U{XEP-0030<http://www.xmpp.org/extensions/xep-0030.html>}.
     10U{XEP-0030<http://xmpp.org/extensions/xep-0030.html>}.
    1111"""
    1212
  • wokkel/formats.py

    r96 r165  
    1010
    1111    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>}.
    1313
    1414    @ivar value: The mood value.
     
    6161
    6262    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>}.
    6464
    6565    @ivar artist: The artist or performer of the song or piece.
  • wokkel/generic.py

    r103 r165  
    1515from twisted.words.protocols.jabber.xmlstream import toResponse
    1616from 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
     17from twisted.words.xish.xmlstream import BootstrapMixin
    2218
    2319from wokkel.iwokkel import IDisco
     
    9490
    9591    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>}.
    9793    """
    9894
     
    110106
    111107        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)
    114110        self.send(response)
    115111
  • wokkel/iwokkel.py

    r160 r165  
     1# -*- test-case-name: wokkel.test.test_iwokkel -*-
     2#
    13# Copyright (c) Ralph Meijer.
    24# See LICENSE for details.
     
    68"""
    79
    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
     14from zope.interface import Interface
     15from twisted.python.deprecate import deprecatedModuleAttribute
     16from twisted.python.versions import Version
     17from twisted.words.protocols.jabber.ijabber import IXMPPHandler
     18from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection
     19
     20deprecatedModuleAttribute(
     21        Version("Wokkel", 0, 7, 0),
     22        "Use twisted.words.protocols.jabber.ijabber.IXMPPHandler instead.",
     23        __name__,
     24        "IXMPPHandler")
     25
     26deprecatedModuleAttribute(
     27        Version("Wokkel", 0, 7, 0),
     28        "Use twisted.words.protocols.jabber.ijabber.IXMPPHandlerCollection "
     29                "instead.",
     30        __name__,
     31        "IXMPPHandlerCollection")
    11132
    11233
     
    14364        @type nodeIdentifier: C{unicode}
    14465        """
     66
    14567
    14668
     
    250172        @rtype: L{defer.Deferred}
    251173        """
     174
    252175
    253176
     
    1029952
    1030953
     954
    1031955class IMUCStatuses(Interface):
    1032956    """
  • wokkel/ping.py

    r96 r165  
    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
  • wokkel/pubsub.py

    r105 r165  
    88
    99This protocol is specified in
    10 U{XEP-0060<http://www.xmpp.org/extensions/xep-0060.html>}.
     10U{XEP-0060<http://xmpp.org/extensions/xep-0060.html>}.
    1111"""
    1212
  • wokkel/server.py

    r96 r165  
    2424from zope.interface import implements
    2525
    26 from twisted.application import service
    2726from twisted.internet import defer, reactor
    2827from twisted.names.srvconnect import SRVConnector
     
    3231
    3332from wokkel.generic import DeferredXmlStreamFactory, XmlPipe
    34 from wokkel.compat import XmlStreamServerFactory
    3533
    3634NS_DIALBACK = 'jabber:server:dialback'
     
    4139
    4240    The dialback key is generated using the algorithm described in
    43     U{XEP-0185<http://www.xmpp.org/extensions/xep-0185.html>}. The used
     41    U{XEP-0185<http://xmpp.org/extensions/xep-0185.html>}. The used
    4442    terminology for the parameters is described in RFC-3920.
    4543
     
    478476
    479477
    480 class XMPPS2SServerFactory(XmlStreamServerFactory):
     478class XMPPS2SServerFactory(xmlstream.XmlStreamServerFactory):
    481479    """
    482480    XMPP Server-to-Server Server factory.
     
    493491            return XMPPServerListenAuthenticator(service)
    494492
    495         XmlStreamServerFactory.__init__(self, authenticatorFactory)
     493        xmlstream.XmlStreamServerFactory.__init__(self, authenticatorFactory)
    496494        self.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT,
    497495                          self.onConnectionMade)
     
    702700            try:
    703701                sender = jid.internJID(stanzaFrom)
    704                 recipient = jid.internJID(stanzaTo)
     702                jid.internJID(stanzaTo)
    705703            except jid.InvalidFormat:
    706704                log.msg("Dropping error stanza with malformed JID")
  • wokkel/shim.py

    r96 r165  
    88
    99This protocol is specified in
    10 U{XEP-0131<http://www.xmpp.org/extensions/xep-0131.html>}.
     10U{XEP-0131<http://xmpp.org/extensions/xep-0131.html>}.
    1111"""
    1212
  • wokkel/subprotocols.py

    r101 r165  
    88"""
    99
     10__all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager',
     11           'IQHandlerMixin']
     12
    1013from zope.interface import implements
    1114
     
    1316from twisted.internet.error import ConnectionDone
    1417from twisted.python import failure, log
    15 from twisted.words.protocols.jabber import error, xmlstream
     18from twisted.python.deprecate import deprecatedModuleAttribute
     19from twisted.python.versions import Version
     20from twisted.words.protocols.jabber import error, ijabber, xmlstream
    1621from twisted.words.protocols.jabber.xmlstream import toResponse
     22from twisted.words.protocols.jabber.xmlstream import XMPPHandlerCollection
    1723from twisted.words.xish import xpath
    1824from twisted.words.xish.domish import IElement
    1925
    20 from wokkel.iwokkel import IXMPPHandler, IXMPPHandlerCollection
     26deprecatedModuleAttribute(
     27        Version("Wokkel", 0, 7, 0),
     28        "Use twisted.words.protocols.jabber.xmlstream.XMPPHandlerCollection "
     29                "instead.",
     30        __name__,
     31        "XMPPHandlerCollection")
    2132
    2233class XMPPHandler(object):
     
    2839    """
    2940
    30     implements(IXMPPHandler)
     41    implements(ijabber.IXMPPHandler)
    3142
    3243    def __init__(self):
     
    105116        """
    106117        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 an
    115     L{XMPPHandler} itself, so this is not recursive.
    116 
    117     @ivar handlers: List of protocol handlers.
    118     @type handlers: L{list} of objects providing
    119                       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)
    149118
    150119
     
    476445
    477446        def fromStanzaError(failure, iq):
    478             e = failure.trap(error.StanzaError)
     447            failure.trap(error.StanzaError)
    479448            return failure.value.toResponse(iq)
    480449
  • wokkel/test/test_client.py

    r96 r165  
    1313from twisted.words.protocols.jabber.xmlstream import STREAM_AUTHD_EVENT
    1414from 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
     15from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    2016
    2117from wokkel import client
    22 from wokkel.test.test_compat import BootstrapMixinTest
    2318
    2419class XMPPClientTest(unittest.TestCase):
     
    4944
    5045
    51 class DeferredClientFactoryTest(BootstrapMixinTest):
     46class DeferredClientFactoryTest(unittest.TestCase):
    5247    """
    5348    Tests for L{client.DeferredClientFactory}.
     
    10499            pass
    105100
    106         xs = self.factory.buildProtocol(None)
     101        self.factory.buildProtocol(None)
    107102        self.factory.clientConnectionFailed(self, TestException())
    108103        self.assertFailure(self.factory.deferred, TestException)
  • wokkel/test/test_compat.py

    r160 r165  
    88
    99from 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
     10from twisted.internet import task
     11from twisted.internet.interfaces import IReactorTime
    1312from twisted.trial import unittest
    14 from twisted.words.xish import utility
    1513from twisted.words.protocols.jabber import xmlstream
    1614
    17 from wokkel.compat import BootstrapMixin, IQ, XmlStreamServerFactory
     15from wokkel.compat import IQ
    1816from wokkel.compat import NamedConstant, Names, ValueConstant, Values
    1917
    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)
     18class 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")
    17159
    17260
  • wokkel/test/test_component.py

    r96 r165  
    88from zope.interface.verify import verifyObject
    99
    10 from twisted.internet import defer
    1110from twisted.python import failure
    1211from twisted.trial import unittest
    13 from twisted.words.protocols.jabber import ijabber, xmlstream
     12from twisted.words.protocols.jabber import xmlstream
     13from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection
    1414from twisted.words.protocols.jabber.jid import JID
     15from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    1516from twisted.words.xish import domish
    16 
    17 try:
    18     from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection
    19     from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    20 except ImportError:
    21     from wokkel.subprotocols import IXMPPHandlerCollection, XMPPHandler
    2217
    2318from wokkel import component
     
    4035        """
    4136        verifyObject(IXMPPHandlerCollection, self.component)
    42 
    4337
    4438
  • wokkel/test/test_generic.py

    r102 r165  
    3434        iq['to'] = 'example.org'
    3535        iq['type'] = 'get'
    36         query = iq.addElement((NS_VERSION, 'query'))
     36        iq.addElement((NS_VERSION, 'query'))
    3737        self.stub.send(iq)
    3838
  • wokkel/test/test_subprotocols.py

    r101 r165  
    1414from twisted.python import failure
    1515from twisted.words.xish import domish
    16 from twisted.words.protocols.jabber import error, xmlstream
    17 
    18 from wokkel import generic, iwokkel, subprotocols
     16from twisted.words.protocols.jabber import error, ijabber, xmlstream
     17
     18from wokkel import generic, subprotocols
     19
     20class 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
    1951
    2052class DummyFactory(object):
     
    88120    def test_interface(self):
    89121        """
    90         L{xmlstream.XMPPHandler} implements L{iwokkel.IXMPPHandler}.
    91         """
    92         verifyObject(iwokkel.IXMPPHandler, subprotocols.XMPPHandler())
     122        L{xmlstream.XMPPHandler} implements L{ijabber.IXMPPHandler}.
     123        """
     124        verifyObject(ijabber.IXMPPHandler, subprotocols.XMPPHandler())
    93125
    94126
     
    155187        self.assertIdentical(request, handler.parent.requests[-1])
    156188        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)
    195189
    196190
     
    319313        handler = FailureReasonXMPPHandler()
    320314        handler.setHandlerParent(sm)
    321         xs = xmlstream.XmlStream(xmlstream.Authenticator())
     315        xmlstream.XmlStream(xmlstream.Authenticator())
    322316        sm._disconnected(failure.Failure(Exception("no reason")))
    323317        self.assertEquals(True, handler.gotFailureReason)
  • wokkel/xmppim.py

    r141 r165  
    88
    99This module provides generic implementations for the protocols defined in
    10 U{RFC 3921<http://www.xmpp.org/rfcs/rfc3921.html>} (XMPP IM).
     10U{RFC 3921<http://xmpp.org/rfcs/rfc3921.html>} (XMPP IM).
    1111
    1212All of it should eventually move to Twisted.
Note: See TracChangeset for help on using the changeset viewer.