cpython: 876bee0bd0ba (original) (raw)
--- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -1102,10 +1102,10 @@ class RawConfigParser(MutableMapping): # raised at the end of the file and will contain a # list of all bogus lines e = self._handle_error(e, fpname, lineno, line)
self._join_multiline_values()[](#l1.7) # if any parsing errors occurred, raise an exception[](#l1.8) if e:[](#l1.9) raise e[](#l1.10)
self._join_multiline_values()[](#l1.11)
def _join_multiline_values(self): defaults = self.default_section, self._defaults
--- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -9,6 +9,7 @@ import warnings from test import support + class SortedDict(collections.UserDict): def items(self): @@ -64,6 +65,7 @@ class CfgParserTestCaseClass: cf.read_string(string) return cf + class BasicTestCase(CfgParserTestCaseClass): def basic_test(self, cf): @@ -828,6 +830,21 @@ 123 {0[1]} strange but acceptable self.assertEqual(set(cf['section3'].keys()), set()) self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
- def test_invalid_multiline_value(self):
if self.allow_no_value:[](#l2.24)
self.skipTest('if no_value is allowed, ParsingError is not raised')[](#l2.25)
invalid = textwrap.dedent("""\[](#l2.27)
[DEFAULT][](#l2.28)
test {0} test[](#l2.29)
invalid""".format(self.delimiters[0])[](#l2.30)
)[](#l2.31)
cf = self.newconfig()[](#l2.32)
with self.assertRaises(configparser.ParsingError):[](#l2.33)
cf.read_string(invalid)[](#l2.34)
self.assertEqual(cf.get('DEFAULT', 'test'), 'test')[](#l2.35)
self.assertEqual(cf['DEFAULT']['test'], 'test')[](#l2.36)
+ class StrictTestCase(BasicTestCase, unittest.TestCase): config_class = configparser.RawConfigParser @@ -981,14 +998,17 @@ class ConfigParserTestCaseLegacyInterpol cf.set("sect", "option2", "foo%%bar") self.assertEqual(cf.get("sect", "option2"), "foo%%bar") + class ConfigParserTestCaseNonStandardDelimiters(ConfigParserTestCase): delimiters = (':=', '$') comment_prefixes = ('//', '"') inline_comment_prefixes = ('//', '"') + class ConfigParserTestCaseNonStandardDefaultSection(ConfigParserTestCase): default_section = 'general' + class MultilineValuesTestCase(BasicTestCase, unittest.TestCase): config_class = configparser.ConfigParser wonderful_spam = ("I'm having spam spam spam spam " @@ -1017,6 +1037,7 @@ class MultilineValuesTestCase(BasicTestC self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'), self.wonderful_spam.replace('\t\n', '\n')) + class RawConfigParserTestCase(BasicTestCase, unittest.TestCase): config_class = configparser.RawConfigParser @@ -1059,11 +1080,13 @@ class RawConfigParserTestCase(BasicTestC cf.set('non-string', 1, 1) self.assertEqual(cf.get('non-string', 1), 1) + class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase): delimiters = (':=', '$') comment_prefixes = ('//', '"') inline_comment_prefixes = ('//', '"') + class RawConfigParserTestSambaConf(CfgParserTestCaseClass, unittest.TestCase): config_class = configparser.RawConfigParser comment_prefixes = ('#', ';', '----') @@ -1258,6 +1281,7 @@ class ConfigParserTestCaseExtendedInterp class ConfigParserTestCaseNoValue(ConfigParserTestCase): allow_no_value = True + class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase): config_class = configparser.ConfigParser delimiters = {'='}
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -664,6 +664,7 @@ Jeremy Hylton Ludwig Hähne Gerhard Häring Fredrik Håård +Florian Höch Catalin Iacob Mihai Ibanescu Ali Ikinci