Skip to content

Commit

Permalink
Issue #16706: get rid of os.error
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Dec 18, 2012
1 parent a191959 commit ad28c7f
Show file tree
Hide file tree
Showing 33 changed files with 4,069 additions and 4,103 deletions.
2 changes: 1 addition & 1 deletion Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
buffering = DEFAULT_BUFFER_SIZE
try:
bs = os.fstat(raw.fileno()).st_blksize
except (os.error, AttributeError):
except (OSError, AttributeError):
pass
else:
if bs > 1:
Expand Down
2 changes: 1 addition & 1 deletion Lib/cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def print_directory():
print("<H3>Current Working Directory:</H3>")
try:
pwd = os.getcwd()
except os.error as msg:
except OSError as msg:
print("os.error:", html.escape(str(msg)))
else:
print(html.escape(pwd))
Expand Down
2 changes: 1 addition & 1 deletion Lib/compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
print('Listing {!r}...'.format(dir))
try:
names = os.listdir(dir)
except os.error:
except OSError:
print("Can't list {!r}".format(dir))
names = []
names.sort()
Expand Down
4 changes: 2 additions & 2 deletions Lib/dbm/dumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def _commit(self):

try:
self._os.unlink(self._bakfile)
except self._os.error:
except OSError:
pass

try:
self._os.rename(self._dirfile, self._bakfile)
except self._os.error:
except OSError:
pass

f = self._io.open(self._dirfile, 'w', encoding="Latin-1")
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class found in 'cmdclass' is used in place of the default, which is
dist.run_commands()
except KeyboardInterrupt:
raise SystemExit("interrupted")
except (IOError, os.error) as exc:
except (IOError, OSError) as exc:
error = grok_environment_error(exc)

if DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/dir_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
"cannot copy tree '%s': not a directory" % src)
try:
names = os.listdir(src)
except os.error as e:
except OSError as e:
(errno, errstr) = e
if dry_run:
names = []
Expand Down
16 changes: 8 additions & 8 deletions Lib/distutils/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):
try:
try:
fsrc = open(src, 'rb')
except os.error as e:
except OSError as e:
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))

if os.path.exists(dst):
try:
os.unlink(dst)
except os.error as e:
except OSError as e:
raise DistutilsFileError(
"could not delete '%s': %s" % (dst, e.strerror))

try:
fdst = open(dst, 'wb')
except os.error as e:
except OSError as e:
raise DistutilsFileError(
"could not create '%s': %s" % (dst, e.strerror))

while True:
try:
buf = fsrc.read(buffer_size)
except os.error as e:
except OSError as e:
raise DistutilsFileError(
"could not read from '%s': %s" % (src, e.strerror))

Expand All @@ -55,7 +55,7 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):

