From 9e6f85726db3c5d601b04f00bd0af2070771f1d6 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 13 Dec 2023 22:00:09 +0100 Subject: [PATCH 1/2] Chore: Add `.venv` to `.gitignore` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 95a4edc..a7b0385 100644 --- a/.gitignore +++ b/.gitignore @@ -82,6 +82,7 @@ celerybeat-schedule .env # virtualenv +.venv/ venv/ ENV/ From 407266127a12c65ba12ef81fc63e58b3e5a2e1da Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 13 Dec 2023 22:01:18 +0100 Subject: [PATCH 2/2] Fix reading binary files/streams by adjusting `encoding` to match `mode` When reading in binary mode, undefine `encoding`. Otherwise, `smart_open` will return a `TextIOWrapper` in `"r"` mode. However, reading binary streams needs a `BufferedReader`. --- tap_spreadsheets_anywhere/format_handler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tap_spreadsheets_anywhere/format_handler.py b/tap_spreadsheets_anywhere/format_handler.py index 3bf911f..36ab330 100644 --- a/tap_spreadsheets_anywhere/format_handler.py +++ b/tap_spreadsheets_anywhere/format_handler.py @@ -32,6 +32,11 @@ def get_streamreader(uri, universal_newlines=True, newline='', open_mode='r', en SCHEME_SEP = "://" kwargs = kwarg_dispatch.get(uri.split(SCHEME_SEP, 1)[0], lambda: {})() + # When reading in binary mode, undefine `encoding`. + # Otherwise, `smart_open` will return a `TextIOWrapper` in `"r"` mode. + # However, reading binary streams needs a `BufferedReader`. + if "b" in open_mode: + encoding = None streamreader = smart_open.open(uri, open_mode, newline=newline, errors='surrogateescape', encoding=encoding, **kwargs) if not universal_newlines and isinstance(streamreader, StreamReader):