]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 1781. Now ConfigParser.add_section does not let you add a
authorFacundo Batista <facundobatista@gmail.com>
Sat, 23 Feb 2008 12:46:10 +0000 (12:46 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Sat, 23 Feb 2008 12:46:10 +0000 (12:46 +0000)
DEFAULT section any more, because it duplicated sections with
the rest of the machinery. Thanks Tim Lesher and Manuel Kaufmann.

Doc/library/configparser.rst
Lib/ConfigParser.py
Lib/test/test_cfgparser.py
Misc/NEWS

index ec3b0220ba7fcc1c5b4b98f96840e969a6ca454f..96c001fc7d72131bd878ab61fb56f41be3b79f1b 100644 (file)
@@ -187,8 +187,9 @@ RawConfigParser Objects
 .. 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)
 
index 131d69746798c1459f74df63ca184b8b13a4f1f7..65c6ae2ae38950f3ffa7d79b88267963783d7014 100644 (file)
@@ -235,8 +235,12 @@ class RawConfigParser:
         """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()
index c4df74185e024f6c14af97a21da3f5211c097971..a8b5d7c389ad4ed48a5db1bda3668173c8b2199b 100644 (file)
@@ -446,6 +446,14 @@ class SafeConfigParserTestCase(ConfigParserTestCase):
         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)
index a33bf714c45f203c2912333ee4648e8850c61893..89f4c4993716de8a06a6886fbf74e0532c462308 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -434,6 +434,9 @@ Core and builtins
 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