diff --git a/sat/plugins/plugin_xep_0231.py b/sat/plugins/plugin_xep_0231.py index e21c4bc7..ec55b502 100644 --- a/sat/plugins/plugin_xep_0231.py +++ b/sat/plugins/plugin_xep_0231.py @@ -184,11 +184,12 @@ class XEP_0231(object): 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 @@ class XEP_0231(object): 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 @@ class XEP_0231(object): @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: diff --git a/sat/plugins/plugin_xep_0264.py b/sat/plugins/plugin_xep_0264.py index e5ea129a..45240ff6 100644 --- a/sat/plugins/plugin_xep_0264.py +++ b/sat/plugins/plugin_xep_0264.py @@ -131,7 +131,7 @@ class XEP_0264(object): @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