Skip to content

Commit

Permalink
Fixed file text mode while reading for s3boto3 (#827)
Browse files Browse the repository at this point in the history
Co-authored-by: Vsevolod Novikov <nnseva@mail.ru>
  • Loading branch information
jschneier and nnseva authored Feb 3, 2020
1 parent dfd3cac commit b6255ed
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, name, mode, storage, buffer_size=None):
self._storage = storage
self.name = name[len(self._storage.location):].lstrip('/')
self._mode = mode
self._force_mode = (lambda b: b) if 'b' in mode else force_text
self.obj = storage.bucket.Object(storage._encode_name(name))
if 'w' not in mode:
# Force early RAII-style exception if object does not exist
Expand Down Expand Up @@ -110,7 +111,12 @@ def _set_file(self, value):
def read(self, *args, **kwargs):
if 'r' not in self._mode:
raise AttributeError("File was not opened in read mode.")
return super(S3Boto3StorageFile, self).read(*args, **kwargs)
return self._force_mode(super(S3Boto3StorageFile, self).read(*args, **kwargs))

def readline(self, *args, **kwargs):
if 'r' not in self._mode:
raise AttributeError("File was not opened in read mode.")
return self._force_mode(super(S3Boto3StorageFile, self).readline(*args, **kwargs))

def write(self, content):
if 'w' not in self._mode:
Expand Down

0 comments on commit b6255ed

Please sign in to comment.