From 45315136021b9cdfdfa77eb85bfaaf9677e9f256 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 1 Jul 2018 14:25:22 -0700 Subject: [PATCH] cmd_send/receive: work around python3.7.0 bug See https://bugs.python.org/issue26175 . tempfile.SpooledTemporaryFile doesn't fully implement the IOBase abstract class, which breaks because py3.7.0's new zipfile module tries to delegate .seekable down to the wrapped file and causes an AttributeError. refs #306 --- src/wormhole/cli/cmd_receive.py | 9 ++++++++- src/wormhole/cli/cmd_send.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index 4b18822..3e4668d 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -331,7 +331,14 @@ class Receiver: self._msg(u"%d files, %s (uncompressed)" % (file_data["numfiles"], naturalsize(file_data["numbytes"]))) self._ask_permission() - return tempfile.SpooledTemporaryFile() + f = tempfile.SpooledTemporaryFile() + # workaround for https://bugs.python.org/issue26175 (STF doesn't + # fully implement IOBase abstract class), which breaks the new + # zipfile in py3.7.0 that expects .seekable + if not hasattr(f, "seekable"): + # AFAICT all the filetypes that STF wraps can seek + f.seekable = lambda: True + return f def _decide_destname(self, mode, destname): # the basename() is intended to protect us against diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index ea5d69e..e97fc8b 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -314,6 +314,12 @@ class Sender: # We're sending a directory. Create a zipfile in a tempdir and # send that. fd_to_send = tempfile.SpooledTemporaryFile() + # workaround for https://bugs.python.org/issue26175 (STF doesn't + # fully implement IOBase abstract class), which breaks the new + # zipfile in py3.7.0 that expects .seekable + if not hasattr(fd_to_send, "seekable"): + # AFAICT all the filetypes that STF wraps can seek + fd_to_send.seekable = lambda: True num_files = 0 num_bytes = 0 tostrip = len(what.split(os.sep))