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

Implement url() method and force_text paths #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions inmemorystorage/storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.conf import settings
from django.core.files.storage import Storage
from django.core.files.base import ContentFile
from django.utils.encoding import filepath_to_uri, force_text
from django.utils.six.moves.urllib.parse import urljoin

class PathDoesNotExist(Exception):
pass
Expand Down Expand Up @@ -98,16 +101,20 @@ def listdir(self, dir):
return self.filesystem.listdir(dir)

def delete(self, path):
return self.filesystem.delete(path)
return self.filesystem.delete(force_text(path))

def exists(self, name):
return self.filesystem.exists(name)
return self.filesystem.exists(force_text(name))

def size(self, name):
return self.filesystem.size(name)
return self.filesystem.size(force_text(name))

def url(self, name):
base_url = settings.MEDIA_URL
return urljoin(base_url, filepath_to_uri(name))

def _open(self, name, mode=None):
return self.filesystem.open(name)
return self.filesystem.open(force_text(name))

def _save(self, name, content):
return self.filesystem.save(name, content.read())