Ignore:
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • debian/control

    r74 r143  
    1111Architecture: all
    1212XB-Python-Version: ${python:Versions}
    13 Depends: ${python:Depends}, ${misc:Depends}, python-twisted, python-twisted-words (>= 8.0.0), python-twisted-names
     13Depends: ${python:Depends}, ${misc:Depends}, python-twisted, python-twisted-words (>= 8.0.0), python-twisted-names, python-dateutil
    1414Description: A set of enhancements to Twisted Words' Jabber/XMPP
    1515 It serves as a testing ground for new features and enhancements which will
  • wokkel/iwokkel.py

    r96 r155  
    1 # Copyright (c) Ralph Meijer.
     1# Copyright (c) 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, user, 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 user: The user that set the subject.
     790        @type  user: L{muc.User}
     791
     792        @param subject: The subject of the given room.
     793        @type subject: C{unicode}
     794        """
     795
     796
     797    def receivedHistory(room, user, message):
     798        """
     799        Past messages from a chat room has been received. This occurs when you join a room.
     800        """
     801
     802
     803    def configure(roomJID, options):
     804        """
     805        Configure a room.
     806
     807        @param roomJID: The room to configure.
     808        @type roomJID: L{jid.JID}
     809
     810        @param options: A mapping of field names to values, or C{None} to cancel.
     811        @type options: C{dict}
     812        """
     813
     814
     815    def getConfiguration(roomJID):
     816        """
     817        Grab the configuration from the room.
     818
     819        This sends an iq request to the room.
     820
     821        @param roomJID: The bare JID of the room.
     822        @type roomJID: L{jid.JID}
     823
     824        @return: A deferred that fires with the room's configuration form as
     825            a L{data_form.Form} or C{None} if there are no configuration
     826            options available.
     827        """
     828
     829
     830    def join(roomJID, nick, historyOptions=None, password=None):
     831        """
     832        Join a MUC room by sending presence to it.
     833
     834        @param roomJID: The JID of the room the entity is joining.
     835        @type roomJID: L{jid.JID}
     836
     837        @param nick: The nick name for the entitity joining the room.
     838        @type nick: C{unicode}
     839
     840        @param historyOptions: Options for conversation history sent by the
     841            room upon joining.
     842        @type historyOptions: L{HistoryOptions}
     843
     844        @param password: Optional password for the room.
     845        @type password: C{unicode}
     846
     847        @return: A deferred that fires when the entity is in the room or an
     848                 error has occurred.
     849        """
     850
     851
     852    def nick(roomJID, nick):
     853        """
     854        Change an entity's nick name in a MUC room.
     855
     856        See: http://xmpp.org/extensions/xep-0045.html#changenick
     857
     858        @param roomJID: The JID of the room, i.e. without a resource.
     859        @type roomJID: L{jid.JID}
     860
     861        @param nick: The new nick name within the room.
     862        @type nick: C{unicode}
     863        """
     864
     865
     866    def leave(roomJID):
     867        """
     868        Leave a MUC room.
     869
     870        See: http://xmpp.org/extensions/xep-0045.html#exit
     871
     872        @param roomJID: The Room JID of the room to leave.
     873        @type roomJID: L{jid.JID}
     874        """
     875
     876
     877    def userJoinedRoom(room, user):
     878        """
     879        User has joined a MUC room.
     880
     881        This method will need to be modified inorder for clients to
     882        do something when this event occurs.
     883
     884        @param room: The room the user joined.
     885        @type  room: L{muc.Room}
     886
     887        @param user: The user that joined the room.
     888        @type  user: L{muc.User}
     889        """
     890
     891
     892    def groupChat(roomJID, body):
     893        """
     894        Send a groupchat message.
     895        """
     896
     897
     898    def chat(occupantJID, body):
     899        """
     900        Send a private chat message to a user in a MUC room.
     901
     902        See: http://xmpp.org/extensions/xep-0045.html#privatemessage
     903
     904        @param occupantJID: The Room JID of the other user.
     905        @type occupantJID: L{jid.JID}
     906        """
     907
     908
     909    def register(roomJID, options):
     910        """
     911        Send a request to register for a room.
     912
     913        @param roomJID: The bare JID of the room.
     914        @type roomJID: L{jid.JID}
     915
     916        @param options: A mapping of field names to values, or C{None} to
     917            cancel.
     918        @type options: C{dict}
     919        """
     920
     921
     922    def subject(roomJID, subject):
     923        """
     924        Change the subject of a MUC room.
     925
     926        See: http://xmpp.org/extensions/xep-0045.html#subject-mod
     927
     928        @param roomJID: The bare JID of the room.
     929        @type roomJID: L{jid.JID}
     930
     931        @param subject: The subject you want to set.
     932        @type subject: C{unicode}
     933        """
     934
     935
     936    def voice(roomJID):
     937        """
     938        Request voice for a moderated room.
     939
     940        @param roomJID: The room jabber/xmpp entity id.
     941        @type roomJID: L{jid.JID}
     942        """
     943
     944
     945    def history(roomJID, messages):
     946        """
     947        Send history to create a MUC based on a one on one chat.
     948
     949        See: http://xmpp.org/extensions/xep-0045.html#continue
     950
     951        @param roomJID: The room jabber/xmpp entity id.
     952        @type roomJID: L{jid.JID}
     953
     954        @param messages: The history to send to the room as an ordered list of
     955                         message, represented by a dictionary with the keys
     956                         C{'stanza'}, holding the original stanza a
     957                         L{domish.Element}, and C{'timestamp'} with the
     958                         timestamp.
     959        @type messages: L{list} of L{domish.Element}
     960        """
     961
     962
     963    def ban(roomJID, entity, reason=None, sender=None):
     964        """
     965        Ban a user from a MUC room.
     966
     967        @param roomJID: The bare JID of the room.
     968        @type roomJID: L{jid.JID}
     969
     970        @param entity: The bare JID of the entity to be banned.
     971        @type entity: L{jid.JID}
     972
     973        @param reason: The reason for banning the entity.
     974        @type reason: C{unicode}
     975
     976        @param sender: The entity sending the request.
     977        @type sender: L{jid.JID}
     978        """
     979
     980
     981    def kick(roomJID, nick, reason=None, sender=None):
     982        """
     983        Kick a user from a MUC room.
     984
     985        @param roomJID: The bare JID of the room.
     986        @type roomJID: L{jid.JID}
     987
     988        @param nick: The occupant to be banned.
     989        @type nick: L{jid.JID} or C{unicode}
     990
     991        @param reason: The reason given for the kick.
     992        @type reason: C{unicode}
     993
     994        @param sender: The entity sending the request.
     995        @type sender: L{jid.JID}
     996        """
  • wokkel/test/helpers.py

    r96 r147  
    66"""
    77
    8 from twisted.internet import defer
     8from twisted.internet import defer, task
    99from twisted.words.xish import xpath
    1010from twisted.words.xish.utility import EventDispatcher
    1111
    1212from wokkel.generic import parseXml
     13from wokkel.subprotocols import StreamManager
    1314
    1415class XmlStreamStub(object):
     
    9394
    9495        return d
     96
     97
     98class TestableStreamManager(StreamManager):
     99    """
     100    Stream manager for testing subprotocol handlers.
     101    """
     102
     103    def __init__(self, reactor=None):
     104        class DummyFactory(object):
     105            def addBootstrap(self, event, fn):
     106                pass
     107
     108        factory = DummyFactory()
     109        StreamManager.__init__(self, factory, reactor)
     110        self.stub = XmlStreamStub()
     111        self._connected(self.stub.xmlstream)
     112        self._authd(self.stub.xmlstream)
  • wokkel/xmppim.py

    r96 r141  
    297297
    298298
     299    def __get_status(self):
     300        if None in self.statuses:
     301            return self.statuses[None]
     302        elif self.statuses:
     303            for status in self.status.itervalues():
     304                return status
     305        else:
     306            return None
     307
     308    status = property(__get_status)
     309
     310
    299311    def _childParser_show(self, element):
    300312        show = unicode(element)
     
    368380
    369381
    370 class PresenceProtocol(XMPPHandler):
    371     """
    372     XMPP Presence protocol.
     382class BasePresenceProtocol(XMPPHandler):
     383    """
     384    XMPP Presence base protocol handler.
     385
     386    This class is the base for protocol handlers that receive presence
     387    stanzas. Listening to all incoming presence stanzas, it extracts the
     388    stanza's type and looks up a matching stanza parser and calls the
     389    associated method. The method's name is the type + C{Received}. E.g.
     390    C{availableReceived}. See L{PresenceProtocol} for a complete example.
    373391
    374392    @cvar presenceTypeParserMap: Maps presence stanza types to their respective
     
    376394    @type presenceTypeParserMap: C{dict}
    377395    """
     396
     397    presenceTypeParserMap = {}
     398
     399    def connectionInitialized(self):
     400        self.xmlstream.addObserver("/presence", self._onPresence)
     401
     402
     403
     404    def _onPresence(self, element):
     405        """
     406        Called when a presence stanza has been received.
     407        """
     408        stanza = Stanza.fromElement(element)
     409
     410        presenceType = stanza.stanzaType or 'available'
     411
     412        try:
     413            parser = self.presenceTypeParserMap[presenceType]
     414        except KeyError:
     415            return
     416
     417        presence = parser.fromElement(element)
     418
     419        try:
     420            handler = getattr(self, '%sReceived' % presenceType)
     421        except AttributeError:
     422            return
     423        else:
     424            handler(presence)
     425
     426
     427
     428class PresenceProtocol(BasePresenceProtocol):
    378429
    379430    presenceTypeParserMap = {
     
    386437                'unsubscribed': SubscriptionPresence,
    387438                'probe': ProbePresence,
    388         }
    389 
    390     def connectionInitialized(self):
    391         self.xmlstream.addObserver("/presence", self._onPresence)
    392 
    393 
    394     def _onPresence(self, element):
    395         stanza = Stanza.fromElement(element)
    396 
    397         presenceType = stanza.stanzaType or 'available'
    398 
    399         try:
    400             parser = self.presenceTypeParserMap[presenceType]
    401         except KeyError:
    402             return
    403 
    404         presence = parser.fromElement(element)
    405 
    406         try:
    407             handler = getattr(self, '%sReceived' % presenceType)
    408         except AttributeError:
    409             return
    410         else:
    411             handler(presence)
     439                }
    412440
    413441
     
    700728        """
    701729
     730
     731
     732class Message(Stanza):
     733    """
     734    A message stanza.
     735    """
     736
     737    stanzaKind = 'message'
     738
     739    childParsers = {
     740            (None, 'body'): '_childParser_body',
     741            (None, 'subject'): '_childParser_subject',
     742            }
     743
     744    def __init__(self, recipient=None, sender=None, body=None, subject=None):
     745        Stanza.__init__(self, recipient, sender)
     746        self.body = body
     747        self.subject = subject
     748
     749
     750    def _childParser_body(self, element):
     751        self.body = unicode(element)
     752
     753
     754    def _childParser_subject(self, element):
     755        self.subject = unicode(element)
     756
     757
     758    def toElement(self):
     759        element = Stanza.toElement(self)
     760
     761        if self.body:
     762            element.addElement('body', content=self.body)
     763        if self.subject:
     764            element.addElement('subject', content=self.subject)
     765
     766        return element
     767
     768
     769
    702770class MessageProtocol(XMPPHandler):
    703771    """
Note: See TracChangeset for help on using the changeset viewer.