Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and standardise obsolete OSError aliases: #2107

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AutoDuck/fixHelpCompression.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

try:
os.stat(fname)
except os.error:
except OSError:
sys.stderr.write("The project file '%s' was not found\n" % (fname))
sys.exit(1)

Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/Scintilla/src/LexGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def UpdateFile(filename, updated):
it as modified."""
try:
infile = open(filename, "rb")
except IOError: # File is not there yet
except OSError: # File is not there yet
out = open(filename, "wb")
out.write(updated)
out.close()
Expand Down Expand Up @@ -136,7 +136,7 @@ def Generate(inpath, outpath, commentPrefix, eolType, *lists):
# % (inpath, outpath, commentPrefix, eolType)
try:
infile = open(inpath, "r")
except IOError:
except OSError:
print("Can not open", inpath)
return
original = infile.read()
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/hiertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def GetText(self):
os.path.basename(self.filename),
os.stat(self.filename)[6],
)
except os.error as details:
except OSError as details:
return "%-20s - %s" % (self.filename, details[1])

def IsExpandable(self):
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def OnInitDialog(self):
open(os.path.join(site_packages, "pywin32.version.txt")).read().strip()
)
ver = "pywin32 build %s" % build_no
except EnvironmentError:
except OSError:
ver = None
if ver is None:
# See if we are Part of Active Python
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def OnOpenDocument(self, filename):
try:
try:
self.bitmap.LoadBitmapFile(f)
except IOError:
except OSError:
win32ui.MessageBox("Could not load the bitmap from %s" % filename)
return 0
finally:
Expand Down
14 changes: 7 additions & 7 deletions Pythonwin/pywin/framework/editor/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ def OnSaveDocument(self, fileName):
tempPath = os.path.join(win32api.GetTempPath(), "bak")
try:
os.mkdir(tempPath, 0)
except os.error:
except OSError:
pass
bakFileName = os.path.join(tempPath, basename)
try:
os.unlink(bakFileName) # raise NameError if no bakups wanted.
except (os.error, NameError):
except (OSError, NameError):
pass
try:
# Do a copy as it might be on different volumes,
# and the file may be a hard-link, causing the link
# to follow the backup.
shutil.copy2(fileName, bakFileName)
except (os.error, NameError, IOError):
except (OSError, NameError):
pass
try:
self.SaveFile(fileName)
except IOError as details:
except OSError as details:
win32ui.MessageBox("Error - could not save file\r\n\r\n%s" % details)
return 0
except (UnicodeEncodeError, LookupError) as details:
Expand All @@ -99,7 +99,7 @@ def OnSaveDocument(self, fileName):
if rc == win32con.IDYES:
try:
self.SaveFile(fileName, encoding="latin-1")
except IOError as details:
except OSError as details:
win32ui.MessageBox(
"Error - could not save file\r\n\r\n%s" % details
)
Expand Down Expand Up @@ -155,7 +155,7 @@ def CheckExternalDocumentUpdated(self):
return
try:
newstat = os.stat(self.GetPathName())
except os.error as exc:
except OSError as exc:
if not self.bReportedFileNotFound:
print(
"The file '%s' is open for editing, but\nchecking it for changes caused the error: %s"
Expand Down Expand Up @@ -207,7 +207,7 @@ def _DocumentStateChanged(self):
if self.GetPathName():
try:
self.fileStat = os.stat(self.GetPathName())
except os.error:
except OSError:
self.fileStat = None
else:
self.fileStat = None
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def OnOpenDocument(self, filename):
win32ui.SetStatusText("Loading file...", 1)
try:
f = open(filename, "rb")
except IOError:
except OSError:
win32ui.MessageBox(
filename
+ "\nCan not find this file\nPlease verify that the correct path and file name are given"
Expand Down
8 changes: 4 additions & 4 deletions Pythonwin/pywin/framework/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def RunScript(defName=None, defArgs=None, bShowDialog=1, debuggingType=None):
try:
os.stat(fnameonly) # See if it is OK as is...
script = fnameonly
except os.error:
except OSError:
fullScript = LocatePythonFile(script)
if fullScript is None:
win32ui.MessageBox("The file '%s' can not be located" % script)
Expand All @@ -308,7 +308,7 @@ def RunScript(defName=None, defArgs=None, bShowDialog=1, debuggingType=None):
# So: do the binary thing and manually normalize \r\n.
try:
f = open(script, "rb")
except IOError as exc:
except OSError as exc:
win32ui.MessageBox(
"The file could not be opened - %s (%d)" % (exc.strerror, exc.errno)
)
Expand Down Expand Up @@ -505,7 +505,7 @@ def CheckFile():
win32ui.DoWaitCursor(1)
try:
f = open(pathName)
except IOError as details:
except OSError as details:
print("Cant open file '%s' - %s" % (pathName, details))
return
try:
Expand Down Expand Up @@ -640,7 +640,7 @@ def FindTabNanny():
fname = os.path.join(path, "Tools\\Scripts\\%s" % filename)
try:
os.stat(fname)
except os.error:
except OSError:
print(
"WARNING - The file '%s' can not be located in path '%s'" % (filename, path)
)
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/winout.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def OnSaveDocument(self, fileName):
win32ui.SetStatusText("Saving file...", 1)
try:
self.SaveFile(fileName)
except IOError as details:
except OSError as details:
win32ui.MessageBox("Error - could not save file\r\n\r\n%s" % details)
return 0
win32ui.SetStatusText("Ready")
Expand Down
6 changes: 3 additions & 3 deletions Pythonwin/pywin/scintilla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, f):
try:
f = find_config_file(f)
src_stat = os.stat(f)
except os.error:
except OSError:
self.report_error("Config file '%s' not found" % f)
return
self.filename = f
Expand Down Expand Up @@ -119,7 +119,7 @@ def __init__(self, f):
return # We are ready to roll!
finally:
cf.close()
except (os.error, IOError, EOFError):
except (OSError, EOFError):
pass
fp = open(f)
b_close = True
Expand Down Expand Up @@ -167,7 +167,7 @@ def __init__(self, f):
marshal.dump(src_stat[stat.ST_MTIME], cf)
marshal.dump(self.cache, cf)
cf.close()
except (IOError, EOFError):
except (OSError, EOFError):
pass # Ignore errors - may be read only.

def configure(self, editor, subsections=None):
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/scintilla/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def OnOpenDocument(self, filename):
self._LoadTextFromFile(f)
finally:
f.close()
except IOError:
except OSError:
rc = win32ui.MessageBox(
"Could not load the file from %s\n\nDo you want to create a new file?"
% filename,
Expand All @@ -63,7 +63,7 @@ def OnOpenDocument(self, filename):
self._LoadTextFromFile(f)
finally:
f.close()
except IOError as e:
except OSError as e:
rc = win32ui.MessageBox("Cannot create the file %s" % filename)
return 1

Expand Down
20 changes: 10 additions & 10 deletions com/win32com/client/gencache.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__():
# Initialize the module. Called once explicitly at module import below.
try:
_LoadDicts()
except IOError:
except OSError:
Rebuild()


Expand Down Expand Up @@ -100,7 +100,7 @@ def _LoadDicts():
except AttributeError:
# The __loader__ has no get_data method. See below.
return
except IOError:
except OSError:
# Our gencache is in a .zip file (and almost certainly readonly)
# but no dicts file. That actually needn't be fatal for a frozen
# application. Assuming they call "EnsureModule" with the same
Expand All @@ -115,7 +115,7 @@ def _LoadDicts():
return
f = io.BytesIO(data)
else:
# NOTE: IOError on file open must be caught by caller.
# NOTE: OSError on file open must be caught by caller.
f = open(os.path.join(win32com.__gen_path__, "dicts.dat"), "rb")
try:
p = pickle.Unpickler(f)
Expand Down Expand Up @@ -147,12 +147,12 @@ def GetGeneratePath():
try:
os.makedirs(win32com.__gen_path__)
# os.mkdir(win32com.__gen_path__)
except os.error:
except OSError:
pass
try:
fname = os.path.join(win32com.__gen_path__, "__init__.py")
os.stat(fname)
except os.error:
except OSError:
f = open(fname, "w")
f.write(
"# Generated file - this directory may be deleted to reset the COM cache...\n"
Expand Down Expand Up @@ -528,11 +528,11 @@ def EnsureModule(
# try to erase the bad file from the cache
try:
os.unlink(filePath)
except os.error:
except OSError:
pass
try:
os.unlink(filePathPyc)
except os.error:
except OSError:
pass
if os.path.isdir(filePathPrefix):
import shutil
Expand All @@ -554,21 +554,21 @@ def EnsureModule(
try:
pyModTime = os.stat(filePath)[8]
fModTimeSet = 1
except os.error as e:
except OSError as e:
# If .py file fails, try .pyc file
# print "Trying pyc stat", filePathPyc
try:
pyModTime = os.stat(filePathPyc)[8]
fModTimeSet = 1
except os.error as e:
except OSError as e:
pass
# print "Trying stat typelib", pyModTime
# print str(typLibPath)
typLibModTime = os.stat(typLibPath)[8]
if fModTimeSet and (typLibModTime > pyModTime):
bReloadNeeded = 1
module = None
except (ImportError, os.error):
except (ImportError, OSError):
module = None
if module is None:
# We need to build an item. If we are in a read-only cache, we
Expand Down
6 changes: 3 additions & 3 deletions com/win32com/client/genpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,13 @@ def finish_writer(self, filename, f, worked):
f.close()
try:
os.unlink(filename)
except os.error:
except OSError:
pass
temp_filename = self.get_temp_filename(filename)
if worked:
try:
os.rename(temp_filename, filename)
except os.error:
except OSError:
# If we are really unlucky, another process may have written the
# file in between our calls to os.unlink and os.rename. So try
# again, but only once.
Expand All @@ -1064,7 +1064,7 @@ def finish_writer(self, filename, f, worked):
# as well.
try:
os.unlink(filename)
except os.error:
except OSError:
pass
os.rename(temp_filename, filename)
else:
Expand Down
6 changes: 3 additions & 3 deletions com/win32com/client/makepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ def GenerateFromTypeLibSpec(
if bForDemand:
try:
os.unlink(full_name + ".py")
except os.error:
except OSError:
pass
try:
os.unlink(full_name + ".pyc")
except os.error:
except OSError:
pass
try:
os.unlink(full_name + ".pyo")
except os.error:
except OSError:
pass
if not os.path.isdir(full_name):
os.mkdir(full_name)
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/demos/excelAddin.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def UnregisterAddin(klass):
winreg.HKEY_CURRENT_USER,
"Software\\Microsoft\\Office\\Excel\\Addins\\" + klass._reg_progid_,
)
except WindowsError:
except OSError:
pass


Expand Down
4 changes: 2 additions & 2 deletions com/win32com/demos/iebutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def register(classobj):
winreg.SetValueEx(hKey, "ToolTip", 0, winreg.REG_SZ, classobj._tool_tip_)
winreg.SetValueEx(hKey, "Icon", 0, winreg.REG_SZ, classobj._icon_)
winreg.SetValueEx(hKey, "HotIcon", 0, winreg.REG_SZ, classobj._hot_icon_)
except WindowsError:
except OSError:
print("Couldn't set standard toolbar reg keys.")
else:
print("Set standard toolbar reg keys.")
Expand All @@ -180,7 +180,7 @@ def unregister(classobj):
winreg.DeleteValue(hKey, "Icon")
winreg.DeleteValue(hKey, "HotIcon")
winreg.DeleteKey(winreg.HKEY_LOCAL_MACHINE, subKeyCLSID)
except WindowsError:
except OSError:
print("Couldn't delete Standard toolbar regkey.")
else:
print("Deleted Standard toolbar regkey.")
Expand Down
4 changes: 2 additions & 2 deletions com/win32com/demos/ietoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def DllRegisterServer():
subKey = winreg.SetValueEx(
hkey, comclass._reg_clsid_, 0, winreg.REG_BINARY, "\0"
)
except WindowsError:
except OSError:
print(
"Couldn't set registry value.\nhkey: %d\tCLSID: %s\n"
% (hkey, comclass._reg_clsid_)
Expand All @@ -351,7 +351,7 @@ def DllUnregisterServer():
winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar"
)
winreg.DeleteValue(hkey, comclass._reg_clsid_)
except WindowsError:
except OSError:
print(
"Couldn't delete registry value.\nhkey: %d\tCLSID: %s\n"
% (hkey, comclass._reg_clsid_)
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/demos/outlookAddin.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def UnregisterAddin(klass):
winreg.HKEY_CURRENT_USER,
"Software\\Microsoft\\Office\\Outlook\\Addins\\" + klass._reg_progid_,
)
except WindowsError:
except OSError:
pass


Expand Down
Loading