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
e698cd54
Kaydet (Commit)
e698cd54
authored
Nis 28, 2011
tarafından
Łukasz Langa
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes #11858: configparser.ExtendedInterpolation and section case.
Patch by ゆかり ぴんく魔女. Thanks!
üst
8a410d31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
6 deletions
+72
-6
configparser.py
Lib/configparser.py
+5
-3
test_cfgparser.py
Lib/test/test_cfgparser.py
+67
-3
No files found.
Lib/configparser.py
Dosyayı görüntüle @
e698cd54
...
...
@@ -481,17 +481,17 @@ class ExtendedInterpolation(Interpolation):
if
m
is
None
:
raise
InterpolationSyntaxError
(
option
,
section
,
"bad interpolation variable reference
%
r"
%
rest
)
path
=
parser
.
optionxform
(
m
.
group
(
1
)
)
.
split
(
':'
)
path
=
m
.
group
(
1
)
.
split
(
':'
)
rest
=
rest
[
m
.
end
():]
sect
=
section
opt
=
option
try
:
if
len
(
path
)
==
1
:
opt
=
pa
th
[
0
]
opt
=
pa
rser
.
optionxform
(
path
[
0
])
v
=
map
[
opt
]
elif
len
(
path
)
==
2
:
sect
=
path
[
0
]
opt
=
pa
th
[
1
]
opt
=
pa
rser
.
optionxform
(
path
[
1
])
v
=
parser
.
get
(
sect
,
opt
,
raw
=
True
)
else
:
raise
InterpolationSyntaxError
(
...
...
@@ -1056,6 +1056,8 @@ class RawConfigParser(MutableMapping):
if
not
optname
:
e
=
self
.
_handle_error
(
e
,
fpname
,
lineno
,
line
)
optname
=
self
.
optionxform
(
optname
.
rstrip
())
if
hasattr
(
self
,
'__ping__'
):
import
pdb
;
pdb
.
set_trace
()
if
(
self
.
_strict
and
(
sectname
,
optname
)
in
elements_added
):
raise
DuplicateOptionError
(
sectname
,
optname
,
...
...
Lib/test/test_cfgparser.py
Dosyayı görüntüle @
e698cd54
...
...
@@ -20,10 +20,16 @@ class SortedDict(collections.UserDict):
def
values
(
self
):
return
[
i
[
1
]
for
i
in
self
.
items
()]
def
iteritems
(
self
):
return
iter
(
self
.
items
())
def
iterkeys
(
self
):
return
iter
(
self
.
keys
())
def
iteritems
(
self
):
return
iter
(
self
.
items
())
def
iterkeys
(
self
):
return
iter
(
self
.
keys
())
def
itervalues
(
self
):
return
iter
(
self
.
values
())
__iter__
=
iterkeys
def
itervalues
(
self
):
return
iter
(
self
.
values
())
class
CfgParserTestCaseClass
(
unittest
.
TestCase
):
...
...
@@ -986,6 +992,14 @@ class ConfigParserTestCaseExtendedInterpolation(BasicTestCase):
config_class
=
configparser
.
ConfigParser
interpolation
=
configparser
.
ExtendedInterpolation
()
default_section
=
'common'
strict
=
True
def
fromstring
(
self
,
string
,
defaults
=
None
,
optionxform
=
None
):
cf
=
self
.
newconfig
(
defaults
)
if
optionxform
:
cf
.
optionxform
=
optionxform
cf
.
read_string
(
string
)
return
cf
def
test_extended_interpolation
(
self
):
cf
=
self
.
fromstring
(
textwrap
.
dedent
(
"""
...
...
@@ -1070,6 +1084,56 @@ class ConfigParserTestCaseExtendedInterpolation(BasicTestCase):
self
.
assertEqual
(
cm
.
exception
.
reference
,
'dollars:${sick'
)
self
.
assertEqual
(
cm
.
exception
.
args
[
2
],
'}'
)
#rawval
def
test_case_sensitivity_basic
(
self
):
ini
=
textwrap
.
dedent
(
"""
[common]
optionlower = value
OptionUpper = Value
[Common]
optionlower = a better ${common:optionlower}
OptionUpper = A Better ${common:OptionUpper}
[random]
foolower = ${common:optionlower} redefined
FooUpper = ${Common:OptionUpper} Redefined
"""
)
.
strip
()
cf
=
self
.
fromstring
(
ini
)
eq
=
self
.
assertEqual
eq
(
cf
[
'common'
][
'optionlower'
],
'value'
)
eq
(
cf
[
'common'
][
'OptionUpper'
],
'Value'
)
eq
(
cf
[
'Common'
][
'optionlower'
],
'a better value'
)
eq
(
cf
[
'Common'
][
'OptionUpper'
],
'A Better Value'
)
eq
(
cf
[
'random'
][
'foolower'
],
'value redefined'
)
eq
(
cf
[
'random'
][
'FooUpper'
],
'A Better Value Redefined'
)
def
test_case_sensitivity_conflicts
(
self
):
ini
=
textwrap
.
dedent
(
"""
[common]
option = value
Option = Value
[Common]
option = a better ${common:option}
Option = A Better ${common:Option}
[random]
foo = ${common:option} redefined
Foo = ${Common:Option} Redefined
"""
)
.
strip
()
with
self
.
assertRaises
(
configparser
.
DuplicateOptionError
):
cf
=
self
.
fromstring
(
ini
)
# raw options
cf
=
self
.
fromstring
(
ini
,
optionxform
=
lambda
opt
:
opt
)
eq
=
self
.
assertEqual
eq
(
cf
[
'common'
][
'option'
],
'value'
)
eq
(
cf
[
'common'
][
'Option'
],
'Value'
)
eq
(
cf
[
'Common'
][
'option'
],
'a better value'
)
eq
(
cf
[
'Common'
][
'Option'
],
'A Better Value'
)
eq
(
cf
[
'random'
][
'foo'
],
'value redefined'
)
eq
(
cf
[
'random'
][
'Foo'
],
'A Better Value Redefined'
)
def
test_other_errors
(
self
):
cf
=
self
.
fromstring
(
"""
...
...
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