8000 Issue #16706: get rid of os.error · python/cpython@ad28c7f · GitHub
[go: up one dir, main page]

Skip to content

Commit ad28c7f

Browse files
committed
Issue #16706: get rid of os.error
1 parent a191959 commit ad28c7f

33 files changed

+4069
-4103
lines changed

Lib/_pyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
200200
buffering = DEFAULT_BUFFER_SIZE
201201
try:
202202
bs = os.fstat(raw.fileno()).st_blksize
203-
except (os.error, AttributeError):
203+
except (OSError, AttributeError):
204204
pass
205205
else:
206206
if bs > 1:

Lib/cgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ def print_directory():
949949
print("<H3>Current Working Directory:</H3>")
950950
try:
951951
pwd = os.getcwd()
952-
except os.error as msg:
952+
except OSError as msg:
953953
print("os.error:", html.escape(str(msg)))
954954
else:
955955
print(html.escape(pwd))

Lib/compileall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
3838
print('Listing {!r}...'.format(dir))
3939
try:
4040
names = os.listdir(dir)
41-
except os.error:
41+
except OSError:
4242
print("Can't list {!r}".format(dir))
4343
names = []
4444
names.sort()

Lib/dbm/dumb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ def _commit(self):
100100

101101
try:
102102
self._os.unlink(self._bakfile)
103-
except self._os.error:
103+
except OSError:
104104
pass
105105

106106
try:
107107
self._os.rename(self._dirfile, self._bakfile)
108-
except self._os.error:
108+
except OSError:
109109
pass
110110

111111
f = self._io.open(self._dirfile, 'w', encoding="Latin-1")

Lib/distutils/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class found in 'cmdclass' is used in place of the default, which is
148148
dist.run_commands()
149149
except KeyboardInterrupt:
150150
raise SystemExit("interrupted")
151-
except (IOError, os.error) as exc:
151+
except (IOError, OSError) as exc:
152152
error = grok_environment_error(exc)
153153

154154
if DEBUG:

Lib/distutils/dir_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
124124
"cannot copy tree '%s': not a directory" % src)
125125
try:
126126
names = os.listdir(src)
127-
except os.error as e:
127+
except OSError as e:
128128
(errno, errstr) = e
129129
if dry_run:
130130
names = []

Lib/distutils/file_util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):
2727
try:
2828
try:
2929
fsrc = open(src, 'rb')
30-
except os.error as e:
30+
except OSError as e:
3131
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
3232

3333
if os.path.exists(dst):
3434
try:
3535
os.unlink(dst)
36-
except os.error as e:
36+
except OSError as e:
3737
raise DistutilsFileError(
3838
"could not delete '%s': %s" % (dst, e.strerror))
3939

4040
try:
4141
fdst = open(dst, 'wb')
42-
except os.error as e:
42+
except OSError as e:
4343
raise DistutilsFileError(
4444
"could not create '%s': %s" % (dst, e.strerror))
4545

4646
while True:
4747
try:
4848
buf = fsrc.read(buffer_size)
49-
except os.error as e:
49+
except OSError as e:
5050
raise DistutilsFileError(
5151
"could not read from '%s': %s" % (src, e.strerror))
5252

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

