1
0
mirror of https://github.com/enpaul/kodak.git synced 2025-06-07 15:23:25 +00:00
kodak/kodak/_server.py

33 lines
939 B
Python
Raw Normal View History

2020-09-21 23:23:47 -04:00
import flask
2021-10-28 23:17:00 -04:00
from kodak import configuration
from kodak import database
from kodak import exceptions
2020-09-21 23:23:47 -04:00
def make_the_tea() -> None:
"""Just for fun
2021-10-28 19:03:09 -04:00
2020-09-21 23:23:47 -04:00
https://en.wikipedia.org/wiki/Hyper_Text_Coffee_Pot_Control_Protocol
"""
if flask.request.content_type == "message/coffeepot":
raise exceptions.IAmATeapotError(
f"Coffee brewing request for '{flask.request.path}' cannot be completed by teapot application"
)
def initialize_database() -> None:
"""Initialize the database connection"""
database.initialize(flask.current_app.appconfig)
2021-10-28 23:17:00 -04:00
class KodakFlask(flask.Flask):
2020-09-21 23:23:47 -04:00
"""Extend the default Flask object to add the custom application config
There's probably an easier/more kosher way to do this, but ¯\\_(ツ)_/¯
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
2021-10-28 23:17:00 -04:00
self.appconfig: configuration.KodakConfig = configuration.load()