Skip to content

Commit 16799d3

Browse files
committed
use directly OSError everywhere
1 parent 439065e commit 16799d3

37 files changed

+57
-57
lines changed

src/sage/databases/cremona.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def build(name, data_tgz, largest_conductor=0, mini=False, decompress=True):
121121
raise RuntimeError('Please (re)move %s before building ' % db_path
122122
+ 'database')
123123
if not os.path.exists(data_tgz):
124-
raise IOError("The data file is not at %s" % data_tgz)
124+
raise OSError("The data file is not at %s" % data_tgz)
125125
t = walltime()
126126

127127
if decompress:

src/sage/databases/cubic_hecke_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def read(self, section):
918918
try:
919919
data_lib[section] = load(fname)
920920
verbose('... finished!')
921-
except IOError:
921+
except OSError:
922922
self.reset_library(section)
923923
verbose('... not found!')
924924
except (ImportError, ModuleNotFoundError):

src/sage/databases/db_modular_polynomials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _dbz_to_string(name):
6060
try:
6161
with open(filename, 'rb') as f:
6262
data = bz2.decompress(f.read())
63-
except IOError:
63+
except OSError:
6464
raise ValueError('file not found in the Kohel database')
6565
return bytes_to_str(data)
6666

src/sage/databases/findstat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def statistic(pi):
881881
code = inspect.getsource(function.f)
882882
else:
883883
code = inspect.getsource(function)
884-
except (IOError, TypeError):
884+
except (OSError, TypeError):
885885
verbose("inspect.getsource could not get code from function provided",
886886
caller_name='FindStat')
887887
return code

src/sage/databases/jones.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _init(self, path):
152152
self.root = {}
153153
self.root[tuple()] = [x - 1]
154154
if not os.path.exists(path):
155-
raise IOError("Path %s does not exist." % path)
155+
raise OSError("Path %s does not exist." % path)
156156
for X in os.listdir(path):
157157
if X[-4:] == "solo":
158158
Z = path + "/" + X

src/sage/databases/oeis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def _fetch(url):
187187
result = f.read()
188188
f.close()
189189
return bytes_to_str(result)
190-
except IOError as msg:
191-
raise IOError("%s\nerror fetching %s" % (msg, url))
190+
except OSError as msg:
191+
raise OSError("%s\nerror fetching %s" % (msg, url))
192192

193193

194194
def _urls(html_string):

src/sage/databases/sloane.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,20 @@ def install(self, oeis_url="https://oeis.org/stripped.gz",
197197
"""
198198
# See if the encyclopedia already exists
199199
if not overwrite and os.path.exists(self.__file__):
200-
raise IOError("Sloane encyclopedia is already installed")
200+
raise OSError("Sloane encyclopedia is already installed")
201201

202202
tm = verbose("Downloading stripped version of Sloane encyclopedia")
203203
ssl._create_default_https_context = ssl.create_default_context
204204
try:
205205
fname, _ = urlretrieve(oeis_url)
206-
except IOError as msg:
207-
raise IOError("%s\nError fetching the following website:\n %s\nTry checking your internet connection." % (msg, oeis_url))
206+
except OSError as msg:
207+
raise OSError("%s\nError fetching the following website:\n %s\nTry checking your internet connection." % (msg, oeis_url))
208208

209209
if names_url is not None:
210210
try:
211211
nname, _ = urlretrieve(names_url)
212-
except IOError as msg:
213-
raise IOError("%s\nError fetching the following website:\n %s\nTry checking your internet connection." % (msg, names_url))
212+
except OSError as msg:
213+
raise OSError("%s\nError fetching the following website:\n %s\nTry checking your internet connection." % (msg, names_url))
214214
else:
215215
nname = None
216216
verbose("Finished downloading", tm)
@@ -237,7 +237,7 @@ def install_from_gz(self, stripped_file, names_file, overwrite=False):
237237
old encyclopedia.
238238
"""
239239
if not overwrite and os.path.exists(self.__file__):
240-
raise IOError("Sloane encyclopedia is already installed")
240+
raise OSError("Sloane encyclopedia is already installed")
241241

242242
copy_gz_file(stripped_file, self.__file__)
243243

@@ -262,8 +262,8 @@ def load(self):
262262
return
263263
try:
264264
file_seq = bz2.BZ2File(self.__file__, 'r')
265-
except IOError:
266-
raise IOError("The Sloane Encyclopedia database must be installed."
265+
except OSError:
266+
raise OSError("The Sloane Encyclopedia database must be installed."
267267
" Use e.g. 'SloaneEncyclopedia.install()' to download and install it.")
268268

269269
self.__data__ = {}
@@ -296,7 +296,7 @@ def load(self):
296296
# Some sequence in the names file is not in the database
297297
raise KeyError("Sloane OEIS sequence and name files do not match."
298298
" Try reinstalling, e.g. SloaneEncyclopedia.install(overwrite=True).")
299-
except IOError:
299+
except OSError:
300300
# The names database is not installed
301301
self.__loaded_names__ = False
302302

@@ -323,7 +323,7 @@ def sequence_name(self, N):
323323
"""
324324
self.load()
325325
if not self.__loaded_names__:
326-
raise IOError("The Sloane OEIS names file is not installed."
326+
raise OSError("The Sloane OEIS names file is not installed."
327327
" Try reinstalling, e.g. SloaneEncyclopedia.install(overwrite=True).")
328328

329329
if N not in self.__data__: # sequence N does not exist
@@ -364,14 +364,14 @@ def copy_gz_file(gz_source, bz_destination):
364364
gz_input = gzip.open(gz_source, 'r')
365365
db_text = gz_input.read()
366366
gz_input.close()
367-
except IOError as msg:
368-
raise IOError("Error reading gzipped input file:\n%s" % msg)
367+
except OSError as msg:
368+
raise OSError("Error reading gzipped input file:\n%s" % msg)
369369

370370
# Write the bzipped output
371371
try:
372372
os.makedirs(os.path.dirname(bz_destination), exist_ok=True)
373373
bz2_output = bz2.BZ2File(bz_destination, 'w')
374374
bz2_output.write(db_text)
375375
bz2_output.close()
376-
except IOError as msg:
377-
raise IOError("Error writing bzipped output file:\n%s" % msg)
376+
except OSError as msg:
377+
raise OSError("Error writing bzipped output file:\n%s" % msg)

src/sage/databases/stein_watkins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ def __iter__(self):
214214
"""
215215
try:
216216
file = bz2.open(self._file, 'rt', encoding="utf-8")
217-
except IOError:
218-
raise IOError("The Stein-Watkins data file %s must be installed." % self._file)
217+
except OSError:
218+
raise OSError("The Stein-Watkins data file %s must be installed." % self._file)
219219
C = None
220220
for L in file:
221221
if len(L) == 0:

src/sage/databases/symbolic_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ def _dom2ideal(node):
149149
try:
150150
name = self.__intpath + name + ".xml"
151151
open(name)
152-
except IOError:
152+
except OSError:
153153
try:
154154
name = self.__genpath + name + ".xml"
155155
open(name)
156-
except IOError:
156+
except OSError:
157157
raise AttributeError("No ideal matching '%s' found in database." % orig_name)
158158

159159
dom = parse(name)

src/sage/doctest/control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def __init__(self, options, args):
532532
# string from DocTestDefaults
533533
try:
534534
self.logfile = open(options.logfile, 'a')
535-
except IOError:
535+
except OSError:
536536
print("Unable to open logfile {!r}\nProceeding without logging.".format(options.logfile))
537537
self.logfile = None
538538
else:

0 commit comments

Comments
 (0)