import unittest
from .compat.odict import odict as OrderedDict
+from .util.convert import to_string, from_string
DEFAULT_PATHS = [
in turn overrides the developer defaults.
"""
-CONVERT_FROM_STRING = {
- 'string': lambda x: x,
- 'bool': lambda x: x == 'True',
- 'int': lambda x: int(x),
- 'float': lambda x: float(x),
- }
-"""Functions converting strings to values, keyed by type.
-"""
-
-CONVERT_TO_STRING = {
- 'string': lambda x: x,
- 'bool': lambda x: str(x),
- 'int': lambda x: str(x),
- 'float': lambda x: str(x),
- }
-"""Functions converting values to strings, keyed by type.
-"""
-
class Setting (object):
"""An entry (section or option) in HookeConfigParser.
"""
help=None, wrap=True):
self.section = section
self.option = option
- self.value = CONVERT_TO_STRING[type](value)
+ self.value = to_string(value=value, type=type)
self.type = type
self.help = help
self.wrap = wrap
for i,kv in enumerate(items):
key,value = kv
setting = self._default_settings_dict[(section, key)]
- items[i] = (key, CONVERT_FROM_STRING[setting.type](value))
+ items[i] = (key, from_string(value=value, type=setting.type))
return items
def set(self, section, option, value):
"""Set an option."""
setting = self._default_settings_dict[(section, option)]
- value = CONVERT_TO_STRING[setting.type](value)
+ value = to_string(value=value, type=setting.type)
# Can't use super() because RawConfigParser is a classic class
#return super(HookeConfigParser, self).set(section, option, value)
configparser.RawConfigParser.set(self, section, option, value)