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
33dc0a17
Kaydet (Commit)
33dc0a17
authored
Tem 27, 2001
tarafından
Tim Peters
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
One more crack at join(): stop trying to pretend this isn't a mass of
special cases. test_pkg works again on Windows.
üst
4223f89e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
16 deletions
+47
-16
ntpath.py
Lib/ntpath.py
+40
-16
test_ntpath.py
Lib/test/test_ntpath.py
+7
-0
No files found.
Lib/ntpath.py
Dosyayı görüntüle @
33dc0a17
...
...
@@ -42,22 +42,46 @@ def join(a, *p):
"""Join two or more pathname components, inserting "
\\
" as needed"""
path
=
a
for
b
in
p
:
# If path starts with a raw drive letter (e.g. "C:"), and b doesn't
# start with a drive letter, path+b is correct, and regardless of\
# whether b is absolute on its own.
if
len
(
path
)
>=
2
and
path
[
1
]
==
":"
and
splitdrive
(
b
)[
0
]
==
""
:
if
path
[
-
1
]
in
"/
\\
"
and
b
[:
1
]
in
"/
\\
"
:
b
=
b
[
1
:]
# In any other case, if b is absolute it wipes out the path so far.
elif
isabs
(
b
)
or
path
==
""
:
path
=
""
# Else make sure a separator appears between the pieces.
elif
path
[
-
1
:]
not
in
"/
\\
"
:
b
=
"
\\
"
+
b
path
+=
b
b_wins
=
0
# set to 1 iff b makes path irrelevant
if
path
==
""
:
b_wins
=
1
elif
isabs
(
b
):
# This probably wipes out path so far. However, it's more
# complicated if path begins with a drive letter:
# 1. join('c:', '/a') == 'c:/a'
# 2. join('c:/', '/a') == 'c:/a'
# But
# 3. join('c:/a', '/b') == '/b'
# 4. join('c:', 'd:/') = 'd:/'
# 5. join('c:/', 'd:/') = 'd:/'
if
path
[
1
:
2
]
!=
":"
or
b
[
1
:
2
]
==
":"
:
# Path doesn't start with a drive letter, or cases 4 and 5.
b_wins
=
1
# Else path has a drive letter, and b doesn't but is absolute.
elif
len
(
path
)
>
3
or
(
len
(
path
)
==
3
and
path
[
-
1
]
not
in
"/
\\
"
):
# case 3
b_wins
=
1
if
b_wins
:
path
=
b
else
:
# Join, and ensure there's a separator.
assert
len
(
path
)
>
0
if
path
[
-
1
]
in
"/
\\
"
:
if
b
and
b
[
0
]
in
"/
\\
"
:
path
+=
b
[
1
:]
else
:
path
+=
b
elif
path
[
-
1
]
==
":"
:
path
+=
b
elif
b
:
if
b
[
0
]
in
"/
\\
"
:
path
+=
b
else
:
path
+=
"
\\
"
+
b
return
path
...
...
Lib/test/test_ntpath.py
Dosyayı görüntüle @
33dc0a17
...
...
@@ -66,6 +66,13 @@ tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
tester
(
'ntpath.join("a", "b
\\
", "c")'
,
'a
\\
b
\\
c'
)
tester
(
'ntpath.join("a", "b", "
\\
c")'
,
'
\\
c'
)
tester
(
'ntpath.join("d:
\\
", "
\\
pleep")'
,
'd:
\\
pleep'
)
tester
(
'ntpath.join("d:
\\
", "a", "b")'
,
'd:
\\
a
\\
b'
)
tester
(
"ntpath.join('c:', '/a')"
,
'c:/a'
)
tester
(
"ntpath.join('c:/', '/a')"
,
'c:/a'
)
tester
(
"ntpath.join('c:/a', '/b')"
,
'/b'
)
tester
(
"ntpath.join('c:', 'd:/')"
,
'd:/'
)
tester
(
"ntpath.join('c:/', 'd:/')"
,
'd:/'
)
tester
(
"ntpath.join('c:/', 'd:/a/b')"
,
'd:/a/b'
)
if
errors
:
raise
TestFailed
(
str
(
errors
)
+
" errors."
)
...
...
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