Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

r60976 - in python/trunk: Doc/library/configparser.rst Lib/ConfigParser.py Lib/test/test_cfgparser.py Misc/NEWS

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

Feb 23, 2008, 4:46 AM

Post #1 of 2 (1418 views)
Permalink
r60976 - in python/trunk: Doc/library/configparser.rst Lib/ConfigParser.py Lib/test/test_cfgparser.py Misc/NEWS

Author: facundo.batista
Date: Sat Feb 23 13:46:10 2008
New Revision: 60976

Modified:
python/trunk/Doc/library/configparser.rst
python/trunk/Lib/ConfigParser.py
python/trunk/Lib/test/test_cfgparser.py
python/trunk/Misc/NEWS
Log:

Issue 1781. Now ConfigParser.add_section does not let you add a
DEFAULT section any more, because it duplicated sections with
the rest of the machinery. Thanks Tim Lesher and Manuel Kaufmann.


Modified: python/trunk/Doc/library/configparser.rst
==============================================================================
--- python/trunk/Doc/library/configparser.rst (original)
+++ python/trunk/Doc/library/configparser.rst Sat Feb 23 13:46:10 2008
@@ -187,8 +187,9 @@
.. method:: RawConfigParser.add_section(section)

Add a section named *section* to the instance. If a section by the given name
- already exists, :exc:`DuplicateSectionError` is raised.
-
+ already exists, :exc:`DuplicateSectionError` is raised. If the name
+ ``DEFAULT`` (or any of it's case-insensitive variants) is passed,
+ :exc:`ValueError` is raised.

.. method:: RawConfigParser.has_section(section)


Modified: python/trunk/Lib/ConfigParser.py
==============================================================================
--- python/trunk/Lib/ConfigParser.py (original)
+++ python/trunk/Lib/ConfigParser.py Sat Feb 23 13:46:10 2008
@@ -235,8 +235,12 @@
"""Create a new section in the configuration.

Raise DuplicateSectionError if a section by the specified name
- already exists.
+ already exists. Raise ValueError if name is DEFAULT or any of it's
+ case-insensitive variants.
"""
+ if section.lower() == "default":
+ raise ValueError, 'Invalid section name: %s' % section
+
if section in self._sections:
raise DuplicateSectionError(section)
self._sections[section] = self._dict()

Modified: python/trunk/Lib/test/test_cfgparser.py
==============================================================================
--- python/trunk/Lib/test/test_cfgparser.py (original)
+++ python/trunk/Lib/test/test_cfgparser.py Sat Feb 23 13:46:10 2008
@@ -446,6 +446,14 @@
self.assertRaises(TypeError, cf.set, "sect", "option2", 1.0)
self.assertRaises(TypeError, cf.set, "sect", "option2", object())

+ def test_add_section_default_1(self):
+ cf = self.newconfig()
+ self.assertRaises(ValueError, cf.add_section, "default")
+
+ def test_add_section_default_2(self):
+ cf = self.newconfig()
+ self.assertRaises(ValueError, cf.add_section, "DEFAULT")
+
class SortedTestCase(RawConfigParserTestCase):
def newconfig(self, defaults=None):
self.cf = self.config_class(defaults=defaults, dict_type=SortedDict)

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Feb 23 13:46:10 2008
@@ -434,6 +434,9 @@
Library
-------

+- Issue 1781: ConfigParser now does not let you add the "default" section
+ (ignore-case)
+
- Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
_______________________________________________
Python-checkins mailing list
Python-checkins [at] python
http://mail.python.org/mailman/listinfo/python-checkins


fdrake at acm

Feb 23, 2008, 10:19 AM

Post #2 of 2 (1334 views)
Permalink
Re: r60976 - in python/trunk: Doc/library/configparser.rst Lib/ConfigParser.py Lib/test/test_cfgparser.py Misc/NEWS [In reply to]

On Feb 23, 2008, at 7:46 AM, facundo.batista wrote:
> Issue 1781. Now ConfigParser.add_section does not let you add a
> DEFAULT section any more, because it duplicated sections with
> the rest of the machinery. Thanks Tim Lesher and Manuel Kaufmann.

That's a good catch; thanks!

> Modified: python/trunk/Doc/library/configparser.rst
...
> + already exists, :exc:`DuplicateSectionError` is raised. If the
> name
> + ``DEFAULT`` (or any of it's case-insensitive variants) is passed,
> + :exc:`ValueError` is raised.

Why are we concerned about the case-insensitive variants? Section
names are not case-folded, as option names are by default. There are
also no ways to control the interpretation of section names, so I
think checking only for "DEFAULT" is sufficient.

If a config file contains a [default] section, that's currently loaded
and accessible.


-Fred

--
Fred Drake <fdrake at acm.org>




_______________________________________________
Python-checkins mailing list
Python-checkins [at] python
http://mail.python.org/mailman/listinfo/python-checkins

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.