From 6f8320827a50a855ee8d1f9bba5ac25f32618471 Mon Sep 17 00:00:00 2001 From: Mike McKerns Date: Sat, 27 Jan 2024 14:39:10 -0500 Subject: [PATCH] skip BufferedRandomType on pyodide (#644) --- .travis.yml | 6 +++--- dill/_dill.py | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96c61344..ca9bb44d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,15 +26,15 @@ matrix: - python: 'pypy3.8-7.3.9' # at 7.3.11 env: - - python: 'pypy3.9-7.3.9' # at 7.3.13 + - python: 'pypy3.9-7.3.9' # at 7.3.15 env: - - python: 'pypy3.10-7.3.13' + - python: 'pypy3.10-7.3.15' env: allow_failures: - python: '3.13-dev' - - python: 'pypy3.10-7.3.13' # CI missing + - python: 'pypy3.10-7.3.15' # CI missing fast_finish: true cache: diff --git a/dill/_dill.py b/dill/_dill.py index a628c85e..d42432ff 100644 --- a/dill/_dill.py +++ b/dill/_dill.py @@ -158,15 +158,17 @@ def get_file_type(*args, **kwargs): f.close() return t +IS_PYODIDE = sys.platform == 'emscripten' + FileType = get_file_type('rb', buffering=0) TextWrapperType = get_file_type('r', buffering=-1) -BufferedRandomType = get_file_type('r+b', buffering=-1) +BufferedRandomType = None if IS_PYODIDE else get_file_type('r+b', buffering=-1) BufferedReaderType = get_file_type('rb', buffering=-1) BufferedWriterType = get_file_type('wb', buffering=-1) try: from _pyio import open as _open PyTextWrapperType = get_file_type('r', buffering=-1, open=_open) - PyBufferedRandomType = get_file_type('r+b', buffering=-1, open=_open) + PyBufferedRandomType = None if IS_PYODIDE else get_file_type('r+b', buffering=-1, open=_open) PyBufferedReaderType = get_file_type('rb', buffering=-1, open=_open) PyBufferedWriterType = get_file_type('wb', buffering=-1, open=_open) except ImportError: @@ -1356,7 +1358,6 @@ def _save_file(pickler, obj, open_): @register(FileType) #XXX: in 3.x has buffer=0, needs different _create? -@register(BufferedRandomType) @register(BufferedReaderType) @register(BufferedWriterType) @register(TextWrapperType) @@ -1366,8 +1367,15 @@ def save_file(pickler, obj): logger.trace(pickler, "# Fi") return f +if BufferedRandomType: + @register(BufferedRandomType) + def save_file(pickler, obj): + logger.trace(pickler, "Fi: %s", obj) + f = _save_file(pickler, obj, open) + logger.trace(pickler, "# Fi") + return f + if PyTextWrapperType: - @register(PyBufferedRandomType) @register(PyBufferedReaderType) @register(PyBufferedWriterType) @register(PyTextWrapperType) @@ -1377,6 +1385,15 @@ def save_file(pickler, obj): logger.trace(pickler, "# Fi") return f + if PyBufferedRandomType: + @register(PyBufferedRandomType) + def save_file(pickler, obj): + logger.trace(pickler, "Fi: %s", obj) + f = _save_file(pickler, obj, _open) + logger.trace(pickler, "# Fi") + return f + + # The following two functions are based on 'saveCStringIoInput' # and 'saveCStringIoOutput' from spickle # Copyright (c) 2011 by science+computing ag