Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a2e7acd1
Commit
a2e7acd1
authored
Jan 01, 2013
by
Łukasz Langa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
configparser: preserve section order when using `__setitem__` (issue #16820)
parent
e4110dc1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
Lib/configparser.py
Lib/configparser.py
+2
-1
Lib/test/test_cfgparser.py
Lib/test/test_cfgparser.py
+26
-0
No files found.
Lib/configparser.py
View file @
a2e7acd1
...
...
@@ -959,7 +959,8 @@ class RawConfigParser(MutableMapping):
# XXX this is not atomic if read_dict fails at any point. Then again,
# no update method in configparser is atomic in this implementation.
self.remove_section(key)
if key in self._sections:
self._sections[key].clear()
self.read_dict({key: value})
def __delitem__(self, key):
...
...
Lib/test/test_cfgparser.py
View file @
a2e7acd1
...
...
@@ -797,6 +797,32 @@ boolean {0[0]} NO
self
.
assertEqual
(
set
(
cf
.
sections
()),
set
())
self
.
assertEqual
(
set
(
cf
[
self
.
default_section
].
keys
()),
{
'foo'
})
def
test_setitem
(
self
):
cf
=
self
.
fromstring
(
"""
[section1]
name1 {0[0]} value1
[section2]
name2 {0[0]} value2
[section3]
name3 {0[0]} value3
"""
.
format
(
self
.
delimiters
),
defaults
=
{
"nameD"
:
"valueD"
})
self
.
assertEqual
(
set
(
cf
[
'section1'
].
keys
()),
{
'name1'
,
'named'
})
self
.
assertEqual
(
set
(
cf
[
'section2'
].
keys
()),
{
'name2'
,
'named'
})
self
.
assertEqual
(
set
(
cf
[
'section3'
].
keys
()),
{
'name3'
,
'named'
})
self
.
assertEqual
(
cf
[
'section1'
][
'name1'
],
'value1'
)
self
.
assertEqual
(
cf
[
'section2'
][
'name2'
],
'value2'
)
self
.
assertEqual
(
cf
[
'section3'
][
'name3'
],
'value3'
)
self
.
assertEqual
(
cf
.
sections
(),
[
'section1'
,
'section2'
,
'section3'
])
cf
[
'section2'
]
=
{
'name22'
:
'value22'
}
self
.
assertEqual
(
set
(
cf
[
'section2'
].
keys
()),
{
'name22'
,
'named'
})
self
.
assertEqual
(
cf
[
'section2'
][
'name22'
],
'value22'
)
self
.
assertNotIn
(
'name2'
,
cf
[
'section2'
])
self
.
assertEqual
(
cf
.
sections
(),
[
'section1'
,
'section2'
,
'section3'
])
cf
[
'section3'
]
=
{}
self
.
assertEqual
(
set
(
cf
[
'section3'
].
keys
()),
{
'named'
})
self
.
assertNotIn
(
'name3'
,
cf
[
'section3'
])
self
.
assertEqual
(
cf
.
sections
(),
[
'section1'
,
'section2'
,
'section3'
])
class
StrictTestCase
(
BasicTestCase
):
config_class
=
configparser
.
RawConfigParser
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment