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
1fa36268
Kaydet (Commit)
1fa36268
authored
Agu 24, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #22034: Improve handling of wrong argument types in posixpath.join().
üst
66106626
549c1972
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
posixpath.py
Lib/posixpath.py
+7
-8
test_posixpath.py
Lib/test/test_posixpath.py
+13
-13
No files found.
Lib/posixpath.py
Dosyayı görüntüle @
1fa36268
...
@@ -82,14 +82,13 @@ def join(a, *p):
...
@@ -82,14 +82,13 @@ def join(a, *p):
path
+=
b
path
+=
b
else
:
else
:
path
+=
sep
+
b
path
+=
sep
+
b
except
TypeError
:
except
(
TypeError
,
AttributeError
):
valid_types
=
all
(
isinstance
(
s
,
(
str
,
bytes
,
bytearray
))
for
s
in
(
a
,)
+
p
:
for
s
in
(
a
,
)
+
p
)
if
not
isinstance
(
s
,
(
str
,
bytes
)):
if
valid_types
:
raise
TypeError
(
'join() argument must be str or bytes, not
%
r'
%
# Must have a mixture of text and binary data
s
.
__class__
.
__name__
)
from
None
raise
TypeError
(
"Can't mix strings and bytes in path "
# Must have a mixture of text and binary data
"components."
)
from
None
raise
TypeError
(
"Can't mix strings and bytes in path components"
)
from
None
raise
return
path
return
path
...
...
Lib/test/test_posixpath.py
Dosyayı görüntüle @
1fa36268
...
@@ -57,21 +57,21 @@ class PosixPathTest(unittest.TestCase):
...
@@ -57,21 +57,21 @@ class PosixPathTest(unittest.TestCase):
self
.
assertEqual
(
posixpath
.
join
(
b
"/foo/"
,
b
"bar/"
,
b
"baz/"
),
self
.
assertEqual
(
posixpath
.
join
(
b
"/foo/"
,
b
"bar/"
,
b
"baz/"
),
b
"/foo/bar/baz/"
)
b
"/foo/bar/baz/"
)
def
check_error_msg
(
list_of_args
,
msg
):
def
test_join_errors
(
self
):
"""Check posixpath.join raises friendly TypeErrors."""
# Check posixpath.join raises friendly TypeErrors.
for
args
in
(
item
for
perm
in
list_of_args
errmsg
=
"Can't mix strings and bytes in path components"
for
item
in
itertools
.
permutations
(
perm
)):
with
self
.
assertRaisesRegex
(
TypeError
,
errmsg
):
with
self
.
assertRaises
(
TypeError
)
as
cm
:
posixpath
.
join
(
b
'bytes'
,
'str'
)
posixpath
.
join
(
*
args
)
with
self
.
assertRaisesRegex
(
TypeError
,
errmsg
):
self
.
assertEqual
(
msg
,
cm
.
exception
.
args
[
0
])
posixpath
.
join
(
'str'
,
b
'bytes'
)
check_error_msg
([[
b
'bytes'
,
'str'
],
[
bytearray
(
b
'bytes'
),
'str'
]],
"Can't mix strings and bytes in path components."
)
# regression, see #15377
# regression, see #15377
with
self
.
assertRaises
(
TypeError
)
as
cm
:
errmsg
=
r'join\(\) argument must be str or bytes, not
%
r'
with
self
.
assertRaisesRegex
(
TypeError
,
errmsg
%
'NoneType'
):
posixpath
.
join
(
None
,
'str'
)
posixpath
.
join
(
None
,
'str'
)
self
.
assertNotEqual
(
"Can't mix strings and bytes in path components."
,
with
self
.
assertRaisesRegex
(
TypeError
,
errmsg
%
'NoneType'
):
cm
.
exception
.
args
[
0
])
posixpath
.
join
(
'str'
,
None
)
with
self
.
assertRaisesRegex
(
TypeError
,
errmsg
%
'bytearray'
):
posixpath
.
join
(
bytearray
(
b
'foo'
),
bytearray
(
b
'bar'
))
def
test_split
(
self
):
def
test_split
(
self
):
self
.
assertEqual
(
posixpath
.
split
(
"/foo/bar"
),
(
"/foo"
,
"bar"
))
self
.
assertEqual
(
posixpath
.
split
(
"/foo/bar"
),
(
"/foo"
,
"bar"
))
...
...
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