In the (legacy) code I maintain people are using WindowsError
. I could go ahead and replace all occurrences with OSError
but alas the winerror
attribute is used, happily only in three cases - namely 123:
try:
mtime = int(os.path.getmtime(self._s))
except WindowsError, werr:
if werr.winerror != 123: raise
deprint(u'Unable to determine modified time of %s - probably a unicode error' % self._s)
740:
try:
popen = subprocess.Popen(args, close_fds=bolt.close_fds)
if wait: popen.wait()
except UnicodeError:
self._showUnicodeError()
except WindowsError as werr:
if werr.winerror != 740:
self.ShowError(werr)
and 32:
try:
patchName.untemp() # calls shutil.move() and os.remove()
except WindowsError, werr:
while werr.winerror == 32 and self._retry(patchName.temp.s,
patchName.s):
try:
patchName.untemp()
except WindowsError, werr:
continue
break
else:
raise
How am I going to translate these codes to OSError
?
I am in python 2.7 so I can't use the nice exceptions introduced in pep-3151
Here is a discussion on mapping winerror to the errno module