offline switchg

This commit is contained in:
Lionel Dricot 2021-12-06 16:43:16 +01:00
parent acdc83ed6d
commit b1c9220fc5
1 changed files with 11 additions and 0 deletions

11
av98.py
View File

@ -95,6 +95,7 @@ _MIME_HANDLERS = {
"text/*": "cat %s",
}
# monkey-patch Gemini support in urllib.parse
# see https://github.com/python/cpython/blob/master/Lib/urllib/parse.py
urllib.parse.uses_relative.append("gemini")
@ -276,6 +277,7 @@ class GeminiClient(cmd.Cmd):
self.tmp_filename = ""
self.visited_hosts = set()
self.waypoints = []
self.offline_only = False
self.client_certs = {
"active": None
@ -1235,6 +1237,15 @@ you'll be able to transparently follow links to Gopherspace!""")
self.stdout.write("{:<7} {}\n".format(k, v))
self.stdout.write("\n")
def do_offline(self, *args):
"""Use AV-98 offline by only accessing cached content"""
if self.offline_only:
self.offline_only = False
print("AV-98 is online and will access the network")
else:
self.offline_only = True
print("AV-98 is now offline and will only access cached content")
### Stuff for getting around
def do_go(self, line):
"""Go to a gemini URL or marked item."""