mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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.
This commit is contained in:
parent
bfe5684308
commit
68a1abdade
3 changed files with 24 additions and 7 deletions
|
@ -202,10 +202,10 @@ class MissingSectionHeaderError(ParsingError):
|
||||||
class RawConfigParser:
|
class RawConfigParser:
|
||||||
def __init__(self, defaults=None):
|
def __init__(self, defaults=None):
|
||||||
self._sections = {}
|
self._sections = {}
|
||||||
if defaults is None:
|
self._defaults = {}
|
||||||
self._defaults = {}
|
if defaults:
|
||||||
else:
|
for key, value in defaults.items():
|
||||||
self._defaults = defaults
|
self._defaults[self.optionxform(key)] = value
|
||||||
|
|
||||||
def defaults(self):
|
def defaults(self):
|
||||||
return self._defaults
|
return self._defaults
|
||||||
|
@ -511,8 +511,9 @@ class ConfigParser(RawConfigParser):
|
||||||
if section != DEFAULTSECT:
|
if section != DEFAULTSECT:
|
||||||
raise NoSectionError(section)
|
raise NoSectionError(section)
|
||||||
# Update with the entry specific variables
|
# Update with the entry specific variables
|
||||||
if vars is not None:
|
if vars:
|
||||||
d.update(vars)
|
for key, value in vars.items():
|
||||||
|
d[self.optionxform(key)] = value
|
||||||
option = self.optionxform(option)
|
option = self.optionxform(option)
|
||||||
try:
|
try:
|
||||||
value = d[option]
|
value = d[option]
|
||||||
|
@ -544,7 +545,8 @@ class ConfigParser(RawConfigParser):
|
||||||
raise NoSectionError(section)
|
raise NoSectionError(section)
|
||||||
# Update with the entry specific variables
|
# Update with the entry specific variables
|
||||||
if vars:
|
if vars:
|
||||||
d.update(vars)
|
for key, value in vars.items():
|
||||||
|
d[self.optionxform(key)] = value
|
||||||
options = d.keys()
|
options = d.keys()
|
||||||
if "__name__" in options:
|
if "__name__" in options:
|
||||||
options.remove("__name__")
|
options.remove("__name__")
|
||||||
|
|
|
@ -115,6 +115,16 @@ class TestCaseBase(unittest.TestCase):
|
||||||
self.failUnless(cf.has_option("section", "Key"))
|
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):
|
def test_parse_errors(self):
|
||||||
self.newconfig()
|
self.newconfig()
|
||||||
self.parse_error(ConfigParser.ParsingError,
|
self.parse_error(ConfigParser.ParsingError,
|
||||||
|
|
|
@ -94,6 +94,11 @@ Library
|
||||||
|
|
||||||
- httplib now handles ipv6 address/port pairs.
|
- 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
|
Build
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue