Skip to content

Commit

Permalink
Fixes #52 - python 3 compat for apache_libcloud
Browse files Browse the repository at this point in the history
also some slight style changes
  • Loading branch information
jschneier committed Jul 1, 2015
1 parent bc480c7 commit ae3dd73
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions storages/backends/apache_libcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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('/'):
Expand All @@ -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)
Expand Down

0 comments on commit ae3dd73

Please sign in to comment.