summaryrefslogtreecommitdiffstats
path: root/Lib/dos-8x3/configpa.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-02-09 18:40:13 (GMT)
committerGuido van Rossum <guido@python.org>1999-02-09 18:40:13 (GMT)
commit2e7840fe8fdb52b8d026017237593b445ebf9059 (patch)
treea7ee5115e9bdeb27b450c61b61aabe5c8144d491 /Lib/dos-8x3/configpa.py
parent01b7ced83452b733c4db004307292493c9dd6d73 (diff)
downloadcpython-2e7840fe8fdb52b8d026017237593b445ebf9059.zip
cpython-2e7840fe8fdb52b8d026017237593b445ebf9059.tar.gz
cpython-2e7840fe8fdb52b8d026017237593b445ebf9059.tar.bz2
The usual.
Diffstat (limited to 'Lib/dos-8x3/configpa.py')
-rw-r--r--Lib/dos-8x3/configpa.py72
1 files changed, 43 insertions, 29 deletions
diff --git a/Lib/dos-8x3/configpa.py b/Lib/dos-8x3/configpa.py
index 89e2d85..bc646e4 100644
--- a/Lib/dos-8x3/configpa.py
+++ b/Lib/dos-8x3/configpa.py
@@ -24,34 +24,37 @@ ConfigParser -- responsible for for parsing a list of
methods:
- __init__(defaults=None) -- create the parser and specify a
- dictionary of intrinsic defaults. The
- keys must be strings, the values must
- be appropriate for %()s string
- interpolation. Note that `__name__' is
- always an intrinsic default; it's value
- is the section's name.
+ __init__(defaults=None)
+ create the parser and specify a dictionary of intrinsic defaults. The
+ keys must be strings, the values must be appropriate for %()s string
+ interpolation. Note that `__name__' is always an intrinsic default;
+ it's value is the section's name.
- sections() -- return all the configuration section names, sans DEFAULT
+ sections()
+ return all the configuration section names, sans DEFAULT
- options(section) -- return list of configuration options for the named
- section
+ options(section)
+ return list of configuration options for the named section
- read(*filenames) -- read and parse the list of named configuration files
+ read(filenames)
+ read and parse the list of named configuration files
- get(section, option, raw=0) -- return a string value for the named
- option. All % interpolations are
- expanded in the return values, based on
- the defaults passed into the constructor
- and the DEFAULT section.
+ get(section, option, raw=0, vars=None)
+ return a string value for the named option. All % interpolations are
+ expanded in the return values, based on the defaults passed into the
+ constructor and the DEFAULT section. Additional substitutions may be
+ provided using the `vars' argument, which must be a dictionary whose
+ contents override any pre-existing defaults.
- getint(section, options) -- like get(), but convert value to an integer
+ getint(section, options)
+ like get(), but convert value to an integer
- getfloat(section, options) -- like get(), but convert value to a float
+ getfloat(section, options)
+ like get(), but convert value to a float
- getboolean(section, options) -- like get(), but convert value to
- a boolean (currently defined as 0
- or 1, only)
+ getboolean(section, options)
+ like get(), but convert value to a boolean (currently defined as 0 or
+ 1, only)
"""
import sys
@@ -173,12 +176,14 @@ class ConfigParser:
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.
+ All % interpolations are expanded in the return values, based on the
+ defaults passed into the constructor, unless the optional argument
+ `raw' is true. Additional substitutions may be provided using the
+ `vars' argument, which must be a dictionary whose contents overrides
+ any pre-existing defaults.
The section DEFAULT is special.
"""
@@ -191,6 +196,9 @@ class ConfigParser:
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 +207,17 @@ class ConfigParser:
# 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))