def _interpolate_some(self, option, accum, rest, section, map, depth):
     rawval = self.get(section, option, raw=True, fallback=rest)
     if depth > MAX_INTERPOLATION_DEPTH:
         raise InterpolationDepthError(option, section, rawval)
     while rest:
         p = rest.find("$")
         if p < 0:
             accum.append(rest)
             return
         if p > 0:
             accum.append(rest[:p])
             rest = rest[p:]
         # p is no longer used
         c = rest[1:2]
         if c == "$":
             accum.append("$")
             rest = rest[2:]
         elif c == "{":
             m = self._KEYCRE.match(rest)
             if m is None:
                 raise InterpolationSyntaxError(
                     option, section,
                     "bad interpolation variable reference %r" % rest)
             path = m.group(1).split(':')
             rest = rest[m.end():]
             sect = section
             opt = option
             try:
                 if len(path) == 1:
                     opt = self.optionxform(path[0])
                     v = map[opt]
                 elif len(path) == 2:
                     sect = path[0]
                     opt = self.optionxform(path[1])
                     v = self.get(sect, opt, raw=True)
                 else:
                     raise InterpolationSyntaxError(
                         option, section,
                         "More that one ':' found: %r" % (rest, ))
             except (KeyError, NoSectionError, NoOptionError):
                 raise InterpolationMissingOptionError(
                     option, section, rawval, ":".join(path))
             if "$" in v:
                 self._interpolate_some(opt, accum, v, sect,
                                        dict(self.items(sect, raw=True)),
                                        depth + 1)
             else:
                 accum.append(v)
         else:
             raise InterpolationSyntaxError(
                 option, section, "'$' must be followed by '$' or '{', "
                 "found: %r" % (rest, ))
Exemple #2
0
 def _interpolate_some(self, option, accum, rest, section, map, depth):
     if depth > MAX_INTERPOLATION_DEPTH:
         raise InterpolationDepthError(option, section, rest)
     while rest:
         p = rest.find("%")
         if p < 0:
             accum.append(rest)
             return
         if p > 0:
             accum.append(rest[:p])
             rest = rest[p:]
         # p is no longer used
         c = rest[1:2]
         if c == "%":
             accum.append("%")
             rest = rest[2:]
         elif c == "(":
             m = self._interpvar_match(rest)
             if m is None:
                 raise InterpolationSyntaxError(
                     option, section,
                     "bad interpolation variable reference %r" % rest)
             var = m.group(1)
             rest = rest[m.end():]
             try:
                 v = map[var]
             except KeyError:
                 raise InterpolationMissingOptionError(
                     option, section, rest, var)
             if "%" in v:
                 self._interpolate_some(option, accum, v, section, map,
                                        depth + 1)
             else:
                 accum.append(v)
         else:
             raise InterpolationSyntaxError(
                 option, section,
                 "'%' must be followed by '%' or '(', found: " + repr(rest))