Skip to content
Snippets Groups Projects
Commit 5718694e authored by Alan De Smet's avatar Alan De Smet
Browse files

Raise built-in open exceptions if file inaccessible

If the file is inaccessible, raise the same Exception the built-in global open() would.  This makes for more specific and helpful errors. This is done by doing an experimental open() on the file and not catching anything.
parent 44a95c78
No related branches found
No related tags found
No related merge requests found
...@@ -1355,6 +1355,13 @@ class jpss_adl(object): ...@@ -1355,6 +1355,13 @@ class jpss_adl(object):
def open(pathname, allowWrite=False): def open(pathname, allowWrite=False):
suffix = os.path.splitext(pathname)[1][1:].lower() suffix = os.path.splitext(pathname)[1][1:].lower()
# Just test we can open the file so we automatically raise a suitable
# error if we can't access it.
from __builtin__ import open
with open(pathname):
pass
if (not suffix) or (suffix not in globals()): if (not suffix) or (suffix not in globals()):
# this ican be used to specify a format on the command line by setting the # this ican be used to specify a format on the command line by setting the
# environment variable FORMAT, for example: # environment variable FORMAT, for example:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment