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

GoogleCloudFile text mode read fix #865

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion storages/__init__.py
@@ -1 +1 @@
__version__ = '1.9.1'
__version__ = '1.9.2'
jschneier marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 8 additions & 6 deletions storages/backends/gcloud.py
Expand Up @@ -7,7 +7,7 @@
from django.core.files.base import File
from django.utils import timezone
from django.utils.deconstruct import deconstructible
from django.utils.encoding import force_bytes, smart_str
from django.utils.encoding import force_bytes, smart_str, force_str

from storages.base import BaseStorage
from storages.utils import (
Expand All @@ -29,6 +29,7 @@ def __init__(self, name, mode, storage):
self.name = name
self.mime_type = mimetypes.guess_type(name)[0]
self._mode = mode
self._force_mode = (lambda b: b) if 'b' in mode else force_str
self._storage = storage
self.blob = storage.bucket.get_blob(name)
if not self.blob and 'w' in mode:
Expand Down Expand Up @@ -60,14 +61,15 @@ def _set_file(self, value):

file = property(_get_file, _set_file)

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

if num_bytes is None:
num_bytes = -1

return super(GoogleCloudFile, self).read(num_bytes)
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(GoogleCloudFile, self).readline(*args, **kwargs))

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