summaryrefslogtreecommitdiffstats
path: root/Lib/configparser.py
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-08-13 23:47:41 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-08-13 23:47:41 (GMT)
commitf7a92673ab38f43c1d274e1663f62da394f4f153 (patch)
treecf25f632ec399556bf31bb10be43385bbcc4bee1 /Lib/configparser.py
parent5e8d47f6ab98f607e2df7b4ad27964eec70429a4 (diff)
parentac37ba0742b1eb794eca7b6fd95a1ffecc9b6333 (diff)
downloadcpython-f7a92673ab38f43c1d274e1663f62da394f4f153.zip
cpython-f7a92673ab38f43c1d274e1663f62da394f4f153.tar.gz
cpython-f7a92673ab38f43c1d274e1663f62da394f4f153.tar.bz2
Issue #21159: Improve message in configparser.InterpolationMissingOptionError.
Patch from Ɓukasz Langa.
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r--Lib/configparser.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py
index ecd0660..3a9fb56 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -263,12 +263,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)
@@ -286,11 +283,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)
@@ -406,8 +403,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:
@@ -432,7 +430,7 @@ class BasicInterpolation(Interpolation):
v = map[var]
except KeyError:
raise InterpolationMissingOptionError(
- option, section, rest, var) from None
+ option, section, rawval, var) from None
if "%" in v:
self._interpolate_some(parser, option, accum, v,
section, map, depth + 1)
@@ -466,8 +464,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:
@@ -504,7 +503,7 @@ class ExtendedInterpolation(Interpolation):
"More than one ':' found: %r" % (rest,))
except (KeyError, NoSectionError, NoOptionError):
raise InterpolationMissingOptionError(
- option, section, rest, ":".join(path)) from None
+ option, section, rawval, ":".join(path)) from None
if "$" in v:
self._interpolate_some(parser, opt, accum, v, sect,
dict(parser.items(sect, raw=True)),