-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
497 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from collections.abc import Callable, Collection | ||
from typing import Any | ||
|
||
from pydantic import BaseModel | ||
|
||
from frontik import media_types | ||
from frontik.handler import PageHandler | ||
from frontik.json_builder import json_encode | ||
|
||
ReturnedValue = Any | ||
ReturnedValueHandler = Callable[[PageHandler, ReturnedValue], Any] | ||
ReturnedValueHandlers = Collection[ReturnedValueHandler] | ||
|
||
|
||
def write_json_response_from_dict(handler: PageHandler, value: Any) -> None: | ||
if isinstance(value, dict): | ||
handler.set_header('Content-Type', media_types.APPLICATION_JSON) | ||
handler.text = json_encode(value) | ||
|
||
|
||
def write_json_response_from_pydantic(handler: PageHandler, value: BaseModel) -> None: | ||
if isinstance(value, BaseModel): | ||
handler.set_header('Content-Type', media_types.APPLICATION_JSON) | ||
handler.text = value.model_dump_json() | ||
|
||
|
||
def get_default_returned_value_handlers() -> ReturnedValueHandlers: | ||
return [write_json_response_from_dict, write_json_response_from_pydantic] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.