in src/ab/config/config.py [0:0]
def from_mapping(self, *mapping, **kwargs):
"""Updates the config like :meth:`update` ignoring items with non-upper
keys.
.. versionadded:: 0.11
"""
def is_int(s):
try:
int(s)
return True
except:
pass
return False
mappings = []
if len(mapping) == 1:
if hasattr(mapping[0], 'items'):
mappings.append(mapping[0].items())
else:
mappings.append(mapping[0])
elif len(mapping) > 1:
raise TypeError(
'expected at most 1 positional argument, got %d' % len(mapping)
)
mappings.append(kwargs.items())
for mapping in mappings:
for (key, value) in mapping:
if is_int(value):
self[key] = int(value)
else:
self[key] = value
if str(value).lower() == "true":
self[key] = True
if str(value).lower() == "false":
self[key] = False
return True