- backport a patch to fix a change in behaviour in configparse.

This commit is contained in:
Toshio Kuratomi 2010-09-16 13:42:05 -04:00
parent 2ec5b35c5f
commit 7211207a67
2 changed files with 77 additions and 1 deletions

View File

@ -0,0 +1,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,
)

View File

@ -94,7 +94,7 @@ Summary: An interpreted, interactive, object-oriented programming language
Name: %{python}
# Remember to also rebase python-docs when changing this:
Version: 2.7
Release: 9%{?dist}
Release: 10%{?dist}
License: Python
Group: Development/Languages
Requires: %{python}-libs%{?_isa} = %{version}-%{release}
@ -268,6 +268,11 @@ Patch54: python-2.6.4-setup-db48.patch
# for 2.7rc1 by dmalcolm:
Patch55: python-2.7rc1-dtrace.patch
# Backported fix from upstream for regression in ConfigParse's handling
# of None values
# http://bugs.python.org/issue7005#msg115417
Patch56: python-2.7-r84443-cfgparse.patch
# "lib64 patches"
# This patch seems to be associated with bug 122304, which was
# http://sourceforge.net/tracker/?func=detail&atid=105470&aid=931848&group_id=5470
@ -659,6 +664,8 @@ rm -r Modules/zlib || exit 1
%patch55 -p1 -b .systemtap
%endif
%patch56 -p0 -b .cfgparse
%patch110 -p1 -b .selinux
%patch111 -p1 -b .no-static-lib
@ -1625,6 +1632,9 @@ rm -fr %{buildroot}
# payload file would be unpackaged)
%changelog
* Thu Sep 16 2010 Toshio Kuratomi <toshio@fedoraproject.org> - 2.7-10
- backport a patch to fix a change in behaviour in configparse.
* Thu Sep 9 2010 David Malcolm <dmalcolm@redhat.com> - 2.7-9
- move most of the payload of the core package to the libs subpackage, given
that the libs aren't meaningfully usable without the standard libraries