diff --git a/swift3/cfg.py b/swift3/cfg.py index 797f4af6..09fa8a95 100644 --- a/swift3/cfg.py +++ b/swift3/cfg.py @@ -21,6 +21,18 @@ class Config(dict): if base is not None: self.update(base) + def __getattr__(self, name): + if name not in self: + raise AttributeError("No attribute '%s'" % name) + + return self[name] + + def __setattr__(self, name, value): + self[name] = value + + def __delattr__(self, name): + del self[name] + def update(self, other): if hasattr(other, 'keys'): for key in other.keys(): diff --git a/swift3/controllers/bucket.py b/swift3/controllers/bucket.py index 319ff84a..53e736d7 100644 --- a/swift3/controllers/bucket.py +++ b/swift3/controllers/bucket.py @@ -50,8 +50,8 @@ class BucketController(Controller): if req.params.get('max-keys').isdigit() is False: raise InvalidArgument('max-keys', req.params['max-keys']) - max_keys = int(req.params.get('max-keys', CONF['max_bucket_listing'])) - max_keys = min(max_keys, CONF['max_bucket_listing']) + max_keys = int(req.params.get('max-keys', CONF.max_bucket_listing)) + max_keys = min(max_keys, CONF.max_bucket_listing) query = { 'format': 'json', @@ -132,7 +132,7 @@ class BucketController(Controller): LOGGER.debug(e) raise MalformedXML() - if location != CONF.get('location'): + if location != CONF.location: # Swift3 cannot support multiple reagions now. raise InvalidLocationConstraint() diff --git a/swift3/controllers/location.py b/swift3/controllers/location.py index eb7b21af..6c26c5d3 100644 --- a/swift3/controllers/location.py +++ b/swift3/controllers/location.py @@ -32,8 +32,8 @@ class LocationController(Controller): req.get_response(self.app, method='HEAD') elem = Element('LocationConstraint') - if CONF['location'] != 'US': - elem.text = CONF['location'] + if CONF.location != 'US': + elem.text = CONF.location body = tostring(elem) return HTTPOk(body=body, content_type='application/xml') diff --git a/swift3/request.py b/swift3/request.py index 927282e0..6135f9c3 100644 --- a/swift3/request.py +++ b/swift3/request.py @@ -75,7 +75,7 @@ class Request(swob.Request): self.environ['swift.leave_relative_location'] = True def _parse_host(self): - storage_domain = CONF['storage_domain'] + storage_domain = CONF.storage_domain if not storage_domain: return None