jp: jp asyncio port:

/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\

This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).

During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
This commit is contained in:
Goffi 2019-09-25 08:56:41 +02:00
commit 76aadbb3fb

View file

@ -44,7 +44,7 @@ except:
raise exceptions.MissingModule(
"Missing module pillow, please download/install it from https://python-pillow.github.io"
)
from io import StringIO
import io
try:
from twisted.words.protocols.xmlstream import XMPPHandler
@ -52,7 +52,8 @@ except ImportError:
from wokkel.subprotocols import XMPPHandler
AVATAR_PATH = "avatars"
AVATAR_DIM = (64, 64) #  FIXME: dim are not adapted to modern resolutions !
# AVATAR_DIM = (64, 64) #  FIXME: dim are not adapted to modern resolutions !
AVATAR_DIM = (128, 128)
IQ_GET = '/iq[@type="get"]'
NS_VCARD = "vcard-temp"
@ -318,7 +319,7 @@ class XEP_0054(object):
avatar_hash = yield threads.deferToThread(
self.savePhoto, client, elem, entity_jid
)
except (exceptions.DataError, exceptions.NotFound) as e:
except (exceptions.DataError, exceptions.NotFound):
avatar_hash = ""
vcard_dict["avatar"] = avatar_hash
except Exception as e:
@ -515,12 +516,13 @@ class XEP_0054(object):
left += offset
right -= offset
img = img.crop((left, upper, right, lower))
img_buf = StringIO()
img_buf = io.BytesIO()
img.save(img_buf, "PNG")
photo_elt = vcard_elt.addElement("PHOTO")
photo_elt.addElement("TYPE", content="image/png")
photo_elt.addElement("BINVAL", content=b64encode(img_buf.getvalue()))
image_b64 = b64encode(img_buf.getvalue()).decode('utf-8')
photo_elt.addElement("BINVAL", content=image_b64)
image_hash = sha1(img_buf.getvalue()).hexdigest()
with client.cache.cacheData(
PLUGIN_INFO["import_name"], image_hash, "image/png", MAX_AGE