diff options
| author | alex <alex@pdp7.net> | 2023-09-17 17:39:54 +0200 |
|---|---|---|
| committer | alex <alex@pdp7.net> | 2023-09-17 17:39:54 +0200 |
| commit | e7d04e802ea9fcf4a56210be16aaa0b131e5e797 (patch) | |
| tree | 071fc39e31a08dd9c91fe5c5ab4d8c05fde3feab /blog_experiment/blog/page.py | |
| parent | e5a7e9667c709c20988158b30b29e5ac019c0fe2 (diff) | |
Refactor in modules, add gemtext parser
Diffstat (limited to 'blog_experiment/blog/page.py')
| -rw-r--r-- | blog_experiment/blog/page.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/blog_experiment/blog/page.py b/blog_experiment/blog/page.py new file mode 100644 index 00000000..fcc4841a --- /dev/null +++ b/blog_experiment/blog/page.py @@ -0,0 +1,37 @@ +import bicephalus + + +class BasePage: + def __init__(self, request): + self.request = request + + def response(self): + if self.request.proto == bicephalus.Proto.GEMINI: + status, content_type, content = self.get_gemini_content() + elif self.request.proto == bicephalus.Proto.HTTP: + status, content_type, content = self.get_http_content() + else: + assert False, f"unknown protocol {self.request.proto}" + + return bicephalus.Response( + content=content.encode("utf8"), + content_type=content_type, + status=bicephalus.Status.OK, + ) + + +class NotFound(BasePage): + def get_gemini_content(self): + # TODO: does not work! + return ( + bicephalus.Status.NOT_FOUND, + "text/gemini", + f"{self.request.path} not found", + ) + + def get_http_content(self): + return ( + bicephalus.Status.NOT_FOUND, + "text/html", + f"{self.request.path} not found", + ) |
