diff --git a/Lib/cgi.py b/Lib/cgi.py
index 4222ef20b89..8cc48bd78b8 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -950,7 +950,7 @@ def print_directory():
try:
pwd = os.getcwd()
except OSError as msg:
- print("os.error:", html.escape(str(msg)))
+ print("OSError:", html.escape(str(msg)))
else:
print(html.escape(pwd))
print()
diff --git a/Lib/os.py b/Lib/os.py
index 5f11fdfd13d..0557f1442a2 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -275,7 +275,7 @@ def removedirs(name):
while head and tail:
try:
rmdir(head)
- except error:
+ except OSrror:
break
head, tail = path.split(head)
@@ -302,7 +302,7 @@ def renames(old, new):
if head and tail:
try:
removedirs(head)
- except error:
+ except OSError:
pass
__all__.extend(["makedirs", "removedirs", "renames"])
@@ -372,10 +372,10 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# minor reason when (say) a thousand readable directories are still
# left to visit. That logic is copied here.
try:
- # Note that listdir and error are globals in this module due
+ # Note that listdir is global in this module due
# to earlier import-*.
names = listdir(top)
- except error as err:
+ except OSError as err:
if onerror is not None:
onerror(err)
return
@@ -477,7 +477,7 @@ if {open, stat} <= supports_dir_fd and {listdir, stat} <= supports_fd:
try:
orig_st = stat(name, dir_fd=topfd, follow_symlinks=follow_symlinks)
dirfd = open(name, O_RDONLY, dir_fd=topfd)
- except error as err:
+ except OSError as err:
if onerror is not None:
onerror(err)
return
@@ -572,7 +572,7 @@ def _execvpe(file, args, env=None):
fullname = path.join(dir, file)
try:
exec_func(fullname, *argrest)
- except error as e:
+ except OSError as e:
last_exc = e
tb = sys.exc_info()[2]
if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
@@ -830,7 +830,7 @@ if _exists("fork") and not _exists("spawnv") and _exists("execv"):
elif WIFEXITED(sts):
return WEXITSTATUS(sts)
else:
- raise error("Not stopped, signaled or exited???")
+ raise OSError("Not stopped, signaled or exited???")
def spawnv(mode, file, args):
"""spawnv(mode, file, args) -> integer
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 2b32767de15..0a6d4466905 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -773,7 +773,7 @@ class ByteArrayTest(BaseBytesTest):
finally:
try:
os.remove(tfn)
- except os.error:
+ except OSError:
pass
def test_reverse(self):
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 165a9bfeac6..cc9bd4e8e2c 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1190,31 +1190,31 @@ if sys.platform != 'win32':
if hasattr(os, 'setuid'):
def test_setuid(self):
if os.getuid() != 0:
- self.assertRaises(os.error, os.setuid, 0)
+ self.assertRaises(OSError, os.setuid, 0)
self.assertRaises(OverflowError, os.setuid, 1<<32)
if hasattr(os, 'setgid'):
def test_setgid(self):
if os.getuid() != 0:
- self.assertRaises(os.error, os.setgid, 0)
+ self.assertRaises(OSError, os.setgid, 0)
self.assertRaises(OverflowError, os.setgid, 1<<32)
if hasattr(os, 'seteuid'):
def test_seteuid(self):
if os.getuid() != 0:
- self.assertRaises(os.error, os.seteuid, 0)
+ self.assertRaises(OSError, os.seteuid, 0)
self.assertRaises(OverflowError, os.seteuid, 1<<32)
if hasattr(os, 'setegid'):
def test_setegid(self):
if os.getuid() != 0:
- self.assertRaises(os.error, os.setegid, 0)
+ self.assertRaises(OSError, os.setegid, 0)
self.assertRaises(OverflowError, os.setegid, 1<<32)
if hasattr(os, 'setreuid'):
def test_setreuid(self):
if os.getuid() != 0:
- self.assertRaises(os.error, os.setreuid, 0, 0)
+ self.assertRaises(OSError, os.setreuid, 0, 0)
self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
@@ -1228,7 +1228,7 @@ if sys.platform != 'win32':
if hasattr(os, 'setregid'):
def test_setregid(self):
if os.getuid() != 0:
- self.assertRaises(os.error, os.setregid, 0, 0)
+ self.assertRaises(OSError, os.setregid, 0, 0)
self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index 29297f8841d..8916861f5bb 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -187,7 +187,7 @@ class PtyTest(unittest.TestCase):
##debug("Reading from master_fd now that the child has exited")
##try:
## s1 = os.read(master_fd, 1024)
- ##except os.error:
+ ##except OSError:
## pass
##else:
## raise TestFailed("Read from master_fd did not raise exception")
diff --git a/Tools/freeze/bkfile.py b/Tools/freeze/bkfile.py
index 0e895f28169..58246fa2ad9 100644
--- a/Tools/freeze/bkfile.py
+++ b/Tools/freeze/bkfile.py
@@ -7,11 +7,11 @@ class _BkFile:
self.__backup = file + '~'
try:
os.unlink(self.__backup)
- except os.error:
+ except OSError:
pass
try:
os.rename(file, self.__backup)
- except os.error:
+ except OSError:
self.__backup = None
self.__file = _orig_open(file, mode, bufsize)
self.closed = self.__file.closed
diff --git a/Tools/freeze/freeze.py b/Tools/freeze/freeze.py
index 769a2d1acc0..479ca3c14b4 100755
--- a/Tools/freeze/freeze.py
+++ b/Tools/freeze/freeze.py
@@ -311,7 +311,7 @@ def main():
try:
os.mkdir(odir)
print("Created output directory", odir)
- except os.error as msg:
+ except OSError as msg:
usage('%s: mkdir failed (%s)' % (odir, str(msg)))
base = ''
if odir:
diff --git a/Tools/scripts/byext.py b/Tools/scripts/byext.py
index b79ff37e8cf..736a441761f 100755
--- a/Tools/scripts/byext.py
+++ b/Tools/scripts/byext.py
@@ -25,7 +25,7 @@ class Stats:
self.addstats("
", "dirs", 1)
try:
names = os.listdir(dir)
- except os.error as err:
+ except OSError as err:
sys.stderr.write("Can't list %s: %s\n" % (dir, err))
self.addstats("", "unlistable", 1)
return
diff --git a/Tools/scripts/byteyears.py b/Tools/scripts/byteyears.py
index 490b37f0bf2..f58c34608fa 100755
--- a/Tools/scripts/byteyears.py
+++ b/Tools/scripts/byteyears.py
@@ -43,7 +43,7 @@ def main():
for filename in sys.argv[1:]:
try:
st = statfunc(filename)
- except os.error as msg:
+ except OSError as msg:
sys.stderr.write("can't stat %r: %r\n" % (filename, msg))
status = 1
st = ()
diff --git a/Tools/scripts/checkpyc.py b/Tools/scripts/checkpyc.py
index d4fdce2515f..009f85bb7c5 100755
--- a/Tools/scripts/checkpyc.py
+++ b/Tools/scripts/checkpyc.py
@@ -24,7 +24,7 @@ def main():
for dirname in sys.path:
try:
names = os.listdir(dirname)
- except os.error:
+ except OSError:
print('Cannot list directory', repr(dirname))
continue
if not silent:
@@ -34,7 +34,7 @@ def main():
name = os.path.join(dirname, name)
try:
st = os.stat(name)
- except os.error:
+ except OSError:
print('Cannot stat', repr(name))
continue
if verbose:
diff --git a/Tools/scripts/copytime.py b/Tools/scripts/copytime.py
index e0220b54432..715683f1255 100755
--- a/Tools/scripts/copytime.py
+++ b/Tools/scripts/copytime.py
@@ -13,12 +13,12 @@ def main():
file1, file2 = sys.argv[1], sys.argv[2]
try:
stat1 = os.stat(file1)
- except os.error:
+ except OSError:
sys.stderr.write(file1 + ': cannot stat\n')
sys.exit(1)
try:
os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
- except os.error:
+ except OSError:
sys.stderr.write(file2 + ': cannot change time\n')
sys.exit(2)
diff --git a/Tools/scripts/finddiv.py b/Tools/scripts/finddiv.py
index f24a702966f..a705f562036 100755
--- a/Tools/scripts/finddiv.py
+++ b/Tools/scripts/finddiv.py
@@ -70,7 +70,7 @@ def process(filename, listnames):
def processdir(dir, listnames):
try:
names = os.listdir(dir)
- except os.error as msg:
+ except OSError as msg:
sys.stderr.write("Can't list directory: %s\n" % dir)
return 1
files = []
diff --git a/Tools/scripts/findlinksto.py b/Tools/scripts/findlinksto.py
index b4c09ef1ce4..b924f27b095 100755
--- a/Tools/scripts/findlinksto.py
+++ b/Tools/scripts/findlinksto.py
@@ -36,7 +36,7 @@ def visit(prog, dirname, names):
linkto = os.readlink(name)
if prog.search(linkto) is not None:
print(name, '->', linkto)
- except os.error:
+ except OSError:
pass
if __name__ == '__main__':
diff --git a/Tools/scripts/fixcid.py b/Tools/scripts/fixcid.py
index 87e2a0929f1..1e4c4288514 100755
--- a/Tools/scripts/fixcid.py
+++ b/Tools/scripts/fixcid.py
@@ -97,7 +97,7 @@ def recursedown(dirname):
bad = 0
try:
names = os.listdir(dirname)
- except os.error as msg:
+ except OSError as msg:
err(dirname + ': cannot list directory: ' + str(msg) + '\n')
return 1
names.sort()
@@ -175,17 +175,17 @@ def fix(filename):
try:
statbuf = os.stat(filename)
os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
- except os.error as msg:
+ except OSError as msg:
err(tempname + ': warning: chmod failed (' + str(msg) + ')\n')
# Then make a backup of the original file as filename~
try:
os.rename(filename, filename + '~')
- except os.error as msg:
+ except OSError as msg:
err(filename + ': warning: backup failed (' + str(msg) + ')\n')
# Now move the temp file to the original file
try:
os.rename(tempname, filename)
- except os.error as msg:
+ except OSError as msg:
err(filename + ': rename failed (' + str(msg) + ')\n')
return 1
# Return success
diff --git a/Tools/scripts/ftpmirror.py b/Tools/scripts/ftpmirror.py
index 9e8be1daf84..a1b683a319a 100755
--- a/Tools/scripts/ftpmirror.py
+++ b/Tools/scripts/ftpmirror.py
@@ -108,7 +108,7 @@ def mirrorsubdir(f, localdir):
if verbose: print('Creating local directory', repr(localdir))
try:
makedir(localdir)
- except os.error as msg:
+ except OSError as msg:
print("Failed to establish local directory", repr(localdir))
return
infofilename = os.path.join(localdir, '.mirrorinfo')
@@ -183,7 +183,7 @@ def mirrorsubdir(f, localdir):
continue
try:
os.unlink(tempname)
- except os.error:
+ except OSError:
pass
if mode[0] == 'l':
if verbose:
@@ -218,11 +218,11 @@ def mirrorsubdir(f, localdir):
fp1.close()
try:
os.unlink(fullname)
- except os.error:
+ except OSError:
pass # Ignore the error
try:
os.rename(tempname, fullname)
- except os.error as msg:
+ except OSError as msg:
print("Can't rename %r to %r: %s" % (tempname, fullname, msg))
continue
info[filename] = infostuff
@@ -255,7 +255,7 @@ def mirrorsubdir(f, localdir):
try:
if not localdir: names = os.listdir(os.curdir)
else: names = os.listdir(localdir)
- except os.error:
+ except OSError:
names = []
for name in names:
if name[0] == '.' or name in info or name in subdirs:
@@ -312,7 +312,7 @@ def remove(fullname):
if os.path.isdir(fullname) and not os.path.islink(fullname):
try:
names = os.listdir(fullname)
- except os.error:
+ except OSError:
names = []
ok = 1
for name in names:
@@ -322,13 +322,13 @@ def remove(fullname):
return 0
try:
os.rmdir(fullname)
- except os.error as msg:
+ except OSError as msg:
print("Can't remove local directory %r: %s" % (fullname, msg))
return 0
else:
try:
os.unlink(fullname)
- except os.error as msg:
+ except OSError as msg:
print("Can't remove local file %r: %s" % (fullname, msg))
return 0
return 1
@@ -386,7 +386,7 @@ def writedict(dict, filename):
backup = os.path.join(dir, fname + '~')
try:
os.unlink(backup)
- except os.error:
+ except OSError:
pass
fp = open(tempname, 'w')
fp.write('{\n')
@@ -396,7 +396,7 @@ def writedict(dict, filename):
fp.close()
try:
os.rename(filename, backup)
- except os.error:
+ except OSError:
pass
os.rename(tempname, filename)
diff --git a/Tools/scripts/linktree.py b/Tools/scripts/linktree.py
index 982f4800ba3..e83f198593a 100755
--- a/Tools/scripts/linktree.py
+++ b/Tools/scripts/linktree.py
@@ -32,13 +32,13 @@ def main():
return 1
try:
os.mkdir(newtree, 0o777)
- except os.error as msg:
+ except OSError as msg:
print(newtree + ': cannot mkdir:', msg)
return 1
linkname = os.path.join(newtree, link)
try:
os.symlink(os.path.join(os.pardir, oldtree), linkname)
- except os.error as msg:
+ except OSError as msg:
if not link_may_fail:
print(linkname + ': cannot symlink:', msg)
return 1
@@ -51,7 +51,7 @@ def linknames(old, new, link):
if debug: print('linknames', (old, new, link))
try:
names = os.listdir(old)
- except os.error as msg:
+ except OSError as msg:
print(old + ': warning: cannot listdir:', msg)
return
for name in names:
diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py
index dd08e0aba38..ae1556162b0 100755
--- a/Tools/scripts/pathfix.py
+++ b/Tools/scripts/pathfix.py
@@ -73,7 +73,7 @@ def recursedown(dirname):
bad = 0
try:
names = os.listdir(dirname)
- except os.error as msg:
+ except OSError as msg:
err('%s: cannot list directory: %r\n' % (dirname, msg))
return 1
names.sort()
@@ -131,24 +131,24 @@ def fix(filename):
mtime = statbuf.st_mtime
atime = statbuf.st_atime
os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
- except os.error as msg:
+ except OSError as msg:
err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
# Then make a backup of the original file as filename~
try:
os.rename(filename, filename + '~')
- except os.error as msg:
+ except OSError as msg:
err('%s: warning: backup failed (%r)\n' % (filename, msg))
# Now move the temp file to the original file
try:
os.rename(tempname, filename)
- except os.error as msg:
+ except OSError as msg:
err('%s: rename failed (%r)\n' % (filename, msg))
return 1
if preserve_timestamps:
if atime and mtime:
try:
os.utime(filename, (atime, mtime))
- except os.error as msg:
+ except OSError as msg:
err('%s: reset of timestamp failed (%r)\n' % (filename, msg))
return 1
# Return succes
diff --git a/Tools/scripts/pindent.py b/Tools/scripts/pindent.py
index 15b6399f793..0151773de20 100755
--- a/Tools/scripts/pindent.py
+++ b/Tools/scripts/pindent.py
@@ -427,7 +427,7 @@ def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
# end if
import os
try: os.rename(filename, filename + '~')
- except os.error: pass
+ except OSError: pass
# end try
f = open(filename, 'w')
f.write(result)
@@ -442,7 +442,7 @@ def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = E
# end if
import os
try: os.rename(filename, filename + '~')
- except os.error: pass
+ except OSError: pass
# end try
f = open(filename, 'w')
f.write(result)
@@ -457,7 +457,7 @@ def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
# end if
import os
try: os.rename(filename, filename + '~')
- except os.error: pass
+ except OSError: pass
# end try
f = open(filename, 'w')
f.write(result)
diff --git a/Tools/scripts/treesync.py b/Tools/scripts/treesync.py
index b2649c474e8..652d3940a49 100755
--- a/Tools/scripts/treesync.py
+++ b/Tools/scripts/treesync.py
@@ -78,7 +78,7 @@ def process(slave, master):
print("creating slave directory", slave)
try:
os.mkdir(slave)
- except os.error as msg:
+ except OSError as msg:
print("can't make slave directory", slave, ":", msg)
return
else:
diff --git a/Tools/scripts/untabify.py b/Tools/scripts/untabify.py
index 4b67c151543..861c83ced90 100755
--- a/Tools/scripts/untabify.py
+++ b/Tools/scripts/untabify.py
@@ -39,11 +39,11 @@ def process(filename, tabsize, verbose=True):
backup = filename + "~"
try:
os.unlink(backup)
- except os.error:
+ except OSError:
pass
try:
os.rename(filename, backup)
- except os.error:
+ except OSError:
pass
with open(filename, "w", encoding=encoding) as f:
f.write(newtext)
diff --git a/Tools/scripts/which.py b/Tools/scripts/which.py
index 4fc37a027ca..df54ce032cb 100755
--- a/Tools/scripts/which.py
+++ b/Tools/scripts/which.py
@@ -29,7 +29,7 @@ def main():
filename = os.path.join(dir, prog)
try:
st = os.stat(filename)
- except os.error:
+ except OSError:
continue
if not S_ISREG(st[ST_MODE]):
msg(filename + ': not a disk file')