|
From: Michael F. <fuz...@vo...> - 2009-10-17 16:49:08
|
Jeremy Gray wrote:
> Hi Michael,
>
> I think I've isolated this to whether the spec contains defaults for
> items in the section that goes missing. if there are defaults
> specified, the section gets recreated using the defaults, and
> validation succeeds (== the section is not reported as missing). its
> very cool to have the option to recreate the section from defaults,
> but it would seem nice to be warned about that situation too. is this
> expected behavior? is there a way to tell configobj what to do? sorry
> if I just missed this on the web page(s).
>
> original example that succeeds (validate reports missing section):
>
>>>> from configobj import ConfigObj, flatten_errors
>>>> from validate import Validator
>>>> a = ['baz = 3']
>>>> b = ['baz = integer', '[foo]', 'bar=integer']
>>>> c = ConfigObj(a, configspec=b)
>>>> v = Validator()
>>>> r = c.validate(v)
>>>> r
>>>>
> {'foo': False, 'baz': True}
>
> adding 'default=2' WITHIN the section in b that is missing from a
> (namely section [foo]): validate does not report the missing section:
>
>>>> a = ['baz = 3']
>>>> b = ['baz = integer', '[foo]', 'bar=integer(default=2)']
>>>> c = ConfigObj(a, configspec=b)
>>>> r = c.validate(v)
>>>> r
>>>>
> True
>
> adding 'default=2', but outside the section that is missing: validate
> does report the missing section:
>
>>>> b = ['baz = integer(default=2)', '[foo]', 'bar=integer']
>>>> c = ConfigObj(a, configspec=b)
>>>> r = c.validate(v)
>>>> r
>>>>
> {'foo': False, 'baz': True}
>
Thanks for tracking this down - however I don't think that it is a bug.
If the only values in a missing section have defaults then there are no
missing values and nothing to report. In order to fill in the default
ConfigObj *has* to create the section so it is no longer missing.
It would also make things harder for error handling code - if you have
to handle a missing section then you would no longer know if the section
is actually present in the resulting ConfigObj instance or not...
All the best,
Michael Foord
> --Jeremy
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|