This repository was archived by the owner on Jul 16, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1212if PY2 :
1313 class FileExistsError (OSError ):
1414 errno = errno .EEXIST
15+
16+ class FileNotFoundError (OSError ):
17+ errno = errno .ENOENT
1518else :
1619 # For some reason we have to redefine this, or users can't import it.
1720 FileExistsError = FileExistsError
21+ FileNotFoundError = FileNotFoundError
1822
1923
2024if sys .platform != 'win32' :
@@ -42,14 +46,19 @@ def _move_atomic(src, dst):
4246 import pywintypes
4347
4448 _windows_default_flags = win32file .MOVEFILE_WRITE_THROUGH
49+ _windows_error_table = {
50+ 183 : FileExistsError ,
51+ 3 : FileNotFoundError
52+ }
4553
4654 @contextlib .contextmanager
4755 def handle_errors ():
4856 try :
4957 yield
5058 except pywintypes .error as e :
51- if e .winerror == 183 :
52- raise FileExistsError (str (e ))
59+ native_cls = _windows_error_table .get (e .winerror , None )
60+ if native_cls is not None :
61+ raise native_cls (str (e ))
5362 else :
5463 raise
5564
Original file line number Diff line number Diff line change 77
88.. autofunction :: atomic_write
99
10+
11+ Exceptions
12+ ----------
13+
1014.. exception :: FileExistsError
1115
12- This is Python 3's builtin ``FileExistsError ``, under Python 2 it's a
13- subclass of ``OSError `` with similar semantics.
16+ This is Python 3's builtin ``FileExistsError ``, under Python 2 it's a
17+ subclass of ``OSError `` with similar semantics.
18+
19+ .. exception :: FileNotFoundError
20+
21+ This is Python 3's builtin ``FileNotFoundError ``, under Python 2 it's a
22+ subclass of ``OSError `` with similar semantics.
1423
1524Low-level API
1625-------------
You can’t perform that action at this time.
0 commit comments