summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-08-13 11:35:25 +0100
committerMark McLoughlin <markmc@redhat.com>2012-08-13 11:35:25 +0100
commit4dc2043df6e64adb902081d2ff7cb72ef4d20de5 (patch)
tree4e6edff580146e4e1b6ca8a3396017dcd00f0a2c /openstack
parent513bd3a917207099125cc044705aee438fee7143 (diff)
downloadoslo-4dc2043df6e64adb902081d2ff7cb72ef4d20de5.tar.gz
oslo-4dc2043df6e64adb902081d2ff7cb72ef4d20de5.tar.xz
oslo-4dc2043df6e64adb902081d2ff7cb72ef4d20de5.zip
cfg: clean up None value handling
Remove the need for an internal NoneValue class by making the existence of the 'default' or 'override' keys signify whether a default or override is set. Change-Id: Iacf49553df5ba8414307904a3ee334c7b8c55758
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/cfg.py36
1 files changed, 13 insertions, 23 deletions
diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py
index a56f957..37c65b1 100644
--- a/openstack/common/cfg.py
+++ b/openstack/common/cfg.py
@@ -809,7 +809,7 @@ class OptGroup(object):
if _is_opt_registered(self._opts, opt):
return False
- self._opts[opt.dest] = {'opt': opt, 'override': None, 'default': None}
+ self._opts[opt.dest] = {'opt': opt}
return True
@@ -1087,7 +1087,7 @@ class ConfigOpts(collections.Mapping):
if _is_opt_registered(self._opts, opt):
return False
- self._opts[opt.dest] = {'opt': opt, 'override': None, 'default': None}
+ self._opts[opt.dest] = {'opt': opt}
return True
@@ -1175,9 +1175,6 @@ class ConfigOpts(collections.Mapping):
__import__(module_str)
self._get_opt_info(name, group)
- class _NoneValue(object):
- pass
-
@__clear_cache
def set_override(self, name, override, group=None):
"""Override an opt value.
@@ -1190,8 +1187,6 @@ class ConfigOpts(collections.Mapping):
:param group: an option OptGroup object or group name
:raises: NoSuchOptError, NoSuchGroupError
"""
- if override is None:
- override = self._NoneValue()
opt_info = self._get_opt_info(name, group)
opt_info['override'] = override
@@ -1207,8 +1202,6 @@ class ConfigOpts(collections.Mapping):
:param group: an option OptGroup object or group name
:raises: NoSuchOptError, NoSuchGroupError
"""
- if default is None:
- default = self._NoneValue()
opt_info = self._get_opt_info(name, group)
opt_info['default'] = default
@@ -1224,7 +1217,7 @@ class ConfigOpts(collections.Mapping):
:raises: NoSuchOptError, NoSuchGroupError
"""
opt_info = self._get_opt_info(name, group)
- opt_info['override'] = None
+ opt_info.pop('override', None)
@__clear_cache
def clear_default(self, name, group=None):
@@ -1237,7 +1230,7 @@ class ConfigOpts(collections.Mapping):
:raises: NoSuchOptError, NoSuchGroupError
"""
opt_info = self._get_opt_info(name, group)
- opt_info['default'] = None
+ opt_info.pop('default', None)
def _all_opt_infos(self):
"""A generator function for iteration opt infos."""
@@ -1255,8 +1248,8 @@ class ConfigOpts(collections.Mapping):
def _unset_defaults_and_overrides(self):
"""Unset any default or override on all options."""
for info, group in self._all_opt_infos():
- info['default'] = None
- info['override'] = None
+ info.pop('default', None)
+ info.pop('override', None)
def disable_interspersed_args(self):
"""Set parsing to stop on the first non-option.
@@ -1379,13 +1372,10 @@ class ConfigOpts(collections.Mapping):
return self.GroupAttr(self, self._get_group(name))
info = self._get_opt_info(name, group)
- default, opt, override = [info[k] for k in sorted(info.keys())]
-
- def _convert_none(value):
- return None if isinstance(value, self._NoneValue) else value
+ opt = info['opt']
- if override is not None:
- return _convert_none(override)
+ if 'override' in info:
+ return info['override']
values = []
if self._cparser is not None:
@@ -1413,8 +1403,8 @@ class ConfigOpts(collections.Mapping):
if values:
return values
- if default is not None:
- return _convert_none(default)
+ if 'default' in info:
+ return info['default']
return opt.default
@@ -1506,10 +1496,10 @@ class ConfigOpts(collections.Mapping):
:raises: RequiredOptError
"""
for info, group in self._all_opt_infos():
- default, opt, override = [info[k] for k in sorted(info.keys())]
+ opt = info['opt']
if opt.required:
- if (default is not None or override is not None):
+ if ('default' in info or 'override' in info):
continue
if self._get(opt.name, group) is None: