New submission from Kunjesh Kaushik kunjesh.kaus...@gmail.com:
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
R. David Murray rdmur...@bitdance.com 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
Raymond Hettinger rhettin...@users.sourceforge.net 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
Kunjesh Kaushik kunjesh.kaus...@gmail.com 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*(?Pheader[^]]+)\s*\]') # as in the patch
r.match('[ section header ]').group('header')
R. David Murray rdmur...@bitdance.com 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
Fred L. Drake, Jr. fdr...@acm.org 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
Raymond Hettinger rhettin...@users.sourceforge.net 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'[\*(?Pheader[^]]+)\s*]'
or:
Kunjesh Kaushik kunjesh.kaus...@gmail.com 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