diff options
author | Fred Drake <fdrake@acm.org> | 2010-09-03 03:55:50 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2010-09-03 03:55:50 (GMT) |
commit | a1e627d61c57fefbfdabf308b33de75e08ca5374 (patch) | |
tree | 36e327d20096d27acd42a6bff049fd060bba21a3 | |
parent | 5cd2d8c7eca0a0a62ab58e8fa3b06d837ba6d6c1 (diff) | |
download | cpython-a1e627d61c57fefbfdabf308b33de75e08ca5374.zip cpython-a1e627d61c57fefbfdabf308b33de75e08ca5374.tar.gz cpython-a1e627d61c57fefbfdabf308b33de75e08ca5374.tar.bz2 |
fix output from RawConfigParser.write and ConfigParser.write for None
values (http://bugs.python.org/issue7005)
-rw-r--r-- | Lib/ConfigParser.py | 2 | ||||
-rw-r--r-- | Lib/test/test_cfgparser.py | 28 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 32 insertions, 1 deletions
diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py index d356a13..dc73988 100644 --- a/Lib/ConfigParser.py +++ b/Lib/ConfigParser.py @@ -400,7 +400,7 @@ class RawConfigParser: for (key, value) in self._sections[section].items(): if key == "__name__": continue - if value is not None: + if (value is not None) or (self._optcre == self.OPTCRE): key = " = ".join((key, str(value).replace('\n', '\n\t'))) fp.write("%s\n" % (key)) fp.write("\n") diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py index 5417d24..20c10dc 100644 --- a/Lib/test/test_cfgparser.py +++ b/Lib/test/test_cfgparser.py @@ -530,6 +530,33 @@ class SafeConfigParserTestCaseNoValue(SafeConfigParserTestCase): allow_no_value = True +class Issue7005TestCase(unittest.TestCase): + """Test output when None is set() as a value and allow_no_value == False. + + http://bugs.python.org/issue7005 + + """ + + expected_output = "[section]\noption = None\n\n" + + def prepare(self, config_class): + # This is the default, but that's the point. + cp = config_class(allow_no_value=False) + cp.add_section("section") + cp.set("section", "option", None) + sio = StringIO.StringIO() + cp.write(sio) + return sio.getvalue() + + def test_none_as_value_stringified(self): + output = self.prepare(ConfigParser.ConfigParser) + self.assertEqual(output, self.expected_output) + + def test_none_as_value_stringified_raw(self): + output = self.prepare(ConfigParser.RawConfigParser) + self.assertEqual(output, self.expected_output) + + class SortedTestCase(RawConfigParserTestCase): def newconfig(self, defaults=None): self.cf = self.config_class(defaults=defaults, dict_type=SortedDict) @@ -563,6 +590,7 @@ def test_main(): SafeConfigParserTestCase, SafeConfigParserTestCaseNoValue, SortedTestCase, + Issue7005TestCase, ) @@ -36,6 +36,9 @@ Core and Builtins Library ------- +- Issue #7005: Fixed output of None values for RawConfigParser.write and + ConfigParser.write. + - Issue #808164: Fixed socket.close to avoid references to globals, to avoid issues when socket.close is called from a __del__ method. |