]> granicus.if.org Git - python/commitdiff
SF bug #1017864: ConfigParser now correctly handles default keys, processing them...
authorDavid Goodger <goodger@python.org>
Sun, 3 Oct 2004 15:40:25 +0000 (15:40 +0000)
committerDavid Goodger <goodger@python.org>
Sun, 3 Oct 2004 15:40:25 +0000 (15:40 +0000)
Lib/ConfigParser.py
Lib/test/test_cfgparser.py
Misc/NEWS

index 5f80269407c0dfc605875f7032159f98327457ac..acbf3ea144a072e4c8d7babc01c52886a9bdce6b 100644 (file)
@@ -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__")
index c799c7df0a714cb4333452b0a41aa9304ad78ebb..6b3e68a6d16430f50e8f5c1f77d62fb6916b06aa 100644 (file)
@@ -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,
index cf7a321b557590d5387929894e62da4bf6338769..634f661fbc4df47b451662678b2c8cadd1383e8c 100644 (file)
--- 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
 -----