[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread Kunjesh Kaushik

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 
configuration files.

The following (attached) patch will achieve the desired result. It is also 
backward-compatible. Kindly arrange for the patch to be applied to the 
repository or to a future release.

Original Code Location: 
http://svn.python.org/view/*checkout*/python/branches/release27-maint/Lib/ConfigParser.py?revision=84443

Index: Lib/ConfigParser.py
===
--- Lib/ConfigParser.py (revision 84443)
+++ Lib/ConfigParser.py (working copy)
@@ -432,7 +432,7 @@
 #
 SECTCRE = re.compile(
 r'\[' # [
-r'(?Pheader[^]]+)'  # very permissive!
+r'\s*(?Pheader[^]]+)\s*'# very permissive!
 r'\]' # ]
 )
 OPTCRE = re.compile(

--
components: Library (Lib)
files: allow_spaces_around_section_header.diff
keywords: patch
messages: 127193
nosy: Kunjesh.Kaushik
priority: normal
severity: normal
status: open
title: Allow spaces around section header in ConfigParser
type: feature request
versions: Python 2.7
Added file: 
http://bugs.python.org/file20547/allow_spaces_around_section_header.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread R. David Murray

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

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread Raymond Hettinger

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 'section 
header'.

 import configparser
 r = configparser.ConfigParser.SECTCRE
 r.match('[ section header ]').group('header')
' section header '

That result is not want people would usually want or expect.  I don't see any 
advantage to deferring this to 3.3.

--
keywords: +easy -patch
nosy: +rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread Kunjesh Kaushik

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')  # still has issues
'section header '

ISTM, the only solution to this problem is to strip the section headers while 
parsing the file. Subsequent access mechanism should also follow suit. IMHO, 
section headers should be made case-insensitive as well -- similar to option 
keys.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread R. David Murray

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

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread Fred L. Drake, Jr.

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 whitespace, they can set that (to str) to cancel out the change in 
behavior.

While I'd be surprised if anyone relies on this, it is a feature change, no 
matter how it's implemented, so must wait for 3.3.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread Raymond Hettinger

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:

  RawConfigParser.SECTRE = re.compile(r'[\*(?Pheader[^]]+)\s*]'

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11027] Allow spaces around section header in ConfigParser

2011-01-27 Thread Kunjesh Kaushik

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 two issues and solve them as such. Deferring the latter may be 
undesirable.

Also, I found that a non-greedy pattern will work with the original patch:

 import re
 r = re.compile(r'\[\s*(?Pheader[^]]+?)\s*\]') # note +? instead of +
 r.match('[ section header ]').group('header')   # works as expected
'section header'

Attaching a new patch file as well.

--
keywords: +patch
Added file: 
http://bugs.python.org/file20569/allow_spaces_around_section_header.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11027
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com