[Python-Dev] ConfigParser patches
David Goodger
goodger at python.org
Fri Oct 1 16:24:39 CEST 2004
I have patches up on SF for two ConfigParser bugs, which I'd like to
check in ASAP. Any objections?
http://www.python.org/sf/1017864: Case sensitivity bug in ConfigParser
======================================================================
This is a simple bug relating to default values passed in as
dictionaries, illustrated here:
>>> import ConfigParser
>>> cp = ConfigParser.ConfigParser({"foo": "Bar"})
>>> cp.get("DEFAULT", "Foo")
'Bar'
>>> cp = ConfigParser.ConfigParser({"FOO": "Bar"}) # <-- note CAPS
>>> cp.get("DEFAULT", "FOO") # same for "foo", "Foo", etc.
Traceback (most recent call last):
...
ConfigParser.NoOptionError: No option 'foo' in section: 'DEFAULT'
The patch applies ConfigParser.optionxform to keys of defaults when
supplied, to be consistent with the handling of keys of config file
entries and runtime-set options. A test patch is also included.
http://www.python.org/sf/997050: ConfigParser behavior change
=============================================================
This may be more controversial. In Python 2.3 and earlier,
ConfigParser implicitly allowed non-string values to be set.
http://python.org/sf/810843 asked for clarification, and in rev 1.65
an explicit type check was added that raises TypeError. The problem
is that this breaks Docutils code, and I suspect it will break other
code as well, which we won't hear about until after Python 2.4 final
is released. Setting non-string values worked just fine for
application-internal use, as long as interpolation is turned off
(RawConfigParser is used or ConfigParser with "raw" parameter set) and
config files aren't written.
A new SafeConfigParser class was added in Python 2.3:
New applications should prefer this version if they don't need to
be compatible with older versions of Python.
My solution is to add the new string-only restriction to the
SafeConfigParser class, leave existing ConfigParser & RawConfigParser
behavior alone, and document the conditions under which non-string
values work. Code, doc, and test patches included.
What say you?
--
David Goodger <http://python.net/~goodger>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : http://mail.python.org/pipermail/python-dev/attachments/20041001/d193ff4f/signature.pgp
More information about the Python-Dev
mailing list