]> granicus.if.org Git - python/commitdiff
Added has_option(); fix bug in get() which botched interpolation if
authorGuido van Rossum <guido@python.org>
Mon, 4 Oct 1999 19:58:22 +0000 (19:58 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 4 Oct 1999 19:58:22 +0000 (19:58 +0000)
'%(' was found in first position (found by Fred Drake).

Lib/ConfigParser.py

index b0475a37d5658c14cdc6e8c4e89fc2e8f6cdefbf..03f4c6b82fe56c6a2634b08fedbdaafef607d8a0 100644 (file)
@@ -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: