@@ -263,12 +263,9 @@ class InterpolationMissingOptionError(InterpolationError):
263263 """A string substitution required a setting which was not available."""
264264
265265 def __init__ (self , option , section , rawval , reference ):
266- msg = ("Bad value substitution:\n "
267- "\t section: [%s]\n "
268- "\t option : %s\n "
269- "\t key : %s\n "
270- "\t rawval : %s\n "
271- % (section , option , reference , rawval ))
266+ msg = ("Bad value substitution: option {!r} in section {!r} contains "
267+ "an interpolation key {!r} which is not a valid option name. "
268+ "Raw value: {!r}" .format (option , section , reference , rawval ))
272269 InterpolationError .__init__ (self , option , section , msg )
273270 self .reference = reference
274271 self .args = (option , section , rawval , reference )
@@ -286,11 +283,11 @@ class InterpolationDepthError(InterpolationError):
286283 """Raised when substitutions are nested too deeply."""
287284
288285 def __init__ (self , option , section , rawval ):
289- msg = ("Value interpolation too deeply recursive: \n "
290- "\t section: [%s] \n "
291- "\t option : %s \n "
292- "\t rawval : %s \n "
293- % ( section , option , rawval ))
286+ msg = ("Recursion limit exceeded in value substitution: option {!r} "
287+ "in section {!r} contains an interpolation key which "
288+ "cannot be substituted in {} steps. Raw value: {!r} "
289+ "" . format ( option , section , MAX_INTERPOLATION_DEPTH ,
290+ rawval ))
294291 InterpolationError .__init__ (self , option , section , msg )
295292 self .args = (option , section , rawval )
296293
@@ -406,8 +403,9 @@ def before_set(self, parser, section, option, value):
406403
407404 def _interpolate_some (self , parser , option , accum , rest , section , map ,
408405 depth ):
406+ rawval = parser .get (section , option , raw = True , fallback = rest )
409407 if depth > MAX_INTERPOLATION_DEPTH :
410- raise InterpolationDepthError (option , section , rest )
408+ raise InterpolationDepthError (option , section , rawval )
411409 while rest :
412410 p = rest .find ("%" )
413411 if p < 0 :
@@ -432,7 +430,7 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
432430 v = map [var ]
433431 except KeyError :
434432 raise InterpolationMissingOptionError (
435- option , section , rest , var ) from None
433+ option , section , rawval , var ) from None
436434 if "%" in v :
437435 self ._interpolate_some (parser , option , accum , v ,
438436 section , map , depth + 1 )
@@ -466,8 +464,9 @@ def before_set(self, parser, section, option, value):
466464
467465 def _interpolate_some (self , parser , option , accum , rest , section , map ,
468466 depth ):
467+ rawval = parser .get (section , option , raw = True , fallback = rest )
469468 if depth > MAX_INTERPOLATION_DEPTH :
470- raise InterpolationDepthError (option , section , rest )
469+ raise InterpolationDepthError (option , section , rawval )
471470 while rest :
472471 p = rest .find ("$" )
473472 if p < 0 :
@@ -504,7 +503,7 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
504503 "More than one ':' found: %r" % (rest ,))
505504 except (KeyError , NoSectionError , NoOptionError ):
506505 raise InterpolationMissingOptionError (
507- option , section , rest , ":" .join (path )) from None
506+ option , section , rawval , ":" .join (path )) from None
508507 if "$" in v :
509508 self ._interpolate_some (parser , opt , accum , v , sect ,
510509 dict (parser .items (sect , raw = True )),
0 commit comments