Skip to content

[3.10] gh-93573: Replace wrong example domains in configparser doc (GH-93574) #101954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ Let's take a very basic configuration file that looks like this:
CompressionLevel = 9
ForwardX11 = yes

[bitbucket.org]
[forge.example]
User = hg

[topsecret.server.com]
[topsecret.server.example]
Port = 50022
ForwardX11 = no

Expand All @@ -85,10 +85,10 @@ creating the above configuration file programmatically.
>>> config['DEFAULT'] = {'ServerAliveInterval': '45',
... 'Compression': 'yes',
... 'CompressionLevel': '9'}
>>> config['bitbucket.org'] = {}
>>> config['bitbucket.org']['User'] = 'hg'
>>> config['topsecret.server.com'] = {}
>>> topsecret = config['topsecret.server.com']
>>> config['forge.example'] = {}
>>> config['forge.example']['User'] = 'hg'
>>> config['topsecret.server.example'] = {}
>>> topsecret = config['topsecret.server.example']
>>> topsecret['Port'] = '50022' # mutates the parser
>>> topsecret['ForwardX11'] = 'no' # same here
>>> config['DEFAULT']['ForwardX11'] = 'yes'
Expand All @@ -111,28 +111,28 @@ back and explore the data it holds.
>>> config.read('example.ini')
['example.ini']
>>> config.sections()
['bitbucket.org', 'topsecret.server.com']
>>> 'bitbucket.org' in config
['forge.example', 'topsecret.server.example']
>>> 'forge.example' in config
True
>>> 'bytebong.com' in config
>>> 'python.org' in config
False
>>> config['bitbucket.org']['User']
>>> config['forge.example']['User']
'hg'
>>> config['DEFAULT']['Compression']
'yes'
>>> topsecret = config['topsecret.server.com']
>>> topsecret = config['topsecret.server.example']
>>> topsecret['ForwardX11']
'no'
>>> topsecret['Port']
'50022'
>>> for key in config['bitbucket.org']: # doctest: +SKIP
>>> for key in config['forge.example']: # doctest: +SKIP
... print(key)
user
compressionlevel
serveraliveinterval
compression
forwardx11
>>> config['bitbucket.org']['ForwardX11']
>>> config['forge.example']['ForwardX11']
'yes'

As we can see above, the API is pretty straightforward. The only bit of magic
Expand All @@ -150,15 +150,15 @@ configuration while the previously existing keys are retained.
>>> another_config = configparser.ConfigParser()
>>> another_config.read('example.ini')
['example.ini']
>>> another_config['topsecret.server.com']['Port']
>>> another_config['topsecret.server.example']['Port']
'50022'
>>> another_config.read_string("[topsecret.server.com]\nPort=48484")
>>> another_config['topsecret.server.com']['Port']
>>> another_config.read_string("[topsecret.server.example]\nPort=48484")
>>> another_config['topsecret.server.example']['Port']
'48484'
>>> another_config.read_dict({"topsecret.server.com": {"Port": 21212}})
>>> another_config['topsecret.server.com']['Port']
>>> another_config.read_dict({"topsecret.server.example": {"Port": 21212}})
>>> another_config['topsecret.server.example']['Port']
'21212'
>>> another_config['topsecret.server.com']['ForwardX11']
>>> another_config['topsecret.server.example']['ForwardX11']
'no'

This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
Expand Down Expand Up @@ -191,9 +191,9 @@ recognizes Boolean values from ``'yes'``/``'no'``, ``'on'``/``'off'``,

>>> topsecret.getboolean('ForwardX11')
False
>>> config['bitbucket.org'].getboolean('ForwardX11')
>>> config['forge.example'].getboolean('ForwardX11')
True
>>> config.getboolean('bitbucket.org', 'Compression')
>>> config.getboolean('forge.example', 'Compression')
True

Apart from :meth:`~ConfigParser.getboolean`, config parsers also
Expand All @@ -220,7 +220,7 @@ provide fallback values:
Please note that default values have precedence over fallback values.
For instance, in our example the ``'CompressionLevel'`` key was
specified only in the ``'DEFAULT'`` section. If we try to get it from
the section ``'topsecret.server.com'``, we will always get the default,
the section ``'topsecret.server.example'``, we will always get the default,
even if we specify a fallback:

.. doctest::
Expand All @@ -235,7 +235,7 @@ the ``fallback`` keyword-only argument:

.. doctest::

>>> config.get('bitbucket.org', 'monster',
>>> config.get('forge.example', 'monster',
... fallback='No such things as monsters')
'No such things as monsters'

Expand Down