mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
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.
This commit is contained in:
parent
1660933d23
commit
b12f0b581a
4 changed files with 19 additions and 3 deletions
|
|
@ -187,8 +187,9 @@ RawConfigParser Objects
|
||||||
.. method:: RawConfigParser.add_section(section)
|
.. method:: RawConfigParser.add_section(section)
|
||||||
|
|
||||||
Add a section named *section* to the instance. If a section by the given name
|
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)
|
.. method:: RawConfigParser.has_section(section)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -235,8 +235,12 @@ def add_section(self, section):
|
||||||
"""Create a new section in the configuration.
|
"""Create a new section in the configuration.
|
||||||
|
|
||||||
Raise DuplicateSectionError if a section by the specified name
|
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:
|
if section in self._sections:
|
||||||
raise DuplicateSectionError(section)
|
raise DuplicateSectionError(section)
|
||||||
self._sections[section] = self._dict()
|
self._sections[section] = self._dict()
|
||||||
|
|
|
||||||
|
|
@ -446,6 +446,14 @@ def test_set_nonstring_types(self):
|
||||||
self.assertRaises(TypeError, cf.set, "sect", "option2", 1.0)
|
self.assertRaises(TypeError, cf.set, "sect", "option2", 1.0)
|
||||||
self.assertRaises(TypeError, cf.set, "sect", "option2", object())
|
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):
|
class SortedTestCase(RawConfigParserTestCase):
|
||||||
def newconfig(self, defaults=None):
|
def newconfig(self, defaults=None):
|
||||||
self.cf = self.config_class(defaults=defaults, dict_type=SortedDict)
|
self.cf = self.config_class(defaults=defaults, dict_type=SortedDict)
|
||||||
|
|
|
||||||
|
|
@ -434,6 +434,9 @@ Core and builtins
|
||||||
Library
|
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
|
- Removed uses of dict.has_key() from distutils, and uses of
|
||||||
callable() from copy_reg.py, so the interpreter now starts up
|
callable() from copy_reg.py, so the interpreter now starts up
|
||||||
without warnings when '-3' is given. More work like this needs to
|
without warnings when '-3' is given. More work like this needs to
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue