[stdlib-sig] ConfigParser - parsing options with no value

Mats Kindahl mats at sun.com
Thu Sep 17 22:28:50 CEST 2009



Brett Cannon wrote:
> On Thu, Sep 17, 2009 at 09:53, Mats Kindahl <mats at sun.com> wrote:
>> Hi all,
>>
>> I am currently using the ConfigParser module to parse MySQL configuration files.
>>  Just plain config files, nothing fancy except... options without values.
>>
>> There is a number of options here that does not require a value, they are
>> basically just turning on a feature. They are also common in the standard
>> template files for the server. Options that are for mysqld can have a value even
>> though it is not required and the option file parser will not complain, but for
>> some of the client tools, values may not be given or there will be a error.
>>
>> Looking at the tests of ConfigParser, I see that it is a deliberate design
>> decision to not allow options without values (or I am misunderstanding
>> something). Why?
>>
> 
> Who knows. =) Module is old enough it's quite possible no one
> remembers why. Maybe the original creator thought it would help catch
> errors when people accidentally left off a value.

Hmmm....

If one should allow value-less options, I see two ways to handle that:

- For options lacking values, set the value to the empty string, or

- For options lacking values, set the value to None.

I have a patch for the first case, but I really think that the second approach
is better. That would make it possible to distinguish between options that were
given the empty string value and that were not given a value at all.

Where should I post such patches and what is people opinion of these to
alternatives?

Another consideration is how to allow this extension. It would be possible to
add flags to allow new and old behaviour, but I don't know how much value people
attribute to be able to get an exception if there is no value for the option.

I am also thinking that some option files have extensions to be able to include
files (MySQL option parsing package has), so it might be a good idea to add
callbacks to handle unrecognized lines, allowing the callback to inject text
into the parsing stream to, for example, support include files or even a macro
language.

Just my few cents,
Mats Kindahl
-- 
Mats Kindahl
Senior Software Engineer
Database Technology Group
Sun Microsystems


More information about the stdlib-sig mailing list