[ python-Bugs-830449 ] Config parser don't raise DuplicateSectionError when reading

SourceForge.net noreply at sourceforge.net
Mon May 17 23:59:53 EDT 2004


Bugs item #830449, was opened at 2003-10-26 07:20
Message generated for change (Settings changed) made by fdrake
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=830449&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Miki Tebeka (tebeka)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Config parser don't raise DuplicateSectionError when reading

Initial Comment:
According to the documentation of ConfigParser
"DuplicateSectionError" it is raised if multiple
sections with the same name are found.

In the code this is not the case (it continues to
update the section with the same name (see
ConfigParser.py line 447).

Either fix the code (which I prefer :-) of the
documentation.

Miki

----------------------------------------------------------------------

>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2004-05-17 23:59

Message:
Logged In: YES 
user_id=3066

I've fixed the documentation; changing the semantics is too
invasive to existing applications.  ConfigParser doesn't
have enough internal state to know whether a section was
defined twice in a single input file or if it was defined in
two different files.  The later case should be  allowed,
while the former case is questionable at best.

Doc/lib/libcfgparser.tex 1.37

----------------------------------------------------------------------

Comment By: Johan M. Hahn (johahn)
Date: 2003-10-26 16:18

Message:
Logged In: YES 
user_id=887415

I hereby confirm the bug and I've included some sample code 
of it as well. Though I don't know which solution is the best. 
Fixing the code might break some production code that uses 
duplicate sections and it is therefor easier to just change the 
documentation. I also don't see reason to why they should be  
disallowed in the first place.

>>> import ConfigParser
>>> cp = ConfigParser.ConfigParser()
>>> from StringIO import StringIO
>>> fp = StringIO("""
;
[section1]
var1=option1
[section2]
var2=option2
[section1]
var3=option3
""")
>>> cp.readfp(fp)
>>> [x for x in cp.items('sec1')]
[('var1', 'option1'), ('var3', 'option3')]
>>> 

...johahn

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=830449&group_id=5470



More information about the Python-bugs-list mailing list