<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=ConfParser.py</id>
	<title>ConfParser.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=ConfParser.py"/>
	<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=ConfParser.py&amp;action=history"/>
	<updated>2026-05-20T21:40:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://performiq.com/kb/index.php?title=ConfParser.py&amp;diff=3091&amp;oldid=prev</id>
		<title>PeterHarding at 06:05, 19 July 2009</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=ConfParser.py&amp;diff=3091&amp;oldid=prev"/>
		<updated>2009-07-19T06:05:58Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:05, 19 July 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l447&quot;&gt;Line 447:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 447:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Python]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Python]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Examples]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=ConfParser.py&amp;diff=2147&amp;oldid=prev</id>
		<title>PeterHarding: New page: &lt;pre&gt; #!/usr/bin/python &#039;&#039;&#039;Configuration file parser for files similar to MS-Windows .ini files. Meant as a replacement for the broken ConfigParser module in the Python standard library.  ...</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=ConfParser.py&amp;diff=2147&amp;oldid=prev"/>
		<updated>2008-05-24T07:04:41Z</updated>

		<summary type="html">&lt;p&gt;New page: &amp;lt;pre&amp;gt; #!/usr/bin/python &amp;#039;&amp;#039;&amp;#039;Configuration file parser for files similar to MS-Windows .ini files. Meant as a replacement for the broken ConfigParser module in the Python standard library.  ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Configuration file parser for files similar to MS-Windows .ini files.&lt;br /&gt;
Meant as a replacement for the broken ConfigParser module in the Python&lt;br /&gt;
standard library.&lt;br /&gt;
&lt;br /&gt;
Copyright (C) 2000 Charles Cazabon &amp;lt;getmail @ discworld.dyndns.org&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This program is free software; you can redistribute it and/or&lt;br /&gt;
modify it under the terms of version 2 of the GNU General Public License&lt;br /&gt;
as published by the Free Software Foundation.  A copy of this license should&lt;br /&gt;
be included in the file COPYING.&lt;br /&gt;
&lt;br /&gt;
This program is distributed in the hope that it will be useful,&lt;br /&gt;
but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
You should have received a copy of the GNU General Public License&lt;br /&gt;
along with this program; if not, write to the Free Software&lt;br /&gt;
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.&lt;br /&gt;
&lt;br /&gt;
For documentation, see the Python standard module ConfigParser documentation.&lt;br /&gt;
This module is similar, except:&lt;br /&gt;
    o Options are supplied with option_name=option_value pairs only (not &amp;#039;:&amp;#039;).&lt;br /&gt;
    o Comments are allowed on the same lines as data, with &amp;#039;#&amp;#039; as the comment&lt;br /&gt;
        delimiter.&lt;br /&gt;
    o Leading and trailing whitespace is ignored.&lt;br /&gt;
    o Whitespace surrounding the &amp;#039;=&amp;#039; sign is ignored.&lt;br /&gt;
    o Option values can be quoted with single or double quotes, to preserve&lt;br /&gt;
        leading or trailing whitespace, or if they contain a whitespace or the &lt;br /&gt;
        &amp;quot;#&amp;quot; symbol which would otherwise mark the start of a comment.&lt;br /&gt;
    o Empty option values must be quoted; use the empty string (&amp;quot;&amp;quot; or &amp;#039;&amp;#039;)&lt;br /&gt;
    o Option values are returned as either:&lt;br /&gt;
        o a string, if the option name occurs once in the section&lt;br /&gt;
        o a list of strings, if the option name occurs multiple times&lt;br /&gt;
    o All the limitations on what characters can be in section headers and&lt;br /&gt;
        option values are gone, except that &amp;#039;#&amp;#039; is forbidden (because it&lt;br /&gt;
        starts a comment), and option names cannot contain &amp;#039;=&amp;#039; (because that&lt;br /&gt;
        starts a value).&lt;br /&gt;
