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
2dae7646
Kaydet (Commit)
2dae7646
authored
Kas 12, 2004
tarafından
Just van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
On second thought: "Errors should never pass silently", so barf when a
string contains control chars that are illegal for XML
üst
48ecaccf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
plistlib.py
Lib/plat-mac/plistlib.py
+6
-3
test_plistlib.py
Lib/test/test_plistlib.py
+10
-7
No files found.
Lib/plat-mac/plistlib.py
Dosyayı görüntüle @
2dae7646
...
...
@@ -200,18 +200,21 @@ def _dateToString(d):
)
# Regex to
strip all control chars, bu
t for \t \n and \r
_control
Stripper
=
re
.
compile
(
# Regex to
find any control chars, excep
t for \t \n and \r
_control
CharPat
=
re
.
compile
(
r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]"
)
def
_escapeAndEncode
(
text
):
m
=
_controlCharPat
.
search
(
text
)
if
m
is
not
None
:
raise
ValueError
(
"strings can't contains control characters; "
"use plistlib.Data instead"
)
text
=
text
.
replace
(
"
\r\n
"
,
"
\n
"
)
# convert DOS line endings
text
=
text
.
replace
(
"
\r
"
,
"
\n
"
)
# convert Mac line endings
text
=
text
.
replace
(
"&"
,
"&"
)
# escape '&'
text
=
text
.
replace
(
"<"
,
"<"
)
# escape '<'
text
=
text
.
replace
(
">"
,
">"
)
# escape '>'
text
=
_controlStripper
.
sub
(
"?"
,
text
)
# replace control chars with '?'
return
text
.
encode
(
"utf-8"
)
# encode as UTF-8
...
...
Lib/test/test_plistlib.py
Dosyayı görüntüle @
2dae7646
...
...
@@ -165,13 +165,16 @@ class TestPlistlib(unittest.TestCase):
self
.
assertEqual
(
dict
(
pl
),
dict
(
pl2
))
def
test_controlcharacters
(
self
):
# chars in the range 0..31 are replaced by '?', except for
# \r, \n and \t since they aren't legal XML characters
testString
=
""
.
join
([
chr
(
i
)
for
i
in
range
(
32
)])
expectedResult
=
'?????????
\t\n
??
\n
??????????????????'
xml
=
plistlib
.
writePlistToString
(
testString
)
result
=
plistlib
.
readPlistFromString
(
xml
)
self
.
assertEqual
(
result
,
expectedResult
)
for
i
in
range
(
128
):
c
=
chr
(
i
)
testString
=
"string containing
%
s"
%
c
if
i
>=
32
or
c
in
"
\r\n\t
"
:
# \r, \n and \t are the only legal control chars in XML
plistlib
.
writePlistToString
(
testString
)
else
:
self
.
assertRaises
(
ValueError
,
plistlib
.
writePlistToString
,
testString
)
def
test_nondictroot
(
self
):
test1
=
"abc"
...
...
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