[Python-checkins] cpython (merge 3.2 -> default): Merged solution for #11324 from 3.2.

lukasz.langa python-checkins at python.org
Thu Apr 28 17:04:45 CEST 2011


http://hg.python.org/cpython/rev/de7dc59260b1
changeset:   69669:de7dc59260b1
parent:      69667:062ca988cbf6
parent:      69668:32031e33d793
user:        Łukasz Langa <lukasz at langa.pl>
date:        Thu Apr 28 17:04:25 2011 +0200
summary:
  Merged solution for #11324 from 3.2.

files:
  Lib/configparser.py           |   9 +++--
  Lib/test/test_configparser.py |  38 +++++++++++++++++++++++
  Misc/ACKS                     |   1 +
  3 files changed, 44 insertions(+), 4 deletions(-)


diff --git a/Lib/configparser.py b/Lib/configparser.py
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -624,11 +624,12 @@
         self._strict = strict
         self._allow_no_value = allow_no_value
         self._empty_lines_in_values = empty_lines_in_values
-        if interpolation is _UNSET:
+        self.default_section=default_section
+        self._interpolation = interpolation
+        if self._interpolation is _UNSET:
             self._interpolation = self._DEFAULT_INTERPOLATION
-        else:
-            self._interpolation = interpolation
-        self.default_section=default_section
+        if self._interpolation is None:
+            self._interpolation = Interpolation()
 
     def defaults(self):
         return self._defaults
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py
--- a/Lib/test/test_configparser.py
+++ b/Lib/test/test_configparser.py
@@ -864,6 +864,43 @@
         cf = self.newconfig()
         self.assertRaises(ValueError, cf.add_section, self.default_section)
 
+
+class ConfigParserTestCaseNoInterpolation(BasicTestCase):
+    config_class = configparser.ConfigParser
+    interpolation = None
+    ini = textwrap.dedent("""
+        [numbers]
+        one = 1
+        two = %(one)s * 2
+        three = ${common:one} * 3
+
+        [hexen]
+        sixteen = ${numbers:two} * 8
+    """).strip()
+
+    def assertMatchesIni(self, cf):
+        self.assertEqual(cf['numbers']['one'], '1')
+        self.assertEqual(cf['numbers']['two'], '%(one)s * 2')
+        self.assertEqual(cf['numbers']['three'], '${common:one} * 3')
+        self.assertEqual(cf['hexen']['sixteen'], '${numbers:two} * 8')
+
+    def test_no_interpolation(self):
+        cf = self.fromstring(self.ini)
+        self.assertMatchesIni(cf)
+
+    def test_empty_case(self):
+        cf = self.newconfig()
+        self.assertIsNone(cf.read_string(""))
+
+    def test_none_as_default_interpolation(self):
+        class CustomConfigParser(configparser.ConfigParser):
+            _DEFAULT_INTERPOLATION = None
+
+        cf = CustomConfigParser()
+        cf.read_string(self.ini)
+        self.assertMatchesIni(cf)
+
+
 class ConfigParserTestCaseLegacyInterpolation(ConfigParserTestCase):
     config_class = configparser.ConfigParser
     interpolation = configparser.LegacyInterpolation()
@@ -1444,6 +1481,7 @@
         ConfigParserTestCaseNoValue,
         ConfigParserTestCaseExtendedInterpolation,
         ConfigParserTestCaseLegacyInterpolation,
+        ConfigParserTestCaseNoInterpolation,
         ConfigParserTestCaseTrickyFile,
         MultilineValuesTestCase,
         RawConfigParserTestCase,
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -115,6 +115,7 @@
 Brian Brazil
 Dave Brennan
 Tom Bridgman
+Tobias Brink
 Richard Brodie
 Michael Broghton
 Daniel Brotsky

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list