&lt;br /&gt;
I welcome questions and comments at &amp;lt;software @ discworld.dyndns.org&amp;gt;.&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
__version__ = &amp;#039;3.1&amp;#039;&lt;br /&gt;
__author__ = &amp;#039;Charles Cazabon &amp;lt;software @ discworld.dyndns.org&amp;gt;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Imports&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
import string&lt;br /&gt;
import UserDict&lt;br /&gt;
import sys&lt;br /&gt;
import shlex&lt;br /&gt;
import cStringIO&lt;br /&gt;
from types import *&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# ConfParser exception classes&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Base class for all ConfParser exceptions&lt;br /&gt;
class ConfParserException (Exception):&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
# Specific exceptions&lt;br /&gt;
class NoSectionError (ConfParserException):&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;Exception raised when a specified section is not found.&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
class DuplicateSectionError (ConfParserException):&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;Exception raised when mutliple sections with the same name are found, or &lt;br /&gt;
    if add_section() is called with the name of a section that is already &lt;br /&gt;
    present.&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
class NoOptionError (ConfParserException):&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;Exception raised when a specified option is not found in the specified &lt;br /&gt;
    section.&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
class InterpolationError (ConfParserException):&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;Exception raised when problems occur performing string interpolation.&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
     pass&lt;br /&gt;
&lt;br /&gt;
class MissingSectionHeaderError (ConfParserException):&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;Exception raised when attempting to parse a file which has no section&lt;br /&gt;
    headers.&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
class ParsingError (ConfParserException):&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;Exception raised when errors occur attempting to parse a file.&lt;br /&gt;
    Also raised if defaults is not a dictionary, or when reading a file fails.&lt;br /&gt;
    These errors are not covered by exceptions in the standard Python&lt;br /&gt;
    ConfigParser module.&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Globals&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
