Instructions to use giancap61/AXEL-AI_Virtual_Race_Engineer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M # Run inference directly in the terminal: llama cli -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M # Run inference directly in the terminal: llama cli -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M # Run inference directly in the terminal: ./build/bin/llama cli -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Use Docker
docker model run hf.co/giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
- Llama new
- LM Studio
- Jan
- Ollama
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Ollama:
ollama run hf.co/giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
- Unsloth Desktop
- Pi
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Docker Model Runner:
docker model run hf.co/giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
- Lemonade
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Run and chat with the model
lemonade run user.AXEL-AI_Virtual_Race_Engineer-Q5_K_M
List all available models
lemonade list
- Hermes Agent
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:9931/v1 hermes config set model.default giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:9931/v1 \ --custom-model-id "giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/INSTALLER +1 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/METADATA +637 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/RECORD +104 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/REQUESTED +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/WHEEL +4 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/entry_points.txt +5 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/__init__.py +25 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/__main__.py +3 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/applications.py +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/encoders.py +347 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/exception_handlers.py +34 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/exceptions.py +256 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/logger.py +3 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/param_functions.py +2461 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/params.py +755 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/py.typed +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/requests.py +2 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/responses.py +84 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/routing.py +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/staticfiles.py +1 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/templating.py +1 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/testclient.py +1 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/types.py +12 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/utils.py +136 -0
- TTS/Kokoro/.venv/Lib/site-packages/fastapi/websockets.py +3 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/INSTALLER +1 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/METADATA +38 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/RECORD +26 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/WHEEL +4 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/__init__.py +77 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/_api.py +578 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/_error.py +30 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/_read_write.py +363 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/_soft.py +127 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/_unix.py +109 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/_util.py +53 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/_windows.py +100 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/asyncio.py +376 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/py.typed +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/filelock/version.py +34 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/INSTALLER +1 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/METADATA +257 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/RECORD +119 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/WHEEL +4 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec/__init__.py +71 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec/_version.py +34 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec/archive.py +75 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec/asyn.py +1103 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec/caching.py +1004 -0
- TTS/Kokoro/.venv/Lib/site-packages/fsspec/callbacks.py +324 -0
TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,637 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
| 2 |
+
Name: fastapi
|
| 3 |
+
Version: 0.134.0
|
| 4 |
+
Summary: FastAPI framework, high performance, easy to learn, fast to code, ready for production
|
| 5 |
+
Author-Email: =?utf-8?q?Sebasti=C3=A1n_Ram=C3=ADrez?= <tiangolo@gmail.com>
|
| 6 |
+
License-Expression: MIT
|
| 7 |
+
License-File: LICENSE
|
| 8 |
+
Classifier: Intended Audience :: Information Technology
|
| 9 |
+
Classifier: Intended Audience :: System Administrators
|
| 10 |
+
Classifier: Operating System :: OS Independent
|
| 11 |
+
Classifier: Programming Language :: Python :: 3
|
| 12 |
+
Classifier: Programming Language :: Python
|
| 13 |
+
Classifier: Topic :: Internet
|
| 14 |
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
| 15 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 16 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 17 |
+
Classifier: Topic :: Software Development
|
| 18 |
+
Classifier: Typing :: Typed
|
| 19 |
+
Classifier: Development Status :: 4 - Beta
|
| 20 |
+
Classifier: Environment :: Web Environment
|
| 21 |
+
Classifier: Framework :: AsyncIO
|
| 22 |
+
Classifier: Framework :: FastAPI
|
| 23 |
+
Classifier: Framework :: Pydantic
|
| 24 |
+
Classifier: Framework :: Pydantic :: 2
|
| 25 |
+
Classifier: Intended Audience :: Developers
|
| 26 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 27 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 28 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 29 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 30 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 31 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 32 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
| 33 |
+
Classifier: Topic :: Internet :: WWW/HTTP
|
| 34 |
+
Project-URL: Homepage, https://github.com/fastapi/fastapi
|
| 35 |
+
Project-URL: Documentation, https://fastapi.tiangolo.com/
|
| 36 |
+
Project-URL: Repository, https://github.com/fastapi/fastapi
|
| 37 |
+
Project-URL: Issues, https://github.com/fastapi/fastapi/issues
|
| 38 |
+
Project-URL: Changelog, https://fastapi.tiangolo.com/release-notes/
|
| 39 |
+
Requires-Python: >=3.10
|
| 40 |
+
Requires-Dist: starlette>=0.46.0
|
| 41 |
+
Requires-Dist: pydantic>=2.7.0
|
| 42 |
+
Requires-Dist: typing-extensions>=4.8.0
|
| 43 |
+
Requires-Dist: typing-inspection>=0.4.2
|
| 44 |
+
Requires-Dist: annotated-doc>=0.0.2
|
| 45 |
+
Provides-Extra: standard
|
| 46 |
+
Requires-Dist: fastapi-cli[standard]>=0.0.8; extra == "standard"
|
| 47 |
+
Requires-Dist: httpx<1.0.0,>=0.23.0; extra == "standard"
|
| 48 |
+
Requires-Dist: jinja2>=3.1.5; extra == "standard"
|
| 49 |
+
Requires-Dist: python-multipart>=0.0.18; extra == "standard"
|
| 50 |
+
Requires-Dist: email-validator>=2.0.0; extra == "standard"
|
| 51 |
+
Requires-Dist: uvicorn[standard]>=0.12.0; extra == "standard"
|
| 52 |
+
Requires-Dist: pydantic-settings>=2.0.0; extra == "standard"
|
| 53 |
+
Requires-Dist: pydantic-extra-types>=2.0.0; extra == "standard"
|
| 54 |
+
Provides-Extra: standard-no-fastapi-cloud-cli
|
| 55 |
+
Requires-Dist: fastapi-cli[standard-no-fastapi-cloud-cli]>=0.0.8; extra == "standard-no-fastapi-cloud-cli"
|
| 56 |
+
Requires-Dist: httpx<1.0.0,>=0.23.0; extra == "standard-no-fastapi-cloud-cli"
|
| 57 |
+
Requires-Dist: jinja2>=3.1.5; extra == "standard-no-fastapi-cloud-cli"
|
| 58 |
+
Requires-Dist: python-multipart>=0.0.18; extra == "standard-no-fastapi-cloud-cli"
|
| 59 |
+
Requires-Dist: email-validator>=2.0.0; extra == "standard-no-fastapi-cloud-cli"
|
| 60 |
+
Requires-Dist: uvicorn[standard]>=0.12.0; extra == "standard-no-fastapi-cloud-cli"
|
| 61 |
+
Requires-Dist: pydantic-settings>=2.0.0; extra == "standard-no-fastapi-cloud-cli"
|
| 62 |
+
Requires-Dist: pydantic-extra-types>=2.0.0; extra == "standard-no-fastapi-cloud-cli"
|
| 63 |
+
Provides-Extra: all
|
| 64 |
+
Requires-Dist: fastapi-cli[standard]>=0.0.8; extra == "all"
|
| 65 |
+
Requires-Dist: httpx<1.0.0,>=0.23.0; extra == "all"
|
| 66 |
+
Requires-Dist: jinja2>=3.1.5; extra == "all"
|
| 67 |
+
Requires-Dist: python-multipart>=0.0.18; extra == "all"
|
| 68 |
+
Requires-Dist: itsdangerous>=1.1.0; extra == "all"
|
| 69 |
+
Requires-Dist: pyyaml>=5.3.1; extra == "all"
|
| 70 |
+
Requires-Dist: email-validator>=2.0.0; extra == "all"
|
| 71 |
+
Requires-Dist: uvicorn[standard]>=0.12.0; extra == "all"
|
| 72 |
+
Requires-Dist: pydantic-settings>=2.0.0; extra == "all"
|
| 73 |
+
Requires-Dist: pydantic-extra-types>=2.0.0; extra == "all"
|
| 74 |
+
Description-Content-Type: text/markdown
|
| 75 |
+
|
| 76 |
+
<p align="center">
|
| 77 |
+
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
|
| 78 |
+
</p>
|
| 79 |
+
<p align="center">
|
| 80 |
+
<em>FastAPI framework, high performance, easy to learn, fast to code, ready for production</em>
|
| 81 |
+
</p>
|
| 82 |
+
<p align="center">
|
| 83 |
+
<a href="https://github.com/fastapi/fastapi/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster" target="_blank">
|
| 84 |
+
<img src="https://github.com/fastapi/fastapi/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Test">
|
| 85 |
+
</a>
|
| 86 |
+
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/fastapi" target="_blank">
|
| 87 |
+
<img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/fastapi.svg" alt="Coverage">
|
| 88 |
+
</a>
|
| 89 |
+
<a href="https://pypi.org/project/fastapi" target="_blank">
|
| 90 |
+
<img src="https://img.shields.io/pypi/v/fastapi?color=%2334D058&label=pypi%20package" alt="Package version">
|
| 91 |
+
</a>
|
| 92 |
+
<a href="https://pypi.org/project/fastapi" target="_blank">
|
| 93 |
+
<img src="https://img.shields.io/pypi/pyversions/fastapi.svg?color=%2334D058" alt="Supported Python versions">
|
| 94 |
+
</a>
|
| 95 |
+
</p>
|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
**Documentation**: <a href="https://fastapi.tiangolo.com" target="_blank">https://fastapi.tiangolo.com</a>
|
| 100 |
+
|
| 101 |
+
**Source Code**: <a href="https://github.com/fastapi/fastapi" target="_blank">https://github.com/fastapi/fastapi</a>
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.
|
| 106 |
+
|
| 107 |
+
The key features are:
|
| 108 |
+
|
| 109 |
+
* **Fast**: Very high performance, on par with **NodeJS** and **Go** (thanks to Starlette and Pydantic). [One of the fastest Python frameworks available](#performance).
|
| 110 |
+
* **Fast to code**: Increase the speed to develop features by about 200% to 300%. *
|
| 111 |
+
* **Fewer bugs**: Reduce about 40% of human (developer) induced errors. *
|
| 112 |
+
* **Intuitive**: Great editor support. <dfn title="also known as auto-complete, autocompletion, IntelliSense">Completion</dfn> everywhere. Less time debugging.
|
| 113 |
+
* **Easy**: Designed to be easy to use and learn. Less time reading docs.
|
| 114 |
+
* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
|
| 115 |
+
* **Robust**: Get production-ready code. With automatic interactive documentation.
|
| 116 |
+
* **Standards-based**: Based on (and fully compatible with) the open standards for APIs: <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">OpenAPI</a> (previously known as Swagger) and <a href="https://json-schema.org/" class="external-link" target="_blank">JSON Schema</a>.
|
| 117 |
+
|
| 118 |
+
<small>* estimation based on tests conducted by an internal development team, building production applications.</small>
|
| 119 |
+
|
| 120 |
+
## Sponsors
|
| 121 |
+
|
| 122 |
+
<!-- sponsors -->
|
| 123 |
+
### Keystone Sponsor
|
| 124 |
+
|
| 125 |
+
<a href="https://fastapicloud.com" target="_blank" title="FastAPI Cloud. By the same team behind FastAPI. You code. We Cloud."><img src="https://fastapi.tiangolo.com/img/sponsors/fastapicloud.png"></a>
|
| 126 |
+
|
| 127 |
+
### Gold and Silver Sponsors
|
| 128 |
+
|
| 129 |
+
<a href="https://blockbee.io?ref=fastapi" target="_blank" title="BlockBee Cryptocurrency Payment Gateway"><img src="https://fastapi.tiangolo.com/img/sponsors/blockbee.png"></a>
|
| 130 |
+
<a href="https://github.com/scalar/scalar/?utm_source=fastapi&utm_medium=website&utm_campaign=main-badge" target="_blank" title="Scalar: Beautiful Open-Source API References from Swagger/OpenAPI files"><img src="https://fastapi.tiangolo.com/img/sponsors/scalar.svg"></a>
|
| 131 |
+
<a href="https://www.propelauth.com/?utm_source=fastapi&utm_campaign=1223&utm_medium=mainbadge" target="_blank" title="Auth, user management and more for your B2B product"><img src="https://fastapi.tiangolo.com/img/sponsors/propelauth.png"></a>
|
| 132 |
+
<a href="https://zuplo.link/fastapi-gh" target="_blank" title="Zuplo: Deploy, Secure, Document, and Monetize your FastAPI"><img src="https://fastapi.tiangolo.com/img/sponsors/zuplo.png"></a>
|
| 133 |
+
<a href="https://liblab.com?utm_source=fastapi" target="_blank" title="liblab - Generate SDKs from FastAPI"><img src="https://fastapi.tiangolo.com/img/sponsors/liblab.png"></a>
|
| 134 |
+
<a href="https://docs.render.com/deploy-fastapi?utm_source=deploydoc&utm_medium=referral&utm_campaign=fastapi" target="_blank" title="Deploy & scale any full-stack web app on Render. Focus on building apps, not infra."><img src="https://fastapi.tiangolo.com/img/sponsors/render.svg"></a>
|
| 135 |
+
<a href="https://www.coderabbit.ai/?utm_source=fastapi&utm_medium=badge&utm_campaign=fastapi" target="_blank" title="Cut Code Review Time & Bugs in Half with CodeRabbit"><img src="https://fastapi.tiangolo.com/img/sponsors/coderabbit.png"></a>
|
| 136 |
+
<a href="https://subtotal.com/?utm_source=fastapi&utm_medium=sponsorship&utm_campaign=open-source" target="_blank" title="The Gold Standard in Retail Account Linking"><img src="https://fastapi.tiangolo.com/img/sponsors/subtotal.svg"></a>
|
| 137 |
+
<a href="https://docs.railway.com/guides/fastapi?utm_medium=integration&utm_source=docs&utm_campaign=fastapi" target="_blank" title="Deploy enterprise applications at startup speed"><img src="https://fastapi.tiangolo.com/img/sponsors/railway.png"></a>
|
| 138 |
+
<a href="https://serpapi.com/?utm_source=fastapi_website" target="_blank" title="SerpApi: Web Search API"><img src="https://fastapi.tiangolo.com/img/sponsors/serpapi.png"></a>
|
| 139 |
+
<a href="https://www.greptile.com/?utm_source=fastapi&utm_medium=sponsorship&utm_campaign=fastapi_sponsor_page" target="_blank" title="Greptile: The AI Code Reviewer"><img src="https://fastapi.tiangolo.com/img/sponsors/greptile.png"></a>
|
| 140 |
+
<a href="https://databento.com/?utm_source=fastapi&utm_medium=sponsor&utm_content=display" target="_blank" title="Pay as you go for market data"><img src="https://fastapi.tiangolo.com/img/sponsors/databento.svg"></a>
|
| 141 |
+
<a href="https://speakeasy.com/editor?utm_source=fastapi+repo&utm_medium=github+sponsorship" target="_blank" title="SDKs for your API | Speakeasy"><img src="https://fastapi.tiangolo.com/img/sponsors/speakeasy.png"></a>
|
| 142 |
+
<a href="https://www.svix.com/" target="_blank" title="Svix - Webhooks as a service"><img src="https://fastapi.tiangolo.com/img/sponsors/svix.svg"></a>
|
| 143 |
+
<a href="https://www.stainlessapi.com/?utm_source=fastapi&utm_medium=referral" target="_blank" title="Stainless | Generate best-in-class SDKs"><img src="https://fastapi.tiangolo.com/img/sponsors/stainless.png"></a>
|
| 144 |
+
<a href="https://www.permit.io/blog/implement-authorization-in-fastapi?utm_source=github&utm_medium=referral&utm_campaign=fastapi" target="_blank" title="Fine-Grained Authorization for FastAPI"><img src="https://fastapi.tiangolo.com/img/sponsors/permit.png"></a>
|
| 145 |
+
<a href="https://www.interviewpal.com/?utm_source=fastapi&utm_medium=open-source&utm_campaign=dev-hiring" target="_blank" title="InterviewPal - AI Interview Coach for Engineers and Devs"><img src="https://fastapi.tiangolo.com/img/sponsors/interviewpal.png"></a>
|
| 146 |
+
<a href="https://dribia.com/en/" target="_blank" title="Dribia - Data Science within your reach"><img src="https://fastapi.tiangolo.com/img/sponsors/dribia.png"></a>
|
| 147 |
+
|
| 148 |
+
<!-- /sponsors -->
|
| 149 |
+
|
| 150 |
+
<a href="https://fastapi.tiangolo.com/fastapi-people/#sponsors" class="external-link" target="_blank">Other sponsors</a>
|
| 151 |
+
|
| 152 |
+
## Opinions
|
| 153 |
+
|
| 154 |
+
"_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._"
|
| 155 |
+
|
| 156 |
+
<div style="text-align: right; margin-right: 10%;">Kabir Khan - <strong>Microsoft</strong> <a href="https://github.com/fastapi/fastapi/pull/26" target="_blank"><small>(ref)</small></a></div>
|
| 157 |
+
|
| 158 |
+
---
|
| 159 |
+
|
| 160 |
+
"_We adopted the **FastAPI** library to spawn a **REST** server that can be queried to obtain **predictions**. [for Ludwig]_"
|
| 161 |
+
|
| 162 |
+
<div style="text-align: right; margin-right: 10%;">Piero Molino, Yaroslav Dudin, and Sai Sumanth Miryala - <strong>Uber</strong> <a href="https://eng.uber.com/ludwig-v0-2/" target="_blank"><small>(ref)</small></a></div>
|
| 163 |
+
|
| 164 |
+
---
|
| 165 |
+
|
| 166 |
+
"_**Netflix** is pleased to announce the open-source release of our **crisis management** orchestration framework: **Dispatch**! [built with **FastAPI**]_"
|
| 167 |
+
|
| 168 |
+
<div style="text-align: right; margin-right: 10%;">Kevin Glisson, Marc Vilanova, Forest Monsen - <strong>Netflix</strong> <a href="https://netflixtechblog.com/introducing-dispatch-da4b8a2a8072" target="_blank"><small>(ref)</small></a></div>
|
| 169 |
+
|
| 170 |
+
---
|
| 171 |
+
|
| 172 |
+
"_I’m over the moon excited about **FastAPI**. It’s so fun!_"
|
| 173 |
+
|
| 174 |
+
<div style="text-align: right; margin-right: 10%;">Brian Okken - <strong><a href="https://pythonbytes.fm/episodes/show/123/time-to-right-the-py-wrongs?time_in_sec=855" target="_blank">Python Bytes</a> podcast host</strong> <a href="https://x.com/brianokken/status/1112220079972728832" target="_blank"><small>(ref)</small></a></div>
|
| 175 |
+
|
| 176 |
+
---
|
| 177 |
+
|
| 178 |
+
"_Honestly, what you've built looks super solid and polished. In many ways, it's what I wanted **Hug** to be - it's really inspiring to see someone build that._"
|
| 179 |
+
|
| 180 |
+
<div style="text-align: right; margin-right: 10%;">Timothy Crosley - <strong><a href="https://github.com/hugapi/hug" target="_blank">Hug</a> creator</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(ref)</small></a></div>
|
| 181 |
+
|
| 182 |
+
---
|
| 183 |
+
|
| 184 |
+
"_If you're looking to learn one **modern framework** for building REST APIs, check out **FastAPI** [...] It's fast, easy to use and easy to learn [...]_"
|
| 185 |
+
|
| 186 |
+
"_We've switched over to **FastAPI** for our **APIs** [...] I think you'll like it [...]_"
|
| 187 |
+
|
| 188 |
+
<div style="text-align: right; margin-right: 10%;">Ines Montani - Matthew Honnibal - <strong><a href="https://explosion.ai" target="_blank">Explosion AI</a> founders - <a href="https://spacy.io" target="_blank">spaCy</a> creators</strong> <a href="https://x.com/_inesmontani/status/1144173225322143744" target="_blank"><small>(ref)</small></a> - <a href="https://x.com/honnibal/status/1144031421859655680" target="_blank"><small>(ref)</small></a></div>
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
"_If anyone is looking to build a production Python API, I would highly recommend **FastAPI**. It is **beautifully designed**, **simple to use** and **highly scalable**, it has become a **key component** in our API first development strategy and is driving many automations and services such as our Virtual TAC Engineer._"
|
| 193 |
+
|
| 194 |
+
<div style="text-align: right; margin-right: 10%;">Deon Pillsbury - <strong>Cisco</strong> <a href="https://www.linkedin.com/posts/deonpillsbury_cisco-cx-python-activity-6963242628536487936-trAp/" target="_blank"><small>(ref)</small></a></div>
|
| 195 |
+
|
| 196 |
+
---
|
| 197 |
+
|
| 198 |
+
## FastAPI mini documentary
|
| 199 |
+
|
| 200 |
+
There's a <a href="https://www.youtube.com/watch?v=mpR8ngthqiE" class="external-link" target="_blank">FastAPI mini documentary</a> released at the end of 2025, you can watch it online:
|
| 201 |
+
|
| 202 |
+
<a href="https://www.youtube.com/watch?v=mpR8ngthqiE" target="_blank"><img src="https://fastapi.tiangolo.com/img/fastapi-documentary.jpg" alt="FastAPI Mini Documentary"></a>
|
| 203 |
+
|
| 204 |
+
## **Typer**, the FastAPI of CLIs
|
| 205 |
+
|
| 206 |
+
<a href="https://typer.tiangolo.com" target="_blank"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" style="width: 20%;"></a>
|
| 207 |
+
|
| 208 |
+
If you are building a <abbr title="Command Line Interface">CLI</abbr> app to be used in the terminal instead of a web API, check out <a href="https://typer.tiangolo.com/" class="external-link" target="_blank">**Typer**</a>.
|
| 209 |
+
|
| 210 |
+
**Typer** is FastAPI's little sibling. And it's intended to be the **FastAPI of CLIs**. ⌨️ 🚀
|
| 211 |
+
|
| 212 |
+
## Requirements
|
| 213 |
+
|
| 214 |
+
FastAPI stands on the shoulders of giants:
|
| 215 |
+
|
| 216 |
+
* <a href="https://www.starlette.dev/" class="external-link" target="_blank">Starlette</a> for the web parts.
|
| 217 |
+
* <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a> for the data parts.
|
| 218 |
+
|
| 219 |
+
## Installation
|
| 220 |
+
|
| 221 |
+
Create and activate a <a href="https://fastapi.tiangolo.com/virtual-environments/" class="external-link" target="_blank">virtual environment</a> and then install FastAPI:
|
| 222 |
+
|
| 223 |
+
<div class="termy">
|
| 224 |
+
|
| 225 |
+
```console
|
| 226 |
+
$ pip install "fastapi[standard]"
|
| 227 |
+
|
| 228 |
+
---> 100%
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
</div>
|
| 232 |
+
|
| 233 |
+
**Note**: Make sure you put `"fastapi[standard]"` in quotes to ensure it works in all terminals.
|
| 234 |
+
|
| 235 |
+
## Example
|
| 236 |
+
|
| 237 |
+
### Create it
|
| 238 |
+
|
| 239 |
+
Create a file `main.py` with:
|
| 240 |
+
|
| 241 |
+
```Python
|
| 242 |
+
from fastapi import FastAPI
|
| 243 |
+
|
| 244 |
+
app = FastAPI()
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
@app.get("/")
|
| 248 |
+
def read_root():
|
| 249 |
+
return {"Hello": "World"}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
@app.get("/items/{item_id}")
|
| 253 |
+
def read_item(item_id: int, q: str | None = None):
|
| 254 |
+
return {"item_id": item_id, "q": q}
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
<details markdown="1">
|
| 258 |
+
<summary>Or use <code>async def</code>...</summary>
|
| 259 |
+
|
| 260 |
+
If your code uses `async` / `await`, use `async def`:
|
| 261 |
+
|
| 262 |
+
```Python hl_lines="7 12"
|
| 263 |
+
from fastapi import FastAPI
|
| 264 |
+
|
| 265 |
+
app = FastAPI()
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
@app.get("/")
|
| 269 |
+
async def read_root():
|
| 270 |
+
return {"Hello": "World"}
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
@app.get("/items/{item_id}")
|
| 274 |
+
async def read_item(item_id: int, q: str | None = None):
|
| 275 |
+
return {"item_id": item_id, "q": q}
|
| 276 |
+
```
|
| 277 |
+
|
| 278 |
+
**Note**:
|
| 279 |
+
|
| 280 |
+
If you don't know, check the _"In a hurry?"_ section about <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank">`async` and `await` in the docs</a>.
|
| 281 |
+
|
| 282 |
+
</details>
|
| 283 |
+
|
| 284 |
+
### Run it
|
| 285 |
+
|
| 286 |
+
Run the server with:
|
| 287 |
+
|
| 288 |
+
<div class="termy">
|
| 289 |
+
|
| 290 |
+
```console
|
| 291 |
+
$ fastapi dev main.py
|
| 292 |
+
|
| 293 |
+
╭────────── FastAPI CLI - Development mode ───────────╮
|
| 294 |
+
│ │
|
| 295 |
+
│ Serving at: http://127.0.0.1:8000 │
|
| 296 |
+
│ │
|
| 297 |
+
│ API docs: http://127.0.0.1:8000/docs │
|
| 298 |
+
│ │
|
| 299 |
+
│ Running in development mode, for production use: │
|
| 300 |
+
│ │
|
| 301 |
+
│ fastapi run │
|
| 302 |
+
│ │
|
| 303 |
+
╰─────────────────────────────────────────────────────╯
|
| 304 |
+
|
| 305 |
+
INFO: Will watch for changes in these directories: ['/home/user/code/awesomeapp']
|
| 306 |
+
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
| 307 |
+
INFO: Started reloader process [2248755] using WatchFiles
|
| 308 |
+
INFO: Started server process [2248757]
|
| 309 |
+
INFO: Waiting for application startup.
|
| 310 |
+
INFO: Application startup complete.
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
</div>
|
| 314 |
+
|
| 315 |
+
<details markdown="1">
|
| 316 |
+
<summary>About the command <code>fastapi dev main.py</code>...</summary>
|
| 317 |
+
|
| 318 |
+
The command `fastapi dev` reads your `main.py` file, detects the **FastAPI** app in it, and starts a server using <a href="https://www.uvicorn.dev" class="external-link" target="_blank">Uvicorn</a>.
|
| 319 |
+
|
| 320 |
+
By default, `fastapi dev` will start with auto-reload enabled for local development.
|
| 321 |
+
|
| 322 |
+
You can read more about it in the <a href="https://fastapi.tiangolo.com/fastapi-cli/" target="_blank">FastAPI CLI docs</a>.
|
| 323 |
+
|
| 324 |
+
</details>
|
| 325 |
+
|
| 326 |
+
### Check it
|
| 327 |
+
|
| 328 |
+
Open your browser at <a href="http://127.0.0.1:8000/items/5?q=somequery" class="external-link" target="_blank">http://127.0.0.1:8000/items/5?q=somequery</a>.
|
| 329 |
+
|
| 330 |
+
You will see the JSON response as:
|
| 331 |
+
|
| 332 |
+
```JSON
|
| 333 |
+
{"item_id": 5, "q": "somequery"}
|
| 334 |
+
```
|
| 335 |
+
|
| 336 |
+
You already created an API that:
|
| 337 |
+
|
| 338 |
+
* Receives HTTP requests in the _paths_ `/` and `/items/{item_id}`.
|
| 339 |
+
* Both _paths_ take `GET` <em>operations</em> (also known as HTTP _methods_).
|
| 340 |
+
* The _path_ `/items/{item_id}` has a _path parameter_ `item_id` that should be an `int`.
|
| 341 |
+
* The _path_ `/items/{item_id}` has an optional `str` _query parameter_ `q`.
|
| 342 |
+
|
| 343 |
+
### Interactive API docs
|
| 344 |
+
|
| 345 |
+
Now go to <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
| 346 |
+
|
| 347 |
+
You will see the automatic interactive API documentation (provided by <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">Swagger UI</a>):
|
| 348 |
+
|
| 349 |
+

|
| 350 |
+
|
| 351 |
+
### Alternative API docs
|
| 352 |
+
|
| 353 |
+
And now, go to <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
|
| 354 |
+
|
| 355 |
+
You will see the alternative automatic documentation (provided by <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">ReDoc</a>):
|
| 356 |
+
|
| 357 |
+

|
| 358 |
+
|
| 359 |
+
## Example upgrade
|
| 360 |
+
|
| 361 |
+
Now modify the file `main.py` to receive a body from a `PUT` request.
|
| 362 |
+
|
| 363 |
+
Declare the body using standard Python types, thanks to Pydantic.
|
| 364 |
+
|
| 365 |
+
```Python hl_lines="2 7-10 23-25"
|
| 366 |
+
from fastapi import FastAPI
|
| 367 |
+
from pydantic import BaseModel
|
| 368 |
+
|
| 369 |
+
app = FastAPI()
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
class Item(BaseModel):
|
| 373 |
+
name: str
|
| 374 |
+
price: float
|
| 375 |
+
is_offer: bool | None = None
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
@app.get("/")
|
| 379 |
+
def read_root():
|
| 380 |
+
return {"Hello": "World"}
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
@app.get("/items/{item_id}")
|
| 384 |
+
def read_item(item_id: int, q: str | None = None):
|
| 385 |
+
return {"item_id": item_id, "q": q}
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
@app.put("/items/{item_id}")
|
| 389 |
+
def update_item(item_id: int, item: Item):
|
| 390 |
+
return {"item_name": item.name, "item_id": item_id}
|
| 391 |
+
```
|
| 392 |
+
|
| 393 |
+
The `fastapi dev` server should reload automatically.
|
| 394 |
+
|
| 395 |
+
### Interactive API docs upgrade
|
| 396 |
+
|
| 397 |
+
Now go to <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
| 398 |
+
|
| 399 |
+
* The interactive API documentation will be automatically updated, including the new body:
|
| 400 |
+
|
| 401 |
+

|
| 402 |
+
|
| 403 |
+
* Click on the button "Try it out", it allows you to fill the parameters and directly interact with the API:
|
| 404 |
+
|
| 405 |
+

|
| 406 |
+
|
| 407 |
+
* Then click on the "Execute" button, the user interface will communicate with your API, send the parameters, get the results and show them on the screen:
|
| 408 |
+
|
| 409 |
+

|
| 410 |
+
|
| 411 |
+
### Alternative API docs upgrade
|
| 412 |
+
|
| 413 |
+
And now, go to <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
|
| 414 |
+
|
| 415 |
+
* The alternative documentation will also reflect the new query parameter and body:
|
| 416 |
+
|
| 417 |
+

|
| 418 |
+
|
| 419 |
+
### Recap
|
| 420 |
+
|
| 421 |
+
In summary, you declare **once** the types of parameters, body, etc. as function parameters.
|
| 422 |
+
|
| 423 |
+
You do that with standard modern Python types.
|
| 424 |
+
|
| 425 |
+
You don't have to learn a new syntax, the methods or classes of a specific library, etc.
|
| 426 |
+
|
| 427 |
+
Just standard **Python**.
|
| 428 |
+
|
| 429 |
+
For example, for an `int`:
|
| 430 |
+
|
| 431 |
+
```Python
|
| 432 |
+
item_id: int
|
| 433 |
+
```
|
| 434 |
+
|
| 435 |
+
or for a more complex `Item` model:
|
| 436 |
+
|
| 437 |
+
```Python
|
| 438 |
+
item: Item
|
| 439 |
+
```
|
| 440 |
+
|
| 441 |
+
...and with that single declaration you get:
|
| 442 |
+
|
| 443 |
+
* Editor support, including:
|
| 444 |
+
* Completion.
|
| 445 |
+
* Type checks.
|
| 446 |
+
* Validation of data:
|
| 447 |
+
* Automatic and clear errors when the data is invalid.
|
| 448 |
+
* Validation even for deeply nested JSON objects.
|
| 449 |
+
* <dfn title="also known as: serialization, parsing, marshalling">Conversion</dfn> of input data: coming from the network to Python data and types. Reading from:
|
| 450 |
+
* JSON.
|
| 451 |
+
* Path parameters.
|
| 452 |
+
* Query parameters.
|
| 453 |
+
* Cookies.
|
| 454 |
+
* Headers.
|
| 455 |
+
* Forms.
|
| 456 |
+
* Files.
|
| 457 |
+
* <dfn title="also known as: serialization, parsing, marshalling">Conversion</dfn> of output data: converting from Python data and types to network data (as JSON):
|
| 458 |
+
* Convert Python types (`str`, `int`, `float`, `bool`, `list`, etc).
|
| 459 |
+
* `datetime` objects.
|
| 460 |
+
* `UUID` objects.
|
| 461 |
+
* Database models.
|
| 462 |
+
* ...and many more.
|
| 463 |
+
* Automatic interactive API documentation, including 2 alternative user interfaces:
|
| 464 |
+
* Swagger UI.
|
| 465 |
+
* ReDoc.
|
| 466 |
+
|
| 467 |
+
---
|
| 468 |
+
|
| 469 |
+
Coming back to the previous code example, **FastAPI** will:
|
| 470 |
+
|
| 471 |
+
* Validate that there is an `item_id` in the path for `GET` and `PUT` requests.
|
| 472 |
+
* Validate that the `item_id` is of type `int` for `GET` and `PUT` requests.
|
| 473 |
+
* If it is not, the client will see a useful, clear error.
|
| 474 |
+
* Check if there is an optional query parameter named `q` (as in `http://127.0.0.1:8000/items/foo?q=somequery`) for `GET` requests.
|
| 475 |
+
* As the `q` parameter is declared with `= None`, it is optional.
|
| 476 |
+
* Without the `None` it would be required (as is the body in the case with `PUT`).
|
| 477 |
+
* For `PUT` requests to `/items/{item_id}`, read the body as JSON:
|
| 478 |
+
* Check that it has a required attribute `name` that should be a `str`.
|
| 479 |
+
* Check that it has a required attribute `price` that has to be a `float`.
|
| 480 |
+
* Check that it has an optional attribute `is_offer`, that should be a `bool`, if present.
|
| 481 |
+
* All this would also work for deeply nested JSON objects.
|
| 482 |
+
* Convert from and to JSON automatically.
|
| 483 |
+
* Document everything with OpenAPI, that can be used by:
|
| 484 |
+
* Interactive documentation systems.
|
| 485 |
+
* Automatic client code generation systems, for many languages.
|
| 486 |
+
* Provide 2 interactive documentation web interfaces directly.
|
| 487 |
+
|
| 488 |
+
---
|
| 489 |
+
|
| 490 |
+
We just scratched the surface, but you already get the idea of how it all works.
|
| 491 |
+
|
| 492 |
+
Try changing the line with:
|
| 493 |
+
|
| 494 |
+
```Python
|
| 495 |
+
return {"item_name": item.name, "item_id": item_id}
|
| 496 |
+
```
|
| 497 |
+
|
| 498 |
+
...from:
|
| 499 |
+
|
| 500 |
+
```Python
|
| 501 |
+
... "item_name": item.name ...
|
| 502 |
+
```
|
| 503 |
+
|
| 504 |
+
...to:
|
| 505 |
+
|
| 506 |
+
```Python
|
| 507 |
+
... "item_price": item.price ...
|
| 508 |
+
```
|
| 509 |
+
|
| 510 |
+
...and see how your editor will auto-complete the attributes and know their types:
|
| 511 |
+
|
| 512 |
+

|
| 513 |
+
|
| 514 |
+
For a more complete example including more features, see the <a href="https://fastapi.tiangolo.com/tutorial/">Tutorial - User Guide</a>.
|
| 515 |
+
|
| 516 |
+
**Spoiler alert**: the tutorial - user guide includes:
|
| 517 |
+
|
| 518 |
+
* Declaration of **parameters** from other different places as: **headers**, **cookies**, **form fields** and **files**.
|
| 519 |
+
* How to set **validation constraints** as `maximum_length` or `regex`.
|
| 520 |
+
* A very powerful and easy to use **<dfn title="also known as components, resources, providers, services, injectables">Dependency Injection</dfn>** system.
|
| 521 |
+
* Security and authentication, including support for **OAuth2** with **JWT tokens** and **HTTP Basic** auth.
|
| 522 |
+
* More advanced (but equally easy) techniques for declaring **deeply nested JSON models** (thanks to Pydantic).
|
| 523 |
+
* **GraphQL** integration with <a href="https://strawberry.rocks" class="external-link" target="_blank">Strawberry</a> and other libraries.
|
| 524 |
+
* Many extra features (thanks to Starlette) as:
|
| 525 |
+
* **WebSockets**
|
| 526 |
+
* extremely easy tests based on HTTPX and `pytest`
|
| 527 |
+
* **CORS**
|
| 528 |
+
* **Cookie Sessions**
|
| 529 |
+
* ...and more.
|
| 530 |
+
|
| 531 |
+
### Deploy your app (optional)
|
| 532 |
+
|
| 533 |
+
You can optionally deploy your FastAPI app to <a href="https://fastapicloud.com" class="external-link" target="_blank">FastAPI Cloud</a>, go and join the waiting list if you haven't. 🚀
|
| 534 |
+
|
| 535 |
+
If you already have a **FastAPI Cloud** account (we invited you from the waiting list 😉), you can deploy your application with one command.
|
| 536 |
+
|
| 537 |
+
Before deploying, make sure you are logged in:
|
| 538 |
+
|
| 539 |
+
<div class="termy">
|
| 540 |
+
|
| 541 |
+
```console
|
| 542 |
+
$ fastapi login
|
| 543 |
+
|
| 544 |
+
You are logged in to FastAPI Cloud 🚀
|
| 545 |
+
```
|
| 546 |
+
|
| 547 |
+
</div>
|
| 548 |
+
|
| 549 |
+
Then deploy your app:
|
| 550 |
+
|
| 551 |
+
<div class="termy">
|
| 552 |
+
|
| 553 |
+
```console
|
| 554 |
+
$ fastapi deploy
|
| 555 |
+
|
| 556 |
+
Deploying to FastAPI Cloud...
|
| 557 |
+
|
| 558 |
+
✅ Deployment successful!
|
| 559 |
+
|
| 560 |
+
🐔 Ready the chicken! Your app is ready at https://myapp.fastapicloud.dev
|
| 561 |
+
```
|
| 562 |
+
|
| 563 |
+
</div>
|
| 564 |
+
|
| 565 |
+
That's it! Now you can access your app at that URL. ✨
|
| 566 |
+
|
| 567 |
+
#### About FastAPI Cloud
|
| 568 |
+
|
| 569 |
+
**<a href="https://fastapicloud.com" class="external-link" target="_blank">FastAPI Cloud</a>** is built by the same author and team behind **FastAPI**.
|
| 570 |
+
|
| 571 |
+
It streamlines the process of **building**, **deploying**, and **accessing** an API with minimal effort.
|
| 572 |
+
|
| 573 |
+
It brings the same **developer experience** of building apps with FastAPI to **deploying** them to the cloud. 🎉
|
| 574 |
+
|
| 575 |
+
FastAPI Cloud is the primary sponsor and funding provider for the *FastAPI and friends* open source projects. ✨
|
| 576 |
+
|
| 577 |
+
#### Deploy to other cloud providers
|
| 578 |
+
|
| 579 |
+
FastAPI is open source and based on standards. You can deploy FastAPI apps to any cloud provider you choose.
|
| 580 |
+
|
| 581 |
+
Follow your cloud provider's guides to deploy FastAPI apps with them. 🤓
|
| 582 |
+
|
| 583 |
+
## Performance
|
| 584 |
+
|
| 585 |
+
Independent TechEmpower benchmarks show **FastAPI** applications running under Uvicorn as <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7" class="external-link" target="_blank">one of the fastest Python frameworks available</a>, only below Starlette and Uvicorn themselves (used internally by FastAPI). (*)
|
| 586 |
+
|
| 587 |
+
To understand more about it, see the section <a href="https://fastapi.tiangolo.com/benchmarks/" class="internal-link" target="_blank">Benchmarks</a>.
|
| 588 |
+
|
| 589 |
+
## Dependencies
|
| 590 |
+
|
| 591 |
+
FastAPI depends on Pydantic and Starlette.
|
| 592 |
+
|
| 593 |
+
### `standard` Dependencies
|
| 594 |
+
|
| 595 |
+
When you install FastAPI with `pip install "fastapi[standard]"` it comes with the `standard` group of optional dependencies:
|
| 596 |
+
|
| 597 |
+
Used by Pydantic:
|
| 598 |
+
|
| 599 |
+
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - for email validation.
|
| 600 |
+
|
| 601 |
+
Used by Starlette:
|
| 602 |
+
|
| 603 |
+
* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
|
| 604 |
+
* <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
|
| 605 |
+
* <a href="https://github.com/Kludex/python-multipart" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <dfn title="converting the string that comes from an HTTP request into Python data">"parsing"</dfn>, with `request.form()`.
|
| 606 |
+
|
| 607 |
+
Used by FastAPI:
|
| 608 |
+
|
| 609 |
+
* <a href="https://www.uvicorn.dev" target="_blank"><code>uvicorn</code></a> - for the server that loads and serves your application. This includes `uvicorn[standard]`, which includes some dependencies (e.g. `uvloop`) needed for high performance serving.
|
| 610 |
+
* `fastapi-cli[standard]` - to provide the `fastapi` command.
|
| 611 |
+
* This includes `fastapi-cloud-cli`, which allows you to deploy your FastAPI application to <a href="https://fastapicloud.com" class="external-link" target="_blank">FastAPI Cloud</a>.
|
| 612 |
+
|
| 613 |
+
### Without `standard` Dependencies
|
| 614 |
+
|
| 615 |
+
If you don't want to include the `standard` optional dependencies, you can install with `pip install fastapi` instead of `pip install "fastapi[standard]"`.
|
| 616 |
+
|
| 617 |
+
### Without `fastapi-cloud-cli`
|
| 618 |
+
|
| 619 |
+
If you want to install FastAPI with the standard dependencies but without the `fastapi-cloud-cli`, you can install with `pip install "fastapi[standard-no-fastapi-cloud-cli]"`.
|
| 620 |
+
|
| 621 |
+
### Additional Optional Dependencies
|
| 622 |
+
|
| 623 |
+
There are some additional dependencies you might want to install.
|
| 624 |
+
|
| 625 |
+
Additional optional Pydantic dependencies:
|
| 626 |
+
|
| 627 |
+
* <a href="https://docs.pydantic.dev/latest/usage/pydantic_settings/" target="_blank"><code>pydantic-settings</code></a> - for settings management.
|
| 628 |
+
* <a href="https://docs.pydantic.dev/latest/usage/types/extra_types/extra_types/" target="_blank"><code>pydantic-extra-types</code></a> - for extra types to be used with Pydantic.
|
| 629 |
+
|
| 630 |
+
Additional optional FastAPI dependencies:
|
| 631 |
+
|
| 632 |
+
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - Required if you want to use `ORJSONResponse`.
|
| 633 |
+
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Required if you want to use `UJSONResponse`.
|
| 634 |
+
|
| 635 |
+
## License
|
| 636 |
+
|
| 637 |
+
This project is licensed under the terms of the MIT license.
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../Scripts/fastapi.exe,sha256=pwXXiopVh2rcEWGekvQVY9DANL8HCsdE76TWXlwO5Ck,108374
|
| 2 |
+
fastapi-0.134.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 3 |
+
fastapi-0.134.0.dist-info/METADATA,sha256=sTQHky_4KhvLXtzm6rls2SZEXdHjotZDTHen0ySZiNI,30710
|
| 4 |
+
fastapi-0.134.0.dist-info/RECORD,,
|
| 5 |
+
fastapi-0.134.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
fastapi-0.134.0.dist-info/WHEEL,sha256=Wb0ASbVj8JvWHpOiIpPi7ucfIgJeCi__PzivviEAQFc,90
|
| 7 |
+
fastapi-0.134.0.dist-info/entry_points.txt,sha256=GCf-WbIZxyGT4MUmrPGj1cOHYZoGsNPHAvNkT6hnGeA,61
|
| 8 |
+
fastapi-0.134.0.dist-info/licenses/LICENSE,sha256=Tsif_IFIW5f-xYSy1KlhAy7v_oNEU4lP2cEnSQbMdE4,1086
|
| 9 |
+
fastapi/.agents/skills/fastapi/SKILL.md,sha256=UMMerdlb5BFT2PXw4xl5G3k5F3Zr9odCjhc_4SFNAZM,14816
|
| 10 |
+
fastapi/__init__.py,sha256=1fE2PpyTwBM0Ik9RGbUuAEKjee1byKpLr9On47bALT4,1081
|
| 11 |
+
fastapi/__main__.py,sha256=bKePXLdO4SsVSM6r9SVoLickJDcR2c0cTOxZRKq26YQ,37
|
| 12 |
+
fastapi/__pycache__/__init__.cpython-312.pyc,,
|
| 13 |
+
fastapi/__pycache__/__main__.cpython-312.pyc,,
|
| 14 |
+
fastapi/__pycache__/applications.cpython-312.pyc,,
|
| 15 |
+
fastapi/__pycache__/background.cpython-312.pyc,,
|
| 16 |
+
fastapi/__pycache__/cli.cpython-312.pyc,,
|
| 17 |
+
fastapi/__pycache__/concurrency.cpython-312.pyc,,
|
| 18 |
+
fastapi/__pycache__/datastructures.cpython-312.pyc,,
|
| 19 |
+
fastapi/__pycache__/encoders.cpython-312.pyc,,
|
| 20 |
+
fastapi/__pycache__/exception_handlers.cpython-312.pyc,,
|
| 21 |
+
fastapi/__pycache__/exceptions.cpython-312.pyc,,
|
| 22 |
+
fastapi/__pycache__/logger.cpython-312.pyc,,
|
| 23 |
+
fastapi/__pycache__/param_functions.cpython-312.pyc,,
|
| 24 |
+
fastapi/__pycache__/params.cpython-312.pyc,,
|
| 25 |
+
fastapi/__pycache__/requests.cpython-312.pyc,,
|
| 26 |
+
fastapi/__pycache__/responses.cpython-312.pyc,,
|
| 27 |
+
fastapi/__pycache__/routing.cpython-312.pyc,,
|
| 28 |
+
fastapi/__pycache__/staticfiles.cpython-312.pyc,,
|
| 29 |
+
fastapi/__pycache__/templating.cpython-312.pyc,,
|
| 30 |
+
fastapi/__pycache__/testclient.cpython-312.pyc,,
|
| 31 |
+
fastapi/__pycache__/types.cpython-312.pyc,,
|
| 32 |
+
fastapi/__pycache__/utils.cpython-312.pyc,,
|
| 33 |
+
fastapi/__pycache__/websockets.cpython-312.pyc,,
|
| 34 |
+
fastapi/_compat/__init__.py,sha256=PYOR-8vJ5va4Qjl810FcQmJbqmpyyeQMoZ9R86CeE2U,2095
|
| 35 |
+
fastapi/_compat/__pycache__/__init__.cpython-312.pyc,,
|
| 36 |
+
fastapi/_compat/__pycache__/shared.cpython-312.pyc,,
|
| 37 |
+
fastapi/_compat/__pycache__/v2.cpython-312.pyc,,
|
| 38 |
+
fastapi/_compat/shared.py,sha256=9Jgi16IkiwhXdnIgAw325qOSaSkYE_u3o33uEUeWLPE,7045
|
| 39 |
+
fastapi/_compat/v2.py,sha256=sS6BoXG-byP77tpuVs4NpDrT_AzxytGktyh6bhOby5I,16951
|
| 40 |
+
fastapi/applications.py,sha256=d6Zgi0PUXdChBQVCXMhGI9cxjpTKWIbWOysCo4Ysf3g,181192
|
| 41 |
+
fastapi/background.py,sha256=TADzAethOAaqpVvckYuTT3c4O9N1HaFQysFCPt0MsgU,1820
|
| 42 |
+
fastapi/cli.py,sha256=OYhZb0NR_deuT5ofyPF2NoNBzZDNOP8Salef2nk-HqA,418
|
| 43 |
+
fastapi/concurrency.py,sha256=xHGDEOQAA6cvFEDX46oq3r2t1Zd4sVvreaRgdIE4juM,1489
|
| 44 |
+
fastapi/datastructures.py,sha256=PH_HLJqgZPjv52lOmM0S-X_ind7S-kOWEpR1k1AzZg8,5206
|
| 45 |
+
fastapi/dependencies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 46 |
+
fastapi/dependencies/__pycache__/__init__.cpython-312.pyc,,
|
| 47 |
+
fastapi/dependencies/__pycache__/models.cpython-312.pyc,,
|
| 48 |
+
fastapi/dependencies/__pycache__/utils.cpython-312.pyc,,
|
| 49 |
+
fastapi/dependencies/models.py,sha256=XPIkEaukHaTaFz9LoeI9f_T-3otOAVkoOC113TpFbWI,7250
|
| 50 |
+
fastapi/dependencies/utils.py,sha256=Q0sLKt5QbBQXJ_npEIIJPLzGjmsUF6QX1_mHXcXlbp8,39276
|
| 51 |
+
fastapi/encoders.py,sha256=XPsYWWS0AYvz7w_wXPsiXtU8OvP38ZvvIcwSw9WzjFY,11049
|
| 52 |
+
fastapi/exception_handlers.py,sha256=YVcT8Zy021VYYeecgdyh5YEUjEIHKcLspbkSf4OfbJI,1275
|
| 53 |
+
fastapi/exceptions.py,sha256=fUNOBRdIsULU0TnO8aNBg3HoJeyJxXp9UV6D8wYu9lI,7453
|
| 54 |
+
fastapi/logger.py,sha256=I9NNi3ov8AcqbsbC9wl1X-hdItKgYt2XTrx1f99Zpl4,54
|
| 55 |
+
fastapi/middleware/__init__.py,sha256=oQDxiFVcc1fYJUOIFvphnK7pTT5kktmfL32QXpBFvvo,58
|
| 56 |
+
fastapi/middleware/__pycache__/__init__.cpython-312.pyc,,
|
| 57 |
+
fastapi/middleware/__pycache__/asyncexitstack.cpython-312.pyc,,
|
| 58 |
+
fastapi/middleware/__pycache__/cors.cpython-312.pyc,,
|
| 59 |
+
fastapi/middleware/__pycache__/gzip.cpython-312.pyc,,
|
| 60 |
+
fastapi/middleware/__pycache__/httpsredirect.cpython-312.pyc,,
|
| 61 |
+
fastapi/middleware/__pycache__/trustedhost.cpython-312.pyc,,
|
| 62 |
+
fastapi/middleware/__pycache__/wsgi.cpython-312.pyc,,
|
| 63 |
+
fastapi/middleware/asyncexitstack.py,sha256=RKGlQpGzg3GLosqVhrxBy_NCZ9qJS7zQeNHt5Y3x-00,637
|
| 64 |
+
fastapi/middleware/cors.py,sha256=ynwjWQZoc_vbhzZ3_ZXceoaSrslHFHPdoM52rXr0WUU,79
|
| 65 |
+
fastapi/middleware/gzip.py,sha256=xM5PcsH8QlAimZw4VDvcmTnqQamslThsfe3CVN2voa0,79
|
| 66 |
+
fastapi/middleware/httpsredirect.py,sha256=rL8eXMnmLijwVkH7_400zHri1AekfeBd6D6qs8ix950,115
|
| 67 |
+
fastapi/middleware/trustedhost.py,sha256=eE5XGRxGa7c5zPnMJDGp3BxaL25k5iVQlhnv-Pk0Pss,109
|
| 68 |
+
fastapi/middleware/wsgi.py,sha256=a_FMDoeTwcdig9wdAGumIH82oDFfuj4pxtQxLbAw2Ns,107
|
| 69 |
+
fastapi/openapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 70 |
+
fastapi/openapi/__pycache__/__init__.cpython-312.pyc,,
|
| 71 |
+
fastapi/openapi/__pycache__/constants.cpython-312.pyc,,
|
| 72 |
+
fastapi/openapi/__pycache__/docs.cpython-312.pyc,,
|
| 73 |
+
fastapi/openapi/__pycache__/models.cpython-312.pyc,,
|
| 74 |
+
fastapi/openapi/__pycache__/utils.cpython-312.pyc,,
|
| 75 |
+
fastapi/openapi/constants.py,sha256=adGzmis1L1HJRTE3kJ5fmHS_Noq6tIY6pWv_SFzoFDU,153
|
| 76 |
+
fastapi/openapi/docs.py,sha256=PcjH0Sn-yp97O0exXincG8epsY7ATyJC5662bK1DRao,12425
|
| 77 |
+
fastapi/openapi/models.py,sha256=4sYz9_TgXcNEWeErEbN87ccJ-2XtXIIAWnyOfQgLc1M,14554
|
| 78 |
+
fastapi/openapi/utils.py,sha256=B-2YsD29xa5phYZmyq8-eTPWjNQjulopDwvjWbnr5Zg,25013
|
| 79 |
+
fastapi/param_functions.py,sha256=UHGNmToBYOpon6RtrDcRWyKgkBjK4zrvW1UYGK6pwMM,69467
|
| 80 |
+
fastapi/params.py,sha256=PA1mGbj7fmH-BFa7nLE9s6JqH43iGhrhpF8s32H15W8,26043
|
| 81 |
+
fastapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 82 |
+
fastapi/requests.py,sha256=zayepKFcienBllv3snmWI20Gk0oHNVLU4DDhqXBb4LU,142
|
| 83 |
+
fastapi/responses.py,sha256=x4SeN3nFO-uWkYrpTCGJFLrMhVFKzzKr6YT6eSEWsR8,3635
|
| 84 |
+
fastapi/routing.py,sha256=C0BA-XMqJJuHXc3Ke2ywmR8fD2-9x6OcXCmyXigiJUc,189850
|
| 85 |
+
fastapi/security/__init__.py,sha256=bO8pNmxqVRXUjfl2mOKiVZLn0FpBQ61VUYVjmppnbJw,881
|
| 86 |
+
fastapi/security/__pycache__/__init__.cpython-312.pyc,,
|
| 87 |
+
fastapi/security/__pycache__/api_key.cpython-312.pyc,,
|
| 88 |
+
fastapi/security/__pycache__/base.cpython-312.pyc,,
|
| 89 |
+
fastapi/security/__pycache__/http.cpython-312.pyc,,
|
| 90 |
+
fastapi/security/__pycache__/oauth2.cpython-312.pyc,,
|
| 91 |
+
fastapi/security/__pycache__/open_id_connect_url.cpython-312.pyc,,
|
| 92 |
+
fastapi/security/__pycache__/utils.cpython-312.pyc,,
|
| 93 |
+
fastapi/security/api_key.py,sha256=2BevKitSAaFKaaYeJFC4nXgKONi9_ozU_BhX-0cZ6cM,9737
|
| 94 |
+
fastapi/security/base.py,sha256=dl4pvbC-RxjfbWgPtCWd8MVU-7CB2SZ22rJDXVCXO6c,141
|
| 95 |
+
fastapi/security/http.py,sha256=Ho9qFuRfFeLJoj90UYVyjeKIzGfY05JhUFy7IfZ59pw,13424
|
| 96 |
+
fastapi/security/oauth2.py,sha256=osYwJYmQSpYbsFXWfIkxvM21we4uqkXwGbNUJlOdaOg,24192
|
| 97 |
+
fastapi/security/open_id_connect_url.py,sha256=Pj-irukboMiZ8_9WSbTyM97cRcQiiLY1y4-u3Vqb3kQ,3139
|
| 98 |
+
fastapi/security/utils.py,sha256=E9YIoez-H2k1oBLEdxqJEi8sV1umunJYKjQHvZG3FRY,261
|
| 99 |
+
fastapi/staticfiles.py,sha256=iirGIt3sdY2QZXd36ijs3Cj-T0FuGFda3cd90kM9Ikw,69
|
| 100 |
+
fastapi/templating.py,sha256=4zsuTWgcjcEainMJFAlW6-gnslm6AgOS1SiiDWfmQxk,76
|
| 101 |
+
fastapi/testclient.py,sha256=nBvaAmX66YldReJNZXPOk1sfuo2Q6hs8bOvIaCep6LQ,66
|
| 102 |
+
fastapi/types.py,sha256=g2tD842BUHC2C3_P8P06albQ4MhCb9RybrSmp5rODgU,438
|
| 103 |
+
fastapi/utils.py,sha256=DX0VrnMwfVsZxRz8IitQ42c2---fDzmFZkeRMZR2UMo,4341
|
| 104 |
+
fastapi/websockets.py,sha256=419uncYObEKZG0YcrXscfQQYLSWoE10jqxVMetGdR98,222
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/REQUESTED
ADDED
|
File without changes
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: pdm-backend (2.4.7)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi-0.134.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
fastapi = fastapi.cli:main
|
| 3 |
+
|
| 4 |
+
[gui_scripts]
|
| 5 |
+
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FastAPI framework, high performance, easy to learn, fast to code, ready for production"""
|
| 2 |
+
|
| 3 |
+
__version__ = "0.134.0"
|
| 4 |
+
|
| 5 |
+
from starlette import status as status
|
| 6 |
+
|
| 7 |
+
from .applications import FastAPI as FastAPI
|
| 8 |
+
from .background import BackgroundTasks as BackgroundTasks
|
| 9 |
+
from .datastructures import UploadFile as UploadFile
|
| 10 |
+
from .exceptions import HTTPException as HTTPException
|
| 11 |
+
from .exceptions import WebSocketException as WebSocketException
|
| 12 |
+
from .param_functions import Body as Body
|
| 13 |
+
from .param_functions import Cookie as Cookie
|
| 14 |
+
from .param_functions import Depends as Depends
|
| 15 |
+
from .param_functions import File as File
|
| 16 |
+
from .param_functions import Form as Form
|
| 17 |
+
from .param_functions import Header as Header
|
| 18 |
+
from .param_functions import Path as Path
|
| 19 |
+
from .param_functions import Query as Query
|
| 20 |
+
from .param_functions import Security as Security
|
| 21 |
+
from .requests import Request as Request
|
| 22 |
+
from .responses import Response as Response
|
| 23 |
+
from .routing import APIRouter as APIRouter
|
| 24 |
+
from .websockets import WebSocket as WebSocket
|
| 25 |
+
from .websockets import WebSocketDisconnect as WebSocketDisconnect
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/__main__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi.cli import main
|
| 2 |
+
|
| 3 |
+
main()
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/applications.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/encoders.py
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import dataclasses
|
| 2 |
+
import datetime
|
| 3 |
+
from collections import defaultdict, deque
|
| 4 |
+
from collections.abc import Callable
|
| 5 |
+
from decimal import Decimal
|
| 6 |
+
from enum import Enum
|
| 7 |
+
from ipaddress import (
|
| 8 |
+
IPv4Address,
|
| 9 |
+
IPv4Interface,
|
| 10 |
+
IPv4Network,
|
| 11 |
+
IPv6Address,
|
| 12 |
+
IPv6Interface,
|
| 13 |
+
IPv6Network,
|
| 14 |
+
)
|
| 15 |
+
from pathlib import Path, PurePath
|
| 16 |
+
from re import Pattern
|
| 17 |
+
from types import GeneratorType
|
| 18 |
+
from typing import Annotated, Any
|
| 19 |
+
from uuid import UUID
|
| 20 |
+
|
| 21 |
+
from annotated_doc import Doc
|
| 22 |
+
from fastapi.exceptions import PydanticV1NotSupportedError
|
| 23 |
+
from fastapi.types import IncEx
|
| 24 |
+
from pydantic import BaseModel
|
| 25 |
+
from pydantic.color import Color
|
| 26 |
+
from pydantic.networks import AnyUrl, NameEmail
|
| 27 |
+
from pydantic.types import SecretBytes, SecretStr
|
| 28 |
+
from pydantic_core import PydanticUndefinedType
|
| 29 |
+
|
| 30 |
+
from ._compat import (
|
| 31 |
+
Url,
|
| 32 |
+
is_pydantic_v1_model_instance,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Taken from Pydantic v1 as is
|
| 37 |
+
def isoformat(o: datetime.date | datetime.time) -> str:
|
| 38 |
+
return o.isoformat()
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Adapted from Pydantic v1
|
| 42 |
+
# TODO: pv2 should this return strings instead?
|
| 43 |
+
def decimal_encoder(dec_value: Decimal) -> int | float:
|
| 44 |
+
"""
|
| 45 |
+
Encodes a Decimal as int if there's no exponent, otherwise float
|
| 46 |
+
|
| 47 |
+
This is useful when we use ConstrainedDecimal to represent Numeric(x,0)
|
| 48 |
+
where an integer (but not int typed) is used. Encoding this as a float
|
| 49 |
+
results in failed round-tripping between encode and parse.
|
| 50 |
+
Our Id type is a prime example of this.
|
| 51 |
+
|
| 52 |
+
>>> decimal_encoder(Decimal("1.0"))
|
| 53 |
+
1.0
|
| 54 |
+
|
| 55 |
+
>>> decimal_encoder(Decimal("1"))
|
| 56 |
+
1
|
| 57 |
+
|
| 58 |
+
>>> decimal_encoder(Decimal("NaN"))
|
| 59 |
+
nan
|
| 60 |
+
"""
|
| 61 |
+
exponent = dec_value.as_tuple().exponent
|
| 62 |
+
if isinstance(exponent, int) and exponent >= 0:
|
| 63 |
+
return int(dec_value)
|
| 64 |
+
else:
|
| 65 |
+
return float(dec_value)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
ENCODERS_BY_TYPE: dict[type[Any], Callable[[Any], Any]] = {
|
| 69 |
+
bytes: lambda o: o.decode(),
|
| 70 |
+
Color: str,
|
| 71 |
+
datetime.date: isoformat,
|
| 72 |
+
datetime.datetime: isoformat,
|
| 73 |
+
datetime.time: isoformat,
|
| 74 |
+
datetime.timedelta: lambda td: td.total_seconds(),
|
| 75 |
+
Decimal: decimal_encoder,
|
| 76 |
+
Enum: lambda o: o.value,
|
| 77 |
+
frozenset: list,
|
| 78 |
+
deque: list,
|
| 79 |
+
GeneratorType: list,
|
| 80 |
+
IPv4Address: str,
|
| 81 |
+
IPv4Interface: str,
|
| 82 |
+
IPv4Network: str,
|
| 83 |
+
IPv6Address: str,
|
| 84 |
+
IPv6Interface: str,
|
| 85 |
+
IPv6Network: str,
|
| 86 |
+
NameEmail: str,
|
| 87 |
+
Path: str,
|
| 88 |
+
Pattern: lambda o: o.pattern,
|
| 89 |
+
SecretBytes: str,
|
| 90 |
+
SecretStr: str,
|
| 91 |
+
set: list,
|
| 92 |
+
UUID: str,
|
| 93 |
+
Url: str,
|
| 94 |
+
AnyUrl: str,
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def generate_encoders_by_class_tuples(
|
| 99 |
+
type_encoder_map: dict[Any, Callable[[Any], Any]],
|
| 100 |
+
) -> dict[Callable[[Any], Any], tuple[Any, ...]]:
|
| 101 |
+
encoders_by_class_tuples: dict[Callable[[Any], Any], tuple[Any, ...]] = defaultdict(
|
| 102 |
+
tuple
|
| 103 |
+
)
|
| 104 |
+
for type_, encoder in type_encoder_map.items():
|
| 105 |
+
encoders_by_class_tuples[encoder] += (type_,)
|
| 106 |
+
return encoders_by_class_tuples
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
encoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def jsonable_encoder(
|
| 113 |
+
obj: Annotated[
|
| 114 |
+
Any,
|
| 115 |
+
Doc(
|
| 116 |
+
"""
|
| 117 |
+
The input object to convert to JSON.
|
| 118 |
+
"""
|
| 119 |
+
),
|
| 120 |
+
],
|
| 121 |
+
include: Annotated[
|
| 122 |
+
IncEx | None,
|
| 123 |
+
Doc(
|
| 124 |
+
"""
|
| 125 |
+
Pydantic's `include` parameter, passed to Pydantic models to set the
|
| 126 |
+
fields to include.
|
| 127 |
+
"""
|
| 128 |
+
),
|
| 129 |
+
] = None,
|
| 130 |
+
exclude: Annotated[
|
| 131 |
+
IncEx | None,
|
| 132 |
+
Doc(
|
| 133 |
+
"""
|
| 134 |
+
Pydantic's `exclude` parameter, passed to Pydantic models to set the
|
| 135 |
+
fields to exclude.
|
| 136 |
+
"""
|
| 137 |
+
),
|
| 138 |
+
] = None,
|
| 139 |
+
by_alias: Annotated[
|
| 140 |
+
bool,
|
| 141 |
+
Doc(
|
| 142 |
+
"""
|
| 143 |
+
Pydantic's `by_alias` parameter, passed to Pydantic models to define if
|
| 144 |
+
the output should use the alias names (when provided) or the Python
|
| 145 |
+
attribute names. In an API, if you set an alias, it's probably because you
|
| 146 |
+
want to use it in the result, so you probably want to leave this set to
|
| 147 |
+
`True`.
|
| 148 |
+
"""
|
| 149 |
+
),
|
| 150 |
+
] = True,
|
| 151 |
+
exclude_unset: Annotated[
|
| 152 |
+
bool,
|
| 153 |
+
Doc(
|
| 154 |
+
"""
|
| 155 |
+
Pydantic's `exclude_unset` parameter, passed to Pydantic models to define
|
| 156 |
+
if it should exclude from the output the fields that were not explicitly
|
| 157 |
+
set (and that only had their default values).
|
| 158 |
+
"""
|
| 159 |
+
),
|
| 160 |
+
] = False,
|
| 161 |
+
exclude_defaults: Annotated[
|
| 162 |
+
bool,
|
| 163 |
+
Doc(
|
| 164 |
+
"""
|
| 165 |
+
Pydantic's `exclude_defaults` parameter, passed to Pydantic models to define
|
| 166 |
+
if it should exclude from the output the fields that had the same default
|
| 167 |
+
value, even when they were explicitly set.
|
| 168 |
+
"""
|
| 169 |
+
),
|
| 170 |
+
] = False,
|
| 171 |
+
exclude_none: Annotated[
|
| 172 |
+
bool,
|
| 173 |
+
Doc(
|
| 174 |
+
"""
|
| 175 |
+
Pydantic's `exclude_none` parameter, passed to Pydantic models to define
|
| 176 |
+
if it should exclude from the output any fields that have a `None` value.
|
| 177 |
+
"""
|
| 178 |
+
),
|
| 179 |
+
] = False,
|
| 180 |
+
custom_encoder: Annotated[
|
| 181 |
+
dict[Any, Callable[[Any], Any]] | None,
|
| 182 |
+
Doc(
|
| 183 |
+
"""
|
| 184 |
+
Pydantic's `custom_encoder` parameter, passed to Pydantic models to define
|
| 185 |
+
a custom encoder.
|
| 186 |
+
"""
|
| 187 |
+
),
|
| 188 |
+
] = None,
|
| 189 |
+
sqlalchemy_safe: Annotated[
|
| 190 |
+
bool,
|
| 191 |
+
Doc(
|
| 192 |
+
"""
|
| 193 |
+
Exclude from the output any fields that start with the name `_sa`.
|
| 194 |
+
|
| 195 |
+
This is mainly a hack for compatibility with SQLAlchemy objects, they
|
| 196 |
+
store internal SQLAlchemy-specific state in attributes named with `_sa`,
|
| 197 |
+
and those objects can't (and shouldn't be) serialized to JSON.
|
| 198 |
+
"""
|
| 199 |
+
),
|
| 200 |
+
] = True,
|
| 201 |
+
) -> Any:
|
| 202 |
+
"""
|
| 203 |
+
Convert any object to something that can be encoded in JSON.
|
| 204 |
+
|
| 205 |
+
This is used internally by FastAPI to make sure anything you return can be
|
| 206 |
+
encoded as JSON before it is sent to the client.
|
| 207 |
+
|
| 208 |
+
You can also use it yourself, for example to convert objects before saving them
|
| 209 |
+
in a database that supports only JSON.
|
| 210 |
+
|
| 211 |
+
Read more about it in the
|
| 212 |
+
[FastAPI docs for JSON Compatible Encoder](https://fastapi.tiangolo.com/tutorial/encoder/).
|
| 213 |
+
"""
|
| 214 |
+
custom_encoder = custom_encoder or {}
|
| 215 |
+
if custom_encoder:
|
| 216 |
+
if type(obj) in custom_encoder:
|
| 217 |
+
return custom_encoder[type(obj)](obj)
|
| 218 |
+
else:
|
| 219 |
+
for encoder_type, encoder_instance in custom_encoder.items():
|
| 220 |
+
if isinstance(obj, encoder_type):
|
| 221 |
+
return encoder_instance(obj)
|
| 222 |
+
if include is not None and not isinstance(include, (set, dict)):
|
| 223 |
+
include = set(include) # type: ignore[assignment]
|
| 224 |
+
if exclude is not None and not isinstance(exclude, (set, dict)):
|
| 225 |
+
exclude = set(exclude) # type: ignore[assignment]
|
| 226 |
+
if isinstance(obj, BaseModel):
|
| 227 |
+
obj_dict = obj.model_dump(
|
| 228 |
+
mode="json",
|
| 229 |
+
include=include,
|
| 230 |
+
exclude=exclude,
|
| 231 |
+
by_alias=by_alias,
|
| 232 |
+
exclude_unset=exclude_unset,
|
| 233 |
+
exclude_none=exclude_none,
|
| 234 |
+
exclude_defaults=exclude_defaults,
|
| 235 |
+
)
|
| 236 |
+
return jsonable_encoder(
|
| 237 |
+
obj_dict,
|
| 238 |
+
exclude_none=exclude_none,
|
| 239 |
+
exclude_defaults=exclude_defaults,
|
| 240 |
+
sqlalchemy_safe=sqlalchemy_safe,
|
| 241 |
+
)
|
| 242 |
+
if dataclasses.is_dataclass(obj):
|
| 243 |
+
assert not isinstance(obj, type)
|
| 244 |
+
obj_dict = dataclasses.asdict(obj)
|
| 245 |
+
return jsonable_encoder(
|
| 246 |
+
obj_dict,
|
| 247 |
+
include=include,
|
| 248 |
+
exclude=exclude,
|
| 249 |
+
by_alias=by_alias,
|
| 250 |
+
exclude_unset=exclude_unset,
|
| 251 |
+
exclude_defaults=exclude_defaults,
|
| 252 |
+
exclude_none=exclude_none,
|
| 253 |
+
custom_encoder=custom_encoder,
|
| 254 |
+
sqlalchemy_safe=sqlalchemy_safe,
|
| 255 |
+
)
|
| 256 |
+
if isinstance(obj, Enum):
|
| 257 |
+
return obj.value
|
| 258 |
+
if isinstance(obj, PurePath):
|
| 259 |
+
return str(obj)
|
| 260 |
+
if isinstance(obj, (str, int, float, type(None))):
|
| 261 |
+
return obj
|
| 262 |
+
if isinstance(obj, PydanticUndefinedType):
|
| 263 |
+
return None
|
| 264 |
+
if isinstance(obj, dict):
|
| 265 |
+
encoded_dict = {}
|
| 266 |
+
allowed_keys = set(obj.keys())
|
| 267 |
+
if include is not None:
|
| 268 |
+
allowed_keys &= set(include)
|
| 269 |
+
if exclude is not None:
|
| 270 |
+
allowed_keys -= set(exclude)
|
| 271 |
+
for key, value in obj.items():
|
| 272 |
+
if (
|
| 273 |
+
(
|
| 274 |
+
not sqlalchemy_safe
|
| 275 |
+
or (not isinstance(key, str))
|
| 276 |
+
or (not key.startswith("_sa"))
|
| 277 |
+
)
|
| 278 |
+
and (value is not None or not exclude_none)
|
| 279 |
+
and key in allowed_keys
|
| 280 |
+
):
|
| 281 |
+
encoded_key = jsonable_encoder(
|
| 282 |
+
key,
|
| 283 |
+
by_alias=by_alias,
|
| 284 |
+
exclude_unset=exclude_unset,
|
| 285 |
+
exclude_none=exclude_none,
|
| 286 |
+
custom_encoder=custom_encoder,
|
| 287 |
+
sqlalchemy_safe=sqlalchemy_safe,
|
| 288 |
+
)
|
| 289 |
+
encoded_value = jsonable_encoder(
|
| 290 |
+
value,
|
| 291 |
+
by_alias=by_alias,
|
| 292 |
+
exclude_unset=exclude_unset,
|
| 293 |
+
exclude_none=exclude_none,
|
| 294 |
+
custom_encoder=custom_encoder,
|
| 295 |
+
sqlalchemy_safe=sqlalchemy_safe,
|
| 296 |
+
)
|
| 297 |
+
encoded_dict[encoded_key] = encoded_value
|
| 298 |
+
return encoded_dict
|
| 299 |
+
if isinstance(obj, (list, set, frozenset, GeneratorType, tuple, deque)):
|
| 300 |
+
encoded_list = []
|
| 301 |
+
for item in obj:
|
| 302 |
+
encoded_list.append(
|
| 303 |
+
jsonable_encoder(
|
| 304 |
+
item,
|
| 305 |
+
include=include,
|
| 306 |
+
exclude=exclude,
|
| 307 |
+
by_alias=by_alias,
|
| 308 |
+
exclude_unset=exclude_unset,
|
| 309 |
+
exclude_defaults=exclude_defaults,
|
| 310 |
+
exclude_none=exclude_none,
|
| 311 |
+
custom_encoder=custom_encoder,
|
| 312 |
+
sqlalchemy_safe=sqlalchemy_safe,
|
| 313 |
+
)
|
| 314 |
+
)
|
| 315 |
+
return encoded_list
|
| 316 |
+
|
| 317 |
+
if type(obj) in ENCODERS_BY_TYPE:
|
| 318 |
+
return ENCODERS_BY_TYPE[type(obj)](obj)
|
| 319 |
+
for encoder, classes_tuple in encoders_by_class_tuples.items():
|
| 320 |
+
if isinstance(obj, classes_tuple):
|
| 321 |
+
return encoder(obj)
|
| 322 |
+
if is_pydantic_v1_model_instance(obj):
|
| 323 |
+
raise PydanticV1NotSupportedError(
|
| 324 |
+
"pydantic.v1 models are no longer supported by FastAPI."
|
| 325 |
+
f" Please update the model {obj!r}."
|
| 326 |
+
)
|
| 327 |
+
try:
|
| 328 |
+
data = dict(obj)
|
| 329 |
+
except Exception as e:
|
| 330 |
+
errors: list[Exception] = []
|
| 331 |
+
errors.append(e)
|
| 332 |
+
try:
|
| 333 |
+
data = vars(obj)
|
| 334 |
+
except Exception as e:
|
| 335 |
+
errors.append(e)
|
| 336 |
+
raise ValueError(errors) from e
|
| 337 |
+
return jsonable_encoder(
|
| 338 |
+
data,
|
| 339 |
+
include=include,
|
| 340 |
+
exclude=exclude,
|
| 341 |
+
by_alias=by_alias,
|
| 342 |
+
exclude_unset=exclude_unset,
|
| 343 |
+
exclude_defaults=exclude_defaults,
|
| 344 |
+
exclude_none=exclude_none,
|
| 345 |
+
custom_encoder=custom_encoder,
|
| 346 |
+
sqlalchemy_safe=sqlalchemy_safe,
|
| 347 |
+
)
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/exception_handlers.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi.encoders import jsonable_encoder
|
| 2 |
+
from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError
|
| 3 |
+
from fastapi.utils import is_body_allowed_for_status_code
|
| 4 |
+
from fastapi.websockets import WebSocket
|
| 5 |
+
from starlette.exceptions import HTTPException
|
| 6 |
+
from starlette.requests import Request
|
| 7 |
+
from starlette.responses import JSONResponse, Response
|
| 8 |
+
from starlette.status import WS_1008_POLICY_VIOLATION
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
async def http_exception_handler(request: Request, exc: HTTPException) -> Response:
|
| 12 |
+
headers = getattr(exc, "headers", None)
|
| 13 |
+
if not is_body_allowed_for_status_code(exc.status_code):
|
| 14 |
+
return Response(status_code=exc.status_code, headers=headers)
|
| 15 |
+
return JSONResponse(
|
| 16 |
+
{"detail": exc.detail}, status_code=exc.status_code, headers=headers
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
async def request_validation_exception_handler(
|
| 21 |
+
request: Request, exc: RequestValidationError
|
| 22 |
+
) -> JSONResponse:
|
| 23 |
+
return JSONResponse(
|
| 24 |
+
status_code=422,
|
| 25 |
+
content={"detail": jsonable_encoder(exc.errors())},
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
async def websocket_request_validation_exception_handler(
|
| 30 |
+
websocket: WebSocket, exc: WebSocketRequestValidationError
|
| 31 |
+
) -> None:
|
| 32 |
+
await websocket.close(
|
| 33 |
+
code=WS_1008_POLICY_VIOLATION, reason=jsonable_encoder(exc.errors())
|
| 34 |
+
)
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/exceptions.py
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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abc import Mapping, Sequence
|
| 2 |
+
from typing import Annotated, Any, TypedDict
|
| 3 |
+
|
| 4 |
+
from annotated_doc import Doc
|
| 5 |
+
from pydantic import BaseModel, create_model
|
| 6 |
+
from starlette.exceptions import HTTPException as StarletteHTTPException
|
| 7 |
+
from starlette.exceptions import WebSocketException as StarletteWebSocketException
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class EndpointContext(TypedDict, total=False):
|
| 11 |
+
function: str
|
| 12 |
+
path: str
|
| 13 |
+
file: str
|
| 14 |
+
line: int
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class HTTPException(StarletteHTTPException):
|
| 18 |
+
"""
|
| 19 |
+
An HTTP exception you can raise in your own code to show errors to the client.
|
| 20 |
+
|
| 21 |
+
This is for client errors, invalid authentication, invalid data, etc. Not for server
|
| 22 |
+
errors in your code.
|
| 23 |
+
|
| 24 |
+
Read more about it in the
|
| 25 |
+
[FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/).
|
| 26 |
+
|
| 27 |
+
## Example
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
from fastapi import FastAPI, HTTPException
|
| 31 |
+
|
| 32 |
+
app = FastAPI()
|
| 33 |
+
|
| 34 |
+
items = {"foo": "The Foo Wrestlers"}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@app.get("/items/{item_id}")
|
| 38 |
+
async def read_item(item_id: str):
|
| 39 |
+
if item_id not in items:
|
| 40 |
+
raise HTTPException(status_code=404, detail="Item not found")
|
| 41 |
+
return {"item": items[item_id]}
|
| 42 |
+
```
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
def __init__(
|
| 46 |
+
self,
|
| 47 |
+
status_code: Annotated[
|
| 48 |
+
int,
|
| 49 |
+
Doc(
|
| 50 |
+
"""
|
| 51 |
+
HTTP status code to send to the client.
|
| 52 |
+
|
| 53 |
+
Read more about it in the
|
| 54 |
+
[FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/#use-httpexception)
|
| 55 |
+
"""
|
| 56 |
+
),
|
| 57 |
+
],
|
| 58 |
+
detail: Annotated[
|
| 59 |
+
Any,
|
| 60 |
+
Doc(
|
| 61 |
+
"""
|
| 62 |
+
Any data to be sent to the client in the `detail` key of the JSON
|
| 63 |
+
response.
|
| 64 |
+
|
| 65 |
+
Read more about it in the
|
| 66 |
+
[FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/#use-httpexception)
|
| 67 |
+
"""
|
| 68 |
+
),
|
| 69 |
+
] = None,
|
| 70 |
+
headers: Annotated[
|
| 71 |
+
Mapping[str, str] | None,
|
| 72 |
+
Doc(
|
| 73 |
+
"""
|
| 74 |
+
Any headers to send to the client in the response.
|
| 75 |
+
|
| 76 |
+
Read more about it in the
|
| 77 |
+
[FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/#add-custom-headers)
|
| 78 |
+
|
| 79 |
+
"""
|
| 80 |
+
),
|
| 81 |
+
] = None,
|
| 82 |
+
) -> None:
|
| 83 |
+
super().__init__(status_code=status_code, detail=detail, headers=headers)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class WebSocketException(StarletteWebSocketException):
|
| 87 |
+
"""
|
| 88 |
+
A WebSocket exception you can raise in your own code to show errors to the client.
|
| 89 |
+
|
| 90 |
+
This is for client errors, invalid authentication, invalid data, etc. Not for server
|
| 91 |
+
errors in your code.
|
| 92 |
+
|
| 93 |
+
Read more about it in the
|
| 94 |
+
[FastAPI docs for WebSockets](https://fastapi.tiangolo.com/advanced/websockets/).
|
| 95 |
+
|
| 96 |
+
## Example
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
from typing import Annotated
|
| 100 |
+
|
| 101 |
+
from fastapi import (
|
| 102 |
+
Cookie,
|
| 103 |
+
FastAPI,
|
| 104 |
+
WebSocket,
|
| 105 |
+
WebSocketException,
|
| 106 |
+
status,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
app = FastAPI()
|
| 110 |
+
|
| 111 |
+
@app.websocket("/items/{item_id}/ws")
|
| 112 |
+
async def websocket_endpoint(
|
| 113 |
+
*,
|
| 114 |
+
websocket: WebSocket,
|
| 115 |
+
session: Annotated[str | None, Cookie()] = None,
|
| 116 |
+
item_id: str,
|
| 117 |
+
):
|
| 118 |
+
if session is None:
|
| 119 |
+
raise WebSocketException(code=status.WS_1008_POLICY_VIOLATION)
|
| 120 |
+
await websocket.accept()
|
| 121 |
+
while True:
|
| 122 |
+
data = await websocket.receive_text()
|
| 123 |
+
await websocket.send_text(f"Session cookie is: {session}")
|
| 124 |
+
await websocket.send_text(f"Message text was: {data}, for item ID: {item_id}")
|
| 125 |
+
```
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
def __init__(
|
| 129 |
+
self,
|
| 130 |
+
code: Annotated[
|
| 131 |
+
int,
|
| 132 |
+
Doc(
|
| 133 |
+
"""
|
| 134 |
+
A closing code from the
|
| 135 |
+
[valid codes defined in the specification](https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1).
|
| 136 |
+
"""
|
| 137 |
+
),
|
| 138 |
+
],
|
| 139 |
+
reason: Annotated[
|
| 140 |
+
str | None,
|
| 141 |
+
Doc(
|
| 142 |
+
"""
|
| 143 |
+
The reason to close the WebSocket connection.
|
| 144 |
+
|
| 145 |
+
It is UTF-8-encoded data. The interpretation of the reason is up to the
|
| 146 |
+
application, it is not specified by the WebSocket specification.
|
| 147 |
+
|
| 148 |
+
It could contain text that could be human-readable or interpretable
|
| 149 |
+
by the client code, etc.
|
| 150 |
+
"""
|
| 151 |
+
),
|
| 152 |
+
] = None,
|
| 153 |
+
) -> None:
|
| 154 |
+
super().__init__(code=code, reason=reason)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
RequestErrorModel: type[BaseModel] = create_model("Request")
|
| 158 |
+
WebSocketErrorModel: type[BaseModel] = create_model("WebSocket")
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class FastAPIError(RuntimeError):
|
| 162 |
+
"""
|
| 163 |
+
A generic, FastAPI-specific error.
|
| 164 |
+
"""
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
class DependencyScopeError(FastAPIError):
|
| 168 |
+
"""
|
| 169 |
+
A dependency declared that it depends on another dependency with an invalid
|
| 170 |
+
(narrower) scope.
|
| 171 |
+
"""
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
class ValidationException(Exception):
|
| 175 |
+
def __init__(
|
| 176 |
+
self,
|
| 177 |
+
errors: Sequence[Any],
|
| 178 |
+
*,
|
| 179 |
+
endpoint_ctx: EndpointContext | None = None,
|
| 180 |
+
) -> None:
|
| 181 |
+
self._errors = errors
|
| 182 |
+
self.endpoint_ctx = endpoint_ctx
|
| 183 |
+
|
| 184 |
+
ctx = endpoint_ctx or {}
|
| 185 |
+
self.endpoint_function = ctx.get("function")
|
| 186 |
+
self.endpoint_path = ctx.get("path")
|
| 187 |
+
self.endpoint_file = ctx.get("file")
|
| 188 |
+
self.endpoint_line = ctx.get("line")
|
| 189 |
+
|
| 190 |
+
def errors(self) -> Sequence[Any]:
|
| 191 |
+
return self._errors
|
| 192 |
+
|
| 193 |
+
def _format_endpoint_context(self) -> str:
|
| 194 |
+
if not (self.endpoint_file and self.endpoint_line and self.endpoint_function):
|
| 195 |
+
if self.endpoint_path:
|
| 196 |
+
return f"\n Endpoint: {self.endpoint_path}"
|
| 197 |
+
return ""
|
| 198 |
+
|
| 199 |
+
context = f'\n File "{self.endpoint_file}", line {self.endpoint_line}, in {self.endpoint_function}'
|
| 200 |
+
if self.endpoint_path:
|
| 201 |
+
context += f"\n {self.endpoint_path}"
|
| 202 |
+
return context
|
| 203 |
+
|
| 204 |
+
def __str__(self) -> str:
|
| 205 |
+
message = f"{len(self._errors)} validation error{'s' if len(self._errors) != 1 else ''}:\n"
|
| 206 |
+
for err in self._errors:
|
| 207 |
+
message += f" {err}\n"
|
| 208 |
+
message += self._format_endpoint_context()
|
| 209 |
+
return message.rstrip()
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class RequestValidationError(ValidationException):
|
| 213 |
+
def __init__(
|
| 214 |
+
self,
|
| 215 |
+
errors: Sequence[Any],
|
| 216 |
+
*,
|
| 217 |
+
body: Any = None,
|
| 218 |
+
endpoint_ctx: EndpointContext | None = None,
|
| 219 |
+
) -> None:
|
| 220 |
+
super().__init__(errors, endpoint_ctx=endpoint_ctx)
|
| 221 |
+
self.body = body
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
class WebSocketRequestValidationError(ValidationException):
|
| 225 |
+
def __init__(
|
| 226 |
+
self,
|
| 227 |
+
errors: Sequence[Any],
|
| 228 |
+
*,
|
| 229 |
+
endpoint_ctx: EndpointContext | None = None,
|
| 230 |
+
) -> None:
|
| 231 |
+
super().__init__(errors, endpoint_ctx=endpoint_ctx)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
class ResponseValidationError(ValidationException):
|
| 235 |
+
def __init__(
|
| 236 |
+
self,
|
| 237 |
+
errors: Sequence[Any],
|
| 238 |
+
*,
|
| 239 |
+
body: Any = None,
|
| 240 |
+
endpoint_ctx: EndpointContext | None = None,
|
| 241 |
+
) -> None:
|
| 242 |
+
super().__init__(errors, endpoint_ctx=endpoint_ctx)
|
| 243 |
+
self.body = body
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class PydanticV1NotSupportedError(FastAPIError):
|
| 247 |
+
"""
|
| 248 |
+
A pydantic.v1 model is used, which is no longer supported.
|
| 249 |
+
"""
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
class FastAPIDeprecationWarning(UserWarning):
|
| 253 |
+
"""
|
| 254 |
+
A custom deprecation warning as DeprecationWarning is ignored
|
| 255 |
+
Ref: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries
|
| 256 |
+
"""
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/logger.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable, Sequence
|
| 2 |
+
from typing import Annotated, Any, Literal
|
| 3 |
+
|
| 4 |
+
from annotated_doc import Doc
|
| 5 |
+
from fastapi import params
|
| 6 |
+
from fastapi._compat import Undefined
|
| 7 |
+
from fastapi.openapi.models import Example
|
| 8 |
+
from pydantic import AliasChoices, AliasPath
|
| 9 |
+
from typing_extensions import deprecated
|
| 10 |
+
|
| 11 |
+
_Unset: Any = Undefined
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def Path( # noqa: N802
|
| 15 |
+
default: Annotated[
|
| 16 |
+
Any,
|
| 17 |
+
Doc(
|
| 18 |
+
"""
|
| 19 |
+
Default value if the parameter field is not set.
|
| 20 |
+
|
| 21 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 22 |
+
The parameter is available only for compatibility.
|
| 23 |
+
"""
|
| 24 |
+
),
|
| 25 |
+
] = ...,
|
| 26 |
+
*,
|
| 27 |
+
default_factory: Annotated[
|
| 28 |
+
Callable[[], Any] | None,
|
| 29 |
+
Doc(
|
| 30 |
+
"""
|
| 31 |
+
A callable to generate the default value.
|
| 32 |
+
|
| 33 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 34 |
+
The parameter is available only for compatibility.
|
| 35 |
+
"""
|
| 36 |
+
),
|
| 37 |
+
] = _Unset,
|
| 38 |
+
alias: Annotated[
|
| 39 |
+
str | None,
|
| 40 |
+
Doc(
|
| 41 |
+
"""
|
| 42 |
+
An alternative name for the parameter field.
|
| 43 |
+
|
| 44 |
+
This will be used to extract the data and for the generated OpenAPI.
|
| 45 |
+
It is particularly useful when you can't use the name you want because it
|
| 46 |
+
is a Python reserved keyword or similar.
|
| 47 |
+
"""
|
| 48 |
+
),
|
| 49 |
+
] = None,
|
| 50 |
+
alias_priority: Annotated[
|
| 51 |
+
int | None,
|
| 52 |
+
Doc(
|
| 53 |
+
"""
|
| 54 |
+
Priority of the alias. This affects whether an alias generator is used.
|
| 55 |
+
"""
|
| 56 |
+
),
|
| 57 |
+
] = _Unset,
|
| 58 |
+
validation_alias: Annotated[
|
| 59 |
+
str | AliasPath | AliasChoices | None,
|
| 60 |
+
Doc(
|
| 61 |
+
"""
|
| 62 |
+
'Whitelist' validation step. The parameter field will be the single one
|
| 63 |
+
allowed by the alias or set of aliases defined.
|
| 64 |
+
"""
|
| 65 |
+
),
|
| 66 |
+
] = None,
|
| 67 |
+
serialization_alias: Annotated[
|
| 68 |
+
str | None,
|
| 69 |
+
Doc(
|
| 70 |
+
"""
|
| 71 |
+
'Blacklist' validation step. The vanilla parameter field will be the
|
| 72 |
+
single one of the alias' or set of aliases' fields and all the other
|
| 73 |
+
fields will be ignored at serialization time.
|
| 74 |
+
"""
|
| 75 |
+
),
|
| 76 |
+
] = None,
|
| 77 |
+
title: Annotated[
|
| 78 |
+
str | None,
|
| 79 |
+
Doc(
|
| 80 |
+
"""
|
| 81 |
+
Human-readable title.
|
| 82 |
+
|
| 83 |
+
Read more about it in the
|
| 84 |
+
[FastAPI docs for Path Parameters and Numeric Validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#declare-metadata)
|
| 85 |
+
"""
|
| 86 |
+
),
|
| 87 |
+
] = None,
|
| 88 |
+
description: Annotated[
|
| 89 |
+
str | None,
|
| 90 |
+
Doc(
|
| 91 |
+
"""
|
| 92 |
+
Human-readable description.
|
| 93 |
+
"""
|
| 94 |
+
),
|
| 95 |
+
] = None,
|
| 96 |
+
gt: Annotated[
|
| 97 |
+
float | None,
|
| 98 |
+
Doc(
|
| 99 |
+
"""
|
| 100 |
+
Greater than. If set, value must be greater than this. Only applicable to
|
| 101 |
+
numbers.
|
| 102 |
+
|
| 103 |
+
Read more about it in the
|
| 104 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 105 |
+
"""
|
| 106 |
+
),
|
| 107 |
+
] = None,
|
| 108 |
+
ge: Annotated[
|
| 109 |
+
float | None,
|
| 110 |
+
Doc(
|
| 111 |
+
"""
|
| 112 |
+
Greater than or equal. If set, value must be greater than or equal to
|
| 113 |
+
this. Only applicable to numbers.
|
| 114 |
+
|
| 115 |
+
Read more about it in the
|
| 116 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 117 |
+
"""
|
| 118 |
+
),
|
| 119 |
+
] = None,
|
| 120 |
+
lt: Annotated[
|
| 121 |
+
float | None,
|
| 122 |
+
Doc(
|
| 123 |
+
"""
|
| 124 |
+
Less than. If set, value must be less than this. Only applicable to numbers.
|
| 125 |
+
|
| 126 |
+
Read more about it in the
|
| 127 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 128 |
+
"""
|
| 129 |
+
),
|
| 130 |
+
] = None,
|
| 131 |
+
le: Annotated[
|
| 132 |
+
float | None,
|
| 133 |
+
Doc(
|
| 134 |
+
"""
|
| 135 |
+
Less than or equal. If set, value must be less than or equal to this.
|
| 136 |
+
Only applicable to numbers.
|
| 137 |
+
|
| 138 |
+
Read more about it in the
|
| 139 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 140 |
+
"""
|
| 141 |
+
),
|
| 142 |
+
] = None,
|
| 143 |
+
min_length: Annotated[
|
| 144 |
+
int | None,
|
| 145 |
+
Doc(
|
| 146 |
+
"""
|
| 147 |
+
Minimum length for strings.
|
| 148 |
+
"""
|
| 149 |
+
),
|
| 150 |
+
] = None,
|
| 151 |
+
max_length: Annotated[
|
| 152 |
+
int | None,
|
| 153 |
+
Doc(
|
| 154 |
+
"""
|
| 155 |
+
Maximum length for strings.
|
| 156 |
+
"""
|
| 157 |
+
),
|
| 158 |
+
] = None,
|
| 159 |
+
pattern: Annotated[
|
| 160 |
+
str | None,
|
| 161 |
+
Doc(
|
| 162 |
+
"""
|
| 163 |
+
RegEx pattern for strings.
|
| 164 |
+
"""
|
| 165 |
+
),
|
| 166 |
+
] = None,
|
| 167 |
+
regex: Annotated[
|
| 168 |
+
str | None,
|
| 169 |
+
Doc(
|
| 170 |
+
"""
|
| 171 |
+
RegEx pattern for strings.
|
| 172 |
+
"""
|
| 173 |
+
),
|
| 174 |
+
deprecated(
|
| 175 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 176 |
+
),
|
| 177 |
+
] = None,
|
| 178 |
+
discriminator: Annotated[
|
| 179 |
+
str | None,
|
| 180 |
+
Doc(
|
| 181 |
+
"""
|
| 182 |
+
Parameter field name for discriminating the type in a tagged union.
|
| 183 |
+
"""
|
| 184 |
+
),
|
| 185 |
+
] = None,
|
| 186 |
+
strict: Annotated[
|
| 187 |
+
bool | None,
|
| 188 |
+
Doc(
|
| 189 |
+
"""
|
| 190 |
+
If `True`, strict validation is applied to the field.
|
| 191 |
+
"""
|
| 192 |
+
),
|
| 193 |
+
] = _Unset,
|
| 194 |
+
multiple_of: Annotated[
|
| 195 |
+
float | None,
|
| 196 |
+
Doc(
|
| 197 |
+
"""
|
| 198 |
+
Value must be a multiple of this. Only applicable to numbers.
|
| 199 |
+
"""
|
| 200 |
+
),
|
| 201 |
+
] = _Unset,
|
| 202 |
+
allow_inf_nan: Annotated[
|
| 203 |
+
bool | None,
|
| 204 |
+
Doc(
|
| 205 |
+
"""
|
| 206 |
+
Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
|
| 207 |
+
"""
|
| 208 |
+
),
|
| 209 |
+
] = _Unset,
|
| 210 |
+
max_digits: Annotated[
|
| 211 |
+
int | None,
|
| 212 |
+
Doc(
|
| 213 |
+
"""
|
| 214 |
+
Maximum number of allow digits for strings.
|
| 215 |
+
"""
|
| 216 |
+
),
|
| 217 |
+
] = _Unset,
|
| 218 |
+
decimal_places: Annotated[
|
| 219 |
+
int | None,
|
| 220 |
+
Doc(
|
| 221 |
+
"""
|
| 222 |
+
Maximum number of decimal places allowed for numbers.
|
| 223 |
+
"""
|
| 224 |
+
),
|
| 225 |
+
] = _Unset,
|
| 226 |
+
examples: Annotated[
|
| 227 |
+
list[Any] | None,
|
| 228 |
+
Doc(
|
| 229 |
+
"""
|
| 230 |
+
Example values for this field.
|
| 231 |
+
|
| 232 |
+
Read more about it in the
|
| 233 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)
|
| 234 |
+
"""
|
| 235 |
+
),
|
| 236 |
+
] = None,
|
| 237 |
+
example: Annotated[
|
| 238 |
+
Any | None,
|
| 239 |
+
deprecated(
|
| 240 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 241 |
+
"although still supported. Use examples instead."
|
| 242 |
+
),
|
| 243 |
+
] = _Unset,
|
| 244 |
+
openapi_examples: Annotated[
|
| 245 |
+
dict[str, Example] | None,
|
| 246 |
+
Doc(
|
| 247 |
+
"""
|
| 248 |
+
OpenAPI-specific examples.
|
| 249 |
+
|
| 250 |
+
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
|
| 251 |
+
|
| 252 |
+
Swagger UI (that provides the `/docs` interface) has better support for the
|
| 253 |
+
OpenAPI-specific examples than the JSON Schema `examples`, that's the main
|
| 254 |
+
use case for this.
|
| 255 |
+
|
| 256 |
+
Read more about it in the
|
| 257 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
|
| 258 |
+
"""
|
| 259 |
+
),
|
| 260 |
+
] = None,
|
| 261 |
+
deprecated: Annotated[
|
| 262 |
+
deprecated | str | bool | None,
|
| 263 |
+
Doc(
|
| 264 |
+
"""
|
| 265 |
+
Mark this parameter field as deprecated.
|
| 266 |
+
|
| 267 |
+
It will affect the generated OpenAPI (e.g. visible at `/docs`).
|
| 268 |
+
"""
|
| 269 |
+
),
|
| 270 |
+
] = None,
|
| 271 |
+
include_in_schema: Annotated[
|
| 272 |
+
bool,
|
| 273 |
+
Doc(
|
| 274 |
+
"""
|
| 275 |
+
To include (or not) this parameter field in the generated OpenAPI.
|
| 276 |
+
You probably don't need it, but it's available.
|
| 277 |
+
|
| 278 |
+
This affects the generated OpenAPI (e.g. visible at `/docs`).
|
| 279 |
+
"""
|
| 280 |
+
),
|
| 281 |
+
] = True,
|
| 282 |
+
json_schema_extra: Annotated[
|
| 283 |
+
dict[str, Any] | None,
|
| 284 |
+
Doc(
|
| 285 |
+
"""
|
| 286 |
+
Any additional JSON schema data.
|
| 287 |
+
"""
|
| 288 |
+
),
|
| 289 |
+
] = None,
|
| 290 |
+
**extra: Annotated[
|
| 291 |
+
Any,
|
| 292 |
+
Doc(
|
| 293 |
+
"""
|
| 294 |
+
Include extra fields used by the JSON Schema.
|
| 295 |
+
"""
|
| 296 |
+
),
|
| 297 |
+
deprecated(
|
| 298 |
+
"""
|
| 299 |
+
The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
|
| 300 |
+
"""
|
| 301 |
+
),
|
| 302 |
+
],
|
| 303 |
+
) -> Any:
|
| 304 |
+
"""
|
| 305 |
+
Declare a path parameter for a *path operation*.
|
| 306 |
+
|
| 307 |
+
Read more about it in the
|
| 308 |
+
[FastAPI docs for Path Parameters and Numeric Validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/).
|
| 309 |
+
|
| 310 |
+
```python
|
| 311 |
+
from typing import Annotated
|
| 312 |
+
|
| 313 |
+
from fastapi import FastAPI, Path
|
| 314 |
+
|
| 315 |
+
app = FastAPI()
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
@app.get("/items/{item_id}")
|
| 319 |
+
async def read_items(
|
| 320 |
+
item_id: Annotated[int, Path(title="The ID of the item to get")],
|
| 321 |
+
):
|
| 322 |
+
return {"item_id": item_id}
|
| 323 |
+
```
|
| 324 |
+
"""
|
| 325 |
+
return params.Path(
|
| 326 |
+
default=default,
|
| 327 |
+
default_factory=default_factory,
|
| 328 |
+
alias=alias,
|
| 329 |
+
alias_priority=alias_priority,
|
| 330 |
+
validation_alias=validation_alias,
|
| 331 |
+
serialization_alias=serialization_alias,
|
| 332 |
+
title=title,
|
| 333 |
+
description=description,
|
| 334 |
+
gt=gt,
|
| 335 |
+
ge=ge,
|
| 336 |
+
lt=lt,
|
| 337 |
+
le=le,
|
| 338 |
+
min_length=min_length,
|
| 339 |
+
max_length=max_length,
|
| 340 |
+
pattern=pattern,
|
| 341 |
+
regex=regex,
|
| 342 |
+
discriminator=discriminator,
|
| 343 |
+
strict=strict,
|
| 344 |
+
multiple_of=multiple_of,
|
| 345 |
+
allow_inf_nan=allow_inf_nan,
|
| 346 |
+
max_digits=max_digits,
|
| 347 |
+
decimal_places=decimal_places,
|
| 348 |
+
example=example,
|
| 349 |
+
examples=examples,
|
| 350 |
+
openapi_examples=openapi_examples,
|
| 351 |
+
deprecated=deprecated,
|
| 352 |
+
include_in_schema=include_in_schema,
|
| 353 |
+
json_schema_extra=json_schema_extra,
|
| 354 |
+
**extra,
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def Query( # noqa: N802
|
| 359 |
+
default: Annotated[
|
| 360 |
+
Any,
|
| 361 |
+
Doc(
|
| 362 |
+
"""
|
| 363 |
+
Default value if the parameter field is not set.
|
| 364 |
+
|
| 365 |
+
Read more about it in the
|
| 366 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#alternative-old-query-as-the-default-value)
|
| 367 |
+
"""
|
| 368 |
+
),
|
| 369 |
+
] = Undefined,
|
| 370 |
+
*,
|
| 371 |
+
default_factory: Annotated[
|
| 372 |
+
Callable[[], Any] | None,
|
| 373 |
+
Doc(
|
| 374 |
+
"""
|
| 375 |
+
A callable to generate the default value.
|
| 376 |
+
|
| 377 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 378 |
+
The parameter is available only for compatibility.
|
| 379 |
+
"""
|
| 380 |
+
),
|
| 381 |
+
] = _Unset,
|
| 382 |
+
alias: Annotated[
|
| 383 |
+
str | None,
|
| 384 |
+
Doc(
|
| 385 |
+
"""
|
| 386 |
+
An alternative name for the parameter field.
|
| 387 |
+
|
| 388 |
+
This will be used to extract the data and for the generated OpenAPI.
|
| 389 |
+
It is particularly useful when you can't use the name you want because it
|
| 390 |
+
is a Python reserved keyword or similar.
|
| 391 |
+
|
| 392 |
+
Read more about it in the
|
| 393 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#alias-parameters)
|
| 394 |
+
"""
|
| 395 |
+
),
|
| 396 |
+
] = None,
|
| 397 |
+
alias_priority: Annotated[
|
| 398 |
+
int | None,
|
| 399 |
+
Doc(
|
| 400 |
+
"""
|
| 401 |
+
Priority of the alias. This affects whether an alias generator is used.
|
| 402 |
+
"""
|
| 403 |
+
),
|
| 404 |
+
] = _Unset,
|
| 405 |
+
validation_alias: Annotated[
|
| 406 |
+
str | AliasPath | AliasChoices | None,
|
| 407 |
+
Doc(
|
| 408 |
+
"""
|
| 409 |
+
'Whitelist' validation step. The parameter field will be the single one
|
| 410 |
+
allowed by the alias or set of aliases defined.
|
| 411 |
+
"""
|
| 412 |
+
),
|
| 413 |
+
] = None,
|
| 414 |
+
serialization_alias: Annotated[
|
| 415 |
+
str | None,
|
| 416 |
+
Doc(
|
| 417 |
+
"""
|
| 418 |
+
'Blacklist' validation step. The vanilla parameter field will be the
|
| 419 |
+
single one of the alias' or set of aliases' fields and all the other
|
| 420 |
+
fields will be ignored at serialization time.
|
| 421 |
+
"""
|
| 422 |
+
),
|
| 423 |
+
] = None,
|
| 424 |
+
title: Annotated[
|
| 425 |
+
str | None,
|
| 426 |
+
Doc(
|
| 427 |
+
"""
|
| 428 |
+
Human-readable title.
|
| 429 |
+
|
| 430 |
+
Read more about it in the
|
| 431 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#declare-more-metadata)
|
| 432 |
+
"""
|
| 433 |
+
),
|
| 434 |
+
] = None,
|
| 435 |
+
description: Annotated[
|
| 436 |
+
str | None,
|
| 437 |
+
Doc(
|
| 438 |
+
"""
|
| 439 |
+
Human-readable description.
|
| 440 |
+
|
| 441 |
+
Read more about it in the
|
| 442 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#declare-more-metadata)
|
| 443 |
+
"""
|
| 444 |
+
),
|
| 445 |
+
] = None,
|
| 446 |
+
gt: Annotated[
|
| 447 |
+
float | None,
|
| 448 |
+
Doc(
|
| 449 |
+
"""
|
| 450 |
+
Greater than. If set, value must be greater than this. Only applicable to
|
| 451 |
+
numbers.
|
| 452 |
+
|
| 453 |
+
Read more about it in the
|
| 454 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 455 |
+
"""
|
| 456 |
+
),
|
| 457 |
+
] = None,
|
| 458 |
+
ge: Annotated[
|
| 459 |
+
float | None,
|
| 460 |
+
Doc(
|
| 461 |
+
"""
|
| 462 |
+
Greater than or equal. If set, value must be greater than or equal to
|
| 463 |
+
this. Only applicable to numbers.
|
| 464 |
+
|
| 465 |
+
Read more about it in the
|
| 466 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 467 |
+
"""
|
| 468 |
+
),
|
| 469 |
+
] = None,
|
| 470 |
+
lt: Annotated[
|
| 471 |
+
float | None,
|
| 472 |
+
Doc(
|
| 473 |
+
"""
|
| 474 |
+
Less than. If set, value must be less than this. Only applicable to numbers.
|
| 475 |
+
|
| 476 |
+
Read more about it in the
|
| 477 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 478 |
+
"""
|
| 479 |
+
),
|
| 480 |
+
] = None,
|
| 481 |
+
le: Annotated[
|
| 482 |
+
float | None,
|
| 483 |
+
Doc(
|
| 484 |
+
"""
|
| 485 |
+
Less than or equal. If set, value must be less than or equal to this.
|
| 486 |
+
Only applicable to numbers.
|
| 487 |
+
|
| 488 |
+
Read more about it in the
|
| 489 |
+
[FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)
|
| 490 |
+
"""
|
| 491 |
+
),
|
| 492 |
+
] = None,
|
| 493 |
+
min_length: Annotated[
|
| 494 |
+
int | None,
|
| 495 |
+
Doc(
|
| 496 |
+
"""
|
| 497 |
+
Minimum length for strings.
|
| 498 |
+
|
| 499 |
+
Read more about it in the
|
| 500 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/)
|
| 501 |
+
"""
|
| 502 |
+
),
|
| 503 |
+
] = None,
|
| 504 |
+
max_length: Annotated[
|
| 505 |
+
int | None,
|
| 506 |
+
Doc(
|
| 507 |
+
"""
|
| 508 |
+
Maximum length for strings.
|
| 509 |
+
|
| 510 |
+
Read more about it in the
|
| 511 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/)
|
| 512 |
+
"""
|
| 513 |
+
),
|
| 514 |
+
] = None,
|
| 515 |
+
pattern: Annotated[
|
| 516 |
+
str | None,
|
| 517 |
+
Doc(
|
| 518 |
+
"""
|
| 519 |
+
RegEx pattern for strings.
|
| 520 |
+
|
| 521 |
+
Read more about it in the
|
| 522 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#add-regular-expressions
|
| 523 |
+
"""
|
| 524 |
+
),
|
| 525 |
+
] = None,
|
| 526 |
+
regex: Annotated[
|
| 527 |
+
str | None,
|
| 528 |
+
Doc(
|
| 529 |
+
"""
|
| 530 |
+
RegEx pattern for strings.
|
| 531 |
+
"""
|
| 532 |
+
),
|
| 533 |
+
deprecated(
|
| 534 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 535 |
+
),
|
| 536 |
+
] = None,
|
| 537 |
+
discriminator: Annotated[
|
| 538 |
+
str | None,
|
| 539 |
+
Doc(
|
| 540 |
+
"""
|
| 541 |
+
Parameter field name for discriminating the type in a tagged union.
|
| 542 |
+
"""
|
| 543 |
+
),
|
| 544 |
+
] = None,
|
| 545 |
+
strict: Annotated[
|
| 546 |
+
bool | None,
|
| 547 |
+
Doc(
|
| 548 |
+
"""
|
| 549 |
+
If `True`, strict validation is applied to the field.
|
| 550 |
+
"""
|
| 551 |
+
),
|
| 552 |
+
] = _Unset,
|
| 553 |
+
multiple_of: Annotated[
|
| 554 |
+
float | None,
|
| 555 |
+
Doc(
|
| 556 |
+
"""
|
| 557 |
+
Value must be a multiple of this. Only applicable to numbers.
|
| 558 |
+
"""
|
| 559 |
+
),
|
| 560 |
+
] = _Unset,
|
| 561 |
+
allow_inf_nan: Annotated[
|
| 562 |
+
bool | None,
|
| 563 |
+
Doc(
|
| 564 |
+
"""
|
| 565 |
+
Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
|
| 566 |
+
"""
|
| 567 |
+
),
|
| 568 |
+
] = _Unset,
|
| 569 |
+
max_digits: Annotated[
|
| 570 |
+
int | None,
|
| 571 |
+
Doc(
|
| 572 |
+
"""
|
| 573 |
+
Maximum number of allow digits for strings.
|
| 574 |
+
"""
|
| 575 |
+
),
|
| 576 |
+
] = _Unset,
|
| 577 |
+
decimal_places: Annotated[
|
| 578 |
+
int | None,
|
| 579 |
+
Doc(
|
| 580 |
+
"""
|
| 581 |
+
Maximum number of decimal places allowed for numbers.
|
| 582 |
+
"""
|
| 583 |
+
),
|
| 584 |
+
] = _Unset,
|
| 585 |
+
examples: Annotated[
|
| 586 |
+
list[Any] | None,
|
| 587 |
+
Doc(
|
| 588 |
+
"""
|
| 589 |
+
Example values for this field.
|
| 590 |
+
|
| 591 |
+
Read more about it in the
|
| 592 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)
|
| 593 |
+
"""
|
| 594 |
+
),
|
| 595 |
+
] = None,
|
| 596 |
+
example: Annotated[
|
| 597 |
+
Any | None,
|
| 598 |
+
deprecated(
|
| 599 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 600 |
+
"although still supported. Use examples instead."
|
| 601 |
+
),
|
| 602 |
+
] = _Unset,
|
| 603 |
+
openapi_examples: Annotated[
|
| 604 |
+
dict[str, Example] | None,
|
| 605 |
+
Doc(
|
| 606 |
+
"""
|
| 607 |
+
OpenAPI-specific examples.
|
| 608 |
+
|
| 609 |
+
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
|
| 610 |
+
|
| 611 |
+
Swagger UI (that provides the `/docs` interface) has better support for the
|
| 612 |
+
OpenAPI-specific examples than the JSON Schema `examples`, that's the main
|
| 613 |
+
use case for this.
|
| 614 |
+
|
| 615 |
+
Read more about it in the
|
| 616 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
|
| 617 |
+
"""
|
| 618 |
+
),
|
| 619 |
+
] = None,
|
| 620 |
+
deprecated: Annotated[
|
| 621 |
+
deprecated | str | bool | None,
|
| 622 |
+
Doc(
|
| 623 |
+
"""
|
| 624 |
+
Mark this parameter field as deprecated.
|
| 625 |
+
|
| 626 |
+
It will affect the generated OpenAPI (e.g. visible at `/docs`).
|
| 627 |
+
|
| 628 |
+
Read more about it in the
|
| 629 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#deprecating-parameters)
|
| 630 |
+
"""
|
| 631 |
+
),
|
| 632 |
+
] = None,
|
| 633 |
+
include_in_schema: Annotated[
|
| 634 |
+
bool,
|
| 635 |
+
Doc(
|
| 636 |
+
"""
|
| 637 |
+
To include (or not) this parameter field in the generated OpenAPI.
|
| 638 |
+
You probably don't need it, but it's available.
|
| 639 |
+
|
| 640 |
+
This affects the generated OpenAPI (e.g. visible at `/docs`).
|
| 641 |
+
|
| 642 |
+
Read more about it in the
|
| 643 |
+
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#exclude-parameters-from-openapi
|
| 644 |
+
"""
|
| 645 |
+
),
|
| 646 |
+
] = True,
|
| 647 |
+
json_schema_extra: Annotated[
|
| 648 |
+
dict[str, Any] | None,
|
| 649 |
+
Doc(
|
| 650 |
+
"""
|
| 651 |
+
Any additional JSON schema data.
|
| 652 |
+
"""
|
| 653 |
+
),
|
| 654 |
+
] = None,
|
| 655 |
+
**extra: Annotated[
|
| 656 |
+
Any,
|
| 657 |
+
Doc(
|
| 658 |
+
"""
|
| 659 |
+
Include extra fields used by the JSON Schema.
|
| 660 |
+
"""
|
| 661 |
+
),
|
| 662 |
+
deprecated(
|
| 663 |
+
"""
|
| 664 |
+
The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
|
| 665 |
+
"""
|
| 666 |
+
),
|
| 667 |
+
],
|
| 668 |
+
) -> Any:
|
| 669 |
+
return params.Query(
|
| 670 |
+
default=default,
|
| 671 |
+
default_factory=default_factory,
|
| 672 |
+
alias=alias,
|
| 673 |
+
alias_priority=alias_priority,
|
| 674 |
+
validation_alias=validation_alias,
|
| 675 |
+
serialization_alias=serialization_alias,
|
| 676 |
+
title=title,
|
| 677 |
+
description=description,
|
| 678 |
+
gt=gt,
|
| 679 |
+
ge=ge,
|
| 680 |
+
lt=lt,
|
| 681 |
+
le=le,
|
| 682 |
+
min_length=min_length,
|
| 683 |
+
max_length=max_length,
|
| 684 |
+
pattern=pattern,
|
| 685 |
+
regex=regex,
|
| 686 |
+
discriminator=discriminator,
|
| 687 |
+
strict=strict,
|
| 688 |
+
multiple_of=multiple_of,
|
| 689 |
+
allow_inf_nan=allow_inf_nan,
|
| 690 |
+
max_digits=max_digits,
|
| 691 |
+
decimal_places=decimal_places,
|
| 692 |
+
example=example,
|
| 693 |
+
examples=examples,
|
| 694 |
+
openapi_examples=openapi_examples,
|
| 695 |
+
deprecated=deprecated,
|
| 696 |
+
include_in_schema=include_in_schema,
|
| 697 |
+
json_schema_extra=json_schema_extra,
|
| 698 |
+
**extra,
|
| 699 |
+
)
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
def Header( # noqa: N802
|
| 703 |
+
default: Annotated[
|
| 704 |
+
Any,
|
| 705 |
+
Doc(
|
| 706 |
+
"""
|
| 707 |
+
Default value if the parameter field is not set.
|
| 708 |
+
"""
|
| 709 |
+
),
|
| 710 |
+
] = Undefined,
|
| 711 |
+
*,
|
| 712 |
+
default_factory: Annotated[
|
| 713 |
+
Callable[[], Any] | None,
|
| 714 |
+
Doc(
|
| 715 |
+
"""
|
| 716 |
+
A callable to generate the default value.
|
| 717 |
+
|
| 718 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 719 |
+
The parameter is available only for compatibility.
|
| 720 |
+
"""
|
| 721 |
+
),
|
| 722 |
+
] = _Unset,
|
| 723 |
+
alias: Annotated[
|
| 724 |
+
str | None,
|
| 725 |
+
Doc(
|
| 726 |
+
"""
|
| 727 |
+
An alternative name for the parameter field.
|
| 728 |
+
|
| 729 |
+
This will be used to extract the data and for the generated OpenAPI.
|
| 730 |
+
It is particularly useful when you can't use the name you want because it
|
| 731 |
+
is a Python reserved keyword or similar.
|
| 732 |
+
"""
|
| 733 |
+
),
|
| 734 |
+
] = None,
|
| 735 |
+
alias_priority: Annotated[
|
| 736 |
+
int | None,
|
| 737 |
+
Doc(
|
| 738 |
+
"""
|
| 739 |
+
Priority of the alias. This affects whether an alias generator is used.
|
| 740 |
+
"""
|
| 741 |
+
),
|
| 742 |
+
] = _Unset,
|
| 743 |
+
validation_alias: Annotated[
|
| 744 |
+
str | AliasPath | AliasChoices | None,
|
| 745 |
+
Doc(
|
| 746 |
+
"""
|
| 747 |
+
'Whitelist' validation step. The parameter field will be the single one
|
| 748 |
+
allowed by the alias or set of aliases defined.
|
| 749 |
+
"""
|
| 750 |
+
),
|
| 751 |
+
] = None,
|
| 752 |
+
serialization_alias: Annotated[
|
| 753 |
+
str | None,
|
| 754 |
+
Doc(
|
| 755 |
+
"""
|
| 756 |
+
'Blacklist' validation step. The vanilla parameter field will be the
|
| 757 |
+
single one of the alias' or set of aliases' fields and all the other
|
| 758 |
+
fields will be ignored at serialization time.
|
| 759 |
+
"""
|
| 760 |
+
),
|
| 761 |
+
] = None,
|
| 762 |
+
convert_underscores: Annotated[
|
| 763 |
+
bool,
|
| 764 |
+
Doc(
|
| 765 |
+
"""
|
| 766 |
+
Automatically convert underscores to hyphens in the parameter field name.
|
| 767 |
+
|
| 768 |
+
Read more about it in the
|
| 769 |
+
[FastAPI docs for Header Parameters](https://fastapi.tiangolo.com/tutorial/header-params/#automatic-conversion)
|
| 770 |
+
"""
|
| 771 |
+
),
|
| 772 |
+
] = True,
|
| 773 |
+
title: Annotated[
|
| 774 |
+
str | None,
|
| 775 |
+
Doc(
|
| 776 |
+
"""
|
| 777 |
+
Human-readable title.
|
| 778 |
+
"""
|
| 779 |
+
),
|
| 780 |
+
] = None,
|
| 781 |
+
description: Annotated[
|
| 782 |
+
str | None,
|
| 783 |
+
Doc(
|
| 784 |
+
"""
|
| 785 |
+
Human-readable description.
|
| 786 |
+
"""
|
| 787 |
+
),
|
| 788 |
+
] = None,
|
| 789 |
+
gt: Annotated[
|
| 790 |
+
float | None,
|
| 791 |
+
Doc(
|
| 792 |
+
"""
|
| 793 |
+
Greater than. If set, value must be greater than this. Only applicable to
|
| 794 |
+
numbers.
|
| 795 |
+
"""
|
| 796 |
+
),
|
| 797 |
+
] = None,
|
| 798 |
+
ge: Annotated[
|
| 799 |
+
float | None,
|
| 800 |
+
Doc(
|
| 801 |
+
"""
|
| 802 |
+
Greater than or equal. If set, value must be greater than or equal to
|
| 803 |
+
this. Only applicable to numbers.
|
| 804 |
+
"""
|
| 805 |
+
),
|
| 806 |
+
] = None,
|
| 807 |
+
lt: Annotated[
|
| 808 |
+
float | None,
|
| 809 |
+
Doc(
|
| 810 |
+
"""
|
| 811 |
+
Less than. If set, value must be less than this. Only applicable to numbers.
|
| 812 |
+
"""
|
| 813 |
+
),
|
| 814 |
+
] = None,
|
| 815 |
+
le: Annotated[
|
| 816 |
+
float | None,
|
| 817 |
+
Doc(
|
| 818 |
+
"""
|
| 819 |
+
Less than or equal. If set, value must be less than or equal to this.
|
| 820 |
+
Only applicable to numbers.
|
| 821 |
+
"""
|
| 822 |
+
),
|
| 823 |
+
] = None,
|
| 824 |
+
min_length: Annotated[
|
| 825 |
+
int | None,
|
| 826 |
+
Doc(
|
| 827 |
+
"""
|
| 828 |
+
Minimum length for strings.
|
| 829 |
+
"""
|
| 830 |
+
),
|
| 831 |
+
] = None,
|
| 832 |
+
max_length: Annotated[
|
| 833 |
+
int | None,
|
| 834 |
+
Doc(
|
| 835 |
+
"""
|
| 836 |
+
Maximum length for strings.
|
| 837 |
+
"""
|
| 838 |
+
),
|
| 839 |
+
] = None,
|
| 840 |
+
pattern: Annotated[
|
| 841 |
+
str | None,
|
| 842 |
+
Doc(
|
| 843 |
+
"""
|
| 844 |
+
RegEx pattern for strings.
|
| 845 |
+
"""
|
| 846 |
+
),
|
| 847 |
+
] = None,
|
| 848 |
+
regex: Annotated[
|
| 849 |
+
str | None,
|
| 850 |
+
Doc(
|
| 851 |
+
"""
|
| 852 |
+
RegEx pattern for strings.
|
| 853 |
+
"""
|
| 854 |
+
),
|
| 855 |
+
deprecated(
|
| 856 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 857 |
+
),
|
| 858 |
+
] = None,
|
| 859 |
+
discriminator: Annotated[
|
| 860 |
+
str | None,
|
| 861 |
+
Doc(
|
| 862 |
+
"""
|
| 863 |
+
Parameter field name for discriminating the type in a tagged union.
|
| 864 |
+
"""
|
| 865 |
+
),
|
| 866 |
+
] = None,
|
| 867 |
+
strict: Annotated[
|
| 868 |
+
bool | None,
|
| 869 |
+
Doc(
|
| 870 |
+
"""
|
| 871 |
+
If `True`, strict validation is applied to the field.
|
| 872 |
+
"""
|
| 873 |
+
),
|
| 874 |
+
] = _Unset,
|
| 875 |
+
multiple_of: Annotated[
|
| 876 |
+
float | None,
|
| 877 |
+
Doc(
|
| 878 |
+
"""
|
| 879 |
+
Value must be a multiple of this. Only applicable to numbers.
|
| 880 |
+
"""
|
| 881 |
+
),
|
| 882 |
+
] = _Unset,
|
| 883 |
+
allow_inf_nan: Annotated[
|
| 884 |
+
bool | None,
|
| 885 |
+
Doc(
|
| 886 |
+
"""
|
| 887 |
+
Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
|
| 888 |
+
"""
|
| 889 |
+
),
|
| 890 |
+
] = _Unset,
|
| 891 |
+
max_digits: Annotated[
|
| 892 |
+
int | None,
|
| 893 |
+
Doc(
|
| 894 |
+
"""
|
| 895 |
+
Maximum number of allow digits for strings.
|
| 896 |
+
"""
|
| 897 |
+
),
|
| 898 |
+
] = _Unset,
|
| 899 |
+
decimal_places: Annotated[
|
| 900 |
+
int | None,
|
| 901 |
+
Doc(
|
| 902 |
+
"""
|
| 903 |
+
Maximum number of decimal places allowed for numbers.
|
| 904 |
+
"""
|
| 905 |
+
),
|
| 906 |
+
] = _Unset,
|
| 907 |
+
examples: Annotated[
|
| 908 |
+
list[Any] | None,
|
| 909 |
+
Doc(
|
| 910 |
+
"""
|
| 911 |
+
Example values for this field.
|
| 912 |
+
|
| 913 |
+
Read more about it in the
|
| 914 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)
|
| 915 |
+
"""
|
| 916 |
+
),
|
| 917 |
+
] = None,
|
| 918 |
+
example: Annotated[
|
| 919 |
+
Any | None,
|
| 920 |
+
deprecated(
|
| 921 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 922 |
+
"although still supported. Use examples instead."
|
| 923 |
+
),
|
| 924 |
+
] = _Unset,
|
| 925 |
+
openapi_examples: Annotated[
|
| 926 |
+
dict[str, Example] | None,
|
| 927 |
+
Doc(
|
| 928 |
+
"""
|
| 929 |
+
OpenAPI-specific examples.
|
| 930 |
+
|
| 931 |
+
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
|
| 932 |
+
|
| 933 |
+
Swagger UI (that provides the `/docs` interface) has better support for the
|
| 934 |
+
OpenAPI-specific examples than the JSON Schema `examples`, that's the main
|
| 935 |
+
use case for this.
|
| 936 |
+
|
| 937 |
+
Read more about it in the
|
| 938 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
|
| 939 |
+
"""
|
| 940 |
+
),
|
| 941 |
+
] = None,
|
| 942 |
+
deprecated: Annotated[
|
| 943 |
+
deprecated | str | bool | None,
|
| 944 |
+
Doc(
|
| 945 |
+
"""
|
| 946 |
+
Mark this parameter field as deprecated.
|
| 947 |
+
|
| 948 |
+
It will affect the generated OpenAPI (e.g. visible at `/docs`).
|
| 949 |
+
"""
|
| 950 |
+
),
|
| 951 |
+
] = None,
|
| 952 |
+
include_in_schema: Annotated[
|
| 953 |
+
bool,
|
| 954 |
+
Doc(
|
| 955 |
+
"""
|
| 956 |
+
To include (or not) this parameter field in the generated OpenAPI.
|
| 957 |
+
You probably don't need it, but it's available.
|
| 958 |
+
|
| 959 |
+
This affects the generated OpenAPI (e.g. visible at `/docs`).
|
| 960 |
+
"""
|
| 961 |
+
),
|
| 962 |
+
] = True,
|
| 963 |
+
json_schema_extra: Annotated[
|
| 964 |
+
dict[str, Any] | None,
|
| 965 |
+
Doc(
|
| 966 |
+
"""
|
| 967 |
+
Any additional JSON schema data.
|
| 968 |
+
"""
|
| 969 |
+
),
|
| 970 |
+
] = None,
|
| 971 |
+
**extra: Annotated[
|
| 972 |
+
Any,
|
| 973 |
+
Doc(
|
| 974 |
+
"""
|
| 975 |
+
Include extra fields used by the JSON Schema.
|
| 976 |
+
"""
|
| 977 |
+
),
|
| 978 |
+
deprecated(
|
| 979 |
+
"""
|
| 980 |
+
The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
|
| 981 |
+
"""
|
| 982 |
+
),
|
| 983 |
+
],
|
| 984 |
+
) -> Any:
|
| 985 |
+
return params.Header(
|
| 986 |
+
default=default,
|
| 987 |
+
default_factory=default_factory,
|
| 988 |
+
alias=alias,
|
| 989 |
+
alias_priority=alias_priority,
|
| 990 |
+
validation_alias=validation_alias,
|
| 991 |
+
serialization_alias=serialization_alias,
|
| 992 |
+
convert_underscores=convert_underscores,
|
| 993 |
+
title=title,
|
| 994 |
+
description=description,
|
| 995 |
+
gt=gt,
|
| 996 |
+
ge=ge,
|
| 997 |
+
lt=lt,
|
| 998 |
+
le=le,
|
| 999 |
+
min_length=min_length,
|
| 1000 |
+
max_length=max_length,
|
| 1001 |
+
pattern=pattern,
|
| 1002 |
+
regex=regex,
|
| 1003 |
+
discriminator=discriminator,
|
| 1004 |
+
strict=strict,
|
| 1005 |
+
multiple_of=multiple_of,
|
| 1006 |
+
allow_inf_nan=allow_inf_nan,
|
| 1007 |
+
max_digits=max_digits,
|
| 1008 |
+
decimal_places=decimal_places,
|
| 1009 |
+
example=example,
|
| 1010 |
+
examples=examples,
|
| 1011 |
+
openapi_examples=openapi_examples,
|
| 1012 |
+
deprecated=deprecated,
|
| 1013 |
+
include_in_schema=include_in_schema,
|
| 1014 |
+
json_schema_extra=json_schema_extra,
|
| 1015 |
+
**extra,
|
| 1016 |
+
)
|
| 1017 |
+
|
| 1018 |
+
|
| 1019 |
+
def Cookie( # noqa: N802
|
| 1020 |
+
default: Annotated[
|
| 1021 |
+
Any,
|
| 1022 |
+
Doc(
|
| 1023 |
+
"""
|
| 1024 |
+
Default value if the parameter field is not set.
|
| 1025 |
+
"""
|
| 1026 |
+
),
|
| 1027 |
+
] = Undefined,
|
| 1028 |
+
*,
|
| 1029 |
+
default_factory: Annotated[
|
| 1030 |
+
Callable[[], Any] | None,
|
| 1031 |
+
Doc(
|
| 1032 |
+
"""
|
| 1033 |
+
A callable to generate the default value.
|
| 1034 |
+
|
| 1035 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 1036 |
+
The parameter is available only for compatibility.
|
| 1037 |
+
"""
|
| 1038 |
+
),
|
| 1039 |
+
] = _Unset,
|
| 1040 |
+
alias: Annotated[
|
| 1041 |
+
str | None,
|
| 1042 |
+
Doc(
|
| 1043 |
+
"""
|
| 1044 |
+
An alternative name for the parameter field.
|
| 1045 |
+
|
| 1046 |
+
This will be used to extract the data and for the generated OpenAPI.
|
| 1047 |
+
It is particularly useful when you can't use the name you want because it
|
| 1048 |
+
is a Python reserved keyword or similar.
|
| 1049 |
+
"""
|
| 1050 |
+
),
|
| 1051 |
+
] = None,
|
| 1052 |
+
alias_priority: Annotated[
|
| 1053 |
+
int | None,
|
| 1054 |
+
Doc(
|
| 1055 |
+
"""
|
| 1056 |
+
Priority of the alias. This affects whether an alias generator is used.
|
| 1057 |
+
"""
|
| 1058 |
+
),
|
| 1059 |
+
] = _Unset,
|
| 1060 |
+
validation_alias: Annotated[
|
| 1061 |
+
str | AliasPath | AliasChoices | None,
|
| 1062 |
+
Doc(
|
| 1063 |
+
"""
|
| 1064 |
+
'Whitelist' validation step. The parameter field will be the single one
|
| 1065 |
+
allowed by the alias or set of aliases defined.
|
| 1066 |
+
"""
|
| 1067 |
+
),
|
| 1068 |
+
] = None,
|
| 1069 |
+
serialization_alias: Annotated[
|
| 1070 |
+
str | None,
|
| 1071 |
+
Doc(
|
| 1072 |
+
"""
|
| 1073 |
+
'Blacklist' validation step. The vanilla parameter field will be the
|
| 1074 |
+
single one of the alias' or set of aliases' fields and all the other
|
| 1075 |
+
fields will be ignored at serialization time.
|
| 1076 |
+
"""
|
| 1077 |
+
),
|
| 1078 |
+
] = None,
|
| 1079 |
+
title: Annotated[
|
| 1080 |
+
str | None,
|
| 1081 |
+
Doc(
|
| 1082 |
+
"""
|
| 1083 |
+
Human-readable title.
|
| 1084 |
+
"""
|
| 1085 |
+
),
|
| 1086 |
+
] = None,
|
| 1087 |
+
description: Annotated[
|
| 1088 |
+
str | None,
|
| 1089 |
+
Doc(
|
| 1090 |
+
"""
|
| 1091 |
+
Human-readable description.
|
| 1092 |
+
"""
|
| 1093 |
+
),
|
| 1094 |
+
] = None,
|
| 1095 |
+
gt: Annotated[
|
| 1096 |
+
float | None,
|
| 1097 |
+
Doc(
|
| 1098 |
+
"""
|
| 1099 |
+
Greater than. If set, value must be greater than this. Only applicable to
|
| 1100 |
+
numbers.
|
| 1101 |
+
"""
|
| 1102 |
+
),
|
| 1103 |
+
] = None,
|
| 1104 |
+
ge: Annotated[
|
| 1105 |
+
float | None,
|
| 1106 |
+
Doc(
|
| 1107 |
+
"""
|
| 1108 |
+
Greater than or equal. If set, value must be greater than or equal to
|
| 1109 |
+
this. Only applicable to numbers.
|
| 1110 |
+
"""
|
| 1111 |
+
),
|
| 1112 |
+
] = None,
|
| 1113 |
+
lt: Annotated[
|
| 1114 |
+
float | None,
|
| 1115 |
+
Doc(
|
| 1116 |
+
"""
|
| 1117 |
+
Less than. If set, value must be less than this. Only applicable to numbers.
|
| 1118 |
+
"""
|
| 1119 |
+
),
|
| 1120 |
+
] = None,
|
| 1121 |
+
le: Annotated[
|
| 1122 |
+
float | None,
|
| 1123 |
+
Doc(
|
| 1124 |
+
"""
|
| 1125 |
+
Less than or equal. If set, value must be less than or equal to this.
|
| 1126 |
+
Only applicable to numbers.
|
| 1127 |
+
"""
|
| 1128 |
+
),
|
| 1129 |
+
] = None,
|
| 1130 |
+
min_length: Annotated[
|
| 1131 |
+
int | None,
|
| 1132 |
+
Doc(
|
| 1133 |
+
"""
|
| 1134 |
+
Minimum length for strings.
|
| 1135 |
+
"""
|
| 1136 |
+
),
|
| 1137 |
+
] = None,
|
| 1138 |
+
max_length: Annotated[
|
| 1139 |
+
int | None,
|
| 1140 |
+
Doc(
|
| 1141 |
+
"""
|
| 1142 |
+
Maximum length for strings.
|
| 1143 |
+
"""
|
| 1144 |
+
),
|
| 1145 |
+
] = None,
|
| 1146 |
+
pattern: Annotated[
|
| 1147 |
+
str | None,
|
| 1148 |
+
Doc(
|
| 1149 |
+
"""
|
| 1150 |
+
RegEx pattern for strings.
|
| 1151 |
+
"""
|
| 1152 |
+
),
|
| 1153 |
+
] = None,
|
| 1154 |
+
regex: Annotated[
|
| 1155 |
+
str | None,
|
| 1156 |
+
Doc(
|
| 1157 |
+
"""
|
| 1158 |
+
RegEx pattern for strings.
|
| 1159 |
+
"""
|
| 1160 |
+
),
|
| 1161 |
+
deprecated(
|
| 1162 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 1163 |
+
),
|
| 1164 |
+
] = None,
|
| 1165 |
+
discriminator: Annotated[
|
| 1166 |
+
str | None,
|
| 1167 |
+
Doc(
|
| 1168 |
+
"""
|
| 1169 |
+
Parameter field name for discriminating the type in a tagged union.
|
| 1170 |
+
"""
|
| 1171 |
+
),
|
| 1172 |
+
] = None,
|
| 1173 |
+
strict: Annotated[
|
| 1174 |
+
bool | None,
|
| 1175 |
+
Doc(
|
| 1176 |
+
"""
|
| 1177 |
+
If `True`, strict validation is applied to the field.
|
| 1178 |
+
"""
|
| 1179 |
+
),
|
| 1180 |
+
] = _Unset,
|
| 1181 |
+
multiple_of: Annotated[
|
| 1182 |
+
float | None,
|
| 1183 |
+
Doc(
|
| 1184 |
+
"""
|
| 1185 |
+
Value must be a multiple of this. Only applicable to numbers.
|
| 1186 |
+
"""
|
| 1187 |
+
),
|
| 1188 |
+
] = _Unset,
|
| 1189 |
+
allow_inf_nan: Annotated[
|
| 1190 |
+
bool | None,
|
| 1191 |
+
Doc(
|
| 1192 |
+
"""
|
| 1193 |
+
Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
|
| 1194 |
+
"""
|
| 1195 |
+
),
|
| 1196 |
+
] = _Unset,
|
| 1197 |
+
max_digits: Annotated[
|
| 1198 |
+
int | None,
|
| 1199 |
+
Doc(
|
| 1200 |
+
"""
|
| 1201 |
+
Maximum number of allow digits for strings.
|
| 1202 |
+
"""
|
| 1203 |
+
),
|
| 1204 |
+
] = _Unset,
|
| 1205 |
+
decimal_places: Annotated[
|
| 1206 |
+
int | None,
|
| 1207 |
+
Doc(
|
| 1208 |
+
"""
|
| 1209 |
+
Maximum number of decimal places allowed for numbers.
|
| 1210 |
+
"""
|
| 1211 |
+
),
|
| 1212 |
+
] = _Unset,
|
| 1213 |
+
examples: Annotated[
|
| 1214 |
+
list[Any] | None,
|
| 1215 |
+
Doc(
|
| 1216 |
+
"""
|
| 1217 |
+
Example values for this field.
|
| 1218 |
+
|
| 1219 |
+
Read more about it in the
|
| 1220 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)
|
| 1221 |
+
"""
|
| 1222 |
+
),
|
| 1223 |
+
] = None,
|
| 1224 |
+
example: Annotated[
|
| 1225 |
+
Any | None,
|
| 1226 |
+
deprecated(
|
| 1227 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 1228 |
+
"although still supported. Use examples instead."
|
| 1229 |
+
),
|
| 1230 |
+
] = _Unset,
|
| 1231 |
+
openapi_examples: Annotated[
|
| 1232 |
+
dict[str, Example] | None,
|
| 1233 |
+
Doc(
|
| 1234 |
+
"""
|
| 1235 |
+
OpenAPI-specific examples.
|
| 1236 |
+
|
| 1237 |
+
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
|
| 1238 |
+
|
| 1239 |
+
Swagger UI (that provides the `/docs` interface) has better support for the
|
| 1240 |
+
OpenAPI-specific examples than the JSON Schema `examples`, that's the main
|
| 1241 |
+
use case for this.
|
| 1242 |
+
|
| 1243 |
+
Read more about it in the
|
| 1244 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
|
| 1245 |
+
"""
|
| 1246 |
+
),
|
| 1247 |
+
] = None,
|
| 1248 |
+
deprecated: Annotated[
|
| 1249 |
+
deprecated | str | bool | None,
|
| 1250 |
+
Doc(
|
| 1251 |
+
"""
|
| 1252 |
+
Mark this parameter field as deprecated.
|
| 1253 |
+
|
| 1254 |
+
It will affect the generated OpenAPI (e.g. visible at `/docs`).
|
| 1255 |
+
"""
|
| 1256 |
+
),
|
| 1257 |
+
] = None,
|
| 1258 |
+
include_in_schema: Annotated[
|
| 1259 |
+
bool,
|
| 1260 |
+
Doc(
|
| 1261 |
+
"""
|
| 1262 |
+
To include (or not) this parameter field in the generated OpenAPI.
|
| 1263 |
+
You probably don't need it, but it's available.
|
| 1264 |
+
|
| 1265 |
+
This affects the generated OpenAPI (e.g. visible at `/docs`).
|
| 1266 |
+
"""
|
| 1267 |
+
),
|
| 1268 |
+
] = True,
|
| 1269 |
+
json_schema_extra: Annotated[
|
| 1270 |
+
dict[str, Any] | None,
|
| 1271 |
+
Doc(
|
| 1272 |
+
"""
|
| 1273 |
+
Any additional JSON schema data.
|
| 1274 |
+
"""
|
| 1275 |
+
),
|
| 1276 |
+
] = None,
|
| 1277 |
+
**extra: Annotated[
|
| 1278 |
+
Any,
|
| 1279 |
+
Doc(
|
| 1280 |
+
"""
|
| 1281 |
+
Include extra fields used by the JSON Schema.
|
| 1282 |
+
"""
|
| 1283 |
+
),
|
| 1284 |
+
deprecated(
|
| 1285 |
+
"""
|
| 1286 |
+
The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
|
| 1287 |
+
"""
|
| 1288 |
+
),
|
| 1289 |
+
],
|
| 1290 |
+
) -> Any:
|
| 1291 |
+
return params.Cookie(
|
| 1292 |
+
default=default,
|
| 1293 |
+
default_factory=default_factory,
|
| 1294 |
+
alias=alias,
|
| 1295 |
+
alias_priority=alias_priority,
|
| 1296 |
+
validation_alias=validation_alias,
|
| 1297 |
+
serialization_alias=serialization_alias,
|
| 1298 |
+
title=title,
|
| 1299 |
+
description=description,
|
| 1300 |
+
gt=gt,
|
| 1301 |
+
ge=ge,
|
| 1302 |
+
lt=lt,
|
| 1303 |
+
le=le,
|
| 1304 |
+
min_length=min_length,
|
| 1305 |
+
max_length=max_length,
|
| 1306 |
+
pattern=pattern,
|
| 1307 |
+
regex=regex,
|
| 1308 |
+
discriminator=discriminator,
|
| 1309 |
+
strict=strict,
|
| 1310 |
+
multiple_of=multiple_of,
|
| 1311 |
+
allow_inf_nan=allow_inf_nan,
|
| 1312 |
+
max_digits=max_digits,
|
| 1313 |
+
decimal_places=decimal_places,
|
| 1314 |
+
example=example,
|
| 1315 |
+
examples=examples,
|
| 1316 |
+
openapi_examples=openapi_examples,
|
| 1317 |
+
deprecated=deprecated,
|
| 1318 |
+
include_in_schema=include_in_schema,
|
| 1319 |
+
json_schema_extra=json_schema_extra,
|
| 1320 |
+
**extra,
|
| 1321 |
+
)
|
| 1322 |
+
|
| 1323 |
+
|
| 1324 |
+
def Body( # noqa: N802
|
| 1325 |
+
default: Annotated[
|
| 1326 |
+
Any,
|
| 1327 |
+
Doc(
|
| 1328 |
+
"""
|
| 1329 |
+
Default value if the parameter field is not set.
|
| 1330 |
+
"""
|
| 1331 |
+
),
|
| 1332 |
+
] = Undefined,
|
| 1333 |
+
*,
|
| 1334 |
+
default_factory: Annotated[
|
| 1335 |
+
Callable[[], Any] | None,
|
| 1336 |
+
Doc(
|
| 1337 |
+
"""
|
| 1338 |
+
A callable to generate the default value.
|
| 1339 |
+
|
| 1340 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 1341 |
+
The parameter is available only for compatibility.
|
| 1342 |
+
"""
|
| 1343 |
+
),
|
| 1344 |
+
] = _Unset,
|
| 1345 |
+
embed: Annotated[
|
| 1346 |
+
bool | None,
|
| 1347 |
+
Doc(
|
| 1348 |
+
"""
|
| 1349 |
+
When `embed` is `True`, the parameter will be expected in a JSON body as a
|
| 1350 |
+
key instead of being the JSON body itself.
|
| 1351 |
+
|
| 1352 |
+
This happens automatically when more than one `Body` parameter is declared.
|
| 1353 |
+
|
| 1354 |
+
Read more about it in the
|
| 1355 |
+
[FastAPI docs for Body - Multiple Parameters](https://fastapi.tiangolo.com/tutorial/body-multiple-params/#embed-a-single-body-parameter).
|
| 1356 |
+
"""
|
| 1357 |
+
),
|
| 1358 |
+
] = None,
|
| 1359 |
+
media_type: Annotated[
|
| 1360 |
+
str,
|
| 1361 |
+
Doc(
|
| 1362 |
+
"""
|
| 1363 |
+
The media type of this parameter field. Changing it would affect the
|
| 1364 |
+
generated OpenAPI, but currently it doesn't affect the parsing of the data.
|
| 1365 |
+
"""
|
| 1366 |
+
),
|
| 1367 |
+
] = "application/json",
|
| 1368 |
+
alias: Annotated[
|
| 1369 |
+
str | None,
|
| 1370 |
+
Doc(
|
| 1371 |
+
"""
|
| 1372 |
+
An alternative name for the parameter field.
|
| 1373 |
+
|
| 1374 |
+
This will be used to extract the data and for the generated OpenAPI.
|
| 1375 |
+
It is particularly useful when you can't use the name you want because it
|
| 1376 |
+
is a Python reserved keyword or similar.
|
| 1377 |
+
"""
|
| 1378 |
+
),
|
| 1379 |
+
] = None,
|
| 1380 |
+
alias_priority: Annotated[
|
| 1381 |
+
int | None,
|
| 1382 |
+
Doc(
|
| 1383 |
+
"""
|
| 1384 |
+
Priority of the alias. This affects whether an alias generator is used.
|
| 1385 |
+
"""
|
| 1386 |
+
),
|
| 1387 |
+
] = _Unset,
|
| 1388 |
+
validation_alias: Annotated[
|
| 1389 |
+
str | AliasPath | AliasChoices | None,
|
| 1390 |
+
Doc(
|
| 1391 |
+
"""
|
| 1392 |
+
'Whitelist' validation step. The parameter field will be the single one
|
| 1393 |
+
allowed by the alias or set of aliases defined.
|
| 1394 |
+
"""
|
| 1395 |
+
),
|
| 1396 |
+
] = None,
|
| 1397 |
+
serialization_alias: Annotated[
|
| 1398 |
+
str | None,
|
| 1399 |
+
Doc(
|
| 1400 |
+
"""
|
| 1401 |
+
'Blacklist' validation step. The vanilla parameter field will be the
|
| 1402 |
+
single one of the alias' or set of aliases' fields and all the other
|
| 1403 |
+
fields will be ignored at serialization time.
|
| 1404 |
+
"""
|
| 1405 |
+
),
|
| 1406 |
+
] = None,
|
| 1407 |
+
title: Annotated[
|
| 1408 |
+
str | None,
|
| 1409 |
+
Doc(
|
| 1410 |
+
"""
|
| 1411 |
+
Human-readable title.
|
| 1412 |
+
"""
|
| 1413 |
+
),
|
| 1414 |
+
] = None,
|
| 1415 |
+
description: Annotated[
|
| 1416 |
+
str | None,
|
| 1417 |
+
Doc(
|
| 1418 |
+
"""
|
| 1419 |
+
Human-readable description.
|
| 1420 |
+
"""
|
| 1421 |
+
),
|
| 1422 |
+
] = None,
|
| 1423 |
+
gt: Annotated[
|
| 1424 |
+
float | None,
|
| 1425 |
+
Doc(
|
| 1426 |
+
"""
|
| 1427 |
+
Greater than. If set, value must be greater than this. Only applicable to
|
| 1428 |
+
numbers.
|
| 1429 |
+
"""
|
| 1430 |
+
),
|
| 1431 |
+
] = None,
|
| 1432 |
+
ge: Annotated[
|
| 1433 |
+
float | None,
|
| 1434 |
+
Doc(
|
| 1435 |
+
"""
|
| 1436 |
+
Greater than or equal. If set, value must be greater than or equal to
|
| 1437 |
+
this. Only applicable to numbers.
|
| 1438 |
+
"""
|
| 1439 |
+
),
|
| 1440 |
+
] = None,
|
| 1441 |
+
lt: Annotated[
|
| 1442 |
+
float | None,
|
| 1443 |
+
Doc(
|
| 1444 |
+
"""
|
| 1445 |
+
Less than. If set, value must be less than this. Only applicable to numbers.
|
| 1446 |
+
"""
|
| 1447 |
+
),
|
| 1448 |
+
] = None,
|
| 1449 |
+
le: Annotated[
|
| 1450 |
+
float | None,
|
| 1451 |
+
Doc(
|
| 1452 |
+
"""
|
| 1453 |
+
Less than or equal. If set, value must be less than or equal to this.
|
| 1454 |
+
Only applicable to numbers.
|
| 1455 |
+
"""
|
| 1456 |
+
),
|
| 1457 |
+
] = None,
|
| 1458 |
+
min_length: Annotated[
|
| 1459 |
+
int | None,
|
| 1460 |
+
Doc(
|
| 1461 |
+
"""
|
| 1462 |
+
Minimum length for strings.
|
| 1463 |
+
"""
|
| 1464 |
+
),
|
| 1465 |
+
] = None,
|
| 1466 |
+
max_length: Annotated[
|
| 1467 |
+
int | None,
|
| 1468 |
+
Doc(
|
| 1469 |
+
"""
|
| 1470 |
+
Maximum length for strings.
|
| 1471 |
+
"""
|
| 1472 |
+
),
|
| 1473 |
+
] = None,
|
| 1474 |
+
pattern: Annotated[
|
| 1475 |
+
str | None,
|
| 1476 |
+
Doc(
|
| 1477 |
+
"""
|
| 1478 |
+
RegEx pattern for strings.
|
| 1479 |
+
"""
|
| 1480 |
+
),
|
| 1481 |
+
] = None,
|
| 1482 |
+
regex: Annotated[
|
| 1483 |
+
str | None,
|
| 1484 |
+
Doc(
|
| 1485 |
+
"""
|
| 1486 |
+
RegEx pattern for strings.
|
| 1487 |
+
"""
|
| 1488 |
+
),
|
| 1489 |
+
deprecated(
|
| 1490 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 1491 |
+
),
|
| 1492 |
+
] = None,
|
| 1493 |
+
discriminator: Annotated[
|
| 1494 |
+
str | None,
|
| 1495 |
+
Doc(
|
| 1496 |
+
"""
|
| 1497 |
+
Parameter field name for discriminating the type in a tagged union.
|
| 1498 |
+
"""
|
| 1499 |
+
),
|
| 1500 |
+
] = None,
|
| 1501 |
+
strict: Annotated[
|
| 1502 |
+
bool | None,
|
| 1503 |
+
Doc(
|
| 1504 |
+
"""
|
| 1505 |
+
If `True`, strict validation is applied to the field.
|
| 1506 |
+
"""
|
| 1507 |
+
),
|
| 1508 |
+
] = _Unset,
|
| 1509 |
+
multiple_of: Annotated[
|
| 1510 |
+
float | None,
|
| 1511 |
+
Doc(
|
| 1512 |
+
"""
|
| 1513 |
+
Value must be a multiple of this. Only applicable to numbers.
|
| 1514 |
+
"""
|
| 1515 |
+
),
|
| 1516 |
+
] = _Unset,
|
| 1517 |
+
allow_inf_nan: Annotated[
|
| 1518 |
+
bool | None,
|
| 1519 |
+
Doc(
|
| 1520 |
+
"""
|
| 1521 |
+
Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
|
| 1522 |
+
"""
|
| 1523 |
+
),
|
| 1524 |
+
] = _Unset,
|
| 1525 |
+
max_digits: Annotated[
|
| 1526 |
+
int | None,
|
| 1527 |
+
Doc(
|
| 1528 |
+
"""
|
| 1529 |
+
Maximum number of allow digits for strings.
|
| 1530 |
+
"""
|
| 1531 |
+
),
|
| 1532 |
+
] = _Unset,
|
| 1533 |
+
decimal_places: Annotated[
|
| 1534 |
+
int | None,
|
| 1535 |
+
Doc(
|
| 1536 |
+
"""
|
| 1537 |
+
Maximum number of decimal places allowed for numbers.
|
| 1538 |
+
"""
|
| 1539 |
+
),
|
| 1540 |
+
] = _Unset,
|
| 1541 |
+
examples: Annotated[
|
| 1542 |
+
list[Any] | None,
|
| 1543 |
+
Doc(
|
| 1544 |
+
"""
|
| 1545 |
+
Example values for this field.
|
| 1546 |
+
|
| 1547 |
+
Read more about it in the
|
| 1548 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)
|
| 1549 |
+
"""
|
| 1550 |
+
),
|
| 1551 |
+
] = None,
|
| 1552 |
+
example: Annotated[
|
| 1553 |
+
Any | None,
|
| 1554 |
+
deprecated(
|
| 1555 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 1556 |
+
"although still supported. Use examples instead."
|
| 1557 |
+
),
|
| 1558 |
+
] = _Unset,
|
| 1559 |
+
openapi_examples: Annotated[
|
| 1560 |
+
dict[str, Example] | None,
|
| 1561 |
+
Doc(
|
| 1562 |
+
"""
|
| 1563 |
+
OpenAPI-specific examples.
|
| 1564 |
+
|
| 1565 |
+
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
|
| 1566 |
+
|
| 1567 |
+
Swagger UI (that provides the `/docs` interface) has better support for the
|
| 1568 |
+
OpenAPI-specific examples than the JSON Schema `examples`, that's the main
|
| 1569 |
+
use case for this.
|
| 1570 |
+
|
| 1571 |
+
Read more about it in the
|
| 1572 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
|
| 1573 |
+
"""
|
| 1574 |
+
),
|
| 1575 |
+
] = None,
|
| 1576 |
+
deprecated: Annotated[
|
| 1577 |
+
deprecated | str | bool | None,
|
| 1578 |
+
Doc(
|
| 1579 |
+
"""
|
| 1580 |
+
Mark this parameter field as deprecated.
|
| 1581 |
+
|
| 1582 |
+
It will affect the generated OpenAPI (e.g. visible at `/docs`).
|
| 1583 |
+
"""
|
| 1584 |
+
),
|
| 1585 |
+
] = None,
|
| 1586 |
+
include_in_schema: Annotated[
|
| 1587 |
+
bool,
|
| 1588 |
+
Doc(
|
| 1589 |
+
"""
|
| 1590 |
+
To include (or not) this parameter field in the generated OpenAPI.
|
| 1591 |
+
You probably don't need it, but it's available.
|
| 1592 |
+
|
| 1593 |
+
This affects the generated OpenAPI (e.g. visible at `/docs`).
|
| 1594 |
+
"""
|
| 1595 |
+
),
|
| 1596 |
+
] = True,
|
| 1597 |
+
json_schema_extra: Annotated[
|
| 1598 |
+
dict[str, Any] | None,
|
| 1599 |
+
Doc(
|
| 1600 |
+
"""
|
| 1601 |
+
Any additional JSON schema data.
|
| 1602 |
+
"""
|
| 1603 |
+
),
|
| 1604 |
+
] = None,
|
| 1605 |
+
**extra: Annotated[
|
| 1606 |
+
Any,
|
| 1607 |
+
Doc(
|
| 1608 |
+
"""
|
| 1609 |
+
Include extra fields used by the JSON Schema.
|
| 1610 |
+
"""
|
| 1611 |
+
),
|
| 1612 |
+
deprecated(
|
| 1613 |
+
"""
|
| 1614 |
+
The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
|
| 1615 |
+
"""
|
| 1616 |
+
),
|
| 1617 |
+
],
|
| 1618 |
+
) -> Any:
|
| 1619 |
+
return params.Body(
|
| 1620 |
+
default=default,
|
| 1621 |
+
default_factory=default_factory,
|
| 1622 |
+
embed=embed,
|
| 1623 |
+
media_type=media_type,
|
| 1624 |
+
alias=alias,
|
| 1625 |
+
alias_priority=alias_priority,
|
| 1626 |
+
validation_alias=validation_alias,
|
| 1627 |
+
serialization_alias=serialization_alias,
|
| 1628 |
+
title=title,
|
| 1629 |
+
description=description,
|
| 1630 |
+
gt=gt,
|
| 1631 |
+
ge=ge,
|
| 1632 |
+
lt=lt,
|
| 1633 |
+
le=le,
|
| 1634 |
+
min_length=min_length,
|
| 1635 |
+
max_length=max_length,
|
| 1636 |
+
pattern=pattern,
|
| 1637 |
+
regex=regex,
|
| 1638 |
+
discriminator=discriminator,
|
| 1639 |
+
strict=strict,
|
| 1640 |
+
multiple_of=multiple_of,
|
| 1641 |
+
allow_inf_nan=allow_inf_nan,
|
| 1642 |
+
max_digits=max_digits,
|
| 1643 |
+
decimal_places=decimal_places,
|
| 1644 |
+
example=example,
|
| 1645 |
+
examples=examples,
|
| 1646 |
+
openapi_examples=openapi_examples,
|
| 1647 |
+
deprecated=deprecated,
|
| 1648 |
+
include_in_schema=include_in_schema,
|
| 1649 |
+
json_schema_extra=json_schema_extra,
|
| 1650 |
+
**extra,
|
| 1651 |
+
)
|
| 1652 |
+
|
| 1653 |
+
|
| 1654 |
+
def Form( # noqa: N802
|
| 1655 |
+
default: Annotated[
|
| 1656 |
+
Any,
|
| 1657 |
+
Doc(
|
| 1658 |
+
"""
|
| 1659 |
+
Default value if the parameter field is not set.
|
| 1660 |
+
"""
|
| 1661 |
+
),
|
| 1662 |
+
] = Undefined,
|
| 1663 |
+
*,
|
| 1664 |
+
default_factory: Annotated[
|
| 1665 |
+
Callable[[], Any] | None,
|
| 1666 |
+
Doc(
|
| 1667 |
+
"""
|
| 1668 |
+
A callable to generate the default value.
|
| 1669 |
+
|
| 1670 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 1671 |
+
The parameter is available only for compatibility.
|
| 1672 |
+
"""
|
| 1673 |
+
),
|
| 1674 |
+
] = _Unset,
|
| 1675 |
+
media_type: Annotated[
|
| 1676 |
+
str,
|
| 1677 |
+
Doc(
|
| 1678 |
+
"""
|
| 1679 |
+
The media type of this parameter field. Changing it would affect the
|
| 1680 |
+
generated OpenAPI, but currently it doesn't affect the parsing of the data.
|
| 1681 |
+
"""
|
| 1682 |
+
),
|
| 1683 |
+
] = "application/x-www-form-urlencoded",
|
| 1684 |
+
alias: Annotated[
|
| 1685 |
+
str | None,
|
| 1686 |
+
Doc(
|
| 1687 |
+
"""
|
| 1688 |
+
An alternative name for the parameter field.
|
| 1689 |
+
|
| 1690 |
+
This will be used to extract the data and for the generated OpenAPI.
|
| 1691 |
+
It is particularly useful when you can't use the name you want because it
|
| 1692 |
+
is a Python reserved keyword or similar.
|
| 1693 |
+
"""
|
| 1694 |
+
),
|
| 1695 |
+
] = None,
|
| 1696 |
+
alias_priority: Annotated[
|
| 1697 |
+
int | None,
|
| 1698 |
+
Doc(
|
| 1699 |
+
"""
|
| 1700 |
+
Priority of the alias. This affects whether an alias generator is used.
|
| 1701 |
+
"""
|
| 1702 |
+
),
|
| 1703 |
+
] = _Unset,
|
| 1704 |
+
validation_alias: Annotated[
|
| 1705 |
+
str | AliasPath | AliasChoices | None,
|
| 1706 |
+
Doc(
|
| 1707 |
+
"""
|
| 1708 |
+
'Whitelist' validation step. The parameter field will be the single one
|
| 1709 |
+
allowed by the alias or set of aliases defined.
|
| 1710 |
+
"""
|
| 1711 |
+
),
|
| 1712 |
+
] = None,
|
| 1713 |
+
serialization_alias: Annotated[
|
| 1714 |
+
str | None,
|
| 1715 |
+
Doc(
|
| 1716 |
+
"""
|
| 1717 |
+
'Blacklist' validation step. The vanilla parameter field will be the
|
| 1718 |
+
single one of the alias' or set of aliases' fields and all the other
|
| 1719 |
+
fields will be ignored at serialization time.
|
| 1720 |
+
"""
|
| 1721 |
+
),
|
| 1722 |
+
] = None,
|
| 1723 |
+
title: Annotated[
|
| 1724 |
+
str | None,
|
| 1725 |
+
Doc(
|
| 1726 |
+
"""
|
| 1727 |
+
Human-readable title.
|
| 1728 |
+
"""
|
| 1729 |
+
),
|
| 1730 |
+
] = None,
|
| 1731 |
+
description: Annotated[
|
| 1732 |
+
str | None,
|
| 1733 |
+
Doc(
|
| 1734 |
+
"""
|
| 1735 |
+
Human-readable description.
|
| 1736 |
+
"""
|
| 1737 |
+
),
|
| 1738 |
+
] = None,
|
| 1739 |
+
gt: Annotated[
|
| 1740 |
+
float | None,
|
| 1741 |
+
Doc(
|
| 1742 |
+
"""
|
| 1743 |
+
Greater than. If set, value must be greater than this. Only applicable to
|
| 1744 |
+
numbers.
|
| 1745 |
+
"""
|
| 1746 |
+
),
|
| 1747 |
+
] = None,
|
| 1748 |
+
ge: Annotated[
|
| 1749 |
+
float | None,
|
| 1750 |
+
Doc(
|
| 1751 |
+
"""
|
| 1752 |
+
Greater than or equal. If set, value must be greater than or equal to
|
| 1753 |
+
this. Only applicable to numbers.
|
| 1754 |
+
"""
|
| 1755 |
+
),
|
| 1756 |
+
] = None,
|
| 1757 |
+
lt: Annotated[
|
| 1758 |
+
float | None,
|
| 1759 |
+
Doc(
|
| 1760 |
+
"""
|
| 1761 |
+
Less than. If set, value must be less than this. Only applicable to numbers.
|
| 1762 |
+
"""
|
| 1763 |
+
),
|
| 1764 |
+
] = None,
|
| 1765 |
+
le: Annotated[
|
| 1766 |
+
float | None,
|
| 1767 |
+
Doc(
|
| 1768 |
+
"""
|
| 1769 |
+
Less than or equal. If set, value must be less than or equal to this.
|
| 1770 |
+
Only applicable to numbers.
|
| 1771 |
+
"""
|
| 1772 |
+
),
|
| 1773 |
+
] = None,
|
| 1774 |
+
min_length: Annotated[
|
| 1775 |
+
int | None,
|
| 1776 |
+
Doc(
|
| 1777 |
+
"""
|
| 1778 |
+
Minimum length for strings.
|
| 1779 |
+
"""
|
| 1780 |
+
),
|
| 1781 |
+
] = None,
|
| 1782 |
+
max_length: Annotated[
|
| 1783 |
+
int | None,
|
| 1784 |
+
Doc(
|
| 1785 |
+
"""
|
| 1786 |
+
Maximum length for strings.
|
| 1787 |
+
"""
|
| 1788 |
+
),
|
| 1789 |
+
] = None,
|
| 1790 |
+
pattern: Annotated[
|
| 1791 |
+
str | None,
|
| 1792 |
+
Doc(
|
| 1793 |
+
"""
|
| 1794 |
+
RegEx pattern for strings.
|
| 1795 |
+
"""
|
| 1796 |
+
),
|
| 1797 |
+
] = None,
|
| 1798 |
+
regex: Annotated[
|
| 1799 |
+
str | None,
|
| 1800 |
+
Doc(
|
| 1801 |
+
"""
|
| 1802 |
+
RegEx pattern for strings.
|
| 1803 |
+
"""
|
| 1804 |
+
),
|
| 1805 |
+
deprecated(
|
| 1806 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 1807 |
+
),
|
| 1808 |
+
] = None,
|
| 1809 |
+
discriminator: Annotated[
|
| 1810 |
+
str | None,
|
| 1811 |
+
Doc(
|
| 1812 |
+
"""
|
| 1813 |
+
Parameter field name for discriminating the type in a tagged union.
|
| 1814 |
+
"""
|
| 1815 |
+
),
|
| 1816 |
+
] = None,
|
| 1817 |
+
strict: Annotated[
|
| 1818 |
+
bool | None,
|
| 1819 |
+
Doc(
|
| 1820 |
+
"""
|
| 1821 |
+
If `True`, strict validation is applied to the field.
|
| 1822 |
+
"""
|
| 1823 |
+
),
|
| 1824 |
+
] = _Unset,
|
| 1825 |
+
multiple_of: Annotated[
|
| 1826 |
+
float | None,
|
| 1827 |
+
Doc(
|
| 1828 |
+
"""
|
| 1829 |
+
Value must be a multiple of this. Only applicable to numbers.
|
| 1830 |
+
"""
|
| 1831 |
+
),
|
| 1832 |
+
] = _Unset,
|
| 1833 |
+
allow_inf_nan: Annotated[
|
| 1834 |
+
bool | None,
|
| 1835 |
+
Doc(
|
| 1836 |
+
"""
|
| 1837 |
+
Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
|
| 1838 |
+
"""
|
| 1839 |
+
),
|
| 1840 |
+
] = _Unset,
|
| 1841 |
+
max_digits: Annotated[
|
| 1842 |
+
int | None,
|
| 1843 |
+
Doc(
|
| 1844 |
+
"""
|
| 1845 |
+
Maximum number of allow digits for strings.
|
| 1846 |
+
"""
|
| 1847 |
+
),
|
| 1848 |
+
] = _Unset,
|
| 1849 |
+
decimal_places: Annotated[
|
| 1850 |
+
int | None,
|
| 1851 |
+
Doc(
|
| 1852 |
+
"""
|
| 1853 |
+
Maximum number of decimal places allowed for numbers.
|
| 1854 |
+
"""
|
| 1855 |
+
),
|
| 1856 |
+
] = _Unset,
|
| 1857 |
+
examples: Annotated[
|
| 1858 |
+
list[Any] | None,
|
| 1859 |
+
Doc(
|
| 1860 |
+
"""
|
| 1861 |
+
Example values for this field.
|
| 1862 |
+
|
| 1863 |
+
Read more about it in the
|
| 1864 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)
|
| 1865 |
+
"""
|
| 1866 |
+
),
|
| 1867 |
+
] = None,
|
| 1868 |
+
example: Annotated[
|
| 1869 |
+
Any | None,
|
| 1870 |
+
deprecated(
|
| 1871 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 1872 |
+
"although still supported. Use examples instead."
|
| 1873 |
+
),
|
| 1874 |
+
] = _Unset,
|
| 1875 |
+
openapi_examples: Annotated[
|
| 1876 |
+
dict[str, Example] | None,
|
| 1877 |
+
Doc(
|
| 1878 |
+
"""
|
| 1879 |
+
OpenAPI-specific examples.
|
| 1880 |
+
|
| 1881 |
+
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
|
| 1882 |
+
|
| 1883 |
+
Swagger UI (that provides the `/docs` interface) has better support for the
|
| 1884 |
+
OpenAPI-specific examples than the JSON Schema `examples`, that's the main
|
| 1885 |
+
use case for this.
|
| 1886 |
+
|
| 1887 |
+
Read more about it in the
|
| 1888 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
|
| 1889 |
+
"""
|
| 1890 |
+
),
|
| 1891 |
+
] = None,
|
| 1892 |
+
deprecated: Annotated[
|
| 1893 |
+
deprecated | str | bool | None,
|
| 1894 |
+
Doc(
|
| 1895 |
+
"""
|
| 1896 |
+
Mark this parameter field as deprecated.
|
| 1897 |
+
|
| 1898 |
+
It will affect the generated OpenAPI (e.g. visible at `/docs`).
|
| 1899 |
+
"""
|
| 1900 |
+
),
|
| 1901 |
+
] = None,
|
| 1902 |
+
include_in_schema: Annotated[
|
| 1903 |
+
bool,
|
| 1904 |
+
Doc(
|
| 1905 |
+
"""
|
| 1906 |
+
To include (or not) this parameter field in the generated OpenAPI.
|
| 1907 |
+
You probably don't need it, but it's available.
|
| 1908 |
+
|
| 1909 |
+
This affects the generated OpenAPI (e.g. visible at `/docs`).
|
| 1910 |
+
"""
|
| 1911 |
+
),
|
| 1912 |
+
] = True,
|
| 1913 |
+
json_schema_extra: Annotated[
|
| 1914 |
+
dict[str, Any] | None,
|
| 1915 |
+
Doc(
|
| 1916 |
+
"""
|
| 1917 |
+
Any additional JSON schema data.
|
| 1918 |
+
"""
|
| 1919 |
+
),
|
| 1920 |
+
] = None,
|
| 1921 |
+
**extra: Annotated[
|
| 1922 |
+
Any,
|
| 1923 |
+
Doc(
|
| 1924 |
+
"""
|
| 1925 |
+
Include extra fields used by the JSON Schema.
|
| 1926 |
+
"""
|
| 1927 |
+
),
|
| 1928 |
+
deprecated(
|
| 1929 |
+
"""
|
| 1930 |
+
The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
|
| 1931 |
+
"""
|
| 1932 |
+
),
|
| 1933 |
+
],
|
| 1934 |
+
) -> Any:
|
| 1935 |
+
return params.Form(
|
| 1936 |
+
default=default,
|
| 1937 |
+
default_factory=default_factory,
|
| 1938 |
+
media_type=media_type,
|
| 1939 |
+
alias=alias,
|
| 1940 |
+
alias_priority=alias_priority,
|
| 1941 |
+
validation_alias=validation_alias,
|
| 1942 |
+
serialization_alias=serialization_alias,
|
| 1943 |
+
title=title,
|
| 1944 |
+
description=description,
|
| 1945 |
+
gt=gt,
|
| 1946 |
+
ge=ge,
|
| 1947 |
+
lt=lt,
|
| 1948 |
+
le=le,
|
| 1949 |
+
min_length=min_length,
|
| 1950 |
+
max_length=max_length,
|
| 1951 |
+
pattern=pattern,
|
| 1952 |
+
regex=regex,
|
| 1953 |
+
discriminator=discriminator,
|
| 1954 |
+
strict=strict,
|
| 1955 |
+
multiple_of=multiple_of,
|
| 1956 |
+
allow_inf_nan=allow_inf_nan,
|
| 1957 |
+
max_digits=max_digits,
|
| 1958 |
+
decimal_places=decimal_places,
|
| 1959 |
+
example=example,
|
| 1960 |
+
examples=examples,
|
| 1961 |
+
openapi_examples=openapi_examples,
|
| 1962 |
+
deprecated=deprecated,
|
| 1963 |
+
include_in_schema=include_in_schema,
|
| 1964 |
+
json_schema_extra=json_schema_extra,
|
| 1965 |
+
**extra,
|
| 1966 |
+
)
|
| 1967 |
+
|
| 1968 |
+
|
| 1969 |
+
def File( # noqa: N802
|
| 1970 |
+
default: Annotated[
|
| 1971 |
+
Any,
|
| 1972 |
+
Doc(
|
| 1973 |
+
"""
|
| 1974 |
+
Default value if the parameter field is not set.
|
| 1975 |
+
"""
|
| 1976 |
+
),
|
| 1977 |
+
] = Undefined,
|
| 1978 |
+
*,
|
| 1979 |
+
default_factory: Annotated[
|
| 1980 |
+
Callable[[], Any] | None,
|
| 1981 |
+
Doc(
|
| 1982 |
+
"""
|
| 1983 |
+
A callable to generate the default value.
|
| 1984 |
+
|
| 1985 |
+
This doesn't affect `Path` parameters as the value is always required.
|
| 1986 |
+
The parameter is available only for compatibility.
|
| 1987 |
+
"""
|
| 1988 |
+
),
|
| 1989 |
+
] = _Unset,
|
| 1990 |
+
media_type: Annotated[
|
| 1991 |
+
str,
|
| 1992 |
+
Doc(
|
| 1993 |
+
"""
|
| 1994 |
+
The media type of this parameter field. Changing it would affect the
|
| 1995 |
+
generated OpenAPI, but currently it doesn't affect the parsing of the data.
|
| 1996 |
+
"""
|
| 1997 |
+
),
|
| 1998 |
+
] = "multipart/form-data",
|
| 1999 |
+
alias: Annotated[
|
| 2000 |
+
str | None,
|
| 2001 |
+
Doc(
|
| 2002 |
+
"""
|
| 2003 |
+
An alternative name for the parameter field.
|
| 2004 |
+
|
| 2005 |
+
This will be used to extract the data and for the generated OpenAPI.
|
| 2006 |
+
It is particularly useful when you can't use the name you want because it
|
| 2007 |
+
is a Python reserved keyword or similar.
|
| 2008 |
+
"""
|
| 2009 |
+
),
|
| 2010 |
+
] = None,
|
| 2011 |
+
alias_priority: Annotated[
|
| 2012 |
+
int | None,
|
| 2013 |
+
Doc(
|
| 2014 |
+
"""
|
| 2015 |
+
Priority of the alias. This affects whether an alias generator is used.
|
| 2016 |
+
"""
|
| 2017 |
+
),
|
| 2018 |
+
] = _Unset,
|
| 2019 |
+
validation_alias: Annotated[
|
| 2020 |
+
str | AliasPath | AliasChoices | None,
|
| 2021 |
+
Doc(
|
| 2022 |
+
"""
|
| 2023 |
+
'Whitelist' validation step. The parameter field will be the single one
|
| 2024 |
+
allowed by the alias or set of aliases defined.
|
| 2025 |
+
"""
|
| 2026 |
+
),
|
| 2027 |
+
] = None,
|
| 2028 |
+
serialization_alias: Annotated[
|
| 2029 |
+
str | None,
|
| 2030 |
+
Doc(
|
| 2031 |
+
"""
|
| 2032 |
+
'Blacklist' validation step. The vanilla parameter field will be the
|
| 2033 |
+
single one of the alias' or set of aliases' fields and all the other
|
| 2034 |
+
fields will be ignored at serialization time.
|
| 2035 |
+
"""
|
| 2036 |
+
),
|
| 2037 |
+
] = None,
|
| 2038 |
+
title: Annotated[
|
| 2039 |
+
str | None,
|
| 2040 |
+
Doc(
|
| 2041 |
+
"""
|
| 2042 |
+
Human-readable title.
|
| 2043 |
+
"""
|
| 2044 |
+
),
|
| 2045 |
+
] = None,
|
| 2046 |
+
description: Annotated[
|
| 2047 |
+
str | None,
|
| 2048 |
+
Doc(
|
| 2049 |
+
"""
|
| 2050 |
+
Human-readable description.
|
| 2051 |
+
"""
|
| 2052 |
+
),
|
| 2053 |
+
] = None,
|
| 2054 |
+
gt: Annotated[
|
| 2055 |
+
float | None,
|
| 2056 |
+
Doc(
|
| 2057 |
+
"""
|
| 2058 |
+
Greater than. If set, value must be greater than this. Only applicable to
|
| 2059 |
+
numbers.
|
| 2060 |
+
"""
|
| 2061 |
+
),
|
| 2062 |
+
] = None,
|
| 2063 |
+
ge: Annotated[
|
| 2064 |
+
float | None,
|
| 2065 |
+
Doc(
|
| 2066 |
+
"""
|
| 2067 |
+
Greater than or equal. If set, value must be greater than or equal to
|
| 2068 |
+
this. Only applicable to numbers.
|
| 2069 |
+
"""
|
| 2070 |
+
),
|
| 2071 |
+
] = None,
|
| 2072 |
+
lt: Annotated[
|
| 2073 |
+
float | None,
|
| 2074 |
+
Doc(
|
| 2075 |
+
"""
|
| 2076 |
+
Less than. If set, value must be less than this. Only applicable to numbers.
|
| 2077 |
+
"""
|
| 2078 |
+
),
|
| 2079 |
+
] = None,
|
| 2080 |
+
le: Annotated[
|
| 2081 |
+
float | None,
|
| 2082 |
+
Doc(
|
| 2083 |
+
"""
|
| 2084 |
+
Less than or equal. If set, value must be less than or equal to this.
|
| 2085 |
+
Only applicable to numbers.
|
| 2086 |
+
"""
|
| 2087 |
+
),
|
| 2088 |
+
] = None,
|
| 2089 |
+
min_length: Annotated[
|
| 2090 |
+
int | None,
|
| 2091 |
+
Doc(
|
| 2092 |
+
"""
|
| 2093 |
+
Minimum length for strings.
|
| 2094 |
+
"""
|
| 2095 |
+
),
|
| 2096 |
+
] = None,
|
| 2097 |
+
max_length: Annotated[
|
| 2098 |
+
int | None,
|
| 2099 |
+
Doc(
|
| 2100 |
+
"""
|
| 2101 |
+
Maximum length for strings.
|
| 2102 |
+
"""
|
| 2103 |
+
),
|
| 2104 |
+
] = None,
|
| 2105 |
+
pattern: Annotated[
|
| 2106 |
+
str | None,
|
| 2107 |
+
Doc(
|
| 2108 |
+
"""
|
| 2109 |
+
RegEx pattern for strings.
|
| 2110 |
+
"""
|
| 2111 |
+
),
|
| 2112 |
+
] = None,
|
| 2113 |
+
regex: Annotated[
|
| 2114 |
+
str | None,
|
| 2115 |
+
Doc(
|
| 2116 |
+
"""
|
| 2117 |
+
RegEx pattern for strings.
|
| 2118 |
+
"""
|
| 2119 |
+
),
|
| 2120 |
+
deprecated(
|
| 2121 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 2122 |
+
),
|
| 2123 |
+
] = None,
|
| 2124 |
+
discriminator: Annotated[
|
| 2125 |
+
str | None,
|
| 2126 |
+
Doc(
|
| 2127 |
+
"""
|
| 2128 |
+
Parameter field name for discriminating the type in a tagged union.
|
| 2129 |
+
"""
|
| 2130 |
+
),
|
| 2131 |
+
] = None,
|
| 2132 |
+
strict: Annotated[
|
| 2133 |
+
bool | None,
|
| 2134 |
+
Doc(
|
| 2135 |
+
"""
|
| 2136 |
+
If `True`, strict validation is applied to the field.
|
| 2137 |
+
"""
|
| 2138 |
+
),
|
| 2139 |
+
] = _Unset,
|
| 2140 |
+
multiple_of: Annotated[
|
| 2141 |
+
float | None,
|
| 2142 |
+
Doc(
|
| 2143 |
+
"""
|
| 2144 |
+
Value must be a multiple of this. Only applicable to numbers.
|
| 2145 |
+
"""
|
| 2146 |
+
),
|
| 2147 |
+
] = _Unset,
|
| 2148 |
+
allow_inf_nan: Annotated[
|
| 2149 |
+
bool | None,
|
| 2150 |
+
Doc(
|
| 2151 |
+
"""
|
| 2152 |
+
Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
|
| 2153 |
+
"""
|
| 2154 |
+
),
|
| 2155 |
+
] = _Unset,
|
| 2156 |
+
max_digits: Annotated[
|
| 2157 |
+
int | None,
|
| 2158 |
+
Doc(
|
| 2159 |
+
"""
|
| 2160 |
+
Maximum number of allow digits for strings.
|
| 2161 |
+
"""
|
| 2162 |
+
),
|
| 2163 |
+
] = _Unset,
|
| 2164 |
+
decimal_places: Annotated[
|
| 2165 |
+
int | None,
|
| 2166 |
+
Doc(
|
| 2167 |
+
"""
|
| 2168 |
+
Maximum number of decimal places allowed for numbers.
|
| 2169 |
+
"""
|
| 2170 |
+
),
|
| 2171 |
+
] = _Unset,
|
| 2172 |
+
examples: Annotated[
|
| 2173 |
+
list[Any] | None,
|
| 2174 |
+
Doc(
|
| 2175 |
+
"""
|
| 2176 |
+
Example values for this field.
|
| 2177 |
+
|
| 2178 |
+
Read more about it in the
|
| 2179 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)
|
| 2180 |
+
"""
|
| 2181 |
+
),
|
| 2182 |
+
] = None,
|
| 2183 |
+
example: Annotated[
|
| 2184 |
+
Any | None,
|
| 2185 |
+
deprecated(
|
| 2186 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 2187 |
+
"although still supported. Use examples instead."
|
| 2188 |
+
),
|
| 2189 |
+
] = _Unset,
|
| 2190 |
+
openapi_examples: Annotated[
|
| 2191 |
+
dict[str, Example] | None,
|
| 2192 |
+
Doc(
|
| 2193 |
+
"""
|
| 2194 |
+
OpenAPI-specific examples.
|
| 2195 |
+
|
| 2196 |
+
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
|
| 2197 |
+
|
| 2198 |
+
Swagger UI (that provides the `/docs` interface) has better support for the
|
| 2199 |
+
OpenAPI-specific examples than the JSON Schema `examples`, that's the main
|
| 2200 |
+
use case for this.
|
| 2201 |
+
|
| 2202 |
+
Read more about it in the
|
| 2203 |
+
[FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
|
| 2204 |
+
"""
|
| 2205 |
+
),
|
| 2206 |
+
] = None,
|
| 2207 |
+
deprecated: Annotated[
|
| 2208 |
+
deprecated | str | bool | None,
|
| 2209 |
+
Doc(
|
| 2210 |
+
"""
|
| 2211 |
+
Mark this parameter field as deprecated.
|
| 2212 |
+
|
| 2213 |
+
It will affect the generated OpenAPI (e.g. visible at `/docs`).
|
| 2214 |
+
"""
|
| 2215 |
+
),
|
| 2216 |
+
] = None,
|
| 2217 |
+
include_in_schema: Annotated[
|
| 2218 |
+
bool,
|
| 2219 |
+
Doc(
|
| 2220 |
+
"""
|
| 2221 |
+
To include (or not) this parameter field in the generated OpenAPI.
|
| 2222 |
+
You probably don't need it, but it's available.
|
| 2223 |
+
|
| 2224 |
+
This affects the generated OpenAPI (e.g. visible at `/docs`).
|
| 2225 |
+
"""
|
| 2226 |
+
),
|
| 2227 |
+
] = True,
|
| 2228 |
+
json_schema_extra: Annotated[
|
| 2229 |
+
dict[str, Any] | None,
|
| 2230 |
+
Doc(
|
| 2231 |
+
"""
|
| 2232 |
+
Any additional JSON schema data.
|
| 2233 |
+
"""
|
| 2234 |
+
),
|
| 2235 |
+
] = None,
|
| 2236 |
+
**extra: Annotated[
|
| 2237 |
+
Any,
|
| 2238 |
+
Doc(
|
| 2239 |
+
"""
|
| 2240 |
+
Include extra fields used by the JSON Schema.
|
| 2241 |
+
"""
|
| 2242 |
+
),
|
| 2243 |
+
deprecated(
|
| 2244 |
+
"""
|
| 2245 |
+
The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
|
| 2246 |
+
"""
|
| 2247 |
+
),
|
| 2248 |
+
],
|
| 2249 |
+
) -> Any:
|
| 2250 |
+
return params.File(
|
| 2251 |
+
default=default,
|
| 2252 |
+
default_factory=default_factory,
|
| 2253 |
+
media_type=media_type,
|
| 2254 |
+
alias=alias,
|
| 2255 |
+
alias_priority=alias_priority,
|
| 2256 |
+
validation_alias=validation_alias,
|
| 2257 |
+
serialization_alias=serialization_alias,
|
| 2258 |
+
title=title,
|
| 2259 |
+
description=description,
|
| 2260 |
+
gt=gt,
|
| 2261 |
+
ge=ge,
|
| 2262 |
+
lt=lt,
|
| 2263 |
+
le=le,
|
| 2264 |
+
min_length=min_length,
|
| 2265 |
+
max_length=max_length,
|
| 2266 |
+
pattern=pattern,
|
| 2267 |
+
regex=regex,
|
| 2268 |
+
discriminator=discriminator,
|
| 2269 |
+
strict=strict,
|
| 2270 |
+
multiple_of=multiple_of,
|
| 2271 |
+
allow_inf_nan=allow_inf_nan,
|
| 2272 |
+
max_digits=max_digits,
|
| 2273 |
+
decimal_places=decimal_places,
|
| 2274 |
+
example=example,
|
| 2275 |
+
examples=examples,
|
| 2276 |
+
openapi_examples=openapi_examples,
|
| 2277 |
+
deprecated=deprecated,
|
| 2278 |
+
include_in_schema=include_in_schema,
|
| 2279 |
+
json_schema_extra=json_schema_extra,
|
| 2280 |
+
**extra,
|
| 2281 |
+
)
|
| 2282 |
+
|
| 2283 |
+
|
| 2284 |
+
def Depends( # noqa: N802
|
| 2285 |
+
dependency: Annotated[
|
| 2286 |
+
Callable[..., Any] | None,
|
| 2287 |
+
Doc(
|
| 2288 |
+
"""
|
| 2289 |
+
A "dependable" callable (like a function).
|
| 2290 |
+
|
| 2291 |
+
Don't call it directly, FastAPI will call it for you, just pass the object
|
| 2292 |
+
directly.
|
| 2293 |
+
|
| 2294 |
+
Read more about it in the
|
| 2295 |
+
[FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/)
|
| 2296 |
+
"""
|
| 2297 |
+
),
|
| 2298 |
+
] = None,
|
| 2299 |
+
*,
|
| 2300 |
+
use_cache: Annotated[
|
| 2301 |
+
bool,
|
| 2302 |
+
Doc(
|
| 2303 |
+
"""
|
| 2304 |
+
By default, after a dependency is called the first time in a request, if
|
| 2305 |
+
the dependency is declared again for the rest of the request (for example
|
| 2306 |
+
if the dependency is needed by several dependencies), the value will be
|
| 2307 |
+
re-used for the rest of the request.
|
| 2308 |
+
|
| 2309 |
+
Set `use_cache` to `False` to disable this behavior and ensure the
|
| 2310 |
+
dependency is called again (if declared more than once) in the same request.
|
| 2311 |
+
|
| 2312 |
+
Read more about it in the
|
| 2313 |
+
[FastAPI docs about sub-dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/#using-the-same-dependency-multiple-times)
|
| 2314 |
+
"""
|
| 2315 |
+
),
|
| 2316 |
+
] = True,
|
| 2317 |
+
scope: Annotated[
|
| 2318 |
+
Literal["function", "request"] | None,
|
| 2319 |
+
Doc(
|
| 2320 |
+
"""
|
| 2321 |
+
Mainly for dependencies with `yield`, define when the dependency function
|
| 2322 |
+
should start (the code before `yield`) and when it should end (the code
|
| 2323 |
+
after `yield`).
|
| 2324 |
+
|
| 2325 |
+
* `"function"`: start the dependency before the *path operation function*
|
| 2326 |
+
that handles the request, end the dependency after the *path operation
|
| 2327 |
+
function* ends, but **before** the response is sent back to the client.
|
| 2328 |
+
So, the dependency function will be executed **around** the *path operation
|
| 2329 |
+
**function***.
|
| 2330 |
+
* `"request"`: start the dependency before the *path operation function*
|
| 2331 |
+
that handles the request (similar to when using `"function"`), but end
|
| 2332 |
+
**after** the response is sent back to the client. So, the dependency
|
| 2333 |
+
function will be executed **around** the **request** and response cycle.
|
| 2334 |
+
|
| 2335 |
+
Read more about it in the
|
| 2336 |
+
[FastAPI docs for FastAPI Dependencies with yield](https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-with-yield/#early-exit-and-scope)
|
| 2337 |
+
"""
|
| 2338 |
+
),
|
| 2339 |
+
] = None,
|
| 2340 |
+
) -> Any:
|
| 2341 |
+
"""
|
| 2342 |
+
Declare a FastAPI dependency.
|
| 2343 |
+
|
| 2344 |
+
It takes a single "dependable" callable (like a function).
|
| 2345 |
+
|
| 2346 |
+
Don't call it directly, FastAPI will call it for you.
|
| 2347 |
+
|
| 2348 |
+
Read more about it in the
|
| 2349 |
+
[FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/).
|
| 2350 |
+
|
| 2351 |
+
**Example**
|
| 2352 |
+
|
| 2353 |
+
```python
|
| 2354 |
+
from typing import Annotated
|
| 2355 |
+
|
| 2356 |
+
from fastapi import Depends, FastAPI
|
| 2357 |
+
|
| 2358 |
+
app = FastAPI()
|
| 2359 |
+
|
| 2360 |
+
|
| 2361 |
+
async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
|
| 2362 |
+
return {"q": q, "skip": skip, "limit": limit}
|
| 2363 |
+
|
| 2364 |
+
|
| 2365 |
+
@app.get("/items/")
|
| 2366 |
+
async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
|
| 2367 |
+
return commons
|
| 2368 |
+
```
|
| 2369 |
+
"""
|
| 2370 |
+
return params.Depends(dependency=dependency, use_cache=use_cache, scope=scope)
|
| 2371 |
+
|
| 2372 |
+
|
| 2373 |
+
def Security( # noqa: N802
|
| 2374 |
+
dependency: Annotated[
|
| 2375 |
+
Callable[..., Any] | None,
|
| 2376 |
+
Doc(
|
| 2377 |
+
"""
|
| 2378 |
+
A "dependable" callable (like a function).
|
| 2379 |
+
|
| 2380 |
+
Don't call it directly, FastAPI will call it for you, just pass the object
|
| 2381 |
+
directly.
|
| 2382 |
+
|
| 2383 |
+
Read more about it in the
|
| 2384 |
+
[FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/)
|
| 2385 |
+
"""
|
| 2386 |
+
),
|
| 2387 |
+
] = None,
|
| 2388 |
+
*,
|
| 2389 |
+
scopes: Annotated[
|
| 2390 |
+
Sequence[str] | None,
|
| 2391 |
+
Doc(
|
| 2392 |
+
"""
|
| 2393 |
+
OAuth2 scopes required for the *path operation* that uses this Security
|
| 2394 |
+
dependency.
|
| 2395 |
+
|
| 2396 |
+
The term "scope" comes from the OAuth2 specification, it seems to be
|
| 2397 |
+
intentionally vague and interpretable. It normally refers to permissions,
|
| 2398 |
+
in cases to roles.
|
| 2399 |
+
|
| 2400 |
+
These scopes are integrated with OpenAPI (and the API docs at `/docs`).
|
| 2401 |
+
So they are visible in the OpenAPI specification.
|
| 2402 |
+
|
| 2403 |
+
Read more about it in the
|
| 2404 |
+
[FastAPI docs about OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/)
|
| 2405 |
+
"""
|
| 2406 |
+
),
|
| 2407 |
+
] = None,
|
| 2408 |
+
use_cache: Annotated[
|
| 2409 |
+
bool,
|
| 2410 |
+
Doc(
|
| 2411 |
+
"""
|
| 2412 |
+
By default, after a dependency is called the first time in a request, if
|
| 2413 |
+
the dependency is declared again for the rest of the request (for example
|
| 2414 |
+
if the dependency is needed by several dependencies), the value will be
|
| 2415 |
+
re-used for the rest of the request.
|
| 2416 |
+
|
| 2417 |
+
Set `use_cache` to `False` to disable this behavior and ensure the
|
| 2418 |
+
dependency is called again (if declared more than once) in the same request.
|
| 2419 |
+
|
| 2420 |
+
Read more about it in the
|
| 2421 |
+
[FastAPI docs about sub-dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/#using-the-same-dependency-multiple-times)
|
| 2422 |
+
"""
|
| 2423 |
+
),
|
| 2424 |
+
] = True,
|
| 2425 |
+
) -> Any:
|
| 2426 |
+
"""
|
| 2427 |
+
Declare a FastAPI Security dependency.
|
| 2428 |
+
|
| 2429 |
+
The only difference with a regular dependency is that it can declare OAuth2
|
| 2430 |
+
scopes that will be integrated with OpenAPI and the automatic UI docs (by default
|
| 2431 |
+
at `/docs`).
|
| 2432 |
+
|
| 2433 |
+
It takes a single "dependable" callable (like a function).
|
| 2434 |
+
|
| 2435 |
+
Don't call it directly, FastAPI will call it for you.
|
| 2436 |
+
|
| 2437 |
+
Read more about it in the
|
| 2438 |
+
[FastAPI docs for Security](https://fastapi.tiangolo.com/tutorial/security/) and
|
| 2439 |
+
in the
|
| 2440 |
+
[FastAPI docs for OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/).
|
| 2441 |
+
|
| 2442 |
+
**Example**
|
| 2443 |
+
|
| 2444 |
+
```python
|
| 2445 |
+
from typing import Annotated
|
| 2446 |
+
|
| 2447 |
+
from fastapi import Security, FastAPI
|
| 2448 |
+
|
| 2449 |
+
from .db import User
|
| 2450 |
+
from .security import get_current_active_user
|
| 2451 |
+
|
| 2452 |
+
app = FastAPI()
|
| 2453 |
+
|
| 2454 |
+
@app.get("/users/me/items/")
|
| 2455 |
+
async def read_own_items(
|
| 2456 |
+
current_user: Annotated[User, Security(get_current_active_user, scopes=["items"])]
|
| 2457 |
+
):
|
| 2458 |
+
return [{"item_id": "Foo", "owner": current_user.username}]
|
| 2459 |
+
```
|
| 2460 |
+
"""
|
| 2461 |
+
return params.Security(dependency=dependency, scopes=scopes, use_cache=use_cache)
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/params.py
ADDED
|
@@ -0,0 +1,755 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
from collections.abc import Callable, Sequence
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from enum import Enum
|
| 5 |
+
from typing import Annotated, Any, Literal
|
| 6 |
+
|
| 7 |
+
from fastapi.exceptions import FastAPIDeprecationWarning
|
| 8 |
+
from fastapi.openapi.models import Example
|
| 9 |
+
from pydantic import AliasChoices, AliasPath
|
| 10 |
+
from pydantic.fields import FieldInfo
|
| 11 |
+
from typing_extensions import deprecated
|
| 12 |
+
|
| 13 |
+
from ._compat import (
|
| 14 |
+
Undefined,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
_Unset: Any = Undefined
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class ParamTypes(Enum):
|
| 21 |
+
query = "query"
|
| 22 |
+
header = "header"
|
| 23 |
+
path = "path"
|
| 24 |
+
cookie = "cookie"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Param(FieldInfo): # type: ignore[misc]
|
| 28 |
+
in_: ParamTypes
|
| 29 |
+
|
| 30 |
+
def __init__(
|
| 31 |
+
self,
|
| 32 |
+
default: Any = Undefined,
|
| 33 |
+
*,
|
| 34 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 35 |
+
annotation: Any | None = None,
|
| 36 |
+
alias: str | None = None,
|
| 37 |
+
alias_priority: int | None = _Unset,
|
| 38 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 39 |
+
serialization_alias: str | None = None,
|
| 40 |
+
title: str | None = None,
|
| 41 |
+
description: str | None = None,
|
| 42 |
+
gt: float | None = None,
|
| 43 |
+
ge: float | None = None,
|
| 44 |
+
lt: float | None = None,
|
| 45 |
+
le: float | None = None,
|
| 46 |
+
min_length: int | None = None,
|
| 47 |
+
max_length: int | None = None,
|
| 48 |
+
pattern: str | None = None,
|
| 49 |
+
regex: Annotated[
|
| 50 |
+
str | None,
|
| 51 |
+
deprecated(
|
| 52 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 53 |
+
),
|
| 54 |
+
] = None,
|
| 55 |
+
discriminator: str | None = None,
|
| 56 |
+
strict: bool | None = _Unset,
|
| 57 |
+
multiple_of: float | None = _Unset,
|
| 58 |
+
allow_inf_nan: bool | None = _Unset,
|
| 59 |
+
max_digits: int | None = _Unset,
|
| 60 |
+
decimal_places: int | None = _Unset,
|
| 61 |
+
examples: list[Any] | None = None,
|
| 62 |
+
example: Annotated[
|
| 63 |
+
Any | None,
|
| 64 |
+
deprecated(
|
| 65 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 66 |
+
"although still supported. Use examples instead."
|
| 67 |
+
),
|
| 68 |
+
] = _Unset,
|
| 69 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 70 |
+
deprecated: deprecated | str | bool | None = None,
|
| 71 |
+
include_in_schema: bool = True,
|
| 72 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 73 |
+
**extra: Any,
|
| 74 |
+
):
|
| 75 |
+
if example is not _Unset:
|
| 76 |
+
warnings.warn(
|
| 77 |
+
"`example` has been deprecated, please use `examples` instead",
|
| 78 |
+
category=FastAPIDeprecationWarning,
|
| 79 |
+
stacklevel=4,
|
| 80 |
+
)
|
| 81 |
+
self.example = example
|
| 82 |
+
self.include_in_schema = include_in_schema
|
| 83 |
+
self.openapi_examples = openapi_examples
|
| 84 |
+
kwargs = dict(
|
| 85 |
+
default=default,
|
| 86 |
+
default_factory=default_factory,
|
| 87 |
+
alias=alias,
|
| 88 |
+
title=title,
|
| 89 |
+
description=description,
|
| 90 |
+
gt=gt,
|
| 91 |
+
ge=ge,
|
| 92 |
+
lt=lt,
|
| 93 |
+
le=le,
|
| 94 |
+
min_length=min_length,
|
| 95 |
+
max_length=max_length,
|
| 96 |
+
discriminator=discriminator,
|
| 97 |
+
multiple_of=multiple_of,
|
| 98 |
+
allow_inf_nan=allow_inf_nan,
|
| 99 |
+
max_digits=max_digits,
|
| 100 |
+
decimal_places=decimal_places,
|
| 101 |
+
**extra,
|
| 102 |
+
)
|
| 103 |
+
if examples is not None:
|
| 104 |
+
kwargs["examples"] = examples
|
| 105 |
+
if regex is not None:
|
| 106 |
+
warnings.warn(
|
| 107 |
+
"`regex` has been deprecated, please use `pattern` instead",
|
| 108 |
+
category=FastAPIDeprecationWarning,
|
| 109 |
+
stacklevel=4,
|
| 110 |
+
)
|
| 111 |
+
current_json_schema_extra = json_schema_extra or extra
|
| 112 |
+
kwargs["deprecated"] = deprecated
|
| 113 |
+
|
| 114 |
+
if serialization_alias in (_Unset, None) and isinstance(alias, str):
|
| 115 |
+
serialization_alias = alias
|
| 116 |
+
if validation_alias in (_Unset, None):
|
| 117 |
+
validation_alias = alias
|
| 118 |
+
kwargs.update(
|
| 119 |
+
{
|
| 120 |
+
"annotation": annotation,
|
| 121 |
+
"alias_priority": alias_priority,
|
| 122 |
+
"validation_alias": validation_alias,
|
| 123 |
+
"serialization_alias": serialization_alias,
|
| 124 |
+
"strict": strict,
|
| 125 |
+
"json_schema_extra": current_json_schema_extra,
|
| 126 |
+
}
|
| 127 |
+
)
|
| 128 |
+
kwargs["pattern"] = pattern or regex
|
| 129 |
+
|
| 130 |
+
use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset}
|
| 131 |
+
|
| 132 |
+
super().__init__(**use_kwargs)
|
| 133 |
+
|
| 134 |
+
def __repr__(self) -> str:
|
| 135 |
+
return f"{self.__class__.__name__}({self.default})"
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class Path(Param): # type: ignore[misc]
|
| 139 |
+
in_ = ParamTypes.path
|
| 140 |
+
|
| 141 |
+
def __init__(
|
| 142 |
+
self,
|
| 143 |
+
default: Any = ...,
|
| 144 |
+
*,
|
| 145 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 146 |
+
annotation: Any | None = None,
|
| 147 |
+
alias: str | None = None,
|
| 148 |
+
alias_priority: int | None = _Unset,
|
| 149 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 150 |
+
serialization_alias: str | None = None,
|
| 151 |
+
title: str | None = None,
|
| 152 |
+
description: str | None = None,
|
| 153 |
+
gt: float | None = None,
|
| 154 |
+
ge: float | None = None,
|
| 155 |
+
lt: float | None = None,
|
| 156 |
+
le: float | None = None,
|
| 157 |
+
min_length: int | None = None,
|
| 158 |
+
max_length: int | None = None,
|
| 159 |
+
pattern: str | None = None,
|
| 160 |
+
regex: Annotated[
|
| 161 |
+
str | None,
|
| 162 |
+
deprecated(
|
| 163 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 164 |
+
),
|
| 165 |
+
] = None,
|
| 166 |
+
discriminator: str | None = None,
|
| 167 |
+
strict: bool | None = _Unset,
|
| 168 |
+
multiple_of: float | None = _Unset,
|
| 169 |
+
allow_inf_nan: bool | None = _Unset,
|
| 170 |
+
max_digits: int | None = _Unset,
|
| 171 |
+
decimal_places: int | None = _Unset,
|
| 172 |
+
examples: list[Any] | None = None,
|
| 173 |
+
example: Annotated[
|
| 174 |
+
Any | None,
|
| 175 |
+
deprecated(
|
| 176 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 177 |
+
"although still supported. Use examples instead."
|
| 178 |
+
),
|
| 179 |
+
] = _Unset,
|
| 180 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 181 |
+
deprecated: deprecated | str | bool | None = None,
|
| 182 |
+
include_in_schema: bool = True,
|
| 183 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 184 |
+
**extra: Any,
|
| 185 |
+
):
|
| 186 |
+
assert default is ..., "Path parameters cannot have a default value"
|
| 187 |
+
self.in_ = self.in_
|
| 188 |
+
super().__init__(
|
| 189 |
+
default=default,
|
| 190 |
+
default_factory=default_factory,
|
| 191 |
+
annotation=annotation,
|
| 192 |
+
alias=alias,
|
| 193 |
+
alias_priority=alias_priority,
|
| 194 |
+
validation_alias=validation_alias,
|
| 195 |
+
serialization_alias=serialization_alias,
|
| 196 |
+
title=title,
|
| 197 |
+
description=description,
|
| 198 |
+
gt=gt,
|
| 199 |
+
ge=ge,
|
| 200 |
+
lt=lt,
|
| 201 |
+
le=le,
|
| 202 |
+
min_length=min_length,
|
| 203 |
+
max_length=max_length,
|
| 204 |
+
pattern=pattern,
|
| 205 |
+
regex=regex,
|
| 206 |
+
discriminator=discriminator,
|
| 207 |
+
strict=strict,
|
| 208 |
+
multiple_of=multiple_of,
|
| 209 |
+
allow_inf_nan=allow_inf_nan,
|
| 210 |
+
max_digits=max_digits,
|
| 211 |
+
decimal_places=decimal_places,
|
| 212 |
+
deprecated=deprecated,
|
| 213 |
+
example=example,
|
| 214 |
+
examples=examples,
|
| 215 |
+
openapi_examples=openapi_examples,
|
| 216 |
+
include_in_schema=include_in_schema,
|
| 217 |
+
json_schema_extra=json_schema_extra,
|
| 218 |
+
**extra,
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
class Query(Param): # type: ignore[misc]
|
| 223 |
+
in_ = ParamTypes.query
|
| 224 |
+
|
| 225 |
+
def __init__(
|
| 226 |
+
self,
|
| 227 |
+
default: Any = Undefined,
|
| 228 |
+
*,
|
| 229 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 230 |
+
annotation: Any | None = None,
|
| 231 |
+
alias: str | None = None,
|
| 232 |
+
alias_priority: int | None = _Unset,
|
| 233 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 234 |
+
serialization_alias: str | None = None,
|
| 235 |
+
title: str | None = None,
|
| 236 |
+
description: str | None = None,
|
| 237 |
+
gt: float | None = None,
|
| 238 |
+
ge: float | None = None,
|
| 239 |
+
lt: float | None = None,
|
| 240 |
+
le: float | None = None,
|
| 241 |
+
min_length: int | None = None,
|
| 242 |
+
max_length: int | None = None,
|
| 243 |
+
pattern: str | None = None,
|
| 244 |
+
regex: Annotated[
|
| 245 |
+
str | None,
|
| 246 |
+
deprecated(
|
| 247 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 248 |
+
),
|
| 249 |
+
] = None,
|
| 250 |
+
discriminator: str | None = None,
|
| 251 |
+
strict: bool | None = _Unset,
|
| 252 |
+
multiple_of: float | None = _Unset,
|
| 253 |
+
allow_inf_nan: bool | None = _Unset,
|
| 254 |
+
max_digits: int | None = _Unset,
|
| 255 |
+
decimal_places: int | None = _Unset,
|
| 256 |
+
examples: list[Any] | None = None,
|
| 257 |
+
example: Annotated[
|
| 258 |
+
Any | None,
|
| 259 |
+
deprecated(
|
| 260 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 261 |
+
"although still supported. Use examples instead."
|
| 262 |
+
),
|
| 263 |
+
] = _Unset,
|
| 264 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 265 |
+
deprecated: deprecated | str | bool | None = None,
|
| 266 |
+
include_in_schema: bool = True,
|
| 267 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 268 |
+
**extra: Any,
|
| 269 |
+
):
|
| 270 |
+
super().__init__(
|
| 271 |
+
default=default,
|
| 272 |
+
default_factory=default_factory,
|
| 273 |
+
annotation=annotation,
|
| 274 |
+
alias=alias,
|
| 275 |
+
alias_priority=alias_priority,
|
| 276 |
+
validation_alias=validation_alias,
|
| 277 |
+
serialization_alias=serialization_alias,
|
| 278 |
+
title=title,
|
| 279 |
+
description=description,
|
| 280 |
+
gt=gt,
|
| 281 |
+
ge=ge,
|
| 282 |
+
lt=lt,
|
| 283 |
+
le=le,
|
| 284 |
+
min_length=min_length,
|
| 285 |
+
max_length=max_length,
|
| 286 |
+
pattern=pattern,
|
| 287 |
+
regex=regex,
|
| 288 |
+
discriminator=discriminator,
|
| 289 |
+
strict=strict,
|
| 290 |
+
multiple_of=multiple_of,
|
| 291 |
+
allow_inf_nan=allow_inf_nan,
|
| 292 |
+
max_digits=max_digits,
|
| 293 |
+
decimal_places=decimal_places,
|
| 294 |
+
deprecated=deprecated,
|
| 295 |
+
example=example,
|
| 296 |
+
examples=examples,
|
| 297 |
+
openapi_examples=openapi_examples,
|
| 298 |
+
include_in_schema=include_in_schema,
|
| 299 |
+
json_schema_extra=json_schema_extra,
|
| 300 |
+
**extra,
|
| 301 |
+
)
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
class Header(Param): # type: ignore[misc]
|
| 305 |
+
in_ = ParamTypes.header
|
| 306 |
+
|
| 307 |
+
def __init__(
|
| 308 |
+
self,
|
| 309 |
+
default: Any = Undefined,
|
| 310 |
+
*,
|
| 311 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 312 |
+
annotation: Any | None = None,
|
| 313 |
+
alias: str | None = None,
|
| 314 |
+
alias_priority: int | None = _Unset,
|
| 315 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 316 |
+
serialization_alias: str | None = None,
|
| 317 |
+
convert_underscores: bool = True,
|
| 318 |
+
title: str | None = None,
|
| 319 |
+
description: str | None = None,
|
| 320 |
+
gt: float | None = None,
|
| 321 |
+
ge: float | None = None,
|
| 322 |
+
lt: float | None = None,
|
| 323 |
+
le: float | None = None,
|
| 324 |
+
min_length: int | None = None,
|
| 325 |
+
max_length: int | None = None,
|
| 326 |
+
pattern: str | None = None,
|
| 327 |
+
regex: Annotated[
|
| 328 |
+
str | None,
|
| 329 |
+
deprecated(
|
| 330 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 331 |
+
),
|
| 332 |
+
] = None,
|
| 333 |
+
discriminator: str | None = None,
|
| 334 |
+
strict: bool | None = _Unset,
|
| 335 |
+
multiple_of: float | None = _Unset,
|
| 336 |
+
allow_inf_nan: bool | None = _Unset,
|
| 337 |
+
max_digits: int | None = _Unset,
|
| 338 |
+
decimal_places: int | None = _Unset,
|
| 339 |
+
examples: list[Any] | None = None,
|
| 340 |
+
example: Annotated[
|
| 341 |
+
Any | None,
|
| 342 |
+
deprecated(
|
| 343 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 344 |
+
"although still supported. Use examples instead."
|
| 345 |
+
),
|
| 346 |
+
] = _Unset,
|
| 347 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 348 |
+
deprecated: deprecated | str | bool | None = None,
|
| 349 |
+
include_in_schema: bool = True,
|
| 350 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 351 |
+
**extra: Any,
|
| 352 |
+
):
|
| 353 |
+
self.convert_underscores = convert_underscores
|
| 354 |
+
super().__init__(
|
| 355 |
+
default=default,
|
| 356 |
+
default_factory=default_factory,
|
| 357 |
+
annotation=annotation,
|
| 358 |
+
alias=alias,
|
| 359 |
+
alias_priority=alias_priority,
|
| 360 |
+
validation_alias=validation_alias,
|
| 361 |
+
serialization_alias=serialization_alias,
|
| 362 |
+
title=title,
|
| 363 |
+
description=description,
|
| 364 |
+
gt=gt,
|
| 365 |
+
ge=ge,
|
| 366 |
+
lt=lt,
|
| 367 |
+
le=le,
|
| 368 |
+
min_length=min_length,
|
| 369 |
+
max_length=max_length,
|
| 370 |
+
pattern=pattern,
|
| 371 |
+
regex=regex,
|
| 372 |
+
discriminator=discriminator,
|
| 373 |
+
strict=strict,
|
| 374 |
+
multiple_of=multiple_of,
|
| 375 |
+
allow_inf_nan=allow_inf_nan,
|
| 376 |
+
max_digits=max_digits,
|
| 377 |
+
decimal_places=decimal_places,
|
| 378 |
+
deprecated=deprecated,
|
| 379 |
+
example=example,
|
| 380 |
+
examples=examples,
|
| 381 |
+
openapi_examples=openapi_examples,
|
| 382 |
+
include_in_schema=include_in_schema,
|
| 383 |
+
json_schema_extra=json_schema_extra,
|
| 384 |
+
**extra,
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
class Cookie(Param): # type: ignore[misc]
|
| 389 |
+
in_ = ParamTypes.cookie
|
| 390 |
+
|
| 391 |
+
def __init__(
|
| 392 |
+
self,
|
| 393 |
+
default: Any = Undefined,
|
| 394 |
+
*,
|
| 395 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 396 |
+
annotation: Any | None = None,
|
| 397 |
+
alias: str | None = None,
|
| 398 |
+
alias_priority: int | None = _Unset,
|
| 399 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 400 |
+
serialization_alias: str | None = None,
|
| 401 |
+
title: str | None = None,
|
| 402 |
+
description: str | None = None,
|
| 403 |
+
gt: float | None = None,
|
| 404 |
+
ge: float | None = None,
|
| 405 |
+
lt: float | None = None,
|
| 406 |
+
le: float | None = None,
|
| 407 |
+
min_length: int | None = None,
|
| 408 |
+
max_length: int | None = None,
|
| 409 |
+
pattern: str | None = None,
|
| 410 |
+
regex: Annotated[
|
| 411 |
+
str | None,
|
| 412 |
+
deprecated(
|
| 413 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 414 |
+
),
|
| 415 |
+
] = None,
|
| 416 |
+
discriminator: str | None = None,
|
| 417 |
+
strict: bool | None = _Unset,
|
| 418 |
+
multiple_of: float | None = _Unset,
|
| 419 |
+
allow_inf_nan: bool | None = _Unset,
|
| 420 |
+
max_digits: int | None = _Unset,
|
| 421 |
+
decimal_places: int | None = _Unset,
|
| 422 |
+
examples: list[Any] | None = None,
|
| 423 |
+
example: Annotated[
|
| 424 |
+
Any | None,
|
| 425 |
+
deprecated(
|
| 426 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 427 |
+
"although still supported. Use examples instead."
|
| 428 |
+
),
|
| 429 |
+
] = _Unset,
|
| 430 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 431 |
+
deprecated: deprecated | str | bool | None = None,
|
| 432 |
+
include_in_schema: bool = True,
|
| 433 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 434 |
+
**extra: Any,
|
| 435 |
+
):
|
| 436 |
+
super().__init__(
|
| 437 |
+
default=default,
|
| 438 |
+
default_factory=default_factory,
|
| 439 |
+
annotation=annotation,
|
| 440 |
+
alias=alias,
|
| 441 |
+
alias_priority=alias_priority,
|
| 442 |
+
validation_alias=validation_alias,
|
| 443 |
+
serialization_alias=serialization_alias,
|
| 444 |
+
title=title,
|
| 445 |
+
description=description,
|
| 446 |
+
gt=gt,
|
| 447 |
+
ge=ge,
|
| 448 |
+
lt=lt,
|
| 449 |
+
le=le,
|
| 450 |
+
min_length=min_length,
|
| 451 |
+
max_length=max_length,
|
| 452 |
+
pattern=pattern,
|
| 453 |
+
regex=regex,
|
| 454 |
+
discriminator=discriminator,
|
| 455 |
+
strict=strict,
|
| 456 |
+
multiple_of=multiple_of,
|
| 457 |
+
allow_inf_nan=allow_inf_nan,
|
| 458 |
+
max_digits=max_digits,
|
| 459 |
+
decimal_places=decimal_places,
|
| 460 |
+
deprecated=deprecated,
|
| 461 |
+
example=example,
|
| 462 |
+
examples=examples,
|
| 463 |
+
openapi_examples=openapi_examples,
|
| 464 |
+
include_in_schema=include_in_schema,
|
| 465 |
+
json_schema_extra=json_schema_extra,
|
| 466 |
+
**extra,
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
class Body(FieldInfo): # type: ignore[misc]
|
| 471 |
+
def __init__(
|
| 472 |
+
self,
|
| 473 |
+
default: Any = Undefined,
|
| 474 |
+
*,
|
| 475 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 476 |
+
annotation: Any | None = None,
|
| 477 |
+
embed: bool | None = None,
|
| 478 |
+
media_type: str = "application/json",
|
| 479 |
+
alias: str | None = None,
|
| 480 |
+
alias_priority: int | None = _Unset,
|
| 481 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 482 |
+
serialization_alias: str | None = None,
|
| 483 |
+
title: str | None = None,
|
| 484 |
+
description: str | None = None,
|
| 485 |
+
gt: float | None = None,
|
| 486 |
+
ge: float | None = None,
|
| 487 |
+
lt: float | None = None,
|
| 488 |
+
le: float | None = None,
|
| 489 |
+
min_length: int | None = None,
|
| 490 |
+
max_length: int | None = None,
|
| 491 |
+
pattern: str | None = None,
|
| 492 |
+
regex: Annotated[
|
| 493 |
+
str | None,
|
| 494 |
+
deprecated(
|
| 495 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 496 |
+
),
|
| 497 |
+
] = None,
|
| 498 |
+
discriminator: str | None = None,
|
| 499 |
+
strict: bool | None = _Unset,
|
| 500 |
+
multiple_of: float | None = _Unset,
|
| 501 |
+
allow_inf_nan: bool | None = _Unset,
|
| 502 |
+
max_digits: int | None = _Unset,
|
| 503 |
+
decimal_places: int | None = _Unset,
|
| 504 |
+
examples: list[Any] | None = None,
|
| 505 |
+
example: Annotated[
|
| 506 |
+
Any | None,
|
| 507 |
+
deprecated(
|
| 508 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 509 |
+
"although still supported. Use examples instead."
|
| 510 |
+
),
|
| 511 |
+
] = _Unset,
|
| 512 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 513 |
+
deprecated: deprecated | str | bool | None = None,
|
| 514 |
+
include_in_schema: bool = True,
|
| 515 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 516 |
+
**extra: Any,
|
| 517 |
+
):
|
| 518 |
+
self.embed = embed
|
| 519 |
+
self.media_type = media_type
|
| 520 |
+
if example is not _Unset:
|
| 521 |
+
warnings.warn(
|
| 522 |
+
"`example` has been deprecated, please use `examples` instead",
|
| 523 |
+
category=FastAPIDeprecationWarning,
|
| 524 |
+
stacklevel=4,
|
| 525 |
+
)
|
| 526 |
+
self.example = example
|
| 527 |
+
self.include_in_schema = include_in_schema
|
| 528 |
+
self.openapi_examples = openapi_examples
|
| 529 |
+
kwargs = dict(
|
| 530 |
+
default=default,
|
| 531 |
+
default_factory=default_factory,
|
| 532 |
+
alias=alias,
|
| 533 |
+
title=title,
|
| 534 |
+
description=description,
|
| 535 |
+
gt=gt,
|
| 536 |
+
ge=ge,
|
| 537 |
+
lt=lt,
|
| 538 |
+
le=le,
|
| 539 |
+
min_length=min_length,
|
| 540 |
+
max_length=max_length,
|
| 541 |
+
discriminator=discriminator,
|
| 542 |
+
multiple_of=multiple_of,
|
| 543 |
+
allow_inf_nan=allow_inf_nan,
|
| 544 |
+
max_digits=max_digits,
|
| 545 |
+
decimal_places=decimal_places,
|
| 546 |
+
**extra,
|
| 547 |
+
)
|
| 548 |
+
if examples is not None:
|
| 549 |
+
kwargs["examples"] = examples
|
| 550 |
+
if regex is not None:
|
| 551 |
+
warnings.warn(
|
| 552 |
+
"`regex` has been deprecated, please use `pattern` instead",
|
| 553 |
+
category=FastAPIDeprecationWarning,
|
| 554 |
+
stacklevel=4,
|
| 555 |
+
)
|
| 556 |
+
current_json_schema_extra = json_schema_extra or extra
|
| 557 |
+
kwargs["deprecated"] = deprecated
|
| 558 |
+
if serialization_alias in (_Unset, None) and isinstance(alias, str):
|
| 559 |
+
serialization_alias = alias
|
| 560 |
+
if validation_alias in (_Unset, None):
|
| 561 |
+
validation_alias = alias
|
| 562 |
+
kwargs.update(
|
| 563 |
+
{
|
| 564 |
+
"annotation": annotation,
|
| 565 |
+
"alias_priority": alias_priority,
|
| 566 |
+
"validation_alias": validation_alias,
|
| 567 |
+
"serialization_alias": serialization_alias,
|
| 568 |
+
"strict": strict,
|
| 569 |
+
"json_schema_extra": current_json_schema_extra,
|
| 570 |
+
}
|
| 571 |
+
)
|
| 572 |
+
kwargs["pattern"] = pattern or regex
|
| 573 |
+
|
| 574 |
+
use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset}
|
| 575 |
+
|
| 576 |
+
super().__init__(**use_kwargs)
|
| 577 |
+
|
| 578 |
+
def __repr__(self) -> str:
|
| 579 |
+
return f"{self.__class__.__name__}({self.default})"
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
class Form(Body): # type: ignore[misc]
|
| 583 |
+
def __init__(
|
| 584 |
+
self,
|
| 585 |
+
default: Any = Undefined,
|
| 586 |
+
*,
|
| 587 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 588 |
+
annotation: Any | None = None,
|
| 589 |
+
media_type: str = "application/x-www-form-urlencoded",
|
| 590 |
+
alias: str | None = None,
|
| 591 |
+
alias_priority: int | None = _Unset,
|
| 592 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 593 |
+
serialization_alias: str | None = None,
|
| 594 |
+
title: str | None = None,
|
| 595 |
+
description: str | None = None,
|
| 596 |
+
gt: float | None = None,
|
| 597 |
+
ge: float | None = None,
|
| 598 |
+
lt: float | None = None,
|
| 599 |
+
le: float | None = None,
|
| 600 |
+
min_length: int | None = None,
|
| 601 |
+
max_length: int | None = None,
|
| 602 |
+
pattern: str | None = None,
|
| 603 |
+
regex: Annotated[
|
| 604 |
+
str | None,
|
| 605 |
+
deprecated(
|
| 606 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 607 |
+
),
|
| 608 |
+
] = None,
|
| 609 |
+
discriminator: str | None = None,
|
| 610 |
+
strict: bool | None = _Unset,
|
| 611 |
+
multiple_of: float | None = _Unset,
|
| 612 |
+
allow_inf_nan: bool | None = _Unset,
|
| 613 |
+
max_digits: int | None = _Unset,
|
| 614 |
+
decimal_places: int | None = _Unset,
|
| 615 |
+
examples: list[Any] | None = None,
|
| 616 |
+
example: Annotated[
|
| 617 |
+
Any | None,
|
| 618 |
+
deprecated(
|
| 619 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 620 |
+
"although still supported. Use examples instead."
|
| 621 |
+
),
|
| 622 |
+
] = _Unset,
|
| 623 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 624 |
+
deprecated: deprecated | str | bool | None = None,
|
| 625 |
+
include_in_schema: bool = True,
|
| 626 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 627 |
+
**extra: Any,
|
| 628 |
+
):
|
| 629 |
+
super().__init__(
|
| 630 |
+
default=default,
|
| 631 |
+
default_factory=default_factory,
|
| 632 |
+
annotation=annotation,
|
| 633 |
+
media_type=media_type,
|
| 634 |
+
alias=alias,
|
| 635 |
+
alias_priority=alias_priority,
|
| 636 |
+
validation_alias=validation_alias,
|
| 637 |
+
serialization_alias=serialization_alias,
|
| 638 |
+
title=title,
|
| 639 |
+
description=description,
|
| 640 |
+
gt=gt,
|
| 641 |
+
ge=ge,
|
| 642 |
+
lt=lt,
|
| 643 |
+
le=le,
|
| 644 |
+
min_length=min_length,
|
| 645 |
+
max_length=max_length,
|
| 646 |
+
pattern=pattern,
|
| 647 |
+
regex=regex,
|
| 648 |
+
discriminator=discriminator,
|
| 649 |
+
strict=strict,
|
| 650 |
+
multiple_of=multiple_of,
|
| 651 |
+
allow_inf_nan=allow_inf_nan,
|
| 652 |
+
max_digits=max_digits,
|
| 653 |
+
decimal_places=decimal_places,
|
| 654 |
+
deprecated=deprecated,
|
| 655 |
+
example=example,
|
| 656 |
+
examples=examples,
|
| 657 |
+
openapi_examples=openapi_examples,
|
| 658 |
+
include_in_schema=include_in_schema,
|
| 659 |
+
json_schema_extra=json_schema_extra,
|
| 660 |
+
**extra,
|
| 661 |
+
)
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
class File(Form): # type: ignore[misc]
|
| 665 |
+
def __init__(
|
| 666 |
+
self,
|
| 667 |
+
default: Any = Undefined,
|
| 668 |
+
*,
|
| 669 |
+
default_factory: Callable[[], Any] | None = _Unset,
|
| 670 |
+
annotation: Any | None = None,
|
| 671 |
+
media_type: str = "multipart/form-data",
|
| 672 |
+
alias: str | None = None,
|
| 673 |
+
alias_priority: int | None = _Unset,
|
| 674 |
+
validation_alias: str | AliasPath | AliasChoices | None = None,
|
| 675 |
+
serialization_alias: str | None = None,
|
| 676 |
+
title: str | None = None,
|
| 677 |
+
description: str | None = None,
|
| 678 |
+
gt: float | None = None,
|
| 679 |
+
ge: float | None = None,
|
| 680 |
+
lt: float | None = None,
|
| 681 |
+
le: float | None = None,
|
| 682 |
+
min_length: int | None = None,
|
| 683 |
+
max_length: int | None = None,
|
| 684 |
+
pattern: str | None = None,
|
| 685 |
+
regex: Annotated[
|
| 686 |
+
str | None,
|
| 687 |
+
deprecated(
|
| 688 |
+
"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
|
| 689 |
+
),
|
| 690 |
+
] = None,
|
| 691 |
+
discriminator: str | None = None,
|
| 692 |
+
strict: bool | None = _Unset,
|
| 693 |
+
multiple_of: float | None = _Unset,
|
| 694 |
+
allow_inf_nan: bool | None = _Unset,
|
| 695 |
+
max_digits: int | None = _Unset,
|
| 696 |
+
decimal_places: int | None = _Unset,
|
| 697 |
+
examples: list[Any] | None = None,
|
| 698 |
+
example: Annotated[
|
| 699 |
+
Any | None,
|
| 700 |
+
deprecated(
|
| 701 |
+
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
|
| 702 |
+
"although still supported. Use examples instead."
|
| 703 |
+
),
|
| 704 |
+
] = _Unset,
|
| 705 |
+
openapi_examples: dict[str, Example] | None = None,
|
| 706 |
+
deprecated: deprecated | str | bool | None = None,
|
| 707 |
+
include_in_schema: bool = True,
|
| 708 |
+
json_schema_extra: dict[str, Any] | None = None,
|
| 709 |
+
**extra: Any,
|
| 710 |
+
):
|
| 711 |
+
super().__init__(
|
| 712 |
+
default=default,
|
| 713 |
+
default_factory=default_factory,
|
| 714 |
+
annotation=annotation,
|
| 715 |
+
media_type=media_type,
|
| 716 |
+
alias=alias,
|
| 717 |
+
alias_priority=alias_priority,
|
| 718 |
+
validation_alias=validation_alias,
|
| 719 |
+
serialization_alias=serialization_alias,
|
| 720 |
+
title=title,
|
| 721 |
+
description=description,
|
| 722 |
+
gt=gt,
|
| 723 |
+
ge=ge,
|
| 724 |
+
lt=lt,
|
| 725 |
+
le=le,
|
| 726 |
+
min_length=min_length,
|
| 727 |
+
max_length=max_length,
|
| 728 |
+
pattern=pattern,
|
| 729 |
+
regex=regex,
|
| 730 |
+
discriminator=discriminator,
|
| 731 |
+
strict=strict,
|
| 732 |
+
multiple_of=multiple_of,
|
| 733 |
+
allow_inf_nan=allow_inf_nan,
|
| 734 |
+
max_digits=max_digits,
|
| 735 |
+
decimal_places=decimal_places,
|
| 736 |
+
deprecated=deprecated,
|
| 737 |
+
example=example,
|
| 738 |
+
examples=examples,
|
| 739 |
+
openapi_examples=openapi_examples,
|
| 740 |
+
include_in_schema=include_in_schema,
|
| 741 |
+
json_schema_extra=json_schema_extra,
|
| 742 |
+
**extra,
|
| 743 |
+
)
|
| 744 |
+
|
| 745 |
+
|
| 746 |
+
@dataclass(frozen=True)
|
| 747 |
+
class Depends:
|
| 748 |
+
dependency: Callable[..., Any] | None = None
|
| 749 |
+
use_cache: bool = True
|
| 750 |
+
scope: Literal["function", "request"] | None = None
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
@dataclass(frozen=True)
|
| 754 |
+
class Security(Depends):
|
| 755 |
+
scopes: Sequence[str] | None = None
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/py.typed
ADDED
|
File without changes
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/requests.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from starlette.requests import HTTPConnection as HTTPConnection # noqa: F401
|
| 2 |
+
from starlette.requests import Request as Request # noqa: F401
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/responses.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
from fastapi.exceptions import FastAPIDeprecationWarning
|
| 4 |
+
from starlette.responses import FileResponse as FileResponse # noqa
|
| 5 |
+
from starlette.responses import HTMLResponse as HTMLResponse # noqa
|
| 6 |
+
from starlette.responses import JSONResponse as JSONResponse # noqa
|
| 7 |
+
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
|
| 8 |
+
from starlette.responses import RedirectResponse as RedirectResponse # noqa
|
| 9 |
+
from starlette.responses import Response as Response # noqa
|
| 10 |
+
from starlette.responses import StreamingResponse as StreamingResponse # noqa
|
| 11 |
+
from typing_extensions import deprecated
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
import ujson
|
| 15 |
+
except ImportError: # pragma: nocover
|
| 16 |
+
ujson = None # type: ignore
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
import orjson
|
| 21 |
+
except ImportError: # pragma: nocover
|
| 22 |
+
orjson = None # type: ignore
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@deprecated(
|
| 26 |
+
"UJSONResponse is deprecated, FastAPI now serializes data directly to JSON "
|
| 27 |
+
"bytes via Pydantic when a return type or response model is set, which is "
|
| 28 |
+
"faster and doesn't need a custom response class. Read more in the FastAPI "
|
| 29 |
+
"docs: https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model "
|
| 30 |
+
"and https://fastapi.tiangolo.com/tutorial/response-model/",
|
| 31 |
+
category=FastAPIDeprecationWarning,
|
| 32 |
+
stacklevel=2,
|
| 33 |
+
)
|
| 34 |
+
class UJSONResponse(JSONResponse):
|
| 35 |
+
"""JSON response using the ujson library to serialize data to JSON.
|
| 36 |
+
|
| 37 |
+
**Deprecated**: `UJSONResponse` is deprecated. FastAPI now serializes data
|
| 38 |
+
directly to JSON bytes via Pydantic when a return type or response model is
|
| 39 |
+
set, which is faster and doesn't need a custom response class.
|
| 40 |
+
|
| 41 |
+
Read more in the
|
| 42 |
+
[FastAPI docs for Custom Response](https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model)
|
| 43 |
+
and the
|
| 44 |
+
[FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/).
|
| 45 |
+
|
| 46 |
+
**Note**: `ujson` is not included with FastAPI and must be installed
|
| 47 |
+
separately, e.g. `pip install ujson`.
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
def render(self, content: Any) -> bytes:
|
| 51 |
+
assert ujson is not None, "ujson must be installed to use UJSONResponse"
|
| 52 |
+
return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@deprecated(
|
| 56 |
+
"ORJSONResponse is deprecated, FastAPI now serializes data directly to JSON "
|
| 57 |
+
"bytes via Pydantic when a return type or response model is set, which is "
|
| 58 |
+
"faster and doesn't need a custom response class. Read more in the FastAPI "
|
| 59 |
+
"docs: https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model "
|
| 60 |
+
"and https://fastapi.tiangolo.com/tutorial/response-model/",
|
| 61 |
+
category=FastAPIDeprecationWarning,
|
| 62 |
+
stacklevel=2,
|
| 63 |
+
)
|
| 64 |
+
class ORJSONResponse(JSONResponse):
|
| 65 |
+
"""JSON response using the orjson library to serialize data to JSON.
|
| 66 |
+
|
| 67 |
+
**Deprecated**: `ORJSONResponse` is deprecated. FastAPI now serializes data
|
| 68 |
+
directly to JSON bytes via Pydantic when a return type or response model is
|
| 69 |
+
set, which is faster and doesn't need a custom response class.
|
| 70 |
+
|
| 71 |
+
Read more in the
|
| 72 |
+
[FastAPI docs for Custom Response](https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model)
|
| 73 |
+
and the
|
| 74 |
+
[FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/).
|
| 75 |
+
|
| 76 |
+
**Note**: `orjson` is not included with FastAPI and must be installed
|
| 77 |
+
separately, e.g. `pip install orjson`.
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
def render(self, content: Any) -> bytes:
|
| 81 |
+
assert orjson is not None, "orjson must be installed to use ORJSONResponse"
|
| 82 |
+
return orjson.dumps(
|
| 83 |
+
content, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY
|
| 84 |
+
)
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/routing.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/staticfiles.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from starlette.staticfiles import StaticFiles as StaticFiles # noqa
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/templating.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from starlette.templating import Jinja2Templates as Jinja2Templates # noqa
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/testclient.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from starlette.testclient import TestClient as TestClient # noqa
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/types.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import types
|
| 2 |
+
from collections.abc import Callable
|
| 3 |
+
from enum import Enum
|
| 4 |
+
from typing import Any, TypeVar, Union
|
| 5 |
+
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
+
from pydantic.main import IncEx as IncEx
|
| 8 |
+
|
| 9 |
+
DecoratedCallable = TypeVar("DecoratedCallable", bound=Callable[..., Any])
|
| 10 |
+
UnionType = getattr(types, "UnionType", Union)
|
| 11 |
+
ModelNameMap = dict[type[BaseModel] | type[Enum], str]
|
| 12 |
+
DependencyCacheKey = tuple[Callable[..., Any] | None, tuple[str, ...], str]
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/utils.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import warnings
|
| 3 |
+
from typing import (
|
| 4 |
+
TYPE_CHECKING,
|
| 5 |
+
Any,
|
| 6 |
+
Literal,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
import fastapi
|
| 10 |
+
from fastapi._compat import (
|
| 11 |
+
ModelField,
|
| 12 |
+
PydanticSchemaGenerationError,
|
| 13 |
+
Undefined,
|
| 14 |
+
annotation_is_pydantic_v1,
|
| 15 |
+
)
|
| 16 |
+
from fastapi.datastructures import DefaultPlaceholder, DefaultType
|
| 17 |
+
from fastapi.exceptions import FastAPIDeprecationWarning, PydanticV1NotSupportedError
|
| 18 |
+
from pydantic.fields import FieldInfo
|
| 19 |
+
|
| 20 |
+
from ._compat import v2
|
| 21 |
+
|
| 22 |
+
if TYPE_CHECKING: # pragma: nocover
|
| 23 |
+
from .routing import APIRoute
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def is_body_allowed_for_status_code(status_code: int | str | None) -> bool:
|
| 27 |
+
if status_code is None:
|
| 28 |
+
return True
|
| 29 |
+
# Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#patterned-fields-1
|
| 30 |
+
if status_code in {
|
| 31 |
+
"default",
|
| 32 |
+
"1XX",
|
| 33 |
+
"2XX",
|
| 34 |
+
"3XX",
|
| 35 |
+
"4XX",
|
| 36 |
+
"5XX",
|
| 37 |
+
}:
|
| 38 |
+
return True
|
| 39 |
+
current_status_code = int(status_code)
|
| 40 |
+
return not (current_status_code < 200 or current_status_code in {204, 205, 304})
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def get_path_param_names(path: str) -> set[str]:
|
| 44 |
+
return set(re.findall("{(.*?)}", path))
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
_invalid_args_message = (
|
| 48 |
+
"Invalid args for response field! Hint: "
|
| 49 |
+
"check that {type_} is a valid Pydantic field type. "
|
| 50 |
+
"If you are using a return type annotation that is not a valid Pydantic "
|
| 51 |
+
"field (e.g. Union[Response, dict, None]) you can disable generating the "
|
| 52 |
+
"response model from the type annotation with the path operation decorator "
|
| 53 |
+
"parameter response_model=None. Read more: "
|
| 54 |
+
"https://fastapi.tiangolo.com/tutorial/response-model/"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def create_model_field(
|
| 59 |
+
name: str,
|
| 60 |
+
type_: Any,
|
| 61 |
+
default: Any | None = Undefined,
|
| 62 |
+
field_info: FieldInfo | None = None,
|
| 63 |
+
alias: str | None = None,
|
| 64 |
+
mode: Literal["validation", "serialization"] = "validation",
|
| 65 |
+
) -> ModelField:
|
| 66 |
+
if annotation_is_pydantic_v1(type_):
|
| 67 |
+
raise PydanticV1NotSupportedError(
|
| 68 |
+
"pydantic.v1 models are no longer supported by FastAPI."
|
| 69 |
+
f" Please update the response model {type_!r}."
|
| 70 |
+
)
|
| 71 |
+
field_info = field_info or FieldInfo(annotation=type_, default=default, alias=alias)
|
| 72 |
+
try:
|
| 73 |
+
return v2.ModelField(mode=mode, name=name, field_info=field_info)
|
| 74 |
+
except PydanticSchemaGenerationError:
|
| 75 |
+
raise fastapi.exceptions.FastAPIError(
|
| 76 |
+
_invalid_args_message.format(type_=type_)
|
| 77 |
+
) from None
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def generate_operation_id_for_path(
|
| 81 |
+
*, name: str, path: str, method: str
|
| 82 |
+
) -> str: # pragma: nocover
|
| 83 |
+
warnings.warn(
|
| 84 |
+
message="fastapi.utils.generate_operation_id_for_path() was deprecated, "
|
| 85 |
+
"it is not used internally, and will be removed soon",
|
| 86 |
+
category=FastAPIDeprecationWarning,
|
| 87 |
+
stacklevel=2,
|
| 88 |
+
)
|
| 89 |
+
operation_id = f"{name}{path}"
|
| 90 |
+
operation_id = re.sub(r"\W", "_", operation_id)
|
| 91 |
+
operation_id = f"{operation_id}_{method.lower()}"
|
| 92 |
+
return operation_id
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def generate_unique_id(route: "APIRoute") -> str:
|
| 96 |
+
operation_id = f"{route.name}{route.path_format}"
|
| 97 |
+
operation_id = re.sub(r"\W", "_", operation_id)
|
| 98 |
+
assert route.methods
|
| 99 |
+
operation_id = f"{operation_id}_{list(route.methods)[0].lower()}"
|
| 100 |
+
return operation_id
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def deep_dict_update(main_dict: dict[Any, Any], update_dict: dict[Any, Any]) -> None:
|
| 104 |
+
for key, value in update_dict.items():
|
| 105 |
+
if (
|
| 106 |
+
key in main_dict
|
| 107 |
+
and isinstance(main_dict[key], dict)
|
| 108 |
+
and isinstance(value, dict)
|
| 109 |
+
):
|
| 110 |
+
deep_dict_update(main_dict[key], value)
|
| 111 |
+
elif (
|
| 112 |
+
key in main_dict
|
| 113 |
+
and isinstance(main_dict[key], list)
|
| 114 |
+
and isinstance(update_dict[key], list)
|
| 115 |
+
):
|
| 116 |
+
main_dict[key] = main_dict[key] + update_dict[key]
|
| 117 |
+
else:
|
| 118 |
+
main_dict[key] = value
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def get_value_or_default(
|
| 122 |
+
first_item: DefaultPlaceholder | DefaultType,
|
| 123 |
+
*extra_items: DefaultPlaceholder | DefaultType,
|
| 124 |
+
) -> DefaultPlaceholder | DefaultType:
|
| 125 |
+
"""
|
| 126 |
+
Pass items or `DefaultPlaceholder`s by descending priority.
|
| 127 |
+
|
| 128 |
+
The first one to _not_ be a `DefaultPlaceholder` will be returned.
|
| 129 |
+
|
| 130 |
+
Otherwise, the first item (a `DefaultPlaceholder`) will be returned.
|
| 131 |
+
"""
|
| 132 |
+
items = (first_item,) + extra_items
|
| 133 |
+
for item in items:
|
| 134 |
+
if not isinstance(item, DefaultPlaceholder):
|
| 135 |
+
return item
|
| 136 |
+
return first_item
|
TTS/Kokoro/.venv/Lib/site-packages/fastapi/websockets.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from starlette.websockets import WebSocket as WebSocket # noqa
|
| 2 |
+
from starlette.websockets import WebSocketDisconnect as WebSocketDisconnect # noqa
|
| 3 |
+
from starlette.websockets import WebSocketState as WebSocketState # noqa
|
TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/METADATA
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: filelock
|
| 3 |
+
Version: 3.24.3
|
| 4 |
+
Summary: A platform independent file lock.
|
| 5 |
+
Project-URL: Documentation, https://py-filelock.readthedocs.io
|
| 6 |
+
Project-URL: Homepage, https://github.com/tox-dev/py-filelock
|
| 7 |
+
Project-URL: Source, https://github.com/tox-dev/py-filelock
|
| 8 |
+
Project-URL: Tracker, https://github.com/tox-dev/py-filelock/issues
|
| 9 |
+
Maintainer-email: Bernát Gábor <gaborjbernat@gmail.com>
|
| 10 |
+
License-Expression: MIT
|
| 11 |
+
License-File: LICENSE
|
| 12 |
+
Keywords: application,cache,directory,log,user
|
| 13 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 14 |
+
Classifier: Intended Audience :: Developers
|
| 15 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 16 |
+
Classifier: Operating System :: OS Independent
|
| 17 |
+
Classifier: Programming Language :: Python
|
| 18 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 24 |
+
Classifier: Topic :: Internet
|
| 25 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 26 |
+
Classifier: Topic :: System
|
| 27 |
+
Requires-Python: >=3.10
|
| 28 |
+
Description-Content-Type: text/markdown
|
| 29 |
+
|
| 30 |
+
# filelock
|
| 31 |
+
|
| 32 |
+
[](https://pypi.org/project/filelock/)
|
| 33 |
+
[](https://pypi.org/project/filelock/)
|
| 34 |
+
[](https://py-filelock.readthedocs.io/en/latest/?badge=latest)
|
| 35 |
+
[](https://pepy.tech/project/filelock)
|
| 36 |
+
[](https://github.com/tox-dev/py-filelock/actions/workflows/check.yaml)
|
| 37 |
+
|
| 38 |
+
For more information checkout the [official documentation](https://py-filelock.readthedocs.io/en/latest/index.html).
|
TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/RECORD
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
filelock-3.24.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
filelock-3.24.3.dist-info/METADATA,sha256=2SzY43viecqbmVNOokZgXcYTE04sufy5Rjf6wZTMWC4,1977
|
| 3 |
+
filelock-3.24.3.dist-info/RECORD,,
|
| 4 |
+
filelock-3.24.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
| 5 |
+
filelock-3.24.3.dist-info/licenses/LICENSE,sha256=YIyJ1QYK6ZIa3M8yNmlbxlSplG4SMj72wCHfoE4pTUg,1088
|
| 6 |
+
filelock/__init__.py,sha256=12pKiL8AjSCkmWLozJhcCg6qQY70_XizYh9AHUvzZ1Q,2009
|
| 7 |
+
filelock/__pycache__/__init__.cpython-312.pyc,,
|
| 8 |
+
filelock/__pycache__/_api.cpython-312.pyc,,
|
| 9 |
+
filelock/__pycache__/_error.cpython-312.pyc,,
|
| 10 |
+
filelock/__pycache__/_read_write.cpython-312.pyc,,
|
| 11 |
+
filelock/__pycache__/_soft.cpython-312.pyc,,
|
| 12 |
+
filelock/__pycache__/_unix.cpython-312.pyc,,
|
| 13 |
+
filelock/__pycache__/_util.cpython-312.pyc,,
|
| 14 |
+
filelock/__pycache__/_windows.cpython-312.pyc,,
|
| 15 |
+
filelock/__pycache__/asyncio.cpython-312.pyc,,
|
| 16 |
+
filelock/__pycache__/version.cpython-312.pyc,,
|
| 17 |
+
filelock/_api.py,sha256=l8P7bqosgleI3vPn8OVGQ0-sa2d3WVhvM_j9SCCcTx4,21159
|
| 18 |
+
filelock/_error.py,sha256=mnelOh0EVyVeskG3rksL4kW3OArL4TMb2-PwmzQWIFg,788
|
| 19 |
+
filelock/_read_write.py,sha256=o6pcX04--nXFspDXtV_J113EDH_-rzz-Hvp-cmH76P4,15313
|
| 20 |
+
filelock/_soft.py,sha256=8aSSoyLZjBDV-ql3LJt_Ec_kg7ywHDE8ZZFcCtVWxQ8,4665
|
| 21 |
+
filelock/_unix.py,sha256=DL0mk9OAE21wY-uhdClJ2ezBUFfi-vNszdBJCw7slqE,4233
|
| 22 |
+
filelock/_util.py,sha256=wPf-LvzmdHWHw4DinDeVJlB0GNVOYGNUeNKSnHBQuUU,1716
|
| 23 |
+
filelock/_windows.py,sha256=-CEBIFfFPwmfSSmTmbbGzgUR30E0jBacBW9j4_ER0YM,3508
|
| 24 |
+
filelock/asyncio.py,sha256=NvrDsqS095NZc16l_OjBQcTY-D6xB4Vy7AK3ni8tr8A,13943
|
| 25 |
+
filelock/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 26 |
+
filelock/version.py,sha256=cEVcBJgzKOmekaY1NFrR1sXy1-sBY4F7inrTVfovZUA,706
|
TTS/Kokoro/.venv/Lib/site-packages/filelock-3.24.3.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: hatchling 1.28.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/__init__.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A platform independent file lock that supports the with-statement.
|
| 3 |
+
|
| 4 |
+
.. autodata:: filelock.__version__
|
| 5 |
+
:no-value:
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import sys
|
| 12 |
+
import warnings
|
| 13 |
+
from typing import TYPE_CHECKING
|
| 14 |
+
|
| 15 |
+
from ._api import AcquireReturnProxy, BaseFileLock
|
| 16 |
+
from ._error import Timeout
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
from ._read_write import ReadWriteLock
|
| 20 |
+
except ImportError: # sqlite3 may be unavailable if Python was built without it or the C library is missing
|
| 21 |
+
ReadWriteLock = None # type: ignore[assignment, misc]
|
| 22 |
+
|
| 23 |
+
from ._soft import SoftFileLock
|
| 24 |
+
from ._unix import UnixFileLock, has_fcntl
|
| 25 |
+
from ._windows import WindowsFileLock
|
| 26 |
+
from .asyncio import (
|
| 27 |
+
AsyncAcquireReturnProxy,
|
| 28 |
+
AsyncSoftFileLock,
|
| 29 |
+
AsyncUnixFileLock,
|
| 30 |
+
AsyncWindowsFileLock,
|
| 31 |
+
BaseAsyncFileLock,
|
| 32 |
+
)
|
| 33 |
+
from .version import version
|
| 34 |
+
|
| 35 |
+
#: version of the project as a string
|
| 36 |
+
__version__: str = version
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 40 |
+
_FileLock: type[BaseFileLock] = WindowsFileLock
|
| 41 |
+
_AsyncFileLock: type[BaseAsyncFileLock] = AsyncWindowsFileLock
|
| 42 |
+
else: # pragma: win32 no cover # noqa: PLR5501
|
| 43 |
+
if has_fcntl:
|
| 44 |
+
_FileLock: type[BaseFileLock] = UnixFileLock
|
| 45 |
+
_AsyncFileLock: type[BaseAsyncFileLock] = AsyncUnixFileLock
|
| 46 |
+
else:
|
| 47 |
+
_FileLock = SoftFileLock
|
| 48 |
+
_AsyncFileLock = AsyncSoftFileLock
|
| 49 |
+
if warnings is not None:
|
| 50 |
+
warnings.warn("only soft file lock is available", stacklevel=2)
|
| 51 |
+
|
| 52 |
+
if TYPE_CHECKING:
|
| 53 |
+
FileLock = SoftFileLock
|
| 54 |
+
AsyncFileLock = AsyncSoftFileLock
|
| 55 |
+
else:
|
| 56 |
+
#: Alias for the lock, which should be used for the current platform.
|
| 57 |
+
FileLock = _FileLock
|
| 58 |
+
AsyncFileLock = _AsyncFileLock
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
__all__ = [
|
| 62 |
+
"AcquireReturnProxy",
|
| 63 |
+
"AsyncAcquireReturnProxy",
|
| 64 |
+
"AsyncFileLock",
|
| 65 |
+
"AsyncSoftFileLock",
|
| 66 |
+
"AsyncUnixFileLock",
|
| 67 |
+
"AsyncWindowsFileLock",
|
| 68 |
+
"BaseAsyncFileLock",
|
| 69 |
+
"BaseFileLock",
|
| 70 |
+
"FileLock",
|
| 71 |
+
"ReadWriteLock",
|
| 72 |
+
"SoftFileLock",
|
| 73 |
+
"Timeout",
|
| 74 |
+
"UnixFileLock",
|
| 75 |
+
"WindowsFileLock",
|
| 76 |
+
"__version__",
|
| 77 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/_api.py
ADDED
|
@@ -0,0 +1,578 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import inspect
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import sys
|
| 9 |
+
import time
|
| 10 |
+
import warnings
|
| 11 |
+
from abc import ABCMeta, abstractmethod
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from threading import local
|
| 14 |
+
from typing import TYPE_CHECKING, Any, cast
|
| 15 |
+
from weakref import WeakValueDictionary
|
| 16 |
+
|
| 17 |
+
from ._error import Timeout
|
| 18 |
+
|
| 19 |
+
#: Sentinel indicating that no explicit file permission mode was passed.
|
| 20 |
+
#: When used, lock files are created with 0o666 (letting umask and default ACLs control the final permissions)
|
| 21 |
+
#: and fchmod is skipped so that POSIX default ACL inheritance is preserved.
|
| 22 |
+
_UNSET_FILE_MODE: int = -1
|
| 23 |
+
|
| 24 |
+
if TYPE_CHECKING:
|
| 25 |
+
from collections.abc import Callable
|
| 26 |
+
from types import TracebackType
|
| 27 |
+
|
| 28 |
+
from ._read_write import ReadWriteLock
|
| 29 |
+
|
| 30 |
+
if sys.version_info >= (3, 11): # pragma: no cover (py311+)
|
| 31 |
+
from typing import Self
|
| 32 |
+
else: # pragma: no cover (<py311)
|
| 33 |
+
from typing_extensions import Self
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
_LOGGER = logging.getLogger("filelock")
|
| 37 |
+
|
| 38 |
+
# On Windows os.path.realpath calls CreateFileW with share_mode=0, which blocks concurrent DeleteFileW and causes
|
| 39 |
+
# livelocks under threaded contention with SoftFileLock. os.path.abspath is purely string-based and avoids this.
|
| 40 |
+
_canonical = os.path.abspath if sys.platform == "win32" else os.path.realpath
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class _ThreadLocalRegistry(local):
|
| 44 |
+
def __init__(self) -> None:
|
| 45 |
+
super().__init__()
|
| 46 |
+
self.held: dict[str, int] = {}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
_registry = _ThreadLocalRegistry()
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# This is a helper class which is returned by :meth:`BaseFileLock.acquire` and wraps the lock to make sure __enter__
|
| 53 |
+
# is not called twice when entering the with statement. If we would simply return *self*, the lock would be acquired
|
| 54 |
+
# again in the *__enter__* method of the BaseFileLock, but not released again automatically. issue #37 (memory leak)
|
| 55 |
+
class AcquireReturnProxy:
|
| 56 |
+
"""A context-aware object that will release the lock file when exiting."""
|
| 57 |
+
|
| 58 |
+
def __init__(self, lock: BaseFileLock | ReadWriteLock) -> None:
|
| 59 |
+
self.lock: BaseFileLock | ReadWriteLock = lock
|
| 60 |
+
|
| 61 |
+
def __enter__(self) -> BaseFileLock | ReadWriteLock:
|
| 62 |
+
return self.lock
|
| 63 |
+
|
| 64 |
+
def __exit__(
|
| 65 |
+
self,
|
| 66 |
+
exc_type: type[BaseException] | None,
|
| 67 |
+
exc_value: BaseException | None,
|
| 68 |
+
traceback: TracebackType | None,
|
| 69 |
+
) -> None:
|
| 70 |
+
self.lock.release()
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@dataclass
|
| 74 |
+
class FileLockContext:
|
| 75 |
+
"""A dataclass which holds the context for a ``BaseFileLock`` object."""
|
| 76 |
+
|
| 77 |
+
# The context is held in a separate class to allow optional use of thread local storage via the
|
| 78 |
+
# ThreadLocalFileContext class.
|
| 79 |
+
|
| 80 |
+
#: The path to the lock file.
|
| 81 |
+
lock_file: str
|
| 82 |
+
|
| 83 |
+
#: The default timeout value.
|
| 84 |
+
timeout: float
|
| 85 |
+
|
| 86 |
+
#: The mode for the lock files
|
| 87 |
+
mode: int
|
| 88 |
+
|
| 89 |
+
#: Whether the lock should be blocking or not
|
| 90 |
+
blocking: bool
|
| 91 |
+
|
| 92 |
+
#: The default polling interval value.
|
| 93 |
+
poll_interval: float
|
| 94 |
+
|
| 95 |
+
#: The lock lifetime in seconds; ``None`` means the lock never expires.
|
| 96 |
+
lifetime: float | None = None
|
| 97 |
+
|
| 98 |
+
#: The file descriptor for the *_lock_file* as it is returned by the os.open() function, not None when lock held
|
| 99 |
+
lock_file_fd: int | None = None
|
| 100 |
+
|
| 101 |
+
#: The lock counter is used for implementing the nested locking mechanism.
|
| 102 |
+
lock_counter: int = 0 # When the lock is acquired is increased and the lock is only released, when this value is 0
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class ThreadLocalFileContext(FileLockContext, local):
|
| 106 |
+
"""A thread local version of the ``FileLockContext`` class."""
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class FileLockMeta(ABCMeta):
|
| 110 |
+
_instances: WeakValueDictionary[str, BaseFileLock]
|
| 111 |
+
|
| 112 |
+
def __call__( # noqa: PLR0913
|
| 113 |
+
cls,
|
| 114 |
+
lock_file: str | os.PathLike[str],
|
| 115 |
+
timeout: float = -1,
|
| 116 |
+
mode: int = _UNSET_FILE_MODE,
|
| 117 |
+
thread_local: bool = True, # noqa: FBT001, FBT002
|
| 118 |
+
*,
|
| 119 |
+
blocking: bool = True,
|
| 120 |
+
is_singleton: bool = False,
|
| 121 |
+
poll_interval: float = 0.05,
|
| 122 |
+
lifetime: float | None = None,
|
| 123 |
+
**kwargs: Any, # capture remaining kwargs for subclasses # noqa: ANN401
|
| 124 |
+
) -> BaseFileLock:
|
| 125 |
+
if is_singleton:
|
| 126 |
+
instance = cls._instances.get(str(lock_file))
|
| 127 |
+
if instance:
|
| 128 |
+
params_to_check = {
|
| 129 |
+
"thread_local": (thread_local, instance.is_thread_local()),
|
| 130 |
+
"timeout": (timeout, instance.timeout),
|
| 131 |
+
"mode": (mode, instance._context.mode), # noqa: SLF001
|
| 132 |
+
"blocking": (blocking, instance.blocking),
|
| 133 |
+
"poll_interval": (poll_interval, instance.poll_interval),
|
| 134 |
+
"lifetime": (lifetime, instance.lifetime),
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
non_matching_params = {
|
| 138 |
+
name: (passed_param, set_param)
|
| 139 |
+
for name, (passed_param, set_param) in params_to_check.items()
|
| 140 |
+
if passed_param != set_param
|
| 141 |
+
}
|
| 142 |
+
if not non_matching_params:
|
| 143 |
+
return cast("BaseFileLock", instance)
|
| 144 |
+
|
| 145 |
+
# parameters do not match; raise error
|
| 146 |
+
msg = "Singleton lock instances cannot be initialized with differing arguments"
|
| 147 |
+
msg += "\nNon-matching arguments: "
|
| 148 |
+
for param_name, (passed_param, set_param) in non_matching_params.items():
|
| 149 |
+
msg += f"\n\t{param_name} (existing lock has {set_param} but {passed_param} was passed)"
|
| 150 |
+
raise ValueError(msg)
|
| 151 |
+
|
| 152 |
+
# Workaround to make `__init__`'s params optional in subclasses
|
| 153 |
+
# E.g. virtualenv changes the signature of the `__init__` method in the `BaseFileLock` class descendant
|
| 154 |
+
# (https://github.com/tox-dev/filelock/pull/340)
|
| 155 |
+
|
| 156 |
+
all_params = {
|
| 157 |
+
"timeout": timeout,
|
| 158 |
+
"mode": mode,
|
| 159 |
+
"thread_local": thread_local,
|
| 160 |
+
"blocking": blocking,
|
| 161 |
+
"is_singleton": is_singleton,
|
| 162 |
+
"poll_interval": poll_interval,
|
| 163 |
+
"lifetime": lifetime,
|
| 164 |
+
**kwargs,
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
present_params = inspect.signature(cls.__init__).parameters
|
| 168 |
+
init_params = {key: value for key, value in all_params.items() if key in present_params}
|
| 169 |
+
|
| 170 |
+
instance = super().__call__(lock_file, **init_params)
|
| 171 |
+
|
| 172 |
+
if is_singleton:
|
| 173 |
+
cls._instances[str(lock_file)] = instance
|
| 174 |
+
|
| 175 |
+
return cast("BaseFileLock", instance)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
class BaseFileLock(contextlib.ContextDecorator, metaclass=FileLockMeta):
|
| 179 |
+
"""
|
| 180 |
+
Abstract base class for a file lock object.
|
| 181 |
+
|
| 182 |
+
Provides a reentrant, cross-process exclusive lock backed by OS-level primitives. Subclasses implement the actual
|
| 183 |
+
locking mechanism (:class:`UnixFileLock <filelock.UnixFileLock>`, :class:`WindowsFileLock
|
| 184 |
+
<filelock.WindowsFileLock>`, :class:`SoftFileLock <filelock.SoftFileLock>`).
|
| 185 |
+
|
| 186 |
+
"""
|
| 187 |
+
|
| 188 |
+
_instances: WeakValueDictionary[str, BaseFileLock]
|
| 189 |
+
|
| 190 |
+
def __init_subclass__(cls, **kwargs: dict[str, Any]) -> None:
|
| 191 |
+
"""Setup unique state for lock subclasses."""
|
| 192 |
+
super().__init_subclass__(**kwargs)
|
| 193 |
+
cls._instances = WeakValueDictionary()
|
| 194 |
+
|
| 195 |
+
def __init__( # noqa: PLR0913
|
| 196 |
+
self,
|
| 197 |
+
lock_file: str | os.PathLike[str],
|
| 198 |
+
timeout: float = -1,
|
| 199 |
+
mode: int = _UNSET_FILE_MODE,
|
| 200 |
+
thread_local: bool = True, # noqa: FBT001, FBT002
|
| 201 |
+
*,
|
| 202 |
+
blocking: bool = True,
|
| 203 |
+
is_singleton: bool = False,
|
| 204 |
+
poll_interval: float = 0.05,
|
| 205 |
+
lifetime: float | None = None,
|
| 206 |
+
) -> None:
|
| 207 |
+
"""
|
| 208 |
+
Create a new lock object.
|
| 209 |
+
|
| 210 |
+
:param lock_file: path to the file
|
| 211 |
+
:param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the
|
| 212 |
+
acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a
|
| 213 |
+
negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.
|
| 214 |
+
:param mode: file permissions for the lockfile. When not specified, the OS controls permissions via umask and
|
| 215 |
+
default ACLs, preserving POSIX default ACL inheritance in shared directories.
|
| 216 |
+
:param thread_local: Whether this object's internal context should be thread local or not. If this is set to
|
| 217 |
+
``False`` then the lock will be reentrant across threads.
|
| 218 |
+
:param blocking: whether the lock should be blocking or not
|
| 219 |
+
:param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock
|
| 220 |
+
file. This is useful if you want to use the lock object for reentrant locking without needing to pass the
|
| 221 |
+
same object around.
|
| 222 |
+
:param poll_interval: default interval for polling the lock file, in seconds. It will be used as fallback value
|
| 223 |
+
in the acquire method, if no poll_interval value (``None``) is given.
|
| 224 |
+
:param lifetime: maximum time in seconds a lock can be held before it is considered expired. When set, a waiting
|
| 225 |
+
process will break a lock whose file modification time is older than ``lifetime`` seconds. ``None`` (the
|
| 226 |
+
default) means locks never expire.
|
| 227 |
+
|
| 228 |
+
"""
|
| 229 |
+
self._is_thread_local = thread_local
|
| 230 |
+
self._is_singleton = is_singleton
|
| 231 |
+
|
| 232 |
+
# Create the context. Note that external code should not work with the context directly and should instead use
|
| 233 |
+
# properties of this class.
|
| 234 |
+
kwargs: dict[str, Any] = {
|
| 235 |
+
"lock_file": os.fspath(lock_file),
|
| 236 |
+
"timeout": timeout,
|
| 237 |
+
"mode": mode,
|
| 238 |
+
"blocking": blocking,
|
| 239 |
+
"poll_interval": poll_interval,
|
| 240 |
+
"lifetime": lifetime,
|
| 241 |
+
}
|
| 242 |
+
self._context: FileLockContext = (ThreadLocalFileContext if thread_local else FileLockContext)(**kwargs)
|
| 243 |
+
|
| 244 |
+
def is_thread_local(self) -> bool:
|
| 245 |
+
""":returns: a flag indicating if this lock is thread local or not"""
|
| 246 |
+
return self._is_thread_local
|
| 247 |
+
|
| 248 |
+
@property
|
| 249 |
+
def is_singleton(self) -> bool:
|
| 250 |
+
"""
|
| 251 |
+
:returns: a flag indicating if this lock is singleton or not
|
| 252 |
+
|
| 253 |
+
.. versionadded:: 3.13.0
|
| 254 |
+
|
| 255 |
+
"""
|
| 256 |
+
return self._is_singleton
|
| 257 |
+
|
| 258 |
+
@property
|
| 259 |
+
def lock_file(self) -> str:
|
| 260 |
+
""":returns: path to the lock file"""
|
| 261 |
+
return self._context.lock_file
|
| 262 |
+
|
| 263 |
+
@property
|
| 264 |
+
def timeout(self) -> float:
|
| 265 |
+
"""
|
| 266 |
+
:returns: the default timeout value, in seconds
|
| 267 |
+
|
| 268 |
+
.. versionadded:: 2.0.0
|
| 269 |
+
|
| 270 |
+
"""
|
| 271 |
+
return self._context.timeout
|
| 272 |
+
|
| 273 |
+
@timeout.setter
|
| 274 |
+
def timeout(self, value: float | str) -> None:
|
| 275 |
+
"""
|
| 276 |
+
Change the default timeout value.
|
| 277 |
+
|
| 278 |
+
:param value: the new value, in seconds
|
| 279 |
+
|
| 280 |
+
"""
|
| 281 |
+
self._context.timeout = float(value)
|
| 282 |
+
|
| 283 |
+
@property
|
| 284 |
+
def blocking(self) -> bool:
|
| 285 |
+
"""
|
| 286 |
+
:returns: whether the locking is blocking or not
|
| 287 |
+
|
| 288 |
+
.. versionadded:: 3.14.0
|
| 289 |
+
|
| 290 |
+
"""
|
| 291 |
+
return self._context.blocking
|
| 292 |
+
|
| 293 |
+
@blocking.setter
|
| 294 |
+
def blocking(self, value: bool) -> None:
|
| 295 |
+
"""
|
| 296 |
+
Change the default blocking value.
|
| 297 |
+
|
| 298 |
+
:param value: the new value as bool
|
| 299 |
+
|
| 300 |
+
"""
|
| 301 |
+
self._context.blocking = value
|
| 302 |
+
|
| 303 |
+
@property
|
| 304 |
+
def poll_interval(self) -> float:
|
| 305 |
+
"""
|
| 306 |
+
:returns: the default polling interval, in seconds
|
| 307 |
+
|
| 308 |
+
.. versionadded:: 3.24.0
|
| 309 |
+
|
| 310 |
+
"""
|
| 311 |
+
return self._context.poll_interval
|
| 312 |
+
|
| 313 |
+
@poll_interval.setter
|
| 314 |
+
def poll_interval(self, value: float) -> None:
|
| 315 |
+
"""
|
| 316 |
+
Change the default polling interval.
|
| 317 |
+
|
| 318 |
+
:param value: the new value, in seconds
|
| 319 |
+
|
| 320 |
+
"""
|
| 321 |
+
self._context.poll_interval = value
|
| 322 |
+
|
| 323 |
+
@property
|
| 324 |
+
def lifetime(self) -> float | None:
|
| 325 |
+
"""
|
| 326 |
+
:returns: the lock lifetime in seconds, or ``None`` if the lock never expires
|
| 327 |
+
|
| 328 |
+
.. versionadded:: 3.24.0
|
| 329 |
+
|
| 330 |
+
"""
|
| 331 |
+
return self._context.lifetime
|
| 332 |
+
|
| 333 |
+
@lifetime.setter
|
| 334 |
+
def lifetime(self, value: float | None) -> None:
|
| 335 |
+
"""
|
| 336 |
+
Change the lock lifetime.
|
| 337 |
+
|
| 338 |
+
:param value: the new value in seconds, or ``None`` to disable expiration
|
| 339 |
+
|
| 340 |
+
"""
|
| 341 |
+
self._context.lifetime = value
|
| 342 |
+
|
| 343 |
+
@property
|
| 344 |
+
def mode(self) -> int:
|
| 345 |
+
""":returns: the file permissions for the lockfile"""
|
| 346 |
+
return 0o644 if self._context.mode == _UNSET_FILE_MODE else self._context.mode
|
| 347 |
+
|
| 348 |
+
@property
|
| 349 |
+
def has_explicit_mode(self) -> bool:
|
| 350 |
+
""":returns: whether the file permissions were explicitly set"""
|
| 351 |
+
return self._context.mode != _UNSET_FILE_MODE
|
| 352 |
+
|
| 353 |
+
def _open_mode(self) -> int:
|
| 354 |
+
""":returns: the mode for os.open() — 0o666 when unset (let umask/ACLs decide), else the explicit mode"""
|
| 355 |
+
return 0o666 if self._context.mode == _UNSET_FILE_MODE else self._context.mode
|
| 356 |
+
|
| 357 |
+
def _try_break_expired_lock(self) -> None:
|
| 358 |
+
"""Remove the lock file if its modification time exceeds the configured :attr:`lifetime`."""
|
| 359 |
+
if (lifetime := self._context.lifetime) is None:
|
| 360 |
+
return
|
| 361 |
+
with contextlib.suppress(OSError):
|
| 362 |
+
if time.time() - pathlib.Path(self.lock_file).stat().st_mtime < lifetime:
|
| 363 |
+
return
|
| 364 |
+
break_path = f"{self.lock_file}.break.{os.getpid()}"
|
| 365 |
+
pathlib.Path(self.lock_file).rename(break_path)
|
| 366 |
+
pathlib.Path(break_path).unlink()
|
| 367 |
+
|
| 368 |
+
@abstractmethod
|
| 369 |
+
def _acquire(self) -> None:
|
| 370 |
+
"""If the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file."""
|
| 371 |
+
raise NotImplementedError
|
| 372 |
+
|
| 373 |
+
@abstractmethod
|
| 374 |
+
def _release(self) -> None:
|
| 375 |
+
"""Releases the lock and sets self._context.lock_file_fd to None."""
|
| 376 |
+
raise NotImplementedError
|
| 377 |
+
|
| 378 |
+
@property
|
| 379 |
+
def is_locked(self) -> bool:
|
| 380 |
+
"""
|
| 381 |
+
:returns: A boolean indicating if the lock file is holding the lock currently.
|
| 382 |
+
|
| 383 |
+
.. versionchanged:: 2.0.0
|
| 384 |
+
|
| 385 |
+
This was previously a method and is now a property.
|
| 386 |
+
|
| 387 |
+
"""
|
| 388 |
+
return self._context.lock_file_fd is not None
|
| 389 |
+
|
| 390 |
+
@property
|
| 391 |
+
def lock_counter(self) -> int:
|
| 392 |
+
""":returns: The number of times this lock has been acquired (but not yet released)."""
|
| 393 |
+
return self._context.lock_counter
|
| 394 |
+
|
| 395 |
+
@staticmethod
|
| 396 |
+
def _check_give_up( # noqa: PLR0913
|
| 397 |
+
lock_id: int,
|
| 398 |
+
lock_filename: str,
|
| 399 |
+
*,
|
| 400 |
+
blocking: bool,
|
| 401 |
+
cancel_check: Callable[[], bool] | None,
|
| 402 |
+
timeout: float,
|
| 403 |
+
start_time: float,
|
| 404 |
+
) -> bool:
|
| 405 |
+
if blocking is False:
|
| 406 |
+
_LOGGER.debug("Failed to immediately acquire lock %s on %s", lock_id, lock_filename)
|
| 407 |
+
return True
|
| 408 |
+
if cancel_check is not None and cancel_check():
|
| 409 |
+
_LOGGER.debug("Cancellation requested for lock %s on %s", lock_id, lock_filename)
|
| 410 |
+
return True
|
| 411 |
+
if 0 <= timeout < time.perf_counter() - start_time:
|
| 412 |
+
_LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename)
|
| 413 |
+
return True
|
| 414 |
+
return False
|
| 415 |
+
|
| 416 |
+
def acquire( # noqa: C901
|
| 417 |
+
self,
|
| 418 |
+
timeout: float | None = None,
|
| 419 |
+
poll_interval: float | None = None,
|
| 420 |
+
*,
|
| 421 |
+
poll_intervall: float | None = None,
|
| 422 |
+
blocking: bool | None = None,
|
| 423 |
+
cancel_check: Callable[[], bool] | None = None,
|
| 424 |
+
) -> AcquireReturnProxy:
|
| 425 |
+
"""
|
| 426 |
+
Try to acquire the file lock.
|
| 427 |
+
|
| 428 |
+
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
|
| 429 |
+
if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
|
| 430 |
+
:param poll_interval: interval of trying to acquire the lock file, ``None`` means use the default
|
| 431 |
+
:attr:`~poll_interval`
|
| 432 |
+
:param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead
|
| 433 |
+
:param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the
|
| 434 |
+
first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.
|
| 435 |
+
:param cancel_check: a callable returning ``True`` when the acquisition should be canceled. Checked on each poll
|
| 436 |
+
iteration. When triggered, raises :class:`~Timeout` just like an expired timeout.
|
| 437 |
+
|
| 438 |
+
:returns: a context object that will unlock the file when the context is exited
|
| 439 |
+
|
| 440 |
+
:raises Timeout: if fails to acquire lock within the timeout period
|
| 441 |
+
|
| 442 |
+
.. code-block:: python
|
| 443 |
+
|
| 444 |
+
# You can use this method in the context manager (recommended)
|
| 445 |
+
with lock.acquire():
|
| 446 |
+
pass
|
| 447 |
+
|
| 448 |
+
# Or use an equivalent try-finally construct:
|
| 449 |
+
lock.acquire()
|
| 450 |
+
try:
|
| 451 |
+
pass
|
| 452 |
+
finally:
|
| 453 |
+
lock.release()
|
| 454 |
+
|
| 455 |
+
.. versionchanged:: 2.0.0
|
| 456 |
+
|
| 457 |
+
This method returns now a *proxy* object instead of *self*, so that it can be used in a with statement
|
| 458 |
+
without side effects.
|
| 459 |
+
|
| 460 |
+
"""
|
| 461 |
+
# Use the default timeout, if no timeout is provided.
|
| 462 |
+
if timeout is None:
|
| 463 |
+
timeout = self._context.timeout
|
| 464 |
+
|
| 465 |
+
if blocking is None:
|
| 466 |
+
blocking = self._context.blocking
|
| 467 |
+
|
| 468 |
+
if poll_intervall is not None:
|
| 469 |
+
msg = "use poll_interval instead of poll_intervall"
|
| 470 |
+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
| 471 |
+
poll_interval = poll_intervall
|
| 472 |
+
|
| 473 |
+
poll_interval = poll_interval if poll_interval is not None else self._context.poll_interval
|
| 474 |
+
|
| 475 |
+
# Increment the number right at the beginning. We can still undo it, if something fails.
|
| 476 |
+
self._context.lock_counter += 1
|
| 477 |
+
|
| 478 |
+
lock_id = id(self)
|
| 479 |
+
lock_filename = self.lock_file
|
| 480 |
+
canonical = _canonical(lock_filename)
|
| 481 |
+
|
| 482 |
+
would_block = self._context.lock_counter == 1 and not self.is_locked and timeout < 0 and blocking
|
| 483 |
+
if would_block and (existing := _registry.held.get(canonical)) is not None and existing != lock_id:
|
| 484 |
+
self._context.lock_counter -= 1
|
| 485 |
+
msg = (
|
| 486 |
+
f"Deadlock: lock '{lock_filename}' is already held by a different "
|
| 487 |
+
f"FileLock instance in this thread. Use is_singleton=True to "
|
| 488 |
+
f"enable reentrant locking across instances."
|
| 489 |
+
)
|
| 490 |
+
raise RuntimeError(msg)
|
| 491 |
+
|
| 492 |
+
start_time = time.perf_counter()
|
| 493 |
+
try:
|
| 494 |
+
while True:
|
| 495 |
+
if not self.is_locked:
|
| 496 |
+
self._try_break_expired_lock()
|
| 497 |
+
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
|
| 498 |
+
self._acquire()
|
| 499 |
+
if self.is_locked:
|
| 500 |
+
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
|
| 501 |
+
break
|
| 502 |
+
if self._check_give_up(
|
| 503 |
+
lock_id,
|
| 504 |
+
lock_filename,
|
| 505 |
+
blocking=blocking,
|
| 506 |
+
cancel_check=cancel_check,
|
| 507 |
+
timeout=timeout,
|
| 508 |
+
start_time=start_time,
|
| 509 |
+
):
|
| 510 |
+
raise Timeout(lock_filename) # noqa: TRY301
|
| 511 |
+
msg = "Lock %s not acquired on %s, waiting %s seconds ..."
|
| 512 |
+
_LOGGER.debug(msg, lock_id, lock_filename, poll_interval)
|
| 513 |
+
time.sleep(poll_interval)
|
| 514 |
+
except BaseException:
|
| 515 |
+
self._context.lock_counter = max(0, self._context.lock_counter - 1)
|
| 516 |
+
if self._context.lock_counter == 0:
|
| 517 |
+
_registry.held.pop(canonical, None)
|
| 518 |
+
raise
|
| 519 |
+
if self._context.lock_counter == 1:
|
| 520 |
+
_registry.held[canonical] = lock_id
|
| 521 |
+
return AcquireReturnProxy(lock=self)
|
| 522 |
+
|
| 523 |
+
def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002
|
| 524 |
+
"""
|
| 525 |
+
Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file
|
| 526 |
+
itself is not automatically deleted.
|
| 527 |
+
|
| 528 |
+
:param force: If true, the lock counter is ignored and the lock is released in every case.
|
| 529 |
+
|
| 530 |
+
"""
|
| 531 |
+
if self.is_locked:
|
| 532 |
+
self._context.lock_counter -= 1
|
| 533 |
+
|
| 534 |
+
if self._context.lock_counter == 0 or force:
|
| 535 |
+
lock_id, lock_filename = id(self), self.lock_file
|
| 536 |
+
|
| 537 |
+
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
|
| 538 |
+
self._release()
|
| 539 |
+
self._context.lock_counter = 0
|
| 540 |
+
_registry.held.pop(_canonical(lock_filename), None)
|
| 541 |
+
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)
|
| 542 |
+
|
| 543 |
+
def __enter__(self) -> Self:
|
| 544 |
+
"""
|
| 545 |
+
Acquire the lock.
|
| 546 |
+
|
| 547 |
+
:returns: the lock object
|
| 548 |
+
|
| 549 |
+
"""
|
| 550 |
+
self.acquire()
|
| 551 |
+
return self
|
| 552 |
+
|
| 553 |
+
def __exit__(
|
| 554 |
+
self,
|
| 555 |
+
exc_type: type[BaseException] | None,
|
| 556 |
+
exc_value: BaseException | None,
|
| 557 |
+
traceback: TracebackType | None,
|
| 558 |
+
) -> None:
|
| 559 |
+
"""
|
| 560 |
+
Release the lock.
|
| 561 |
+
|
| 562 |
+
:param exc_type: the exception type if raised
|
| 563 |
+
:param exc_value: the exception value if raised
|
| 564 |
+
:param traceback: the exception traceback if raised
|
| 565 |
+
|
| 566 |
+
"""
|
| 567 |
+
self.release()
|
| 568 |
+
|
| 569 |
+
def __del__(self) -> None:
|
| 570 |
+
"""Called when the lock object is deleted."""
|
| 571 |
+
self.release(force=True)
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
__all__ = [
|
| 575 |
+
"_UNSET_FILE_MODE",
|
| 576 |
+
"AcquireReturnProxy",
|
| 577 |
+
"BaseFileLock",
|
| 578 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/_error.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Timeout(TimeoutError): # noqa: N818
|
| 7 |
+
"""Raised when the lock could not be acquired in *timeout* seconds."""
|
| 8 |
+
|
| 9 |
+
def __init__(self, lock_file: str) -> None:
|
| 10 |
+
super().__init__()
|
| 11 |
+
self._lock_file = lock_file
|
| 12 |
+
|
| 13 |
+
def __reduce__(self) -> str | tuple[Any, ...]:
|
| 14 |
+
return self.__class__, (self._lock_file,) # Properly pickle the exception
|
| 15 |
+
|
| 16 |
+
def __str__(self) -> str:
|
| 17 |
+
return f"The file lock '{self._lock_file}' could not be acquired."
|
| 18 |
+
|
| 19 |
+
def __repr__(self) -> str:
|
| 20 |
+
return f"{self.__class__.__name__}({self.lock_file!r})"
|
| 21 |
+
|
| 22 |
+
@property
|
| 23 |
+
def lock_file(self) -> str:
|
| 24 |
+
""":returns: The path of the file lock."""
|
| 25 |
+
return self._lock_file
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
__all__ = [
|
| 29 |
+
"Timeout",
|
| 30 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/_read_write.py
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import atexit
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
import pathlib
|
| 7 |
+
import sqlite3
|
| 8 |
+
import threading
|
| 9 |
+
import time
|
| 10 |
+
from contextlib import contextmanager, suppress
|
| 11 |
+
from typing import TYPE_CHECKING, Literal
|
| 12 |
+
from weakref import WeakValueDictionary
|
| 13 |
+
|
| 14 |
+
from ._api import AcquireReturnProxy
|
| 15 |
+
from ._error import Timeout
|
| 16 |
+
|
| 17 |
+
if TYPE_CHECKING:
|
| 18 |
+
from collections.abc import Generator
|
| 19 |
+
|
| 20 |
+
_LOGGER = logging.getLogger("filelock")
|
| 21 |
+
|
| 22 |
+
_all_connections: set[sqlite3.Connection] = set()
|
| 23 |
+
_all_connections_lock = threading.Lock()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _cleanup_connections() -> None:
|
| 27 |
+
with _all_connections_lock:
|
| 28 |
+
for con in list(_all_connections):
|
| 29 |
+
with suppress(Exception):
|
| 30 |
+
con.close()
|
| 31 |
+
_all_connections.clear()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
atexit.register(_cleanup_connections)
|
| 35 |
+
|
| 36 |
+
# sqlite3_busy_timeout() accepts a C int, max 2_147_483_647 on 32-bit. Use a lower value to be safe (~23 days).
|
| 37 |
+
_MAX_SQLITE_TIMEOUT_MS = 2_000_000_000 - 1
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def timeout_for_sqlite(timeout: float, *, blocking: bool, already_waited: float) -> int:
|
| 41 |
+
if blocking is False:
|
| 42 |
+
return 0
|
| 43 |
+
|
| 44 |
+
if timeout == -1:
|
| 45 |
+
return _MAX_SQLITE_TIMEOUT_MS
|
| 46 |
+
|
| 47 |
+
if timeout < 0:
|
| 48 |
+
msg = "timeout must be a non-negative number or -1"
|
| 49 |
+
raise ValueError(msg)
|
| 50 |
+
|
| 51 |
+
remaining = max(timeout - already_waited, 0) if timeout > 0 else timeout
|
| 52 |
+
timeout_ms = int(remaining * 1000)
|
| 53 |
+
if timeout_ms > _MAX_SQLITE_TIMEOUT_MS or timeout_ms < 0:
|
| 54 |
+
_LOGGER.warning("timeout %s is too large for SQLite, using %s ms instead", timeout, _MAX_SQLITE_TIMEOUT_MS)
|
| 55 |
+
return _MAX_SQLITE_TIMEOUT_MS
|
| 56 |
+
return timeout_ms
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class _ReadWriteLockMeta(type):
|
| 60 |
+
"""
|
| 61 |
+
Metaclass that handles singleton resolution when is_singleton=True.
|
| 62 |
+
|
| 63 |
+
Singleton logic lives here rather than in ReadWriteLock.get_lock so that ``ReadWriteLock(path)`` transparently
|
| 64 |
+
returns cached instances without a 2-arg ``super()`` call that type checkers cannot verify.
|
| 65 |
+
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
_instances: WeakValueDictionary[pathlib.Path, ReadWriteLock]
|
| 69 |
+
_instances_lock: threading.Lock
|
| 70 |
+
|
| 71 |
+
def __call__(
|
| 72 |
+
cls,
|
| 73 |
+
lock_file: str | os.PathLike[str],
|
| 74 |
+
timeout: float = -1,
|
| 75 |
+
*,
|
| 76 |
+
blocking: bool = True,
|
| 77 |
+
is_singleton: bool = True,
|
| 78 |
+
) -> ReadWriteLock:
|
| 79 |
+
if not is_singleton:
|
| 80 |
+
return super().__call__(lock_file, timeout, blocking=blocking, is_singleton=is_singleton)
|
| 81 |
+
|
| 82 |
+
normalized = pathlib.Path(lock_file).resolve()
|
| 83 |
+
with cls._instances_lock:
|
| 84 |
+
if normalized not in cls._instances:
|
| 85 |
+
instance = super().__call__(lock_file, timeout, blocking=blocking, is_singleton=is_singleton)
|
| 86 |
+
cls._instances[normalized] = instance
|
| 87 |
+
else:
|
| 88 |
+
instance = cls._instances[normalized]
|
| 89 |
+
|
| 90 |
+
if instance.timeout != timeout or instance.blocking != blocking:
|
| 91 |
+
msg = (
|
| 92 |
+
f"Singleton lock created with timeout={instance.timeout}, blocking={instance.blocking},"
|
| 93 |
+
f" cannot be changed to timeout={timeout}, blocking={blocking}"
|
| 94 |
+
)
|
| 95 |
+
raise ValueError(msg)
|
| 96 |
+
return instance
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class ReadWriteLock(metaclass=_ReadWriteLockMeta):
|
| 100 |
+
"""
|
| 101 |
+
Cross-process read-write lock backed by SQLite.
|
| 102 |
+
|
| 103 |
+
Allows concurrent shared readers or a single exclusive writer. The lock is reentrant within the same mode (multiple
|
| 104 |
+
``acquire_read`` calls nest, as do multiple ``acquire_write`` calls from the same thread), but upgrading from read
|
| 105 |
+
to write or downgrading from write to read raises :class:`RuntimeError`. Write locks are pinned to the thread that
|
| 106 |
+
acquired them.
|
| 107 |
+
|
| 108 |
+
By default, ``is_singleton=True``: calling ``ReadWriteLock(path)`` with the same resolved path returns the same
|
| 109 |
+
instance. The lock file must use a ``.db`` extension (SQLite database).
|
| 110 |
+
|
| 111 |
+
:param lock_file: path to the SQLite database file used as the lock
|
| 112 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 113 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 114 |
+
:param is_singleton: if ``True``, reuse existing instances for the same resolved path
|
| 115 |
+
|
| 116 |
+
.. versionadded:: 3.21.0
|
| 117 |
+
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
_instances: WeakValueDictionary[pathlib.Path, ReadWriteLock] = WeakValueDictionary()
|
| 121 |
+
_instances_lock = threading.Lock()
|
| 122 |
+
|
| 123 |
+
@classmethod
|
| 124 |
+
def get_lock(
|
| 125 |
+
cls, lock_file: str | os.PathLike[str], timeout: float = -1, *, blocking: bool = True
|
| 126 |
+
) -> ReadWriteLock:
|
| 127 |
+
"""
|
| 128 |
+
Return the singleton :class:`ReadWriteLock` for *lock_file*.
|
| 129 |
+
|
| 130 |
+
:param lock_file: path to the SQLite database file used as the lock
|
| 131 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 132 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 133 |
+
|
| 134 |
+
:returns: the singleton lock instance
|
| 135 |
+
|
| 136 |
+
:raises ValueError: if an instance already exists for this path with different *timeout* or *blocking* values
|
| 137 |
+
|
| 138 |
+
"""
|
| 139 |
+
return cls(lock_file, timeout, blocking=blocking)
|
| 140 |
+
|
| 141 |
+
def __init__(
|
| 142 |
+
self,
|
| 143 |
+
lock_file: str | os.PathLike[str],
|
| 144 |
+
timeout: float = -1,
|
| 145 |
+
*,
|
| 146 |
+
blocking: bool = True,
|
| 147 |
+
is_singleton: bool = True, # noqa: ARG002 # consumed by _ReadWriteLockMeta.__call__
|
| 148 |
+
) -> None:
|
| 149 |
+
self.lock_file = os.fspath(lock_file)
|
| 150 |
+
self.timeout = timeout
|
| 151 |
+
self.blocking = blocking
|
| 152 |
+
self._transaction_lock = threading.Lock() # serializes the (possibly blocking) SQLite transaction work
|
| 153 |
+
self._internal_lock = threading.Lock() # protects _lock_level / _current_mode updates and rollback
|
| 154 |
+
self._lock_level = 0
|
| 155 |
+
self._current_mode: Literal["read", "write"] | None = None
|
| 156 |
+
self._write_thread_id: int | None = None
|
| 157 |
+
self._con = sqlite3.connect(self.lock_file, check_same_thread=False)
|
| 158 |
+
with _all_connections_lock:
|
| 159 |
+
_all_connections.add(self._con)
|
| 160 |
+
|
| 161 |
+
def _acquire_transaction_lock(self, *, blocking: bool, timeout: float) -> None:
|
| 162 |
+
if timeout == -1:
|
| 163 |
+
# blocking=True with no timeout means wait indefinitely per threading.Lock.acquire semantics
|
| 164 |
+
acquired = self._transaction_lock.acquire(blocking)
|
| 165 |
+
else:
|
| 166 |
+
acquired = self._transaction_lock.acquire(blocking, timeout)
|
| 167 |
+
if not acquired:
|
| 168 |
+
raise Timeout(self.lock_file) from None
|
| 169 |
+
|
| 170 |
+
def _validate_reentrant(self, mode: Literal["read", "write"], opposite: str, direction: str) -> AcquireReturnProxy:
|
| 171 |
+
if self._current_mode != mode:
|
| 172 |
+
msg = (
|
| 173 |
+
f"Cannot acquire {mode} lock on {self.lock_file} (lock id: {id(self)}): "
|
| 174 |
+
f"already holding a {opposite} lock ({direction} not allowed)"
|
| 175 |
+
)
|
| 176 |
+
raise RuntimeError(msg)
|
| 177 |
+
if mode == "write" and (cur := threading.get_ident()) != self._write_thread_id:
|
| 178 |
+
msg = (
|
| 179 |
+
f"Cannot acquire write lock on {self.lock_file} (lock id: {id(self)}) "
|
| 180 |
+
f"from thread {cur} while it is held by thread {self._write_thread_id}"
|
| 181 |
+
)
|
| 182 |
+
raise RuntimeError(msg)
|
| 183 |
+
self._lock_level += 1
|
| 184 |
+
return AcquireReturnProxy(lock=self)
|
| 185 |
+
|
| 186 |
+
def _configure_and_begin(
|
| 187 |
+
self, mode: Literal["read", "write"], timeout: float, *, blocking: bool, start_time: float
|
| 188 |
+
) -> None:
|
| 189 |
+
waited = time.perf_counter() - start_time
|
| 190 |
+
timeout_ms = timeout_for_sqlite(timeout, blocking=blocking, already_waited=waited)
|
| 191 |
+
self._con.execute(f"PRAGMA busy_timeout={timeout_ms};").close()
|
| 192 |
+
# Use legacy journal mode (not WAL) because WAL does not block readers when a concurrent EXCLUSIVE
|
| 193 |
+
# write transaction is active, making read-write locking impossible without modifying table data.
|
| 194 |
+
# MEMORY is safe here since no actual writes happen — crashes cannot corrupt the DB.
|
| 195 |
+
# See https://sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions
|
| 196 |
+
#
|
| 197 |
+
# Set here (not in __init__) because this pragma itself may block on a locked database,
|
| 198 |
+
# so it must run after busy_timeout is configured above.
|
| 199 |
+
self._con.execute("PRAGMA journal_mode=MEMORY;").close()
|
| 200 |
+
# Recompute remaining timeout after the potentially blocking journal_mode pragma.
|
| 201 |
+
waited = time.perf_counter() - start_time
|
| 202 |
+
if (recomputed := timeout_for_sqlite(timeout, blocking=blocking, already_waited=waited)) != timeout_ms:
|
| 203 |
+
self._con.execute(f"PRAGMA busy_timeout={recomputed};").close()
|
| 204 |
+
stmt = "BEGIN EXCLUSIVE TRANSACTION;" if mode == "write" else "BEGIN TRANSACTION;"
|
| 205 |
+
self._con.execute(stmt).close()
|
| 206 |
+
if mode == "read":
|
| 207 |
+
# A SELECT is needed to force SQLite to actually acquire the SHARED lock on the database.
|
| 208 |
+
# https://www.sqlite.org/lockingv3.html#transaction_control
|
| 209 |
+
self._con.execute("SELECT name FROM sqlite_schema LIMIT 1;").close()
|
| 210 |
+
|
| 211 |
+
def _acquire(self, mode: Literal["read", "write"], timeout: float, *, blocking: bool) -> AcquireReturnProxy:
|
| 212 |
+
opposite = "write" if mode == "read" else "read"
|
| 213 |
+
direction = "downgrade" if mode == "read" else "upgrade"
|
| 214 |
+
|
| 215 |
+
with self._internal_lock:
|
| 216 |
+
if self._lock_level > 0:
|
| 217 |
+
return self._validate_reentrant(mode, opposite, direction)
|
| 218 |
+
|
| 219 |
+
start_time = time.perf_counter()
|
| 220 |
+
self._acquire_transaction_lock(blocking=blocking, timeout=timeout)
|
| 221 |
+
try:
|
| 222 |
+
# Double-check: another thread may have acquired the lock while we waited on _transaction_lock.
|
| 223 |
+
with self._internal_lock:
|
| 224 |
+
if self._lock_level > 0:
|
| 225 |
+
return self._validate_reentrant(mode, opposite, direction)
|
| 226 |
+
|
| 227 |
+
self._configure_and_begin(mode, timeout, blocking=blocking, start_time=start_time)
|
| 228 |
+
|
| 229 |
+
with self._internal_lock:
|
| 230 |
+
self._current_mode = mode
|
| 231 |
+
self._lock_level = 1
|
| 232 |
+
if mode == "write":
|
| 233 |
+
self._write_thread_id = threading.get_ident()
|
| 234 |
+
|
| 235 |
+
return AcquireReturnProxy(lock=self)
|
| 236 |
+
|
| 237 |
+
except sqlite3.OperationalError as exc:
|
| 238 |
+
if "database is locked" not in str(exc):
|
| 239 |
+
raise
|
| 240 |
+
raise Timeout(self.lock_file) from None
|
| 241 |
+
finally:
|
| 242 |
+
self._transaction_lock.release()
|
| 243 |
+
|
| 244 |
+
def acquire_read(self, timeout: float = -1, *, blocking: bool = True) -> AcquireReturnProxy:
|
| 245 |
+
"""
|
| 246 |
+
Acquire a shared read lock.
|
| 247 |
+
|
| 248 |
+
If this instance already holds a read lock, the lock level is incremented (reentrant). Attempting to acquire a
|
| 249 |
+
read lock while holding a write lock raises :class:`RuntimeError` (downgrade not allowed).
|
| 250 |
+
|
| 251 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 252 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 253 |
+
|
| 254 |
+
:returns: a proxy that can be used as a context manager to release the lock
|
| 255 |
+
|
| 256 |
+
:raises RuntimeError: if a write lock is already held on this instance
|
| 257 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 258 |
+
|
| 259 |
+
"""
|
| 260 |
+
return self._acquire("read", timeout, blocking=blocking)
|
| 261 |
+
|
| 262 |
+
def acquire_write(self, timeout: float = -1, *, blocking: bool = True) -> AcquireReturnProxy:
|
| 263 |
+
"""
|
| 264 |
+
Acquire an exclusive write lock.
|
| 265 |
+
|
| 266 |
+
If this instance already holds a write lock from the same thread, the lock level is incremented (reentrant).
|
| 267 |
+
Attempting to acquire a write lock while holding a read lock raises :class:`RuntimeError` (upgrade not allowed).
|
| 268 |
+
Write locks are pinned to the acquiring thread: a different thread trying to re-enter also raises
|
| 269 |
+
:class:`RuntimeError`.
|
| 270 |
+
|
| 271 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 272 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 273 |
+
|
| 274 |
+
:returns: a proxy that can be used as a context manager to release the lock
|
| 275 |
+
|
| 276 |
+
:raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
|
| 277 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 278 |
+
|
| 279 |
+
"""
|
| 280 |
+
return self._acquire("write", timeout, blocking=blocking)
|
| 281 |
+
|
| 282 |
+
def release(self, *, force: bool = False) -> None:
|
| 283 |
+
"""
|
| 284 |
+
Release one level of the current lock.
|
| 285 |
+
|
| 286 |
+
When the lock level reaches zero the underlying SQLite transaction is rolled back, releasing the database lock.
|
| 287 |
+
|
| 288 |
+
:param force: if ``True``, release the lock completely regardless of the current lock level
|
| 289 |
+
|
| 290 |
+
:raises RuntimeError: if no lock is currently held and *force* is ``False``
|
| 291 |
+
|
| 292 |
+
"""
|
| 293 |
+
should_rollback = False
|
| 294 |
+
with self._internal_lock:
|
| 295 |
+
if self._lock_level == 0:
|
| 296 |
+
if force:
|
| 297 |
+
return
|
| 298 |
+
msg = f"Cannot release a lock on {self.lock_file} (lock id: {id(self)}) that is not held"
|
| 299 |
+
raise RuntimeError(msg)
|
| 300 |
+
if force:
|
| 301 |
+
self._lock_level = 0
|
| 302 |
+
else:
|
| 303 |
+
self._lock_level -= 1
|
| 304 |
+
if self._lock_level == 0:
|
| 305 |
+
self._current_mode = None
|
| 306 |
+
self._write_thread_id = None
|
| 307 |
+
should_rollback = True
|
| 308 |
+
if should_rollback:
|
| 309 |
+
self._con.rollback()
|
| 310 |
+
|
| 311 |
+
@contextmanager
|
| 312 |
+
def read_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:
|
| 313 |
+
"""
|
| 314 |
+
Context manager that acquires and releases a shared read lock.
|
| 315 |
+
|
| 316 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 317 |
+
|
| 318 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 319 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 320 |
+
|
| 321 |
+
"""
|
| 322 |
+
if timeout is None:
|
| 323 |
+
timeout = self.timeout
|
| 324 |
+
if blocking is None:
|
| 325 |
+
blocking = self.blocking
|
| 326 |
+
self.acquire_read(timeout, blocking=blocking)
|
| 327 |
+
try:
|
| 328 |
+
yield
|
| 329 |
+
finally:
|
| 330 |
+
self.release()
|
| 331 |
+
|
| 332 |
+
@contextmanager
|
| 333 |
+
def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:
|
| 334 |
+
"""
|
| 335 |
+
Context manager that acquires and releases an exclusive write lock.
|
| 336 |
+
|
| 337 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 338 |
+
|
| 339 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 340 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 341 |
+
|
| 342 |
+
"""
|
| 343 |
+
if timeout is None:
|
| 344 |
+
timeout = self.timeout
|
| 345 |
+
if blocking is None:
|
| 346 |
+
blocking = self.blocking
|
| 347 |
+
self.acquire_write(timeout, blocking=blocking)
|
| 348 |
+
try:
|
| 349 |
+
yield
|
| 350 |
+
finally:
|
| 351 |
+
self.release()
|
| 352 |
+
|
| 353 |
+
def close(self) -> None:
|
| 354 |
+
"""
|
| 355 |
+
Release the lock (if held) and close the underlying SQLite connection.
|
| 356 |
+
|
| 357 |
+
After calling this method, the lock instance is no longer usable.
|
| 358 |
+
|
| 359 |
+
"""
|
| 360 |
+
self.release(force=True)
|
| 361 |
+
self._con.close()
|
| 362 |
+
with _all_connections_lock:
|
| 363 |
+
_all_connections.discard(self._con)
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/_soft.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import socket
|
| 5 |
+
import sys
|
| 6 |
+
import time
|
| 7 |
+
from contextlib import suppress
|
| 8 |
+
from errno import EACCES, EEXIST, EPERM, ESRCH
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
from ._api import BaseFileLock
|
| 12 |
+
from ._util import ensure_directory_exists, raise_on_not_writable_file
|
| 13 |
+
|
| 14 |
+
_WIN_SYNCHRONIZE = 0x100000
|
| 15 |
+
_WIN_ERROR_INVALID_PARAMETER = 87
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class SoftFileLock(BaseFileLock):
|
| 19 |
+
"""
|
| 20 |
+
Portable file lock based on file existence.
|
| 21 |
+
|
| 22 |
+
Unlike :class:`UnixFileLock <filelock.UnixFileLock>` and :class:`WindowsFileLock <filelock.WindowsFileLock>`, this
|
| 23 |
+
lock does not use OS-level locking primitives. Instead, it creates the lock file with ``O_CREAT | O_EXCL`` and
|
| 24 |
+
treats its existence as the lock indicator. This makes it work on any filesystem but leaves stale lock files behind
|
| 25 |
+
if the process crashes without releasing the lock.
|
| 26 |
+
|
| 27 |
+
To mitigate stale locks, the lock file contains the PID and hostname of the holding process. On contention, if the
|
| 28 |
+
holder is on the same host and its PID no longer exists, the stale lock is broken automatically.
|
| 29 |
+
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def _acquire(self) -> None:
|
| 33 |
+
raise_on_not_writable_file(self.lock_file)
|
| 34 |
+
ensure_directory_exists(self.lock_file)
|
| 35 |
+
flags = (
|
| 36 |
+
os.O_WRONLY # open for writing only
|
| 37 |
+
| os.O_CREAT
|
| 38 |
+
| os.O_EXCL # together with above raise EEXIST if the file specified by filename exists
|
| 39 |
+
| os.O_TRUNC # truncate the file to zero byte
|
| 40 |
+
)
|
| 41 |
+
if (o_nofollow := getattr(os, "O_NOFOLLOW", None)) is not None:
|
| 42 |
+
flags |= o_nofollow
|
| 43 |
+
try:
|
| 44 |
+
file_handler = os.open(self.lock_file, flags, self._open_mode())
|
| 45 |
+
except OSError as exception:
|
| 46 |
+
if not (
|
| 47 |
+
exception.errno == EEXIST or (exception.errno == EACCES and sys.platform == "win32")
|
| 48 |
+
): # pragma: win32 no cover
|
| 49 |
+
raise
|
| 50 |
+
if exception.errno == EEXIST and sys.platform != "win32": # pragma: win32 no cover
|
| 51 |
+
self._try_break_stale_lock()
|
| 52 |
+
else:
|
| 53 |
+
self._write_lock_info(file_handler)
|
| 54 |
+
self._context.lock_file_fd = file_handler
|
| 55 |
+
|
| 56 |
+
def _try_break_stale_lock(self) -> None:
|
| 57 |
+
with suppress(OSError):
|
| 58 |
+
content = Path(self.lock_file).read_text(encoding="utf-8")
|
| 59 |
+
lines = content.strip().splitlines()
|
| 60 |
+
if len(lines) != 2: # noqa: PLR2004
|
| 61 |
+
return
|
| 62 |
+
pid_str, hostname = lines
|
| 63 |
+
if hostname != socket.gethostname():
|
| 64 |
+
return
|
| 65 |
+
pid = int(pid_str)
|
| 66 |
+
if self._is_process_alive(pid):
|
| 67 |
+
return
|
| 68 |
+
break_path = f"{self.lock_file}.break.{os.getpid()}"
|
| 69 |
+
Path(self.lock_file).rename(break_path)
|
| 70 |
+
Path(break_path).unlink()
|
| 71 |
+
|
| 72 |
+
@staticmethod
|
| 73 |
+
def _is_process_alive(pid: int) -> bool:
|
| 74 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 75 |
+
import ctypes # noqa: PLC0415
|
| 76 |
+
|
| 77 |
+
kernel32 = ctypes.windll.kernel32
|
| 78 |
+
handle = kernel32.OpenProcess(_WIN_SYNCHRONIZE, 0, pid)
|
| 79 |
+
if handle:
|
| 80 |
+
kernel32.CloseHandle(handle)
|
| 81 |
+
return True
|
| 82 |
+
return kernel32.GetLastError() != _WIN_ERROR_INVALID_PARAMETER
|
| 83 |
+
try:
|
| 84 |
+
os.kill(pid, 0)
|
| 85 |
+
except OSError as exc:
|
| 86 |
+
if exc.errno == ESRCH:
|
| 87 |
+
return False
|
| 88 |
+
if exc.errno == EPERM:
|
| 89 |
+
return True
|
| 90 |
+
raise
|
| 91 |
+
return True
|
| 92 |
+
|
| 93 |
+
@staticmethod
|
| 94 |
+
def _write_lock_info(fd: int) -> None:
|
| 95 |
+
with suppress(OSError):
|
| 96 |
+
os.write(fd, f"{os.getpid()}\n{socket.gethostname()}\n".encode())
|
| 97 |
+
|
| 98 |
+
def _release(self) -> None:
|
| 99 |
+
assert self._context.lock_file_fd is not None # noqa: S101
|
| 100 |
+
os.close(self._context.lock_file_fd)
|
| 101 |
+
self._context.lock_file_fd = None
|
| 102 |
+
if sys.platform == "win32":
|
| 103 |
+
self._windows_unlink_with_retry()
|
| 104 |
+
else:
|
| 105 |
+
with suppress(OSError):
|
| 106 |
+
Path(self.lock_file).unlink()
|
| 107 |
+
|
| 108 |
+
def _windows_unlink_with_retry(self) -> None:
|
| 109 |
+
max_retries = 10
|
| 110 |
+
retry_delay = 0.001
|
| 111 |
+
for attempt in range(max_retries):
|
| 112 |
+
# Windows doesn't immediately release file handles after close, causing EACCES/EPERM on unlink
|
| 113 |
+
try:
|
| 114 |
+
Path(self.lock_file).unlink()
|
| 115 |
+
except OSError as exc: # noqa: PERF203
|
| 116 |
+
if exc.errno not in {EACCES, EPERM}:
|
| 117 |
+
return
|
| 118 |
+
if attempt < max_retries - 1:
|
| 119 |
+
time.sleep(retry_delay)
|
| 120 |
+
retry_delay *= 2
|
| 121 |
+
else:
|
| 122 |
+
return
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
__all__ = [
|
| 126 |
+
"SoftFileLock",
|
| 127 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/_unix.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import warnings
|
| 6 |
+
from contextlib import suppress
|
| 7 |
+
from errno import EAGAIN, ENOSYS, EWOULDBLOCK
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import cast
|
| 10 |
+
|
| 11 |
+
from ._api import BaseFileLock
|
| 12 |
+
from ._util import ensure_directory_exists
|
| 13 |
+
|
| 14 |
+
#: a flag to indicate if the fcntl API is available
|
| 15 |
+
has_fcntl = False
|
| 16 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 17 |
+
|
| 18 |
+
class UnixFileLock(BaseFileLock):
|
| 19 |
+
"""Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems."""
|
| 20 |
+
|
| 21 |
+
def _acquire(self) -> None:
|
| 22 |
+
raise NotImplementedError
|
| 23 |
+
|
| 24 |
+
def _release(self) -> None:
|
| 25 |
+
raise NotImplementedError
|
| 26 |
+
|
| 27 |
+
else: # pragma: win32 no cover
|
| 28 |
+
try:
|
| 29 |
+
import fcntl
|
| 30 |
+
|
| 31 |
+
_ = (fcntl.flock, fcntl.LOCK_EX, fcntl.LOCK_NB, fcntl.LOCK_UN)
|
| 32 |
+
except (ImportError, AttributeError):
|
| 33 |
+
pass
|
| 34 |
+
else:
|
| 35 |
+
has_fcntl = True
|
| 36 |
+
|
| 37 |
+
class UnixFileLock(BaseFileLock):
|
| 38 |
+
"""Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems."""
|
| 39 |
+
|
| 40 |
+
def _acquire(self) -> None: # noqa: C901, PLR0912
|
| 41 |
+
ensure_directory_exists(self.lock_file)
|
| 42 |
+
open_flags = os.O_RDWR | os.O_TRUNC
|
| 43 |
+
o_nofollow = getattr(os, "O_NOFOLLOW", None)
|
| 44 |
+
if o_nofollow is not None:
|
| 45 |
+
open_flags |= o_nofollow
|
| 46 |
+
open_flags |= os.O_CREAT
|
| 47 |
+
open_mode = self._open_mode()
|
| 48 |
+
try:
|
| 49 |
+
fd = os.open(self.lock_file, open_flags, open_mode)
|
| 50 |
+
except FileNotFoundError:
|
| 51 |
+
# On FUSE/NFS, os.open(O_CREAT) is not atomic: LOOKUP + CREATE can be split, allowing a concurrent
|
| 52 |
+
# unlink() to delete the file between them. For valid paths, treat ENOENT as transient contention.
|
| 53 |
+
# For invalid paths (e.g., empty string), re-raise to avoid infinite retry loops.
|
| 54 |
+
if self.lock_file and Path(self.lock_file).parent.exists():
|
| 55 |
+
return
|
| 56 |
+
raise
|
| 57 |
+
except PermissionError:
|
| 58 |
+
# Sticky-bit dirs (e.g. /tmp): O_CREAT fails if the file is owned by another user (#317).
|
| 59 |
+
# Fall back to opening the existing file without O_CREAT.
|
| 60 |
+
if not Path(self.lock_file).exists():
|
| 61 |
+
raise
|
| 62 |
+
try:
|
| 63 |
+
fd = os.open(self.lock_file, open_flags & ~os.O_CREAT, open_mode)
|
| 64 |
+
except FileNotFoundError:
|
| 65 |
+
return
|
| 66 |
+
if self.has_explicit_mode:
|
| 67 |
+
with suppress(PermissionError):
|
| 68 |
+
os.fchmod(fd, self._context.mode)
|
| 69 |
+
try:
|
| 70 |
+
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
| 71 |
+
except OSError as exception:
|
| 72 |
+
os.close(fd)
|
| 73 |
+
if exception.errno == ENOSYS:
|
| 74 |
+
with suppress(OSError):
|
| 75 |
+
Path(self.lock_file).unlink()
|
| 76 |
+
self._fallback_to_soft_lock()
|
| 77 |
+
self._acquire()
|
| 78 |
+
return
|
| 79 |
+
if exception.errno not in {EAGAIN, EWOULDBLOCK}:
|
| 80 |
+
raise
|
| 81 |
+
else:
|
| 82 |
+
# The file may have been unlinked by a concurrent _release() between our open() and flock().
|
| 83 |
+
# A lock on an unlinked inode is useless — discard and let the retry loop start fresh.
|
| 84 |
+
if os.fstat(fd).st_nlink == 0:
|
| 85 |
+
os.close(fd)
|
| 86 |
+
else:
|
| 87 |
+
self._context.lock_file_fd = fd
|
| 88 |
+
|
| 89 |
+
def _fallback_to_soft_lock(self) -> None:
|
| 90 |
+
from ._soft import SoftFileLock # noqa: PLC0415
|
| 91 |
+
|
| 92 |
+
warnings.warn("flock not supported on this filesystem, falling back to SoftFileLock", stacklevel=2)
|
| 93 |
+
from .asyncio import AsyncSoftFileLock, BaseAsyncFileLock # noqa: PLC0415
|
| 94 |
+
|
| 95 |
+
self.__class__ = AsyncSoftFileLock if isinstance(self, BaseAsyncFileLock) else SoftFileLock
|
| 96 |
+
|
| 97 |
+
def _release(self) -> None:
|
| 98 |
+
fd = cast("int", self._context.lock_file_fd)
|
| 99 |
+
self._context.lock_file_fd = None
|
| 100 |
+
with suppress(OSError):
|
| 101 |
+
Path(self.lock_file).unlink()
|
| 102 |
+
fcntl.flock(fd, fcntl.LOCK_UN)
|
| 103 |
+
os.close(fd)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
__all__ = [
|
| 107 |
+
"UnixFileLock",
|
| 108 |
+
"has_fcntl",
|
| 109 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/_util.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import stat
|
| 5 |
+
import sys
|
| 6 |
+
from errno import EACCES, EISDIR
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def raise_on_not_writable_file(filename: str) -> None:
|
| 11 |
+
"""
|
| 12 |
+
Raise an exception if attempting to open the file for writing would fail.
|
| 13 |
+
|
| 14 |
+
This is done so files that will never be writable can be separated from files that are writable but currently
|
| 15 |
+
locked.
|
| 16 |
+
|
| 17 |
+
:param filename: file to check
|
| 18 |
+
|
| 19 |
+
:raises OSError: as if the file was opened for writing.
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
try: # use stat to do exists + can write to check without race condition
|
| 23 |
+
file_stat = os.stat(filename) # noqa: PTH116
|
| 24 |
+
except OSError:
|
| 25 |
+
return # swallow does not exist or other errors
|
| 26 |
+
|
| 27 |
+
if file_stat.st_mtime != 0: # if os.stat returns but modification is zero that's an invalid os.stat - ignore it
|
| 28 |
+
if not (file_stat.st_mode & stat.S_IWUSR):
|
| 29 |
+
raise PermissionError(EACCES, "Permission denied", filename)
|
| 30 |
+
|
| 31 |
+
if stat.S_ISDIR(file_stat.st_mode):
|
| 32 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 33 |
+
# On Windows, this is PermissionError
|
| 34 |
+
raise PermissionError(EACCES, "Permission denied", filename)
|
| 35 |
+
else: # pragma: win32 no cover # noqa: RET506
|
| 36 |
+
# On linux / macOS, this is IsADirectoryError
|
| 37 |
+
raise IsADirectoryError(EISDIR, "Is a directory", filename)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def ensure_directory_exists(filename: Path | str) -> None:
|
| 41 |
+
"""
|
| 42 |
+
Ensure the directory containing the file exists (create it if necessary).
|
| 43 |
+
|
| 44 |
+
:param filename: file.
|
| 45 |
+
|
| 46 |
+
"""
|
| 47 |
+
Path(filename).parent.mkdir(parents=True, exist_ok=True)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
__all__ = [
|
| 51 |
+
"ensure_directory_exists",
|
| 52 |
+
"raise_on_not_writable_file",
|
| 53 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/_windows.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from errno import EACCES
|
| 6 |
+
from typing import cast
|
| 7 |
+
|
| 8 |
+
from ._api import BaseFileLock
|
| 9 |
+
from ._util import ensure_directory_exists, raise_on_not_writable_file
|
| 10 |
+
|
| 11 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 12 |
+
import ctypes
|
| 13 |
+
import msvcrt
|
| 14 |
+
from ctypes import wintypes
|
| 15 |
+
|
| 16 |
+
# Windows API constants for reparse point detection
|
| 17 |
+
FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
|
| 18 |
+
INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF
|
| 19 |
+
|
| 20 |
+
# Load kernel32.dll
|
| 21 |
+
_kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
| 22 |
+
_kernel32.GetFileAttributesW.argtypes = [wintypes.LPCWSTR]
|
| 23 |
+
_kernel32.GetFileAttributesW.restype = wintypes.DWORD
|
| 24 |
+
|
| 25 |
+
def _is_reparse_point(path: str) -> bool:
|
| 26 |
+
"""
|
| 27 |
+
Check if a path is a reparse point (symlink, junction, etc.) on Windows.
|
| 28 |
+
|
| 29 |
+
:param path: Path to check
|
| 30 |
+
|
| 31 |
+
:returns: True if path is a reparse point, False otherwise
|
| 32 |
+
|
| 33 |
+
:raises OSError: If GetFileAttributesW fails for reasons other than file-not-found
|
| 34 |
+
|
| 35 |
+
"""
|
| 36 |
+
attrs = _kernel32.GetFileAttributesW(path)
|
| 37 |
+
if attrs == INVALID_FILE_ATTRIBUTES:
|
| 38 |
+
# File doesn't exist yet - that's fine, we'll create it
|
| 39 |
+
err = ctypes.get_last_error()
|
| 40 |
+
if err == 2: # noqa: PLR2004 # ERROR_FILE_NOT_FOUND
|
| 41 |
+
return False
|
| 42 |
+
if err == 3: # noqa: PLR2004 # ERROR_PATH_NOT_FOUND
|
| 43 |
+
return False
|
| 44 |
+
# Some other error - let caller handle it
|
| 45 |
+
return False
|
| 46 |
+
return bool(attrs & FILE_ATTRIBUTE_REPARSE_POINT)
|
| 47 |
+
|
| 48 |
+
class WindowsFileLock(BaseFileLock):
|
| 49 |
+
"""Uses the :func:`msvcrt.locking` function to hard lock the lock file on Windows systems."""
|
| 50 |
+
|
| 51 |
+
def _acquire(self) -> None:
|
| 52 |
+
raise_on_not_writable_file(self.lock_file)
|
| 53 |
+
ensure_directory_exists(self.lock_file)
|
| 54 |
+
|
| 55 |
+
# Security check: Refuse to open reparse points (symlinks, junctions)
|
| 56 |
+
# This prevents TOCTOU symlink attacks (CVE-TBD)
|
| 57 |
+
if _is_reparse_point(self.lock_file):
|
| 58 |
+
msg = f"Lock file is a reparse point (symlink/junction): {self.lock_file}"
|
| 59 |
+
raise OSError(msg)
|
| 60 |
+
|
| 61 |
+
flags = (
|
| 62 |
+
os.O_RDWR # open for read and write
|
| 63 |
+
| os.O_CREAT # create file if not exists
|
| 64 |
+
)
|
| 65 |
+
try:
|
| 66 |
+
fd = os.open(self.lock_file, flags, self._open_mode())
|
| 67 |
+
except OSError as exception:
|
| 68 |
+
if exception.errno != EACCES: # has no access to this lock
|
| 69 |
+
raise
|
| 70 |
+
else:
|
| 71 |
+
try:
|
| 72 |
+
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)
|
| 73 |
+
except OSError as exception:
|
| 74 |
+
os.close(fd) # close file first
|
| 75 |
+
if exception.errno != EACCES: # file is already locked
|
| 76 |
+
raise
|
| 77 |
+
else:
|
| 78 |
+
self._context.lock_file_fd = fd
|
| 79 |
+
|
| 80 |
+
def _release(self) -> None:
|
| 81 |
+
fd = cast("int", self._context.lock_file_fd)
|
| 82 |
+
self._context.lock_file_fd = None
|
| 83 |
+
msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
|
| 84 |
+
os.close(fd)
|
| 85 |
+
|
| 86 |
+
else: # pragma: win32 no cover
|
| 87 |
+
|
| 88 |
+
class WindowsFileLock(BaseFileLock):
|
| 89 |
+
"""Uses the :func:`msvcrt.locking` function to hard lock the lock file on Windows systems."""
|
| 90 |
+
|
| 91 |
+
def _acquire(self) -> None:
|
| 92 |
+
raise NotImplementedError
|
| 93 |
+
|
| 94 |
+
def _release(self) -> None:
|
| 95 |
+
raise NotImplementedError
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
__all__ = [
|
| 99 |
+
"WindowsFileLock",
|
| 100 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/asyncio.py
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""An asyncio-based implementation of the file lock."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import asyncio
|
| 6 |
+
import contextlib
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import time
|
| 10 |
+
from dataclasses import dataclass
|
| 11 |
+
from inspect import iscoroutinefunction
|
| 12 |
+
from threading import local
|
| 13 |
+
from typing import TYPE_CHECKING, Any, NoReturn, cast
|
| 14 |
+
|
| 15 |
+
from ._api import _UNSET_FILE_MODE, BaseFileLock, FileLockContext, FileLockMeta
|
| 16 |
+
from ._error import Timeout
|
| 17 |
+
from ._soft import SoftFileLock
|
| 18 |
+
from ._unix import UnixFileLock
|
| 19 |
+
from ._windows import WindowsFileLock
|
| 20 |
+
|
| 21 |
+
if TYPE_CHECKING:
|
| 22 |
+
import sys
|
| 23 |
+
from collections.abc import Callable
|
| 24 |
+
from concurrent import futures
|
| 25 |
+
from types import TracebackType
|
| 26 |
+
|
| 27 |
+
if sys.version_info >= (3, 11): # pragma: no cover (py311+)
|
| 28 |
+
from typing import Self
|
| 29 |
+
else: # pragma: no cover (<py311)
|
| 30 |
+
from typing_extensions import Self
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
_LOGGER = logging.getLogger("filelock")
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@dataclass
|
| 37 |
+
class AsyncFileLockContext(FileLockContext):
|
| 38 |
+
"""A dataclass which holds the context for a ``BaseAsyncFileLock`` object."""
|
| 39 |
+
|
| 40 |
+
#: Whether run in executor
|
| 41 |
+
run_in_executor: bool = True
|
| 42 |
+
|
| 43 |
+
#: The executor
|
| 44 |
+
executor: futures.Executor | None = None
|
| 45 |
+
|
| 46 |
+
#: The loop
|
| 47 |
+
loop: asyncio.AbstractEventLoop | None = None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class AsyncThreadLocalFileContext(AsyncFileLockContext, local):
|
| 51 |
+
"""A thread local version of the ``FileLockContext`` class."""
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class AsyncAcquireReturnProxy:
|
| 55 |
+
"""A context-aware object that will release the lock file when exiting."""
|
| 56 |
+
|
| 57 |
+
def __init__(self, lock: BaseAsyncFileLock) -> None: # noqa: D107
|
| 58 |
+
self.lock = lock
|
| 59 |
+
|
| 60 |
+
async def __aenter__(self) -> BaseAsyncFileLock: # noqa: D105
|
| 61 |
+
return self.lock
|
| 62 |
+
|
| 63 |
+
async def __aexit__( # noqa: D105
|
| 64 |
+
self,
|
| 65 |
+
exc_type: type[BaseException] | None,
|
| 66 |
+
exc_value: BaseException | None,
|
| 67 |
+
traceback: TracebackType | None,
|
| 68 |
+
) -> None:
|
| 69 |
+
await self.lock.release()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class AsyncFileLockMeta(FileLockMeta):
|
| 73 |
+
def __call__( # ty: ignore[invalid-method-override] # noqa: PLR0913
|
| 74 |
+
cls, # noqa: N805
|
| 75 |
+
lock_file: str | os.PathLike[str],
|
| 76 |
+
timeout: float = -1,
|
| 77 |
+
mode: int = _UNSET_FILE_MODE,
|
| 78 |
+
thread_local: bool = False, # noqa: FBT001, FBT002
|
| 79 |
+
*,
|
| 80 |
+
blocking: bool = True,
|
| 81 |
+
is_singleton: bool = False,
|
| 82 |
+
poll_interval: float = 0.05,
|
| 83 |
+
lifetime: float | None = None,
|
| 84 |
+
loop: asyncio.AbstractEventLoop | None = None,
|
| 85 |
+
run_in_executor: bool = True,
|
| 86 |
+
executor: futures.Executor | None = None,
|
| 87 |
+
) -> BaseAsyncFileLock:
|
| 88 |
+
if thread_local and run_in_executor:
|
| 89 |
+
msg = "run_in_executor is not supported when thread_local is True"
|
| 90 |
+
raise ValueError(msg)
|
| 91 |
+
instance = super().__call__(
|
| 92 |
+
lock_file=lock_file,
|
| 93 |
+
timeout=timeout,
|
| 94 |
+
mode=mode,
|
| 95 |
+
thread_local=thread_local,
|
| 96 |
+
blocking=blocking,
|
| 97 |
+
is_singleton=is_singleton,
|
| 98 |
+
poll_interval=poll_interval,
|
| 99 |
+
lifetime=lifetime,
|
| 100 |
+
loop=loop,
|
| 101 |
+
run_in_executor=run_in_executor,
|
| 102 |
+
executor=executor,
|
| 103 |
+
)
|
| 104 |
+
return cast("BaseAsyncFileLock", instance)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class BaseAsyncFileLock(BaseFileLock, metaclass=AsyncFileLockMeta):
|
| 108 |
+
"""
|
| 109 |
+
Base class for asynchronous file locks.
|
| 110 |
+
|
| 111 |
+
.. versionadded:: 3.15.0
|
| 112 |
+
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
def __init__( # noqa: PLR0913
|
| 116 |
+
self,
|
| 117 |
+
lock_file: str | os.PathLike[str],
|
| 118 |
+
timeout: float = -1,
|
| 119 |
+
mode: int = _UNSET_FILE_MODE,
|
| 120 |
+
thread_local: bool = False, # noqa: FBT001, FBT002
|
| 121 |
+
*,
|
| 122 |
+
blocking: bool = True,
|
| 123 |
+
is_singleton: bool = False,
|
| 124 |
+
poll_interval: float = 0.05,
|
| 125 |
+
lifetime: float | None = None,
|
| 126 |
+
loop: asyncio.AbstractEventLoop | None = None,
|
| 127 |
+
run_in_executor: bool = True,
|
| 128 |
+
executor: futures.Executor | None = None,
|
| 129 |
+
) -> None:
|
| 130 |
+
"""
|
| 131 |
+
Create a new lock object.
|
| 132 |
+
|
| 133 |
+
:param lock_file: path to the file
|
| 134 |
+
:param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the
|
| 135 |
+
acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a
|
| 136 |
+
negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.
|
| 137 |
+
:param mode: file permissions for the lockfile. When not specified, the OS controls permissions via umask and
|
| 138 |
+
default ACLs, preserving POSIX default ACL inheritance in shared directories.
|
| 139 |
+
:param thread_local: Whether this object's internal context should be thread local or not. If this is set to
|
| 140 |
+
``False`` then the lock will be reentrant across threads.
|
| 141 |
+
:param blocking: whether the lock should be blocking or not
|
| 142 |
+
:param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock
|
| 143 |
+
file. This is useful if you want to use the lock object for reentrant locking without needing to pass the
|
| 144 |
+
same object around.
|
| 145 |
+
:param poll_interval: default interval for polling the lock file, in seconds. It will be used as fallback value
|
| 146 |
+
in the acquire method, if no poll_interval value (``None``) is given.
|
| 147 |
+
:param lifetime: maximum time in seconds a lock can be held before it is considered expired. When set, a waiting
|
| 148 |
+
process will break a lock whose file modification time is older than ``lifetime`` seconds. ``None`` (the
|
| 149 |
+
default) means locks never expire.
|
| 150 |
+
:param loop: The event loop to use. If not specified, the running event loop will be used.
|
| 151 |
+
:param run_in_executor: If this is set to ``True`` then the lock will be acquired in an executor.
|
| 152 |
+
:param executor: The executor to use. If not specified, the default executor will be used.
|
| 153 |
+
|
| 154 |
+
"""
|
| 155 |
+
self._is_thread_local = thread_local
|
| 156 |
+
self._is_singleton = is_singleton
|
| 157 |
+
|
| 158 |
+
# Create the context. Note that external code should not work with the context directly and should instead use
|
| 159 |
+
# properties of this class.
|
| 160 |
+
kwargs: dict[str, Any] = {
|
| 161 |
+
"lock_file": os.fspath(lock_file),
|
| 162 |
+
"timeout": timeout,
|
| 163 |
+
"mode": mode,
|
| 164 |
+
"blocking": blocking,
|
| 165 |
+
"poll_interval": poll_interval,
|
| 166 |
+
"lifetime": lifetime,
|
| 167 |
+
"loop": loop,
|
| 168 |
+
"run_in_executor": run_in_executor,
|
| 169 |
+
"executor": executor,
|
| 170 |
+
}
|
| 171 |
+
self._context: AsyncFileLockContext = (AsyncThreadLocalFileContext if thread_local else AsyncFileLockContext)(
|
| 172 |
+
**kwargs
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
@property
|
| 176 |
+
def run_in_executor(self) -> bool:
|
| 177 |
+
""":returns: whether run in executor."""
|
| 178 |
+
return self._context.run_in_executor
|
| 179 |
+
|
| 180 |
+
@property
|
| 181 |
+
def executor(self) -> futures.Executor | None:
|
| 182 |
+
""":returns: the executor."""
|
| 183 |
+
return self._context.executor
|
| 184 |
+
|
| 185 |
+
@executor.setter
|
| 186 |
+
def executor(self, value: futures.Executor | None) -> None: # pragma: no cover
|
| 187 |
+
"""
|
| 188 |
+
Change the executor.
|
| 189 |
+
|
| 190 |
+
:param futures.Executor | None value: the new executor or ``None``
|
| 191 |
+
|
| 192 |
+
"""
|
| 193 |
+
self._context.executor = value
|
| 194 |
+
|
| 195 |
+
@property
|
| 196 |
+
def loop(self) -> asyncio.AbstractEventLoop | None:
|
| 197 |
+
""":returns: the event loop."""
|
| 198 |
+
return self._context.loop
|
| 199 |
+
|
| 200 |
+
async def acquire( # ty: ignore[invalid-method-override]
|
| 201 |
+
self,
|
| 202 |
+
timeout: float | None = None,
|
| 203 |
+
poll_interval: float | None = None,
|
| 204 |
+
*,
|
| 205 |
+
blocking: bool | None = None,
|
| 206 |
+
cancel_check: Callable[[], bool] | None = None,
|
| 207 |
+
) -> AsyncAcquireReturnProxy:
|
| 208 |
+
"""
|
| 209 |
+
Try to acquire the file lock.
|
| 210 |
+
|
| 211 |
+
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default
|
| 212 |
+
:attr:`~BaseFileLock.timeout` is and if ``timeout < 0``, there is no timeout and this method will block
|
| 213 |
+
until the lock could be acquired
|
| 214 |
+
:param poll_interval: interval of trying to acquire the lock file, ``None`` means use the default
|
| 215 |
+
:attr:`~BaseFileLock.poll_interval`
|
| 216 |
+
:param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the
|
| 217 |
+
first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.
|
| 218 |
+
:param cancel_check: a callable returning ``True`` when the acquisition should be canceled. Checked on each poll
|
| 219 |
+
iteration. When triggered, raises :class:`~Timeout` just like an expired timeout.
|
| 220 |
+
|
| 221 |
+
:returns: a context object that will unlock the file when the context is exited
|
| 222 |
+
|
| 223 |
+
:raises Timeout: if fails to acquire lock within the timeout period
|
| 224 |
+
|
| 225 |
+
.. code-block:: python
|
| 226 |
+
|
| 227 |
+
# You can use this method in the context manager (recommended)
|
| 228 |
+
with lock.acquire():
|
| 229 |
+
pass
|
| 230 |
+
|
| 231 |
+
# Or use an equivalent try-finally construct:
|
| 232 |
+
lock.acquire()
|
| 233 |
+
try:
|
| 234 |
+
pass
|
| 235 |
+
finally:
|
| 236 |
+
lock.release()
|
| 237 |
+
|
| 238 |
+
"""
|
| 239 |
+
# Use the default timeout, if no timeout is provided.
|
| 240 |
+
if timeout is None:
|
| 241 |
+
timeout = self._context.timeout
|
| 242 |
+
|
| 243 |
+
if blocking is None:
|
| 244 |
+
blocking = self._context.blocking
|
| 245 |
+
|
| 246 |
+
if poll_interval is None:
|
| 247 |
+
poll_interval = self._context.poll_interval
|
| 248 |
+
|
| 249 |
+
# Increment the number right at the beginning. We can still undo it, if something fails.
|
| 250 |
+
self._context.lock_counter += 1
|
| 251 |
+
|
| 252 |
+
lock_id = id(self)
|
| 253 |
+
lock_filename = self.lock_file
|
| 254 |
+
start_time = time.perf_counter()
|
| 255 |
+
try:
|
| 256 |
+
while True:
|
| 257 |
+
if not self.is_locked:
|
| 258 |
+
self._try_break_expired_lock()
|
| 259 |
+
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
|
| 260 |
+
await self._run_internal_method(self._acquire)
|
| 261 |
+
if self.is_locked:
|
| 262 |
+
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
|
| 263 |
+
break
|
| 264 |
+
if self._check_give_up(
|
| 265 |
+
lock_id,
|
| 266 |
+
lock_filename,
|
| 267 |
+
blocking=blocking,
|
| 268 |
+
cancel_check=cancel_check,
|
| 269 |
+
timeout=timeout,
|
| 270 |
+
start_time=start_time,
|
| 271 |
+
):
|
| 272 |
+
raise Timeout(lock_filename) # noqa: TRY301
|
| 273 |
+
msg = "Lock %s not acquired on %s, waiting %s seconds ..."
|
| 274 |
+
_LOGGER.debug(msg, lock_id, lock_filename, poll_interval)
|
| 275 |
+
await asyncio.sleep(poll_interval)
|
| 276 |
+
except BaseException: # Something did go wrong, so decrement the counter.
|
| 277 |
+
self._context.lock_counter = max(0, self._context.lock_counter - 1)
|
| 278 |
+
raise
|
| 279 |
+
return AsyncAcquireReturnProxy(lock=self)
|
| 280 |
+
|
| 281 |
+
async def release(self, force: bool = False) -> None: # ty: ignore[invalid-method-override] # noqa: FBT001, FBT002
|
| 282 |
+
"""
|
| 283 |
+
Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file
|
| 284 |
+
itself is not automatically deleted.
|
| 285 |
+
|
| 286 |
+
:param force: If true, the lock counter is ignored and the lock is released in every case.
|
| 287 |
+
|
| 288 |
+
"""
|
| 289 |
+
if self.is_locked:
|
| 290 |
+
self._context.lock_counter -= 1
|
| 291 |
+
|
| 292 |
+
if self._context.lock_counter == 0 or force:
|
| 293 |
+
lock_id, lock_filename = id(self), self.lock_file
|
| 294 |
+
|
| 295 |
+
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
|
| 296 |
+
await self._run_internal_method(self._release)
|
| 297 |
+
self._context.lock_counter = 0
|
| 298 |
+
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)
|
| 299 |
+
|
| 300 |
+
async def _run_internal_method(self, method: Callable[[], Any]) -> None:
|
| 301 |
+
if iscoroutinefunction(method):
|
| 302 |
+
await method()
|
| 303 |
+
elif self.run_in_executor:
|
| 304 |
+
loop = self.loop or asyncio.get_running_loop()
|
| 305 |
+
await loop.run_in_executor(self.executor, method)
|
| 306 |
+
else:
|
| 307 |
+
method()
|
| 308 |
+
|
| 309 |
+
def __enter__(self) -> NoReturn:
|
| 310 |
+
"""
|
| 311 |
+
Replace old __enter__ method to avoid using it.
|
| 312 |
+
|
| 313 |
+
NOTE: DO NOT USE `with` FOR ASYNCIO LOCKS, USE `async with` INSTEAD.
|
| 314 |
+
|
| 315 |
+
:returns: none
|
| 316 |
+
:rtype: NoReturn
|
| 317 |
+
|
| 318 |
+
"""
|
| 319 |
+
msg = "Do not use `with` for asyncio locks, use `async with` instead."
|
| 320 |
+
raise NotImplementedError(msg)
|
| 321 |
+
|
| 322 |
+
async def __aenter__(self) -> Self:
|
| 323 |
+
"""
|
| 324 |
+
Acquire the lock.
|
| 325 |
+
|
| 326 |
+
:returns: the lock object
|
| 327 |
+
|
| 328 |
+
"""
|
| 329 |
+
await self.acquire()
|
| 330 |
+
return self
|
| 331 |
+
|
| 332 |
+
async def __aexit__(
|
| 333 |
+
self,
|
| 334 |
+
exc_type: type[BaseException] | None,
|
| 335 |
+
exc_value: BaseException | None,
|
| 336 |
+
traceback: TracebackType | None,
|
| 337 |
+
) -> None:
|
| 338 |
+
"""
|
| 339 |
+
Release the lock.
|
| 340 |
+
|
| 341 |
+
:param exc_type: the exception type if raised
|
| 342 |
+
:param exc_value: the exception value if raised
|
| 343 |
+
:param traceback: the exception traceback if raised
|
| 344 |
+
|
| 345 |
+
"""
|
| 346 |
+
await self.release()
|
| 347 |
+
|
| 348 |
+
def __del__(self) -> None:
|
| 349 |
+
"""Called when the lock object is deleted."""
|
| 350 |
+
with contextlib.suppress(RuntimeError):
|
| 351 |
+
loop = self.loop or asyncio.get_running_loop()
|
| 352 |
+
if not loop.is_running(): # pragma: no cover
|
| 353 |
+
loop.run_until_complete(self.release(force=True))
|
| 354 |
+
else:
|
| 355 |
+
loop.create_task(self.release(force=True))
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
class AsyncSoftFileLock(SoftFileLock, BaseAsyncFileLock):
|
| 359 |
+
"""Simply watches the existence of the lock file."""
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
class AsyncUnixFileLock(UnixFileLock, BaseAsyncFileLock):
|
| 363 |
+
"""Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems."""
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
class AsyncWindowsFileLock(WindowsFileLock, BaseAsyncFileLock):
|
| 367 |
+
"""Uses the :func:`msvcrt.locking` to hard lock the lock file on windows systems."""
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
__all__ = [
|
| 371 |
+
"AsyncAcquireReturnProxy",
|
| 372 |
+
"AsyncSoftFileLock",
|
| 373 |
+
"AsyncUnixFileLock",
|
| 374 |
+
"AsyncWindowsFileLock",
|
| 375 |
+
"BaseAsyncFileLock",
|
| 376 |
+
]
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/py.typed
ADDED
|
File without changes
|
TTS/Kokoro/.venv/Lib/site-packages/filelock/version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# file generated by setuptools-scm
|
| 2 |
+
# don't change, don't track in version control
|
| 3 |
+
|
| 4 |
+
__all__ = [
|
| 5 |
+
"__version__",
|
| 6 |
+
"__version_tuple__",
|
| 7 |
+
"version",
|
| 8 |
+
"version_tuple",
|
| 9 |
+
"__commit_id__",
|
| 10 |
+
"commit_id",
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
TYPE_CHECKING = False
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from typing import Tuple
|
| 16 |
+
from typing import Union
|
| 17 |
+
|
| 18 |
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
| 19 |
+
COMMIT_ID = Union[str, None]
|
| 20 |
+
else:
|
| 21 |
+
VERSION_TUPLE = object
|
| 22 |
+
COMMIT_ID = object
|
| 23 |
+
|
| 24 |
+
version: str
|
| 25 |
+
__version__: str
|
| 26 |
+
__version_tuple__: VERSION_TUPLE
|
| 27 |
+
version_tuple: VERSION_TUPLE
|
| 28 |
+
commit_id: COMMIT_ID
|
| 29 |
+
__commit_id__: COMMIT_ID
|
| 30 |
+
|
| 31 |
+
__version__ = version = '3.24.3'
|
| 32 |
+
__version_tuple__ = version_tuple = (3, 24, 3)
|
| 33 |
+
|
| 34 |
+
__commit_id__ = commit_id = None
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: fsspec
|
| 3 |
+
Version: 2026.2.0
|
| 4 |
+
Summary: File-system specification
|
| 5 |
+
Project-URL: Changelog, https://filesystem-spec.readthedocs.io/en/latest/changelog.html
|
| 6 |
+
Project-URL: Documentation, https://filesystem-spec.readthedocs.io/en/latest/
|
| 7 |
+
Project-URL: Homepage, https://github.com/fsspec/filesystem_spec
|
| 8 |
+
Maintainer-email: Martin Durant <mdurant@anaconda.com>
|
| 9 |
+
License-Expression: BSD-3-Clause
|
| 10 |
+
License-File: LICENSE
|
| 11 |
+
Keywords: file
|
| 12 |
+
Classifier: Development Status :: 4 - Beta
|
| 13 |
+
Classifier: Intended Audience :: Developers
|
| 14 |
+
Classifier: Operating System :: OS Independent
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 20 |
+
Requires-Python: >=3.10
|
| 21 |
+
Provides-Extra: abfs
|
| 22 |
+
Requires-Dist: adlfs; extra == 'abfs'
|
| 23 |
+
Provides-Extra: adl
|
| 24 |
+
Requires-Dist: adlfs; extra == 'adl'
|
| 25 |
+
Provides-Extra: arrow
|
| 26 |
+
Requires-Dist: pyarrow>=1; extra == 'arrow'
|
| 27 |
+
Provides-Extra: dask
|
| 28 |
+
Requires-Dist: dask; extra == 'dask'
|
| 29 |
+
Requires-Dist: distributed; extra == 'dask'
|
| 30 |
+
Provides-Extra: dev
|
| 31 |
+
Requires-Dist: pre-commit; extra == 'dev'
|
| 32 |
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
| 33 |
+
Provides-Extra: doc
|
| 34 |
+
Requires-Dist: numpydoc; extra == 'doc'
|
| 35 |
+
Requires-Dist: sphinx; extra == 'doc'
|
| 36 |
+
Requires-Dist: sphinx-design; extra == 'doc'
|
| 37 |
+
Requires-Dist: sphinx-rtd-theme; extra == 'doc'
|
| 38 |
+
Requires-Dist: yarl; extra == 'doc'
|
| 39 |
+
Provides-Extra: dropbox
|
| 40 |
+
Requires-Dist: dropbox; extra == 'dropbox'
|
| 41 |
+
Requires-Dist: dropboxdrivefs; extra == 'dropbox'
|
| 42 |
+
Requires-Dist: requests; extra == 'dropbox'
|
| 43 |
+
Provides-Extra: entrypoints
|
| 44 |
+
Provides-Extra: full
|
| 45 |
+
Requires-Dist: adlfs; extra == 'full'
|
| 46 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'full'
|
| 47 |
+
Requires-Dist: dask; extra == 'full'
|
| 48 |
+
Requires-Dist: distributed; extra == 'full'
|
| 49 |
+
Requires-Dist: dropbox; extra == 'full'
|
| 50 |
+
Requires-Dist: dropboxdrivefs; extra == 'full'
|
| 51 |
+
Requires-Dist: fusepy; extra == 'full'
|
| 52 |
+
Requires-Dist: gcsfs>2024.2.0; extra == 'full'
|
| 53 |
+
Requires-Dist: libarchive-c; extra == 'full'
|
| 54 |
+
Requires-Dist: ocifs; extra == 'full'
|
| 55 |
+
Requires-Dist: panel; extra == 'full'
|
| 56 |
+
Requires-Dist: paramiko; extra == 'full'
|
| 57 |
+
Requires-Dist: pyarrow>=1; extra == 'full'
|
| 58 |
+
Requires-Dist: pygit2; extra == 'full'
|
| 59 |
+
Requires-Dist: requests; extra == 'full'
|
| 60 |
+
Requires-Dist: s3fs>2024.2.0; extra == 'full'
|
| 61 |
+
Requires-Dist: smbprotocol; extra == 'full'
|
| 62 |
+
Requires-Dist: tqdm; extra == 'full'
|
| 63 |
+
Provides-Extra: fuse
|
| 64 |
+
Requires-Dist: fusepy; extra == 'fuse'
|
| 65 |
+
Provides-Extra: gcs
|
| 66 |
+
Requires-Dist: gcsfs>2024.2.0; extra == 'gcs'
|
| 67 |
+
Provides-Extra: git
|
| 68 |
+
Requires-Dist: pygit2; extra == 'git'
|
| 69 |
+
Provides-Extra: github
|
| 70 |
+
Requires-Dist: requests; extra == 'github'
|
| 71 |
+
Provides-Extra: gs
|
| 72 |
+
Requires-Dist: gcsfs; extra == 'gs'
|
| 73 |
+
Provides-Extra: gui
|
| 74 |
+
Requires-Dist: panel; extra == 'gui'
|
| 75 |
+
Provides-Extra: hdfs
|
| 76 |
+
Requires-Dist: pyarrow>=1; extra == 'hdfs'
|
| 77 |
+
Provides-Extra: http
|
| 78 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'http'
|
| 79 |
+
Provides-Extra: libarchive
|
| 80 |
+
Requires-Dist: libarchive-c; extra == 'libarchive'
|
| 81 |
+
Provides-Extra: oci
|
| 82 |
+
Requires-Dist: ocifs; extra == 'oci'
|
| 83 |
+
Provides-Extra: s3
|
| 84 |
+
Requires-Dist: s3fs>2024.2.0; extra == 's3'
|
| 85 |
+
Provides-Extra: sftp
|
| 86 |
+
Requires-Dist: paramiko; extra == 'sftp'
|
| 87 |
+
Provides-Extra: smb
|
| 88 |
+
Requires-Dist: smbprotocol; extra == 'smb'
|
| 89 |
+
Provides-Extra: ssh
|
| 90 |
+
Requires-Dist: paramiko; extra == 'ssh'
|
| 91 |
+
Provides-Extra: test
|
| 92 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'test'
|
| 93 |
+
Requires-Dist: numpy; extra == 'test'
|
| 94 |
+
Requires-Dist: pytest; extra == 'test'
|
| 95 |
+
Requires-Dist: pytest-asyncio!=0.22.0; extra == 'test'
|
| 96 |
+
Requires-Dist: pytest-benchmark; extra == 'test'
|
| 97 |
+
Requires-Dist: pytest-cov; extra == 'test'
|
| 98 |
+
Requires-Dist: pytest-mock; extra == 'test'
|
| 99 |
+
Requires-Dist: pytest-recording; extra == 'test'
|
| 100 |
+
Requires-Dist: pytest-rerunfailures; extra == 'test'
|
| 101 |
+
Requires-Dist: requests; extra == 'test'
|
| 102 |
+
Provides-Extra: test-downstream
|
| 103 |
+
Requires-Dist: aiobotocore<3.0.0,>=2.5.4; extra == 'test-downstream'
|
| 104 |
+
Requires-Dist: dask[dataframe,test]; extra == 'test-downstream'
|
| 105 |
+
Requires-Dist: moto[server]<5,>4; extra == 'test-downstream'
|
| 106 |
+
Requires-Dist: pytest-timeout; extra == 'test-downstream'
|
| 107 |
+
Requires-Dist: xarray; extra == 'test-downstream'
|
| 108 |
+
Provides-Extra: test-full
|
| 109 |
+
Requires-Dist: adlfs; extra == 'test-full'
|
| 110 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'test-full'
|
| 111 |
+
Requires-Dist: backports-zstd; (python_version < '3.14') and extra == 'test-full'
|
| 112 |
+
Requires-Dist: cloudpickle; extra == 'test-full'
|
| 113 |
+
Requires-Dist: dask; extra == 'test-full'
|
| 114 |
+
Requires-Dist: distributed; extra == 'test-full'
|
| 115 |
+
Requires-Dist: dropbox; extra == 'test-full'
|
| 116 |
+
Requires-Dist: dropboxdrivefs; extra == 'test-full'
|
| 117 |
+
Requires-Dist: fastparquet; extra == 'test-full'
|
| 118 |
+
Requires-Dist: fusepy; extra == 'test-full'
|
| 119 |
+
Requires-Dist: gcsfs; extra == 'test-full'
|
| 120 |
+
Requires-Dist: jinja2; extra == 'test-full'
|
| 121 |
+
Requires-Dist: kerchunk; extra == 'test-full'
|
| 122 |
+
Requires-Dist: libarchive-c; extra == 'test-full'
|
| 123 |
+
Requires-Dist: lz4; extra == 'test-full'
|
| 124 |
+
Requires-Dist: notebook; extra == 'test-full'
|
| 125 |
+
Requires-Dist: numpy; extra == 'test-full'
|
| 126 |
+
Requires-Dist: ocifs; extra == 'test-full'
|
| 127 |
+
Requires-Dist: pandas<3.0.0; extra == 'test-full'
|
| 128 |
+
Requires-Dist: panel; extra == 'test-full'
|
| 129 |
+
Requires-Dist: paramiko; extra == 'test-full'
|
| 130 |
+
Requires-Dist: pyarrow; extra == 'test-full'
|
| 131 |
+
Requires-Dist: pyarrow>=1; extra == 'test-full'
|
| 132 |
+
Requires-Dist: pyftpdlib; extra == 'test-full'
|
| 133 |
+
Requires-Dist: pygit2; extra == 'test-full'
|
| 134 |
+
Requires-Dist: pytest; extra == 'test-full'
|
| 135 |
+
Requires-Dist: pytest-asyncio!=0.22.0; extra == 'test-full'
|
| 136 |
+
Requires-Dist: pytest-benchmark; extra == 'test-full'
|
| 137 |
+
Requires-Dist: pytest-cov; extra == 'test-full'
|
| 138 |
+
Requires-Dist: pytest-mock; extra == 'test-full'
|
| 139 |
+
Requires-Dist: pytest-recording; extra == 'test-full'
|
| 140 |
+
Requires-Dist: pytest-rerunfailures; extra == 'test-full'
|
| 141 |
+
Requires-Dist: python-snappy; extra == 'test-full'
|
| 142 |
+
Requires-Dist: requests; extra == 'test-full'
|
| 143 |
+
Requires-Dist: smbprotocol; extra == 'test-full'
|
| 144 |
+
Requires-Dist: tqdm; extra == 'test-full'
|
| 145 |
+
Requires-Dist: urllib3; extra == 'test-full'
|
| 146 |
+
Requires-Dist: zarr; extra == 'test-full'
|
| 147 |
+
Requires-Dist: zstandard; (python_version < '3.14') and extra == 'test-full'
|
| 148 |
+
Provides-Extra: tqdm
|
| 149 |
+
Requires-Dist: tqdm; extra == 'tqdm'
|
| 150 |
+
Description-Content-Type: text/markdown
|
| 151 |
+
|
| 152 |
+
# filesystem_spec
|
| 153 |
+
|
| 154 |
+
[](https://pypi.python.org/pypi/fsspec/)
|
| 155 |
+
[](https://anaconda.org/conda-forge/fsspec)
|
| 156 |
+

|
| 157 |
+
[](https://filesystem-spec.readthedocs.io/en/latest/?badge=latest)
|
| 158 |
+
|
| 159 |
+
A specification for pythonic filesystems.
|
| 160 |
+
|
| 161 |
+
## Install
|
| 162 |
+
|
| 163 |
+
```bash
|
| 164 |
+
pip install fsspec
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
would install the base fsspec. Various optionally supported features might require specification of custom
|
| 168 |
+
extra require, e.g. `pip install fsspec[ssh]` will install dependencies for `ssh` backends support.
|
| 169 |
+
Use `pip install fsspec[full]` for installation of all known extra dependencies.
|
| 170 |
+
|
| 171 |
+
Up-to-date package also provided through conda-forge distribution:
|
| 172 |
+
|
| 173 |
+
```bash
|
| 174 |
+
conda install -c conda-forge fsspec
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
## Purpose
|
| 179 |
+
|
| 180 |
+
To produce a template or specification for a file-system interface, that specific implementations should follow,
|
| 181 |
+
so that applications making use of them can rely on a common behaviour and not have to worry about the specific
|
| 182 |
+
internal implementation decisions with any given backend. Many such implementations are included in this package,
|
| 183 |
+
or in sister projects such as `s3fs` and `gcsfs`.
|
| 184 |
+
|
| 185 |
+
In addition, if this is well-designed, then additional functionality, such as a key-value store or FUSE
|
| 186 |
+
mounting of the file-system implementation may be available for all implementations "for free".
|
| 187 |
+
|
| 188 |
+
## Documentation
|
| 189 |
+
|
| 190 |
+
Please refer to [RTD](https://filesystem-spec.readthedocs.io/en/latest/?badge=latest)
|
| 191 |
+
|
| 192 |
+
## Develop
|
| 193 |
+
|
| 194 |
+
fsspec uses GitHub Actions for CI. Environment files can be found
|
| 195 |
+
in the "ci/" directory. Note that the main environment is called "py38",
|
| 196 |
+
but it is expected that the version of python installed be adjustable at
|
| 197 |
+
CI runtime. For local use, pick a version suitable for you.
|
| 198 |
+
|
| 199 |
+
```bash
|
| 200 |
+
# For a new environment (mamba / conda).
|
| 201 |
+
mamba create -n fsspec -c conda-forge python=3.10 -y
|
| 202 |
+
conda activate fsspec
|
| 203 |
+
|
| 204 |
+
# Standard dev install with docs and tests.
|
| 205 |
+
pip install -e ".[dev,doc,test]"
|
| 206 |
+
|
| 207 |
+
# Full tests except for downstream
|
| 208 |
+
pip install s3fs
|
| 209 |
+
pip uninstall s3fs
|
| 210 |
+
pip install -e .[dev,doc,test_full]
|
| 211 |
+
pip install s3fs --no-deps
|
| 212 |
+
pytest -v
|
| 213 |
+
|
| 214 |
+
# Downstream tests.
|
| 215 |
+
sh install_s3fs.sh
|
| 216 |
+
# Windows powershell.
|
| 217 |
+
install_s3fs.sh
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
### Testing
|
| 221 |
+
|
| 222 |
+
Tests can be run in the dev environment, if activated, via ``pytest fsspec``.
|
| 223 |
+
|
| 224 |
+
The full fsspec suite requires a system-level docker, docker-compose, and fuse
|
| 225 |
+
installation. If only making changes to one backend implementation, it is
|
| 226 |
+
not generally necessary to run all tests locally.
|
| 227 |
+
|
| 228 |
+
It is expected that contributors ensure that any change to fsspec does not
|
| 229 |
+
cause issues or regressions for either other fsspec-related packages such
|
| 230 |
+
as gcsfs and s3fs, nor for downstream users of fsspec. The "downstream" CI
|
| 231 |
+
run and corresponding environment file run a set of tests from the dask
|
| 232 |
+
test suite, and very minimal tests against pandas and zarr from the
|
| 233 |
+
test_downstream.py module in this repo.
|
| 234 |
+
|
| 235 |
+
### Code Formatting
|
| 236 |
+
|
| 237 |
+
fsspec uses [Black](https://black.readthedocs.io/en/stable) to ensure
|
| 238 |
+
a consistent code format throughout the project.
|
| 239 |
+
Run ``black fsspec`` from the root of the filesystem_spec repository to
|
| 240 |
+
auto-format your code. Additionally, many editors have plugins that will apply
|
| 241 |
+
``black`` as you edit files. ``black`` is included in the ``tox`` environments.
|
| 242 |
+
|
| 243 |
+
Optionally, you may wish to setup [pre-commit hooks](https://pre-commit.com) to
|
| 244 |
+
automatically run ``black`` when you make a git commit.
|
| 245 |
+
Run ``pre-commit install --install-hooks`` from the root of the
|
| 246 |
+
filesystem_spec repository to setup pre-commit hooks. ``black`` will now be run
|
| 247 |
+
before you commit, reformatting any changed files. You can format without
|
| 248 |
+
committing via ``pre-commit run`` or skip these checks with ``git commit
|
| 249 |
+
--no-verify``.
|
| 250 |
+
|
| 251 |
+
## Support
|
| 252 |
+
|
| 253 |
+
Work on this repository is supported in part by:
|
| 254 |
+
|
| 255 |
+
"Anaconda, Inc. - Advancing AI through open source."
|
| 256 |
+
|
| 257 |
+
<a href="https://anaconda.com/"><img src="https://camo.githubusercontent.com/b8555ef2222598ed37ce38ac86955febbd25de7619931bb7dd3c58432181d3b6/68747470733a2f2f626565776172652e6f72672f636f6d6d756e6974792f6d656d626572732f616e61636f6e64612f616e61636f6e64612d6c617267652e706e67" alt="anaconda logo" width="40%"/></a>
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fsspec-2026.2.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
fsspec-2026.2.0.dist-info/METADATA,sha256=Pw6QhbyXeg-elb0hpWPiQRpAeMD_ApJ9vdNFoYCnrPs,10524
|
| 3 |
+
fsspec-2026.2.0.dist-info/RECORD,,
|
| 4 |
+
fsspec-2026.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
| 5 |
+
fsspec-2026.2.0.dist-info/licenses/LICENSE,sha256=LcNUls5TpzB5FcAIqESq1T53K0mzTN0ARFBnaRQH7JQ,1513
|
| 6 |
+
fsspec/__init__.py,sha256=L7qwNBU1iMNQd8Of87HYSNFT9gWlNMSESaJC8fY0AaQ,2053
|
| 7 |
+
fsspec/__pycache__/__init__.cpython-312.pyc,,
|
| 8 |
+
fsspec/__pycache__/_version.cpython-312.pyc,,
|
| 9 |
+
fsspec/__pycache__/archive.cpython-312.pyc,,
|
| 10 |
+
fsspec/__pycache__/asyn.cpython-312.pyc,,
|
| 11 |
+
fsspec/__pycache__/caching.cpython-312.pyc,,
|
| 12 |
+
fsspec/__pycache__/callbacks.cpython-312.pyc,,
|
| 13 |
+
fsspec/__pycache__/compression.cpython-312.pyc,,
|
| 14 |
+
fsspec/__pycache__/config.cpython-312.pyc,,
|
| 15 |
+
fsspec/__pycache__/conftest.cpython-312.pyc,,
|
| 16 |
+
fsspec/__pycache__/core.cpython-312.pyc,,
|
| 17 |
+
fsspec/__pycache__/dircache.cpython-312.pyc,,
|
| 18 |
+
fsspec/__pycache__/exceptions.cpython-312.pyc,,
|
| 19 |
+
fsspec/__pycache__/fuse.cpython-312.pyc,,
|
| 20 |
+
fsspec/__pycache__/generic.cpython-312.pyc,,
|
| 21 |
+
fsspec/__pycache__/gui.cpython-312.pyc,,
|
| 22 |
+
fsspec/__pycache__/json.cpython-312.pyc,,
|
| 23 |
+
fsspec/__pycache__/mapping.cpython-312.pyc,,
|
| 24 |
+
fsspec/__pycache__/parquet.cpython-312.pyc,,
|
| 25 |
+
fsspec/__pycache__/registry.cpython-312.pyc,,
|
| 26 |
+
fsspec/__pycache__/spec.cpython-312.pyc,,
|
| 27 |
+
fsspec/__pycache__/transaction.cpython-312.pyc,,
|
| 28 |
+
fsspec/__pycache__/utils.cpython-312.pyc,,
|
| 29 |
+
fsspec/_version.py,sha256=AEamMn8IHx_wGXrogRYVBycv6M5u2_UCmFedn7R8hYI,710
|
| 30 |
+
fsspec/archive.py,sha256=vM6t_lgV6lBWbBYwpm3S4ofBQFQxUPr5KkDQrrQcQro,2411
|
| 31 |
+
fsspec/asyn.py,sha256=LP_OicTWXmKHe31wBoYs2MrrNf8rmlhjVeGg5AqvVy8,36630
|
| 32 |
+
fsspec/caching.py,sha256=8IJ4rgcWnvq_b_DqlcMGJ-K59d4Db5O9Gz8PkATAgHo,34023
|
| 33 |
+
fsspec/callbacks.py,sha256=BDIwLzK6rr_0V5ch557fSzsivCElpdqhXr5dZ9Te-EE,9210
|
| 34 |
+
fsspec/compression.py,sha256=3v_Fe39gzRRWfaeXpzNjAGPqgTzmETYRCo3qHVqD3po,5132
|
| 35 |
+
fsspec/config.py,sha256=LF4Zmu1vhJW7Je9Q-cwkRc3xP7Rhyy7Xnwj26Z6sv2g,4279
|
| 36 |
+
fsspec/conftest.py,sha256=uWfm_Qs5alPRxOhRpDfQ0-1jqSJ54pni4y96IxOREXM,3446
|
| 37 |
+
fsspec/core.py,sha256=lc7XSnZU6_C6xljp7Z_xEGN3V7704hbeQLkxvPP0wds,24173
|
| 38 |
+
fsspec/dircache.py,sha256=YzogWJrhEastHU7vWz-cJiJ7sdtLXFXhEpInGKd4EcM,2717
|
| 39 |
+
fsspec/exceptions.py,sha256=pauSLDMxzTJMOjvX1WEUK0cMyFkrFxpWJsyFywav7A8,331
|
| 40 |
+
fsspec/fuse.py,sha256=Q-3NOOyLqBfYa4Db5E19z_ZY36zzYHtIs1mOUasItBQ,10177
|
| 41 |
+
fsspec/generic.py,sha256=9QHQYMNb-8w8-eYuIqShcTjO_LeHXFoQTyt8J5oEq5Q,13482
|
| 42 |
+
fsspec/gui.py,sha256=CQ7QsrTpaDlWSLNOpwNoJc7khOcYXIZxmrAJN9bHWQU,14002
|
| 43 |
+
fsspec/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 44 |
+
fsspec/implementations/__pycache__/__init__.cpython-312.pyc,,
|
| 45 |
+
fsspec/implementations/__pycache__/arrow.cpython-312.pyc,,
|
| 46 |
+
fsspec/implementations/__pycache__/asyn_wrapper.cpython-312.pyc,,
|
| 47 |
+
fsspec/implementations/__pycache__/cache_mapper.cpython-312.pyc,,
|
| 48 |
+
fsspec/implementations/__pycache__/cache_metadata.cpython-312.pyc,,
|
| 49 |
+
fsspec/implementations/__pycache__/cached.cpython-312.pyc,,
|
| 50 |
+
fsspec/implementations/__pycache__/chained.cpython-312.pyc,,
|
| 51 |
+
fsspec/implementations/__pycache__/dask.cpython-312.pyc,,
|
| 52 |
+
fsspec/implementations/__pycache__/data.cpython-312.pyc,,
|
| 53 |
+
fsspec/implementations/__pycache__/dbfs.cpython-312.pyc,,
|
| 54 |
+
fsspec/implementations/__pycache__/dirfs.cpython-312.pyc,,
|
| 55 |
+
fsspec/implementations/__pycache__/ftp.cpython-312.pyc,,
|
| 56 |
+
fsspec/implementations/__pycache__/gist.cpython-312.pyc,,
|
| 57 |
+
fsspec/implementations/__pycache__/git.cpython-312.pyc,,
|
| 58 |
+
fsspec/implementations/__pycache__/github.cpython-312.pyc,,
|
| 59 |
+
fsspec/implementations/__pycache__/http.cpython-312.pyc,,
|
| 60 |
+
fsspec/implementations/__pycache__/http_sync.cpython-312.pyc,,
|
| 61 |
+
fsspec/implementations/__pycache__/jupyter.cpython-312.pyc,,
|
| 62 |
+
fsspec/implementations/__pycache__/libarchive.cpython-312.pyc,,
|
| 63 |
+
fsspec/implementations/__pycache__/local.cpython-312.pyc,,
|
| 64 |
+
fsspec/implementations/__pycache__/memory.cpython-312.pyc,,
|
| 65 |
+
fsspec/implementations/__pycache__/reference.cpython-312.pyc,,
|
| 66 |
+
fsspec/implementations/__pycache__/sftp.cpython-312.pyc,,
|
| 67 |
+
fsspec/implementations/__pycache__/smb.cpython-312.pyc,,
|
| 68 |
+
fsspec/implementations/__pycache__/tar.cpython-312.pyc,,
|
| 69 |
+
fsspec/implementations/__pycache__/webhdfs.cpython-312.pyc,,
|
| 70 |
+
fsspec/implementations/__pycache__/zip.cpython-312.pyc,,
|
| 71 |
+
fsspec/implementations/arrow.py,sha256=8FhvcvOYLZNMMegCYFFCEHgEqig8AkOU7Ehb8XfcgnA,8890
|
| 72 |
+
fsspec/implementations/asyn_wrapper.py,sha256=3lfJkGs6D_AwRBdxTSYlL-RCVdaXBZ9Itys2P5o5Si0,3738
|
| 73 |
+
fsspec/implementations/cache_mapper.py,sha256=W4wlxyPxZbSp9ItJ0pYRVBMh6bw9eFypgP6kUYuuiI4,2421
|
| 74 |
+
fsspec/implementations/cache_metadata.py,sha256=ipIe4S8nlU_M9oRJkvTqr-b0tcbXVZsxH3GxaelaNOY,8502
|
| 75 |
+
fsspec/implementations/cached.py,sha256=67ipbj-3o8O1zMGR11rZ_IWCi_7h-VRYpEAowFXqrvA,36175
|
| 76 |
+
fsspec/implementations/chained.py,sha256=iGivpNaHUFjB_ea0-HAPhcmm6CL8qnDf270PSj7JwuE,680
|
| 77 |
+
fsspec/implementations/dask.py,sha256=CXZbJzIVOhKV8ILcxuy3bTvcacCueAbyQxmvAkbPkrk,4466
|
| 78 |
+
fsspec/implementations/data.py,sha256=IhOGDkacYp5gkl9jhEu4msQfZPb0gS5Q_ml7Mbr6dgQ,1627
|
| 79 |
+
fsspec/implementations/dbfs.py,sha256=1cvvC6KBWOb8pBVpc01xavVbEPXO1xsgZvPD7H73M9k,16217
|
| 80 |
+
fsspec/implementations/dirfs.py,sha256=VNj6gPMfmmLPK4wxbtxt7mUqW7xkh2XDgMmEmSK_E1c,12166
|
| 81 |
+
fsspec/implementations/ftp.py,sha256=fJhaMIKq2RvzYlLwG3bewy2jq4iRqjVt1aIpwtUIRwI,13235
|
| 82 |
+
fsspec/implementations/gist.py,sha256=Y6jTDrE-wuTwvpPyAQDuuOMBGxlajafKWoB1_yX6jdY,8528
|
| 83 |
+
fsspec/implementations/git.py,sha256=qBDWMz5LNllPqVjr5jf_1FuNha4P5lyQI3IlhYg-wUE,3731
|
| 84 |
+
fsspec/implementations/github.py,sha256=aCsZL8UvXZgdkcB1RUs3DdLeNrjLKcFsFYeQFDWbBFo,11653
|
| 85 |
+
fsspec/implementations/http.py,sha256=-AV5qeNpBWqnsmgnIO9Ily9B6--SR4sQJ7G4cBHarGE,30675
|
| 86 |
+
fsspec/implementations/http_sync.py,sha256=UmBqd938ebwVjYgVtzg-ysG3ZoGhIJw0wFtQAfxV3Aw,30332
|
| 87 |
+
fsspec/implementations/jupyter.py,sha256=q1PlQ66AAswGFyr8MFKWyobaV2YekMWRtqENBDQtD28,4002
|
| 88 |
+
fsspec/implementations/libarchive.py,sha256=SpIA1F-zf7kb2-VYUVuhMrXTBOhBxUXKgEW1RaAdDoA,7098
|
| 89 |
+
fsspec/implementations/local.py,sha256=ERDUdXdRI8AvRX06icXaDKwO-hcQgivc7EorqnayFFM,17028
|
| 90 |
+
fsspec/implementations/memory.py,sha256=TDdLtSPWXxZKrrVGwmc3uS3oK_2mlcVTk2BiqR8IeII,10507
|
| 91 |
+
fsspec/implementations/reference.py,sha256=xSUpB8o_QFAZiVJE2dt78QZMCUMLo5TaJ27e5DwDAfg,48814
|
| 92 |
+
fsspec/implementations/sftp.py,sha256=L9pZOa6eLUWfJNtxkxeG2YI96SQwrM5Hj6ocyUZXUbg,5923
|
| 93 |
+
fsspec/implementations/smb.py,sha256=5fhu8h06nOLBPh2c48aT7WBRqh9cEcbIwtyu06wTjec,15236
|
| 94 |
+
fsspec/implementations/tar.py,sha256=dam78Tp_CozybNqCY2JYgGBS3Uc9FuJUAT9oB0lolOs,4111
|
| 95 |
+
fsspec/implementations/webhdfs.py,sha256=osF2m0nhDil6sbMzYW_4DZzhxF4ygtb59XDiybd9Fyg,17589
|
| 96 |
+
fsspec/implementations/zip.py,sha256=6f3z0s12tDbz1RMx7iDc3JDx730IAaKDdx7tf_XYDp0,6151
|
| 97 |
+
fsspec/json.py,sha256=4EBZ-xOmRiyxmIqPIwxmDImosRQ7io7qBM2xjJPsEE4,3768
|
| 98 |
+
fsspec/mapping.py,sha256=m2ndB_gtRBXYmNJg0Ie1-BVR75TFleHmIQBzC-yWhjU,8343
|
| 99 |
+
fsspec/parquet.py,sha256=xGW3xfd9js7hrre7qN85XpSM0A1FObqkTcAv_H2xSwY,20505
|
| 100 |
+
fsspec/registry.py,sha256=o7EGl8TEaLkcwN53X_103arzuzJeeOoVaNUWnPiXgf0,12148
|
| 101 |
+
fsspec/spec.py,sha256=Ym-Ust6LRjHgbhrmvNqwOBZxoVnaw3g3xHXMZGHx_xg,77692
|
| 102 |
+
fsspec/tests/abstract/__init__.py,sha256=4xUJrv7gDgc85xAOz1p-V_K1hrsdMWTSa0rviALlJk8,10181
|
| 103 |
+
fsspec/tests/abstract/__pycache__/__init__.cpython-312.pyc,,
|
| 104 |
+
fsspec/tests/abstract/__pycache__/common.cpython-312.pyc,,
|
| 105 |
+
fsspec/tests/abstract/__pycache__/copy.cpython-312.pyc,,
|
| 106 |
+
fsspec/tests/abstract/__pycache__/get.cpython-312.pyc,,
|
| 107 |
+
fsspec/tests/abstract/__pycache__/mv.cpython-312.pyc,,
|
| 108 |
+
fsspec/tests/abstract/__pycache__/open.cpython-312.pyc,,
|
| 109 |
+
fsspec/tests/abstract/__pycache__/pipe.cpython-312.pyc,,
|
| 110 |
+
fsspec/tests/abstract/__pycache__/put.cpython-312.pyc,,
|
| 111 |
+
fsspec/tests/abstract/common.py,sha256=1GQwNo5AONzAnzZj0fWgn8NJPLXALehbsuGxS3FzWVU,4973
|
| 112 |
+
fsspec/tests/abstract/copy.py,sha256=gU5-d97U3RSde35Vp4RxPY4rWwL744HiSrJ8IBOp9-8,19967
|
| 113 |
+
fsspec/tests/abstract/get.py,sha256=vNR4HztvTR7Cj56AMo7_tx7TeYz1Jgr_2Wb8Lv-UiBY,20755
|
| 114 |
+
fsspec/tests/abstract/mv.py,sha256=k8eUEBIrRrGMsBY5OOaDXdGnQUKGwDIfQyduB6YD3Ns,1982
|
| 115 |
+
fsspec/tests/abstract/open.py,sha256=Fi2PBPYLbRqysF8cFm0rwnB41kMdQVYjq8cGyDXp3BU,329
|
| 116 |
+
fsspec/tests/abstract/pipe.py,sha256=LFzIrLCB5GLXf9rzFKJmE8AdG7LQ_h4bJo70r8FLPqM,402
|
| 117 |
+
fsspec/tests/abstract/put.py,sha256=7aih17OKB_IZZh1Mkq1eBDIjobhtMQmI8x-Pw-S_aZk,21201
|
| 118 |
+
fsspec/transaction.py,sha256=xliRG6U2Zf3khG4xcw9WiB-yAoqJSHEGK_VjHOdtgo0,2398
|
| 119 |
+
fsspec/utils.py,sha256=E24ji0XLWC6n3bw2sHA28OYxrGU9Wy_al2XydsRgrRk,23623
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec-2026.2.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: hatchling 1.28.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import caching
|
| 2 |
+
from ._version import __version__ # noqa: F401
|
| 3 |
+
from .callbacks import Callback
|
| 4 |
+
from .compression import available_compressions
|
| 5 |
+
from .core import get_fs_token_paths, open, open_files, open_local, url_to_fs
|
| 6 |
+
from .exceptions import FSTimeoutError
|
| 7 |
+
from .mapping import FSMap, get_mapper
|
| 8 |
+
from .registry import (
|
| 9 |
+
available_protocols,
|
| 10 |
+
filesystem,
|
| 11 |
+
get_filesystem_class,
|
| 12 |
+
register_implementation,
|
| 13 |
+
registry,
|
| 14 |
+
)
|
| 15 |
+
from .spec import AbstractFileSystem
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
"AbstractFileSystem",
|
| 19 |
+
"FSTimeoutError",
|
| 20 |
+
"FSMap",
|
| 21 |
+
"filesystem",
|
| 22 |
+
"register_implementation",
|
| 23 |
+
"get_filesystem_class",
|
| 24 |
+
"get_fs_token_paths",
|
| 25 |
+
"get_mapper",
|
| 26 |
+
"open",
|
| 27 |
+
"open_files",
|
| 28 |
+
"open_local",
|
| 29 |
+
"registry",
|
| 30 |
+
"caching",
|
| 31 |
+
"Callback",
|
| 32 |
+
"available_protocols",
|
| 33 |
+
"available_compressions",
|
| 34 |
+
"url_to_fs",
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def process_entries():
|
| 39 |
+
try:
|
| 40 |
+
from importlib.metadata import entry_points
|
| 41 |
+
except ImportError:
|
| 42 |
+
return
|
| 43 |
+
if entry_points is not None:
|
| 44 |
+
try:
|
| 45 |
+
eps = entry_points()
|
| 46 |
+
except TypeError:
|
| 47 |
+
pass # importlib-metadata < 0.8
|
| 48 |
+
else:
|
| 49 |
+
if hasattr(eps, "select"): # Python 3.10+ / importlib_metadata >= 3.9.0
|
| 50 |
+
specs = eps.select(group="fsspec.specs")
|
| 51 |
+
else:
|
| 52 |
+
specs = eps.get("fsspec.specs", [])
|
| 53 |
+
registered_names = {}
|
| 54 |
+
for spec in specs:
|
| 55 |
+
err_msg = f"Unable to load filesystem from {spec}"
|
| 56 |
+
name = spec.name
|
| 57 |
+
if name in registered_names:
|
| 58 |
+
continue
|
| 59 |
+
registered_names[name] = True
|
| 60 |
+
register_implementation(
|
| 61 |
+
name,
|
| 62 |
+
spec.value.replace(":", "."),
|
| 63 |
+
errtxt=err_msg,
|
| 64 |
+
# We take our implementations as the ones to overload with if
|
| 65 |
+
# for some reason we encounter some, may be the same, already
|
| 66 |
+
# registered
|
| 67 |
+
clobber=True,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
process_entries()
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# file generated by setuptools-scm
|
| 2 |
+
# don't change, don't track in version control
|
| 3 |
+
|
| 4 |
+
__all__ = [
|
| 5 |
+
"__version__",
|
| 6 |
+
"__version_tuple__",
|
| 7 |
+
"version",
|
| 8 |
+
"version_tuple",
|
| 9 |
+
"__commit_id__",
|
| 10 |
+
"commit_id",
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
TYPE_CHECKING = False
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from typing import Tuple
|
| 16 |
+
from typing import Union
|
| 17 |
+
|
| 18 |
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
| 19 |
+
COMMIT_ID = Union[str, None]
|
| 20 |
+
else:
|
| 21 |
+
VERSION_TUPLE = object
|
| 22 |
+
COMMIT_ID = object
|
| 23 |
+
|
| 24 |
+
version: str
|
| 25 |
+
__version__: str
|
| 26 |
+
__version_tuple__: VERSION_TUPLE
|
| 27 |
+
version_tuple: VERSION_TUPLE
|
| 28 |
+
commit_id: COMMIT_ID
|
| 29 |
+
__commit_id__: COMMIT_ID
|
| 30 |
+
|
| 31 |
+
__version__ = version = '2026.2.0'
|
| 32 |
+
__version_tuple__ = version_tuple = (2026, 2, 0)
|
| 33 |
+
|
| 34 |
+
__commit_id__ = commit_id = None
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec/archive.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import operator
|
| 2 |
+
|
| 3 |
+
from fsspec import AbstractFileSystem
|
| 4 |
+
from fsspec.utils import tokenize
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class AbstractArchiveFileSystem(AbstractFileSystem):
|
| 8 |
+
"""
|
| 9 |
+
A generic superclass for implementing Archive-based filesystems.
|
| 10 |
+
|
| 11 |
+
Currently, it is shared amongst
|
| 12 |
+
:class:`~fsspec.implementations.zip.ZipFileSystem`,
|
| 13 |
+
:class:`~fsspec.implementations.libarchive.LibArchiveFileSystem` and
|
| 14 |
+
:class:`~fsspec.implementations.tar.TarFileSystem`.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
def __str__(self):
|
| 18 |
+
return f"<Archive-like object {type(self).__name__} at {id(self)}>"
|
| 19 |
+
|
| 20 |
+
__repr__ = __str__
|
| 21 |
+
|
| 22 |
+
def ukey(self, path):
|
| 23 |
+
return tokenize(path, self.fo, self.protocol)
|
| 24 |
+
|
| 25 |
+
def _all_dirnames(self, paths):
|
| 26 |
+
"""Returns *all* directory names for each path in paths, including intermediate
|
| 27 |
+
ones.
|
| 28 |
+
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
paths: Iterable of path strings
|
| 32 |
+
"""
|
| 33 |
+
if len(paths) == 0:
|
| 34 |
+
return set()
|
| 35 |
+
|
| 36 |
+
dirnames = {self._parent(path) for path in paths} - {self.root_marker}
|
| 37 |
+
return dirnames | self._all_dirnames(dirnames)
|
| 38 |
+
|
| 39 |
+
def info(self, path, **kwargs):
|
| 40 |
+
self._get_dirs()
|
| 41 |
+
path = self._strip_protocol(path)
|
| 42 |
+
if path in {"", "/"} and self.dir_cache:
|
| 43 |
+
return {"name": "", "type": "directory", "size": 0}
|
| 44 |
+
if path in self.dir_cache:
|
| 45 |
+
return self.dir_cache[path]
|
| 46 |
+
elif path + "/" in self.dir_cache:
|
| 47 |
+
return self.dir_cache[path + "/"]
|
| 48 |
+
else:
|
| 49 |
+
raise FileNotFoundError(path)
|
| 50 |
+
|
| 51 |
+
def ls(self, path, detail=True, **kwargs):
|
| 52 |
+
self._get_dirs()
|
| 53 |
+
paths = {}
|
| 54 |
+
for p, f in self.dir_cache.items():
|
| 55 |
+
p = p.rstrip("/")
|
| 56 |
+
if "/" in p:
|
| 57 |
+
root = p.rsplit("/", 1)[0]
|
| 58 |
+
else:
|
| 59 |
+
root = ""
|
| 60 |
+
if root == path.rstrip("/"):
|
| 61 |
+
paths[p] = f
|
| 62 |
+
elif all(
|
| 63 |
+
(a == b)
|
| 64 |
+
for a, b in zip(path.split("/"), [""] + p.strip("/").split("/"))
|
| 65 |
+
):
|
| 66 |
+
# root directory entry
|
| 67 |
+
ppath = p.rstrip("/").split("/", 1)[0]
|
| 68 |
+
if ppath not in paths:
|
| 69 |
+
out = {"name": ppath, "size": 0, "type": "directory"}
|
| 70 |
+
paths[ppath] = out
|
| 71 |
+
if detail:
|
| 72 |
+
out = sorted(paths.values(), key=operator.itemgetter("name"))
|
| 73 |
+
return out
|
| 74 |
+
else:
|
| 75 |
+
return sorted(paths)
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec/asyn.py
ADDED
|
@@ -0,0 +1,1103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import asyncio.events
|
| 3 |
+
import functools
|
| 4 |
+
import inspect
|
| 5 |
+
import io
|
| 6 |
+
import numbers
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
import threading
|
| 10 |
+
from collections.abc import Iterable
|
| 11 |
+
from glob import has_magic
|
| 12 |
+
from typing import TYPE_CHECKING
|
| 13 |
+
|
| 14 |
+
from .callbacks import DEFAULT_CALLBACK
|
| 15 |
+
from .exceptions import FSTimeoutError
|
| 16 |
+
from .implementations.local import LocalFileSystem, make_path_posix, trailing_sep
|
| 17 |
+
from .spec import AbstractBufferedFile, AbstractFileSystem
|
| 18 |
+
from .utils import glob_translate, is_exception, other_paths
|
| 19 |
+
|
| 20 |
+
private = re.compile("_[^_]")
|
| 21 |
+
iothread = [None] # dedicated fsspec IO thread
|
| 22 |
+
loop = [None] # global event loop for any non-async instance
|
| 23 |
+
_lock = None # global lock placeholder
|
| 24 |
+
get_running_loop = asyncio.get_running_loop
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_lock():
|
| 28 |
+
"""Allocate or return a threading lock.
|
| 29 |
+
|
| 30 |
+
The lock is allocated on first use to allow setting one lock per forked process.
|
| 31 |
+
"""
|
| 32 |
+
global _lock
|
| 33 |
+
if not _lock:
|
| 34 |
+
_lock = threading.Lock()
|
| 35 |
+
return _lock
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def reset_lock():
|
| 39 |
+
"""Reset the global lock.
|
| 40 |
+
|
| 41 |
+
This should be called only on the init of a forked process to reset the lock to
|
| 42 |
+
None, enabling the new forked process to get a new lock.
|
| 43 |
+
"""
|
| 44 |
+
global _lock
|
| 45 |
+
|
| 46 |
+
iothread[0] = None
|
| 47 |
+
loop[0] = None
|
| 48 |
+
_lock = None
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
async def _runner(event, coro, result, timeout=None):
|
| 52 |
+
timeout = timeout if timeout else None # convert 0 or 0.0 to None
|
| 53 |
+
if timeout is not None:
|
| 54 |
+
coro = asyncio.wait_for(coro, timeout=timeout)
|
| 55 |
+
try:
|
| 56 |
+
result[0] = await coro
|
| 57 |
+
except Exception as ex:
|
| 58 |
+
result[0] = ex
|
| 59 |
+
finally:
|
| 60 |
+
event.set()
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def sync(loop, func, *args, timeout=None, **kwargs):
|
| 64 |
+
"""
|
| 65 |
+
Make loop run coroutine until it returns. Runs in other thread
|
| 66 |
+
|
| 67 |
+
Examples
|
| 68 |
+
--------
|
| 69 |
+
>>> fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args,
|
| 70 |
+
timeout=timeout, **kwargs)
|
| 71 |
+
"""
|
| 72 |
+
timeout = timeout if timeout else None # convert 0 or 0.0 to None
|
| 73 |
+
# NB: if the loop is not running *yet*, it is OK to submit work
|
| 74 |
+
# and we will wait for it
|
| 75 |
+
if loop is None or loop.is_closed():
|
| 76 |
+
raise RuntimeError("Loop is not running")
|
| 77 |
+
try:
|
| 78 |
+
loop0 = asyncio.events.get_running_loop()
|
| 79 |
+
if loop0 is loop:
|
| 80 |
+
raise NotImplementedError("Calling sync() from within a running loop")
|
| 81 |
+
except NotImplementedError:
|
| 82 |
+
raise
|
| 83 |
+
except RuntimeError:
|
| 84 |
+
pass
|
| 85 |
+
coro = func(*args, **kwargs)
|
| 86 |
+
result = [None]
|
| 87 |
+
event = threading.Event()
|
| 88 |
+
asyncio.run_coroutine_threadsafe(_runner(event, coro, result, timeout), loop)
|
| 89 |
+
while True:
|
| 90 |
+
# this loops allows thread to get interrupted
|
| 91 |
+
if event.wait(1):
|
| 92 |
+
break
|
| 93 |
+
if timeout is not None:
|
| 94 |
+
timeout -= 1
|
| 95 |
+
if timeout < 0:
|
| 96 |
+
raise FSTimeoutError
|
| 97 |
+
|
| 98 |
+
return_result = result[0]
|
| 99 |
+
if isinstance(return_result, asyncio.TimeoutError):
|
| 100 |
+
# suppress asyncio.TimeoutError, raise FSTimeoutError
|
| 101 |
+
raise FSTimeoutError from return_result
|
| 102 |
+
elif isinstance(return_result, BaseException):
|
| 103 |
+
raise return_result
|
| 104 |
+
else:
|
| 105 |
+
return return_result
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def sync_wrapper(func, obj=None):
|
| 109 |
+
"""Given a function, make so can be called in blocking contexts
|
| 110 |
+
|
| 111 |
+
Leave obj=None if defining within a class. Pass the instance if attaching
|
| 112 |
+
as an attribute of the instance.
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
@functools.wraps(func)
|
| 116 |
+
def wrapper(*args, **kwargs):
|
| 117 |
+
self = obj or args[0]
|
| 118 |
+
return sync(self.loop, func, *args, **kwargs)
|
| 119 |
+
|
| 120 |
+
return wrapper
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def get_loop():
|
| 124 |
+
"""Create or return the default fsspec IO loop
|
| 125 |
+
|
| 126 |
+
The loop will be running on a separate thread.
|
| 127 |
+
"""
|
| 128 |
+
if loop[0] is None:
|
| 129 |
+
with get_lock():
|
| 130 |
+
# repeat the check just in case the loop got filled between the
|
| 131 |
+
# previous two calls from another thread
|
| 132 |
+
if loop[0] is None:
|
| 133 |
+
loop[0] = asyncio.new_event_loop()
|
| 134 |
+
th = threading.Thread(target=loop[0].run_forever, name="fsspecIO")
|
| 135 |
+
th.daemon = True
|
| 136 |
+
th.start()
|
| 137 |
+
iothread[0] = th
|
| 138 |
+
return loop[0]
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def reset_after_fork():
|
| 142 |
+
global lock
|
| 143 |
+
loop[0] = None
|
| 144 |
+
iothread[0] = None
|
| 145 |
+
lock = None
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
if hasattr(os, "register_at_fork"):
|
| 149 |
+
# should be posix; this will do nothing for spawn or forkserver subprocesses
|
| 150 |
+
os.register_at_fork(after_in_child=reset_after_fork)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
if TYPE_CHECKING:
|
| 154 |
+
import resource
|
| 155 |
+
|
| 156 |
+
ResourceError = resource.error
|
| 157 |
+
else:
|
| 158 |
+
try:
|
| 159 |
+
import resource
|
| 160 |
+
except ImportError:
|
| 161 |
+
resource = None
|
| 162 |
+
ResourceError = OSError
|
| 163 |
+
else:
|
| 164 |
+
ResourceError = getattr(resource, "error", OSError)
|
| 165 |
+
|
| 166 |
+
_DEFAULT_BATCH_SIZE = 128
|
| 167 |
+
_NOFILES_DEFAULT_BATCH_SIZE = 1280
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def _get_batch_size(nofiles=False):
|
| 171 |
+
from fsspec.config import conf
|
| 172 |
+
|
| 173 |
+
if nofiles:
|
| 174 |
+
if "nofiles_gather_batch_size" in conf:
|
| 175 |
+
return conf["nofiles_gather_batch_size"]
|
| 176 |
+
else:
|
| 177 |
+
if "gather_batch_size" in conf:
|
| 178 |
+
return conf["gather_batch_size"]
|
| 179 |
+
if nofiles:
|
| 180 |
+
return _NOFILES_DEFAULT_BATCH_SIZE
|
| 181 |
+
if resource is None:
|
| 182 |
+
return _DEFAULT_BATCH_SIZE
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
|
| 186 |
+
except (ImportError, ValueError, ResourceError):
|
| 187 |
+
return _DEFAULT_BATCH_SIZE
|
| 188 |
+
|
| 189 |
+
if soft_limit == resource.RLIM_INFINITY:
|
| 190 |
+
return -1
|
| 191 |
+
else:
|
| 192 |
+
return soft_limit // 8
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def running_async() -> bool:
|
| 196 |
+
"""Being executed by an event loop?"""
|
| 197 |
+
try:
|
| 198 |
+
asyncio.get_running_loop()
|
| 199 |
+
return True
|
| 200 |
+
except RuntimeError:
|
| 201 |
+
return False
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
async def _run_coros_in_chunks(
|
| 205 |
+
coros,
|
| 206 |
+
batch_size=None,
|
| 207 |
+
callback=DEFAULT_CALLBACK,
|
| 208 |
+
timeout=None,
|
| 209 |
+
return_exceptions=False,
|
| 210 |
+
nofiles=False,
|
| 211 |
+
):
|
| 212 |
+
"""Run the given coroutines in chunks.
|
| 213 |
+
|
| 214 |
+
Parameters
|
| 215 |
+
----------
|
| 216 |
+
coros: list of coroutines to run
|
| 217 |
+
batch_size: int or None
|
| 218 |
+
Number of coroutines to submit/wait on simultaneously.
|
| 219 |
+
If -1, then it will not be any throttling. If
|
| 220 |
+
None, it will be inferred from _get_batch_size()
|
| 221 |
+
callback: fsspec.callbacks.Callback instance
|
| 222 |
+
Gets a relative_update when each coroutine completes
|
| 223 |
+
timeout: number or None
|
| 224 |
+
If given, each coroutine times out after this time. Note that, since
|
| 225 |
+
there are multiple batches, the total run time of this function will in
|
| 226 |
+
general be longer
|
| 227 |
+
return_exceptions: bool
|
| 228 |
+
Same meaning as in asyncio.gather
|
| 229 |
+
nofiles: bool
|
| 230 |
+
If inferring the batch_size, does this operation involve local files?
|
| 231 |
+
If yes, you normally expect smaller batches.
|
| 232 |
+
"""
|
| 233 |
+
|
| 234 |
+
if batch_size is None:
|
| 235 |
+
batch_size = _get_batch_size(nofiles=nofiles)
|
| 236 |
+
|
| 237 |
+
if batch_size == -1:
|
| 238 |
+
batch_size = len(coros)
|
| 239 |
+
|
| 240 |
+
assert batch_size > 0
|
| 241 |
+
|
| 242 |
+
async def _run_coro(coro, i):
|
| 243 |
+
try:
|
| 244 |
+
return await asyncio.wait_for(coro, timeout=timeout), i
|
| 245 |
+
except Exception as e:
|
| 246 |
+
if not return_exceptions:
|
| 247 |
+
raise
|
| 248 |
+
return e, i
|
| 249 |
+
finally:
|
| 250 |
+
callback.relative_update(1)
|
| 251 |
+
|
| 252 |
+
i = 0
|
| 253 |
+
n = len(coros)
|
| 254 |
+
results = [None] * n
|
| 255 |
+
pending = set()
|
| 256 |
+
|
| 257 |
+
while pending or i < n:
|
| 258 |
+
while len(pending) < batch_size and i < n:
|
| 259 |
+
pending.add(asyncio.ensure_future(_run_coro(coros[i], i)))
|
| 260 |
+
i += 1
|
| 261 |
+
|
| 262 |
+
if not pending:
|
| 263 |
+
break
|
| 264 |
+
|
| 265 |
+
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
|
| 266 |
+
while done:
|
| 267 |
+
result, k = await done.pop()
|
| 268 |
+
results[k] = result
|
| 269 |
+
|
| 270 |
+
return results
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
# these methods should be implemented as async by any async-able backend
|
| 274 |
+
async_methods = [
|
| 275 |
+
"_ls",
|
| 276 |
+
"_cat_file",
|
| 277 |
+
"_get_file",
|
| 278 |
+
"_put_file",
|
| 279 |
+
"_rm_file",
|
| 280 |
+
"_cp_file",
|
| 281 |
+
"_pipe_file",
|
| 282 |
+
"_expand_path",
|
| 283 |
+
"_info",
|
| 284 |
+
"_isfile",
|
| 285 |
+
"_isdir",
|
| 286 |
+
"_exists",
|
| 287 |
+
"_walk",
|
| 288 |
+
"_glob",
|
| 289 |
+
"_find",
|
| 290 |
+
"_du",
|
| 291 |
+
"_size",
|
| 292 |
+
"_mkdir",
|
| 293 |
+
"_makedirs",
|
| 294 |
+
]
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class AsyncFileSystem(AbstractFileSystem):
|
| 298 |
+
"""Async file operations, default implementations
|
| 299 |
+
|
| 300 |
+
Passes bulk operations to asyncio.gather for concurrent operation.
|
| 301 |
+
|
| 302 |
+
Implementations that have concurrent batch operations and/or async methods
|
| 303 |
+
should inherit from this class instead of AbstractFileSystem. Docstrings are
|
| 304 |
+
copied from the un-underscored method in AbstractFileSystem, if not given.
|
| 305 |
+
"""
|
| 306 |
+
|
| 307 |
+
# note that methods do not have docstring here; they will be copied
|
| 308 |
+
# for _* methods and inferred for overridden methods.
|
| 309 |
+
|
| 310 |
+
async_impl = True
|
| 311 |
+
mirror_sync_methods = True
|
| 312 |
+
disable_throttling = False
|
| 313 |
+
|
| 314 |
+
def __init__(self, *args, asynchronous=False, loop=None, batch_size=None, **kwargs):
|
| 315 |
+
self.asynchronous = asynchronous
|
| 316 |
+
self._pid = os.getpid()
|
| 317 |
+
if not asynchronous:
|
| 318 |
+
self._loop = loop or get_loop()
|
| 319 |
+
else:
|
| 320 |
+
self._loop = None
|
| 321 |
+
self.batch_size = batch_size
|
| 322 |
+
super().__init__(*args, **kwargs)
|
| 323 |
+
|
| 324 |
+
@property
|
| 325 |
+
def loop(self):
|
| 326 |
+
if self._pid != os.getpid():
|
| 327 |
+
raise RuntimeError("This class is not fork-safe")
|
| 328 |
+
return self._loop
|
| 329 |
+
|
| 330 |
+
async def _rm_file(self, path, **kwargs):
|
| 331 |
+
if (
|
| 332 |
+
inspect.iscoroutinefunction(self._rm)
|
| 333 |
+
and type(self)._rm is not AsyncFileSystem._rm
|
| 334 |
+
):
|
| 335 |
+
return await self._rm(path, recursive=False, batch_size=1, **kwargs)
|
| 336 |
+
raise NotImplementedError
|
| 337 |
+
|
| 338 |
+
async def _rm(self, path, recursive=False, batch_size=None, **kwargs):
|
| 339 |
+
# TODO: implement on_error
|
| 340 |
+
batch_size = batch_size or self.batch_size
|
| 341 |
+
path = await self._expand_path(path, recursive=recursive)
|
| 342 |
+
return await _run_coros_in_chunks(
|
| 343 |
+
[self._rm_file(p, **kwargs) for p in reversed(path)],
|
| 344 |
+
batch_size=batch_size,
|
| 345 |
+
nofiles=True,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
async def _cp_file(self, path1, path2, **kwargs):
|
| 349 |
+
raise NotImplementedError
|
| 350 |
+
|
| 351 |
+
async def _mv_file(self, path1, path2):
|
| 352 |
+
await self._cp_file(path1, path2)
|
| 353 |
+
await self._rm_file(path1)
|
| 354 |
+
|
| 355 |
+
async def _copy(
|
| 356 |
+
self,
|
| 357 |
+
path1,
|
| 358 |
+
path2,
|
| 359 |
+
recursive=False,
|
| 360 |
+
on_error=None,
|
| 361 |
+
maxdepth=None,
|
| 362 |
+
batch_size=None,
|
| 363 |
+
**kwargs,
|
| 364 |
+
):
|
| 365 |
+
if on_error is None and recursive:
|
| 366 |
+
on_error = "ignore"
|
| 367 |
+
elif on_error is None:
|
| 368 |
+
on_error = "raise"
|
| 369 |
+
|
| 370 |
+
if isinstance(path1, list) and isinstance(path2, list):
|
| 371 |
+
# No need to expand paths when both source and destination
|
| 372 |
+
# are provided as lists
|
| 373 |
+
paths1 = path1
|
| 374 |
+
paths2 = path2
|
| 375 |
+
else:
|
| 376 |
+
source_is_str = isinstance(path1, str)
|
| 377 |
+
paths1 = await self._expand_path(
|
| 378 |
+
path1, maxdepth=maxdepth, recursive=recursive
|
| 379 |
+
)
|
| 380 |
+
if source_is_str and (not recursive or maxdepth is not None):
|
| 381 |
+
# Non-recursive glob does not copy directories
|
| 382 |
+
paths1 = [
|
| 383 |
+
p for p in paths1 if not (trailing_sep(p) or await self._isdir(p))
|
| 384 |
+
]
|
| 385 |
+
if not paths1:
|
| 386 |
+
return
|
| 387 |
+
|
| 388 |
+
source_is_file = len(paths1) == 1
|
| 389 |
+
dest_is_dir = isinstance(path2, str) and (
|
| 390 |
+
trailing_sep(path2) or await self._isdir(path2)
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
exists = source_is_str and (
|
| 394 |
+
(has_magic(path1) and source_is_file)
|
| 395 |
+
or (not has_magic(path1) and dest_is_dir and not trailing_sep(path1))
|
| 396 |
+
)
|
| 397 |
+
paths2 = other_paths(
|
| 398 |
+
paths1,
|
| 399 |
+
path2,
|
| 400 |
+
exists=exists,
|
| 401 |
+
flatten=not source_is_str,
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
batch_size = batch_size or self.batch_size
|
| 405 |
+
coros = [self._cp_file(p1, p2, **kwargs) for p1, p2 in zip(paths1, paths2)]
|
| 406 |
+
result = await _run_coros_in_chunks(
|
| 407 |
+
coros, batch_size=batch_size, return_exceptions=True, nofiles=True
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
for ex in filter(is_exception, result):
|
| 411 |
+
if on_error == "ignore" and isinstance(ex, FileNotFoundError):
|
| 412 |
+
continue
|
| 413 |
+
raise ex
|
| 414 |
+
|
| 415 |
+
async def _pipe_file(self, path, value, mode="overwrite", **kwargs):
|
| 416 |
+
raise NotImplementedError
|
| 417 |
+
|
| 418 |
+
async def _pipe(self, path, value=None, batch_size=None, **kwargs):
|
| 419 |
+
if isinstance(path, str):
|
| 420 |
+
path = {path: value}
|
| 421 |
+
batch_size = batch_size or self.batch_size
|
| 422 |
+
return await _run_coros_in_chunks(
|
| 423 |
+
[self._pipe_file(k, v, **kwargs) for k, v in path.items()],
|
| 424 |
+
batch_size=batch_size,
|
| 425 |
+
nofiles=True,
|
| 426 |
+
)
|
| 427 |
+
|
| 428 |
+
async def _process_limits(self, url, start, end):
|
| 429 |
+
"""Helper for "Range"-based _cat_file"""
|
| 430 |
+
size = None
|
| 431 |
+
suff = False
|
| 432 |
+
if start is not None and start < 0:
|
| 433 |
+
# if start is negative and end None, end is the "suffix length"
|
| 434 |
+
if end is None:
|
| 435 |
+
end = -start
|
| 436 |
+
start = ""
|
| 437 |
+
suff = True
|
| 438 |
+
else:
|
| 439 |
+
size = size or (await self._info(url))["size"]
|
| 440 |
+
start = size + start
|
| 441 |
+
elif start is None:
|
| 442 |
+
start = 0
|
| 443 |
+
if not suff:
|
| 444 |
+
if end is not None and end < 0:
|
| 445 |
+
if start is not None:
|
| 446 |
+
size = size or (await self._info(url))["size"]
|
| 447 |
+
end = size + end
|
| 448 |
+
elif end is None:
|
| 449 |
+
end = ""
|
| 450 |
+
if isinstance(end, numbers.Integral):
|
| 451 |
+
end -= 1 # bytes range is inclusive
|
| 452 |
+
return f"bytes={start}-{end}"
|
| 453 |
+
|
| 454 |
+
async def _cat_file(self, path, start=None, end=None, **kwargs):
|
| 455 |
+
raise NotImplementedError
|
| 456 |
+
|
| 457 |
+
async def _cat(
|
| 458 |
+
self, path, recursive=False, on_error="raise", batch_size=None, **kwargs
|
| 459 |
+
):
|
| 460 |
+
paths = await self._expand_path(path, recursive=recursive)
|
| 461 |
+
coros = [self._cat_file(path, **kwargs) for path in paths]
|
| 462 |
+
batch_size = batch_size or self.batch_size
|
| 463 |
+
out = await _run_coros_in_chunks(
|
| 464 |
+
coros, batch_size=batch_size, nofiles=True, return_exceptions=True
|
| 465 |
+
)
|
| 466 |
+
if on_error == "raise":
|
| 467 |
+
ex = next(filter(is_exception, out), False)
|
| 468 |
+
if ex:
|
| 469 |
+
raise ex
|
| 470 |
+
if (
|
| 471 |
+
len(paths) > 1
|
| 472 |
+
or isinstance(path, list)
|
| 473 |
+
or paths[0] != self._strip_protocol(path)
|
| 474 |
+
):
|
| 475 |
+
return {
|
| 476 |
+
k: v
|
| 477 |
+
for k, v in zip(paths, out)
|
| 478 |
+
if on_error != "omit" or not is_exception(v)
|
| 479 |
+
}
|
| 480 |
+
else:
|
| 481 |
+
return out[0]
|
| 482 |
+
|
| 483 |
+
async def _cat_ranges(
|
| 484 |
+
self,
|
| 485 |
+
paths,
|
| 486 |
+
starts,
|
| 487 |
+
ends,
|
| 488 |
+
max_gap=None,
|
| 489 |
+
batch_size=None,
|
| 490 |
+
on_error="return",
|
| 491 |
+
**kwargs,
|
| 492 |
+
):
|
| 493 |
+
"""Get the contents of byte ranges from one or more files
|
| 494 |
+
|
| 495 |
+
Parameters
|
| 496 |
+
----------
|
| 497 |
+
paths: list
|
| 498 |
+
A list of of filepaths on this filesystems
|
| 499 |
+
starts, ends: int or list
|
| 500 |
+
Bytes limits of the read. If using a single int, the same value will be
|
| 501 |
+
used to read all the specified files.
|
| 502 |
+
"""
|
| 503 |
+
# TODO: on_error
|
| 504 |
+
if max_gap is not None:
|
| 505 |
+
# use utils.merge_offset_ranges
|
| 506 |
+
raise NotImplementedError
|
| 507 |
+
if not isinstance(paths, list):
|
| 508 |
+
raise TypeError
|
| 509 |
+
if not isinstance(starts, Iterable):
|
| 510 |
+
starts = [starts] * len(paths)
|
| 511 |
+
if not isinstance(ends, Iterable):
|
| 512 |
+
ends = [ends] * len(paths)
|
| 513 |
+
if len(starts) != len(paths) or len(ends) != len(paths):
|
| 514 |
+
raise ValueError
|
| 515 |
+
coros = [
|
| 516 |
+
self._cat_file(p, start=s, end=e, **kwargs)
|
| 517 |
+
for p, s, e in zip(paths, starts, ends)
|
| 518 |
+
]
|
| 519 |
+
batch_size = batch_size or self.batch_size
|
| 520 |
+
return await _run_coros_in_chunks(
|
| 521 |
+
coros, batch_size=batch_size, nofiles=True, return_exceptions=True
|
| 522 |
+
)
|
| 523 |
+
|
| 524 |
+
async def _put_file(self, lpath, rpath, mode="overwrite", **kwargs):
|
| 525 |
+
raise NotImplementedError
|
| 526 |
+
|
| 527 |
+
async def _put(
|
| 528 |
+
self,
|
| 529 |
+
lpath,
|
| 530 |
+
rpath,
|
| 531 |
+
recursive=False,
|
| 532 |
+
callback=DEFAULT_CALLBACK,
|
| 533 |
+
batch_size=None,
|
| 534 |
+
maxdepth=None,
|
| 535 |
+
**kwargs,
|
| 536 |
+
):
|
| 537 |
+
"""Copy file(s) from local.
|
| 538 |
+
|
| 539 |
+
Copies a specific file or tree of files (if recursive=True). If rpath
|
| 540 |
+
ends with a "/", it will be assumed to be a directory, and target files
|
| 541 |
+
will go within.
|
| 542 |
+
|
| 543 |
+
The put_file method will be called concurrently on a batch of files. The
|
| 544 |
+
batch_size option can configure the amount of futures that can be executed
|
| 545 |
+
at the same time. If it is -1, then all the files will be uploaded concurrently.
|
| 546 |
+
The default can be set for this instance by passing "batch_size" in the
|
| 547 |
+
constructor, or for all instances by setting the "gather_batch_size" key
|
| 548 |
+
in ``fsspec.config.conf``, falling back to 1/8th of the system limit .
|
| 549 |
+
"""
|
| 550 |
+
if isinstance(lpath, list) and isinstance(rpath, list):
|
| 551 |
+
# No need to expand paths when both source and destination
|
| 552 |
+
# are provided as lists
|
| 553 |
+
rpaths = rpath
|
| 554 |
+
lpaths = lpath
|
| 555 |
+
else:
|
| 556 |
+
source_is_str = isinstance(lpath, str)
|
| 557 |
+
if source_is_str:
|
| 558 |
+
lpath = make_path_posix(lpath)
|
| 559 |
+
fs = LocalFileSystem()
|
| 560 |
+
lpaths = fs.expand_path(lpath, recursive=recursive, maxdepth=maxdepth)
|
| 561 |
+
if source_is_str and (not recursive or maxdepth is not None):
|
| 562 |
+
# Non-recursive glob does not copy directories
|
| 563 |
+
lpaths = [p for p in lpaths if not (trailing_sep(p) or fs.isdir(p))]
|
| 564 |
+
if not lpaths:
|
| 565 |
+
return
|
| 566 |
+
|
| 567 |
+
source_is_file = len(lpaths) == 1
|
| 568 |
+
dest_is_dir = isinstance(rpath, str) and (
|
| 569 |
+
trailing_sep(rpath) or await self._isdir(rpath)
|
| 570 |
+
)
|
| 571 |
+
|
| 572 |
+
rpath = self._strip_protocol(rpath)
|
| 573 |
+
exists = source_is_str and (
|
| 574 |
+
(has_magic(lpath) and source_is_file)
|
| 575 |
+
or (not has_magic(lpath) and dest_is_dir and not trailing_sep(lpath))
|
| 576 |
+
)
|
| 577 |
+
rpaths = other_paths(
|
| 578 |
+
lpaths,
|
| 579 |
+
rpath,
|
| 580 |
+
exists=exists,
|
| 581 |
+
flatten=not source_is_str,
|
| 582 |
+
)
|
| 583 |
+
|
| 584 |
+
is_dir = {l: os.path.isdir(l) for l in lpaths}
|
| 585 |
+
rdirs = [r for l, r in zip(lpaths, rpaths) if is_dir[l]]
|
| 586 |
+
file_pairs = [(l, r) for l, r in zip(lpaths, rpaths) if not is_dir[l]]
|
| 587 |
+
|
| 588 |
+
await asyncio.gather(*[self._makedirs(d, exist_ok=True) for d in rdirs])
|
| 589 |
+
batch_size = batch_size or self.batch_size
|
| 590 |
+
|
| 591 |
+
coros = []
|
| 592 |
+
callback.set_size(len(file_pairs))
|
| 593 |
+
for lfile, rfile in file_pairs:
|
| 594 |
+
put_file = callback.branch_coro(self._put_file)
|
| 595 |
+
coros.append(put_file(lfile, rfile, **kwargs))
|
| 596 |
+
|
| 597 |
+
return await _run_coros_in_chunks(
|
| 598 |
+
coros, batch_size=batch_size, callback=callback
|
| 599 |
+
)
|
| 600 |
+
|
| 601 |
+
async def _get_file(self, rpath, lpath, **kwargs):
|
| 602 |
+
raise NotImplementedError
|
| 603 |
+
|
| 604 |
+
async def _get(
|
| 605 |
+
self,
|
| 606 |
+
rpath,
|
| 607 |
+
lpath,
|
| 608 |
+
recursive=False,
|
| 609 |
+
callback=DEFAULT_CALLBACK,
|
| 610 |
+
maxdepth=None,
|
| 611 |
+
**kwargs,
|
| 612 |
+
):
|
| 613 |
+
"""Copy file(s) to local.
|
| 614 |
+
|
| 615 |
+
Copies a specific file or tree of files (if recursive=True). If lpath
|
| 616 |
+
ends with a "/", it will be assumed to be a directory, and target files
|
| 617 |
+
will go within. Can submit a list of paths, which may be glob-patterns
|
| 618 |
+
and will be expanded.
|
| 619 |
+
|
| 620 |
+
The get_file method will be called concurrently on a batch of files. The
|
| 621 |
+
batch_size option can configure the amount of futures that can be executed
|
| 622 |
+
at the same time. If it is -1, then all the files will be uploaded concurrently.
|
| 623 |
+
The default can be set for this instance by passing "batch_size" in the
|
| 624 |
+
constructor, or for all instances by setting the "gather_batch_size" key
|
| 625 |
+
in ``fsspec.config.conf``, falling back to 1/8th of the system limit .
|
| 626 |
+
"""
|
| 627 |
+
if isinstance(lpath, list) and isinstance(rpath, list):
|
| 628 |
+
# No need to expand paths when both source and destination
|
| 629 |
+
# are provided as lists
|
| 630 |
+
rpaths = rpath
|
| 631 |
+
lpaths = lpath
|
| 632 |
+
else:
|
| 633 |
+
source_is_str = isinstance(rpath, str)
|
| 634 |
+
# First check for rpath trailing slash as _strip_protocol removes it.
|
| 635 |
+
source_not_trailing_sep = source_is_str and not trailing_sep(rpath)
|
| 636 |
+
rpath = self._strip_protocol(rpath)
|
| 637 |
+
rpaths = await self._expand_path(
|
| 638 |
+
rpath, recursive=recursive, maxdepth=maxdepth
|
| 639 |
+
)
|
| 640 |
+
if source_is_str and (not recursive or maxdepth is not None):
|
| 641 |
+
# Non-recursive glob does not copy directories
|
| 642 |
+
rpaths = [
|
| 643 |
+
p for p in rpaths if not (trailing_sep(p) or await self._isdir(p))
|
| 644 |
+
]
|
| 645 |
+
if not rpaths:
|
| 646 |
+
return
|
| 647 |
+
|
| 648 |
+
lpath = make_path_posix(lpath)
|
| 649 |
+
source_is_file = len(rpaths) == 1
|
| 650 |
+
dest_is_dir = isinstance(lpath, str) and (
|
| 651 |
+
trailing_sep(lpath) or LocalFileSystem().isdir(lpath)
|
| 652 |
+
)
|
| 653 |
+
|
| 654 |
+
exists = source_is_str and (
|
| 655 |
+
(has_magic(rpath) and source_is_file)
|
| 656 |
+
or (not has_magic(rpath) and dest_is_dir and source_not_trailing_sep)
|
| 657 |
+
)
|
| 658 |
+
lpaths = other_paths(
|
| 659 |
+
rpaths,
|
| 660 |
+
lpath,
|
| 661 |
+
exists=exists,
|
| 662 |
+
flatten=not source_is_str,
|
| 663 |
+
)
|
| 664 |
+
|
| 665 |
+
[os.makedirs(os.path.dirname(lp), exist_ok=True) for lp in lpaths]
|
| 666 |
+
batch_size = kwargs.pop("batch_size", self.batch_size)
|
| 667 |
+
|
| 668 |
+
coros = []
|
| 669 |
+
callback.set_size(len(lpaths))
|
| 670 |
+
for lpath, rpath in zip(lpaths, rpaths):
|
| 671 |
+
get_file = callback.branch_coro(self._get_file)
|
| 672 |
+
coros.append(get_file(rpath, lpath, **kwargs))
|
| 673 |
+
return await _run_coros_in_chunks(
|
| 674 |
+
coros, batch_size=batch_size, callback=callback
|
| 675 |
+
)
|
| 676 |
+
|
| 677 |
+
async def _isfile(self, path):
|
| 678 |
+
try:
|
| 679 |
+
return (await self._info(path))["type"] == "file"
|
| 680 |
+
except: # noqa: E722
|
| 681 |
+
return False
|
| 682 |
+
|
| 683 |
+
async def _isdir(self, path):
|
| 684 |
+
try:
|
| 685 |
+
return (await self._info(path))["type"] == "directory"
|
| 686 |
+
except OSError:
|
| 687 |
+
return False
|
| 688 |
+
|
| 689 |
+
async def _size(self, path):
|
| 690 |
+
return (await self._info(path)).get("size", None)
|
| 691 |
+
|
| 692 |
+
async def _sizes(self, paths, batch_size=None):
|
| 693 |
+
batch_size = batch_size or self.batch_size
|
| 694 |
+
return await _run_coros_in_chunks(
|
| 695 |
+
[self._size(p) for p in paths], batch_size=batch_size
|
| 696 |
+
)
|
| 697 |
+
|
| 698 |
+
async def _exists(self, path, **kwargs):
|
| 699 |
+
try:
|
| 700 |
+
await self._info(path, **kwargs)
|
| 701 |
+
return True
|
| 702 |
+
except FileNotFoundError:
|
| 703 |
+
return False
|
| 704 |
+
|
| 705 |
+
async def _info(self, path, **kwargs):
|
| 706 |
+
raise NotImplementedError
|
| 707 |
+
|
| 708 |
+
async def _ls(self, path, detail=True, **kwargs):
|
| 709 |
+
raise NotImplementedError
|
| 710 |
+
|
| 711 |
+
async def _walk(self, path, maxdepth=None, on_error="omit", **kwargs):
|
| 712 |
+
if maxdepth is not None and maxdepth < 1:
|
| 713 |
+
raise ValueError("maxdepth must be at least 1")
|
| 714 |
+
|
| 715 |
+
path = self._strip_protocol(path)
|
| 716 |
+
full_dirs = {}
|
| 717 |
+
dirs = {}
|
| 718 |
+
files = {}
|
| 719 |
+
|
| 720 |
+
detail = kwargs.pop("detail", False)
|
| 721 |
+
try:
|
| 722 |
+
listing = await self._ls(path, detail=True, **kwargs)
|
| 723 |
+
except (FileNotFoundError, OSError) as e:
|
| 724 |
+
if on_error == "raise":
|
| 725 |
+
raise
|
| 726 |
+
elif callable(on_error):
|
| 727 |
+
on_error(e)
|
| 728 |
+
if detail:
|
| 729 |
+
yield path, {}, {}
|
| 730 |
+
else:
|
| 731 |
+
yield path, [], []
|
| 732 |
+
return
|
| 733 |
+
|
| 734 |
+
for info in listing:
|
| 735 |
+
# each info name must be at least [path]/part , but here
|
| 736 |
+
# we check also for names like [path]/part/
|
| 737 |
+
pathname = info["name"].rstrip("/")
|
| 738 |
+
name = pathname.rsplit("/", 1)[-1]
|
| 739 |
+
if info["type"] == "directory" and pathname != path:
|
| 740 |
+
# do not include "self" path
|
| 741 |
+
full_dirs[name] = pathname
|
| 742 |
+
dirs[name] = info
|
| 743 |
+
elif pathname == path:
|
| 744 |
+
# file-like with same name as give path
|
| 745 |
+
files[""] = info
|
| 746 |
+
else:
|
| 747 |
+
files[name] = info
|
| 748 |
+
|
| 749 |
+
if detail:
|
| 750 |
+
yield path, dirs, files
|
| 751 |
+
else:
|
| 752 |
+
yield path, list(dirs), list(files)
|
| 753 |
+
|
| 754 |
+
if maxdepth is not None:
|
| 755 |
+
maxdepth -= 1
|
| 756 |
+
if maxdepth < 1:
|
| 757 |
+
return
|
| 758 |
+
|
| 759 |
+
for d in dirs:
|
| 760 |
+
async for _ in self._walk(
|
| 761 |
+
full_dirs[d], maxdepth=maxdepth, detail=detail, **kwargs
|
| 762 |
+
):
|
| 763 |
+
yield _
|
| 764 |
+
|
| 765 |
+
async def _glob(self, path, maxdepth=None, **kwargs):
|
| 766 |
+
if maxdepth is not None and maxdepth < 1:
|
| 767 |
+
raise ValueError("maxdepth must be at least 1")
|
| 768 |
+
|
| 769 |
+
import re
|
| 770 |
+
|
| 771 |
+
seps = (os.path.sep, os.path.altsep) if os.path.altsep else (os.path.sep,)
|
| 772 |
+
ends_with_sep = path.endswith(seps) # _strip_protocol strips trailing slash
|
| 773 |
+
path = self._strip_protocol(path)
|
| 774 |
+
append_slash_to_dirname = ends_with_sep or path.endswith(
|
| 775 |
+
tuple(sep + "**" for sep in seps)
|
| 776 |
+
)
|
| 777 |
+
idx_star = path.find("*") if path.find("*") >= 0 else len(path)
|
| 778 |
+
idx_qmark = path.find("?") if path.find("?") >= 0 else len(path)
|
| 779 |
+
idx_brace = path.find("[") if path.find("[") >= 0 else len(path)
|
| 780 |
+
|
| 781 |
+
min_idx = min(idx_star, idx_qmark, idx_brace)
|
| 782 |
+
|
| 783 |
+
detail = kwargs.pop("detail", False)
|
| 784 |
+
withdirs = kwargs.pop("withdirs", True)
|
| 785 |
+
|
| 786 |
+
if not has_magic(path):
|
| 787 |
+
if await self._exists(path, **kwargs):
|
| 788 |
+
if not detail:
|
| 789 |
+
return [path]
|
| 790 |
+
else:
|
| 791 |
+
return {path: await self._info(path, **kwargs)}
|
| 792 |
+
else:
|
| 793 |
+
if not detail:
|
| 794 |
+
return [] # glob of non-existent returns empty
|
| 795 |
+
else:
|
| 796 |
+
return {}
|
| 797 |
+
elif "/" in path[:min_idx]:
|
| 798 |
+
min_idx = path[:min_idx].rindex("/")
|
| 799 |
+
root = path[: min_idx + 1]
|
| 800 |
+
depth = path[min_idx + 1 :].count("/") + 1
|
| 801 |
+
else:
|
| 802 |
+
root = ""
|
| 803 |
+
depth = path[min_idx + 1 :].count("/") + 1
|
| 804 |
+
|
| 805 |
+
if "**" in path:
|
| 806 |
+
if maxdepth is not None:
|
| 807 |
+
idx_double_stars = path.find("**")
|
| 808 |
+
depth_double_stars = path[idx_double_stars:].count("/") + 1
|
| 809 |
+
depth = depth - depth_double_stars + maxdepth
|
| 810 |
+
else:
|
| 811 |
+
depth = None
|
| 812 |
+
|
| 813 |
+
allpaths = await self._find(
|
| 814 |
+
root, maxdepth=depth, withdirs=withdirs, detail=True, **kwargs
|
| 815 |
+
)
|
| 816 |
+
|
| 817 |
+
pattern = glob_translate(path + ("/" if ends_with_sep else ""))
|
| 818 |
+
pattern = re.compile(pattern)
|
| 819 |
+
|
| 820 |
+
out = {
|
| 821 |
+
p: info
|
| 822 |
+
for p, info in sorted(allpaths.items())
|
| 823 |
+
if pattern.match(
|
| 824 |
+
p + "/"
|
| 825 |
+
if append_slash_to_dirname and info["type"] == "directory"
|
| 826 |
+
else p
|
| 827 |
+
)
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
if detail:
|
| 831 |
+
return out
|
| 832 |
+
else:
|
| 833 |
+
return list(out)
|
| 834 |
+
|
| 835 |
+
async def _du(self, path, total=True, maxdepth=None, **kwargs):
|
| 836 |
+
sizes = {}
|
| 837 |
+
# async for?
|
| 838 |
+
for f in await self._find(path, maxdepth=maxdepth, **kwargs):
|
| 839 |
+
info = await self._info(f)
|
| 840 |
+
sizes[info["name"]] = info["size"]
|
| 841 |
+
if total:
|
| 842 |
+
return sum(sizes.values())
|
| 843 |
+
else:
|
| 844 |
+
return sizes
|
| 845 |
+
|
| 846 |
+
async def _find(self, path, maxdepth=None, withdirs=False, **kwargs):
|
| 847 |
+
path = self._strip_protocol(path)
|
| 848 |
+
out = {}
|
| 849 |
+
detail = kwargs.pop("detail", False)
|
| 850 |
+
|
| 851 |
+
# Add the root directory if withdirs is requested
|
| 852 |
+
# This is needed for posix glob compliance
|
| 853 |
+
if withdirs and path != "" and await self._isdir(path):
|
| 854 |
+
out[path] = await self._info(path)
|
| 855 |
+
|
| 856 |
+
# async for?
|
| 857 |
+
async for _, dirs, files in self._walk(path, maxdepth, detail=True, **kwargs):
|
| 858 |
+
if withdirs:
|
| 859 |
+
files.update(dirs)
|
| 860 |
+
out.update({info["name"]: info for name, info in files.items()})
|
| 861 |
+
if not out and (await self._isfile(path)):
|
| 862 |
+
# walk works on directories, but find should also return [path]
|
| 863 |
+
# when path happens to be a file
|
| 864 |
+
out[path] = {}
|
| 865 |
+
names = sorted(out)
|
| 866 |
+
if not detail:
|
| 867 |
+
return names
|
| 868 |
+
else:
|
| 869 |
+
return {name: out[name] for name in names}
|
| 870 |
+
|
| 871 |
+
async def _expand_path(self, path, recursive=False, maxdepth=None):
|
| 872 |
+
if maxdepth is not None and maxdepth < 1:
|
| 873 |
+
raise ValueError("maxdepth must be at least 1")
|
| 874 |
+
|
| 875 |
+
if isinstance(path, str):
|
| 876 |
+
out = await self._expand_path([path], recursive, maxdepth)
|
| 877 |
+
else:
|
| 878 |
+
out = set()
|
| 879 |
+
path = [self._strip_protocol(p) for p in path]
|
| 880 |
+
for p in path: # can gather here
|
| 881 |
+
if has_magic(p):
|
| 882 |
+
bit = set(await self._glob(p, maxdepth=maxdepth))
|
| 883 |
+
out |= bit
|
| 884 |
+
if recursive:
|
| 885 |
+
# glob call above expanded one depth so if maxdepth is defined
|
| 886 |
+
# then decrement it in expand_path call below. If it is zero
|
| 887 |
+
# after decrementing then avoid expand_path call.
|
| 888 |
+
if maxdepth is not None and maxdepth <= 1:
|
| 889 |
+
continue
|
| 890 |
+
out |= set(
|
| 891 |
+
await self._expand_path(
|
| 892 |
+
list(bit),
|
| 893 |
+
recursive=recursive,
|
| 894 |
+
maxdepth=maxdepth - 1 if maxdepth is not None else None,
|
| 895 |
+
)
|
| 896 |
+
)
|
| 897 |
+
continue
|
| 898 |
+
elif recursive:
|
| 899 |
+
rec = set(await self._find(p, maxdepth=maxdepth, withdirs=True))
|
| 900 |
+
out |= rec
|
| 901 |
+
if p not in out and (recursive is False or (await self._exists(p))):
|
| 902 |
+
# should only check once, for the root
|
| 903 |
+
out.add(p)
|
| 904 |
+
if not out:
|
| 905 |
+
raise FileNotFoundError(path)
|
| 906 |
+
return sorted(out)
|
| 907 |
+
|
| 908 |
+
async def _mkdir(self, path, create_parents=True, **kwargs):
|
| 909 |
+
pass # not necessary to implement, may not have directories
|
| 910 |
+
|
| 911 |
+
async def _makedirs(self, path, exist_ok=False):
|
| 912 |
+
pass # not necessary to implement, may not have directories
|
| 913 |
+
|
| 914 |
+
async def open_async(self, path, mode="rb", **kwargs):
|
| 915 |
+
if "b" not in mode or kwargs.get("compression"):
|
| 916 |
+
raise ValueError
|
| 917 |
+
raise NotImplementedError
|
| 918 |
+
|
| 919 |
+
|
| 920 |
+
def mirror_sync_methods(obj):
|
| 921 |
+
"""Populate sync and async methods for obj
|
| 922 |
+
|
| 923 |
+
For each method will create a sync version if the name refers to an async method
|
| 924 |
+
(coroutine) and there is no override in the child class; will create an async
|
| 925 |
+
method for the corresponding sync method if there is no implementation.
|
| 926 |
+
|
| 927 |
+
Uses the methods specified in
|
| 928 |
+
- async_methods: the set that an implementation is expected to provide
|
| 929 |
+
- default_async_methods: that can be derived from their sync version in
|
| 930 |
+
AbstractFileSystem
|
| 931 |
+
- AsyncFileSystem: async-specific default coroutines
|
| 932 |
+
"""
|
| 933 |
+
from fsspec import AbstractFileSystem
|
| 934 |
+
|
| 935 |
+
for method in async_methods + dir(AsyncFileSystem):
|
| 936 |
+
if not method.startswith("_"):
|
| 937 |
+
continue
|
| 938 |
+
smethod = method[1:]
|
| 939 |
+
if private.match(method):
|
| 940 |
+
isco = inspect.iscoroutinefunction(getattr(obj, method, None))
|
| 941 |
+
unsync = getattr(getattr(obj, smethod, False), "__func__", None)
|
| 942 |
+
is_default = unsync is getattr(AbstractFileSystem, smethod, "")
|
| 943 |
+
if isco and is_default:
|
| 944 |
+
mth = sync_wrapper(getattr(obj, method), obj=obj)
|
| 945 |
+
setattr(obj, smethod, mth)
|
| 946 |
+
if not mth.__doc__:
|
| 947 |
+
mth.__doc__ = getattr(
|
| 948 |
+
getattr(AbstractFileSystem, smethod, None), "__doc__", ""
|
| 949 |
+
)
|
| 950 |
+
|
| 951 |
+
|
| 952 |
+
class FSSpecCoroutineCancel(Exception):
|
| 953 |
+
pass
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
def _dump_running_tasks(
|
| 957 |
+
printout=True, cancel=True, exc=FSSpecCoroutineCancel, with_task=False
|
| 958 |
+
):
|
| 959 |
+
import traceback
|
| 960 |
+
|
| 961 |
+
tasks = [t for t in asyncio.tasks.all_tasks(loop[0]) if not t.done()]
|
| 962 |
+
if printout:
|
| 963 |
+
[task.print_stack() for task in tasks]
|
| 964 |
+
out = [
|
| 965 |
+
{
|
| 966 |
+
"locals": task._coro.cr_frame.f_locals,
|
| 967 |
+
"file": task._coro.cr_frame.f_code.co_filename,
|
| 968 |
+
"firstline": task._coro.cr_frame.f_code.co_firstlineno,
|
| 969 |
+
"linelo": task._coro.cr_frame.f_lineno,
|
| 970 |
+
"stack": traceback.format_stack(task._coro.cr_frame),
|
| 971 |
+
"task": task if with_task else None,
|
| 972 |
+
}
|
| 973 |
+
for task in tasks
|
| 974 |
+
]
|
| 975 |
+
if cancel:
|
| 976 |
+
for t in tasks:
|
| 977 |
+
cbs = t._callbacks
|
| 978 |
+
t.cancel()
|
| 979 |
+
asyncio.futures.Future.set_exception(t, exc)
|
| 980 |
+
asyncio.futures.Future.cancel(t)
|
| 981 |
+
[cb[0](t) for cb in cbs] # cancels any dependent concurrent.futures
|
| 982 |
+
try:
|
| 983 |
+
t._coro.throw(exc) # exits coro, unless explicitly handled
|
| 984 |
+
except exc:
|
| 985 |
+
pass
|
| 986 |
+
return out
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
class AbstractAsyncStreamedFile(AbstractBufferedFile):
|
| 990 |
+
# no read buffering, and always auto-commit
|
| 991 |
+
# TODO: readahead might still be useful here, but needs async version
|
| 992 |
+
|
| 993 |
+
async def read(self, length=-1):
|
| 994 |
+
"""
|
| 995 |
+
Return data from cache, or fetch pieces as necessary
|
| 996 |
+
|
| 997 |
+
Parameters
|
| 998 |
+
----------
|
| 999 |
+
length: int (-1)
|
| 1000 |
+
Number of bytes to read; if <0, all remaining bytes.
|
| 1001 |
+
"""
|
| 1002 |
+
length = -1 if length is None else int(length)
|
| 1003 |
+
if self.mode != "rb":
|
| 1004 |
+
raise ValueError("File not in read mode")
|
| 1005 |
+
if length < 0:
|
| 1006 |
+
length = self.size - self.loc
|
| 1007 |
+
if self.closed:
|
| 1008 |
+
raise ValueError("I/O operation on closed file.")
|
| 1009 |
+
if length == 0:
|
| 1010 |
+
# don't even bother calling fetch
|
| 1011 |
+
return b""
|
| 1012 |
+
out = await self._fetch_range(self.loc, self.loc + length)
|
| 1013 |
+
self.loc += len(out)
|
| 1014 |
+
return out
|
| 1015 |
+
|
| 1016 |
+
async def write(self, data):
|
| 1017 |
+
"""
|
| 1018 |
+
Write data to buffer.
|
| 1019 |
+
|
| 1020 |
+
Buffer only sent on flush() or if buffer is greater than
|
| 1021 |
+
or equal to blocksize.
|
| 1022 |
+
|
| 1023 |
+
Parameters
|
| 1024 |
+
----------
|
| 1025 |
+
data: bytes
|
| 1026 |
+
Set of bytes to be written.
|
| 1027 |
+
"""
|
| 1028 |
+
if self.mode not in {"wb", "ab"}:
|
| 1029 |
+
raise ValueError("File not in write mode")
|
| 1030 |
+
if self.closed:
|
| 1031 |
+
raise ValueError("I/O operation on closed file.")
|
| 1032 |
+
if self.forced:
|
| 1033 |
+
raise ValueError("This file has been force-flushed, can only close")
|
| 1034 |
+
out = self.buffer.write(data)
|
| 1035 |
+
self.loc += out
|
| 1036 |
+
if self.buffer.tell() >= self.blocksize:
|
| 1037 |
+
await self.flush()
|
| 1038 |
+
return out
|
| 1039 |
+
|
| 1040 |
+
async def close(self):
|
| 1041 |
+
"""Close file
|
| 1042 |
+
|
| 1043 |
+
Finalizes writes, discards cache
|
| 1044 |
+
"""
|
| 1045 |
+
if getattr(self, "_unclosable", False):
|
| 1046 |
+
return
|
| 1047 |
+
if self.closed:
|
| 1048 |
+
return
|
| 1049 |
+
if self.mode == "rb":
|
| 1050 |
+
self.cache = None
|
| 1051 |
+
else:
|
| 1052 |
+
if not self.forced:
|
| 1053 |
+
await self.flush(force=True)
|
| 1054 |
+
|
| 1055 |
+
if self.fs is not None:
|
| 1056 |
+
self.fs.invalidate_cache(self.path)
|
| 1057 |
+
self.fs.invalidate_cache(self.fs._parent(self.path))
|
| 1058 |
+
|
| 1059 |
+
self.closed = True
|
| 1060 |
+
|
| 1061 |
+
async def flush(self, force=False):
|
| 1062 |
+
if self.closed:
|
| 1063 |
+
raise ValueError("Flush on closed file")
|
| 1064 |
+
if force and self.forced:
|
| 1065 |
+
raise ValueError("Force flush cannot be called more than once")
|
| 1066 |
+
if force:
|
| 1067 |
+
self.forced = True
|
| 1068 |
+
|
| 1069 |
+
if self.mode not in {"wb", "ab"}:
|
| 1070 |
+
# no-op to flush on read-mode
|
| 1071 |
+
return
|
| 1072 |
+
|
| 1073 |
+
if not force and self.buffer.tell() < self.blocksize:
|
| 1074 |
+
# Defer write on small block
|
| 1075 |
+
return
|
| 1076 |
+
|
| 1077 |
+
if self.offset is None:
|
| 1078 |
+
# Initialize a multipart upload
|
| 1079 |
+
self.offset = 0
|
| 1080 |
+
try:
|
| 1081 |
+
await self._initiate_upload()
|
| 1082 |
+
except:
|
| 1083 |
+
self.closed = True
|
| 1084 |
+
raise
|
| 1085 |
+
|
| 1086 |
+
if await self._upload_chunk(final=force) is not False:
|
| 1087 |
+
self.offset += self.buffer.seek(0, 2)
|
| 1088 |
+
self.buffer = io.BytesIO()
|
| 1089 |
+
|
| 1090 |
+
async def __aenter__(self):
|
| 1091 |
+
return self
|
| 1092 |
+
|
| 1093 |
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
| 1094 |
+
await self.close()
|
| 1095 |
+
|
| 1096 |
+
async def _fetch_range(self, start, end):
|
| 1097 |
+
raise NotImplementedError
|
| 1098 |
+
|
| 1099 |
+
async def _initiate_upload(self):
|
| 1100 |
+
pass
|
| 1101 |
+
|
| 1102 |
+
async def _upload_chunk(self, final=False):
|
| 1103 |
+
raise NotImplementedError
|
TTS/Kokoro/.venv/Lib/site-packages/fsspec/caching.py
ADDED
|
@@ -0,0 +1,1004 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import collections
|
| 4 |
+
import functools
|
| 5 |
+
import logging
|
| 6 |
+
import math
|
| 7 |
+
import os
|
| 8 |
+
import threading
|
| 9 |
+
from collections import OrderedDict
|
| 10 |
+
from collections.abc import Callable
|
| 11 |
+
from concurrent.futures import Future, ThreadPoolExecutor
|
| 12 |
+
from itertools import groupby
|
| 13 |
+
from operator import itemgetter
|
| 14 |
+
from typing import TYPE_CHECKING, Any, ClassVar, Generic, NamedTuple, TypeVar
|
| 15 |
+
|
| 16 |
+
if TYPE_CHECKING:
|
| 17 |
+
import mmap
|
| 18 |
+
|
| 19 |
+
from typing_extensions import ParamSpec
|
| 20 |
+
|
| 21 |
+
P = ParamSpec("P")
|
| 22 |
+
else:
|
| 23 |
+
P = TypeVar("P")
|
| 24 |
+
|
| 25 |
+
T = TypeVar("T")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
logger = logging.getLogger("fsspec.caching")
|
| 29 |
+
|
| 30 |
+
Fetcher = Callable[[int, int], bytes] # Maps (start, end) to bytes
|
| 31 |
+
MultiFetcher = Callable[[list[int, int]], bytes] # Maps [(start, end)] to bytes
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class BaseCache:
|
| 35 |
+
"""Pass-though cache: doesn't keep anything, calls every time
|
| 36 |
+
|
| 37 |
+
Acts as base class for other cachers
|
| 38 |
+
|
| 39 |
+
Parameters
|
| 40 |
+
----------
|
| 41 |
+
blocksize: int
|
| 42 |
+
How far to read ahead in numbers of bytes
|
| 43 |
+
fetcher: func
|
| 44 |
+
Function of the form f(start, end) which gets bytes from remote as
|
| 45 |
+
specified
|
| 46 |
+
size: int
|
| 47 |
+
How big this file is
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
name: ClassVar[str] = "none"
|
| 51 |
+
|
| 52 |
+
def __init__(self, blocksize: int, fetcher: Fetcher, size: int) -> None:
|
| 53 |
+
self.blocksize = blocksize
|
| 54 |
+
self.nblocks = 0
|
| 55 |
+
self.fetcher = fetcher
|
| 56 |
+
self.size = size
|
| 57 |
+
self.hit_count = 0
|
| 58 |
+
self.miss_count = 0
|
| 59 |
+
# the bytes that we actually requested
|
| 60 |
+
self.total_requested_bytes = 0
|
| 61 |
+
|
| 62 |
+
def _fetch(self, start: int | None, stop: int | None) -> bytes:
|
| 63 |
+
if start is None:
|
| 64 |
+
start = 0
|
| 65 |
+
if stop is None:
|
| 66 |
+
stop = self.size
|
| 67 |
+
if start >= self.size or start >= stop:
|
| 68 |
+
return b""
|
| 69 |
+
return self.fetcher(start, stop)
|
| 70 |
+
|
| 71 |
+
def _reset_stats(self) -> None:
|
| 72 |
+
"""Reset hit and miss counts for a more ganular report e.g. by file."""
|
| 73 |
+
self.hit_count = 0
|
| 74 |
+
self.miss_count = 0
|
| 75 |
+
self.total_requested_bytes = 0
|
| 76 |
+
|
| 77 |
+
def _log_stats(self) -> str:
|
| 78 |
+
"""Return a formatted string of the cache statistics."""
|
| 79 |
+
if self.hit_count == 0 and self.miss_count == 0:
|
| 80 |
+
# a cache that does nothing, this is for logs only
|
| 81 |
+
return ""
|
| 82 |
+
return f" , {self.name}: {self.hit_count} hits, {self.miss_count} misses, {self.total_requested_bytes} total requested bytes"
|
| 83 |
+
|
| 84 |
+
def __repr__(self) -> str:
|
| 85 |
+
# TODO: use rich for better formatting
|
| 86 |
+
return f"""
|
| 87 |
+
<{self.__class__.__name__}:
|
| 88 |
+
block size : {self.blocksize}
|
| 89 |
+
block count : {self.nblocks}
|
| 90 |
+
file size : {self.size}
|
| 91 |
+
cache hits : {self.hit_count}
|
| 92 |
+
cache misses: {self.miss_count}
|
| 93 |
+
total requested bytes: {self.total_requested_bytes}>
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class MMapCache(BaseCache):
|
| 98 |
+
"""memory-mapped sparse file cache
|
| 99 |
+
|
| 100 |
+
Opens temporary file, which is filled blocks-wise when data is requested.
|
| 101 |
+
Ensure there is enough disc space in the temporary location.
|
| 102 |
+
|
| 103 |
+
This cache method might only work on posix
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
blocksize: int
|
| 108 |
+
How far to read ahead in numbers of bytes
|
| 109 |
+
fetcher: Fetcher
|
| 110 |
+
Function of the form f(start, end) which gets bytes from remote as
|
| 111 |
+
specified
|
| 112 |
+
size: int
|
| 113 |
+
How big this file is
|
| 114 |
+
location: str
|
| 115 |
+
Where to create the temporary file. If None, a temporary file is
|
| 116 |
+
created using tempfile.TemporaryFile().
|
| 117 |
+
blocks: set[int]
|
| 118 |
+
Set of block numbers that have already been fetched. If None, an empty
|
| 119 |
+
set is created.
|
| 120 |
+
multi_fetcher: MultiFetcher
|
| 121 |
+
Function of the form f([(start, end)]) which gets bytes from remote
|
| 122 |
+
as specified. This function is used to fetch multiple blocks at once.
|
| 123 |
+
If not specified, the fetcher function is used instead.
|
| 124 |
+
"""
|
| 125 |
+
|
| 126 |
+
name = "mmap"
|
| 127 |
+
|
| 128 |
+
def __init__(
|
| 129 |
+
self,
|
| 130 |
+
blocksize: int,
|
| 131 |
+
fetcher: Fetcher,
|
| 132 |
+
size: int,
|
| 133 |
+
location: str | None = None,
|
| 134 |
+
blocks: set[int] | None = None,
|
| 135 |
+
multi_fetcher: MultiFetcher | None = None,
|
| 136 |
+
) -> None:
|
| 137 |
+
super().__init__(blocksize, fetcher, size)
|
| 138 |
+
self.blocks = set() if blocks is None else blocks
|
| 139 |
+
self.location = location
|
| 140 |
+
self.multi_fetcher = multi_fetcher
|
| 141 |
+
self.cache = self._makefile()
|
| 142 |
+
|
| 143 |
+
def _makefile(self) -> mmap.mmap | bytearray:
|
| 144 |
+
import mmap
|
| 145 |
+
import tempfile
|
| 146 |
+
|
| 147 |
+
if self.size == 0:
|
| 148 |
+
return bytearray()
|
| 149 |
+
|
| 150 |
+
# posix version
|
| 151 |
+
if self.location is None or not os.path.exists(self.location):
|
| 152 |
+
if self.location is None:
|
| 153 |
+
fd = tempfile.TemporaryFile()
|
| 154 |
+
self.blocks = set()
|
| 155 |
+
else:
|
| 156 |
+
fd = open(self.location, "wb+")
|
| 157 |
+
fd.seek(self.size - 1)
|
| 158 |
+
fd.write(b"1")
|
| 159 |
+
fd.flush()
|
| 160 |
+
else:
|
| 161 |
+
fd = open(self.location, "r+b")
|
| 162 |
+
|
| 163 |
+
return mmap.mmap(fd.fileno(), self.size)
|
| 164 |
+
|
| 165 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 166 |
+
logger.debug(f"MMap cache fetching {start}-{end}")
|
| 167 |
+
if start is None:
|
| 168 |
+
start = 0
|
| 169 |
+
if end is None:
|
| 170 |
+
end = self.size
|
| 171 |
+
if start >= self.size or start >= end:
|
| 172 |
+
return b""
|
| 173 |
+
start_block = start // self.blocksize
|
| 174 |
+
end_block = end // self.blocksize
|
| 175 |
+
block_range = range(start_block, end_block + 1)
|
| 176 |
+
# Determine which blocks need to be fetched. This sequence is sorted by construction.
|
| 177 |
+
need = (i for i in block_range if i not in self.blocks)
|
| 178 |
+
# Count the number of blocks already cached
|
| 179 |
+
self.hit_count += sum(1 for i in block_range if i in self.blocks)
|
| 180 |
+
|
| 181 |
+
ranges = []
|
| 182 |
+
|
| 183 |
+
# Consolidate needed blocks.
|
| 184 |
+
# Algorithm adapted from Python 2.x itertools documentation.
|
| 185 |
+
# We are grouping an enumerated sequence of blocks. By comparing when the difference
|
| 186 |
+
# between an ascending range (provided by enumerate) and the needed block numbers
|
| 187 |
+
# we can detect when the block number skips values. The key computes this difference.
|
| 188 |
+
# Whenever the difference changes, we know that we have previously cached block(s),
|
| 189 |
+
# and a new group is started. In other words, this algorithm neatly groups
|
| 190 |
+
# runs of consecutive block numbers so they can be fetched together.
|
| 191 |
+
for _, _blocks in groupby(enumerate(need), key=lambda x: x[0] - x[1]):
|
| 192 |
+
# Extract the blocks from the enumerated sequence
|
| 193 |
+
_blocks = tuple(map(itemgetter(1), _blocks))
|
| 194 |
+
# Compute start of first block
|
| 195 |
+
sstart = _blocks[0] * self.blocksize
|
| 196 |
+
# Compute the end of the last block. Last block may not be full size.
|
| 197 |
+
send = min(_blocks[-1] * self.blocksize + self.blocksize, self.size)
|
| 198 |
+
|
| 199 |
+
# Fetch bytes (could be multiple consecutive blocks)
|
| 200 |
+
self.total_requested_bytes += send - sstart
|
| 201 |
+
logger.debug(
|
| 202 |
+
f"MMap get blocks {_blocks[0]}-{_blocks[-1]} ({sstart}-{send})"
|
| 203 |
+
)
|
| 204 |
+
ranges.append((sstart, send))
|
| 205 |
+
|
| 206 |
+
# Update set of cached blocks
|
| 207 |
+
self.blocks.update(_blocks)
|
| 208 |
+
# Update cache statistics with number of blocks we had to cache
|
| 209 |
+
self.miss_count += len(_blocks)
|
| 210 |
+
|
| 211 |
+
if not ranges:
|
| 212 |
+
return self.cache[start:end]
|
| 213 |
+
|
| 214 |
+
if self.multi_fetcher:
|
| 215 |
+
logger.debug(f"MMap get blocks {ranges}")
|
| 216 |
+
for idx, r in enumerate(self.multi_fetcher(ranges)):
|
| 217 |
+
sstart, send = ranges[idx]
|
| 218 |
+
logger.debug(f"MMap copy block ({sstart}-{send}")
|
| 219 |
+
self.cache[sstart:send] = r
|
| 220 |
+
else:
|
| 221 |
+
for sstart, send in ranges:
|
| 222 |
+
logger.debug(f"MMap get block ({sstart}-{send}")
|
| 223 |
+
self.cache[sstart:send] = self.fetcher(sstart, send)
|
| 224 |
+
|
| 225 |
+
return self.cache[start:end]
|
| 226 |
+
|
| 227 |
+
def __getstate__(self) -> dict[str, Any]:
|
| 228 |
+
state = self.__dict__.copy()
|
| 229 |
+
# Remove the unpicklable entries.
|
| 230 |
+
del state["cache"]
|
| 231 |
+
return state
|
| 232 |
+
|
| 233 |
+
def __setstate__(self, state: dict[str, Any]) -> None:
|
| 234 |
+
# Restore instance attributes
|
| 235 |
+
self.__dict__.update(state)
|
| 236 |
+
self.cache = self._makefile()
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class ReadAheadCache(BaseCache):
|
| 240 |
+
"""Cache which reads only when we get beyond a block of data
|
| 241 |
+
|
| 242 |
+
This is a much simpler version of BytesCache, and does not attempt to
|
| 243 |
+
fill holes in the cache or keep fragments alive. It is best suited to
|
| 244 |
+
many small reads in a sequential order (e.g., reading lines from a file).
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
name = "readahead"
|
| 248 |
+
|
| 249 |
+
def __init__(self, blocksize: int, fetcher: Fetcher, size: int) -> None:
|
| 250 |
+
super().__init__(blocksize, fetcher, size)
|
| 251 |
+
self.cache = b""
|
| 252 |
+
self.start = 0
|
| 253 |
+
self.end = 0
|
| 254 |
+
|
| 255 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 256 |
+
if start is None:
|
| 257 |
+
start = 0
|
| 258 |
+
if end is None or end > self.size:
|
| 259 |
+
end = self.size
|
| 260 |
+
if start >= self.size or start >= end:
|
| 261 |
+
return b""
|
| 262 |
+
l = end - start
|
| 263 |
+
if start >= self.start and end <= self.end:
|
| 264 |
+
# cache hit
|
| 265 |
+
self.hit_count += 1
|
| 266 |
+
return self.cache[start - self.start : end - self.start]
|
| 267 |
+
elif self.start <= start < self.end:
|
| 268 |
+
# partial hit
|
| 269 |
+
self.miss_count += 1
|
| 270 |
+
part = self.cache[start - self.start :]
|
| 271 |
+
l -= len(part)
|
| 272 |
+
start = self.end
|
| 273 |
+
else:
|
| 274 |
+
# miss
|
| 275 |
+
self.miss_count += 1
|
| 276 |
+
part = b""
|
| 277 |
+
end = min(self.size, end + self.blocksize)
|
| 278 |
+
self.total_requested_bytes += end - start
|
| 279 |
+
self.cache = self.fetcher(start, end) # new block replaces old
|
| 280 |
+
self.start = start
|
| 281 |
+
self.end = self.start + len(self.cache)
|
| 282 |
+
return part + self.cache[:l]
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
class FirstChunkCache(BaseCache):
|
| 286 |
+
"""Caches the first block of a file only
|
| 287 |
+
|
| 288 |
+
This may be useful for file types where the metadata is stored in the header,
|
| 289 |
+
but is randomly accessed.
|
| 290 |
+
"""
|
| 291 |
+
|
| 292 |
+
name = "first"
|
| 293 |
+
|
| 294 |
+
def __init__(self, blocksize: int, fetcher: Fetcher, size: int) -> None:
|
| 295 |
+
if blocksize > size:
|
| 296 |
+
# this will buffer the whole thing
|
| 297 |
+
blocksize = size
|
| 298 |
+
super().__init__(blocksize, fetcher, size)
|
| 299 |
+
self.cache: bytes | None = None
|
| 300 |
+
|
| 301 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 302 |
+
start = start or 0
|
| 303 |
+
if start > self.size:
|
| 304 |
+
logger.debug("FirstChunkCache: requested start > file size")
|
| 305 |
+
return b""
|
| 306 |
+
|
| 307 |
+
end = min(end, self.size)
|
| 308 |
+
|
| 309 |
+
if start < self.blocksize:
|
| 310 |
+
if self.cache is None:
|
| 311 |
+
self.miss_count += 1
|
| 312 |
+
if end > self.blocksize:
|
| 313 |
+
self.total_requested_bytes += end
|
| 314 |
+
data = self.fetcher(0, end)
|
| 315 |
+
self.cache = data[: self.blocksize]
|
| 316 |
+
return data[start:]
|
| 317 |
+
self.cache = self.fetcher(0, self.blocksize)
|
| 318 |
+
self.total_requested_bytes += self.blocksize
|
| 319 |
+
part = self.cache[start:end]
|
| 320 |
+
if end > self.blocksize:
|
| 321 |
+
self.total_requested_bytes += end - self.blocksize
|
| 322 |
+
part += self.fetcher(self.blocksize, end)
|
| 323 |
+
self.hit_count += 1
|
| 324 |
+
return part
|
| 325 |
+
else:
|
| 326 |
+
self.miss_count += 1
|
| 327 |
+
self.total_requested_bytes += end - start
|
| 328 |
+
return self.fetcher(start, end)
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
class BlockCache(BaseCache):
|
| 332 |
+
"""
|
| 333 |
+
Cache holding memory as a set of blocks.
|
| 334 |
+
|
| 335 |
+
Requests are only ever made ``blocksize`` at a time, and are
|
| 336 |
+
stored in an LRU cache. The least recently accessed block is
|
| 337 |
+
discarded when more than ``maxblocks`` are stored.
|
| 338 |
+
|
| 339 |
+
Parameters
|
| 340 |
+
----------
|
| 341 |
+
blocksize : int
|
| 342 |
+
The number of bytes to store in each block.
|
| 343 |
+
Requests are only ever made for ``blocksize``, so this
|
| 344 |
+
should balance the overhead of making a request against
|
| 345 |
+
the granularity of the blocks.
|
| 346 |
+
fetcher : Callable
|
| 347 |
+
size : int
|
| 348 |
+
The total size of the file being cached.
|
| 349 |
+
maxblocks : int
|
| 350 |
+
The maximum number of blocks to cache for. The maximum memory
|
| 351 |
+
use for this cache is then ``blocksize * maxblocks``.
|
| 352 |
+
"""
|
| 353 |
+
|
| 354 |
+
name = "blockcache"
|
| 355 |
+
|
| 356 |
+
def __init__(
|
| 357 |
+
self, blocksize: int, fetcher: Fetcher, size: int, maxblocks: int = 32
|
| 358 |
+
) -> None:
|
| 359 |
+
super().__init__(blocksize, fetcher, size)
|
| 360 |
+
self.nblocks = math.ceil(size / blocksize)
|
| 361 |
+
self.maxblocks = maxblocks
|
| 362 |
+
self._fetch_block_cached = functools.lru_cache(maxblocks)(self._fetch_block)
|
| 363 |
+
|
| 364 |
+
def cache_info(self):
|
| 365 |
+
"""
|
| 366 |
+
The statistics on the block cache.
|
| 367 |
+
|
| 368 |
+
Returns
|
| 369 |
+
-------
|
| 370 |
+
NamedTuple
|
| 371 |
+
Returned directly from the LRU Cache used internally.
|
| 372 |
+
"""
|
| 373 |
+
return self._fetch_block_cached.cache_info()
|
| 374 |
+
|
| 375 |
+
def __getstate__(self) -> dict[str, Any]:
|
| 376 |
+
state = self.__dict__
|
| 377 |
+
del state["_fetch_block_cached"]
|
| 378 |
+
return state
|
| 379 |
+
|
| 380 |
+
def __setstate__(self, state: dict[str, Any]) -> None:
|
| 381 |
+
self.__dict__.update(state)
|
| 382 |
+
self._fetch_block_cached = functools.lru_cache(state["maxblocks"])(
|
| 383 |
+
self._fetch_block
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 387 |
+
if start is None:
|
| 388 |
+
start = 0
|
| 389 |
+
if end is None:
|
| 390 |
+
end = self.size
|
| 391 |
+
if start >= self.size or start >= end:
|
| 392 |
+
return b""
|
| 393 |
+
|
| 394 |
+
return self._read_cache(
|
| 395 |
+
start, end, start // self.blocksize, (end - 1) // self.blocksize
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
def _fetch_block(self, block_number: int) -> bytes:
|
| 399 |
+
"""
|
| 400 |
+
Fetch the block of data for `block_number`.
|
| 401 |
+
"""
|
| 402 |
+
if block_number > self.nblocks:
|
| 403 |
+
raise ValueError(
|
| 404 |
+
f"'block_number={block_number}' is greater than "
|
| 405 |
+
f"the number of blocks ({self.nblocks})"
|
| 406 |
+
)
|
| 407 |
+
|
| 408 |
+
start = block_number * self.blocksize
|
| 409 |
+
end = start + self.blocksize
|
| 410 |
+
self.total_requested_bytes += end - start
|
| 411 |
+
self.miss_count += 1
|
| 412 |
+
logger.info("BlockCache fetching block %d", block_number)
|
| 413 |
+
block_contents = super()._fetch(start, end)
|
| 414 |
+
return block_contents
|
| 415 |
+
|
| 416 |
+
def _read_cache(
|
| 417 |
+
self, start: int, end: int, start_block_number: int, end_block_number: int
|
| 418 |
+
) -> bytes:
|
| 419 |
+
"""
|
| 420 |
+
Read from our block cache.
|
| 421 |
+
|
| 422 |
+
Parameters
|
| 423 |
+
----------
|
| 424 |
+
start, end : int
|
| 425 |
+
The start and end byte positions.
|
| 426 |
+
start_block_number, end_block_number : int
|
| 427 |
+
The start and end block numbers.
|
| 428 |
+
"""
|
| 429 |
+
start_pos = start % self.blocksize
|
| 430 |
+
end_pos = end % self.blocksize
|
| 431 |
+
if end_pos == 0:
|
| 432 |
+
end_pos = self.blocksize
|
| 433 |
+
|
| 434 |
+
self.hit_count += 1
|
| 435 |
+
if start_block_number == end_block_number:
|
| 436 |
+
block: bytes = self._fetch_block_cached(start_block_number)
|
| 437 |
+
return block[start_pos:end_pos]
|
| 438 |
+
|
| 439 |
+
else:
|
| 440 |
+
# read from the initial
|
| 441 |
+
out = [self._fetch_block_cached(start_block_number)[start_pos:]]
|
| 442 |
+
|
| 443 |
+
# intermediate blocks
|
| 444 |
+
# Note: it'd be nice to combine these into one big request. However
|
| 445 |
+
# that doesn't play nicely with our LRU cache.
|
| 446 |
+
out.extend(
|
| 447 |
+
map(
|
| 448 |
+
self._fetch_block_cached,
|
| 449 |
+
range(start_block_number + 1, end_block_number),
|
| 450 |
+
)
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
# final block
|
| 454 |
+
out.append(self._fetch_block_cached(end_block_number)[:end_pos])
|
| 455 |
+
|
| 456 |
+
return b"".join(out)
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
class BytesCache(BaseCache):
|
| 460 |
+
"""Cache which holds data in a in-memory bytes object
|
| 461 |
+
|
| 462 |
+
Implements read-ahead by the block size, for semi-random reads progressing
|
| 463 |
+
through the file.
|
| 464 |
+
|
| 465 |
+
Parameters
|
| 466 |
+
----------
|
| 467 |
+
trim: bool
|
| 468 |
+
As we read more data, whether to discard the start of the buffer when
|
| 469 |
+
we are more than a blocksize ahead of it.
|
| 470 |
+
"""
|
| 471 |
+
|
| 472 |
+
name: ClassVar[str] = "bytes"
|
| 473 |
+
|
| 474 |
+
def __init__(
|
| 475 |
+
self, blocksize: int, fetcher: Fetcher, size: int, trim: bool = True
|
| 476 |
+
) -> None:
|
| 477 |
+
super().__init__(blocksize, fetcher, size)
|
| 478 |
+
self.cache = b""
|
| 479 |
+
self.start: int | None = None
|
| 480 |
+
self.end: int | None = None
|
| 481 |
+
self.trim = trim
|
| 482 |
+
|
| 483 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 484 |
+
# TODO: only set start/end after fetch, in case it fails?
|
| 485 |
+
# is this where retry logic might go?
|
| 486 |
+
if start is None:
|
| 487 |
+
start = 0
|
| 488 |
+
if end is None:
|
| 489 |
+
end = self.size
|
| 490 |
+
if start >= self.size or start >= end:
|
| 491 |
+
return b""
|
| 492 |
+
if (
|
| 493 |
+
self.start is not None
|
| 494 |
+
and start >= self.start
|
| 495 |
+
and self.end is not None
|
| 496 |
+
and end < self.end
|
| 497 |
+
):
|
| 498 |
+
# cache hit: we have all the required data
|
| 499 |
+
offset = start - self.start
|
| 500 |
+
self.hit_count += 1
|
| 501 |
+
return self.cache[offset : offset + end - start]
|
| 502 |
+
|
| 503 |
+
if self.blocksize:
|
| 504 |
+
bend = min(self.size, end + self.blocksize)
|
| 505 |
+
else:
|
| 506 |
+
bend = end
|
| 507 |
+
|
| 508 |
+
if bend == start or start > self.size:
|
| 509 |
+
return b""
|
| 510 |
+
|
| 511 |
+
if (self.start is None or start < self.start) and (
|
| 512 |
+
self.end is None or end > self.end
|
| 513 |
+
):
|
| 514 |
+
# First read, or extending both before and after
|
| 515 |
+
self.total_requested_bytes += bend - start
|
| 516 |
+
self.miss_count += 1
|
| 517 |
+
self.cache = self.fetcher(start, bend)
|
| 518 |
+
self.start = start
|
| 519 |
+
else:
|
| 520 |
+
assert self.start is not None
|
| 521 |
+
assert self.end is not None
|
| 522 |
+
self.miss_count += 1
|
| 523 |
+
|
| 524 |
+
if start < self.start:
|
| 525 |
+
if self.end is None or self.end - end > self.blocksize:
|
| 526 |
+
self.total_requested_bytes += bend - start
|
| 527 |
+
self.cache = self.fetcher(start, bend)
|
| 528 |
+
self.start = start
|
| 529 |
+
else:
|
| 530 |
+
self.total_requested_bytes += self.start - start
|
| 531 |
+
new = self.fetcher(start, self.start)
|
| 532 |
+
self.start = start
|
| 533 |
+
self.cache = new + self.cache
|
| 534 |
+
elif self.end is not None and bend > self.end:
|
| 535 |
+
if self.end > self.size:
|
| 536 |
+
pass
|
| 537 |
+
elif end - self.end > self.blocksize:
|
| 538 |
+
self.total_requested_bytes += bend - start
|
| 539 |
+
self.cache = self.fetcher(start, bend)
|
| 540 |
+
self.start = start
|
| 541 |
+
else:
|
| 542 |
+
self.total_requested_bytes += bend - self.end
|
| 543 |
+
new = self.fetcher(self.end, bend)
|
| 544 |
+
self.cache = self.cache + new
|
| 545 |
+
|
| 546 |
+
self.end = self.start + len(self.cache)
|
| 547 |
+
offset = start - self.start
|
| 548 |
+
out = self.cache[offset : offset + end - start]
|
| 549 |
+
if self.trim:
|
| 550 |
+
num = (self.end - self.start) // (self.blocksize + 1)
|
| 551 |
+
if num > 1:
|
| 552 |
+
self.start += self.blocksize * num
|
| 553 |
+
self.cache = self.cache[self.blocksize * num :]
|
| 554 |
+
return out
|
| 555 |
+
|
| 556 |
+
def __len__(self) -> int:
|
| 557 |
+
return len(self.cache)
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
class AllBytes(BaseCache):
|
| 561 |
+
"""Cache entire contents of the file"""
|
| 562 |
+
|
| 563 |
+
name: ClassVar[str] = "all"
|
| 564 |
+
|
| 565 |
+
def __init__(
|
| 566 |
+
self,
|
| 567 |
+
blocksize: int | None = None,
|
| 568 |
+
fetcher: Fetcher | None = None,
|
| 569 |
+
size: int | None = None,
|
| 570 |
+
data: bytes | None = None,
|
| 571 |
+
) -> None:
|
| 572 |
+
super().__init__(blocksize, fetcher, size) # type: ignore[arg-type]
|
| 573 |
+
if data is None:
|
| 574 |
+
self.miss_count += 1
|
| 575 |
+
self.total_requested_bytes += self.size
|
| 576 |
+
data = self.fetcher(0, self.size)
|
| 577 |
+
self.data = data
|
| 578 |
+
|
| 579 |
+
def _fetch(self, start: int | None, stop: int | None) -> bytes:
|
| 580 |
+
self.hit_count += 1
|
| 581 |
+
return self.data[start:stop]
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
class KnownPartsOfAFile(BaseCache):
|
| 585 |
+
"""
|
| 586 |
+
Cache holding known file parts.
|
| 587 |
+
|
| 588 |
+
Parameters
|
| 589 |
+
----------
|
| 590 |
+
blocksize: int
|
| 591 |
+
How far to read ahead in numbers of bytes
|
| 592 |
+
fetcher: func
|
| 593 |
+
Function of the form f(start, end) which gets bytes from remote as
|
| 594 |
+
specified
|
| 595 |
+
size: int
|
| 596 |
+
How big this file is
|
| 597 |
+
data: dict
|
| 598 |
+
A dictionary mapping explicit `(start, stop)` file-offset tuples
|
| 599 |
+
with known bytes.
|
| 600 |
+
strict: bool, default True
|
| 601 |
+
Whether to fetch reads that go beyond a known byte-range boundary.
|
| 602 |
+
If `False`, any read that ends outside a known part will be zero
|
| 603 |
+
padded. Note that zero padding will not be used for reads that
|
| 604 |
+
begin outside a known byte-range.
|
| 605 |
+
"""
|
| 606 |
+
|
| 607 |
+
name: ClassVar[str] = "parts"
|
| 608 |
+
|
| 609 |
+
def __init__(
|
| 610 |
+
self,
|
| 611 |
+
blocksize: int,
|
| 612 |
+
fetcher: Fetcher,
|
| 613 |
+
size: int,
|
| 614 |
+
data: dict[tuple[int, int], bytes] | None = None,
|
| 615 |
+
strict: bool = False,
|
| 616 |
+
**_: Any,
|
| 617 |
+
):
|
| 618 |
+
super().__init__(blocksize, fetcher, size)
|
| 619 |
+
self.strict = strict
|
| 620 |
+
|
| 621 |
+
# simple consolidation of contiguous blocks
|
| 622 |
+
if data:
|
| 623 |
+
old_offsets = sorted(data.keys())
|
| 624 |
+
offsets = [old_offsets[0]]
|
| 625 |
+
blocks = [data.pop(old_offsets[0])]
|
| 626 |
+
for start, stop in old_offsets[1:]:
|
| 627 |
+
start0, stop0 = offsets[-1]
|
| 628 |
+
if start == stop0:
|
| 629 |
+
offsets[-1] = (start0, stop)
|
| 630 |
+
blocks[-1] += data.pop((start, stop))
|
| 631 |
+
else:
|
| 632 |
+
offsets.append((start, stop))
|
| 633 |
+
blocks.append(data.pop((start, stop)))
|
| 634 |
+
|
| 635 |
+
self.data = dict(zip(offsets, blocks))
|
| 636 |
+
else:
|
| 637 |
+
self.data = {}
|
| 638 |
+
|
| 639 |
+
@property
|
| 640 |
+
def size(self):
|
| 641 |
+
return sum(_[1] - _[0] for _ in self.data)
|
| 642 |
+
|
| 643 |
+
@size.setter
|
| 644 |
+
def size(self, value):
|
| 645 |
+
pass
|
| 646 |
+
|
| 647 |
+
@property
|
| 648 |
+
def nblocks(self):
|
| 649 |
+
return len(self.data)
|
| 650 |
+
|
| 651 |
+
@nblocks.setter
|
| 652 |
+
def nblocks(self, value):
|
| 653 |
+
pass
|
| 654 |
+
|
| 655 |
+
def _fetch(self, start: int | None, stop: int | None) -> bytes:
|
| 656 |
+
logger.debug("Known parts request %s %s", start, stop)
|
| 657 |
+
if start is None:
|
| 658 |
+
start = 0
|
| 659 |
+
if stop is None:
|
| 660 |
+
stop = self.size
|
| 661 |
+
self.total_requested_bytes += stop - start
|
| 662 |
+
out = b""
|
| 663 |
+
started = False
|
| 664 |
+
loc_old = 0
|
| 665 |
+
for loc0, loc1 in sorted(self.data):
|
| 666 |
+
if (loc0 <= start < loc1) and (loc0 <= stop <= loc1):
|
| 667 |
+
# entirely within the block
|
| 668 |
+
off = start - loc0
|
| 669 |
+
self.hit_count += 1
|
| 670 |
+
return self.data[(loc0, loc1)][off : off + stop - start]
|
| 671 |
+
if stop <= loc0:
|
| 672 |
+
break
|
| 673 |
+
if started and loc0 > loc_old:
|
| 674 |
+
# a gap where we need data
|
| 675 |
+
self.miss_count += 1
|
| 676 |
+
if self.strict:
|
| 677 |
+
raise ValueError
|
| 678 |
+
out += b"\x00" * (loc0 - loc_old)
|
| 679 |
+
if loc0 <= start < loc1:
|
| 680 |
+
# found the start
|
| 681 |
+
self.hit_count += 1
|
| 682 |
+
off = start - loc0
|
| 683 |
+
out = self.data[(loc0, loc1)][off : off + stop - start]
|
| 684 |
+
started = True
|
| 685 |
+
elif start < loc0 and stop > loc1:
|
| 686 |
+
# the whole block
|
| 687 |
+
self.hit_count += 1
|
| 688 |
+
out += self.data[(loc0, loc1)]
|
| 689 |
+
elif loc0 <= stop <= loc1:
|
| 690 |
+
# end block
|
| 691 |
+
self.hit_count += 1
|
| 692 |
+
out = out + self.data[(loc0, loc1)][: stop - loc0]
|
| 693 |
+
return out
|
| 694 |
+
loc_old = loc1
|
| 695 |
+
self.miss_count += 1
|
| 696 |
+
if started and not self.strict:
|
| 697 |
+
out = out + b"\x00" * (stop - loc_old)
|
| 698 |
+
return out
|
| 699 |
+
raise ValueError
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
class UpdatableLRU(Generic[P, T]):
|
| 703 |
+
"""
|
| 704 |
+
Custom implementation of LRU cache that allows updating keys
|
| 705 |
+
|
| 706 |
+
Used by BackgroudBlockCache
|
| 707 |
+
"""
|
| 708 |
+
|
| 709 |
+
class CacheInfo(NamedTuple):
|
| 710 |
+
hits: int
|
| 711 |
+
misses: int
|
| 712 |
+
maxsize: int
|
| 713 |
+
currsize: int
|
| 714 |
+
|
| 715 |
+
def __init__(self, func: Callable[P, T], max_size: int = 128) -> None:
|
| 716 |
+
self._cache: OrderedDict[Any, T] = collections.OrderedDict()
|
| 717 |
+
self._func = func
|
| 718 |
+
self._max_size = max_size
|
| 719 |
+
self._hits = 0
|
| 720 |
+
self._misses = 0
|
| 721 |
+
self._lock = threading.Lock()
|
| 722 |
+
|
| 723 |
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
| 724 |
+
if kwargs:
|
| 725 |
+
raise TypeError(f"Got unexpected keyword argument {kwargs.keys()}")
|
| 726 |
+
with self._lock:
|
| 727 |
+
if args in self._cache:
|
| 728 |
+
self._cache.move_to_end(args)
|
| 729 |
+
self._hits += 1
|
| 730 |
+
return self._cache[args]
|
| 731 |
+
|
| 732 |
+
result = self._func(*args, **kwargs)
|
| 733 |
+
|
| 734 |
+
with self._lock:
|
| 735 |
+
self._cache[args] = result
|
| 736 |
+
self._misses += 1
|
| 737 |
+
if len(self._cache) > self._max_size:
|
| 738 |
+
self._cache.popitem(last=False)
|
| 739 |
+
|
| 740 |
+
return result
|
| 741 |
+
|
| 742 |
+
def is_key_cached(self, *args: Any) -> bool:
|
| 743 |
+
with self._lock:
|
| 744 |
+
return args in self._cache
|
| 745 |
+
|
| 746 |
+
def add_key(self, result: T, *args: Any) -> None:
|
| 747 |
+
with self._lock:
|
| 748 |
+
self._cache[args] = result
|
| 749 |
+
if len(self._cache) > self._max_size:
|
| 750 |
+
self._cache.popitem(last=False)
|
| 751 |
+
|
| 752 |
+
def cache_info(self) -> UpdatableLRU.CacheInfo:
|
| 753 |
+
with self._lock:
|
| 754 |
+
return self.CacheInfo(
|
| 755 |
+
maxsize=self._max_size,
|
| 756 |
+
currsize=len(self._cache),
|
| 757 |
+
hits=self._hits,
|
| 758 |
+
misses=self._misses,
|
| 759 |
+
)
|
| 760 |
+
|
| 761 |
+
|
| 762 |
+
class BackgroundBlockCache(BaseCache):
|
| 763 |
+
"""
|
| 764 |
+
Cache holding memory as a set of blocks with pre-loading of
|
| 765 |
+
the next block in the background.
|
| 766 |
+
|
| 767 |
+
Requests are only ever made ``blocksize`` at a time, and are
|
| 768 |
+
stored in an LRU cache. The least recently accessed block is
|
| 769 |
+
discarded when more than ``maxblocks`` are stored. If the
|
| 770 |
+
next block is not in cache, it is loaded in a separate thread
|
| 771 |
+
in non-blocking way.
|
| 772 |
+
|
| 773 |
+
Parameters
|
| 774 |
+
----------
|
| 775 |
+
blocksize : int
|
| 776 |
+
The number of bytes to store in each block.
|
| 777 |
+
Requests are only ever made for ``blocksize``, so this
|
| 778 |
+
should balance the overhead of making a request against
|
| 779 |
+
the granularity of the blocks.
|
| 780 |
+
fetcher : Callable
|
| 781 |
+
size : int
|
| 782 |
+
The total size of the file being cached.
|
| 783 |
+
maxblocks : int
|
| 784 |
+
The maximum number of blocks to cache for. The maximum memory
|
| 785 |
+
use for this cache is then ``blocksize * maxblocks``.
|
| 786 |
+
"""
|
| 787 |
+
|
| 788 |
+
name: ClassVar[str] = "background"
|
| 789 |
+
|
| 790 |
+
def __init__(
|
| 791 |
+
self, blocksize: int, fetcher: Fetcher, size: int, maxblocks: int = 32
|
| 792 |
+
) -> None:
|
| 793 |
+
super().__init__(blocksize, fetcher, size)
|
| 794 |
+
self.nblocks = math.ceil(size / blocksize)
|
| 795 |
+
self.maxblocks = maxblocks
|
| 796 |
+
self._fetch_block_cached = UpdatableLRU(self._fetch_block, maxblocks)
|
| 797 |
+
|
| 798 |
+
self._thread_executor = ThreadPoolExecutor(max_workers=1)
|
| 799 |
+
self._fetch_future_block_number: int | None = None
|
| 800 |
+
self._fetch_future: Future[bytes] | None = None
|
| 801 |
+
self._fetch_future_lock = threading.Lock()
|
| 802 |
+
|
| 803 |
+
def cache_info(self) -> UpdatableLRU.CacheInfo:
|
| 804 |
+
"""
|
| 805 |
+
The statistics on the block cache.
|
| 806 |
+
|
| 807 |
+
Returns
|
| 808 |
+
-------
|
| 809 |
+
NamedTuple
|
| 810 |
+
Returned directly from the LRU Cache used internally.
|
| 811 |
+
"""
|
| 812 |
+
return self._fetch_block_cached.cache_info()
|
| 813 |
+
|
| 814 |
+
def __getstate__(self) -> dict[str, Any]:
|
| 815 |
+
state = self.__dict__
|
| 816 |
+
del state["_fetch_block_cached"]
|
| 817 |
+
del state["_thread_executor"]
|
| 818 |
+
del state["_fetch_future_block_number"]
|
| 819 |
+
del state["_fetch_future"]
|
| 820 |
+
del state["_fetch_future_lock"]
|
| 821 |
+
return state
|
| 822 |
+
|
| 823 |
+
def __setstate__(self, state) -> None:
|
| 824 |
+
self.__dict__.update(state)
|
| 825 |
+
self._fetch_block_cached = UpdatableLRU(self._fetch_block, state["maxblocks"])
|
| 826 |
+
self._thread_executor = ThreadPoolExecutor(max_workers=1)
|
| 827 |
+
self._fetch_future_block_number = None
|
| 828 |
+
self._fetch_future = None
|
| 829 |
+
self._fetch_future_lock = threading.Lock()
|
| 830 |
+
|
| 831 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 832 |
+
if start is None:
|
| 833 |
+
start = 0
|
| 834 |
+
if end is None:
|
| 835 |
+
end = self.size
|
| 836 |
+
if start >= self.size or start >= end:
|
| 837 |
+
return b""
|
| 838 |
+
|
| 839 |
+
# byte position -> block numbers
|
| 840 |
+
start_block_number = start // self.blocksize
|
| 841 |
+
end_block_number = end // self.blocksize
|
| 842 |
+
|
| 843 |
+
fetch_future_block_number = None
|
| 844 |
+
fetch_future = None
|
| 845 |
+
with self._fetch_future_lock:
|
| 846 |
+
# Background thread is running. Check we we can or must join it.
|
| 847 |
+
if self._fetch_future is not None:
|
| 848 |
+
assert self._fetch_future_block_number is not None
|
| 849 |
+
if self._fetch_future.done():
|
| 850 |
+
logger.info("BlockCache joined background fetch without waiting.")
|
| 851 |
+
self._fetch_block_cached.add_key(
|
| 852 |
+
self._fetch_future.result(), self._fetch_future_block_number
|
| 853 |
+
)
|
| 854 |
+
# Cleanup the fetch variables. Done with fetching the block.
|
| 855 |
+
self._fetch_future_block_number = None
|
| 856 |
+
self._fetch_future = None
|
| 857 |
+
else:
|
| 858 |
+
# Must join if we need the block for the current fetch
|
| 859 |
+
must_join = bool(
|
| 860 |
+
start_block_number
|
| 861 |
+
<= self._fetch_future_block_number
|
| 862 |
+
<= end_block_number
|
| 863 |
+
)
|
| 864 |
+
if must_join:
|
| 865 |
+
# Copy to the local variables to release lock
|
| 866 |
+
# before waiting for result
|
| 867 |
+
fetch_future_block_number = self._fetch_future_block_number
|
| 868 |
+
fetch_future = self._fetch_future
|
| 869 |
+
|
| 870 |
+
# Cleanup the fetch variables. Have a local copy.
|
| 871 |
+
self._fetch_future_block_number = None
|
| 872 |
+
self._fetch_future = None
|
| 873 |
+
|
| 874 |
+
# Need to wait for the future for the current read
|
| 875 |
+
if fetch_future is not None:
|
| 876 |
+
logger.info("BlockCache waiting for background fetch.")
|
| 877 |
+
# Wait until result and put it in cache
|
| 878 |
+
self._fetch_block_cached.add_key(
|
| 879 |
+
fetch_future.result(), fetch_future_block_number
|
| 880 |
+
)
|
| 881 |
+
|
| 882 |
+
# these are cached, so safe to do multiple calls for the same start and end.
|
| 883 |
+
for block_number in range(start_block_number, end_block_number + 1):
|
| 884 |
+
self._fetch_block_cached(block_number)
|
| 885 |
+
|
| 886 |
+
# fetch next block in the background if nothing is running in the background,
|
| 887 |
+
# the block is within file and it is not already cached
|
| 888 |
+
end_block_plus_1 = end_block_number + 1
|
| 889 |
+
with self._fetch_future_lock:
|
| 890 |
+
if (
|
| 891 |
+
self._fetch_future is None
|
| 892 |
+
and end_block_plus_1 <= self.nblocks
|
| 893 |
+
and not self._fetch_block_cached.is_key_cached(end_block_plus_1)
|
| 894 |
+
):
|
| 895 |
+
self._fetch_future_block_number = end_block_plus_1
|
| 896 |
+
self._fetch_future = self._thread_executor.submit(
|
| 897 |
+
self._fetch_block, end_block_plus_1, "async"
|
| 898 |
+
)
|
| 899 |
+
|
| 900 |
+
return self._read_cache(
|
| 901 |
+
start,
|
| 902 |
+
end,
|
| 903 |
+
start_block_number=start_block_number,
|
| 904 |
+
end_block_number=end_block_number,
|
| 905 |
+
)
|
| 906 |
+
|
| 907 |
+
def _fetch_block(self, block_number: int, log_info: str = "sync") -> bytes:
|
| 908 |
+
"""
|
| 909 |
+
Fetch the block of data for `block_number`.
|
| 910 |
+
"""
|
| 911 |
+
if block_number > self.nblocks:
|
| 912 |
+
raise ValueError(
|
| 913 |
+
f"'block_number={block_number}' is greater than "
|
| 914 |
+
f"the number of blocks ({self.nblocks})"
|
| 915 |
+
)
|
| 916 |
+
|
| 917 |
+
start = block_number * self.blocksize
|
| 918 |
+
end = start + self.blocksize
|
| 919 |
+
logger.info("BlockCache fetching block (%s) %d", log_info, block_number)
|
| 920 |
+
self.total_requested_bytes += end - start
|
| 921 |
+
self.miss_count += 1
|
| 922 |
+
block_contents = super()._fetch(start, end)
|
| 923 |
+
return block_contents
|
| 924 |
+
|
| 925 |
+
def _read_cache(
|
| 926 |
+
self, start: int, end: int, start_block_number: int, end_block_number: int
|
| 927 |
+
) -> bytes:
|
| 928 |
+
"""
|
| 929 |
+
Read from our block cache.
|
| 930 |
+
|
| 931 |
+
Parameters
|
| 932 |
+
----------
|
| 933 |
+
start, end : int
|
| 934 |
+
The start and end byte positions.
|
| 935 |
+
start_block_number, end_block_number : int
|
| 936 |
+
The start and end block numbers.
|
| 937 |
+
"""
|
| 938 |
+
start_pos = start % self.blocksize
|
| 939 |
+
end_pos = end % self.blocksize
|
| 940 |
+
|
| 941 |
+
# kind of pointless to count this as a hit, but it is
|
| 942 |
+
self.hit_count += 1
|
| 943 |
+
|
| 944 |
+
if start_block_number == end_block_number:
|
| 945 |
+
block = self._fetch_block_cached(start_block_number)
|
| 946 |
+
return block[start_pos:end_pos]
|
| 947 |
+
|
| 948 |
+
else:
|
| 949 |
+
# read from the initial
|
| 950 |
+
out = [self._fetch_block_cached(start_block_number)[start_pos:]]
|
| 951 |
+
|
| 952 |
+
# intermediate blocks
|
| 953 |
+
# Note: it'd be nice to combine these into one big request. However
|
| 954 |
+
# that doesn't play nicely with our LRU cache.
|
| 955 |
+
out.extend(
|
| 956 |
+
map(
|
| 957 |
+
self._fetch_block_cached,
|
| 958 |
+
range(start_block_number + 1, end_block_number),
|
| 959 |
+
)
|
| 960 |
+
)
|
| 961 |
+
|
| 962 |
+
# final block
|
| 963 |
+
out.append(self._fetch_block_cached(end_block_number)[:end_pos])
|
| 964 |
+
|
| 965 |
+
return b"".join(out)
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
caches: dict[str | None, type[BaseCache]] = {
|
| 969 |
+
# one custom case
|
| 970 |
+
None: BaseCache,
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
|
| 974 |
+
def register_cache(cls: type[BaseCache], clobber: bool = False) -> None:
|
| 975 |
+
"""'Register' cache implementation.
|
| 976 |
+
|
| 977 |
+
Parameters
|
| 978 |
+
----------
|
| 979 |
+
clobber: bool, optional
|
| 980 |
+
If set to True (default is False) - allow to overwrite existing
|
| 981 |
+
entry.
|
| 982 |
+
|
| 983 |
+
Raises
|
| 984 |
+
------
|
| 985 |
+
ValueError
|
| 986 |
+
"""
|
| 987 |
+
name = cls.name
|
| 988 |
+
if not clobber and name in caches:
|
| 989 |
+
raise ValueError(f"Cache with name {name!r} is already known: {caches[name]}")
|
| 990 |
+
caches[name] = cls
|
| 991 |
+
|
| 992 |
+
|
| 993 |
+
for c in (
|
| 994 |
+
BaseCache,
|
| 995 |
+
MMapCache,
|
| 996 |
+
BytesCache,
|
| 997 |
+
ReadAheadCache,
|
| 998 |
+
BlockCache,
|
| 999 |
+
FirstChunkCache,
|
| 1000 |
+
AllBytes,
|
| 1001 |
+
KnownPartsOfAFile,
|
| 1002 |
+
BackgroundBlockCache,
|
| 1003 |
+
):
|
| 1004 |
+
register_cache(c)
|
TTS/Kokoro/.venv/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|
| 5 |
+
"""
|
| 6 |
+
Base class and interface for callback mechanism
|
| 7 |
+
|
| 8 |
+
This class can be used directly for monitoring file transfers by
|
| 9 |
+
providing ``callback=Callback(hooks=...)`` (see the ``hooks`` argument,
|
| 10 |
+
below), or subclassed for more specialised behaviour.
|
| 11 |
+
|
| 12 |
+
Parameters
|
| 13 |
+
----------
|
| 14 |
+
size: int (optional)
|
| 15 |
+
Nominal quantity for the value that corresponds to a complete
|
| 16 |
+
transfer, e.g., total number of tiles or total number of
|
| 17 |
+
bytes
|
| 18 |
+
value: int (0)
|
| 19 |
+
Starting internal counter value
|
| 20 |
+
hooks: dict or None
|
| 21 |
+
A dict of named functions to be called on each update. The signature
|
| 22 |
+
of these must be ``f(size, value, **kwargs)``
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
def __init__(self, size=None, value=0, hooks=None, **kwargs):
|
| 26 |
+
self.size = size
|
| 27 |
+
self.value = value
|
| 28 |
+
self.hooks = hooks or {}
|
| 29 |
+
self.kw = kwargs
|
| 30 |
+
|
| 31 |
+
def __enter__(self):
|
| 32 |
+
return self
|
| 33 |
+
|
| 34 |
+
def __exit__(self, *exc_args):
|
| 35 |
+
self.close()
|
| 36 |
+
|
| 37 |
+
def close(self):
|
| 38 |
+
"""Close callback."""
|
| 39 |
+
|
| 40 |
+
def branched(self, path_1, path_2, **kwargs):
|
| 41 |
+
"""
|
| 42 |
+
Return callback for child transfers
|
| 43 |
+
|
| 44 |
+
If this callback is operating at a higher level, e.g., put, which may
|
| 45 |
+
trigger transfers that can also be monitored. The function returns a callback
|
| 46 |
+
that has to be passed to the child method, e.g., put_file,
|
| 47 |
+
as `callback=` argument.
|
| 48 |
+
|
| 49 |
+
The implementation uses `callback.branch` for compatibility.
|
| 50 |
+
When implementing callbacks, it is recommended to override this function instead
|
| 51 |
+
of `branch` and avoid calling `super().branched(...)`.
|
| 52 |
+
|
| 53 |
+
Prefer using this function over `branch`.
|
| 54 |
+
|
| 55 |
+
Parameters
|
| 56 |
+
----------
|
| 57 |
+
path_1: str
|
| 58 |
+
Child's source path
|
| 59 |
+
path_2: str
|
| 60 |
+
Child's destination path
|
| 61 |
+
**kwargs:
|
| 62 |
+
Arbitrary keyword arguments
|
| 63 |
+
|
| 64 |
+
Returns
|
| 65 |
+
-------
|
| 66 |
+
callback: Callback
|
| 67 |
+
A callback instance to be passed to the child method
|
| 68 |
+
"""
|
| 69 |
+
self.branch(path_1, path_2, kwargs)
|
| 70 |
+
# mutate kwargs so that we can force the caller to pass "callback=" explicitly
|
| 71 |
+
return kwargs.pop("callback", DEFAULT_CALLBACK)
|
| 72 |
+
|
| 73 |
+
def branch_coro(self, fn):
|
| 74 |
+
"""
|
| 75 |
+
Wraps a coroutine, and pass a new child callback to it.
|
| 76 |
+
"""
|
| 77 |
+
|
| 78 |
+
@wraps(fn)
|
| 79 |
+
async def func(path1, path2: str, **kwargs):
|
| 80 |
+
with self.branched(path1, path2, **kwargs) as child:
|
| 81 |
+
return await fn(path1, path2, callback=child, **kwargs)
|
| 82 |
+
|
| 83 |
+
return func
|
| 84 |
+
|
| 85 |
+
def set_size(self, size):
|
| 86 |
+
"""
|
| 87 |
+
Set the internal maximum size attribute
|
| 88 |
+
|
| 89 |
+
Usually called if not initially set at instantiation. Note that this
|
| 90 |
+
triggers a ``call()``.
|
| 91 |
+
|
| 92 |
+
Parameters
|
| 93 |
+
----------
|
| 94 |
+
size: int
|
| 95 |
+
"""
|
| 96 |
+
self.size = size
|
| 97 |
+
self.call()
|
| 98 |
+
|
| 99 |
+
def absolute_update(self, value):
|
| 100 |
+
"""
|
| 101 |
+
Set the internal value state
|
| 102 |
+
|
| 103 |
+
Triggers ``call()``
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
value: int
|
| 108 |
+
"""
|
| 109 |
+
self.value = value
|
| 110 |
+
self.call()
|
| 111 |
+
|
| 112 |
+
def relative_update(self, inc=1):
|
| 113 |
+
"""
|
| 114 |
+
Delta increment the internal counter
|
| 115 |
+
|
| 116 |
+
Triggers ``call()``
|
| 117 |
+
|
| 118 |
+
Parameters
|
| 119 |
+
----------
|
| 120 |
+
inc: int
|
| 121 |
+
"""
|
| 122 |
+
self.value += inc
|
| 123 |
+
self.call()
|
| 124 |
+
|
| 125 |
+
def call(self, hook_name=None, **kwargs):
|
| 126 |
+
"""
|
| 127 |
+
Execute hook(s) with current state
|
| 128 |
+
|
| 129 |
+
Each function is passed the internal size and current value
|
| 130 |
+
|
| 131 |
+
Parameters
|
| 132 |
+
----------
|
| 133 |
+
hook_name: str or None
|
| 134 |
+
If given, execute on this hook
|
| 135 |
+
kwargs: passed on to (all) hook(s)
|
| 136 |
+
"""
|
| 137 |
+
if not self.hooks:
|
| 138 |
+
return
|
| 139 |
+
kw = self.kw.copy()
|
| 140 |
+
kw.update(kwargs)
|
| 141 |
+
if hook_name:
|
| 142 |
+
if hook_name not in self.hooks:
|
| 143 |
+
return
|
| 144 |
+
return self.hooks[hook_name](self.size, self.value, **kw)
|
| 145 |
+
for hook in self.hooks.values() or []:
|
| 146 |
+
hook(self.size, self.value, **kw)
|
| 147 |
+
|
| 148 |
+
def wrap(self, iterable):
|
| 149 |
+
"""
|
| 150 |
+
Wrap an iterable to call ``relative_update`` on each iterations
|
| 151 |
+
|
| 152 |
+
Parameters
|
| 153 |
+
----------
|
| 154 |
+
iterable: Iterable
|
| 155 |
+
The iterable that is being wrapped
|
| 156 |
+
"""
|
| 157 |
+
for item in iterable:
|
| 158 |
+
self.relative_update()
|
| 159 |
+
yield item
|
| 160 |
+
|
| 161 |
+
def branch(self, path_1, path_2, kwargs):
|
| 162 |
+
"""
|
| 163 |
+
Set callbacks for child transfers
|
| 164 |
+
|
| 165 |
+
If this callback is operating at a higher level, e.g., put, which may
|
| 166 |
+
trigger transfers that can also be monitored. The passed kwargs are
|
| 167 |
+
to be *mutated* to add ``callback=``, if this class supports branching
|
| 168 |
+
to children.
|
| 169 |
+
|
| 170 |
+
Parameters
|
| 171 |
+
----------
|
| 172 |
+
path_1: str
|
| 173 |
+
Child's source path
|
| 174 |
+
path_2: str
|
| 175 |
+
Child's destination path
|
| 176 |
+
kwargs: dict
|
| 177 |
+
arguments passed to child method, e.g., put_file.
|
| 178 |
+
|
| 179 |
+
Returns
|
| 180 |
+
-------
|
| 181 |
+
|
| 182 |
+
"""
|
| 183 |
+
return None
|
| 184 |
+
|
| 185 |
+
def no_op(self, *_, **__):
|
| 186 |
+
pass
|
| 187 |
+
|
| 188 |
+
def __getattr__(self, item):
|
| 189 |
+
"""
|
| 190 |
+
If undefined methods are called on this class, nothing happens
|
| 191 |
+
"""
|
| 192 |
+
return self.no_op
|
| 193 |
+
|
| 194 |
+
@classmethod
|
| 195 |
+
def as_callback(cls, maybe_callback=None):
|
| 196 |
+
"""Transform callback=... into Callback instance
|
| 197 |
+
|
| 198 |
+
For the special value of ``None``, return the global instance of
|
| 199 |
+
``NoOpCallback``. This is an alternative to including
|
| 200 |
+
``callback=DEFAULT_CALLBACK`` directly in a method signature.
|
| 201 |
+
"""
|
| 202 |
+
if maybe_callback is None:
|
| 203 |
+
return DEFAULT_CALLBACK
|
| 204 |
+
return maybe_callback
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
class NoOpCallback(Callback):
|
| 208 |
+
"""
|
| 209 |
+
This implementation of Callback does exactly nothing
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
def call(self, *args, **kwargs):
|
| 213 |
+
return None
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class DotPrinterCallback(Callback):
|
| 217 |
+
"""
|
| 218 |
+
Simple example Callback implementation
|
| 219 |
+
|
| 220 |
+
Almost identical to Callback with a hook that prints a char; here we
|
| 221 |
+
demonstrate how the outer layer may print "#" and the inner layer "."
|
| 222 |
+
"""
|
| 223 |
+
|
| 224 |
+
def __init__(self, chr_to_print="#", **kwargs):
|
| 225 |
+
self.chr = chr_to_print
|
| 226 |
+
super().__init__(**kwargs)
|
| 227 |
+
|
| 228 |
+
def branch(self, path_1, path_2, kwargs):
|
| 229 |
+
"""Mutate kwargs to add new instance with different print char"""
|
| 230 |
+
kwargs["callback"] = DotPrinterCallback(".")
|
| 231 |
+
|
| 232 |
+
def call(self, **kwargs):
|
| 233 |
+
"""Just outputs a character"""
|
| 234 |
+
print(self.chr, end="")
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
class TqdmCallback(Callback):
|
| 238 |
+
"""
|
| 239 |
+
A callback to display a progress bar using tqdm
|
| 240 |
+
|
| 241 |
+
Parameters
|
| 242 |
+
----------
|
| 243 |
+
tqdm_kwargs : dict, (optional)
|
| 244 |
+
Any argument accepted by the tqdm constructor.
|
| 245 |
+
See the `tqdm doc <https://tqdm.github.io/docs/tqdm/#__init__>`_.
|
| 246 |
+
Will be forwarded to `tqdm_cls`.
|
| 247 |
+
tqdm_cls: (optional)
|
| 248 |
+
subclass of `tqdm.tqdm`. If not passed, it will default to `tqdm.tqdm`.
|
| 249 |
+
|
| 250 |
+
Examples
|
| 251 |
+
--------
|
| 252 |
+
>>> import fsspec
|
| 253 |
+
>>> from fsspec.callbacks import TqdmCallback
|
| 254 |
+
>>> fs = fsspec.filesystem("memory")
|
| 255 |
+
>>> path2distant_data = "/your-path"
|
| 256 |
+
>>> fs.upload(
|
| 257 |
+
".",
|
| 258 |
+
path2distant_data,
|
| 259 |
+
recursive=True,
|
| 260 |
+
callback=TqdmCallback(),
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
You can forward args to tqdm using the ``tqdm_kwargs`` parameter.
|
| 264 |
+
|
| 265 |
+
>>> fs.upload(
|
| 266 |
+
".",
|
| 267 |
+
path2distant_data,
|
| 268 |
+
recursive=True,
|
| 269 |
+
callback=TqdmCallback(tqdm_kwargs={"desc": "Your tqdm description"}),
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
You can also customize the progress bar by passing a subclass of `tqdm`.
|
| 273 |
+
|
| 274 |
+
.. code-block:: python
|
| 275 |
+
|
| 276 |
+
class TqdmFormat(tqdm):
|
| 277 |
+
'''Provides a `total_time` format parameter'''
|
| 278 |
+
@property
|
| 279 |
+
def format_dict(self):
|
| 280 |
+
d = super().format_dict
|
| 281 |
+
total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
|
| 282 |
+
d.update(total_time=self.format_interval(total_time) + " in total")
|
| 283 |
+
return d
|
| 284 |
+
|
| 285 |
+
>>> with TqdmCallback(
|
| 286 |
+
tqdm_kwargs={
|
| 287 |
+
"desc": "desc",
|
| 288 |
+
"bar_format": "{total_time}: {percentage:.0f}%|{bar}{r_bar}",
|
| 289 |
+
},
|
| 290 |
+
tqdm_cls=TqdmFormat,
|
| 291 |
+
) as callback:
|
| 292 |
+
fs.upload(".", path2distant_data, recursive=True, callback=callback)
|
| 293 |
+
"""
|
| 294 |
+
|
| 295 |
+
def __init__(self, tqdm_kwargs=None, *args, **kwargs):
|
| 296 |
+
try:
|
| 297 |
+
from tqdm import tqdm
|
| 298 |
+
|
| 299 |
+
except ImportError as exce:
|
| 300 |
+
raise ImportError(
|
| 301 |
+
"Using TqdmCallback requires tqdm to be installed"
|
| 302 |
+
) from exce
|
| 303 |
+
|
| 304 |
+
self._tqdm_cls = kwargs.pop("tqdm_cls", tqdm)
|
| 305 |
+
self._tqdm_kwargs = tqdm_kwargs or {}
|
| 306 |
+
self.tqdm = None
|
| 307 |
+
super().__init__(*args, **kwargs)
|
| 308 |
+
|
| 309 |
+
def call(self, *args, **kwargs):
|
| 310 |
+
if self.tqdm is None:
|
| 311 |
+
self.tqdm = self._tqdm_cls(total=self.size, **self._tqdm_kwargs)
|
| 312 |
+
self.tqdm.total = self.size
|
| 313 |
+
self.tqdm.update(self.value - self.tqdm.n)
|
| 314 |
+
|
| 315 |
+
def close(self):
|
| 316 |
+
if self.tqdm is not None:
|
| 317 |
+
self.tqdm.close()
|
| 318 |
+
self.tqdm = None
|
| 319 |
+
|
| 320 |
+
def __del__(self):
|
| 321 |
+
return self.close()
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
DEFAULT_CALLBACK = _DEFAULT_CALLBACK = NoOpCallback()
|