source: ralphm-patches/roster_item_more.patch @ 49:537d1413b661

Last change on this file since 49:537d1413b661 was 49:537d1413b661, checked in by Ralph Meijer <ralphm@…>, 9 years ago

Save work after moving stuff to keep from wokkel.xmppim to wokkel.im.

File size: 2.9 KB
  • wokkel/im.py

    # HG changeset patch
    # Parent 542d8f19d4438edd7493773cb7a6e0d5e1581d0c
    
    diff -r 542d8f19d443 wokkel/im.py
    a b  
    373373    @ivar groups: Set of groups this contact is categorized in. Groups are
    374374                  represented by an opaque identifier of type C{unicode}.
    375375    @type groups: C{set}
     376    @ivar approved: Signals pre-approved subscription.
     377    @type approved: C{bool}
     378    @ivar remove: Signals roster item removal.
     379    @type remove: C{bool}
     380    @ivar sender: The JID of the entity that sent this roster item.
     381    @type sender: L{JID}
    376382    """
    377383
    378384    __subscriptionStates = {(False, False): None,
     
    383389    def __init__(self, entity, subscriptionTo=False, subscriptionFrom=False,
    384390                       name=None, groups=None):
    385391        self.entity = entity
     392        self.name = name
    386393        self.subscriptionTo = subscriptionTo
    387394        self.subscriptionFrom = subscriptionFrom
    388         self.name = name
    389395        self.groups = groups or set()
    390396
    391397        self.pendingOut = False
    392398        self.approved = False
    393399        self.remove = False
    394400
     401        self.sender = None
     402
    395403
    396404    def __getJID(self):
    397405        warnings.warn("Use RosterItem.entity instead.", DeprecationWarning)
     
    535543
    536544        itemElement = iq.query.item
    537545        item = RosterItem.fromElement(iq.query.item)
     546        if iq.hasAttribute('from'):
     547            item.sender = internJID(iq['from'])
    538548
    539549        if item.remove:
    540550            d = defer.maybeDeferred(self.onRosterRemove, item.entity)
  • wokkel/test/test_im.py

    diff -r 542d8f19d443 wokkel/test/test_im.py
    a b  
    815815        return d
    816816
    817817
    818     def test_onRosterSetUntrusted(self):
     818    def test_onRosterSetIgnored(self):
    819819        """
    820         Roster pushes from untrusted sources will be not be handled.
     820        Ignored roster pushes return a service unavailable error.
    821821        """
    822822        xml = """
    823823          <iq type='set' from='bad@example.org'>
     
    841841        return d
    842842
    843843
     844    def test_onRosterSetOtherSource(self):
     845        """
     846        Roster pushes can be sent from other entities, too.
     847        """
     848        xml = """
     849          <iq type='set' from='other@example.org'>
     850            <query xmlns='jabber:iq:roster'>
     851              <item jid='user@example.org'/>
     852            </query>
     853          </iq>
     854        """
     855
     856        items = []
     857
     858        def onRosterSet(item):
     859            items.append(item)
     860
     861        def cb(result):
     862            item = items[0]
     863            self.assertEquals(JID('other@example.org'), item.sender)
     864
     865        self.service.onRosterSet = onRosterSet
     866
     867        d = self.handleRequest(xml)
     868        d.addCallback(cb)
     869        return d
     870
     871
    844872    def test_onRosterRemove(self):
    845873        """
    846874        A roster push causes onRosterSet to be called with the parsed item.
Note: See TracBrowser for help on using the repository browser.