exec
dece 3 years ago
parent 8b1561e689
commit f63d875fc3

@ -18,12 +18,21 @@ TODO DONE
open last download
media files
identity management
logging
home page
logging
--------------------------------------------------------------------------------
BACKLOG
--------------------------------------------------------------------------------
bug: can't input unicode
click on links to open them
download to disk, not in memory
bug: can't reload bebop: pages
bug: exiting editor breaks curses
dumb rendering mode per site
disable cache per site
well, preferences per site maybe?
download without memory buffer
download in the background
download view instead of last download
does encoding really work? cf. egsam
@ -36,8 +45,6 @@ bug: combining chars reduce lengths
non shit command-line
response code 11 (if still there)
gopher?
save history
opt. maintain history between sessions
history (forward) (useful?)
bug: can't reload bebop: pages
bug: can't input unicode
bug: astrobotany loops on /app
search in page (ugh)

@ -1,4 +1,5 @@
import argparse
import logging
from bebop.browser.browser import Browser
from bebop.config import load_config
@ -9,8 +10,18 @@ from bebop.tofu import get_cert_stash_path, load_cert_stash, save_cert_stash
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument("url", nargs="?", default=None)
argparser.add_argument("-d", "--debug", action="store_true")
args = argparser.parse_args()
if args.debug:
logging.basicConfig(
filename="bebop.log",
level=logging.DEBUG,
format="%(asctime)s %(levelname)-8s %(message)s"
)
else:
logging.disable()
if args.url:
start_url = args.url
else:
@ -21,7 +32,7 @@ def main():
bebop_files_error = ensure_bebop_files_exist()
if bebop_files_error:
print("Bebop could not create local files:", bebop_files_error)
logging.critical(f"Failed to create files: {bebop_files_error}")
return
cert_stash_path = get_cert_stash_path()

@ -3,12 +3,13 @@
import curses
import curses.ascii
import curses.textpad
import logging
import os
import subprocess
import tempfile
from math import inf
from pathlib import Path
from typing import Optional, Tuple
from typing import Dict, Optional, Tuple
from bebop.bookmarks import (
get_bookmarks_path, get_bookmarks_document, save_bookmark
@ -113,6 +114,7 @@ class Browser:
def run(self, *args, **kwargs):
"""Use curses' wrapper around _run."""
os.environ.setdefault("ESCDELAY", "25")
logging.info("Cursing…")
curses.wrapper(self._run, *args, **kwargs)
def _run(self, stdscr, start_url=None):
@ -259,6 +261,7 @@ class Browser:
def refresh_status_line(self):
"""Refresh status line contents."""
text, pair, attributes = self.status_data
logging.debug("Status: " + text)
text = text[:self.w - 1]
color = curses.color_pair(pair)
self.status_line.addstr(0, 0, text, color | attributes)

@ -1,5 +1,6 @@
"""Gemini-related features of the browser."""
import logging
from pathlib import Path
from typing import Optional
@ -77,6 +78,10 @@ def open_gemini_url(
browser.set_status(url)
return url
logging.info(
f"Request {url}"
+ (f" using cert and key {cert_and_key}" if cert_and_key else "")
)
req = Request(url, browser.stash, identity=cert_and_key)
connect_timeout = browser.config["connect_timeout"]
connected = req.connect(connect_timeout)
@ -151,6 +156,7 @@ def _handle_response(
Returns:
The final URL on success, None otherwise.
"""
logging.info(f"Response {response.code} {response.meta}")
if response.code == 20:
return _handle_successful_response(browser, response, url)
elif response.generic_code == 30 and response.meta:

@ -1,6 +1,7 @@
"""Config management."""
import json
import logging
import os.path
@ -25,9 +26,9 @@ def load_config(config_path):
with open(config_path, "rt") as config_file:
config = json.load(config_file)
except OSError as exc:
print(f"Could not read config file {config_path}: {exc}")
logging.error(f"Could not read config file {config_path}: {exc}")
except ValueError as exc:
print(f"Could not parse config file {config_path}: {exc}")
logging.error(f"Could not parse config file {config_path}: {exc}")
else:
# Fill missing values with defaults.
for key, value in DEFAULT_CONFIG.items():
@ -42,4 +43,4 @@ def create_default_config(config_path):
with open(config_path, "wt") as config_file:
json.dump(DEFAULT_CONFIG, config_file, indent=2)
except OSError as exc:
print(f"Could not create config file {config_path}: {exc}")
logging.error(f"Could not create config file {config_path}: {exc}")

@ -24,6 +24,7 @@ The identity file and the identities dict both have the following format:
import hashlib
import json
import logging
import secrets
import string
import subprocess
@ -40,6 +41,7 @@ def load_identities(identities_path: Path) -> Optional[dict]:
with open(identities_path, "rt") as identities_file:
identities = json.load(identities_file)
except (OSError, ValueError) as exc:
logging.error(f"Failed to load identities '{identities_path}': {exc}")
return None
return identities
@ -50,6 +52,7 @@ def save_identities(identities: dict, identities_path: Path):
with open(identities_path, "wt") as identities_file:
json.dump(identities, identities_file)
except (OSError, ValueError) as exc:
logging.error(f"Failed to save identities '{identities_path}': {exc}")
return False
return True

@ -5,6 +5,7 @@ requires more clarity both in specification and in our own implementation.
"""
import hashlib
import logging
import re
from enum import Enum
from pathlib import Path
@ -105,7 +106,7 @@ def save_cert_stash(stash: dict, stash_path: Path):
entry_line = f"{name} {algo} {fingerprint}\n"
stash_file.write(entry_line)
except (OSError, ValueError) as exc:
print(f"Failed to save certificate stash '{stash_path}': {exc}")
logging.error(f"Failed to save certificate stash '{stash_path}': {exc}")
class CertStatus(Enum):

Loading…
Cancel
Save