Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
97d5f052
Commit
97d5f052
authored
Oct 25, 2002
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to reflect the refactoring into the RawConfigParser and
ConfigParser classes.
parent
b1248ceb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
18 deletions
+41
-18
Doc/lib/libcfgparser.tex
Doc/lib/libcfgparser.tex
+41
-18
No files found.
Doc/lib/libcfgparser.tex
View file @
97d5f052
...
...
@@ -22,13 +22,14 @@ with continuations in the style of \rfc{822}; \samp{name=value} is
also accepted. Note that leading whitespace is removed from values.
The optional values can contain format strings which refer to other
values in the same section, or values in a special
\code
{
DEFAULT
}
section. Additional defaults can be provided
up
on
\code
{
DEFAULT
}
section. Additional defaults can be provided on
initialization and retrieval. Lines beginning with
\character
{
\#
}
or
\character
{
;
}
are ignored and may be used to provide comments.
For example:
\begin{verbatim}
[My Section]
foodir:
%(dir)s/whatever
dir=frob
\end{verbatim}
...
...
@@ -42,10 +43,17 @@ Default values can be specified by passing them into the
may be passed into the
\method
{
get()
}
method which will override all
others.
\begin{classdesc}
{
RawConfigParser
}{
\optional
{
defaults
}}
The basic configuration object. When
\var
{
defaults
}
is given, it is
initialized into the dictionary of intrinsic defaults. This class
does not support the magical interpolation behavior.
\versionadded
{
2.3
}
\end{classdesc}
\begin{classdesc}
{
ConfigParser
}{
\optional
{
defaults
}}
Return a new instance of the
\class
{
ConfigParser
}
class. When
\var
{
defaults
}
is given, it is initialized into the dictionary of
intrinsic defaults. The keys must be strings, and the values must be
Derived class of
\class
{
RawConfigParser
}
that implements the magical
interpolation feature and adds optional arguments the
\method
{
get()
}
and
\method
{
items()
}
methods. The values in
\var
{
defaults
}
must be
appropriate for the
\samp
{
\%
()s
}
string interpolation. Note that
\var
{__
name
__}
is an intrinsic default; its value is the section name,
and will override any value provided in
\var
{
defaults
}
.
...
...
@@ -86,8 +94,8 @@ Exception raised when errors occur attempting to parse a file.
\begin{datadesc}
{
MAX
_
INTERPOLATION
_
DEPTH
}
The maximum depth for recursive interpolation for
\method
{
get()
}
when
the
\var
{
raw
}
parameter is false.
Setting this does not change
the
allowed recursion depth
.
the
\var
{
raw
}
parameter is false.
This is relevant only for
the
\class
{
ConfigParser
}
class
.
\end{datadesc}
...
...
@@ -98,9 +106,9 @@ allowed recursion depth.
\end{seealso}
\subsection
{
ConfigParser Objects
\label
{
ConfigParser-objects
}}
\subsection
{
RawConfigParser Objects
\label
{
Raw
ConfigParser-objects
}}
\class
{
ConfigParser
}
instances have the following methods:
\class
{
Raw
ConfigParser
}
instances have the following methods:
\begin{methoddesc}
{
defaults
}{}
Return a dictionary containing the instance-wide defaults.
...
...
@@ -162,11 +170,8 @@ Read and parse configuration data from the file or file-like object in
that is used for
\var
{
filename
}
; the default is
\samp
{
<???>
}
.
\end{methoddesc}
\begin{methoddesc}
{
get
}{
section, option
\optional
{
, raw
\optional
{
, vars
}}}
Get an
\var
{
option
}
value for the provided
\var
{
section
}
. All the
\character
{
\%
}
interpolations are expanded in the return values, based on
the defaults passed into the constructor, as well as the options
\var
{
vars
}
provided, unless the
\var
{
raw
}
argument is true.
\begin{methoddesc}
{
get
}{
section, option
}
Get an
\var
{
option
}
value for the named
\var
{
section
}
.
\end{methoddesc}
\begin{methoddesc}
{
getint
}{
section, option
}
...
...
@@ -189,11 +194,9 @@ values are checked in a case-insensitive manner. Any other value will
cause it to raise
\exception
{
ValueError
}
.
\end{methoddesc}
\begin{methoddesc}
{
items
}{
section
\optional
{
, raw
\optional
{
, vars
}}}
Create a generator which will return a tuple
\code
{
(name, value)
}
for
each option in the given
\var
{
section
}
. Optional arguments have the
same meaning as for the
\code
{
get()
}
method.
\versionadded
{
2.3
}
\begin{methoddesc}
{
items
}{
section
}
Return a list of
\code
{
(
\var
{
name
}
,
\var
{
value
}
)
}
pairs for each
option in the given
\var
{
section
}
.
\end{methoddesc}
\begin{methoddesc}
{
set
}{
section, option, value
}
...
...
@@ -231,3 +234,23 @@ can set an attribute of this name on instances to affect this
behavior. Setting this to
\function
{
str()
}
, for example, would make
option names case sensitive.
\end{methoddesc}
\subsection
{
ConfigParser Objects
\label
{
ConfigParser-objects
}}
The
\class
{
ConfigParser
}
class extends some methods of the
\class
{
RawConfigParser
}
interface, adding some optional arguments.
\begin{methoddesc}
{
get
}{
section, option
\optional
{
, raw
\optional
{
, vars
}}}
Get an
\var
{
option
}
value for the named
\var
{
section
}
. All the
\character
{
\%
}
interpolations are expanded in the return values, based
on the defaults passed into the constructor, as well as the options
\var
{
vars
}
provided, unless the
\var
{
raw
}
argument is true.
\end{methoddesc}
\begin{methoddesc}
{
items
}{
section
\optional
{
, raw
\optional
{
, vars
}}}
Create a generator which will return a tuple
\code
{
(name, value)
}
for
each option in the given
\var
{
section
}
. Optional arguments have the
same meaning as for the
\code
{
get()
}
method.
\versionadded
{
2.3
}
\end{methoddesc}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment