Gracefully handle requests for file:// URLs where the file does not exist.
This commit is contained in:
parent
681b11b8a4
commit
0ce09f37a6
15
av98.py
15
av98.py
|
@ -375,18 +375,19 @@ you'll be able to transparently follow links to Gopherspace!""")
|
|||
elif isinstance(err, (TimeoutError, socket.timeout)):
|
||||
ui_out.error("""ERROR: Connection timed out!
|
||||
Slow internet connection? Use 'set timeout' to be more patient.""")
|
||||
elif isinstance(err, FileNotFoundError):
|
||||
ui_out.error("ERROR: Local file not found!")
|
||||
else:
|
||||
ui_out.error("ERROR: " + str(err))
|
||||
ui_out.debug(traceback.format_exc())
|
||||
|
||||
def _handle_local_file(self, gi):
|
||||
if gi.path.endswith(".gmi"): # TODO: be better about this
|
||||
mime = "text/gemini"
|
||||
with open(gi.path, "r") as fp:
|
||||
body = fp.read()
|
||||
else:
|
||||
mime, noise = mimetypes.guess_type(gi.path)
|
||||
body = None
|
||||
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
|
||||
mime = "text/gemini"
|
||||
return mime
|
||||
|
||||
def _fetch_over_network(self, gi, destination=None):
|
||||
|
|
Loading…
Reference in New Issue