[patch] Duplicate sections detection in ConfigParser

Greetings Pythonistas, ConfigParser as you most certainly know is a .ini parser included in the Python standard library. It's documentation mentions a DuplicateSectionError but I was puzzled after hunting a bug in our application that this error was not raised when parsing a file with duplicate sections. After looking at the code, it turns out that DuplicateSectionError is only raised when using the builder interface; the parser interface will never throw it. The attached patch is compatible with both the 2.x and the 3.x branches; it adds a `unique_sects` parameter to the constructor of RawConfigParser and a test in the parser loop that raises DuplicateSectionError if a section is seen more then once and that unique_sects is True. This is just a proof of concept and I'd like your opinion on it before working on the final version. I see two main issues regarding backward compatibility and uniformity. For uniformity `unique_sects` should also apply to the builder interface. However, if it does, it should default to True since it was the default behavior for the builder interface to raise on duplicate sections. On the other hand, the default behavior for the parser interface was to ignore duplicate sections so making `unique_sects` default to True might break existing code. To summarize, I ask you all: * Is the lack of duplicates detection in the parser a problem worth addressing? * Should `unique_sects` control the builder interface? * Should it default to True? Best regards, -- Yannick Gingras http://ygingras.net

On Tue, Feb 03, 2009, Yannick Gingras wrote:
The attached patch is compatible with both the 2.x and the 3.x branches; it adds a `unique_sects` parameter to the constructor of RawConfigParser and a test in the parser loop that raises DuplicateSectionError if a section is seen more then once and that unique_sects is True.
Please go ahead and post the patch to bugs.python.org; it can always be revised later and this ensures that we have a record. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.

The attached patch is compatible with both the 2.x and the 3.x branches; it adds a `unique_sects` parameter to the constructor of RawConfigParser and a test in the parser loop that raises DuplicateSectionError if a section is seen more then once and that unique_sects is True.
http://bugs.python.org/issue2204 refers to the same issue. Perhaps, you can upload your patch there in addition to adding any comments. Thanks, Raghu

On Tuesday 03 February 2009, Raghuram Devarakonda wrote:
http://bugs.python.org/issue2204 refers to the same issue. Perhaps, you can upload your patch there in addition to adding any comments.
I attached the patch to the ticket. Do you have recommendations on how to solve the uniformity issue with the builder interface? -- Yannick Gingras http://ygingras.net
participants (3)
-
Aahz
-
Raghuram Devarakonda
-
Yannick Gingras