mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
ConfigParser:
- ensure that option names in interpolations are handled by self.optionxform in the same way that other references to option names - add tests, documentation (closes SF bug #857881, patch #865455)
This commit is contained in:
parent
beddfcb6d0
commit
bc12b01d83
3 changed files with 24 additions and 5 deletions
|
@ -555,6 +555,7 @@ class ConfigParser(RawConfigParser):
|
|||
while depth: # Loop through this until it's done
|
||||
depth -= 1
|
||||
if "%(" in value:
|
||||
value = self._KEYCRE.sub(self._interpolation_replace, value)
|
||||
try:
|
||||
value = value % vars
|
||||
except KeyError, e:
|
||||
|
@ -566,6 +567,15 @@ class ConfigParser(RawConfigParser):
|
|||
raise InterpolationDepthError(option, section, rawval)
|
||||
return value
|
||||
|
||||
_KEYCRE = re.compile(r"%\(([^)]*)\)s|.")
|
||||
|
||||
def _interpolation_replace(self, match):
|
||||
s = match.group(1)
|
||||
if s is None:
|
||||
return match.group()
|
||||
else:
|
||||
return "%%(%s)s" % self.optionxform(s)
|
||||
|
||||
|
||||
class SafeConfigParser(ConfigParser):
|
||||
|
||||
|
@ -598,7 +608,7 @@ class SafeConfigParser(ConfigParser):
|
|||
if m is None:
|
||||
raise InterpolationSyntaxError(option, section,
|
||||
"bad interpolation variable reference %r" % rest)
|
||||
var = m.group(1)
|
||||
var = self.optionxform(m.group(1))
|
||||
rest = rest[m.end():]
|
||||
try:
|
||||
v = map[var]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue