forked from meizon/django-storages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dramatically improved the S3BotoStorage and GSBotoStorage.
- Fixed subclassing and setting handling. - Use correct Key class for GSBotoStorage and use all settings correctly. - Fixed tests. - Initialize connection only when needed.
- Loading branch information
Showing
3 changed files
with
254 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,47 @@ | ||
from django.conf import settings | ||
from storages.backends.s3boto import S3BotoStorage | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from boto.gs.connection import GSConnection, SubdomainCallingFormat | ||
from boto.exception import GSResponseError | ||
from storages.backends.s3boto import S3BotoStorage, S3BotoStorageFile, setting | ||
|
||
ACCESS_KEY_NAME = getattr(settings, 'GS_ACCESS_KEY_ID', None) | ||
SECRET_KEY_NAME = getattr(settings, 'GS_SECRET_ACCESS_KEY', None) | ||
HEADERS = getattr(settings, 'GS_HEADERS', {}) | ||
STORAGE_BUCKET_NAME = getattr(settings, 'GS_BUCKET_NAME', None) | ||
AUTO_CREATE_BUCKET = getattr(settings, 'GS_AUTO_CREATE_BUCKET', False) | ||
DEFAULT_ACL = getattr(settings, 'GS_DEFAULT_ACL', 'public-read') | ||
BUCKET_ACL = getattr(settings, 'GS_BUCKET_ACL', DEFAULT_ACL) | ||
QUERYSTRING_AUTH = getattr(settings, 'GS_QUERYSTRING_AUTH', True) | ||
QUERYSTRING_EXPIRE = getattr(settings, 'GS_QUERYSTRING_EXPIRE', 3600) | ||
REDUCED_REDUNDANCY = getattr(settings, 'GS_REDUCED_REDUNDANCY', False) | ||
LOCATION = getattr(settings, 'GS_LOCATION', '') | ||
CUSTOM_DOMAIN = getattr(settings, 'GS_CUSTOM_DOMAIN', None) | ||
CALLING_FORMAT = getattr(settings, 'GS_CALLING_FORMAT', SubdomainCallingFormat()) | ||
SECURE_URLS = getattr(settings, 'GS_SECURE_URLS', True) | ||
FILE_NAME_CHARSET = getattr(settings, 'GS_FILE_NAME_CHARSET', 'utf-8') | ||
FILE_OVERWRITE = getattr(settings, 'GS_FILE_OVERWRITE', True) | ||
FILE_BUFFER_SIZE = getattr(settings, 'GS_FILE_BUFFER_SIZE', 5242880) | ||
IS_GZIPPED = getattr(settings, 'GS_IS_GZIPPED', False) | ||
PRELOAD_METADATA = getattr(settings, 'GS_PRELOAD_METADATA', False) | ||
GZIP_CONTENT_TYPES = getattr(settings, 'GS_GZIP_CONTENT_TYPES', ( | ||
'text/css', | ||
'application/javascript', | ||
'application/x-javascript', | ||
)) | ||
try: | ||
from boto.gs.connection import GSConnection, SubdomainCallingFormat | ||
from boto.exception import GSResponseError | ||
from boto.gs.key import Key as GSKey | ||
except ImportError: | ||
raise ImproperlyConfigured("Could not load Boto's Google Storage bindings.\n" | ||
"See https://github.com/boto/boto") | ||
|
||
|
||
class GSBotoStorageFile(S3BotoStorageFile): | ||
buffer_size = setting('GS_FILE_BUFFER_SIZE', 5242880) | ||
|
||
|
||
class GSBotoStorage(S3BotoStorage): | ||
connection_class = GSConnection | ||
connection_response_error = GSResponseError | ||
file_class = GSBotoStorageFile | ||
key_class = GSKey | ||
|
||
def __init__(self, bucket=STORAGE_BUCKET_NAME, access_key=None, | ||
secret_key=None, bucket_acl=BUCKET_ACL, acl=DEFAULT_ACL, | ||
headers=HEADERS, gzip=IS_GZIPPED, | ||
gzip_content_types=GZIP_CONTENT_TYPES, | ||
querystring_auth=QUERYSTRING_AUTH, | ||
querystring_expire=QUERYSTRING_EXPIRE, | ||
reduced_redundancy=REDUCED_REDUNDANCY, | ||
custom_domain=CUSTOM_DOMAIN, secure_urls=SECURE_URLS, | ||
location=LOCATION, file_name_charset=FILE_NAME_CHARSET, | ||
preload_metadata=PRELOAD_METADATA, | ||
calling_format=CALLING_FORMAT): | ||
super(GSBotoStorage, self).__init__(bucket=bucket, | ||
access_key=access_key, secret_key=secret_key, | ||
bucket_acl=bucket_acl, acl=acl, headers=headers, gzip=gzip, | ||
gzip_content_types=gzip_content_types, | ||
querystring_auth=querystring_auth, | ||
querystring_expire=querystring_expire, | ||
reduced_redundancy=reduced_redundancy, | ||
custom_domain=custom_domain, secure_urls=secure_urls, | ||
location=location, file_name_charset=file_name_charset, | ||
preload_metadata=preload_metadata, calling_format=calling_format) | ||
access_key = setting('GS_ACCESS_KEY_ID') | ||
secret_key = setting('GS_SECRET_ACCESS_KEY') | ||
file_overwrite = setting('GS_FILE_OVERWRITE', True) | ||
headers = setting('GS_HEADERS', {}) | ||
storage_bucket_name = setting('GS_BUCKET_NAME', None) | ||
auto_create_bucket = setting('GS_AUTO_CREATE_BUCKET', False) | ||
default_acl = setting('GS_DEFAULT_ACL', 'public-read') | ||
bucket_acl = setting('GS_BUCKET_ACL', default_acl) | ||
querystring_auth = setting('GS_QUERYSTRING_AUTH', True) | ||
querystring_expire = setting('GS_QUERYSTRING_EXPIRE', 3600) | ||
reduced_redundancy = setting('GS_REDUCED_REDUNDANCY', False) | ||
location = setting('GS_LOCATION', '') | ||
custom_domain = setting('GS_CUSTOM_DOMAIN') | ||
calling_format = setting('GS_CALLING_FORMAT', SubdomainCallingFormat()) | ||
secure_urls = setting('GS_SECURE_URLS', True) | ||
file_name_charset = setting('GS_FILE_NAME_CHARSET', 'utf-8') | ||
is_gzipped = setting('GS_IS_GZIPPED', False) | ||
preload_metadata = setting('GS_PRELOAD_METADATA', False) | ||
gzip_content_types = setting('GS_GZIP_CONTENT_TYPES', ( | ||
'text/css', | ||
'application/javascript', | ||
'application/x-javascript', | ||
)) | ||
url_protocol = setting('GS_URL_PROTOCOL', 'http:') |
Oops, something went wrong.