source: ralphm-patches/py3-muc.patch

Last change on this file was 78:361e2111a663, checked in by Ralph Meijer <ralphm@…>, 4 years ago

Start port to Python 3.

File size: 15.9 KB
  • wokkel/compat.py

    # HG changeset patch
    # Parent  67c8865969f4350bfc019ddd852ee6f2ed707cdf
    
    diff --git a/wokkel/compat.py b/wokkel/compat.py
    a b  
    99
    1010from __future__ import division, absolute_import
    1111
    12 from twisted.python.deprecate import deprecatedModuleAttribute
    13 from twisted.python.versions import Version
    1412from twisted.words.protocols.jabber import xmlstream
    1513
    1614class IQ(xmlstream.IQ):
  • wokkel/muc.py

    diff --git a/wokkel/muc.py b/wokkel/muc.py
    a b  
    1414from zope.interface import implementer
    1515
    1616from twisted.internet import defer
     17from twisted.python.compat import unicode
    1718from twisted.python.constants import Values, ValueConstant
    1819from twisted.words.protocols.jabber import jid, error, xmlstream
    1920from twisted.words.xish import domish
     
    7273    This is currently implemented as a set of constant values from
    7374    L{STATUS_CODE}. Instances of this class provide L{IMUCStatuses}, that
    7475    defines the supported operations. Even though this class currently derives
    75     from C{set}, future versions might not. This provides an upgrade path to
     76    from L{set}, future versions might not. This provides an upgrade path to
    7677    cater for extensible status conditions, as defined in
    7778    U{XEP-0306<http://xmpp.org/extensions/xep-0306.html>}.
    7879    """
     
    224225    Room destruction request.
    225226
    226227    @param reason: Optional reason for the destruction of this room.
    227     @type reason: C{unicode}.
     228    @type reason: L{unicode}.
    228229
    229230    @param alternate: Optional room JID of an alternate venue.
    230231    @type alternate: L{JID<twisted.words.protocols.jabber.jid.JID>}
    231232
    232233    @param password: Optional password for entering the alternate venue.
    233     @type password: C{unicode}
     234    @type password: L{unicode}
    234235    """
    235236
    236237    stanzaType = 'set'
     
    273274        """
    274275        Render into a domish Element.
    275276
    276         @param legacyDelay: If C{True} send the delayed delivery information
     277        @param legacyDelay: If L{True} send the delayed delivery information
    277278        in legacy format.
    278279        """
    279280        element = xmppim.Message.toElement(self)
     
    323324    @ivar maxchars: Limit the total number of characters in the history to "X"
    324325        (where the character count is the characters of the complete XML
    325326        stanzas, not only their XML character data).
    326     @type maxchars: C{int}
     327    @type maxchars: L{int}
    327328
    328329    @ivar maxstanzas: Limit the total number of messages in the history to "X".
    329     @type mazstanzas: C{int}
     330    @type mazstanzas: L{int}
    330331
    331332    @ivar seconds: Send only the messages received in the last "X" seconds.
    332     @type seconds: C{int}
     333    @type seconds: L{int}
    333334
    334335    @ivar since: Send only the messages received since the datetime specified.
    335336        Note that this must be an offset-aware instance.
     
    391392    Availability presence sent from MUC service to client.
    392393
    393394    @ivar affiliation: Affiliation of the entity to the room.
    394     @type affiliation: C{unicode}
     395    @type affiliation: L{unicode}
    395396
    396397    @ivar role: Role of the entity in the room.
    397     @type role: C{unicode}
     398    @type role: L{unicode}
    398399
    399400    @ivar entity: The real JID of the entity this presence is from.
    400401    @type entity: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    404405    @type mucStatuses: L{Statuses}
    405406
    406407    @ivar nick: The nick name of the entity in the room.
    407     @type nick: C{unicode}
     408    @type nick: L{unicode}
    408409    """
    409410
    410411    affiliation = None
     
    545546
    546547        @param timeout: The number of seconds to wait before the deferred is
    547548            timed out.
    548         @type timeout: C{int}
     549        @type timeout: L{int}
    549550
    550551        The deferred object L{defer.Deferred} is returned.
    551552        """
     
    591592        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    592593
    593594        @param nick: The nick name for the entitity joining the room.
    594         @type nick: C{unicode}
     595        @type nick: L{unicode}
    595596
    596597        @param historyOptions: Options for conversation history sent by the
    597598            room upon joining.
    598599        @type historyOptions: L{HistoryOptions}
    599600
    600601        @param password: Optional password for the room.
    601         @type password: C{unicode}
     602        @type password: L{unicode}
    602603
    603604        @return: A deferred that fires when the entity is in the room or an
    604605                 error has occurred.
     
    624625        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    625626
    626627        @param nick: The new nick name within the room.
    627         @type nick: C{unicode}
     628        @type nick: L{unicode}
    628629        """
    629630        occupantJID = jid.JID(tuple=(roomJID.user, roomJID.host, nick))
    630631        presence = BasicPresence(recipient=occupantJID)
     
    642643
    643644        @param show: The availability of the entity. Common values are xa,
    644645            available, etc
    645         @type show: C{unicode}
     646        @type show: L{unicode}
    646647
    647648        @param status: The current status of the entity.
    648         @type status: C{unicode}
     649        @type status: L{unicode}
    649650        """
    650651        occupantJID = self._roomOccupantMap[roomJID]
    651652        presence = BasicPresence(recipient=occupantJID, show=show,
     
    700701        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    701702
    702703        @param subject: The subject you want to set.
    703         @type subject: C{unicode}
     704        @type subject: L{unicode}
    704705        """
    705706        message = GroupChat(roomJID.userhostJID(), subject=subject)
    706707        self.send(message.toElement())
     
    719720        @type invitee: L{JID<twisted.words.protocols.jabber.jid.JID>}
    720721
    721722        @param reason: The reason for the invite.
    722         @type reason: C{unicode}
     723        @type reason: L{unicode}
    723724        """
    724725        message = InviteMessage(recipient=roomJID, invitee=invitee,
    725726                                reason=reason)
     
    751752        @param roomJID: The bare JID of the room.
    752753        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    753754
    754         @param options: A mapping of field names to values, or C{None} to
     755        @param options: A mapping of field names to values, or L{None} to
    755756            cancel.
    756         @type options: C{dict}
     757        @type options: L{dict}
    757758        """
    758759        if options is None:
    759760            options = False
     
    783784
    784785        @param messages: The history to send to the room as an ordered list of
    785786                         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
     787                         L{'stanza'}, holding the original stanza a
     788                         L{domish.Element}, and L{'timestamp'} with the
    788789                         timestamp.
    789         @type messages: C{list} of L{domish.Element}
     790        @type messages: L{list} of L{domish.Element}
    790791        """
    791792
    792793        for message in messages:
     
    818819        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    819820
    820821        @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
     822            a L{data_form.Form} or L{None} if there are no configuration
    822823            options available.
    823824        """
    824825        def cb(response):
     
    838839        @param roomJID: The room to configure.
    839840        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    840841
    841         @param options: A mapping of field names to values, or C{None} to
     842        @param options: A mapping of field names to values, or L{None} to
    842843            cancel.
    843         @type options: C{dict}
     844        @type options: L{dict}
    844845        """
    845846        if options is None:
    846847            options = False
     
    962963        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    963964
    964965        @param entities: The list of entities to change for a room.
    965         @type entities: C{list} of
     966        @type entities: L{list} of
    966967            L{JID<twisted.words.protocols.jabber.jid.JID>}
    967968
    968969        @param affiliation: The affilation to the entities will acquire.
    969         @type affiliation: C{unicode}
     970        @type affiliation: L{unicode}
    970971
    971972        @param sender: The entity sending the request.
    972973        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    988989        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    989990
    990991        @param nick: The nick name for the user in this room.
    991         @type nick: C{unicode}
     992        @type nick: L{unicode}
    992993
    993994        @param reason: The reason for granting voice to the entity.
    994         @type reason: C{unicode}
     995        @type reason: L{unicode}
    995996
    996997        @param sender: The entity sending the request.
    997998        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    10111012        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    10121013
    10131014        @param nick: The nick name for the user in this room.
    1014         @type nick: C{unicode}
     1015        @type nick: L{unicode}
    10151016
    10161017        @param reason: The reason for revoking voice from the entity.
    1017         @type reason: C{unicode}
     1018        @type reason: L{unicode}
    10181019
    10191020        @param sender: The entity sending the request.
    10201021        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    10311032        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    10321033
    10331034        @param nick: The nick name for the user in this room.
    1034         @type nick: C{unicode}
     1035        @type nick: L{unicode}
    10351036
    10361037        @param reason: The reason for granting moderation to the entity.
    1037         @type reason: C{unicode}
     1038        @type reason: L{unicode}
    10381039
    10391040        @param sender: The entity sending the request.
    10401041        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    10541055        @type entity: L{JID<twisted.words.protocols.jabber.jid.JID>}
    10551056
    10561057        @param reason: The reason for banning the entity.
    1057         @type reason: C{unicode}
     1058        @type reason: L{unicode}
    10581059
    10591060        @param sender: The entity sending the request.
    10601061        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    10711072        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    10721073
    10731074        @param nick: The occupant to be banned.
    1074         @type nick: C{unicode}
     1075        @type nick: L{unicode}
    10751076
    10761077        @param reason: The reason given for the kick.
    1077         @type reason: C{unicode}
     1078        @type reason: L{unicode}
    10781079
    10791080        @param sender: The entity sending the request.
    10801081        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    10911092        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    10921093
    10931094        @param reason: The reason for the destruction of the room.
    1094         @type reason: C{unicode}
     1095        @type reason: L{unicode}
    10951096
    10961097        @param alternate: The JID of the room suggested as an alternate venue.
    10971098        @type alternate: L{JID<twisted.words.protocols.jabber.jid.JID>}
     
    11311132    @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    11321133
    11331134    @ivar nick: The nick name for the client in this room.
    1134     @type nick: C{unicode}
     1135    @type nick: L{unicode}
    11351136
    11361137    @ivar occupantJID: The JID of the occupant in the room. Generated from
    11371138        roomJID and nick.
     
    11411142        to be configured before it can be used. See
    11421143        L{MUCClientProtocol.getConfiguration} and
    11431144        L{MUCClientProtocol.configure}.
    1144     @type locked: C{bool}
     1145    @type locked: L{bool}
    11451146    """
    11461147
    11471148    locked = False
     
    11861187        Get a user from the room's roster.
    11871188
    11881189        @param nick: The nick for the user in the MUC room.
    1189         @type nick: C{unicode}
     1190        @type nick: L{unicode}
    11901191        """
    11911192        return self.roster.get(nick)
    11921193
     
    12131214    @ivar _rooms: Collection of occupied rooms, keyed by the bare JID of the
    12141215                  room. Note that a particular entity can only join a room once
    12151216                  at a time.
    1216     @type _rooms: C{dict}
     1217    @type _rooms: L{dict}
    12171218    """
    12181219
    12191220    def __init__(self, reactor=None):
     
    13981399        @param room: The room the message was received from.
    13991400        @type room: L{Room}
    14001401
    1401         @param user: The user that sent the message, or C{None} if it was a
     1402        @param user: The user that sent the message, or L{None} if it was a
    14021403            message from the room itself.
    14031404        @type user: L{User}
    14041405
     
    14191420        @param room: The room the message was received from.
    14201421        @type room: L{Room}
    14211422
    1422         @param user: The user that sent the message, or C{None} if it was a
     1423        @param user: The user that sent the message, or L{None} if it was a
    14231424            message from the room itself.
    14241425        @type user: L{User}
    14251426
     
    14381439        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    14391440
    14401441        @param nick: The nick name for the entitity joining the room.
    1441         @type nick: C{unicode}
     1442        @type nick: L{unicode}
    14421443
    14431444        @param historyOptions: Options for conversation history sent by the
    14441445            room upon joining.
    14451446        @type historyOptions: L{HistoryOptions}
    14461447
    14471448        @param password: Optional password for the room.
    1448         @type password: C{unicode}
     1449        @type password: L{unicode}
    14491450
    14501451        @return: A deferred that fires with the room when the entity is in the
    14511452            room, or with a failure if an error has occurred.
     
    14821483        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    14831484
    14841485        @param nick: The new nick name within the room.
    1485         @type nick: C{unicode}
     1486        @type nick: L{unicode}
    14861487        """
    14871488        def cb(presence):
    14881489            # Presence confirmation, change the nickname.
     
    15241525
    15251526        @param show: The availability of the entity. Common values are xa,
    15261527            available, etc
    1527         @type show: C{unicode}
     1528        @type show: L{unicode}
    15281529
    15291530        @param status: The current status of the entity.
    1530         @type status: C{unicode}
     1531        @type status: L{unicode}
    15311532        """
    15321533        room = self._getRoom(roomJID)
    15331534        d = MUCClientProtocol.status(self, roomJID, show, status)
     
    15431544        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}
    15441545
    15451546        @param reason: The reason for the destruction of the room.
    1546         @type reason: C{unicode}
     1547        @type reason: L{unicode}
    15471548
    15481549        @param alternate: The JID of the room suggested as an alternate venue.
    15491550        @type alternate: L{JID<twisted.words.protocols.jabber.jid.JID>}
  • wokkel/test/test_muc.py

    diff --git a/wokkel/test/test_muc.py b/wokkel/test/test_muc.py
    a b  
    1212
    1313from twisted.trial import unittest
    1414from twisted.internet import defer, task
     15from twisted.python.compat import iteritems, unicode
    1516from twisted.words.xish import domish, xpath
    1617from twisted.words.protocols.jabber.jid import JID
    1718from twisted.words.protocols.jabber.error import StanzaError
     
    7879            332: 'removed-shutdown',
    7980        }
    8081
    81         for code, condition in codes.iteritems():
     82        for code, condition in iteritems(codes):
    8283            constantName = condition.replace('-', '_').upper()
    8384            self.assertEqual(getattr(muc.STATUS_CODE, constantName),
    8485                             muc.STATUS_CODE.lookupByValue(code))
     
    823824        nodes = xpath.queryForNodes(query, iq)
    824825        self.assertNotIdentical(None, nodes, 'Missing query element')
    825826
    826         self.assertRaises(StopIteration, nodes[0].elements().next)
     827        self.assertRaises(StopIteration, next, nodes[0].elements())
    827828
    828829        xml = u"""
    829830            <iq from='%s' id='%s' to='%s' type='result'>
     
    969970        nodes = xpath.queryForNodes(query, iq)
    970971        self.assertNotIdentical(None, nodes, 'Missing query element')
    971972
    972         self.assertRaises(StopIteration, nodes[0].elements().next)
     973        self.assertRaises(StopIteration, next, nodes[0].elements())
    973974
    974975        xml = u"""
    975976            <iq from='%s' id='%s' to='%s' type='result'>
Note: See TracBrowser for help on using the repository browser.