@@ -65,10 +65,10 @@ Let's take a very basic configuration file that looks like this:
65
65
CompressionLevel = 9
66
66
ForwardX11 = yes
67
67
68
- [bitbucket.org ]
68
+ [forge.example ]
69
69
User = hg
70
70
71
- [topsecret.server.com ]
71
+ [topsecret.server.example ]
72
72
Port = 50022
73
73
ForwardX11 = no
74
74
@@ -85,10 +85,10 @@ creating the above configuration file programmatically.
85
85
>>> config[' DEFAULT' ] = {' ServerAliveInterval' : ' 45' ,
86
86
... ' Compression' : ' yes' ,
87
87
... ' CompressionLevel' : ' 9' }
88
- >>> config[' bitbucket.org ' ] = {}
89
- >>> config[' bitbucket.org ' ][' User' ] = ' hg'
90
- >>> config[' topsecret.server.com ' ] = {}
91
- >>> topsecret = config[' topsecret.server.com ' ]
88
+ >>> config[' forge.example ' ] = {}
89
+ >>> config[' forge.example ' ][' User' ] = ' hg'
90
+ >>> config[' topsecret.server.example ' ] = {}
91
+ >>> topsecret = config[' topsecret.server.example ' ]
92
92
>>> topsecret[' Port' ] = ' 50022' # mutates the parser
93
93
>>> topsecret[' ForwardX11' ] = ' no' # same here
94
94
>>> config[' DEFAULT' ][' ForwardX11' ] = ' yes'
@@ -111,28 +111,28 @@ back and explore the data it holds.
111
111
>>> config.read(' example.ini' )
112
112
['example.ini']
113
113
>>> config.sections()
114
- ['bitbucket.org ', 'topsecret.server.com ']
115
- >>> ' bitbucket.org ' in config
114
+ ['forge.example ', 'topsecret.server.example ']
115
+ >>> ' forge.example ' in config
116
116
True
117
- >>> ' bytebong.com ' in config
117
+ >>> ' python.org ' in config
118
118
False
119
- >>> config[' bitbucket.org ' ][' User' ]
119
+ >>> config[' forge.example ' ][' User' ]
120
120
'hg'
121
121
>>> config[' DEFAULT' ][' Compression' ]
122
122
'yes'
123
- >>> topsecret = config[' topsecret.server.com ' ]
123
+ >>> topsecret = config[' topsecret.server.example ' ]
124
124
>>> topsecret[' ForwardX11' ]
125
125
'no'
126
126
>>> topsecret[' Port' ]
127
127
'50022'
128
- >>> for key in config[' bitbucket.org ' ]: # doctest: +SKIP
128
+ >>> for key in config[' forge.example ' ]: # doctest: +SKIP
129
129
... print (key)
130
130
user
131
131
compressionlevel
132
132
serveraliveinterval
133
133
compression
134
134
forwardx11
135
- >>> config[' bitbucket.org ' ][' ForwardX11' ]
135
+ >>> config[' forge.example ' ][' ForwardX11' ]
136
136
'yes'
137
137
138
138
As we can see above, the API is pretty straightforward. The only bit of magic
@@ -150,15 +150,15 @@ configuration while the previously existing keys are retained.
150
150
>>> another_config = configparser.ConfigParser()
151
151
>>> another_config.read(' example.ini' )
152
152
['example.ini']
153
- >>> another_config[' topsecret.server.com ' ][' Port' ]
153
+ >>> another_config[' topsecret.server.example ' ][' Port' ]
154
154
'50022'
155
- >>> another_config.read_string(" [topsecret.server.com ]\n Port=48484" )
156
- >>> another_config[' topsecret.server.com ' ][' Port' ]
155
+ >>> another_config.read_string(" [topsecret.server.example ]\n Port=48484" )
156
+ >>> another_config[' topsecret.server.example ' ][' Port' ]
157
157
'48484'
158
- >>> another_config.read_dict({" topsecret.server.com " : {" Port" : 21212 }})
159
- >>> another_config[' topsecret.server.com ' ][' Port' ]
158
+ >>> another_config.read_dict({" topsecret.server.example " : {" Port" : 21212 }})
159
+ >>> another_config[' topsecret.server.example ' ][' Port' ]
160
160
'21212'
161
- >>> another_config[' topsecret.server.com ' ][' ForwardX11' ]
161
+ >>> another_config[' topsecret.server.example ' ][' ForwardX11' ]
162
162
'no'
163
163
164
164
This behaviour is equivalent to a :meth: `ConfigParser.read ` call with several
@@ -191,9 +191,9 @@ recognizes Boolean values from ``'yes'``/``'no'``, ``'on'``/``'off'``,
191
191
192
192
>>> topsecret.getboolean(' ForwardX11' )
193
193
False
194
- >>> config[' bitbucket.org ' ].getboolean(' ForwardX11' )
194
+ >>> config[' forge.example ' ].getboolean(' ForwardX11' )
195
195
True
196
- >>> config.getboolean(' bitbucket.org ' , ' Compression' )
196
+ >>> config.getboolean(' forge.example ' , ' Compression' )
197
197
True
198
198
199
199
Apart from :meth: `~ConfigParser.getboolean `, config parsers also
@@ -220,7 +220,7 @@ provide fallback values:
220
220
Please note that default values have precedence over fallback values.
221
221
For instance, in our example the ``'CompressionLevel' `` key was
222
222
specified only in the ``'DEFAULT' `` section. If we try to get it from
223
- the section ``'topsecret.server.com ' ``, we will always get the default,
223
+ the section ``'topsecret.server.example ' ``, we will always get the default,
224
224
even if we specify a fallback:
225
225
226
226
.. doctest ::
@@ -235,7 +235,7 @@ the ``fallback`` keyword-only argument:
235
235
236
236
.. doctest ::
237
237
238
- >>> config.get(' bitbucket.org ' , ' monster' ,
238
+ >>> config.get(' forge.example ' , ' monster' ,
239
239
... fallback= ' No such things as monsters' )
240
240
'No such things as monsters'
241
241
0 commit comments