Changeset 50:b69ca8f7174e in ralphm-patches
- Timestamp:
- Jun 1, 2011, 9:29:29 AM (11 years ago)
- Branch:
- default
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
jid_cleanup.patch
r49 r50 1 1 # HG changeset patch 2 # Parent c91f18811c37c85486826a8e7916333ad769dce72 # Parent 7d4897a32913c43d69e4b77db226714705ac5cd6 3 3 4 diff -r c91f18811c37wokkel/im.py5 --- a/wokkel/im.py Mon May 23 18:19:442011 +02006 +++ b/wokkel/im.py Wed May 25 09:36:06 2011 +02004 diff -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 7 7 @@ -12,7 +12,7 @@ 8 8 All of it should eventually move to Twisted. … … 10 10 11 11 -from twisted.words.protocols.jabber.jid import JID 12 +from twisted.words.protocols.jabber .jid import JID, internJID12 +from twisted.words.protocols.jabber import jid 13 13 from twisted.words.xish import domish 14 14 … … 19 19 sent. 20 20 - @type recipient: {JID} 21 + @type recipient: L{ JID}21 + @type recipient: L{jid.JID} 22 22 23 23 @param show: Optional detailed presence information. One of C{'away'}, … … 28 28 @param recipient: Optional entity to which the presence should be sent. 29 29 - @type recipient: {JID} 30 + @type recipient: L{ JID}30 + @type recipient: L{jid.JID} 31 31 32 32 @param statuses: dictionary of natural language descriptions of the … … 37 37 @param recipient: Entity to subscribe to. 38 38 - @type recipient: {JID} 39 + @type recipient: L{ JID}39 + @type recipient: L{jid.JID} 40 40 """ 41 41 presence = SubscriptionPresence(recipient=recipient, sender=sender) … … 46 46 @param recipient: Entity to unsubscribe from. 47 47 - @type recipient: {JID} 48 + @type recipient: L{ JID}48 + @type recipient: L{jid.JID} 49 49 """ 50 50 presence = SubscriptionPresence(recipient=recipient, sender=sender) … … 55 55 @param recipient: Entity that subscribed. 56 56 - @type recipient: {JID} 57 + @type recipient: L{ JID}57 + @type recipient: L{jid.JID} 58 58 """ 59 59 presence = SubscriptionPresence(recipient=recipient, sender=sender) … … 64 64 @param recipient: Entity that unsubscribed. 65 65 - @type recipient: {JID} 66 + @type recipient: L{ JID}66 + @type recipient: L{jid.JID} 67 67 """ 68 68 presence = SubscriptionPresence(recipient=recipient, sender=sender) … … 73 73 @param recipient: Entity to be probed. 74 74 - @type recipient: {JID} 75 + @type recipient: L{ JID}75 + @type recipient: L{jid.JID} 76 76 """ 77 77 presence = ProbePresence(recipient=recipient, sender=sender) 78 78 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 @@ 80 89 81 90 82 91 def _parseRosterItem(self, element): 83 92 - 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) 86 96 item.name = element.getAttribute('name') 87 97 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 88 108 @@ -453,7 +453,7 @@ 89 109 itemElement = iq.query.item … … 91 111 if unicode(itemElement['subscription']) == 'remove': 92 112 - self.onRosterRemove(JID(itemElement['jid'])) 93 + self.onRosterRemove( internJID(itemElement['jid']))113 + self.onRosterRemove(jid.internJID(itemElement['jid'])) 94 114 else: 95 115 item = self._parseRosterItem(iq.query.item) 96 116 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 c 91f18811c37wokkel/im.py2 --- a/wokkel/im.py Mon May 23 18:19:442011 +02003 +++ b/wokkel/im.py Wed May 25 09:24:292011 +02004 @@ -7,21 +7,2 7@@1 diff -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 @@ 5 5 XMPP IM protocol support. 6 6 … … 12 12 """ 13 13 14 +import warnings15 +16 14 +from twisted.internet import defer 17 from twisted.words.protocols.jabber .jid import JID, internJID15 from twisted.words.protocols.jabber import jid 18 16 +from twisted.words.protocols.jabber import error 19 17 from twisted.words.xish import domish … … 34 32 """ 35 33 Stanza of kind presence. 36 @@ -349,8 +35 5,8 @@34 @@ -349,8 +353,8 @@ 37 35 38 36 This represents one contact from an XMPP contact list known as roster. 39 37 40 38 - @ivar jid: The JID of the contact. 41 - @type jid: L{ JID}39 - @type jid: L{jid.JID} 42 40 + @ivar entity: The JID of the contact. 43 + @type entity: L{ JID}41 + @type entity: L{jid.JID} 44 42 @ivar name: The optional associated nickname for this contact. 45 43 @type name: C{unicode} 46 44 @ivar subscriptionTo: Subscription state to contact's presence. If C{True}, 47 @@ -360,47 +36 6,126@@45 @@ -360,47 +364,99 @@ 48 46 @ivar subscriptionFrom: Contact's subscription state. If C{True}, the 49 47 contact is subscribed to the presence information … … 87 85 -class RosterClientProtocol(XMPPHandler): 88 86 + 89 + def __getJID(self):90 + warnings.warn("Use RosterItem.entity instead.", DeprecationWarning)91 + return self.entity92 +93 +94 + def __setJID(self, value):95 + warnings.warn("Use RosterItem.entity instead.", DeprecationWarning)96 + self.entity = value97 +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.pendingOut106 +107 +108 + def __setAsk(self, value):109 + warnings.warn("Use RosterItem.pendingOut instead.", DeprecationWarning)110 + self.pendingOut = value111 +112 +113 + ask = property(__getAsk, __setAsk, doc="""114 + Pending out subscription. Deprecated in favour of C{pendingOut}.""")115 +116 +117 87 + def toElement(self): 118 88 + element = domish.Element((NS_ROSTER, 'item')) … … 146 116 + @classmethod 147 117 + def fromElement(Class, element): 148 + entity = internJID(element['jid'])118 + entity = jid.internJID(element['jid']) 149 119 + item = Class(entity) 150 120 + subscription = element.getAttribute('subscription') … … 178 148 + iqHandlers = {XPATH_ROSTER_SET: "_onRosterSet"} 179 149 + 150 + 180 151 def connectionInitialized(self): 181 152 - ROSTER_SET = "/iq[@type='set']/query[@xmlns='%s']" % NS_ROSTER … … 184 155 - 185 156 - def _parseRosterItem(self, element): 186 - jid =internJID(element['jid'])187 - item = RosterItem( jid)157 - entity = jid.internJID(element['jid']) 158 - item = RosterItem(entity) 188 159 - item.name = element.getAttribute('name') 189 160 - subscription = element.getAttribute('subscription') … … 200 171 201 172 def getRoster(self): 202 @@ -415,8 + 500,8 @@173 @@ -415,8 +471,8 @@ 203 174 roster = {} 204 175 for element in domish.generateElementsQNamed(result.query.children, … … 211 182 return roster 212 183 213 @@ -437,32 + 522,37@@184 @@ -437,32 +493,36 @@ 214 185 """ 215 186 iq = IQ(self.xmlstream, 'set') … … 228 199 - iq.hasAttribute('from') and iq['from'] != self.xmlstream: 229 200 - return 230 -231 - iq.handled = True232 201 + def eb(failure): 233 202 + failure.trap(RosterPushIgnored) 234 203 + raise error.StanzaError('service-unavailable') 235 204 236 itemElement = iq.query.item 205 - iq.handled = True 237 206 + item = RosterItem.fromElement(iq.query.item) 238 207 239 - if unicode(itemElement['subscription']) == 'remove': 240 - self.onRosterRemove(internJID(itemElement['jid'])) 208 - itemElement = iq.query.item 241 209 + if item.remove: 242 210 + 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: 244 217 - item = self._parseRosterItem(iq.query.item) 245 218 - self.onRosterSet(item) 246 + d = defer.maybeDeferred(self.onRosterSet, item)247 +248 219 + d.addErrback(eb) 249 220 + return d … … 261 232 @type item: L{RosterItem} 262 233 """ 263 @@ -472,6 +5 62,10 @@234 @@ -472,6 +532,10 @@ 264 235 """ 265 236 Called when a roster push for the removal of an item was received. … … 270 241 + 271 242 @param entity: The entity for which the roster item has been removed. 272 @type entity: L{ JID}243 @type entity: L{jid.JID} 273 244 """ 274 diff -r c 91f18811c37wokkel/test/test_im.py275 --- a/wokkel/test/test_im.py Mon May 23 18:19:442011 +0200276 +++ b/wokkel/test/test_im.py Wed May 25 09:24:292011 +0200245 diff -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 277 248 @@ -7,13 +7,14 @@ 278 249 … … 291 262 NS_XML = 'http://www.w3.org/XML/1998/namespace' 292 263 NS_ROSTER = 'jabber:iq:roster' 293 @@ -389,23 +390,3 56@@264 @@ -389,23 +390,305 @@ 294 265 295 266 … … 300 271 + Tests for L{im.RosterItem}. 301 272 + """ 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 = True334 + 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 +353 273 + 354 274 + def test_toElement(self): … … 653 573 # Inspect outgoing iq request 654 574 655 @@ -419,10 +7 53,117 @@575 @@ -419,10 +702,117 @@ 656 576 self.assertEquals(1, len(children)) 657 577 child = children[0] -
roster_item_more.patch
r49 r50 1 1 # HG changeset patch 2 # Parent 542d8f19d4438edd7493773cb7a6e0d5e1581d0c2 # Parent 2741eaf2b765b6b175a9da29669c23ce13e2a14c 3 3 4 diff -r 542d8f19d443wokkel/im.py5 --- a/wokkel/im.py Wed May 25 09:37:042011 +02006 +++ b/wokkel/im.py Wed May 25 09:39:422011 +02007 @@ -37 3,6 +373,12 @@4 diff -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 @@ 8 8 @ivar groups: Set of groups this contact is categorized in. Groups are 9 9 represented by an opaque identifier of type C{unicode}. … … 18 18 19 19 __subscriptionStates = {(False, False): None, 20 @@ -38 3,15 +389,17 @@20 @@ -381,15 +387,17 @@ 21 21 def __init__(self, entity, subscriptionTo=False, subscriptionFrom=False, 22 22 name=None, groups=None): … … 35 35 + 36 36 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') 40 41 41 itemElement = iq.query.item42 42 item = RosterItem.fromElement(iq.query.item) 43 43 + if iq.hasAttribute('from'): 44 + item.sender = internJID(iq['from'])44 + item.sender = jid.internJID(iq['from']) 45 45 46 46 if item.remove: 47 47 d = defer.maybeDeferred(self.onRosterRemove, item.entity) 48 diff -r 542d8f19d443wokkel/test/test_im.py49 --- a/wokkel/test/test_im.py Wed May 25 09:37:042011 +020050 +++ b/wokkel/test/test_im.py Wed May 25 09:39:422011 +020051 @@ - 815,9 +815,9 @@48 diff -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 @@ 52 52 return d 53 53 … … 61 61 xml = """ 62 62 <iq type='set' from='bad@example.org'> 63 @@ - 841,6 +841,34 @@63 @@ -790,6 +790,34 @@ 64 64 return d 65 65 -
roster_server.patch
r49 r50 1 diff -r 3c5fb05162e1wokkel/im.py2 --- a/wokkel/im.py Wed May 25 09:39:422011 +02003 +++ b/wokkel/im.py Wed May 25 09:40:282011 +02004 @@ -1 4,7 +14,7 @@1 diff -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 @@ 5 5 6 6 from twisted.internet import defer 7 from twisted.words.protocols.jabber .jid import JID, internJID7 from twisted.words.protocols.jabber import jid 8 8 -from twisted.words.protocols.jabber import error 9 9 +from twisted.words.protocols.jabber import error, xmlstream … … 11 11 12 12 from wokkel.compat import IQ 13 @@ -2 5,6 +25,7 @@13 @@ -23,6 +23,7 @@ 14 14 NS_ROSTER = 'jabber:iq:roster' 15 15 … … 19 19 20 20 21 @@ -5 79,3 +580,43 @@21 @@ -550,3 +551,43 @@ 22 22 @param entity: The entity for which the roster item has been removed. 23 @type entity: L{ JID}23 @type entity: L{jid.JID} 24 24 """ 25 25 +
Note: See TracChangeset
for help on using the changeset viewer.