7211207
Index: Lib/ConfigParser.py
7211207
===================================================================
7211207
--- Lib/ConfigParser.py.orig
7211207
+++ Lib/ConfigParser.py
7211207
@@ -399,11 +399,10 @@ class RawConfigParser:
7211207
             fp.write("[%s]\n" % section)
7211207
             for (key, value) in self._sections[section].items():
7211207
                 if key != "__name__":
7211207
-                    if value is None:
7211207
-                        fp.write("%s\n" % (key))
7211207
-                    else:
7211207
-                        fp.write("%s = %s\n" %
7211207
-                                 (key, str(value).replace('\n', '\n\t')))
7211207
+                    if (value is not None) or (self._optcre == self.OPTCRE):
7211207
+                        key = " = ".join((key, str(value).replace('\n', '\n\t')))
7211207
+                    fp.write("%s\n" % (key))
7211207
+
7211207
             fp.write("\n")
7211207
 
7211207
     def remove_option(self, section, option):
7211207
Index: Lib/test/test_cfgparser.py
7211207
===================================================================
7211207
--- Lib/test/test_cfgparser.py.orig
7211207
+++ Lib/test/test_cfgparser.py
7211207
@@ -493,6 +493,33 @@ class SafeConfigParserTestCaseNoValue(Sa
7211207
     allow_no_value = True
7211207
 
7211207
 
7211207
+class Issue7005TestCase(unittest.TestCase):
7211207
+    """Test output when None is set() as a value and allow_no_value == False.
7211207
+
7211207
+    http://bugs.python.org/issue7005
7211207
+
7211207
+    """
7211207
+
7211207
+    expected_output = "[section]\noption = None\n\n"
7211207
+
7211207
+    def prepare(self, config_class):
7211207
+        # This is the default, but that's the point.
7211207
+        cp = config_class(allow_no_value=False)
7211207
+        cp.add_section("section")
7211207
+        cp.set("section", "option", None)
7211207
+        sio = StringIO.StringIO()
7211207
+        cp.write(sio)
7211207
+        return sio.getvalue()
7211207
+
7211207
+    def test_none_as_value_stringified(self):
7211207
+        output = self.prepare(ConfigParser.ConfigParser)
7211207
+        self.assertEqual(output, self.expected_output)
7211207
+
7211207
+    def test_none_as_value_stringified_raw(self):
7211207
+        output = self.prepare(ConfigParser.RawConfigParser)
7211207
+        self.assertEqual(output, self.expected_output)
7211207
+
7211207
+
7211207
 class SortedTestCase(RawConfigParserTestCase):
7211207
     def newconfig(self, defaults=None):
7211207
         self.cf = self.config_class(defaults=defaults, dict_type=SortedDict)
7211207
@@ -524,6 +551,7 @@ def test_main():
7211207
         RawConfigParserTestCase,
7211207
         SafeConfigParserTestCase,
7211207
         SortedTestCase,
7211207
+        Issue7005TestCase,
7211207
         SafeConfigParserTestCaseNoValue,
7211207
         )
7211207