mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #16706: get rid of os.error
This commit is contained in:
parent
a191959849
commit
ad28c7f9da
33 changed files with 4089 additions and 4123 deletions
|
@ -200,7 +200,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
|
||||||
buffering = DEFAULT_BUFFER_SIZE
|
buffering = DEFAULT_BUFFER_SIZE
|
||||||
try:
|
try:
|
||||||
bs = os.fstat(raw.fileno()).st_blksize
|
bs = os.fstat(raw.fileno()).st_blksize
|
||||||
except (os.error, AttributeError):
|
except (OSError, AttributeError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if bs > 1:
|
if bs > 1:
|
||||||
|
|
|
@ -949,7 +949,7 @@ def print_directory():
|
||||||
print("<H3>Current Working Directory:</H3>")
|
print("<H3>Current Working Directory:</H3>")
|
||||||
try:
|
try:
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
except os.error as msg:
|
except OSError as msg:
|
||||||
print("os.error:", html.escape(str(msg)))
|
print("os.error:", html.escape(str(msg)))
|
||||||
else:
|
else:
|
||||||
print(html.escape(pwd))
|
print(html.escape(pwd))
|
||||||
|
|
|
@ -38,7 +38,7 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
|
||||||
print('Listing {!r}...'.format(dir))
|
print('Listing {!r}...'.format(dir))
|
||||||
try:
|
try:
|
||||||
names = os.listdir(dir)
|
names = os.listdir(dir)
|
||||||
except os.error:
|
except OSError:
|
||||||
print("Can't list {!r}".format(dir))
|
print("Can't list {!r}".format(dir))
|
||||||
names = []
|
names = []
|
||||||
names.sort()
|
names.sort()
|
||||||
|
|
|
@ -100,12 +100,12 @@ class _Database(collections.MutableMapping):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._os.unlink(self._bakfile)
|
self._os.unlink(self._bakfile)
|
||||||
except self._os.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._os.rename(self._dirfile, self._bakfile)
|
self._os.rename(self._dirfile, self._bakfile)
|
||||||
except self._os.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
f = self._io.open(self._dirfile, 'w', encoding="Latin-1")
|
f = self._io.open(self._dirfile, 'w', encoding="Latin-1")
|
||||||
|
|
|
@ -148,7 +148,7 @@ def setup (**attrs):
|
||||||
dist.run_commands()
|
dist.run_commands()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise SystemExit("interrupted")
|
raise SystemExit("interrupted")
|
||||||
except (IOError, os.error) as exc:
|
except (IOError, OSError) as exc:
|
||||||
error = grok_environment_error(exc)
|
error = grok_environment_error(exc)
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
|
|
@ -124,7 +124,7 @@ def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
|
||||||
"cannot copy tree '%s': not a directory" % src)
|
"cannot copy tree '%s': not a directory" % src)
|
||||||
try:
|
try:
|
||||||
names = os.listdir(src)
|
names = os.listdir(src)
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
(errno, errstr) = e
|
(errno, errstr) = e
|
||||||
if dry_run:
|
if dry_run:
|
||||||
names = []
|
names = []
|
||||||
|
|
|
@ -27,26 +27,26 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
fsrc = open(src, 'rb')
|
fsrc = open(src, 'rb')
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
|
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
|
||||||
|
|
||||||
if os.path.exists(dst):
|
if os.path.exists(dst):
|
||||||
try:
|
try:
|
||||||
os.unlink(dst)
|
os.unlink(dst)
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not delete '%s': %s" % (dst, e.strerror))
|
"could not delete '%s': %s" % (dst, e.strerror))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fdst = open(dst, 'wb')
|
fdst = open(dst, 'wb')
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not create '%s': %s" % (dst, e.strerror))
|
"could not create '%s': %s" % (dst, e.strerror))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
buf = fsrc.read(buffer_size)
|
buf = fsrc.read(buffer_size)
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not read from '%s': %s" % (src, e.strerror))
|
"could not read from '%s': %s" % (src, e.strerror))
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fdst.write(buf)
|
fdst.write(buf)
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not write to '%s': %s" % (dst, e.strerror))
|
"could not write to '%s': %s" % (dst, e.strerror))
|
||||||
finally:
|
finally:
|
||||||
|
@ -193,7 +193,7 @@ def move_file (src, dst,
|
||||||
copy_it = False
|
copy_it = False
|
||||||
try:
|
try:
|
||||||
os.rename(src, dst)
|
os.rename(src, dst)
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
(num, msg) = e
|
(num, msg) = e
|
||||||
if num == errno.EXDEV:
|
if num == errno.EXDEV:
|
||||||
copy_it = True
|
copy_it = True
|
||||||
|
@ -205,11 +205,11 @@ def move_file (src, dst,
|
||||||
copy_file(src, dst, verbose=verbose)
|
copy_file(src, dst, verbose=verbose)
|
||||||
try:
|
try:
|
||||||
os.unlink(src)
|
os.unlink(src)
|
||||||
except os.error as e:
|
except OSError as e:
|
||||||
(num, msg) = e
|
(num, msg) = e
|
||||||
try:
|
try:
|
||||||
os.unlink(dst)
|
os.unlink(dst)
|
||||||
except os.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"couldn't move '%s' to '%s' by copy/delete: "
|
"couldn't move '%s' to '%s' by copy/delete: "
|
||||||
|
|
|
@ -324,8 +324,10 @@ class FileInput:
|
||||||
if self._inplace:
|
if self._inplace:
|
||||||
self._backupfilename = (
|
self._backupfilename = (
|
||||||
self._filename + (self._backup or ".bak"))
|
self._filename + (self._backup or ".bak"))
|
||||||
try: os.unlink(self._backupfilename)
|
try:
|
||||||
except os.error: pass
|
os.unlink(self._backupfilename)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
# The next few lines may raise IOError
|
# The next few lines may raise IOError
|
||||||
os.rename(self._filename, self._backupfilename)
|
os.rename(self._filename, self._backupfilename)
|
||||||
self._file = open(self._backupfilename, self._mode)
|
self._file = open(self._backupfilename, self._mode)
|
||||||
|
|
|
@ -16,7 +16,7 @@ def exists(path):
|
||||||
"""Test whether a path exists. Returns False for broken symbolic links"""
|
"""Test whether a path exists. Returns False for broken symbolic links"""
|
||||||
try:
|
try:
|
||||||
os.stat(path)
|
os.stat(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ def isfile(path):
|
||||||
"""Test whether a path is a regular file"""
|
"""Test whether a path is a regular file"""
|
||||||
try:
|
try:
|
||||||
st = os.stat(path)
|
st = os.stat(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
return stat.S_ISREG(st.st_mode)
|
return stat.S_ISREG(st.st_mode)
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ def isdir(s):
|
||||||
"""Return true if the pathname refers to an existing directory."""
|
"""Return true if the pathname refers to an existing directory."""
|
||||||
try:
|
try:
|
||||||
st = os.stat(s)
|
st = os.stat(s)
|
||||||
except os.error:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
return stat.S_ISDIR(st.st_mode)
|
return stat.S_ISDIR(st.st_mode)
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ def glob1(dirname, pattern):
|
||||||
dirname = os.curdir
|
dirname = os.curdir
|
||||||
try:
|
try:
|
||||||
names = os.listdir(dirname)
|
names = os.listdir(dirname)
|
||||||
except os.error:
|
except OSError:
|
||||||
return []
|
return []
|
||||||
if pattern[0] != '.':
|
if pattern[0] != '.':
|
||||||
names = [x for x in names if x[0] != '.']
|
names = [x for x in names if x[0] != '.']
|
||||||
|
|
|
@ -732,7 +732,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
list = os.listdir(path)
|
list = os.listdir(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
self.send_error(404, "No permission to list directory")
|
self.send_error(404, "No permission to list directory")
|
||||||
return None
|
return None
|
||||||
list.sort(key=lambda a: a.lower())
|
list.sort(key=lambda a: a.lower())
|
||||||
|
@ -1123,7 +1123,7 @@ class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
os.setuid(nobody)
|
os.setuid(nobody)
|
||||||
except os.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
os.dup2(self.rfile.fileno(), 0)
|
os.dup2(self.rfile.fileno(), 0)
|
||||||
os.dup2(self.wfile.fileno(), 1)
|
os.dup2(self.wfile.fileno(), 1)
|
||||||
|
|
|
@ -90,11 +90,11 @@ class StdoutRefactoringTool(refactor.MultiprocessRefactoringTool):
|
||||||
if os.path.lexists(backup):
|
if os.path.lexists(backup):
|
||||||
try:
|
try:
|
||||||
os.remove(backup)
|
os.remove(backup)
|
||||||
except os.error as err:
|
except OSError as err:
|
||||||
self.log_message("Can't remove backup %s", backup)
|
self.log_message("Can't remove backup %s", backup)
|
||||||
try:
|
try:
|
||||||
os.rename(filename, backup)
|
os.rename(filename, backup)
|
||||||
except os.error as err:
|
except OSError as err:
|
||||||
self.log_message("Can't rename %s to %s", filename, backup)
|
self.log_message("Can't rename %s to %s", filename, backup)
|
||||||
# Actually write the new file
|
# Actually write the new file
|
||||||
write = super(StdoutRefactoringTool, self).write_file
|
write = super(StdoutRefactoringTool, self).write_file
|
||||||
|
|
|
@ -534,12 +534,12 @@ class RefactoringTool(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
f = _open_with_encoding(filename, "w", encoding=encoding)
|
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)
|
self.log_error("Can't create %s: %s", filename, err)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
f.write(_to_system_newlines(new_text))
|
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)
|
self.log_error("Can't write %s: %s", filename, err)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
@ -53,7 +53,7 @@ def main():
|
||||||
for dir in sys.path:
|
for dir in sys.path:
|
||||||
try:
|
try:
|
||||||
names = os.listdir(dir)
|
names = os.listdir(dir)
|
||||||
except os.error:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
print("Scanning", dir, "...", file=sys.stderr)
|
print("Scanning", dir, "...", file=sys.stderr)
|
||||||
for name in names:
|
for name in names:
|
||||||
|
|
|
@ -59,7 +59,7 @@ def checkcache(filename=None):
|
||||||
continue # no-op for files loaded via a __loader__
|
continue # no-op for files loaded via a __loader__
|
||||||
try:
|
try:
|
||||||
stat = os.stat(fullname)
|
stat = os.stat(fullname)
|
||||||
except os.error:
|
except OSError:
|
||||||
del cache[filename]
|
del cache[filename]
|
||||||
continue
|
continue
|
||||||
if size != stat.st_size or mtime != stat.st_mtime:
|
if size != stat.st_size or mtime != stat.st_mtime:
|
||||||
|
@ -118,7 +118,7 @@ def updatecache(filename, module_globals=None):
|
||||||
try:
|
try:
|
||||||
stat = os.stat(fullname)
|
stat = os.stat(fullname)
|
||||||
break
|
break
|
||||||
except os.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -127,7 +127,7 @@ def lexists(path):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
st = os.lstat(path)
|
st = os.lstat(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ class ModuleFinder:
|
||||||
for dir in m.__path__:
|
for dir in m.__path__:
|
||||||
try:
|
try:
|
||||||
names = os.listdir(dir)
|
names = os.listdir(dir)
|
||||||
except os.error:
|
except OSError:
|
||||||
self.msg(2, "can't list directory", dir)
|
self.msg(2, "can't list directory", dir)
|
||||||
continue
|
continue
|
||||||
for name in names:
|
for name in names:
|
||||||
|
|
|
@ -111,7 +111,7 @@ if sys.platform != 'win32':
|
||||||
if self.returncode is None:
|
if self.returncode is None:
|
||||||
try:
|
try:
|
||||||
pid, sts = os.waitpid(self.pid, flag)
|
pid, sts = os.waitpid(self.pid, flag)
|
||||||
except os.error:
|
except OSError:
|
||||||
# Child process not yet created. See #1731717
|
# Child process not yet created. See #1731717
|
||||||
# e.errno == errno.ECHILD == 10
|
# e.errno == errno.ECHILD == 10
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -321,7 +321,7 @@ def islink(path):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
st = os.lstat(path)
|
st = os.lstat(path)
|
||||||
except (os.error, AttributeError):
|
except (OSError, AttributeError):
|
||||||
return False
|
return False
|
||||||
return stat.S_ISLNK(st.st_mode)
|
return stat.S_ISLNK(st.st_mode)
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ def lexists(path):
|
||||||
"""Test whether a path exists. Returns True for broken symbolic links"""
|
"""Test whether a path exists. Returns True for broken symbolic links"""
|
||||||
try:
|
try:
|
||||||
st = os.lstat(path)
|
st = os.lstat(path)
|
||||||
except (os.error, WindowsError):
|
except (OSError, WindowsError):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
|
||||||
|
|
||||||
By default errors from the os.listdir() call are ignored. If
|
By default errors from the os.listdir() call are ignored. If
|
||||||
optional arg 'onerror' is specified, it should be a function; it
|
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
|
report the error to continue with the walk, or raise the exception
|
||||||
to abort the walk. Note that the filename is available as the
|
to abort the walk. Note that the filename is available as the
|
||||||
filename attribute of the exception object.
|
filename attribute of the exception object.
|
||||||
|
|
|
@ -316,7 +316,7 @@ def linux_distribution(distname='', version='', id='',
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
etc = os.listdir('/etc')
|
etc = os.listdir('/etc')
|
||||||
except os.error:
|
except OSError:
|
||||||
# Probably not a Unix system
|
# Probably not a Unix system
|
||||||
return distname,version,id
|
return distname,version,id
|
||||||
etc.sort()
|
etc.sort()
|
||||||
|
@ -424,10 +424,10 @@ def _syscmd_ver(system='', release='', version='',
|
||||||
pipe = popen(cmd)
|
pipe = popen(cmd)
|
||||||
info = pipe.read()
|
info = pipe.read()
|
||||||
if pipe.close():
|
if pipe.close():
|
||||||
raise os.error('command failed')
|
raise OSError('command failed')
|
||||||
# XXX How can I suppress shell errors from being written
|
# XXX How can I suppress shell errors from being written
|
||||||
# to stderr ?
|
# to stderr ?
|
||||||
except os.error as why:
|
except OSError as why:
|
||||||
#print 'Command %s failed: %s' % (cmd,why)
|
#print 'Command %s failed: %s' % (cmd,why)
|
||||||
continue
|
continue
|
||||||
except IOError as why:
|
except IOError as why:
|
||||||
|
@ -906,7 +906,7 @@ def _syscmd_uname(option,default=''):
|
||||||
return default
|
return default
|
||||||
try:
|
try:
|
||||||
f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
|
f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
|
||||||
except (AttributeError,os.error):
|
except (AttributeError, OSError):
|
||||||
return default
|
return default
|
||||||
output = f.read().strip()
|
output = f.read().strip()
|
||||||
rc = f.close()
|
rc = f.close()
|
||||||
|
@ -932,7 +932,7 @@ def _syscmd_file(target,default=''):
|
||||||
proc = subprocess.Popen(['file', target],
|
proc = subprocess.Popen(['file', target],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
except (AttributeError,os.error):
|
except (AttributeError, OSError):
|
||||||
return default
|
return default
|
||||||
output = proc.communicate()[0].decode('latin-1')
|
output = proc.communicate()[0].decode('latin-1')
|
||||||
rc = proc.wait()
|
rc = proc.wait()
|
||||||
|
|
|
@ -162,7 +162,7 @@ def islink(path):
|
||||||
"""Test whether a path is a symbolic link"""
|
"""Test whether a path is a symbolic link"""
|
||||||
try:
|
try:
|
||||||
st = os.lstat(path)
|
st = os.lstat(path)
|
||||||
except (os.error, AttributeError):
|
except (OSError, AttributeError):
|
||||||
return False
|
return False
|
||||||
return stat.S_ISLNK(st.st_mode)
|
return stat.S_ISLNK(st.st_mode)
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ def lexists(path):
|
||||||
"""Test whether a path exists. Returns True for broken symbolic links"""
|
"""Test whether a path exists. Returns True for broken symbolic links"""
|
||||||
try:
|
try:
|
||||||
os.lstat(path)
|
os.lstat(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ def ismount(path):
|
||||||
else:
|
else:
|
||||||
parent = join(path, '..')
|
parent = join(path, '..')
|
||||||
s2 = os.lstat(parent)
|
s2 = os.lstat(parent)
|
||||||
except os.error:
|
except OSError:
|
||||||
return False # It doesn't exist -- so not a mount point :-)
|
return False # It doesn't exist -- so not a mount point :-)
|
||||||
dev1 = s1.st_dev
|
dev1 = s1.st_dev
|
||||||
dev2 = s2.st_dev
|
dev2 = s2.st_dev
|
||||||
|
|
|
@ -57,17 +57,17 @@ def _open_terminal():
|
||||||
try:
|
try:
|
||||||
tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
|
tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
|
||||||
except IOError as msg:
|
except IOError as msg:
|
||||||
raise os.error(msg)
|
raise OSError(msg)
|
||||||
return master_fd, tty_name
|
return master_fd, tty_name
|
||||||
for x in 'pqrstuvwxyzPQRST':
|
for x in 'pqrstuvwxyzPQRST':
|
||||||
for y in '0123456789abcdef':
|
for y in '0123456789abcdef':
|
||||||
pty_name = '/dev/pty' + x + y
|
pty_name = '/dev/pty' + x + y
|
||||||
try:
|
try:
|
||||||
fd = os.open(pty_name, os.O_RDWR)
|
fd = os.open(pty_name, os.O_RDWR)
|
||||||
except os.error:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
return (fd, '/dev/tty' + x + y)
|
return (fd, '/dev/tty' + x + y)
|
||||||
raise os.error('out of pty devices')
|
raise OSError('out of pty devices')
|
||||||
|
|
||||||
def slave_open(tty_name):
|
def slave_open(tty_name):
|
||||||
"""slave_open(tty_name) -> slave_fd
|
"""slave_open(tty_name) -> slave_fd
|
||||||
|
|
|
@ -356,24 +356,24 @@ def _rmtree_unsafe(path, onerror):
|
||||||
names = []
|
names = []
|
||||||
try:
|
try:
|
||||||
names = os.listdir(path)
|
names = os.listdir(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
onerror(os.listdir, path, sys.exc_info())
|
onerror(os.listdir, path, sys.exc_info())
|
||||||
for name in names:
|
for name in names:
|
||||||
fullname = os.path.join(path, name)
|
fullname = os.path.join(path, name)
|
||||||
try:
|
try:
|
||||||
mode = os.lstat(fullname).st_mode
|
mode = os.lstat(fullname).st_mode
|
||||||
except os.error:
|
except OSError:
|
||||||
mode = 0
|
mode = 0
|
||||||
if stat.S_ISDIR(mode):
|
if stat.S_ISDIR(mode):
|
||||||
_rmtree_unsafe(fullname, onerror)
|
_rmtree_unsafe(fullname, onerror)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.unlink(fullname)
|
os.unlink(fullname)
|
||||||
except os.error:
|
except OSError:
|
||||||
onerror(os.unlink, fullname, sys.exc_info())
|
onerror(os.unlink, fullname, sys.exc_info())
|
||||||
try:
|
try:
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
onerror(os.rmdir, path, sys.exc_info())
|
onerror(os.rmdir, path, sys.exc_info())
|
||||||
|
|
||||||
# Version using fd-based APIs to protect against races
|
# Version using fd-based APIs to protect against races
|
||||||
|
@ -464,7 +464,7 @@ def rmtree(path, ignore_errors=False, onerror=None):
|
||||||
_rmtree_safe_fd(fd, path, onerror)
|
_rmtree_safe_fd(fd, path, onerror)
|
||||||
try:
|
try:
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
except os.error:
|
except OSError:
|
||||||
onerror(os.rmdir, path, sys.exc_info())
|
onerror(os.rmdir, path, sys.exc_info())
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -196,7 +196,7 @@ def addsitedir(sitedir, known_paths=None):
|
||||||
known_paths.add(sitedircase)
|
known_paths.add(sitedircase)
|
||||||
try:
|
try:
|
||||||
names = os.listdir(sitedir)
|
names = os.listdir(sitedir)
|
||||||
except os.error:
|
except OSError:
|
||||||
return
|
return
|
||||||
names = [name for name in names if name.endswith(".pth")]
|
names = [name for name in names if name.endswith(".pth")]
|
||||||
for name in sorted(names):
|
for name in sorted(names):
|
||||||
|
|
|
@ -532,7 +532,7 @@ class ForkingMixIn:
|
||||||
# children.
|
# children.
|
||||||
try:
|
try:
|
||||||
pid, status = os.waitpid(0, 0)
|
pid, status = os.waitpid(0, 0)
|
||||||
except os.error:
|
except OSError:
|
||||||
pid = None
|
pid = None
|
||||||
if pid not in self.active_children: continue
|
if pid not in self.active_children: continue
|
||||||
self.active_children.remove(pid)
|
self.active_children.remove(pid)
|
||||||
|
@ -545,7 +545,7 @@ class ForkingMixIn:
|
||||||
for child in self.active_children:
|
for child in self.active_children:
|
||||||
try:
|
try:
|
||||||
pid, status = os.waitpid(child, os.WNOHANG)
|
pid, status = os.waitpid(child, os.WNOHANG)
|
||||||
except os.error:
|
except OSError:
|
||||||
pid = None
|
pid = None
|
||||||
if not pid: continue
|
if not pid: continue
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1444,7 +1444,7 @@ class Popen(object):
|
||||||
|
|
||||||
|
|
||||||
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
|
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
|
||||||
_WNOHANG=os.WNOHANG, _os_error=os.error):
|
_WNOHANG=os.WNOHANG):
|
||||||
"""Check if child process has terminated. Returns returncode
|
"""Check if child process has terminated. Returns returncode
|
||||||
attribute.
|
attribute.
|
||||||
|
|
||||||
|
@ -1457,7 +1457,7 @@ class Popen(object):
|
||||||
pid, sts = _waitpid(self.pid, _WNOHANG)
|
pid, sts = _waitpid(self.pid, _WNOHANG)
|
||||||
if pid == self.pid:
|
if pid == self.pid:
|
||||||
self._handle_exitstatus(sts)
|
self._handle_exitstatus(sts)
|
||||||
except _os_error as e:
|
except OSError as e:
|
||||||
if _deadstate is not None:
|
if _deadstate is not None:
|
||||||
self.returncode = _deadstate
|
self.returncode = _deadstate
|
||||||
elif e.errno == errno.ECHILD:
|
elif e.errno == errno.ECHILD:
|
||||||
|
|
|
@ -665,7 +665,6 @@ class TemporaryDirectory(object):
|
||||||
_islink = staticmethod(_os.path.islink)
|
_islink = staticmethod(_os.path.islink)
|
||||||
_remove = staticmethod(_os.remove)
|
_remove = staticmethod(_os.remove)
|
||||||
_rmdir = staticmethod(_os.rmdir)
|
_rmdir = staticmethod(_os.rmdir)
|
||||||
_os_error = OSError
|
|
||||||
_warn = _warnings.warn
|
_warn = _warnings.warn
|
||||||
|
|
||||||
def _rmtree(self, path):
|
def _rmtree(self, path):
|
||||||
|
@ -675,16 +674,16 @@ class TemporaryDirectory(object):
|
||||||
fullname = self._path_join(path, name)
|
fullname = self._path_join(path, name)
|
||||||
try:
|
try:
|
||||||
isdir = self._isdir(fullname) and not self._islink(fullname)
|
isdir = self._isdir(fullname) and not self._islink(fullname)
|
||||||
except self._os_error:
|
except OSError:
|
||||||
isdir = False
|
isdir = False
|
||||||
if isdir:
|
if isdir:
|
||||||
self._rmtree(fullname)
|
self._rmtree(fullname)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self._remove(fullname)
|
self._remove(fullname)
|
||||||
except self._os_error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self._rmdir(path)
|
self._rmdir(path)
|
||||||
except self._os_error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -35,7 +35,7 @@ def randfloats(n):
|
||||||
if fp:
|
if fp:
|
||||||
try:
|
try:
|
||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
except os.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
except IOError as msg:
|
except IOError as msg:
|
||||||
print("can't write", fn, ":", msg)
|
print("can't write", fn, ":", msg)
|
||||||
|
|
|
@ -82,7 +82,7 @@ class SocketServerTest(unittest.TestCase):
|
||||||
for fn in self.test_files:
|
for fn in self.test_files:
|
||||||
try:
|
try:
|
||||||
os.remove(fn)
|
os.remove(fn)
|
||||||
except os.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
self.test_files[:] = []
|
self.test_files[:] = []
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ class TestCandidateTempdirList(BaseTestCase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dirname = os.getcwd()
|
dirname = os.getcwd()
|
||||||
except (AttributeError, os.error):
|
except (AttributeError, OSError):
|
||||||
dirname = os.curdir
|
dirname = os.curdir
|
||||||
|
|
||||||
self.assertIn(dirname, cand)
|
self.assertIn(dirname, cand)
|
||||||
|
@ -924,7 +924,7 @@ class TestTemporaryDirectory(BaseTestCase):
|
||||||
# (noted as part of Issue #10188)
|
# (noted as part of Issue #10188)
|
||||||
with tempfile.TemporaryDirectory() as nonexistent:
|
with tempfile.TemporaryDirectory() as nonexistent:
|
||||||
pass
|
pass
|
||||||
with self.assertRaises(os.error):
|
with self.assertRaises(OSError):
|
||||||
tempfile.TemporaryDirectory(dir=nonexistent)
|
tempfile.TemporaryDirectory(dir=nonexistent)
|
||||||
|
|
||||||
def test_explicit_cleanup(self):
|
def test_explicit_cleanup(self):
|
||||||
|
|
|
@ -11,7 +11,7 @@ try:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.write(fd, b"blat")
|
os.write(fd, b"blat")
|
||||||
except os.error:
|
except OSError:
|
||||||
# Success -- could not write to fd.
|
# Success -- could not write to fd.
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
|
|
8079
Python/importlib.h
8079
Python/importlib.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue