summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2013-06-29 22:33:00 -0700
committerLance Stout <lancestout@gmail.com>2013-06-29 22:33:00 -0700
commitcedc9dd175afba02e7beba21dc9eb4de1e63623d (patch)
treef3a88ae757f9312adc265f8b4da83e641c132259
parent669e708b70beb4d924caf552bf75640762248686 (diff)
downloadslixmpp-cedc9dd175afba02e7beba21dc9eb4de1e63623d.tar.gz
slixmpp-cedc9dd175afba02e7beba21dc9eb4de1e63623d.tar.bz2
slixmpp-cedc9dd175afba02e7beba21dc9eb4de1e63623d.tar.xz
slixmpp-cedc9dd175afba02e7beba21dc9eb4de1e63623d.zip
Adjust get_roster to always return, even with invalid JIDs
Issue #245
-rw-r--r--sleekxmpp/clientxmpp.py19
-rw-r--r--tests/test_stream_roster.py6
2 files changed, 17 insertions, 8 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py
index 905e1944..c8c389f6 100644
--- a/sleekxmpp/clientxmpp.py
+++ b/sleekxmpp/clientxmpp.py
@@ -96,6 +96,7 @@ class ClientXMPP(BaseXMPP):
self.add_event_handler('connected', self._reset_connection_state)
self.add_event_handler('session_bind', self._handle_session_bind)
+ self.add_event_handler('roster_update', self._handle_roster)
self.register_stanza(StreamFeatures)
@@ -106,7 +107,7 @@ class ClientXMPP(BaseXMPP):
self.register_handler(
Callback('Roster Update',
StanzaPath('iq@type=set/roster'),
- self._handle_roster))
+ lambda iq: self.event('roster_update', iq)))
# Setup default stream features
self.register_plugin('feature_starttls')
@@ -244,13 +245,22 @@ class ClientXMPP(BaseXMPP):
if 'rosterver' in self.features:
iq['roster']['ver'] = self.client_roster.version
- if not block and callback is None:
- callback = lambda resp: self._handle_roster(resp)
+
+ if not block or callback is not None:
+ block = False
+ if callback is None:
+ callback = lambda resp: self.event('roster_update', resp)
+ else:
+ orig_cb = callback
+ def wrapped(resp):
+ self.event('roster_update', resp)
+ orig_cb(resp)
+ callback = wrapped
response = iq.send(block, timeout, callback)
if block:
- self._handle_roster(response)
+ self.event('roster_update', response)
return response
def _reset_connection_state(self, event=None):
@@ -301,7 +311,6 @@ class ClientXMPP(BaseXMPP):
roster[jid].save(remove=(item['subscription'] == 'remove'))
- self.event("roster_update", iq)
if iq['type'] == 'set':
resp = self.Iq(stype='result',
sto=iq['from'],
diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py
index 3d1447a3..fa87105e 100644
--- a/tests/test_stream_roster.py
+++ b/tests/test_stream_roster.py
@@ -49,6 +49,9 @@ class TestStreamRoster(SleekTest):
# Wait for get_roster to return.
t.join()
+ # Give the event queue time to process.
+ time.sleep(.1)
+
self.check_roster('tester@localhost', 'user@localhost',
name='User',
subscription='from',
@@ -56,9 +59,6 @@ class TestStreamRoster(SleekTest):
pending_out=True,
groups=['Friends', 'Examples'])
- # Give the event queue time to process.
- time.sleep(.1)
-
self.failUnless(len(roster_updates) == 1,
"Wrong number of roster_update events fired: %s (should be 1)" % len(roster_updates))