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
1b02da95
Kaydet (Commit)
1b02da95
authored
Ock 02, 2014
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix.
üst
8ec15f7a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
0 deletions
+28
-0
pathlib.py
Lib/pathlib.py
+6
-0
test_pathlib.py
Lib/test/test_pathlib.py
+20
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/pathlib.py
Dosyayı görüntüle @
1b02da95
...
...
@@ -755,6 +755,12 @@ class PurePath(object):
def
with_suffix
(
self
,
suffix
):
"""Return a new path with the file suffix changed (or added, if none)."""
# XXX if suffix is None, should the current suffix be removed?
drv
,
root
,
parts
=
self
.
_flavour
.
parse_parts
((
suffix
,))
if
drv
or
root
or
len
(
parts
)
!=
1
:
raise
ValueError
(
"Invalid suffix
%
r"
%
(
suffix
))
suffix
=
parts
[
0
]
if
not
suffix
.
startswith
(
'.'
):
raise
ValueError
(
"Invalid suffix
%
r"
%
(
suffix
))
name
=
self
.
name
if
not
name
:
raise
ValueError
(
"
%
r has an empty name"
%
(
self
,))
...
...
Lib/test/test_pathlib.py
Dosyayı görüntüle @
1b02da95
...
...
@@ -528,9 +528,16 @@ class _BasePurePathTest(object):
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'
))
# 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'
)
# Invalid suffix
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
,
'/.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'c/d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
)
.
with_suffix
,
'.c/.d'
)
def
test_relative_to_common
(
self
):
P
=
self
.
cls
...
...
@@ -920,10 +927,23 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
self
.
assertEqual
(
P
(
'c:/a/b'
)
.
with_suffix
(
'.gz'
),
P
(
'c:/a/b.gz'
))
self
.
assertEqual
(
P
(
'c:a/b.py'
)
.
with_suffix
(
'.gz'
),
P
(
'c:a/b.gz'
))
self
.
assertEqual
(
P
(
'c:/a/b.py'
)
.
with_suffix
(
'.gz'
),
P
(
'c:/a/b.gz'
))
# 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
(
'//My/Share'
)
.
with_suffix
,
'.gz'
)
# Invalid suffix
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'/'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'
\\
'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'c:'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'/.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'
\\
.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'c:.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'c/d'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'c
\\
d'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'.c/d'
)
self
.
assertRaises
(
ValueError
,
P
(
'c:a/b'
)
.
with_suffix
,
'.c
\\
d'
)
def
test_relative_to
(
self
):
P
=
self
.
cls
...
...
Misc/NEWS
Dosyayı görüntüle @
1b02da95
...
...
@@ -44,6 +44,8 @@ Core and Builtins
Library
-------
- Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix.
- Fix breakage in TestSuite.countTestCases() introduced by issue #11798.
- Issue #20108: Avoid parameter name clash in inspect.getcallargs().
...
...
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