From ae3dd7333c930c420150de1df8aa7206848c9c17 Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Wed, 1 Jul 2015 18:36:34 -0400 Subject: [PATCH] Fixes #52 - python 3 compat for apache_libcloud also some slight style changes --- storages/backends/apache_libcloud.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/storages/backends/apache_libcloud.py b/storages/backends/apache_libcloud.py index 276a7808d..1b4178a6e 100644 --- a/storages/backends/apache_libcloud.py +++ b/storages/backends/apache_libcloud.py @@ -6,6 +6,7 @@ from django.conf import settings from django.core.files.base import File from django.core.exceptions import ImproperlyConfigured +from django.utils.six import string_types from storages.compat import BytesIO, deconstructible, Storage @@ -15,6 +16,7 @@ except ImportError: raise ImproperlyConfigured("Could not load libcloud") + @deconstructible class LibCloudStorage(Storage): """Django storage derived class using apache libcloud to operate @@ -32,7 +34,7 @@ def __init__(self, provider_name=None, option=None): extra_kwargs['region'] = self.provider['region'] try: provider_type = self.provider['type'] - if isinstance(provider_type, basestring): + if isinstance(provider_type, string_types): module_path, tag = provider_type.rsplit('.', 1) if module_path != 'libcloud.storage.types.Provider': raise ValueError("Invalid module path") @@ -46,7 +48,7 @@ def __init__(self, provider_name=None, option=None): ) except Exception as e: raise ImproperlyConfigured( - "Unable to create libcloud driver type %s: %s" % \ + "Unable to create libcloud driver type %s: %s" % (self.provider.get('type'), e)) self.bucket = self.provider['bucket'] # Limit to one container @@ -76,7 +78,7 @@ def delete(self, name): def exists(self, name): obj = self._get_object(name) - return True if obj else False + return bool(obj) def listdir(self, path='/'): """Lists the contents of the specified path, @@ -98,7 +100,7 @@ def listdir(self, path='/'): files.append(o.name) elif o.name.count('/') == 1: dir_name = o.name[:o.name.index('/')] - if not dir_name in dirs: + if dir_name not in dirs: dirs.append(dir_name) elif o.name.startswith(path): if o.name.count('/') <= path.count('/'): @@ -114,10 +116,7 @@ def listdir(self, path='/'): def size(self, name): obj = self._get_object(name) - if obj: - return obj.size - else: - return -1 + return obj.size if obj else -1 def url(self, name): obj = self._get_object(name)