|
From: Michael F. <fuz...@vo...> - 2009-07-04 19:36:54
|
Robert Šmol wrote:
> Hi,
> response is unbelievable quick enough if compared to our R&D ;)
>
>
Hmmm... I think interpolation should be switched off by default in
configspec reading - but that would be a backwards incompatible change.
Here is a workaround:
>>> config = ConfigObj(configFile, configspec=ConfigObj(_configspec,
interpolation=False, _inspec=True, list_values=False))
>>> results = config.validate(validator)
All the best,
Michael Foord
> Here is the code to reproduce the problem:
>
>
> from configobj import ConfigObj, flatten_errors
> from validate import Validator
>
> #some defaults
> _pidFile = '/var/run/xdr.pid'
> _defaultLogFormat = '%(asctime)s - %(levelname)s - %(message)s'
>
> #configspec is used to validate configuration file
> _configspec = ('''
> [general]
> pid_file = string(min=1, max=100, default=%s)
>
> [logging]
> level= option('INFO','DEBUG','CRITICAL','ERROR', default='INFO')
> log_format = string(min=1, max=100, default=%s)
> ''' % (_pidFile, _defaultLogFormat)).split('\n')
>
> #dummy config file
> configFile = ''
>
>
> #main loop, if called as a program start main
> if __name__ == '__main__':
> validator = Validator()
> config = ConfigObj(configFile,configspec=_configspec)
> results = config.validate(validator)
> <<<<<<<<<<<<<<<<
>
> The problem is, config['log_format'] should be '%(asctime)s -
> %(levelname)s - %(message)s'
> and the values 'asctime' are interpolated when using logging facility,
> but they are evaluated during validation. Perhaps I just need to
> somehow properly escape?
>
> Thanks,
>
> Robert
>
>
> On Thu, Jul 2, 2009 at 4:51 PM, Michael Foord<fuz...@vo...> wrote:
>
>> Robert Šmol wrote:
>>
>>> Hi,
>>> I have following for my config spec:
>>>
>>> _defaultLogFormat = '%(asctime)s - %(levelname)s - %(message)s'
>>> _configspec = ('''
>>> [general]
>>> log_format = string(min=1, max=100, default=%s)
>>> ''' % (_defaultLogFormat)).split('\n')
>>>
>>> When I execute I get the MissingInterpolationError
>>> ...
>>> ..
>>> File "/var/lib/python-support/python2.5/configobj.py", line 368, in
>>> recursive_interpolate
>>> k, v, s = self._parse_match(match)
>>> File "/var/lib/python-support/python2.5/configobj.py", line 454, in
>>> _parse_match
>>> value, section = self._fetch(key)
>>> File "/var/lib/python-support/python2.5/configobj.py", line 424, in _fetch
>>> raise MissingInterpolationOption(key)
>>> configobj.MissingInterpolationOption: missing option "asctime" in interpolation.
>>>
>>> How do I get round this?
>>>
>>>
>> Sorry for the slow response I'm currently at EuroPython. Can you send me
>> a config file and *full* code to reproduce this.
>>
>> Thanks
>>
>> Michael
>>
>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Configobj-develop mailing list
>>> Con...@li...
>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>>
>>>
>> --
>> http://www.ironpythoninaction.com/
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Configobj-develop mailing list
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>
>>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|