Removed blackbox (it was broken for years)

Also, fixed the non-interactive mode of fetch_gemini
This commit is contained in:
Lionel Dricot 2023-08-14 15:41:11 +02:00
parent 91013f5d3d
commit d88d2cdc20
3 changed files with 11 additions and 41 deletions

View File

@ -5,7 +5,6 @@ List of things before release
TODO: man pages for netcache, ansicat, opnk
REGR: restore gemini certificate code
REGR: implement grep
REGR: avoid asking for user input while in non-interactive mode
This is an an experimental and unstable release. Lot of breakages are expected.
Wait for 2.1 if you are not willing to do testing/bug reporting.
- Licence has been changed to AGPL for ideological reasons

View File

@ -735,7 +735,7 @@ def _validate_cert(address, host, cert,accept_bad_ssl=False,automatic_choice=Non
with open(os.path.join(certdir, fingerprint+".crt"), "wb") as fp:
fp.write(cert)
def _fetch_gemini(url,timeout=DEFAULT_TIMEOUT,**kwargs):
def _fetch_gemini(url,timeout=DEFAULT_TIMEOUT,interactive=True,**kwargs):
cache = None
url_parts = urllib.parse.urlparse(url)
host = url_parts.hostname
@ -881,13 +881,16 @@ def _fetch_gemini(url,timeout=DEFAULT_TIMEOUT,**kwargs):
# Handle non-SUCCESS headers, which don't have a response body
# Inputs
if status.startswith("1"):
print(meta)
if status == "11":
user_input = getpass.getpass("> ")
if interactive:
print(meta)
if status == "11":
user_input = getpass.getpass("> ")
else:
#TODO:FIXME we should not ask for user input while non-interactive
user_input = input("> ")
return _fetch_gemini(query(user_input))
else:
#TODO:FIXME we should not ask for user input while non-interactive
user_input = input("> ")
return _fetch_gemini(query(user_input))
return None
# Redirects
elif status.startswith("3"):
newurl = urllib.parse.urljoin(url,meta)

View File

@ -206,7 +206,6 @@ class GeminiClient(cmd.Cmd):
self.page_index = 0
self.permanent_redirects = {}
# Sync-only mode is restriced by design
self.visited_hosts = set()
self.offline_only = False
self.sync_only = False
self.support_http = _DO_HTTP
@ -250,17 +249,6 @@ class GeminiClient(cmd.Cmd):
term_width(new_width=self.options["width"])
self.log = {
"start_time": time.time(),
"requests": 0,
"ipv4_requests": 0,
"ipv6_requests": 0,
"bytes_recvd": 0,
"ipv4_bytes_recvd": 0,
"ipv6_bytes_recvd": 0,
"dns_failures": 0,
"refused_connections": 0,
"reset_connections": 0,
"timeouts": 0,
"cache_hits": 0,
}
@ -334,6 +322,7 @@ class GeminiClient(cmd.Cmd):
if limit_size:
params["max_size"] = int(self.options["max_size_download"])*1000000
params["print_error"] = not self.sync_only
params["interactive"] = not self.sync_only
params["offline"] = self.offline_only
if not check_cache:
params["validity"] = 1
@ -1583,29 +1572,8 @@ current gemini browsing session."""
delta = now - self.log["start_time"]
hours, remainder = divmod(delta, 3600)
minutes, seconds = divmod(remainder, 60)
# Count hosts
ipv4_hosts = len([host for host in self.visited_hosts if host[0] == socket.AF_INET])
ipv6_hosts = len([host for host in self.visited_hosts if host[0] == socket.AF_INET6])
# Assemble lines
lines.append(("Patrol duration", "%02d:%02d:%02d" % (hours, minutes, seconds)))
lines.append(("Requests sent:", self.log["requests"]))
lines.append((" IPv4 requests:", self.log["ipv4_requests"]))
lines.append((" IPv6 requests:", self.log["ipv6_requests"]))
lines.append(("Bytes received:", self.log["bytes_recvd"]))
lines.append((" IPv4 bytes:", self.log["ipv4_bytes_recvd"]))
lines.append((" IPv6 bytes:", self.log["ipv6_bytes_recvd"]))
lines.append(("Unique hosts visited:", len(self.visited_hosts)))
lines.append((" IPv4 hosts:", ipv4_hosts))
lines.append((" IPv6 hosts:", ipv6_hosts))
lines.append(("DNS failures:", self.log["dns_failures"]))
lines.append(("Timeouts:", self.log["timeouts"]))
lines.append(("Refused connections:", self.log["refused_connections"]))
lines.append(("Reset connections:", self.log["reset_connections"]))
lines.append(("Cache hits:", self.log["cache_hits"]))
# Print
for key, value in lines:
print(key.ljust(24) + str(value).rjust(8))
def do_sync(self, line):
"""Synchronize all bookmarks lists and URLs from the to_fetch list.