From 6f83b85cfdfddb4b99b4652250680d686b6c5012 Mon Sep 17 00:00:00 2001 From: Menshikh Ivan Date: Thu, 30 Nov 2017 15:32:47 +0500 Subject: [PATCH] Fix mode for case with updating file (#150) --- smart_open/smart_open_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smart_open/smart_open_lib.py b/smart_open/smart_open_lib.py index ec71f87d..fa631471 100644 --- a/smart_open/smart_open_lib.py +++ b/smart_open/smart_open_lib.py @@ -617,7 +617,7 @@ def encoding_wrapper(fileobj, mode, encoding=None): # smart_open(filename, encoding='utf-8') would return a byte stream # without our assumption, because the default mode is rb. # - if mode in ('rb', 'wb', 'ab') and encoding is None: + if 'b' in mode and encoding is None: return fileobj if encoding is None: @@ -651,7 +651,7 @@ def file_smart_open(fname, mode='rb', encoding=None): # filename ---------------> bytes -------------> bytes ---------> text # raw_fobj decompressed_fobj decoded_fobj # - try: + try: # TODO need to fix this place (for cases with r+ and so on) raw_mode = {'r': 'rb', 'w': 'wb', 'a': 'ab'}[mode] except KeyError: raw_mode = mode