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