mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Issue #21159: Improve message in configparser.InterpolationMissingOptionError.
Patch from Łukasz Langa.
This commit is contained in:
parent
4ce4f974da
commit
ac37ba0742
3 changed files with 21 additions and 18 deletions
|
@ -241,12 +241,9 @@ class InterpolationMissingOptionError(InterpolationError):
|
|||
"""A string substitution required a setting which was not available."""
|
||||
|
||||
def __init__(self, option, section, rawval, reference):
|
||||
msg = ("Bad value substitution:\n"
|
||||
"\tsection: [%s]\n"
|
||||
"\toption : %s\n"
|
||||
"\tkey : %s\n"
|
||||
"\trawval : %s\n"
|
||||
% (section, option, reference, rawval))
|
||||
msg = ("Bad value substitution: option {!r} in section {!r} contains "
|
||||
"an interpolation key {!r} which is not a valid option name. "
|
||||
"Raw value: {!r}".format(option, section, reference, rawval))
|
||||
InterpolationError.__init__(self, option, section, msg)
|
||||
self.reference = reference
|
||||
self.args = (option, section, rawval, reference)
|
||||
|
@ -264,11 +261,11 @@ class InterpolationDepthError(InterpolationError):
|
|||
"""Raised when substitutions are nested too deeply."""
|
||||
|
||||
def __init__(self, option, section, rawval):
|
||||
msg = ("Value interpolation too deeply recursive:\n"
|
||||
"\tsection: [%s]\n"
|
||||
"\toption : %s\n"
|
||||
"\trawval : %s\n"
|
||||
% (section, option, rawval))
|
||||
msg = ("Recursion limit exceeded in value substitution: option {!r} "
|
||||
"in section {!r} contains an interpolation key which "
|
||||
"cannot be substituted in {} steps. Raw value: {!r}"
|
||||
"".format(option, section, MAX_INTERPOLATION_DEPTH,
|
||||
rawval))
|
||||
InterpolationError.__init__(self, option, section, msg)
|
||||
self.args = (option, section, rawval)
|
||||
|
||||
|
@ -384,8 +381,9 @@ class BasicInterpolation(Interpolation):
|
|||
|
||||
def _interpolate_some(self, parser, option, accum, rest, section, map,
|
||||
depth):
|
||||
rawval = parser.get(section, option, raw=True, fallback=rest)
|
||||
if depth > MAX_INTERPOLATION_DEPTH:
|
||||
raise InterpolationDepthError(option, section, rest)
|
||||
raise InterpolationDepthError(option, section, rawval)
|
||||
while rest:
|
||||
p = rest.find("%")
|
||||
if p < 0:
|
||||
|
@ -410,7 +408,7 @@ class BasicInterpolation(Interpolation):
|
|||
v = map[var]
|
||||
except KeyError:
|
||||
raise InterpolationMissingOptionError(
|
||||
option, section, rest, var)
|
||||
option, section, rawval, var)
|
||||
if "%" in v:
|
||||
self._interpolate_some(parser, option, accum, v,
|
||||
section, map, depth + 1)
|
||||
|
@ -444,8 +442,9 @@ class ExtendedInterpolation(Interpolation):
|
|||
|
||||
def _interpolate_some(self, parser, option, accum, rest, section, map,
|
||||
depth):
|
||||
rawval = parser.get(section, option, raw=True, fallback=rest)
|
||||
if depth > MAX_INTERPOLATION_DEPTH:
|
||||
raise InterpolationDepthError(option, section, rest)
|
||||
raise InterpolationDepthError(option, section, rawval)
|
||||
while rest:
|
||||
p = rest.find("$")
|
||||
if p < 0:
|
||||
|
@ -482,7 +481,7 @@ class ExtendedInterpolation(Interpolation):
|
|||
"More than one ':' found: %r" % (rest,))
|
||||
except (KeyError, NoSectionError, NoOptionError):
|
||||
raise InterpolationMissingOptionError(
|
||||
option, section, rest, ":".join(path))
|
||||
option, section, rawval, ":".join(path))
|
||||
if "$" in v:
|
||||
self._interpolate_some(parser, opt, accum, v, sect,
|
||||
dict(parser.items(sect, raw=True)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue