diff sat/plugins/plugin_xep_0054.py @ 3040:fee60f17ebac

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.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents ab2696e34d29
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0054.py	Wed Sep 25 08:53:38 2019 +0200
+++ b/sat/plugins/plugin_xep_0054.py	Wed Sep 25 08:56:41 2019 +0200
@@ -44,7 +44,7 @@
     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 @@
     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 @@
                     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 @@
                     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