[Python-Dev] Re: ConfigParser case sensitive and strings vs objects returned

Fred L. Drake, Jr. fdrake at acm.org
Tue Oct 7 14:48:13 EDT 2003


Gordon Williams writes:
 > Hi Fred,
 > 
 > A couple of other things about the ConfigParser module that I find a bit
 > strange and I'm not sure that is intended behaivior.
 > 
 > 
 > 1. Option gets converted to lower case and therefore is not case sensitive,
 > but section is case sensitive.  I would have thought that both would be or
 > neither would be case sensitive.  (My preference would be that neither would
 > be case sensitive.)

And mine would be that both are case sensitive!  ;-) I guess that's
why we have optionxform to override the transform for option names at
least.

Ideally, both option and section names should be transformed, but the
specific transforms should be independently pluggable.  I'm not
adverse to a patch which adds a sectionxform, but don't have the time
or motivation to change it myself.  Feel free to post a patch to
SourceForge and assign it to me for review.  Documentation and tests
are required.

[...examples elided...]
 > The differences in handling the option and section are annoying and should
 > at least be described in the docs if they cant be changed.

Please suggest specific changes; I don't expect to have much time for
ConfigParser anytime soon, so specific changes (esp. a patch if you
can deal with the LaTeX) would be greatly appreciated.

 > 2. SafeConfigParser is the recommended ConfigParser in the docs.  I'm not
 > sure what is meant be safe.  When values are read in from a file they are
 > first converted to strings.  This is not true for values set within the
 > code.

True.  I'd suggest that at most, a typecheck for a value being a
string could be added to the code; the documentation may need further
elaboration.

The "Safe" was intended to refer specifically to the string
substitution algorithm; it uses a more careful implementation that
isn't as subject to weird border conditions.  Again, the documentation
may require improvements.

 > If I set an option with anything other than a string then this occurs:
...
 > Likely the value assigned to the object should be first converted to a
 > string before it is stored.

Or an exception should be raised, placing the burden squarely on the
caller to do the right thing, instead of guessing what the right thing
is.

 > One last comment is that 'interpolation' is a bit confusing in the docs.
 > Maybe 'substitution' would be a better word.

Agreed.

I'd like to suggest two things:

- Get a SourceForge account and file a bug report (you don't need to
  be on the Python project, just having an account is sufficient).

- Take a look at some of the alternate configuration libraries; they
  may be more suited to your requirements.  My current favorite is
  ZConfig, for which a new version is expected in the next week or so:

  http://www.python.org/pypi?%3Aaction=search&name=ZConfig

  But I might be biased about this one.  ;-)


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation



More information about the Python-Dev mailing list