Changeset 134:250a1041a437 for wokkel


Ignore:
Timestamp:
Aug 3, 2011, 8:48:50 PM (9 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
wokkel-muc-client-support-24
Parents:
133:2ea562934152 (diff), 104:7de2ae0a6a88 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge in trunk changes.

Location:
wokkel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wokkel/disco.py

    • Property exe set to *
    r133 r134  
    11# -*- test-case-name: wokkel.test.test_disco -*-
    22#
    3 # Copyright (c) 2003-2009 Ralph Meijer
     3# Copyright (c) Ralph Meijer.
    44# See LICENSE for details.
    55
     
    1515from twisted.words.xish import domish
    1616
    17 from wokkel import data_form
    18 from wokkel.compat import IQ
     17from wokkel import data_form, generic
    1918from wokkel.iwokkel import IDisco
    2019from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
     
    120119    @type nodeIdentifier: C{unicode}
    121120    @ivar features: Features as L{DiscoFeature}.
    122     @type features: C{set)
     121    @type features: C{set}
    123122    @ivar identities: Identities as a mapping from (category, type) to name,
    124123                      all C{unicode}.
     
    347346
    348347
    349 class _DiscoRequest(IQ):
    350     """
    351     Element representing an XMPP service discovery request.
    352     """
    353 
    354     def __init__(self, xs, namespace, nodeIdentifier=''):
    355         """
    356         Initialize the request.
    357 
    358         @param xs: XML Stream the request should go out on.
    359         @type xs: L{xmlstream.XmlStream}
    360         @param namespace: Request namespace.
    361         @type namespace: C{str}
    362         @param nodeIdentifier: Node to request info from.
    363         @type nodeIdentifier: C{unicode}
    364         """
    365         IQ.__init__(self, xs, "get")
    366         query = self.addElement((namespace, 'query'))
    367         if nodeIdentifier:
    368             query['node'] = nodeIdentifier
     348class _DiscoRequest(generic.Request):
     349    """
     350    A Service Discovery request.
     351
     352    @ivar verb: Type of request: C{'info'} or C{'items'}.
     353    @type verb: C{str}
     354    @ivar nodeIdentifier: Optional node to request info for.
     355    @type nodeIdentifier: C{unicode}
     356    """
     357
     358    verb = None
     359    nodeIdentifier = ''
     360
     361    _requestVerbMap = {
     362            NS_DISCO_INFO: 'info',
     363            NS_DISCO_ITEMS: 'items',
     364            }
     365
     366    _verbRequestMap = dict(((v, k) for k, v in _requestVerbMap.iteritems()))
     367
     368    def __init__(self, verb=None, nodeIdentifier='',
     369                       recipient=None, sender=None):
     370        generic.Request.__init__(self, recipient=recipient, sender=sender,
     371                                       stanzaType='get')
     372        self.verb = verb
     373        self.nodeIdentifier = nodeIdentifier
     374
     375
     376    def parseElement(self, element):
     377        generic.Request.parseElement(self, element)
     378
     379        verbElement = None
     380        for child in element.elements():
     381            if child.name == 'query' and child.uri in self._requestVerbMap:
     382                self.verb = self._requestVerbMap[child.uri]
     383                verbElement = child
     384
     385        if verbElement:
     386            self.nodeIdentifier = verbElement.getAttribute('node', '')
     387
     388
     389    def toElement(self):
     390        element = generic.Request.toElement(self)
     391
     392        childURI = self._verbRequestMap[self.verb]
     393        query = element.addElement((childURI, 'query'))
     394
     395        if self.nodeIdentifier:
     396            query['node'] = self.nodeIdentifier
     397
     398        return element
    369399
    370400
     
    389419        """
    390420
    391         request = _DiscoRequest(self.xmlstream, NS_DISCO_INFO, nodeIdentifier)
    392         if sender is not None:
    393             request['from'] = unicode(sender)
    394 
    395         d = request.send(entity.full())
     421        request = _DiscoRequest('info', nodeIdentifier)
     422        request.sender = sender
     423        request.recipient = entity
     424
     425        d = self.request(request)
    396426        d.addCallback(lambda iq: DiscoInfo.fromElement(iq.query))
    397427        return d
     
    412442        """
    413443
    414         request = _DiscoRequest(self.xmlstream, NS_DISCO_ITEMS, nodeIdentifier)
    415         if sender is not None:
    416             request['from'] = unicode(sender)
    417 
    418         d = request.send(entity.full())
     444        request = _DiscoRequest('items', nodeIdentifier)
     445        request.sender = sender
     446        request.recipient = entity
     447
     448        d = self.request(request)
    419449        d.addCallback(lambda iq: DiscoItems.fromElement(iq.query))
    420450        return d
     
    446476        @type iq: L{Element<twisted.words.xish.domish.Element>}
    447477        """
    448         requestor = jid.internJID(iq["from"])
    449         target = jid.internJID(iq["to"])
    450         nodeIdentifier = iq.query.getAttribute("node", '')
     478        request = _DiscoRequest.fromElement(iq)
    451479
    452480        def toResponse(info):
    453             if nodeIdentifier and not info:
     481            if request.nodeIdentifier and not info:
    454482                raise error.StanzaError('item-not-found')
    455483            else:
    456484                response = DiscoInfo()
    457                 response.nodeIdentifier = nodeIdentifier
     485                response.nodeIdentifier = request.nodeIdentifier
    458486
    459487                for item in info:
     
    462490            return response.toElement()
    463491
    464         d = self.info(requestor, target, nodeIdentifier)
     492        d = self.info(request.sender, request.recipient,
     493                      request.nodeIdentifier)
    465494        d.addCallback(toResponse)
    466495        return d
     
    474503        @type iq: L{Element<twisted.words.xish.domish.Element>}
    475504        """
    476         requestor = jid.internJID(iq["from"])
    477         target = jid.internJID(iq["to"])
    478         nodeIdentifier = iq.query.getAttribute("node", '')
     505        request = _DiscoRequest.fromElement(iq)
    479506
    480507        def toResponse(items):
    481508            response = DiscoItems()
    482             response.nodeIdentifier = nodeIdentifier
     509            response.nodeIdentifier = request.nodeIdentifier
    483510
    484511            for item in items:
     
    487514            return response.toElement()
    488515
    489         d = self.items(requestor, target, nodeIdentifier)
     516        d = self.items(request.sender, request.recipient,
     517                       request.nodeIdentifier)
    490518        d.addCallback(toResponse)
    491519        return d
  • wokkel/iwokkel.py

    r96 r134  
    1 # Copyright (c) Ralph Meijer.
     1# Copyright (c) 2003-2008 Ralph Meijer
    22# See LICENSE for details.
    33
     
    770770
    771771
    772     def affiliationsGet(request):
    773         """
    774         Called when a affiliations retrieval request (owner) has been received.
    775 
    776         @param request: The publish-subscribe request.
    777         @type request: L{wokkel.pubsub.PubSubRequest}
    778         @return: A deferred that fires with a C{dict} of affiliations with the
    779             entity as key (L{JID}) and the affiliation state as value
    780             (C{unicode}).  The affiliation can be C{u'owner'}, C{u'publisher'},
    781             or C{u'outcast'}.
    782         @rtype: L{defer.Deferred}
    783 
    784         @note: Affiliations are always on the bare JID. An implementation of
    785         this method MUST NOT return JIDs with a resource part.
    786         """
    787 
    788 
    789     def affiliationsSet(request):
    790         """
    791         Called when a affiliations modify request has been received.
    792 
    793         @param request: The publish-subscribe request.
    794         @type request: L{wokkel.pubsub.PubSubRequest}
    795         @return: A deferred that fires with C{None} when the affiliation
    796             changes were succesfully processed..
    797         @rtype: L{defer.Deferred}
    798 
    799         @note: Affiliations are always on the bare JID. The JIDs in
    800         L{wokkel.pubsub.PubSubRequest.affiliations} are already stripped of
    801         any resource.
    802         """
     772
     773class IMUCClient(Interface):
     774    """
     775    Multi-User Chat Client
     776
     777    A client interface to XEP-045 : http://xmpp.org/extensions/xep-0045.html
     778
     779    """
     780
     781    def receivedSubject(room, subject):
     782        """
     783        A subject is received when you join a room and when the subject is changed. This
     784        method is triggered by one of those two events.
     785
     786        @param room: The room the subject was accepted for.
     787        @type room: L{muc.Room}
     788
     789        @param subject: The subject of the given room.
     790        @type subject: C{unicode}
     791        """
     792
     793
     794    def receivedHistory(room, user, message, history, frm=None):
     795        """
     796        Past messages from a chat room has been received. This occurs when you join a room.
     797
     798
     799        """
     800
     801
     802    def configure(room_jid, fields=[]):
     803        """Configure a room. When a user has administration privledges they can configure
     804        a room.
     805
     806        @param room_jid: A XMPP entity for the room.
     807        @type room_jid: L{jid.JID}
     808
     809        @param fields: A list of fields to change or add to the room's configuration.
     810        @type fields: C{list}
     811
     812        """
     813
     814    def getConfigureForm(room_jid):
     815        """
     816        In order to know the fields to change in a room you will need to get the form.
     817       
     818        @param room_jid: The room you want the configuration form from.
     819        @type room_jid: L{jid.JID}
     820
     821        """
     822
     823    def join(server, room, nick):
     824        """
     825        Join a multi-user chat room.
     826
     827        @param server: The server the room is on.
     828        @type server: C{str}
     829
     830        @param room: The room name.
     831        @type room: C{str}
     832       
     833        @param nick: The nick name you want when you join the room.
     834        @type nick: C{str}
     835
     836        """
     837
     838
     839    def leave(room_jid):
     840        """
     841        Leave a multi-user chat room.
     842
     843        @param room_jid: The room you want the configuration form from.
     844        @type room_jid: L{jid.JID}
     845
     846        """
     847
     848    def userJoinedRoom(room, user):
     849        """User has joined the room.
     850
     851        @param room: The room the user joined.
     852        @type  room: L{muc.Room}
     853
     854        @param user: The user that joined the room.
     855        @type  user: L{muc.User}
     856
     857        """
     858   
     859
     860    def groupChat(to, message, children=None):
     861        """Send a groupchat message to a room.
     862
     863        """
     864
     865
     866    def chat(to, message, children=None):
     867        """
     868
     869        """
     870
     871
     872    def password(to, password):
     873        """
     874        """
     875   
     876    def register(to, fields=[]):
     877        """
     878        """
     879
     880
     881    def subject(to, subject):
     882        """
     883        """
     884
     885    def voice(to):
     886        """
     887        """
     888
     889
     890    def history(to, message_list):
     891        """
     892        """
     893
     894    def ban(to, ban_jid, frm, reason=None):
     895        """
     896        """
     897
     898
     899    def kick(to, kick_jid, frm, reason=None):
     900        """
     901        """
  • wokkel/iwokkel.py

    • Property exe set to *
Note: See TracChangeset for help on using the changeset viewer.