|
From: F. <bou...@gm...> - 2010-08-13 19:00:23
|
Le 13/08/2010 20:52, Michael Foord a écrit : > On 13/08/2010 15:40, François wrote: >> Le 13/08/2010 14:34, Michael Foord a écrit : >> >>> On 13/08/2010 13:29, François wrote: >>> >>>> Hi, >>>> >>>> I don't know if it is a bug or if I'm using the library in a wrong way >>>> but I can pass successfully a configfile which is obviously wrong. >>>> >>>> >>>> >>> I think you are using validation incorrectly. Try printing the result of >>> config.validate(Validator()) and I think you will see your mistake. >>> >>> Michael >>> >>> >> You mean I have to make a for loop on the hash elements to be sure they >> are all correct? >> >> >> > >From the docs on the validate method: > > By default, the validate method either returns True (everything > passed) or a dictionary of True / False representing pass/fail. The > dictionary follows the structure of the ConfigObj. > > http://www.voidspace.org.uk/python/configobj.html#return-value > > So in the event of a validation fail you will get a dictionary of > values telling you which one(s) failed. This is going to evaluate as > True if you check it in an if statement. Instead you should do > (something like): > > result = configobj.validate(Validator()) > > if result == True > # validation succeeded Ok! I feel stupid since I read many times the doc and missed the mention of the dictionary. I thought the two steps were to explicit as much as possible, so I tried to compress the code. Many thanks for your answer (and your job). Regards, Francois. |