plugin XEP-0231, XEP-0264: fixed some remaining encoding issue following Python 3 port

This commit is contained in:
Goffi 2020-05-18 23:39:41 +02:00
commit 234bbcbdd5
2 changed files with 8 additions and 5 deletions

View file

@ -184,11 +184,12 @@ class XEP_0231(object):
client.send(error_elt) client.send(error_elt)
return return
with open(metadata["path"]) as f: with open(metadata["path"], 'rb') as f:
data = f.read() data = f.read()
result_elt = xmlstream.toResponse(iq_elt, "result") 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["cid"] = cid
data_elt["type"] = metadata["mime_type"] data_elt["type"] = metadata["mime_type"]
data_elt["max-age"] = str(int(max(0, metadata["eol"] - time.time()))) 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) peer_jid = jid.JID(peer_jid_s)
assert cid assert cid
client = self.host.getClient(profile) 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): def getFile(self, client, peer_jid, cid, parent_elt=None):
"""Retrieve a file from it's content-id """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, @param parent_elt(domish.Element, None): if file is not in cache,
data will be looked after in children of this elements. data will be looked after in children of this elements.
None to ignore None to ignore
@return D(unicode): path to cached data @return D(Path): path to cached data
""" """
file_path = client.cache.getFilePath(cid) file_path = client.cache.getFilePath(cid)
if file_path is not None: if file_path is not None:

View file

@ -131,7 +131,7 @@ class XEP_0264(object):
@param size(tuple(int)): requested size of thumbnail @param size(tuple(int)): requested size of thumbnail
@return (unicode): unique id for this image/size @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): def _blockingGenThumb(self, source_path, size=None, max_age=None, image_uid=None):
"""Generate a thumbnail for image """Generate a thumbnail for image