Buckets:
MisterAI/LocalAI_Demo_backends / cpu-pocket-tts.upgrade-tmp /venv /lib /python3.10 /site-packages /fastapi /responses.py
| import importlib | |
| from typing import Any, Protocol, cast | |
| from fastapi.exceptions import FastAPIDeprecationWarning | |
| from fastapi.sse import EventSourceResponse as EventSourceResponse # noqa | |
| from starlette.responses import FileResponse as FileResponse # noqa | |
| from starlette.responses import HTMLResponse as HTMLResponse # noqa | |
| from starlette.responses import JSONResponse as JSONResponse # noqa | |
| from starlette.responses import PlainTextResponse as PlainTextResponse # noqa | |
| from starlette.responses import RedirectResponse as RedirectResponse # noqa | |
| from starlette.responses import Response as Response # noqa | |
| from starlette.responses import StreamingResponse as StreamingResponse # noqa | |
| from typing_extensions import deprecated | |
| class _UjsonModule(Protocol): | |
| def dumps(self, __obj: Any, *, ensure_ascii: bool = ...) -> str: ... | |
| class _OrjsonModule(Protocol): | |
| OPT_NON_STR_KEYS: int | |
| OPT_SERIALIZE_NUMPY: int | |
| def dumps(self, __obj: Any, *, option: int = ...) -> bytes: ... | |
| try: | |
| ujson = cast(_UjsonModule, importlib.import_module("ujson")) | |
| except ModuleNotFoundError: # pragma: nocover | |
| ujson = None # type: ignore[assignment] | |
| try: | |
| orjson = cast(_OrjsonModule, importlib.import_module("orjson")) | |
| except ModuleNotFoundError: # pragma: nocover | |
| orjson = None # type: ignore[assignment] | |
| class UJSONResponse(JSONResponse): | |
| """JSON response using the ujson library to serialize data to JSON. | |
| **Deprecated**: `UJSONResponse` is deprecated. FastAPI now serializes data | |
| directly to JSON bytes via Pydantic when a return type or response model is | |
| set, which is faster and doesn't need a custom response class. | |
| Read more in the | |
| [FastAPI docs for Custom Response](https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model) | |
| and the | |
| [FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/). | |
| **Note**: `ujson` is not included with FastAPI and must be installed | |
| separately, e.g. `pip install ujson`. | |
| """ | |
| def render(self, content: Any) -> bytes: | |
| assert ujson is not None, "ujson must be installed to use UJSONResponse" | |
| return ujson.dumps(content, ensure_ascii=False).encode("utf-8") | |
| class ORJSONResponse(JSONResponse): | |
| """JSON response using the orjson library to serialize data to JSON. | |
| **Deprecated**: `ORJSONResponse` is deprecated. FastAPI now serializes data | |
| directly to JSON bytes via Pydantic when a return type or response model is | |
| set, which is faster and doesn't need a custom response class. | |
| Read more in the | |
| [FastAPI docs for Custom Response](https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model) | |
| and the | |
| [FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/). | |
| **Note**: `orjson` is not included with FastAPI and must be installed | |
| separately, e.g. `pip install orjson`. | |
| """ | |
| def render(self, content: Any) -> bytes: | |
| assert orjson is not None, "orjson must be installed to use ORJSONResponse" | |
| return orjson.dumps( | |
| content, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY | |
| ) | |
Xet Storage Details
- Size:
- 4.14 kB
- Xet hash:
- 9b80e554b0d7504aeaaf08ef698edc1d547f6744d56844f92060c49b764e3654
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.