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
006c7254
Kaydet (Commit)
006c7254
authored
Tem 07, 2014
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pathlib fixes
üst
7447edbc
e50dafcd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
pathlib.py
Lib/pathlib.py
+7
-4
test_pathlib.py
Lib/test/test_pathlib.py
+14
-0
NEWS
Misc/NEWS
+6
-0
No files found.
Lib/pathlib.py
Dosyayı görüntüle @
006c7254
...
@@ -749,17 +749,20 @@ class PurePath(object):
...
@@ -749,17 +749,20 @@ class PurePath(object):
"""Return a new path with the file name changed."""
"""Return a new path with the file name changed."""
if
not
self
.
name
:
if
not
self
.
name
:
raise
ValueError
(
"
%
r has an empty name"
%
(
self
,))
raise
ValueError
(
"
%
r has an empty name"
%
(
self
,))
drv
,
root
,
parts
=
self
.
_flavour
.
parse_parts
((
name
,))
if
(
not
name
or
name
[
-
1
]
in
[
self
.
_flavour
.
sep
,
self
.
_flavour
.
altsep
]
or
drv
or
root
or
len
(
parts
)
!=
1
):
raise
ValueError
(
"Invalid name
%
r"
%
(
name
))
return
self
.
_from_parsed_parts
(
self
.
_drv
,
self
.
_root
,
return
self
.
_from_parsed_parts
(
self
.
_drv
,
self
.
_root
,
self
.
_parts
[:
-
1
]
+
[
name
])
self
.
_parts
[:
-
1
]
+
[
name
])
def
with_suffix
(
self
,
suffix
):
def
with_suffix
(
self
,
suffix
):
"""Return a new path with the file suffix changed (or added, if none)."""
"""Return a new path with the file suffix changed (or added, if none)."""
# XXX if suffix is None, should the current suffix be removed?
# XXX if suffix is None, should the current suffix be removed?
drv
,
root
,
parts
=
self
.
_flavour
.
parse_parts
((
suffix
,))
f
=
self
.
_flavour
if
drv
or
root
or
len
(
parts
)
!=
1
:
if
f
.
sep
in
suffix
or
f
.
altsep
and
f
.
altsep
in
suffix
:
raise
ValueError
(
"Invalid suffix
%
r"
%
(
suffix
))
raise
ValueError
(
"Invalid suffix
%
r"
%
(
suffix
))
suffix
=
parts
[
0
]
if
suffix
and
not
suffix
.
startswith
(
'.'
)
or
suffix
==
'.'
:
if
not
suffix
.
startswith
(
'.'
):
raise
ValueError
(
"Invalid suffix
%
r"
%
(
suffix
))
raise
ValueError
(
"Invalid suffix
%
r"
%
(
suffix
))
name
=
self
.
name
name
=
self
.
name
if
not
name
:
if
not
name
:
...
...
Lib/test/test_pathlib.py
Dosyayı görüntüle @
006c7254
...
@@ -540,6 +540,10 @@ class _BasePurePathTest(object):
...
@@ -540,6 +540,10 @@ class _BasePurePathTest(object):
self
.
assertRaises
(
ValueError
,
P
(
''
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
''
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'.'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'.'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'/'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'/'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_name
,
''
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_name
,
'/c'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_name
,
'c/'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_name
,
'c/d'
)
def
test_with_suffix_common
(
self
):
def
test_with_suffix_common
(
self
):
P
=
self
.
cls
P
=
self
.
cls
...
@@ -547,6 +551,9 @@ class _BasePurePathTest(object):
...
@@ -547,6 +551,9 @@ class _BasePurePathTest(object):
self
.
assertEqual
(
P
(
'/a/b'
)
.
with_suffix
(
'.gz'
),
P
(
'/a/b.gz'
))
self
.
assertEqual
(
P
(
'/a/b'
)
.
with_suffix
(
'.gz'
),
P
(
'/a/b.gz'
))
self
.
assertEqual
(
P
(
'a/b.py'
)
.
with_suffix
(
'.gz'
),
P
(
'a/b.gz'
))
self
.
assertEqual
(
P
(
'a/b.py'
)
.
with_suffix
(
'.gz'
),
P
(
'a/b.gz'
))
self
.
assertEqual
(
P
(
'/a/b.py'
)
.
with_suffix
(
'.gz'
),
P
(
'/a/b.gz'
))
self
.
assertEqual
(
P
(
'/a/b.py'
)
.
with_suffix
(
'.gz'
),
P
(
'/a/b.gz'
))
# Stripping suffix
self
.
assertEqual
(
P
(
'a/b.py'
)
.
with_suffix
(
''
),
P
(
'a/b'
))
self
.
assertEqual
(
P
(
'/a/b'
)
.
with_suffix
(
''
),
P
(
'/a/b'
))
# Path doesn't have a "filename" component
# Path doesn't have a "filename" component
self
.
assertRaises
(
ValueError
,
P
(
''
)
.
with_suffix
,
'.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
''
)
.
with_suffix
,
'.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'.'
)
.
with_suffix
,
'.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'.'
)
.
with_suffix
,
'.gz'
)
...
@@ -554,9 +561,12 @@ class _BasePurePathTest(object):
...
@@ -554,9 +561,12 @@ class _BasePurePathTest(object):
# Invalid suffix
# Invalid suffix
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'/'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'/'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'.'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'/.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'/.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'c/d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'c/d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'.c/.d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'.c/.d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'./.d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'.d/.'
)
def
test_relative_to_common
(
self
):
def
test_relative_to_common
(
self
):
P
=
self
.
cls
P
=
self
.
cls
...
@@ -950,6 +960,10 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
...
@@ -950,6 +960,10 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
self
.
assertRaises
(
ValueError
,
P
(
'c:'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:/'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:/'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'//My/Share'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'//My/Share'
)
.
with_name
,
'd.xml'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_name
,
'd:'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_name
,
'd:e'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_name
,
'd:/e'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_name
,
'//My/Share'
)
def
test_with_suffix
(
self
):
def
test_with_suffix
(
self
):
P
=
self
.
cls
P
=
self
.
cls
...
...
Misc/NEWS
Dosyayı görüntüle @
006c7254
...
@@ -108,6 +108,12 @@ Core and Builtins
...
@@ -108,6 +108,12 @@ Core and Builtins
Library
Library
-------
-------
- Issue #20639: calling Path.with_suffix('') allows removing the suffix
again. Patch by July Tikhonov.
- Issue #21714: Disallow the construction of invalid paths using
Path.with_name(). Original patch by Antony Lee.
- Issue #15014: Added '
auth
' method to smtplib to make implementing auth
- Issue #15014: Added '
auth
' method to smtplib to make implementing auth
mechanisms simpler, and used it internally in the login method.
mechanisms simpler, and used it internally in the login method.
...
...
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