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
4865376c
Kaydet (Commit)
4865376c
authored
Eki 07, 2012
tarafından
Hynek Schlawack
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes #1492704: Make shutil.copyfile() raise a distinct SameFileError
Patch by Atsuo Ishimoto.
üst
09c61bef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
5 deletions
+35
-5
shutil.rst
Doc/library/shutil.rst
+13
-1
shutil.py
Lib/shutil.py
+7
-1
test_shutil.py
Lib/test/test_shutil.py
+12
-3
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/shutil.rst
Dosyayı görüntüle @
4865376c
...
...
@@ -53,7 +53,7 @@ Directory and files operations
*dst* and return *dst*. *src* and *dst* are path names given as strings.
*dst* must be the complete target file name; look at :func:`shutil.copy`
for a copy that accepts a target directory path. If *src* and *dst*
specify the same file, :exc:`Error` is raised.
specify the same file, :exc:`
SameFile
Error` is raised.
The destination location must be writable; otherwise, an :exc:`OSError`
exception will be raised. If *dst* already exists, it will be replaced.
...
...
@@ -69,6 +69,18 @@ Directory and files operations
Added *follow_symlinks* argument.
Now returns *dst*.
.. versionchanged:: 3.4
Raise :exc:`SameFileError` instead of :exc:`Error`.
.. exception:: SameFileError
This exception is raised if source and destination in :func:`copyfile`
are the same file.
.. versionadded:: 3.4
.. function:: copymode(src, dst, *, follow_symlinks=True)
Copy the permission bits from *src* to *dst*. The file contents, owner, and
...
...
Lib/shutil.py
Dosyayı görüntüle @
4865376c
...
...
@@ -42,6 +42,9 @@ __all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2",
class
Error
(
EnvironmentError
):
pass
class
SameFileError
(
Error
):
"""Raised when source and destination are the same file."""
class
SpecialFileError
(
EnvironmentError
):
"""Raised when trying to do a kind of operation (e.g. copying) which is
not supported on a special file (e.g. a named pipe)"""
...
...
@@ -90,7 +93,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
"""
if
_samefile
(
src
,
dst
):
raise
Error
(
"`
%
s` and `
%
s` are the same file"
%
(
src
,
dst
))
raise
SameFileError
(
"{!r} and {!r} are the same file"
.
format
(
src
,
dst
))
for
fn
in
[
src
,
dst
]:
try
:
...
...
@@ -215,6 +218,9 @@ def copy(src, dst, *, follow_symlinks=True):
If follow_symlinks is false, symlinks won't be followed. This
resembles GNU's "cp -P src dst".
If source and destination are the same file, a SameFileError will be
raised.
"""
if
os
.
path
.
isdir
(
dst
):
dst
=
os
.
path
.
join
(
dst
,
os
.
path
.
basename
(
src
))
...
...
Lib/test/test_shutil.py
Dosyayı görüntüle @
4865376c
...
...
@@ -18,7 +18,8 @@ from shutil import (_make_tarball, _make_zipfile, make_archive,
register_archive_format
,
unregister_archive_format
,
get_archive_formats
,
Error
,
unpack_archive
,
register_unpack_format
,
RegistryError
,
unregister_unpack_format
,
get_unpack_formats
)
unregister_unpack_format
,
get_unpack_formats
,
SameFileError
)
import
tarfile
import
warnings
...
...
@@ -688,7 +689,7 @@ class TestShutil(unittest.TestCase):
with
open
(
src
,
'w'
)
as
f
:
f
.
write
(
'cheddar'
)
os
.
link
(
src
,
dst
)
self
.
assertRaises
(
shutil
.
Error
,
shutil
.
copyfile
,
src
,
dst
)
self
.
assertRaises
(
shutil
.
SameFile
Error
,
shutil
.
copyfile
,
src
,
dst
)
with
open
(
src
,
'r'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
'cheddar'
)
os
.
remove
(
dst
)
...
...
@@ -708,7 +709,7 @@ class TestShutil(unittest.TestCase):
# to TESTFN/TESTFN/cheese, while it should point at
# TESTFN/cheese.
os
.
symlink
(
'cheese'
,
dst
)
self
.
assertRaises
(
shutil
.
Error
,
shutil
.
copyfile
,
src
,
dst
)
self
.
assertRaises
(
shutil
.
SameFile
Error
,
shutil
.
copyfile
,
src
,
dst
)
with
open
(
src
,
'r'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
'cheddar'
)
os
.
remove
(
dst
)
...
...
@@ -1215,6 +1216,14 @@ class TestShutil(unittest.TestCase):
self
.
assertTrue
(
os
.
path
.
exists
(
rv
))
self
.
assertEqual
(
read_file
(
src_file
),
read_file
(
dst_file
))
def
test_copyfile_same_file
(
self
):
# copyfile() should raise SameFileError if the source and destination
# are the same.
src_dir
=
self
.
mkdtemp
()
src_file
=
os
.
path
.
join
(
src_dir
,
'foo'
)
write_file
(
src_file
,
'foo'
)
self
.
assertRaises
(
SameFileError
,
shutil
.
copyfile
,
src_file
,
src_file
)
def
test_copytree_return_value
(
self
):
# copytree returns its destination path.
src_dir
=
self
.
mkdtemp
()
...
...
Misc/NEWS
Dosyayı görüntüle @
4865376c
...
...
@@ -39,6 +39,9 @@ Core and Builtins
Library
-------
- Issue #1492704: shutil.copyfile() raises a distinct SameFileError now if
source and destination are the same file. Patch by Atsuo Ishimoto.
- Issue #13896: Make shelf instances work with 'with' as context managers.
Original patch by Filip Gruszczyński.
...
...
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