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
05c075d6
Kaydet (Commit)
05c075d6
authored
Mar 07, 2007
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
üst
f08c073d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
40 deletions
+69
-40
libposixpath.tex
Doc/lib/libposixpath.tex
+6
-1
genericpath.py
Lib/genericpath.py
+29
-0
macpath.py
Lib/macpath.py
+3
-11
ntpath.py
Lib/ntpath.py
+3
-10
posixpath.py
Lib/posixpath.py
+3
-8
test_macpath.py
Lib/test/test_macpath.py
+1
-1
test_ntpath.py
Lib/test/test_ntpath.py
+2
-1
test_posixpath.py
Lib/test/test_posixpath.py
+20
-8
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/lib/libposixpath.tex
Dosyayı görüntüle @
05c075d6
...
@@ -234,7 +234,12 @@ empty string. On systems which do not use drive specifications,
...
@@ -234,7 +234,12 @@ empty string. On systems which do not use drive specifications,
Split the pathname
\var
{
path
}
into a pair
\code
{
(
\var
{
root
}
,
\var
{
ext
}
)
}
Split the pathname
\var
{
path
}
into a pair
\code
{
(
\var
{
root
}
,
\var
{
ext
}
)
}
such that
\code
{
\var
{
root
}
+
\var
{
ext
}
==
\var
{
path
}}
,
such that
\code
{
\var
{
root
}
+
\var
{
ext
}
==
\var
{
path
}}
,
and
\var
{
ext
}
is empty or begins with a period and contains
and
\var
{
ext
}
is empty or begins with a period and contains
at most one period.
at most one period. Leading periods on the basename are
ignored;
\code
{
\var
{
splitext
}
.('.cshrc')
}
returns
\code
{
('.cshrc', '')
}
.
\versionchanged
[Earlier versions could produce an empty root when
the only period was the first character]
{
2.6
}
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
splitunc
}{
path
}
\begin{funcdesc}
{
splitunc
}{
path
}
...
...
Lib/genericpath.py
Dosyayı görüntüle @
05c075d6
...
@@ -75,3 +75,32 @@ def commonprefix(m):
...
@@ -75,3 +75,32 @@ def commonprefix(m):
if
s1
[
i
]
!=
s2
[
i
]:
if
s1
[
i
]
!=
s2
[
i
]:
return
s1
[:
i
]
return
s1
[:
i
]
return
s1
[:
n
]
return
s1
[:
n
]
# Split a path in root and extension.
# The extension is everything starting at the last dot in the last
# pathname component; the root is everything before that.
# It is always true that root + ext == p.
# Generic implementation of splitext, to be parametrized with
# the separators
def
_splitext
(
p
,
sep
,
altsep
,
extsep
):
"""Split the extension from a pathname.
Extension is everything from the last dot to the end, ignoring
leading dots. Returns "(root, ext)"; ext may be empty."""
sepIndex
=
p
.
rfind
(
sep
)
if
altsep
:
altsepIndex
=
p
.
rfind
(
altsep
)
sepIndex
=
max
(
sepIndex
,
altsepIndex
)
dotIndex
=
p
.
rfind
(
extsep
)
if
dotIndex
>
sepIndex
:
# skip all leading dots
filenameIndex
=
sepIndex
+
1
while
filenameIndex
<
dotIndex
:
if
p
[
filenameIndex
]
!=
extsep
:
return
p
[:
dotIndex
],
p
[
dotIndex
:]
filenameIndex
+=
1
return
p
,
''
Lib/macpath.py
Dosyayı görüntüle @
05c075d6
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
os
import
os
from
stat
import
*
from
stat
import
*
import
genericpath
from
genericpath
import
*
from
genericpath
import
*
__all__
=
[
"normcase"
,
"isabs"
,
"join"
,
"splitdrive"
,
"split"
,
"splitext"
,
__all__
=
[
"normcase"
,
"isabs"
,
"join"
,
"splitdrive"
,
"split"
,
"splitext"
,
...
@@ -69,17 +70,8 @@ def split(s):
...
@@ -69,17 +70,8 @@ def split(s):
def
splitext
(
p
):
def
splitext
(
p
):
"""Split a path into root and extension.
return
genericpath
.
_splitext
(
p
,
sep
,
altsep
,
extsep
)
The extension is everything starting at the last dot in the last
splitext
.
__doc__
=
genericpath
.
_splitext
.
__doc__
pathname component; the root is everything before that.
It is always true that root + ext == p."""
i
=
p
.
rfind
(
'.'
)
if
i
<=
p
.
rfind
(
':'
):
return
p
,
''
else
:
return
p
[:
i
],
p
[
i
:]
def
splitdrive
(
p
):
def
splitdrive
(
p
):
"""Split a pathname into a drive specification and the rest of the
"""Split a pathname into a drive specification and the rest of the
...
...
Lib/ntpath.py
Dosyayı görüntüle @
05c075d6
...
@@ -8,6 +8,7 @@ module as os.path.
...
@@ -8,6 +8,7 @@ module as os.path.
import
os
import
os
import
stat
import
stat
import
sys
import
sys
import
genericpath
from
genericpath
import
*
from
genericpath
import
*
__all__
=
[
"normcase"
,
"isabs"
,
"join"
,
"splitdrive"
,
"split"
,
"splitext"
,
__all__
=
[
"normcase"
,
"isabs"
,
"join"
,
"splitdrive"
,
"split"
,
"splitext"
,
...
@@ -182,16 +183,8 @@ def split(p):
...
@@ -182,16 +183,8 @@ def split(p):
# It is always true that root + ext == p.
# It is always true that root + ext == p.
def
splitext
(
p
):
def
splitext
(
p
):
"""Split the extension from a pathname.
return
genericpath
.
_splitext
(
p
,
sep
,
altsep
,
extsep
)
splitext
.
__doc__
=
genericpath
.
_splitext
.
__doc__
Extension is everything from the last dot to the end.
Return (root, ext), either part may be empty."""
i
=
p
.
rfind
(
'.'
)
if
i
<=
max
(
p
.
rfind
(
'/'
),
p
.
rfind
(
'
\\
'
)):
return
p
,
''
else
:
return
p
[:
i
],
p
[
i
:]
# Return the tail (basename) part of a path.
# Return the tail (basename) part of a path.
...
...
Lib/posixpath.py
Dosyayı görüntüle @
05c075d6
...
@@ -12,6 +12,7 @@ for manipulation of the pathname component of URLs.
...
@@ -12,6 +12,7 @@ for manipulation of the pathname component of URLs.
import
os
import
os
import
stat
import
stat
import
genericpath
from
genericpath
import
*
from
genericpath
import
*
__all__
=
[
"normcase"
,
"isabs"
,
"join"
,
"splitdrive"
,
"split"
,
"splitext"
,
__all__
=
[
"normcase"
,
"isabs"
,
"join"
,
"splitdrive"
,
"split"
,
"splitext"
,
...
@@ -88,14 +89,8 @@ def split(p):
...
@@ -88,14 +89,8 @@ def split(p):
# It is always true that root + ext == p.
# It is always true that root + ext == p.
def
splitext
(
p
):
def
splitext
(
p
):
"""Split the extension from a pathname. Extension is everything from the
return
genericpath
.
_splitext
(
p
,
sep
,
altsep
,
extsep
)
last dot to the end. Returns "(root, ext)", either part may be empty."""
splitext
.
__doc__
=
genericpath
.
_splitext
.
__doc__
i
=
p
.
rfind
(
'.'
)
if
i
<=
p
.
rfind
(
'/'
):
return
p
,
''
else
:
return
p
[:
i
],
p
[
i
:]
# Split a pathname into a drive specification and the rest of the
# Split a pathname into a drive specification and the rest of the
# path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
# path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
...
...
Lib/test/test_macpath.py
Dosyayı görüntüle @
05c075d6
...
@@ -48,7 +48,7 @@ class MacPathTestCase(unittest.TestCase):
...
@@ -48,7 +48,7 @@ class MacPathTestCase(unittest.TestCase):
splitext
=
macpath
.
splitext
splitext
=
macpath
.
splitext
self
.
assertEquals
(
splitext
(
":foo.ext"
),
(
':foo'
,
'.ext'
))
self
.
assertEquals
(
splitext
(
":foo.ext"
),
(
':foo'
,
'.ext'
))
self
.
assertEquals
(
splitext
(
"foo:foo.ext"
),
(
'foo:foo'
,
'.ext'
))
self
.
assertEquals
(
splitext
(
"foo:foo.ext"
),
(
'foo:foo'
,
'.ext'
))
self
.
assertEquals
(
splitext
(
".ext"
),
(
'
'
,
'.ext
'
))
self
.
assertEquals
(
splitext
(
".ext"
),
(
'
.ext'
,
'
'
))
self
.
assertEquals
(
splitext
(
"foo.ext:foo"
),
(
'foo.ext:foo'
,
''
))
self
.
assertEquals
(
splitext
(
"foo.ext:foo"
),
(
'foo.ext:foo'
,
''
))
self
.
assertEquals
(
splitext
(
":foo.ext:"
),
(
':foo.ext:'
,
''
))
self
.
assertEquals
(
splitext
(
":foo.ext:"
),
(
':foo.ext:'
,
''
))
self
.
assertEquals
(
splitext
(
""
),
(
''
,
''
))
self
.
assertEquals
(
splitext
(
""
),
(
''
,
''
))
...
...
Lib/test/test_ntpath.py
Dosyayı görüntüle @
05c075d6
...
@@ -18,13 +18,14 @@ def tester(fn, wantResult):
...
@@ -18,13 +18,14 @@ def tester(fn, wantResult):
tester
(
'ntpath.splitext("foo.ext")'
,
(
'foo'
,
'.ext'
))
tester
(
'ntpath.splitext("foo.ext")'
,
(
'foo'
,
'.ext'
))
tester
(
'ntpath.splitext("/foo/foo.ext")'
,
(
'/foo/foo'
,
'.ext'
))
tester
(
'ntpath.splitext("/foo/foo.ext")'
,
(
'/foo/foo'
,
'.ext'
))
tester
(
'ntpath.splitext(".ext")'
,
(
'
'
,
'.ext
'
))
tester
(
'ntpath.splitext(".ext")'
,
(
'
.ext'
,
'
'
))
tester
(
'ntpath.splitext("
\\
foo.ext
\\
foo")'
,
(
'
\\
foo.ext
\\
foo'
,
''
))
tester
(
'ntpath.splitext("
\\
foo.ext
\\
foo")'
,
(
'
\\
foo.ext
\\
foo'
,
''
))
tester
(
'ntpath.splitext("foo.ext
\\
")'
,
(
'foo.ext
\\
'
,
''
))
tester
(
'ntpath.splitext("foo.ext
\\
")'
,
(
'foo.ext
\\
'
,
''
))
tester
(
'ntpath.splitext("")'
,
(
''
,
''
))
tester
(
'ntpath.splitext("")'
,
(
''
,
''
))
tester
(
'ntpath.splitext("foo.bar.ext")'
,
(
'foo.bar'
,
'.ext'
))
tester
(
'ntpath.splitext("foo.bar.ext")'
,
(
'foo.bar'
,
'.ext'
))
tester
(
'ntpath.splitext("xx/foo.bar.ext")'
,
(
'xx/foo.bar'
,
'.ext'
))
tester
(
'ntpath.splitext("xx/foo.bar.ext")'
,
(
'xx/foo.bar'
,
'.ext'
))
tester
(
'ntpath.splitext("xx
\\
foo.bar.ext")'
,
(
'xx
\\
foo.bar'
,
'.ext'
))
tester
(
'ntpath.splitext("xx
\\
foo.bar.ext")'
,
(
'xx
\\
foo.bar'
,
'.ext'
))
tester
(
'ntpath.splitext("c:a/b
\\
c.d")'
,
(
'c:a/b
\\
c'
,
'.d'
))
tester
(
'ntpath.splitdrive("c:
\\
foo
\\
bar")'
,
tester
(
'ntpath.splitdrive("c:
\\
foo
\\
bar")'
,
(
'c:'
,
'
\\
foo
\\
bar'
))
(
'c:'
,
'
\\
foo
\\
bar'
))
...
...
Lib/test/test_posixpath.py
Dosyayı görüntüle @
05c075d6
...
@@ -43,15 +43,27 @@ class PosixPathTest(unittest.TestCase):
...
@@ -43,15 +43,27 @@ class PosixPathTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
posixpath
.
split
)
self
.
assertRaises
(
TypeError
,
posixpath
.
split
)
def
test_splitext
(
self
):
def
splitextTest
(
self
,
path
,
filename
,
ext
):
self
.
assertEqual
(
posixpath
.
splitext
(
"foo.ext"
),
(
"foo"
,
".ext"
))
self
.
assertEqual
(
posixpath
.
splitext
(
path
),
(
filename
,
ext
))
self
.
assertEqual
(
posixpath
.
splitext
(
"/foo/foo.ext"
),
(
"/foo/foo"
,
".ext"
))
self
.
assertEqual
(
posixpath
.
splitext
(
"/"
+
path
),
(
"/"
+
filename
,
ext
))
self
.
assertEqual
(
posixpath
.
splitext
(
".ext"
),
(
""
,
".ext"
))
self
.
assertEqual
(
posixpath
.
splitext
(
"abc/"
+
path
),
(
"abc/"
+
filename
,
ext
))
self
.
assertEqual
(
posixpath
.
splitext
(
"/foo.ext/foo"
),
(
"/foo.ext/foo"
,
""
))
self
.
assertEqual
(
posixpath
.
splitext
(
"abc.def/"
+
path
),
(
"abc.def/"
+
filename
,
ext
))
self
.
assertEqual
(
posixpath
.
splitext
(
"foo.ext/"
),
(
"foo.ext/"
,
""
))
self
.
assertEqual
(
posixpath
.
splitext
(
"/abc.def/"
+
path
),
(
"/abc.def/"
+
filename
,
ext
))
self
.
assertEqual
(
posixpath
.
splitext
(
""
),
(
""
,
""
))
self
.
assertEqual
(
posixpath
.
splitext
(
path
+
"/"
),
(
filename
+
ext
+
"/"
,
""
))
self
.
assertEqual
(
posixpath
.
splitext
(
"foo.bar.ext"
),
(
"foo.bar"
,
".ext"
))
def
test_splitext
(
self
):
self
.
splitextTest
(
"foo.bar"
,
"foo"
,
".bar"
)
self
.
splitextTest
(
"foo.boo.bar"
,
"foo.boo"
,
".bar"
)
self
.
splitextTest
(
"foo.boo.biff.bar"
,
"foo.boo.biff"
,
".bar"
)
self
.
splitextTest
(
".csh.rc"
,
".csh"
,
".rc"
)
self
.
splitextTest
(
"nodots"
,
"nodots"
,
""
)
self
.
splitextTest
(
".cshrc"
,
".cshrc"
,
""
)
self
.
splitextTest
(
"...manydots"
,
"...manydots"
,
""
)
self
.
splitextTest
(
"...manydots.ext"
,
"...manydots"
,
".ext"
)
self
.
splitextTest
(
"."
,
"."
,
""
)
self
.
splitextTest
(
".."
,
".."
,
""
)
self
.
splitextTest
(
"........"
,
"........"
,
""
)
self
.
splitextTest
(
""
,
""
,
""
)
self
.
assertRaises
(
TypeError
,
posixpath
.
splitext
)
self
.
assertRaises
(
TypeError
,
posixpath
.
splitext
)
def
test_isabs
(
self
):
def
test_isabs
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
05c075d6
...
@@ -152,6 +152,8 @@ Core and builtins
...
@@ -152,6 +152,8 @@ Core and builtins
Library
Library
-------
-------
- Bug #1115886: os.path.splitext('
.
cshrc
') gives now ('
.
cshrc
', '').
- Patch #787789: allow to pass custom TestRunner instances to unittest'
s
- Patch #787789: allow to pass custom TestRunner instances to unittest'
s
main
()
function
.
main
()
function
.
...
...
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