Kunjesh Kaushik added the comment:
I think we are dealing with two separate issues: a feature request for
sectionxform kind of functionality desirable in a future release (3.3 maybe)
and a behaviour issue in current releases (2.x and 3.x both). I suggest we
split the two issues and solve them
Raymond Hettinger added the comment:
Could just expand the docs to show examples of customizing behavior through
monkey-patching or subclassing:
class MyConfigParser(ConfigParser):
SECTRE = re.compile(r'[\*(?P[^]]+)\s*]'
or:
RawConfigParser.SECTRE = re.compile(r'[\*(?P[^]]+)\s*]'
-
Fred L. Drake, Jr. added the comment:
I doubt anyone is looking for section names with leading or trailing whitespace.
One approach to dealing with this is to provide and sectionxform similar to
optionxform. If we're wrong and someone really is expecting leading or
trailing whitespace, they
R. David Murray added the comment:
Well, there's still a backward compatibility issue: if this is changed,
currently working code may break. Maybe Lukasz or Fred will have a guess as to
how likely that is, because I don't.
--
nosy: +fdrake
___
Pyt
Kunjesh Kaushik added the comment:
Mr. Raymond has raised a valid point. On second thought, I think the submitted
patch won't resolve the issue.
>>> import re
>>> r = re.compile(r'\[\s*(?P[^]]+)\s*\]') # as in the patch
>>> r.match('[ section header ]').group('header') # still has issues
'sec
Raymond Hettinger added the comment:
There's a case to be made that the current regex is buggy. It already accepts
whitespace around the header name but doesn't strip it. ISTM, this is
undesirable: [ section header ] --> ' section header ' instead of 'section
header'.
>>> import configpa
R. David Murray added the comment:
A feature request can only go in to 3.3 at this point. ConfigParser has had a
serious overhaul in 3.2, by the way.
--
assignee: -> lukasz.langa
nosy: +lukasz.langa, r.david.murray
versions: +Python 3.3 -Python 2.7
__
New submission from Kunjesh Kaushik :
It is often desirable to be able to write a section with spaces around the
header, as in "[ default ]" instead of "[default]" for the sake of readability
of configuration file. I am not sure if this is the "standard" format of
configuration files.
The fol