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
2f0fd0fa
Kaydet (Commit)
2f0fd0fa
authored
Ara 04, 2010
tarafından
Łukasz Langa
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
configparser: mapping protocol access get() handles configparser-specific arguments as well
üst
12159150
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
6 deletions
+59
-6
configparser.py
Lib/configparser.py
+16
-6
test_cfgparser.py
Lib/test/test_cfgparser.py
+43
-0
No files found.
Lib/configparser.py
Dosyayı görüntüle @
2f0fd0fa
...
...
@@ -1195,12 +1195,6 @@ class SectionProxy(MutableMapping):
"""Creates a view on a section of the specified `name` in `parser`."""
self
.
_parser
=
parser
self
.
_name
=
name
self
.
getint
=
functools
.
partial
(
self
.
_parser
.
getint
,
self
.
_name
)
self
.
getfloat
=
functools
.
partial
(
self
.
_parser
.
getfloat
,
self
.
_name
)
self
.
getboolean
=
functools
.
partial
(
self
.
_parser
.
getboolean
,
self
.
_name
)
def
__repr__
(
self
):
return
'<Section: {}>'
.
format
(
self
.
_name
)
...
...
@@ -1231,6 +1225,22 @@ class SectionProxy(MutableMapping):
# XXX does not break when underlying container state changed
return
self
.
_parser
.
options
(
self
.
_name
)
.
__iter__
()
def
get
(
self
,
option
,
fallback
=
None
,
*
,
raw
=
False
,
vars
=
None
):
return
self
.
_parser
.
get
(
self
.
_name
,
option
,
raw
=
raw
,
vars
=
vars
,
fallback
=
fallback
)
def
getint
(
self
,
option
,
fallback
=
None
,
*
,
raw
=
False
,
vars
=
None
):
return
self
.
_parser
.
getint
(
self
.
_name
,
option
,
raw
=
raw
,
vars
=
vars
,
fallback
=
fallback
)
def
getfloat
(
self
,
option
,
fallback
=
None
,
*
,
raw
=
False
,
vars
=
None
):
return
self
.
_parser
.
getfloat
(
self
.
_name
,
option
,
raw
=
raw
,
vars
=
vars
,
fallback
=
fallback
)
def
getboolean
(
self
,
option
,
fallback
=
None
,
*
,
raw
=
False
,
vars
=
None
):
return
self
.
_parser
.
getboolean
(
self
.
_name
,
option
,
raw
=
raw
,
vars
=
vars
,
fallback
=
fallback
)
@property
def
parser
(
self
):
# The parser object of the proxy is read-only.
...
...
Lib/test/test_cfgparser.py
Dosyayı görüntüle @
2f0fd0fa
...
...
@@ -160,6 +160,49 @@ class BasicTestCase(CfgParserTestCaseClass):
'this line is much, much longer than my editor
\n
likes it.'
)
if
self
.
allow_no_value
:
eq
(
cf
[
'NoValue'
][
'option-without-value'
],
None
)
# test vars= and fallback=
eq
(
cf
[
'Foo Bar'
]
.
get
(
'foo'
,
'baz'
),
'bar1'
)
eq
(
cf
[
'Foo Bar'
]
.
get
(
'foo'
,
fallback
=
'baz'
),
'bar1'
)
eq
(
cf
[
'Foo Bar'
]
.
get
(
'foo'
,
vars
=
{
'foo'
:
'baz'
}),
'baz'
)
with
self
.
assertRaises
(
KeyError
):
cf
[
'No Such Foo Bar'
][
'foo'
]
with
self
.
assertRaises
(
KeyError
):
cf
[
'Foo Bar'
][
'no-such-foo'
]
with
self
.
assertRaises
(
KeyError
):
cf
[
'No Such Foo Bar'
]
.
get
(
'foo'
,
fallback
=
'baz'
)
eq
(
cf
[
'Foo Bar'
]
.
get
(
'no-such-foo'
,
'baz'
),
'baz'
)
eq
(
cf
[
'Foo Bar'
]
.
get
(
'no-such-foo'
,
fallback
=
'baz'
),
'baz'
)
eq
(
cf
[
'Spacey Bar'
]
.
get
(
'foo'
,
None
),
'bar2'
)
eq
(
cf
[
'Spacey Bar'
]
.
get
(
'foo'
,
fallback
=
None
),
'bar2'
)
with
self
.
assertRaises
(
KeyError
):
cf
[
'No Such Spacey Bar'
]
.
get
(
'foo'
,
None
)
eq
(
cf
[
'Types'
]
.
getint
(
'int'
,
18
),
42
)
eq
(
cf
[
'Types'
]
.
getint
(
'int'
,
fallback
=
18
),
42
)
eq
(
cf
[
'Types'
]
.
getint
(
'no-such-int'
,
18
),
18
)
eq
(
cf
[
'Types'
]
.
getint
(
'no-such-int'
,
fallback
=
18
),
18
)
eq
(
cf
[
'Types'
]
.
getint
(
'no-such-int'
,
"18"
),
"18"
)
# sic!
eq
(
cf
[
'Types'
]
.
getint
(
'no-such-int'
,
fallback
=
"18"
),
"18"
)
# sic!
self
.
assertAlmostEqual
(
cf
[
'Types'
]
.
getfloat
(
'float'
,
0.0
),
0.44
)
self
.
assertAlmostEqual
(
cf
[
'Types'
]
.
getfloat
(
'float'
,
fallback
=
0.0
),
0.44
)
self
.
assertAlmostEqual
(
cf
[
'Types'
]
.
getfloat
(
'no-such-float'
,
0.0
),
0.0
)
self
.
assertAlmostEqual
(
cf
[
'Types'
]
.
getfloat
(
'no-such-float'
,
fallback
=
0.0
),
0.0
)
eq
(
cf
[
'Types'
]
.
getfloat
(
'no-such-float'
,
"0.0"
),
"0.0"
)
# sic!
eq
(
cf
[
'Types'
]
.
getfloat
(
'no-such-float'
,
fallback
=
"0.0"
),
"0.0"
)
# sic!
eq
(
cf
[
'Types'
]
.
getboolean
(
'boolean'
,
True
),
False
)
eq
(
cf
[
'Types'
]
.
getboolean
(
'boolean'
,
fallback
=
True
),
False
)
eq
(
cf
[
'Types'
]
.
getboolean
(
'no-such-boolean'
,
"yes"
),
"yes"
)
# sic!
eq
(
cf
[
'Types'
]
.
getboolean
(
'no-such-boolean'
,
fallback
=
"yes"
),
"yes"
)
# sic!
eq
(
cf
[
'Types'
]
.
getboolean
(
'no-such-boolean'
,
True
),
True
)
eq
(
cf
[
'Types'
]
.
getboolean
(
'no-such-boolean'
,
fallback
=
True
),
True
)
if
self
.
allow_no_value
:
eq
(
cf
[
'NoValue'
]
.
get
(
'option-without-value'
,
False
),
None
)
eq
(
cf
[
'NoValue'
]
.
get
(
'option-without-value'
,
fallback
=
False
),
None
)
eq
(
cf
[
'NoValue'
]
.
get
(
'no-such-option-without-value'
,
False
),
False
)
eq
(
cf
[
'NoValue'
]
.
get
(
'no-such-option-without-value'
,
fallback
=
False
),
False
)
# Make sure the right things happen for remove_option();
# added to include check for SourceForge bug #123324:
...
...
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