From 12e8bb6ddcd686ec9835ba478a112984e65120a1 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 31 Oct 2012 00:03:55 -0700 Subject: Turns out not all data is UTF-8, so don't try to decode it. Fixes issue #204 --- examples/ibb_transfer/ibb_receiver.py | 2 +- sleekxmpp/plugins/xep_0047/stanza.py | 2 +- tests/test_stream_xep_0047.py | 28 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/ibb_transfer/ibb_receiver.py b/examples/ibb_transfer/ibb_receiver.py index 18d18f92..0169d63d 100755 --- a/examples/ibb_transfer/ibb_receiver.py +++ b/examples/ibb_transfer/ibb_receiver.py @@ -85,7 +85,7 @@ class IBBReceiver(sleekxmpp.ClientXMPP): def stream_opened(self, stream): # NOTE: IBB streams are bi-directional, so the original sender is # now the opened stream's receiver. - print('Stream opened: %s from ' % (stream.sid, stream.receiver)) + print('Stream opened: %s from %s' % (stream.sid, stream.receiver)) # You could run a loop reading from the stream using stream.recv(), # or use the ibb_stream_data event. diff --git a/sleekxmpp/plugins/xep_0047/stanza.py b/sleekxmpp/plugins/xep_0047/stanza.py index e4a32f87..7e5d2fed 100644 --- a/sleekxmpp/plugins/xep_0047/stanza.py +++ b/sleekxmpp/plugins/xep_0047/stanza.py @@ -14,7 +14,7 @@ def to_b64(data): def from_b64(data): - return bytes(base64.b64decode(bytes(data))).decode('utf-8') + return bytes(base64.b64decode(bytes(data))) class Open(ElementBase): diff --git a/tests/test_stream_xep_0047.py b/tests/test_stream_xep_0047.py index d8cdd6a3..8c46606e 100644 --- a/tests/test_stream_xep_0047.py +++ b/tests/test_stream_xep_0047.py @@ -5,7 +5,7 @@ from sleekxmpp.test import * class TestInBandByteStreams(SleekTest): - + def setUp(self): self.stream_start(plugins=['xep_0047', 'xep_0030']) @@ -13,7 +13,7 @@ class TestInBandByteStreams(SleekTest): self.stream_close() def testOpenStream(self): - """Test requesting a stream, successfully""" + """Test requesting a stream, successfully""" events = [] @@ -22,7 +22,7 @@ class TestInBandByteStreams(SleekTest): self.xmpp.add_event_handler('ibb_stream_start', on_stream_start) - + t = threading.Thread(name='open_stream', target=self.xmpp['xep_0047'].open_stream, args=('tester@localhost/receiver',), @@ -31,7 +31,7 @@ class TestInBandByteStreams(SleekTest): self.send(""" - @@ -62,18 +62,18 @@ class TestInBandByteStreams(SleekTest): events.add('callback') self.xmpp.add_event_handler('ibb_stream_start', on_stream_start) - + t = threading.Thread(name='open_stream', target=self.xmpp['xep_0047'].open_stream, args=('tester@localhost/receiver',), - kwargs={'sid': 'testing', + kwargs={'sid': 'testing', 'block': False, 'callback': stream_callback}) t.start() self.send(""" - @@ -106,7 +106,7 @@ class TestInBandByteStreams(SleekTest): self.xmpp.add_event_handler('ibb_stream_start', on_stream_start) self.xmpp.add_event_handler('ibb_stream_data', on_stream_data) - + t = threading.Thread(name='open_stream', target=self.xmpp['xep_0047'].open_stream, args=('tester@localhost/receiver',), @@ -115,7 +115,7 @@ class TestInBandByteStreams(SleekTest): self.send(""" - @@ -142,8 +142,8 @@ class TestInBandByteStreams(SleekTest): - VGVzdGluZw== @@ -161,8 +161,8 @@ class TestInBandByteStreams(SleekTest): - aXQgd29ya3Mh @@ -174,7 +174,7 @@ class TestInBandByteStreams(SleekTest): to="tester@localhost/receiver" /> """) - self.assertEqual(data, ['it works!']) + self.assertEqual(data, [b'it works!']) suite = unittest.TestLoader().loadTestsFromTestCase(TestInBandByteStreams) -- cgit v1.2.3