aboutsummaryrefslogtreecommitdiff
path: root/blog_experiment/blog/page.py
diff options
context:
space:
mode:
Diffstat (limited to 'blog_experiment/blog/page.py')
-rw-r--r--blog_experiment/blog/page.py37
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",
+ )