MCPcopy
hub / github.com/sanic-org/sanic / text

Function text

sanic/response/convenience.py:67–94  ·  view source on GitHub ↗

Returns response object with body in text format. Args: body (str): Response data. status (int, optional): HTTP response code. Defaults to `200`. headers (Dict[str, str], optional): Custom HTTP headers. Defaults to `None`. content_type (str, optional): The conten

(
    body: str,
    status: int = 200,
    headers: dict[str, str] | None = None,
    content_type: str = "text/plain; charset=utf-8",
)

Source from the content-addressed store, hash-verified

65
66
67def text(
68 body: str,
69 status: int = 200,
70 headers: dict[str, str] | None = None,
71 content_type: str = "text/plain; charset=utf-8",
72) -> HTTPResponse:
73 """Returns response object with body in text format.
74
75 Args:
76 body (str): Response data.
77 status (int, optional): HTTP response code. Defaults to `200`.
78 headers (Dict[str, str], optional): Custom HTTP headers. Defaults to `None`.
79 content_type (str, optional): The content type (string) of the response. Defaults to `"text/plain; charset=utf-8"`.
80
81 Returns:
82 HTTPResponse: A response object with body in text format.
83
84 Raises:
85 TypeError: If the body is not a string.
86 """ # noqa: E501
87 if not isinstance(body, str):
88 raise TypeError(
89 f"Bad body type. Expected str, got {type(body).__name__})"
90 )
91
92 return HTTPResponse(
93 body, status=status, headers=headers, content_type=content_type
94 )
95
96
97def raw(

Callers 15

fullMethod · 0.90
minimalMethod · 0.90
responseMethod · 0.90
handlerFunction · 0.90
handler_exceptionFunction · 0.90
getFunction · 0.90
postFunction · 0.90
view_nameFunction · 0.90
my_unique_handlerFunction · 0.90
bp_rootFunction · 0.90
url_forFunction · 0.90
handler1Function · 0.90

Calls 1

HTTPResponseClass · 0.85

Tested by 15

handlerFunction · 0.72
handler_exceptionFunction · 0.72
getFunction · 0.72
postFunction · 0.72
view_nameFunction · 0.72
my_unique_handlerFunction · 0.72
bp_rootFunction · 0.72
url_forFunction · 0.72
handler1Function · 0.72
handler2Function · 0.72
handlerFunction · 0.72
handler_4Function · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…