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
cba24321
Kaydet (Commit)
cba24321
authored
Tem 07, 2012
tarafından
Łukasz Langa
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixes #14590: ConfigParser doesn't strip inline comment when delimiter occurs
earlier without preceding space.
üst
d94adb73
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
6 deletions
+51
-6
configparser.py
Lib/configparser.py
+14
-6
test_configparser.py
Lib/test/test_configparser.py
+37
-0
No files found.
Lib/configparser.py
Dosyayı görüntüle @
cba24321
...
@@ -993,18 +993,26 @@ class RawConfigParser(MutableMapping):
...
@@ -993,18 +993,26 @@ class RawConfigParser(MutableMapping):
indent_level
=
0
indent_level
=
0
e
=
None
# None, or an exception
e
=
None
# None, or an exception
for
lineno
,
line
in
enumerate
(
fp
,
start
=
1
):
for
lineno
,
line
in
enumerate
(
fp
,
start
=
1
):
comment_start
=
Non
e
comment_start
=
sys
.
maxsiz
e
# strip inline comments
# strip inline comments
for
prefix
in
self
.
_inline_comment_prefixes
:
inline_prefixes
=
{
p
:
-
1
for
p
in
self
.
_inline_comment_prefixes
}
index
=
line
.
find
(
prefix
)
while
comment_start
==
sys
.
maxsize
and
inline_prefixes
:
if
index
==
0
or
(
index
>
0
and
line
[
index
-
1
]
.
isspace
()):
next_prefixes
=
{}
comment_start
=
index
for
prefix
,
index
in
inline_prefixes
.
items
():
break
index
=
line
.
find
(
prefix
,
index
+
1
)
if
index
==
-
1
:
continue
next_prefixes
[
prefix
]
=
index
if
index
==
0
or
(
index
>
0
and
line
[
index
-
1
]
.
isspace
()):
comment_start
=
min
(
comment_start
,
index
)
inline_prefixes
=
next_prefixes
# strip full line comments
# strip full line comments
for
prefix
in
self
.
_comment_prefixes
:
for
prefix
in
self
.
_comment_prefixes
:
if
line
.
strip
()
.
startswith
(
prefix
):
if
line
.
strip
()
.
startswith
(
prefix
):
comment_start
=
0
comment_start
=
0
break
break
if
comment_start
==
sys
.
maxsize
:
comment_start
=
None
value
=
line
[:
comment_start
]
.
strip
()
value
=
line
[:
comment_start
]
.
strip
()
if
not
value
:
if
not
value
:
if
self
.
_empty_lines_in_values
:
if
self
.
_empty_lines_in_values
:
...
...
Lib/test/test_configparser.py
Dosyayı görüntüle @
cba24321
...
@@ -1618,6 +1618,42 @@ class ExceptionPicklingTestCase(unittest.TestCase):
...
@@ -1618,6 +1618,42 @@ class ExceptionPicklingTestCase(unittest.TestCase):
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
class
InlineCommentStrippingTestCase
(
unittest
.
TestCase
):
"""Tests for issue #14590: ConfigParser doesn't strip inline comment when
delimiter occurs earlier without preceding space.."""
def
test_stripping
(
self
):
cfg
=
configparser
.
ConfigParser
(
inline_comment_prefixes
=
(
';'
,
'#'
,
'//'
))
cfg
.
read_string
(
"""
[section]
k1 = v1;still v1
k2 = v2 ;a comment
k3 = v3 ; also a comment
k4 = v4;still v4 ;a comment
k5 = v5;still v5 ; also a comment
k6 = v6;still v6; and still v6 ;a comment
k7 = v7;still v7; and still v7 ; also a comment
[multiprefix]
k1 = v1;still v1 #a comment ; yeah, pretty much
k2 = v2 // this already is a comment ; continued
k3 = v3;#//still v3# and still v3 ; a comment
"""
)
s
=
cfg
[
'section'
]
self
.
assertEqual
(
s
[
'k1'
],
'v1;still v1'
)
self
.
assertEqual
(
s
[
'k2'
],
'v2'
)
self
.
assertEqual
(
s
[
'k3'
],
'v3'
)
self
.
assertEqual
(
s
[
'k4'
],
'v4;still v4'
)
self
.
assertEqual
(
s
[
'k5'
],
'v5;still v5'
)
self
.
assertEqual
(
s
[
'k6'
],
'v6;still v6; and still v6'
)
self
.
assertEqual
(
s
[
'k7'
],
'v7;still v7; and still v7'
)
s
=
cfg
[
'multiprefix'
]
self
.
assertEqual
(
s
[
'k1'
],
'v1;still v1'
)
self
.
assertEqual
(
s
[
'k2'
],
'v2'
)
self
.
assertEqual
(
s
[
'k3'
],
'v3;#//still v3# and still v3'
)
def
test_main
():
def
test_main
():
support
.
run_unittest
(
support
.
run_unittest
(
ConfigParserTestCase
,
ConfigParserTestCase
,
...
@@ -1640,4 +1676,5 @@ def test_main():
...
@@ -1640,4 +1676,5 @@ def test_main():
ReadFileTestCase
,
ReadFileTestCase
,
CoverageOneHundredTestCase
,
CoverageOneHundredTestCase
,
ExceptionPicklingTestCase
,
ExceptionPicklingTestCase
,
InlineCommentStrippingTestCase
,
)
)
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