|
From: Michael F. <fuz...@vo...> - 2011-09-06 22:18:54
|
Hey Gary,
Chris is correct - those values are not "missing", they exist but are set to the empty string. Remove them and the validation defaults should be filled in. Alternatively write your own validation functions that interpret and empty value as missing and uses the default instead.
The validate module documentation shows how to write validation functions.
All the best,
Michael
On 6 Sep 2011, at 23:01, Chris Sontag wrote:
>
> Hi Gary,
>
> I'm usually just a lurker on this list, but try taking "services" and "deploy_sso" out of your config file. Right now they are set to empty strings. If they come out, they will be filled with default values (in self.config) after your validate() call.
>
> Chris
>
>
> On 9/6/11 5:36 PM, gar...@th... wrote:
>> Hello there, thanks for this library tool!
>>
>> Im trying to incorporate configobj-4.7.2 into an object to read configuration files with default values. The configobj can load the configurationfile fine, but the configspec default values are not being read in, and therefore validation fails.
>> not sure if my code is at fault.
>>
>>
>> What steps will reproduce the problem?
>> 1.
>> Im loading code like this:
>> config = ConfigObj( infile=self.config_file,
>> configspec=self.config_spec,
>> encoding='latin-1',
>> create_empty=True,
>> unrepr=True,
>> stringify=True,
>> )
>> 2.
>> my config_file looks like this:
>> [Environment]
>> name = 'qapod5'
>> services =
>> email =
>> deploy_sso =
>>
>> 3.
>> my configspec looks like this:
>> [Environment]
>> name = string()
>> services = list(default=list(''))
>> email = string(default="tes...@th...")
>> deploy_sso = boolean(default=False)
>>
>> 4. my validator code looks like this:
>> val = Validator()
>> test = self.config.validate(val, preserve_errors=True, copy=True)
>>
>>
>> with the configspec above, i would expect that the loaded configobj would have the defaults after being validated with the Validator. However, i get this error:
>>
>> ValidateError: [([u'Environment'], 'deploy_sso', VdtTypeError(u'the value "" is of the wrong type.',)), ([u'Environment'], 'services', VdtTypeError(u'the value "" is of the wrong type.',))]
>>
>>
>> Is my configspec not written properly?
>>
>> Thanks,
>>
>>
>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>> Gary Siaw
>> Application Engineer, Paisley
>>
>> Thomson Reuters
>>
>> Phone: 763-450-4776
>> Fax: 763-450-4710
>> gar...@th...
>>
>> paisley.thomsonreuters.com
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Malware Security Report: Protecting Your Business, Customers, and the
>> Bottom Line. Protect your business and customers by understanding the
>> threat from malware and how it can impact your online business.
>>
>> http://www.accelacomm.com/jaw/sfnl/114/51427462/
>>
>>
>> _______________________________________________
>> Configobj-develop mailing list
>>
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
> ------------------------------------------------------------------------------
> Malware Security Report: Protecting Your Business, Customers, and the
> Bottom Line. Protect your business and customers by understanding the
> threat from malware and how it can impact your online business.
> http://www.accelacomm.com/jaw/sfnl/114/51427462/_______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing
http://www.sqlite.org/different.html
|