|
From: Michael F. <fuz...@vo...> - 2009-12-11 14:33:07
|
On 11/12/2009 14:25, Michael Haberler wrote: > I find the ConfigObj together with validation, type conversion and > default generation extremely useful - in theory. I hope I dont > overlook something obvious, but after putting in a day to coerce > ConfigObj to do what I want I need to post this. > > Here is why: > > I have an application like many others - commandline arguments, > environment, internal variables and all. I *would* like to use > ConfigObj to handle some limited object persistence together with > validate, type conversion and to generate default .ini files. > > Some of the persistent strings will be format strings referring to > internal program variables, and I would like to get them > uninterpolated - that I do myself. > > For some reason there seems to be a built-in assumption in ConfigObj > as follows: > > - Interpolation just has to happen even during validation, > ConfigParser-style and no way to turn that off. > - and it just has to be against other variables in the DEFAULT > section, which is a fairly limiting concept of interpolation. > > Here is an example: > > The spec is: > > axis3_safe_margin = string(default= "%(ax3_letter)s safety margin > [mm]:") > > The task is: > - if the default ini file does not exist, generate it from the spec. > - when reading the default .ini back in, I want the string equivalent > as generated by: > > <foo>.axis3_safe_margin = "%(ax3_letter)s safety margin [mm]:" > ---------------------------^^^^^^^^^^^^^ note - no mutilation here > > Am I missing something here? > > The way this stands means for me: > - validation cant be used, hence no automatic type conversion and > default generation > - this means I have to use ConfigObj without validate() which means I > could pretty much stay with ConfigParser in the first place. > > > pleaaaaaaasse - provide a way to turn of this interpolation !$"!% if > one doesnt want/need it > Have you tried the interpolation attribute? Does that not work? http://www.voidspace.org.uk/python/configobj.html#interpolation Try setting it to False before validation and then back to True after. It can also be passed as a keyword argument to the ConfigObj constructor. Also you are incorrect that interpolation is only done against the DEFAULT section. Version 4.4 contained a lot of improvements to the interpolation engine and I believe this was one of the changes: http://www.voidspace.org.uk/python/configobj.html#version-4-4-0 http://www.voidspace.org.uk/python/configobj.html#string-interpolation """ Interpolation checks first the current section to see if name is the key to a value. ('name' is case sensitive). If it doesn't find it, next it checks the 'DEFAULT' sub-section of the current section. If it still doesn't find it, it moves on to check the parent section and the parent section's 'DEFAULT' subsection, and so on all the way up to the main section. """ All the best, Michael Foord > my suggestion: an interpolation=(True|False) parameter to validate() > and please leave my strings untouched... > > > thanks un advance > > Michael > > > > > > ------------------------------------------------------------------------------ > Return on Information: > Google Enterprise Search pays you back > Get the facts. > http://p.sf.net/sfu/google-dev2dev > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog |