From 5718694e25b4bcf29ed9cb152f913a802af4cbd0 Mon Sep 17 00:00:00 2001
From: Alan De Smet <alan.desmet@ssec.wisc.edu>
Date: Tue, 27 Dec 2016 15:18:53 -0600
Subject: [PATCH] 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.
---
 pyglance/glance/io.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/pyglance/glance/io.py b/pyglance/glance/io.py
index 40d7c13..b2aa372 100644
--- a/pyglance/glance/io.py
+++ b/pyglance/glance/io.py
@@ -1355,6 +1355,13 @@ class jpss_adl(object):
 
 def open(pathname, allowWrite=False):
     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()):
         # this ican be used to specify a format on the command line by setting the
         # environment variable FORMAT, for example:
-- 
GitLab