kyoukai.util

Misc utilities for usage inside the framework.

Functions

as_html(text[, code, headers]) Returns a HTML response.
as_json(data[, code, headers, json_encoder]) Returns a JSON response.
as_plaintext(text[, code, headers]) Returns a plaintext response.
wrap_response(args[, response_class]) Wrap up a response, if applicable.
kyoukai.util.as_html(text, code=200, headers=None)[source]

Returns a HTML response.

return as_html("<h1>Hel Na</h1>", code=403)
Parameters:
  • text (str) – The text to return.
  • code (int) – The status code of the response.
  • headers (Optional[dict]) – Any optional headers.
Return type:

Response

Returns:

A new werkzeug.wrappers.Response representing the HTML.

kyoukai.util.as_plaintext(text, code=200, headers=None)[source]

Returns a plaintext response.

return as_plaintext("hel yea", code=201)
Parameters:
  • text (str) – The text to return.
  • code (int) – The status code of the response.
  • headers (Optional[dict]) – Any optional headers.
Return type:

Response

Returns:

A new werkzeug.wrappers.Response representing the text.

kyoukai.util.as_json(data, code=200, headers=None, *, json_encoder=None, **kwargs)[source]

Returns a JSON response.

return as_json({"response": "yes", "code": 201}, code=201)
Parameters:
  • data (Union[dict, list]) – The data to encode.
  • code (int) – The status code of the response.
  • headers (Optional[dict]) – Any optional headers.
  • json_encoder (Optional[JSONEncoder]) – The encoder class to use to encode.
Return type:

Response

Returns:

A new werkzeug.wrappers.Response representing the JSON.

kyoukai.util.wrap_response(args, response_class=<class 'werkzeug.wrappers.Response'>)[source]

Wrap up a response, if applicable. This allows Flask-like return “whatever”.

Parameters:
  • args – The arguments that are being wrapped.
  • response_class (Response) – The Response class that is being used.
Return type:

Response