commit - 1f653a9870bcdabc5ca4dbbb3041ec60b4687b7a
commit + 5c749e57812a8fb3757c5a2afe3cebd9deab3a36
blob - 23c3b5ca275d13889f071c1d91d57e8c7d8237bc
blob + 7ae8f8fa63c794d6db3fa417a921f6fc05cc170d
--- lonk.py
+++ lonk.py
+from sqlite3 import connect as sqlite3_connect
+from argparse import ArgumentParser
from json import loads as json_loads
from pathlib import Path
from socket import socket
src = img.get("src")
if src:
self.gmi_text.append(f"=> {urljoin(self.base_url, src)} {title}")
+ elif tag == "br":
+ if self.stack:
+ self.gmi_text.append(self.stack[-1].flush())
def handle_data(self, data):
# print(f" . {data=}")
print(_format_honk(honk))
+def create_schema(dbcon):
+ pass
+
+
def server():
- from argparse import ArgumentParser
+ parser = ArgumentParser()
parser.add_argument("--address", default="127.0.0.1", help="bind to this address (default: %(default)s)")
parser.add_argument("--port", default=1965, type=int, help="bind to this port (default: %(default)s)")
- parser.add_argument("--settings", required=True, help="path to server settings (JSON file)")
parser.add_argument("--certfile", required=True, help="path server certificate file")
parser.add_argument("--keyfile", required=True, help="path certificate private key file")
parser.add_argument("--dbfile", required=True, help="path to databale file")
args = parser.parse_args()
+ need_to_create_schema = not Path(args.dbfile).exists()
+ dbcon = sqlite3_connect(args.dbfile)
+ if need_to_create_schema:
+ with dbcon:
+ create_schema(dbcon)
+
ssl_ctx = SSLContext(PROTOCOL_TLS_SERVER)
ssl_ctx.load_cert_chain(args.certfile, args.keyfile)
sock.listen()
with ssl_ctx.wrap_socket(sock, server_side=True) as ssl_sock:
conn, addr = ssl_sock.accept()
+ if conn.getpeercert() is None:
+ raise NotImplementedError()
+ raise NotImplementedError()
if __name__ == '__main__':
blob - 645ae6bd91a6c1d866d6cfd9f1b19c544531bca7
blob + b4f00241cdc9d1d15900206ebe3aa4860a9f2f8f
--- tests.py
+++ tests.py
class TestHtmlToGmi(TestCase):
+ def test_br(self):
+ html = '<p>head<br>tail</p>'
+ self.assertEqual(HtmlToGmi("https://localhost/api").feed(html), """\
+head
+
+tail
+""")
+
def test_img_realtive(self):
html = '<img src="/d/xxxx.jpg" title="yyy">'
self.assertEqual(HtmlToGmi("https://localhost/api").feed(html), "=> https://localhost/d/xxxx.jpg yyy")