summaryrefslogtreecommitdiff
path: root/boto/s3/connection.py
diff options
context:
space:
mode:
Diffstat (limited to 'boto/s3/connection.py')
-rw-r--r--boto/s3/connection.py57
1 files changed, 55 insertions, 2 deletions
diff --git a/boto/s3/connection.py b/boto/s3/connection.py
index fcb983b5..7808d530 100644
--- a/boto/s3/connection.py
+++ b/boto/s3/connection.py
@@ -148,17 +148,20 @@ class Location:
class S3Connection(AWSAuthConnection):
- DefaultHost = 's3.amazonaws.com'
+ DefaultHost = boto.config.get('s3', 'host', 's3.amazonaws.com')
+ DefaultCallingFormat = boto.config.get('s3', 'calling_format', 'boto.s3.connection.SubdomainCallingFormat')
QueryString = 'Signature=%s&Expires=%d&AWSAccessKeyId=%s'
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None,
host=DefaultHost, debug=0, https_connection_factory=None,
- calling_format=SubdomainCallingFormat(), path='/',
+ calling_format=DefaultCallingFormat, path='/',
provider='aws', bucket_class=Bucket, security_token=None,
suppress_consec_slashes=True, anon=False,
validate_certs=None):
+ if isinstance(calling_format, str):
+ calling_format=boto.utils.find_class(calling_format)()
self.calling_format = calling_format
self.bucket_class = bucket_class
self.anon = anon
@@ -404,12 +407,49 @@ class S3Connection(AWSAuthConnection):
return rs.owner.id
def get_bucket(self, bucket_name, validate=True, headers=None):
+ """
+ Retrieves a bucket by name.
+
+ If the bucket does not exist, an ``S3ResponseError`` will be raised. If
+ you are unsure if the bucket exists or not, you can use the
+ ``S3Connection.lookup`` method, which will either return a valid bucket
+ or ``None``.
+
+ :type bucket_name: string
+ :param bucket_name: The name of the bucket
+
+ :type headers: dict
+ :param headers: Additional headers to pass along with the request to
+ AWS.
+
+ :type validate: boolean
+ :param validate: If ``True``, it will try to fetch all keys within the
+ given bucket. (Default: ``True``)
+ """
bucket = self.bucket_class(self, bucket_name)
if validate:
bucket.get_all_keys(headers, maxkeys=0)
return bucket
def lookup(self, bucket_name, validate=True, headers=None):
+ """
+ Attempts to get a bucket from S3.
+
+ Works identically to ``S3Connection.get_bucket``, save for that it
+ will return ``None`` if the bucket does not exist instead of throwing
+ an exception.
+
+ :type bucket_name: string
+ :param bucket_name: The name of the bucket
+
+ :type headers: dict
+ :param headers: Additional headers to pass along with the request to
+ AWS.
+
+ :type validate: boolean
+ :param validate: If ``True``, it will try to fetch all keys within the
+ given bucket. (Default: ``True``)
+ """
try:
bucket = self.get_bucket(bucket_name, validate, headers=headers)
except:
@@ -463,6 +503,19 @@ class S3Connection(AWSAuthConnection):
response.status, response.reason, body)
def delete_bucket(self, bucket, headers=None):
+ """
+ Removes an S3 bucket.
+
+ In order to remove the bucket, it must first be empty. If the bucket is
+ not empty, an ``S3ResponseError`` will be raised.
+
+ :type bucket_name: string
+ :param bucket_name: The name of the bucket
+
+ :type headers: dict
+ :param headers: Additional headers to pass along with the request to
+ AWS.
+ """
response = self.make_request('DELETE', bucket, headers=headers)
body = response.read()
if response.status != 204: