summaryrefslogtreecommitdiffstats
path: root/Lib/ConfigParser.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-09-27 15:49:56 (GMT)
committerFred Drake <fdrake@acm.org>2002-09-27 15:49:56 (GMT)
commit2ca041fde0e20077b1a2bdb33a54db4c3badf38a (patch)
tree8cd094ffbd1b8c5ff55c250011edcff7e422895f /Lib/ConfigParser.py
parent309db061af45c9f85d9fafcbb5f39a332486906e (diff)
downloadcpython-2ca041fde0e20077b1a2bdb33a54db4c3badf38a.zip
cpython-2ca041fde0e20077b1a2bdb33a54db4c3badf38a.tar.gz
cpython-2ca041fde0e20077b1a2bdb33a54db4c3badf38a.tar.bz2
items(): New method, provided by Gustavo Niemeyer in SF bug #545096.
Diffstat (limited to 'Lib/ConfigParser.py')
-rw-r--r--Lib/ConfigParser.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py
index 327f9ea..47243fb 100644
--- a/Lib/ConfigParser.py
+++ b/Lib/ConfigParser.py
@@ -70,6 +70,10 @@ ConfigParser -- responsible for for parsing a list of
insensitively defined as 0, false, no, off for 0, and 1, true,
yes, on for 1). Returns 0 or 1.
+ items(section, raw=0, vars=None)
+ return a list of tuples with (name, value) for each option
+ in the section.
+
remove_section(section)
remove the given file section and all its options
@@ -278,6 +282,35 @@ class ConfigParser:
return value
return self._interpolate(section, option, value, d)
+ def items(self, section, raw=0, vars=None):
+ """Return a list of tuples with (name, value) for each option
+ in the section.
+
+ 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.
+ """
+ d = self.__defaults.copy()
+ try:
+ d.update(self.__sections[section])
+ except KeyError:
+ if section != DEFAULTSECT:
+ raise NoSectionError(section)
+ # Update with the entry specific variables
+ if vars:
+ d.update(vars)
+ if raw:
+ for option in self.options(section):
+ yield (option, d[option])
+ else:
+ for option in self.options(section):
+ yield (option,
+ self._interpolate(section, option, d[option], d))
+
def _interpolate(self, section, option, rawval, vars):
# do the string interpolation
value = rawval