plugin XEP-0231, XEP-0264: fixed some remaining encoding issue following Python 3 port
This commit is contained in:
parent
abbd14484b
commit
234bbcbdd5
2 changed files with 8 additions and 5 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue