File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed
Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -1206,8 +1206,16 @@ def add_section(self, section):
12061206
12071207 def _read_defaults (self , defaults ):
12081208 """Reads the defaults passed in the initializer, implicitly converting
1209- values to strings like the rest of the API."""
1210- self .read_dict ({self .default_section : defaults })
1209+ values to strings like the rest of the API.
1210+
1211+ Does not perform interpolation for backwards compatibility.
1212+ """
1213+ try :
1214+ hold_interpolation = self ._interpolation
1215+ self ._interpolation = Interpolation ()
1216+ self .read_dict ({self .default_section : defaults })
1217+ finally :
1218+ self ._interpolation = hold_interpolation
12111219
12121220
12131221class SafeConfigParser (ConfigParser ):
Original file line number Diff line number Diff line change @@ -1451,6 +1451,49 @@ def test_logger_disabling(self):
14511451 self .apply_config (self .disable_test , disable_existing_loggers = False )
14521452 self .assertFalse (logger .disabled )
14531453
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+ try :
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+ finally :
1495+ os .unlink (fn )
1496+
14541497
14551498class SocketHandlerTest (BaseTest ):
14561499
You can’t perform that action at this time.
0 commit comments