summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Goodger <goodger@python.org>2004-10-03 15:40:25 (GMT)
committerDavid Goodger <goodger@python.org>2004-10-03 15:40:25 (GMT)
commit68a1abdadec2377fd3e8d2211cb3cc119de77a28 (patch)
tree93db094b5487a4e8999c894c3ce7ba950bea97a3
parentbfe56843084c0ccb7f26e5225b1c22d767d90eb8 (diff)
downloadcpython-68a1abdadec2377fd3e8d2211cb3cc119de77a28.zip
cpython-68a1abdadec2377fd3e8d2211cb3cc119de77a28.tar.gz
cpython-68a1abdadec2377fd3e8d2211cb3cc119de77a28.tar.bz2
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
-rw-r--r--Lib/ConfigParser.py16
-rw-r--r--Lib/test/test_cfgparser.py10
-rw-r--r--Misc/NEWS5
3 files changed, 24 insertions, 7 deletions
diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py
index 5f80269..acbf3ea 100644
--- a/Lib/ConfigParser.py
+++ b/Lib/ConfigParser.py
@@ -202,10 +202,10 @@ class MissingSectionHeaderError(ParsingError):
class RawConfigParser:
def __init__(self, defaults=None):
self._sections = {}
- if defaults is None:
- self._defaults = {}
- else:
- self._defaults = defaults
+ self._defaults = {}
+ if defaults:
+ for key, value in defaults.items():
+ self._defaults[self.optionxform(key)] = value
def defaults(self):
return self._defaults
@@ -511,8 +511,9 @@ class ConfigParser(RawConfigParser):
if section != DEFAULTSECT:
raise NoSectionError(section)
# Update with the entry specific variables
- if vars is not None:
- d.update(vars)
+ if vars:
+ for key, value in vars.items():
+ d[self.optionxform(key)] = value
option = self.optionxform(option)
try:
value = d[option]
@@ -544,7 +545,8 @@ class ConfigParser(RawConfigParser):
raise NoSectionError(section)
# Update with the entry specific variables
if vars:
- d.update(vars)
+ for key, value in vars.items():
+ d[self.optionxform(key)] = value
options = d.keys()
if "__name__" in options:
options.remove("__name__")
diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py
index c799c7d..6b3e68a 100644
--- a/Lib/test/test_cfgparser.py
+++ b/Lib/test/test_cfgparser.py
@@ -115,6 +115,16 @@ class TestCaseBase(unittest.TestCase):
self.failUnless(cf.has_option("section", "Key"))
+ def test_default_case_sensitivity(self):
+ cf = self.newconfig({"foo": "Bar"})
+ self.assertEqual(
+ cf.get("DEFAULT", "Foo"), "Bar",
+ "could not locate option, expecting case-insensitive option names")
+ cf = self.newconfig({"Foo": "Bar"})
+ self.assertEqual(
+ cf.get("DEFAULT", "Foo"), "Bar",
+ "could not locate option, expecting case-insensitive defaults")
+
def test_parse_errors(self):
self.newconfig()
self.parse_error(ConfigParser.ParsingError,
diff --git a/Misc/NEWS b/Misc/NEWS
index cf7a321..634f661 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -94,6 +94,11 @@ Library
- httplib now handles ipv6 address/port pairs.
+- SF bug #1017864: ConfigParser now correctly handles default keys,
+ processing them with ``ConfigParser.optionxform`` when supplied,
+ consistent with the handling of config file entries and runtime-set
+ options.
+
Build
-----