Ignore:
Timestamp:
Jan 22, 2012, 2:51:25 PM (10 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.