classification
Title: distinct error type from shutil.move()
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: eric.araujo Nosy List: BreamoreBoy, anthonybaxter, eric.araujo, gennad, nnorwitz, pitrou, tarek, zooko
Priority: normal Keywords: easy, patch

Created on 2006-05-22 03:08 by zooko, last changed 2011-09-09 17:39 by gennad.

Files
File name Uploaded Description Edit
patch.txt zooko, 2006-05-22 03:08
1492704.diff gennad, 2011-08-10 14:33 review
new_patch.diff gennad, 2011-09-07 15:14 review
Messages (15)
msg50324 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2006-05-22 03:08
I need to call shutil.move() and be able to tell the
difference between an error such as access denied and
an error due to the two arguments being the same file.


--- old-dw/src/Lib/shutil.py    2006-05-22
00:06:02.000000000 -0300
+++ new-dw/src/Lib/shutil.py    2006-05-22
00:06:02.000000000 -0300
@@ -16,6 +16,9 @@
 class Error(exceptions.EnvironmentError):
     pass

+class SameFileError(Error):
+    pass
+
 def copyfileobj(fsrc, fdst, length=16*1024):
     """copy data from file-like object fsrc to
file-like object fdst"""
     while 1:
@@ -39,7 +42,7 @@
 def copyfile(src, dst):
     """Copy data from src to dst"""
     if _samefile(src, dst):
-        raise Error, "`%s` and `%s` are the same file"
% (src, dst)
+        raise SameFileError, "`%s` and `%s` are the
same file" % (src, dst)

     fsrc = None
     fdst = None

msg50325 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2006-07-06 22:53
Logged In: YES 
user_id=52562

Please apply.  This patch is completely backwards-compatible
and makes possible some uses of shutil.move().
msg50326 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2006-07-06 22:55
Logged In: YES 
user_id=52562

I'm not sure how to draw attention to my patch, so I will
try assigning it to anthonybaxter.  That ought to get attention.
msg50327 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2007-06-28 15:08
Dear Pythonistas: please apply this patch.  There is no reason not to, and it enables programmers to use shutil more cleanly.
msg50328 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-07-06 05:25
In order for patches to be applied, they require tests and doc updates as appropriate.  Can you supply these updates and attach a patch with all the changes?
msg114664 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-08-22 10:24
@Zooko are you interested in taking this forward?
msg114723 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-23 01:27
Antoine, is this obsoleted by PEP 3151?
msg141825 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-09 15:10
I have re-read PEP 3151 and think it has no bearing on this bug: the PEP is about adding exception classes that map to errno values, and this report is about a library function that returns a custom exception unrelated to errnos.

I’m willing to review a patch with tests and docs updates for this, or write one myself.
msg141864 - (view) Author: Gennadiy Zlobin (gennad) Date: 2011-08-10 14:33
This patch should fix the issue
msg142473 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-19 16:08
Thanks for the patch.  I made a review on Rietveld; a mail should have been sent.
msg143688 - (view) Author: Gennadiy Zlobin (gennad) Date: 2011-09-07 15:14
Thanks for the comments! Here'a a new patch.
msg143690 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-09-07 15:26
Thanks, looks good.  There are a few minor cosmetic things I’ll change before committing.  I assume you have tested it on Windows?
msg143724 - (view) Author: Gennadiy Zlobin (gennad) Date: 2011-09-08 09:59
My fault. I tested it only partially, relying on the documentation that says

"""
On Windows, if dst already exists, OSError will be raised even if it is a file
"""
Actually it does not (at least at my Windows 7):
(Pdb) os.path.isfile(src)
True
(Pdb) p os.rename(src, src)
None

Am I doing something wrong?
msg143774 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-09-09 17:18
By testing, I mean running ./python -m test test_shutil
msg143781 - (view) Author: Gennadiy Zlobin (gennad) Date: 2011-09-09 17:39
Yes, I got Windows 7, downloaded VS 2008 express, compiled, ran
python python_d.exe -m test test_shutil 
and tests failed. I found out that os.rename does not raise OSError, according to my previous comment...
History
Date User Action Args
2011-09-09 17:39:22gennadsetmessages: + msg143781
2011-09-09 17:18:45eric.araujosetmessages: + msg143774
2011-09-08 09:59:52gennadsetmessages: + msg143724
2011-09-07 15:26:29eric.araujosetmessages: + msg143690
2011-09-07 15:15:00gennadsetfiles: + new_patch.diff

messages: + msg143688
2011-08-19 16:08:32eric.araujosetmessages: + msg142473
2011-08-10 14:33:46gennadsetfiles: + 1492704.diff
nosy: + gennad
messages: + msg141864

2011-08-09 15:10:39eric.araujosetassignee: tarek -> eric.araujo
messages: + msg141825
versions: + Python 3.3, - Python 3.2
2010-08-23 01:27:36eric.araujosetnosy: + pitrou
messages: + msg114723
2010-08-22 10:24:53BreamoreBoysetnosy: + BreamoreBoy
messages: + msg114664
2010-06-12 09:27:13eric.araujosetassignee: anthonybaxter -> tarek
versions: + Python 3.2, - Python 3.1, Python 2.7
nosy: + tarek, eric.araujo
2009-04-22 12:47:19ajaksu2setkeywords: + easy
2009-03-21 02:46:38ajaksu2setstage: test needed
type: enhancement
versions: + Python 3.1, Python 2.7, - Python 2.6
2006-05-22 03:08:36zookocreate