Gracefully handle requests for file:// URLs which point at a directory.
This commit is contained in:
parent
0ce09f37a6
commit
71f8a3dc86
8
av98.py
8
av98.py
|
@ -330,6 +330,10 @@ you'll be able to transparently follow links to Gopherspace!""")
|
|||
# Use local file, use cache, or hit the network if resource is not cached
|
||||
try:
|
||||
if gi.scheme == "file":
|
||||
if not os.path.exists(gi.path):
|
||||
raise FileNotFoundError
|
||||
elif os.path.isdir(gi.path):
|
||||
raise IsADirectoryError
|
||||
mime = self._handle_local_file(gi)
|
||||
self.active_raw_file = gi.path
|
||||
elif check_cache and self.options["cache"] and self.cache.check(gi.url):
|
||||
|
@ -377,13 +381,13 @@ you'll be able to transparently follow links to Gopherspace!""")
|
|||
Slow internet connection? Use 'set timeout' to be more patient.""")
|
||||
elif isinstance(err, FileNotFoundError):
|
||||
ui_out.error("ERROR: Local file not found!")
|
||||
elif isinstance(err, IsADirectoryError):
|
||||
ui_out.error("ERROR: Viewing local directories is not supported!")
|
||||
else:
|
||||
ui_out.error("ERROR: " + str(err))
|
||||
ui_out.debug(traceback.format_exc())
|
||||
|
||||
def _handle_local_file(self, gi):
|
||||
if not os.path.exists(gi.path):
|
||||
raise FileNotFoundError
|
||||
mime, noise = mimetypes.guess_type(gi.path)
|
||||
if not mime:
|
||||
if gi.path.endswith(".gmi"): # TODO: be better about this
|
||||
|
|
Loading…
Reference in New Issue