summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-10-04 19:58:22 (GMT)
committerGuido van Rossum <guido@python.org>1999-10-04 19:58:22 (GMT)
commita5a24b76f494c2e5a83c08061a471963e3e297a9 (patch)
treee6c9caf944411245eea6b0e6565bd596443955af
parent6a8d84b0c1508d0a3f10f716f3faf3863b41f758 (diff)
downloadcpython-a5a24b76f494c2e5a83c08061a471963e3e297a9.zip
cpython-a5a24b76f494c2e5a83c08061a471963e3e297a9.tar.gz
cpython-a5a24b76f494c2e5a83c08061a471963e3e297a9.tar.bz2
Added has_option(); fix bug in get() which botched interpolation if
'%(' was found in first position (found by Fred Drake).
-rw-r--r--Lib/ConfigParser.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py
index b0475a3..03f4c6b 100644
--- a/Lib/ConfigParser.py
+++ b/Lib/ConfigParser.py
@@ -33,9 +33,15 @@ ConfigParser -- responsible for for parsing a list of
sections()
return all the configuration section names, sans DEFAULT
+ has_section(section)
+ return whether the given section exists
+
options(section)
return list of configuration options for the named section
+ has_option(section, option)
+ return whether the given section has the given option
+
read(filenames)
read and parse the list of named configuration files, given by
name. A single filename is also allowed. Non-existing files
@@ -165,6 +171,7 @@ class ConfigParser:
return self.__sections.has_key(section)
def options(self, section):
+ """Return a list of option names for the given section name."""
try:
opts = self.__sections[section].copy()
except KeyError:
@@ -172,6 +179,14 @@ class ConfigParser:
opts.update(self.__defaults)
return opts.keys()
+ def has_option(self, section, option):
+ """Return whether the given section has the given option."""
+ try:
+ opts = self.__sections[section]
+ except KeyError:
+ raise NoSectionError(section)
+ return opts.has_key(option)
+
def read(self, filenames):
"""Read and parse a filename or a list of filenames.
@@ -245,7 +260,7 @@ class ConfigParser:
depth = 0
while depth < 10: # Loop through this until it's done
depth = depth + 1
- if not string.find(value, "%("):
+ if string.find(value, "%(") >= 0:
try:
value = value % d
except KeyError, key: