Bug in ConfigParser

tnixon at avalanchesoftware.com tnixon at avalanchesoftware.com
Sun Oct 22 05:29:23 EDT 2000


There's a case sensitivity bug lurking in ConfigParser. (just
downloaded the final version of 2.0 for windows, which is where I found
this)

The following script:

import ConfigParser

cp = ConfigParser.ConfigParser()
cp.add_section('test')
cp.set('test','MyCaseOption','MixedCase')
cp.get('test','MyCaseOption')

produces the following output:

Traceback (most recent call last):
  File "cp.py", line 6, in ?
    cp.get('test','MyCaseOption')
  File "c:\python20\lib\ConfigParser.py", line 279, in get
    raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option `mycaseoption' in section: test

The problem is that both get() and read() switch the options to lower
case (using ConfigParser.optionxform()) , but NONE of the other methods
do this.

Basically what this means is that ConfigParser only works if you don't
use any upper case in your option names, or you only use read() and get
()

I don't know what the original intent was, but personally I would
prefer to have the case sensitivity there, so I changed optionxform so
that it doesn't do anything.  Quick and easy, and it does what I want.
Changing it so everything uses the xform is a little more involved. :)


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list