Changeset 50:b69ca8f7174e in ralphm-patches


Ignore:
Timestamp:
Jun 1, 2011, 9:29:29 AM (9 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Cleanup JIDs a bit more and adjust affected patches.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • jid_cleanup.patch

    r49 r50  
    11# HG changeset patch
    2 # Parent c91f18811c37c85486826a8e7916333ad769dce7
     2# Parent 7d4897a32913c43d69e4b77db226714705ac5cd6
    33
    4 diff -r c91f18811c37 wokkel/im.py
    5 --- a/wokkel/im.py      Mon May 23 18:19:44 2011 +0200
    6 +++ b/wokkel/im.py      Wed May 25 09:36:06 2011 +0200
     4diff -r 7d4897a32913 wokkel/im.py
     5--- a/wokkel/im.py      Wed May 25 09:48:39 2011 +0200
     6+++ b/wokkel/im.py      Wed May 25 20:24:36 2011 +0200
    77@@ -12,7 +12,7 @@
    88 All of it should eventually move to Twisted.
     
    1010 
    1111-from twisted.words.protocols.jabber.jid import JID
    12 +from twisted.words.protocols.jabber.jid import JID, internJID
     12+from twisted.words.protocols.jabber import jid
    1313 from twisted.words.xish import domish
    1414 
     
    1919             sent.
    2020-        @type recipient: {JID}
    21 +        @type recipient: L{JID}
     21+        @type recipient: L{jid.JID}
    2222 
    2323         @param show: Optional detailed presence information. One of C{'away'},
     
    2828         @param recipient: Optional entity to which the presence should be sent.
    2929-        @type recipient: {JID}
    30 +        @type recipient: L{JID}
     30+        @type recipient: L{jid.JID}
    3131 
    3232         @param statuses: dictionary of natural language descriptions of the
     
    3737         @param recipient: Entity to subscribe to.
    3838-        @type recipient: {JID}
    39 +        @type recipient: L{JID}
     39+        @type recipient: L{jid.JID}
    4040         """
    4141         presence = SubscriptionPresence(recipient=recipient, sender=sender)
     
    4646         @param recipient: Entity to unsubscribe from.
    4747-        @type recipient: {JID}
    48 +        @type recipient: L{JID}
     48+        @type recipient: L{jid.JID}
    4949         """
    5050         presence = SubscriptionPresence(recipient=recipient, sender=sender)
     
    5555         @param recipient: Entity that subscribed.
    5656-        @type recipient: {JID}
    57 +        @type recipient: L{JID}
     57+        @type recipient: L{jid.JID}
    5858         """
    5959         presence = SubscriptionPresence(recipient=recipient, sender=sender)
     
    6464         @param recipient: Entity that unsubscribed.
    6565-        @type recipient: {JID}
    66 +        @type recipient: L{JID}
     66+        @type recipient: L{jid.JID}
    6767         """
    6868         presence = SubscriptionPresence(recipient=recipient, sender=sender)
     
    7373         @param recipient: Entity to be probed.
    7474-        @type recipient: {JID}
    75 +        @type recipient: L{JID}
     75+        @type recipient: L{jid.JID}
    7676         """
    7777         presence = ProbePresence(recipient=recipient, sender=sender)
    7878         self.send(presence.toElement())
    79 @@ -389,7 +389,7 @@
     79@@ -350,7 +350,7 @@
     80     This represents one contact from an XMPP contact list known as roster.
     81 
     82     @ivar jid: The JID of the contact.
     83-    @type jid: L{JID}
     84+    @type jid: L{jid.JID}
     85     @ivar name: The optional associated nickname for this contact.
     86     @type name: C{unicode}
     87     @ivar subscriptionTo: Subscription state to contact's presence. If C{True},
     88@@ -389,8 +389,8 @@
    8089 
    8190 
    8291     def _parseRosterItem(self, element):
    8392-        jid = JID(element['jid'])
    84 +        jid = internJID(element['jid'])
    85          item = RosterItem(jid)
     93-        item = RosterItem(jid)
     94+        entity = jid.internJID(element['jid'])
     95+        item = RosterItem(entity)
    8696         item.name = element.getAttribute('name')
    8797         subscription = element.getAttribute('subscription')
     98         item.subscriptionTo = subscription in ('to', 'both')
     99@@ -407,7 +407,7 @@
     100         """
     101         Retrieve contact list.
     102 
     103-        @return: Roster as a mapping from L{JID} to L{RosterItem}.
     104+        @return: Roster as a mapping from L{jid.JID} to L{RosterItem}.
     105         @rtype: L{twisted.internet.defer.Deferred}
     106         """
     107 
    88108@@ -453,7 +453,7 @@
    89109         itemElement = iq.query.item
     
    91111         if unicode(itemElement['subscription']) == 'remove':
    92112-            self.onRosterRemove(JID(itemElement['jid']))
    93 +            self.onRosterRemove(internJID(itemElement['jid']))
     113+            self.onRosterRemove(jid.internJID(itemElement['jid']))
    94114         else:
    95115             item = self._parseRosterItem(iq.query.item)
    96116             self.onRosterSet(item)
     117@@ -473,5 +473,5 @@
     118         Called when a roster push for the removal of an item was received.
     119 
     120         @param entity: The entity for which the roster item has been removed.
     121-        @type entity: L{JID}
     122+        @type entity: L{jid.JID}
     123         """
  • roster_item.patch

    r49 r50  
    1 diff -r c91f18811c37 wokkel/im.py
    2 --- a/wokkel/im.py      Mon May 23 18:19:44 2011 +0200
    3 +++ b/wokkel/im.py      Wed May 25 09:24:29 2011 +0200
    4 @@ -7,21 +7,27 @@
     1diff -r c103529d9f46 wokkel/im.py
     2--- a/wokkel/im.py      Wed May 25 20:24:36 2011 +0200
     3+++ b/wokkel/im.py      Wed May 25 20:26:47 2011 +0200
     4@@ -7,21 +7,25 @@
    55 XMPP IM protocol support.
    66 
     
    1212 """
    1313 
    14 +import warnings
    15 +
    1614+from twisted.internet import defer
    17  from twisted.words.protocols.jabber.jid import JID, internJID
     15 from twisted.words.protocols.jabber import jid
    1816+from twisted.words.protocols.jabber import error
    1917 from twisted.words.xish import domish
     
    3432     """
    3533     Stanza of kind presence.
    36 @@ -349,8 +355,8 @@
     34@@ -349,8 +353,8 @@
    3735 
    3836     This represents one contact from an XMPP contact list known as roster.
    3937 
    4038-    @ivar jid: The JID of the contact.
    41 -    @type jid: L{JID}
     39-    @type jid: L{jid.JID}
    4240+    @ivar entity: The JID of the contact.
    43 +    @type entity: L{JID}
     41+    @type entity: L{jid.JID}
    4442     @ivar name: The optional associated nickname for this contact.
    4543     @type name: C{unicode}
    4644     @ivar subscriptionTo: Subscription state to contact's presence. If C{True},
    47 @@ -360,47 +366,126 @@
     45@@ -360,47 +364,99 @@
    4846     @ivar subscriptionFrom: Contact's subscription state. If C{True}, the
    4947                             contact is subscribed to the presence information
     
    8785-class RosterClientProtocol(XMPPHandler):
    8886+
    89 +    def __getJID(self):
    90 +        warnings.warn("Use RosterItem.entity instead.", DeprecationWarning)
    91 +        return self.entity
    92 +
    93 +
    94 +    def __setJID(self, value):
    95 +        warnings.warn("Use RosterItem.entity instead.", DeprecationWarning)
    96 +        self.entity = value
    97 +
    98 +
    99 +    jid = property(__getJID, __setJID, doc="""
    100 +            JID of the contact. Deprecated in favour of C{entity}.""")
    101 +
    102 +
    103 +    def __getAsk(self):
    104 +        warnings.warn("Use RosterItem.pendingOut instead.", DeprecationWarning)
    105 +        return self.pendingOut
    106 +
    107 +
    108 +    def __setAsk(self, value):
    109 +        warnings.warn("Use RosterItem.pendingOut instead.", DeprecationWarning)
    110 +        self.pendingOut = value
    111 +
    112 +
    113 +    ask = property(__getAsk, __setAsk, doc="""
    114 +            Pending out subscription. Deprecated in favour of C{pendingOut}.""")
    115 +
    116 +
    11787+    def toElement(self):
    11888+        element = domish.Element((NS_ROSTER, 'item'))
     
    146116+    @classmethod
    147117+    def fromElement(Class, element):
    148 +        entity = internJID(element['jid'])
     118+        entity = jid.internJID(element['jid'])
    149119+        item = Class(entity)
    150120+        subscription = element.getAttribute('subscription')
     
    178148+    iqHandlers = {XPATH_ROSTER_SET: "_onRosterSet"}
    179149+
     150+
    180151     def connectionInitialized(self):
    181152-        ROSTER_SET = "/iq[@type='set']/query[@xmlns='%s']" % NS_ROSTER
     
    184155-
    185156-    def _parseRosterItem(self, element):
    186 -        jid = internJID(element['jid'])
    187 -        item = RosterItem(jid)
     157-        entity = jid.internJID(element['jid'])
     158-        item = RosterItem(entity)
    188159-        item.name = element.getAttribute('name')
    189160-        subscription = element.getAttribute('subscription')
     
    200171 
    201172     def getRoster(self):
    202 @@ -415,8 +500,8 @@
     173@@ -415,8 +471,8 @@
    203174             roster = {}
    204175             for element in domish.generateElementsQNamed(result.query.children,
     
    211182             return roster
    212183 
    213 @@ -437,32 +522,37 @@
     184@@ -437,32 +493,36 @@
    214185         """
    215186         iq = IQ(self.xmlstream, 'set')
     
    228199-           iq.hasAttribute('from') and iq['from'] != self.xmlstream:
    229200-            return
    230 -
    231 -        iq.handled = True
    232201+        def eb(failure):
    233202+            failure.trap(RosterPushIgnored)
    234203+            raise error.StanzaError('service-unavailable')
    235204 
    236          itemElement = iq.query.item
     205-        iq.handled = True
    237206+        item = RosterItem.fromElement(iq.query.item)
    238207 
    239 -        if unicode(itemElement['subscription']) == 'remove':
    240 -            self.onRosterRemove(internJID(itemElement['jid']))
     208-        itemElement = iq.query.item
    241209+        if item.remove:
    242210+            d = defer.maybeDeferred(self.onRosterRemove, item.entity)
    243          else:
     211+        else:
     212+            d = defer.maybeDeferred(self.onRosterSet, item)
     213 
     214-        if unicode(itemElement['subscription']) == 'remove':
     215-            self.onRosterRemove(jid.internJID(itemElement['jid']))
     216-        else:
    244217-            item = self._parseRosterItem(iq.query.item)
    245218-            self.onRosterSet(item)
    246 +            d = defer.maybeDeferred(self.onRosterSet, item)
    247 +
    248219+        d.addErrback(eb)
    249220+        return d
     
    261232         @type item: L{RosterItem}
    262233         """
    263 @@ -472,6 +562,10 @@
     234@@ -472,6 +532,10 @@
    264235         """
    265236         Called when a roster push for the removal of an item was received.
     
    270241+
    271242         @param entity: The entity for which the roster item has been removed.
    272          @type entity: L{JID}
     243         @type entity: L{jid.JID}
    273244         """
    274 diff -r c91f18811c37 wokkel/test/test_im.py
    275 --- a/wokkel/test/test_im.py    Mon May 23 18:19:44 2011 +0200
    276 +++ b/wokkel/test/test_im.py    Wed May 25 09:24:29 2011 +0200
     245diff -r c103529d9f46 wokkel/test/test_im.py
     246--- a/wokkel/test/test_im.py    Wed May 25 20:24:36 2011 +0200
     247+++ b/wokkel/test/test_im.py    Wed May 25 20:26:47 2011 +0200
    277248@@ -7,13 +7,14 @@
    278249 
     
    291262 NS_XML = 'http://www.w3.org/XML/1998/namespace'
    292263 NS_ROSTER = 'jabber:iq:roster'
    293 @@ -389,23 +390,356 @@
     264@@ -389,23 +390,305 @@
    294265 
    295266 
     
    300271+    Tests for L{im.RosterItem}.
    301272+    """
    302 +
    303 +    def test_jidDeprecationGet(self):
    304 +        """
    305 +        Getting the jid attribute works as entity and warns deprecation.
    306 +        """
    307 +        item = im.RosterItem(JID('user@example.org'))
    308 +        entity = self.assertWarns(DeprecationWarning,
    309 +                                  "Use RosterItem.entity instead.",
    310 +                                  im.__file__,
    311 +                                  getattr, item, 'jid')
    312 +        self.assertIdentical(entity, item.entity)
    313 +
    314 +
    315 +    def test_jidDeprecationSet(self):
    316 +        """
    317 +        Setting the jid attribute works as entity and warns deprecation.
    318 +        """
    319 +        item = im.RosterItem(JID('user@example.org'))
    320 +        entity = self.assertWarns(DeprecationWarning,
    321 +                                  "Use RosterItem.entity instead.",
    322 +                                  im.__file__,
    323 +                                  setattr, item, 'jid',
    324 +                                  JID('other@example.org'))
    325 +        self.assertEquals(JID('other@example.org'), item.entity)
    326 +
    327 +
    328 +    def test_askDeprecationGet(self):
    329 +        """
    330 +        Getting the ask attribute works as entity and warns deprecation.
    331 +        """
    332 +        item = im.RosterItem(JID('user@example.org'))
    333 +        item.pendingOut = True
    334 +        ask = self.assertWarns(DeprecationWarning,
    335 +                               "Use RosterItem.pendingOut instead.",
    336 +                               im.__file__,
    337 +                               getattr, item, 'ask')
    338 +        self.assertTrue(ask)
    339 +
    340 +
    341 +    def test_askDeprecationSet(self):
    342 +        """
    343 +        Setting the ask attribute works as entity and warns deprecation.
    344 +        """
    345 +        item = im.RosterItem(JID('user@example.org'))
    346 +        entity = self.assertWarns(DeprecationWarning,
    347 +                                  "Use RosterItem.pendingOut instead.",
    348 +                                  im.__file__,
    349 +                                  setattr, item, 'ask',
    350 +                                  True)
    351 +        self.assertTrue(item.pendingOut)
    352 +
    353273+
    354274+    def test_toElement(self):
     
    653573         # Inspect outgoing iq request
    654574 
    655 @@ -419,10 +753,117 @@
     575@@ -419,10 +702,117 @@
    656576         self.assertEquals(1, len(children))
    657577         child = children[0]
  • roster_item_more.patch

    r49 r50  
    11# HG changeset patch
    2 # Parent 542d8f19d4438edd7493773cb7a6e0d5e1581d0c
     2# Parent 2741eaf2b765b6b175a9da29669c23ce13e2a14c
    33
    4 diff -r 542d8f19d443 wokkel/im.py
    5 --- a/wokkel/im.py      Wed May 25 09:37:04 2011 +0200
    6 +++ b/wokkel/im.py      Wed May 25 09:39:42 2011 +0200
    7 @@ -373,6 +373,12 @@
     4diff -r 2741eaf2b765 wokkel/im.py
     5--- a/wokkel/im.py      Wed May 25 20:26:47 2011 +0200
     6+++ b/wokkel/im.py      Wed May 25 20:27:04 2011 +0200
     7@@ -371,6 +371,12 @@
    88     @ivar groups: Set of groups this contact is categorized in. Groups are
    99                   represented by an opaque identifier of type C{unicode}.
     
    1818 
    1919     __subscriptionStates = {(False, False): None,
    20 @@ -383,15 +389,17 @@
     20@@ -381,15 +387,17 @@
    2121     def __init__(self, entity, subscriptionTo=False, subscriptionFrom=False,
    2222                        name=None, groups=None):
     
    3535+
    3636 
    37      def __getJID(self):
    38          warnings.warn("Use RosterItem.entity instead.", DeprecationWarning)
    39 @@ -535,6 +543,8 @@
     37     def toElement(self):
     38         element = domish.Element((NS_ROSTER, 'item'))
     39@@ -505,6 +513,8 @@
     40             raise error.StanzaError('service-unavailable')
    4041 
    41          itemElement = iq.query.item
    4242         item = RosterItem.fromElement(iq.query.item)
    4343+        if iq.hasAttribute('from'):
    44 +            item.sender = internJID(iq['from'])
     44+            item.sender = jid.internJID(iq['from'])
    4545 
    4646         if item.remove:
    4747             d = defer.maybeDeferred(self.onRosterRemove, item.entity)
    48 diff -r 542d8f19d443 wokkel/test/test_im.py
    49 --- a/wokkel/test/test_im.py    Wed May 25 09:37:04 2011 +0200
    50 +++ b/wokkel/test/test_im.py    Wed May 25 09:39:42 2011 +0200
    51 @@ -815,9 +815,9 @@
     48diff -r 2741eaf2b765 wokkel/test/test_im.py
     49--- a/wokkel/test/test_im.py    Wed May 25 20:26:47 2011 +0200
     50+++ b/wokkel/test/test_im.py    Wed May 25 20:27:04 2011 +0200
     51@@ -764,9 +764,9 @@
    5252         return d
    5353 
     
    6161         xml = """
    6262           <iq type='set' from='bad@example.org'>
    63 @@ -841,6 +841,34 @@
     63@@ -790,6 +790,34 @@
    6464         return d
    6565 
  • roster_server.patch

    r49 r50  
    1 diff -r 3c5fb05162e1 wokkel/im.py
    2 --- a/wokkel/im.py      Wed May 25 09:39:42 2011 +0200
    3 +++ b/wokkel/im.py      Wed May 25 09:40:28 2011 +0200
    4 @@ -14,7 +14,7 @@
     1diff -r 05330d69e16c wokkel/im.py
     2--- a/wokkel/im.py      Wed May 25 20:20:50 2011 +0200
     3+++ b/wokkel/im.py      Wed May 25 20:22:14 2011 +0200
     4@@ -12,7 +12,7 @@
    55 
    66 from twisted.internet import defer
    7  from twisted.words.protocols.jabber.jid import JID, internJID
     7 from twisted.words.protocols.jabber import jid
    88-from twisted.words.protocols.jabber import error
    99+from twisted.words.protocols.jabber import error, xmlstream
     
    1111 
    1212 from wokkel.compat import IQ
    13 @@ -25,6 +25,7 @@
     13@@ -23,6 +23,7 @@
    1414 NS_ROSTER = 'jabber:iq:roster'
    1515 
     
    1919 
    2020 
    21 @@ -579,3 +580,43 @@
     21@@ -550,3 +551,43 @@
    2222         @param entity: The entity for which the roster item has been removed.
    23          @type entity: L{JID}
     23         @type entity: L{jid.JID}
    2424         """
    2525+
Note: See TracChangeset for help on using the changeset viewer.