emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/comint-mime 21ba536c27 1/2: comint-mime.py: Add a size


From: ELPA Syncer
Subject: [elpa] externals/comint-mime 21ba536c27 1/2: comint-mime.py: Add a size limit for the payload
Date: Sat, 26 Feb 2022 06:57:21 -0500 (EST)

branch: externals/comint-mime
commit 21ba536c2707b3e4f960770d1b5f98805a91545a
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>

    comint-mime.py: Add a size limit for the payload
---
 comint-mime.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/comint-mime.py b/comint-mime.py
index 2033a55bb6..c70593f919 100644
--- a/comint-mime.py
+++ b/comint-mime.py
@@ -18,6 +18,8 @@ def __COMINT_MIME_setup(types):
             return decodebytes(data.encode())
         return data
 
+    SIZE_LIMIT = 4000
+
     MIME_TYPES = {
         "image/png": encoding_workaround,
         "image/jpeg": encoding_workaround,
@@ -36,7 +38,13 @@ def __COMINT_MIME_setup(types):
         if encoder:
             data = encoder(data)
         header = to_json({**meta, "type": type})
-        payload = encodebytes(data).decode()
+        if len(data) > SIZE_LIMIT:
+            from tempfile import mkstemp
+            fdesc, fname = mkstemp()
+            with open(fdesc, "wb") as f: f.write(data)
+            payload = "tmpfile://" + fname
+        else:
+            payload = encodebytes(data).decode()
         print(f"\033]5151;{header}\n{payload}\033\\")
 
     ipython.enable_matplotlib("inline")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]