changeset 3273:4230aaeab9a7

plugin XEP-0231, XEP-0264: fixed some remaining encoding issue following Python 3 port
author Goffi <goffi@goffi.org>
date Mon, 18 May 2020 23:39:41 +0200 (2020-05-18)
parents 4c98f4972db5
children 430204a3cc10
files sat/plugins/plugin_xep_0231.py sat/plugins/plugin_xep_0264.py
diffstat 2 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0231.py	Mon May 18 23:38:21 2020 +0200
+++ b/sat/plugins/plugin_xep_0231.py	Mon May 18 23:39:41 2020 +0200
@@ -184,11 +184,12 @@
             client.send(error_elt)
             return
 
-        with open(metadata["path"]) as f:
+        with open(metadata["path"], 'rb') as f:
             data = f.read()
 
         result_elt = xmlstream.toResponse(iq_elt, "result")
-        data_elt = result_elt.addElement((NS_BOB, "data"), content=data.encode("base64"))
+        data_elt = result_elt.addElement(
+            (NS_BOB, "data"), content=base64.b64encode(data).decode())
         data_elt["cid"] = cid
         data_elt["type"] = metadata["mime_type"]
         data_elt["max-age"] = str(int(max(0, metadata["eol"] - time.time())))
@@ -198,7 +199,9 @@
         peer_jid = jid.JID(peer_jid_s)
         assert cid
         client = self.host.getClient(profile)
-        return self.getFile(client, peer_jid, cid)
+        d = self.getFile(client, peer_jid, cid)
+        d.addCallback(lambda path: str(path))
+        return d
 
     def getFile(self, client, peer_jid, cid, parent_elt=None):
         """Retrieve a file from it's content-id
@@ -208,7 +211,7 @@
         @param parent_elt(domish.Element, None): if file is not in cache,
             data will be looked after in children of this elements.
             None to ignore
-        @return D(unicode): path to cached data
+        @return D(Path): path to cached data
         """
         file_path = client.cache.getFilePath(cid)
         if file_path is not None:
--- a/sat/plugins/plugin_xep_0264.py	Mon May 18 23:38:21 2020 +0200
+++ b/sat/plugins/plugin_xep_0264.py	Mon May 18 23:39:41 2020 +0200
@@ -131,7 +131,7 @@
         @param size(tuple(int)): requested size of thumbnail
         @return (unicode): unique id for this image/size
         """
-        return hashlib.sha256(repr((image_uid, size))).hexdigest()
+        return hashlib.sha256(repr((image_uid, size)).encode()).hexdigest()
 
     def _blockingGenThumb(self, source_path, size=None, max_age=None, image_uid=None):
         """Generate a thumbnail for image