Ignore:
Files:
1 added
37 edited

Legend:

Unmodified
Added
Removed
  • .travis.yml

    r187 r211  
    22
    33python:
    4     - 2.6
    54    - 2.7
     5    - 3.3
     6    - 3.5
    67    - pypy
    78
     
    1011        - PYFLAKES_NODOCTEST=1
    1112    matrix:
    12         - TWISTED=Twisted==12.3
    13         - TWISTED=svn+svn://svn.twistedmatrix.com/svn/Twisted/trunk
     13        - TWISTED=Twisted==15.5
     14        - TWISTED=Twisted==16.4
     15        - TWISTED=https://github.com/twisted/twisted/archive/trunk.zip
     16
     17matrix:
     18    exclude:
     19        - python: 3.3
     20          env: TWISTED=Twisted==15.5
     21        - python: 3.5
     22          env: TWISTED=Twisted==15.5
    1423
    1524install:
    16     - pip install pyflakes --use-mirrors
    17     - pip install -q $TWISTED --use-mirrors
     25    - pip install pyflakes
     26    - pip install -q $TWISTED
    1827    - python setup.py install
    1928
  • doc/examples/echo_server.tac

    r69 r207  
    99
    1010from twisted.application import service, strports
     11from twisted.python.compat import unicode
    1112from twisted.words.protocols.jabber.xmlstream import toResponse
    1213from wokkel import component, server, xmppim
  • doc/examples/pinger.py

    r65 r207  
    1616    def connectionInitialized(self):
    1717        def cb(response):
    18             print "*** Pong ***"
     18            print("*** Pong ***")
    1919
    20         print "*** Ping ***"
     20        print("*** Ping ***")
    2121        d = self.ping(self.entity, sender=self.sender)
    2222        d.addCallback(cb)
  • setup.py

    r179 r214  
    44# See LICENSE for details.
    55
     6import sys
    67from setuptools import setup
    78
     
    2829    egg_info.write_toplevel_names = _hacked_write_toplevel_names
    2930
     31if sys.version_info < (3, 0):
     32    requiredTwisted = "15.5.0"
     33else:
     34    requiredTwisted = "16.4.0"
     35
    3036setup(name='wokkel',
    3137      version='0.7.1',
     
    4551      zip_safe=False,
    4652      install_requires=[
    47           'Twisted >= 10.0.0',
     53          'Twisted >= %s' % requiredTwisted,
    4854          'python-dateutil',
    4955      ],
  • wokkel/client.py

    r184 r208  
    1010that should probably eventually move there.
    1111"""
     12
     13from __future__ import division, absolute_import
    1214
    1315from twisted.application import service
  • wokkel/compat.py

    r165 r204  
    88"""
    99
    10 __all__ = ['BootstrapMixin', 'XmlStreamServerFactory', 'IQ',
    11            'NamedConstant', 'ValueConstant', 'Names', 'Values']
     10from __future__ import division, absolute_import
    1211
    13 from itertools import count
    14 
    15 from twisted.python.deprecate import deprecatedModuleAttribute
    16 from twisted.python.versions import Version
    1712from twisted.words.protocols.jabber import xmlstream
    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")
    3313
    3414class IQ(xmlstream.IQ):
     
    5434
    5535
    56 _unspecified = object()
    57 _constantOrder = count().next
    58 
    59 
    60 class _Constant(object):
    61     """
    62     @ivar _index: A C{int} allocated from a shared counter in order to keep
    63         track of the order in which L{_Constant}s are instantiated.
    64 
    65     @ivar name: A C{str} giving the name of this constant; only set once the
    66         constant is initialized by L{_ConstantsContainer}.
    67 
    68     @ivar _container: The L{_ConstantsContainer} subclass this constant belongs
    69         to; only set once the constant is initialized by that subclass.
    70 
    71     @since: Twisted 12.0.0.
    72     """
    73     def __init__(self):
    74         self._index = _constantOrder()
    75 
    76 
    77     def __get__(self, oself, cls):
    78         """
    79         Ensure this constant has been initialized before returning it.
    80         """
    81         cls._initializeEnumerants()
    82         return self
    83 
    84 
    85     def __repr__(self):
    86         """
    87         Return text identifying both which constant this is and which collection
    88         it belongs to.
    89         """
    90         return "<%s=%s>" % (self._container.__name__, self.name)
    91 
    92 
    93     def _realize(self, container, name, value):
    94         """
    95         Complete the initialization of this L{_Constant}.
    96 
    97         @param container: The L{_ConstantsContainer} subclass this constant is
    98             part of.
    99 
    100         @param name: The name of this constant in its container.
    101 
    102         @param value: The value of this constant; not used, as named constants
    103             have no value apart from their identity.
    104         """
    105         self._container = container
    106         self.name = name
    107 
    108 
    109 
    110 class _EnumerantsInitializer(object):
    111     """
    112     L{_EnumerantsInitializer} is a descriptor used to initialize a cache of
    113     objects representing named constants for a particular L{_ConstantsContainer}
    114     subclass.
    115 
    116     @since: Twisted 12.0.0.
    117     """
    118     def __get__(self, oself, cls):
    119         """
    120         Trigger the initialization of the enumerants cache on C{cls} and then
    121         return it.
    122         """
    123         cls._initializeEnumerants()
    124         return cls._enumerants
    125 
    126 
    127 
    128 class _ConstantsContainer(object):
    129     """
    130     L{_ConstantsContainer} is a class with attributes used as symbolic
    131     constants.  It is up to subclasses to specify what kind of constants are
    132     allowed.
    133 
    134     @cvar _constantType: Specified by a L{_ConstantsContainer} subclass to
    135         specify the type of constants allowed by that subclass.
    136 
    137     @cvar _enumerantsInitialized: A C{bool} tracking whether C{_enumerants} has
    138         been initialized yet or not.
    139 
    140     @cvar _enumerants: A C{dict} mapping the names of constants (eg
    141         L{NamedConstant} instances) found in the class definition to those
    142         instances.  This is initialized via the L{_EnumerantsInitializer}
    143         descriptor the first time it is accessed.
    144 
    145     @since: Twisted 12.0.0.
    146     """
    147     _constantType = None
    148 
    149     _enumerantsInitialized = False
    150     _enumerants = _EnumerantsInitializer()
    151 
    152     def __new__(cls):
    153         """
    154         Classes representing constants containers are not intended to be
    155         instantiated.
    156 
    157         The class object itself is used directly.
    158         """
    159         raise TypeError("%s may not be instantiated." % (cls.__name__,))
    160 
    161 
    162     def _initializeEnumerants(cls):
    163         """
    164         Find all of the L{NamedConstant} instances in the definition of C{cls},
    165         initialize them with constant values, and build a mapping from their
    166         names to them to attach to C{cls}.
    167         """
    168         if not cls._enumerantsInitialized:
    169             constants = []
    170             for (name, descriptor) in cls.__dict__.iteritems():
    171                 if isinstance(descriptor, cls._constantType):
    172                     constants.append((descriptor._index, name, descriptor))
    173             enumerants = {}
    174             for (index, enumerant, descriptor) in constants:
    175                 value = cls._constantFactory(enumerant)
    176                 descriptor._realize(cls, enumerant, value)
    177                 enumerants[enumerant] = descriptor
    178             # Replace the _enumerants descriptor with the result so future
    179             # access will go directly to the values.  The _enumerantsInitialized
    180             # flag is still necessary because NamedConstant.__get__ may also
    181             # call this method.
    182             cls._enumerants = enumerants
    183             cls._enumerantsInitialized = True
    184     _initializeEnumerants = classmethod(_initializeEnumerants)
    185 
    186 
    187     def _constantFactory(cls, name):
    188         """
    189         Construct the value for a new constant to add to this container.
    190 
    191         @param name: The name of the constant to create.
    192 
    193         @return: L{NamedConstant} instances have no value apart from identity,
    194             so return a meaningless dummy value.
    195         """
    196         return _unspecified
    197     _constantFactory = classmethod(_constantFactory)
    198 
    199 
    200     def lookupByName(cls, name):
    201         """
    202         Retrieve a constant by its name or raise a C{ValueError} if there is no
    203         constant associated with that name.
    204 
    205         @param name: A C{str} giving the name of one of the constants defined by
    206             C{cls}.
    207 
    208         @raise ValueError: If C{name} is not the name of one of the constants
    209             defined by C{cls}.
    210 
    211         @return: The L{NamedConstant} associated with C{name}.
    212         """
    213         if name in cls._enumerants:
    214             return getattr(cls, name)
    215         raise ValueError(name)
    216     lookupByName = classmethod(lookupByName)
    217 
    218 
    219     def iterconstants(cls):
    220         """
    221         Iteration over a L{Names} subclass results in all of the constants it
    222         contains.
    223 
    224         @return: an iterator the elements of which are the L{NamedConstant}
    225             instances defined in the body of this L{Names} subclass.
    226         """
    227         constants = cls._enumerants.values()
    228         constants.sort(key=lambda descriptor: descriptor._index)
    229         return iter(constants)
    230     iterconstants = classmethod(iterconstants)
    231 
    232 
    233 
    234 class NamedConstant(_Constant):
    235     """
    236     L{NamedConstant} defines an attribute to be a named constant within a
    237     collection defined by a L{Names} subclass.
    238 
    239     L{NamedConstant} is only for use in the definition of L{Names}
    240     subclasses.  Do not instantiate L{NamedConstant} elsewhere and do not
    241     subclass it.
    242 
    243     @since: Twisted 12.0.0.
    244     """
    245 
    246 
    247 
    248 class Names(_ConstantsContainer):
    249     """
    250     A L{Names} subclass contains constants which differ only in their names and
    251     identities.
    252 
    253     @since: Twisted 12.0.0.
    254     """
    255     _constantType = NamedConstant
    256 
    257 
    258 
    259 class ValueConstant(_Constant):
    260     """
    261     L{ValueConstant} defines an attribute to be a named constant within a
    262     collection defined by a L{Values} subclass.
    263 
    264     L{ValueConstant} is only for use in the definition of L{Values} subclasses.
    265     Do not instantiate L{ValueConstant} elsewhere and do not subclass it.
    266 
    267     @since: Twisted 12.0.0.
    268     """
    269     def __init__(self, value):
    270         _Constant.__init__(self)
    271         self.value = value
    272 
    273 
    274 
    275 class Values(_ConstantsContainer):
    276     """
    277     A L{Values} subclass contains constants which are associated with arbitrary
    278     values.
    279 
    280     @since: Twisted 12.0.0.
    281     """
    282     _constantType = ValueConstant
    283 
    284     def lookupByValue(cls, value):
    285         """
    286         Retrieve a constant by its value or raise a C{ValueError} if there is no
    287         constant associated with that value.
    288 
    289         @param value: The value of one of the constants defined by C{cls}.
    290 
    291         @raise ValueError: If C{value} is not the value of one of the constants
    292             defined by C{cls}.
    293 
    294         @return: The L{ValueConstant} associated with C{value}.
    295         """
    296         for constant in cls.iterconstants():
    297             if constant.value == value:
    298                 return constant
    299         raise ValueError(value)
    300     lookupByValue = classmethod(lookupByValue)
     36__all__ = ['IQ']
  • wokkel/component.py

    r176 r205  
    88"""
    99
     10from __future__ import division, absolute_import
     11
    1012from twisted.application import service
    1113from twisted.internet import reactor
    1214from twisted.python import log
     15from twisted.python.compat import unicode
    1316from twisted.words.protocols.jabber.jid import internJID as JID
    1417from twisted.words.protocols.jabber import component, error, xmlstream
     
    103106    allows for one-process XMPP servers.
    104107
    105     @ivar domains: Domains (as C{str}) this component will handle traffic for.
    106     @type domains: C{set}
     108    @ivar domains: Domains (as L{unicode}) this component will handle traffic
     109        for.
     110    @type domains: L{set}
    107111    """
    108112
     
    174178
    175179    @ivar secret: The shared used to authorized incoming component connections.
    176     @type secret: C{unicode}.
     180    @type secret: L{unicode}.
    177181    """
    178182
     
    275279    stanzas they offer for routing.
    276280
    277     A route destination of C{None} adds a default route. Traffic for which no
     281    A route destination of L{None} adds a default route. Traffic for which no
    278282    specific route exists, will be routed to this default route.
    279283
    280284    @ivar routes: Routes based on the host part of JIDs. Maps host names to the
    281285        L{EventDispatcher<twisted.words.xish.utility.EventDispatcher>}s that
    282         should receive the traffic. A key of C{None} means the default route.
    283     @type routes: C{dict}
     286        should receive the traffic. A key of L{None} means the default route.
     287    @type routes: L{dict}
    284288    """
    285289
     
    297301
    298302        @param destination: Destination of the route to be added as a host name
    299                             or C{None} for the default route.
    300         @type destination: C{str} or C{NoneType}
     303                            or L{None} for the default route.
     304        @type destination: L{unicode} or L{NoneType}
    301305
    302306        @param xs: XML Stream to register the route for.
     
    313317
    314318        @param destination: Destination of the route that should be removed.
    315         @type destination: C{str}.
     319        @type destination: L{unicode}
    316320
    317321        @param xs: XML Stream to remove the route for.
  • wokkel/componentservertap.py

    r96 r209  
    99domain(s).
    1010"""
     11
     12from __future__ import division, absolute_import
    1113
    1214from twisted.application import service, strports
  • wokkel/data_form.py

    r182 r196  
    1313"""
    1414
    15 from zope.interface import implements
     15from __future__ import division, absolute_import
     16
     17from zope.interface import implementer
    1618from zope.interface.common import mapping
     19
     20from twisted.python.compat import iteritems, unicode, _PY3
    1721from twisted.words.protocols.jabber.jid import JID
    1822from twisted.words.xish import domish
     
    4852
    4953    @ivar value: Value of this option.
    50     @type value: C{unicode}
     54    @type value: L{unicode}
    5155    @ivar label: Optional label for this option.
    52     @type label: C{unicode} or C{NoneType}
     56    @type label: L{unicode} or L{NoneType}
    5357    """
    5458
     
    101105
    102106                     The default is C{'text-single'}.
    103     @type fieldType: C{str}
     107    @type fieldType: L{str}
    104108    @ivar var: Field name. Optional if C{fieldType} is C{'fixed'}.
    105     @type var: C{str}
     109    @type var: L{str}
    106110    @ivar label: Human readable label for this field.
    107     @type label: C{unicode}
     111    @type label: L{unicode}
    108112    @ivar values: The values for this field, for multi-valued field
    109                   types, as a list of C{bool}, C{unicode} or L{JID}.
    110     @type values: C{list}
     113                  types, as a list of L{bool}, L{unicode} or L{JID}.
     114    @type values: L{list}
    111115    @ivar options: List of possible values to choose from in a response
    112116                   to this form as a list of L{Option}s.
    113     @type options: C{list}
     117    @type options: L{list}
    114118    @ivar desc: Human readable description for this field.
    115     @type desc: C{unicode}
     119    @type desc: L{unicode}
    116120    @ivar required: Whether the field is required to be provided in a
    117121                    response to this form.
    118     @type required: C{bool}
     122    @type required: L{bool}
    119123    """
    120124
     
    127131        See the identically named instance variables for descriptions.
    128132
    129         If C{value} is not C{None}, it overrides C{values}, setting the
     133        If C{value} is not L{None}, it overrides C{values}, setting the
    130134        given value as the only value for this field.
    131135        """
     
    144148            self.options = [Option(optionValue, optionLabel)
    145149                            for optionValue, optionLabel
    146                             in options.iteritems()]
     150                            in iteritems(options)]
    147151        except AttributeError:
    148152            self.options = options or []
     
    182186        Sets C{value} as the only element of L{values}.
    183187
    184         @type value: C{bool}, C{unicode} or L{JID}
     188        @type value: L{bool}, L{unicode} or L{JID}
    185189        """
    186190        self.values = [value]
     
    191195        Getter of value property.
    192196
    193         Returns the first element of L{values}, if present, or C{None}.
     197        Returns the first element of L{values}, if present, or L{None}.
    194198        """
    195199
     
    310314        field = Field(None)
    311315
    312         for eAttr, fAttr in {'type': 'fieldType',
    313                              'var': 'var',
    314                              'label': 'label'}.iteritems():
     316        for eAttr, fAttr in iteritems({'type': 'fieldType',
     317                                       'var': 'var',
     318                                       'label': 'label'}):
    315319            value = element.getAttribute(eAttr)
    316320            if value:
     
    347351        if 'options' in fieldDict:
    348352            options = []
    349             for value, label in fieldDict['options'].iteritems():
     353            for value, label in iteritems(fieldDict['options']):
    350354                options.append(Option(value, label))
    351355            kwargs['options'] = options
     
    354358
    355359
     360
     361@implementer(mapping.IIterableMapping,
     362             mapping.IEnumerableMapping,
     363             mapping.IReadMapping,
     364             mapping.IItemMapping)
    356365
    357366class Form(object):
     
    374383    @ivar formType: Type of form. One of C{'form'}, C{'submit'}, {'cancel'},
    375384                    or {'result'}.
    376     @type formType: C{str}
     385    @type formType: L{str}
    377386
    378387    @ivar title: Natural language title of the form.
    379     @type title: C{unicode}
    380 
    381     @ivar instructions: Natural language instructions as a list of C{unicode}
     388    @type title: L{unicode}
     389
     390    @ivar instructions: Natural language instructions as a list of L{unicode}
    382391        strings without line breaks.
    383     @type instructions: C{list}
     392    @type instructions: L{list}
    384393
    385394    @ivar formNamespace: The optional namespace of the field names for this
    386395        form. This goes in the special field named C{'FORM_TYPE'}, if set.
    387     @type formNamespace: C{str}
     396    @type formNamespace: L{str}
    388397
    389398    @ivar fields: Dictionary of named fields. Note that this is meant to be
    390399        used for reading, only. One should use L{addField} or L{makeFields} and
    391400        L{removeField} for adding and removing fields.
    392     @type fields: C{dict}
     401    @type fields: L{dict}
    393402
    394403    @ivar fieldList: List of all fields, in the order they are added. Like
    395404        C{fields}, this is meant to be used for reading, only.
    396     @type fieldList: C{list}
    397     """
    398 
    399     implements(mapping.IIterableMapping,
    400                mapping.IEnumerableMapping,
    401                mapping.IReadMapping,
    402                mapping.IItemMapping)
     405    @type fieldList: L{list}
     406    """
    403407
    404408    def __init__(self, formType, title=None, instructions=None,
     
    469473        this form. It is typically used for generating outgoing forms.
    470474
    471         If C{fieldDefs} is not C{None}, this is used to fill in
     475        If C{fieldDefs} is not L{None}, this is used to fill in
    472476        additional properties of fields, like the field types, labels and
    473477        possible options.
    474478
    475         If C{filterUnknown} is C{True} and C{fieldDefs} is not C{None}, fields
     479        If C{filterUnknown} is L{True} and C{fieldDefs} is not L{None}, fields
    476480        will only be created from C{values} with a corresponding entry in
    477481        C{fieldDefs}.
    478482
    479         If the field type is unknown, the field type is C{None}. When the form
     483        If the field type is unknown, the field type is L{None}. When the form
    480484        is rendered using L{toElement}, these fields will have no C{'type'}
    481485        attribute, and it is up to the receiving party to interpret the values
     
    484488
    485489        @param values: Values to create fields from.
    486         @type values: C{dict}
     490        @type values: L{dict}
    487491
    488492        @param fieldDefs: Field definitions as a dictionary. See
    489493            L{wokkel.iwokkel.IPubSubService.getConfigurationOptions}
    490         @type fieldDefs: C{dict}
    491 
    492         @param filterUnknown: If C{True}, ignore fields that are not in
     494        @type fieldDefs: L{dict}
     495
     496        @param filterUnknown: If L{True}, ignore fields that are not in
    493497            C{fieldDefs}.
    494         @type filterUnknown: C{bool}
    495         """
    496         for name, value in values.iteritems():
     498        @type filterUnknown: L{bool}
     499        """
     500        for name, value in iteritems(values):
    497501            fieldDict = {'var': name,
    498502                         'type': None}
     
    634638            yield (key, self[key])
    635639
    636 
    637     def keys(self):
    638         return list(self)
    639 
    640 
    641     def values(self):
    642         return list(self.itervalues())
    643 
    644 
    645     def items(self):
    646         return list(self.iteritems())
     640    if _PY3:
     641        keys = iterkeys
     642        values = itervalues
     643        items = iteritems
     644    else:
     645        def keys(self):
     646            return list(self)
     647
     648
     649        def values(self):
     650            return list(self.itervalues())
     651
     652
     653        def items(self):
     654            return list(self.iteritems())
    647655
    648656
     
    653661        For all named fields, the corresponding value or values are
    654662        returned in a dictionary keyed by the field name. This is equivalent
    655         do C{dict(f)}, where C{f} is a L{Form}.
     663        do L{dict(f)}, where C{f} is a L{Form}.
    656664
    657665        @see: L{__getitem__}
    658         @rtype: C{dict}
     666        @rtype: L{dict}
    659667        """
    660668        return dict(self)
     
    669677        field definition in C{fieldDefs} is used to check the field type.
    670678
    671         If C{filterUnknown} is C{True}, fields that are not present in
     679        If C{filterUnknown} is L{True}, fields that are not present in
    672680        C{fieldDefs} are removed from the form.
    673681
    674         If the field type is C{None} (when not set by the sending entity),
     682        If the field type is L{None} (when not set by the sending entity),
    675683        the type from the field definitition is used, or C{'text-single'} if
    676684        that is not set.
     
    682690        @param fieldDefs: Field definitions as a dictionary. See
    683691            L{wokkel.iwokkel.IPubSubService.getConfigurationOptions}
    684         @type fieldDefs: C{dict}
    685 
    686         @param filterUnknown: If C{True}, remove fields that are not in
     692        @type fieldDefs: L{dict}
     693
     694        @param filterUnknown: If L{True}, remove fields that are not in
    687695            C{fieldDefs}.
    688         @type filterUnknown: C{bool}
     696        @type filterUnknown: L{bool}
    689697        """
    690698
     
    694702        filtered = []
    695703
    696         for name, field in self.fields.iteritems():
     704        for name, field in iteritems(self.fields):
    697705            if name in fieldDefs:
    698706                fieldDef = fieldDefs[name]
  • wokkel/delay.py

    r104 r216  
    1111U{XEP-0091<http://xmpp.org/extensions/xep-0091.html>}.
    1212"""
     13
     14from __future__ import division, absolute_import
    1315
    1416from dateutil.parser import parse
     
    7981            if stamp.tzinfo is None:
    8082                stamp = stamp.replace(tzinfo=tzutc())
    81         except (KeyError, ValueError):
     83        except (KeyError, ValueError, TypeError):
    8284            stamp = None
    8385
  • wokkel/disco.py

    r166 r198  
    1111"""
    1212
     13from __future__ import division, absolute_import
     14
    1315from twisted.internet import defer
     16from twisted.python.compat import iteritems, unicode
    1417from twisted.words.protocols.jabber import error, jid
    1518from twisted.words.xish import domish
     
    364367            }
    365368
    366     _verbRequestMap = dict(((v, k) for k, v in _requestVerbMap.iteritems()))
     369    _verbRequestMap = dict(((v, k) for k, v in iteritems(_requestVerbMap)))
    367370
    368371    def __init__(self, verb=None, nodeIdentifier='',
  • wokkel/formats.py

    r165 r213  
     1# -*- test-case-name: wokkel.test.test_formats -*-
     2#
    13# Copyright (c) Ralph Meijer.
    24# See LICENSE for details.
     5
     6"""
     7Generic payload formats.
     8"""
     9
     10from __future__ import division, absolute_import
     11
     12from twisted.python.compat import unicode
    313
    414NS_MOOD = 'http://jabber.org/protocol/mood'
     
    2030        self.value = value
    2131        self.text = text
     32
    2233
    2334    def fromXml(self, element):
     
    5566
    5667    fromXml = classmethod(fromXml)
     68
     69
    5770
    5871class Tune:
  • wokkel/generic.py

    r185 r195  
    88"""
    99
    10 from zope.interface import implements
     10from __future__ import division, absolute_import
     11
     12from zope.interface import implementer
    1113
    1214from twisted.internet import defer, protocol
     
    8789
    8890
     91@implementer(IDisco)
    8992class VersionHandler(XMPPHandler):
    9093    """
     
    9497    U{XEP-0092<http://xmpp.org/extensions/xep-0092.html>}.
    9598    """
    96 
    97     implements(IDisco)
    9899
    99100    def __init__(self, name, version):
     
    114115        iq.handled = True
    115116
    116     def getDiscoInfo(self, requestor, target, node):
     117    def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
    117118        info = set()
    118119
    119         if not node:
     120        if not nodeIdentifier:
    120121            from wokkel import disco
    121122            info.add(disco.DiscoFeature(NS_VERSION))
     
    123124        return defer.succeed(info)
    124125
    125     def getDiscoItems(self, requestor, target, node):
     126    def getDiscoItems(self, requestor, target, nodeIdentifier=''):
    126127        return defer.succeed([])
    127128
  • wokkel/iwokkel.py

    r166 r193  
    88"""
    99
    10 __all__ = ['IXMPPHandler', 'IXMPPHandlerCollection',
    11            'IPubSubClient', 'IPubSubService', 'IPubSubResource',
    12            'IMUCClient', 'IMUCStatuses']
     10from __future__ import division, absolute_import
    1311
    1412from zope.interface import Interface
     
    983981        Return the number of status conditions.
    984982        """
     983
     984
     985
     986__all__ = ['IXMPPHandler', 'IXMPPHandlerCollection',
     987           'IPubSubClient', 'IPubSubService', 'IPubSubResource',
     988           'IMUCClient', 'IMUCStatuses']
  • wokkel/muc.py

    r217 r219  
    1010U{XEP-0045<http://xmpp.org/extensions/xep-0045.html>}.
    1111"""
     12
     13from __future__ import division, absolute_import
     14
    1215from dateutil.tz import tzutc
    1316
    14 from zope.interface import implements
     17from zope.interface import implementer
    1518
    1619from twisted.internet import defer
     20from twisted.python.compat import unicode
     21from twisted.python.constants import Values, ValueConstant
    1722from twisted.words.protocols.jabber import jid, error, xmlstream
    1823from twisted.words.xish import domish
    1924
    2025from wokkel import data_form, generic, iwokkel, xmppim
    21 from wokkel.compat import Values, ValueConstant
    2226from wokkel.delay import Delay, DelayMixin
    2327from wokkel.subprotocols import XMPPHandler
     
    6569
    6670
     71@implementer(iwokkel.IMUCStatuses)
    6772class Statuses(set):
    6873    """
     
    7277    L{STATUS_CODE}. Instances of this class provide L{IMUCStatuses}, that
    7378    defines the supported operations. Even though this class currently derives
    74     from C{set}, future versions might not. This provides an upgrade path to
     79    from L{set}, future versions might not. This provides an upgrade path to
    7580    cater for extensible status conditions, as defined in
    7681    U{XEP-0306<http://xmpp.org/extensions/xep-0306.html>}.
    7782    """
    78     implements(iwokkel.IMUCStatuses)
    7983
    8084
     
    225229
    226230    @param reason: Optional reason for the destruction of this room.
    227     @type reason: C{unicode}.
     231    @type reason: L{unicode}.
    228232
    229233    @param alternate: Optional room JID of an alternate venue.
     
    231235
    232236    @param password: Optional password for entering the alternate venue.
    233     @type password: C{unicode}
     237    @type password: L{unicode}
    234238    """
    235239
     
    274278        Render into a domish Element.
    275279
    276         @param legacyDelay: If C{True} send the delayed delivery information
     280        @param legacyDelay: If L{True} send the delayed delivery information
    277281        in legacy format.
    278282        """
     
    324328        (where the character count is the characters of the complete XML
    325329        stanzas, not only their XML character data).
    326     @type maxchars: C{int}
     330    @type maxchars: L{int}
    327331
    328332    @ivar maxstanzas: Limit the total number of messages in the history to "X".
    329     @type mazstanzas: C{int}
     333    @type mazstanzas: L{int}
    330334
    331335    @ivar seconds: Send only the messages received in the last "X" seconds.
    332     @type seconds: C{int}
     336    @type seconds: L{int}
    333337
    334338    @ivar since: Send only the messages received since the datetime specified.
     
    392396
    393397    @ivar affiliation: Affiliation of the entity to the room.
    394     @type affiliation: C{unicode}
     398    @type affiliation: L{unicode}
    395399
    396400    @ivar role: Role of the entity in the room.
    397     @type role: C{unicode}
     401    @type role: L{unicode}
    398402
    399403    @ivar entity: The real JID of the entity this presence is from.
     
    405409
    406410    @ivar nick: The nick name of the entity in the room.
    407     @type nick: C{unicode}
     411    @type nick: L{unicode}
    408412    """
    409413
     
    546550        @param timeout: The number of seconds to wait before the deferred is
    547551            timed out.
    548         @type timeout: C{int}
     552        @type timeout: L{int}
    549553
    550554        The deferred object L{defer.Deferred} is returned.
     
    592596
    593597        @param nick: The nick name for the entitity joining the room.
    594         @type nick: C{unicode}
     598        @type nick: L{unicode}
    595599
    596600        @param historyOptions: Options for conversation history sent by the
     
    599603
    600604        @param password: Optional password for the room.
    601         @type password: C{unicode}
     605        @type password: L{unicode}
    602606
    603607        @return: A deferred that fires when the entity is in the room or an
     
    625629
    626630        @param nick: The new nick name within the room.
    627         @type nick: C{unicode}
     631        @type nick: L{unicode}
    628632        """
    629633        occupantJID = jid.JID(tuple=(roomJID.user, roomJID.host, nick))
     
    643647        @param show: The availability of the entity. Common values are xa,
    644648            available, etc
    645         @type show: C{unicode}
     649        @type show: L{unicode}
    646650
    647651        @param status: The current status of the entity.
    648         @type status: C{unicode}
     652        @type status: L{unicode}
    649653        """
    650654        occupantJID = self._roomOccupantMap[roomJID]
     
    701705
    702706        @param subject: The subject you want to set.
    703         @type subject: C{unicode}
     707        @type subject: L{unicode}
    704708        """
    705709        message = GroupChat(roomJID.userhostJID(), subject=subject)
     
    720724
    721725        @param reason: The reason for the invite.
    722         @type reason: C{unicode}
     726        @type reason: L{unicode}
    723727        """
    724728        message = InviteMessage(recipient=roomJID, invitee=invitee,
     
    752756        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    753757
    754         @param options: A mapping of field names to values, or C{None} to
     758        @param options: A mapping of field names to values, or L{None} to
    755759            cancel.
    756         @type options: C{dict}
     760        @type options: L{dict}
    757761        """
    758762        if options is None:
     
    784788        @param messages: The history to send to the room as an ordered list of
    785789                         message, represented by a dictionary with the keys
    786                          C{'stanza'}, holding the original stanza a
    787                          L{domish.Element}, and C{'timestamp'} with the
     790                         L{'stanza'}, holding the original stanza a
     791                         L{domish.Element}, and L{'timestamp'} with the
    788792                         timestamp.
    789         @type messages: C{list} of L{domish.Element}
     793        @type messages: L{list} of L{domish.Element}
    790794        """
    791795
     
    819823
    820824        @return: A deferred that fires with the room's configuration form as
    821             a L{data_form.Form} or C{None} if there are no configuration
     825            a L{data_form.Form} or L{None} if there are no configuration
    822826            options available.
    823827        """
     
    839843        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    840844
    841         @param options: A mapping of field names to values, or C{None} to
     845        @param options: A mapping of field names to values, or L{None} to
    842846            cancel.
    843         @type options: C{dict}
     847        @type options: L{dict}
    844848        """
    845849        if options is None:
     
    963967
    964968        @param entities: The list of entities to change for a room.
    965         @type entities: C{list} of
     969        @type entities: L{list} of
    966970            L{JID<twisted.words.protocols.jabber.jid.JID>}
    967971
    968972        @param affiliation: The affilation to the entities will acquire.
    969         @type affiliation: C{unicode}
     973        @type affiliation: L{unicode}
    970974
    971975        @param sender: The entity sending the request.
     
    989993
    990994        @param nick: The nick name for the user in this room.
    991         @type nick: C{unicode}
     995        @type nick: L{unicode}
    992996
    993997        @param reason: The reason for granting voice to the entity.
    994         @type reason: C{unicode}
     998        @type reason: L{unicode}
    995999
    9961000        @param sender: The entity sending the request.
     
    10121016
    10131017        @param nick: The nick name for the user in this room.
    1014         @type nick: C{unicode}
     1018        @type nick: L{unicode}
    10151019
    10161020        @param reason: The reason for revoking voice from the entity.
    1017         @type reason: C{unicode}
     1021        @type reason: L{unicode}
    10181022
    10191023        @param sender: The entity sending the request.
     
    10321036
    10331037        @param nick: The nick name for the user in this room.
    1034         @type nick: C{unicode}
     1038        @type nick: L{unicode}
    10351039
    10361040        @param reason: The reason for granting moderation to the entity.
    1037         @type reason: C{unicode}
     1041        @type reason: L{unicode}
    10381042
    10391043        @param sender: The entity sending the request.
     
    10551059
    10561060        @param reason: The reason for banning the entity.
    1057         @type reason: C{unicode}
     1061        @type reason: L{unicode}
    10581062
    10591063        @param sender: The entity sending the request.
     
    10721076
    10731077        @param nick: The occupant to be banned.
    1074         @type nick: C{unicode}
     1078        @type nick: L{unicode}
    10751079
    10761080        @param reason: The reason given for the kick.
    1077         @type reason: C{unicode}
     1081        @type reason: L{unicode}
    10781082
    10791083        @param sender: The entity sending the request.
     
    10921096
    10931097        @param reason: The reason for the destruction of the room.
    1094         @type reason: C{unicode}
     1098        @type reason: L{unicode}
    10951099
    10961100        @param alternate: The JID of the room suggested as an alternate venue.
     
    11321136
    11331137    @ivar nick: The nick name for the client in this room.
    1134     @type nick: C{unicode}
     1138    @type nick: L{unicode}
    11351139
    11361140    @ivar occupantJID: The JID of the occupant in the room. Generated from
     
    11421146        L{MUCClientProtocol.getConfiguration} and
    11431147        L{MUCClientProtocol.configure}.
    1144     @type locked: C{bool}
     1148    @type locked: L{bool}
    11451149    """
    11461150
     
    11871191
    11881192        @param nick: The nick for the user in the MUC room.
    1189         @type nick: C{unicode}
     1193        @type nick: L{unicode}
    11901194        """
    11911195        return self.roster.get(nick)
     
    12041208
    12051209
     1210@implementer(IMUCClient)
    12061211class MUCClient(MUCClientProtocol):
    12071212    """
     
    12131218                  room. Note that a particular entity can only join a room once
    12141219                  at a time.
    1215     @type _rooms: C{dict}
    1216     """
    1217 
    1218     implements(IMUCClient)
     1220    @type _rooms: L{dict}
     1221    """
    12191222
    12201223    def __init__(self, reactor=None):
     
    14021405        @type room: L{Room}
    14031406
    1404         @param user: The user that sent the message, or C{None} if it was a
     1407        @param user: The user that sent the message, or L{None} if it was a
    14051408            message from the room itself.
    14061409        @type user: L{User}
     
    14231426        @type room: L{Room}
    14241427
    1425         @param user: The user that sent the message, or C{None} if it was a
     1428        @param user: The user that sent the message, or L{None} if it was a
    14261429            message from the room itself.
    14271430        @type user: L{User}
     
    14421445
    14431446        @param nick: The nick name for the entitity joining the room.
    1444         @type nick: C{unicode}
     1447        @type nick: L{unicode}
    14451448
    14461449        @param historyOptions: Options for conversation history sent by the
     
    14491452
    14501453        @param password: Optional password for the room.
    1451         @type password: C{unicode}
     1454        @type password: L{unicode}
    14521455
    14531456        @return: A deferred that fires with the room when the entity is in the
     
    14861489
    14871490        @param nick: The new nick name within the room.
    1488         @type nick: C{unicode}
     1491        @type nick: L{unicode}
    14891492        """
    14901493        def cb(presence):
     
    15281531        @param show: The availability of the entity. Common values are xa,
    15291532            available, etc
    1530         @type show: C{unicode}
     1533        @type show: L{unicode}
    15311534
    15321535        @param status: The current status of the entity.
    1533         @type status: C{unicode}
     1536        @type status: L{unicode}
    15341537        """
    15351538        room = self._getRoom(roomJID)
     
    15471550
    15481551        @param reason: The reason for the destruction of the room.
    1549         @type reason: C{unicode}
     1552        @type reason: L{unicode}
    15501553
    15511554        @param alternate: The JID of the room suggested as an alternate venue.
  • wokkel/ping.py

    r166 r199  
    1111"""
    1212
    13 from zope.interface import implements
     13from __future__ import division, absolute_import
     14
     15from zope.interface import implementer
    1416
    1517from twisted.words.protocols.jabber.error import StanzaError
     
    5759
    5860        if sender is not None:
    59             request['from'] = unicode(sender)
     61            request['from'] = sender.full()
    6062
    6163        d = request.send(entity.full())
     
    6567
    6668
     69@implementer(iwokkel.IDisco)
    6770class PingHandler(XMPPHandler):
    6871    """
     
    7174    This handler waits for XMPP Ping requests and sends a response.
    7275    """
    73 
    74     implements(iwokkel.IDisco)
    7576
    7677    def connectionInitialized(self):
  • wokkel/pubsub.py

    r166 r212  
    1111"""
    1212
    13 from zope.interface import implements
     13from __future__ import division, absolute_import
     14
     15from zope.interface import implementer
    1416
    1517from twisted.internet import defer
    1618from twisted.python import log
     19from twisted.python.compat import StringType, iteritems, unicode
    1720from twisted.words.protocols.jabber import jid, error
    1821from twisted.words.xish import domish
     
    104107
    105108    @ivar nodeIdentifier: The identifier of the node subscribed to.  The root
    106         node is denoted by C{None}.
    107     @type nodeIdentifier: C{unicode}
     109        node is denoted by L{None}.
     110    @type nodeIdentifier: L{unicode}
    108111
    109112    @ivar subscriber: The subscribing entity.
     
    112115    @ivar state: The subscription state. One of C{'subscribed'}, C{'pending'},
    113116                 C{'unconfigured'}.
    114     @type state: C{unicode}
     117    @type state: L{unicode}
    115118
    116119    @ivar options: Optional list of subscription options.
    117     @type options: C{dict}
     120    @type options: L{dict}
    118121
    119122    @ivar subscriptionIdentifier: Optional subscription identifier.
    120     @type subscriptionIdentifier: C{unicode}
     123    @type subscriptionIdentifier: L{unicode}
    121124    """
    122125
     
    169172        """
    170173        @param id: optional item identifier
    171         @type id: C{unicode}
     174        @type id: L{unicode}
    172175        @param payload: optional item payload. Either as a domish element, or
    173176                        as serialized XML.
    174         @type payload: object providing L{domish.IElement} or C{unicode}.
     177        @type payload: object providing L{domish.IElement} or L{unicode}.
    175178        """
    176179
     
    179182            self['id'] = id
    180183        if payload is not None:
    181             if isinstance(payload, basestring):
     184            if isinstance(payload, StringType):
    182185                self.addRawXml(payload)
    183186            else:
     
    192195    The set of instance variables used depends on the type of request. If
    193196    a variable is not applicable or not passed in the request, its value is
    194     C{None}.
     197    L{None}.
    195198
    196199    @ivar verb: The type of publish-subscribe request. See C{_requestVerbMap}.
    197     @type verb: C{str}.
     200    @type verb: L{str}.
    198201
    199202    @ivar affiliations: Affiliations to be modified.
    200     @type affiliations: C{set}
     203    @type affiliations: L{set}
    201204
    202205    @ivar items: The items to be published, as L{domish.Element}s.
    203     @type items: C{list}
     206    @type items: L{list}
    204207
    205208    @ivar itemIdentifiers: Identifiers of the items to be retrieved or
    206209                           retracted.
    207     @type itemIdentifiers: C{set}
     210    @type itemIdentifiers: L{set}
    208211
    209212    @ivar maxItems: Maximum number of items to retrieve.
    210     @type maxItems: C{int}.
     213    @type maxItems: L{int}.
    211214
    212215    @ivar nodeIdentifier: Identifier of the node the request is about.
    213     @type nodeIdentifier: C{unicode}
     216    @type nodeIdentifier: L{unicode}
    214217
    215218    @ivar nodeType: The type of node that should be created, or for which the
    216219                    configuration is retrieved. C{'leaf'} or C{'collection'}.
    217     @type nodeType: C{str}
     220    @type nodeType: L{str}
    218221
    219222    @ivar options: Configurations options for nodes, subscriptions and publish
     
    225228
    226229    @ivar subscriptionIdentifier: Identifier for a specific subscription.
    227     @type subscriptionIdentifier: C{unicode}
     230    @type subscriptionIdentifier: L{unicode}
    228231
    229232    @ivar subscriptions: Subscriptions to be modified, as a set of
    230233        L{Subscription}.
    231     @type subscriptions: C{set}
     234    @type subscriptions: L{set}
    232235
    233236    @ivar affiliations: Affiliations to be modified, as a dictionary of entity
    234237        (L{JID<twisted.words.protocols.jabber.jid.JID>} to affiliation
    235         (C{unicode}).
    236     @type affiliations: C{dict}
     238        (L{unicode}).
     239    @type affiliations: L{dict}
    237240    """
    238241
     
    275278
    276279    # Map request verb to request iq type and subelement name
    277     _verbRequestMap = dict(((v, k) for k, v in _requestVerbMap.iteritems()))
     280    _verbRequestMap = dict(((v, k) for k, v in iteritems(_requestVerbMap)))
    278281
    279282    # Map request verb to parameter handler names
     
    646649    @type recipient: L{wokkel.pubsub.ItemsEvent}
    647650    @param nodeIdentifier: Identifier of the node the event pertains to.
    648     @type nodeIdentifier: C{unicode}
     651    @type nodeIdentifier: L{unicode}
    649652    @param headers: SHIM headers, see L{wokkel.shim.extractHeaders}.
    650     @type headers: C{dict}
     653    @type headers: L{dict}
    651654    """
    652655
     
    664667
    665668    @param items: List of received items as domish elements.
    666     @type items: C{list} of L{domish.Element}
     669    @type items: L{list} of L{domish.Element}
    667670    """
    668671
     
    689692
    690693
     694@implementer(IPubSubClient)
    691695class PubSubClient(XMPPHandler):
    692696    """
    693697    Publish subscribe client protocol.
    694698    """
    695 
    696     implements(IPubSubClient)
    697699
    698700    def connectionInitialized(self):
     
    771773        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    772774        @param nodeIdentifier: Optional suggestion for the id of the node.
    773         @type nodeIdentifier: C{unicode}
     775        @type nodeIdentifier: L{unicode}
    774776        @param options: Optional node configuration options.
    775         @type options: C{dict}
     777        @type options: L{dict}
    776778        """
    777779        request = PubSubRequest('create')
     
    806808        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    807809        @param nodeIdentifier: The identifier of the node.
    808         @type nodeIdentifier: C{unicode}
     810        @type nodeIdentifier: L{unicode}
    809811        """
    810812        request = PubSubRequest('delete')
     
    824826
    825827        @param nodeIdentifier: The identifier of the node.
    826         @type nodeIdentifier: C{unicode}
     828        @type nodeIdentifier: L{unicode}
    827829
    828830        @param subscriber: The entity to subscribe to the node. This entity
     
    831833
    832834        @param options: Subscription options.
    833         @type options: C{dict}
     835        @type options: L{dict}
    834836
    835837        @return: Deferred that fires with L{Subscription} or errbacks with
     
    876878
    877879        @param nodeIdentifier: The identifier of the node.
    878         @type nodeIdentifier: C{unicode}
     880        @type nodeIdentifier: L{unicode}
    879881
    880882        @param subscriber: The entity to unsubscribe from the node.
     
    882884
    883885        @param subscriptionIdentifier: Optional subscription identifier.
    884         @type subscriptionIdentifier: C{unicode}
     886        @type subscriptionIdentifier: L{unicode}
    885887        """
    886888        request = PubSubRequest('unsubscribe')
     
    900902        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    901903        @param nodeIdentifier: The identifier of the node.
    902         @type nodeIdentifier: C{unicode}
     904        @type nodeIdentifier: L{unicode}
    903905        @param items: Optional list of L{Item}s to publish.
    904         @type items: C{list}
     906        @type items: L{list}
    905907        """
    906908        request = PubSubRequest('publish')
     
    921923
    922924        @param nodeIdentifier: The identifier of the node.
    923         @type nodeIdentifier: C{unicode}
     925        @type nodeIdentifier: L{unicode}
    924926
    925927        @param maxItems: Optional limit on the number of retrieved items.
    926         @type maxItems: C{int}
     928        @type maxItems: L{int}
    927929
    928930        @param subscriptionIdentifier: Optional subscription identifier. In
    929931            case the node has been subscribed to multiple times, this narrows
    930932            the results to the specific subscription.
    931         @type subscriptionIdentifier: C{unicode}
     933        @type subscriptionIdentifier: L{unicode}
    932934        """
    933935        request = PubSubRequest('items')
     
    960962
    961963        @param nodeIdentifier: The identifier of the node.
    962         @type nodeIdentifier: C{unicode}
     964        @type nodeIdentifier: L{unicode}
    963965
    964966        @param subscriber: The entity subscribed to the node.
     
    966968
    967969        @param subscriptionIdentifier: Optional subscription identifier.
    968         @type subscriptionIdentifier: C{unicode}
     970        @type subscriptionIdentifier: L{unicode}
    969971
    970972        @rtype: L{data_form.Form}
     
    997999
    9981000        @param nodeIdentifier: The identifier of the node.
    999         @type nodeIdentifier: C{unicode}
     1001        @type nodeIdentifier: L{unicode}
    10001002
    10011003        @param subscriber: The entity subscribed to the node.
     
    10031005
    10041006        @param options: Subscription options.
    1005         @type options: C{dict}.
     1007        @type options: L{dict}.
    10061008
    10071009        @param subscriptionIdentifier: Optional subscription identifier.
    1008         @type subscriptionIdentifier: C{unicode}
     1010        @type subscriptionIdentifier: L{unicode}
    10091011        """
    10101012        request = PubSubRequest('optionsSet')
     
    10251027
    10261028
     1029@implementer(IPubSubService, disco.IDisco)
    10271030class PubSubService(XMPPHandler, IQHandlerMixin):
    10281031    """
     
    10491052                         keys C{'category'}, C{'type'} and C{'name'}.
    10501053    @ivar pubSubFeatures: List of supported publish-subscribe features for
    1051                           service discovery, as C{str}.
    1052     @type pubSubFeatures: C{list} or C{None}
    1053     """
    1054 
    1055     implements(IPubSubService, disco.IDisco)
     1054                          service discovery, as L{str}.
     1055    @type pubSubFeatures: L{list} or L{None}
     1056    """
    10561057
    10571058    iqHandlers = {
     
    13521353            affiliations['node'] = request.nodeIdentifier
    13531354
    1354         for entity, affiliation in result.iteritems():
     1355        for entity, affiliation in iteritems(result):
    13551356            item = affiliations.addElement('affiliation')
    13561357            item['jid'] = entity.full()
     
    14511452
    14521453
     1454@implementer(IPubSubResource)
    14531455class PubSubResource(object):
    1454 
    1455     implements(IPubSubResource)
    14561456
    14571457    features = []
  • wokkel/server.py

    r184 r206  
    1212"""
    1313
    14 # hashlib is new in Python 2.5, try that first.
    15 try:
    16     from hashlib import sha256
    17     digestmod = sha256
    18 except ImportError:
    19     import Crypto.Hash.SHA256 as digestmod
    20     sha256 = digestmod.new
    21 
     14from __future__ import division, absolute_import
     15
     16import binascii
     17from hashlib import sha256
    2218import hmac
    2319
    24 from zope.interface import implements
     20from zope.interface import implementer
    2521
    2622from twisted.internet import defer, reactor
    2723from twisted.names.srvconnect import SRVConnector
    2824from twisted.python import log, randbytes
     25from twisted.python.compat import iteritems, unicode
    2926from twisted.words.protocols.jabber import error, ijabber, jid, xmlstream
    3027from twisted.words.xish import domish
     
    4441    @param secret: the shared secret known to the Originating Server and
    4542                   Authoritive Server.
    46     @type secret: C{str}
     43    @type secret: L{unicode}
    4744    @param receivingServer: the Receiving Server host name.
    48     @type receivingServer: C{str}
     45    @type receivingServer: L{unicode}
    4946    @param originatingServer: the Originating Server host name.
    50     @type originatingServer: C{str}
     47    @type originatingServer: L{unicode}
    5148    @param streamID: the Stream ID as generated by the Receiving Server.
    52     @type streamID: C{str}
     49    @type streamID: L{unicode}
    5350    @return: hexadecimal digest of the generated key.
    5451    @type: C{str}
     
    5653
    5754    hashObject = sha256()
    58     hashObject.update(secret)
     55    hashObject.update(secret.encode('ascii'))
    5956    hashedSecret = hashObject.hexdigest()
    6057    message = " ".join([receivingServer, originatingServer, streamID])
    61     hash = hmac.HMAC(hashedSecret, message, digestmod=digestmod)
     58    hash = hmac.HMAC(hashedSecret.encode('ascii'),
     59                     message.encode('ascii'),
     60                     digestmod=sha256)
    6261    return hash.hexdigest()
    6362
     
    7877        try:
    7978            observer(element)
    80         except error.StreamError, exc:
     79        except error.StreamError as exc:
    8180            xs.sendStreamError(exc)
    8281        except:
     
    108107
    109108
     109@implementer(ijabber.IInitiatingInitializer)
    110110class OriginatingDialbackInitializer(object):
    111111    """
    112112    Server Dialback Initializer for the Orginating Server.
    113113    """
    114 
    115     implements(ijabber.IInitiatingInitializer)
    116114
    117115    _deferred = None
     
    161159
    162160
     161@implementer(ijabber.IInitiatingInitializer)
    163162class ReceivingDialbackInitializer(object):
    164163    """
    165164    Server Dialback Initializer for the Receiving Server.
    166165    """
    167 
    168     implements(ijabber.IInitiatingInitializer)
    169166
    170167    _deferred = None
     
    329326        xmlstream.ListenAuthenticator.streamStarted(self, rootElement)
    330327
    331         # Compatibility fix for pre-8.2 implementations of ListenAuthenticator
    332         if not self.xmlstream.sid:
    333             self.xmlstream.sid = randbytes.secureRandom(8).encode('hex')
    334 
    335328        if self.xmlstream.thisEntity:
    336329            targetDomain = self.xmlstream.thisEntity.host
     
    348341            if xmlstream.NS_STREAMS != rootElement.uri or \
    349342               self.namespace != self.xmlstream.namespace or \
    350                ('db', NS_DIALBACK) not in rootElement.localPrefixes.iteritems():
     343               ('db', NS_DIALBACK) not in iteritems(rootElement.localPrefixes):
    351344                raise error.StreamError('invalid-namespace')
    352345
    353346            if targetDomain and targetDomain not in self.service.domains:
    354347                raise error.StreamError('host-unknown')
    355         except error.StreamError, exc:
     348        except error.StreamError as exc:
    356349            prepareStream(self.service.defaultDomain)
    357350            self.xmlstream.sendStreamError(exc)
     
    576569            self.secret = secret
    577570        else:
    578             self.secret = randbytes.secureRandom(16).encode('hex')
     571            self.secret = binascii.hexlify(randbytes.secureRandom(16))
    579572
    580573        self._outgoingStreams = {}
  • wokkel/shim.py

    r165 r201  
    1111"""
    1212
     13from __future__ import division, absolute_import
     14
     15from twisted.python.compat import unicode
    1316from twisted.words.xish import domish
    1417
  • wokkel/subprotocols.py

    r166 r194  
    88"""
    99
    10 __all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager',
    11            'IQHandlerMixin']
    12 
    13 from zope.interface import implements
     10from __future__ import division, absolute_import
     11
     12from zope.interface import implementer
    1413
    1514from twisted.internet import defer
    1615from twisted.internet.error import ConnectionDone
    1716from twisted.python import failure, log
     17from twisted.python.compat import iteritems, itervalues
    1818from twisted.python.deprecate import deprecatedModuleAttribute
    1919from twisted.python.versions import Version
     
    3131        "XMPPHandlerCollection")
    3232
     33@implementer(ijabber.IXMPPHandler)
    3334class XMPPHandler(object):
    3435    """
     
    3839    extension protocols, and are referred to as a subprotocol implementation.
    3940    """
    40 
    41     implements(ijabber.IXMPPHandler)
    4241
    4342    def __init__(self):
     
    278277        iqDeferreds = self._iqDeferreds
    279278        self._iqDeferreds = {}
    280         for d in iqDeferreds.itervalues():
     279        for d in itervalues(iqDeferreds):
    281280            d.errback(reason)
    282281
     
    456455
    457456        handler = None
    458         for queryString, method in self.iqHandlers.iteritems():
     457        for queryString, method in iteritems(self.iqHandlers):
    459458            if xpath.internQuery(queryString).matches(iq):
    460459                handler = getattr(self, method)
     
    473472
    474473        iq.handled = True
     474
     475
     476
     477__all__ = ['XMPPHandler', 'XMPPHandlerCollection', 'StreamManager',
     478           'IQHandlerMixin']
  • wokkel/test/helpers.py

    r186 r197  
    66"""
    77
     8from __future__ import division, absolute_import
     9
    810from twisted.internet import defer
     11from twisted.python.compat import iteritems
    912from twisted.words.xish import xpath
    1013from twisted.words.xish.utility import EventDispatcher
     
    3538        u'<presence/>'
    3639        >>> def cb(stanza):
    37         ...     print "Got: %r" stanza.toXml()
     40        ...     print("Got: %r" stanza.toXml())
    3841        >>> stub.xmlstream.addObserver('/presence')
    3942        >>> stub.send(domish.Element((None, 'presence')))
     
    8487        handler = None
    8588        iq = parseXml(xml)
    86         for queryString, method in self.service.iqHandlers.iteritems():
     89        for queryString, method in iteritems(self.service.iqHandlers):
    8790            if xpath.internQuery(queryString).matches(iq):
    8891                handler = getattr(self.service, method)
  • wokkel/test/test_client.py

    r178 r208  
    55Tests for L{wokkel.client}.
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from twisted.internet import defer
     
    151153        def cb(connector):
    152154            self.assertEqual('xmpp-client', connector.service)
    153             self.assertIsInstance(connector.domain, bytes)
    154             self.assertEqual(b'example.org', connector.domain)
     155            self.assertEqual('example.org', connector.domain)
    155156            self.assertEqual(factory, connector.factory)
    156157
  • wokkel/test/test_compat.py

    r165 r200  
    77"""
    88
    9 from zope.interface import implements
     9from __future__ import division, absolute_import
     10
     11from zope.interface import implementer
    1012from twisted.internet import task
    1113from twisted.internet.interfaces import IReactorTime
     
    1416
    1517from wokkel.compat import IQ
    16 from wokkel.compat import NamedConstant, Names, ValueConstant, Values
    1718
    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")
    59 
    60 
    61 
     19@implementer(IReactorTime)
    6220class FakeReactor(object):
    6321
    64     implements(IReactorTime)
    6522    def __init__(self):
    6623        self.clock = task.Clock()
     
    9855        self.assertFalse(xs.iqDeferreds)
    9956        return d
    100 
    101 
    102 
    103 class NamedConstantTests(unittest.TestCase):
    104     """
    105     Tests for the L{twisted.python.constants.NamedConstant} class which is used
    106     to represent individual values.
    107     """
    108     def setUp(self):
    109         """
    110         Create a dummy container into which constants can be placed.
    111         """
    112         class foo(Names):
    113             pass
    114         self.container = foo
    115 
    116 
    117     def test_name(self):
    118         """
    119         The C{name} attribute of a L{NamedConstant} refers to the value passed
    120         for the C{name} parameter to C{_realize}.
    121         """
    122         name = NamedConstant()
    123         name._realize(self.container, "bar", None)
    124         self.assertEqual("bar", name.name)
    125 
    126 
    127     def test_representation(self):
    128         """
    129         The string representation of an instance of L{NamedConstant} includes
    130         the container the instances belongs to as well as the instance's name.
    131         """
    132         name = NamedConstant()
    133         name._realize(self.container, "bar", None)
    134         self.assertEqual("<foo=bar>", repr(name))
    135 
    136 
    137     def test_equality(self):
    138         """
    139         A L{NamedConstant} instance compares equal to itself.
    140         """
    141         name = NamedConstant()
    142         name._realize(self.container, "bar", None)
    143         self.assertTrue(name == name)
    144         self.assertFalse(name != name)
    145 
    146 
    147     def test_nonequality(self):
    148         """
    149         Two different L{NamedConstant} instances do not compare equal to each
    150         other.
    151         """
    152         first = NamedConstant()
    153         first._realize(self.container, "bar", None)
    154         second = NamedConstant()
    155         second._realize(self.container, "bar", None)
    156         self.assertFalse(first == second)
    157         self.assertTrue(first != second)
    158 
    159 
    160     def test_hash(self):
    161         """
    162         Because two different L{NamedConstant} instances do not compare as equal
    163         to each other, they also have different hashes to avoid collisions when
    164         added to a C{dict} or C{set}.
    165         """
    166         first = NamedConstant()
    167         first._realize(self.container, "bar", None)
    168         second = NamedConstant()
    169         second._realize(self.container, "bar", None)
    170         self.assertNotEqual(hash(first), hash(second))
    171 
    172 
    173 
    174 class _ConstantsTestsMixin(object):
    175     """
    176     Mixin defining test helpers common to multiple types of constants
    177     collections.
    178     """
    179     def _notInstantiableTest(self, name, cls):
    180         """
    181         Assert that an attempt to instantiate the constants class raises
    182         C{TypeError}.
    183 
    184         @param name: A C{str} giving the name of the constants collection.
    185         @param cls: The constants class to test.
    186         """
    187         exc = self.assertRaises(TypeError, cls)
    188         self.assertEqual(name + " may not be instantiated.", str(exc))
    189 
    190 
    191 
    192 class NamesTests(unittest.TestCase, _ConstantsTestsMixin):
    193     """
    194     Tests for L{twisted.python.constants.Names}, a base class for containers of
    195     related constaints.
    196     """
    197     def setUp(self):
    198         """
    199         Create a fresh new L{Names} subclass for each unit test to use.  Since
    200         L{Names} is stateful, re-using the same subclass across test methods
    201         makes exercising all of the implementation code paths difficult.
    202         """
    203         class METHOD(Names):
    204             """
    205             A container for some named constants to use in unit tests for
    206             L{Names}.
    207             """
    208             GET = NamedConstant()
    209             PUT = NamedConstant()
    210             POST = NamedConstant()
    211             DELETE = NamedConstant()
    212 
    213         self.METHOD = METHOD
    214 
    215 
    216     def test_notInstantiable(self):
    217         """
    218         A subclass of L{Names} raises C{TypeError} if an attempt is made to
    219         instantiate it.
    220         """
    221         self._notInstantiableTest("METHOD", self.METHOD)
    222 
    223 
    224     def test_symbolicAttributes(self):
    225         """
    226         Each name associated with a L{NamedConstant} instance in the definition
    227         of a L{Names} subclass is available as an attribute on the resulting
    228         class.
    229         """
    230         self.assertTrue(hasattr(self.METHOD, "GET"))
    231         self.assertTrue(hasattr(self.METHOD, "PUT"))
    232         self.assertTrue(hasattr(self.METHOD, "POST"))
    233         self.assertTrue(hasattr(self.METHOD, "DELETE"))
    234 
    235 
    236     def test_withoutOtherAttributes(self):
    237         """
    238         As usual, names not defined in the class scope of a L{Names}
    239         subclass are not available as attributes on the resulting class.
    240         """
    241         self.assertFalse(hasattr(self.METHOD, "foo"))
    242 
    243 
    244     def test_representation(self):
    245         """
    246         The string representation of a constant on a L{Names} subclass includes
    247         the name of the L{Names} subclass and the name of the constant itself.
    248         """
    249         self.assertEqual("<METHOD=GET>", repr(self.METHOD.GET))
    250 
    251 
    252     def test_lookupByName(self):
    253         """
    254         Constants can be looked up by name using L{Names.lookupByName}.
    255         """
    256         method = self.METHOD.lookupByName("GET")
    257         self.assertIdentical(self.METHOD.GET, method)
    258 
    259 
    260     def test_notLookupMissingByName(self):
    261         """
    262         Names not defined with a L{NamedConstant} instance cannot be looked up
    263         using L{Names.lookupByName}.
    264         """
    265         self.assertRaises(ValueError, self.METHOD.lookupByName, "lookupByName")
    266         self.assertRaises(ValueError, self.METHOD.lookupByName, "__init__")
    267         self.assertRaises(ValueError, self.METHOD.lookupByName, "foo")
    268 
    269 
    270     def test_name(self):
    271         """
    272         The C{name} attribute of one of the named constants gives that
    273         constant's name.
    274         """
    275         self.assertEqual("GET", self.METHOD.GET.name)
    276 
    277 
    278     def test_attributeIdentity(self):
    279         """
    280         Repeated access of an attribute associated with a L{NamedConstant} value
    281         in a L{Names} subclass results in the same object.
    282         """
    283         self.assertIdentical(self.METHOD.GET, self.METHOD.GET)
    284 
    285 
    286     def test_iterconstants(self):
    287         """
    288         L{Names.iterconstants} returns an iterator over all of the constants
    289         defined in the class, in the order they were defined.
    290         """
    291         constants = list(self.METHOD.iterconstants())
    292         self.assertEqual(
    293             [self.METHOD.GET, self.METHOD.PUT,
    294              self.METHOD.POST, self.METHOD.DELETE],
    295             constants)
    296 
    297 
    298     def test_attributeIterconstantsIdentity(self):
    299         """
    300         The constants returned from L{Names.iterconstants} are identical to the
    301         constants accessible using attributes.
    302         """
    303         constants = list(self.METHOD.iterconstants())
    304         self.assertIdentical(self.METHOD.GET, constants[0])
    305         self.assertIdentical(self.METHOD.PUT, constants[1])
    306         self.assertIdentical(self.METHOD.POST, constants[2])
    307         self.assertIdentical(self.METHOD.DELETE, constants[3])
    308 
    309 
    310     def test_iterconstantsIdentity(self):
    311         """
    312         The constants returned from L{Names.iterconstants} are identical on each
    313         call to that method.
    314         """
    315         constants = list(self.METHOD.iterconstants())
    316         again = list(self.METHOD.iterconstants())
    317         self.assertIdentical(again[0], constants[0])
    318         self.assertIdentical(again[1], constants[1])
    319         self.assertIdentical(again[2], constants[2])
    320         self.assertIdentical(again[3], constants[3])
    321 
    322 
    323     def test_initializedOnce(self):
    324         """
    325         L{Names._enumerants} is initialized once and its value re-used on
    326         subsequent access.
    327         """
    328         first = self.METHOD._enumerants
    329         self.METHOD.GET # Side-effects!
    330         second = self.METHOD._enumerants
    331         self.assertIdentical(first, second)
    332 
    333 
    334 
    335 class ValuesTests(unittest.TestCase, _ConstantsTestsMixin):
    336     """
    337     Tests for L{twisted.python.constants.Names}, a base class for containers of
    338     related constaints with arbitrary values.
    339     """
    340     def setUp(self):
    341         """
    342         Create a fresh new L{Values} subclass for each unit test to use.  Since
    343         L{Values} is stateful, re-using the same subclass across test methods
    344         makes exercising all of the implementation code paths difficult.
    345         """
    346         class STATUS(Values):
    347             OK = ValueConstant("200")
    348             NOT_FOUND = ValueConstant("404")
    349 
    350         self.STATUS = STATUS
    351 
    352 
    353     def test_notInstantiable(self):
    354         """
    355         A subclass of L{Values} raises C{TypeError} if an attempt is made to
    356         instantiate it.
    357         """
    358         self._notInstantiableTest("STATUS", self.STATUS)
    359 
    360 
    361     def test_symbolicAttributes(self):
    362         """
    363         Each name associated with a L{ValueConstant} instance in the definition
    364         of a L{Values} subclass is available as an attribute on the resulting
    365         class.
    366         """
    367         self.assertTrue(hasattr(self.STATUS, "OK"))
    368         self.assertTrue(hasattr(self.STATUS, "NOT_FOUND"))
    369 
    370 
    371     def test_withoutOtherAttributes(self):
    372         """
    373         As usual, names not defined in the class scope of a L{Values}
    374         subclass are not available as attributes on the resulting class.
    375         """
    376         self.assertFalse(hasattr(self.STATUS, "foo"))
    377 
    378 
    379     def test_representation(self):
    380         """
    381         The string representation of a constant on a L{Values} subclass includes
    382         the name of the L{Values} subclass and the name of the constant itself.
    383         """
    384         self.assertEqual("<STATUS=OK>", repr(self.STATUS.OK))
    385 
    386 
    387     def test_lookupByName(self):
    388         """
    389         Constants can be looked up by name using L{Values.lookupByName}.
    390         """
    391         method = self.STATUS.lookupByName("OK")
    392         self.assertIdentical(self.STATUS.OK, method)
    393 
    394 
    395     def test_notLookupMissingByName(self):
    396         """
    397         Names not defined with a L{ValueConstant} instance cannot be looked up
    398         using L{Values.lookupByName}.
    399         """
    400         self.assertRaises(ValueError, self.STATUS.lookupByName, "lookupByName")
    401         self.assertRaises(ValueError, self.STATUS.lookupByName, "__init__")
    402         self.assertRaises(ValueError, self.STATUS.lookupByName, "foo")
    403 
    404 
    405     def test_lookupByValue(self):
    406         """
    407         Constants can be looked up by their associated value, defined by the
    408         argument passed to L{ValueConstant}, using L{Values.lookupByValue}.
    409         """
    410         status = self.STATUS.lookupByValue("200")
    411         self.assertIdentical(self.STATUS.OK, status)
    412 
    413 
    414     def test_lookupDuplicateByValue(self):
    415         """
    416         If more than one constant is associated with a particular value,
    417         L{Values.lookupByValue} returns whichever of them is defined first.
    418         """
    419         class TRANSPORT_MESSAGE(Values):
    420             """
    421             Message types supported by an SSH transport.
    422             """
    423             KEX_DH_GEX_REQUEST_OLD = ValueConstant(30)
    424             KEXDH_INIT = ValueConstant(30)
    425 
    426         self.assertIdentical(
    427             TRANSPORT_MESSAGE.lookupByValue(30),
    428             TRANSPORT_MESSAGE.KEX_DH_GEX_REQUEST_OLD)
    429 
    430 
    431     def test_notLookupMissingByValue(self):
    432         """
    433         L{Values.lookupByValue} raises L{ValueError} when called with a value
    434         with which no constant is associated.
    435         """
    436         self.assertRaises(ValueError, self.STATUS.lookupByValue, "OK")
    437         self.assertRaises(ValueError, self.STATUS.lookupByValue, 200)
    438         self.assertRaises(ValueError, self.STATUS.lookupByValue, "200.1")
    439 
    440 
    441     def test_name(self):
    442         """
    443         The C{name} attribute of one of the constants gives that constant's
    444         name.
    445         """
    446         self.assertEqual("OK", self.STATUS.OK.name)
    447 
    448 
    449     def test_attributeIdentity(self):
    450         """
    451         Repeated access of an attribute associated with a L{ValueConstant} value
    452         in a L{Values} subclass results in the same object.
    453         """
    454         self.assertIdentical(self.STATUS.OK, self.STATUS.OK)
    455 
    456 
    457     def test_iterconstants(self):
    458         """
    459         L{Values.iterconstants} returns an iterator over all of the constants
    460         defined in the class, in the order they were defined.
    461         """
    462         constants = list(self.STATUS.iterconstants())
    463         self.assertEqual(
    464             [self.STATUS.OK, self.STATUS.NOT_FOUND],
    465             constants)
    466 
    467 
    468     def test_attributeIterconstantsIdentity(self):
    469         """
    470         The constants returned from L{Values.iterconstants} are identical to the
    471         constants accessible using attributes.
    472         """
    473         constants = list(self.STATUS.iterconstants())
    474         self.assertIdentical(self.STATUS.OK, constants[0])
    475         self.assertIdentical(self.STATUS.NOT_FOUND, constants[1])
    476 
    477 
    478     def test_iterconstantsIdentity(self):
    479         """
    480         The constants returned from L{Values.iterconstants} are identical on
    481         each call to that method.
    482         """
    483         constants = list(self.STATUS.iterconstants())
    484         again = list(self.STATUS.iterconstants())
    485         self.assertIdentical(again[0], constants[0])
    486         self.assertIdentical(again[1], constants[1])
    487 
    488 
    489     def test_initializedOnce(self):
    490         """
    491         L{Values._enumerants} is initialized once and its value re-used on
    492         subsequent access.
    493         """
    494         first = self.STATUS._enumerants
    495         self.STATUS.OK # Side-effects!
    496         second = self.STATUS._enumerants
    497         self.assertIdentical(first, second)
  • wokkel/test/test_component.py

    r169 r205  
    55Tests for L{wokkel.component}.
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from zope.interface.verify import verifyObject
     
    313315        Test routing of a message using the default route.
    314316
    315         The default route is the one with C{None} as its key in the
     317        The default route is the one with L{None} as its key in the
    316318        routing table. It is taken when there is no more specific route
    317319        in the routing table that matches the stanza's destination.
  • wokkel/test/test_data_form.py

    r105 r196  
    66"""
    77
     8from __future__ import division, absolute_import
     9
    810from zope.interface import verify
    911from zope.interface.common.mapping import IIterableMapping
    1012
     13from twisted.python.compat import unicode, _PY3
    1114from twisted.trial import unittest
    1215from twisted.words.xish import domish
     
    11351138        form = data_form.Form('submit', fields=fields)
    11361139        keys = form.keys()
    1137         self.assertIsInstance(keys, list)
     1140        if not _PY3:
     1141            self.assertIsInstance(keys, list)
    11381142        self.assertEqual(set(['botname', 'public', 'features']),
    11391143                         set(keys))
     
    11481152        form = data_form.Form('submit', fields=fields)
    11491153        values = form.values()
    1150         self.assertIsInstance(values, list)
     1154        if not _PY3:
     1155            self.assertIsInstance(values, list)
    11511156        self.assertEqual(set(['The Jabber Bot', True]), set(values))
    11521157
     
    11601165        form = data_form.Form('submit', fields=fields)
    11611166        items = form.items()
    1162         self.assertIsInstance(items, list)
     1167        if not _PY3:
     1168            self.assertIsInstance(items, list)
    11631169        self.assertEqual(set([('botname', 'The Jabber Bot'),
    11641170                              ('public', True)]),
  • wokkel/test/test_delay.py

    r104 r209  
    55Tests for L{wokkel.delay}.
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from datetime import datetime
  • wokkel/test/test_disco.py

    r103 r198  
    66"""
    77
    8 from zope.interface import implements
     8from __future__ import division, absolute_import
     9
     10from zope.interface import implementer
    911
    1012from twisted.internet import defer
     
    847849        ]
    848850
     851        @implementer(disco.IDisco)
    849852        class DiscoResponder(XMPPHandler):
    850             implements(disco.IDisco)
    851853
    852854            def getDiscoInfo(self, requestor, target, nodeIdentifier):
     
    874876        ]
    875877
     878        @implementer(disco.IDisco)
    876879        class DiscoResponder(XMPPHandler):
    877             implements(disco.IDisco)
    878880
    879881            def getDiscoInfo(self, requestor, target, nodeIdentifier):
     
    898900        discoItems = [disco.DiscoItem(JID('example.com'), 'test', 'Test node')]
    899901
     902        @implementer(disco.IDisco)
    900903        class DiscoResponder(XMPPHandler):
    901             implements(disco.IDisco)
    902904
    903905            def getDiscoItems(self, requestor, target, nodeIdentifier):
     
    922924        discoItems = [disco.DiscoItem(JID('example.com'), 'test', 'Test node')]
    923925
     926        @implementer(disco.IDisco)
    924927        class DiscoResponder(XMPPHandler):
    925             implements(disco.IDisco)
    926928
    927929            def getDiscoItems(self, requestor, target, nodeIdentifier):
  • wokkel/test/test_generic.py

    r185 r195  
    66"""
    77
     8from __future__ import division, absolute_import
     9
    810import re
    911
     12from zope.interface.verify import verifyObject
     13
    1014from twisted.python import deprecate
     15from twisted.python.compat import unicode
    1116from twisted.python.versions import Version
    1217from twisted.trial import unittest
     
    1621
    1722from wokkel import generic
     23from wokkel.iwokkel import IDisco
    1824from wokkel.test.helpers import XmlStreamStub
    1925
     
    2531    """
    2632
     33    def setUp(self):
     34        self.protocol = generic.VersionHandler('Test', '0.1.0')
     35
     36
     37    def test_interface(self):
     38        """
     39        L{generic.VersionHandler} implements {IDisco}.
     40        """
     41        verifyObject(IDisco, self.protocol)
     42
     43
    2744    def test_onVersion(self):
    2845        """
     
    3047        """
    3148        self.stub = XmlStreamStub()
    32         self.protocol = generic.VersionHandler('Test', '0.1.0')
    3349        self.protocol.xmlstream = self.stub.xmlstream
    3450        self.protocol.send = self.stub.xmlstream.send
     
    320336        self.callDeprecated((Version("Wokkel", 0, 8, 0),
    321337                             "unicode.encode('idna')"),
    322                             generic.prepareIDNName, (b"example.com"))
     338                            generic.prepareIDNName, ("example.com"))
    323339    test_deprecated.suppress = []
    324 
    325 
    326     def test_bytestring(self):
    327         """
    328         An ASCII-encoded byte string is left as-is.
    329         """
    330         name = b"example.com"
    331         result = generic.prepareIDNName(name)
    332         self.assertEqual(b"example.com", result)
    333340
    334341
  • wokkel/test/test_iwokkel.py

    r165 r193  
    55Tests for L{wokkel.iwokkel}
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from twisted.trial import unittest
  • wokkel/test/test_muc.py

    r218 r219  
    66"""
    77
     8from __future__ import division, absolute_import
     9
    810from datetime import datetime
    911from dateutil.tz import tzutc
     
    1315from twisted.trial import unittest
    1416from twisted.internet import defer, task
     17from twisted.python.compat import iteritems, unicode
    1518from twisted.words.xish import domish, xpath
    1619from twisted.words.protocols.jabber.jid import JID
     
    7982        }
    8083
    81         for code, condition in codes.iteritems():
     84        for code, condition in iteritems(codes):
    8285            constantName = condition.replace('-', '_').upper()
    8386            self.assertEqual(getattr(muc.STATUS_CODE, constantName),
     
    824827        self.assertNotIdentical(None, nodes, 'Missing query element')
    825828
    826         self.assertRaises(StopIteration, nodes[0].elements().next)
     829        self.assertRaises(StopIteration, next, nodes[0].elements())
    827830
    828831        xml = u"""
     
    970973        self.assertNotIdentical(None, nodes, 'Missing query element')
    971974
    972         self.assertRaises(StopIteration, nodes[0].elements().next)
     975        self.assertRaises(StopIteration, next, nodes[0].elements())
    973976
    974977        xml = u"""
  • wokkel/test/test_ping.py

    r96 r199  
    55Tests for L{wokkel.ping}.
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from zope.interface import verify
  • wokkel/test/test_pubsub.py

    r183 r212  
    55Tests for L{wokkel.pubsub}
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from zope.interface import verify
     
    113115        element = subscription.toElement()
    114116        self.assertEqual('1234', element.getAttribute('subid'))
     117
     118
     119
     120class ItemTests(unittest.TestCase):
     121    """
     122    Tests for L{pubsub.Item}.
     123    """
     124
     125    def test_payloadRaw(self):
     126        """
     127        Adding a payload as a string assumes serialized XML.
     128        """
     129        payload = "<test xmlns='foo'/>"
     130        item = pubsub.Item(payload=payload)
     131        self.assertEqual(payload, item.children[0])
     132
     133
     134    def test_payloadElement(self):
     135        """
     136        Adding a payload as an domish Element, just adds that element as child.
     137        """
     138        payload = domish.Element(('foo', 'test'))
     139        item = pubsub.Item(payload=payload)
     140        self.assertIs(payload, item.children[0])
    115141
    116142
     
    29142940        def configureSet(request):
    29152941            self.assertEquals(['pubsub#deliver_payloads'],
    2916                               request.options.keys())
     2942                              list(request.options.keys()))
    29172943
    29182944        self.resource.getConfigurationOptions = getConfigurationOptions
  • wokkel/test/test_server.py

    r96 r206  
    66"""
    77
     8from __future__ import division, absolute_import
    89from twisted.internet import defer
    910from twisted.python import failure
     
    449450
    450451        self.assertEqual(1, len(errors))
     452
     453
     454    def test_generatedSecret(self):
     455        self.router = component.Router()
     456        self.service = server.ServerService(self.router,
     457                                            domain='example.org')
     458        self.assertEqual(32, len(self.service.secret))
  • wokkel/test/test_shim.py

    r96 r201  
    88"""
    99
     10from __future__ import division, absolute_import
     11
     12from twisted.python.compat import unicode
    1013from twisted.trial import unittest
     14
    1115from wokkel import shim
    1216from wokkel.generic import parseXml
  • wokkel/test/test_subprotocols.py

    r165 r194  
    55Tests for L{wokkel.subprotocols}
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from zope.interface.verify import verifyObject
     
    211213        self.xmlstream.connectionMade()
    212214        self.xmlstream.dataReceived(
    213                 "<stream:stream xmlns='jabber:client' "
    214                     "xmlns:stream='http://etherx.jabber.org/streams' "
    215                     "from='example.com' id='12345'>")
     215                b"<stream:stream xmlns='jabber:client' "
     216                    b"xmlns:stream='http://etherx.jabber.org/streams' "
     217                    b"from='example.com' id='12345'>")
    216218        self.xmlstream.dispatch(self.xmlstream, "//event/stream/authd")
    217219
     
    476478        xs.transport = proto_helpers.StringTransport()
    477479        xs.connectionMade()
    478         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    479                         "xmlns:stream='http://etherx.jabber.org/streams' "
    480                         "from='example.com' id='12345'>")
     480        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     481                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     482                        b"from='example.com' id='12345'>")
    481483        xs.dispatch(xs, "//event/stream/authd")
    482484        sm.send("<presence/>")
    483         self.assertEquals("<presence/>", xs.transport.value())
     485        self.assertEquals(b"<presence/>", xs.transport.value())
    484486
    485487
     
    499501        xs.transport = proto_helpers.StringTransport()
    500502        sm.send("<presence/>")
    501         self.assertEquals("", xs.transport.value())
     503        self.assertEquals(b"", xs.transport.value())
    502504        self.assertEquals("<presence/>", sm._packetQueue[0])
    503505
    504506        xs.connectionMade()
    505         self.assertEquals("", xs.transport.value())
     507        self.assertEquals(b"", xs.transport.value())
    506508        self.assertEquals("<presence/>", sm._packetQueue[0])
    507509
    508         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    509                         "xmlns:stream='http://etherx.jabber.org/streams' "
    510                         "from='example.com' id='12345'>")
     510        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     511                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     512                        b"from='example.com' id='12345'>")
    511513        xs.dispatch(xs, "//event/stream/authd")
    512514
    513         self.assertEquals("<presence/>", xs.transport.value())
     515        self.assertEquals(b"<presence/>", xs.transport.value())
    514516        self.assertFalse(sm._packetQueue)
    515517
     
    526528        xs.transport = proto_helpers.StringTransport()
    527529        xs.connectionMade()
    528         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    529                         "xmlns:stream='http://etherx.jabber.org/streams' "
    530                         "from='example.com' id='12345'>")
     530        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     531                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     532                        b"from='example.com' id='12345'>")
    531533        sm.send("<presence/>")
    532         self.assertEquals("", xs.transport.value())
     534        self.assertEquals(b"", xs.transport.value())
    533535        self.assertEquals("<presence/>", sm._packetQueue[0])
    534536
     
    552554
    553555        sm.send("<presence/>")
    554         self.assertEquals("", xs.transport.value())
     556        self.assertEquals(b"", xs.transport.value())
    555557        self.assertEquals("<presence/>", sm._packetQueue[0])
    556558
     
    563565
    564566        self.streamManager.request(self.request)
    565         expected = u"<iq type='get' id='%s'/>" % self.request.stanzaID
    566         self.assertEquals(expected, self.transport.value())
     567        self.assertTrue(self.transport.value())
    567568
    568569
     
    576577        self.streamManager.request(self.request)
    577578        self.assertNotIdentical(None, self.request.stanzaID)
    578         expected = u"<iq type='get' id='%s'/>" % self.request.stanzaID
    579         self.assertEquals(expected, self.transport.value())
     579        self.assertTrue(self.transport.value())
    580580
    581581
     
    588588
    589589        self.streamManager.request(self.request)
    590         expected = u"<iq type='get' id='test'/>"
    591590
    592591        xs = self.xmlstream
    593         self.assertEquals("", xs.transport.value())
     592        self.assertEquals(b"", xs.transport.value())
    594593
    595594        xs.connectionMade()
    596         self.assertEquals("", xs.transport.value())
    597 
    598         xs.dataReceived("<stream:stream xmlns='jabber:client' "
    599                         "xmlns:stream='http://etherx.jabber.org/streams' "
    600                         "from='example.com' id='12345'>")
     595        self.assertEquals(b"", xs.transport.value())
     596
     597        xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
     598                        b"xmlns:stream='http://etherx.jabber.org/streams' "
     599                        b"from='example.com' id='12345'>")
    601600        xs.dispatch(xs, "//event/stream/authd")
    602601
    603         self.assertEquals(expected, xs.transport.value())
     602        self.assertTrue(self.transport.value())
    604603        self.assertFalse(self.streamManager._packetQueue)
    605604
     
    617616
    618617        xs = self.xmlstream
    619         xs.dataReceived("<iq type='result' id='test'/>")
     618        xs.dataReceived(b"<iq type='result' id='test'/>")
    620619        return d
    621620
     
    630629
    631630        xs = self.xmlstream
    632         xs.dataReceived("<iq type='error' id='test'/>")
     631        xs.dataReceived(b"<iq type='error' id='test'/>")
    633632        return d
    634633
     
    652651
    653652        # Receive an untracked iq response
    654         self.xmlstream.dataReceived("<iq type='result' id='other'/>")
     653        self.xmlstream.dataReceived(b"<iq type='result' id='other'/>")
    655654        self.assertEquals(1, len(dispatched))
    656655        self.assertFalse(getattr(dispatched[-1], 'handled', False))
     
    666665        d = self.streamManager.request(self.request)
    667666        xs = self.xmlstream
    668         xs.dataReceived("<iq type='result' id='test'/>")
     667        xs.dataReceived(b"<iq type='result' id='test'/>")
    669668        self.assertNotIn('test', self.streamManager._iqDeferreds)
    670669        return d
     
    722721        d = self.streamManager.request(self.request)
    723722        self.clock.callLater(1, self.xmlstream.dataReceived,
    724                              "<iq type='result' id='test'/>")
     723                                b"<iq type='result' id='test'/>")
    725724        self.clock.pump([1, 1])
    726725        self.assertFalse(self.clock.calls)
     
    868867        self.assertEquals('iq', response.name)
    869868        self.assertEquals('result', response['type'])
    870         payload = response.elements().next()
     869        payload = next(response.elements())
    871870        self.assertEqual(handler.payload, payload)
    872871
  • wokkel/test/test_xmppim.py

    r179 r203  
    66"""
    77
     8from __future__ import division, absolute_import
     9
    810from twisted.internet import defer
    911from twisted.trial import unittest
     12from twisted.python.compat import unicode
    1013from twisted.words.protocols.jabber import error
    1114from twisted.words.protocols.jabber.jid import JID
     
    897900        element = request.toElement()
    898901        children = element.elements()
    899         child = children.next()
     902        child = next(children)
    900903        self.assertEqual(NS_ROSTER, child.uri)
    901904        self.assertEqual('query', child.name)
     
    910913        element = request.toElement()
    911914        children = element.query.elements()
    912         child = children.next()
     915        child = next(children)
    913916        self.assertEqual(NS_ROSTER, child.uri)
    914917        self.assertEqual('item', child.name)
  • wokkel/xmppim.py

    r179 r203  
    1111"""
    1212
     13from __future__ import division, absolute_import
     14
    1315import warnings
    1416
    1517from twisted.internet import defer
     18from twisted.python.compat import iteritems, itervalues, unicode
    1619from twisted.words.protocols.jabber import error
    1720from twisted.words.protocols.jabber.jid import JID
     
    4649
    4750        if statuses is not None:
    48             for lang, status in statuses.iteritems():
     51            for lang, status in iteritems(statuses):
    4952                s = self.addElement('status', content=status)
    5053                if lang:
     
    5962
    6063        if statuses is not None:
    61             for lang, status in statuses.iteritems():
     64            for lang, status in iteritems(statuses):
    6265                s = self.addElement('status', content=status)
    6366                if lang:
     
    307310            return self.statuses[None]
    308311        elif self.statuses:
    309             for status in self.status.itervalues():
     312            for status in itervalues(self.status):
    310313                return status
    311314        else:
     
    353356                presence.addElement('priority', content=unicode(self.priority))
    354357
    355         for lang, text in self.statuses.iteritems():
     358        for lang, text in iteritems(self.statuses):
    356359            status = presence.addElement('status', content=text)
    357360            if lang:
Note: See TracChangeset for help on using the changeset viewer.