Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[s3] Fixed file text mode while reading #827

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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