5656
try:
5757
fdst.write(buf)
58-
except os.error as e:
58+
except OSError as e:
5959
raise DistutilsFileError(
6060
"could not write to '%s': %s" % (dst, e.strerror))
6161
finally:
@@ -193,7 +193,7 @@ def move_file (src, dst,
193193
copy_it = False
194194
try:
195195
os.rename(src, dst)
196-
except os.error as e:
196+
except OSError as e:
197197
(num, msg) = e
198198
if num == errno.EXDEV:
199199
copy_it = True
@@ -205,11 +205,11 @@ def move_file (src, dst,
205205
copy_file(src, dst, verbose=verbose)
206206
try:
207207
os.unlink(src)
208-
except os.error as e:
208+
except OSError as e:
209209
(num, msg) = e
210210
try:
211211
os.unlink(dst)
212-
except os.error:
212+
except OSError:
213213
pass
214214
raise DistutilsFileError(
215215
"couldn't move '%s' to '%s' by copy/delete: "

Lib/fileinput.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ def readline(self):
324324
if self._inplace:
325325
self._backupfilename = (
326326
self._filename + (self._backup or ".bak"))
327-
try: os.unlink(self._backupfilename)
328-
except os.error: pass
327+
try:
328+
os.unlink(self._backupfilename)
329+
except OSError:
330+
pass
329331
# The next few lines may raise IOError
330332
os.rename(self._filename, self._backupfilename)
331333
self._file = open(self._backupfilename, self._mode)

Lib/genericpath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def exists(path):
1616
"""Test whether a path exists. Returns False for broken symbolic links"""
1717
try:
1818
os.stat(path)
19-
except os.error:
19+
except OSError:
2020
return False
2121
return True
2222

@@ -27,7 +27,7 @@ def isfile(path):
2727
"""Test whether a path is a regular file"""
2828
try:
2929
st = os.stat(path)
30-
except os.error:
30+
except OSError:
3131
return False
3232
return stat.S_ISREG(st.st_mode)
3333

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

Lib/glob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def glob1(dirname, pattern):
5555
dirname = os.curdir
5656
try:
5757
names = os.listdir(dirname)
58-
except os.error:
58+
except OSError:
5959
return []
6060
if pattern[0] != '.':
6161
names = [x for x in names if x[0] != '.']

Lib/http/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def list_directory(self, path):
732732
"""
733733
try:
734734
list = os.listdir(path)
735-
except os.error:
735+
except OSError:
736736
self.send_error(404, "No permission to list directory")
737737
return None
738738
list.sort(key=lambda a: a.lower())
@@ -1123,7 +1123,7 @@ def run_cgi(self):
11231123
try:
11241124
try:
11251125
os.setuid(nobody)
1126-
except os.error:
1126+
except OSError:
11271127
pass
11281128
os.dup2(self.rfile.fileno(), 0)
11291129
os.dup2(self.wfile.fileno(), 1)

Lib/lib2to3/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def write_file(self, new_text, filename, old_text, encoding):
9090
if os.path.lexists(backup):
9191
try:
9292
os.remove(backup)
93-
except os.error as err:
93+
except OSError as err:
9494
self.log_message("Can't remove backup %s", backup)
9595
try:
9696
os.rename(filename, backup)
97-
except os.error as err:
97+
except OSError as err:
9898
self.log_message("Can't rename %s to %s", filename, backup)
9999
# Actually write the new file
100100
write = super(StdoutRefactoringTool, self).write_file

Lib/lib2to3/refactor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,12 @@ def write_file(self, new_text, filename, old_text, encoding=None):
534534
"""
535535
try:
536536
f = _open_with_encoding(filename, "w", encoding=encoding)
537-
except os.error as err:
537+
except OSError as err:
538538
self.log_error("Can't create %s: %s", filename, err)
539539
return
540540
try:
541541
f.write(_to_system_newlines(new_text))
542-
except os.error as err:
542+
except OSError as err:
543543
self.log_error("Can't write %s: %s", filename, err)
544544
finally:
545545
f.close()

Lib/lib2to3/tests/pytree_idempotency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def main():
5353
for dir in sys.path:
5454
try:
5555
names = os.listdir(dir)
56-
except os.error:
56+
except OSError:
5757
continue
5858
print("Scanning", dir, "...", file=sys.stderr)
5959
for name in names:

Lib/linecache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def checkcache(filename=None):
5959
continue # no-op for files loaded via a __loader__
6060
try:
6161
stat = os.stat(fullname)
62-
except os.error:
62+
except OSError:
6363
del cache[filename]
6464
continue
6565
if size != stat.st_size or mtime != stat.st_mtime:
@@ -118,7 +118,7 @@ def updatecache(filename, module_globals=None):
118118
try:
119119
stat = os.stat(fullname)
120120
break
121-
except os.error:
121+
except OSError:
122122
pass
123123
else:
124124
return []

Lib/macpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def lexists(path):
127127

128128
try:
129129
st = os.lstat(path)
130-
except os.error:
130+
except OSError:
131131
return False
132132
return True
133133

Lib/modulefinder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def find_all_submodules(self, m):
228228
for dir in m.__path__:
229229
try:
230230
names = os.listdir(dir)
231-
except os.error:
231+
except OSError:
232232
self.msg(2, "can't list directory", dir)
233233
continue
234234
for name in names:

Lib/multiprocessing/forking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def poll(self, flag=os.WNOHANG):
111111
if self.returncode is None:
112112
try:
113113
pid, sts = os.waitpid(self.pid, flag)
114-
except os.error:
114+
except OSError:
115115
# Child process not yet created. See #1731717
116116
# e.errno == errno.ECHILD == 10
117117
return None

Lib/ntpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def islink(path):
321321
"""
322322
try:
323323
st = os.lstat(path)
324-
except (os.error, AttributeError):
324+
except (OSError, AttributeError):
325325
return False
326326
return stat.S_ISLNK(st.st_mode)
327327

@@ -331,7 +331,7 @@ def lexists(path):
331331
"""Test whether a path exists. Returns True for broken symbolic links"""
332332
try:
333333
st = os.lstat(path)
334-
except (os.error, WindowsError):
334+
except (OSError, WindowsError):
335335
return False
336336
return True
337337

Lib/os.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
338338
339339
By default errors from the os.listdir() call are ignored. If
340340
optional arg 'onerror' is specified, it should be a function; it
341-
will be called with one argument, an os.error instance. It can
341+
will be called with one argument, an OSError instance. It can
342342
report the error to continue with the walk, or raise the exception
343343
to abort the walk. Note that the filename is available as the
344344
filename attribute of the exception object.

Lib/platform.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def linux_distribution(distname='', version='', id='',
316316
"""
317317
try:
318318
etc = os.listdir('/etc')
319-
except os.error:
319+
except OSError:
320320
# Probably not a Unix system
321321
return distname,version,id
322322
etc.sort()
@@ -424,10 +424,10 @@ def _syscmd_ver(system='', release='', version='',
424424
pipe = popen(cmd)
425425
info = pipe.read()
426426
if pipe.close():
427-
raise os.error('command failed')
427+
raise OSError('command failed')
428428
# XXX How 10000 can I suppress shell errors from being written
429429
# to stderr ?
430-
except os.error as why:
430+
except OSError as why:
431431
#print 'Command %s failed: %s' % (cmd,why)
432432
continue
433433
except IOError as why:
@@ -906,7 +906,7 @@ def _syscmd_uname(option,default=''):
906906
return default
907907
try:
908908
f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
909-
except (AttributeError,os.error):
909+
except (AttributeError, OSError):
910910
return default
911911
output = f.read().strip()
912912
rc = f.close()
@@ -932,7 +932,7 @@ def _syscmd_file(target,default=''):
932932
proc = subprocess.Popen(['file', target],
933933
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
934934

935-
except (AttributeError,os.error):
935+
except (AttributeError, OSError):
936936
return default
937937
output = proc.communicate()[0].decode('latin-1')
938938
rc = proc.wait()

Lib/posixpath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def islink(path):
162162
"""Test whether a path is a symbolic link"""
163163
try:
164164
st = os.lstat(path)
165-
except (os.error, AttributeError):
165+
except (OSError, AttributeError):
166166
return False
167167
return stat.S_ISLNK(st.st_mode)
168168

@@ -172,7 +172,7 @@ def lexists(path):
172172
"""Test whether a path exists. Returns True for broken symbolic links"""
173173
try:
174174
os.lstat(path)
175-
except os.error:
175+
except OSError:
176176
return False
177177
return True
178178

@@ -220,7 +220,7 @@ def ismount(path):
220220
else:
221221
parent = join(path, '..')
222222
s2 = os.lstat(parent)
223-
except os.error:
223+
except OSError:
224224
return False # It doesn't exist -- so not a mount point :-)
225225
dev1 = s1.st_dev
226226
dev2 = s2.st_dev

Lib/pty.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ def _open_terminal():
5757
try:
5858
tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
5959
except IOError as msg:
60-
raise os.error(msg)
60+
raise OSError(msg)
6161
return master_fd, tty_name
6262
for x in 'pqrstuvwxyzPQRST':
6363
for y in '0123456789abcdef':
6464
pty_name = '/dev/pty' + x + y
6565
try:
6666
fd = os.open(pty_name, os.O_RDWR)
67-
except os.error:
67+
except OSError:
6868
continue
6969
return (fd, '/dev/tty' + x + y)
70-
raise os.error('out of pty devices')
70+
raise OSError('out of pty devices')
7171

7272
def slave_open(tty_name):
7373
"""slave_open(tty_name) -> slave_fd

0 commit comments

Comments
 (0)
0