diff sat/plugins/plugin_xep_0047.py @ 3392:0957ea9137b8

plugin XEP-0047: fixed file reading and content encoding
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:15 +0100
parents 559a625a236b
children be6d91572633
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0047.py	Thu Nov 12 14:53:15 2020 +0100
+++ b/sat/plugins/plugin_xep_0047.py	Thu Nov 12 14:53:15 2020 +0100
@@ -327,7 +327,8 @@
         """
         session_data["timer"].reset(TIMEOUT)
 
-        buffer_ = session_data["stream_object"].read(session_data["block_size"])
+        # FIXME: producer/consumer mechanism is not used properly here
+        buffer_ = session_data["stream_object"].file_obj.read(session_data["block_size"])
         if buffer_:
             next_iq_elt = client.IQ()
             next_iq_elt["from"] = session_data["local_jid"].full()
@@ -336,7 +337,7 @@
             seq = session_data["seq"] = (session_data["seq"] + 1) % 65535
             data_elt["seq"] = str(seq)
             data_elt["sid"] = session_data["id"]
-            data_elt.addContent(base64.b64encode(buffer_))
+            data_elt.addContent(base64.b64encode(buffer_).decode())
             args = [session_data, client]
             d = next_iq_elt.send()
             d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args)