debug = 0&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Helper functions&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
#######################################&lt;br /&gt;
def log (msg):&lt;br /&gt;
    if not debug:  return&lt;br /&gt;
    sys.stderr.write (msg + &amp;#039;\n&amp;#039;)&lt;br /&gt;
    sys.stderr.flush ()&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# ConfParser SmartDict class&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
#######################################&lt;br /&gt;
class SmartDict (UserDict.UserDict):&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;Dictionary class which handles lists and singletons intelligently.&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    #######################################&lt;br /&gt;
    def __init__ (self, initialdata = {}):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Constructor.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        UserDict.UserDict.__init__ (self, {})&lt;br /&gt;
        for (key, value) in initialdata.items ():&lt;br /&gt;
            self.__setitem (key, value)&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def __getitem__ (self, key):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        try:&lt;br /&gt;
            value = self.data[key]&lt;br /&gt;
            if len (value) == 1:&lt;br /&gt;
                return value[0]&lt;br /&gt;
            return value&lt;br /&gt;
        except KeyError, txt:&lt;br /&gt;
            raise KeyError, txt&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def __setitem__ (self, key, value):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        if type (value) in (ListType, TupleType):&lt;br /&gt;
            self.data[key] = list (value)&lt;br /&gt;
        else:&lt;br /&gt;
            self.data[key] = [value]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Main ConfParser class&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
#######################################&lt;br /&gt;
class ConfParser:&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;Class to parse a configuration file without all the limitations in&lt;br /&gt;
    ConfigParser.py, but without the dictionary formatting options either.&lt;br /&gt;
    &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    #######################################&lt;br /&gt;
    def __init__ (self, defaults = {}):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Constructor.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        self.__rawdata = []&lt;br /&gt;
        self.__sectionlist = []&lt;br /&gt;
        self.__sections = []&lt;br /&gt;
        self.__defaults = SmartDict ()&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
            for key in defaults.keys ():&lt;br /&gt;
                self.__defaults[key] = defaults[key]&lt;br /&gt;
&lt;br /&gt;
        except AttributeError:&lt;br /&gt;
            raise ParsingError, &amp;#039;defaults not a dictionary (%s)&amp;#039; % defaults&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def read (self, filelist):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Read configuration file(s) from list of 1 or more filenames.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        if type (filelist) not in (ListType, TupleType):&lt;br /&gt;
            filelist = [filelist]&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
            for filename in filelist:&lt;br /&gt;
                log (&amp;#039;Reading configuration file &amp;quot;%s&amp;quot;&amp;#039; % filename)&lt;br /&gt;
                f = open (filename, &amp;#039;r&amp;#039;)&lt;br /&gt;
                self.__rawdata = self.__rawdata + f.readlines ()&lt;br /&gt;
                f.close ()&lt;br /&gt;
    &lt;br /&gt;
        except IOError, txt:&lt;br /&gt;
            raise ParsingError, &amp;#039;error reading configuration file (%s)&amp;#039; % txt&lt;br /&gt;
&lt;br /&gt;
        self.__parse ()&lt;br /&gt;
        return self&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def __parse (self):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Parse the read-in configuration file.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        config = string.join (self.__rawdata, &amp;#039;\n&amp;#039;)&lt;br /&gt;
        f = cStringIO.StringIO (config)&lt;br /&gt;
        lex = shlex.shlex (f)&lt;br /&gt;
        lex.wordchars = lex.wordchars + &amp;#039;|/.,$^\\():;@-+?&amp;lt;&amp;gt;!%&amp;amp;*`~&amp;#039;&lt;br /&gt;
        section_name = &amp;#039;&amp;#039;&lt;br /&gt;
        option_name = &amp;#039;&amp;#039;&lt;br /&gt;
        option_value = &amp;#039;&amp;#039;&lt;br /&gt;
        &lt;br /&gt;
        while 1:&lt;br /&gt;
            token = lex.get_token ()&lt;br /&gt;
            if token == &amp;#039;&amp;#039;:&lt;br /&gt;
                break&lt;br /&gt;
&lt;br /&gt;
            if not (section_name):&lt;br /&gt;
                if token != &amp;#039;[&amp;#039;:&lt;br /&gt;
                    raise ParsingError, &amp;#039;expected section start, got %s&amp;#039; % token&lt;br /&gt;
                section_name = &amp;#039;&amp;#039;&lt;br /&gt;
                while 1:&lt;br /&gt;
                    token = lex.get_token ()&lt;br /&gt;
                    if token == &amp;#039;]&amp;#039;:&lt;br /&gt;
                        break&lt;br /&gt;
                    if token == &amp;#039;&amp;#039;:&lt;br /&gt;
                        raise ParsingError, &amp;#039;expected section end, hit EOF&amp;#039;&lt;br /&gt;
                    if section_name:&lt;br /&gt;
                        section_name = section_name + &amp;#039; &amp;#039;&lt;br /&gt;
                    section_name = section_name + token&lt;br /&gt;
                if not section_name:&lt;br /&gt;
                    raise ParsingError, &amp;#039;expected section name, got nothing&amp;#039;&lt;br /&gt;
&lt;br /&gt;
                section = SmartDict ()&lt;br /&gt;
                # Collapse case on section names&lt;br /&gt;
                section_name = string.lower (section_name)&lt;br /&gt;
                if section_name in self.__sectionlist:&lt;br /&gt;
                    raise DuplicateSectionError, \&lt;br /&gt;
                        &amp;#039;duplicate section (%s)&amp;#039; % section_name&lt;br /&gt;
                section[&amp;#039;__name__&amp;#039;] = section_name&lt;br /&gt;
                continue&lt;br /&gt;
&lt;br /&gt;
            if token == &amp;#039;=&amp;#039;:&lt;br /&gt;
                raise ParsingError, &amp;#039;expected option name, got =&amp;#039;&lt;br /&gt;
&lt;br /&gt;
            if token == &amp;#039;[&amp;#039;:&lt;br /&gt;
                # Start new section&lt;br /&gt;
                lex.push_token (token)&lt;br /&gt;
                if section_name in self.__sectionlist:&lt;br /&gt;
                    raise DuplicateSectionError, \&lt;br /&gt;
                        &amp;#039;duplicate section (%s)&amp;#039; % section_name&lt;br /&gt;
                if section[&amp;#039;__name__&amp;#039;] == &amp;#039;default&amp;#039;:&lt;br /&gt;
                    self.__defaults.update (section)&lt;br /&gt;
                self.__sectionlist.append (section_name)&lt;br /&gt;
                self.__sections.append (section.copy ())&lt;br /&gt;
                section_name = &amp;#039;&amp;#039;&lt;br /&gt;
                continue&lt;br /&gt;
&lt;br /&gt;
            if not option_name:&lt;br /&gt;
                option_name = token&lt;br /&gt;
                token = lex.get_token ()&lt;br /&gt;
                if token != &amp;#039;=&amp;#039;:&lt;br /&gt;
                    raise ParsingError, &amp;#039;Expected =, got %s&amp;#039; % token&lt;br /&gt;
&lt;br /&gt;
                token = lex.get_token ()&lt;br /&gt;
                if token in (&amp;#039;[&amp;#039;, &amp;#039;=&amp;#039;):&lt;br /&gt;
                    raise ParsingError, &amp;#039;expected option value, got %s&amp;#039; % token&lt;br /&gt;
                option_value = token&lt;br /&gt;
&lt;br /&gt;
                if option_value[0] in (&amp;#039;&amp;quot;&amp;#039;, &amp;quot;&amp;#039;&amp;quot;) and option_value[0] == option_value[-1]:&lt;br /&gt;
                    option_value = option_value[1:-1]&lt;br /&gt;
                                  &lt;br /&gt;
                if section.has_key (option_name):&lt;br /&gt;
                    if type (section[option_name]) == ListType:&lt;br /&gt;
                        section[option_name].append (option_value)&lt;br /&gt;
                    else:&lt;br /&gt;
                        section[option_name] = [section[option_name], option_value]&lt;br /&gt;
                else:&lt;br /&gt;
                    section[option_name] = option_value&lt;br /&gt;
                &lt;br /&gt;
                option_name = &amp;#039;&amp;#039;&lt;br /&gt;
                &lt;br /&gt;
        # Done parsing        &lt;br /&gt;
        if section_name:&lt;br /&gt;
            if section_name in self.__sectionlist:&lt;br /&gt;
                raise DuplicateSectionError, \&lt;br /&gt;
                    &amp;#039;duplicate section (%s)&amp;#039; % section_name&lt;br /&gt;
            if section[&amp;#039;__name__&amp;#039;] == &amp;#039;default&amp;#039;:&lt;br /&gt;
                self.__defaults.update (section)&lt;br /&gt;
            self.__sectionlist.append (section_name)&lt;br /&gt;
            self.__sections.append (section.copy ())&lt;br /&gt;
        &lt;br /&gt;
        if not self.__sectionlist:&lt;br /&gt;
            raise MissingSectionHeaderError, &amp;#039;no section headers in file&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def defaults (self):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Return a dictionary containing the passed-in instance-wide defaults.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        return self.__defaults.copy ()&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def has_section (self, section):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Indicates whether the named section is present in the configuration. &lt;br /&gt;
        The default section is not acknowledged.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        section = string.lower (section)&lt;br /&gt;
        if section not in self.sections ():&lt;br /&gt;
            return 0&lt;br /&gt;
        return 1&lt;br /&gt;
        &lt;br /&gt;
    #######################################&lt;br /&gt;
    def sections (self):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Return a list of sections in the configuration file.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        s = self.__sectionlist[:]&lt;br /&gt;
        try:&lt;br /&gt;
            # Remove &amp;#039;default&amp;#039; section from returned list&lt;br /&gt;
            i = s.index (&amp;#039;default&amp;#039;)&lt;br /&gt;
            del s[i]&lt;br /&gt;
        except ValueError:&lt;br /&gt;
            # No default section&lt;br /&gt;
            pass&lt;br /&gt;
        &lt;br /&gt;
        return s&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def options (self, section):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Return list of options in section.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        try:&lt;br /&gt;
            s = self.__sectionlist.index (string.lower (section))&lt;br /&gt;
&lt;br /&gt;
        except ValueError:&lt;br /&gt;
            raise NoSectionError, &amp;#039;missing section:  &amp;quot;%s&amp;quot;&amp;#039; % section&lt;br /&gt;
&lt;br /&gt;
        return self.__sections[s].keys ()&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def get (self, section, option, raw=0, _vars={}):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Get an option value for the provided section. All the &amp;quot;%&amp;quot; &lt;br /&gt;
        interpolations are expanded in the return values, based on the defaults &lt;br /&gt;
        passed into the constructor, as well as the options _vars provided, &lt;br /&gt;
        unless the raw argument is true.  __vars contents must be lists.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
            s = self.__sectionlist.index (string.lower (section))&lt;br /&gt;
            options = self.__sections[s]&lt;br /&gt;
        except ValueError:&lt;br /&gt;
            raise NoSectionError, &amp;#039;missing section (%s)&amp;#039; % section&lt;br /&gt;
&lt;br /&gt;
        expand = self.__defaults.copy ()&lt;br /&gt;
        expand.update (_vars)&lt;br /&gt;
        &lt;br /&gt;
        if not options.has_key (option):&lt;br /&gt;
            if expand.has_key (option):&lt;br /&gt;
                return expand[option]&lt;br /&gt;
            raise NoOptionError, &amp;#039;section [%s] missing option (%s)&amp;#039; \&lt;br /&gt;
                % (section, option)&lt;br /&gt;
&lt;br /&gt;
        rawval = options[option]&lt;br /&gt;
        &lt;br /&gt;
        if raw:&lt;br /&gt;
            return rawval&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
            value = []&lt;br /&gt;
            if type (rawval) != ListType:&lt;br /&gt;
                rawval = [rawval]&lt;br /&gt;
            for part in rawval:&lt;br /&gt;
                try:&lt;br /&gt;
                    part = part % expand&lt;br /&gt;
                except:&lt;br /&gt;
                    raise&lt;br /&gt;
                value.append (part)&lt;br /&gt;
            if len (value) == 1:&lt;br /&gt;
                return value[0]&lt;br /&gt;
            return value                &lt;br /&gt;
        except KeyError, txt:&lt;br /&gt;
            raise NoOptionError, &amp;#039;section [%s] missing option (%s)&amp;#039; \&lt;br /&gt;
                % (section, option)&lt;br /&gt;
        except TypeError, txt:&lt;br /&gt;
            raise InterpolationError, &amp;#039;invalid conversion or specification&amp;#039; \&lt;br /&gt;
                &amp;#039; for option %s (%s (%s))&amp;#039; % (option, rawval, txt)&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def getint (self, section, option):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;A convenience method which coerces the option in the specified&lt;br /&gt;
        section to an integer.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        val = self.get (section, option)&lt;br /&gt;
        try:&lt;br /&gt;
            return int (val)&lt;br /&gt;
        except ValueError:&lt;br /&gt;
            raise InterpolationError, &amp;#039;option %s not an integer (%s)&amp;#039; \&lt;br /&gt;
                % (option, val)&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def getfloat (self, section, option):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;A convenience method which coerces the option in the specified&lt;br /&gt;
        section to a floating point number.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        val = self.get (section, option)&lt;br /&gt;
        try:&lt;br /&gt;
            return float (val)&lt;br /&gt;
        except ValueError:&lt;br /&gt;
            raise InterpolationError, &amp;#039;option %s not a float (%s)&amp;#039; \&lt;br /&gt;
                % (option, val)&lt;br /&gt;
&lt;br /&gt;
    #######################################&lt;br /&gt;
    def getboolean (self, section, option):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;A convenience method which coerces the option in the specified&lt;br /&gt;
        section to a boolean value. Note that the only accepted values for the&lt;br /&gt;
        option are &amp;quot;0&amp;quot; and &amp;quot;1&amp;quot;, any others will raise ValueError.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        val = self.getint (section, option)&lt;br /&gt;
        return val != 0     &lt;br /&gt;
        &lt;br /&gt;
    #######################################&lt;br /&gt;
    def dump (self):&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;Dump the parsed contents of the configuration file.&lt;br /&gt;
        &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
        sys.stderr.write (&amp;#039;ConfParser dump:\n\n&amp;#039;)&lt;br /&gt;
        sections = self.__sectionlist[:]&lt;br /&gt;
        sections.sort ()&lt;br /&gt;
        for section in sections:&lt;br /&gt;
            sys.stderr.write (&amp;#039;  Section [%s]:\n&amp;#039; % section)&lt;br /&gt;
            options = self.options (section)&lt;br /&gt;
            options.sort ()&lt;br /&gt;
            for option in options:&lt;br /&gt;
                values = self.get (section, option)&lt;br /&gt;
                if type (values) == ListType:&lt;br /&gt;
                    sys.stderr.write (&amp;#039;    %s:\n&amp;#039; % option)&lt;br /&gt;
                    for value in values:&lt;br /&gt;
                        sys.stderr.write (&amp;#039;         %s\n&amp;#039; % value)&lt;br /&gt;
                else:&lt;br /&gt;
                    sys.stderr.write (&amp;#039;    %s:  %s\n&amp;#039; % (option, values))&lt;br /&gt;
            sys.stderr.write (&amp;#039;\n&amp;#039;)&lt;br /&gt;
            &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
</feed>