Changeset 123:b55a7560f174 for wokkel


Ignore:
Timestamp:
Oct 20, 2008, 11:34:19 PM (11 years ago)
Author:
Christopher Zorn <tofu@…>
Branch:
wokkel-muc-client-support-24
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@119
Message:

some docstrings, some bug fixes and some cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r122 r123  
    354354    @ivar maxchars: Limit the total number of characters in the history to "X"
    355355                    (where the character count is the characters of the complete XML stanzas, not only their XML character data).
    356     @itype maxchars: L{int}
     356    @type maxchars: L{int}
    357357               
    358358    @ivar  maxstanzas:  Limit the total number of messages in the history to "X".
    359     @itype mazstanzas: L{int}
     359    @type mazstanzas: L{int}
    360360
    361361    @ivar  seconds: Send only the messages received in the last "X" seconds.
    362     @itype seconds: L{int}
     362    @type seconds: L{int}
    363363
    364364    @ivar  since: Send only the messages received since the datetime specified (which MUST conform to the DateTime profile specified in XMPP Date and Time Profiles [14]).
    365     @itype since: L{datetime.datetime}
     365    @type since: L{datetime.datetime}
    366366
    367367    """
     
    536536class MUCClient(XMPPHandler):
    537537    """
    538     Multi-User chat client protocol.
     538    Multi-User chat client protocol. This is a subclass of L{XMPPHandler} and implements L{IMUCCLient}.
     539
    539540    """
    540541
     
    548549
    549550    def connectionInitialized(self):
     551        """ This method is called when the client has successfully authenticated.
     552        It initializes several xpath events to handle MUC stanzas that come in.
     553        After those are initialized then the method initialized is called to signal that we have finished.
     554        """
    550555        self.xmlstream.addObserver(PRESENCE+"[not(@type) or @type='available']/x", self._onXPresence)
    551556        self.xmlstream.addObserver(PRESENCE+"[@type='unavailable']", self._onUnavailablePresence)
     
    558563
    559564    def _setRoom(self, room):
     565        """Add a room to the room collection.
     566        """
    560567        self.rooms[room.entity_id.userhost().lower()] = room
    561568
    562569    def _getRoom(self, room_jid):
     570        """Grab a room from the room collection.
     571        """
    563572        return self.rooms.get(room_jid.userhost().lower())
    564573
    565574    def _removeRoom(self, room_jid):
     575        """Delete a room from the room collection.
     576        """
    566577        if self.rooms.has_key(room_jid.userhost().lower()):
    567578            del self.rooms[room_jid.userhost().lower()]
     
    569580
    570581    def _onUnavailablePresence(self, prs):
    571         """
     582        """ This method is called when the stanza matches the xpath observer.
     583        The client has received a presence stanza with the 'type' attribute of unavailable.
     584        It means a user has exited a MUC room.
    572585        """
    573586
     
    578591
    579592    def _onPresenceError(self, prs):
    580         """
     593        """This method is called when a presence stanza with the 'type' attribute of error.
     594        There are various reasons for receiving a presence error and it means that the user has left the room.
    581595        """
    582596        if not prs.hasAttribute('from'):
     
    587601       
    588602    def _getExceptionFromElement(self, stanza):
     603        # find an exception based on the error stanza
    589604        muc_condition = 'exception'
    590605
     
    597612
    598613    def _userLeavesRoom(self, room_jid):
     614        # when a user leaves a room we need to update it
    599615        room = self._getRoom(room_jid)
    600616        if room is None:
     
    610626       
    611627    def _onXPresence(self, prs):
    612         """
     628        """ A muc presence has been received.
    613629        """
    614630        if not prs.hasAttribute('from'):
     
    906922   
    907923    def leave(self, room_jid):
    908         """
     924        """Leave a MUC room.
     925
     926        See: http://xmpp.org/extensions/xep-0045.html#exit
     927
     928        @param room_jid: The room entity id you want to exit.
     929        @type  room_jid: L{jid.JID}
     930
    909931        """
    910932        r = self._getRoom(room_jid)
     
    10011023
    10021024
     1025    def _getRoleList(self, room_jid, role):
     1026        iq = RoleRequest(self.xmlstream,
     1027                                method='get',
     1028                                role=role,
     1029                                )
     1030        iq['to'] = room_jid.full()
     1031        return iq.send()       
     1032
     1033
     1034    def self._setAffiliationList(self, affiliation, room_jid, iq):
     1035        r = self._getRoom(room_jid)
     1036        if r is not None:
     1037            affiliation_list = []
     1038            setattr(r, affiliation, [])
     1039           
     1040            for item in iq.query.elements():
     1041                nick   = item.getAttribute('nick', None)
     1042                entity = item.getAttribute('jid', None)
     1043                u      = None
     1044                if nick is None and entity is None:
     1045                    raise Exception, 'bad attributes in item list'
     1046                if nick is not None:
     1047                    u = room.getUser(nick)
     1048                if u is None:
     1049                    u = User(nick, user_jid=jid.internJID(entity))
     1050                    u.affiliation = 'member'
     1051                   
     1052                affiliation_list.append(u)
     1053
     1054            setattr(r, affiliation, affiliation_list)
     1055        return r
    10031056
    10041057    def getMemberList(self, room_jid):
     
    10091062
    10101063        """
    1011         return self._getAffiliationList(room_jid, 'member')
    1012 
     1064        d = self._getAffiliationList(room_jid, 'member')
     1065        d.addCallback(self._setAffiliationList, 'members', room_jid)
     1066        return d
    10131067
    10141068    def getAdminList(self, room_jid):
     
    10191073
    10201074        """
    1021         return self._getAffiliationList(room_jid, 'admin')
     1075        d = self._getAffiliationList(room_jid, 'admin')
     1076        d.addCallback(self._setAffiliationList, 'members', room_jid)
     1077        return d
    10221078
    10231079    def getBanList(self, room_jid):
     
    10281084
    10291085        """
    1030         return self._getAffiliationList(room_jid, 'outcast')
     1086        d = self._getAffiliationList(room_jid, 'outcast')
     1087        d.addCallback(self._setAffiliationList, 'members', room_jid)
     1088        return d
    10311089
    10321090    def getOwnerList(self, room_jid):
     
    10371095
    10381096        """
    1039         return self._getAffiliationList(room_jid, 'owner')
    1040 
     1097        d = self._getAffiliationList(room_jid, 'owner')
     1098        d.addCallback(self._setAffiliationList, 'members', room_jid)
     1099        return d
    10411100
    10421101    def getRegisterForm(self, room):
     
    11201179        return iq.send()
    11211180
     1181    def _cbRequest(self, room_jid, iq):
     1182        r = self._getRoom(room_jid)
     1183        if r is None:
     1184            raise NotFound
     1185
     1186        return r
     1187
    11221188    def grantVoice(self, frm, room_jid, reason=None):
    1123         return self._setAffiliation(frm, room_jid, 'participant', reason=reason)
    1124 
     1189        return self._setRole(frm, room_jid, role='participant', reason=reason)
     1190
     1191    def grantVisitor(self, frm, room_jid, reason=None):
     1192        return self._setRole(frm, room_jid, role='visitor', reason=reason)
     1193
     1194    def grantModerator(self, frm, room_jid, reason=None):
     1195        return self._setRole(frm, room_jid, role='moderator', reason=reason)
    11251196
    11261197    def ban(self, to, ban_jid, frm, reason=None):
    11271198        return self._setAffiliation(frm, to, 'outcast', a_jid=ban_jid, reason=reason)
    11281199
    1129 
    11301200    def kick(self, to, kick_jid, frm, reason=None):       
    11311201        return self._setAffiliation(frm, to, 'none', a_jid=kick_jid, reason=reason)
Note: See TracChangeset for help on using the changeset viewer.