Ignore:
Timestamp:
Aug 12, 2011, 2:11:43 PM (9 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
wokkel-muc-client-support-24
Message:

Use generic.Request for room destruction request, add TestableStreamManager?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r145 r147  
    105105
    106106
    107 class OwnerRequest(xmlstream.IQ):
    108     """
    109     A basic owner iq request.
    110 
    111     @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}
    112     @type method: C{str}
    113     """
    114 
    115     def __init__(self, xs, method='get'):
    116         xmlstream.IQ.__init__(self, xs, method)
    117         q = self.addElement((NS_MUC_OWNER, 'query'))
     107class DestructionRequest(generic.Request):
     108    """
     109    Room destruction request.
     110
     111    @param reason: Optional reason for the destruction of this room.
     112    @type reason: C{unicode}.
     113
     114    @param alternate: Optional room JID of an alternate venue.
     115    @type alternate: L{jid.JID}
     116
     117    @param password: Optional password for entering the alternate venue.
     118    @type password: C{unicode}
     119    """
     120
     121    stanzaType = 'set'
     122
     123    def __init__(self, recipient, sender=None, reason=None, alternate=None,
     124                       password=None):
     125        generic.Request.__init__(self, recipient, sender)
     126        self.reason = reason
     127        self.alternate = alternate
     128        self.password = password
     129
     130
     131    def toElement(self):
     132        element = generic.Request.toElement(self)
     133        element.addElement((NS_MUC_OWNER, 'query'))
     134        element.query.addElement('destroy')
     135
     136        if self.alternate:
     137            element.query.destroy['jid'] = self.alternate.full()
     138
     139            if self.password:
     140                element.query.destroy.addElement('password',
     141                                                 content=self.password)
     142
     143        if self.reason:
     144            element.query.destroy.addElement('reason', content=self.reason)
     145
     146        return element
    118147
    119148
     
    11551184
    11561185
    1157     def destroy(self, roomJID, reason=None, alternate=None):
     1186    def destroy(self, roomJID, reason=None, alternate=None, password=None):
    11581187        """
    11591188        Destroy a room.
    11601189
    1161         @param roomJID: The bare JID of the room.
    1162         @type roomJID: L{jid.JID}
    1163 
    1164         @param reason: The reason we are destroying the room.
     1190        @param roomJID: The JID of the room.
     1191        @type roomJID: L{jid.JID}
     1192
     1193        @param reason: The reason for the destruction of the room.
    11651194        @type reason: C{unicode}
    11661195
    1167         @param alternate: The bare JID of the room suggested as an alternate
    1168                           venue.
     1196        @param alternate: The JID of the room suggested as an alternate venue.
    11691197        @type alternate: L{jid.JID}
    11701198
     
    11721200        def destroyed(iq):
    11731201            self._removeRoom(roomJID)
    1174             return True
    1175 
    1176         iq = OwnerRequest(self.xmlstream, method='set')
    1177         iq['to'] = roomJID.userhost()
    1178         d = iq.query.addElement('destroy')
    1179 
    1180         if alternate is not None:
    1181             d['jid'] = alternate.userhost()
    1182         if reason is not None:
    1183             d.addElement('reason', None, reason)
    1184 
    1185         return iq.send().addCallback(destroyed)
     1202
     1203        request = DestructionRequest(recipient=roomJID, reason=reason,
     1204                                     alternate=alternate, password=password)
     1205
     1206        d = self.request(request)
     1207        d.addCallback(destroyed)
     1208        return d
    11861209
    11871210
Note: See TracChangeset for help on using the changeset viewer.