modernize some modules' code by replacing OSError->ENOENT/ENOTDIR/EPERM/EEXIST occurrences with the corresponding pep-3151 exceptions (FileNotFoundError, NotADirectoryError, etc.)

This commit is contained in:
Giampaolo Rodola' 2013-02-12 15:14:17 +01:00
parent b071d4f3da
commit 0166a283f6
6 changed files with 27 additions and 51 deletions

View file

@ -291,25 +291,20 @@ else:
def unlink(filename):
try:
_unlink(filename)
except OSError as error:
# The filename need not exist.
if error.errno not in (errno.ENOENT, errno.ENOTDIR):
raise
except (FileNotFoundError, NotADirectoryError):
pass
def rmdir(dirname):
try:
_rmdir(dirname)
except OSError as error:
# The directory need not exist.
if error.errno != errno.ENOENT:
raise
except FileNotFoundError:
pass
def rmtree(path):
try:
_rmtree(path)
except OSError as error:
if error.errno != errno.ENOENT:
raise
except FileNotFoundError:
pass
def make_legacy_pyc(source):
"""Move a PEP 3147 pyc/pyo file to its legacy pyc/pyo location.