@@ -241,12 +241,9 @@ class InterpolationMissingOptionError(InterpolationError):
241241 """A string substitution required a setting which was not available."""
242242
243243 def __init__ (self , option , section , rawval , reference ):
244- msg = ("Bad value substitution:\n "
245- "\t section: [%s]\n "
246- "\t option : %s\n "
247- "\t key : %s\n "
248- "\t rawval : %s\n "
249- % (section , option , reference , rawval ))
244+ msg = ("Bad value substitution: option {!r} in section {!r} contains "
245+ "an interpolation key {!r} which is not a valid option name. "
246+ "Raw value: {!r}" .format (option , section , reference , rawval ))
250247 InterpolationError .__init__ (self , option , section , msg )
251248 self .reference = reference
252249 self .args = (option , section , rawval , reference )
@@ -264,11 +261,11 @@ class InterpolationDepthError(InterpolationError):
264261 """Raised when substitutions are nested too deeply."""
265262
266263 def __init__ (self , option , section , rawval ):
267- msg = ("Value interpolation too deeply recursive: \n "
268- "\t section: [%s] \n "
269- "\t option : %s \n "
270- "\t rawval : %s \n "
271- % ( section , option , rawval ))
264+ msg = ("Recursion limit exceeded in value substitution: option {!r} "
265+ "in section {!r} contains an interpolation key which "
266+ "cannot be substituted in {} steps. Raw value: {!r} "
267+ "" . format ( option , section , MAX_INTERPOLATION_DEPTH ,
268+ rawval ))
272269 InterpolationError .__init__ (self , option , section , msg )
273270 self .args = (option , section , rawval )
274271
@@ -384,8 +381,9 @@ def before_set(self, parser, section, option, value):
384381
385382 def _interpolate_some (self , parser , option , accum , rest , section , map ,
386383 depth ):
384+ rawval = parser .get (section , option , raw = True , fallback = rest )
387385 if depth > MAX_INTERPOLATION_DEPTH :
388- raise InterpolationDepthError (option , section , rest )
386+ raise InterpolationDepthError (option , section , rawval )
389387 while rest :
390388 p = rest .find ("%" )
391389 if p < 0 :
@@ -410,7 +408,7 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
410408 v = map [var ]
411409 except KeyError :
412410 raise InterpolationMissingOptionError (
413- option , section , rest , var )
411+ option , section , rawval , var )
414412 if "%" in v :
415413 self ._interpolate_some (parser , option , accum , v ,
416414 section , map , depth + 1 )
@@ -444,8 +442,9 @@ def before_set(self, parser, section, option, value):
444442
445443 def _interpolate_some (self , parser , option , accum , rest , section , map ,
446444 depth ):
445+ rawval = parser .get (section , option , raw = True , fallback = rest )
447446 if depth > MAX_INTERPOLATION_DEPTH :
448- raise InterpolationDepthError (option , section , rest )
447+ raise InterpolationDepthError (option , section , rawval )
449448 while rest :
450449 p = rest .find ("$" )
451450 if p < 0 :
@@ -482,7 +481,7 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
482481 "More than one ':' found: %r" % (rest ,))
483482 except (KeyError , NoSectionError , NoOptionError ):
484483 raise InterpolationMissingOptionError (
485- option , section , rest , ":" .join (path ))
484+ option , section , rawval , ":" .join (path ))
486485 if "$" in v :
487486 self ._interpolate_some (parser , opt , accum , v , sect ,
488487 dict (parser .items (sect , raw = True )),
0 commit comments