Mercurial > cpython-lru_cache-weakref
diff Lib/ConfigParser.py @ 9959:572e131ae369 legacy-trunk
Patch by Chris Petrilli (not really tested since I don't know this
module myself) to accept an option keyword argument (vars) that is
substituted on top of the defaults that were setup in __init__. The
patch also fixes the problem where you can't have recusive references
inside your configuration file.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 26 Jan 1999 19:29:25 +0000 |
| parents | bbe9d72bccda |
| children | 879e3491b661 |
line wrap: on
line diff
--- a/Lib/ConfigParser.py Tue Jan 26 19:23:09 1999 +0000 +++ b/Lib/ConfigParser.py Tue Jan 26 19:29:25 1999 +0000 @@ -173,12 +173,14 @@ except IOError: pass - def get(self, section, option, raw=0): + def get(self, section, option, raw=0, vars=None): """Get an option value for a given section. All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional - argument `raw' is true. + argument `raw' is true. Additional substitutions may be provided + using the vars keyword argument, which override any pre-existing + defaults. The section DEFAULT is special. """ @@ -191,6 +193,9 @@ raise NoSectionError(section) d = self.__defaults.copy() d.update(sectdict) + # Update with the entry specific variables + if vars: + d.update(vars) option = string.lower(option) try: rawval = d[option] @@ -199,11 +204,17 @@ # do the string interpolation if raw: return rawval - try: - return rawval % d - except KeyError, key: - raise InterpolationError(key, option, section, rawval) + value = rawval # Make it a pretty variable name + while 1: # Loop through this until it's done + if not string.find(value, "%("): + try: + value = value % d + except KeyError, key: + raise InterpolationError(key, option, section, rawval) + else: + return value + def __get(self, section, conv, option): return conv(self.get(section, option))
