blob: 7f09581dc0187c846484015cd49e7536094f6cd7 [file] [log] [blame]
Fred Drakebc866ce1999-01-26 15:47:59 +00001\section{\module{ConfigParser} ---
2 Configuration file parser.}
3
4\declaremodule{standard}{ConfigParser}
5
6\modulesynopsis{Configuration file parser.}
7\sectionauthor{Christopher G. Petrilli}{petrilli@amber.org}
8
9This module defines the class \class{ConfigParser}. The
10\class{ConfigParser} class implements a basic configuration file
11parser language which provides a structure similar to what you would
12find on Microsoft Windows INI files. You can use this to write Python
13programs which can be customized by end users easily.
14
15The configuration file consists of sections, lead by a
16\samp{[section]} header and followed by \samp{name: value} entries,
17with continuations in the style of \rfc{959}. The optional values
18can contain format strings which refer to other values in the same
19section, or values in a special \code{DEFAULT} section. Additional
20defaults can provided upon instantiation of the class.
21
22For example:
23
24\begin{verbatim}
25foodir: %(dir)s/whatever
26\end{verbatim}
27
28would resolve the \samp{\%(dir)s} to the value of dir. All reference
29expansions are done late, on demand.
30
31Intrinsic defaults can be specified by passing them into the
32\class{ConfigParser} constructor as a dictionary.
33
34\begin{classdesc}{ConfigParser}{\optional{defaults}}
35Return a new instance of the \class{ConfigParser} class. When
36\var{defaults} is given, it is initialized into the dictionairy of
37intrinsic defaults. They keys must be strings, and the values must be
38appropriate for the \samp{\%()s} string interpolation. Note that
39\var{__name__} is always an intrinsic default; it's value is the
40section name.
41\end{classdesc}
42
43\begin{excdesc}{NoSectionError}
44Exception raised when a specified section is not found.
45\end{excdesc}
46
47\begin{excdesc}{DuplicateSectionError}
48Exception raised when mutliple sections with the same name are found.
49\end{excdesc}
50
51\begin{excdesc}{NoOptionError}
52Exception raised when a specified option is not found in the specified
53section.
54\end{excdesc}
55
56\begin{excdesc}{InterpolationError}
57Exception raised when problems occur performing string interpolation.
58\end{excdesc}
59
60\begin{excdesc}{MissingSectionHeaderError}
61Exception raised when attempting to parse a file which has no section
62headers.
63\end{excdesc}
64
65\begin{excdesc}{ParsingError}
66Exception raised when errors occur attempting to parse a file.
67\end{excdesc}
68
69\subsection{ConfigParser Objects \label{ConfigParser-objects}}
70
71\class{ConfigParser} instances have the following methods:
72
73\begin{methoddesc}{defaults}{}
74Return a dictionairy containing the instance-wide defaults.
75\end{methoddesc}
76
77\begin{methoddesc}{sections}{}
78Return a list of the sections available.
79\end{methoddesc}
80
81\begin{methoddesc}{has_section}{section}
82Indicates whether the named section is present in the
83configuration. The \code{DEFAULT} section is not acknowledged.
84\end{methoddesc}
85
86\begin{methoddesc}{options}{section}
87Returns a list of options available in the specified \var{section}.
88\end{methoddesc}
89
90\begin{methoddesc}{read}{filenames}
91Read and parse a list of filenames.
92\end{methoddesc}
93
94\begin{methoddesc}{get}{section, option\optional{, raw}}
95Get an \var{option} value for the provided \var{section}. All the
96\samp{\%} interpolations are expanded in the return values, based on
97the defaults passed into the constructor, unless the \var{raw}
98argument is true.
99\end{methoddesc}
100
101\begin{methoddesc}{getint}{section, option}
102A convenience method which coerces the \var{option} in the specified
103\var{section} to an integer.
104\end{methoddesc}
105
106\begin{methoddesc}{getfloat}{section, option}
107A convenience method which coerces the \var{option} in the specified
108\var{section} to a floating point number.
109\end{methoddesc}
110
111\begin{methoddesc}{getboolean}{section, option}
112A convenience method which coerces the \var{option} in the specified
113\var{section} to a boolean value. Note that the only accepted values
114for the option are \code{0} and \code{1}, any others will raise
115\exception{ValueError}.
116\end{methoddesc}