# HG changeset patch # User Goffi # Date 1589837981 -7200 # Node ID 4230aaeab9a7e5cb9305be5355e132c2912b2f4d # Parent 4c98f4972db5f6cf75cd163deb2d214dab276b25 plugin XEP-0231, XEP-0264: fixed some remaining encoding issue following Python 3 port diff -r 4c98f4972db5 -r 4230aaeab9a7 sat/plugins/plugin_xep_0231.py --- 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: diff -r 4c98f4972db5 -r 4230aaeab9a7 sat/plugins/plugin_xep_0264.py --- 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