try:
fdst.write(buf)
except os.error as e:
except OSError as e:
raise DistutilsFileError(
"could not write to '%s': %s" % (dst, e.strerror))
finally:
Expand Down Expand Up @@ -193,7 +193,7 @@ def move_file (src, dst,
copy_it = False
try:
os.rename(src, dst)
except os.error as e:
except OSError as e:
(num, msg) = e
if num == errno.EXDEV:
copy_it = True
Expand All @@ -205,11 +205,11 @@ def move_file (src, dst,
copy_file(src, dst, verbose=verbose)
try:
os.unlink(src)
except os.error as e:
except OSError as e:
(num, msg) = e
try:
os.unlink(dst)
except os.error:
except OSError:
pass
raise DistutilsFileError(
"couldn't move '%s' to '%s' by copy/delete: "
Expand Down
6 changes: 4 additions & 2 deletions Lib/fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ def readline(self):
if self._inplace:
self._backupfilename = (
self._filename + (self._backup or ".bak"))
try: os.unlink(self._backupfilename)
except os.error: pass
try:
os.unlink(self._backupfilename)
except OSError:
pass
# The next few lines may raise IOError
os.rename(self._filename, self._backupfilename)
self._file = open(self._backupfilename, self._mode)
Expand Down
6 changes: 3 additions & 3 deletions Lib/genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def exists(path):
"""Test whether a path exists. Returns False for broken symbolic links"""
try:
os.stat(path)
except os.error:
except OSError:
return False
return True

Expand All @@ -27,7 +27,7 @@ def isfile(path):
"""Test whether a path is a regular file"""
try:
st = os.stat(path)
except os.error:
except OSError:
return False
return stat.S_ISREG(st.st_mode)

Expand All @@ -39,7 +39,7 @@ def isdir(s):
"""Return true if the pathname refers to an existing directory."""
try:
st = os.stat(s)
except os.error:
except OSError:
return False
return stat.S_ISDIR(st.st_mode)

Expand Down
2 changes: 1 addition & 1 deletion Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def glob1(dirname, pattern):
dirname = os.curdir
try:
names = os.listdir(dirname)
except os.error:
except OSError:
return []
if pattern[0] != '.':
names = [x for x in names if x[0] != '.']
Expand Down
4 changes: 2 additions & 2 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def list_directory(self, path):
"""
try:
list = os.listdir(path)
except os.error:
except OSError:
self.send_error(404, "No permission to list directory")
return None
list.sort(key=lambda a: a.lower())
Expand Down Expand Up @@ -1123,7 +1123,7 @@ def run_cgi(self):
try:
try:
os.setuid(nobody)
except os.error:
except OSError:
pass
os.dup2(self.rfile.fileno(), 0)
os.dup2(self.wfile.fileno(), 1)
Expand Down
4 changes: 2 additions & 2 deletions Lib/lib2to3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def write_file(self, new_text, filename, old_text, encoding):
if os.path.lexists(backup):
try:
os.remove(backup)
except os.error as err:
except OSError as err:
self.log_message("Can't remove backup %s", backup)
try:
os.rename(filename, backup)
except os.error as err:
except OSError as err:
self.log_message("Can't rename %s to %s", filename, backup)
# Actually write the new file
write = super(StdoutRefactoringTool, self).write_file
Expand Down
4 changes: 2 additions & 2 deletions Lib/lib2to3/refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,12 @@ def write_file(self, new_text, filename, old_text, encoding=None):
"""
try:
f = _open_with_encoding(filename, "w", encoding=encoding)
except os.error as err:
except OSError as err:
self.log_error("Can't create %s: %s", filename, err)
return
try:
f.write(_to_system_newlines(new_text))
except os.error as err:
except OSError as err:
self.log_error("Can't write %s: %s", filename, err)
finally:
f.close()
Expand Down
2 changes: 1 addition & 1 deletion Lib/lib2to3/tests/pytree_idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():
for dir in sys.path:
try:
names = os.listdir(dir)
except os.error:
except OSError:
continue
print("Scanning", dir, "...", file=sys.stderr)
for name in names:
Expand Down
4 changes: 2 additions & 2 deletions Lib/linecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def checkcache(filename=None):
continue # no-op for files loaded via a __loader__
try:
stat = os.stat(fullname)
except os.error:
except OSError:
del cache[filename]
continue
if size != stat.st_size or mtime != stat.st_mtime:
Expand Down Expand Up @@ -118,7 +118,7 @@ def updatecache(filename, module_globals=None):
try:
stat = os.stat(fullname)
break
except os.error:
except OSError:
pass
else:
return []
Expand Down
2 changes: 1 addition & 1 deletion Lib/macpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def lexists(path):

try:
st = os.lstat(path)
except os.error:
except OSError:
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion Lib/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def find_all_submodules(self, m):
for dir in m.__path__:
try:
names = os.listdir(dir)
except os.error:
except OSError:
self.msg(2, "can't list directory", dir)
continue
for name in names:
Expand Down
2 changes: 1 addition & 1 deletion Lib/multiprocessing/forking.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def poll(self, flag=os.WNOHANG):
if self.returncode is None:
try:
pid, sts = os.waitpid(self.pid, flag)
except os.error:
except OSError:
# Child process not yet created. See #1731717
# e.errno == errno.ECHILD == 10
return None
Expand Down
4 changes: 2 additions & 2 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def islink(path):
"""
try:
st = os.lstat(path)
except (os.error, AttributeError):
except (OSError, AttributeError):
return False
return stat.S_ISLNK(st.st_mode)

Expand All @@ -331,7 +331,7 @@ def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
st = os.lstat(path)
except (os.error, WindowsError):
except (OSError, WindowsError):
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
By default errors from the os.listdir() call are ignored. If
optional arg 'onerror' is specified, it should be a function; it
will be called with one argument, an os.error instance. It can
will be called with one argument, an OSError instance. It can
report the error to continue with the walk, or raise the exception
to abort the walk. Note that the filename is available as the
filename attribute of the exception object.
Expand Down
10 changes: 5 additions & 5 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def linux_distribution(distname='', version='', id='',
"""
try:
etc = os.listdir('/etc')
except os.error:
except OSError:
# Probably not a Unix system
return distname,version,id
etc.sort()
Expand Down Expand Up @@ -424,10 +424,10 @@ def _syscmd_ver(system='', release='', version='',
pipe = popen(cmd)
info = pipe.read()
if pipe.close():
raise os.error('command failed')
raise OSError('command failed')
# XXX How can I suppress shell errors from being written
# to stderr ?
except os.error as why:
except OSError as why:
#print 'Command %s failed: %s' % (cmd,why)
continue
except IOError as why:
Expand Down Expand Up @@ -906,7 +906,7 @@ def _syscmd_uname(option,default=''):
return default
try:
f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
except (AttributeError,os.error):
except (AttributeError, OSError):
return default
output = f.read().strip()
rc = f.close()
Expand All @@ -932,7 +932,7 @@ def _syscmd_file(target,default=''):
proc = subprocess.Popen(['file', target],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

except (AttributeError,os.error):
except (AttributeError, OSError):
return default
output = proc.communicate()[0].decode('latin-1')
rc = proc.wait()
Expand Down
6 changes: 3 additions & 3 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def islink(path):
"""Test whether a path is a symbolic link"""
try:
st = os.lstat(path)
except (os.error, AttributeError):
except (OSError, AttributeError):
return False
return stat.S_ISLNK(st.st_mode)

Expand All @@ -172,7 +172,7 @@ def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
os.lstat(path)
except os.error:
except OSError:
return False
return True

Expand Down Expand Up @@ -220,7 +220,7 @@ def ismount(path):
else:
parent = join(path, '..')
s2 = os.lstat(parent)
except os.error:
except OSError:
return False # It doesn't exist -- so not a mount point :-)
dev1 = s1.st_dev
dev2 = s2.st_dev
Expand Down
6 changes: 3 additions & 3 deletions Lib/pty.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ def _open_terminal():
try:
tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
except IOError as msg:
raise os.error(msg)
raise OSError(msg)
return master_fd, tty_name
for x in 'pqrstuvwxyzPQRST':
for y in '0123456789abcdef':
pty_name = '/dev/pty' + x + y
try:
fd = os.open(pty_name, os.O_RDWR)
except os.error:
except OSError:
continue
return (fd, '/dev/tty' + x + y)
raise os.error('out of pty devices')
raise OSError('out of pty devices')

def slave_open(tty_name):
"""slave_open(tty_name) -> slave_fd
Expand Down
Loading

0 comments on commit ad28c7f

Please sign in to comment.