Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
26fe37dd
Commit
26fe37dd
authored
Jul 19, 2012
by
Hynek Schlawack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1492704: Backout and wait for 3.4
parent
024abca0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
33 deletions
+5
-33
Doc/library/shutil.rst
Doc/library/shutil.rst
+1
-11
Lib/shutil.py
Lib/shutil.py
+1
-7
Lib/test/test_shutil.py
Lib/test/test_shutil.py
+3
-12
Misc/NEWS
Misc/NEWS
+0
-3
No files found.
Doc/library/shutil.rst
View file @
26fe37dd
...
...
@@ -52,7 +52,7 @@ Directory and files operations
Copy the contents (no metadata) of the file named *src* to a file named
*dst* and return *dst*. *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* are the same files, :exc:`
SameFile
Error` is raised.
*src* and *dst* are the same files, :exc:`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. Special files
...
...
@@ -67,16 +67,6 @@ Directory and files operations
:exc:`IOError` used to be raised instead of :exc:`OSError`.
Added *follow_symlinks* argument.
Now returns *dst*.
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.3
.. function:: copymode(src, dst, *, follow_symlinks=True)
...
...
Lib/shutil.py
View file @
26fe37dd
...
...
@@ -42,9 +42,6 @@ __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)"""
...
...
@@ -93,7 +90,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
"""
if
_samefile
(
src
,
dst
):
raise
SameFileError
(
"{!r} and {!r} are the same file"
.
format
(
src
,
dst
))
raise
Error
(
"`%s` and `%s` are the same file"
%
(
src
,
dst
))
for
fn
in
[
src
,
dst
]:
try
:
...
...
@@ -218,9 +215,6 @@ 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
View file @
26fe37dd
...
...
@@ -18,8 +18,7 @@ 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
,
SameFileError
)
unregister_unpack_format
,
get_unpack_formats
)
import
tarfile
import
warnings
...
...
@@ -689,7 +688,7 @@ class TestShutil(unittest.TestCase):
with
open
(
src
,
'w'
)
as
f
:
f
.
write
(
'cheddar'
)
os
.
link
(
src
,
dst
)
self
.
assertRaises
(
shutil
.
SameFile
Error
,
shutil
.
copyfile
,
src
,
dst
)
self
.
assertRaises
(
shutil
.
Error
,
shutil
.
copyfile
,
src
,
dst
)
with
open
(
src
,
'r'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
'cheddar'
)
os
.
remove
(
dst
)
...
...
@@ -709,7 +708,7 @@ class TestShutil(unittest.TestCase):
# to TESTFN/TESTFN/cheese, while it should point at
# TESTFN/cheese.
os
.
symlink
(
'cheese'
,
dst
)
self
.
assertRaises
(
shutil
.
SameFile
Error
,
shutil
.
copyfile
,
src
,
dst
)
self
.
assertRaises
(
shutil
.
Error
,
shutil
.
copyfile
,
src
,
dst
)
with
open
(
src
,
'r'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
'cheddar'
)
os
.
remove
(
dst
)
...
...
@@ -1216,14 +1215,6 @@ 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
View file @
26fe37dd
...
...
@@ -47,9 +47,6 @@ 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
#
15397
:
inspect
.
getmodulename
()
is
now
based
directly
on
importlib
via
a
new
importlib
.
machinery
.
all_suffixes
()
API
.
...
...
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