1
0
mirror of https://github.com/enpaul/kodak.git synced 2024-11-14 10:36:55 +00:00
kodak/fresnel_lens/_server.py

55 lines
1.7 KiB
Python
Raw Normal View History

2020-09-22 03:23:47 +00:00
import flask
2021-10-28 23:03:09 +00:00
from fresnel_lens import __about__
from fresnel_lens import configuration
from fresnel_lens import constants
from fresnel_lens import database
from fresnel_lens import exceptions
from fresnel_lens.resources import ResponseHeaders
2020-09-22 03:23:47 +00:00
def make_the_tea() -> None:
"""Just for fun
2021-10-28 23:03:09 +00:00
2020-09-22 03:23:47 +00: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:03:09 +00:00
class FresnelRequest(flask.Request):
2020-09-22 03:23:47 +00:00
"""Extend the default Flask request object to add custom application state settings"""
def make_response_headers(self) -> ResponseHeaders:
"""Create the headers dictionary of the standard response headers
This function should be used when determining response headers so that the header names,
their contents, and formatting are universal.
:returns: Dictionary of headers
"""
return {
constants.HTTP_HEADER_RESPONSE_VERSION: __about__.__version__,
}
2021-05-05 17:48:02 +00:00
class ImageMuckFlask(flask.Flask):
2020-09-22 03:23:47 +00:00
"""Extend the default Flask object to add the custom application config
There's probably an easier/more kosher way to do this, but ¯\\_(ツ)_/¯
"""
2021-10-28 23:03:09 +00:00
request_class = FresnelRequest
2020-09-22 03:23:47 +00:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
2021-10-28 23:03:09 +00:00
self.appconfig: configuration.FresnelConfig = configuration.load()