appropriate for the \samp{\%()s} string interpolation. Note that
\var{__name__} is an intrinsic default; its value is the section name,
and will override any value provided in \var{defaults}.
+
+All option names used in interpolation will be passed through the
+\method{optionxform()} method just like any other option name
+reference. For example, using the default implementation of
+\method{optionxform()} (which converts option names to lower case),
+the values \samp{foo \%(bar)s} and \samp{foo \%(BAR)s} are
+equivalent.
\end{classdesc}
\begin{classdesc}{SafeConfigParser}{\optional{defaults}}
The \class{ConfigParser} class extends some methods of the
\class{RawConfigParser} interface, adding some optional arguments.
+The \class{SafeConfigParser} class implements the same extended
+interface.
\begin{methoddesc}{get}{section, option\optional{, raw\optional{, vars}}}
Get an \var{option} value for the named \var{section}. All the
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:
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):
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]