Skip to content

Commit cc645b9

Browse files
committed
add consistent support for the vars and default arguments on all
configuration parser classes (http://bugs.python.org/issue9421)
1 parent c934f32 commit cc645b9

4 files changed

Lines changed: 252 additions & 78 deletions

File tree

Doc/library/configparser.rst

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ keys within each section.
135135
*empty_lines_in_values* were added.
136136

137137

138-
.. class:: SafeConfigParser(defaults=None, dict_type=collections.OrderedDict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), strict=False, empty_lines_in_values=True)
138+
.. class:: SafeConfigParser(defaults=None, dict_type=collections.OrderedDict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=_COMPATIBLE, strict=False, empty_lines_in_values=True)
139139

140140
Derived class of :class:`ConfigParser` that implements a sane variant of the
141141
magical interpolation feature. This implementation is more predictable as it
@@ -155,7 +155,7 @@ keys within each section.
155155
*empty_lines_in_values* were added.
156156

157157

158-
.. class:: ConfigParser(defaults=None, dict_type=collections.OrderedDict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), strict=False, empty_lines_in_values=True)
158+
.. class:: ConfigParser(defaults=None, dict_type=collections.OrderedDict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=_COMPATIBLE, strict=False, empty_lines_in_values=True)
159159

160160
Derived class of :class:`RawConfigParser` that implements the magical
161161
interpolation feature and adds optional arguments to the :meth:`get` and
@@ -366,39 +366,44 @@ RawConfigParser Objects
366366
Load configuration from a dictionary. Keys are section names, values are
367367
dictionaries with keys and values that should be present in the section. If
368368
the used dictionary type preserves order, sections and their keys will be
369-
added in order.
369+
added in order. Values are automatically converted to strings.
370370

371371
Optional argument *source* specifies a context-specific name of the
372372
dictionary passed. If not given, ``<dict>`` is used.
373373

374374
.. versionadded:: 3.2
375375

376+
.. method:: RawConfigParser.get(section, option, [vars, default])
376377

377-
.. method:: RawConfigParser.get(section, option)
378-
379-
Get an *option* value for the named *section*.
378+
Get an *option* value for the named *section*. If *vars* is provided, it
379+
must be a dictionary. The *option* is looked up in *vars* (if provided),
380+
*section*, and in *DEFAULTSECT* in that order. If the key is not found and
381+
*default* is provided, it is used as a fallback value. ``None`` can be
382+
provided as a *default* value.
380383

381384

382-
.. method:: RawConfigParser.getint(section, option)
385+
.. method:: RawConfigParser.getint(section, option, [vars, default])
383386

384-
A convenience method which coerces the *option* in the specified *section* to an
385-
integer.
387+
A convenience method which coerces the *option* in the specified *section* to
388+
an integer. See :meth:`get` for explanation of *vars* and *default*.
386389

387390

388-
.. method:: RawConfigParser.getfloat(section, option)
391+
.. method:: RawConfigParser.getfloat(section, option, [vars, default])
389392

390-
A convenience method which coerces the *option* in the specified *section* to a
391-
floating point number.
393+
A convenience method which coerces the *option* in the specified *section* to
394+
a floating point number. See :meth:`get` for explanation of *vars* and
395+
*default*.
392396

393397

394-
.. method:: RawConfigParser.getboolean(section, option)
398+
.. method:: RawConfigParser.getboolean(section, option, [vars, default])
395399

396-
A convenience method which coerces the *option* in the specified *section* to a
397-
Boolean value. Note that the accepted values for the option are ``"1"``,
398-
``"yes"``, ``"true"``, and ``"on"``, which cause this method to return ``True``,
399-
and ``"0"``, ``"no"``, ``"false"``, and ``"off"``, which cause it to return
400-
``False``. These string values are checked in a case-insensitive manner. Any
401-
other value will cause it to raise :exc:`ValueError`.
400+
A convenience method which coerces the *option* in the specified *section*
401+
to a Boolean value. Note that the accepted values for the option are
402+
``"1"``, ``"yes"``, ``"true"``, and ``"on"``, which cause this method to
403+
return ``True``, and ``"0"``, ``"no"``, ``"false"``, and ``"off"``, which
404+
cause it to return ``False``. These string values are checked in
405+
a case-insensitive manner. Any other value will cause it to raise
406+
:exc:`ValueError`. See :meth:`get` for explanation of *vars* and *default*.
402407

403408

404409
.. method:: RawConfigParser.items(section)
@@ -475,17 +480,44 @@ can, consider using :class:`SafeConfigParser` which adds validation and escaping
475480
for the interpolation.
476481

477482

478-
.. method:: ConfigParser.get(section, option, raw=False, vars=None)
483+
.. method:: ConfigParser.get(section, option, raw=False, [vars, default])
479484

480485
Get an *option* value for the named *section*. If *vars* is provided, it
481486
must be a dictionary. The *option* is looked up in *vars* (if provided),
482-
*section*, and in *defaults* in that order.
487+
*section*, and in *DEFAULTSECT* in that order. If the key is not found and
488+
*default* is provided, it is used as a fallback value. ``None`` can be
489+
provided as a *default* value.
483490

484491
All the ``'%'`` interpolations are expanded in the return values, unless the
485492
*raw* argument is true. Values for interpolation keys are looked up in the
486493
same manner as the option.
487494

488495

496+
.. method:: ConfigParser.getint(section, option, raw=False, [vars, default])
497+
498+
A convenience method which coerces the *option* in the specified *section* to
499+
an integer. See :meth:`get` for explanation of *raw*, *vars* and *default*.
500+
501+
502+
.. method:: ConfigParser.getfloat(section, option, raw=False, [vars, default])
503+
504+
A convenience method which coerces the *option* in the specified *section* to
505+
a floating point number. See :meth:`get` for explanation of *raw*, *vars*
506+
and *default*.
507+
508+
509+
.. method:: ConfigParser.getboolean(section, option, raw=False, [vars, default])
510+
511+
A convenience method which coerces the *option* in the specified *section*
512+
to a Boolean value. Note that the accepted values for the option are
513+
``"1"``, ``"yes"``, ``"true"``, and ``"on"``, which cause this method to
514+
return ``True``, and ``"0"``, ``"no"``, ``"false"``, and ``"off"``, which
515+
cause it to return ``False``. These string values are checked in
516+
a case-insensitive manner. Any other value will cause it to raise
517+
:exc:`ValueError`. See :meth:`get` for explanation of *raw*, *vars* and
518+
*default*.
519+
520+
489521
.. method:: ConfigParser.items(section, raw=False, vars=None)
490522

491523
Return a list of ``(name, value)`` pairs for each option in the given

0 commit comments

Comments
 (0)