@@ -674,97 +674,98 @@ be overridden by subclasses or by attribute assignment.
674674
675675.. attribute :: ConfigParser.BOOLEAN_STATES
676676
677- By default when using :meth: `~ConfigParser.getboolean `, config parsers
678- consider the following values ``True ``: ``'1' ``, ``'yes' ``, ``'true' ``,
679- ``'on' `` and the following values ``False ``: ``'0' ``, ``'no' ``, ``'false' ``,
680- ``'off' ``. You can override this by specifying a custom dictionary of strings
681- and their Boolean outcomes. For example:
682-
683- .. doctest ::
684-
685- >>> custom = configparser.ConfigParser()
686- >>> custom[' section1' ] = {' funky' : ' nope' }
687- >>> custom[' section1' ].getboolean(' funky' )
688- Traceback (most recent call last):
689- ...
690- ValueError: Not a boolean: nope
691- >>> custom.BOOLEAN_STATES = {' sure' : True , ' nope' : False }
692- >>> custom[' section1' ].getboolean(' funky' )
693- False
694-
695- Other typical Boolean pairs include ``accept ``/``reject `` or
696- ``enabled ``/``disabled ``.
677+ By default when using :meth: `~ConfigParser.getboolean `, config parsers
678+ consider the following values ``True ``: ``'1' ``, ``'yes' ``, ``'true' ``,
679+ ``'on' `` and the following values ``False ``: ``'0' ``, ``'no' ``, ``'false' ``,
680+ ``'off' ``. You can override this by specifying a custom dictionary of strings
681+ and their Boolean outcomes. For example:
682+
683+ .. doctest ::
684+
685+ >>> custom = configparser.ConfigParser()
686+ >>> custom[' section1' ] = {' funky' : ' nope' }
687+ >>> custom[' section1' ].getboolean(' funky' )
688+ Traceback (most recent call last):
689+ ...
690+ ValueError: Not a boolean: nope
691+ >>> custom.BOOLEAN_STATES = {' sure' : True , ' nope' : False }
692+ >>> custom[' section1' ].getboolean(' funky' )
693+ False
694+
695+ Other typical Boolean pairs include ``accept ``/``reject `` or
696+ ``enabled ``/``disabled ``.
697697
698698.. method :: ConfigParser.optionxform(option)
699+ :noindex:
699700
700- This method transforms option names on every read, get, or set
701- operation. The default converts the name to lowercase. This also
702- means that when a configuration file gets written, all keys will be
703- lowercase. Override this method if that's unsuitable.
704- For example:
701+ This method transforms option names on every read, get, or set
702+ operation. The default converts the name to lowercase. This also
703+ means that when a configuration file gets written, all keys will be
704+ lowercase. Override this method if that's unsuitable.
705+ For example:
705706
706- .. doctest ::
707+ .. doctest ::
708+
709+ >>> config = """
710+ ... [Section1]
711+ ... Key = Value
712+ ...
713+ ... [Section2]
714+ ... AnotherKey = Value
715+ ... """
716+ >>> typical = configparser.ConfigParser()
717+ >>> typical.read_string(config)
718+ >>> list (typical[' Section1' ].keys())
719+ ['key']
720+ >>> list (typical[' Section2' ].keys())
721+ ['anotherkey']
722+ >>> custom = configparser.RawConfigParser()
723+ >>> custom.optionxform = lambda option : option
724+ >>> custom.read_string(config)
725+ >>> list (custom[' Section1' ].keys())
726+ ['Key']
727+ >>> list (custom[' Section2' ].keys())
728+ ['AnotherKey']
707729
708- >>> config = """
709- ... [Section1]
710- ... Key = Value
711- ...
712- ... [Section2]
713- ... AnotherKey = Value
714- ... """
715- >>> typical = configparser.ConfigParser()
716- >>> typical.read_string(config)
717- >>> list (typical[' Section1' ].keys())
718- ['key']
719- >>> list (typical[' Section2' ].keys())
720- ['anotherkey']
721- >>> custom = configparser.RawConfigParser()
722- >>> custom.optionxform = lambda option : option
723- >>> custom.read_string(config)
724- >>> list (custom[' Section1' ].keys())
725- ['Key']
726- >>> list (custom[' Section2' ].keys())
727- ['AnotherKey']
728-
729- .. note ::
730- The optionxform function transforms option names to a canonical form.
731- This should be an idempotent function: if the name is already in
732- canonical form, it should be returned unchanged.
730+ .. note ::
731+ The optionxform function transforms option names to a canonical form.
732+ This should be an idempotent function: if the name is already in
733+ canonical form, it should be returned unchanged.
733734
734735
735736.. attribute :: ConfigParser.SECTCRE
736737
737- A compiled regular expression used to parse section headers. The default
738- matches ``[section] `` to the name ``"section" ``. Whitespace is considered
739- part of the section name, thus ``[ larch ] `` will be read as a section of
740- name ``" larch " ``. Override this attribute if that's unsuitable. For
741- example:
738+ A compiled regular expression used to parse section headers. The default
739+ matches ``[section] `` to the name ``"section" ``. Whitespace is considered
740+ part of the section name, thus ``[ larch ] `` will be read as a section of
741+ name ``" larch " ``. Override this attribute if that's unsuitable. For
742+ example:
743+
744+ .. doctest ::
745+
746+ >>> import re
747+ >>> config = """
748+ ... [Section 1 ]
749+ ... option = value
750+ ...
751+ ... [ Section 2 ]
752+ ... another = val
753+ ... """
754+ >>> typical = configparser.ConfigParser()
755+ >>> typical.read_string(config)
756+ >>> typical.sections()
757+ ['Section 1', ' Section 2 ']
758+ >>> custom = configparser.ConfigParser()
759+ >>> custom.SECTCRE = re.compile(r " \[ * ( ?P<header> [^ ] ]+? ) * \] " )
760+ >>> custom.read_string(config)
761+ >>> custom.sections()
762+ ['Section 1', 'Section 2']
742763
743- .. doctest ::
764+ .. note ::
744765
745- >>> import re
746- >>> config = """
747- ... [Section 1 ]
748- ... option = value
749- ...
750- ... [ Section 2 ]
751- ... another = val
752- ... """
753- >>> typical = configparser.ConfigParser()
754- >>> typical.read_string(config)
755- >>> typical.sections()
756- ['Section 1', ' Section 2 ']
757- >>> custom = configparser.ConfigParser()
758- >>> custom.SECTCRE = re.compile(r " \[ * ( ?P<header> [^ ] ]+? ) * \] " )
759- >>> custom.read_string(config)
760- >>> custom.sections()
761- ['Section 1', 'Section 2']
762-
763- .. note ::
764-
765- While ConfigParser objects also use an ``OPTCRE `` attribute for recognizing
766- option lines, it's not recommended to override it because that would
767- interfere with constructor options *allow_no_value * and *delimiters *.
766+ While ConfigParser objects also use an ``OPTCRE `` attribute for recognizing
767+ option lines, it's not recommended to override it because that would
768+ interfere with constructor options *allow_no_value * and *delimiters *.
768769
769770
770771Legacy API Examples
0 commit comments