branch: externals/comint-mime commit 21ba536c2707b3e4f960770d1b5f98805a91545a Author: Augusto Stoffel <arstof...@gmail.com> Commit: Augusto Stoffel <arstof...@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")