Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
3a8479a5
Kaydet (Commit)
3a8479a5
authored
Ara 31, 2012
tarafından
Łukasz Langa
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixes `parser.clean()` reported in issue #16820.
üst
30574695
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
1 deletion
+47
-1
configparser.rst
Doc/library/configparser.rst
+7
-1
configparser.py
Lib/configparser.py
+13
-0
test_cfgparser.py
Lib/test/test_cfgparser.py
+27
-0
No files found.
Doc/library/configparser.rst
Dosyayı görüntüle @
3a8479a5
...
...
@@ -389,7 +389,13 @@ However, there are a few differences that should be taken into account:
the default value to be visible again. Trying to delete a default value
causes a ``KeyError``.
* Trying to delete the ``DEFAULTSECT`` raises ``ValueError``.
* ``DEFAULTSECT`` cannot be removed from the parser:
* trying to delete it raises ``ValueError``,
* ``parser.clear()`` leaves it intact,
* ``parser.popitem()`` never returns it.
* ``parser.get(section, option, **kwargs)`` - the second argument is **not**
a fallback value. Note however that the section-level ``get()`` methods are
...
...
Lib/configparser.py
Dosyayı görüntüle @
3a8479a5
...
...
@@ -851,6 +851,19 @@ class RawConfigParser(MutableMapping):
value_getter
=
lambda
option
:
d
[
option
]
return
[(
option
,
value_getter
(
option
))
for
option
in
d
.
keys
()]
def
popitem
(
self
):
"""Remove a section from the parser and return it as
a (section_name, section_proxy) tuple. If no section is present, raise
KeyError.
The section DEFAULT is never returned because it cannot be removed.
"""
for
key
in
self
.
sections
():
value
=
self
[
key
]
del
self
[
key
]
return
key
,
value
raise
KeyError
def
optionxform
(
self
,
optionstr
):
return
optionstr
.
lower
()
...
...
Lib/test/test_cfgparser.py
Dosyayı görüntüle @
3a8479a5
...
...
@@ -770,6 +770,33 @@ boolean {0[0]} NO
with
self
.
assertRaises
(
configparser
.
NoSectionError
):
cf
.
items
(
"no such section"
)
def
test_popitem
(
self
):
cf
=
self
.
fromstring
(
"""
[section1]
name1 {0[0]} value1
[section2]
name2 {0[0]} value2
[section3]
name3 {0[0]} value3
"""
.
format
(
self
.
delimiters
),
defaults
=
{
"default"
:
"<default>"
})
self
.
assertEqual
(
cf
.
popitem
()[
0
],
'section1'
)
self
.
assertEqual
(
cf
.
popitem
()[
0
],
'section2'
)
self
.
assertEqual
(
cf
.
popitem
()[
0
],
'section3'
)
with
self
.
assertRaises
(
KeyError
):
cf
.
popitem
()
def
test_clear
(
self
):
cf
=
self
.
newconfig
({
"foo"
:
"Bar"
})
self
.
assertEqual
(
cf
.
get
(
self
.
default_section
,
"Foo"
),
"Bar"
,
"could not locate option, expecting case-insensitive option names"
)
cf
[
'zing'
]
=
{
'option1'
:
'value1'
,
'option2'
:
'value2'
}
self
.
assertEqual
(
cf
.
sections
(),
[
'zing'
])
self
.
assertEqual
(
set
(
cf
[
'zing'
]
.
keys
()),
{
'option1'
,
'option2'
,
'foo'
})
cf
.
clear
()
self
.
assertEqual
(
set
(
cf
.
sections
()),
set
())
self
.
assertEqual
(
set
(
cf
[
self
.
default_section
]
.
keys
()),
{
'foo'
})
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