diff --git a/storages/backends/s3boto.py b/storages/backends/s3boto.py index c475ffb91..8b7bd94d6 100644 --- a/storages/backends/s3boto.py +++ b/storages/backends/s3boto.py @@ -193,6 +193,7 @@ def close(self): self._multipart.cancel_upload() self.key.close() + @deconstructible class S3BotoStorage(Storage): """ @@ -240,6 +241,8 @@ class S3BotoStorage(Storage): host = setting('AWS_S3_HOST', S3Connection.DefaultHost) use_ssl = setting('AWS_S3_USE_SSL', True) port = setting('AWS_S3_PORT', None) + proxy = setting('AWS_S3_PROXY_HOST', None) + proxy_port = setting('AWS_S3_PROXY_PORT', None) # The max amount of memory a returned file can take up before being # rolled over into a temporary file on disk. Default is 0: Do not roll over. @@ -282,6 +285,8 @@ def connection(self): calling_format=self.calling_format, host=self.host, port=self.port, + proxy=self.proxy, + proxy_port=self.proxy_port ) return self._connection @@ -302,7 +307,7 @@ def entries(self): """ if self.preload_metadata and not self._entries: self._entries = dict((self._decode_name(entry.key), entry) - for entry in self.bucket.list(prefix=self.location)) + for entry in self.bucket.list(prefix=self.location)) return self._entries def _get_access_keys(self): @@ -325,8 +330,7 @@ def _get_or_create_bucket(self, name): Retrieves a bucket if it exists, otherwise creates it. """ try: - return self.connection.get_bucket(name, - validate=self.auto_create_bucket) + return self.connection.get_bucket(name, validate=self.auto_create_bucket) except self.connection_response_error: if self.auto_create_bucket: bucket = self.connection.create_bucket(name) @@ -395,7 +399,7 @@ def _save(self, name, content): name = self._normalize_name(cleaned_name) headers = self.headers.copy() content_type = getattr(content, 'content_type', - mimetypes.guess_type(name)[0] or self.key_class.DefaultContentType) + mimetypes.guess_type(name)[0] or self.key_class.DefaultContentType) # setting the content_type in the key object is not enough. headers.update({'Content-Type': content_type}) @@ -486,10 +490,10 @@ def url(self, name, headers=None, response_headers=None): return "%s//%s/%s" % (self.url_protocol, self.custom_domain, filepath_to_uri(name)) return self.connection.generate_url(self.querystring_expire, - method='GET', bucket=self.bucket.name, key=self._encode_name(name), - headers=headers, - query_auth=self.querystring_auth, force_http=not self.secure_urls, - response_headers=response_headers) + method='GET', bucket=self.bucket.name, key=self._encode_name(name), + headers=headers, + query_auth=self.querystring_auth, force_http=not self.secure_urls, + response_headers=response_headers) def get_available_name(self, name): """ Overwrite existing file with the same name. """