There was an error while loading. Please reload this page.
1 parent 66f02aa commit 214f18eCopy full SHA for 214f18e
2 files changed
Lib/configparser.py
@@ -1208,8 +1208,16 @@ def add_section(self, section):
1208
1209
def _read_defaults(self, defaults):
1210
"""Reads the defaults passed in the initializer, implicitly converting
1211
- values to strings like the rest of the API."""
1212
- self.read_dict({self.default_section: defaults})
+ values to strings like the rest of the API.
+
1213
+ Does not perform interpolation for backwards compatibility.
1214
+ """
1215
+ try:
1216
+ hold_interpolation = self._interpolation
1217
+ self._interpolation = Interpolation()
1218
+ self.read_dict({self.default_section: defaults})
1219
+ finally:
1220
+ self._interpolation = hold_interpolation
1221
1222
1223
class SafeConfigParser(ConfigParser):
Lib/test/test_logging.py
@@ -1451,6 +1451,49 @@ def test_logger_disabling(self):
1451
self.apply_config(self.disable_test, disable_existing_loggers=False)
1452
self.assertFalse(logger.disabled)
1453
1454
+ def test_defaults_do_no_interpolation(self):
1455
+ """bpo-33802 defaults should not get interpolated"""
1456
+ ini = textwrap.dedent("""
1457
+ [formatters]
1458
+ keys=default
1459
1460
+ [formatter_default]
1461
1462
+ [handlers]
1463
+ keys=console
1464
1465
+ [handler_console]
1466
+ class=logging.StreamHandler
1467
+ args=tuple()
1468
1469
+ [loggers]
1470
+ keys=root
1471
1472
+ [logger_root]
1473
+ formatter=default
1474
+ handlers=console
1475
+ """).strip()
1476
+ fd, fn = tempfile.mkstemp(prefix='test_logging_', suffix='.ini')
1477
1478
+ os.write(fd, ini.encode('ascii'))
1479
+ os.close(fd)
1480
+ logging.config.fileConfig(
1481
+ fn,
1482
+ defaults=dict(
1483
+ version=1,
1484
+ disable_existing_loggers=False,
1485
+ formatters={
1486
+ "generic": {
1487
+ "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s",
1488
+ "datefmt": "[%Y-%m-%d %H:%M:%S %z]",
1489
+ "class": "logging.Formatter"
1490
+ },
1491
1492
+ )
1493
1494
1495
+ os.unlink(fn)
1496
1497
1498
class SocketHandlerTest(BaseTest):
1499
0 commit comments