Message255304
Discussion continues because my close message was, I now realize, incomplete and therefore unsatisfying. Ditto for the doc. So I complete my close message here and reopen issue to augment the doc.
The discussion has so far has glossed over the key question: "What is a legal section name?" Pulling the answer from the doc was a challenge. It uses 'legal section name', once, as if one should already know. Reading further, I found the answer: there is no (fixed) answer!
The legal section name for a particular parser is determined by its .SECTCRE class attribute.
'''configparser.SECTCRE
A compiled regular expression used to parse section headers. The default matches [section] to the name "section".''' (This neglects to say whether the closing ']' is the first or last ']' on the line after the opening '['.) A non-verbose version of the default is
re.compile(r"\[(?P<header>[^]]+)\]").
I propose adding near the top of the doc:
"By default, a legal section name can be any string that does not contain '\n' or ']'. To change this, see configparser.SECTCRE."
So my response to Miloš should have been to set SECTCRE to something like p below.
>>> p = re.compile(r"\[(?P<header>.*)\]")
>>> m = p.search("[Test[2]_foo]")
>>> m.group('header')
'Test[2]_foo'
Additional note: Postel's principle was formulated for internet protocols, which .ini files are not. In any case, it is not a Python design principle. Neither is "always check user input", which amounts to 'look before you leap'. So I will not debate these. However, "Errors should never pass silently." is #10 on the Zen of Python ('import this') and that I do attend to. |
|
Date |
User |
Action |
Args |
2015-11-24 23:37:00 | terry.reedy | set | recipients:
+ terry.reedy, r.david.murray, docs@python, BreamoreBoy, lukasz.langa, miloskomarcevic, xflr6, spaceone |
2015-11-24 23:37:00 | terry.reedy | set | messageid: <1448408220.9.0.150519052999.issue20923@psf.upfronthosting.co.za> |
2015-11-24 23:37:00 | terry.reedy | link | issue20923 messages |
2015-11-24 23:37:00 | terry.reedy | create | |
|