|
From: Michael F. <fuz...@vo...> - 2008-06-22 20:59:29
|
Jesse Noller wrote:
> He Michael - I hope you don't mind me dropping you a line about this -
>
> Using the latest configObj and validator code - I am trying to build
> up a config file and spec and then do the validation/type coercion on
> it offered by configObj - and I am running into a mystifying issue -
> for example, here is the config file:
>
> ["network_options"]
> portal_port =
>
> And here is the spec:
> ["network_options"]
> portal_port = integer(min=0, default=8082)
>
> When I try this:
>
> vdt = Validator()
> configspec = ConfigObj('config.spec')
> config = ConfigObj(configFile, configspec=configspec)
> config.validate(vdt)
>
>
I'm really sorry - I should have looked at this more closely when you
sent it.
The answer is really quite simple. In order for a ConfigObj instance to
be used as a configspec it must be created with 'list_values=False' (or
the commas in the configspec will cause the right hand side to be parsed
as a list.
configspec = ConfigObj('config.spec', list_values=False)
Should work. Sorry that took so long.
Michael Foord
> It explodes with:
>
> Traceback (most recent call last):
> File "ctransfer.py", line 92, in <module>
> sys.exit(main(sys.argv[1]))
> File "ctransfer.py", line 85, in main
> config = load_config(configFile)
> File "ctransfer.py", line 49, in load_config
> config.validate(vdt)
> File "/Library/Python/2.5/site-packages/configobj.py", line 2301, in validate
> copy=copy, section=section[entry])
> File "/Library/Python/2.5/site-packages/configobj.py", line 2245, in validate
> missing=missing
> File "/Library/Python/2.5/site-packages/validate.py", line 595, in check
> fun_name, fun_args, fun_kwargs, default = self._parse_with_caching(check)
> File "/Library/Python/2.5/site-packages/validate.py", line 620, in
> _parse_with_caching
> if check in self._cache:
> TypeError: list objects are unhashable
>
> I added some debugging (print statements for the win) to the code and
> found that check looks like this:
>
> ['integer(min=0', 'default=8082)']
>
> So on line 619 - check is actually being passed in as a list so the if
> check in self._cache check fails. Did I do something horribly wrong
> here?
>
> -jesse
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/
|