-
Notifications
You must be signed in to change notification settings - Fork 4
/
python-2.7-r84443-cfgparse.patch
66 lines (62 loc) · 2.33 KB
/
python-2.7-r84443-cfgparse.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Index: Lib/ConfigParser.py
===================================================================
--- Lib/ConfigParser.py.orig
+++ Lib/ConfigParser.py
@@ -399,11 +399,10 @@ class RawConfigParser:
fp.write("[%s]\n" % section)
for (key, value) in self._sections[section].items():
if key != "__name__":
- if value is None:
- fp.write("%s\n" % (key))
- else:
- fp.write("%s = %s\n" %
- (key, str(value).replace('\n', '\n\t')))
+ 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")
def remove_option(self, section, option):
Index: Lib/test/test_cfgparser.py
===================================================================
--- Lib/test/test_cfgparser.py.orig
+++ Lib/test/test_cfgparser.py
@@ -493,6 +493,33 @@ class SafeConfigParserTestCaseNoValue(Sa
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)
@@ -524,6 +551,7 @@ def test_main():
RawConfigParserTestCase,
SafeConfigParserTestCase,
SortedTestCase,
+ Issue7005TestCase,
SafeConfigParserTestCaseNoValue,
)