|
From: Fuzzyman <fuz...@vo...> - 2005-12-05 13:07:40
|
Fuzzyman wrote:
[snip..]
> This is correct - and it's a bug.
>
> Replace ``Section.update`` with :
>
> def update(self, indict):
> """A version of update that uses our ``__setitem__``."""
> for key, val in indict.items():
> if key in self and isinstance(self[key], dict):
> self[key].update(val)
> else:
> self[key] = val
>
> and it should work.
>
Hmmm.. that had probably better be :
def update(self, indict):
"""
A version of update that uses our ``__setitem__``.
>>> a = '''[section1]
... option1 = True
... [[subsection]]
... more_options = False
... # end of file'''.splitlines()
>>> b = '''# File is user.ini
... [section1]
... option1 = False
... # end of file'''.splitlines()
>>> c1 = ConfigObj(b)
>>> c2 = ConfigObj(a)
>>> c2.update(c1)
>>> c2
{'section1': {'option1': 'False', 'subsection': {'more_options':
'False'}}}
"""
for key, val in indict.items():
if key in self and isinstance(self[key], dict) and
isinstance(val, dict):
self[key].update(val)
else:
self[key] = val
Just in case you try to overwrite a sub-section with a scalar value.
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
> Update to follow. :-)
>
> Thanks
>
> Fuzzyman
> http://www.voidspace.org.uk/python/index.shtml
>
>>>*However* - validation includes a system for setting default values. You
>>>do this by including the default in the configspec.
>>>
>>>
>>
>>I think I can't use the configspec defaults, because this will mean
>>that the defaults are filled in for every file I load, so I won't be
>>able to tell in my merge whether the values came from the file, or
>>from the defaults - but very happy to be corrected if that's not the
>>case...
>>
>>Thanks again,
>>
>>Matthew
>>
>>
>>
>
|