Skip to content

Commit

Permalink
skip BufferedRandomType on pyodide (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckerns authored Jan 27, 2024
1 parent 72f6523 commit 6f83208
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 21 additions & 4 deletions dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 6f83208

Please sign in to comment.