From f30f9d0acac54022da59fdaaf8edb86a71b052d8 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Tue, 26 Jul 2011 13:37:17 -0700 Subject: [PATCH] Refactor S3 connection opening. --- s3tests/common/__init__.py | 42 ++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/s3tests/common/__init__.py b/s3tests/common/__init__.py index 38189ee..ba60658 100644 --- a/s3tests/common/__init__.py +++ b/s3tests/common/__init__.py @@ -91,6 +91,22 @@ def read_config(fp): config.update(bunch.bunchify(new)) return config +def connect(conf): + mapping = dict( + port='port', + host='host', + is_secure='is_secure', + access_key='aws_access_key_id', + secret_key='aws_secret_access_key', + ) + kwargs = dict((mapping[k],v) for (k,v) in conf.iteritems() if k in mapping) + conn = boto.s3.connection.S3Connection( + # TODO support & test all variations + calling_format=boto.s3.connection.OrdinaryCallingFormat(), + **kwargs + ) + return conn + def setup(): global s3, config, prefix s3.clear() @@ -123,29 +139,11 @@ def setup(): for section in config.s3.keys(): if section == 'defaults': continue - section_config = config.s3[section] - kwargs = bunch.Bunch() - conn_args = bunch.Bunch( - port='port', - host='host', - is_secure='is_secure', - access_key='aws_access_key_id', - secret_key='aws_secret_access_key', - ) - for cfg_key in conn_args.keys(): - conn_key = conn_args[cfg_key] - - if section_config.has_key(cfg_key): - kwargs[conn_key] = section_config[cfg_key] - elif defaults.has_key(cfg_key): - kwargs[conn_key] = defaults[cfg_key] - - conn = boto.s3.connection.S3Connection( - # TODO support & test all variations - calling_format=boto.s3.connection.OrdinaryCallingFormat(), - **kwargs - ) + conf = {} + conf.update(defaults) + conf.update(config.s3[section]) + conn = connect(conf) s3[section] = conn # WARNING! we actively delete all buckets we see with the prefix