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

facundo.batista python-checkins at python.org
Sat Feb 23 13:46:11 CET 2008


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


More information about the Python-checkins mailing list