Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/INSTALLER +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/METADATA +392 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/RECORD +181 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/REQUESTED +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/WHEEL +5 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/entry_points.txt +6 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/top_level.txt +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/INSTALLER +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/LICENSE +20 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/METADATA +104 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/RECORD +86 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/WHEEL +5 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/entry_points.txt +2 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/top_level.txt +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/INSTALLER +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/LICENSE +502 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/METADATA +97 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/RECORD +107 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/WHEEL +5 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/entry_points.txt +2 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/top_level.txt +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/INSTALLER +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/LICENSE +21 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/METADATA +721 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/RECORD +35 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/WHEEL +6 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/entry_points.txt +2 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/top_level.txt +1 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/__init__.py +75 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/_compat.py +623 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/_termui_impl.py +788 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/_textwrap.py +49 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/_winconsole.py +279 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/core.py +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/decorators.py +562 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/exceptions.py +296 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/formatting.py +301 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/globals.py +67 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/parser.py +531 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/py.typed +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/shell_completion.py +603 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/termui.py +784 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/testing.py +483 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/types.py +1093 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/utils.py +624 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/__init__.py +24 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/_common.py +43 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/_version.py +4 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/easter.py +89 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/relativedelta.py +599 -0
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/IN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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: accelerate
|
| 3 |
+
Version: 1.12.0
|
| 4 |
+
Summary: Accelerate
|
| 5 |
+
Home-page: https://github.com/huggingface/accelerate
|
| 6 |
+
Author: The HuggingFace team
|
| 7 |
+
Author-email: zach.mueller@huggingface.co
|
| 8 |
+
License: Apache
|
| 9 |
+
Keywords: deep learning
|
| 10 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 11 |
+
Classifier: Intended Audience :: Developers
|
| 12 |
+
Classifier: Intended Audience :: Education
|
| 13 |
+
Classifier: Intended Audience :: Science/Research
|
| 14 |
+
Classifier: License :: OSI Approved :: Apache Software License
|
| 15 |
+
Classifier: Operating System :: OS Independent
|
| 16 |
+
Classifier: Programming Language :: Python :: 3
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 18 |
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
| 19 |
+
Requires-Python: >=3.10.0
|
| 20 |
+
Description-Content-Type: text/markdown
|
| 21 |
+
License-File: LICENSE
|
| 22 |
+
Requires-Dist: numpy>=1.17
|
| 23 |
+
Requires-Dist: packaging>=20.0
|
| 24 |
+
Requires-Dist: psutil
|
| 25 |
+
Requires-Dist: pyyaml
|
| 26 |
+
Requires-Dist: torch>=2.0.0
|
| 27 |
+
Requires-Dist: huggingface_hub>=0.21.0
|
| 28 |
+
Requires-Dist: safetensors>=0.4.3
|
| 29 |
+
Provides-Extra: quality
|
| 30 |
+
Requires-Dist: ruff==0.13.1; extra == "quality"
|
| 31 |
+
Provides-Extra: docs
|
| 32 |
+
Provides-Extra: test-prod
|
| 33 |
+
Requires-Dist: pytest>=7.2.0; extra == "test-prod"
|
| 34 |
+
Requires-Dist: pytest-xdist; extra == "test-prod"
|
| 35 |
+
Requires-Dist: pytest-subtests; extra == "test-prod"
|
| 36 |
+
Requires-Dist: parameterized; extra == "test-prod"
|
| 37 |
+
Requires-Dist: pytest-order; extra == "test-prod"
|
| 38 |
+
Provides-Extra: test-dev
|
| 39 |
+
Requires-Dist: datasets; extra == "test-dev"
|
| 40 |
+
Requires-Dist: diffusers; extra == "test-dev"
|
| 41 |
+
Requires-Dist: evaluate; extra == "test-dev"
|
| 42 |
+
Requires-Dist: torchdata>=0.8.0; extra == "test-dev"
|
| 43 |
+
Requires-Dist: torchpippy>=0.2.0; extra == "test-dev"
|
| 44 |
+
Requires-Dist: transformers; extra == "test-dev"
|
| 45 |
+
Requires-Dist: scipy; extra == "test-dev"
|
| 46 |
+
Requires-Dist: scikit-learn; extra == "test-dev"
|
| 47 |
+
Requires-Dist: tqdm; extra == "test-dev"
|
| 48 |
+
Requires-Dist: bitsandbytes; extra == "test-dev"
|
| 49 |
+
Requires-Dist: timm; extra == "test-dev"
|
| 50 |
+
Provides-Extra: testing
|
| 51 |
+
Requires-Dist: pytest>=7.2.0; extra == "testing"
|
| 52 |
+
Requires-Dist: pytest-xdist; extra == "testing"
|
| 53 |
+
Requires-Dist: pytest-subtests; extra == "testing"
|
| 54 |
+
Requires-Dist: parameterized; extra == "testing"
|
| 55 |
+
Requires-Dist: pytest-order; extra == "testing"
|
| 56 |
+
Requires-Dist: datasets; extra == "testing"
|
| 57 |
+
Requires-Dist: diffusers; extra == "testing"
|
| 58 |
+
Requires-Dist: evaluate; extra == "testing"
|
| 59 |
+
Requires-Dist: torchdata>=0.8.0; extra == "testing"
|
| 60 |
+
Requires-Dist: torchpippy>=0.2.0; extra == "testing"
|
| 61 |
+
Requires-Dist: transformers; extra == "testing"
|
| 62 |
+
Requires-Dist: scipy; extra == "testing"
|
| 63 |
+
Requires-Dist: scikit-learn; extra == "testing"
|
| 64 |
+
Requires-Dist: tqdm; extra == "testing"
|
| 65 |
+
Requires-Dist: bitsandbytes; extra == "testing"
|
| 66 |
+
Requires-Dist: timm; extra == "testing"
|
| 67 |
+
Provides-Extra: deepspeed
|
| 68 |
+
Requires-Dist: deepspeed; extra == "deepspeed"
|
| 69 |
+
Provides-Extra: rich
|
| 70 |
+
Requires-Dist: rich; extra == "rich"
|
| 71 |
+
Provides-Extra: test-fp8
|
| 72 |
+
Requires-Dist: torchao; extra == "test-fp8"
|
| 73 |
+
Provides-Extra: test-trackers
|
| 74 |
+
Requires-Dist: wandb; extra == "test-trackers"
|
| 75 |
+
Requires-Dist: comet-ml; extra == "test-trackers"
|
| 76 |
+
Requires-Dist: tensorboard; extra == "test-trackers"
|
| 77 |
+
Requires-Dist: dvclive; extra == "test-trackers"
|
| 78 |
+
Requires-Dist: matplotlib; extra == "test-trackers"
|
| 79 |
+
Requires-Dist: swanlab[dashboard]; extra == "test-trackers"
|
| 80 |
+
Requires-Dist: trackio; extra == "test-trackers"
|
| 81 |
+
Provides-Extra: dev
|
| 82 |
+
Requires-Dist: ruff==0.13.1; extra == "dev"
|
| 83 |
+
Requires-Dist: pytest>=7.2.0; extra == "dev"
|
| 84 |
+
Requires-Dist: pytest-xdist; extra == "dev"
|
| 85 |
+
Requires-Dist: pytest-subtests; extra == "dev"
|
| 86 |
+
Requires-Dist: parameterized; extra == "dev"
|
| 87 |
+
Requires-Dist: pytest-order; extra == "dev"
|
| 88 |
+
Requires-Dist: datasets; extra == "dev"
|
| 89 |
+
Requires-Dist: diffusers; extra == "dev"
|
| 90 |
+
Requires-Dist: evaluate; extra == "dev"
|
| 91 |
+
Requires-Dist: torchdata>=0.8.0; extra == "dev"
|
| 92 |
+
Requires-Dist: torchpippy>=0.2.0; extra == "dev"
|
| 93 |
+
Requires-Dist: transformers; extra == "dev"
|
| 94 |
+
Requires-Dist: scipy; extra == "dev"
|
| 95 |
+
Requires-Dist: scikit-learn; extra == "dev"
|
| 96 |
+
Requires-Dist: tqdm; extra == "dev"
|
| 97 |
+
Requires-Dist: bitsandbytes; extra == "dev"
|
| 98 |
+
Requires-Dist: timm; extra == "dev"
|
| 99 |
+
Requires-Dist: rich; extra == "dev"
|
| 100 |
+
Provides-Extra: sagemaker
|
| 101 |
+
Requires-Dist: sagemaker; extra == "sagemaker"
|
| 102 |
+
Dynamic: author
|
| 103 |
+
Dynamic: author-email
|
| 104 |
+
Dynamic: classifier
|
| 105 |
+
Dynamic: description
|
| 106 |
+
Dynamic: description-content-type
|
| 107 |
+
Dynamic: home-page
|
| 108 |
+
Dynamic: keywords
|
| 109 |
+
Dynamic: license
|
| 110 |
+
Dynamic: license-file
|
| 111 |
+
Dynamic: provides-extra
|
| 112 |
+
Dynamic: requires-dist
|
| 113 |
+
Dynamic: requires-python
|
| 114 |
+
Dynamic: summary
|
| 115 |
+
|
| 116 |
+
<!---
|
| 117 |
+
Copyright 2021 The HuggingFace Team. All rights reserved.
|
| 118 |
+
|
| 119 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 120 |
+
you may not use this file except in compliance with the License.
|
| 121 |
+
You may obtain a copy of the License at
|
| 122 |
+
|
| 123 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 124 |
+
|
| 125 |
+
Unless required by applicable law or agreed to in writing, software
|
| 126 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 127 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 128 |
+
See the License for the specific language governing permissions and
|
| 129 |
+
limitations under the License.
|
| 130 |
+
-->
|
| 131 |
+
|
| 132 |
+
<p align="center">
|
| 133 |
+
<br>
|
| 134 |
+
<img src="https://raw.githubusercontent.com/huggingface/accelerate/main/docs/source/imgs/accelerate_logo.png" width="400"/>
|
| 135 |
+
<br>
|
| 136 |
+
<p>
|
| 137 |
+
|
| 138 |
+
<p align="center">
|
| 139 |
+
<!-- Uncomment when CircleCI is set up
|
| 140 |
+
<a href="https://circleci.com/gh/huggingface/accelerate"><img alt="Build" src="https://img.shields.io/circleci/build/github/huggingface/transformers/master"></a>
|
| 141 |
+
-->
|
| 142 |
+
<a href="https://github.com/huggingface/accelerate/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/huggingface/accelerate.svg?color=blue"></a>
|
| 143 |
+
<a href="https://huggingface.co/docs/accelerate/index.html"><img alt="Documentation" src="https://img.shields.io/website/http/huggingface.co/docs/accelerate/index.html.svg?down_color=red&down_message=offline&up_message=online"></a>
|
| 144 |
+
<a href="https://github.com/huggingface/accelerate/releases"><img alt="GitHub release" src="https://img.shields.io/github/release/huggingface/accelerate.svg"></a>
|
| 145 |
+
<a href="https://github.com/huggingface/accelerate/blob/main/CODE_OF_CONDUCT.md"><img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg"></a>
|
| 146 |
+
</p>
|
| 147 |
+
|
| 148 |
+
<h3 align="center">
|
| 149 |
+
<p>Run your *raw* PyTorch training script on any kind of device
|
| 150 |
+
</h3>
|
| 151 |
+
|
| 152 |
+
<h3 align="center">
|
| 153 |
+
<a href="https://hf.co/course"><img src="https://raw.githubusercontent.com/huggingface/accelerate/main/docs/source/imgs/course_banner.png"></a>
|
| 154 |
+
</h3>
|
| 155 |
+
|
| 156 |
+
## Easy to integrate
|
| 157 |
+
|
| 158 |
+
🤗 Accelerate was created for PyTorch users who like to write the training loop of PyTorch models but are reluctant to write and maintain the boilerplate code needed to use multi-GPUs/TPU/fp16.
|
| 159 |
+
|
| 160 |
+
🤗 Accelerate abstracts exactly and only the boilerplate code related to multi-GPUs/TPU/fp16 and leaves the rest of your code unchanged.
|
| 161 |
+
|
| 162 |
+
Here is an example:
|
| 163 |
+
|
| 164 |
+
```diff
|
| 165 |
+
import torch
|
| 166 |
+
import torch.nn.functional as F
|
| 167 |
+
from datasets import load_dataset
|
| 168 |
+
+ from accelerate import Accelerator
|
| 169 |
+
|
| 170 |
+
+ accelerator = Accelerator()
|
| 171 |
+
- device = 'cpu'
|
| 172 |
+
+ device = accelerator.device
|
| 173 |
+
|
| 174 |
+
model = torch.nn.Transformer().to(device)
|
| 175 |
+
optimizer = torch.optim.Adam(model.parameters())
|
| 176 |
+
|
| 177 |
+
dataset = load_dataset('my_dataset')
|
| 178 |
+
data = torch.utils.data.DataLoader(dataset, shuffle=True)
|
| 179 |
+
|
| 180 |
+
+ model, optimizer, data = accelerator.prepare(model, optimizer, data)
|
| 181 |
+
|
| 182 |
+
model.train()
|
| 183 |
+
for epoch in range(10):
|
| 184 |
+
for source, targets in data:
|
| 185 |
+
source = source.to(device)
|
| 186 |
+
targets = targets.to(device)
|
| 187 |
+
|
| 188 |
+
optimizer.zero_grad()
|
| 189 |
+
|
| 190 |
+
output = model(source)
|
| 191 |
+
loss = F.cross_entropy(output, targets)
|
| 192 |
+
|
| 193 |
+
- loss.backward()
|
| 194 |
+
+ accelerator.backward(loss)
|
| 195 |
+
|
| 196 |
+
optimizer.step()
|
| 197 |
+
```
|
| 198 |
+
|
| 199 |
+
As you can see in this example, by adding 5-lines to any standard PyTorch training script you can now run on any kind of single or distributed node setting (single CPU, single GPU, multi-GPUs and TPUs) as well as with or without mixed precision (fp8, fp16, bf16).
|
| 200 |
+
|
| 201 |
+
In particular, the same code can then be run without modification on your local machine for debugging or your training environment.
|
| 202 |
+
|
| 203 |
+
🤗 Accelerate even handles the device placement for you (which requires a few more changes to your code, but is safer in general), so you can even simplify your training loop further:
|
| 204 |
+
|
| 205 |
+
```diff
|
| 206 |
+
import torch
|
| 207 |
+
import torch.nn.functional as F
|
| 208 |
+
from datasets import load_dataset
|
| 209 |
+
+ from accelerate import Accelerator
|
| 210 |
+
|
| 211 |
+
- device = 'cpu'
|
| 212 |
+
+ accelerator = Accelerator()
|
| 213 |
+
|
| 214 |
+
- model = torch.nn.Transformer().to(device)
|
| 215 |
+
+ model = torch.nn.Transformer()
|
| 216 |
+
optimizer = torch.optim.Adam(model.parameters())
|
| 217 |
+
|
| 218 |
+
dataset = load_dataset('my_dataset')
|
| 219 |
+
data = torch.utils.data.DataLoader(dataset, shuffle=True)
|
| 220 |
+
|
| 221 |
+
+ model, optimizer, data = accelerator.prepare(model, optimizer, data)
|
| 222 |
+
|
| 223 |
+
model.train()
|
| 224 |
+
for epoch in range(10):
|
| 225 |
+
for source, targets in data:
|
| 226 |
+
- source = source.to(device)
|
| 227 |
+
- targets = targets.to(device)
|
| 228 |
+
|
| 229 |
+
optimizer.zero_grad()
|
| 230 |
+
|
| 231 |
+
output = model(source)
|
| 232 |
+
loss = F.cross_entropy(output, targets)
|
| 233 |
+
|
| 234 |
+
- loss.backward()
|
| 235 |
+
+ accelerator.backward(loss)
|
| 236 |
+
|
| 237 |
+
optimizer.step()
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
Want to learn more? Check out the [documentation](https://huggingface.co/docs/accelerate) or have a look at our [examples](https://github.com/huggingface/accelerate/tree/main/examples).
|
| 241 |
+
|
| 242 |
+
## Launching script
|
| 243 |
+
|
| 244 |
+
🤗 Accelerate also provides an optional CLI tool that allows you to quickly configure and test your training environment before launching the scripts. No need to remember how to use `torch.distributed.run` or to write a specific launcher for TPU training!
|
| 245 |
+
On your machine(s) just run:
|
| 246 |
+
|
| 247 |
+
```bash
|
| 248 |
+
accelerate config
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
and answer the questions asked. This will generate a config file that will be used automatically to properly set the default options when doing
|
| 252 |
+
|
| 253 |
+
```bash
|
| 254 |
+
accelerate launch my_script.py --args_to_my_script
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
For instance, here is how you would run the GLUE example on the MRPC task (from the root of the repo):
|
| 258 |
+
|
| 259 |
+
```bash
|
| 260 |
+
accelerate launch examples/nlp_example.py
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
This CLI tool is **optional**, and you can still use `python my_script.py` or `python -m torchrun my_script.py` at your convenience.
|
| 264 |
+
|
| 265 |
+
You can also directly pass in the arguments you would to `torchrun` as arguments to `accelerate launch` if you wish to not run` accelerate config`.
|
| 266 |
+
|
| 267 |
+
For example, here is how to launch on two GPUs:
|
| 268 |
+
|
| 269 |
+
```bash
|
| 270 |
+
accelerate launch --multi_gpu --num_processes 2 examples/nlp_example.py
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
To learn more, check the CLI documentation available [here](https://huggingface.co/docs/accelerate/package_reference/cli).
|
| 274 |
+
|
| 275 |
+
Or view the configuration zoo [here](https://github.com/huggingface/accelerate/blob/main/examples/config_yaml_templates/)
|
| 276 |
+
|
| 277 |
+
## Launching multi-CPU run using MPI
|
| 278 |
+
|
| 279 |
+
🤗 Here is another way to launch multi-CPU run using MPI. You can learn how to install Open MPI on [this page](https://www.open-mpi.org/faq/?category=building#easy-build). You can use Intel MPI or MVAPICH as well.
|
| 280 |
+
Once you have MPI setup on your cluster, just run:
|
| 281 |
+
```bash
|
| 282 |
+
accelerate config
|
| 283 |
+
```
|
| 284 |
+
Answer the questions that are asked, selecting to run using multi-CPU, and answer "yes" when asked if you want accelerate to launch mpirun.
|
| 285 |
+
Then, use `accelerate launch` with your script like:
|
| 286 |
+
```bash
|
| 287 |
+
accelerate launch examples/nlp_example.py
|
| 288 |
+
```
|
| 289 |
+
Alternatively, you can use mpirun directly, without using the CLI like:
|
| 290 |
+
```bash
|
| 291 |
+
mpirun -np 2 python examples/nlp_example.py
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
## Launching training using DeepSpeed
|
| 295 |
+
|
| 296 |
+
🤗 Accelerate supports training on single/multiple GPUs using DeepSpeed. To use it, you don't need to change anything in your training code; you can set everything using just `accelerate config`. However, if you desire to tweak your DeepSpeed related args from your Python script, we provide you the `DeepSpeedPlugin`.
|
| 297 |
+
|
| 298 |
+
```python
|
| 299 |
+
from accelerate import Accelerator, DeepSpeedPlugin
|
| 300 |
+
|
| 301 |
+
# deepspeed needs to know your gradient accumulation steps beforehand, so don't forget to pass it
|
| 302 |
+
# Remember you still need to do gradient accumulation by yourself, just like you would have done without deepspeed
|
| 303 |
+
deepspeed_plugin = DeepSpeedPlugin(zero_stage=2, gradient_accumulation_steps=2)
|
| 304 |
+
accelerator = Accelerator(mixed_precision='fp16', deepspeed_plugin=deepspeed_plugin)
|
| 305 |
+
|
| 306 |
+
# How to save your 🤗 Transformer?
|
| 307 |
+
accelerator.wait_for_everyone()
|
| 308 |
+
unwrapped_model = accelerator.unwrap_model(model)
|
| 309 |
+
unwrapped_model.save_pretrained(save_dir, save_function=accelerator.save, state_dict=accelerator.get_state_dict(model))
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
Note: DeepSpeed support is experimental for now. In case you get into some problem, please open an issue.
|
| 313 |
+
|
| 314 |
+
## Launching your training from a notebook
|
| 315 |
+
|
| 316 |
+
🤗 Accelerate also provides a `notebook_launcher` function you can use in a notebook to launch a distributed training. This is especially useful for Colab or Kaggle notebooks with a TPU backend. Just define your training loop in a `training_function` then in your last cell, add:
|
| 317 |
+
|
| 318 |
+
```python
|
| 319 |
+
from accelerate import notebook_launcher
|
| 320 |
+
|
| 321 |
+
notebook_launcher(training_function)
|
| 322 |
+
```
|
| 323 |
+
|
| 324 |
+
An example can be found in [this notebook](https://github.com/huggingface/notebooks/blob/main/examples/accelerate_examples/simple_nlp_example.ipynb). [](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/accelerate_examples/simple_nlp_example.ipynb)
|
| 325 |
+
|
| 326 |
+
## Why should I use 🤗 Accelerate?
|
| 327 |
+
|
| 328 |
+
You should use 🤗 Accelerate when you want to easily run your training scripts in a distributed environment without having to renounce full control over your training loop. This is not a high-level framework above PyTorch, just a thin wrapper so you don't have to learn a new library. In fact, the whole API of 🤗 Accelerate is in one class, the `Accelerator` object.
|
| 329 |
+
|
| 330 |
+
## Why shouldn't I use 🤗 Accelerate?
|
| 331 |
+
|
| 332 |
+
You shouldn't use 🤗 Accelerate if you don't want to write a training loop yourself. There are plenty of high-level libraries above PyTorch that will offer you that, 🤗 Accelerate is not one of them.
|
| 333 |
+
|
| 334 |
+
## Frameworks using 🤗 Accelerate
|
| 335 |
+
|
| 336 |
+
If you like the simplicity of 🤗 Accelerate but would prefer a higher-level abstraction around its capabilities, some frameworks and libraries that are built on top of 🤗 Accelerate are listed below:
|
| 337 |
+
|
| 338 |
+
* [Amphion](https://github.com/open-mmlab/Amphion) is a toolkit for Audio, Music, and Speech Generation. Its purpose is to support reproducible research and help junior researchers and engineers get started in the field of audio, music, and speech generation research and development.
|
| 339 |
+
* [Animus](https://github.com/Scitator/animus) is a minimalistic framework to run machine learning experiments. Animus highlights common "breakpoints" in ML experiments and provides a unified interface for them within [IExperiment](https://github.com/Scitator/animus/blob/main/animus/core.py#L76).
|
| 340 |
+
* [Catalyst](https://github.com/catalyst-team/catalyst#getting-started) is a PyTorch framework for Deep Learning Research and Development. It focuses on reproducibility, rapid experimentation, and codebase reuse so you can create something new rather than write yet another train loop. Catalyst provides a [Runner](https://catalyst-team.github.io/catalyst/api/core.html#runner) to connect all parts of the experiment: hardware backend, data transformations, model training, and inference logic.
|
| 341 |
+
* [fastai](https://github.com/fastai/fastai#installing) is a PyTorch framework for Deep Learning that simplifies training fast and accurate neural nets using modern best practices. fastai provides a [Learner](https://docs.fast.ai/learner.html#Learner) to handle the training, fine-tuning, and inference of deep learning algorithms.
|
| 342 |
+
* [Finetuner](https://github.com/jina-ai/finetuner) is a service that enables models to create higher-quality embeddings for semantic search, visual similarity search, cross-modal text<->image search, recommendation systems, clustering, duplication detection, anomaly detection, or other uses.
|
| 343 |
+
* [InvokeAI](https://github.com/invoke-ai/InvokeAI) is a creative engine for Stable Diffusion models, offering industry-leading WebUI, terminal usage support, and serves as the foundation for many commercial products.
|
| 344 |
+
* [Kornia](https://kornia.readthedocs.io/en/latest/get-started/introduction.html) is a differentiable library that allows classical computer vision to be integrated into deep learning models. Kornia provides a [Trainer](https://kornia.readthedocs.io/en/latest/x.html#kornia.x.Trainer) with the specific purpose to train and fine-tune the supported deep learning algorithms within the library.
|
| 345 |
+
* [Open Assistant](https://projects.laion.ai/Open-Assistant/) is a chat-based assistant that understands tasks, can interact with their party systems, and retrieve information dynamically to do so.
|
| 346 |
+
* [pytorch-accelerated](https://github.com/Chris-hughes10/pytorch-accelerated) is a lightweight training library, with a streamlined feature set centered around a general-purpose [Trainer](https://pytorch-accelerated.readthedocs.io/en/latest/trainer.html), that places a huge emphasis on simplicity and transparency; enabling users to understand exactly what is going on under the hood, but without having to write and maintain the boilerplate themselves!
|
| 347 |
+
* [Stable Diffusion web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) is an open-source browser-based easy-to-use interface based on the Gradio library for Stable Diffusion.
|
| 348 |
+
* [torchkeras](https://github.com/lyhue1991/torchkeras) is a simple tool for training pytorch model just in a keras style, a dynamic and beautiful plot is provided in notebook to monitor your loss or metric.
|
| 349 |
+
* [transformers](https://github.com/huggingface/transformers) as a tool for helping train state-of-the-art machine learning models in PyTorch, Tensorflow, and JAX. (Accelerate is the backend for the PyTorch side).
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
## Installation
|
| 353 |
+
|
| 354 |
+
This repository is tested on Python 3.8+ and PyTorch 1.10.0+
|
| 355 |
+
|
| 356 |
+
You should install 🤗 Accelerate in a [virtual environment](https://docs.python.org/3/library/venv.html). If you're unfamiliar with Python virtual environments, check out the [user guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/).
|
| 357 |
+
|
| 358 |
+
First, create a virtual environment with the version of Python you're going to use and activate it.
|
| 359 |
+
|
| 360 |
+
Then, you will need to install PyTorch: refer to the [official installation page](https://pytorch.org/get-started/locally/#start-locally) regarding the specific install command for your platform. Then 🤗 Accelerate can be installed using pip as follows:
|
| 361 |
+
|
| 362 |
+
```bash
|
| 363 |
+
pip install accelerate
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
## Supported integrations
|
| 367 |
+
|
| 368 |
+
- CPU only
|
| 369 |
+
- multi-CPU on one node (machine)
|
| 370 |
+
- multi-CPU on several nodes (machines)
|
| 371 |
+
- single GPU
|
| 372 |
+
- multi-GPU on one node (machine)
|
| 373 |
+
- multi-GPU on several nodes (machines)
|
| 374 |
+
- TPU
|
| 375 |
+
- FP16/BFloat16 mixed precision
|
| 376 |
+
- FP8 mixed precision with [Transformer Engine](https://github.com/NVIDIA/TransformerEngine) or [MS-AMP](https://github.com/Azure/MS-AMP/)
|
| 377 |
+
- DeepSpeed support (Experimental)
|
| 378 |
+
- PyTorch Fully Sharded Data Parallel (FSDP) support (Experimental)
|
| 379 |
+
- Megatron-LM support (Experimental)
|
| 380 |
+
|
| 381 |
+
## Citing 🤗 Accelerate
|
| 382 |
+
|
| 383 |
+
If you use 🤗 Accelerate in your publication, please cite it by using the following BibTeX entry.
|
| 384 |
+
|
| 385 |
+
```bibtex
|
| 386 |
+
@Misc{accelerate,
|
| 387 |
+
title = {Accelerate: Training and inference at scale made simple, efficient and adaptable.},
|
| 388 |
+
author = {Sylvain Gugger and Lysandre Debut and Thomas Wolf and Philipp Schmid and Zachary Mueller and Sourab Mangrulkar and Marc Sun and Benjamin Bossan},
|
| 389 |
+
howpublished = {\url{https://github.com/huggingface/accelerate}},
|
| 390 |
+
year = {2022}
|
| 391 |
+
}
|
| 392 |
+
```
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
| 1 |
+
../../../bin/accelerate,sha256=xcOI514u92SqR44hsSewrxTXVy4CHcW0d0xn2IzhN9Q,295
|
| 2 |
+
../../../bin/accelerate-config,sha256=dV2JpgWmnysNdehUJcVKkH0mCNpEm902s3ZAmO7vJk8,287
|
| 3 |
+
../../../bin/accelerate-estimate-memory,sha256=oKW4cJGG_StYZQMpVmFStOsiPoPd8ClS3-JOKAQgZvA,289
|
| 4 |
+
../../../bin/accelerate-launch,sha256=6LbJS4l0anZFnS0GrfCAE_rJye0Q_KitNu04X9wzjaA,287
|
| 5 |
+
../../../bin/accelerate-merge-weights,sha256=0qIe_phL9sps5b-H19CIlcAq-6XnoYq94-kQW4p7cd8,286
|
| 6 |
+
accelerate-1.12.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 7 |
+
accelerate-1.12.0.dist-info/METADATA,sha256=MdiA4qoer_tQ3-y2K8gdU_AmLtGf83Tn_3p2tBuHxrg,19601
|
| 8 |
+
accelerate-1.12.0.dist-info/RECORD,,
|
| 9 |
+
accelerate-1.12.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 10 |
+
accelerate-1.12.0.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
|
| 11 |
+
accelerate-1.12.0.dist-info/entry_points.txt,sha256=Vpy8gUGfZ-1VnM2229fb8CpJNLBdMH_wtJ9PQ7b_2tQ,296
|
| 12 |
+
accelerate-1.12.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
| 13 |
+
accelerate-1.12.0.dist-info/top_level.txt,sha256=esVfdxTidsjQ90zsN_rPpjLFJ4ijRlx4mnLrG09hlt4,11
|
| 14 |
+
accelerate/__init__.py,sha256=DaZo-ztl0IEKqEtBjUz2jLT-qRQCXr6z8kLOlA1u-rM,1555
|
| 15 |
+
accelerate/__pycache__/__init__.cpython-312.pyc,,
|
| 16 |
+
accelerate/__pycache__/accelerator.cpython-312.pyc,,
|
| 17 |
+
accelerate/__pycache__/big_modeling.cpython-312.pyc,,
|
| 18 |
+
accelerate/__pycache__/checkpointing.cpython-312.pyc,,
|
| 19 |
+
accelerate/__pycache__/data_loader.cpython-312.pyc,,
|
| 20 |
+
accelerate/__pycache__/hooks.cpython-312.pyc,,
|
| 21 |
+
accelerate/__pycache__/inference.cpython-312.pyc,,
|
| 22 |
+
accelerate/__pycache__/launchers.cpython-312.pyc,,
|
| 23 |
+
accelerate/__pycache__/local_sgd.cpython-312.pyc,,
|
| 24 |
+
accelerate/__pycache__/logging.cpython-312.pyc,,
|
| 25 |
+
accelerate/__pycache__/memory_utils.cpython-312.pyc,,
|
| 26 |
+
accelerate/__pycache__/optimizer.cpython-312.pyc,,
|
| 27 |
+
accelerate/__pycache__/parallelism_config.cpython-312.pyc,,
|
| 28 |
+
accelerate/__pycache__/scheduler.cpython-312.pyc,,
|
| 29 |
+
accelerate/__pycache__/state.cpython-312.pyc,,
|
| 30 |
+
accelerate/__pycache__/tracking.cpython-312.pyc,,
|
| 31 |
+
accelerate/accelerator.py,sha256=is2XY1TGZ7hYphz_CLqq7diNvvd1702ju4jJMns939c,197200
|
| 32 |
+
accelerate/big_modeling.py,sha256=s434XS4IHvidURez-iOKApy5V1DkYmhstHSr3LaB6lo,36931
|
| 33 |
+
accelerate/checkpointing.py,sha256=clOiZp0pLht2Rtkjp2UFUSOdow3hVrG8Po8xXtIXqY0,13995
|
| 34 |
+
accelerate/commands/__init__.py,sha256=m1PPTDT4ziIAvM0-FDSgIMIZ69Konn126s6LwuzH6v8,606
|
| 35 |
+
accelerate/commands/__pycache__/__init__.cpython-312.pyc,,
|
| 36 |
+
accelerate/commands/__pycache__/accelerate_cli.cpython-312.pyc,,
|
| 37 |
+
accelerate/commands/__pycache__/env.cpython-312.pyc,,
|
| 38 |
+
accelerate/commands/__pycache__/estimate.cpython-312.pyc,,
|
| 39 |
+
accelerate/commands/__pycache__/launch.cpython-312.pyc,,
|
| 40 |
+
accelerate/commands/__pycache__/merge.cpython-312.pyc,,
|
| 41 |
+
accelerate/commands/__pycache__/test.cpython-312.pyc,,
|
| 42 |
+
accelerate/commands/__pycache__/to_fsdp2.cpython-312.pyc,,
|
| 43 |
+
accelerate/commands/__pycache__/tpu.cpython-312.pyc,,
|
| 44 |
+
accelerate/commands/__pycache__/utils.cpython-312.pyc,,
|
| 45 |
+
accelerate/commands/accelerate_cli.py,sha256=SkwFad6Z1ZsGjtm7TiXFq8je-akshp_0WxX_6rGSBw8,1972
|
| 46 |
+
accelerate/commands/config/__init__.py,sha256=iJK8dgj3pc5Vdr1E7UuGoFu-BlybyXLxYDoTg9gXngE,1645
|
| 47 |
+
accelerate/commands/config/__pycache__/__init__.cpython-312.pyc,,
|
| 48 |
+
accelerate/commands/config/__pycache__/cluster.cpython-312.pyc,,
|
| 49 |
+
accelerate/commands/config/__pycache__/config.cpython-312.pyc,,
|
| 50 |
+
accelerate/commands/config/__pycache__/config_args.cpython-312.pyc,,
|
| 51 |
+
accelerate/commands/config/__pycache__/config_utils.cpython-312.pyc,,
|
| 52 |
+
accelerate/commands/config/__pycache__/default.cpython-312.pyc,,
|
| 53 |
+
accelerate/commands/config/__pycache__/sagemaker.cpython-312.pyc,,
|
| 54 |
+
accelerate/commands/config/__pycache__/update.cpython-312.pyc,,
|
| 55 |
+
accelerate/commands/config/cluster.py,sha256=aHlkL4o2BH3h2w5RCL3IUCKH37fvl9vGWx01up_ltvE,39376
|
| 56 |
+
accelerate/commands/config/config.py,sha256=FuRlQvOjgATEtyqOSsGD-KEtOCvACOHjs2C-krrtldk,3035
|
| 57 |
+
accelerate/commands/config/config_args.py,sha256=b-_GLJKM2_7w84Zjf6PSWV5is-VUHmG0KVE8XeWupBU,10275
|
| 58 |
+
accelerate/commands/config/config_utils.py,sha256=lbV9iKAVSF5bUyQDGpzFduhH5JENYgAilPpRLLlCEq8,3299
|
| 59 |
+
accelerate/commands/config/default.py,sha256=UY0dQ7w1peBkQe8QDCm3XJrTnsRcm_G-_hf44NzNAbU,6213
|
| 60 |
+
accelerate/commands/config/sagemaker.py,sha256=SRLup9XrV_Z-23A3d8gZbkqbonDcscMDDmbpmytCzbY,10636
|
| 61 |
+
accelerate/commands/config/update.py,sha256=0Et2qKKgoeisVQixsJKSqp4dLzSofbZ2jXmAPgJP-DQ,2396
|
| 62 |
+
accelerate/commands/env.py,sha256=gRGwtPhMMWmZ5NTMaMrgHXaOzBV6SvAtP78TuuJvC6g,4336
|
| 63 |
+
accelerate/commands/estimate.py,sha256=4lpX89bh7PmWlhM9uh5LkTGazplZZAWn2v7VvbHOF3k,12650
|
| 64 |
+
accelerate/commands/launch.py,sha256=nw33odiozF6V5lQYBWFPLWdAf9wlN6StJ-LU6-kKhmo,50197
|
| 65 |
+
accelerate/commands/menu/__init__.py,sha256=uqSlBM0TFHBwzdv3p3SXfpAk1lZFp4h1a7mbBdscPHs,645
|
| 66 |
+
accelerate/commands/menu/__pycache__/__init__.cpython-312.pyc,,
|
| 67 |
+
accelerate/commands/menu/__pycache__/cursor.cpython-312.pyc,,
|
| 68 |
+
accelerate/commands/menu/__pycache__/helpers.cpython-312.pyc,,
|
| 69 |
+
accelerate/commands/menu/__pycache__/input.cpython-312.pyc,,
|
| 70 |
+
accelerate/commands/menu/__pycache__/keymap.cpython-312.pyc,,
|
| 71 |
+
accelerate/commands/menu/__pycache__/selection_menu.cpython-312.pyc,,
|
| 72 |
+
accelerate/commands/menu/cursor.py,sha256=-lmpJVAzvNc0c3EOtSuLoKB59zqylVCbYyWLPnrOmvQ,2028
|
| 73 |
+
accelerate/commands/menu/helpers.py,sha256=KrSB5fJjH4MUEUAQJ6bYaN16AYcnl9UalDrPD3DYeeg,1483
|
| 74 |
+
accelerate/commands/menu/input.py,sha256=T8Mdd-Y_OURgqfDV9qZh4Wf6hmT22AneNtJzj4JA1Rk,2512
|
| 75 |
+
accelerate/commands/menu/keymap.py,sha256=eXj-suyYs1m5dEHoUKN4mKAMLc8DWHnwhP6G6JSU0jQ,4086
|
| 76 |
+
accelerate/commands/menu/selection_menu.py,sha256=iylPHUmEemEhn6gwidbgdTGOrCJiR3Il1EjqiYbnues,4959
|
| 77 |
+
accelerate/commands/merge.py,sha256=3Uo14LADvk8RJwZ_i6kIsGwWB3Ul5y8Uq47oHkDYqKU,2387
|
| 78 |
+
accelerate/commands/test.py,sha256=YrPYEaAACOGZ6btn2MV6NbMSEdBUcMWADLbQWaZSHtk,2149
|
| 79 |
+
accelerate/commands/to_fsdp2.py,sha256=TWGc7mC4rzjQmFp2mwUEUiidrPWP9PLdM0Ipm0oEF8o,5992
|
| 80 |
+
accelerate/commands/tpu.py,sha256=KyxDP7IuveidZrbW4rx2s8Ku3o_ptI6tzwr_R7ck0os,5548
|
| 81 |
+
accelerate/commands/utils.py,sha256=aT8xUCe2pCkFII7yZxcfaohEjgBAzMUM7WiD4UuWSOY,4150
|
| 82 |
+
accelerate/data_loader.py,sha256=jev7IMauWO_zpGbP1nJEoSzIuNPeADFqbB1UsDEO5so,65614
|
| 83 |
+
accelerate/hooks.py,sha256=GEGP0GNpkcdcyrqpXTjezMcILLNO7TCABOCAr9fKgO0,33855
|
| 84 |
+
accelerate/inference.py,sha256=8M1LRCfXSstOUhS8O6UlCipQ14cTQgvAqWqDXQEQn50,7684
|
| 85 |
+
accelerate/launchers.py,sha256=Jyini7mmqFo7JV7BodkFzQA3pkbnhEdZR33nKzaYqHE,14168
|
| 86 |
+
accelerate/local_sgd.py,sha256=Xtn5_XbUg9KgsRExHyrEpXo-q0_58lvT036eNroT7m4,4176
|
| 87 |
+
accelerate/logging.py,sha256=rpXi7zO4cKnt72cc_R3WS2xPyL_gZWzd_0vWBp2hTac,5080
|
| 88 |
+
accelerate/memory_utils.py,sha256=3R5LoeHl6GgTZ-IMPrDZMdaEehWarGdPqODushb-6pg,862
|
| 89 |
+
accelerate/optimizer.py,sha256=p5qfCOMi8DAjvx6eECypo4ej3pvmQ_U_bgmrEAKc4hY,8158
|
| 90 |
+
accelerate/parallelism_config.py,sha256=RTxa-aNvD4_Vxds-X1CadIwm1AJ90ATNn72kPd79Eug,15906
|
| 91 |
+
accelerate/scheduler.py,sha256=des_4M_Tt1W8gCYZZbLla0GHBEgJY3Wx2EGBQPTzeiY,4238
|
| 92 |
+
accelerate/state.py,sha256=pIOUfXT2Q3Bj2Sd4t1nGB26axuzCnf7HYwDZIgHx8PA,58300
|
| 93 |
+
accelerate/test_utils/__init__.py,sha256=E347JKLya-_vi4IbWhdsAVQ0FCudtcaD7ErX2bh6RC0,1826
|
| 94 |
+
accelerate/test_utils/__pycache__/__init__.cpython-312.pyc,,
|
| 95 |
+
accelerate/test_utils/__pycache__/examples.cpython-312.pyc,,
|
| 96 |
+
accelerate/test_utils/__pycache__/testing.cpython-312.pyc,,
|
| 97 |
+
accelerate/test_utils/__pycache__/training.cpython-312.pyc,,
|
| 98 |
+
accelerate/test_utils/examples.py,sha256=kSXJrx6OhUghHGzqLnCwqdsDUufMjmB2DPQyQSfZHvQ,7301
|
| 99 |
+
accelerate/test_utils/scripts/__init__.py,sha256=m1PPTDT4ziIAvM0-FDSgIMIZ69Konn126s6LwuzH6v8,606
|
| 100 |
+
accelerate/test_utils/scripts/__pycache__/__init__.cpython-312.pyc,,
|
| 101 |
+
accelerate/test_utils/scripts/__pycache__/test_cli.cpython-312.pyc,,
|
| 102 |
+
accelerate/test_utils/scripts/__pycache__/test_ddp_comm_hook.cpython-312.pyc,,
|
| 103 |
+
accelerate/test_utils/scripts/__pycache__/test_distributed_data_loop.cpython-312.pyc,,
|
| 104 |
+
accelerate/test_utils/scripts/__pycache__/test_merge_weights.cpython-312.pyc,,
|
| 105 |
+
accelerate/test_utils/scripts/__pycache__/test_notebook.cpython-312.pyc,,
|
| 106 |
+
accelerate/test_utils/scripts/__pycache__/test_ops.cpython-312.pyc,,
|
| 107 |
+
accelerate/test_utils/scripts/__pycache__/test_script.cpython-312.pyc,,
|
| 108 |
+
accelerate/test_utils/scripts/__pycache__/test_sync.cpython-312.pyc,,
|
| 109 |
+
accelerate/test_utils/scripts/external_deps/__init__.py,sha256=m1PPTDT4ziIAvM0-FDSgIMIZ69Konn126s6LwuzH6v8,606
|
| 110 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/__init__.cpython-312.pyc,,
|
| 111 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_checkpointing.cpython-312.pyc,,
|
| 112 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_ds_alst_ulysses_sp.cpython-312.pyc,,
|
| 113 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_ds_multiple_model.cpython-312.pyc,,
|
| 114 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_metrics.cpython-312.pyc,,
|
| 115 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_peak_memory_usage.cpython-312.pyc,,
|
| 116 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_performance.cpython-312.pyc,,
|
| 117 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_pippy.cpython-312.pyc,,
|
| 118 |
+
accelerate/test_utils/scripts/external_deps/__pycache__/test_zero3_integration.cpython-312.pyc,,
|
| 119 |
+
accelerate/test_utils/scripts/external_deps/test_checkpointing.py,sha256=XHaNRmnrARd1izXFjWGi5UjYGas-4vqayW51jAHBPCA,10699
|
| 120 |
+
accelerate/test_utils/scripts/external_deps/test_ds_alst_ulysses_sp.py,sha256=wPg4iEhvwx8-2eNzOdC3HhdCilmG3rPAUUob5-BheSA,4047
|
| 121 |
+
accelerate/test_utils/scripts/external_deps/test_ds_multiple_model.py,sha256=hEfb6woEUHBpvMa8cHa-P5MJ2yMi_89ABA45q05P0u4,13765
|
| 122 |
+
accelerate/test_utils/scripts/external_deps/test_metrics.py,sha256=Ev2XKaiwmznoxKujskAAuISGChW646MOiyf0CXEPb9Y,12168
|
| 123 |
+
accelerate/test_utils/scripts/external_deps/test_peak_memory_usage.py,sha256=jlKq-kwd5mQE71k0dGO_Xk61dCen1Qw9Z7deulq8N-4,12495
|
| 124 |
+
accelerate/test_utils/scripts/external_deps/test_performance.py,sha256=y77O2Y9JpcDeP2IBhT0k0FgxrdcYIn68zMPCl7qfo8g,11749
|
| 125 |
+
accelerate/test_utils/scripts/external_deps/test_pippy.py,sha256=rYF5bqSCe_pfylxDv2_2Q7S2mHIb9_6fGns-IcLgE_E,4789
|
| 126 |
+
accelerate/test_utils/scripts/external_deps/test_zero3_integration.py,sha256=-fc3l3PSAplU82FLaeIWCAJdAVBsT72vBQpdJfZ2Hsw,1666
|
| 127 |
+
accelerate/test_utils/scripts/test_cli.py,sha256=-p78NTJgKdeTNDqyrQuGEZZqMpnzdUHPyWZ05FMl5EI,1081
|
| 128 |
+
accelerate/test_utils/scripts/test_ddp_comm_hook.py,sha256=k_-2MBjLKNdMGIcneTbuGd84K05Wp1GEQX6DUVF9UBw,3566
|
| 129 |
+
accelerate/test_utils/scripts/test_distributed_data_loop.py,sha256=RUWTwd7DIpr2fl7JtKOsvTjMiJioTxO8FdSr2Lw_5uI,15137
|
| 130 |
+
accelerate/test_utils/scripts/test_merge_weights.py,sha256=r1oqPOMOqLe5zWenWWTyl9cDbbkFJadpNNiPNBlgR18,5982
|
| 131 |
+
accelerate/test_utils/scripts/test_notebook.py,sha256=qfIy3IvH74-kGn8nadBn_k7qrviqvsxy5ijsnUhuY6o,3894
|
| 132 |
+
accelerate/test_utils/scripts/test_ops.py,sha256=k817w-6h54F1OCIrsarAu8XieWM3H8oZV7bvK-4aJ5k,6268
|
| 133 |
+
accelerate/test_utils/scripts/test_script.py,sha256=dj9zhBhIWHvZ7YSQImzy5B6lWWnV0kAnpENk-k1JkpQ,36259
|
| 134 |
+
accelerate/test_utils/scripts/test_sync.py,sha256=PDe8sYZLCL2LKjj_L9b-Bh2BjAjeii9EZ8sZNfuYx5s,18817
|
| 135 |
+
accelerate/test_utils/testing.py,sha256=0qf5qqTlnzaDqBuJkT4juq5yC1kZgbjRNUUqavbhuPA,30165
|
| 136 |
+
accelerate/test_utils/training.py,sha256=Xn1fIeBUa6QR7SBv_j-JOGL9e3Nl4IZrbtFLL-Zfy6k,5935
|
| 137 |
+
accelerate/tracking.py,sha256=TBIaw_-dyZkA13q-C4GxYF2TFyQHE4ObhQfv6IQQNBE,51520
|
| 138 |
+
accelerate/utils/__init__.py,sha256=iDbm951P44B1BxiH63Tk4MH9yaK4YmyZZp-A1qxdVAE,8252
|
| 139 |
+
accelerate/utils/__pycache__/__init__.cpython-312.pyc,,
|
| 140 |
+
accelerate/utils/__pycache__/ao.cpython-312.pyc,,
|
| 141 |
+
accelerate/utils/__pycache__/bnb.cpython-312.pyc,,
|
| 142 |
+
accelerate/utils/__pycache__/constants.cpython-312.pyc,,
|
| 143 |
+
accelerate/utils/__pycache__/dataclasses.cpython-312.pyc,,
|
| 144 |
+
accelerate/utils/__pycache__/deepspeed.cpython-312.pyc,,
|
| 145 |
+
accelerate/utils/__pycache__/environment.cpython-312.pyc,,
|
| 146 |
+
accelerate/utils/__pycache__/fsdp_utils.cpython-312.pyc,,
|
| 147 |
+
accelerate/utils/__pycache__/imports.cpython-312.pyc,,
|
| 148 |
+
accelerate/utils/__pycache__/launch.cpython-312.pyc,,
|
| 149 |
+
accelerate/utils/__pycache__/megatron_lm.cpython-312.pyc,,
|
| 150 |
+
accelerate/utils/__pycache__/memory.cpython-312.pyc,,
|
| 151 |
+
accelerate/utils/__pycache__/modeling.cpython-312.pyc,,
|
| 152 |
+
accelerate/utils/__pycache__/offload.cpython-312.pyc,,
|
| 153 |
+
accelerate/utils/__pycache__/operations.cpython-312.pyc,,
|
| 154 |
+
accelerate/utils/__pycache__/other.cpython-312.pyc,,
|
| 155 |
+
accelerate/utils/__pycache__/random.cpython-312.pyc,,
|
| 156 |
+
accelerate/utils/__pycache__/rich.cpython-312.pyc,,
|
| 157 |
+
accelerate/utils/__pycache__/torch_xla.cpython-312.pyc,,
|
| 158 |
+
accelerate/utils/__pycache__/tqdm.cpython-312.pyc,,
|
| 159 |
+
accelerate/utils/__pycache__/transformer_engine.cpython-312.pyc,,
|
| 160 |
+
accelerate/utils/__pycache__/versions.cpython-312.pyc,,
|
| 161 |
+
accelerate/utils/ao.py,sha256=yfi84ywNpXsKZ6di4jbmtd6bIvRi9bmygr3giN92_Pg,4777
|
| 162 |
+
accelerate/utils/bnb.py,sha256=mlkellhznuPnlJLnv-dLFsWRWaZi_LkY0a609R7SssU,20660
|
| 163 |
+
accelerate/utils/constants.py,sha256=uVgDWPYJSvjDVpOcoMFhlCAxL1va2ywRorzTrEX6F5M,3608
|
| 164 |
+
accelerate/utils/dataclasses.py,sha256=b22xAYwb5xQ240uuxLSO863ZG-gFaohMsDJXbdhn6Q0,139788
|
| 165 |
+
accelerate/utils/deepspeed.py,sha256=gt-jwOpOtRs6N4sohuSO2I3x1qLoO6uYYjnPrKp6Zk4,14796
|
| 166 |
+
accelerate/utils/environment.py,sha256=7HhYDNMsLRPjPwqHKcgAScF2bwckGPztltFFOgQzoRs,16964
|
| 167 |
+
accelerate/utils/fsdp_utils.py,sha256=az6HwVlRVVihV5Wrv4gD2d_92-O-L7ymREmD7mumYo0,38174
|
| 168 |
+
accelerate/utils/imports.py,sha256=A7AOE2zlIXrBy3gfq_cL_4I-9B0P4zeuNOwiDtbD1e0,17166
|
| 169 |
+
accelerate/utils/launch.py,sha256=iVgz5y52gx_8j1Y8yWy2LhIKDBEZMz_ZJNb0W0ICP0Q,35225
|
| 170 |
+
accelerate/utils/megatron_lm.py,sha256=SOze6fUn1T_mPbtwGJSmBDGz87AmgUFRqCZxHuhC5YA,58055
|
| 171 |
+
accelerate/utils/memory.py,sha256=5GtoWvi8H4k8edIHk95Qxy98hFYjbCHh4dN4Iqhc38Q,7270
|
| 172 |
+
accelerate/utils/modeling.py,sha256=QhqI-6JdalB5H7VOpS5-79O-tnjRoTEFUXbAmofoINY,95544
|
| 173 |
+
accelerate/utils/offload.py,sha256=N6ATpOZph7gGrZUjriicD7F6oIhZvmJND66jRyy1nlw,7845
|
| 174 |
+
accelerate/utils/operations.py,sha256=GJ6D10DlgVOhrTvSrdv6zq37dzTBNyVZSyUJI3Og2T8,31301
|
| 175 |
+
accelerate/utils/other.py,sha256=ZttbLr-YsGvI2GXLAQH0DhRimh1MQl5dqqhLfi4ShZw,20321
|
| 176 |
+
accelerate/utils/random.py,sha256=Xv_ZJm9eaC2Q7rgZy9OpOunKuTingMiDQCH00qhNVxE,6220
|
| 177 |
+
accelerate/utils/rich.py,sha256=8JZX_uGMQX-BufdXxJpdne7BWd1KyLHSgbiGxrDMYr8,847
|
| 178 |
+
accelerate/utils/torch_xla.py,sha256=Pq1tuqN0X_pWDVza6YgjfO45uoJdoRVRForLeLQzFus,1908
|
| 179 |
+
accelerate/utils/tqdm.py,sha256=k8e9JnieTEQHCCNBaiBys7hPxWlEbyRASdIma-qy_X8,1657
|
| 180 |
+
accelerate/utils/transformer_engine.py,sha256=sVh7oqQL2LepdzAFPHxs2a8VtgukTFbvaNxzLlaq2mo,7521
|
| 181 |
+
accelerate/utils/versions.py,sha256=UgmcbjBm--6CIx1ZamSAMjAK_B_2l48LbeaNygqej8M,2149
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/REQUESTED
ADDED
|
File without changes
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (78.1.1)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
accelerate = accelerate.commands.accelerate_cli:main
|
| 3 |
+
accelerate-config = accelerate.commands.config:main
|
| 4 |
+
accelerate-estimate-memory = accelerate.commands.estimate:main
|
| 5 |
+
accelerate-launch = accelerate.commands.launch:main
|
| 6 |
+
accelerate-merge-weights = accelerate.commands.merge:main
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/accelerate-1.12.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
accelerate
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2018 Alex Grönholm
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
the Software without restriction, including without limitation the rights to
|
| 8 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: anyio
|
| 3 |
+
Version: 4.8.0
|
| 4 |
+
Summary: High level compatibility layer for multiple asynchronous event loop implementations
|
| 5 |
+
Author-email: Alex Grönholm <alex.gronholm@nextday.fi>
|
| 6 |
+
License: MIT
|
| 7 |
+
Project-URL: Documentation, https://anyio.readthedocs.io/en/latest/
|
| 8 |
+
Project-URL: Changelog, https://anyio.readthedocs.io/en/stable/versionhistory.html
|
| 9 |
+
Project-URL: Source code, https://github.com/agronholm/anyio
|
| 10 |
+
Project-URL: Issue tracker, https://github.com/agronholm/anyio/issues
|
| 11 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 12 |
+
Classifier: Intended Audience :: Developers
|
| 13 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 14 |
+
Classifier: Framework :: AnyIO
|
| 15 |
+
Classifier: Typing :: Typed
|
| 16 |
+
Classifier: Programming Language :: Python
|
| 17 |
+
Classifier: Programming Language :: Python :: 3
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 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 |
+
Requires-Python: >=3.9
|
| 24 |
+
Description-Content-Type: text/x-rst
|
| 25 |
+
License-File: LICENSE
|
| 26 |
+
Requires-Dist: exceptiongroup>=1.0.2; python_version < "3.11"
|
| 27 |
+
Requires-Dist: idna>=2.8
|
| 28 |
+
Requires-Dist: sniffio>=1.1
|
| 29 |
+
Requires-Dist: typing_extensions>=4.5; python_version < "3.13"
|
| 30 |
+
Provides-Extra: trio
|
| 31 |
+
Requires-Dist: trio>=0.26.1; extra == "trio"
|
| 32 |
+
Provides-Extra: test
|
| 33 |
+
Requires-Dist: anyio[trio]; extra == "test"
|
| 34 |
+
Requires-Dist: coverage[toml]>=7; extra == "test"
|
| 35 |
+
Requires-Dist: exceptiongroup>=1.2.0; extra == "test"
|
| 36 |
+
Requires-Dist: hypothesis>=4.0; extra == "test"
|
| 37 |
+
Requires-Dist: psutil>=5.9; extra == "test"
|
| 38 |
+
Requires-Dist: pytest>=7.0; extra == "test"
|
| 39 |
+
Requires-Dist: trustme; extra == "test"
|
| 40 |
+
Requires-Dist: truststore>=0.9.1; python_version >= "3.10" and extra == "test"
|
| 41 |
+
Requires-Dist: uvloop>=0.21; (platform_python_implementation == "CPython" and platform_system != "Windows" and python_version < "3.14") and extra == "test"
|
| 42 |
+
Provides-Extra: doc
|
| 43 |
+
Requires-Dist: packaging; extra == "doc"
|
| 44 |
+
Requires-Dist: Sphinx~=7.4; extra == "doc"
|
| 45 |
+
Requires-Dist: sphinx_rtd_theme; extra == "doc"
|
| 46 |
+
Requires-Dist: sphinx-autodoc-typehints>=1.2.0; extra == "doc"
|
| 47 |
+
|
| 48 |
+
.. image:: https://github.com/agronholm/anyio/actions/workflows/test.yml/badge.svg
|
| 49 |
+
:target: https://github.com/agronholm/anyio/actions/workflows/test.yml
|
| 50 |
+
:alt: Build Status
|
| 51 |
+
.. image:: https://coveralls.io/repos/github/agronholm/anyio/badge.svg?branch=master
|
| 52 |
+
:target: https://coveralls.io/github/agronholm/anyio?branch=master
|
| 53 |
+
:alt: Code Coverage
|
| 54 |
+
.. image:: https://readthedocs.org/projects/anyio/badge/?version=latest
|
| 55 |
+
:target: https://anyio.readthedocs.io/en/latest/?badge=latest
|
| 56 |
+
:alt: Documentation
|
| 57 |
+
.. image:: https://badges.gitter.im/gitterHQ/gitter.svg
|
| 58 |
+
:target: https://gitter.im/python-trio/AnyIO
|
| 59 |
+
:alt: Gitter chat
|
| 60 |
+
|
| 61 |
+
AnyIO is an asynchronous networking and concurrency library that works on top of either asyncio_ or
|
| 62 |
+
trio_. It implements trio-like `structured concurrency`_ (SC) on top of asyncio and works in harmony
|
| 63 |
+
with the native SC of trio itself.
|
| 64 |
+
|
| 65 |
+
Applications and libraries written against AnyIO's API will run unmodified on either asyncio_ or
|
| 66 |
+
trio_. AnyIO can also be adopted into a library or application incrementally – bit by bit, no full
|
| 67 |
+
refactoring necessary. It will blend in with the native libraries of your chosen backend.
|
| 68 |
+
|
| 69 |
+
Documentation
|
| 70 |
+
-------------
|
| 71 |
+
|
| 72 |
+
View full documentation at: https://anyio.readthedocs.io/
|
| 73 |
+
|
| 74 |
+
Features
|
| 75 |
+
--------
|
| 76 |
+
|
| 77 |
+
AnyIO offers the following functionality:
|
| 78 |
+
|
| 79 |
+
* Task groups (nurseries_ in trio terminology)
|
| 80 |
+
* High-level networking (TCP, UDP and UNIX sockets)
|
| 81 |
+
|
| 82 |
+
* `Happy eyeballs`_ algorithm for TCP connections (more robust than that of asyncio on Python
|
| 83 |
+
3.8)
|
| 84 |
+
* async/await style UDP sockets (unlike asyncio where you still have to use Transports and
|
| 85 |
+
Protocols)
|
| 86 |
+
|
| 87 |
+
* A versatile API for byte streams and object streams
|
| 88 |
+
* Inter-task synchronization and communication (locks, conditions, events, semaphores, object
|
| 89 |
+
streams)
|
| 90 |
+
* Worker threads
|
| 91 |
+
* Subprocesses
|
| 92 |
+
* Asynchronous file I/O (using worker threads)
|
| 93 |
+
* Signal handling
|
| 94 |
+
|
| 95 |
+
AnyIO also comes with its own pytest_ plugin which also supports asynchronous fixtures.
|
| 96 |
+
It even works with the popular Hypothesis_ library.
|
| 97 |
+
|
| 98 |
+
.. _asyncio: https://docs.python.org/3/library/asyncio.html
|
| 99 |
+
.. _trio: https://github.com/python-trio/trio
|
| 100 |
+
.. _structured concurrency: https://en.wikipedia.org/wiki/Structured_concurrency
|
| 101 |
+
.. _nurseries: https://trio.readthedocs.io/en/stable/reference-core.html#nurseries-and-spawning
|
| 102 |
+
.. _Happy eyeballs: https://en.wikipedia.org/wiki/Happy_Eyeballs
|
| 103 |
+
.. _pytest: https://docs.pytest.org/en/latest/
|
| 104 |
+
.. _Hypothesis: https://hypothesis.works/
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
anyio-4.8.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
anyio-4.8.0.dist-info/LICENSE,sha256=U2GsncWPLvX9LpsJxoKXwX8ElQkJu8gCO9uC6s8iwrA,1081
|
| 3 |
+
anyio-4.8.0.dist-info/METADATA,sha256=WjTz5zz2NgMStBtw4xDh8CDvf6YXgAOrA0nboFQkXEg,4630
|
| 4 |
+
anyio-4.8.0.dist-info/RECORD,,
|
| 5 |
+
anyio-4.8.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
| 6 |
+
anyio-4.8.0.dist-info/entry_points.txt,sha256=_d6Yu6uiaZmNe0CydowirE9Cmg7zUL2g08tQpoS3Qvc,39
|
| 7 |
+
anyio-4.8.0.dist-info/top_level.txt,sha256=QglSMiWX8_5dpoVAEIHdEYzvqFMdSYWmCj6tYw2ITkQ,6
|
| 8 |
+
anyio/__init__.py,sha256=mVsWuQ6wxcPT9QUAxhz1Rg2u53PskaBJw4TXVXk63ZQ,4513
|
| 9 |
+
anyio/__pycache__/__init__.cpython-312.pyc,,
|
| 10 |
+
anyio/__pycache__/from_thread.cpython-312.pyc,,
|
| 11 |
+
anyio/__pycache__/lowlevel.cpython-312.pyc,,
|
| 12 |
+
anyio/__pycache__/pytest_plugin.cpython-312.pyc,,
|
| 13 |
+
anyio/__pycache__/to_interpreter.cpython-312.pyc,,
|
| 14 |
+
anyio/__pycache__/to_process.cpython-312.pyc,,
|
| 15 |
+
anyio/__pycache__/to_thread.cpython-312.pyc,,
|
| 16 |
+
anyio/_backends/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 17 |
+
anyio/_backends/__pycache__/__init__.cpython-312.pyc,,
|
| 18 |
+
anyio/_backends/__pycache__/_asyncio.cpython-312.pyc,,
|
| 19 |
+
anyio/_backends/__pycache__/_trio.cpython-312.pyc,,
|
| 20 |
+
anyio/_backends/_asyncio.py,sha256=_6BDFDrEPI1aRPFDSPsUzyPGm-dnRgBPfEOdeCH1Ixg,92951
|
| 21 |
+
anyio/_backends/_trio.py,sha256=7PNO_GPq8Dmo1kQmmE2z57dhnv4TUoinsEHt_PJg3oE,40405
|
| 22 |
+
anyio/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 23 |
+
anyio/_core/__pycache__/__init__.cpython-312.pyc,,
|
| 24 |
+
anyio/_core/__pycache__/_asyncio_selector_thread.cpython-312.pyc,,
|
| 25 |
+
anyio/_core/__pycache__/_eventloop.cpython-312.pyc,,
|
| 26 |
+
anyio/_core/__pycache__/_exceptions.cpython-312.pyc,,
|
| 27 |
+
anyio/_core/__pycache__/_fileio.cpython-312.pyc,,
|
| 28 |
+
anyio/_core/__pycache__/_resources.cpython-312.pyc,,
|
| 29 |
+
anyio/_core/__pycache__/_signals.cpython-312.pyc,,
|
| 30 |
+
anyio/_core/__pycache__/_sockets.cpython-312.pyc,,
|
| 31 |
+
anyio/_core/__pycache__/_streams.cpython-312.pyc,,
|
| 32 |
+
anyio/_core/__pycache__/_subprocesses.cpython-312.pyc,,
|
| 33 |
+
anyio/_core/__pycache__/_synchronization.cpython-312.pyc,,
|
| 34 |
+
anyio/_core/__pycache__/_tasks.cpython-312.pyc,,
|
| 35 |
+
anyio/_core/__pycache__/_testing.cpython-312.pyc,,
|
| 36 |
+
anyio/_core/__pycache__/_typedattr.cpython-312.pyc,,
|
| 37 |
+
anyio/_core/_asyncio_selector_thread.py,sha256=53RhMHpFAexW0dQz2Rn8iy8zt931NXyEJITyILWVV_A,5626
|
| 38 |
+
anyio/_core/_eventloop.py,sha256=t_tAwBFPjF8jrZGjlJ6bbYy6KA3bjsbZxV9mvh9t1i0,4695
|
| 39 |
+
anyio/_core/_exceptions.py,sha256=RlPRlwastdmfDPoskdXNO6SI8_l3fclA2wtW6cokU9I,3503
|
| 40 |
+
anyio/_core/_fileio.py,sha256=r6QJmwn90vU0CyCDAWgGhCwc8cT26ofosaHl7Jo3LJU,22853
|
| 41 |
+
anyio/_core/_resources.py,sha256=NbmU5O5UX3xEyACnkmYX28Fmwdl-f-ny0tHym26e0w0,435
|
| 42 |
+
anyio/_core/_signals.py,sha256=vulT1M1xdLYtAR-eY5TamIgaf1WTlOwOrMGwswlTTr8,905
|
| 43 |
+
anyio/_core/_sockets.py,sha256=vQ5GnSDLHjEhHhV2yvsdiPs5wmPxxb1kRsv3RM5lbQk,26951
|
| 44 |
+
anyio/_core/_streams.py,sha256=OnaKgoDD-FcMSwLvkoAUGP51sG2ZdRvMpxt9q2w1gYA,1804
|
| 45 |
+
anyio/_core/_subprocesses.py,sha256=WquR6sHrnaZofaeqnL8U4Yv___msVW_WqivleLHK4zI,7760
|
| 46 |
+
anyio/_core/_synchronization.py,sha256=DwUh8Tl6cG_UMVC_GyzPoC_U9BpfDfjMl9SINSxcZN4,20320
|
| 47 |
+
anyio/_core/_tasks.py,sha256=f3CuWwo06cCZ6jaOv-JHFKWkgpgf2cvaF25Oh4augMA,4757
|
| 48 |
+
anyio/_core/_testing.py,sha256=YUGwA5cgFFbUTv4WFd7cv_BSVr4ryTtPp8owQA3JdWE,2118
|
| 49 |
+
anyio/_core/_typedattr.py,sha256=P4ozZikn3-DbpoYcvyghS_FOYAgbmUxeoU8-L_07pZM,2508
|
| 50 |
+
anyio/abc/__init__.py,sha256=c2OQbTCS_fQowviMXanLPh8m29ccwkXmpDr7uyNZYOo,2652
|
| 51 |
+
anyio/abc/__pycache__/__init__.cpython-312.pyc,,
|
| 52 |
+
anyio/abc/__pycache__/_eventloop.cpython-312.pyc,,
|
| 53 |
+
anyio/abc/__pycache__/_resources.cpython-312.pyc,,
|
| 54 |
+
anyio/abc/__pycache__/_sockets.cpython-312.pyc,,
|
| 55 |
+
anyio/abc/__pycache__/_streams.cpython-312.pyc,,
|
| 56 |
+
anyio/abc/__pycache__/_subprocesses.cpython-312.pyc,,
|
| 57 |
+
anyio/abc/__pycache__/_tasks.cpython-312.pyc,,
|
| 58 |
+
anyio/abc/__pycache__/_testing.cpython-312.pyc,,
|
| 59 |
+
anyio/abc/_eventloop.py,sha256=Wd_3C3hLm0ex5z_eHHWGqvLle2OKCSexJSZVnwQNGV4,9658
|
| 60 |
+
anyio/abc/_resources.py,sha256=DrYvkNN1hH6Uvv5_5uKySvDsnknGVDe8FCKfko0VtN8,783
|
| 61 |
+
anyio/abc/_sockets.py,sha256=KhWtJxan8jpBXKwPaFeQzI4iRXdFaOIn0HXtDZnaO7U,6262
|
| 62 |
+
anyio/abc/_streams.py,sha256=GzST5Q2zQmxVzdrAqtbSyHNxkPlIC9AzeZJg_YyPAXw,6598
|
| 63 |
+
anyio/abc/_subprocesses.py,sha256=cumAPJTktOQtw63IqG0lDpyZqu_l1EElvQHMiwJgL08,2067
|
| 64 |
+
anyio/abc/_tasks.py,sha256=yJWbMwowvqjlAX4oJ3l9Is1w-zwynr2lX1Z02AWJqsY,3080
|
| 65 |
+
anyio/abc/_testing.py,sha256=tBJUzkSfOXJw23fe8qSJ03kJlShOYjjaEyFB6k6MYT8,1821
|
| 66 |
+
anyio/from_thread.py,sha256=dbi5TUH45_Sg_jZ8Vv1NJWVohe0WeQ_OaCvXIKveAGg,17478
|
| 67 |
+
anyio/lowlevel.py,sha256=nkgmW--SdxGVp0cmLUYazjkigveRm5HY7-gW8Bpp9oY,4169
|
| 68 |
+
anyio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 69 |
+
anyio/pytest_plugin.py,sha256=vjGhGRHD31OyMgJRFQrMvExhx3Ea8KbyDqYKmiSDdXA,6712
|
| 70 |
+
anyio/streams/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 71 |
+
anyio/streams/__pycache__/__init__.cpython-312.pyc,,
|
| 72 |
+
anyio/streams/__pycache__/buffered.cpython-312.pyc,,
|
| 73 |
+
anyio/streams/__pycache__/file.cpython-312.pyc,,
|
| 74 |
+
anyio/streams/__pycache__/memory.cpython-312.pyc,,
|
| 75 |
+
anyio/streams/__pycache__/stapled.cpython-312.pyc,,
|
| 76 |
+
anyio/streams/__pycache__/text.cpython-312.pyc,,
|
| 77 |
+
anyio/streams/__pycache__/tls.cpython-312.pyc,,
|
| 78 |
+
anyio/streams/buffered.py,sha256=UCldKC168YuLvT7n3HtNPnQ2iWAMSTYQWbZvzLwMwkM,4500
|
| 79 |
+
anyio/streams/file.py,sha256=6uoTNb5KbMoj-6gS3_xrrL8uZN8Q4iIvOS1WtGyFfKw,4383
|
| 80 |
+
anyio/streams/memory.py,sha256=j8AyOExK4-UPaon_Xbhwax25Vqs0DwFg3ZXc-EIiHjY,10550
|
| 81 |
+
anyio/streams/stapled.py,sha256=U09pCrmOw9kkNhe6tKopsm1QIMT1lFTFvtb-A7SIe4k,4302
|
| 82 |
+
anyio/streams/text.py,sha256=6x8w8xlfCZKTUWQoJiMPoMhSSJFUBRKgoBNSBtbd9yg,5094
|
| 83 |
+
anyio/streams/tls.py,sha256=m3AE2LVSpoRHSIwSoSCupiOVL54EvOFoY3CcwTxcZfg,12742
|
| 84 |
+
anyio/to_interpreter.py,sha256=QhTFaSdyUjxpuN_wBJWPWyh8N6kKV4qhkn71Op84AEc,6624
|
| 85 |
+
anyio/to_process.py,sha256=ZvruelRM-HNmqDaql4sdNODg2QD_uSlwSCxnV4OhsfQ,9595
|
| 86 |
+
anyio/to_thread.py,sha256=WM2JQ2MbVsd5D5CM08bQiTwzZIvpsGjfH1Fy247KoDQ,2396
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (75.6.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[pytest11]
|
| 2 |
+
anyio = anyio.pytest_plugin
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/anyio-4.8.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
anyio
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU LESSER GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 2.1, February 1999
|
| 3 |
+
|
| 4 |
+
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
| 5 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 6 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 7 |
+
of this license document, but changing it is not allowed.
|
| 8 |
+
|
| 9 |
+
[This is the first released version of the Lesser GPL. It also counts
|
| 10 |
+
as the successor of the GNU Library Public License, version 2, hence
|
| 11 |
+
the version number 2.1.]
|
| 12 |
+
|
| 13 |
+
Preamble
|
| 14 |
+
|
| 15 |
+
The licenses for most software are designed to take away your
|
| 16 |
+
freedom to share and change it. By contrast, the GNU General Public
|
| 17 |
+
Licenses are intended to guarantee your freedom to share and change
|
| 18 |
+
free software--to make sure the software is free for all its users.
|
| 19 |
+
|
| 20 |
+
This license, the Lesser General Public License, applies to some
|
| 21 |
+
specially designated software packages--typically libraries--of the
|
| 22 |
+
Free Software Foundation and other authors who decide to use it. You
|
| 23 |
+
can use it too, but we suggest you first think carefully about whether
|
| 24 |
+
this license or the ordinary General Public License is the better
|
| 25 |
+
strategy to use in any particular case, based on the explanations below.
|
| 26 |
+
|
| 27 |
+
When we speak of free software, we are referring to freedom of use,
|
| 28 |
+
not price. Our General Public Licenses are designed to make sure that
|
| 29 |
+
you have the freedom to distribute copies of free software (and charge
|
| 30 |
+
for this service if you wish); that you receive source code or can get
|
| 31 |
+
it if you want it; that you can change the software and use pieces of
|
| 32 |
+
it in new free programs; and that you are informed that you can do
|
| 33 |
+
these things.
|
| 34 |
+
|
| 35 |
+
To protect your rights, we need to make restrictions that forbid
|
| 36 |
+
distributors to deny you these rights or to ask you to surrender these
|
| 37 |
+
rights. These restrictions translate to certain responsibilities for
|
| 38 |
+
you if you distribute copies of the library or if you modify it.
|
| 39 |
+
|
| 40 |
+
For example, if you distribute copies of the library, whether gratis
|
| 41 |
+
or for a fee, you must give the recipients all the rights that we gave
|
| 42 |
+
you. You must make sure that they, too, receive or can get the source
|
| 43 |
+
code. If you link other code with the library, you must provide
|
| 44 |
+
complete object files to the recipients, so that they can relink them
|
| 45 |
+
with the library after making changes to the library and recompiling
|
| 46 |
+
it. And you must show them these terms so they know their rights.
|
| 47 |
+
|
| 48 |
+
We protect your rights with a two-step method: (1) we copyright the
|
| 49 |
+
library, and (2) we offer you this license, which gives you legal
|
| 50 |
+
permission to copy, distribute and/or modify the library.
|
| 51 |
+
|
| 52 |
+
To protect each distributor, we want to make it very clear that
|
| 53 |
+
there is no warranty for the free library. Also, if the library is
|
| 54 |
+
modified by someone else and passed on, the recipients should know
|
| 55 |
+
that what they have is not the original version, so that the original
|
| 56 |
+
author's reputation will not be affected by problems that might be
|
| 57 |
+
introduced by others.
|
| 58 |
+
|
| 59 |
+
Finally, software patents pose a constant threat to the existence of
|
| 60 |
+
any free program. We wish to make sure that a company cannot
|
| 61 |
+
effectively restrict the users of a free program by obtaining a
|
| 62 |
+
restrictive license from a patent holder. Therefore, we insist that
|
| 63 |
+
any patent license obtained for a version of the library must be
|
| 64 |
+
consistent with the full freedom of use specified in this license.
|
| 65 |
+
|
| 66 |
+
Most GNU software, including some libraries, is covered by the
|
| 67 |
+
ordinary GNU General Public License. This license, the GNU Lesser
|
| 68 |
+
General Public License, applies to certain designated libraries, and
|
| 69 |
+
is quite different from the ordinary General Public License. We use
|
| 70 |
+
this license for certain libraries in order to permit linking those
|
| 71 |
+
libraries into non-free programs.
|
| 72 |
+
|
| 73 |
+
When a program is linked with a library, whether statically or using
|
| 74 |
+
a shared library, the combination of the two is legally speaking a
|
| 75 |
+
combined work, a derivative of the original library. The ordinary
|
| 76 |
+
General Public License therefore permits such linking only if the
|
| 77 |
+
entire combination fits its criteria of freedom. The Lesser General
|
| 78 |
+
Public License permits more lax criteria for linking other code with
|
| 79 |
+
the library.
|
| 80 |
+
|
| 81 |
+
We call this license the "Lesser" General Public License because it
|
| 82 |
+
does Less to protect the user's freedom than the ordinary General
|
| 83 |
+
Public License. It also provides other free software developers Less
|
| 84 |
+
of an advantage over competing non-free programs. These disadvantages
|
| 85 |
+
are the reason we use the ordinary General Public License for many
|
| 86 |
+
libraries. However, the Lesser license provides advantages in certain
|
| 87 |
+
special circumstances.
|
| 88 |
+
|
| 89 |
+
For example, on rare occasions, there may be a special need to
|
| 90 |
+
encourage the widest possible use of a certain library, so that it becomes
|
| 91 |
+
a de-facto standard. To achieve this, non-free programs must be
|
| 92 |
+
allowed to use the library. A more frequent case is that a free
|
| 93 |
+
library does the same job as widely used non-free libraries. In this
|
| 94 |
+
case, there is little to gain by limiting the free library to free
|
| 95 |
+
software only, so we use the Lesser General Public License.
|
| 96 |
+
|
| 97 |
+
In other cases, permission to use a particular library in non-free
|
| 98 |
+
programs enables a greater number of people to use a large body of
|
| 99 |
+
free software. For example, permission to use the GNU C Library in
|
| 100 |
+
non-free programs enables many more people to use the whole GNU
|
| 101 |
+
operating system, as well as its variant, the GNU/Linux operating
|
| 102 |
+
system.
|
| 103 |
+
|
| 104 |
+
Although the Lesser General Public License is Less protective of the
|
| 105 |
+
users' freedom, it does ensure that the user of a program that is
|
| 106 |
+
linked with the Library has the freedom and the wherewithal to run
|
| 107 |
+
that program using a modified version of the Library.
|
| 108 |
+
|
| 109 |
+
The precise terms and conditions for copying, distribution and
|
| 110 |
+
modification follow. Pay close attention to the difference between a
|
| 111 |
+
"work based on the library" and a "work that uses the library". The
|
| 112 |
+
former contains code derived from the library, whereas the latter must
|
| 113 |
+
be combined with the library in order to run.
|
| 114 |
+
|
| 115 |
+
GNU LESSER GENERAL PUBLIC LICENSE
|
| 116 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
| 117 |
+
|
| 118 |
+
0. This License Agreement applies to any software library or other
|
| 119 |
+
program which contains a notice placed by the copyright holder or
|
| 120 |
+
other authorized party saying it may be distributed under the terms of
|
| 121 |
+
this Lesser General Public License (also called "this License").
|
| 122 |
+
Each licensee is addressed as "you".
|
| 123 |
+
|
| 124 |
+
A "library" means a collection of software functions and/or data
|
| 125 |
+
prepared so as to be conveniently linked with application programs
|
| 126 |
+
(which use some of those functions and data) to form executables.
|
| 127 |
+
|
| 128 |
+
The "Library", below, refers to any such software library or work
|
| 129 |
+
which has been distributed under these terms. A "work based on the
|
| 130 |
+
Library" means either the Library or any derivative work under
|
| 131 |
+
copyright law: that is to say, a work containing the Library or a
|
| 132 |
+
portion of it, either verbatim or with modifications and/or translated
|
| 133 |
+
straightforwardly into another language. (Hereinafter, translation is
|
| 134 |
+
included without limitation in the term "modification".)
|
| 135 |
+
|
| 136 |
+
"Source code" for a work means the preferred form of the work for
|
| 137 |
+
making modifications to it. For a library, complete source code means
|
| 138 |
+
all the source code for all modules it contains, plus any associated
|
| 139 |
+
interface definition files, plus the scripts used to control compilation
|
| 140 |
+
and installation of the library.
|
| 141 |
+
|
| 142 |
+
Activities other than copying, distribution and modification are not
|
| 143 |
+
covered by this License; they are outside its scope. The act of
|
| 144 |
+
running a program using the Library is not restricted, and output from
|
| 145 |
+
such a program is covered only if its contents constitute a work based
|
| 146 |
+
on the Library (independent of the use of the Library in a tool for
|
| 147 |
+
writing it). Whether that is true depends on what the Library does
|
| 148 |
+
and what the program that uses the Library does.
|
| 149 |
+
|
| 150 |
+
1. You may copy and distribute verbatim copies of the Library's
|
| 151 |
+
complete source code as you receive it, in any medium, provided that
|
| 152 |
+
you conspicuously and appropriately publish on each copy an
|
| 153 |
+
appropriate copyright notice and disclaimer of warranty; keep intact
|
| 154 |
+
all the notices that refer to this License and to the absence of any
|
| 155 |
+
warranty; and distribute a copy of this License along with the
|
| 156 |
+
Library.
|
| 157 |
+
|
| 158 |
+
You may charge a fee for the physical act of transferring a copy,
|
| 159 |
+
and you may at your option offer warranty protection in exchange for a
|
| 160 |
+
fee.
|
| 161 |
+
|
| 162 |
+
2. You may modify your copy or copies of the Library or any portion
|
| 163 |
+
of it, thus forming a work based on the Library, and copy and
|
| 164 |
+
distribute such modifications or work under the terms of Section 1
|
| 165 |
+
above, provided that you also meet all of these conditions:
|
| 166 |
+
|
| 167 |
+
a) The modified work must itself be a software library.
|
| 168 |
+
|
| 169 |
+
b) You must cause the files modified to carry prominent notices
|
| 170 |
+
stating that you changed the files and the date of any change.
|
| 171 |
+
|
| 172 |
+
c) You must cause the whole of the work to be licensed at no
|
| 173 |
+
charge to all third parties under the terms of this License.
|
| 174 |
+
|
| 175 |
+
d) If a facility in the modified Library refers to a function or a
|
| 176 |
+
table of data to be supplied by an application program that uses
|
| 177 |
+
the facility, other than as an argument passed when the facility
|
| 178 |
+
is invoked, then you must make a good faith effort to ensure that,
|
| 179 |
+
in the event an application does not supply such function or
|
| 180 |
+
table, the facility still operates, and performs whatever part of
|
| 181 |
+
its purpose remains meaningful.
|
| 182 |
+
|
| 183 |
+
(For example, a function in a library to compute square roots has
|
| 184 |
+
a purpose that is entirely well-defined independent of the
|
| 185 |
+
application. Therefore, Subsection 2d requires that any
|
| 186 |
+
application-supplied function or table used by this function must
|
| 187 |
+
be optional: if the application does not supply it, the square
|
| 188 |
+
root function must still compute square roots.)
|
| 189 |
+
|
| 190 |
+
These requirements apply to the modified work as a whole. If
|
| 191 |
+
identifiable sections of that work are not derived from the Library,
|
| 192 |
+
and can be reasonably considered independent and separate works in
|
| 193 |
+
themselves, then this License, and its terms, do not apply to those
|
| 194 |
+
sections when you distribute them as separate works. But when you
|
| 195 |
+
distribute the same sections as part of a whole which is a work based
|
| 196 |
+
on the Library, the distribution of the whole must be on the terms of
|
| 197 |
+
this License, whose permissions for other licensees extend to the
|
| 198 |
+
entire whole, and thus to each and every part regardless of who wrote
|
| 199 |
+
it.
|
| 200 |
+
|
| 201 |
+
Thus, it is not the intent of this section to claim rights or contest
|
| 202 |
+
your rights to work written entirely by you; rather, the intent is to
|
| 203 |
+
exercise the right to control the distribution of derivative or
|
| 204 |
+
collective works based on the Library.
|
| 205 |
+
|
| 206 |
+
In addition, mere aggregation of another work not based on the Library
|
| 207 |
+
with the Library (or with a work based on the Library) on a volume of
|
| 208 |
+
a storage or distribution medium does not bring the other work under
|
| 209 |
+
the scope of this License.
|
| 210 |
+
|
| 211 |
+
3. You may opt to apply the terms of the ordinary GNU General Public
|
| 212 |
+
License instead of this License to a given copy of the Library. To do
|
| 213 |
+
this, you must alter all the notices that refer to this License, so
|
| 214 |
+
that they refer to the ordinary GNU General Public License, version 2,
|
| 215 |
+
instead of to this License. (If a newer version than version 2 of the
|
| 216 |
+
ordinary GNU General Public License has appeared, then you can specify
|
| 217 |
+
that version instead if you wish.) Do not make any other change in
|
| 218 |
+
these notices.
|
| 219 |
+
|
| 220 |
+
Once this change is made in a given copy, it is irreversible for
|
| 221 |
+
that copy, so the ordinary GNU General Public License applies to all
|
| 222 |
+
subsequent copies and derivative works made from that copy.
|
| 223 |
+
|
| 224 |
+
This option is useful when you wish to copy part of the code of
|
| 225 |
+
the Library into a program that is not a library.
|
| 226 |
+
|
| 227 |
+
4. You may copy and distribute the Library (or a portion or
|
| 228 |
+
derivative of it, under Section 2) in object code or executable form
|
| 229 |
+
under the terms of Sections 1 and 2 above provided that you accompany
|
| 230 |
+
it with the complete corresponding machine-readable source code, which
|
| 231 |
+
must be distributed under the terms of Sections 1 and 2 above on a
|
| 232 |
+
medium customarily used for software interchange.
|
| 233 |
+
|
| 234 |
+
If distribution of object code is made by offering access to copy
|
| 235 |
+
from a designated place, then offering equivalent access to copy the
|
| 236 |
+
source code from the same place satisfies the requirement to
|
| 237 |
+
distribute the source code, even though third parties are not
|
| 238 |
+
compelled to copy the source along with the object code.
|
| 239 |
+
|
| 240 |
+
5. A program that contains no derivative of any portion of the
|
| 241 |
+
Library, but is designed to work with the Library by being compiled or
|
| 242 |
+
linked with it, is called a "work that uses the Library". Such a
|
| 243 |
+
work, in isolation, is not a derivative work of the Library, and
|
| 244 |
+
therefore falls outside the scope of this License.
|
| 245 |
+
|
| 246 |
+
However, linking a "work that uses the Library" with the Library
|
| 247 |
+
creates an executable that is a derivative of the Library (because it
|
| 248 |
+
contains portions of the Library), rather than a "work that uses the
|
| 249 |
+
library". The executable is therefore covered by this License.
|
| 250 |
+
Section 6 states terms for distribution of such executables.
|
| 251 |
+
|
| 252 |
+
When a "work that uses the Library" uses material from a header file
|
| 253 |
+
that is part of the Library, the object code for the work may be a
|
| 254 |
+
derivative work of the Library even though the source code is not.
|
| 255 |
+
Whether this is true is especially significant if the work can be
|
| 256 |
+
linked without the Library, or if the work is itself a library. The
|
| 257 |
+
threshold for this to be true is not precisely defined by law.
|
| 258 |
+
|
| 259 |
+
If such an object file uses only numerical parameters, data
|
| 260 |
+
structure layouts and accessors, and small macros and small inline
|
| 261 |
+
functions (ten lines or less in length), then the use of the object
|
| 262 |
+
file is unrestricted, regardless of whether it is legally a derivative
|
| 263 |
+
work. (Executables containing this object code plus portions of the
|
| 264 |
+
Library will still fall under Section 6.)
|
| 265 |
+
|
| 266 |
+
Otherwise, if the work is a derivative of the Library, you may
|
| 267 |
+
distribute the object code for the work under the terms of Section 6.
|
| 268 |
+
Any executables containing that work also fall under Section 6,
|
| 269 |
+
whether or not they are linked directly with the Library itself.
|
| 270 |
+
|
| 271 |
+
6. As an exception to the Sections above, you may also combine or
|
| 272 |
+
link a "work that uses the Library" with the Library to produce a
|
| 273 |
+
work containing portions of the Library, and distribute that work
|
| 274 |
+
under terms of your choice, provided that the terms permit
|
| 275 |
+
modification of the work for the customer's own use and reverse
|
| 276 |
+
engineering for debugging such modifications.
|
| 277 |
+
|
| 278 |
+
You must give prominent notice with each copy of the work that the
|
| 279 |
+
Library is used in it and that the Library and its use are covered by
|
| 280 |
+
this License. You must supply a copy of this License. If the work
|
| 281 |
+
during execution displays copyright notices, you must include the
|
| 282 |
+
copyright notice for the Library among them, as well as a reference
|
| 283 |
+
directing the user to the copy of this License. Also, you must do one
|
| 284 |
+
of these things:
|
| 285 |
+
|
| 286 |
+
a) Accompany the work with the complete corresponding
|
| 287 |
+
machine-readable source code for the Library including whatever
|
| 288 |
+
changes were used in the work (which must be distributed under
|
| 289 |
+
Sections 1 and 2 above); and, if the work is an executable linked
|
| 290 |
+
with the Library, with the complete machine-readable "work that
|
| 291 |
+
uses the Library", as object code and/or source code, so that the
|
| 292 |
+
user can modify the Library and then relink to produce a modified
|
| 293 |
+
executable containing the modified Library. (It is understood
|
| 294 |
+
that the user who changes the contents of definitions files in the
|
| 295 |
+
Library will not necessarily be able to recompile the application
|
| 296 |
+
to use the modified definitions.)
|
| 297 |
+
|
| 298 |
+
b) Use a suitable shared library mechanism for linking with the
|
| 299 |
+
Library. A suitable mechanism is one that (1) uses at run time a
|
| 300 |
+
copy of the library already present on the user's computer system,
|
| 301 |
+
rather than copying library functions into the executable, and (2)
|
| 302 |
+
will operate properly with a modified version of the library, if
|
| 303 |
+
the user installs one, as long as the modified version is
|
| 304 |
+
interface-compatible with the version that the work was made with.
|
| 305 |
+
|
| 306 |
+
c) Accompany the work with a written offer, valid for at
|
| 307 |
+
least three years, to give the same user the materials
|
| 308 |
+
specified in Subsection 6a, above, for a charge no more
|
| 309 |
+
than the cost of performing this distribution.
|
| 310 |
+
|
| 311 |
+
d) If distribution of the work is made by offering access to copy
|
| 312 |
+
from a designated place, offer equivalent access to copy the above
|
| 313 |
+
specified materials from the same place.
|
| 314 |
+
|
| 315 |
+
e) Verify that the user has already received a copy of these
|
| 316 |
+
materials or that you have already sent this user a copy.
|
| 317 |
+
|
| 318 |
+
For an executable, the required form of the "work that uses the
|
| 319 |
+
Library" must include any data and utility programs needed for
|
| 320 |
+
reproducing the executable from it. However, as a special exception,
|
| 321 |
+
the materials to be distributed need not include anything that is
|
| 322 |
+
normally distributed (in either source or binary form) with the major
|
| 323 |
+
components (compiler, kernel, and so on) of the operating system on
|
| 324 |
+
which the executable runs, unless that component itself accompanies
|
| 325 |
+
the executable.
|
| 326 |
+
|
| 327 |
+
It may happen that this requirement contradicts the license
|
| 328 |
+
restrictions of other proprietary libraries that do not normally
|
| 329 |
+
accompany the operating system. Such a contradiction means you cannot
|
| 330 |
+
use both them and the Library together in an executable that you
|
| 331 |
+
distribute.
|
| 332 |
+
|
| 333 |
+
7. You may place library facilities that are a work based on the
|
| 334 |
+
Library side-by-side in a single library together with other library
|
| 335 |
+
facilities not covered by this License, and distribute such a combined
|
| 336 |
+
library, provided that the separate distribution of the work based on
|
| 337 |
+
the Library and of the other library facilities is otherwise
|
| 338 |
+
permitted, and provided that you do these two things:
|
| 339 |
+
|
| 340 |
+
a) Accompany the combined library with a copy of the same work
|
| 341 |
+
based on the Library, uncombined with any other library
|
| 342 |
+
facilities. This must be distributed under the terms of the
|
| 343 |
+
Sections above.
|
| 344 |
+
|
| 345 |
+
b) Give prominent notice with the combined library of the fact
|
| 346 |
+
that part of it is a work based on the Library, and explaining
|
| 347 |
+
where to find the accompanying uncombined form of the same work.
|
| 348 |
+
|
| 349 |
+
8. You may not copy, modify, sublicense, link with, or distribute
|
| 350 |
+
the Library except as expressly provided under this License. Any
|
| 351 |
+
attempt otherwise to copy, modify, sublicense, link with, or
|
| 352 |
+
distribute the Library is void, and will automatically terminate your
|
| 353 |
+
rights under this License. However, parties who have received copies,
|
| 354 |
+
or rights, from you under this License will not have their licenses
|
| 355 |
+
terminated so long as such parties remain in full compliance.
|
| 356 |
+
|
| 357 |
+
9. You are not required to accept this License, since you have not
|
| 358 |
+
signed it. However, nothing else grants you permission to modify or
|
| 359 |
+
distribute the Library or its derivative works. These actions are
|
| 360 |
+
prohibited by law if you do not accept this License. Therefore, by
|
| 361 |
+
modifying or distributing the Library (or any work based on the
|
| 362 |
+
Library), you indicate your acceptance of this License to do so, and
|
| 363 |
+
all its terms and conditions for copying, distributing or modifying
|
| 364 |
+
the Library or works based on it.
|
| 365 |
+
|
| 366 |
+
10. Each time you redistribute the Library (or any work based on the
|
| 367 |
+
Library), the recipient automatically receives a license from the
|
| 368 |
+
original licensor to copy, distribute, link with or modify the Library
|
| 369 |
+
subject to these terms and conditions. You may not impose any further
|
| 370 |
+
restrictions on the recipients' exercise of the rights granted herein.
|
| 371 |
+
You are not responsible for enforcing compliance by third parties with
|
| 372 |
+
this License.
|
| 373 |
+
|
| 374 |
+
11. If, as a consequence of a court judgment or allegation of patent
|
| 375 |
+
infringement or for any other reason (not limited to patent issues),
|
| 376 |
+
conditions are imposed on you (whether by court order, agreement or
|
| 377 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 378 |
+
excuse you from the conditions of this License. If you cannot
|
| 379 |
+
distribute so as to satisfy simultaneously your obligations under this
|
| 380 |
+
License and any other pertinent obligations, then as a consequence you
|
| 381 |
+
may not distribute the Library at all. For example, if a patent
|
| 382 |
+
license would not permit royalty-free redistribution of the Library by
|
| 383 |
+
all those who receive copies directly or indirectly through you, then
|
| 384 |
+
the only way you could satisfy both it and this License would be to
|
| 385 |
+
refrain entirely from distribution of the Library.
|
| 386 |
+
|
| 387 |
+
If any portion of this section is held invalid or unenforceable under any
|
| 388 |
+
particular circumstance, the balance of the section is intended to apply,
|
| 389 |
+
and the section as a whole is intended to apply in other circumstances.
|
| 390 |
+
|
| 391 |
+
It is not the purpose of this section to induce you to infringe any
|
| 392 |
+
patents or other property right claims or to contest validity of any
|
| 393 |
+
such claims; this section has the sole purpose of protecting the
|
| 394 |
+
integrity of the free software distribution system which is
|
| 395 |
+
implemented by public license practices. Many people have made
|
| 396 |
+
generous contributions to the wide range of software distributed
|
| 397 |
+
through that system in reliance on consistent application of that
|
| 398 |
+
system; it is up to the author/donor to decide if he or she is willing
|
| 399 |
+
to distribute software through any other system and a licensee cannot
|
| 400 |
+
impose that choice.
|
| 401 |
+
|
| 402 |
+
This section is intended to make thoroughly clear what is believed to
|
| 403 |
+
be a consequence of the rest of this License.
|
| 404 |
+
|
| 405 |
+
12. If the distribution and/or use of the Library is restricted in
|
| 406 |
+
certain countries either by patents or by copyrighted interfaces, the
|
| 407 |
+
original copyright holder who places the Library under this License may add
|
| 408 |
+
an explicit geographical distribution limitation excluding those countries,
|
| 409 |
+
so that distribution is permitted only in or among countries not thus
|
| 410 |
+
excluded. In such case, this License incorporates the limitation as if
|
| 411 |
+
written in the body of this License.
|
| 412 |
+
|
| 413 |
+
13. The Free Software Foundation may publish revised and/or new
|
| 414 |
+
versions of the Lesser General Public License from time to time.
|
| 415 |
+
Such new versions will be similar in spirit to the present version,
|
| 416 |
+
but may differ in detail to address new problems or concerns.
|
| 417 |
+
|
| 418 |
+
Each version is given a distinguishing version number. If the Library
|
| 419 |
+
specifies a version number of this License which applies to it and
|
| 420 |
+
"any later version", you have the option of following the terms and
|
| 421 |
+
conditions either of that version or of any later version published by
|
| 422 |
+
the Free Software Foundation. If the Library does not specify a
|
| 423 |
+
license version number, you may choose any version ever published by
|
| 424 |
+
the Free Software Foundation.
|
| 425 |
+
|
| 426 |
+
14. If you wish to incorporate parts of the Library into other free
|
| 427 |
+
programs whose distribution conditions are incompatible with these,
|
| 428 |
+
write to the author to ask for permission. For software which is
|
| 429 |
+
copyrighted by the Free Software Foundation, write to the Free
|
| 430 |
+
Software Foundation; we sometimes make exceptions for this. Our
|
| 431 |
+
decision will be guided by the two goals of preserving the free status
|
| 432 |
+
of all derivatives of our free software and of promoting the sharing
|
| 433 |
+
and reuse of software generally.
|
| 434 |
+
|
| 435 |
+
NO WARRANTY
|
| 436 |
+
|
| 437 |
+
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
| 438 |
+
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
| 439 |
+
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
| 440 |
+
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
| 441 |
+
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
| 442 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 443 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
| 444 |
+
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
| 445 |
+
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 446 |
+
|
| 447 |
+
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
| 448 |
+
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
| 449 |
+
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
| 450 |
+
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
| 451 |
+
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
| 452 |
+
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
| 453 |
+
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
| 454 |
+
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
| 455 |
+
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
| 456 |
+
DAMAGES.
|
| 457 |
+
|
| 458 |
+
END OF TERMS AND CONDITIONS
|
| 459 |
+
|
| 460 |
+
How to Apply These Terms to Your New Libraries
|
| 461 |
+
|
| 462 |
+
If you develop a new library, and you want it to be of the greatest
|
| 463 |
+
possible use to the public, we recommend making it free software that
|
| 464 |
+
everyone can redistribute and change. You can do so by permitting
|
| 465 |
+
redistribution under these terms (or, alternatively, under the terms of the
|
| 466 |
+
ordinary General Public License).
|
| 467 |
+
|
| 468 |
+
To apply these terms, attach the following notices to the library. It is
|
| 469 |
+
safest to attach them to the start of each source file to most effectively
|
| 470 |
+
convey the exclusion of warranty; and each file should have at least the
|
| 471 |
+
"copyright" line and a pointer to where the full notice is found.
|
| 472 |
+
|
| 473 |
+
<one line to give the library's name and a brief idea of what it does.>
|
| 474 |
+
Copyright (C) <year> <name of author>
|
| 475 |
+
|
| 476 |
+
This library is free software; you can redistribute it and/or
|
| 477 |
+
modify it under the terms of the GNU Lesser General Public
|
| 478 |
+
License as published by the Free Software Foundation; either
|
| 479 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 480 |
+
|
| 481 |
+
This library is distributed in the hope that it will be useful,
|
| 482 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 483 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 484 |
+
Lesser General Public License for more details.
|
| 485 |
+
|
| 486 |
+
You should have received a copy of the GNU Lesser General Public
|
| 487 |
+
License along with this library; if not, write to the Free Software
|
| 488 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 489 |
+
|
| 490 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 491 |
+
|
| 492 |
+
You should also get your employer (if you work as a programmer) or your
|
| 493 |
+
school, if any, to sign a "copyright disclaimer" for the library, if
|
| 494 |
+
necessary. Here is a sample; alter the names:
|
| 495 |
+
|
| 496 |
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
| 497 |
+
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
| 498 |
+
|
| 499 |
+
<signature of Ty Coon>, 1 April 1990
|
| 500 |
+
Ty Coon, President of Vice
|
| 501 |
+
|
| 502 |
+
That's all there is to it!
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: chardet
|
| 3 |
+
Version: 5.2.0
|
| 4 |
+
Summary: Universal encoding detector for Python 3
|
| 5 |
+
Home-page: https://github.com/chardet/chardet
|
| 6 |
+
Author: Mark Pilgrim
|
| 7 |
+
Author-email: mark@diveintomark.org
|
| 8 |
+
Maintainer: Daniel Blanchard
|
| 9 |
+
Maintainer-email: dan.blanchard@gmail.com
|
| 10 |
+
License: LGPL
|
| 11 |
+
Project-URL: Documentation, https://chardet.readthedocs.io/
|
| 12 |
+
Project-URL: GitHub Project, https://github.com/chardet/chardet
|
| 13 |
+
Project-URL: Issue Tracker, https://github.com/chardet/chardet/issues
|
| 14 |
+
Keywords: encoding,i18n,xml
|
| 15 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 16 |
+
Classifier: Intended Audience :: Developers
|
| 17 |
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
|
| 18 |
+
Classifier: Operating System :: OS Independent
|
| 19 |
+
Classifier: Programming Language :: Python
|
| 20 |
+
Classifier: Programming Language :: Python :: 3
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 24 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 25 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 26 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 27 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 28 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 29 |
+
Classifier: Topic :: Text Processing :: Linguistic
|
| 30 |
+
Requires-Python: >=3.7
|
| 31 |
+
License-File: LICENSE
|
| 32 |
+
|
| 33 |
+
Chardet: The Universal Character Encoding Detector
|
| 34 |
+
--------------------------------------------------
|
| 35 |
+
|
| 36 |
+
.. image:: https://img.shields.io/travis/chardet/chardet/stable.svg
|
| 37 |
+
:alt: Build status
|
| 38 |
+
:target: https://travis-ci.org/chardet/chardet
|
| 39 |
+
|
| 40 |
+
.. image:: https://img.shields.io/coveralls/chardet/chardet/stable.svg
|
| 41 |
+
:target: https://coveralls.io/r/chardet/chardet
|
| 42 |
+
|
| 43 |
+
.. image:: https://img.shields.io/pypi/v/chardet.svg
|
| 44 |
+
:target: https://warehouse.python.org/project/chardet/
|
| 45 |
+
:alt: Latest version on PyPI
|
| 46 |
+
|
| 47 |
+
.. image:: https://img.shields.io/pypi/l/chardet.svg
|
| 48 |
+
:alt: License
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Detects
|
| 52 |
+
- ASCII, UTF-8, UTF-16 (2 variants), UTF-32 (4 variants)
|
| 53 |
+
- Big5, GB2312, EUC-TW, HZ-GB-2312, ISO-2022-CN (Traditional and Simplified Chinese)
|
| 54 |
+
- EUC-JP, SHIFT_JIS, CP932, ISO-2022-JP (Japanese)
|
| 55 |
+
- EUC-KR, ISO-2022-KR, Johab (Korean)
|
| 56 |
+
- KOI8-R, MacCyrillic, IBM855, IBM866, ISO-8859-5, windows-1251 (Cyrillic)
|
| 57 |
+
- ISO-8859-5, windows-1251 (Bulgarian)
|
| 58 |
+
- ISO-8859-1, windows-1252, MacRoman (Western European languages)
|
| 59 |
+
- ISO-8859-7, windows-1253 (Greek)
|
| 60 |
+
- ISO-8859-8, windows-1255 (Visual and Logical Hebrew)
|
| 61 |
+
- TIS-620 (Thai)
|
| 62 |
+
|
| 63 |
+
.. note::
|
| 64 |
+
Our ISO-8859-2 and windows-1250 (Hungarian) probers have been temporarily
|
| 65 |
+
disabled until we can retrain the models.
|
| 66 |
+
|
| 67 |
+
Requires Python 3.7+.
|
| 68 |
+
|
| 69 |
+
Installation
|
| 70 |
+
------------
|
| 71 |
+
|
| 72 |
+
Install from `PyPI <https://pypi.org/project/chardet/>`_::
|
| 73 |
+
|
| 74 |
+
pip install chardet
|
| 75 |
+
|
| 76 |
+
Documentation
|
| 77 |
+
-------------
|
| 78 |
+
|
| 79 |
+
For users, docs are now available at https://chardet.readthedocs.io/.
|
| 80 |
+
|
| 81 |
+
Command-line Tool
|
| 82 |
+
-----------------
|
| 83 |
+
|
| 84 |
+
chardet comes with a command-line script which reports on the encodings of one
|
| 85 |
+
or more files::
|
| 86 |
+
|
| 87 |
+
% chardetect somefile someotherfile
|
| 88 |
+
somefile: windows-1252 with confidence 0.5
|
| 89 |
+
someotherfile: ascii with confidence 1.0
|
| 90 |
+
|
| 91 |
+
About
|
| 92 |
+
-----
|
| 93 |
+
|
| 94 |
+
This is a continuation of Mark Pilgrim's excellent original chardet port from C, and `Ian Cordasco <https://github.com/sigmavirus24>`_'s
|
| 95 |
+
`charade <https://github.com/sigmavirus24/charade>`_ Python 3-compatible fork.
|
| 96 |
+
|
| 97 |
+
:maintainer: Dan Blanchard
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
chardet-5.2.0.dist-info/entry_points.txt,sha256=_cdvYc4jyY68GYfsQAAthNMxO-yodcGkvNC1xOEsLmI,59
|
| 8 |
+
chardet-5.2.0.dist-info/top_level.txt,sha256=AowzBbZy4x8EirABDdJSLJZMkJ_53iIag8xfKR6D7kI,8
|
| 9 |
+
chardet/__init__.py,sha256=57R-HSxj0PWmILMN0GFmUNqEMfrEVSamXyjD-W6_fbs,4797
|
| 10 |
+
chardet/__main__.py,sha256=puNj2o_QfBRKElEkiVp1zEIL1gGYD2o-JuXLFlqHDC4,123
|
| 11 |
+
chardet/__pycache__/__init__.cpython-312.pyc,,
|
| 12 |
+
chardet/__pycache__/__main__.cpython-312.pyc,,
|
| 13 |
+
chardet/__pycache__/big5freq.cpython-312.pyc,,
|
| 14 |
+
chardet/__pycache__/big5prober.cpython-312.pyc,,
|
| 15 |
+
chardet/__pycache__/chardistribution.cpython-312.pyc,,
|
| 16 |
+
chardet/__pycache__/charsetgroupprober.cpython-312.pyc,,
|
| 17 |
+
chardet/__pycache__/charsetprober.cpython-312.pyc,,
|
| 18 |
+
chardet/__pycache__/codingstatemachine.cpython-312.pyc,,
|
| 19 |
+
chardet/__pycache__/codingstatemachinedict.cpython-312.pyc,,
|
| 20 |
+
chardet/__pycache__/cp949prober.cpython-312.pyc,,
|
| 21 |
+
chardet/__pycache__/enums.cpython-312.pyc,,
|
| 22 |
+
chardet/__pycache__/escprober.cpython-312.pyc,,
|
| 23 |
+
chardet/__pycache__/escsm.cpython-312.pyc,,
|
| 24 |
+
chardet/__pycache__/eucjpprober.cpython-312.pyc,,
|
| 25 |
+
chardet/__pycache__/euckrfreq.cpython-312.pyc,,
|
| 26 |
+
chardet/__pycache__/euckrprober.cpython-312.pyc,,
|
| 27 |
+
chardet/__pycache__/euctwfreq.cpython-312.pyc,,
|
| 28 |
+
chardet/__pycache__/euctwprober.cpython-312.pyc,,
|
| 29 |
+
chardet/__pycache__/gb2312freq.cpython-312.pyc,,
|
| 30 |
+
chardet/__pycache__/gb2312prober.cpython-312.pyc,,
|
| 31 |
+
chardet/__pycache__/hebrewprober.cpython-312.pyc,,
|
| 32 |
+
chardet/__pycache__/jisfreq.cpython-312.pyc,,
|
| 33 |
+
chardet/__pycache__/johabfreq.cpython-312.pyc,,
|
| 34 |
+
chardet/__pycache__/johabprober.cpython-312.pyc,,
|
| 35 |
+
chardet/__pycache__/jpcntx.cpython-312.pyc,,
|
| 36 |
+
chardet/__pycache__/langbulgarianmodel.cpython-312.pyc,,
|
| 37 |
+
chardet/__pycache__/langgreekmodel.cpython-312.pyc,,
|
| 38 |
+
chardet/__pycache__/langhebrewmodel.cpython-312.pyc,,
|
| 39 |
+
chardet/__pycache__/langhungarianmodel.cpython-312.pyc,,
|
| 40 |
+
chardet/__pycache__/langrussianmodel.cpython-312.pyc,,
|
| 41 |
+
chardet/__pycache__/langthaimodel.cpython-312.pyc,,
|
| 42 |
+
chardet/__pycache__/langturkishmodel.cpython-312.pyc,,
|
| 43 |
+
chardet/__pycache__/latin1prober.cpython-312.pyc,,
|
| 44 |
+
chardet/__pycache__/macromanprober.cpython-312.pyc,,
|
| 45 |
+
chardet/__pycache__/mbcharsetprober.cpython-312.pyc,,
|
| 46 |
+
chardet/__pycache__/mbcsgroupprober.cpython-312.pyc,,
|
| 47 |
+
chardet/__pycache__/mbcssm.cpython-312.pyc,,
|
| 48 |
+
chardet/__pycache__/resultdict.cpython-312.pyc,,
|
| 49 |
+
chardet/__pycache__/sbcharsetprober.cpython-312.pyc,,
|
| 50 |
+
chardet/__pycache__/sbcsgroupprober.cpython-312.pyc,,
|
| 51 |
+
chardet/__pycache__/sjisprober.cpython-312.pyc,,
|
| 52 |
+
chardet/__pycache__/universaldetector.cpython-312.pyc,,
|
| 53 |
+
chardet/__pycache__/utf1632prober.cpython-312.pyc,,
|
| 54 |
+
chardet/__pycache__/utf8prober.cpython-312.pyc,,
|
| 55 |
+
chardet/__pycache__/version.cpython-312.pyc,,
|
| 56 |
+
chardet/big5freq.py,sha256=ltcfP-3PjlNHCoo5e4a7C4z-2DhBTXRfY6jbMbB7P30,31274
|
| 57 |
+
chardet/big5prober.py,sha256=lPMfwCX6v2AaPgvFh_cSWZcgLDbWiFCHLZ_p9RQ9uxE,1763
|
| 58 |
+
chardet/chardistribution.py,sha256=13B8XUG4oXDuLdXvfbIWwLFeR-ZU21AqTS1zcdON8bU,10032
|
| 59 |
+
chardet/charsetgroupprober.py,sha256=UKK3SaIZB2PCdKSIS0gnvMtLR9JJX62M-fZJu3OlWyg,3915
|
| 60 |
+
chardet/charsetprober.py,sha256=L3t8_wIOov8em-vZWOcbkdsrwe43N6_gqNh5pH7WPd4,5420
|
| 61 |
+
chardet/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 62 |
+
chardet/cli/__pycache__/__init__.cpython-312.pyc,,
|
| 63 |
+
chardet/cli/__pycache__/chardetect.cpython-312.pyc,,
|
| 64 |
+
chardet/cli/chardetect.py,sha256=zibMVg5RpKb-ME9_7EYG4ZM2Sf07NHcQzZ12U-rYJho,3242
|
| 65 |
+
chardet/codingstatemachine.py,sha256=K7k69sw3jY5DmTXoSJQVsUtFIQKYPQVOSJJhBuGv_yE,3732
|
| 66 |
+
chardet/codingstatemachinedict.py,sha256=0GY3Hi2qIZvDrOOJ3AtqppM1RsYxr_66ER4EHjuMiMc,542
|
| 67 |
+
chardet/cp949prober.py,sha256=0jKRV7fECuWI16rNnks0ZECKA1iZYCIEaP8A1ZvjUSI,1860
|
| 68 |
+
chardet/enums.py,sha256=TzECiZoCKNMqgwU76cPCeKWFBqaWvAdLMev5_bCkhY8,1683
|
| 69 |
+
chardet/escprober.py,sha256=Kho48X65xE0scFylIdeJjM2bcbvRvv0h0WUbMWrJD3A,4006
|
| 70 |
+
chardet/escsm.py,sha256=AqyXpA2FQFD7k-buBty_7itGEYkhmVa8X09NLRul3QM,12176
|
| 71 |
+
chardet/eucjpprober.py,sha256=5KYaM9fsxkRYzw1b5k0fL-j_-ezIw-ij9r97a9MHxLY,3934
|
| 72 |
+
chardet/euckrfreq.py,sha256=3mHuRvXfsq_QcQysDQFb8qSudvTiol71C6Ic2w57tKM,13566
|
| 73 |
+
chardet/euckrprober.py,sha256=hiFT6wM174GIwRvqDsIcuOc-dDsq2uPKMKbyV8-1Xnc,1753
|
| 74 |
+
chardet/euctwfreq.py,sha256=2alILE1Lh5eqiFJZjzRkMQXolNJRHY5oBQd-vmZYFFM,36913
|
| 75 |
+
chardet/euctwprober.py,sha256=NxbpNdBtU0VFI0bKfGfDkpP7S2_8_6FlO87dVH0ogws,1753
|
| 76 |
+
chardet/gb2312freq.py,sha256=49OrdXzD-HXqwavkqjo8Z7gvs58hONNzDhAyMENNkvY,20735
|
| 77 |
+
chardet/gb2312prober.py,sha256=KPEBueaSLSvBpFeINMu0D6TgHcR90e5PaQawifzF4o0,1759
|
| 78 |
+
chardet/hebrewprober.py,sha256=96T_Lj_OmW-fK7JrSHojYjyG3fsGgbzkoTNleZ3kfYE,14537
|
| 79 |
+
chardet/jisfreq.py,sha256=mm8tfrwqhpOd3wzZKS4NJqkYBQVcDfTM2JiQ5aW932E,25796
|
| 80 |
+
chardet/johabfreq.py,sha256=dBpOYG34GRX6SL8k_LbS9rxZPMjLjoMlgZ03Pz5Hmqc,42498
|
| 81 |
+
chardet/johabprober.py,sha256=O1Qw9nVzRnun7vZp4UZM7wvJSv9W941mEU9uDMnY3DU,1752
|
| 82 |
+
chardet/jpcntx.py,sha256=uhHrYWkLxE_rF5OkHKInm0HUsrjgKHHVQvtt3UcvotA,27055
|
| 83 |
+
chardet/langbulgarianmodel.py,sha256=bGoRpxBYtrbSHa6mX6PkEA26v30pWmhDjemhdxmkew8,104550
|
| 84 |
+
chardet/langgreekmodel.py,sha256=3wMlEzQ8oU2MbrL2xN8lkuOB0dCMLBhW6heekxusoc0,98472
|
| 85 |
+
chardet/langhebrewmodel.py,sha256=ZUTqusxMvR_earWPs5w-rH10xoe5sPjd9FLMu1DUIvE,98184
|
| 86 |
+
chardet/langhungarianmodel.py,sha256=N-YtC2EiswyS7XsUicCPRycrIzRNj47Y048odp9qOoo,101351
|
| 87 |
+
chardet/langrussianmodel.py,sha256=6v7RcZKGj0VH0864BHzizKNceAYbHvGts2p00ifC7w4,128023
|
| 88 |
+
chardet/langthaimodel.py,sha256=Mr673U9U8rkQFfUDtLP01pp-0TOsl2o6sb75YEjvpcs,102762
|
| 89 |
+
chardet/langturkishmodel.py,sha256=LkXCjWhGUEzqKXvfasHN0SFBigwKJ3xeWNVZ0EyI0kA,95360
|
| 90 |
+
chardet/latin1prober.py,sha256=p15EEmFbmQUwbKLC7lOJVGHEZwcG45ubEZYTGu01J5g,5380
|
| 91 |
+
chardet/macromanprober.py,sha256=9anfzmY6TBfUPDyBDOdY07kqmTHpZ1tK0jL-p1JWcOY,6077
|
| 92 |
+
chardet/mbcharsetprober.py,sha256=Wr04WNI4F3X_VxEverNG-H25g7u-MDDKlNt-JGj-_uU,3715
|
| 93 |
+
chardet/mbcsgroupprober.py,sha256=iRpaNBjV0DNwYPu_z6TiHgRpwYahiM7ztI_4kZ4Uz9A,2131
|
| 94 |
+
chardet/mbcssm.py,sha256=hUtPvDYgWDaA2dWdgLsshbwRfm3Q5YRlRogdmeRUNQw,30391
|
| 95 |
+
chardet/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 96 |
+
chardet/metadata/__pycache__/__init__.cpython-312.pyc,,
|
| 97 |
+
chardet/metadata/__pycache__/languages.cpython-312.pyc,,
|
| 98 |
+
chardet/metadata/languages.py,sha256=FhvBIdZFxRQ-dTwkb_0madRKgVBCaUMQz9I5xqjE5iQ,13560
|
| 99 |
+
chardet/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 100 |
+
chardet/resultdict.py,sha256=ez4FRvN5KaSosJeJ2WzUyKdDdg35HDy_SSLPXKCdt5M,402
|
| 101 |
+
chardet/sbcharsetprober.py,sha256=-nd3F90i7GpXLjehLVHqVBE0KlWzGvQUPETLBNn4o6U,6400
|
| 102 |
+
chardet/sbcsgroupprober.py,sha256=gcgI0fOfgw_3YTClpbra_MNxwyEyJ3eUXraoLHYb59E,4137
|
| 103 |
+
chardet/sjisprober.py,sha256=aqQufMzRw46ZpFlzmYaYeT2-nzmKb-hmcrApppJ862k,4007
|
| 104 |
+
chardet/universaldetector.py,sha256=xYBrg4x0dd9WnT8qclfADVD9ondrUNkqPmvte1pa520,14848
|
| 105 |
+
chardet/utf1632prober.py,sha256=pw1epGdMj1hDGiCu1AHqqzOEfjX8MVdiW7O1BlT8-eQ,8505
|
| 106 |
+
chardet/utf8prober.py,sha256=8m08Ub5490H4jQ6LYXvFysGtgKoKsHUd2zH_i8_TnVw,2812
|
| 107 |
+
chardet/version.py,sha256=jp8ePp1zC63YxruGcHSuKxtf3-fF1LYAMUZD2eDWYok,244
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.41.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
chardetect = chardet.cli.chardetect:main
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet-5.2.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
chardet
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2025 TAHRI Ahmed R.
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
Prism/LLaDA/LLaDA_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: charset-normalizer
|
| 3 |
+
Version: 3.4.1
|
| 4 |
+
Summary: The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet.
|
| 5 |
+
Author-email: "Ahmed R. TAHRI" <tahri.ahmed@proton.me>
|
| 6 |
+
Maintainer-email: "Ahmed R. TAHRI" <tahri.ahmed@proton.me>
|
| 7 |
+
License: MIT
|
| 8 |
+
Project-URL: Changelog, https://github.com/jawah/charset_normalizer/blob/master/CHANGELOG.md
|
| 9 |
+
Project-URL: Documentation, https://charset-normalizer.readthedocs.io/
|
| 10 |
+
Project-URL: Code, https://github.com/jawah/charset_normalizer
|
| 11 |
+
Project-URL: Issue tracker, https://github.com/jawah/charset_normalizer/issues
|
| 12 |
+
Keywords: encoding,charset,charset-detector,detector,normalization,unicode,chardet,detect
|
| 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
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 24 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 25 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 26 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 27 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 28 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 29 |
+
Classifier: Topic :: Text Processing :: Linguistic
|
| 30 |
+
Classifier: Topic :: Utilities
|
| 31 |
+
Classifier: Typing :: Typed
|
| 32 |
+
Requires-Python: >=3.7
|
| 33 |
+
Description-Content-Type: text/markdown
|
| 34 |
+
License-File: LICENSE
|
| 35 |
+
Provides-Extra: unicode-backport
|
| 36 |
+
|
| 37 |
+
<h1 align="center">Charset Detection, for Everyone 👋</h1>
|
| 38 |
+
|
| 39 |
+
<p align="center">
|
| 40 |
+
<sup>The Real First Universal Charset Detector</sup><br>
|
| 41 |
+
<a href="https://pypi.org/project/charset-normalizer">
|
| 42 |
+
<img src="https://img.shields.io/pypi/pyversions/charset_normalizer.svg?orange=blue" />
|
| 43 |
+
</a>
|
| 44 |
+
<a href="https://pepy.tech/project/charset-normalizer/">
|
| 45 |
+
<img alt="Download Count Total" src="https://static.pepy.tech/badge/charset-normalizer/month" />
|
| 46 |
+
</a>
|
| 47 |
+
<a href="https://bestpractices.coreinfrastructure.org/projects/7297">
|
| 48 |
+
<img src="https://bestpractices.coreinfrastructure.org/projects/7297/badge">
|
| 49 |
+
</a>
|
| 50 |
+
</p>
|
| 51 |
+
<p align="center">
|
| 52 |
+
<sup><i>Featured Packages</i></sup><br>
|
| 53 |
+
<a href="https://github.com/jawah/niquests">
|
| 54 |
+
<img alt="Static Badge" src="https://img.shields.io/badge/Niquests-Best_HTTP_Client-cyan">
|
| 55 |
+
</a>
|
| 56 |
+
<a href="https://github.com/jawah/wassima">
|
| 57 |
+
<img alt="Static Badge" src="https://img.shields.io/badge/Wassima-Certifi_Killer-cyan">
|
| 58 |
+
</a>
|
| 59 |
+
</p>
|
| 60 |
+
<p align="center">
|
| 61 |
+
<sup><i>In other language (unofficial port - by the community)</i></sup><br>
|
| 62 |
+
<a href="https://github.com/nickspring/charset-normalizer-rs">
|
| 63 |
+
<img alt="Static Badge" src="https://img.shields.io/badge/Rust-red">
|
| 64 |
+
</a>
|
| 65 |
+
</p>
|
| 66 |
+
|
| 67 |
+
> A library that helps you read text from an unknown charset encoding.<br /> Motivated by `chardet`,
|
| 68 |
+
> I'm trying to resolve the issue by taking a new approach.
|
| 69 |
+
> All IANA character set names for which the Python core library provides codecs are supported.
|
| 70 |
+
|
| 71 |
+
<p align="center">
|
| 72 |
+
>>>>> <a href="https://charsetnormalizerweb.ousret.now.sh" target="_blank">👉 Try Me Online Now, Then Adopt Me 👈 </a> <<<<<
|
| 73 |
+
</p>
|
| 74 |
+
|
| 75 |
+
This project offers you an alternative to **Universal Charset Encoding Detector**, also known as **Chardet**.
|
| 76 |
+
|
| 77 |
+
| Feature | [Chardet](https://github.com/chardet/chardet) | Charset Normalizer | [cChardet](https://github.com/PyYoshi/cChardet) |
|
| 78 |
+
|--------------------------------------------------|:---------------------------------------------:|:--------------------------------------------------------------------------------------------------:|:-----------------------------------------------:|
|
| 79 |
+
| `Fast` | ❌ | ✅ | ✅ |
|
| 80 |
+
| `Universal**` | ❌ | ✅ | ❌ |
|
| 81 |
+
| `Reliable` **without** distinguishable standards | ❌ | ✅ | ✅ |
|
| 82 |
+
| `Reliable` **with** distinguishable standards | ✅ | ✅ | ✅ |
|
| 83 |
+
| `License` | LGPL-2.1<br>_restrictive_ | MIT | MPL-1.1<br>_restrictive_ |
|
| 84 |
+
| `Native Python` | ✅ | ✅ | ❌ |
|
| 85 |
+
| `Detect spoken language` | ❌ | ✅ | N/A |
|
| 86 |
+
| `UnicodeDecodeError Safety` | ❌ | ✅ | ❌ |
|
| 87 |
+
| `Whl Size (min)` | 193.6 kB | 42 kB | ~200 kB |
|
| 88 |
+
| `Supported Encoding` | 33 | 🎉 [99](https://charset-normalizer.readthedocs.io/en/latest/user/support.html#supported-encodings) | 40 |
|
| 89 |
+
|
| 90 |
+
<p align="center">
|
| 91 |
+
<img src="https://i.imgflip.com/373iay.gif" alt="Reading Normalized Text" width="226"/><img src="https://media.tenor.com/images/c0180f70732a18b4965448d33adba3d0/tenor.gif" alt="Cat Reading Text" width="200"/>
|
| 92 |
+
</p>
|
| 93 |
+
|
| 94 |
+
*\*\* : They are clearly using specific code for a specific encoding even if covering most of used one*<br>
|
| 95 |
+
|
| 96 |
+
## ⚡ Performance
|
| 97 |
+
|
| 98 |
+
This package offer better performance than its counterpart Chardet. Here are some numbers.
|
| 99 |
+
|
| 100 |
+
| Package | Accuracy | Mean per file (ms) | File per sec (est) |
|
| 101 |
+
|-----------------------------------------------|:--------:|:------------------:|:------------------:|
|
| 102 |
+
| [chardet](https://github.com/chardet/chardet) | 86 % | 63 ms | 16 file/sec |
|
| 103 |
+
| charset-normalizer | **98 %** | **10 ms** | 100 file/sec |
|
| 104 |
+
|
| 105 |
+
| Package | 99th percentile | 95th percentile | 50th percentile |
|
| 106 |
+
|-----------------------------------------------|:---------------:|:---------------:|:---------------:|
|
| 107 |
+
| [chardet](https://github.com/chardet/chardet) | 265 ms | 71 ms | 7 ms |
|
| 108 |
+
| charset-normalizer | 100 ms | 50 ms | 5 ms |
|
| 109 |
+
|
| 110 |
+
_updated as of december 2024 using CPython 3.12_
|
| 111 |
+
|
| 112 |
+
Chardet's performance on larger file (1MB+) are very poor. Expect huge difference on large payload.
|
| 113 |
+
|
| 114 |
+
> Stats are generated using 400+ files using default parameters. More details on used files, see GHA workflows.
|
| 115 |
+
> And yes, these results might change at any time. The dataset can be updated to include more files.
|
| 116 |
+
> The actual delays heavily depends on your CPU capabilities. The factors should remain the same.
|
| 117 |
+
> Keep in mind that the stats are generous and that Chardet accuracy vs our is measured using Chardet initial capability
|
| 118 |
+
> (e.g. Supported Encoding) Challenge-them if you want.
|
| 119 |
+
|
| 120 |
+
## ✨ Installation
|
| 121 |
+
|
| 122 |
+
Using pip:
|
| 123 |
+
|
| 124 |
+
```sh
|
| 125 |
+
pip install charset-normalizer -U
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
## 🚀 Basic Usage
|
| 129 |
+
|
| 130 |
+
### CLI
|
| 131 |
+
This package comes with a CLI.
|
| 132 |
+
|
| 133 |
+
```
|
| 134 |
+
usage: normalizer [-h] [-v] [-a] [-n] [-m] [-r] [-f] [-t THRESHOLD]
|
| 135 |
+
file [file ...]
|
| 136 |
+
|
| 137 |
+
The Real First Universal Charset Detector. Discover originating encoding used
|
| 138 |
+
on text file. Normalize text to unicode.
|
| 139 |
+
|
| 140 |
+
positional arguments:
|
| 141 |
+
files File(s) to be analysed
|
| 142 |
+
|
| 143 |
+
optional arguments:
|
| 144 |
+
-h, --help show this help message and exit
|
| 145 |
+
-v, --verbose Display complementary information about file if any.
|
| 146 |
+
Stdout will contain logs about the detection process.
|
| 147 |
+
-a, --with-alternative
|
| 148 |
+
Output complementary possibilities if any. Top-level
|
| 149 |
+
JSON WILL be a list.
|
| 150 |
+
-n, --normalize Permit to normalize input file. If not set, program
|
| 151 |
+
does not write anything.
|
| 152 |
+
-m, --minimal Only output the charset detected to STDOUT. Disabling
|
| 153 |
+
JSON output.
|
| 154 |
+
-r, --replace Replace file when trying to normalize it instead of
|
| 155 |
+
creating a new one.
|
| 156 |
+
-f, --force Replace file without asking if you are sure, use this
|
| 157 |
+
flag with caution.
|
| 158 |
+
-t THRESHOLD, --threshold THRESHOLD
|
| 159 |
+
Define a custom maximum amount of chaos allowed in
|
| 160 |
+
decoded content. 0. <= chaos <= 1.
|
| 161 |
+
--version Show version information and exit.
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
```bash
|
| 165 |
+
normalizer ./data/sample.1.fr.srt
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
or
|
| 169 |
+
|
| 170 |
+
```bash
|
| 171 |
+
python -m charset_normalizer ./data/sample.1.fr.srt
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
🎉 Since version 1.4.0 the CLI produce easily usable stdout result in JSON format.
|
| 175 |
+
|
| 176 |
+
```json
|
| 177 |
+
{
|
| 178 |
+
"path": "/home/default/projects/charset_normalizer/data/sample.1.fr.srt",
|
| 179 |
+
"encoding": "cp1252",
|
| 180 |
+
"encoding_aliases": [
|
| 181 |
+
"1252",
|
| 182 |
+
"windows_1252"
|
| 183 |
+
],
|
| 184 |
+
"alternative_encodings": [
|
| 185 |
+
"cp1254",
|
| 186 |
+
"cp1256",
|
| 187 |
+
"cp1258",
|
| 188 |
+
"iso8859_14",
|
| 189 |
+
"iso8859_15",
|
| 190 |
+
"iso8859_16",
|
| 191 |
+
"iso8859_3",
|
| 192 |
+
"iso8859_9",
|
| 193 |
+
"latin_1",
|
| 194 |
+
"mbcs"
|
| 195 |
+
],
|
| 196 |
+
"language": "French",
|
| 197 |
+
"alphabets": [
|
| 198 |
+
"Basic Latin",
|
| 199 |
+
"Latin-1 Supplement"
|
| 200 |
+
],
|
| 201 |
+
"has_sig_or_bom": false,
|
| 202 |
+
"chaos": 0.149,
|
| 203 |
+
"coherence": 97.152,
|
| 204 |
+
"unicode_path": null,
|
| 205 |
+
"is_preferred": true
|
| 206 |
+
}
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
### Python
|
| 210 |
+
*Just print out normalized text*
|
| 211 |
+
```python
|
| 212 |
+
from charset_normalizer import from_path
|
| 213 |
+
|
| 214 |
+
results = from_path('./my_subtitle.srt')
|
| 215 |
+
|
| 216 |
+
print(str(results.best()))
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
*Upgrade your code without effort*
|
| 220 |
+
```python
|
| 221 |
+
from charset_normalizer import detect
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
The above code will behave the same as **chardet**. We ensure that we offer the best (reasonable) BC result possible.
|
| 225 |
+
|
| 226 |
+
See the docs for advanced usage : [readthedocs.io](https://charset-normalizer.readthedocs.io/en/latest/)
|
| 227 |
+
|
| 228 |
+
## 😇 Why
|
| 229 |
+
|
| 230 |
+
When I started using Chardet, I noticed that it was not suited to my expectations, and I wanted to propose a
|
| 231 |
+
reliable alternative using a completely different method. Also! I never back down on a good challenge!
|
| 232 |
+
|
| 233 |
+
I **don't care** about the **originating charset** encoding, because **two different tables** can
|
| 234 |
+
produce **two identical rendered string.**
|
| 235 |
+
What I want is to get readable text, the best I can.
|
| 236 |
+
|
| 237 |
+
In a way, **I'm brute forcing text decoding.** How cool is that ? 😎
|
| 238 |
+
|
| 239 |
+
Don't confuse package **ftfy** with charset-normalizer or chardet. ftfy goal is to repair Unicode string whereas charset-normalizer to convert raw file in unknown encoding to unicode.
|
| 240 |
+
|
| 241 |
+
## 🍰 How
|
| 242 |
+
|
| 243 |
+
- Discard all charset encoding table that could not fit the binary content.
|
| 244 |
+
- Measure noise, or the mess once opened (by chunks) with a corresponding charset encoding.
|
| 245 |
+
- Extract matches with the lowest mess detected.
|
| 246 |
+
- Additionally, we measure coherence / probe for a language.
|
| 247 |
+
|
| 248 |
+
**Wait a minute**, what is noise/mess and coherence according to **YOU ?**
|
| 249 |
+
|
| 250 |
+
*Noise :* I opened hundred of text files, **written by humans**, with the wrong encoding table. **I observed**, then
|
| 251 |
+
**I established** some ground rules about **what is obvious** when **it seems like** a mess (aka. defining noise in rendered text).
|
| 252 |
+
I know that my interpretation of what is noise is probably incomplete, feel free to contribute in order to
|
| 253 |
+
improve or rewrite it.
|
| 254 |
+
|
| 255 |
+
*Coherence :* For each language there is on earth, we have computed ranked letter appearance occurrences (the best we can). So I thought
|
| 256 |
+
that intel is worth something here. So I use those records against decoded text to check if I can detect intelligent design.
|
| 257 |
+
|
| 258 |
+
## ⚡ Known limitations
|
| 259 |
+
|
| 260 |
+
- Language detection is unreliable when text contains two or more languages sharing identical letters. (eg. HTML (english tags) + Turkish content (Sharing Latin characters))
|
| 261 |
+
- Every charset detector heavily depends on sufficient content. In common cases, do not bother run detection on very tiny content.
|
| 262 |
+
|
| 263 |
+
## ⚠️ About Python EOLs
|
| 264 |
+
|
| 265 |
+
**If you are running:**
|
| 266 |
+
|
| 267 |
+
- Python >=2.7,<3.5: Unsupported
|
| 268 |
+
- Python 3.5: charset-normalizer < 2.1
|
| 269 |
+
- Python 3.6: charset-normalizer < 3.1
|
| 270 |
+
- Python 3.7: charset-normalizer < 4.0
|
| 271 |
+
|
| 272 |
+
Upgrade your Python interpreter as soon as possible.
|
| 273 |
+
|
| 274 |
+
## 👤 Contributing
|
| 275 |
+
|
| 276 |
+
Contributions, issues and feature requests are very much welcome.<br />
|
| 277 |
+
Feel free to check [issues page](https://github.com/ousret/charset_normalizer/issues) if you want to contribute.
|
| 278 |
+
|
| 279 |
+
## 📝 License
|
| 280 |
+
|
| 281 |
+
Copyright © [Ahmed TAHRI @Ousret](https://github.com/Ousret).<br />
|
| 282 |
+
This project is [MIT](https://github.com/Ousret/charset_normalizer/blob/master/LICENSE) licensed.
|
| 283 |
+
|
| 284 |
+
Characters frequencies used in this project © 2012 [Denny Vrandečić](http://simia.net/letters/)
|
| 285 |
+
|
| 286 |
+
## 💼 For Enterprise
|
| 287 |
+
|
| 288 |
+
Professional support for charset-normalizer is available as part of the [Tidelift
|
| 289 |
+
Subscription][1]. Tidelift gives software development teams a single source for
|
| 290 |
+
purchasing and maintaining their software, with professional grade assurances
|
| 291 |
+
from the experts who know it best, while seamlessly integrating with existing
|
| 292 |
+
tools.
|
| 293 |
+
|
| 294 |
+
[1]: https://tidelift.com/subscription/pkg/pypi-charset-normalizer?utm_source=pypi-charset-normalizer&utm_medium=readme
|
| 295 |
+
|
| 296 |
+
[](https://www.bestpractices.dev/projects/7297)
|
| 297 |
+
|
| 298 |
+
# Changelog
|
| 299 |
+
All notable changes to charset-normalizer will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
| 300 |
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
| 301 |
+
|
| 302 |
+
## [3.4.1](https://github.com/Ousret/charset_normalizer/compare/3.4.0...3.4.1) (2024-12-24)
|
| 303 |
+
|
| 304 |
+
### Changed
|
| 305 |
+
- Project metadata are now stored using `pyproject.toml` instead of `setup.cfg` using setuptools as the build backend.
|
| 306 |
+
- Enforce annotation delayed loading for a simpler and consistent types in the project.
|
| 307 |
+
- Optional mypyc compilation upgraded to version 1.14 for Python >= 3.8
|
| 308 |
+
|
| 309 |
+
### Added
|
| 310 |
+
- pre-commit configuration.
|
| 311 |
+
- noxfile.
|
| 312 |
+
|
| 313 |
+
### Removed
|
| 314 |
+
- `build-requirements.txt` as per using `pyproject.toml` native build configuration.
|
| 315 |
+
- `bin/integration.py` and `bin/serve.py` in favor of downstream integration test (see noxfile).
|
| 316 |
+
- `setup.cfg` in favor of `pyproject.toml` metadata configuration.
|
| 317 |
+
- Unused `utils.range_scan` function.
|
| 318 |
+
|
| 319 |
+
### Fixed
|
| 320 |
+
- Converting content to Unicode bytes may insert `utf_8` instead of preferred `utf-8`. (#572)
|
| 321 |
+
- Deprecation warning "'count' is passed as positional argument" when converting to Unicode bytes on Python 3.13+
|
| 322 |
+
|
| 323 |
+
## [3.4.0](https://github.com/Ousret/charset_normalizer/compare/3.3.2...3.4.0) (2024-10-08)
|
| 324 |
+
|
| 325 |
+
### Added
|
| 326 |
+
- Argument `--no-preemptive` in the CLI to prevent the detector to search for hints.
|
| 327 |
+
- Support for Python 3.13 (#512)
|
| 328 |
+
|
| 329 |
+
### Fixed
|
| 330 |
+
- Relax the TypeError exception thrown when trying to compare a CharsetMatch with anything else than a CharsetMatch.
|
| 331 |
+
- Improved the general reliability of the detector based on user feedbacks. (#520) (#509) (#498) (#407) (#537)
|
| 332 |
+
- Declared charset in content (preemptive detection) not changed when converting to utf-8 bytes. (#381)
|
| 333 |
+
|
| 334 |
+
## [3.3.2](https://github.com/Ousret/charset_normalizer/compare/3.3.1...3.3.2) (2023-10-31)
|
| 335 |
+
|
| 336 |
+
### Fixed
|
| 337 |
+
- Unintentional memory usage regression when using large payload that match several encoding (#376)
|
| 338 |
+
- Regression on some detection case showcased in the documentation (#371)
|
| 339 |
+
|
| 340 |
+
### Added
|
| 341 |
+
- Noise (md) probe that identify malformed arabic representation due to the presence of letters in isolated form (credit to my wife)
|
| 342 |
+
|
| 343 |
+
## [3.3.1](https://github.com/Ousret/charset_normalizer/compare/3.3.0...3.3.1) (2023-10-22)
|
| 344 |
+
|
| 345 |
+
### Changed
|
| 346 |
+
- Optional mypyc compilation upgraded to version 1.6.1 for Python >= 3.8
|
| 347 |
+
- Improved the general detection reliability based on reports from the community
|
| 348 |
+
|
| 349 |
+
## [3.3.0](https://github.com/Ousret/charset_normalizer/compare/3.2.0...3.3.0) (2023-09-30)
|
| 350 |
+
|
| 351 |
+
### Added
|
| 352 |
+
- Allow to execute the CLI (e.g. normalizer) through `python -m charset_normalizer.cli` or `python -m charset_normalizer`
|
| 353 |
+
- Support for 9 forgotten encoding that are supported by Python but unlisted in `encoding.aliases` as they have no alias (#323)
|
| 354 |
+
|
| 355 |
+
### Removed
|
| 356 |
+
- (internal) Redundant utils.is_ascii function and unused function is_private_use_only
|
| 357 |
+
- (internal) charset_normalizer.assets is moved inside charset_normalizer.constant
|
| 358 |
+
|
| 359 |
+
### Changed
|
| 360 |
+
- (internal) Unicode code blocks in constants are updated using the latest v15.0.0 definition to improve detection
|
| 361 |
+
- Optional mypyc compilation upgraded to version 1.5.1 for Python >= 3.8
|
| 362 |
+
|
| 363 |
+
### Fixed
|
| 364 |
+
- Unable to properly sort CharsetMatch when both chaos/noise and coherence were close due to an unreachable condition in \_\_lt\_\_ (#350)
|
| 365 |
+
|
| 366 |
+
## [3.2.0](https://github.com/Ousret/charset_normalizer/compare/3.1.0...3.2.0) (2023-06-07)
|
| 367 |
+
|
| 368 |
+
### Changed
|
| 369 |
+
- Typehint for function `from_path` no longer enforce `PathLike` as its first argument
|
| 370 |
+
- Minor improvement over the global detection reliability
|
| 371 |
+
|
| 372 |
+
### Added
|
| 373 |
+
- Introduce function `is_binary` that relies on main capabilities, and optimized to detect binaries
|
| 374 |
+
- Propagate `enable_fallback` argument throughout `from_bytes`, `from_path`, and `from_fp` that allow a deeper control over the detection (default True)
|
| 375 |
+
- Explicit support for Python 3.12
|
| 376 |
+
|
| 377 |
+
### Fixed
|
| 378 |
+
- Edge case detection failure where a file would contain 'very-long' camel cased word (Issue #289)
|
| 379 |
+
|
| 380 |
+
## [3.1.0](https://github.com/Ousret/charset_normalizer/compare/3.0.1...3.1.0) (2023-03-06)
|
| 381 |
+
|
| 382 |
+
### Added
|
| 383 |
+
- Argument `should_rename_legacy` for legacy function `detect` and disregard any new arguments without errors (PR #262)
|
| 384 |
+
|
| 385 |
+
### Removed
|
| 386 |
+
- Support for Python 3.6 (PR #260)
|
| 387 |
+
|
| 388 |
+
### Changed
|
| 389 |
+
- Optional speedup provided by mypy/c 1.0.1
|
| 390 |
+
|
| 391 |
+
## [3.0.1](https://github.com/Ousret/charset_normalizer/compare/3.0.0...3.0.1) (2022-11-18)
|
| 392 |
+
|
| 393 |
+
### Fixed
|
| 394 |
+
- Multi-bytes cutter/chunk generator did not always cut correctly (PR #233)
|
| 395 |
+
|
| 396 |
+
### Changed
|
| 397 |
+
- Speedup provided by mypy/c 0.990 on Python >= 3.7
|
| 398 |
+
|
| 399 |
+
## [3.0.0](https://github.com/Ousret/charset_normalizer/compare/2.1.1...3.0.0) (2022-10-20)
|
| 400 |
+
|
| 401 |
+
### Added
|
| 402 |
+
- Extend the capability of explain=True when cp_isolation contains at most two entries (min one), will log in details of the Mess-detector results
|
| 403 |
+
- Support for alternative language frequency set in charset_normalizer.assets.FREQUENCIES
|
| 404 |
+
- Add parameter `language_threshold` in `from_bytes`, `from_path` and `from_fp` to adjust the minimum expected coherence ratio
|
| 405 |
+
- `normalizer --version` now specify if current version provide extra speedup (meaning mypyc compilation whl)
|
| 406 |
+
|
| 407 |
+
### Changed
|
| 408 |
+
- Build with static metadata using 'build' frontend
|
| 409 |
+
- Make the language detection stricter
|
| 410 |
+
- Optional: Module `md.py` can be compiled using Mypyc to provide an extra speedup up to 4x faster than v2.1
|
| 411 |
+
|
| 412 |
+
### Fixed
|
| 413 |
+
- CLI with opt --normalize fail when using full path for files
|
| 414 |
+
- TooManyAccentuatedPlugin induce false positive on the mess detection when too few alpha character have been fed to it
|
| 415 |
+
- Sphinx warnings when generating the documentation
|
| 416 |
+
|
| 417 |
+
### Removed
|
| 418 |
+
- Coherence detector no longer return 'Simple English' instead return 'English'
|
| 419 |
+
- Coherence detector no longer return 'Classical Chinese' instead return 'Chinese'
|
| 420 |
+
- Breaking: Method `first()` and `best()` from CharsetMatch
|
| 421 |
+
- UTF-7 will no longer appear as "detected" without a recognized SIG/mark (is unreliable/conflict with ASCII)
|
| 422 |
+
- Breaking: Class aliases CharsetDetector, CharsetDoctor, CharsetNormalizerMatch and CharsetNormalizerMatches
|
| 423 |
+
- Breaking: Top-level function `normalize`
|
| 424 |
+
- Breaking: Properties `chaos_secondary_pass`, `coherence_non_latin` and `w_counter` from CharsetMatch
|
| 425 |
+
- Support for the backport `unicodedata2`
|
| 426 |
+
|
| 427 |
+
## [3.0.0rc1](https://github.com/Ousret/charset_normalizer/compare/3.0.0b2...3.0.0rc1) (2022-10-18)
|
| 428 |
+
|
| 429 |
+
### Added
|
| 430 |
+
- Extend the capability of explain=True when cp_isolation contains at most two entries (min one), will log in details of the Mess-detector results
|
| 431 |
+
- Support for alternative language frequency set in charset_normalizer.assets.FREQUENCIES
|
| 432 |
+
- Add parameter `language_threshold` in `from_bytes`, `from_path` and `from_fp` to adjust the minimum expected coherence ratio
|
| 433 |
+
|
| 434 |
+
### Changed
|
| 435 |
+
- Build with static metadata using 'build' frontend
|
| 436 |
+
- Make the language detection stricter
|
| 437 |
+
|
| 438 |
+
### Fixed
|
| 439 |
+
- CLI with opt --normalize fail when using full path for files
|
| 440 |
+
- TooManyAccentuatedPlugin induce false positive on the mess detection when too few alpha character have been fed to it
|
| 441 |
+
|
| 442 |
+
### Removed
|
| 443 |
+
- Coherence detector no longer return 'Simple English' instead return 'English'
|
| 444 |
+
- Coherence detector no longer return 'Classical Chinese' instead return 'Chinese'
|
| 445 |
+
|
| 446 |
+
## [3.0.0b2](https://github.com/Ousret/charset_normalizer/compare/3.0.0b1...3.0.0b2) (2022-08-21)
|
| 447 |
+
|
| 448 |
+
### Added
|
| 449 |
+
- `normalizer --version` now specify if current version provide extra speedup (meaning mypyc compilation whl)
|
| 450 |
+
|
| 451 |
+
### Removed
|
| 452 |
+
- Breaking: Method `first()` and `best()` from CharsetMatch
|
| 453 |
+
- UTF-7 will no longer appear as "detected" without a recognized SIG/mark (is unreliable/conflict with ASCII)
|
| 454 |
+
|
| 455 |
+
### Fixed
|
| 456 |
+
- Sphinx warnings when generating the documentation
|
| 457 |
+
|
| 458 |
+
## [3.0.0b1](https://github.com/Ousret/charset_normalizer/compare/2.1.0...3.0.0b1) (2022-08-15)
|
| 459 |
+
|
| 460 |
+
### Changed
|
| 461 |
+
- Optional: Module `md.py` can be compiled using Mypyc to provide an extra speedup up to 4x faster than v2.1
|
| 462 |
+
|
| 463 |
+
### Removed
|
| 464 |
+
- Breaking: Class aliases CharsetDetector, CharsetDoctor, CharsetNormalizerMatch and CharsetNormalizerMatches
|
| 465 |
+
- Breaking: Top-level function `normalize`
|
| 466 |
+
- Breaking: Properties `chaos_secondary_pass`, `coherence_non_latin` and `w_counter` from CharsetMatch
|
| 467 |
+
- Support for the backport `unicodedata2`
|
| 468 |
+
|
| 469 |
+
## [2.1.1](https://github.com/Ousret/charset_normalizer/compare/2.1.0...2.1.1) (2022-08-19)
|
| 470 |
+
|
| 471 |
+
### Deprecated
|
| 472 |
+
- Function `normalize` scheduled for removal in 3.0
|
| 473 |
+
|
| 474 |
+
### Changed
|
| 475 |
+
- Removed useless call to decode in fn is_unprintable (#206)
|
| 476 |
+
|
| 477 |
+
### Fixed
|
| 478 |
+
- Third-party library (i18n xgettext) crashing not recognizing utf_8 (PEP 263) with underscore from [@aleksandernovikov](https://github.com/aleksandernovikov) (#204)
|
| 479 |
+
|
| 480 |
+
## [2.1.0](https://github.com/Ousret/charset_normalizer/compare/2.0.12...2.1.0) (2022-06-19)
|
| 481 |
+
|
| 482 |
+
### Added
|
| 483 |
+
- Output the Unicode table version when running the CLI with `--version` (PR #194)
|
| 484 |
+
|
| 485 |
+
### Changed
|
| 486 |
+
- Re-use decoded buffer for single byte character sets from [@nijel](https://github.com/nijel) (PR #175)
|
| 487 |
+
- Fixing some performance bottlenecks from [@deedy5](https://github.com/deedy5) (PR #183)
|
| 488 |
+
|
| 489 |
+
### Fixed
|
| 490 |
+
- Workaround potential bug in cpython with Zero Width No-Break Space located in Arabic Presentation Forms-B, Unicode 1.1 not acknowledged as space (PR #175)
|
| 491 |
+
- CLI default threshold aligned with the API threshold from [@oleksandr-kuzmenko](https://github.com/oleksandr-kuzmenko) (PR #181)
|
| 492 |
+
|
| 493 |
+
### Removed
|
| 494 |
+
- Support for Python 3.5 (PR #192)
|
| 495 |
+
|
| 496 |
+
### Deprecated
|
| 497 |
+
- Use of backport unicodedata from `unicodedata2` as Python is quickly catching up, scheduled for removal in 3.0 (PR #194)
|
| 498 |
+
|
| 499 |
+
## [2.0.12](https://github.com/Ousret/charset_normalizer/compare/2.0.11...2.0.12) (2022-02-12)
|
| 500 |
+
|
| 501 |
+
### Fixed
|
| 502 |
+
- ASCII miss-detection on rare cases (PR #170)
|
| 503 |
+
|
| 504 |
+
## [2.0.11](https://github.com/Ousret/charset_normalizer/compare/2.0.10...2.0.11) (2022-01-30)
|
| 505 |
+
|
| 506 |
+
### Added
|
| 507 |
+
- Explicit support for Python 3.11 (PR #164)
|
| 508 |
+
|
| 509 |
+
### Changed
|
| 510 |
+
- The logging behavior have been completely reviewed, now using only TRACE and DEBUG levels (PR #163 #165)
|
| 511 |
+
|
| 512 |
+
## [2.0.10](https://github.com/Ousret/charset_normalizer/compare/2.0.9...2.0.10) (2022-01-04)
|
| 513 |
+
|
| 514 |
+
### Fixed
|
| 515 |
+
- Fallback match entries might lead to UnicodeDecodeError for large bytes sequence (PR #154)
|
| 516 |
+
|
| 517 |
+
### Changed
|
| 518 |
+
- Skipping the language-detection (CD) on ASCII (PR #155)
|
| 519 |
+
|
| 520 |
+
## [2.0.9](https://github.com/Ousret/charset_normalizer/compare/2.0.8...2.0.9) (2021-12-03)
|
| 521 |
+
|
| 522 |
+
### Changed
|
| 523 |
+
- Moderating the logging impact (since 2.0.8) for specific environments (PR #147)
|
| 524 |
+
|
| 525 |
+
### Fixed
|
| 526 |
+
- Wrong logging level applied when setting kwarg `explain` to True (PR #146)
|
| 527 |
+
|
| 528 |
+
## [2.0.8](https://github.com/Ousret/charset_normalizer/compare/2.0.7...2.0.8) (2021-11-24)
|
| 529 |
+
### Changed
|
| 530 |
+
- Improvement over Vietnamese detection (PR #126)
|
| 531 |
+
- MD improvement on trailing data and long foreign (non-pure latin) data (PR #124)
|
| 532 |
+
- Efficiency improvements in cd/alphabet_languages from [@adbar](https://github.com/adbar) (PR #122)
|
| 533 |
+
- call sum() without an intermediary list following PEP 289 recommendations from [@adbar](https://github.com/adbar) (PR #129)
|
| 534 |
+
- Code style as refactored by Sourcery-AI (PR #131)
|
| 535 |
+
- Minor adjustment on the MD around european words (PR #133)
|
| 536 |
+
- Remove and replace SRTs from assets / tests (PR #139)
|
| 537 |
+
- Initialize the library logger with a `NullHandler` by default from [@nmaynes](https://github.com/nmaynes) (PR #135)
|
| 538 |
+
- Setting kwarg `explain` to True will add provisionally (bounded to function lifespan) a specific stream handler (PR #135)
|
| 539 |
+
|
| 540 |
+
### Fixed
|
| 541 |
+
- Fix large (misleading) sequence giving UnicodeDecodeError (PR #137)
|
| 542 |
+
- Avoid using too insignificant chunk (PR #137)
|
| 543 |
+
|
| 544 |
+
### Added
|
| 545 |
+
- Add and expose function `set_logging_handler` to configure a specific StreamHandler from [@nmaynes](https://github.com/nmaynes) (PR #135)
|
| 546 |
+
- Add `CHANGELOG.md` entries, format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) (PR #141)
|
| 547 |
+
|
| 548 |
+
## [2.0.7](https://github.com/Ousret/charset_normalizer/compare/2.0.6...2.0.7) (2021-10-11)
|
| 549 |
+
### Added
|
| 550 |
+
- Add support for Kazakh (Cyrillic) language detection (PR #109)
|
| 551 |
+
|
| 552 |
+
### Changed
|
| 553 |
+
- Further, improve inferring the language from a given single-byte code page (PR #112)
|
| 554 |
+
- Vainly trying to leverage PEP263 when PEP3120 is not supported (PR #116)
|
| 555 |
+
- Refactoring for potential performance improvements in loops from [@adbar](https://github.com/adbar) (PR #113)
|
| 556 |
+
- Various detection improvement (MD+CD) (PR #117)
|
| 557 |
+
|
| 558 |
+
### Removed
|
| 559 |
+
- Remove redundant logging entry about detected language(s) (PR #115)
|
| 560 |
+
|
| 561 |
+
### Fixed
|
| 562 |
+
- Fix a minor inconsistency between Python 3.5 and other versions regarding language detection (PR #117 #102)
|
| 563 |
+
|
| 564 |
+
## [2.0.6](https://github.com/Ousret/charset_normalizer/compare/2.0.5...2.0.6) (2021-09-18)
|
| 565 |
+
### Fixed
|
| 566 |
+
- Unforeseen regression with the loss of the backward-compatibility with some older minor of Python 3.5.x (PR #100)
|
| 567 |
+
- Fix CLI crash when using --minimal output in certain cases (PR #103)
|
| 568 |
+
|
| 569 |
+
### Changed
|
| 570 |
+
- Minor improvement to the detection efficiency (less than 1%) (PR #106 #101)
|
| 571 |
+
|
| 572 |
+
## [2.0.5](https://github.com/Ousret/charset_normalizer/compare/2.0.4...2.0.5) (2021-09-14)
|
| 573 |
+
### Changed
|
| 574 |
+
- The project now comply with: flake8, mypy, isort and black to ensure a better overall quality (PR #81)
|
| 575 |
+
- The BC-support with v1.x was improved, the old staticmethods are restored (PR #82)
|
| 576 |
+
- The Unicode detection is slightly improved (PR #93)
|
| 577 |
+
- Add syntax sugar \_\_bool\_\_ for results CharsetMatches list-container (PR #91)
|
| 578 |
+
|
| 579 |
+
### Removed
|
| 580 |
+
- The project no longer raise warning on tiny content given for detection, will be simply logged as warning instead (PR #92)
|
| 581 |
+
|
| 582 |
+
### Fixed
|
| 583 |
+
- In some rare case, the chunks extractor could cut in the middle of a multi-byte character and could mislead the mess detection (PR #95)
|
| 584 |
+
- Some rare 'space' characters could trip up the UnprintablePlugin/Mess detection (PR #96)
|
| 585 |
+
- The MANIFEST.in was not exhaustive (PR #78)
|
| 586 |
+
|
| 587 |
+
## [2.0.4](https://github.com/Ousret/charset_normalizer/compare/2.0.3...2.0.4) (2021-07-30)
|
| 588 |
+
### Fixed
|
| 589 |
+
- The CLI no longer raise an unexpected exception when no encoding has been found (PR #70)
|
| 590 |
+
- Fix accessing the 'alphabets' property when the payload contains surrogate characters (PR #68)
|
| 591 |
+
- The logger could mislead (explain=True) on detected languages and the impact of one MBCS match (PR #72)
|
| 592 |
+
- Submatch factoring could be wrong in rare edge cases (PR #72)
|
| 593 |
+
- Multiple files given to the CLI were ignored when publishing results to STDOUT. (After the first path) (PR #72)
|
| 594 |
+
- Fix line endings from CRLF to LF for certain project files (PR #67)
|
| 595 |
+
|
| 596 |
+
### Changed
|
| 597 |
+
- Adjust the MD to lower the sensitivity, thus improving the global detection reliability (PR #69 #76)
|
| 598 |
+
- Allow fallback on specified encoding if any (PR #71)
|
| 599 |
+
|
| 600 |
+
## [2.0.3](https://github.com/Ousret/charset_normalizer/compare/2.0.2...2.0.3) (2021-07-16)
|
| 601 |
+
### Changed
|
| 602 |
+
- Part of the detection mechanism has been improved to be less sensitive, resulting in more accurate detection results. Especially ASCII. (PR #63)
|
| 603 |
+
- According to the community wishes, the detection will fall back on ASCII or UTF-8 in a last-resort case. (PR #64)
|
| 604 |
+
|
| 605 |
+
## [2.0.2](https://github.com/Ousret/charset_normalizer/compare/2.0.1...2.0.2) (2021-07-15)
|
| 606 |
+
### Fixed
|
| 607 |
+
- Empty/Too small JSON payload miss-detection fixed. Report from [@tseaver](https://github.com/tseaver) (PR #59)
|
| 608 |
+
|
| 609 |
+
### Changed
|
| 610 |
+
- Don't inject unicodedata2 into sys.modules from [@akx](https://github.com/akx) (PR #57)
|
| 611 |
+
|
| 612 |
+
## [2.0.1](https://github.com/Ousret/charset_normalizer/compare/2.0.0...2.0.1) (2021-07-13)
|
| 613 |
+
### Fixed
|
| 614 |
+
- Make it work where there isn't a filesystem available, dropping assets frequencies.json. Report from [@sethmlarson](https://github.com/sethmlarson). (PR #55)
|
| 615 |
+
- Using explain=False permanently disable the verbose output in the current runtime (PR #47)
|
| 616 |
+
- One log entry (language target preemptive) was not show in logs when using explain=True (PR #47)
|
| 617 |
+
- Fix undesired exception (ValueError) on getitem of instance CharsetMatches (PR #52)
|
| 618 |
+
|
| 619 |
+
### Changed
|
| 620 |
+
- Public function normalize default args values were not aligned with from_bytes (PR #53)
|
| 621 |
+
|
| 622 |
+
### Added
|
| 623 |
+
- You may now use charset aliases in cp_isolation and cp_exclusion arguments (PR #47)
|
| 624 |
+
|
| 625 |
+
## [2.0.0](https://github.com/Ousret/charset_normalizer/compare/1.4.1...2.0.0) (2021-07-02)
|
| 626 |
+
### Changed
|
| 627 |
+
- 4x to 5 times faster than the previous 1.4.0 release. At least 2x faster than Chardet.
|
| 628 |
+
- Accent has been made on UTF-8 detection, should perform rather instantaneous.
|
| 629 |
+
- The backward compatibility with Chardet has been greatly improved. The legacy detect function returns an identical charset name whenever possible.
|
| 630 |
+
- The detection mechanism has been slightly improved, now Turkish content is detected correctly (most of the time)
|
| 631 |
+
- The program has been rewritten to ease the readability and maintainability. (+Using static typing)+
|
| 632 |
+
- utf_7 detection has been reinstated.
|
| 633 |
+
|
| 634 |
+
### Removed
|
| 635 |
+
- This package no longer require anything when used with Python 3.5 (Dropped cached_property)
|
| 636 |
+
- Removed support for these languages: Catalan, Esperanto, Kazakh, Baque, Volapük, Azeri, Galician, Nynorsk, Macedonian, and Serbocroatian.
|
| 637 |
+
- The exception hook on UnicodeDecodeError has been removed.
|
| 638 |
+
|
| 639 |
+
### Deprecated
|
| 640 |
+
- Methods coherence_non_latin, w_counter, chaos_secondary_pass of the class CharsetMatch are now deprecated and scheduled for removal in v3.0
|
| 641 |
+
|
| 642 |
+
### Fixed
|
| 643 |
+
- The CLI output used the relative path of the file(s). Should be absolute.
|
| 644 |
+
|
| 645 |
+
## [1.4.1](https://github.com/Ousret/charset_normalizer/compare/1.4.0...1.4.1) (2021-05-28)
|
| 646 |
+
### Fixed
|
| 647 |
+
- Logger configuration/usage no longer conflict with others (PR #44)
|
| 648 |
+
|
| 649 |
+
## [1.4.0](https://github.com/Ousret/charset_normalizer/compare/1.3.9...1.4.0) (2021-05-21)
|
| 650 |
+
### Removed
|
| 651 |
+
- Using standard logging instead of using the package loguru.
|
| 652 |
+
- Dropping nose test framework in favor of the maintained pytest.
|
| 653 |
+
- Choose to not use dragonmapper package to help with gibberish Chinese/CJK text.
|
| 654 |
+
- Require cached_property only for Python 3.5 due to constraint. Dropping for every other interpreter version.
|
| 655 |
+
- Stop support for UTF-7 that does not contain a SIG.
|
| 656 |
+
- Dropping PrettyTable, replaced with pure JSON output in CLI.
|
| 657 |
+
|
| 658 |
+
### Fixed
|
| 659 |
+
- BOM marker in a CharsetNormalizerMatch instance could be False in rare cases even if obviously present. Due to the sub-match factoring process.
|
| 660 |
+
- Not searching properly for the BOM when trying utf32/16 parent codec.
|
| 661 |
+
|
| 662 |
+
### Changed
|
| 663 |
+
- Improving the package final size by compressing frequencies.json.
|
| 664 |
+
- Huge improvement over the larges payload.
|
| 665 |
+
|
| 666 |
+
### Added
|
| 667 |
+
- CLI now produces JSON consumable output.
|
| 668 |
+
- Return ASCII if given sequences fit. Given reasonable confidence.
|
| 669 |
+
|
| 670 |
+
## [1.3.9](https://github.com/Ousret/charset_normalizer/compare/1.3.8...1.3.9) (2021-05-13)
|
| 671 |
+
|
| 672 |
+
### Fixed
|
| 673 |
+
- In some very rare cases, you may end up getting encode/decode errors due to a bad bytes payload (PR #40)
|
| 674 |
+
|
| 675 |
+
## [1.3.8](https://github.com/Ousret/charset_normalizer/compare/1.3.7...1.3.8) (2021-05-12)
|
| 676 |
+
|
| 677 |
+
### Fixed
|
| 678 |
+
- Empty given payload for detection may cause an exception if trying to access the `alphabets` property. (PR #39)
|
| 679 |
+
|
| 680 |
+
## [1.3.7](https://github.com/Ousret/charset_normalizer/compare/1.3.6...1.3.7) (2021-05-12)
|
| 681 |
+
|
| 682 |
+
### Fixed
|
| 683 |
+
- The legacy detect function should return UTF-8-SIG if sig is present in the payload. (PR #38)
|
| 684 |
+
|
| 685 |
+
## [1.3.6](https://github.com/Ousret/charset_normalizer/compare/1.3.5...1.3.6) (2021-02-09)
|
| 686 |
+
|
| 687 |
+
### Changed
|
| 688 |
+
- Amend the previous release to allow prettytable 2.0 (PR #35)
|
| 689 |
+
|
| 690 |
+
## [1.3.5](https://github.com/Ousret/charset_normalizer/compare/1.3.4...1.3.5) (2021-02-08)
|
| 691 |
+
|
| 692 |
+
### Fixed
|
| 693 |
+
- Fix error while using the package with a python pre-release interpreter (PR #33)
|
| 694 |
+
|
| 695 |
+
### Changed
|
| 696 |
+
- Dependencies refactoring, constraints revised.
|
| 697 |
+
|
| 698 |
+
### Added
|
| 699 |
+
- Add python 3.9 and 3.10 to the supported interpreters
|
| 700 |
+
|
| 701 |
+
MIT License
|
| 702 |
+
|
| 703 |
+
Copyright (c) 2025 TAHRI Ahmed R.
|
| 704 |
+
|
| 705 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 706 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 707 |
+
in the Software without restriction, including without limitation the rights
|
| 708 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 709 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 710 |
+
furnished to do so, subject to the following conditions:
|
| 711 |
+
|
| 712 |
+
The above copyright notice and this permission notice shall be included in all
|
| 713 |
+
copies or substantial portions of the Software.
|
| 714 |
+
|
| 715 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 716 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 717 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 718 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 719 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 720 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 721 |
+
SOFTWARE.
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/RECORD
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../bin/normalizer,sha256=dS9CpoIp7DdErdYWMrC094xlTqSiRIbBea6USTqwiBE,288
|
| 2 |
+
charset_normalizer-3.4.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 3 |
+
charset_normalizer-3.4.1.dist-info/LICENSE,sha256=bQ1Bv-FwrGx9wkjJpj4lTQ-0WmDVCoJX0K-SxuJJuIc,1071
|
| 4 |
+
charset_normalizer-3.4.1.dist-info/METADATA,sha256=JbyHzhmqZh_ugEn1Y7TY7CDYZA9FoU6BP25hrCNDf50,35313
|
| 5 |
+
charset_normalizer-3.4.1.dist-info/RECORD,,
|
| 6 |
+
charset_normalizer-3.4.1.dist-info/WHEEL,sha256=tRzqFuK6eFjpbf2xTNvU7E3xL2y00S_NWJvyqxej3BA,151
|
| 7 |
+
charset_normalizer-3.4.1.dist-info/entry_points.txt,sha256=8C-Y3iXIfyXQ83Tpir2B8t-XLJYpxF5xbb38d_js-h4,65
|
| 8 |
+
charset_normalizer-3.4.1.dist-info/top_level.txt,sha256=7ASyzePr8_xuZWJsnqJjIBtyV8vhEo0wBCv1MPRRi3Q,19
|
| 9 |
+
charset_normalizer/__init__.py,sha256=OKRxRv2Zhnqk00tqkN0c1BtJjm165fWXLydE52IKuHc,1590
|
| 10 |
+
charset_normalizer/__main__.py,sha256=yzYxMR-IhKRHYwcSlavEv8oGdwxsR89mr2X09qXGdps,109
|
| 11 |
+
charset_normalizer/__pycache__/__init__.cpython-312.pyc,,
|
| 12 |
+
charset_normalizer/__pycache__/__main__.cpython-312.pyc,,
|
| 13 |
+
charset_normalizer/__pycache__/api.cpython-312.pyc,,
|
| 14 |
+
charset_normalizer/__pycache__/cd.cpython-312.pyc,,
|
| 15 |
+
charset_normalizer/__pycache__/constant.cpython-312.pyc,,
|
| 16 |
+
charset_normalizer/__pycache__/legacy.cpython-312.pyc,,
|
| 17 |
+
charset_normalizer/__pycache__/md.cpython-312.pyc,,
|
| 18 |
+
charset_normalizer/__pycache__/models.cpython-312.pyc,,
|
| 19 |
+
charset_normalizer/__pycache__/utils.cpython-312.pyc,,
|
| 20 |
+
charset_normalizer/__pycache__/version.cpython-312.pyc,,
|
| 21 |
+
charset_normalizer/api.py,sha256=qBRz8mJ_R5E713R6TOyqHEdnmyxbEDnCSHvx32ubDGg,22617
|
| 22 |
+
charset_normalizer/cd.py,sha256=WKTo1HDb-H9HfCDc3Bfwq5jzS25Ziy9SE2a74SgTq88,12522
|
| 23 |
+
charset_normalizer/cli/__init__.py,sha256=D8I86lFk2-py45JvqxniTirSj_sFyE6sjaY_0-G1shc,136
|
| 24 |
+
charset_normalizer/cli/__main__.py,sha256=VGC9klOoi6_R2z8rmyrc936kv7u2A1udjjHtlmNPDTM,10410
|
| 25 |
+
charset_normalizer/cli/__pycache__/__init__.cpython-312.pyc,,
|
| 26 |
+
charset_normalizer/cli/__pycache__/__main__.cpython-312.pyc,,
|
| 27 |
+
charset_normalizer/constant.py,sha256=4VuTcZNLew1j_8ixA-Rt_VVqNWD4pwgHOHMCMlr0964,40477
|
| 28 |
+
charset_normalizer/legacy.py,sha256=yhNXsPHkBfqPXKRb-sPXNj3Bscp9-mFGcYOkJ62tg9c,2328
|
| 29 |
+
charset_normalizer/md.cpython-312-x86_64-linux-gnu.so,sha256=W654QTU3QZI6eWJ0fanScAr0_O6sL0I61fyRSdC-39Y,16064
|
| 30 |
+
charset_normalizer/md.py,sha256=iyXXQGWl54nnLQLueMWTmUtlivO0-rTBgVkmJxIIAGU,20036
|
| 31 |
+
charset_normalizer/md__mypyc.cpython-312-x86_64-linux-gnu.so,sha256=02IBduHhrAfIJteTWMlJulQK2gKMGP64dy8bVubEw3M,280904
|
| 32 |
+
charset_normalizer/models.py,sha256=lKXhOnIPtiakbK3i__J9wpOfzx3JDTKj7Dn3Rg0VaRI,12394
|
| 33 |
+
charset_normalizer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 34 |
+
charset_normalizer/utils.py,sha256=T5UHo8AS7NVMmgruWoZyqEf0WrZVcQpgUNetRoborSk,12002
|
| 35 |
+
charset_normalizer/version.py,sha256=Ambcj3O8FfvdLfDLc8dkaxZx97O1IM_R4_aKGD_TDdE,115
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (75.6.0)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp312-cp312-manylinux_2_17_x86_64
|
| 5 |
+
Tag: cp312-cp312-manylinux2014_x86_64
|
| 6 |
+
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
normalizer = charset_normalizer:cli.cli_detect
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.1.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
charset_normalizer
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/__init__.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Click is a simple Python module inspired by the stdlib optparse to make
|
| 3 |
+
writing command line scripts fun. Unlike other modules, it's based
|
| 4 |
+
around a simple API that does not come with too much magic and is
|
| 5 |
+
composable.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from .core import Argument as Argument
|
| 9 |
+
from .core import BaseCommand as BaseCommand
|
| 10 |
+
from .core import Command as Command
|
| 11 |
+
from .core import CommandCollection as CommandCollection
|
| 12 |
+
from .core import Context as Context
|
| 13 |
+
from .core import Group as Group
|
| 14 |
+
from .core import MultiCommand as MultiCommand
|
| 15 |
+
from .core import Option as Option
|
| 16 |
+
from .core import Parameter as Parameter
|
| 17 |
+
from .decorators import argument as argument
|
| 18 |
+
from .decorators import command as command
|
| 19 |
+
from .decorators import confirmation_option as confirmation_option
|
| 20 |
+
from .decorators import group as group
|
| 21 |
+
from .decorators import help_option as help_option
|
| 22 |
+
from .decorators import HelpOption as HelpOption
|
| 23 |
+
from .decorators import make_pass_decorator as make_pass_decorator
|
| 24 |
+
from .decorators import option as option
|
| 25 |
+
from .decorators import pass_context as pass_context
|
| 26 |
+
from .decorators import pass_obj as pass_obj
|
| 27 |
+
from .decorators import password_option as password_option
|
| 28 |
+
from .decorators import version_option as version_option
|
| 29 |
+
from .exceptions import Abort as Abort
|
| 30 |
+
from .exceptions import BadArgumentUsage as BadArgumentUsage
|
| 31 |
+
from .exceptions import BadOptionUsage as BadOptionUsage
|
| 32 |
+
from .exceptions import BadParameter as BadParameter
|
| 33 |
+
from .exceptions import ClickException as ClickException
|
| 34 |
+
from .exceptions import FileError as FileError
|
| 35 |
+
from .exceptions import MissingParameter as MissingParameter
|
| 36 |
+
from .exceptions import NoSuchOption as NoSuchOption
|
| 37 |
+
from .exceptions import UsageError as UsageError
|
| 38 |
+
from .formatting import HelpFormatter as HelpFormatter
|
| 39 |
+
from .formatting import wrap_text as wrap_text
|
| 40 |
+
from .globals import get_current_context as get_current_context
|
| 41 |
+
from .parser import OptionParser as OptionParser
|
| 42 |
+
from .termui import clear as clear
|
| 43 |
+
from .termui import confirm as confirm
|
| 44 |
+
from .termui import echo_via_pager as echo_via_pager
|
| 45 |
+
from .termui import edit as edit
|
| 46 |
+
from .termui import getchar as getchar
|
| 47 |
+
from .termui import launch as launch
|
| 48 |
+
from .termui import pause as pause
|
| 49 |
+
from .termui import progressbar as progressbar
|
| 50 |
+
from .termui import prompt as prompt
|
| 51 |
+
from .termui import secho as secho
|
| 52 |
+
from .termui import style as style
|
| 53 |
+
from .termui import unstyle as unstyle
|
| 54 |
+
from .types import BOOL as BOOL
|
| 55 |
+
from .types import Choice as Choice
|
| 56 |
+
from .types import DateTime as DateTime
|
| 57 |
+
from .types import File as File
|
| 58 |
+
from .types import FLOAT as FLOAT
|
| 59 |
+
from .types import FloatRange as FloatRange
|
| 60 |
+
from .types import INT as INT
|
| 61 |
+
from .types import IntRange as IntRange
|
| 62 |
+
from .types import ParamType as ParamType
|
| 63 |
+
from .types import Path as Path
|
| 64 |
+
from .types import STRING as STRING
|
| 65 |
+
from .types import Tuple as Tuple
|
| 66 |
+
from .types import UNPROCESSED as UNPROCESSED
|
| 67 |
+
from .types import UUID as UUID
|
| 68 |
+
from .utils import echo as echo
|
| 69 |
+
from .utils import format_filename as format_filename
|
| 70 |
+
from .utils import get_app_dir as get_app_dir
|
| 71 |
+
from .utils import get_binary_stream as get_binary_stream
|
| 72 |
+
from .utils import get_text_stream as get_text_stream
|
| 73 |
+
from .utils import open_file as open_file
|
| 74 |
+
|
| 75 |
+
__version__ = "8.1.8"
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/_compat.py
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import codecs
|
| 2 |
+
import io
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import sys
|
| 6 |
+
import typing as t
|
| 7 |
+
from weakref import WeakKeyDictionary
|
| 8 |
+
|
| 9 |
+
CYGWIN = sys.platform.startswith("cygwin")
|
| 10 |
+
WIN = sys.platform.startswith("win")
|
| 11 |
+
auto_wrap_for_ansi: t.Optional[t.Callable[[t.TextIO], t.TextIO]] = None
|
| 12 |
+
_ansi_re = re.compile(r"\033\[[;?0-9]*[a-zA-Z]")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _make_text_stream(
|
| 16 |
+
stream: t.BinaryIO,
|
| 17 |
+
encoding: t.Optional[str],
|
| 18 |
+
errors: t.Optional[str],
|
| 19 |
+
force_readable: bool = False,
|
| 20 |
+
force_writable: bool = False,
|
| 21 |
+
) -> t.TextIO:
|
| 22 |
+
if encoding is None:
|
| 23 |
+
encoding = get_best_encoding(stream)
|
| 24 |
+
if errors is None:
|
| 25 |
+
errors = "replace"
|
| 26 |
+
return _NonClosingTextIOWrapper(
|
| 27 |
+
stream,
|
| 28 |
+
encoding,
|
| 29 |
+
errors,
|
| 30 |
+
line_buffering=True,
|
| 31 |
+
force_readable=force_readable,
|
| 32 |
+
force_writable=force_writable,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def is_ascii_encoding(encoding: str) -> bool:
|
| 37 |
+
"""Checks if a given encoding is ascii."""
|
| 38 |
+
try:
|
| 39 |
+
return codecs.lookup(encoding).name == "ascii"
|
| 40 |
+
except LookupError:
|
| 41 |
+
return False
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def get_best_encoding(stream: t.IO[t.Any]) -> str:
|
| 45 |
+
"""Returns the default stream encoding if not found."""
|
| 46 |
+
rv = getattr(stream, "encoding", None) or sys.getdefaultencoding()
|
| 47 |
+
if is_ascii_encoding(rv):
|
| 48 |
+
return "utf-8"
|
| 49 |
+
return rv
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class _NonClosingTextIOWrapper(io.TextIOWrapper):
|
| 53 |
+
def __init__(
|
| 54 |
+
self,
|
| 55 |
+
stream: t.BinaryIO,
|
| 56 |
+
encoding: t.Optional[str],
|
| 57 |
+
errors: t.Optional[str],
|
| 58 |
+
force_readable: bool = False,
|
| 59 |
+
force_writable: bool = False,
|
| 60 |
+
**extra: t.Any,
|
| 61 |
+
) -> None:
|
| 62 |
+
self._stream = stream = t.cast(
|
| 63 |
+
t.BinaryIO, _FixupStream(stream, force_readable, force_writable)
|
| 64 |
+
)
|
| 65 |
+
super().__init__(stream, encoding, errors, **extra)
|
| 66 |
+
|
| 67 |
+
def __del__(self) -> None:
|
| 68 |
+
try:
|
| 69 |
+
self.detach()
|
| 70 |
+
except Exception:
|
| 71 |
+
pass
|
| 72 |
+
|
| 73 |
+
def isatty(self) -> bool:
|
| 74 |
+
# https://bitbucket.org/pypy/pypy/issue/1803
|
| 75 |
+
return self._stream.isatty()
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class _FixupStream:
|
| 79 |
+
"""The new io interface needs more from streams than streams
|
| 80 |
+
traditionally implement. As such, this fix-up code is necessary in
|
| 81 |
+
some circumstances.
|
| 82 |
+
|
| 83 |
+
The forcing of readable and writable flags are there because some tools
|
| 84 |
+
put badly patched objects on sys (one such offender are certain version
|
| 85 |
+
of jupyter notebook).
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
def __init__(
|
| 89 |
+
self,
|
| 90 |
+
stream: t.BinaryIO,
|
| 91 |
+
force_readable: bool = False,
|
| 92 |
+
force_writable: bool = False,
|
| 93 |
+
):
|
| 94 |
+
self._stream = stream
|
| 95 |
+
self._force_readable = force_readable
|
| 96 |
+
self._force_writable = force_writable
|
| 97 |
+
|
| 98 |
+
def __getattr__(self, name: str) -> t.Any:
|
| 99 |
+
return getattr(self._stream, name)
|
| 100 |
+
|
| 101 |
+
def read1(self, size: int) -> bytes:
|
| 102 |
+
f = getattr(self._stream, "read1", None)
|
| 103 |
+
|
| 104 |
+
if f is not None:
|
| 105 |
+
return t.cast(bytes, f(size))
|
| 106 |
+
|
| 107 |
+
return self._stream.read(size)
|
| 108 |
+
|
| 109 |
+
def readable(self) -> bool:
|
| 110 |
+
if self._force_readable:
|
| 111 |
+
return True
|
| 112 |
+
x = getattr(self._stream, "readable", None)
|
| 113 |
+
if x is not None:
|
| 114 |
+
return t.cast(bool, x())
|
| 115 |
+
try:
|
| 116 |
+
self._stream.read(0)
|
| 117 |
+
except Exception:
|
| 118 |
+
return False
|
| 119 |
+
return True
|
| 120 |
+
|
| 121 |
+
def writable(self) -> bool:
|
| 122 |
+
if self._force_writable:
|
| 123 |
+
return True
|
| 124 |
+
x = getattr(self._stream, "writable", None)
|
| 125 |
+
if x is not None:
|
| 126 |
+
return t.cast(bool, x())
|
| 127 |
+
try:
|
| 128 |
+
self._stream.write("") # type: ignore
|
| 129 |
+
except Exception:
|
| 130 |
+
try:
|
| 131 |
+
self._stream.write(b"")
|
| 132 |
+
except Exception:
|
| 133 |
+
return False
|
| 134 |
+
return True
|
| 135 |
+
|
| 136 |
+
def seekable(self) -> bool:
|
| 137 |
+
x = getattr(self._stream, "seekable", None)
|
| 138 |
+
if x is not None:
|
| 139 |
+
return t.cast(bool, x())
|
| 140 |
+
try:
|
| 141 |
+
self._stream.seek(self._stream.tell())
|
| 142 |
+
except Exception:
|
| 143 |
+
return False
|
| 144 |
+
return True
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def _is_binary_reader(stream: t.IO[t.Any], default: bool = False) -> bool:
|
| 148 |
+
try:
|
| 149 |
+
return isinstance(stream.read(0), bytes)
|
| 150 |
+
except Exception:
|
| 151 |
+
return default
|
| 152 |
+
# This happens in some cases where the stream was already
|
| 153 |
+
# closed. In this case, we assume the default.
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def _is_binary_writer(stream: t.IO[t.Any], default: bool = False) -> bool:
|
| 157 |
+
try:
|
| 158 |
+
stream.write(b"")
|
| 159 |
+
except Exception:
|
| 160 |
+
try:
|
| 161 |
+
stream.write("")
|
| 162 |
+
return False
|
| 163 |
+
except Exception:
|
| 164 |
+
pass
|
| 165 |
+
return default
|
| 166 |
+
return True
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def _find_binary_reader(stream: t.IO[t.Any]) -> t.Optional[t.BinaryIO]:
|
| 170 |
+
# We need to figure out if the given stream is already binary.
|
| 171 |
+
# This can happen because the official docs recommend detaching
|
| 172 |
+
# the streams to get binary streams. Some code might do this, so
|
| 173 |
+
# we need to deal with this case explicitly.
|
| 174 |
+
if _is_binary_reader(stream, False):
|
| 175 |
+
return t.cast(t.BinaryIO, stream)
|
| 176 |
+
|
| 177 |
+
buf = getattr(stream, "buffer", None)
|
| 178 |
+
|
| 179 |
+
# Same situation here; this time we assume that the buffer is
|
| 180 |
+
# actually binary in case it's closed.
|
| 181 |
+
if buf is not None and _is_binary_reader(buf, True):
|
| 182 |
+
return t.cast(t.BinaryIO, buf)
|
| 183 |
+
|
| 184 |
+
return None
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def _find_binary_writer(stream: t.IO[t.Any]) -> t.Optional[t.BinaryIO]:
|
| 188 |
+
# We need to figure out if the given stream is already binary.
|
| 189 |
+
# This can happen because the official docs recommend detaching
|
| 190 |
+
# the streams to get binary streams. Some code might do this, so
|
| 191 |
+
# we need to deal with this case explicitly.
|
| 192 |
+
if _is_binary_writer(stream, False):
|
| 193 |
+
return t.cast(t.BinaryIO, stream)
|
| 194 |
+
|
| 195 |
+
buf = getattr(stream, "buffer", None)
|
| 196 |
+
|
| 197 |
+
# Same situation here; this time we assume that the buffer is
|
| 198 |
+
# actually binary in case it's closed.
|
| 199 |
+
if buf is not None and _is_binary_writer(buf, True):
|
| 200 |
+
return t.cast(t.BinaryIO, buf)
|
| 201 |
+
|
| 202 |
+
return None
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def _stream_is_misconfigured(stream: t.TextIO) -> bool:
|
| 206 |
+
"""A stream is misconfigured if its encoding is ASCII."""
|
| 207 |
+
# If the stream does not have an encoding set, we assume it's set
|
| 208 |
+
# to ASCII. This appears to happen in certain unittest
|
| 209 |
+
# environments. It's not quite clear what the correct behavior is
|
| 210 |
+
# but this at least will force Click to recover somehow.
|
| 211 |
+
return is_ascii_encoding(getattr(stream, "encoding", None) or "ascii")
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def _is_compat_stream_attr(stream: t.TextIO, attr: str, value: t.Optional[str]) -> bool:
|
| 215 |
+
"""A stream attribute is compatible if it is equal to the
|
| 216 |
+
desired value or the desired value is unset and the attribute
|
| 217 |
+
has a value.
|
| 218 |
+
"""
|
| 219 |
+
stream_value = getattr(stream, attr, None)
|
| 220 |
+
return stream_value == value or (value is None and stream_value is not None)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def _is_compatible_text_stream(
|
| 224 |
+
stream: t.TextIO, encoding: t.Optional[str], errors: t.Optional[str]
|
| 225 |
+
) -> bool:
|
| 226 |
+
"""Check if a stream's encoding and errors attributes are
|
| 227 |
+
compatible with the desired values.
|
| 228 |
+
"""
|
| 229 |
+
return _is_compat_stream_attr(
|
| 230 |
+
stream, "encoding", encoding
|
| 231 |
+
) and _is_compat_stream_attr(stream, "errors", errors)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def _force_correct_text_stream(
|
| 235 |
+
text_stream: t.IO[t.Any],
|
| 236 |
+
encoding: t.Optional[str],
|
| 237 |
+
errors: t.Optional[str],
|
| 238 |
+
is_binary: t.Callable[[t.IO[t.Any], bool], bool],
|
| 239 |
+
find_binary: t.Callable[[t.IO[t.Any]], t.Optional[t.BinaryIO]],
|
| 240 |
+
force_readable: bool = False,
|
| 241 |
+
force_writable: bool = False,
|
| 242 |
+
) -> t.TextIO:
|
| 243 |
+
if is_binary(text_stream, False):
|
| 244 |
+
binary_reader = t.cast(t.BinaryIO, text_stream)
|
| 245 |
+
else:
|
| 246 |
+
text_stream = t.cast(t.TextIO, text_stream)
|
| 247 |
+
# If the stream looks compatible, and won't default to a
|
| 248 |
+
# misconfigured ascii encoding, return it as-is.
|
| 249 |
+
if _is_compatible_text_stream(text_stream, encoding, errors) and not (
|
| 250 |
+
encoding is None and _stream_is_misconfigured(text_stream)
|
| 251 |
+
):
|
| 252 |
+
return text_stream
|
| 253 |
+
|
| 254 |
+
# Otherwise, get the underlying binary reader.
|
| 255 |
+
possible_binary_reader = find_binary(text_stream)
|
| 256 |
+
|
| 257 |
+
# If that's not possible, silently use the original reader
|
| 258 |
+
# and get mojibake instead of exceptions.
|
| 259 |
+
if possible_binary_reader is None:
|
| 260 |
+
return text_stream
|
| 261 |
+
|
| 262 |
+
binary_reader = possible_binary_reader
|
| 263 |
+
|
| 264 |
+
# Default errors to replace instead of strict in order to get
|
| 265 |
+
# something that works.
|
| 266 |
+
if errors is None:
|
| 267 |
+
errors = "replace"
|
| 268 |
+
|
| 269 |
+
# Wrap the binary stream in a text stream with the correct
|
| 270 |
+
# encoding parameters.
|
| 271 |
+
return _make_text_stream(
|
| 272 |
+
binary_reader,
|
| 273 |
+
encoding,
|
| 274 |
+
errors,
|
| 275 |
+
force_readable=force_readable,
|
| 276 |
+
force_writable=force_writable,
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def _force_correct_text_reader(
|
| 281 |
+
text_reader: t.IO[t.Any],
|
| 282 |
+
encoding: t.Optional[str],
|
| 283 |
+
errors: t.Optional[str],
|
| 284 |
+
force_readable: bool = False,
|
| 285 |
+
) -> t.TextIO:
|
| 286 |
+
return _force_correct_text_stream(
|
| 287 |
+
text_reader,
|
| 288 |
+
encoding,
|
| 289 |
+
errors,
|
| 290 |
+
_is_binary_reader,
|
| 291 |
+
_find_binary_reader,
|
| 292 |
+
force_readable=force_readable,
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def _force_correct_text_writer(
|
| 297 |
+
text_writer: t.IO[t.Any],
|
| 298 |
+
encoding: t.Optional[str],
|
| 299 |
+
errors: t.Optional[str],
|
| 300 |
+
force_writable: bool = False,
|
| 301 |
+
) -> t.TextIO:
|
| 302 |
+
return _force_correct_text_stream(
|
| 303 |
+
text_writer,
|
| 304 |
+
encoding,
|
| 305 |
+
errors,
|
| 306 |
+
_is_binary_writer,
|
| 307 |
+
_find_binary_writer,
|
| 308 |
+
force_writable=force_writable,
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def get_binary_stdin() -> t.BinaryIO:
|
| 313 |
+
reader = _find_binary_reader(sys.stdin)
|
| 314 |
+
if reader is None:
|
| 315 |
+
raise RuntimeError("Was not able to determine binary stream for sys.stdin.")
|
| 316 |
+
return reader
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def get_binary_stdout() -> t.BinaryIO:
|
| 320 |
+
writer = _find_binary_writer(sys.stdout)
|
| 321 |
+
if writer is None:
|
| 322 |
+
raise RuntimeError("Was not able to determine binary stream for sys.stdout.")
|
| 323 |
+
return writer
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def get_binary_stderr() -> t.BinaryIO:
|
| 327 |
+
writer = _find_binary_writer(sys.stderr)
|
| 328 |
+
if writer is None:
|
| 329 |
+
raise RuntimeError("Was not able to determine binary stream for sys.stderr.")
|
| 330 |
+
return writer
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def get_text_stdin(
|
| 334 |
+
encoding: t.Optional[str] = None, errors: t.Optional[str] = None
|
| 335 |
+
) -> t.TextIO:
|
| 336 |
+
rv = _get_windows_console_stream(sys.stdin, encoding, errors)
|
| 337 |
+
if rv is not None:
|
| 338 |
+
return rv
|
| 339 |
+
return _force_correct_text_reader(sys.stdin, encoding, errors, force_readable=True)
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def get_text_stdout(
|
| 343 |
+
encoding: t.Optional[str] = None, errors: t.Optional[str] = None
|
| 344 |
+
) -> t.TextIO:
|
| 345 |
+
rv = _get_windows_console_stream(sys.stdout, encoding, errors)
|
| 346 |
+
if rv is not None:
|
| 347 |
+
return rv
|
| 348 |
+
return _force_correct_text_writer(sys.stdout, encoding, errors, force_writable=True)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def get_text_stderr(
|
| 352 |
+
encoding: t.Optional[str] = None, errors: t.Optional[str] = None
|
| 353 |
+
) -> t.TextIO:
|
| 354 |
+
rv = _get_windows_console_stream(sys.stderr, encoding, errors)
|
| 355 |
+
if rv is not None:
|
| 356 |
+
return rv
|
| 357 |
+
return _force_correct_text_writer(sys.stderr, encoding, errors, force_writable=True)
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
def _wrap_io_open(
|
| 361 |
+
file: t.Union[str, "os.PathLike[str]", int],
|
| 362 |
+
mode: str,
|
| 363 |
+
encoding: t.Optional[str],
|
| 364 |
+
errors: t.Optional[str],
|
| 365 |
+
) -> t.IO[t.Any]:
|
| 366 |
+
"""Handles not passing ``encoding`` and ``errors`` in binary mode."""
|
| 367 |
+
if "b" in mode:
|
| 368 |
+
return open(file, mode)
|
| 369 |
+
|
| 370 |
+
return open(file, mode, encoding=encoding, errors=errors)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def open_stream(
|
| 374 |
+
filename: "t.Union[str, os.PathLike[str]]",
|
| 375 |
+
mode: str = "r",
|
| 376 |
+
encoding: t.Optional[str] = None,
|
| 377 |
+
errors: t.Optional[str] = "strict",
|
| 378 |
+
atomic: bool = False,
|
| 379 |
+
) -> t.Tuple[t.IO[t.Any], bool]:
|
| 380 |
+
binary = "b" in mode
|
| 381 |
+
filename = os.fspath(filename)
|
| 382 |
+
|
| 383 |
+
# Standard streams first. These are simple because they ignore the
|
| 384 |
+
# atomic flag. Use fsdecode to handle Path("-").
|
| 385 |
+
if os.fsdecode(filename) == "-":
|
| 386 |
+
if any(m in mode for m in ["w", "a", "x"]):
|
| 387 |
+
if binary:
|
| 388 |
+
return get_binary_stdout(), False
|
| 389 |
+
return get_text_stdout(encoding=encoding, errors=errors), False
|
| 390 |
+
if binary:
|
| 391 |
+
return get_binary_stdin(), False
|
| 392 |
+
return get_text_stdin(encoding=encoding, errors=errors), False
|
| 393 |
+
|
| 394 |
+
# Non-atomic writes directly go out through the regular open functions.
|
| 395 |
+
if not atomic:
|
| 396 |
+
return _wrap_io_open(filename, mode, encoding, errors), True
|
| 397 |
+
|
| 398 |
+
# Some usability stuff for atomic writes
|
| 399 |
+
if "a" in mode:
|
| 400 |
+
raise ValueError(
|
| 401 |
+
"Appending to an existing file is not supported, because that"
|
| 402 |
+
" would involve an expensive `copy`-operation to a temporary"
|
| 403 |
+
" file. Open the file in normal `w`-mode and copy explicitly"
|
| 404 |
+
" if that's what you're after."
|
| 405 |
+
)
|
| 406 |
+
if "x" in mode:
|
| 407 |
+
raise ValueError("Use the `overwrite`-parameter instead.")
|
| 408 |
+
if "w" not in mode:
|
| 409 |
+
raise ValueError("Atomic writes only make sense with `w`-mode.")
|
| 410 |
+
|
| 411 |
+
# Atomic writes are more complicated. They work by opening a file
|
| 412 |
+
# as a proxy in the same folder and then using the fdopen
|
| 413 |
+
# functionality to wrap it in a Python file. Then we wrap it in an
|
| 414 |
+
# atomic file that moves the file over on close.
|
| 415 |
+
import errno
|
| 416 |
+
import random
|
| 417 |
+
|
| 418 |
+
try:
|
| 419 |
+
perm: t.Optional[int] = os.stat(filename).st_mode
|
| 420 |
+
except OSError:
|
| 421 |
+
perm = None
|
| 422 |
+
|
| 423 |
+
flags = os.O_RDWR | os.O_CREAT | os.O_EXCL
|
| 424 |
+
|
| 425 |
+
if binary:
|
| 426 |
+
flags |= getattr(os, "O_BINARY", 0)
|
| 427 |
+
|
| 428 |
+
while True:
|
| 429 |
+
tmp_filename = os.path.join(
|
| 430 |
+
os.path.dirname(filename),
|
| 431 |
+
f".__atomic-write{random.randrange(1 << 32):08x}",
|
| 432 |
+
)
|
| 433 |
+
try:
|
| 434 |
+
fd = os.open(tmp_filename, flags, 0o666 if perm is None else perm)
|
| 435 |
+
break
|
| 436 |
+
except OSError as e:
|
| 437 |
+
if e.errno == errno.EEXIST or (
|
| 438 |
+
os.name == "nt"
|
| 439 |
+
and e.errno == errno.EACCES
|
| 440 |
+
and os.path.isdir(e.filename)
|
| 441 |
+
and os.access(e.filename, os.W_OK)
|
| 442 |
+
):
|
| 443 |
+
continue
|
| 444 |
+
raise
|
| 445 |
+
|
| 446 |
+
if perm is not None:
|
| 447 |
+
os.chmod(tmp_filename, perm) # in case perm includes bits in umask
|
| 448 |
+
|
| 449 |
+
f = _wrap_io_open(fd, mode, encoding, errors)
|
| 450 |
+
af = _AtomicFile(f, tmp_filename, os.path.realpath(filename))
|
| 451 |
+
return t.cast(t.IO[t.Any], af), True
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
class _AtomicFile:
|
| 455 |
+
def __init__(self, f: t.IO[t.Any], tmp_filename: str, real_filename: str) -> None:
|
| 456 |
+
self._f = f
|
| 457 |
+
self._tmp_filename = tmp_filename
|
| 458 |
+
self._real_filename = real_filename
|
| 459 |
+
self.closed = False
|
| 460 |
+
|
| 461 |
+
@property
|
| 462 |
+
def name(self) -> str:
|
| 463 |
+
return self._real_filename
|
| 464 |
+
|
| 465 |
+
def close(self, delete: bool = False) -> None:
|
| 466 |
+
if self.closed:
|
| 467 |
+
return
|
| 468 |
+
self._f.close()
|
| 469 |
+
os.replace(self._tmp_filename, self._real_filename)
|
| 470 |
+
self.closed = True
|
| 471 |
+
|
| 472 |
+
def __getattr__(self, name: str) -> t.Any:
|
| 473 |
+
return getattr(self._f, name)
|
| 474 |
+
|
| 475 |
+
def __enter__(self) -> "_AtomicFile":
|
| 476 |
+
return self
|
| 477 |
+
|
| 478 |
+
def __exit__(self, exc_type: t.Optional[t.Type[BaseException]], *_: t.Any) -> None:
|
| 479 |
+
self.close(delete=exc_type is not None)
|
| 480 |
+
|
| 481 |
+
def __repr__(self) -> str:
|
| 482 |
+
return repr(self._f)
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def strip_ansi(value: str) -> str:
|
| 486 |
+
return _ansi_re.sub("", value)
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def _is_jupyter_kernel_output(stream: t.IO[t.Any]) -> bool:
|
| 490 |
+
while isinstance(stream, (_FixupStream, _NonClosingTextIOWrapper)):
|
| 491 |
+
stream = stream._stream
|
| 492 |
+
|
| 493 |
+
return stream.__class__.__module__.startswith("ipykernel.")
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
def should_strip_ansi(
|
| 497 |
+
stream: t.Optional[t.IO[t.Any]] = None, color: t.Optional[bool] = None
|
| 498 |
+
) -> bool:
|
| 499 |
+
if color is None:
|
| 500 |
+
if stream is None:
|
| 501 |
+
stream = sys.stdin
|
| 502 |
+
return not isatty(stream) and not _is_jupyter_kernel_output(stream)
|
| 503 |
+
return not color
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
# On Windows, wrap the output streams with colorama to support ANSI
|
| 507 |
+
# color codes.
|
| 508 |
+
# NOTE: double check is needed so mypy does not analyze this on Linux
|
| 509 |
+
if sys.platform.startswith("win") and WIN:
|
| 510 |
+
from ._winconsole import _get_windows_console_stream
|
| 511 |
+
|
| 512 |
+
def _get_argv_encoding() -> str:
|
| 513 |
+
import locale
|
| 514 |
+
|
| 515 |
+
return locale.getpreferredencoding()
|
| 516 |
+
|
| 517 |
+
_ansi_stream_wrappers: t.MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()
|
| 518 |
+
|
| 519 |
+
def auto_wrap_for_ansi(
|
| 520 |
+
stream: t.TextIO, color: t.Optional[bool] = None
|
| 521 |
+
) -> t.TextIO:
|
| 522 |
+
"""Support ANSI color and style codes on Windows by wrapping a
|
| 523 |
+
stream with colorama.
|
| 524 |
+
"""
|
| 525 |
+
try:
|
| 526 |
+
cached = _ansi_stream_wrappers.get(stream)
|
| 527 |
+
except Exception:
|
| 528 |
+
cached = None
|
| 529 |
+
|
| 530 |
+
if cached is not None:
|
| 531 |
+
return cached
|
| 532 |
+
|
| 533 |
+
import colorama
|
| 534 |
+
|
| 535 |
+
strip = should_strip_ansi(stream, color)
|
| 536 |
+
ansi_wrapper = colorama.AnsiToWin32(stream, strip=strip)
|
| 537 |
+
rv = t.cast(t.TextIO, ansi_wrapper.stream)
|
| 538 |
+
_write = rv.write
|
| 539 |
+
|
| 540 |
+
def _safe_write(s):
|
| 541 |
+
try:
|
| 542 |
+
return _write(s)
|
| 543 |
+
except BaseException:
|
| 544 |
+
ansi_wrapper.reset_all()
|
| 545 |
+
raise
|
| 546 |
+
|
| 547 |
+
rv.write = _safe_write
|
| 548 |
+
|
| 549 |
+
try:
|
| 550 |
+
_ansi_stream_wrappers[stream] = rv
|
| 551 |
+
except Exception:
|
| 552 |
+
pass
|
| 553 |
+
|
| 554 |
+
return rv
|
| 555 |
+
|
| 556 |
+
else:
|
| 557 |
+
|
| 558 |
+
def _get_argv_encoding() -> str:
|
| 559 |
+
return getattr(sys.stdin, "encoding", None) or sys.getfilesystemencoding()
|
| 560 |
+
|
| 561 |
+
def _get_windows_console_stream(
|
| 562 |
+
f: t.TextIO, encoding: t.Optional[str], errors: t.Optional[str]
|
| 563 |
+
) -> t.Optional[t.TextIO]:
|
| 564 |
+
return None
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
def term_len(x: str) -> int:
|
| 568 |
+
return len(strip_ansi(x))
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def isatty(stream: t.IO[t.Any]) -> bool:
|
| 572 |
+
try:
|
| 573 |
+
return stream.isatty()
|
| 574 |
+
except Exception:
|
| 575 |
+
return False
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
def _make_cached_stream_func(
|
| 579 |
+
src_func: t.Callable[[], t.Optional[t.TextIO]],
|
| 580 |
+
wrapper_func: t.Callable[[], t.TextIO],
|
| 581 |
+
) -> t.Callable[[], t.Optional[t.TextIO]]:
|
| 582 |
+
cache: t.MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()
|
| 583 |
+
|
| 584 |
+
def func() -> t.Optional[t.TextIO]:
|
| 585 |
+
stream = src_func()
|
| 586 |
+
|
| 587 |
+
if stream is None:
|
| 588 |
+
return None
|
| 589 |
+
|
| 590 |
+
try:
|
| 591 |
+
rv = cache.get(stream)
|
| 592 |
+
except Exception:
|
| 593 |
+
rv = None
|
| 594 |
+
if rv is not None:
|
| 595 |
+
return rv
|
| 596 |
+
rv = wrapper_func()
|
| 597 |
+
try:
|
| 598 |
+
cache[stream] = rv
|
| 599 |
+
except Exception:
|
| 600 |
+
pass
|
| 601 |
+
return rv
|
| 602 |
+
|
| 603 |
+
return func
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
_default_text_stdin = _make_cached_stream_func(lambda: sys.stdin, get_text_stdin)
|
| 607 |
+
_default_text_stdout = _make_cached_stream_func(lambda: sys.stdout, get_text_stdout)
|
| 608 |
+
_default_text_stderr = _make_cached_stream_func(lambda: sys.stderr, get_text_stderr)
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
binary_streams: t.Mapping[str, t.Callable[[], t.BinaryIO]] = {
|
| 612 |
+
"stdin": get_binary_stdin,
|
| 613 |
+
"stdout": get_binary_stdout,
|
| 614 |
+
"stderr": get_binary_stderr,
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
text_streams: t.Mapping[
|
| 618 |
+
str, t.Callable[[t.Optional[str], t.Optional[str]], t.TextIO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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module contains implementations for the termui module. To keep the
|
| 3 |
+
import time of Click down, some infrequently used functionality is
|
| 4 |
+
placed in this module and only imported as needed.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import contextlib
|
| 8 |
+
import math
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import time
|
| 12 |
+
import typing as t
|
| 13 |
+
from gettext import gettext as _
|
| 14 |
+
from io import StringIO
|
| 15 |
+
from shutil import which
|
| 16 |
+
from types import TracebackType
|
| 17 |
+
|
| 18 |
+
from ._compat import _default_text_stdout
|
| 19 |
+
from ._compat import CYGWIN
|
| 20 |
+
from ._compat import get_best_encoding
|
| 21 |
+
from ._compat import isatty
|
| 22 |
+
from ._compat import open_stream
|
| 23 |
+
from ._compat import strip_ansi
|
| 24 |
+
from ._compat import term_len
|
| 25 |
+
from ._compat import WIN
|
| 26 |
+
from .exceptions import ClickException
|
| 27 |
+
from .utils import echo
|
| 28 |
+
|
| 29 |
+
V = t.TypeVar("V")
|
| 30 |
+
|
| 31 |
+
if os.name == "nt":
|
| 32 |
+
BEFORE_BAR = "\r"
|
| 33 |
+
AFTER_BAR = "\n"
|
| 34 |
+
else:
|
| 35 |
+
BEFORE_BAR = "\r\033[?25l"
|
| 36 |
+
AFTER_BAR = "\033[?25h\n"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class ProgressBar(t.Generic[V]):
|
| 40 |
+
def __init__(
|
| 41 |
+
self,
|
| 42 |
+
iterable: t.Optional[t.Iterable[V]],
|
| 43 |
+
length: t.Optional[int] = None,
|
| 44 |
+
fill_char: str = "#",
|
| 45 |
+
empty_char: str = " ",
|
| 46 |
+
bar_template: str = "%(bar)s",
|
| 47 |
+
info_sep: str = " ",
|
| 48 |
+
show_eta: bool = True,
|
| 49 |
+
show_percent: t.Optional[bool] = None,
|
| 50 |
+
show_pos: bool = False,
|
| 51 |
+
item_show_func: t.Optional[t.Callable[[t.Optional[V]], t.Optional[str]]] = None,
|
| 52 |
+
label: t.Optional[str] = None,
|
| 53 |
+
file: t.Optional[t.TextIO] = None,
|
| 54 |
+
color: t.Optional[bool] = None,
|
| 55 |
+
update_min_steps: int = 1,
|
| 56 |
+
width: int = 30,
|
| 57 |
+
) -> None:
|
| 58 |
+
self.fill_char = fill_char
|
| 59 |
+
self.empty_char = empty_char
|
| 60 |
+
self.bar_template = bar_template
|
| 61 |
+
self.info_sep = info_sep
|
| 62 |
+
self.show_eta = show_eta
|
| 63 |
+
self.show_percent = show_percent
|
| 64 |
+
self.show_pos = show_pos
|
| 65 |
+
self.item_show_func = item_show_func
|
| 66 |
+
self.label: str = label or ""
|
| 67 |
+
|
| 68 |
+
if file is None:
|
| 69 |
+
file = _default_text_stdout()
|
| 70 |
+
|
| 71 |
+
# There are no standard streams attached to write to. For example,
|
| 72 |
+
# pythonw on Windows.
|
| 73 |
+
if file is None:
|
| 74 |
+
file = StringIO()
|
| 75 |
+
|
| 76 |
+
self.file = file
|
| 77 |
+
self.color = color
|
| 78 |
+
self.update_min_steps = update_min_steps
|
| 79 |
+
self._completed_intervals = 0
|
| 80 |
+
self.width: int = width
|
| 81 |
+
self.autowidth: bool = width == 0
|
| 82 |
+
|
| 83 |
+
if length is None:
|
| 84 |
+
from operator import length_hint
|
| 85 |
+
|
| 86 |
+
length = length_hint(iterable, -1)
|
| 87 |
+
|
| 88 |
+
if length == -1:
|
| 89 |
+
length = None
|
| 90 |
+
if iterable is None:
|
| 91 |
+
if length is None:
|
| 92 |
+
raise TypeError("iterable or length is required")
|
| 93 |
+
iterable = t.cast(t.Iterable[V], range(length))
|
| 94 |
+
self.iter: t.Iterable[V] = iter(iterable)
|
| 95 |
+
self.length = length
|
| 96 |
+
self.pos = 0
|
| 97 |
+
self.avg: t.List[float] = []
|
| 98 |
+
self.last_eta: float
|
| 99 |
+
self.start: float
|
| 100 |
+
self.start = self.last_eta = time.time()
|
| 101 |
+
self.eta_known: bool = False
|
| 102 |
+
self.finished: bool = False
|
| 103 |
+
self.max_width: t.Optional[int] = None
|
| 104 |
+
self.entered: bool = False
|
| 105 |
+
self.current_item: t.Optional[V] = None
|
| 106 |
+
self.is_hidden: bool = not isatty(self.file)
|
| 107 |
+
self._last_line: t.Optional[str] = None
|
| 108 |
+
|
| 109 |
+
def __enter__(self) -> "ProgressBar[V]":
|
| 110 |
+
self.entered = True
|
| 111 |
+
self.render_progress()
|
| 112 |
+
return self
|
| 113 |
+
|
| 114 |
+
def __exit__(
|
| 115 |
+
self,
|
| 116 |
+
exc_type: t.Optional[t.Type[BaseException]],
|
| 117 |
+
exc_value: t.Optional[BaseException],
|
| 118 |
+
tb: t.Optional[TracebackType],
|
| 119 |
+
) -> None:
|
| 120 |
+
self.render_finish()
|
| 121 |
+
|
| 122 |
+
def __iter__(self) -> t.Iterator[V]:
|
| 123 |
+
if not self.entered:
|
| 124 |
+
raise RuntimeError("You need to use progress bars in a with block.")
|
| 125 |
+
self.render_progress()
|
| 126 |
+
return self.generator()
|
| 127 |
+
|
| 128 |
+
def __next__(self) -> V:
|
| 129 |
+
# Iteration is defined in terms of a generator function,
|
| 130 |
+
# returned by iter(self); use that to define next(). This works
|
| 131 |
+
# because `self.iter` is an iterable consumed by that generator,
|
| 132 |
+
# so it is re-entry safe. Calling `next(self.generator())`
|
| 133 |
+
# twice works and does "what you want".
|
| 134 |
+
return next(iter(self))
|
| 135 |
+
|
| 136 |
+
def render_finish(self) -> None:
|
| 137 |
+
if self.is_hidden:
|
| 138 |
+
return
|
| 139 |
+
self.file.write(AFTER_BAR)
|
| 140 |
+
self.file.flush()
|
| 141 |
+
|
| 142 |
+
@property
|
| 143 |
+
def pct(self) -> float:
|
| 144 |
+
if self.finished:
|
| 145 |
+
return 1.0
|
| 146 |
+
return min(self.pos / (float(self.length or 1) or 1), 1.0)
|
| 147 |
+
|
| 148 |
+
@property
|
| 149 |
+
def time_per_iteration(self) -> float:
|
| 150 |
+
if not self.avg:
|
| 151 |
+
return 0.0
|
| 152 |
+
return sum(self.avg) / float(len(self.avg))
|
| 153 |
+
|
| 154 |
+
@property
|
| 155 |
+
def eta(self) -> float:
|
| 156 |
+
if self.length is not None and not self.finished:
|
| 157 |
+
return self.time_per_iteration * (self.length - self.pos)
|
| 158 |
+
return 0.0
|
| 159 |
+
|
| 160 |
+
def format_eta(self) -> str:
|
| 161 |
+
if self.eta_known:
|
| 162 |
+
t = int(self.eta)
|
| 163 |
+
seconds = t % 60
|
| 164 |
+
t //= 60
|
| 165 |
+
minutes = t % 60
|
| 166 |
+
t //= 60
|
| 167 |
+
hours = t % 24
|
| 168 |
+
t //= 24
|
| 169 |
+
if t > 0:
|
| 170 |
+
return f"{t}d {hours:02}:{minutes:02}:{seconds:02}"
|
| 171 |
+
else:
|
| 172 |
+
return f"{hours:02}:{minutes:02}:{seconds:02}"
|
| 173 |
+
return ""
|
| 174 |
+
|
| 175 |
+
def format_pos(self) -> str:
|
| 176 |
+
pos = str(self.pos)
|
| 177 |
+
if self.length is not None:
|
| 178 |
+
pos += f"/{self.length}"
|
| 179 |
+
return pos
|
| 180 |
+
|
| 181 |
+
def format_pct(self) -> str:
|
| 182 |
+
return f"{int(self.pct * 100): 4}%"[1:]
|
| 183 |
+
|
| 184 |
+
def format_bar(self) -> str:
|
| 185 |
+
if self.length is not None:
|
| 186 |
+
bar_length = int(self.pct * self.width)
|
| 187 |
+
bar = self.fill_char * bar_length
|
| 188 |
+
bar += self.empty_char * (self.width - bar_length)
|
| 189 |
+
elif self.finished:
|
| 190 |
+
bar = self.fill_char * self.width
|
| 191 |
+
else:
|
| 192 |
+
chars = list(self.empty_char * (self.width or 1))
|
| 193 |
+
if self.time_per_iteration != 0:
|
| 194 |
+
chars[
|
| 195 |
+
int(
|
| 196 |
+
(math.cos(self.pos * self.time_per_iteration) / 2.0 + 0.5)
|
| 197 |
+
* self.width
|
| 198 |
+
)
|
| 199 |
+
] = self.fill_char
|
| 200 |
+
bar = "".join(chars)
|
| 201 |
+
return bar
|
| 202 |
+
|
| 203 |
+
def format_progress_line(self) -> str:
|
| 204 |
+
show_percent = self.show_percent
|
| 205 |
+
|
| 206 |
+
info_bits = []
|
| 207 |
+
if self.length is not None and show_percent is None:
|
| 208 |
+
show_percent = not self.show_pos
|
| 209 |
+
|
| 210 |
+
if self.show_pos:
|
| 211 |
+
info_bits.append(self.format_pos())
|
| 212 |
+
if show_percent:
|
| 213 |
+
info_bits.append(self.format_pct())
|
| 214 |
+
if self.show_eta and self.eta_known and not self.finished:
|
| 215 |
+
info_bits.append(self.format_eta())
|
| 216 |
+
if self.item_show_func is not None:
|
| 217 |
+
item_info = self.item_show_func(self.current_item)
|
| 218 |
+
if item_info is not None:
|
| 219 |
+
info_bits.append(item_info)
|
| 220 |
+
|
| 221 |
+
return (
|
| 222 |
+
self.bar_template
|
| 223 |
+
% {
|
| 224 |
+
"label": self.label,
|
| 225 |
+
"bar": self.format_bar(),
|
| 226 |
+
"info": self.info_sep.join(info_bits),
|
| 227 |
+
}
|
| 228 |
+
).rstrip()
|
| 229 |
+
|
| 230 |
+
def render_progress(self) -> None:
|
| 231 |
+
import shutil
|
| 232 |
+
|
| 233 |
+
if self.is_hidden:
|
| 234 |
+
# Only output the label as it changes if the output is not a
|
| 235 |
+
# TTY. Use file=stderr if you expect to be piping stdout.
|
| 236 |
+
if self._last_line != self.label:
|
| 237 |
+
self._last_line = self.label
|
| 238 |
+
echo(self.label, file=self.file, color=self.color)
|
| 239 |
+
|
| 240 |
+
return
|
| 241 |
+
|
| 242 |
+
buf = []
|
| 243 |
+
# Update width in case the terminal has been resized
|
| 244 |
+
if self.autowidth:
|
| 245 |
+
old_width = self.width
|
| 246 |
+
self.width = 0
|
| 247 |
+
clutter_length = term_len(self.format_progress_line())
|
| 248 |
+
new_width = max(0, shutil.get_terminal_size().columns - clutter_length)
|
| 249 |
+
if new_width < old_width:
|
| 250 |
+
buf.append(BEFORE_BAR)
|
| 251 |
+
buf.append(" " * self.max_width) # type: ignore
|
| 252 |
+
self.max_width = new_width
|
| 253 |
+
self.width = new_width
|
| 254 |
+
|
| 255 |
+
clear_width = self.width
|
| 256 |
+
if self.max_width is not None:
|
| 257 |
+
clear_width = self.max_width
|
| 258 |
+
|
| 259 |
+
buf.append(BEFORE_BAR)
|
| 260 |
+
line = self.format_progress_line()
|
| 261 |
+
line_len = term_len(line)
|
| 262 |
+
if self.max_width is None or self.max_width < line_len:
|
| 263 |
+
self.max_width = line_len
|
| 264 |
+
|
| 265 |
+
buf.append(line)
|
| 266 |
+
buf.append(" " * (clear_width - line_len))
|
| 267 |
+
line = "".join(buf)
|
| 268 |
+
# Render the line only if it changed.
|
| 269 |
+
|
| 270 |
+
if line != self._last_line:
|
| 271 |
+
self._last_line = line
|
| 272 |
+
echo(line, file=self.file, color=self.color, nl=False)
|
| 273 |
+
self.file.flush()
|
| 274 |
+
|
| 275 |
+
def make_step(self, n_steps: int) -> None:
|
| 276 |
+
self.pos += n_steps
|
| 277 |
+
if self.length is not None and self.pos >= self.length:
|
| 278 |
+
self.finished = True
|
| 279 |
+
|
| 280 |
+
if (time.time() - self.last_eta) < 1.0:
|
| 281 |
+
return
|
| 282 |
+
|
| 283 |
+
self.last_eta = time.time()
|
| 284 |
+
|
| 285 |
+
# self.avg is a rolling list of length <= 7 of steps where steps are
|
| 286 |
+
# defined as time elapsed divided by the total progress through
|
| 287 |
+
# self.length.
|
| 288 |
+
if self.pos:
|
| 289 |
+
step = (time.time() - self.start) / self.pos
|
| 290 |
+
else:
|
| 291 |
+
step = time.time() - self.start
|
| 292 |
+
|
| 293 |
+
self.avg = self.avg[-6:] + [step]
|
| 294 |
+
|
| 295 |
+
self.eta_known = self.length is not None
|
| 296 |
+
|
| 297 |
+
def update(self, n_steps: int, current_item: t.Optional[V] = None) -> None:
|
| 298 |
+
"""Update the progress bar by advancing a specified number of
|
| 299 |
+
steps, and optionally set the ``current_item`` for this new
|
| 300 |
+
position.
|
| 301 |
+
|
| 302 |
+
:param n_steps: Number of steps to advance.
|
| 303 |
+
:param current_item: Optional item to set as ``current_item``
|
| 304 |
+
for the updated position.
|
| 305 |
+
|
| 306 |
+
.. versionchanged:: 8.0
|
| 307 |
+
Added the ``current_item`` optional parameter.
|
| 308 |
+
|
| 309 |
+
.. versionchanged:: 8.0
|
| 310 |
+
Only render when the number of steps meets the
|
| 311 |
+
``update_min_steps`` threshold.
|
| 312 |
+
"""
|
| 313 |
+
if current_item is not None:
|
| 314 |
+
self.current_item = current_item
|
| 315 |
+
|
| 316 |
+
self._completed_intervals += n_steps
|
| 317 |
+
|
| 318 |
+
if self._completed_intervals >= self.update_min_steps:
|
| 319 |
+
self.make_step(self._completed_intervals)
|
| 320 |
+
self.render_progress()
|
| 321 |
+
self._completed_intervals = 0
|
| 322 |
+
|
| 323 |
+
def finish(self) -> None:
|
| 324 |
+
self.eta_known = False
|
| 325 |
+
self.current_item = None
|
| 326 |
+
self.finished = True
|
| 327 |
+
|
| 328 |
+
def generator(self) -> t.Iterator[V]:
|
| 329 |
+
"""Return a generator which yields the items added to the bar
|
| 330 |
+
during construction, and updates the progress bar *after* the
|
| 331 |
+
yielded block returns.
|
| 332 |
+
"""
|
| 333 |
+
# WARNING: the iterator interface for `ProgressBar` relies on
|
| 334 |
+
# this and only works because this is a simple generator which
|
| 335 |
+
# doesn't create or manage additional state. If this function
|
| 336 |
+
# changes, the impact should be evaluated both against
|
| 337 |
+
# `iter(bar)` and `next(bar)`. `next()` in particular may call
|
| 338 |
+
# `self.generator()` repeatedly, and this must remain safe in
|
| 339 |
+
# order for that interface to work.
|
| 340 |
+
if not self.entered:
|
| 341 |
+
raise RuntimeError("You need to use progress bars in a with block.")
|
| 342 |
+
|
| 343 |
+
if self.is_hidden:
|
| 344 |
+
yield from self.iter
|
| 345 |
+
else:
|
| 346 |
+
for rv in self.iter:
|
| 347 |
+
self.current_item = rv
|
| 348 |
+
|
| 349 |
+
# This allows show_item_func to be updated before the
|
| 350 |
+
# item is processed. Only trigger at the beginning of
|
| 351 |
+
# the update interval.
|
| 352 |
+
if self._completed_intervals == 0:
|
| 353 |
+
self.render_progress()
|
| 354 |
+
|
| 355 |
+
yield rv
|
| 356 |
+
self.update(1)
|
| 357 |
+
|
| 358 |
+
self.finish()
|
| 359 |
+
self.render_progress()
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
def pager(generator: t.Iterable[str], color: t.Optional[bool] = None) -> None:
|
| 363 |
+
"""Decide what method to use for paging through text."""
|
| 364 |
+
stdout = _default_text_stdout()
|
| 365 |
+
|
| 366 |
+
# There are no standard streams attached to write to. For example,
|
| 367 |
+
# pythonw on Windows.
|
| 368 |
+
if stdout is None:
|
| 369 |
+
stdout = StringIO()
|
| 370 |
+
|
| 371 |
+
if not isatty(sys.stdin) or not isatty(stdout):
|
| 372 |
+
return _nullpager(stdout, generator, color)
|
| 373 |
+
pager_cmd = (os.environ.get("PAGER", None) or "").strip()
|
| 374 |
+
if pager_cmd:
|
| 375 |
+
if WIN:
|
| 376 |
+
if _tempfilepager(generator, pager_cmd, color):
|
| 377 |
+
return
|
| 378 |
+
elif _pipepager(generator, pager_cmd, color):
|
| 379 |
+
return
|
| 380 |
+
if os.environ.get("TERM") in ("dumb", "emacs"):
|
| 381 |
+
return _nullpager(stdout, generator, color)
|
| 382 |
+
if (WIN or sys.platform.startswith("os2")) and _tempfilepager(
|
| 383 |
+
generator, "more", color
|
| 384 |
+
):
|
| 385 |
+
return
|
| 386 |
+
if _pipepager(generator, "less", color):
|
| 387 |
+
return
|
| 388 |
+
|
| 389 |
+
import tempfile
|
| 390 |
+
|
| 391 |
+
fd, filename = tempfile.mkstemp()
|
| 392 |
+
os.close(fd)
|
| 393 |
+
try:
|
| 394 |
+
if _pipepager(generator, "more", color):
|
| 395 |
+
return
|
| 396 |
+
return _nullpager(stdout, generator, color)
|
| 397 |
+
finally:
|
| 398 |
+
os.unlink(filename)
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
def _pipepager(generator: t.Iterable[str], cmd: str, color: t.Optional[bool]) -> bool:
|
| 402 |
+
"""Page through text by feeding it to another program. Invoking a
|
| 403 |
+
pager through this might support colors.
|
| 404 |
+
|
| 405 |
+
Returns True if the command was found, False otherwise and thus another
|
| 406 |
+
pager should be attempted.
|
| 407 |
+
"""
|
| 408 |
+
cmd_absolute = which(cmd)
|
| 409 |
+
if cmd_absolute is None:
|
| 410 |
+
return False
|
| 411 |
+
|
| 412 |
+
import subprocess
|
| 413 |
+
|
| 414 |
+
env = dict(os.environ)
|
| 415 |
+
|
| 416 |
+
# If we're piping to less we might support colors under the
|
| 417 |
+
# condition that
|
| 418 |
+
cmd_detail = cmd.rsplit("/", 1)[-1].split()
|
| 419 |
+
if color is None and cmd_detail[0] == "less":
|
| 420 |
+
less_flags = f"{os.environ.get('LESS', '')}{' '.join(cmd_detail[1:])}"
|
| 421 |
+
if not less_flags:
|
| 422 |
+
env["LESS"] = "-R"
|
| 423 |
+
color = True
|
| 424 |
+
elif "r" in less_flags or "R" in less_flags:
|
| 425 |
+
color = True
|
| 426 |
+
|
| 427 |
+
c = subprocess.Popen(
|
| 428 |
+
[cmd_absolute],
|
| 429 |
+
shell=True,
|
| 430 |
+
stdin=subprocess.PIPE,
|
| 431 |
+
env=env,
|
| 432 |
+
errors="replace",
|
| 433 |
+
text=True,
|
| 434 |
+
)
|
| 435 |
+
assert c.stdin is not None
|
| 436 |
+
try:
|
| 437 |
+
for text in generator:
|
| 438 |
+
if not color:
|
| 439 |
+
text = strip_ansi(text)
|
| 440 |
+
|
| 441 |
+
c.stdin.write(text)
|
| 442 |
+
except (OSError, KeyboardInterrupt):
|
| 443 |
+
pass
|
| 444 |
+
else:
|
| 445 |
+
c.stdin.close()
|
| 446 |
+
|
| 447 |
+
# Less doesn't respect ^C, but catches it for its own UI purposes (aborting
|
| 448 |
+
# search or other commands inside less).
|
| 449 |
+
#
|
| 450 |
+
# That means when the user hits ^C, the parent process (click) terminates,
|
| 451 |
+
# but less is still alive, paging the output and messing up the terminal.
|
| 452 |
+
#
|
| 453 |
+
# If the user wants to make the pager exit on ^C, they should set
|
| 454 |
+
# `LESS='-K'`. It's not our decision to make.
|
| 455 |
+
while True:
|
| 456 |
+
try:
|
| 457 |
+
c.wait()
|
| 458 |
+
except KeyboardInterrupt:
|
| 459 |
+
pass
|
| 460 |
+
else:
|
| 461 |
+
break
|
| 462 |
+
|
| 463 |
+
return True
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
def _tempfilepager(
|
| 467 |
+
generator: t.Iterable[str],
|
| 468 |
+
cmd: str,
|
| 469 |
+
color: t.Optional[bool],
|
| 470 |
+
) -> bool:
|
| 471 |
+
"""Page through text by invoking a program on a temporary file.
|
| 472 |
+
|
| 473 |
+
Returns True if the command was found, False otherwise and thus another
|
| 474 |
+
pager should be attempted.
|
| 475 |
+
"""
|
| 476 |
+
# Which is necessary for Windows, it is also recommended in the Popen docs.
|
| 477 |
+
cmd_absolute = which(cmd)
|
| 478 |
+
if cmd_absolute is None:
|
| 479 |
+
return False
|
| 480 |
+
|
| 481 |
+
import subprocess
|
| 482 |
+
import tempfile
|
| 483 |
+
|
| 484 |
+
fd, filename = tempfile.mkstemp()
|
| 485 |
+
# TODO: This never terminates if the passed generator never terminates.
|
| 486 |
+
text = "".join(generator)
|
| 487 |
+
if not color:
|
| 488 |
+
text = strip_ansi(text)
|
| 489 |
+
encoding = get_best_encoding(sys.stdout)
|
| 490 |
+
with open_stream(filename, "wb")[0] as f:
|
| 491 |
+
f.write(text.encode(encoding))
|
| 492 |
+
try:
|
| 493 |
+
subprocess.call([cmd_absolute, filename])
|
| 494 |
+
except OSError:
|
| 495 |
+
# Command not found
|
| 496 |
+
pass
|
| 497 |
+
finally:
|
| 498 |
+
os.close(fd)
|
| 499 |
+
os.unlink(filename)
|
| 500 |
+
|
| 501 |
+
return True
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
def _nullpager(
|
| 505 |
+
stream: t.TextIO, generator: t.Iterable[str], color: t.Optional[bool]
|
| 506 |
+
) -> None:
|
| 507 |
+
"""Simply print unformatted text. This is the ultimate fallback."""
|
| 508 |
+
for text in generator:
|
| 509 |
+
if not color:
|
| 510 |
+
text = strip_ansi(text)
|
| 511 |
+
stream.write(text)
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
class Editor:
|
| 515 |
+
def __init__(
|
| 516 |
+
self,
|
| 517 |
+
editor: t.Optional[str] = None,
|
| 518 |
+
env: t.Optional[t.Mapping[str, str]] = None,
|
| 519 |
+
require_save: bool = True,
|
| 520 |
+
extension: str = ".txt",
|
| 521 |
+
) -> None:
|
| 522 |
+
self.editor = editor
|
| 523 |
+
self.env = env
|
| 524 |
+
self.require_save = require_save
|
| 525 |
+
self.extension = extension
|
| 526 |
+
|
| 527 |
+
def get_editor(self) -> str:
|
| 528 |
+
if self.editor is not None:
|
| 529 |
+
return self.editor
|
| 530 |
+
for key in "VISUAL", "EDITOR":
|
| 531 |
+
rv = os.environ.get(key)
|
| 532 |
+
if rv:
|
| 533 |
+
return rv
|
| 534 |
+
if WIN:
|
| 535 |
+
return "notepad"
|
| 536 |
+
for editor in "sensible-editor", "vim", "nano":
|
| 537 |
+
if which(editor) is not None:
|
| 538 |
+
return editor
|
| 539 |
+
return "vi"
|
| 540 |
+
|
| 541 |
+
def edit_file(self, filename: str) -> None:
|
| 542 |
+
import subprocess
|
| 543 |
+
|
| 544 |
+
editor = self.get_editor()
|
| 545 |
+
environ: t.Optional[t.Dict[str, str]] = None
|
| 546 |
+
|
| 547 |
+
if self.env:
|
| 548 |
+
environ = os.environ.copy()
|
| 549 |
+
environ.update(self.env)
|
| 550 |
+
|
| 551 |
+
try:
|
| 552 |
+
c = subprocess.Popen(f'{editor} "{filename}"', env=environ, shell=True)
|
| 553 |
+
exit_code = c.wait()
|
| 554 |
+
if exit_code != 0:
|
| 555 |
+
raise ClickException(
|
| 556 |
+
_("{editor}: Editing failed").format(editor=editor)
|
| 557 |
+
)
|
| 558 |
+
except OSError as e:
|
| 559 |
+
raise ClickException(
|
| 560 |
+
_("{editor}: Editing failed: {e}").format(editor=editor, e=e)
|
| 561 |
+
) from e
|
| 562 |
+
|
| 563 |
+
def edit(self, text: t.Optional[t.AnyStr]) -> t.Optional[t.AnyStr]:
|
| 564 |
+
import tempfile
|
| 565 |
+
|
| 566 |
+
if not text:
|
| 567 |
+
data = b""
|
| 568 |
+
elif isinstance(text, (bytes, bytearray)):
|
| 569 |
+
data = text
|
| 570 |
+
else:
|
| 571 |
+
if text and not text.endswith("\n"):
|
| 572 |
+
text += "\n"
|
| 573 |
+
|
| 574 |
+
if WIN:
|
| 575 |
+
data = text.replace("\n", "\r\n").encode("utf-8-sig")
|
| 576 |
+
else:
|
| 577 |
+
data = text.encode("utf-8")
|
| 578 |
+
|
| 579 |
+
fd, name = tempfile.mkstemp(prefix="editor-", suffix=self.extension)
|
| 580 |
+
f: t.BinaryIO
|
| 581 |
+
|
| 582 |
+
try:
|
| 583 |
+
with os.fdopen(fd, "wb") as f:
|
| 584 |
+
f.write(data)
|
| 585 |
+
|
| 586 |
+
# If the filesystem resolution is 1 second, like Mac OS
|
| 587 |
+
# 10.12 Extended, or 2 seconds, like FAT32, and the editor
|
| 588 |
+
# closes very fast, require_save can fail. Set the modified
|
| 589 |
+
# time to be 2 seconds in the past to work around this.
|
| 590 |
+
os.utime(name, (os.path.getatime(name), os.path.getmtime(name) - 2))
|
| 591 |
+
# Depending on the resolution, the exact value might not be
|
| 592 |
+
# recorded, so get the new recorded value.
|
| 593 |
+
timestamp = os.path.getmtime(name)
|
| 594 |
+
|
| 595 |
+
self.edit_file(name)
|
| 596 |
+
|
| 597 |
+
if self.require_save and os.path.getmtime(name) == timestamp:
|
| 598 |
+
return None
|
| 599 |
+
|
| 600 |
+
with open(name, "rb") as f:
|
| 601 |
+
rv = f.read()
|
| 602 |
+
|
| 603 |
+
if isinstance(text, (bytes, bytearray)):
|
| 604 |
+
return rv
|
| 605 |
+
|
| 606 |
+
return rv.decode("utf-8-sig").replace("\r\n", "\n") # type: ignore
|
| 607 |
+
finally:
|
| 608 |
+
os.unlink(name)
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
def open_url(url: str, wait: bool = False, locate: bool = False) -> int:
|
| 612 |
+
import subprocess
|
| 613 |
+
|
| 614 |
+
def _unquote_file(url: str) -> str:
|
| 615 |
+
from urllib.parse import unquote
|
| 616 |
+
|
| 617 |
+
if url.startswith("file://"):
|
| 618 |
+
url = unquote(url[7:])
|
| 619 |
+
|
| 620 |
+
return url
|
| 621 |
+
|
| 622 |
+
if sys.platform == "darwin":
|
| 623 |
+
args = ["open"]
|
| 624 |
+
if wait:
|
| 625 |
+
args.append("-W")
|
| 626 |
+
if locate:
|
| 627 |
+
args.append("-R")
|
| 628 |
+
args.append(_unquote_file(url))
|
| 629 |
+
null = open("/dev/null", "w")
|
| 630 |
+
try:
|
| 631 |
+
return subprocess.Popen(args, stderr=null).wait()
|
| 632 |
+
finally:
|
| 633 |
+
null.close()
|
| 634 |
+
elif WIN:
|
| 635 |
+
if locate:
|
| 636 |
+
url = _unquote_file(url)
|
| 637 |
+
args = ["explorer", f"/select,{url}"]
|
| 638 |
+
else:
|
| 639 |
+
args = ["start"]
|
| 640 |
+
if wait:
|
| 641 |
+
args.append("/WAIT")
|
| 642 |
+
args.append("")
|
| 643 |
+
args.append(url)
|
| 644 |
+
try:
|
| 645 |
+
return subprocess.call(args)
|
| 646 |
+
except OSError:
|
| 647 |
+
# Command not found
|
| 648 |
+
return 127
|
| 649 |
+
elif CYGWIN:
|
| 650 |
+
if locate:
|
| 651 |
+
url = _unquote_file(url)
|
| 652 |
+
args = ["cygstart", os.path.dirname(url)]
|
| 653 |
+
else:
|
| 654 |
+
args = ["cygstart"]
|
| 655 |
+
if wait:
|
| 656 |
+
args.append("-w")
|
| 657 |
+
args.append(url)
|
| 658 |
+
try:
|
| 659 |
+
return subprocess.call(args)
|
| 660 |
+
except OSError:
|
| 661 |
+
# Command not found
|
| 662 |
+
return 127
|
| 663 |
+
|
| 664 |
+
try:
|
| 665 |
+
if locate:
|
| 666 |
+
url = os.path.dirname(_unquote_file(url)) or "."
|
| 667 |
+
else:
|
| 668 |
+
url = _unquote_file(url)
|
| 669 |
+
c = subprocess.Popen(["xdg-open", url])
|
| 670 |
+
if wait:
|
| 671 |
+
return c.wait()
|
| 672 |
+
return 0
|
| 673 |
+
except OSError:
|
| 674 |
+
if url.startswith(("http://", "https://")) and not locate and not wait:
|
| 675 |
+
import webbrowser
|
| 676 |
+
|
| 677 |
+
webbrowser.open(url)
|
| 678 |
+
return 0
|
| 679 |
+
return 1
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
def _translate_ch_to_exc(ch: str) -> t.Optional[BaseException]:
|
| 683 |
+
if ch == "\x03":
|
| 684 |
+
raise KeyboardInterrupt()
|
| 685 |
+
|
| 686 |
+
if ch == "\x04" and not WIN: # Unix-like, Ctrl+D
|
| 687 |
+
raise EOFError()
|
| 688 |
+
|
| 689 |
+
if ch == "\x1a" and WIN: # Windows, Ctrl+Z
|
| 690 |
+
raise EOFError()
|
| 691 |
+
|
| 692 |
+
return None
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
if WIN:
|
| 696 |
+
import msvcrt
|
| 697 |
+
|
| 698 |
+
@contextlib.contextmanager
|
| 699 |
+
def raw_terminal() -> t.Iterator[int]:
|
| 700 |
+
yield -1
|
| 701 |
+
|
| 702 |
+
def getchar(echo: bool) -> str:
|
| 703 |
+
# The function `getch` will return a bytes object corresponding to
|
| 704 |
+
# the pressed character. Since Windows 10 build 1803, it will also
|
| 705 |
+
# return \x00 when called a second time after pressing a regular key.
|
| 706 |
+
#
|
| 707 |
+
# `getwch` does not share this probably-bugged behavior. Moreover, it
|
| 708 |
+
# returns a Unicode object by default, which is what we want.
|
| 709 |
+
#
|
| 710 |
+
# Either of these functions will return \x00 or \xe0 to indicate
|
| 711 |
+
# a special key, and you need to call the same function again to get
|
| 712 |
+
# the "rest" of the code. The fun part is that \u00e0 is
|
| 713 |
+
# "latin small letter a with grave", so if you type that on a French
|
| 714 |
+
# keyboard, you _also_ get a \xe0.
|
| 715 |
+
# E.g., consider the Up arrow. This returns \xe0 and then \x48. The
|
| 716 |
+
# resulting Unicode string reads as "a with grave" + "capital H".
|
| 717 |
+
# This is indistinguishable from when the user actually types
|
| 718 |
+
# "a with grave" and then "capital H".
|
| 719 |
+
#
|
| 720 |
+
# When \xe0 is returned, we assume it's part of a special-key sequence
|
| 721 |
+
# and call `getwch` again, but that means that when the user types
|
| 722 |
+
# the \u00e0 character, `getchar` doesn't return until a second
|
| 723 |
+
# character is typed.
|
| 724 |
+
# The alternative is returning immediately, but that would mess up
|
| 725 |
+
# cross-platform handling of arrow keys and others that start with
|
| 726 |
+
# \xe0. Another option is using `getch`, but then we can't reliably
|
| 727 |
+
# read non-ASCII characters, because return values of `getch` are
|
| 728 |
+
# limited to the current 8-bit codepage.
|
| 729 |
+
#
|
| 730 |
+
# Anyway, Click doesn't claim to do this Right(tm), and using `getwch`
|
| 731 |
+
# is doing the right thing in more situations than with `getch`.
|
| 732 |
+
func: t.Callable[[], str]
|
| 733 |
+
|
| 734 |
+
if echo:
|
| 735 |
+
func = msvcrt.getwche # type: ignore
|
| 736 |
+
else:
|
| 737 |
+
func = msvcrt.getwch # type: ignore
|
| 738 |
+
|
| 739 |
+
rv = func()
|
| 740 |
+
|
| 741 |
+
if rv in ("\x00", "\xe0"):
|
| 742 |
+
# \x00 and \xe0 are control characters that indicate special key,
|
| 743 |
+
# see above.
|
| 744 |
+
rv += func()
|
| 745 |
+
|
| 746 |
+
_translate_ch_to_exc(rv)
|
| 747 |
+
return rv
|
| 748 |
+
|
| 749 |
+
else:
|
| 750 |
+
import termios
|
| 751 |
+
import tty
|
| 752 |
+
|
| 753 |
+
@contextlib.contextmanager
|
| 754 |
+
def raw_terminal() -> t.Iterator[int]:
|
| 755 |
+
f: t.Optional[t.TextIO]
|
| 756 |
+
fd: int
|
| 757 |
+
|
| 758 |
+
if not isatty(sys.stdin):
|
| 759 |
+
f = open("/dev/tty")
|
| 760 |
+
fd = f.fileno()
|
| 761 |
+
else:
|
| 762 |
+
fd = sys.stdin.fileno()
|
| 763 |
+
f = None
|
| 764 |
+
|
| 765 |
+
try:
|
| 766 |
+
old_settings = termios.tcgetattr(fd)
|
| 767 |
+
|
| 768 |
+
try:
|
| 769 |
+
tty.setraw(fd)
|
| 770 |
+
yield fd
|
| 771 |
+
finally:
|
| 772 |
+
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
| 773 |
+
sys.stdout.flush()
|
| 774 |
+
|
| 775 |
+
if f is not None:
|
| 776 |
+
f.close()
|
| 777 |
+
except termios.error:
|
| 778 |
+
pass
|
| 779 |
+
|
| 780 |
+
def getchar(echo: bool) -> str:
|
| 781 |
+
with raw_terminal() as fd:
|
| 782 |
+
ch = os.read(fd, 32).decode(get_best_encoding(sys.stdin), "replace")
|
| 783 |
+
|
| 784 |
+
if echo and isatty(sys.stdout):
|
| 785 |
+
sys.stdout.write(ch)
|
| 786 |
+
|
| 787 |
+
_translate_ch_to_exc(ch)
|
| 788 |
+
return ch
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/_textwrap.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import textwrap
|
| 2 |
+
import typing as t
|
| 3 |
+
from contextlib import contextmanager
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class TextWrapper(textwrap.TextWrapper):
|
| 7 |
+
def _handle_long_word(
|
| 8 |
+
self,
|
| 9 |
+
reversed_chunks: t.List[str],
|
| 10 |
+
cur_line: t.List[str],
|
| 11 |
+
cur_len: int,
|
| 12 |
+
width: int,
|
| 13 |
+
) -> None:
|
| 14 |
+
space_left = max(width - cur_len, 1)
|
| 15 |
+
|
| 16 |
+
if self.break_long_words:
|
| 17 |
+
last = reversed_chunks[-1]
|
| 18 |
+
cut = last[:space_left]
|
| 19 |
+
res = last[space_left:]
|
| 20 |
+
cur_line.append(cut)
|
| 21 |
+
reversed_chunks[-1] = res
|
| 22 |
+
elif not cur_line:
|
| 23 |
+
cur_line.append(reversed_chunks.pop())
|
| 24 |
+
|
| 25 |
+
@contextmanager
|
| 26 |
+
def extra_indent(self, indent: str) -> t.Iterator[None]:
|
| 27 |
+
old_initial_indent = self.initial_indent
|
| 28 |
+
old_subsequent_indent = self.subsequent_indent
|
| 29 |
+
self.initial_indent += indent
|
| 30 |
+
self.subsequent_indent += indent
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
yield
|
| 34 |
+
finally:
|
| 35 |
+
self.initial_indent = old_initial_indent
|
| 36 |
+
self.subsequent_indent = old_subsequent_indent
|
| 37 |
+
|
| 38 |
+
def indent_only(self, text: str) -> str:
|
| 39 |
+
rv = []
|
| 40 |
+
|
| 41 |
+
for idx, line in enumerate(text.splitlines()):
|
| 42 |
+
indent = self.initial_indent
|
| 43 |
+
|
| 44 |
+
if idx > 0:
|
| 45 |
+
indent = self.subsequent_indent
|
| 46 |
+
|
| 47 |
+
rv.append(f"{indent}{line}")
|
| 48 |
+
|
| 49 |
+
return "\n".join(rv)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/_winconsole.py
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This module is based on the excellent work by Adam Bartoš who
|
| 2 |
+
# provided a lot of what went into the implementation here in
|
| 3 |
+
# the discussion to issue1602 in the Python bug tracker.
|
| 4 |
+
#
|
| 5 |
+
# There are some general differences in regards to how this works
|
| 6 |
+
# compared to the original patches as we do not need to patch
|
| 7 |
+
# the entire interpreter but just work in our little world of
|
| 8 |
+
# echo and prompt.
|
| 9 |
+
import io
|
| 10 |
+
import sys
|
| 11 |
+
import time
|
| 12 |
+
import typing as t
|
| 13 |
+
from ctypes import byref
|
| 14 |
+
from ctypes import c_char
|
| 15 |
+
from ctypes import c_char_p
|
| 16 |
+
from ctypes import c_int
|
| 17 |
+
from ctypes import c_ssize_t
|
| 18 |
+
from ctypes import c_ulong
|
| 19 |
+
from ctypes import c_void_p
|
| 20 |
+
from ctypes import POINTER
|
| 21 |
+
from ctypes import py_object
|
| 22 |
+
from ctypes import Structure
|
| 23 |
+
from ctypes.wintypes import DWORD
|
| 24 |
+
from ctypes.wintypes import HANDLE
|
| 25 |
+
from ctypes.wintypes import LPCWSTR
|
| 26 |
+
from ctypes.wintypes import LPWSTR
|
| 27 |
+
|
| 28 |
+
from ._compat import _NonClosingTextIOWrapper
|
| 29 |
+
|
| 30 |
+
assert sys.platform == "win32"
|
| 31 |
+
import msvcrt # noqa: E402
|
| 32 |
+
from ctypes import windll # noqa: E402
|
| 33 |
+
from ctypes import WINFUNCTYPE # noqa: E402
|
| 34 |
+
|
| 35 |
+
c_ssize_p = POINTER(c_ssize_t)
|
| 36 |
+
|
| 37 |
+
kernel32 = windll.kernel32
|
| 38 |
+
GetStdHandle = kernel32.GetStdHandle
|
| 39 |
+
ReadConsoleW = kernel32.ReadConsoleW
|
| 40 |
+
WriteConsoleW = kernel32.WriteConsoleW
|
| 41 |
+
GetConsoleMode = kernel32.GetConsoleMode
|
| 42 |
+
GetLastError = kernel32.GetLastError
|
| 43 |
+
GetCommandLineW = WINFUNCTYPE(LPWSTR)(("GetCommandLineW", windll.kernel32))
|
| 44 |
+
CommandLineToArgvW = WINFUNCTYPE(POINTER(LPWSTR), LPCWSTR, POINTER(c_int))(
|
| 45 |
+
("CommandLineToArgvW", windll.shell32)
|
| 46 |
+
)
|
| 47 |
+
LocalFree = WINFUNCTYPE(c_void_p, c_void_p)(("LocalFree", windll.kernel32))
|
| 48 |
+
|
| 49 |
+
STDIN_HANDLE = GetStdHandle(-10)
|
| 50 |
+
STDOUT_HANDLE = GetStdHandle(-11)
|
| 51 |
+
STDERR_HANDLE = GetStdHandle(-12)
|
| 52 |
+
|
| 53 |
+
PyBUF_SIMPLE = 0
|
| 54 |
+
PyBUF_WRITABLE = 1
|
| 55 |
+
|
| 56 |
+
ERROR_SUCCESS = 0
|
| 57 |
+
ERROR_NOT_ENOUGH_MEMORY = 8
|
| 58 |
+
ERROR_OPERATION_ABORTED = 995
|
| 59 |
+
|
| 60 |
+
STDIN_FILENO = 0
|
| 61 |
+
STDOUT_FILENO = 1
|
| 62 |
+
STDERR_FILENO = 2
|
| 63 |
+
|
| 64 |
+
EOF = b"\x1a"
|
| 65 |
+
MAX_BYTES_WRITTEN = 32767
|
| 66 |
+
|
| 67 |
+
try:
|
| 68 |
+
from ctypes import pythonapi
|
| 69 |
+
except ImportError:
|
| 70 |
+
# On PyPy we cannot get buffers so our ability to operate here is
|
| 71 |
+
# severely limited.
|
| 72 |
+
get_buffer = None
|
| 73 |
+
else:
|
| 74 |
+
|
| 75 |
+
class Py_buffer(Structure):
|
| 76 |
+
_fields_ = [
|
| 77 |
+
("buf", c_void_p),
|
| 78 |
+
("obj", py_object),
|
| 79 |
+
("len", c_ssize_t),
|
| 80 |
+
("itemsize", c_ssize_t),
|
| 81 |
+
("readonly", c_int),
|
| 82 |
+
("ndim", c_int),
|
| 83 |
+
("format", c_char_p),
|
| 84 |
+
("shape", c_ssize_p),
|
| 85 |
+
("strides", c_ssize_p),
|
| 86 |
+
("suboffsets", c_ssize_p),
|
| 87 |
+
("internal", c_void_p),
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
PyObject_GetBuffer = pythonapi.PyObject_GetBuffer
|
| 91 |
+
PyBuffer_Release = pythonapi.PyBuffer_Release
|
| 92 |
+
|
| 93 |
+
def get_buffer(obj, writable=False):
|
| 94 |
+
buf = Py_buffer()
|
| 95 |
+
flags = PyBUF_WRITABLE if writable else PyBUF_SIMPLE
|
| 96 |
+
PyObject_GetBuffer(py_object(obj), byref(buf), flags)
|
| 97 |
+
|
| 98 |
+
try:
|
| 99 |
+
buffer_type = c_char * buf.len
|
| 100 |
+
return buffer_type.from_address(buf.buf)
|
| 101 |
+
finally:
|
| 102 |
+
PyBuffer_Release(byref(buf))
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class _WindowsConsoleRawIOBase(io.RawIOBase):
|
| 106 |
+
def __init__(self, handle):
|
| 107 |
+
self.handle = handle
|
| 108 |
+
|
| 109 |
+
def isatty(self):
|
| 110 |
+
super().isatty()
|
| 111 |
+
return True
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
class _WindowsConsoleReader(_WindowsConsoleRawIOBase):
|
| 115 |
+
def readable(self):
|
| 116 |
+
return True
|
| 117 |
+
|
| 118 |
+
def readinto(self, b):
|
| 119 |
+
bytes_to_be_read = len(b)
|
| 120 |
+
if not bytes_to_be_read:
|
| 121 |
+
return 0
|
| 122 |
+
elif bytes_to_be_read % 2:
|
| 123 |
+
raise ValueError(
|
| 124 |
+
"cannot read odd number of bytes from UTF-16-LE encoded console"
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
buffer = get_buffer(b, writable=True)
|
| 128 |
+
code_units_to_be_read = bytes_to_be_read // 2
|
| 129 |
+
code_units_read = c_ulong()
|
| 130 |
+
|
| 131 |
+
rv = ReadConsoleW(
|
| 132 |
+
HANDLE(self.handle),
|
| 133 |
+
buffer,
|
| 134 |
+
code_units_to_be_read,
|
| 135 |
+
byref(code_units_read),
|
| 136 |
+
None,
|
| 137 |
+
)
|
| 138 |
+
if GetLastError() == ERROR_OPERATION_ABORTED:
|
| 139 |
+
# wait for KeyboardInterrupt
|
| 140 |
+
time.sleep(0.1)
|
| 141 |
+
if not rv:
|
| 142 |
+
raise OSError(f"Windows error: {GetLastError()}")
|
| 143 |
+
|
| 144 |
+
if buffer[0] == EOF:
|
| 145 |
+
return 0
|
| 146 |
+
return 2 * code_units_read.value
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class _WindowsConsoleWriter(_WindowsConsoleRawIOBase):
|
| 150 |
+
def writable(self):
|
| 151 |
+
return True
|
| 152 |
+
|
| 153 |
+
@staticmethod
|
| 154 |
+
def _get_error_message(errno):
|
| 155 |
+
if errno == ERROR_SUCCESS:
|
| 156 |
+
return "ERROR_SUCCESS"
|
| 157 |
+
elif errno == ERROR_NOT_ENOUGH_MEMORY:
|
| 158 |
+
return "ERROR_NOT_ENOUGH_MEMORY"
|
| 159 |
+
return f"Windows error {errno}"
|
| 160 |
+
|
| 161 |
+
def write(self, b):
|
| 162 |
+
bytes_to_be_written = len(b)
|
| 163 |
+
buf = get_buffer(b)
|
| 164 |
+
code_units_to_be_written = min(bytes_to_be_written, MAX_BYTES_WRITTEN) // 2
|
| 165 |
+
code_units_written = c_ulong()
|
| 166 |
+
|
| 167 |
+
WriteConsoleW(
|
| 168 |
+
HANDLE(self.handle),
|
| 169 |
+
buf,
|
| 170 |
+
code_units_to_be_written,
|
| 171 |
+
byref(code_units_written),
|
| 172 |
+
None,
|
| 173 |
+
)
|
| 174 |
+
bytes_written = 2 * code_units_written.value
|
| 175 |
+
|
| 176 |
+
if bytes_written == 0 and bytes_to_be_written > 0:
|
| 177 |
+
raise OSError(self._get_error_message(GetLastError()))
|
| 178 |
+
return bytes_written
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class ConsoleStream:
|
| 182 |
+
def __init__(self, text_stream: t.TextIO, byte_stream: t.BinaryIO) -> None:
|
| 183 |
+
self._text_stream = text_stream
|
| 184 |
+
self.buffer = byte_stream
|
| 185 |
+
|
| 186 |
+
@property
|
| 187 |
+
def name(self) -> str:
|
| 188 |
+
return self.buffer.name
|
| 189 |
+
|
| 190 |
+
def write(self, x: t.AnyStr) -> int:
|
| 191 |
+
if isinstance(x, str):
|
| 192 |
+
return self._text_stream.write(x)
|
| 193 |
+
try:
|
| 194 |
+
self.flush()
|
| 195 |
+
except Exception:
|
| 196 |
+
pass
|
| 197 |
+
return self.buffer.write(x)
|
| 198 |
+
|
| 199 |
+
def writelines(self, lines: t.Iterable[t.AnyStr]) -> None:
|
| 200 |
+
for line in lines:
|
| 201 |
+
self.write(line)
|
| 202 |
+
|
| 203 |
+
def __getattr__(self, name: str) -> t.Any:
|
| 204 |
+
return getattr(self._text_stream, name)
|
| 205 |
+
|
| 206 |
+
def isatty(self) -> bool:
|
| 207 |
+
return self.buffer.isatty()
|
| 208 |
+
|
| 209 |
+
def __repr__(self):
|
| 210 |
+
return f"<ConsoleStream name={self.name!r} encoding={self.encoding!r}>"
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def _get_text_stdin(buffer_stream: t.BinaryIO) -> t.TextIO:
|
| 214 |
+
text_stream = _NonClosingTextIOWrapper(
|
| 215 |
+
io.BufferedReader(_WindowsConsoleReader(STDIN_HANDLE)),
|
| 216 |
+
"utf-16-le",
|
| 217 |
+
"strict",
|
| 218 |
+
line_buffering=True,
|
| 219 |
+
)
|
| 220 |
+
return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def _get_text_stdout(buffer_stream: t.BinaryIO) -> t.TextIO:
|
| 224 |
+
text_stream = _NonClosingTextIOWrapper(
|
| 225 |
+
io.BufferedWriter(_WindowsConsoleWriter(STDOUT_HANDLE)),
|
| 226 |
+
"utf-16-le",
|
| 227 |
+
"strict",
|
| 228 |
+
line_buffering=True,
|
| 229 |
+
)
|
| 230 |
+
return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _get_text_stderr(buffer_stream: t.BinaryIO) -> t.TextIO:
|
| 234 |
+
text_stream = _NonClosingTextIOWrapper(
|
| 235 |
+
io.BufferedWriter(_WindowsConsoleWriter(STDERR_HANDLE)),
|
| 236 |
+
"utf-16-le",
|
| 237 |
+
"strict",
|
| 238 |
+
line_buffering=True,
|
| 239 |
+
)
|
| 240 |
+
return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
_stream_factories: t.Mapping[int, t.Callable[[t.BinaryIO], t.TextIO]] = {
|
| 244 |
+
0: _get_text_stdin,
|
| 245 |
+
1: _get_text_stdout,
|
| 246 |
+
2: _get_text_stderr,
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def _is_console(f: t.TextIO) -> bool:
|
| 251 |
+
if not hasattr(f, "fileno"):
|
| 252 |
+
return False
|
| 253 |
+
|
| 254 |
+
try:
|
| 255 |
+
fileno = f.fileno()
|
| 256 |
+
except (OSError, io.UnsupportedOperation):
|
| 257 |
+
return False
|
| 258 |
+
|
| 259 |
+
handle = msvcrt.get_osfhandle(fileno)
|
| 260 |
+
return bool(GetConsoleMode(handle, byref(DWORD())))
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def _get_windows_console_stream(
|
| 264 |
+
f: t.TextIO, encoding: t.Optional[str], errors: t.Optional[str]
|
| 265 |
+
) -> t.Optional[t.TextIO]:
|
| 266 |
+
if (
|
| 267 |
+
get_buffer is not None
|
| 268 |
+
and encoding in {"utf-16-le", None}
|
| 269 |
+
and errors in {"strict", None}
|
| 270 |
+
and _is_console(f)
|
| 271 |
+
):
|
| 272 |
+
func = _stream_factories.get(f.fileno())
|
| 273 |
+
if func is not None:
|
| 274 |
+
b = getattr(f, "buffer", None)
|
| 275 |
+
|
| 276 |
+
if b is None:
|
| 277 |
+
return None
|
| 278 |
+
|
| 279 |
+
return func(b)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/core.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/decorators.py
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
import types
|
| 3 |
+
import typing as t
|
| 4 |
+
from functools import update_wrapper
|
| 5 |
+
from gettext import gettext as _
|
| 6 |
+
|
| 7 |
+
from .core import Argument
|
| 8 |
+
from .core import Command
|
| 9 |
+
from .core import Context
|
| 10 |
+
from .core import Group
|
| 11 |
+
from .core import Option
|
| 12 |
+
from .core import Parameter
|
| 13 |
+
from .globals import get_current_context
|
| 14 |
+
from .utils import echo
|
| 15 |
+
|
| 16 |
+
if t.TYPE_CHECKING:
|
| 17 |
+
import typing_extensions as te
|
| 18 |
+
|
| 19 |
+
P = te.ParamSpec("P")
|
| 20 |
+
|
| 21 |
+
R = t.TypeVar("R")
|
| 22 |
+
T = t.TypeVar("T")
|
| 23 |
+
_AnyCallable = t.Callable[..., t.Any]
|
| 24 |
+
FC = t.TypeVar("FC", bound=t.Union[_AnyCallable, Command])
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def pass_context(f: "t.Callable[te.Concatenate[Context, P], R]") -> "t.Callable[P, R]":
|
| 28 |
+
"""Marks a callback as wanting to receive the current context
|
| 29 |
+
object as first argument.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def new_func(*args: "P.args", **kwargs: "P.kwargs") -> "R":
|
| 33 |
+
return f(get_current_context(), *args, **kwargs)
|
| 34 |
+
|
| 35 |
+
return update_wrapper(new_func, f)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def pass_obj(f: "t.Callable[te.Concatenate[t.Any, P], R]") -> "t.Callable[P, R]":
|
| 39 |
+
"""Similar to :func:`pass_context`, but only pass the object on the
|
| 40 |
+
context onwards (:attr:`Context.obj`). This is useful if that object
|
| 41 |
+
represents the state of a nested system.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
def new_func(*args: "P.args", **kwargs: "P.kwargs") -> "R":
|
| 45 |
+
return f(get_current_context().obj, *args, **kwargs)
|
| 46 |
+
|
| 47 |
+
return update_wrapper(new_func, f)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def make_pass_decorator(
|
| 51 |
+
object_type: t.Type[T], ensure: bool = False
|
| 52 |
+
) -> t.Callable[["t.Callable[te.Concatenate[T, P], R]"], "t.Callable[P, R]"]:
|
| 53 |
+
"""Given an object type this creates a decorator that will work
|
| 54 |
+
similar to :func:`pass_obj` but instead of passing the object of the
|
| 55 |
+
current context, it will find the innermost context of type
|
| 56 |
+
:func:`object_type`.
|
| 57 |
+
|
| 58 |
+
This generates a decorator that works roughly like this::
|
| 59 |
+
|
| 60 |
+
from functools import update_wrapper
|
| 61 |
+
|
| 62 |
+
def decorator(f):
|
| 63 |
+
@pass_context
|
| 64 |
+
def new_func(ctx, *args, **kwargs):
|
| 65 |
+
obj = ctx.find_object(object_type)
|
| 66 |
+
return ctx.invoke(f, obj, *args, **kwargs)
|
| 67 |
+
return update_wrapper(new_func, f)
|
| 68 |
+
return decorator
|
| 69 |
+
|
| 70 |
+
:param object_type: the type of the object to pass.
|
| 71 |
+
:param ensure: if set to `True`, a new object will be created and
|
| 72 |
+
remembered on the context if it's not there yet.
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
def decorator(f: "t.Callable[te.Concatenate[T, P], R]") -> "t.Callable[P, R]":
|
| 76 |
+
def new_func(*args: "P.args", **kwargs: "P.kwargs") -> "R":
|
| 77 |
+
ctx = get_current_context()
|
| 78 |
+
|
| 79 |
+
obj: t.Optional[T]
|
| 80 |
+
if ensure:
|
| 81 |
+
obj = ctx.ensure_object(object_type)
|
| 82 |
+
else:
|
| 83 |
+
obj = ctx.find_object(object_type)
|
| 84 |
+
|
| 85 |
+
if obj is None:
|
| 86 |
+
raise RuntimeError(
|
| 87 |
+
"Managed to invoke callback without a context"
|
| 88 |
+
f" object of type {object_type.__name__!r}"
|
| 89 |
+
" existing."
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
return ctx.invoke(f, obj, *args, **kwargs)
|
| 93 |
+
|
| 94 |
+
return update_wrapper(new_func, f)
|
| 95 |
+
|
| 96 |
+
return decorator
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def pass_meta_key(
|
| 100 |
+
key: str, *, doc_description: t.Optional[str] = None
|
| 101 |
+
) -> "t.Callable[[t.Callable[te.Concatenate[t.Any, P], R]], t.Callable[P, R]]":
|
| 102 |
+
"""Create a decorator that passes a key from
|
| 103 |
+
:attr:`click.Context.meta` as the first argument to the decorated
|
| 104 |
+
function.
|
| 105 |
+
|
| 106 |
+
:param key: Key in ``Context.meta`` to pass.
|
| 107 |
+
:param doc_description: Description of the object being passed,
|
| 108 |
+
inserted into the decorator's docstring. Defaults to "the 'key'
|
| 109 |
+
key from Context.meta".
|
| 110 |
+
|
| 111 |
+
.. versionadded:: 8.0
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
def decorator(f: "t.Callable[te.Concatenate[t.Any, P], R]") -> "t.Callable[P, R]":
|
| 115 |
+
def new_func(*args: "P.args", **kwargs: "P.kwargs") -> R:
|
| 116 |
+
ctx = get_current_context()
|
| 117 |
+
obj = ctx.meta[key]
|
| 118 |
+
return ctx.invoke(f, obj, *args, **kwargs)
|
| 119 |
+
|
| 120 |
+
return update_wrapper(new_func, f)
|
| 121 |
+
|
| 122 |
+
if doc_description is None:
|
| 123 |
+
doc_description = f"the {key!r} key from :attr:`click.Context.meta`"
|
| 124 |
+
|
| 125 |
+
decorator.__doc__ = (
|
| 126 |
+
f"Decorator that passes {doc_description} as the first argument"
|
| 127 |
+
" to the decorated function."
|
| 128 |
+
)
|
| 129 |
+
return decorator
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
CmdType = t.TypeVar("CmdType", bound=Command)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# variant: no call, directly as decorator for a function.
|
| 136 |
+
@t.overload
|
| 137 |
+
def command(name: _AnyCallable) -> Command: ...
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
# variant: with positional name and with positional or keyword cls argument:
|
| 141 |
+
# @command(namearg, CommandCls, ...) or @command(namearg, cls=CommandCls, ...)
|
| 142 |
+
@t.overload
|
| 143 |
+
def command(
|
| 144 |
+
name: t.Optional[str],
|
| 145 |
+
cls: t.Type[CmdType],
|
| 146 |
+
**attrs: t.Any,
|
| 147 |
+
) -> t.Callable[[_AnyCallable], CmdType]: ...
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
# variant: name omitted, cls _must_ be a keyword argument, @command(cls=CommandCls, ...)
|
| 151 |
+
@t.overload
|
| 152 |
+
def command(
|
| 153 |
+
name: None = None,
|
| 154 |
+
*,
|
| 155 |
+
cls: t.Type[CmdType],
|
| 156 |
+
**attrs: t.Any,
|
| 157 |
+
) -> t.Callable[[_AnyCallable], CmdType]: ...
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
# variant: with optional string name, no cls argument provided.
|
| 161 |
+
@t.overload
|
| 162 |
+
def command(
|
| 163 |
+
name: t.Optional[str] = ..., cls: None = None, **attrs: t.Any
|
| 164 |
+
) -> t.Callable[[_AnyCallable], Command]: ...
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def command(
|
| 168 |
+
name: t.Union[t.Optional[str], _AnyCallable] = None,
|
| 169 |
+
cls: t.Optional[t.Type[CmdType]] = None,
|
| 170 |
+
**attrs: t.Any,
|
| 171 |
+
) -> t.Union[Command, t.Callable[[_AnyCallable], t.Union[Command, CmdType]]]:
|
| 172 |
+
r"""Creates a new :class:`Command` and uses the decorated function as
|
| 173 |
+
callback. This will also automatically attach all decorated
|
| 174 |
+
:func:`option`\s and :func:`argument`\s as parameters to the command.
|
| 175 |
+
|
| 176 |
+
The name of the command defaults to the name of the function with
|
| 177 |
+
underscores replaced by dashes. If you want to change that, you can
|
| 178 |
+
pass the intended name as the first argument.
|
| 179 |
+
|
| 180 |
+
All keyword arguments are forwarded to the underlying command class.
|
| 181 |
+
For the ``params`` argument, any decorated params are appended to
|
| 182 |
+
the end of the list.
|
| 183 |
+
|
| 184 |
+
Once decorated the function turns into a :class:`Command` instance
|
| 185 |
+
that can be invoked as a command line utility or be attached to a
|
| 186 |
+
command :class:`Group`.
|
| 187 |
+
|
| 188 |
+
:param name: the name of the command. This defaults to the function
|
| 189 |
+
name with underscores replaced by dashes.
|
| 190 |
+
:param cls: the command class to instantiate. This defaults to
|
| 191 |
+
:class:`Command`.
|
| 192 |
+
|
| 193 |
+
.. versionchanged:: 8.1
|
| 194 |
+
This decorator can be applied without parentheses.
|
| 195 |
+
|
| 196 |
+
.. versionchanged:: 8.1
|
| 197 |
+
The ``params`` argument can be used. Decorated params are
|
| 198 |
+
appended to the end of the list.
|
| 199 |
+
"""
|
| 200 |
+
|
| 201 |
+
func: t.Optional[t.Callable[[_AnyCallable], t.Any]] = None
|
| 202 |
+
|
| 203 |
+
if callable(name):
|
| 204 |
+
func = name
|
| 205 |
+
name = None
|
| 206 |
+
assert cls is None, "Use 'command(cls=cls)(callable)' to specify a class."
|
| 207 |
+
assert not attrs, "Use 'command(**kwargs)(callable)' to provide arguments."
|
| 208 |
+
|
| 209 |
+
if cls is None:
|
| 210 |
+
cls = t.cast(t.Type[CmdType], Command)
|
| 211 |
+
|
| 212 |
+
def decorator(f: _AnyCallable) -> CmdType:
|
| 213 |
+
if isinstance(f, Command):
|
| 214 |
+
raise TypeError("Attempted to convert a callback into a command twice.")
|
| 215 |
+
|
| 216 |
+
attr_params = attrs.pop("params", None)
|
| 217 |
+
params = attr_params if attr_params is not None else []
|
| 218 |
+
|
| 219 |
+
try:
|
| 220 |
+
decorator_params = f.__click_params__ # type: ignore
|
| 221 |
+
except AttributeError:
|
| 222 |
+
pass
|
| 223 |
+
else:
|
| 224 |
+
del f.__click_params__ # type: ignore
|
| 225 |
+
params.extend(reversed(decorator_params))
|
| 226 |
+
|
| 227 |
+
if attrs.get("help") is None:
|
| 228 |
+
attrs["help"] = f.__doc__
|
| 229 |
+
|
| 230 |
+
if t.TYPE_CHECKING:
|
| 231 |
+
assert cls is not None
|
| 232 |
+
assert not callable(name)
|
| 233 |
+
|
| 234 |
+
cmd = cls(
|
| 235 |
+
name=name or f.__name__.lower().replace("_", "-"),
|
| 236 |
+
callback=f,
|
| 237 |
+
params=params,
|
| 238 |
+
**attrs,
|
| 239 |
+
)
|
| 240 |
+
cmd.__doc__ = f.__doc__
|
| 241 |
+
return cmd
|
| 242 |
+
|
| 243 |
+
if func is not None:
|
| 244 |
+
return decorator(func)
|
| 245 |
+
|
| 246 |
+
return decorator
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
GrpType = t.TypeVar("GrpType", bound=Group)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
# variant: no call, directly as decorator for a function.
|
| 253 |
+
@t.overload
|
| 254 |
+
def group(name: _AnyCallable) -> Group: ...
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
# variant: with positional name and with positional or keyword cls argument:
|
| 258 |
+
# @group(namearg, GroupCls, ...) or @group(namearg, cls=GroupCls, ...)
|
| 259 |
+
@t.overload
|
| 260 |
+
def group(
|
| 261 |
+
name: t.Optional[str],
|
| 262 |
+
cls: t.Type[GrpType],
|
| 263 |
+
**attrs: t.Any,
|
| 264 |
+
) -> t.Callable[[_AnyCallable], GrpType]: ...
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
# variant: name omitted, cls _must_ be a keyword argument, @group(cmd=GroupCls, ...)
|
| 268 |
+
@t.overload
|
| 269 |
+
def group(
|
| 270 |
+
name: None = None,
|
| 271 |
+
*,
|
| 272 |
+
cls: t.Type[GrpType],
|
| 273 |
+
**attrs: t.Any,
|
| 274 |
+
) -> t.Callable[[_AnyCallable], GrpType]: ...
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
# variant: with optional string name, no cls argument provided.
|
| 278 |
+
@t.overload
|
| 279 |
+
def group(
|
| 280 |
+
name: t.Optional[str] = ..., cls: None = None, **attrs: t.Any
|
| 281 |
+
) -> t.Callable[[_AnyCallable], Group]: ...
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def group(
|
| 285 |
+
name: t.Union[str, _AnyCallable, None] = None,
|
| 286 |
+
cls: t.Optional[t.Type[GrpType]] = None,
|
| 287 |
+
**attrs: t.Any,
|
| 288 |
+
) -> t.Union[Group, t.Callable[[_AnyCallable], t.Union[Group, GrpType]]]:
|
| 289 |
+
"""Creates a new :class:`Group` with a function as callback. This
|
| 290 |
+
works otherwise the same as :func:`command` just that the `cls`
|
| 291 |
+
parameter is set to :class:`Group`.
|
| 292 |
+
|
| 293 |
+
.. versionchanged:: 8.1
|
| 294 |
+
This decorator can be applied without parentheses.
|
| 295 |
+
"""
|
| 296 |
+
if cls is None:
|
| 297 |
+
cls = t.cast(t.Type[GrpType], Group)
|
| 298 |
+
|
| 299 |
+
if callable(name):
|
| 300 |
+
return command(cls=cls, **attrs)(name)
|
| 301 |
+
|
| 302 |
+
return command(name, cls, **attrs)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def _param_memo(f: t.Callable[..., t.Any], param: Parameter) -> None:
|
| 306 |
+
if isinstance(f, Command):
|
| 307 |
+
f.params.append(param)
|
| 308 |
+
else:
|
| 309 |
+
if not hasattr(f, "__click_params__"):
|
| 310 |
+
f.__click_params__ = [] # type: ignore
|
| 311 |
+
|
| 312 |
+
f.__click_params__.append(param) # type: ignore
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
def argument(
|
| 316 |
+
*param_decls: str, cls: t.Optional[t.Type[Argument]] = None, **attrs: t.Any
|
| 317 |
+
) -> t.Callable[[FC], FC]:
|
| 318 |
+
"""Attaches an argument to the command. All positional arguments are
|
| 319 |
+
passed as parameter declarations to :class:`Argument`; all keyword
|
| 320 |
+
arguments are forwarded unchanged (except ``cls``).
|
| 321 |
+
This is equivalent to creating an :class:`Argument` instance manually
|
| 322 |
+
and attaching it to the :attr:`Command.params` list.
|
| 323 |
+
|
| 324 |
+
For the default argument class, refer to :class:`Argument` and
|
| 325 |
+
:class:`Parameter` for descriptions of parameters.
|
| 326 |
+
|
| 327 |
+
:param cls: the argument class to instantiate. This defaults to
|
| 328 |
+
:class:`Argument`.
|
| 329 |
+
:param param_decls: Passed as positional arguments to the constructor of
|
| 330 |
+
``cls``.
|
| 331 |
+
:param attrs: Passed as keyword arguments to the constructor of ``cls``.
|
| 332 |
+
"""
|
| 333 |
+
if cls is None:
|
| 334 |
+
cls = Argument
|
| 335 |
+
|
| 336 |
+
def decorator(f: FC) -> FC:
|
| 337 |
+
_param_memo(f, cls(param_decls, **attrs))
|
| 338 |
+
return f
|
| 339 |
+
|
| 340 |
+
return decorator
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
def option(
|
| 344 |
+
*param_decls: str, cls: t.Optional[t.Type[Option]] = None, **attrs: t.Any
|
| 345 |
+
) -> t.Callable[[FC], FC]:
|
| 346 |
+
"""Attaches an option to the command. All positional arguments are
|
| 347 |
+
passed as parameter declarations to :class:`Option`; all keyword
|
| 348 |
+
arguments are forwarded unchanged (except ``cls``).
|
| 349 |
+
This is equivalent to creating an :class:`Option` instance manually
|
| 350 |
+
and attaching it to the :attr:`Command.params` list.
|
| 351 |
+
|
| 352 |
+
For the default option class, refer to :class:`Option` and
|
| 353 |
+
:class:`Parameter` for descriptions of parameters.
|
| 354 |
+
|
| 355 |
+
:param cls: the option class to instantiate. This defaults to
|
| 356 |
+
:class:`Option`.
|
| 357 |
+
:param param_decls: Passed as positional arguments to the constructor of
|
| 358 |
+
``cls``.
|
| 359 |
+
:param attrs: Passed as keyword arguments to the constructor of ``cls``.
|
| 360 |
+
"""
|
| 361 |
+
if cls is None:
|
| 362 |
+
cls = Option
|
| 363 |
+
|
| 364 |
+
def decorator(f: FC) -> FC:
|
| 365 |
+
_param_memo(f, cls(param_decls, **attrs))
|
| 366 |
+
return f
|
| 367 |
+
|
| 368 |
+
return decorator
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def confirmation_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
|
| 372 |
+
"""Add a ``--yes`` option which shows a prompt before continuing if
|
| 373 |
+
not passed. If the prompt is declined, the program will exit.
|
| 374 |
+
|
| 375 |
+
:param param_decls: One or more option names. Defaults to the single
|
| 376 |
+
value ``"--yes"``.
|
| 377 |
+
:param kwargs: Extra arguments are passed to :func:`option`.
|
| 378 |
+
"""
|
| 379 |
+
|
| 380 |
+
def callback(ctx: Context, param: Parameter, value: bool) -> None:
|
| 381 |
+
if not value:
|
| 382 |
+
ctx.abort()
|
| 383 |
+
|
| 384 |
+
if not param_decls:
|
| 385 |
+
param_decls = ("--yes",)
|
| 386 |
+
|
| 387 |
+
kwargs.setdefault("is_flag", True)
|
| 388 |
+
kwargs.setdefault("callback", callback)
|
| 389 |
+
kwargs.setdefault("expose_value", False)
|
| 390 |
+
kwargs.setdefault("prompt", "Do you want to continue?")
|
| 391 |
+
kwargs.setdefault("help", "Confirm the action without prompting.")
|
| 392 |
+
return option(*param_decls, **kwargs)
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
def password_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
|
| 396 |
+
"""Add a ``--password`` option which prompts for a password, hiding
|
| 397 |
+
input and asking to enter the value again for confirmation.
|
| 398 |
+
|
| 399 |
+
:param param_decls: One or more option names. Defaults to the single
|
| 400 |
+
value ``"--password"``.
|
| 401 |
+
:param kwargs: Extra arguments are passed to :func:`option`.
|
| 402 |
+
"""
|
| 403 |
+
if not param_decls:
|
| 404 |
+
param_decls = ("--password",)
|
| 405 |
+
|
| 406 |
+
kwargs.setdefault("prompt", True)
|
| 407 |
+
kwargs.setdefault("confirmation_prompt", True)
|
| 408 |
+
kwargs.setdefault("hide_input", True)
|
| 409 |
+
return option(*param_decls, **kwargs)
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
def version_option(
|
| 413 |
+
version: t.Optional[str] = None,
|
| 414 |
+
*param_decls: str,
|
| 415 |
+
package_name: t.Optional[str] = None,
|
| 416 |
+
prog_name: t.Optional[str] = None,
|
| 417 |
+
message: t.Optional[str] = None,
|
| 418 |
+
**kwargs: t.Any,
|
| 419 |
+
) -> t.Callable[[FC], FC]:
|
| 420 |
+
"""Add a ``--version`` option which immediately prints the version
|
| 421 |
+
number and exits the program.
|
| 422 |
+
|
| 423 |
+
If ``version`` is not provided, Click will try to detect it using
|
| 424 |
+
:func:`importlib.metadata.version` to get the version for the
|
| 425 |
+
``package_name``. On Python < 3.8, the ``importlib_metadata``
|
| 426 |
+
backport must be installed.
|
| 427 |
+
|
| 428 |
+
If ``package_name`` is not provided, Click will try to detect it by
|
| 429 |
+
inspecting the stack frames. This will be used to detect the
|
| 430 |
+
version, so it must match the name of the installed package.
|
| 431 |
+
|
| 432 |
+
:param version: The version number to show. If not provided, Click
|
| 433 |
+
will try to detect it.
|
| 434 |
+
:param param_decls: One or more option names. Defaults to the single
|
| 435 |
+
value ``"--version"``.
|
| 436 |
+
:param package_name: The package name to detect the version from. If
|
| 437 |
+
not provided, Click will try to detect it.
|
| 438 |
+
:param prog_name: The name of the CLI to show in the message. If not
|
| 439 |
+
provided, it will be detected from the command.
|
| 440 |
+
:param message: The message to show. The values ``%(prog)s``,
|
| 441 |
+
``%(package)s``, and ``%(version)s`` are available. Defaults to
|
| 442 |
+
``"%(prog)s, version %(version)s"``.
|
| 443 |
+
:param kwargs: Extra arguments are passed to :func:`option`.
|
| 444 |
+
:raise RuntimeError: ``version`` could not be detected.
|
| 445 |
+
|
| 446 |
+
.. versionchanged:: 8.0
|
| 447 |
+
Add the ``package_name`` parameter, and the ``%(package)s``
|
| 448 |
+
value for messages.
|
| 449 |
+
|
| 450 |
+
.. versionchanged:: 8.0
|
| 451 |
+
Use :mod:`importlib.metadata` instead of ``pkg_resources``. The
|
| 452 |
+
version is detected based on the package name, not the entry
|
| 453 |
+
point name. The Python package name must match the installed
|
| 454 |
+
package name, or be passed with ``package_name=``.
|
| 455 |
+
"""
|
| 456 |
+
if message is None:
|
| 457 |
+
message = _("%(prog)s, version %(version)s")
|
| 458 |
+
|
| 459 |
+
if version is None and package_name is None:
|
| 460 |
+
frame = inspect.currentframe()
|
| 461 |
+
f_back = frame.f_back if frame is not None else None
|
| 462 |
+
f_globals = f_back.f_globals if f_back is not None else None
|
| 463 |
+
# break reference cycle
|
| 464 |
+
# https://docs.python.org/3/library/inspect.html#the-interpreter-stack
|
| 465 |
+
del frame
|
| 466 |
+
|
| 467 |
+
if f_globals is not None:
|
| 468 |
+
package_name = f_globals.get("__name__")
|
| 469 |
+
|
| 470 |
+
if package_name == "__main__":
|
| 471 |
+
package_name = f_globals.get("__package__")
|
| 472 |
+
|
| 473 |
+
if package_name:
|
| 474 |
+
package_name = package_name.partition(".")[0]
|
| 475 |
+
|
| 476 |
+
def callback(ctx: Context, param: Parameter, value: bool) -> None:
|
| 477 |
+
if not value or ctx.resilient_parsing:
|
| 478 |
+
return
|
| 479 |
+
|
| 480 |
+
nonlocal prog_name
|
| 481 |
+
nonlocal version
|
| 482 |
+
|
| 483 |
+
if prog_name is None:
|
| 484 |
+
prog_name = ctx.find_root().info_name
|
| 485 |
+
|
| 486 |
+
if version is None and package_name is not None:
|
| 487 |
+
metadata: t.Optional[types.ModuleType]
|
| 488 |
+
|
| 489 |
+
try:
|
| 490 |
+
from importlib import metadata
|
| 491 |
+
except ImportError:
|
| 492 |
+
# Python < 3.8
|
| 493 |
+
import importlib_metadata as metadata # type: ignore
|
| 494 |
+
|
| 495 |
+
try:
|
| 496 |
+
version = metadata.version(package_name) # type: ignore
|
| 497 |
+
except metadata.PackageNotFoundError: # type: ignore
|
| 498 |
+
raise RuntimeError(
|
| 499 |
+
f"{package_name!r} is not installed. Try passing"
|
| 500 |
+
" 'package_name' instead."
|
| 501 |
+
) from None
|
| 502 |
+
|
| 503 |
+
if version is None:
|
| 504 |
+
raise RuntimeError(
|
| 505 |
+
f"Could not determine the version for {package_name!r} automatically."
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
echo(
|
| 509 |
+
message % {"prog": prog_name, "package": package_name, "version": version},
|
| 510 |
+
color=ctx.color,
|
| 511 |
+
)
|
| 512 |
+
ctx.exit()
|
| 513 |
+
|
| 514 |
+
if not param_decls:
|
| 515 |
+
param_decls = ("--version",)
|
| 516 |
+
|
| 517 |
+
kwargs.setdefault("is_flag", True)
|
| 518 |
+
kwargs.setdefault("expose_value", False)
|
| 519 |
+
kwargs.setdefault("is_eager", True)
|
| 520 |
+
kwargs.setdefault("help", _("Show the version and exit."))
|
| 521 |
+
kwargs["callback"] = callback
|
| 522 |
+
return option(*param_decls, **kwargs)
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
class HelpOption(Option):
|
| 526 |
+
"""Pre-configured ``--help`` option which immediately prints the help page
|
| 527 |
+
and exits the program.
|
| 528 |
+
"""
|
| 529 |
+
|
| 530 |
+
def __init__(
|
| 531 |
+
self,
|
| 532 |
+
param_decls: t.Optional[t.Sequence[str]] = None,
|
| 533 |
+
**kwargs: t.Any,
|
| 534 |
+
) -> None:
|
| 535 |
+
if not param_decls:
|
| 536 |
+
param_decls = ("--help",)
|
| 537 |
+
|
| 538 |
+
kwargs.setdefault("is_flag", True)
|
| 539 |
+
kwargs.setdefault("expose_value", False)
|
| 540 |
+
kwargs.setdefault("is_eager", True)
|
| 541 |
+
kwargs.setdefault("help", _("Show this message and exit."))
|
| 542 |
+
kwargs.setdefault("callback", self.show_help)
|
| 543 |
+
|
| 544 |
+
super().__init__(param_decls, **kwargs)
|
| 545 |
+
|
| 546 |
+
@staticmethod
|
| 547 |
+
def show_help(ctx: Context, param: Parameter, value: bool) -> None:
|
| 548 |
+
"""Callback that print the help page on ``<stdout>`` and exits."""
|
| 549 |
+
if value and not ctx.resilient_parsing:
|
| 550 |
+
echo(ctx.get_help(), color=ctx.color)
|
| 551 |
+
ctx.exit()
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
def help_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
|
| 555 |
+
"""Decorator for the pre-configured ``--help`` option defined above.
|
| 556 |
+
|
| 557 |
+
:param param_decls: One or more option names. Defaults to the single
|
| 558 |
+
value ``"--help"``.
|
| 559 |
+
:param kwargs: Extra arguments are passed to :func:`option`.
|
| 560 |
+
"""
|
| 561 |
+
kwargs.setdefault("cls", HelpOption)
|
| 562 |
+
return option(*param_decls, **kwargs)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/exceptions.py
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
from gettext import gettext as _
|
| 3 |
+
from gettext import ngettext
|
| 4 |
+
|
| 5 |
+
from ._compat import get_text_stderr
|
| 6 |
+
from .globals import resolve_color_default
|
| 7 |
+
from .utils import echo
|
| 8 |
+
from .utils import format_filename
|
| 9 |
+
|
| 10 |
+
if t.TYPE_CHECKING:
|
| 11 |
+
from .core import Command
|
| 12 |
+
from .core import Context
|
| 13 |
+
from .core import Parameter
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _join_param_hints(
|
| 17 |
+
param_hint: t.Optional[t.Union[t.Sequence[str], str]],
|
| 18 |
+
) -> t.Optional[str]:
|
| 19 |
+
if param_hint is not None and not isinstance(param_hint, str):
|
| 20 |
+
return " / ".join(repr(x) for x in param_hint)
|
| 21 |
+
|
| 22 |
+
return param_hint
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class ClickException(Exception):
|
| 26 |
+
"""An exception that Click can handle and show to the user."""
|
| 27 |
+
|
| 28 |
+
#: The exit code for this exception.
|
| 29 |
+
exit_code = 1
|
| 30 |
+
|
| 31 |
+
def __init__(self, message: str) -> None:
|
| 32 |
+
super().__init__(message)
|
| 33 |
+
# The context will be removed by the time we print the message, so cache
|
| 34 |
+
# the color settings here to be used later on (in `show`)
|
| 35 |
+
self.show_color: t.Optional[bool] = resolve_color_default()
|
| 36 |
+
self.message = message
|
| 37 |
+
|
| 38 |
+
def format_message(self) -> str:
|
| 39 |
+
return self.message
|
| 40 |
+
|
| 41 |
+
def __str__(self) -> str:
|
| 42 |
+
return self.message
|
| 43 |
+
|
| 44 |
+
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
|
| 45 |
+
if file is None:
|
| 46 |
+
file = get_text_stderr()
|
| 47 |
+
|
| 48 |
+
echo(
|
| 49 |
+
_("Error: {message}").format(message=self.format_message()),
|
| 50 |
+
file=file,
|
| 51 |
+
color=self.show_color,
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class UsageError(ClickException):
|
| 56 |
+
"""An internal exception that signals a usage error. This typically
|
| 57 |
+
aborts any further handling.
|
| 58 |
+
|
| 59 |
+
:param message: the error message to display.
|
| 60 |
+
:param ctx: optionally the context that caused this error. Click will
|
| 61 |
+
fill in the context automatically in some situations.
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
exit_code = 2
|
| 65 |
+
|
| 66 |
+
def __init__(self, message: str, ctx: t.Optional["Context"] = None) -> None:
|
| 67 |
+
super().__init__(message)
|
| 68 |
+
self.ctx = ctx
|
| 69 |
+
self.cmd: t.Optional[Command] = self.ctx.command if self.ctx else None
|
| 70 |
+
|
| 71 |
+
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
|
| 72 |
+
if file is None:
|
| 73 |
+
file = get_text_stderr()
|
| 74 |
+
color = None
|
| 75 |
+
hint = ""
|
| 76 |
+
if (
|
| 77 |
+
self.ctx is not None
|
| 78 |
+
and self.ctx.command.get_help_option(self.ctx) is not None
|
| 79 |
+
):
|
| 80 |
+
hint = _("Try '{command} {option}' for help.").format(
|
| 81 |
+
command=self.ctx.command_path, option=self.ctx.help_option_names[0]
|
| 82 |
+
)
|
| 83 |
+
hint = f"{hint}\n"
|
| 84 |
+
if self.ctx is not None:
|
| 85 |
+
color = self.ctx.color
|
| 86 |
+
echo(f"{self.ctx.get_usage()}\n{hint}", file=file, color=color)
|
| 87 |
+
echo(
|
| 88 |
+
_("Error: {message}").format(message=self.format_message()),
|
| 89 |
+
file=file,
|
| 90 |
+
color=color,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class BadParameter(UsageError):
|
| 95 |
+
"""An exception that formats out a standardized error message for a
|
| 96 |
+
bad parameter. This is useful when thrown from a callback or type as
|
| 97 |
+
Click will attach contextual information to it (for instance, which
|
| 98 |
+
parameter it is).
|
| 99 |
+
|
| 100 |
+
.. versionadded:: 2.0
|
| 101 |
+
|
| 102 |
+
:param param: the parameter object that caused this error. This can
|
| 103 |
+
be left out, and Click will attach this info itself
|
| 104 |
+
if possible.
|
| 105 |
+
:param param_hint: a string that shows up as parameter name. This
|
| 106 |
+
can be used as alternative to `param` in cases
|
| 107 |
+
where custom validation should happen. If it is
|
| 108 |
+
a string it's used as such, if it's a list then
|
| 109 |
+
each item is quoted and separated.
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
def __init__(
|
| 113 |
+
self,
|
| 114 |
+
message: str,
|
| 115 |
+
ctx: t.Optional["Context"] = None,
|
| 116 |
+
param: t.Optional["Parameter"] = None,
|
| 117 |
+
param_hint: t.Optional[str] = None,
|
| 118 |
+
) -> None:
|
| 119 |
+
super().__init__(message, ctx)
|
| 120 |
+
self.param = param
|
| 121 |
+
self.param_hint = param_hint
|
| 122 |
+
|
| 123 |
+
def format_message(self) -> str:
|
| 124 |
+
if self.param_hint is not None:
|
| 125 |
+
param_hint = self.param_hint
|
| 126 |
+
elif self.param is not None:
|
| 127 |
+
param_hint = self.param.get_error_hint(self.ctx) # type: ignore
|
| 128 |
+
else:
|
| 129 |
+
return _("Invalid value: {message}").format(message=self.message)
|
| 130 |
+
|
| 131 |
+
return _("Invalid value for {param_hint}: {message}").format(
|
| 132 |
+
param_hint=_join_param_hints(param_hint), message=self.message
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class MissingParameter(BadParameter):
|
| 137 |
+
"""Raised if click required an option or argument but it was not
|
| 138 |
+
provided when invoking the script.
|
| 139 |
+
|
| 140 |
+
.. versionadded:: 4.0
|
| 141 |
+
|
| 142 |
+
:param param_type: a string that indicates the type of the parameter.
|
| 143 |
+
The default is to inherit the parameter type from
|
| 144 |
+
the given `param`. Valid values are ``'parameter'``,
|
| 145 |
+
``'option'`` or ``'argument'``.
|
| 146 |
+
"""
|
| 147 |
+
|
| 148 |
+
def __init__(
|
| 149 |
+
self,
|
| 150 |
+
message: t.Optional[str] = None,
|
| 151 |
+
ctx: t.Optional["Context"] = None,
|
| 152 |
+
param: t.Optional["Parameter"] = None,
|
| 153 |
+
param_hint: t.Optional[str] = None,
|
| 154 |
+
param_type: t.Optional[str] = None,
|
| 155 |
+
) -> None:
|
| 156 |
+
super().__init__(message or "", ctx, param, param_hint)
|
| 157 |
+
self.param_type = param_type
|
| 158 |
+
|
| 159 |
+
def format_message(self) -> str:
|
| 160 |
+
if self.param_hint is not None:
|
| 161 |
+
param_hint: t.Optional[str] = self.param_hint
|
| 162 |
+
elif self.param is not None:
|
| 163 |
+
param_hint = self.param.get_error_hint(self.ctx) # type: ignore
|
| 164 |
+
else:
|
| 165 |
+
param_hint = None
|
| 166 |
+
|
| 167 |
+
param_hint = _join_param_hints(param_hint)
|
| 168 |
+
param_hint = f" {param_hint}" if param_hint else ""
|
| 169 |
+
|
| 170 |
+
param_type = self.param_type
|
| 171 |
+
if param_type is None and self.param is not None:
|
| 172 |
+
param_type = self.param.param_type_name
|
| 173 |
+
|
| 174 |
+
msg = self.message
|
| 175 |
+
if self.param is not None:
|
| 176 |
+
msg_extra = self.param.type.get_missing_message(self.param)
|
| 177 |
+
if msg_extra:
|
| 178 |
+
if msg:
|
| 179 |
+
msg += f". {msg_extra}"
|
| 180 |
+
else:
|
| 181 |
+
msg = msg_extra
|
| 182 |
+
|
| 183 |
+
msg = f" {msg}" if msg else ""
|
| 184 |
+
|
| 185 |
+
# Translate param_type for known types.
|
| 186 |
+
if param_type == "argument":
|
| 187 |
+
missing = _("Missing argument")
|
| 188 |
+
elif param_type == "option":
|
| 189 |
+
missing = _("Missing option")
|
| 190 |
+
elif param_type == "parameter":
|
| 191 |
+
missing = _("Missing parameter")
|
| 192 |
+
else:
|
| 193 |
+
missing = _("Missing {param_type}").format(param_type=param_type)
|
| 194 |
+
|
| 195 |
+
return f"{missing}{param_hint}.{msg}"
|
| 196 |
+
|
| 197 |
+
def __str__(self) -> str:
|
| 198 |
+
if not self.message:
|
| 199 |
+
param_name = self.param.name if self.param else None
|
| 200 |
+
return _("Missing parameter: {param_name}").format(param_name=param_name)
|
| 201 |
+
else:
|
| 202 |
+
return self.message
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
class NoSuchOption(UsageError):
|
| 206 |
+
"""Raised if click attempted to handle an option that does not
|
| 207 |
+
exist.
|
| 208 |
+
|
| 209 |
+
.. versionadded:: 4.0
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
def __init__(
|
| 213 |
+
self,
|
| 214 |
+
option_name: str,
|
| 215 |
+
message: t.Optional[str] = None,
|
| 216 |
+
possibilities: t.Optional[t.Sequence[str]] = None,
|
| 217 |
+
ctx: t.Optional["Context"] = None,
|
| 218 |
+
) -> None:
|
| 219 |
+
if message is None:
|
| 220 |
+
message = _("No such option: {name}").format(name=option_name)
|
| 221 |
+
|
| 222 |
+
super().__init__(message, ctx)
|
| 223 |
+
self.option_name = option_name
|
| 224 |
+
self.possibilities = possibilities
|
| 225 |
+
|
| 226 |
+
def format_message(self) -> str:
|
| 227 |
+
if not self.possibilities:
|
| 228 |
+
return self.message
|
| 229 |
+
|
| 230 |
+
possibility_str = ", ".join(sorted(self.possibilities))
|
| 231 |
+
suggest = ngettext(
|
| 232 |
+
"Did you mean {possibility}?",
|
| 233 |
+
"(Possible options: {possibilities})",
|
| 234 |
+
len(self.possibilities),
|
| 235 |
+
).format(possibility=possibility_str, possibilities=possibility_str)
|
| 236 |
+
return f"{self.message} {suggest}"
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class BadOptionUsage(UsageError):
|
| 240 |
+
"""Raised if an option is generally supplied but the use of the option
|
| 241 |
+
was incorrect. This is for instance raised if the number of arguments
|
| 242 |
+
for an option is not correct.
|
| 243 |
+
|
| 244 |
+
.. versionadded:: 4.0
|
| 245 |
+
|
| 246 |
+
:param option_name: the name of the option being used incorrectly.
|
| 247 |
+
"""
|
| 248 |
+
|
| 249 |
+
def __init__(
|
| 250 |
+
self, option_name: str, message: str, ctx: t.Optional["Context"] = None
|
| 251 |
+
) -> None:
|
| 252 |
+
super().__init__(message, ctx)
|
| 253 |
+
self.option_name = option_name
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class BadArgumentUsage(UsageError):
|
| 257 |
+
"""Raised if an argument is generally supplied but the use of the argument
|
| 258 |
+
was incorrect. This is for instance raised if the number of values
|
| 259 |
+
for an argument is not correct.
|
| 260 |
+
|
| 261 |
+
.. versionadded:: 6.0
|
| 262 |
+
"""
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
class FileError(ClickException):
|
| 266 |
+
"""Raised if a file cannot be opened."""
|
| 267 |
+
|
| 268 |
+
def __init__(self, filename: str, hint: t.Optional[str] = None) -> None:
|
| 269 |
+
if hint is None:
|
| 270 |
+
hint = _("unknown error")
|
| 271 |
+
|
| 272 |
+
super().__init__(hint)
|
| 273 |
+
self.ui_filename: str = format_filename(filename)
|
| 274 |
+
self.filename = filename
|
| 275 |
+
|
| 276 |
+
def format_message(self) -> str:
|
| 277 |
+
return _("Could not open file {filename!r}: {message}").format(
|
| 278 |
+
filename=self.ui_filename, message=self.message
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
class Abort(RuntimeError):
|
| 283 |
+
"""An internal signalling exception that signals Click to abort."""
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
class Exit(RuntimeError):
|
| 287 |
+
"""An exception that indicates that the application should exit with some
|
| 288 |
+
status code.
|
| 289 |
+
|
| 290 |
+
:param code: the status code to exit with.
|
| 291 |
+
"""
|
| 292 |
+
|
| 293 |
+
__slots__ = ("exit_code",)
|
| 294 |
+
|
| 295 |
+
def __init__(self, code: int = 0) -> None:
|
| 296 |
+
self.exit_code: int = code
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/formatting.py
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
from contextlib import contextmanager
|
| 3 |
+
from gettext import gettext as _
|
| 4 |
+
|
| 5 |
+
from ._compat import term_len
|
| 6 |
+
from .parser import split_opt
|
| 7 |
+
|
| 8 |
+
# Can force a width. This is used by the test system
|
| 9 |
+
FORCED_WIDTH: t.Optional[int] = None
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def measure_table(rows: t.Iterable[t.Tuple[str, str]]) -> t.Tuple[int, ...]:
|
| 13 |
+
widths: t.Dict[int, int] = {}
|
| 14 |
+
|
| 15 |
+
for row in rows:
|
| 16 |
+
for idx, col in enumerate(row):
|
| 17 |
+
widths[idx] = max(widths.get(idx, 0), term_len(col))
|
| 18 |
+
|
| 19 |
+
return tuple(y for x, y in sorted(widths.items()))
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def iter_rows(
|
| 23 |
+
rows: t.Iterable[t.Tuple[str, str]], col_count: int
|
| 24 |
+
) -> t.Iterator[t.Tuple[str, ...]]:
|
| 25 |
+
for row in rows:
|
| 26 |
+
yield row + ("",) * (col_count - len(row))
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def wrap_text(
|
| 30 |
+
text: str,
|
| 31 |
+
width: int = 78,
|
| 32 |
+
initial_indent: str = "",
|
| 33 |
+
subsequent_indent: str = "",
|
| 34 |
+
preserve_paragraphs: bool = False,
|
| 35 |
+
) -> str:
|
| 36 |
+
"""A helper function that intelligently wraps text. By default, it
|
| 37 |
+
assumes that it operates on a single paragraph of text but if the
|
| 38 |
+
`preserve_paragraphs` parameter is provided it will intelligently
|
| 39 |
+
handle paragraphs (defined by two empty lines).
|
| 40 |
+
|
| 41 |
+
If paragraphs are handled, a paragraph can be prefixed with an empty
|
| 42 |
+
line containing the ``\\b`` character (``\\x08``) to indicate that
|
| 43 |
+
no rewrapping should happen in that block.
|
| 44 |
+
|
| 45 |
+
:param text: the text that should be rewrapped.
|
| 46 |
+
:param width: the maximum width for the text.
|
| 47 |
+
:param initial_indent: the initial indent that should be placed on the
|
| 48 |
+
first line as a string.
|
| 49 |
+
:param subsequent_indent: the indent string that should be placed on
|
| 50 |
+
each consecutive line.
|
| 51 |
+
:param preserve_paragraphs: if this flag is set then the wrapping will
|
| 52 |
+
intelligently handle paragraphs.
|
| 53 |
+
"""
|
| 54 |
+
from ._textwrap import TextWrapper
|
| 55 |
+
|
| 56 |
+
text = text.expandtabs()
|
| 57 |
+
wrapper = TextWrapper(
|
| 58 |
+
width,
|
| 59 |
+
initial_indent=initial_indent,
|
| 60 |
+
subsequent_indent=subsequent_indent,
|
| 61 |
+
replace_whitespace=False,
|
| 62 |
+
)
|
| 63 |
+
if not preserve_paragraphs:
|
| 64 |
+
return wrapper.fill(text)
|
| 65 |
+
|
| 66 |
+
p: t.List[t.Tuple[int, bool, str]] = []
|
| 67 |
+
buf: t.List[str] = []
|
| 68 |
+
indent = None
|
| 69 |
+
|
| 70 |
+
def _flush_par() -> None:
|
| 71 |
+
if not buf:
|
| 72 |
+
return
|
| 73 |
+
if buf[0].strip() == "\b":
|
| 74 |
+
p.append((indent or 0, True, "\n".join(buf[1:])))
|
| 75 |
+
else:
|
| 76 |
+
p.append((indent or 0, False, " ".join(buf)))
|
| 77 |
+
del buf[:]
|
| 78 |
+
|
| 79 |
+
for line in text.splitlines():
|
| 80 |
+
if not line:
|
| 81 |
+
_flush_par()
|
| 82 |
+
indent = None
|
| 83 |
+
else:
|
| 84 |
+
if indent is None:
|
| 85 |
+
orig_len = term_len(line)
|
| 86 |
+
line = line.lstrip()
|
| 87 |
+
indent = orig_len - term_len(line)
|
| 88 |
+
buf.append(line)
|
| 89 |
+
_flush_par()
|
| 90 |
+
|
| 91 |
+
rv = []
|
| 92 |
+
for indent, raw, text in p:
|
| 93 |
+
with wrapper.extra_indent(" " * indent):
|
| 94 |
+
if raw:
|
| 95 |
+
rv.append(wrapper.indent_only(text))
|
| 96 |
+
else:
|
| 97 |
+
rv.append(wrapper.fill(text))
|
| 98 |
+
|
| 99 |
+
return "\n\n".join(rv)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class HelpFormatter:
|
| 103 |
+
"""This class helps with formatting text-based help pages. It's
|
| 104 |
+
usually just needed for very special internal cases, but it's also
|
| 105 |
+
exposed so that developers can write their own fancy outputs.
|
| 106 |
+
|
| 107 |
+
At present, it always writes into memory.
|
| 108 |
+
|
| 109 |
+
:param indent_increment: the additional increment for each level.
|
| 110 |
+
:param width: the width for the text. This defaults to the terminal
|
| 111 |
+
width clamped to a maximum of 78.
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
def __init__(
|
| 115 |
+
self,
|
| 116 |
+
indent_increment: int = 2,
|
| 117 |
+
width: t.Optional[int] = None,
|
| 118 |
+
max_width: t.Optional[int] = None,
|
| 119 |
+
) -> None:
|
| 120 |
+
import shutil
|
| 121 |
+
|
| 122 |
+
self.indent_increment = indent_increment
|
| 123 |
+
if max_width is None:
|
| 124 |
+
max_width = 80
|
| 125 |
+
if width is None:
|
| 126 |
+
width = FORCED_WIDTH
|
| 127 |
+
if width is None:
|
| 128 |
+
width = max(min(shutil.get_terminal_size().columns, max_width) - 2, 50)
|
| 129 |
+
self.width = width
|
| 130 |
+
self.current_indent = 0
|
| 131 |
+
self.buffer: t.List[str] = []
|
| 132 |
+
|
| 133 |
+
def write(self, string: str) -> None:
|
| 134 |
+
"""Writes a unicode string into the internal buffer."""
|
| 135 |
+
self.buffer.append(string)
|
| 136 |
+
|
| 137 |
+
def indent(self) -> None:
|
| 138 |
+
"""Increases the indentation."""
|
| 139 |
+
self.current_indent += self.indent_increment
|
| 140 |
+
|
| 141 |
+
def dedent(self) -> None:
|
| 142 |
+
"""Decreases the indentation."""
|
| 143 |
+
self.current_indent -= self.indent_increment
|
| 144 |
+
|
| 145 |
+
def write_usage(
|
| 146 |
+
self, prog: str, args: str = "", prefix: t.Optional[str] = None
|
| 147 |
+
) -> None:
|
| 148 |
+
"""Writes a usage line into the buffer.
|
| 149 |
+
|
| 150 |
+
:param prog: the program name.
|
| 151 |
+
:param args: whitespace separated list of arguments.
|
| 152 |
+
:param prefix: The prefix for the first line. Defaults to
|
| 153 |
+
``"Usage: "``.
|
| 154 |
+
"""
|
| 155 |
+
if prefix is None:
|
| 156 |
+
prefix = f"{_('Usage:')} "
|
| 157 |
+
|
| 158 |
+
usage_prefix = f"{prefix:>{self.current_indent}}{prog} "
|
| 159 |
+
text_width = self.width - self.current_indent
|
| 160 |
+
|
| 161 |
+
if text_width >= (term_len(usage_prefix) + 20):
|
| 162 |
+
# The arguments will fit to the right of the prefix.
|
| 163 |
+
indent = " " * term_len(usage_prefix)
|
| 164 |
+
self.write(
|
| 165 |
+
wrap_text(
|
| 166 |
+
args,
|
| 167 |
+
text_width,
|
| 168 |
+
initial_indent=usage_prefix,
|
| 169 |
+
subsequent_indent=indent,
|
| 170 |
+
)
|
| 171 |
+
)
|
| 172 |
+
else:
|
| 173 |
+
# The prefix is too long, put the arguments on the next line.
|
| 174 |
+
self.write(usage_prefix)
|
| 175 |
+
self.write("\n")
|
| 176 |
+
indent = " " * (max(self.current_indent, term_len(prefix)) + 4)
|
| 177 |
+
self.write(
|
| 178 |
+
wrap_text(
|
| 179 |
+
args, text_width, initial_indent=indent, subsequent_indent=indent
|
| 180 |
+
)
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
self.write("\n")
|
| 184 |
+
|
| 185 |
+
def write_heading(self, heading: str) -> None:
|
| 186 |
+
"""Writes a heading into the buffer."""
|
| 187 |
+
self.write(f"{'':>{self.current_indent}}{heading}:\n")
|
| 188 |
+
|
| 189 |
+
def write_paragraph(self) -> None:
|
| 190 |
+
"""Writes a paragraph into the buffer."""
|
| 191 |
+
if self.buffer:
|
| 192 |
+
self.write("\n")
|
| 193 |
+
|
| 194 |
+
def write_text(self, text: str) -> None:
|
| 195 |
+
"""Writes re-indented text into the buffer. This rewraps and
|
| 196 |
+
preserves paragraphs.
|
| 197 |
+
"""
|
| 198 |
+
indent = " " * self.current_indent
|
| 199 |
+
self.write(
|
| 200 |
+
wrap_text(
|
| 201 |
+
text,
|
| 202 |
+
self.width,
|
| 203 |
+
initial_indent=indent,
|
| 204 |
+
subsequent_indent=indent,
|
| 205 |
+
preserve_paragraphs=True,
|
| 206 |
+
)
|
| 207 |
+
)
|
| 208 |
+
self.write("\n")
|
| 209 |
+
|
| 210 |
+
def write_dl(
|
| 211 |
+
self,
|
| 212 |
+
rows: t.Sequence[t.Tuple[str, str]],
|
| 213 |
+
col_max: int = 30,
|
| 214 |
+
col_spacing: int = 2,
|
| 215 |
+
) -> None:
|
| 216 |
+
"""Writes a definition list into the buffer. This is how options
|
| 217 |
+
and commands are usually formatted.
|
| 218 |
+
|
| 219 |
+
:param rows: a list of two item tuples for the terms and values.
|
| 220 |
+
:param col_max: the maximum width of the first column.
|
| 221 |
+
:param col_spacing: the number of spaces between the first and
|
| 222 |
+
second column.
|
| 223 |
+
"""
|
| 224 |
+
rows = list(rows)
|
| 225 |
+
widths = measure_table(rows)
|
| 226 |
+
if len(widths) != 2:
|
| 227 |
+
raise TypeError("Expected two columns for definition list")
|
| 228 |
+
|
| 229 |
+
first_col = min(widths[0], col_max) + col_spacing
|
| 230 |
+
|
| 231 |
+
for first, second in iter_rows(rows, len(widths)):
|
| 232 |
+
self.write(f"{'':>{self.current_indent}}{first}")
|
| 233 |
+
if not second:
|
| 234 |
+
self.write("\n")
|
| 235 |
+
continue
|
| 236 |
+
if term_len(first) <= first_col - col_spacing:
|
| 237 |
+
self.write(" " * (first_col - term_len(first)))
|
| 238 |
+
else:
|
| 239 |
+
self.write("\n")
|
| 240 |
+
self.write(" " * (first_col + self.current_indent))
|
| 241 |
+
|
| 242 |
+
text_width = max(self.width - first_col - 2, 10)
|
| 243 |
+
wrapped_text = wrap_text(second, text_width, preserve_paragraphs=True)
|
| 244 |
+
lines = wrapped_text.splitlines()
|
| 245 |
+
|
| 246 |
+
if lines:
|
| 247 |
+
self.write(f"{lines[0]}\n")
|
| 248 |
+
|
| 249 |
+
for line in lines[1:]:
|
| 250 |
+
self.write(f"{'':>{first_col + self.current_indent}}{line}\n")
|
| 251 |
+
else:
|
| 252 |
+
self.write("\n")
|
| 253 |
+
|
| 254 |
+
@contextmanager
|
| 255 |
+
def section(self, name: str) -> t.Iterator[None]:
|
| 256 |
+
"""Helpful context manager that writes a paragraph, a heading,
|
| 257 |
+
and the indents.
|
| 258 |
+
|
| 259 |
+
:param name: the section name that is written as heading.
|
| 260 |
+
"""
|
| 261 |
+
self.write_paragraph()
|
| 262 |
+
self.write_heading(name)
|
| 263 |
+
self.indent()
|
| 264 |
+
try:
|
| 265 |
+
yield
|
| 266 |
+
finally:
|
| 267 |
+
self.dedent()
|
| 268 |
+
|
| 269 |
+
@contextmanager
|
| 270 |
+
def indentation(self) -> t.Iterator[None]:
|
| 271 |
+
"""A context manager that increases the indentation."""
|
| 272 |
+
self.indent()
|
| 273 |
+
try:
|
| 274 |
+
yield
|
| 275 |
+
finally:
|
| 276 |
+
self.dedent()
|
| 277 |
+
|
| 278 |
+
def getvalue(self) -> str:
|
| 279 |
+
"""Returns the buffer contents."""
|
| 280 |
+
return "".join(self.buffer)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def join_options(options: t.Sequence[str]) -> t.Tuple[str, bool]:
|
| 284 |
+
"""Given a list of option strings this joins them in the most appropriate
|
| 285 |
+
way and returns them in the form ``(formatted_string,
|
| 286 |
+
any_prefix_is_slash)`` where the second item in the tuple is a flag that
|
| 287 |
+
indicates if any of the option prefixes was a slash.
|
| 288 |
+
"""
|
| 289 |
+
rv = []
|
| 290 |
+
any_prefix_is_slash = False
|
| 291 |
+
|
| 292 |
+
for opt in options:
|
| 293 |
+
prefix = split_opt(opt)[0]
|
| 294 |
+
|
| 295 |
+
if prefix == "/":
|
| 296 |
+
any_prefix_is_slash = True
|
| 297 |
+
|
| 298 |
+
rv.append((len(prefix), opt))
|
| 299 |
+
|
| 300 |
+
rv.sort(key=lambda x: x[0])
|
| 301 |
+
return ", ".join(x[1] for x in rv), any_prefix_is_slash
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/globals.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
from threading import local
|
| 3 |
+
|
| 4 |
+
if t.TYPE_CHECKING:
|
| 5 |
+
import typing_extensions as te
|
| 6 |
+
|
| 7 |
+
from .core import Context
|
| 8 |
+
|
| 9 |
+
_local = local()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@t.overload
|
| 13 |
+
def get_current_context(silent: "te.Literal[False]" = False) -> "Context": ...
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@t.overload
|
| 17 |
+
def get_current_context(silent: bool = ...) -> t.Optional["Context"]: ...
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def get_current_context(silent: bool = False) -> t.Optional["Context"]:
|
| 21 |
+
"""Returns the current click context. This can be used as a way to
|
| 22 |
+
access the current context object from anywhere. This is a more implicit
|
| 23 |
+
alternative to the :func:`pass_context` decorator. This function is
|
| 24 |
+
primarily useful for helpers such as :func:`echo` which might be
|
| 25 |
+
interested in changing its behavior based on the current context.
|
| 26 |
+
|
| 27 |
+
To push the current context, :meth:`Context.scope` can be used.
|
| 28 |
+
|
| 29 |
+
.. versionadded:: 5.0
|
| 30 |
+
|
| 31 |
+
:param silent: if set to `True` the return value is `None` if no context
|
| 32 |
+
is available. The default behavior is to raise a
|
| 33 |
+
:exc:`RuntimeError`.
|
| 34 |
+
"""
|
| 35 |
+
try:
|
| 36 |
+
return t.cast("Context", _local.stack[-1])
|
| 37 |
+
except (AttributeError, IndexError) as e:
|
| 38 |
+
if not silent:
|
| 39 |
+
raise RuntimeError("There is no active click context.") from e
|
| 40 |
+
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def push_context(ctx: "Context") -> None:
|
| 45 |
+
"""Pushes a new context to the current stack."""
|
| 46 |
+
_local.__dict__.setdefault("stack", []).append(ctx)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def pop_context() -> None:
|
| 50 |
+
"""Removes the top level from the stack."""
|
| 51 |
+
_local.stack.pop()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def resolve_color_default(color: t.Optional[bool] = None) -> t.Optional[bool]:
|
| 55 |
+
"""Internal helper to get the default value of the color flag. If a
|
| 56 |
+
value is passed it's returned unchanged, otherwise it's looked up from
|
| 57 |
+
the current context.
|
| 58 |
+
"""
|
| 59 |
+
if color is not None:
|
| 60 |
+
return color
|
| 61 |
+
|
| 62 |
+
ctx = get_current_context(silent=True)
|
| 63 |
+
|
| 64 |
+
if ctx is not None:
|
| 65 |
+
return ctx.color
|
| 66 |
+
|
| 67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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module started out as largely a copy paste from the stdlib's
|
| 3 |
+
optparse module with the features removed that we do not need from
|
| 4 |
+
optparse because we implement them in Click on a higher level (for
|
| 5 |
+
instance type handling, help formatting and a lot more).
|
| 6 |
+
|
| 7 |
+
The plan is to remove more and more from here over time.
|
| 8 |
+
|
| 9 |
+
The reason this is a different module and not optparse from the stdlib
|
| 10 |
+
is that there are differences in 2.x and 3.x about the error messages
|
| 11 |
+
generated and optparse in the stdlib uses gettext for no good reason
|
| 12 |
+
and might cause us issues.
|
| 13 |
+
|
| 14 |
+
Click uses parts of optparse written by Gregory P. Ward and maintained
|
| 15 |
+
by the Python Software Foundation. This is limited to code in parser.py.
|
| 16 |
+
|
| 17 |
+
Copyright 2001-2006 Gregory P. Ward. All rights reserved.
|
| 18 |
+
Copyright 2002-2006 Python Software Foundation. All rights reserved.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# This code uses parts of optparse written by Gregory P. Ward and
|
| 22 |
+
# maintained by the Python Software Foundation.
|
| 23 |
+
# Copyright 2001-2006 Gregory P. Ward
|
| 24 |
+
# Copyright 2002-2006 Python Software Foundation
|
| 25 |
+
import typing as t
|
| 26 |
+
from collections import deque
|
| 27 |
+
from gettext import gettext as _
|
| 28 |
+
from gettext import ngettext
|
| 29 |
+
|
| 30 |
+
from .exceptions import BadArgumentUsage
|
| 31 |
+
from .exceptions import BadOptionUsage
|
| 32 |
+
from .exceptions import NoSuchOption
|
| 33 |
+
from .exceptions import UsageError
|
| 34 |
+
|
| 35 |
+
if t.TYPE_CHECKING:
|
| 36 |
+
import typing_extensions as te
|
| 37 |
+
|
| 38 |
+
from .core import Argument as CoreArgument
|
| 39 |
+
from .core import Context
|
| 40 |
+
from .core import Option as CoreOption
|
| 41 |
+
from .core import Parameter as CoreParameter
|
| 42 |
+
|
| 43 |
+
V = t.TypeVar("V")
|
| 44 |
+
|
| 45 |
+
# Sentinel value that indicates an option was passed as a flag without a
|
| 46 |
+
# value but is not a flag option. Option.consume_value uses this to
|
| 47 |
+
# prompt or use the flag_value.
|
| 48 |
+
_flag_needs_value = object()
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _unpack_args(
|
| 52 |
+
args: t.Sequence[str], nargs_spec: t.Sequence[int]
|
| 53 |
+
) -> t.Tuple[t.Sequence[t.Union[str, t.Sequence[t.Optional[str]], None]], t.List[str]]:
|
| 54 |
+
"""Given an iterable of arguments and an iterable of nargs specifications,
|
| 55 |
+
it returns a tuple with all the unpacked arguments at the first index
|
| 56 |
+
and all remaining arguments as the second.
|
| 57 |
+
|
| 58 |
+
The nargs specification is the number of arguments that should be consumed
|
| 59 |
+
or `-1` to indicate that this position should eat up all the remainders.
|
| 60 |
+
|
| 61 |
+
Missing items are filled with `None`.
|
| 62 |
+
"""
|
| 63 |
+
args = deque(args)
|
| 64 |
+
nargs_spec = deque(nargs_spec)
|
| 65 |
+
rv: t.List[t.Union[str, t.Tuple[t.Optional[str], ...], None]] = []
|
| 66 |
+
spos: t.Optional[int] = None
|
| 67 |
+
|
| 68 |
+
def _fetch(c: "te.Deque[V]") -> t.Optional[V]:
|
| 69 |
+
try:
|
| 70 |
+
if spos is None:
|
| 71 |
+
return c.popleft()
|
| 72 |
+
else:
|
| 73 |
+
return c.pop()
|
| 74 |
+
except IndexError:
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
while nargs_spec:
|
| 78 |
+
nargs = _fetch(nargs_spec)
|
| 79 |
+
|
| 80 |
+
if nargs is None:
|
| 81 |
+
continue
|
| 82 |
+
|
| 83 |
+
if nargs == 1:
|
| 84 |
+
rv.append(_fetch(args))
|
| 85 |
+
elif nargs > 1:
|
| 86 |
+
x = [_fetch(args) for _ in range(nargs)]
|
| 87 |
+
|
| 88 |
+
# If we're reversed, we're pulling in the arguments in reverse,
|
| 89 |
+
# so we need to turn them around.
|
| 90 |
+
if spos is not None:
|
| 91 |
+
x.reverse()
|
| 92 |
+
|
| 93 |
+
rv.append(tuple(x))
|
| 94 |
+
elif nargs < 0:
|
| 95 |
+
if spos is not None:
|
| 96 |
+
raise TypeError("Cannot have two nargs < 0")
|
| 97 |
+
|
| 98 |
+
spos = len(rv)
|
| 99 |
+
rv.append(None)
|
| 100 |
+
|
| 101 |
+
# spos is the position of the wildcard (star). If it's not `None`,
|
| 102 |
+
# we fill it with the remainder.
|
| 103 |
+
if spos is not None:
|
| 104 |
+
rv[spos] = tuple(args)
|
| 105 |
+
args = []
|
| 106 |
+
rv[spos + 1 :] = reversed(rv[spos + 1 :])
|
| 107 |
+
|
| 108 |
+
return tuple(rv), list(args)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def split_opt(opt: str) -> t.Tuple[str, str]:
|
| 112 |
+
first = opt[:1]
|
| 113 |
+
if first.isalnum():
|
| 114 |
+
return "", opt
|
| 115 |
+
if opt[1:2] == first:
|
| 116 |
+
return opt[:2], opt[2:]
|
| 117 |
+
return first, opt[1:]
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def normalize_opt(opt: str, ctx: t.Optional["Context"]) -> str:
|
| 121 |
+
if ctx is None or ctx.token_normalize_func is None:
|
| 122 |
+
return opt
|
| 123 |
+
prefix, opt = split_opt(opt)
|
| 124 |
+
return f"{prefix}{ctx.token_normalize_func(opt)}"
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def split_arg_string(string: str) -> t.List[str]:
|
| 128 |
+
"""Split an argument string as with :func:`shlex.split`, but don't
|
| 129 |
+
fail if the string is incomplete. Ignores a missing closing quote or
|
| 130 |
+
incomplete escape sequence and uses the partial token as-is.
|
| 131 |
+
|
| 132 |
+
.. code-block:: python
|
| 133 |
+
|
| 134 |
+
split_arg_string("example 'my file")
|
| 135 |
+
["example", "my file"]
|
| 136 |
+
|
| 137 |
+
split_arg_string("example my\\")
|
| 138 |
+
["example", "my"]
|
| 139 |
+
|
| 140 |
+
:param string: String to split.
|
| 141 |
+
"""
|
| 142 |
+
import shlex
|
| 143 |
+
|
| 144 |
+
lex = shlex.shlex(string, posix=True)
|
| 145 |
+
lex.whitespace_split = True
|
| 146 |
+
lex.commenters = ""
|
| 147 |
+
out = []
|
| 148 |
+
|
| 149 |
+
try:
|
| 150 |
+
for token in lex:
|
| 151 |
+
out.append(token)
|
| 152 |
+
except ValueError:
|
| 153 |
+
# Raised when end-of-string is reached in an invalid state. Use
|
| 154 |
+
# the partial token as-is. The quote or escape character is in
|
| 155 |
+
# lex.state, not lex.token.
|
| 156 |
+
out.append(lex.token)
|
| 157 |
+
|
| 158 |
+
return out
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class Option:
|
| 162 |
+
def __init__(
|
| 163 |
+
self,
|
| 164 |
+
obj: "CoreOption",
|
| 165 |
+
opts: t.Sequence[str],
|
| 166 |
+
dest: t.Optional[str],
|
| 167 |
+
action: t.Optional[str] = None,
|
| 168 |
+
nargs: int = 1,
|
| 169 |
+
const: t.Optional[t.Any] = None,
|
| 170 |
+
):
|
| 171 |
+
self._short_opts = []
|
| 172 |
+
self._long_opts = []
|
| 173 |
+
self.prefixes: t.Set[str] = set()
|
| 174 |
+
|
| 175 |
+
for opt in opts:
|
| 176 |
+
prefix, value = split_opt(opt)
|
| 177 |
+
if not prefix:
|
| 178 |
+
raise ValueError(f"Invalid start character for option ({opt})")
|
| 179 |
+
self.prefixes.add(prefix[0])
|
| 180 |
+
if len(prefix) == 1 and len(value) == 1:
|
| 181 |
+
self._short_opts.append(opt)
|
| 182 |
+
else:
|
| 183 |
+
self._long_opts.append(opt)
|
| 184 |
+
self.prefixes.add(prefix)
|
| 185 |
+
|
| 186 |
+
if action is None:
|
| 187 |
+
action = "store"
|
| 188 |
+
|
| 189 |
+
self.dest = dest
|
| 190 |
+
self.action = action
|
| 191 |
+
self.nargs = nargs
|
| 192 |
+
self.const = const
|
| 193 |
+
self.obj = obj
|
| 194 |
+
|
| 195 |
+
@property
|
| 196 |
+
def takes_value(self) -> bool:
|
| 197 |
+
return self.action in ("store", "append")
|
| 198 |
+
|
| 199 |
+
def process(self, value: t.Any, state: "ParsingState") -> None:
|
| 200 |
+
if self.action == "store":
|
| 201 |
+
state.opts[self.dest] = value # type: ignore
|
| 202 |
+
elif self.action == "store_const":
|
| 203 |
+
state.opts[self.dest] = self.const # type: ignore
|
| 204 |
+
elif self.action == "append":
|
| 205 |
+
state.opts.setdefault(self.dest, []).append(value) # type: ignore
|
| 206 |
+
elif self.action == "append_const":
|
| 207 |
+
state.opts.setdefault(self.dest, []).append(self.const) # type: ignore
|
| 208 |
+
elif self.action == "count":
|
| 209 |
+
state.opts[self.dest] = state.opts.get(self.dest, 0) + 1 # type: ignore
|
| 210 |
+
else:
|
| 211 |
+
raise ValueError(f"unknown action '{self.action}'")
|
| 212 |
+
state.order.append(self.obj)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
class Argument:
|
| 216 |
+
def __init__(self, obj: "CoreArgument", dest: t.Optional[str], nargs: int = 1):
|
| 217 |
+
self.dest = dest
|
| 218 |
+
self.nargs = nargs
|
| 219 |
+
self.obj = obj
|
| 220 |
+
|
| 221 |
+
def process(
|
| 222 |
+
self,
|
| 223 |
+
value: t.Union[t.Optional[str], t.Sequence[t.Optional[str]]],
|
| 224 |
+
state: "ParsingState",
|
| 225 |
+
) -> None:
|
| 226 |
+
if self.nargs > 1:
|
| 227 |
+
assert value is not None
|
| 228 |
+
holes = sum(1 for x in value if x is None)
|
| 229 |
+
if holes == len(value):
|
| 230 |
+
value = None
|
| 231 |
+
elif holes != 0:
|
| 232 |
+
raise BadArgumentUsage(
|
| 233 |
+
_("Argument {name!r} takes {nargs} values.").format(
|
| 234 |
+
name=self.dest, nargs=self.nargs
|
| 235 |
+
)
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
if self.nargs == -1 and self.obj.envvar is not None and value == ():
|
| 239 |
+
# Replace empty tuple with None so that a value from the
|
| 240 |
+
# environment may be tried.
|
| 241 |
+
value = None
|
| 242 |
+
|
| 243 |
+
state.opts[self.dest] = value # type: ignore
|
| 244 |
+
state.order.append(self.obj)
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
class ParsingState:
|
| 248 |
+
def __init__(self, rargs: t.List[str]) -> None:
|
| 249 |
+
self.opts: t.Dict[str, t.Any] = {}
|
| 250 |
+
self.largs: t.List[str] = []
|
| 251 |
+
self.rargs = rargs
|
| 252 |
+
self.order: t.List[CoreParameter] = []
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
class OptionParser:
|
| 256 |
+
"""The option parser is an internal class that is ultimately used to
|
| 257 |
+
parse options and arguments. It's modelled after optparse and brings
|
| 258 |
+
a similar but vastly simplified API. It should generally not be used
|
| 259 |
+
directly as the high level Click classes wrap it for you.
|
| 260 |
+
|
| 261 |
+
It's not nearly as extensible as optparse or argparse as it does not
|
| 262 |
+
implement features that are implemented on a higher level (such as
|
| 263 |
+
types or defaults).
|
| 264 |
+
|
| 265 |
+
:param ctx: optionally the :class:`~click.Context` where this parser
|
| 266 |
+
should go with.
|
| 267 |
+
"""
|
| 268 |
+
|
| 269 |
+
def __init__(self, ctx: t.Optional["Context"] = None) -> None:
|
| 270 |
+
#: The :class:`~click.Context` for this parser. This might be
|
| 271 |
+
#: `None` for some advanced use cases.
|
| 272 |
+
self.ctx = ctx
|
| 273 |
+
#: This controls how the parser deals with interspersed arguments.
|
| 274 |
+
#: If this is set to `False`, the parser will stop on the first
|
| 275 |
+
#: non-option. Click uses this to implement nested subcommands
|
| 276 |
+
#: safely.
|
| 277 |
+
self.allow_interspersed_args: bool = True
|
| 278 |
+
#: This tells the parser how to deal with unknown options. By
|
| 279 |
+
#: default it will error out (which is sensible), but there is a
|
| 280 |
+
#: second mode where it will ignore it and continue processing
|
| 281 |
+
#: after shifting all the unknown options into the resulting args.
|
| 282 |
+
self.ignore_unknown_options: bool = False
|
| 283 |
+
|
| 284 |
+
if ctx is not None:
|
| 285 |
+
self.allow_interspersed_args = ctx.allow_interspersed_args
|
| 286 |
+
self.ignore_unknown_options = ctx.ignore_unknown_options
|
| 287 |
+
|
| 288 |
+
self._short_opt: t.Dict[str, Option] = {}
|
| 289 |
+
self._long_opt: t.Dict[str, Option] = {}
|
| 290 |
+
self._opt_prefixes = {"-", "--"}
|
| 291 |
+
self._args: t.List[Argument] = []
|
| 292 |
+
|
| 293 |
+
def add_option(
|
| 294 |
+
self,
|
| 295 |
+
obj: "CoreOption",
|
| 296 |
+
opts: t.Sequence[str],
|
| 297 |
+
dest: t.Optional[str],
|
| 298 |
+
action: t.Optional[str] = None,
|
| 299 |
+
nargs: int = 1,
|
| 300 |
+
const: t.Optional[t.Any] = None,
|
| 301 |
+
) -> None:
|
| 302 |
+
"""Adds a new option named `dest` to the parser. The destination
|
| 303 |
+
is not inferred (unlike with optparse) and needs to be explicitly
|
| 304 |
+
provided. Action can be any of ``store``, ``store_const``,
|
| 305 |
+
``append``, ``append_const`` or ``count``.
|
| 306 |
+
|
| 307 |
+
The `obj` can be used to identify the option in the order list
|
| 308 |
+
that is returned from the parser.
|
| 309 |
+
"""
|
| 310 |
+
opts = [normalize_opt(opt, self.ctx) for opt in opts]
|
| 311 |
+
option = Option(obj, opts, dest, action=action, nargs=nargs, const=const)
|
| 312 |
+
self._opt_prefixes.update(option.prefixes)
|
| 313 |
+
for opt in option._short_opts:
|
| 314 |
+
self._short_opt[opt] = option
|
| 315 |
+
for opt in option._long_opts:
|
| 316 |
+
self._long_opt[opt] = option
|
| 317 |
+
|
| 318 |
+
def add_argument(
|
| 319 |
+
self, obj: "CoreArgument", dest: t.Optional[str], nargs: int = 1
|
| 320 |
+
) -> None:
|
| 321 |
+
"""Adds a positional argument named `dest` to the parser.
|
| 322 |
+
|
| 323 |
+
The `obj` can be used to identify the option in the order list
|
| 324 |
+
that is returned from the parser.
|
| 325 |
+
"""
|
| 326 |
+
self._args.append(Argument(obj, dest=dest, nargs=nargs))
|
| 327 |
+
|
| 328 |
+
def parse_args(
|
| 329 |
+
self, args: t.List[str]
|
| 330 |
+
) -> t.Tuple[t.Dict[str, t.Any], t.List[str], t.List["CoreParameter"]]:
|
| 331 |
+
"""Parses positional arguments and returns ``(values, args, order)``
|
| 332 |
+
for the parsed options and arguments as well as the leftover
|
| 333 |
+
arguments if there are any. The order is a list of objects as they
|
| 334 |
+
appear on the command line. If arguments appear multiple times they
|
| 335 |
+
will be memorized multiple times as well.
|
| 336 |
+
"""
|
| 337 |
+
state = ParsingState(args)
|
| 338 |
+
try:
|
| 339 |
+
self._process_args_for_options(state)
|
| 340 |
+
self._process_args_for_args(state)
|
| 341 |
+
except UsageError:
|
| 342 |
+
if self.ctx is None or not self.ctx.resilient_parsing:
|
| 343 |
+
raise
|
| 344 |
+
return state.opts, state.largs, state.order
|
| 345 |
+
|
| 346 |
+
def _process_args_for_args(self, state: ParsingState) -> None:
|
| 347 |
+
pargs, args = _unpack_args(
|
| 348 |
+
state.largs + state.rargs, [x.nargs for x in self._args]
|
| 349 |
+
)
|
| 350 |
+
|
| 351 |
+
for idx, arg in enumerate(self._args):
|
| 352 |
+
arg.process(pargs[idx], state)
|
| 353 |
+
|
| 354 |
+
state.largs = args
|
| 355 |
+
state.rargs = []
|
| 356 |
+
|
| 357 |
+
def _process_args_for_options(self, state: ParsingState) -> None:
|
| 358 |
+
while state.rargs:
|
| 359 |
+
arg = state.rargs.pop(0)
|
| 360 |
+
arglen = len(arg)
|
| 361 |
+
# Double dashes always handled explicitly regardless of what
|
| 362 |
+
# prefixes are valid.
|
| 363 |
+
if arg == "--":
|
| 364 |
+
return
|
| 365 |
+
elif arg[:1] in self._opt_prefixes and arglen > 1:
|
| 366 |
+
self._process_opts(arg, state)
|
| 367 |
+
elif self.allow_interspersed_args:
|
| 368 |
+
state.largs.append(arg)
|
| 369 |
+
else:
|
| 370 |
+
state.rargs.insert(0, arg)
|
| 371 |
+
return
|
| 372 |
+
|
| 373 |
+
# Say this is the original argument list:
|
| 374 |
+
# [arg0, arg1, ..., arg(i-1), arg(i), arg(i+1), ..., arg(N-1)]
|
| 375 |
+
# ^
|
| 376 |
+
# (we are about to process arg(i)).
|
| 377 |
+
#
|
| 378 |
+
# Then rargs is [arg(i), ..., arg(N-1)] and largs is a *subset* of
|
| 379 |
+
# [arg0, ..., arg(i-1)] (any options and their arguments will have
|
| 380 |
+
# been removed from largs).
|
| 381 |
+
#
|
| 382 |
+
# The while loop will usually consume 1 or more arguments per pass.
|
| 383 |
+
# If it consumes 1 (eg. arg is an option that takes no arguments),
|
| 384 |
+
# then after _process_arg() is done the situation is:
|
| 385 |
+
#
|
| 386 |
+
# largs = subset of [arg0, ..., arg(i)]
|
| 387 |
+
# rargs = [arg(i+1), ..., arg(N-1)]
|
| 388 |
+
#
|
| 389 |
+
# If allow_interspersed_args is false, largs will always be
|
| 390 |
+
# *empty* -- still a subset of [arg0, ..., arg(i-1)], but
|
| 391 |
+
# not a very interesting subset!
|
| 392 |
+
|
| 393 |
+
def _match_long_opt(
|
| 394 |
+
self, opt: str, explicit_value: t.Optional[str], state: ParsingState
|
| 395 |
+
) -> None:
|
| 396 |
+
if opt not in self._long_opt:
|
| 397 |
+
from difflib import get_close_matches
|
| 398 |
+
|
| 399 |
+
possibilities = get_close_matches(opt, self._long_opt)
|
| 400 |
+
raise NoSuchOption(opt, possibilities=possibilities, ctx=self.ctx)
|
| 401 |
+
|
| 402 |
+
option = self._long_opt[opt]
|
| 403 |
+
if option.takes_value:
|
| 404 |
+
# At this point it's safe to modify rargs by injecting the
|
| 405 |
+
# explicit value, because no exception is raised in this
|
| 406 |
+
# branch. This means that the inserted value will be fully
|
| 407 |
+
# consumed.
|
| 408 |
+
if explicit_value is not None:
|
| 409 |
+
state.rargs.insert(0, explicit_value)
|
| 410 |
+
|
| 411 |
+
value = self._get_value_from_state(opt, option, state)
|
| 412 |
+
|
| 413 |
+
elif explicit_value is not None:
|
| 414 |
+
raise BadOptionUsage(
|
| 415 |
+
opt, _("Option {name!r} does not take a value.").format(name=opt)
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
else:
|
| 419 |
+
value = None
|
| 420 |
+
|
| 421 |
+
option.process(value, state)
|
| 422 |
+
|
| 423 |
+
def _match_short_opt(self, arg: str, state: ParsingState) -> None:
|
| 424 |
+
stop = False
|
| 425 |
+
i = 1
|
| 426 |
+
prefix = arg[0]
|
| 427 |
+
unknown_options = []
|
| 428 |
+
|
| 429 |
+
for ch in arg[1:]:
|
| 430 |
+
opt = normalize_opt(f"{prefix}{ch}", self.ctx)
|
| 431 |
+
option = self._short_opt.get(opt)
|
| 432 |
+
i += 1
|
| 433 |
+
|
| 434 |
+
if not option:
|
| 435 |
+
if self.ignore_unknown_options:
|
| 436 |
+
unknown_options.append(ch)
|
| 437 |
+
continue
|
| 438 |
+
raise NoSuchOption(opt, ctx=self.ctx)
|
| 439 |
+
if option.takes_value:
|
| 440 |
+
# Any characters left in arg? Pretend they're the
|
| 441 |
+
# next arg, and stop consuming characters of arg.
|
| 442 |
+
if i < len(arg):
|
| 443 |
+
state.rargs.insert(0, arg[i:])
|
| 444 |
+
stop = True
|
| 445 |
+
|
| 446 |
+
value = self._get_value_from_state(opt, option, state)
|
| 447 |
+
|
| 448 |
+
else:
|
| 449 |
+
value = None
|
| 450 |
+
|
| 451 |
+
option.process(value, state)
|
| 452 |
+
|
| 453 |
+
if stop:
|
| 454 |
+
break
|
| 455 |
+
|
| 456 |
+
# If we got any unknown options we recombine the string of the
|
| 457 |
+
# remaining options and re-attach the prefix, then report that
|
| 458 |
+
# to the state as new larg. This way there is basic combinatorics
|
| 459 |
+
# that can be achieved while still ignoring unknown arguments.
|
| 460 |
+
if self.ignore_unknown_options and unknown_options:
|
| 461 |
+
state.largs.append(f"{prefix}{''.join(unknown_options)}")
|
| 462 |
+
|
| 463 |
+
def _get_value_from_state(
|
| 464 |
+
self, option_name: str, option: Option, state: ParsingState
|
| 465 |
+
) -> t.Any:
|
| 466 |
+
nargs = option.nargs
|
| 467 |
+
|
| 468 |
+
if len(state.rargs) < nargs:
|
| 469 |
+
if option.obj._flag_needs_value:
|
| 470 |
+
# Option allows omitting the value.
|
| 471 |
+
value = _flag_needs_value
|
| 472 |
+
else:
|
| 473 |
+
raise BadOptionUsage(
|
| 474 |
+
option_name,
|
| 475 |
+
ngettext(
|
| 476 |
+
"Option {name!r} requires an argument.",
|
| 477 |
+
"Option {name!r} requires {nargs} arguments.",
|
| 478 |
+
nargs,
|
| 479 |
+
).format(name=option_name, nargs=nargs),
|
| 480 |
+
)
|
| 481 |
+
elif nargs == 1:
|
| 482 |
+
next_rarg = state.rargs[0]
|
| 483 |
+
|
| 484 |
+
if (
|
| 485 |
+
option.obj._flag_needs_value
|
| 486 |
+
and isinstance(next_rarg, str)
|
| 487 |
+
and next_rarg[:1] in self._opt_prefixes
|
| 488 |
+
and len(next_rarg) > 1
|
| 489 |
+
):
|
| 490 |
+
# The next arg looks like the start of an option, don't
|
| 491 |
+
# use it as the value if omitting the value is allowed.
|
| 492 |
+
value = _flag_needs_value
|
| 493 |
+
else:
|
| 494 |
+
value = state.rargs.pop(0)
|
| 495 |
+
else:
|
| 496 |
+
value = tuple(state.rargs[:nargs])
|
| 497 |
+
del state.rargs[:nargs]
|
| 498 |
+
|
| 499 |
+
return value
|
| 500 |
+
|
| 501 |
+
def _process_opts(self, arg: str, state: ParsingState) -> None:
|
| 502 |
+
explicit_value = None
|
| 503 |
+
# Long option handling happens in two parts. The first part is
|
| 504 |
+
# supporting explicitly attached values. In any case, we will try
|
| 505 |
+
# to long match the option first.
|
| 506 |
+
if "=" in arg:
|
| 507 |
+
long_opt, explicit_value = arg.split("=", 1)
|
| 508 |
+
else:
|
| 509 |
+
long_opt = arg
|
| 510 |
+
norm_long_opt = normalize_opt(long_opt, self.ctx)
|
| 511 |
+
|
| 512 |
+
# At this point we will match the (assumed) long option through
|
| 513 |
+
# the long option matching code. Note that this allows options
|
| 514 |
+
# like "-foo" to be matched as long options.
|
| 515 |
+
try:
|
| 516 |
+
self._match_long_opt(norm_long_opt, explicit_value, state)
|
| 517 |
+
except NoSuchOption:
|
| 518 |
+
# At this point the long option matching failed, and we need
|
| 519 |
+
# to try with short options. However there is a special rule
|
| 520 |
+
# which says, that if we have a two character options prefix
|
| 521 |
+
# (applies to "--foo" for instance), we do not dispatch to the
|
| 522 |
+
# short option code and will instead raise the no option
|
| 523 |
+
# error.
|
| 524 |
+
if arg[:2] not in self._opt_prefixes:
|
| 525 |
+
self._match_short_opt(arg, state)
|
| 526 |
+
return
|
| 527 |
+
|
| 528 |
+
if not self.ignore_unknown_options:
|
| 529 |
+
raise
|
| 530 |
+
|
| 531 |
+
state.largs.append(arg)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/py.typed
ADDED
|
File without changes
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/shell_completion.py
ADDED
|
@@ -0,0 +1,603 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import typing as t
|
| 4 |
+
from gettext import gettext as _
|
| 5 |
+
|
| 6 |
+
from .core import Argument
|
| 7 |
+
from .core import BaseCommand
|
| 8 |
+
from .core import Context
|
| 9 |
+
from .core import MultiCommand
|
| 10 |
+
from .core import Option
|
| 11 |
+
from .core import Parameter
|
| 12 |
+
from .core import ParameterSource
|
| 13 |
+
from .parser import split_arg_string
|
| 14 |
+
from .utils import echo
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def shell_complete(
|
| 18 |
+
cli: BaseCommand,
|
| 19 |
+
ctx_args: t.MutableMapping[str, t.Any],
|
| 20 |
+
prog_name: str,
|
| 21 |
+
complete_var: str,
|
| 22 |
+
instruction: str,
|
| 23 |
+
) -> int:
|
| 24 |
+
"""Perform shell completion for the given CLI program.
|
| 25 |
+
|
| 26 |
+
:param cli: Command being called.
|
| 27 |
+
:param ctx_args: Extra arguments to pass to
|
| 28 |
+
``cli.make_context``.
|
| 29 |
+
:param prog_name: Name of the executable in the shell.
|
| 30 |
+
:param complete_var: Name of the environment variable that holds
|
| 31 |
+
the completion instruction.
|
| 32 |
+
:param instruction: Value of ``complete_var`` with the completion
|
| 33 |
+
instruction and shell, in the form ``instruction_shell``.
|
| 34 |
+
:return: Status code to exit with.
|
| 35 |
+
"""
|
| 36 |
+
shell, _, instruction = instruction.partition("_")
|
| 37 |
+
comp_cls = get_completion_class(shell)
|
| 38 |
+
|
| 39 |
+
if comp_cls is None:
|
| 40 |
+
return 1
|
| 41 |
+
|
| 42 |
+
comp = comp_cls(cli, ctx_args, prog_name, complete_var)
|
| 43 |
+
|
| 44 |
+
if instruction == "source":
|
| 45 |
+
echo(comp.source())
|
| 46 |
+
return 0
|
| 47 |
+
|
| 48 |
+
if instruction == "complete":
|
| 49 |
+
echo(comp.complete())
|
| 50 |
+
return 0
|
| 51 |
+
|
| 52 |
+
return 1
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class CompletionItem:
|
| 56 |
+
"""Represents a completion value and metadata about the value. The
|
| 57 |
+
default metadata is ``type`` to indicate special shell handling,
|
| 58 |
+
and ``help`` if a shell supports showing a help string next to the
|
| 59 |
+
value.
|
| 60 |
+
|
| 61 |
+
Arbitrary parameters can be passed when creating the object, and
|
| 62 |
+
accessed using ``item.attr``. If an attribute wasn't passed,
|
| 63 |
+
accessing it returns ``None``.
|
| 64 |
+
|
| 65 |
+
:param value: The completion suggestion.
|
| 66 |
+
:param type: Tells the shell script to provide special completion
|
| 67 |
+
support for the type. Click uses ``"dir"`` and ``"file"``.
|
| 68 |
+
:param help: String shown next to the value if supported.
|
| 69 |
+
:param kwargs: Arbitrary metadata. The built-in implementations
|
| 70 |
+
don't use this, but custom type completions paired with custom
|
| 71 |
+
shell support could use it.
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
__slots__ = ("value", "type", "help", "_info")
|
| 75 |
+
|
| 76 |
+
def __init__(
|
| 77 |
+
self,
|
| 78 |
+
value: t.Any,
|
| 79 |
+
type: str = "plain",
|
| 80 |
+
help: t.Optional[str] = None,
|
| 81 |
+
**kwargs: t.Any,
|
| 82 |
+
) -> None:
|
| 83 |
+
self.value: t.Any = value
|
| 84 |
+
self.type: str = type
|
| 85 |
+
self.help: t.Optional[str] = help
|
| 86 |
+
self._info = kwargs
|
| 87 |
+
|
| 88 |
+
def __getattr__(self, name: str) -> t.Any:
|
| 89 |
+
return self._info.get(name)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# Only Bash >= 4.4 has the nosort option.
|
| 93 |
+
_SOURCE_BASH = """\
|
| 94 |
+
%(complete_func)s() {
|
| 95 |
+
local IFS=$'\\n'
|
| 96 |
+
local response
|
| 97 |
+
|
| 98 |
+
response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD \
|
| 99 |
+
%(complete_var)s=bash_complete $1)
|
| 100 |
+
|
| 101 |
+
for completion in $response; do
|
| 102 |
+
IFS=',' read type value <<< "$completion"
|
| 103 |
+
|
| 104 |
+
if [[ $type == 'dir' ]]; then
|
| 105 |
+
COMPREPLY=()
|
| 106 |
+
compopt -o dirnames
|
| 107 |
+
elif [[ $type == 'file' ]]; then
|
| 108 |
+
COMPREPLY=()
|
| 109 |
+
compopt -o default
|
| 110 |
+
elif [[ $type == 'plain' ]]; then
|
| 111 |
+
COMPREPLY+=($value)
|
| 112 |
+
fi
|
| 113 |
+
done
|
| 114 |
+
|
| 115 |
+
return 0
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
%(complete_func)s_setup() {
|
| 119 |
+
complete -o nosort -F %(complete_func)s %(prog_name)s
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
%(complete_func)s_setup;
|
| 123 |
+
"""
|
| 124 |
+
|
| 125 |
+
_SOURCE_ZSH = """\
|
| 126 |
+
#compdef %(prog_name)s
|
| 127 |
+
|
| 128 |
+
%(complete_func)s() {
|
| 129 |
+
local -a completions
|
| 130 |
+
local -a completions_with_descriptions
|
| 131 |
+
local -a response
|
| 132 |
+
(( ! $+commands[%(prog_name)s] )) && return 1
|
| 133 |
+
|
| 134 |
+
response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) \
|
| 135 |
+
%(complete_var)s=zsh_complete %(prog_name)s)}")
|
| 136 |
+
|
| 137 |
+
for type key descr in ${response}; do
|
| 138 |
+
if [[ "$type" == "plain" ]]; then
|
| 139 |
+
if [[ "$descr" == "_" ]]; then
|
| 140 |
+
completions+=("$key")
|
| 141 |
+
else
|
| 142 |
+
completions_with_descriptions+=("$key":"$descr")
|
| 143 |
+
fi
|
| 144 |
+
elif [[ "$type" == "dir" ]]; then
|
| 145 |
+
_path_files -/
|
| 146 |
+
elif [[ "$type" == "file" ]]; then
|
| 147 |
+
_path_files -f
|
| 148 |
+
fi
|
| 149 |
+
done
|
| 150 |
+
|
| 151 |
+
if [ -n "$completions_with_descriptions" ]; then
|
| 152 |
+
_describe -V unsorted completions_with_descriptions -U
|
| 153 |
+
fi
|
| 154 |
+
|
| 155 |
+
if [ -n "$completions" ]; then
|
| 156 |
+
compadd -U -V unsorted -a completions
|
| 157 |
+
fi
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
|
| 161 |
+
# autoload from fpath, call function directly
|
| 162 |
+
%(complete_func)s "$@"
|
| 163 |
+
else
|
| 164 |
+
# eval/source/. command, register function for later
|
| 165 |
+
compdef %(complete_func)s %(prog_name)s
|
| 166 |
+
fi
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
_SOURCE_FISH = """\
|
| 170 |
+
function %(complete_func)s;
|
| 171 |
+
set -l response (env %(complete_var)s=fish_complete COMP_WORDS=(commandline -cp) \
|
| 172 |
+
COMP_CWORD=(commandline -t) %(prog_name)s);
|
| 173 |
+
|
| 174 |
+
for completion in $response;
|
| 175 |
+
set -l metadata (string split "," $completion);
|
| 176 |
+
|
| 177 |
+
if test $metadata[1] = "dir";
|
| 178 |
+
__fish_complete_directories $metadata[2];
|
| 179 |
+
else if test $metadata[1] = "file";
|
| 180 |
+
__fish_complete_path $metadata[2];
|
| 181 |
+
else if test $metadata[1] = "plain";
|
| 182 |
+
echo $metadata[2];
|
| 183 |
+
end;
|
| 184 |
+
end;
|
| 185 |
+
end;
|
| 186 |
+
|
| 187 |
+
complete --no-files --command %(prog_name)s --arguments \
|
| 188 |
+
"(%(complete_func)s)";
|
| 189 |
+
"""
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
class ShellComplete:
|
| 193 |
+
"""Base class for providing shell completion support. A subclass for
|
| 194 |
+
a given shell will override attributes and methods to implement the
|
| 195 |
+
completion instructions (``source`` and ``complete``).
|
| 196 |
+
|
| 197 |
+
:param cli: Command being called.
|
| 198 |
+
:param prog_name: Name of the executable in the shell.
|
| 199 |
+
:param complete_var: Name of the environment variable that holds
|
| 200 |
+
the completion instruction.
|
| 201 |
+
|
| 202 |
+
.. versionadded:: 8.0
|
| 203 |
+
"""
|
| 204 |
+
|
| 205 |
+
name: t.ClassVar[str]
|
| 206 |
+
"""Name to register the shell as with :func:`add_completion_class`.
|
| 207 |
+
This is used in completion instructions (``{name}_source`` and
|
| 208 |
+
``{name}_complete``).
|
| 209 |
+
"""
|
| 210 |
+
|
| 211 |
+
source_template: t.ClassVar[str]
|
| 212 |
+
"""Completion script template formatted by :meth:`source`. This must
|
| 213 |
+
be provided by subclasses.
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
def __init__(
|
| 217 |
+
self,
|
| 218 |
+
cli: BaseCommand,
|
| 219 |
+
ctx_args: t.MutableMapping[str, t.Any],
|
| 220 |
+
prog_name: str,
|
| 221 |
+
complete_var: str,
|
| 222 |
+
) -> None:
|
| 223 |
+
self.cli = cli
|
| 224 |
+
self.ctx_args = ctx_args
|
| 225 |
+
self.prog_name = prog_name
|
| 226 |
+
self.complete_var = complete_var
|
| 227 |
+
|
| 228 |
+
@property
|
| 229 |
+
def func_name(self) -> str:
|
| 230 |
+
"""The name of the shell function defined by the completion
|
| 231 |
+
script.
|
| 232 |
+
"""
|
| 233 |
+
safe_name = re.sub(r"\W*", "", self.prog_name.replace("-", "_"), flags=re.ASCII)
|
| 234 |
+
return f"_{safe_name}_completion"
|
| 235 |
+
|
| 236 |
+
def source_vars(self) -> t.Dict[str, t.Any]:
|
| 237 |
+
"""Vars for formatting :attr:`source_template`.
|
| 238 |
+
|
| 239 |
+
By default this provides ``complete_func``, ``complete_var``,
|
| 240 |
+
and ``prog_name``.
|
| 241 |
+
"""
|
| 242 |
+
return {
|
| 243 |
+
"complete_func": self.func_name,
|
| 244 |
+
"complete_var": self.complete_var,
|
| 245 |
+
"prog_name": self.prog_name,
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
def source(self) -> str:
|
| 249 |
+
"""Produce the shell script that defines the completion
|
| 250 |
+
function. By default this ``%``-style formats
|
| 251 |
+
:attr:`source_template` with the dict returned by
|
| 252 |
+
:meth:`source_vars`.
|
| 253 |
+
"""
|
| 254 |
+
return self.source_template % self.source_vars()
|
| 255 |
+
|
| 256 |
+
def get_completion_args(self) -> t.Tuple[t.List[str], str]:
|
| 257 |
+
"""Use the env vars defined by the shell script to return a
|
| 258 |
+
tuple of ``args, incomplete``. This must be implemented by
|
| 259 |
+
subclasses.
|
| 260 |
+
"""
|
| 261 |
+
raise NotImplementedError
|
| 262 |
+
|
| 263 |
+
def get_completions(
|
| 264 |
+
self, args: t.List[str], incomplete: str
|
| 265 |
+
) -> t.List[CompletionItem]:
|
| 266 |
+
"""Determine the context and last complete command or parameter
|
| 267 |
+
from the complete args. Call that object's ``shell_complete``
|
| 268 |
+
method to get the completions for the incomplete value.
|
| 269 |
+
|
| 270 |
+
:param args: List of complete args before the incomplete value.
|
| 271 |
+
:param incomplete: Value being completed. May be empty.
|
| 272 |
+
"""
|
| 273 |
+
ctx = _resolve_context(self.cli, self.ctx_args, self.prog_name, args)
|
| 274 |
+
obj, incomplete = _resolve_incomplete(ctx, args, incomplete)
|
| 275 |
+
return obj.shell_complete(ctx, incomplete)
|
| 276 |
+
|
| 277 |
+
def format_completion(self, item: CompletionItem) -> str:
|
| 278 |
+
"""Format a completion item into the form recognized by the
|
| 279 |
+
shell script. This must be implemented by subclasses.
|
| 280 |
+
|
| 281 |
+
:param item: Completion item to format.
|
| 282 |
+
"""
|
| 283 |
+
raise NotImplementedError
|
| 284 |
+
|
| 285 |
+
def complete(self) -> str:
|
| 286 |
+
"""Produce the completion data to send back to the shell.
|
| 287 |
+
|
| 288 |
+
By default this calls :meth:`get_completion_args`, gets the
|
| 289 |
+
completions, then calls :meth:`format_completion` for each
|
| 290 |
+
completion.
|
| 291 |
+
"""
|
| 292 |
+
args, incomplete = self.get_completion_args()
|
| 293 |
+
completions = self.get_completions(args, incomplete)
|
| 294 |
+
out = [self.format_completion(item) for item in completions]
|
| 295 |
+
return "\n".join(out)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
class BashComplete(ShellComplete):
|
| 299 |
+
"""Shell completion for Bash."""
|
| 300 |
+
|
| 301 |
+
name = "bash"
|
| 302 |
+
source_template = _SOURCE_BASH
|
| 303 |
+
|
| 304 |
+
@staticmethod
|
| 305 |
+
def _check_version() -> None:
|
| 306 |
+
import shutil
|
| 307 |
+
import subprocess
|
| 308 |
+
|
| 309 |
+
bash_exe = shutil.which("bash")
|
| 310 |
+
|
| 311 |
+
if bash_exe is None:
|
| 312 |
+
match = None
|
| 313 |
+
else:
|
| 314 |
+
output = subprocess.run(
|
| 315 |
+
[bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'],
|
| 316 |
+
stdout=subprocess.PIPE,
|
| 317 |
+
)
|
| 318 |
+
match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode())
|
| 319 |
+
|
| 320 |
+
if match is not None:
|
| 321 |
+
major, minor = match.groups()
|
| 322 |
+
|
| 323 |
+
if major < "4" or major == "4" and minor < "4":
|
| 324 |
+
echo(
|
| 325 |
+
_(
|
| 326 |
+
"Shell completion is not supported for Bash"
|
| 327 |
+
" versions older than 4.4."
|
| 328 |
+
),
|
| 329 |
+
err=True,
|
| 330 |
+
)
|
| 331 |
+
else:
|
| 332 |
+
echo(
|
| 333 |
+
_("Couldn't detect Bash version, shell completion is not supported."),
|
| 334 |
+
err=True,
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
def source(self) -> str:
|
| 338 |
+
self._check_version()
|
| 339 |
+
return super().source()
|
| 340 |
+
|
| 341 |
+
def get_completion_args(self) -> t.Tuple[t.List[str], str]:
|
| 342 |
+
cwords = split_arg_string(os.environ["COMP_WORDS"])
|
| 343 |
+
cword = int(os.environ["COMP_CWORD"])
|
| 344 |
+
args = cwords[1:cword]
|
| 345 |
+
|
| 346 |
+
try:
|
| 347 |
+
incomplete = cwords[cword]
|
| 348 |
+
except IndexError:
|
| 349 |
+
incomplete = ""
|
| 350 |
+
|
| 351 |
+
return args, incomplete
|
| 352 |
+
|
| 353 |
+
def format_completion(self, item: CompletionItem) -> str:
|
| 354 |
+
return f"{item.type},{item.value}"
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
class ZshComplete(ShellComplete):
|
| 358 |
+
"""Shell completion for Zsh."""
|
| 359 |
+
|
| 360 |
+
name = "zsh"
|
| 361 |
+
source_template = _SOURCE_ZSH
|
| 362 |
+
|
| 363 |
+
def get_completion_args(self) -> t.Tuple[t.List[str], str]:
|
| 364 |
+
cwords = split_arg_string(os.environ["COMP_WORDS"])
|
| 365 |
+
cword = int(os.environ["COMP_CWORD"])
|
| 366 |
+
args = cwords[1:cword]
|
| 367 |
+
|
| 368 |
+
try:
|
| 369 |
+
incomplete = cwords[cword]
|
| 370 |
+
except IndexError:
|
| 371 |
+
incomplete = ""
|
| 372 |
+
|
| 373 |
+
return args, incomplete
|
| 374 |
+
|
| 375 |
+
def format_completion(self, item: CompletionItem) -> str:
|
| 376 |
+
return f"{item.type}\n{item.value}\n{item.help if item.help else '_'}"
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
class FishComplete(ShellComplete):
|
| 380 |
+
"""Shell completion for Fish."""
|
| 381 |
+
|
| 382 |
+
name = "fish"
|
| 383 |
+
source_template = _SOURCE_FISH
|
| 384 |
+
|
| 385 |
+
def get_completion_args(self) -> t.Tuple[t.List[str], str]:
|
| 386 |
+
cwords = split_arg_string(os.environ["COMP_WORDS"])
|
| 387 |
+
incomplete = os.environ["COMP_CWORD"]
|
| 388 |
+
args = cwords[1:]
|
| 389 |
+
|
| 390 |
+
# Fish stores the partial word in both COMP_WORDS and
|
| 391 |
+
# COMP_CWORD, remove it from complete args.
|
| 392 |
+
if incomplete and args and args[-1] == incomplete:
|
| 393 |
+
args.pop()
|
| 394 |
+
|
| 395 |
+
return args, incomplete
|
| 396 |
+
|
| 397 |
+
def format_completion(self, item: CompletionItem) -> str:
|
| 398 |
+
if item.help:
|
| 399 |
+
return f"{item.type},{item.value}\t{item.help}"
|
| 400 |
+
|
| 401 |
+
return f"{item.type},{item.value}"
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
ShellCompleteType = t.TypeVar("ShellCompleteType", bound=t.Type[ShellComplete])
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
_available_shells: t.Dict[str, t.Type[ShellComplete]] = {
|
| 408 |
+
"bash": BashComplete,
|
| 409 |
+
"fish": FishComplete,
|
| 410 |
+
"zsh": ZshComplete,
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def add_completion_class(
|
| 415 |
+
cls: ShellCompleteType, name: t.Optional[str] = None
|
| 416 |
+
) -> ShellCompleteType:
|
| 417 |
+
"""Register a :class:`ShellComplete` subclass under the given name.
|
| 418 |
+
The name will be provided by the completion instruction environment
|
| 419 |
+
variable during completion.
|
| 420 |
+
|
| 421 |
+
:param cls: The completion class that will handle completion for the
|
| 422 |
+
shell.
|
| 423 |
+
:param name: Name to register the class under. Defaults to the
|
| 424 |
+
class's ``name`` attribute.
|
| 425 |
+
"""
|
| 426 |
+
if name is None:
|
| 427 |
+
name = cls.name
|
| 428 |
+
|
| 429 |
+
_available_shells[name] = cls
|
| 430 |
+
|
| 431 |
+
return cls
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
def get_completion_class(shell: str) -> t.Optional[t.Type[ShellComplete]]:
|
| 435 |
+
"""Look up a registered :class:`ShellComplete` subclass by the name
|
| 436 |
+
provided by the completion instruction environment variable. If the
|
| 437 |
+
name isn't registered, returns ``None``.
|
| 438 |
+
|
| 439 |
+
:param shell: Name the class is registered under.
|
| 440 |
+
"""
|
| 441 |
+
return _available_shells.get(shell)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
def _is_incomplete_argument(ctx: Context, param: Parameter) -> bool:
|
| 445 |
+
"""Determine if the given parameter is an argument that can still
|
| 446 |
+
accept values.
|
| 447 |
+
|
| 448 |
+
:param ctx: Invocation context for the command represented by the
|
| 449 |
+
parsed complete args.
|
| 450 |
+
:param param: Argument object being checked.
|
| 451 |
+
"""
|
| 452 |
+
if not isinstance(param, Argument):
|
| 453 |
+
return False
|
| 454 |
+
|
| 455 |
+
assert param.name is not None
|
| 456 |
+
# Will be None if expose_value is False.
|
| 457 |
+
value = ctx.params.get(param.name)
|
| 458 |
+
return (
|
| 459 |
+
param.nargs == -1
|
| 460 |
+
or ctx.get_parameter_source(param.name) is not ParameterSource.COMMANDLINE
|
| 461 |
+
or (
|
| 462 |
+
param.nargs > 1
|
| 463 |
+
and isinstance(value, (tuple, list))
|
| 464 |
+
and len(value) < param.nargs
|
| 465 |
+
)
|
| 466 |
+
)
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
def _start_of_option(ctx: Context, value: str) -> bool:
|
| 470 |
+
"""Check if the value looks like the start of an option."""
|
| 471 |
+
if not value:
|
| 472 |
+
return False
|
| 473 |
+
|
| 474 |
+
c = value[0]
|
| 475 |
+
return c in ctx._opt_prefixes
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def _is_incomplete_option(ctx: Context, args: t.List[str], param: Parameter) -> bool:
|
| 479 |
+
"""Determine if the given parameter is an option that needs a value.
|
| 480 |
+
|
| 481 |
+
:param args: List of complete args before the incomplete value.
|
| 482 |
+
:param param: Option object being checked.
|
| 483 |
+
"""
|
| 484 |
+
if not isinstance(param, Option):
|
| 485 |
+
return False
|
| 486 |
+
|
| 487 |
+
if param.is_flag or param.count:
|
| 488 |
+
return False
|
| 489 |
+
|
| 490 |
+
last_option = None
|
| 491 |
+
|
| 492 |
+
for index, arg in enumerate(reversed(args)):
|
| 493 |
+
if index + 1 > param.nargs:
|
| 494 |
+
break
|
| 495 |
+
|
| 496 |
+
if _start_of_option(ctx, arg):
|
| 497 |
+
last_option = arg
|
| 498 |
+
|
| 499 |
+
return last_option is not None and last_option in param.opts
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
def _resolve_context(
|
| 503 |
+
cli: BaseCommand,
|
| 504 |
+
ctx_args: t.MutableMapping[str, t.Any],
|
| 505 |
+
prog_name: str,
|
| 506 |
+
args: t.List[str],
|
| 507 |
+
) -> Context:
|
| 508 |
+
"""Produce the context hierarchy starting with the command and
|
| 509 |
+
traversing the complete arguments. This only follows the commands,
|
| 510 |
+
it doesn't trigger input prompts or callbacks.
|
| 511 |
+
|
| 512 |
+
:param cli: Command being called.
|
| 513 |
+
:param prog_name: Name of the executable in the shell.
|
| 514 |
+
:param args: List of complete args before the incomplete value.
|
| 515 |
+
"""
|
| 516 |
+
ctx_args["resilient_parsing"] = True
|
| 517 |
+
ctx = cli.make_context(prog_name, args.copy(), **ctx_args)
|
| 518 |
+
args = ctx.protected_args + ctx.args
|
| 519 |
+
|
| 520 |
+
while args:
|
| 521 |
+
command = ctx.command
|
| 522 |
+
|
| 523 |
+
if isinstance(command, MultiCommand):
|
| 524 |
+
if not command.chain:
|
| 525 |
+
name, cmd, args = command.resolve_command(ctx, args)
|
| 526 |
+
|
| 527 |
+
if cmd is None:
|
| 528 |
+
return ctx
|
| 529 |
+
|
| 530 |
+
ctx = cmd.make_context(name, args, parent=ctx, resilient_parsing=True)
|
| 531 |
+
args = ctx.protected_args + ctx.args
|
| 532 |
+
else:
|
| 533 |
+
sub_ctx = ctx
|
| 534 |
+
|
| 535 |
+
while args:
|
| 536 |
+
name, cmd, args = command.resolve_command(ctx, args)
|
| 537 |
+
|
| 538 |
+
if cmd is None:
|
| 539 |
+
return ctx
|
| 540 |
+
|
| 541 |
+
sub_ctx = cmd.make_context(
|
| 542 |
+
name,
|
| 543 |
+
args,
|
| 544 |
+
parent=ctx,
|
| 545 |
+
allow_extra_args=True,
|
| 546 |
+
allow_interspersed_args=False,
|
| 547 |
+
resilient_parsing=True,
|
| 548 |
+
)
|
| 549 |
+
args = sub_ctx.args
|
| 550 |
+
|
| 551 |
+
ctx = sub_ctx
|
| 552 |
+
args = [*sub_ctx.protected_args, *sub_ctx.args]
|
| 553 |
+
else:
|
| 554 |
+
break
|
| 555 |
+
|
| 556 |
+
return ctx
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def _resolve_incomplete(
|
| 560 |
+
ctx: Context, args: t.List[str], incomplete: str
|
| 561 |
+
) -> t.Tuple[t.Union[BaseCommand, Parameter], str]:
|
| 562 |
+
"""Find the Click object that will handle the completion of the
|
| 563 |
+
incomplete value. Return the object and the incomplete value.
|
| 564 |
+
|
| 565 |
+
:param ctx: Invocation context for the command represented by
|
| 566 |
+
the parsed complete args.
|
| 567 |
+
:param args: List of complete args before the incomplete value.
|
| 568 |
+
:param incomplete: Value being completed. May be empty.
|
| 569 |
+
"""
|
| 570 |
+
# Different shells treat an "=" between a long option name and
|
| 571 |
+
# value differently. Might keep the value joined, return the "="
|
| 572 |
+
# as a separate item, or return the split name and value. Always
|
| 573 |
+
# split and discard the "=" to make completion easier.
|
| 574 |
+
if incomplete == "=":
|
| 575 |
+
incomplete = ""
|
| 576 |
+
elif "=" in incomplete and _start_of_option(ctx, incomplete):
|
| 577 |
+
name, _, incomplete = incomplete.partition("=")
|
| 578 |
+
args.append(name)
|
| 579 |
+
|
| 580 |
+
# The "--" marker tells Click to stop treating values as options
|
| 581 |
+
# even if they start with the option character. If it hasn't been
|
| 582 |
+
# given and the incomplete arg looks like an option, the current
|
| 583 |
+
# command will provide option name completions.
|
| 584 |
+
if "--" not in args and _start_of_option(ctx, incomplete):
|
| 585 |
+
return ctx.command, incomplete
|
| 586 |
+
|
| 587 |
+
params = ctx.command.get_params(ctx)
|
| 588 |
+
|
| 589 |
+
# If the last complete arg is an option name with an incomplete
|
| 590 |
+
# value, the option will provide value completions.
|
| 591 |
+
for param in params:
|
| 592 |
+
if _is_incomplete_option(ctx, args, param):
|
| 593 |
+
return param, incomplete
|
| 594 |
+
|
| 595 |
+
# It's not an option name or value. The first argument without a
|
| 596 |
+
# parsed value will provide value completions.
|
| 597 |
+
for param in params:
|
| 598 |
+
if _is_incomplete_argument(ctx, param):
|
| 599 |
+
return param, incomplete
|
| 600 |
+
|
| 601 |
+
# There were no unparsed arguments, the command may be a group that
|
| 602 |
+
# will provide command name completions.
|
| 603 |
+
return ctx.command, incomplete
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/termui.py
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
import io
|
| 3 |
+
import itertools
|
| 4 |
+
import sys
|
| 5 |
+
import typing as t
|
| 6 |
+
from gettext import gettext as _
|
| 7 |
+
|
| 8 |
+
from ._compat import isatty
|
| 9 |
+
from ._compat import strip_ansi
|
| 10 |
+
from .exceptions import Abort
|
| 11 |
+
from .exceptions import UsageError
|
| 12 |
+
from .globals import resolve_color_default
|
| 13 |
+
from .types import Choice
|
| 14 |
+
from .types import convert_type
|
| 15 |
+
from .types import ParamType
|
| 16 |
+
from .utils import echo
|
| 17 |
+
from .utils import LazyFile
|
| 18 |
+
|
| 19 |
+
if t.TYPE_CHECKING:
|
| 20 |
+
from ._termui_impl import ProgressBar
|
| 21 |
+
|
| 22 |
+
V = t.TypeVar("V")
|
| 23 |
+
|
| 24 |
+
# The prompt functions to use. The doc tools currently override these
|
| 25 |
+
# functions to customize how they work.
|
| 26 |
+
visible_prompt_func: t.Callable[[str], str] = input
|
| 27 |
+
|
| 28 |
+
_ansi_colors = {
|
| 29 |
+
"black": 30,
|
| 30 |
+
"red": 31,
|
| 31 |
+
"green": 32,
|
| 32 |
+
"yellow": 33,
|
| 33 |
+
"blue": 34,
|
| 34 |
+
"magenta": 35,
|
| 35 |
+
"cyan": 36,
|
| 36 |
+
"white": 37,
|
| 37 |
+
"reset": 39,
|
| 38 |
+
"bright_black": 90,
|
| 39 |
+
"bright_red": 91,
|
| 40 |
+
"bright_green": 92,
|
| 41 |
+
"bright_yellow": 93,
|
| 42 |
+
"bright_blue": 94,
|
| 43 |
+
"bright_magenta": 95,
|
| 44 |
+
"bright_cyan": 96,
|
| 45 |
+
"bright_white": 97,
|
| 46 |
+
}
|
| 47 |
+
_ansi_reset_all = "\033[0m"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def hidden_prompt_func(prompt: str) -> str:
|
| 51 |
+
import getpass
|
| 52 |
+
|
| 53 |
+
return getpass.getpass(prompt)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _build_prompt(
|
| 57 |
+
text: str,
|
| 58 |
+
suffix: str,
|
| 59 |
+
show_default: bool = False,
|
| 60 |
+
default: t.Optional[t.Any] = None,
|
| 61 |
+
show_choices: bool = True,
|
| 62 |
+
type: t.Optional[ParamType] = None,
|
| 63 |
+
) -> str:
|
| 64 |
+
prompt = text
|
| 65 |
+
if type is not None and show_choices and isinstance(type, Choice):
|
| 66 |
+
prompt += f" ({', '.join(map(str, type.choices))})"
|
| 67 |
+
if default is not None and show_default:
|
| 68 |
+
prompt = f"{prompt} [{_format_default(default)}]"
|
| 69 |
+
return f"{prompt}{suffix}"
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _format_default(default: t.Any) -> t.Any:
|
| 73 |
+
if isinstance(default, (io.IOBase, LazyFile)) and hasattr(default, "name"):
|
| 74 |
+
return default.name
|
| 75 |
+
|
| 76 |
+
return default
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def prompt(
|
| 80 |
+
text: str,
|
| 81 |
+
default: t.Optional[t.Any] = None,
|
| 82 |
+
hide_input: bool = False,
|
| 83 |
+
confirmation_prompt: t.Union[bool, str] = False,
|
| 84 |
+
type: t.Optional[t.Union[ParamType, t.Any]] = None,
|
| 85 |
+
value_proc: t.Optional[t.Callable[[str], t.Any]] = None,
|
| 86 |
+
prompt_suffix: str = ": ",
|
| 87 |
+
show_default: bool = True,
|
| 88 |
+
err: bool = False,
|
| 89 |
+
show_choices: bool = True,
|
| 90 |
+
) -> t.Any:
|
| 91 |
+
"""Prompts a user for input. This is a convenience function that can
|
| 92 |
+
be used to prompt a user for input later.
|
| 93 |
+
|
| 94 |
+
If the user aborts the input by sending an interrupt signal, this
|
| 95 |
+
function will catch it and raise a :exc:`Abort` exception.
|
| 96 |
+
|
| 97 |
+
:param text: the text to show for the prompt.
|
| 98 |
+
:param default: the default value to use if no input happens. If this
|
| 99 |
+
is not given it will prompt until it's aborted.
|
| 100 |
+
:param hide_input: if this is set to true then the input value will
|
| 101 |
+
be hidden.
|
| 102 |
+
:param confirmation_prompt: Prompt a second time to confirm the
|
| 103 |
+
value. Can be set to a string instead of ``True`` to customize
|
| 104 |
+
the message.
|
| 105 |
+
:param type: the type to use to check the value against.
|
| 106 |
+
:param value_proc: if this parameter is provided it's a function that
|
| 107 |
+
is invoked instead of the type conversion to
|
| 108 |
+
convert a value.
|
| 109 |
+
:param prompt_suffix: a suffix that should be added to the prompt.
|
| 110 |
+
:param show_default: shows or hides the default value in the prompt.
|
| 111 |
+
:param err: if set to true the file defaults to ``stderr`` instead of
|
| 112 |
+
``stdout``, the same as with echo.
|
| 113 |
+
:param show_choices: Show or hide choices if the passed type is a Choice.
|
| 114 |
+
For example if type is a Choice of either day or week,
|
| 115 |
+
show_choices is true and text is "Group by" then the
|
| 116 |
+
prompt will be "Group by (day, week): ".
|
| 117 |
+
|
| 118 |
+
.. versionadded:: 8.0
|
| 119 |
+
``confirmation_prompt`` can be a custom string.
|
| 120 |
+
|
| 121 |
+
.. versionadded:: 7.0
|
| 122 |
+
Added the ``show_choices`` parameter.
|
| 123 |
+
|
| 124 |
+
.. versionadded:: 6.0
|
| 125 |
+
Added unicode support for cmd.exe on Windows.
|
| 126 |
+
|
| 127 |
+
.. versionadded:: 4.0
|
| 128 |
+
Added the `err` parameter.
|
| 129 |
+
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
def prompt_func(text: str) -> str:
|
| 133 |
+
f = hidden_prompt_func if hide_input else visible_prompt_func
|
| 134 |
+
try:
|
| 135 |
+
# Write the prompt separately so that we get nice
|
| 136 |
+
# coloring through colorama on Windows
|
| 137 |
+
echo(text.rstrip(" "), nl=False, err=err)
|
| 138 |
+
# Echo a space to stdout to work around an issue where
|
| 139 |
+
# readline causes backspace to clear the whole line.
|
| 140 |
+
return f(" ")
|
| 141 |
+
except (KeyboardInterrupt, EOFError):
|
| 142 |
+
# getpass doesn't print a newline if the user aborts input with ^C.
|
| 143 |
+
# Allegedly this behavior is inherited from getpass(3).
|
| 144 |
+
# A doc bug has been filed at https://bugs.python.org/issue24711
|
| 145 |
+
if hide_input:
|
| 146 |
+
echo(None, err=err)
|
| 147 |
+
raise Abort() from None
|
| 148 |
+
|
| 149 |
+
if value_proc is None:
|
| 150 |
+
value_proc = convert_type(type, default)
|
| 151 |
+
|
| 152 |
+
prompt = _build_prompt(
|
| 153 |
+
text, prompt_suffix, show_default, default, show_choices, type
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
if confirmation_prompt:
|
| 157 |
+
if confirmation_prompt is True:
|
| 158 |
+
confirmation_prompt = _("Repeat for confirmation")
|
| 159 |
+
|
| 160 |
+
confirmation_prompt = _build_prompt(confirmation_prompt, prompt_suffix)
|
| 161 |
+
|
| 162 |
+
while True:
|
| 163 |
+
while True:
|
| 164 |
+
value = prompt_func(prompt)
|
| 165 |
+
if value:
|
| 166 |
+
break
|
| 167 |
+
elif default is not None:
|
| 168 |
+
value = default
|
| 169 |
+
break
|
| 170 |
+
try:
|
| 171 |
+
result = value_proc(value)
|
| 172 |
+
except UsageError as e:
|
| 173 |
+
if hide_input:
|
| 174 |
+
echo(_("Error: The value you entered was invalid."), err=err)
|
| 175 |
+
else:
|
| 176 |
+
echo(_("Error: {e.message}").format(e=e), err=err)
|
| 177 |
+
continue
|
| 178 |
+
if not confirmation_prompt:
|
| 179 |
+
return result
|
| 180 |
+
while True:
|
| 181 |
+
value2 = prompt_func(confirmation_prompt)
|
| 182 |
+
is_empty = not value and not value2
|
| 183 |
+
if value2 or is_empty:
|
| 184 |
+
break
|
| 185 |
+
if value == value2:
|
| 186 |
+
return result
|
| 187 |
+
echo(_("Error: The two entered values do not match."), err=err)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def confirm(
|
| 191 |
+
text: str,
|
| 192 |
+
default: t.Optional[bool] = False,
|
| 193 |
+
abort: bool = False,
|
| 194 |
+
prompt_suffix: str = ": ",
|
| 195 |
+
show_default: bool = True,
|
| 196 |
+
err: bool = False,
|
| 197 |
+
) -> bool:
|
| 198 |
+
"""Prompts for confirmation (yes/no question).
|
| 199 |
+
|
| 200 |
+
If the user aborts the input by sending a interrupt signal this
|
| 201 |
+
function will catch it and raise a :exc:`Abort` exception.
|
| 202 |
+
|
| 203 |
+
:param text: the question to ask.
|
| 204 |
+
:param default: The default value to use when no input is given. If
|
| 205 |
+
``None``, repeat until input is given.
|
| 206 |
+
:param abort: if this is set to `True` a negative answer aborts the
|
| 207 |
+
exception by raising :exc:`Abort`.
|
| 208 |
+
:param prompt_suffix: a suffix that should be added to the prompt.
|
| 209 |
+
:param show_default: shows or hides the default value in the prompt.
|
| 210 |
+
:param err: if set to true the file defaults to ``stderr`` instead of
|
| 211 |
+
``stdout``, the same as with echo.
|
| 212 |
+
|
| 213 |
+
.. versionchanged:: 8.0
|
| 214 |
+
Repeat until input is given if ``default`` is ``None``.
|
| 215 |
+
|
| 216 |
+
.. versionadded:: 4.0
|
| 217 |
+
Added the ``err`` parameter.
|
| 218 |
+
"""
|
| 219 |
+
prompt = _build_prompt(
|
| 220 |
+
text,
|
| 221 |
+
prompt_suffix,
|
| 222 |
+
show_default,
|
| 223 |
+
"y/n" if default is None else ("Y/n" if default else "y/N"),
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
while True:
|
| 227 |
+
try:
|
| 228 |
+
# Write the prompt separately so that we get nice
|
| 229 |
+
# coloring through colorama on Windows
|
| 230 |
+
echo(prompt.rstrip(" "), nl=False, err=err)
|
| 231 |
+
# Echo a space to stdout to work around an issue where
|
| 232 |
+
# readline causes backspace to clear the whole line.
|
| 233 |
+
value = visible_prompt_func(" ").lower().strip()
|
| 234 |
+
except (KeyboardInterrupt, EOFError):
|
| 235 |
+
raise Abort() from None
|
| 236 |
+
if value in ("y", "yes"):
|
| 237 |
+
rv = True
|
| 238 |
+
elif value in ("n", "no"):
|
| 239 |
+
rv = False
|
| 240 |
+
elif default is not None and value == "":
|
| 241 |
+
rv = default
|
| 242 |
+
else:
|
| 243 |
+
echo(_("Error: invalid input"), err=err)
|
| 244 |
+
continue
|
| 245 |
+
break
|
| 246 |
+
if abort and not rv:
|
| 247 |
+
raise Abort()
|
| 248 |
+
return rv
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def echo_via_pager(
|
| 252 |
+
text_or_generator: t.Union[t.Iterable[str], t.Callable[[], t.Iterable[str]], str],
|
| 253 |
+
color: t.Optional[bool] = None,
|
| 254 |
+
) -> None:
|
| 255 |
+
"""This function takes a text and shows it via an environment specific
|
| 256 |
+
pager on stdout.
|
| 257 |
+
|
| 258 |
+
.. versionchanged:: 3.0
|
| 259 |
+
Added the `color` flag.
|
| 260 |
+
|
| 261 |
+
:param text_or_generator: the text to page, or alternatively, a
|
| 262 |
+
generator emitting the text to page.
|
| 263 |
+
:param color: controls if the pager supports ANSI colors or not. The
|
| 264 |
+
default is autodetection.
|
| 265 |
+
"""
|
| 266 |
+
color = resolve_color_default(color)
|
| 267 |
+
|
| 268 |
+
if inspect.isgeneratorfunction(text_or_generator):
|
| 269 |
+
i = t.cast(t.Callable[[], t.Iterable[str]], text_or_generator)()
|
| 270 |
+
elif isinstance(text_or_generator, str):
|
| 271 |
+
i = [text_or_generator]
|
| 272 |
+
else:
|
| 273 |
+
i = iter(t.cast(t.Iterable[str], text_or_generator))
|
| 274 |
+
|
| 275 |
+
# convert every element of i to a text type if necessary
|
| 276 |
+
text_generator = (el if isinstance(el, str) else str(el) for el in i)
|
| 277 |
+
|
| 278 |
+
from ._termui_impl import pager
|
| 279 |
+
|
| 280 |
+
return pager(itertools.chain(text_generator, "\n"), color)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def progressbar(
|
| 284 |
+
iterable: t.Optional[t.Iterable[V]] = None,
|
| 285 |
+
length: t.Optional[int] = None,
|
| 286 |
+
label: t.Optional[str] = None,
|
| 287 |
+
show_eta: bool = True,
|
| 288 |
+
show_percent: t.Optional[bool] = None,
|
| 289 |
+
show_pos: bool = False,
|
| 290 |
+
item_show_func: t.Optional[t.Callable[[t.Optional[V]], t.Optional[str]]] = None,
|
| 291 |
+
fill_char: str = "#",
|
| 292 |
+
empty_char: str = "-",
|
| 293 |
+
bar_template: str = "%(label)s [%(bar)s] %(info)s",
|
| 294 |
+
info_sep: str = " ",
|
| 295 |
+
width: int = 36,
|
| 296 |
+
file: t.Optional[t.TextIO] = None,
|
| 297 |
+
color: t.Optional[bool] = None,
|
| 298 |
+
update_min_steps: int = 1,
|
| 299 |
+
) -> "ProgressBar[V]":
|
| 300 |
+
"""This function creates an iterable context manager that can be used
|
| 301 |
+
to iterate over something while showing a progress bar. It will
|
| 302 |
+
either iterate over the `iterable` or `length` items (that are counted
|
| 303 |
+
up). While iteration happens, this function will print a rendered
|
| 304 |
+
progress bar to the given `file` (defaults to stdout) and will attempt
|
| 305 |
+
to calculate remaining time and more. By default, this progress bar
|
| 306 |
+
will not be rendered if the file is not a terminal.
|
| 307 |
+
|
| 308 |
+
The context manager creates the progress bar. When the context
|
| 309 |
+
manager is entered the progress bar is already created. With every
|
| 310 |
+
iteration over the progress bar, the iterable passed to the bar is
|
| 311 |
+
advanced and the bar is updated. When the context manager exits,
|
| 312 |
+
a newline is printed and the progress bar is finalized on screen.
|
| 313 |
+
|
| 314 |
+
Note: The progress bar is currently designed for use cases where the
|
| 315 |
+
total progress can be expected to take at least several seconds.
|
| 316 |
+
Because of this, the ProgressBar class object won't display
|
| 317 |
+
progress that is considered too fast, and progress where the time
|
| 318 |
+
between steps is less than a second.
|
| 319 |
+
|
| 320 |
+
No printing must happen or the progress bar will be unintentionally
|
| 321 |
+
destroyed.
|
| 322 |
+
|
| 323 |
+
Example usage::
|
| 324 |
+
|
| 325 |
+
with progressbar(items) as bar:
|
| 326 |
+
for item in bar:
|
| 327 |
+
do_something_with(item)
|
| 328 |
+
|
| 329 |
+
Alternatively, if no iterable is specified, one can manually update the
|
| 330 |
+
progress bar through the `update()` method instead of directly
|
| 331 |
+
iterating over the progress bar. The update method accepts the number
|
| 332 |
+
of steps to increment the bar with::
|
| 333 |
+
|
| 334 |
+
with progressbar(length=chunks.total_bytes) as bar:
|
| 335 |
+
for chunk in chunks:
|
| 336 |
+
process_chunk(chunk)
|
| 337 |
+
bar.update(chunks.bytes)
|
| 338 |
+
|
| 339 |
+
The ``update()`` method also takes an optional value specifying the
|
| 340 |
+
``current_item`` at the new position. This is useful when used
|
| 341 |
+
together with ``item_show_func`` to customize the output for each
|
| 342 |
+
manual step::
|
| 343 |
+
|
| 344 |
+
with click.progressbar(
|
| 345 |
+
length=total_size,
|
| 346 |
+
label='Unzipping archive',
|
| 347 |
+
item_show_func=lambda a: a.filename
|
| 348 |
+
) as bar:
|
| 349 |
+
for archive in zip_file:
|
| 350 |
+
archive.extract()
|
| 351 |
+
bar.update(archive.size, archive)
|
| 352 |
+
|
| 353 |
+
:param iterable: an iterable to iterate over. If not provided the length
|
| 354 |
+
is required.
|
| 355 |
+
:param length: the number of items to iterate over. By default the
|
| 356 |
+
progressbar will attempt to ask the iterator about its
|
| 357 |
+
length, which might or might not work. If an iterable is
|
| 358 |
+
also provided this parameter can be used to override the
|
| 359 |
+
length. If an iterable is not provided the progress bar
|
| 360 |
+
will iterate over a range of that length.
|
| 361 |
+
:param label: the label to show next to the progress bar.
|
| 362 |
+
:param show_eta: enables or disables the estimated time display. This is
|
| 363 |
+
automatically disabled if the length cannot be
|
| 364 |
+
determined.
|
| 365 |
+
:param show_percent: enables or disables the percentage display. The
|
| 366 |
+
default is `True` if the iterable has a length or
|
| 367 |
+
`False` if not.
|
| 368 |
+
:param show_pos: enables or disables the absolute position display. The
|
| 369 |
+
default is `False`.
|
| 370 |
+
:param item_show_func: A function called with the current item which
|
| 371 |
+
can return a string to show next to the progress bar. If the
|
| 372 |
+
function returns ``None`` nothing is shown. The current item can
|
| 373 |
+
be ``None``, such as when entering and exiting the bar.
|
| 374 |
+
:param fill_char: the character to use to show the filled part of the
|
| 375 |
+
progress bar.
|
| 376 |
+
:param empty_char: the character to use to show the non-filled part of
|
| 377 |
+
the progress bar.
|
| 378 |
+
:param bar_template: the format string to use as template for the bar.
|
| 379 |
+
The parameters in it are ``label`` for the label,
|
| 380 |
+
``bar`` for the progress bar and ``info`` for the
|
| 381 |
+
info section.
|
| 382 |
+
:param info_sep: the separator between multiple info items (eta etc.)
|
| 383 |
+
:param width: the width of the progress bar in characters, 0 means full
|
| 384 |
+
terminal width
|
| 385 |
+
:param file: The file to write to. If this is not a terminal then
|
| 386 |
+
only the label is printed.
|
| 387 |
+
:param color: controls if the terminal supports ANSI colors or not. The
|
| 388 |
+
default is autodetection. This is only needed if ANSI
|
| 389 |
+
codes are included anywhere in the progress bar output
|
| 390 |
+
which is not the case by default.
|
| 391 |
+
:param update_min_steps: Render only when this many updates have
|
| 392 |
+
completed. This allows tuning for very fast iterators.
|
| 393 |
+
|
| 394 |
+
.. versionchanged:: 8.0
|
| 395 |
+
Output is shown even if execution time is less than 0.5 seconds.
|
| 396 |
+
|
| 397 |
+
.. versionchanged:: 8.0
|
| 398 |
+
``item_show_func`` shows the current item, not the previous one.
|
| 399 |
+
|
| 400 |
+
.. versionchanged:: 8.0
|
| 401 |
+
Labels are echoed if the output is not a TTY. Reverts a change
|
| 402 |
+
in 7.0 that removed all output.
|
| 403 |
+
|
| 404 |
+
.. versionadded:: 8.0
|
| 405 |
+
Added the ``update_min_steps`` parameter.
|
| 406 |
+
|
| 407 |
+
.. versionchanged:: 4.0
|
| 408 |
+
Added the ``color`` parameter. Added the ``update`` method to
|
| 409 |
+
the object.
|
| 410 |
+
|
| 411 |
+
.. versionadded:: 2.0
|
| 412 |
+
"""
|
| 413 |
+
from ._termui_impl import ProgressBar
|
| 414 |
+
|
| 415 |
+
color = resolve_color_default(color)
|
| 416 |
+
return ProgressBar(
|
| 417 |
+
iterable=iterable,
|
| 418 |
+
length=length,
|
| 419 |
+
show_eta=show_eta,
|
| 420 |
+
show_percent=show_percent,
|
| 421 |
+
show_pos=show_pos,
|
| 422 |
+
item_show_func=item_show_func,
|
| 423 |
+
fill_char=fill_char,
|
| 424 |
+
empty_char=empty_char,
|
| 425 |
+
bar_template=bar_template,
|
| 426 |
+
info_sep=info_sep,
|
| 427 |
+
file=file,
|
| 428 |
+
label=label,
|
| 429 |
+
width=width,
|
| 430 |
+
color=color,
|
| 431 |
+
update_min_steps=update_min_steps,
|
| 432 |
+
)
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
def clear() -> None:
|
| 436 |
+
"""Clears the terminal screen. This will have the effect of clearing
|
| 437 |
+
the whole visible space of the terminal and moving the cursor to the
|
| 438 |
+
top left. This does not do anything if not connected to a terminal.
|
| 439 |
+
|
| 440 |
+
.. versionadded:: 2.0
|
| 441 |
+
"""
|
| 442 |
+
if not isatty(sys.stdout):
|
| 443 |
+
return
|
| 444 |
+
|
| 445 |
+
# ANSI escape \033[2J clears the screen, \033[1;1H moves the cursor
|
| 446 |
+
echo("\033[2J\033[1;1H", nl=False)
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def _interpret_color(
|
| 450 |
+
color: t.Union[int, t.Tuple[int, int, int], str], offset: int = 0
|
| 451 |
+
) -> str:
|
| 452 |
+
if isinstance(color, int):
|
| 453 |
+
return f"{38 + offset};5;{color:d}"
|
| 454 |
+
|
| 455 |
+
if isinstance(color, (tuple, list)):
|
| 456 |
+
r, g, b = color
|
| 457 |
+
return f"{38 + offset};2;{r:d};{g:d};{b:d}"
|
| 458 |
+
|
| 459 |
+
return str(_ansi_colors[color] + offset)
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
def style(
|
| 463 |
+
text: t.Any,
|
| 464 |
+
fg: t.Optional[t.Union[int, t.Tuple[int, int, int], str]] = None,
|
| 465 |
+
bg: t.Optional[t.Union[int, t.Tuple[int, int, int], str]] = None,
|
| 466 |
+
bold: t.Optional[bool] = None,
|
| 467 |
+
dim: t.Optional[bool] = None,
|
| 468 |
+
underline: t.Optional[bool] = None,
|
| 469 |
+
overline: t.Optional[bool] = None,
|
| 470 |
+
italic: t.Optional[bool] = None,
|
| 471 |
+
blink: t.Optional[bool] = None,
|
| 472 |
+
reverse: t.Optional[bool] = None,
|
| 473 |
+
strikethrough: t.Optional[bool] = None,
|
| 474 |
+
reset: bool = True,
|
| 475 |
+
) -> str:
|
| 476 |
+
"""Styles a text with ANSI styles and returns the new string. By
|
| 477 |
+
default the styling is self contained which means that at the end
|
| 478 |
+
of the string a reset code is issued. This can be prevented by
|
| 479 |
+
passing ``reset=False``.
|
| 480 |
+
|
| 481 |
+
Examples::
|
| 482 |
+
|
| 483 |
+
click.echo(click.style('Hello World!', fg='green'))
|
| 484 |
+
click.echo(click.style('ATTENTION!', blink=True))
|
| 485 |
+
click.echo(click.style('Some things', reverse=True, fg='cyan'))
|
| 486 |
+
click.echo(click.style('More colors', fg=(255, 12, 128), bg=117))
|
| 487 |
+
|
| 488 |
+
Supported color names:
|
| 489 |
+
|
| 490 |
+
* ``black`` (might be a gray)
|
| 491 |
+
* ``red``
|
| 492 |
+
* ``green``
|
| 493 |
+
* ``yellow`` (might be an orange)
|
| 494 |
+
* ``blue``
|
| 495 |
+
* ``magenta``
|
| 496 |
+
* ``cyan``
|
| 497 |
+
* ``white`` (might be light gray)
|
| 498 |
+
* ``bright_black``
|
| 499 |
+
* ``bright_red``
|
| 500 |
+
* ``bright_green``
|
| 501 |
+
* ``bright_yellow``
|
| 502 |
+
* ``bright_blue``
|
| 503 |
+
* ``bright_magenta``
|
| 504 |
+
* ``bright_cyan``
|
| 505 |
+
* ``bright_white``
|
| 506 |
+
* ``reset`` (reset the color code only)
|
| 507 |
+
|
| 508 |
+
If the terminal supports it, color may also be specified as:
|
| 509 |
+
|
| 510 |
+
- An integer in the interval [0, 255]. The terminal must support
|
| 511 |
+
8-bit/256-color mode.
|
| 512 |
+
- An RGB tuple of three integers in [0, 255]. The terminal must
|
| 513 |
+
support 24-bit/true-color mode.
|
| 514 |
+
|
| 515 |
+
See https://en.wikipedia.org/wiki/ANSI_color and
|
| 516 |
+
https://gist.github.com/XVilka/8346728 for more information.
|
| 517 |
+
|
| 518 |
+
:param text: the string to style with ansi codes.
|
| 519 |
+
:param fg: if provided this will become the foreground color.
|
| 520 |
+
:param bg: if provided this will become the background color.
|
| 521 |
+
:param bold: if provided this will enable or disable bold mode.
|
| 522 |
+
:param dim: if provided this will enable or disable dim mode. This is
|
| 523 |
+
badly supported.
|
| 524 |
+
:param underline: if provided this will enable or disable underline.
|
| 525 |
+
:param overline: if provided this will enable or disable overline.
|
| 526 |
+
:param italic: if provided this will enable or disable italic.
|
| 527 |
+
:param blink: if provided this will enable or disable blinking.
|
| 528 |
+
:param reverse: if provided this will enable or disable inverse
|
| 529 |
+
rendering (foreground becomes background and the
|
| 530 |
+
other way round).
|
| 531 |
+
:param strikethrough: if provided this will enable or disable
|
| 532 |
+
striking through text.
|
| 533 |
+
:param reset: by default a reset-all code is added at the end of the
|
| 534 |
+
string which means that styles do not carry over. This
|
| 535 |
+
can be disabled to compose styles.
|
| 536 |
+
|
| 537 |
+
.. versionchanged:: 8.0
|
| 538 |
+
A non-string ``message`` is converted to a string.
|
| 539 |
+
|
| 540 |
+
.. versionchanged:: 8.0
|
| 541 |
+
Added support for 256 and RGB color codes.
|
| 542 |
+
|
| 543 |
+
.. versionchanged:: 8.0
|
| 544 |
+
Added the ``strikethrough``, ``italic``, and ``overline``
|
| 545 |
+
parameters.
|
| 546 |
+
|
| 547 |
+
.. versionchanged:: 7.0
|
| 548 |
+
Added support for bright colors.
|
| 549 |
+
|
| 550 |
+
.. versionadded:: 2.0
|
| 551 |
+
"""
|
| 552 |
+
if not isinstance(text, str):
|
| 553 |
+
text = str(text)
|
| 554 |
+
|
| 555 |
+
bits = []
|
| 556 |
+
|
| 557 |
+
if fg:
|
| 558 |
+
try:
|
| 559 |
+
bits.append(f"\033[{_interpret_color(fg)}m")
|
| 560 |
+
except KeyError:
|
| 561 |
+
raise TypeError(f"Unknown color {fg!r}") from None
|
| 562 |
+
|
| 563 |
+
if bg:
|
| 564 |
+
try:
|
| 565 |
+
bits.append(f"\033[{_interpret_color(bg, 10)}m")
|
| 566 |
+
except KeyError:
|
| 567 |
+
raise TypeError(f"Unknown color {bg!r}") from None
|
| 568 |
+
|
| 569 |
+
if bold is not None:
|
| 570 |
+
bits.append(f"\033[{1 if bold else 22}m")
|
| 571 |
+
if dim is not None:
|
| 572 |
+
bits.append(f"\033[{2 if dim else 22}m")
|
| 573 |
+
if underline is not None:
|
| 574 |
+
bits.append(f"\033[{4 if underline else 24}m")
|
| 575 |
+
if overline is not None:
|
| 576 |
+
bits.append(f"\033[{53 if overline else 55}m")
|
| 577 |
+
if italic is not None:
|
| 578 |
+
bits.append(f"\033[{3 if italic else 23}m")
|
| 579 |
+
if blink is not None:
|
| 580 |
+
bits.append(f"\033[{5 if blink else 25}m")
|
| 581 |
+
if reverse is not None:
|
| 582 |
+
bits.append(f"\033[{7 if reverse else 27}m")
|
| 583 |
+
if strikethrough is not None:
|
| 584 |
+
bits.append(f"\033[{9 if strikethrough else 29}m")
|
| 585 |
+
bits.append(text)
|
| 586 |
+
if reset:
|
| 587 |
+
bits.append(_ansi_reset_all)
|
| 588 |
+
return "".join(bits)
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
def unstyle(text: str) -> str:
|
| 592 |
+
"""Removes ANSI styling information from a string. Usually it's not
|
| 593 |
+
necessary to use this function as Click's echo function will
|
| 594 |
+
automatically remove styling if necessary.
|
| 595 |
+
|
| 596 |
+
.. versionadded:: 2.0
|
| 597 |
+
|
| 598 |
+
:param text: the text to remove style information from.
|
| 599 |
+
"""
|
| 600 |
+
return strip_ansi(text)
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
def secho(
|
| 604 |
+
message: t.Optional[t.Any] = None,
|
| 605 |
+
file: t.Optional[t.IO[t.AnyStr]] = None,
|
| 606 |
+
nl: bool = True,
|
| 607 |
+
err: bool = False,
|
| 608 |
+
color: t.Optional[bool] = None,
|
| 609 |
+
**styles: t.Any,
|
| 610 |
+
) -> None:
|
| 611 |
+
"""This function combines :func:`echo` and :func:`style` into one
|
| 612 |
+
call. As such the following two calls are the same::
|
| 613 |
+
|
| 614 |
+
click.secho('Hello World!', fg='green')
|
| 615 |
+
click.echo(click.style('Hello World!', fg='green'))
|
| 616 |
+
|
| 617 |
+
All keyword arguments are forwarded to the underlying functions
|
| 618 |
+
depending on which one they go with.
|
| 619 |
+
|
| 620 |
+
Non-string types will be converted to :class:`str`. However,
|
| 621 |
+
:class:`bytes` are passed directly to :meth:`echo` without applying
|
| 622 |
+
style. If you want to style bytes that represent text, call
|
| 623 |
+
:meth:`bytes.decode` first.
|
| 624 |
+
|
| 625 |
+
.. versionchanged:: 8.0
|
| 626 |
+
A non-string ``message`` is converted to a string. Bytes are
|
| 627 |
+
passed through without style applied.
|
| 628 |
+
|
| 629 |
+
.. versionadded:: 2.0
|
| 630 |
+
"""
|
| 631 |
+
if message is not None and not isinstance(message, (bytes, bytearray)):
|
| 632 |
+
message = style(message, **styles)
|
| 633 |
+
|
| 634 |
+
return echo(message, file=file, nl=nl, err=err, color=color)
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
def edit(
|
| 638 |
+
text: t.Optional[t.AnyStr] = None,
|
| 639 |
+
editor: t.Optional[str] = None,
|
| 640 |
+
env: t.Optional[t.Mapping[str, str]] = None,
|
| 641 |
+
require_save: bool = True,
|
| 642 |
+
extension: str = ".txt",
|
| 643 |
+
filename: t.Optional[str] = None,
|
| 644 |
+
) -> t.Optional[t.AnyStr]:
|
| 645 |
+
r"""Edits the given text in the defined editor. If an editor is given
|
| 646 |
+
(should be the full path to the executable but the regular operating
|
| 647 |
+
system search path is used for finding the executable) it overrides
|
| 648 |
+
the detected editor. Optionally, some environment variables can be
|
| 649 |
+
used. If the editor is closed without changes, `None` is returned. In
|
| 650 |
+
case a file is edited directly the return value is always `None` and
|
| 651 |
+
`require_save` and `extension` are ignored.
|
| 652 |
+
|
| 653 |
+
If the editor cannot be opened a :exc:`UsageError` is raised.
|
| 654 |
+
|
| 655 |
+
Note for Windows: to simplify cross-platform usage, the newlines are
|
| 656 |
+
automatically converted from POSIX to Windows and vice versa. As such,
|
| 657 |
+
the message here will have ``\n`` as newline markers.
|
| 658 |
+
|
| 659 |
+
:param text: the text to edit.
|
| 660 |
+
:param editor: optionally the editor to use. Defaults to automatic
|
| 661 |
+
detection.
|
| 662 |
+
:param env: environment variables to forward to the editor.
|
| 663 |
+
:param require_save: if this is true, then not saving in the editor
|
| 664 |
+
will make the return value become `None`.
|
| 665 |
+
:param extension: the extension to tell the editor about. This defaults
|
| 666 |
+
to `.txt` but changing this might change syntax
|
| 667 |
+
highlighting.
|
| 668 |
+
:param filename: if provided it will edit this file instead of the
|
| 669 |
+
provided text contents. It will not use a temporary
|
| 670 |
+
file as an indirection in that case.
|
| 671 |
+
"""
|
| 672 |
+
from ._termui_impl import Editor
|
| 673 |
+
|
| 674 |
+
ed = Editor(editor=editor, env=env, require_save=require_save, extension=extension)
|
| 675 |
+
|
| 676 |
+
if filename is None:
|
| 677 |
+
return ed.edit(text)
|
| 678 |
+
|
| 679 |
+
ed.edit_file(filename)
|
| 680 |
+
return None
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
def launch(url: str, wait: bool = False, locate: bool = False) -> int:
|
| 684 |
+
"""This function launches the given URL (or filename) in the default
|
| 685 |
+
viewer application for this file type. If this is an executable, it
|
| 686 |
+
might launch the executable in a new session. The return value is
|
| 687 |
+
the exit code of the launched application. Usually, ``0`` indicates
|
| 688 |
+
success.
|
| 689 |
+
|
| 690 |
+
Examples::
|
| 691 |
+
|
| 692 |
+
click.launch('https://click.palletsprojects.com/')
|
| 693 |
+
click.launch('/my/downloaded/file', locate=True)
|
| 694 |
+
|
| 695 |
+
.. versionadded:: 2.0
|
| 696 |
+
|
| 697 |
+
:param url: URL or filename of the thing to launch.
|
| 698 |
+
:param wait: Wait for the program to exit before returning. This
|
| 699 |
+
only works if the launched program blocks. In particular,
|
| 700 |
+
``xdg-open`` on Linux does not block.
|
| 701 |
+
:param locate: if this is set to `True` then instead of launching the
|
| 702 |
+
application associated with the URL it will attempt to
|
| 703 |
+
launch a file manager with the file located. This
|
| 704 |
+
might have weird effects if the URL does not point to
|
| 705 |
+
the filesystem.
|
| 706 |
+
"""
|
| 707 |
+
from ._termui_impl import open_url
|
| 708 |
+
|
| 709 |
+
return open_url(url, wait=wait, locate=locate)
|
| 710 |
+
|
| 711 |
+
|
| 712 |
+
# If this is provided, getchar() calls into this instead. This is used
|
| 713 |
+
# for unittesting purposes.
|
| 714 |
+
_getchar: t.Optional[t.Callable[[bool], str]] = None
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
def getchar(echo: bool = False) -> str:
|
| 718 |
+
"""Fetches a single character from the terminal and returns it. This
|
| 719 |
+
will always return a unicode character and under certain rare
|
| 720 |
+
circumstances this might return more than one character. The
|
| 721 |
+
situations which more than one character is returned is when for
|
| 722 |
+
whatever reason multiple characters end up in the terminal buffer or
|
| 723 |
+
standard input was not actually a terminal.
|
| 724 |
+
|
| 725 |
+
Note that this will always read from the terminal, even if something
|
| 726 |
+
is piped into the standard input.
|
| 727 |
+
|
| 728 |
+
Note for Windows: in rare cases when typing non-ASCII characters, this
|
| 729 |
+
function might wait for a second character and then return both at once.
|
| 730 |
+
This is because certain Unicode characters look like special-key markers.
|
| 731 |
+
|
| 732 |
+
.. versionadded:: 2.0
|
| 733 |
+
|
| 734 |
+
:param echo: if set to `True`, the character read will also show up on
|
| 735 |
+
the terminal. The default is to not show it.
|
| 736 |
+
"""
|
| 737 |
+
global _getchar
|
| 738 |
+
|
| 739 |
+
if _getchar is None:
|
| 740 |
+
from ._termui_impl import getchar as f
|
| 741 |
+
|
| 742 |
+
_getchar = f
|
| 743 |
+
|
| 744 |
+
return _getchar(echo)
|
| 745 |
+
|
| 746 |
+
|
| 747 |
+
def raw_terminal() -> t.ContextManager[int]:
|
| 748 |
+
from ._termui_impl import raw_terminal as f
|
| 749 |
+
|
| 750 |
+
return f()
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
def pause(info: t.Optional[str] = None, err: bool = False) -> None:
|
| 754 |
+
"""This command stops execution and waits for the user to press any
|
| 755 |
+
key to continue. This is similar to the Windows batch "pause"
|
| 756 |
+
command. If the program is not run through a terminal, this command
|
| 757 |
+
will instead do nothing.
|
| 758 |
+
|
| 759 |
+
.. versionadded:: 2.0
|
| 760 |
+
|
| 761 |
+
.. versionadded:: 4.0
|
| 762 |
+
Added the `err` parameter.
|
| 763 |
+
|
| 764 |
+
:param info: The message to print before pausing. Defaults to
|
| 765 |
+
``"Press any key to continue..."``.
|
| 766 |
+
:param err: if set to message goes to ``stderr`` instead of
|
| 767 |
+
``stdout``, the same as with echo.
|
| 768 |
+
"""
|
| 769 |
+
if not isatty(sys.stdin) or not isatty(sys.stdout):
|
| 770 |
+
return
|
| 771 |
+
|
| 772 |
+
if info is None:
|
| 773 |
+
info = _("Press any key to continue...")
|
| 774 |
+
|
| 775 |
+
try:
|
| 776 |
+
if info:
|
| 777 |
+
echo(info, nl=False, err=err)
|
| 778 |
+
try:
|
| 779 |
+
getchar()
|
| 780 |
+
except (KeyboardInterrupt, EOFError):
|
| 781 |
+
pass
|
| 782 |
+
finally:
|
| 783 |
+
if info:
|
| 784 |
+
echo(err=err)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/testing.py
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import contextlib
|
| 2 |
+
import io
|
| 3 |
+
import os
|
| 4 |
+
import shlex
|
| 5 |
+
import shutil
|
| 6 |
+
import sys
|
| 7 |
+
import tempfile
|
| 8 |
+
import typing as t
|
| 9 |
+
from types import TracebackType
|
| 10 |
+
|
| 11 |
+
from . import _compat
|
| 12 |
+
from . import formatting
|
| 13 |
+
from . import termui
|
| 14 |
+
from . import utils
|
| 15 |
+
from ._compat import _find_binary_reader
|
| 16 |
+
|
| 17 |
+
if t.TYPE_CHECKING:
|
| 18 |
+
from .core import BaseCommand
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class EchoingStdin:
|
| 22 |
+
def __init__(self, input: t.BinaryIO, output: t.BinaryIO) -> None:
|
| 23 |
+
self._input = input
|
| 24 |
+
self._output = output
|
| 25 |
+
self._paused = False
|
| 26 |
+
|
| 27 |
+
def __getattr__(self, x: str) -> t.Any:
|
| 28 |
+
return getattr(self._input, x)
|
| 29 |
+
|
| 30 |
+
def _echo(self, rv: bytes) -> bytes:
|
| 31 |
+
if not self._paused:
|
| 32 |
+
self._output.write(rv)
|
| 33 |
+
|
| 34 |
+
return rv
|
| 35 |
+
|
| 36 |
+
def read(self, n: int = -1) -> bytes:
|
| 37 |
+
return self._echo(self._input.read(n))
|
| 38 |
+
|
| 39 |
+
def read1(self, n: int = -1) -> bytes:
|
| 40 |
+
return self._echo(self._input.read1(n)) # type: ignore
|
| 41 |
+
|
| 42 |
+
def readline(self, n: int = -1) -> bytes:
|
| 43 |
+
return self._echo(self._input.readline(n))
|
| 44 |
+
|
| 45 |
+
def readlines(self) -> t.List[bytes]:
|
| 46 |
+
return [self._echo(x) for x in self._input.readlines()]
|
| 47 |
+
|
| 48 |
+
def __iter__(self) -> t.Iterator[bytes]:
|
| 49 |
+
return iter(self._echo(x) for x in self._input)
|
| 50 |
+
|
| 51 |
+
def __repr__(self) -> str:
|
| 52 |
+
return repr(self._input)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@contextlib.contextmanager
|
| 56 |
+
def _pause_echo(stream: t.Optional[EchoingStdin]) -> t.Iterator[None]:
|
| 57 |
+
if stream is None:
|
| 58 |
+
yield
|
| 59 |
+
else:
|
| 60 |
+
stream._paused = True
|
| 61 |
+
yield
|
| 62 |
+
stream._paused = False
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class _NamedTextIOWrapper(io.TextIOWrapper):
|
| 66 |
+
def __init__(
|
| 67 |
+
self, buffer: t.BinaryIO, name: str, mode: str, **kwargs: t.Any
|
| 68 |
+
) -> None:
|
| 69 |
+
super().__init__(buffer, **kwargs)
|
| 70 |
+
self._name = name
|
| 71 |
+
self._mode = mode
|
| 72 |
+
|
| 73 |
+
@property
|
| 74 |
+
def name(self) -> str:
|
| 75 |
+
return self._name
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def mode(self) -> str:
|
| 79 |
+
return self._mode
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def make_input_stream(
|
| 83 |
+
input: t.Optional[t.Union[str, bytes, t.IO[t.Any]]], charset: str
|
| 84 |
+
) -> t.BinaryIO:
|
| 85 |
+
# Is already an input stream.
|
| 86 |
+
if hasattr(input, "read"):
|
| 87 |
+
rv = _find_binary_reader(t.cast(t.IO[t.Any], input))
|
| 88 |
+
|
| 89 |
+
if rv is not None:
|
| 90 |
+
return rv
|
| 91 |
+
|
| 92 |
+
raise TypeError("Could not find binary reader for input stream.")
|
| 93 |
+
|
| 94 |
+
if input is None:
|
| 95 |
+
input = b""
|
| 96 |
+
elif isinstance(input, str):
|
| 97 |
+
input = input.encode(charset)
|
| 98 |
+
|
| 99 |
+
return io.BytesIO(input)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class Result:
|
| 103 |
+
"""Holds the captured result of an invoked CLI script."""
|
| 104 |
+
|
| 105 |
+
def __init__(
|
| 106 |
+
self,
|
| 107 |
+
runner: "CliRunner",
|
| 108 |
+
stdout_bytes: bytes,
|
| 109 |
+
stderr_bytes: t.Optional[bytes],
|
| 110 |
+
return_value: t.Any,
|
| 111 |
+
exit_code: int,
|
| 112 |
+
exception: t.Optional[BaseException],
|
| 113 |
+
exc_info: t.Optional[
|
| 114 |
+
t.Tuple[t.Type[BaseException], BaseException, TracebackType]
|
| 115 |
+
] = None,
|
| 116 |
+
):
|
| 117 |
+
#: The runner that created the result
|
| 118 |
+
self.runner = runner
|
| 119 |
+
#: The standard output as bytes.
|
| 120 |
+
self.stdout_bytes = stdout_bytes
|
| 121 |
+
#: The standard error as bytes, or None if not available
|
| 122 |
+
self.stderr_bytes = stderr_bytes
|
| 123 |
+
#: The value returned from the invoked command.
|
| 124 |
+
#:
|
| 125 |
+
#: .. versionadded:: 8.0
|
| 126 |
+
self.return_value = return_value
|
| 127 |
+
#: The exit code as integer.
|
| 128 |
+
self.exit_code = exit_code
|
| 129 |
+
#: The exception that happened if one did.
|
| 130 |
+
self.exception = exception
|
| 131 |
+
#: The traceback
|
| 132 |
+
self.exc_info = exc_info
|
| 133 |
+
|
| 134 |
+
@property
|
| 135 |
+
def output(self) -> str:
|
| 136 |
+
"""The (standard) output as unicode string."""
|
| 137 |
+
return self.stdout
|
| 138 |
+
|
| 139 |
+
@property
|
| 140 |
+
def stdout(self) -> str:
|
| 141 |
+
"""The standard output as unicode string."""
|
| 142 |
+
return self.stdout_bytes.decode(self.runner.charset, "replace").replace(
|
| 143 |
+
"\r\n", "\n"
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
@property
|
| 147 |
+
def stderr(self) -> str:
|
| 148 |
+
"""The standard error as unicode string."""
|
| 149 |
+
if self.stderr_bytes is None:
|
| 150 |
+
raise ValueError("stderr not separately captured")
|
| 151 |
+
return self.stderr_bytes.decode(self.runner.charset, "replace").replace(
|
| 152 |
+
"\r\n", "\n"
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
def __repr__(self) -> str:
|
| 156 |
+
exc_str = repr(self.exception) if self.exception else "okay"
|
| 157 |
+
return f"<{type(self).__name__} {exc_str}>"
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class CliRunner:
|
| 161 |
+
"""The CLI runner provides functionality to invoke a Click command line
|
| 162 |
+
script for unittesting purposes in a isolated environment. This only
|
| 163 |
+
works in single-threaded systems without any concurrency as it changes the
|
| 164 |
+
global interpreter state.
|
| 165 |
+
|
| 166 |
+
:param charset: the character set for the input and output data.
|
| 167 |
+
:param env: a dictionary with environment variables for overriding.
|
| 168 |
+
:param echo_stdin: if this is set to `True`, then reading from stdin writes
|
| 169 |
+
to stdout. This is useful for showing examples in
|
| 170 |
+
some circumstances. Note that regular prompts
|
| 171 |
+
will automatically echo the input.
|
| 172 |
+
:param mix_stderr: if this is set to `False`, then stdout and stderr are
|
| 173 |
+
preserved as independent streams. This is useful for
|
| 174 |
+
Unix-philosophy apps that have predictable stdout and
|
| 175 |
+
noisy stderr, such that each may be measured
|
| 176 |
+
independently
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
def __init__(
|
| 180 |
+
self,
|
| 181 |
+
charset: str = "utf-8",
|
| 182 |
+
env: t.Optional[t.Mapping[str, t.Optional[str]]] = None,
|
| 183 |
+
echo_stdin: bool = False,
|
| 184 |
+
mix_stderr: bool = True,
|
| 185 |
+
) -> None:
|
| 186 |
+
self.charset = charset
|
| 187 |
+
self.env: t.Mapping[str, t.Optional[str]] = env or {}
|
| 188 |
+
self.echo_stdin = echo_stdin
|
| 189 |
+
self.mix_stderr = mix_stderr
|
| 190 |
+
|
| 191 |
+
def get_default_prog_name(self, cli: "BaseCommand") -> str:
|
| 192 |
+
"""Given a command object it will return the default program name
|
| 193 |
+
for it. The default is the `name` attribute or ``"root"`` if not
|
| 194 |
+
set.
|
| 195 |
+
"""
|
| 196 |
+
return cli.name or "root"
|
| 197 |
+
|
| 198 |
+
def make_env(
|
| 199 |
+
self, overrides: t.Optional[t.Mapping[str, t.Optional[str]]] = None
|
| 200 |
+
) -> t.Mapping[str, t.Optional[str]]:
|
| 201 |
+
"""Returns the environment overrides for invoking a script."""
|
| 202 |
+
rv = dict(self.env)
|
| 203 |
+
if overrides:
|
| 204 |
+
rv.update(overrides)
|
| 205 |
+
return rv
|
| 206 |
+
|
| 207 |
+
@contextlib.contextmanager
|
| 208 |
+
def isolation(
|
| 209 |
+
self,
|
| 210 |
+
input: t.Optional[t.Union[str, bytes, t.IO[t.Any]]] = None,
|
| 211 |
+
env: t.Optional[t.Mapping[str, t.Optional[str]]] = None,
|
| 212 |
+
color: bool = False,
|
| 213 |
+
) -> t.Iterator[t.Tuple[io.BytesIO, t.Optional[io.BytesIO]]]:
|
| 214 |
+
"""A context manager that sets up the isolation for invoking of a
|
| 215 |
+
command line tool. This sets up stdin with the given input data
|
| 216 |
+
and `os.environ` with the overrides from the given dictionary.
|
| 217 |
+
This also rebinds some internals in Click to be mocked (like the
|
| 218 |
+
prompt functionality).
|
| 219 |
+
|
| 220 |
+
This is automatically done in the :meth:`invoke` method.
|
| 221 |
+
|
| 222 |
+
:param input: the input stream to put into sys.stdin.
|
| 223 |
+
:param env: the environment overrides as dictionary.
|
| 224 |
+
:param color: whether the output should contain color codes. The
|
| 225 |
+
application can still override this explicitly.
|
| 226 |
+
|
| 227 |
+
.. versionchanged:: 8.0
|
| 228 |
+
``stderr`` is opened with ``errors="backslashreplace"``
|
| 229 |
+
instead of the default ``"strict"``.
|
| 230 |
+
|
| 231 |
+
.. versionchanged:: 4.0
|
| 232 |
+
Added the ``color`` parameter.
|
| 233 |
+
"""
|
| 234 |
+
bytes_input = make_input_stream(input, self.charset)
|
| 235 |
+
echo_input = None
|
| 236 |
+
|
| 237 |
+
old_stdin = sys.stdin
|
| 238 |
+
old_stdout = sys.stdout
|
| 239 |
+
old_stderr = sys.stderr
|
| 240 |
+
old_forced_width = formatting.FORCED_WIDTH
|
| 241 |
+
formatting.FORCED_WIDTH = 80
|
| 242 |
+
|
| 243 |
+
env = self.make_env(env)
|
| 244 |
+
|
| 245 |
+
bytes_output = io.BytesIO()
|
| 246 |
+
|
| 247 |
+
if self.echo_stdin:
|
| 248 |
+
bytes_input = echo_input = t.cast(
|
| 249 |
+
t.BinaryIO, EchoingStdin(bytes_input, bytes_output)
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
sys.stdin = text_input = _NamedTextIOWrapper(
|
| 253 |
+
bytes_input, encoding=self.charset, name="<stdin>", mode="r"
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
if self.echo_stdin:
|
| 257 |
+
# Force unbuffered reads, otherwise TextIOWrapper reads a
|
| 258 |
+
# large chunk which is echoed early.
|
| 259 |
+
text_input._CHUNK_SIZE = 1 # type: ignore
|
| 260 |
+
|
| 261 |
+
sys.stdout = _NamedTextIOWrapper(
|
| 262 |
+
bytes_output, encoding=self.charset, name="<stdout>", mode="w"
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
bytes_error = None
|
| 266 |
+
if self.mix_stderr:
|
| 267 |
+
sys.stderr = sys.stdout
|
| 268 |
+
else:
|
| 269 |
+
bytes_error = io.BytesIO()
|
| 270 |
+
sys.stderr = _NamedTextIOWrapper(
|
| 271 |
+
bytes_error,
|
| 272 |
+
encoding=self.charset,
|
| 273 |
+
name="<stderr>",
|
| 274 |
+
mode="w",
|
| 275 |
+
errors="backslashreplace",
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
@_pause_echo(echo_input) # type: ignore
|
| 279 |
+
def visible_input(prompt: t.Optional[str] = None) -> str:
|
| 280 |
+
sys.stdout.write(prompt or "")
|
| 281 |
+
val = text_input.readline().rstrip("\r\n")
|
| 282 |
+
sys.stdout.write(f"{val}\n")
|
| 283 |
+
sys.stdout.flush()
|
| 284 |
+
return val
|
| 285 |
+
|
| 286 |
+
@_pause_echo(echo_input) # type: ignore
|
| 287 |
+
def hidden_input(prompt: t.Optional[str] = None) -> str:
|
| 288 |
+
sys.stdout.write(f"{prompt or ''}\n")
|
| 289 |
+
sys.stdout.flush()
|
| 290 |
+
return text_input.readline().rstrip("\r\n")
|
| 291 |
+
|
| 292 |
+
@_pause_echo(echo_input) # type: ignore
|
| 293 |
+
def _getchar(echo: bool) -> str:
|
| 294 |
+
char = sys.stdin.read(1)
|
| 295 |
+
|
| 296 |
+
if echo:
|
| 297 |
+
sys.stdout.write(char)
|
| 298 |
+
|
| 299 |
+
sys.stdout.flush()
|
| 300 |
+
return char
|
| 301 |
+
|
| 302 |
+
default_color = color
|
| 303 |
+
|
| 304 |
+
def should_strip_ansi(
|
| 305 |
+
stream: t.Optional[t.IO[t.Any]] = None, color: t.Optional[bool] = None
|
| 306 |
+
) -> bool:
|
| 307 |
+
if color is None:
|
| 308 |
+
return not default_color
|
| 309 |
+
return not color
|
| 310 |
+
|
| 311 |
+
old_visible_prompt_func = termui.visible_prompt_func
|
| 312 |
+
old_hidden_prompt_func = termui.hidden_prompt_func
|
| 313 |
+
old__getchar_func = termui._getchar
|
| 314 |
+
old_should_strip_ansi = utils.should_strip_ansi # type: ignore
|
| 315 |
+
old__compat_should_strip_ansi = _compat.should_strip_ansi
|
| 316 |
+
termui.visible_prompt_func = visible_input
|
| 317 |
+
termui.hidden_prompt_func = hidden_input
|
| 318 |
+
termui._getchar = _getchar
|
| 319 |
+
utils.should_strip_ansi = should_strip_ansi # type: ignore
|
| 320 |
+
_compat.should_strip_ansi = should_strip_ansi
|
| 321 |
+
|
| 322 |
+
old_env = {}
|
| 323 |
+
try:
|
| 324 |
+
for key, value in env.items():
|
| 325 |
+
old_env[key] = os.environ.get(key)
|
| 326 |
+
if value is None:
|
| 327 |
+
try:
|
| 328 |
+
del os.environ[key]
|
| 329 |
+
except Exception:
|
| 330 |
+
pass
|
| 331 |
+
else:
|
| 332 |
+
os.environ[key] = value
|
| 333 |
+
yield (bytes_output, bytes_error)
|
| 334 |
+
finally:
|
| 335 |
+
for key, value in old_env.items():
|
| 336 |
+
if value is None:
|
| 337 |
+
try:
|
| 338 |
+
del os.environ[key]
|
| 339 |
+
except Exception:
|
| 340 |
+
pass
|
| 341 |
+
else:
|
| 342 |
+
os.environ[key] = value
|
| 343 |
+
sys.stdout = old_stdout
|
| 344 |
+
sys.stderr = old_stderr
|
| 345 |
+
sys.stdin = old_stdin
|
| 346 |
+
termui.visible_prompt_func = old_visible_prompt_func
|
| 347 |
+
termui.hidden_prompt_func = old_hidden_prompt_func
|
| 348 |
+
termui._getchar = old__getchar_func
|
| 349 |
+
utils.should_strip_ansi = old_should_strip_ansi # type: ignore
|
| 350 |
+
_compat.should_strip_ansi = old__compat_should_strip_ansi
|
| 351 |
+
formatting.FORCED_WIDTH = old_forced_width
|
| 352 |
+
|
| 353 |
+
def invoke(
|
| 354 |
+
self,
|
| 355 |
+
cli: "BaseCommand",
|
| 356 |
+
args: t.Optional[t.Union[str, t.Sequence[str]]] = None,
|
| 357 |
+
input: t.Optional[t.Union[str, bytes, t.IO[t.Any]]] = None,
|
| 358 |
+
env: t.Optional[t.Mapping[str, t.Optional[str]]] = None,
|
| 359 |
+
catch_exceptions: bool = True,
|
| 360 |
+
color: bool = False,
|
| 361 |
+
**extra: t.Any,
|
| 362 |
+
) -> Result:
|
| 363 |
+
"""Invokes a command in an isolated environment. The arguments are
|
| 364 |
+
forwarded directly to the command line script, the `extra` keyword
|
| 365 |
+
arguments are passed to the :meth:`~clickpkg.Command.main` function of
|
| 366 |
+
the command.
|
| 367 |
+
|
| 368 |
+
This returns a :class:`Result` object.
|
| 369 |
+
|
| 370 |
+
:param cli: the command to invoke
|
| 371 |
+
:param args: the arguments to invoke. It may be given as an iterable
|
| 372 |
+
or a string. When given as string it will be interpreted
|
| 373 |
+
as a Unix shell command. More details at
|
| 374 |
+
:func:`shlex.split`.
|
| 375 |
+
:param input: the input data for `sys.stdin`.
|
| 376 |
+
:param env: the environment overrides.
|
| 377 |
+
:param catch_exceptions: Whether to catch any other exceptions than
|
| 378 |
+
``SystemExit``.
|
| 379 |
+
:param extra: the keyword arguments to pass to :meth:`main`.
|
| 380 |
+
:param color: whether the output should contain color codes. The
|
| 381 |
+
application can still override this explicitly.
|
| 382 |
+
|
| 383 |
+
.. versionchanged:: 8.0
|
| 384 |
+
The result object has the ``return_value`` attribute with
|
| 385 |
+
the value returned from the invoked command.
|
| 386 |
+
|
| 387 |
+
.. versionchanged:: 4.0
|
| 388 |
+
Added the ``color`` parameter.
|
| 389 |
+
|
| 390 |
+
.. versionchanged:: 3.0
|
| 391 |
+
Added the ``catch_exceptions`` parameter.
|
| 392 |
+
|
| 393 |
+
.. versionchanged:: 3.0
|
| 394 |
+
The result object has the ``exc_info`` attribute with the
|
| 395 |
+
traceback if available.
|
| 396 |
+
"""
|
| 397 |
+
exc_info = None
|
| 398 |
+
with self.isolation(input=input, env=env, color=color) as outstreams:
|
| 399 |
+
return_value = None
|
| 400 |
+
exception: t.Optional[BaseException] = None
|
| 401 |
+
exit_code = 0
|
| 402 |
+
|
| 403 |
+
if isinstance(args, str):
|
| 404 |
+
args = shlex.split(args)
|
| 405 |
+
|
| 406 |
+
try:
|
| 407 |
+
prog_name = extra.pop("prog_name")
|
| 408 |
+
except KeyError:
|
| 409 |
+
prog_name = self.get_default_prog_name(cli)
|
| 410 |
+
|
| 411 |
+
try:
|
| 412 |
+
return_value = cli.main(args=args or (), prog_name=prog_name, **extra)
|
| 413 |
+
except SystemExit as e:
|
| 414 |
+
exc_info = sys.exc_info()
|
| 415 |
+
e_code = t.cast(t.Optional[t.Union[int, t.Any]], e.code)
|
| 416 |
+
|
| 417 |
+
if e_code is None:
|
| 418 |
+
e_code = 0
|
| 419 |
+
|
| 420 |
+
if e_code != 0:
|
| 421 |
+
exception = e
|
| 422 |
+
|
| 423 |
+
if not isinstance(e_code, int):
|
| 424 |
+
sys.stdout.write(str(e_code))
|
| 425 |
+
sys.stdout.write("\n")
|
| 426 |
+
e_code = 1
|
| 427 |
+
|
| 428 |
+
exit_code = e_code
|
| 429 |
+
|
| 430 |
+
except Exception as e:
|
| 431 |
+
if not catch_exceptions:
|
| 432 |
+
raise
|
| 433 |
+
exception = e
|
| 434 |
+
exit_code = 1
|
| 435 |
+
exc_info = sys.exc_info()
|
| 436 |
+
finally:
|
| 437 |
+
sys.stdout.flush()
|
| 438 |
+
stdout = outstreams[0].getvalue()
|
| 439 |
+
if self.mix_stderr:
|
| 440 |
+
stderr = None
|
| 441 |
+
else:
|
| 442 |
+
stderr = outstreams[1].getvalue() # type: ignore
|
| 443 |
+
|
| 444 |
+
return Result(
|
| 445 |
+
runner=self,
|
| 446 |
+
stdout_bytes=stdout,
|
| 447 |
+
stderr_bytes=stderr,
|
| 448 |
+
return_value=return_value,
|
| 449 |
+
exit_code=exit_code,
|
| 450 |
+
exception=exception,
|
| 451 |
+
exc_info=exc_info, # type: ignore
|
| 452 |
+
)
|
| 453 |
+
|
| 454 |
+
@contextlib.contextmanager
|
| 455 |
+
def isolated_filesystem(
|
| 456 |
+
self, temp_dir: t.Optional[t.Union[str, "os.PathLike[str]"]] = None
|
| 457 |
+
) -> t.Iterator[str]:
|
| 458 |
+
"""A context manager that creates a temporary directory and
|
| 459 |
+
changes the current working directory to it. This isolates tests
|
| 460 |
+
that affect the contents of the CWD to prevent them from
|
| 461 |
+
interfering with each other.
|
| 462 |
+
|
| 463 |
+
:param temp_dir: Create the temporary directory under this
|
| 464 |
+
directory. If given, the created directory is not removed
|
| 465 |
+
when exiting.
|
| 466 |
+
|
| 467 |
+
.. versionchanged:: 8.0
|
| 468 |
+
Added the ``temp_dir`` parameter.
|
| 469 |
+
"""
|
| 470 |
+
cwd = os.getcwd()
|
| 471 |
+
dt = tempfile.mkdtemp(dir=temp_dir)
|
| 472 |
+
os.chdir(dt)
|
| 473 |
+
|
| 474 |
+
try:
|
| 475 |
+
yield dt
|
| 476 |
+
finally:
|
| 477 |
+
os.chdir(cwd)
|
| 478 |
+
|
| 479 |
+
if temp_dir is None:
|
| 480 |
+
try:
|
| 481 |
+
shutil.rmtree(dt)
|
| 482 |
+
except OSError:
|
| 483 |
+
pass
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/click/types.py
ADDED
|
@@ -0,0 +1,1093 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import stat
|
| 3 |
+
import sys
|
| 4 |
+
import typing as t
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
from gettext import gettext as _
|
| 7 |
+
from gettext import ngettext
|
| 8 |
+
|
| 9 |
+
from ._compat import _get_argv_encoding
|
| 10 |
+
from ._compat import open_stream
|
| 11 |
+
from .exceptions import BadParameter
|
| 12 |
+
from .utils import format_filename
|
| 13 |
+
from .utils import LazyFile
|
| 14 |
+
from .utils import safecall
|
| 15 |
+
|
| 16 |
+
if t.TYPE_CHECKING:
|
| 17 |
+
import typing_extensions as te
|
| 18 |
+
|
| 19 |
+
from .core import Context
|
| 20 |
+
from .core import Parameter
|
| 21 |
+
from .shell_completion import CompletionItem
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class ParamType:
|
| 25 |
+
"""Represents the type of a parameter. Validates and converts values
|
| 26 |
+
from the command line or Python into the correct type.
|
| 27 |
+
|
| 28 |
+
To implement a custom type, subclass and implement at least the
|
| 29 |
+
following:
|
| 30 |
+
|
| 31 |
+
- The :attr:`name` class attribute must be set.
|
| 32 |
+
- Calling an instance of the type with ``None`` must return
|
| 33 |
+
``None``. This is already implemented by default.
|
| 34 |
+
- :meth:`convert` must convert string values to the correct type.
|
| 35 |
+
- :meth:`convert` must accept values that are already the correct
|
| 36 |
+
type.
|
| 37 |
+
- It must be able to convert a value if the ``ctx`` and ``param``
|
| 38 |
+
arguments are ``None``. This can occur when converting prompt
|
| 39 |
+
input.
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
is_composite: t.ClassVar[bool] = False
|
| 43 |
+
arity: t.ClassVar[int] = 1
|
| 44 |
+
|
| 45 |
+
#: the descriptive name of this type
|
| 46 |
+
name: str
|
| 47 |
+
|
| 48 |
+
#: if a list of this type is expected and the value is pulled from a
|
| 49 |
+
#: string environment variable, this is what splits it up. `None`
|
| 50 |
+
#: means any whitespace. For all parameters the general rule is that
|
| 51 |
+
#: whitespace splits them up. The exception are paths and files which
|
| 52 |
+
#: are split by ``os.path.pathsep`` by default (":" on Unix and ";" on
|
| 53 |
+
#: Windows).
|
| 54 |
+
envvar_list_splitter: t.ClassVar[t.Optional[str]] = None
|
| 55 |
+
|
| 56 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 57 |
+
"""Gather information that could be useful for a tool generating
|
| 58 |
+
user-facing documentation.
|
| 59 |
+
|
| 60 |
+
Use :meth:`click.Context.to_info_dict` to traverse the entire
|
| 61 |
+
CLI structure.
|
| 62 |
+
|
| 63 |
+
.. versionadded:: 8.0
|
| 64 |
+
"""
|
| 65 |
+
# The class name without the "ParamType" suffix.
|
| 66 |
+
param_type = type(self).__name__.partition("ParamType")[0]
|
| 67 |
+
param_type = param_type.partition("ParameterType")[0]
|
| 68 |
+
|
| 69 |
+
# Custom subclasses might not remember to set a name.
|
| 70 |
+
if hasattr(self, "name"):
|
| 71 |
+
name = self.name
|
| 72 |
+
else:
|
| 73 |
+
name = param_type
|
| 74 |
+
|
| 75 |
+
return {"param_type": param_type, "name": name}
|
| 76 |
+
|
| 77 |
+
def __call__(
|
| 78 |
+
self,
|
| 79 |
+
value: t.Any,
|
| 80 |
+
param: t.Optional["Parameter"] = None,
|
| 81 |
+
ctx: t.Optional["Context"] = None,
|
| 82 |
+
) -> t.Any:
|
| 83 |
+
if value is not None:
|
| 84 |
+
return self.convert(value, param, ctx)
|
| 85 |
+
|
| 86 |
+
def get_metavar(self, param: "Parameter") -> t.Optional[str]:
|
| 87 |
+
"""Returns the metavar default for this param if it provides one."""
|
| 88 |
+
|
| 89 |
+
def get_missing_message(self, param: "Parameter") -> t.Optional[str]:
|
| 90 |
+
"""Optionally might return extra information about a missing
|
| 91 |
+
parameter.
|
| 92 |
+
|
| 93 |
+
.. versionadded:: 2.0
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
def convert(
|
| 97 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 98 |
+
) -> t.Any:
|
| 99 |
+
"""Convert the value to the correct type. This is not called if
|
| 100 |
+
the value is ``None`` (the missing value).
|
| 101 |
+
|
| 102 |
+
This must accept string values from the command line, as well as
|
| 103 |
+
values that are already the correct type. It may also convert
|
| 104 |
+
other compatible types.
|
| 105 |
+
|
| 106 |
+
The ``param`` and ``ctx`` arguments may be ``None`` in certain
|
| 107 |
+
situations, such as when converting prompt input.
|
| 108 |
+
|
| 109 |
+
If the value cannot be converted, call :meth:`fail` with a
|
| 110 |
+
descriptive message.
|
| 111 |
+
|
| 112 |
+
:param value: The value to convert.
|
| 113 |
+
:param param: The parameter that is using this type to convert
|
| 114 |
+
its value. May be ``None``.
|
| 115 |
+
:param ctx: The current context that arrived at this value. May
|
| 116 |
+
be ``None``.
|
| 117 |
+
"""
|
| 118 |
+
return value
|
| 119 |
+
|
| 120 |
+
def split_envvar_value(self, rv: str) -> t.Sequence[str]:
|
| 121 |
+
"""Given a value from an environment variable this splits it up
|
| 122 |
+
into small chunks depending on the defined envvar list splitter.
|
| 123 |
+
|
| 124 |
+
If the splitter is set to `None`, which means that whitespace splits,
|
| 125 |
+
then leading and trailing whitespace is ignored. Otherwise, leading
|
| 126 |
+
and trailing splitters usually lead to empty items being included.
|
| 127 |
+
"""
|
| 128 |
+
return (rv or "").split(self.envvar_list_splitter)
|
| 129 |
+
|
| 130 |
+
def fail(
|
| 131 |
+
self,
|
| 132 |
+
message: str,
|
| 133 |
+
param: t.Optional["Parameter"] = None,
|
| 134 |
+
ctx: t.Optional["Context"] = None,
|
| 135 |
+
) -> "t.NoReturn":
|
| 136 |
+
"""Helper method to fail with an invalid value message."""
|
| 137 |
+
raise BadParameter(message, ctx=ctx, param=param)
|
| 138 |
+
|
| 139 |
+
def shell_complete(
|
| 140 |
+
self, ctx: "Context", param: "Parameter", incomplete: str
|
| 141 |
+
) -> t.List["CompletionItem"]:
|
| 142 |
+
"""Return a list of
|
| 143 |
+
:class:`~click.shell_completion.CompletionItem` objects for the
|
| 144 |
+
incomplete value. Most types do not provide completions, but
|
| 145 |
+
some do, and this allows custom types to provide custom
|
| 146 |
+
completions as well.
|
| 147 |
+
|
| 148 |
+
:param ctx: Invocation context for this command.
|
| 149 |
+
:param param: The parameter that is requesting completion.
|
| 150 |
+
:param incomplete: Value being completed. May be empty.
|
| 151 |
+
|
| 152 |
+
.. versionadded:: 8.0
|
| 153 |
+
"""
|
| 154 |
+
return []
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
class CompositeParamType(ParamType):
|
| 158 |
+
is_composite = True
|
| 159 |
+
|
| 160 |
+
@property
|
| 161 |
+
def arity(self) -> int: # type: ignore
|
| 162 |
+
raise NotImplementedError()
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class FuncParamType(ParamType):
|
| 166 |
+
def __init__(self, func: t.Callable[[t.Any], t.Any]) -> None:
|
| 167 |
+
self.name: str = func.__name__
|
| 168 |
+
self.func = func
|
| 169 |
+
|
| 170 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 171 |
+
info_dict = super().to_info_dict()
|
| 172 |
+
info_dict["func"] = self.func
|
| 173 |
+
return info_dict
|
| 174 |
+
|
| 175 |
+
def convert(
|
| 176 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 177 |
+
) -> t.Any:
|
| 178 |
+
try:
|
| 179 |
+
return self.func(value)
|
| 180 |
+
except ValueError:
|
| 181 |
+
try:
|
| 182 |
+
value = str(value)
|
| 183 |
+
except UnicodeError:
|
| 184 |
+
value = value.decode("utf-8", "replace")
|
| 185 |
+
|
| 186 |
+
self.fail(value, param, ctx)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
class UnprocessedParamType(ParamType):
|
| 190 |
+
name = "text"
|
| 191 |
+
|
| 192 |
+
def convert(
|
| 193 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 194 |
+
) -> t.Any:
|
| 195 |
+
return value
|
| 196 |
+
|
| 197 |
+
def __repr__(self) -> str:
|
| 198 |
+
return "UNPROCESSED"
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class StringParamType(ParamType):
|
| 202 |
+
name = "text"
|
| 203 |
+
|
| 204 |
+
def convert(
|
| 205 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 206 |
+
) -> t.Any:
|
| 207 |
+
if isinstance(value, bytes):
|
| 208 |
+
enc = _get_argv_encoding()
|
| 209 |
+
try:
|
| 210 |
+
value = value.decode(enc)
|
| 211 |
+
except UnicodeError:
|
| 212 |
+
fs_enc = sys.getfilesystemencoding()
|
| 213 |
+
if fs_enc != enc:
|
| 214 |
+
try:
|
| 215 |
+
value = value.decode(fs_enc)
|
| 216 |
+
except UnicodeError:
|
| 217 |
+
value = value.decode("utf-8", "replace")
|
| 218 |
+
else:
|
| 219 |
+
value = value.decode("utf-8", "replace")
|
| 220 |
+
return value
|
| 221 |
+
return str(value)
|
| 222 |
+
|
| 223 |
+
def __repr__(self) -> str:
|
| 224 |
+
return "STRING"
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
class Choice(ParamType):
|
| 228 |
+
"""The choice type allows a value to be checked against a fixed set
|
| 229 |
+
of supported values. All of these values have to be strings.
|
| 230 |
+
|
| 231 |
+
You should only pass a list or tuple of choices. Other iterables
|
| 232 |
+
(like generators) may lead to surprising results.
|
| 233 |
+
|
| 234 |
+
The resulting value will always be one of the originally passed choices
|
| 235 |
+
regardless of ``case_sensitive`` or any ``ctx.token_normalize_func``
|
| 236 |
+
being specified.
|
| 237 |
+
|
| 238 |
+
See :ref:`choice-opts` for an example.
|
| 239 |
+
|
| 240 |
+
:param case_sensitive: Set to false to make choices case
|
| 241 |
+
insensitive. Defaults to true.
|
| 242 |
+
"""
|
| 243 |
+
|
| 244 |
+
name = "choice"
|
| 245 |
+
|
| 246 |
+
def __init__(self, choices: t.Sequence[str], case_sensitive: bool = True) -> None:
|
| 247 |
+
self.choices = choices
|
| 248 |
+
self.case_sensitive = case_sensitive
|
| 249 |
+
|
| 250 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 251 |
+
info_dict = super().to_info_dict()
|
| 252 |
+
info_dict["choices"] = self.choices
|
| 253 |
+
info_dict["case_sensitive"] = self.case_sensitive
|
| 254 |
+
return info_dict
|
| 255 |
+
|
| 256 |
+
def get_metavar(self, param: "Parameter") -> str:
|
| 257 |
+
choices_str = "|".join(self.choices)
|
| 258 |
+
|
| 259 |
+
# Use curly braces to indicate a required argument.
|
| 260 |
+
if param.required and param.param_type_name == "argument":
|
| 261 |
+
return f"{{{choices_str}}}"
|
| 262 |
+
|
| 263 |
+
# Use square braces to indicate an option or optional argument.
|
| 264 |
+
return f"[{choices_str}]"
|
| 265 |
+
|
| 266 |
+
def get_missing_message(self, param: "Parameter") -> str:
|
| 267 |
+
return _("Choose from:\n\t{choices}").format(choices=",\n\t".join(self.choices))
|
| 268 |
+
|
| 269 |
+
def convert(
|
| 270 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 271 |
+
) -> t.Any:
|
| 272 |
+
# Match through normalization and case sensitivity
|
| 273 |
+
# first do token_normalize_func, then lowercase
|
| 274 |
+
# preserve original `value` to produce an accurate message in
|
| 275 |
+
# `self.fail`
|
| 276 |
+
normed_value = value
|
| 277 |
+
normed_choices = {choice: choice for choice in self.choices}
|
| 278 |
+
|
| 279 |
+
if ctx is not None and ctx.token_normalize_func is not None:
|
| 280 |
+
normed_value = ctx.token_normalize_func(value)
|
| 281 |
+
normed_choices = {
|
| 282 |
+
ctx.token_normalize_func(normed_choice): original
|
| 283 |
+
for normed_choice, original in normed_choices.items()
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
if not self.case_sensitive:
|
| 287 |
+
normed_value = normed_value.casefold()
|
| 288 |
+
normed_choices = {
|
| 289 |
+
normed_choice.casefold(): original
|
| 290 |
+
for normed_choice, original in normed_choices.items()
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
if normed_value in normed_choices:
|
| 294 |
+
return normed_choices[normed_value]
|
| 295 |
+
|
| 296 |
+
choices_str = ", ".join(map(repr, self.choices))
|
| 297 |
+
self.fail(
|
| 298 |
+
ngettext(
|
| 299 |
+
"{value!r} is not {choice}.",
|
| 300 |
+
"{value!r} is not one of {choices}.",
|
| 301 |
+
len(self.choices),
|
| 302 |
+
).format(value=value, choice=choices_str, choices=choices_str),
|
| 303 |
+
param,
|
| 304 |
+
ctx,
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
def __repr__(self) -> str:
|
| 308 |
+
return f"Choice({list(self.choices)})"
|
| 309 |
+
|
| 310 |
+
def shell_complete(
|
| 311 |
+
self, ctx: "Context", param: "Parameter", incomplete: str
|
| 312 |
+
) -> t.List["CompletionItem"]:
|
| 313 |
+
"""Complete choices that start with the incomplete value.
|
| 314 |
+
|
| 315 |
+
:param ctx: Invocation context for this command.
|
| 316 |
+
:param param: The parameter that is requesting completion.
|
| 317 |
+
:param incomplete: Value being completed. May be empty.
|
| 318 |
+
|
| 319 |
+
.. versionadded:: 8.0
|
| 320 |
+
"""
|
| 321 |
+
from click.shell_completion import CompletionItem
|
| 322 |
+
|
| 323 |
+
str_choices = map(str, self.choices)
|
| 324 |
+
|
| 325 |
+
if self.case_sensitive:
|
| 326 |
+
matched = (c for c in str_choices if c.startswith(incomplete))
|
| 327 |
+
else:
|
| 328 |
+
incomplete = incomplete.lower()
|
| 329 |
+
matched = (c for c in str_choices if c.lower().startswith(incomplete))
|
| 330 |
+
|
| 331 |
+
return [CompletionItem(c) for c in matched]
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
class DateTime(ParamType):
|
| 335 |
+
"""The DateTime type converts date strings into `datetime` objects.
|
| 336 |
+
|
| 337 |
+
The format strings which are checked are configurable, but default to some
|
| 338 |
+
common (non-timezone aware) ISO 8601 formats.
|
| 339 |
+
|
| 340 |
+
When specifying *DateTime* formats, you should only pass a list or a tuple.
|
| 341 |
+
Other iterables, like generators, may lead to surprising results.
|
| 342 |
+
|
| 343 |
+
The format strings are processed using ``datetime.strptime``, and this
|
| 344 |
+
consequently defines the format strings which are allowed.
|
| 345 |
+
|
| 346 |
+
Parsing is tried using each format, in order, and the first format which
|
| 347 |
+
parses successfully is used.
|
| 348 |
+
|
| 349 |
+
:param formats: A list or tuple of date format strings, in the order in
|
| 350 |
+
which they should be tried. Defaults to
|
| 351 |
+
``'%Y-%m-%d'``, ``'%Y-%m-%dT%H:%M:%S'``,
|
| 352 |
+
``'%Y-%m-%d %H:%M:%S'``.
|
| 353 |
+
"""
|
| 354 |
+
|
| 355 |
+
name = "datetime"
|
| 356 |
+
|
| 357 |
+
def __init__(self, formats: t.Optional[t.Sequence[str]] = None):
|
| 358 |
+
self.formats: t.Sequence[str] = formats or [
|
| 359 |
+
"%Y-%m-%d",
|
| 360 |
+
"%Y-%m-%dT%H:%M:%S",
|
| 361 |
+
"%Y-%m-%d %H:%M:%S",
|
| 362 |
+
]
|
| 363 |
+
|
| 364 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 365 |
+
info_dict = super().to_info_dict()
|
| 366 |
+
info_dict["formats"] = self.formats
|
| 367 |
+
return info_dict
|
| 368 |
+
|
| 369 |
+
def get_metavar(self, param: "Parameter") -> str:
|
| 370 |
+
return f"[{'|'.join(self.formats)}]"
|
| 371 |
+
|
| 372 |
+
def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]:
|
| 373 |
+
try:
|
| 374 |
+
return datetime.strptime(value, format)
|
| 375 |
+
except ValueError:
|
| 376 |
+
return None
|
| 377 |
+
|
| 378 |
+
def convert(
|
| 379 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 380 |
+
) -> t.Any:
|
| 381 |
+
if isinstance(value, datetime):
|
| 382 |
+
return value
|
| 383 |
+
|
| 384 |
+
for format in self.formats:
|
| 385 |
+
converted = self._try_to_convert_date(value, format)
|
| 386 |
+
|
| 387 |
+
if converted is not None:
|
| 388 |
+
return converted
|
| 389 |
+
|
| 390 |
+
formats_str = ", ".join(map(repr, self.formats))
|
| 391 |
+
self.fail(
|
| 392 |
+
ngettext(
|
| 393 |
+
"{value!r} does not match the format {format}.",
|
| 394 |
+
"{value!r} does not match the formats {formats}.",
|
| 395 |
+
len(self.formats),
|
| 396 |
+
).format(value=value, format=formats_str, formats=formats_str),
|
| 397 |
+
param,
|
| 398 |
+
ctx,
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
def __repr__(self) -> str:
|
| 402 |
+
return "DateTime"
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
class _NumberParamTypeBase(ParamType):
|
| 406 |
+
_number_class: t.ClassVar[t.Type[t.Any]]
|
| 407 |
+
|
| 408 |
+
def convert(
|
| 409 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 410 |
+
) -> t.Any:
|
| 411 |
+
try:
|
| 412 |
+
return self._number_class(value)
|
| 413 |
+
except ValueError:
|
| 414 |
+
self.fail(
|
| 415 |
+
_("{value!r} is not a valid {number_type}.").format(
|
| 416 |
+
value=value, number_type=self.name
|
| 417 |
+
),
|
| 418 |
+
param,
|
| 419 |
+
ctx,
|
| 420 |
+
)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
class _NumberRangeBase(_NumberParamTypeBase):
|
| 424 |
+
def __init__(
|
| 425 |
+
self,
|
| 426 |
+
min: t.Optional[float] = None,
|
| 427 |
+
max: t.Optional[float] = None,
|
| 428 |
+
min_open: bool = False,
|
| 429 |
+
max_open: bool = False,
|
| 430 |
+
clamp: bool = False,
|
| 431 |
+
) -> None:
|
| 432 |
+
self.min = min
|
| 433 |
+
self.max = max
|
| 434 |
+
self.min_open = min_open
|
| 435 |
+
self.max_open = max_open
|
| 436 |
+
self.clamp = clamp
|
| 437 |
+
|
| 438 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 439 |
+
info_dict = super().to_info_dict()
|
| 440 |
+
info_dict.update(
|
| 441 |
+
min=self.min,
|
| 442 |
+
max=self.max,
|
| 443 |
+
min_open=self.min_open,
|
| 444 |
+
max_open=self.max_open,
|
| 445 |
+
clamp=self.clamp,
|
| 446 |
+
)
|
| 447 |
+
return info_dict
|
| 448 |
+
|
| 449 |
+
def convert(
|
| 450 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 451 |
+
) -> t.Any:
|
| 452 |
+
import operator
|
| 453 |
+
|
| 454 |
+
rv = super().convert(value, param, ctx)
|
| 455 |
+
lt_min: bool = self.min is not None and (
|
| 456 |
+
operator.le if self.min_open else operator.lt
|
| 457 |
+
)(rv, self.min)
|
| 458 |
+
gt_max: bool = self.max is not None and (
|
| 459 |
+
operator.ge if self.max_open else operator.gt
|
| 460 |
+
)(rv, self.max)
|
| 461 |
+
|
| 462 |
+
if self.clamp:
|
| 463 |
+
if lt_min:
|
| 464 |
+
return self._clamp(self.min, 1, self.min_open) # type: ignore
|
| 465 |
+
|
| 466 |
+
if gt_max:
|
| 467 |
+
return self._clamp(self.max, -1, self.max_open) # type: ignore
|
| 468 |
+
|
| 469 |
+
if lt_min or gt_max:
|
| 470 |
+
self.fail(
|
| 471 |
+
_("{value} is not in the range {range}.").format(
|
| 472 |
+
value=rv, range=self._describe_range()
|
| 473 |
+
),
|
| 474 |
+
param,
|
| 475 |
+
ctx,
|
| 476 |
+
)
|
| 477 |
+
|
| 478 |
+
return rv
|
| 479 |
+
|
| 480 |
+
def _clamp(self, bound: float, dir: "te.Literal[1, -1]", open: bool) -> float:
|
| 481 |
+
"""Find the valid value to clamp to bound in the given
|
| 482 |
+
direction.
|
| 483 |
+
|
| 484 |
+
:param bound: The boundary value.
|
| 485 |
+
:param dir: 1 or -1 indicating the direction to move.
|
| 486 |
+
:param open: If true, the range does not include the bound.
|
| 487 |
+
"""
|
| 488 |
+
raise NotImplementedError
|
| 489 |
+
|
| 490 |
+
def _describe_range(self) -> str:
|
| 491 |
+
"""Describe the range for use in help text."""
|
| 492 |
+
if self.min is None:
|
| 493 |
+
op = "<" if self.max_open else "<="
|
| 494 |
+
return f"x{op}{self.max}"
|
| 495 |
+
|
| 496 |
+
if self.max is None:
|
| 497 |
+
op = ">" if self.min_open else ">="
|
| 498 |
+
return f"x{op}{self.min}"
|
| 499 |
+
|
| 500 |
+
lop = "<" if self.min_open else "<="
|
| 501 |
+
rop = "<" if self.max_open else "<="
|
| 502 |
+
return f"{self.min}{lop}x{rop}{self.max}"
|
| 503 |
+
|
| 504 |
+
def __repr__(self) -> str:
|
| 505 |
+
clamp = " clamped" if self.clamp else ""
|
| 506 |
+
return f"<{type(self).__name__} {self._describe_range()}{clamp}>"
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
class IntParamType(_NumberParamTypeBase):
|
| 510 |
+
name = "integer"
|
| 511 |
+
_number_class = int
|
| 512 |
+
|
| 513 |
+
def __repr__(self) -> str:
|
| 514 |
+
return "INT"
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
class IntRange(_NumberRangeBase, IntParamType):
|
| 518 |
+
"""Restrict an :data:`click.INT` value to a range of accepted
|
| 519 |
+
values. See :ref:`ranges`.
|
| 520 |
+
|
| 521 |
+
If ``min`` or ``max`` are not passed, any value is accepted in that
|
| 522 |
+
direction. If ``min_open`` or ``max_open`` are enabled, the
|
| 523 |
+
corresponding boundary is not included in the range.
|
| 524 |
+
|
| 525 |
+
If ``clamp`` is enabled, a value outside the range is clamped to the
|
| 526 |
+
boundary instead of failing.
|
| 527 |
+
|
| 528 |
+
.. versionchanged:: 8.0
|
| 529 |
+
Added the ``min_open`` and ``max_open`` parameters.
|
| 530 |
+
"""
|
| 531 |
+
|
| 532 |
+
name = "integer range"
|
| 533 |
+
|
| 534 |
+
def _clamp( # type: ignore
|
| 535 |
+
self, bound: int, dir: "te.Literal[1, -1]", open: bool
|
| 536 |
+
) -> int:
|
| 537 |
+
if not open:
|
| 538 |
+
return bound
|
| 539 |
+
|
| 540 |
+
return bound + dir
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
class FloatParamType(_NumberParamTypeBase):
|
| 544 |
+
name = "float"
|
| 545 |
+
_number_class = float
|
| 546 |
+
|
| 547 |
+
def __repr__(self) -> str:
|
| 548 |
+
return "FLOAT"
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
class FloatRange(_NumberRangeBase, FloatParamType):
|
| 552 |
+
"""Restrict a :data:`click.FLOAT` value to a range of accepted
|
| 553 |
+
values. See :ref:`ranges`.
|
| 554 |
+
|
| 555 |
+
If ``min`` or ``max`` are not passed, any value is accepted in that
|
| 556 |
+
direction. If ``min_open`` or ``max_open`` are enabled, the
|
| 557 |
+
corresponding boundary is not included in the range.
|
| 558 |
+
|
| 559 |
+
If ``clamp`` is enabled, a value outside the range is clamped to the
|
| 560 |
+
boundary instead of failing. This is not supported if either
|
| 561 |
+
boundary is marked ``open``.
|
| 562 |
+
|
| 563 |
+
.. versionchanged:: 8.0
|
| 564 |
+
Added the ``min_open`` and ``max_open`` parameters.
|
| 565 |
+
"""
|
| 566 |
+
|
| 567 |
+
name = "float range"
|
| 568 |
+
|
| 569 |
+
def __init__(
|
| 570 |
+
self,
|
| 571 |
+
min: t.Optional[float] = None,
|
| 572 |
+
max: t.Optional[float] = None,
|
| 573 |
+
min_open: bool = False,
|
| 574 |
+
max_open: bool = False,
|
| 575 |
+
clamp: bool = False,
|
| 576 |
+
) -> None:
|
| 577 |
+
super().__init__(
|
| 578 |
+
min=min, max=max, min_open=min_open, max_open=max_open, clamp=clamp
|
| 579 |
+
)
|
| 580 |
+
|
| 581 |
+
if (min_open or max_open) and clamp:
|
| 582 |
+
raise TypeError("Clamping is not supported for open bounds.")
|
| 583 |
+
|
| 584 |
+
def _clamp(self, bound: float, dir: "te.Literal[1, -1]", open: bool) -> float:
|
| 585 |
+
if not open:
|
| 586 |
+
return bound
|
| 587 |
+
|
| 588 |
+
# Could use Python 3.9's math.nextafter here, but clamping an
|
| 589 |
+
# open float range doesn't seem to be particularly useful. It's
|
| 590 |
+
# left up to the user to write a callback to do it if needed.
|
| 591 |
+
raise RuntimeError("Clamping is not supported for open bounds.")
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
class BoolParamType(ParamType):
|
| 595 |
+
name = "boolean"
|
| 596 |
+
|
| 597 |
+
def convert(
|
| 598 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 599 |
+
) -> t.Any:
|
| 600 |
+
if value in {False, True}:
|
| 601 |
+
return bool(value)
|
| 602 |
+
|
| 603 |
+
norm = value.strip().lower()
|
| 604 |
+
|
| 605 |
+
if norm in {"1", "true", "t", "yes", "y", "on"}:
|
| 606 |
+
return True
|
| 607 |
+
|
| 608 |
+
if norm in {"0", "false", "f", "no", "n", "off"}:
|
| 609 |
+
return False
|
| 610 |
+
|
| 611 |
+
self.fail(
|
| 612 |
+
_("{value!r} is not a valid boolean.").format(value=value), param, ctx
|
| 613 |
+
)
|
| 614 |
+
|
| 615 |
+
def __repr__(self) -> str:
|
| 616 |
+
return "BOOL"
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
class UUIDParameterType(ParamType):
|
| 620 |
+
name = "uuid"
|
| 621 |
+
|
| 622 |
+
def convert(
|
| 623 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 624 |
+
) -> t.Any:
|
| 625 |
+
import uuid
|
| 626 |
+
|
| 627 |
+
if isinstance(value, uuid.UUID):
|
| 628 |
+
return value
|
| 629 |
+
|
| 630 |
+
value = value.strip()
|
| 631 |
+
|
| 632 |
+
try:
|
| 633 |
+
return uuid.UUID(value)
|
| 634 |
+
except ValueError:
|
| 635 |
+
self.fail(
|
| 636 |
+
_("{value!r} is not a valid UUID.").format(value=value), param, ctx
|
| 637 |
+
)
|
| 638 |
+
|
| 639 |
+
def __repr__(self) -> str:
|
| 640 |
+
return "UUID"
|
| 641 |
+
|
| 642 |
+
|
| 643 |
+
class File(ParamType):
|
| 644 |
+
"""Declares a parameter to be a file for reading or writing. The file
|
| 645 |
+
is automatically closed once the context tears down (after the command
|
| 646 |
+
finished working).
|
| 647 |
+
|
| 648 |
+
Files can be opened for reading or writing. The special value ``-``
|
| 649 |
+
indicates stdin or stdout depending on the mode.
|
| 650 |
+
|
| 651 |
+
By default, the file is opened for reading text data, but it can also be
|
| 652 |
+
opened in binary mode or for writing. The encoding parameter can be used
|
| 653 |
+
to force a specific encoding.
|
| 654 |
+
|
| 655 |
+
The `lazy` flag controls if the file should be opened immediately or upon
|
| 656 |
+
first IO. The default is to be non-lazy for standard input and output
|
| 657 |
+
streams as well as files opened for reading, `lazy` otherwise. When opening a
|
| 658 |
+
file lazily for reading, it is still opened temporarily for validation, but
|
| 659 |
+
will not be held open until first IO. lazy is mainly useful when opening
|
| 660 |
+
for writing to avoid creating the file until it is needed.
|
| 661 |
+
|
| 662 |
+
Files can also be opened atomically in which case all writes go into a
|
| 663 |
+
separate file in the same folder and upon completion the file will
|
| 664 |
+
be moved over to the original location. This is useful if a file
|
| 665 |
+
regularly read by other users is modified.
|
| 666 |
+
|
| 667 |
+
See :ref:`file-args` for more information.
|
| 668 |
+
|
| 669 |
+
.. versionchanged:: 2.0
|
| 670 |
+
Added the ``atomic`` parameter.
|
| 671 |
+
"""
|
| 672 |
+
|
| 673 |
+
name = "filename"
|
| 674 |
+
envvar_list_splitter: t.ClassVar[str] = os.path.pathsep
|
| 675 |
+
|
| 676 |
+
def __init__(
|
| 677 |
+
self,
|
| 678 |
+
mode: str = "r",
|
| 679 |
+
encoding: t.Optional[str] = None,
|
| 680 |
+
errors: t.Optional[str] = "strict",
|
| 681 |
+
lazy: t.Optional[bool] = None,
|
| 682 |
+
atomic: bool = False,
|
| 683 |
+
) -> None:
|
| 684 |
+
self.mode = mode
|
| 685 |
+
self.encoding = encoding
|
| 686 |
+
self.errors = errors
|
| 687 |
+
self.lazy = lazy
|
| 688 |
+
self.atomic = atomic
|
| 689 |
+
|
| 690 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 691 |
+
info_dict = super().to_info_dict()
|
| 692 |
+
info_dict.update(mode=self.mode, encoding=self.encoding)
|
| 693 |
+
return info_dict
|
| 694 |
+
|
| 695 |
+
def resolve_lazy_flag(self, value: "t.Union[str, os.PathLike[str]]") -> bool:
|
| 696 |
+
if self.lazy is not None:
|
| 697 |
+
return self.lazy
|
| 698 |
+
if os.fspath(value) == "-":
|
| 699 |
+
return False
|
| 700 |
+
elif "w" in self.mode:
|
| 701 |
+
return True
|
| 702 |
+
return False
|
| 703 |
+
|
| 704 |
+
def convert(
|
| 705 |
+
self,
|
| 706 |
+
value: t.Union[str, "os.PathLike[str]", t.IO[t.Any]],
|
| 707 |
+
param: t.Optional["Parameter"],
|
| 708 |
+
ctx: t.Optional["Context"],
|
| 709 |
+
) -> t.IO[t.Any]:
|
| 710 |
+
if _is_file_like(value):
|
| 711 |
+
return value
|
| 712 |
+
|
| 713 |
+
value = t.cast("t.Union[str, os.PathLike[str]]", value)
|
| 714 |
+
|
| 715 |
+
try:
|
| 716 |
+
lazy = self.resolve_lazy_flag(value)
|
| 717 |
+
|
| 718 |
+
if lazy:
|
| 719 |
+
lf = LazyFile(
|
| 720 |
+
value, self.mode, self.encoding, self.errors, atomic=self.atomic
|
| 721 |
+
)
|
| 722 |
+
|
| 723 |
+
if ctx is not None:
|
| 724 |
+
ctx.call_on_close(lf.close_intelligently)
|
| 725 |
+
|
| 726 |
+
return t.cast(t.IO[t.Any], lf)
|
| 727 |
+
|
| 728 |
+
f, should_close = open_stream(
|
| 729 |
+
value, self.mode, self.encoding, self.errors, atomic=self.atomic
|
| 730 |
+
)
|
| 731 |
+
|
| 732 |
+
# If a context is provided, we automatically close the file
|
| 733 |
+
# at the end of the context execution (or flush out). If a
|
| 734 |
+
# context does not exist, it's the caller's responsibility to
|
| 735 |
+
# properly close the file. This for instance happens when the
|
| 736 |
+
# type is used with prompts.
|
| 737 |
+
if ctx is not None:
|
| 738 |
+
if should_close:
|
| 739 |
+
ctx.call_on_close(safecall(f.close))
|
| 740 |
+
else:
|
| 741 |
+
ctx.call_on_close(safecall(f.flush))
|
| 742 |
+
|
| 743 |
+
return f
|
| 744 |
+
except OSError as e:
|
| 745 |
+
self.fail(f"'{format_filename(value)}': {e.strerror}", param, ctx)
|
| 746 |
+
|
| 747 |
+
def shell_complete(
|
| 748 |
+
self, ctx: "Context", param: "Parameter", incomplete: str
|
| 749 |
+
) -> t.List["CompletionItem"]:
|
| 750 |
+
"""Return a special completion marker that tells the completion
|
| 751 |
+
system to use the shell to provide file path completions.
|
| 752 |
+
|
| 753 |
+
:param ctx: Invocation context for this command.
|
| 754 |
+
:param param: The parameter that is requesting completion.
|
| 755 |
+
:param incomplete: Value being completed. May be empty.
|
| 756 |
+
|
| 757 |
+
.. versionadded:: 8.0
|
| 758 |
+
"""
|
| 759 |
+
from click.shell_completion import CompletionItem
|
| 760 |
+
|
| 761 |
+
return [CompletionItem(incomplete, type="file")]
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
def _is_file_like(value: t.Any) -> "te.TypeGuard[t.IO[t.Any]]":
|
| 765 |
+
return hasattr(value, "read") or hasattr(value, "write")
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
class Path(ParamType):
|
| 769 |
+
"""The ``Path`` type is similar to the :class:`File` type, but
|
| 770 |
+
returns the filename instead of an open file. Various checks can be
|
| 771 |
+
enabled to validate the type of file and permissions.
|
| 772 |
+
|
| 773 |
+
:param exists: The file or directory needs to exist for the value to
|
| 774 |
+
be valid. If this is not set to ``True``, and the file does not
|
| 775 |
+
exist, then all further checks are silently skipped.
|
| 776 |
+
:param file_okay: Allow a file as a value.
|
| 777 |
+
:param dir_okay: Allow a directory as a value.
|
| 778 |
+
:param readable: if true, a readable check is performed.
|
| 779 |
+
:param writable: if true, a writable check is performed.
|
| 780 |
+
:param executable: if true, an executable check is performed.
|
| 781 |
+
:param resolve_path: Make the value absolute and resolve any
|
| 782 |
+
symlinks. A ``~`` is not expanded, as this is supposed to be
|
| 783 |
+
done by the shell only.
|
| 784 |
+
:param allow_dash: Allow a single dash as a value, which indicates
|
| 785 |
+
a standard stream (but does not open it). Use
|
| 786 |
+
:func:`~click.open_file` to handle opening this value.
|
| 787 |
+
:param path_type: Convert the incoming path value to this type. If
|
| 788 |
+
``None``, keep Python's default, which is ``str``. Useful to
|
| 789 |
+
convert to :class:`pathlib.Path`.
|
| 790 |
+
|
| 791 |
+
.. versionchanged:: 8.1
|
| 792 |
+
Added the ``executable`` parameter.
|
| 793 |
+
|
| 794 |
+
.. versionchanged:: 8.0
|
| 795 |
+
Allow passing ``path_type=pathlib.Path``.
|
| 796 |
+
|
| 797 |
+
.. versionchanged:: 6.0
|
| 798 |
+
Added the ``allow_dash`` parameter.
|
| 799 |
+
"""
|
| 800 |
+
|
| 801 |
+
envvar_list_splitter: t.ClassVar[str] = os.path.pathsep
|
| 802 |
+
|
| 803 |
+
def __init__(
|
| 804 |
+
self,
|
| 805 |
+
exists: bool = False,
|
| 806 |
+
file_okay: bool = True,
|
| 807 |
+
dir_okay: bool = True,
|
| 808 |
+
writable: bool = False,
|
| 809 |
+
readable: bool = True,
|
| 810 |
+
resolve_path: bool = False,
|
| 811 |
+
allow_dash: bool = False,
|
| 812 |
+
path_type: t.Optional[t.Type[t.Any]] = None,
|
| 813 |
+
executable: bool = False,
|
| 814 |
+
):
|
| 815 |
+
self.exists = exists
|
| 816 |
+
self.file_okay = file_okay
|
| 817 |
+
self.dir_okay = dir_okay
|
| 818 |
+
self.readable = readable
|
| 819 |
+
self.writable = writable
|
| 820 |
+
self.executable = executable
|
| 821 |
+
self.resolve_path = resolve_path
|
| 822 |
+
self.allow_dash = allow_dash
|
| 823 |
+
self.type = path_type
|
| 824 |
+
|
| 825 |
+
if self.file_okay and not self.dir_okay:
|
| 826 |
+
self.name: str = _("file")
|
| 827 |
+
elif self.dir_okay and not self.file_okay:
|
| 828 |
+
self.name = _("directory")
|
| 829 |
+
else:
|
| 830 |
+
self.name = _("path")
|
| 831 |
+
|
| 832 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 833 |
+
info_dict = super().to_info_dict()
|
| 834 |
+
info_dict.update(
|
| 835 |
+
exists=self.exists,
|
| 836 |
+
file_okay=self.file_okay,
|
| 837 |
+
dir_okay=self.dir_okay,
|
| 838 |
+
writable=self.writable,
|
| 839 |
+
readable=self.readable,
|
| 840 |
+
allow_dash=self.allow_dash,
|
| 841 |
+
)
|
| 842 |
+
return info_dict
|
| 843 |
+
|
| 844 |
+
def coerce_path_result(
|
| 845 |
+
self, value: "t.Union[str, os.PathLike[str]]"
|
| 846 |
+
) -> "t.Union[str, bytes, os.PathLike[str]]":
|
| 847 |
+
if self.type is not None and not isinstance(value, self.type):
|
| 848 |
+
if self.type is str:
|
| 849 |
+
return os.fsdecode(value)
|
| 850 |
+
elif self.type is bytes:
|
| 851 |
+
return os.fsencode(value)
|
| 852 |
+
else:
|
| 853 |
+
return t.cast("os.PathLike[str]", self.type(value))
|
| 854 |
+
|
| 855 |
+
return value
|
| 856 |
+
|
| 857 |
+
def convert(
|
| 858 |
+
self,
|
| 859 |
+
value: "t.Union[str, os.PathLike[str]]",
|
| 860 |
+
param: t.Optional["Parameter"],
|
| 861 |
+
ctx: t.Optional["Context"],
|
| 862 |
+
) -> "t.Union[str, bytes, os.PathLike[str]]":
|
| 863 |
+
rv = value
|
| 864 |
+
|
| 865 |
+
is_dash = self.file_okay and self.allow_dash and rv in (b"-", "-")
|
| 866 |
+
|
| 867 |
+
if not is_dash:
|
| 868 |
+
if self.resolve_path:
|
| 869 |
+
# os.path.realpath doesn't resolve symlinks on Windows
|
| 870 |
+
# until Python 3.8. Use pathlib for now.
|
| 871 |
+
import pathlib
|
| 872 |
+
|
| 873 |
+
rv = os.fsdecode(pathlib.Path(rv).resolve())
|
| 874 |
+
|
| 875 |
+
try:
|
| 876 |
+
st = os.stat(rv)
|
| 877 |
+
except OSError:
|
| 878 |
+
if not self.exists:
|
| 879 |
+
return self.coerce_path_result(rv)
|
| 880 |
+
self.fail(
|
| 881 |
+
_("{name} {filename!r} does not exist.").format(
|
| 882 |
+
name=self.name.title(), filename=format_filename(value)
|
| 883 |
+
),
|
| 884 |
+
param,
|
| 885 |
+
ctx,
|
| 886 |
+
)
|
| 887 |
+
|
| 888 |
+
if not self.file_okay and stat.S_ISREG(st.st_mode):
|
| 889 |
+
self.fail(
|
| 890 |
+
_("{name} {filename!r} is a file.").format(
|
| 891 |
+
name=self.name.title(), filename=format_filename(value)
|
| 892 |
+
),
|
| 893 |
+
param,
|
| 894 |
+
ctx,
|
| 895 |
+
)
|
| 896 |
+
if not self.dir_okay and stat.S_ISDIR(st.st_mode):
|
| 897 |
+
self.fail(
|
| 898 |
+
_("{name} {filename!r} is a directory.").format(
|
| 899 |
+
name=self.name.title(), filename=format_filename(value)
|
| 900 |
+
),
|
| 901 |
+
param,
|
| 902 |
+
ctx,
|
| 903 |
+
)
|
| 904 |
+
|
| 905 |
+
if self.readable and not os.access(rv, os.R_OK):
|
| 906 |
+
self.fail(
|
| 907 |
+
_("{name} {filename!r} is not readable.").format(
|
| 908 |
+
name=self.name.title(), filename=format_filename(value)
|
| 909 |
+
),
|
| 910 |
+
param,
|
| 911 |
+
ctx,
|
| 912 |
+
)
|
| 913 |
+
|
| 914 |
+
if self.writable and not os.access(rv, os.W_OK):
|
| 915 |
+
self.fail(
|
| 916 |
+
_("{name} {filename!r} is not writable.").format(
|
| 917 |
+
name=self.name.title(), filename=format_filename(value)
|
| 918 |
+
),
|
| 919 |
+
param,
|
| 920 |
+
ctx,
|
| 921 |
+
)
|
| 922 |
+
|
| 923 |
+
if self.executable and not os.access(value, os.X_OK):
|
| 924 |
+
self.fail(
|
| 925 |
+
_("{name} {filename!r} is not executable.").format(
|
| 926 |
+
name=self.name.title(), filename=format_filename(value)
|
| 927 |
+
),
|
| 928 |
+
param,
|
| 929 |
+
ctx,
|
| 930 |
+
)
|
| 931 |
+
|
| 932 |
+
return self.coerce_path_result(rv)
|
| 933 |
+
|
| 934 |
+
def shell_complete(
|
| 935 |
+
self, ctx: "Context", param: "Parameter", incomplete: str
|
| 936 |
+
) -> t.List["CompletionItem"]:
|
| 937 |
+
"""Return a special completion marker that tells the completion
|
| 938 |
+
system to use the shell to provide path completions for only
|
| 939 |
+
directories or any paths.
|
| 940 |
+
|
| 941 |
+
:param ctx: Invocation context for this command.
|
| 942 |
+
:param param: The parameter that is requesting completion.
|
| 943 |
+
:param incomplete: Value being completed. May be empty.
|
| 944 |
+
|
| 945 |
+
.. versionadded:: 8.0
|
| 946 |
+
"""
|
| 947 |
+
from click.shell_completion import CompletionItem
|
| 948 |
+
|
| 949 |
+
type = "dir" if self.dir_okay and not self.file_okay else "file"
|
| 950 |
+
return [CompletionItem(incomplete, type=type)]
|
| 951 |
+
|
| 952 |
+
|
| 953 |
+
class Tuple(CompositeParamType):
|
| 954 |
+
"""The default behavior of Click is to apply a type on a value directly.
|
| 955 |
+
This works well in most cases, except for when `nargs` is set to a fixed
|
| 956 |
+
count and different types should be used for different items. In this
|
| 957 |
+
case the :class:`Tuple` type can be used. This type can only be used
|
| 958 |
+
if `nargs` is set to a fixed number.
|
| 959 |
+
|
| 960 |
+
For more information see :ref:`tuple-type`.
|
| 961 |
+
|
| 962 |
+
This can be selected by using a Python tuple literal as a type.
|
| 963 |
+
|
| 964 |
+
:param types: a list of types that should be used for the tuple items.
|
| 965 |
+
"""
|
| 966 |
+
|
| 967 |
+
def __init__(self, types: t.Sequence[t.Union[t.Type[t.Any], ParamType]]) -> None:
|
| 968 |
+
self.types: t.Sequence[ParamType] = [convert_type(ty) for ty in types]
|
| 969 |
+
|
| 970 |
+
def to_info_dict(self) -> t.Dict[str, t.Any]:
|
| 971 |
+
info_dict = super().to_info_dict()
|
| 972 |
+
info_dict["types"] = [t.to_info_dict() for t in self.types]
|
| 973 |
+
return info_dict
|
| 974 |
+
|
| 975 |
+
@property
|
| 976 |
+
def name(self) -> str: # type: ignore
|
| 977 |
+
return f"<{' '.join(ty.name for ty in self.types)}>"
|
| 978 |
+
|
| 979 |
+
@property
|
| 980 |
+
def arity(self) -> int: # type: ignore
|
| 981 |
+
return len(self.types)
|
| 982 |
+
|
| 983 |
+
def convert(
|
| 984 |
+
self, value: t.Any, param: t.Optional["Parameter"], ctx: t.Optional["Context"]
|
| 985 |
+
) -> t.Any:
|
| 986 |
+
len_type = len(self.types)
|
| 987 |
+
len_value = len(value)
|
| 988 |
+
|
| 989 |
+
if len_value != len_type:
|
| 990 |
+
self.fail(
|
| 991 |
+
ngettext(
|
| 992 |
+
"{len_type} values are required, but {len_value} was given.",
|
| 993 |
+
"{len_type} values are required, but {len_value} were given.",
|
| 994 |
+
len_value,
|
| 995 |
+
).format(len_type=len_type, len_value=len_value),
|
| 996 |
+
param=param,
|
| 997 |
+
ctx=ctx,
|
| 998 |
+
)
|
| 999 |
+
|
| 1000 |
+
return tuple(ty(x, param, ctx) for ty, x in zip(self.types, value))
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
def convert_type(ty: t.Optional[t.Any], default: t.Optional[t.Any] = None) -> ParamType:
|
| 1004 |
+
"""Find the most appropriate :class:`ParamType` for the given Python
|
| 1005 |
+
type. If the type isn't provided, it can be inferred from a default
|
| 1006 |
+
value.
|
| 1007 |
+
"""
|
| 1008 |
+
guessed_type = False
|
| 1009 |
+
|
| 1010 |
+
if ty is None and default is not None:
|
| 1011 |
+
if isinstance(default, (tuple, list)):
|
| 1012 |
+
# If the default is empty, ty will remain None and will
|
| 1013 |
+
# return STRING.
|
| 1014 |
+
if default:
|
| 1015 |
+
item = default[0]
|
| 1016 |
+
|
| 1017 |
+
# A tuple of tuples needs to detect the inner types.
|
| 1018 |
+
# Can't call convert recursively because that would
|
| 1019 |
+
# incorrectly unwind the tuple to a single type.
|
| 1020 |
+
if isinstance(item, (tuple, list)):
|
| 1021 |
+
ty = tuple(map(type, item))
|
| 1022 |
+
else:
|
| 1023 |
+
ty = type(item)
|
| 1024 |
+
else:
|
| 1025 |
+
ty = type(default)
|
| 1026 |
+
|
| 1027 |
+
guessed_type = True
|
| 1028 |
+
|
| 1029 |
+
if isinstance(ty, tuple):
|
| 1030 |
+
return Tuple(ty)
|
| 1031 |
+
|
| 1032 |
+
if isinstance(ty, ParamType):
|
| 1033 |
+
return ty
|
| 1034 |
+
|
| 1035 |
+
if ty is str or ty is None:
|
| 1036 |
+
return STRING
|
| 1037 |
+
|
| 1038 |
+
if ty is int:
|
| 1039 |
+
return INT
|
| 1040 |
+
|
| 1041 |
+
if ty is float:
|
| 1042 |
+
return FLOAT
|
| 1043 |
+
|
| 1044 |
+
if ty is bool:
|
| 1045 |
+
return BOOL
|
| 1046 |
+
|
| 1047 |
+
if guessed_type:
|
| 1048 |
+
return STRING
|
| 1049 |
+
|
| 1050 |
+
if __debug__:
|
| 1051 |
+
try:
|
| 1052 |
+
if issubclass(ty, ParamType):
|
| 1053 |
+
raise AssertionError(
|
| 1054 |
+
f"Attempted to use an uninstantiated parameter type ({ty})."
|
| 1055 |
+
)
|
| 1056 |
+
except TypeError:
|
| 1057 |
+
# ty is an instance (correct), so issubclass fails.
|
| 1058 |
+
pass
|
| 1059 |
+
|
| 1060 |
+
return FuncParamType(ty)
|
| 1061 |
+
|
| 1062 |
+
|
| 1063 |
+
#: A dummy parameter type that just does nothing. From a user's
|
| 1064 |
+
#: perspective this appears to just be the same as `STRING` but
|
| 1065 |
+
#: internally no string conversion takes place if the input was bytes.
|
| 1066 |
+
#: This is usually useful when working with file paths as they can
|
| 1067 |
+
#: appear in bytes and unicode.
|
| 1068 |
+
#:
|
| 1069 |
+
#: For path related uses the :class:`Path` type is a better choice but
|
| 1070 |
+
#: there are situations where an unprocessed type is useful which is why
|
| 1071 |
+
#: it is is provided.
|
| 1072 |
+
#:
|
| 1073 |
+
#: .. versionadded:: 4.0
|
| 1074 |
+
UNPROCESSED = UnprocessedParamType()
|
| 1075 |
+
|
| 1076 |
+
#: A unicode string parameter type which is the implicit default. This
|
| 1077 |
+
#: can also be selected by using ``str`` as type.
|
| 1078 |
+
STRING = StringParamType()
|
| 1079 |
+
|
| 1080 |
+
#: An integer parameter. This can also be selected by using ``int`` as
|
| 1081 |
+
#: type.
|
| 1082 |
+
INT = IntParamType()
|
| 1083 |
+
|
| 1084 |
+
#: A floating point value parameter. This can also be selected by using
|
| 1085 |
+
#: ``float`` as type.
|
| 1086 |
+
FLOAT = FloatParamType()
|
| 1087 |
+
|
| 1088 |
+
#: A boolean parameter. This is the default for boolean flags. This can
|
| 1089 |
+
#: also be selected by using ``bool`` as a type.
|
| 1090 |
+
BOOL = BoolParamType()
|
| 1091 |
+
|
| 1092 |
+
#: A UUID parameter.
|
| 1093 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import sys
|
| 4 |
+
import typing as t
|
| 5 |
+
from functools import update_wrapper
|
| 6 |
+
from types import ModuleType
|
| 7 |
+
from types import TracebackType
|
| 8 |
+
|
| 9 |
+
from ._compat import _default_text_stderr
|
| 10 |
+
from ._compat import _default_text_stdout
|
| 11 |
+
from ._compat import _find_binary_writer
|
| 12 |
+
from ._compat import auto_wrap_for_ansi
|
| 13 |
+
from ._compat import binary_streams
|
| 14 |
+
from ._compat import open_stream
|
| 15 |
+
from ._compat import should_strip_ansi
|
| 16 |
+
from ._compat import strip_ansi
|
| 17 |
+
from ._compat import text_streams
|
| 18 |
+
from ._compat import WIN
|
| 19 |
+
from .globals import resolve_color_default
|
| 20 |
+
|
| 21 |
+
if t.TYPE_CHECKING:
|
| 22 |
+
import typing_extensions as te
|
| 23 |
+
|
| 24 |
+
P = te.ParamSpec("P")
|
| 25 |
+
|
| 26 |
+
R = t.TypeVar("R")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _posixify(name: str) -> str:
|
| 30 |
+
return "-".join(name.split()).lower()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def safecall(func: "t.Callable[P, R]") -> "t.Callable[P, t.Optional[R]]":
|
| 34 |
+
"""Wraps a function so that it swallows exceptions."""
|
| 35 |
+
|
| 36 |
+
def wrapper(*args: "P.args", **kwargs: "P.kwargs") -> t.Optional[R]:
|
| 37 |
+
try:
|
| 38 |
+
return func(*args, **kwargs)
|
| 39 |
+
except Exception:
|
| 40 |
+
pass
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
return update_wrapper(wrapper, func)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def make_str(value: t.Any) -> str:
|
| 47 |
+
"""Converts a value into a valid string."""
|
| 48 |
+
if isinstance(value, bytes):
|
| 49 |
+
try:
|
| 50 |
+
return value.decode(sys.getfilesystemencoding())
|
| 51 |
+
except UnicodeError:
|
| 52 |
+
return value.decode("utf-8", "replace")
|
| 53 |
+
return str(value)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def make_default_short_help(help: str, max_length: int = 45) -> str:
|
| 57 |
+
"""Returns a condensed version of help string."""
|
| 58 |
+
# Consider only the first paragraph.
|
| 59 |
+
paragraph_end = help.find("\n\n")
|
| 60 |
+
|
| 61 |
+
if paragraph_end != -1:
|
| 62 |
+
help = help[:paragraph_end]
|
| 63 |
+
|
| 64 |
+
# Collapse newlines, tabs, and spaces.
|
| 65 |
+
words = help.split()
|
| 66 |
+
|
| 67 |
+
if not words:
|
| 68 |
+
return ""
|
| 69 |
+
|
| 70 |
+
# The first paragraph started with a "no rewrap" marker, ignore it.
|
| 71 |
+
if words[0] == "\b":
|
| 72 |
+
words = words[1:]
|
| 73 |
+
|
| 74 |
+
total_length = 0
|
| 75 |
+
last_index = len(words) - 1
|
| 76 |
+
|
| 77 |
+
for i, word in enumerate(words):
|
| 78 |
+
total_length += len(word) + (i > 0)
|
| 79 |
+
|
| 80 |
+
if total_length > max_length: # too long, truncate
|
| 81 |
+
break
|
| 82 |
+
|
| 83 |
+
if word[-1] == ".": # sentence end, truncate without "..."
|
| 84 |
+
return " ".join(words[: i + 1])
|
| 85 |
+
|
| 86 |
+
if total_length == max_length and i != last_index:
|
| 87 |
+
break # not at sentence end, truncate with "..."
|
| 88 |
+
else:
|
| 89 |
+
return " ".join(words) # no truncation needed
|
| 90 |
+
|
| 91 |
+
# Account for the length of the suffix.
|
| 92 |
+
total_length += len("...")
|
| 93 |
+
|
| 94 |
+
# remove words until the length is short enough
|
| 95 |
+
while i > 0:
|
| 96 |
+
total_length -= len(words[i]) + (i > 0)
|
| 97 |
+
|
| 98 |
+
if total_length <= max_length:
|
| 99 |
+
break
|
| 100 |
+
|
| 101 |
+
i -= 1
|
| 102 |
+
|
| 103 |
+
return " ".join(words[:i]) + "..."
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class LazyFile:
|
| 107 |
+
"""A lazy file works like a regular file but it does not fully open
|
| 108 |
+
the file but it does perform some basic checks early to see if the
|
| 109 |
+
filename parameter does make sense. This is useful for safely opening
|
| 110 |
+
files for writing.
|
| 111 |
+
"""
|
| 112 |
+
|
| 113 |
+
def __init__(
|
| 114 |
+
self,
|
| 115 |
+
filename: t.Union[str, "os.PathLike[str]"],
|
| 116 |
+
mode: str = "r",
|
| 117 |
+
encoding: t.Optional[str] = None,
|
| 118 |
+
errors: t.Optional[str] = "strict",
|
| 119 |
+
atomic: bool = False,
|
| 120 |
+
):
|
| 121 |
+
self.name: str = os.fspath(filename)
|
| 122 |
+
self.mode = mode
|
| 123 |
+
self.encoding = encoding
|
| 124 |
+
self.errors = errors
|
| 125 |
+
self.atomic = atomic
|
| 126 |
+
self._f: t.Optional[t.IO[t.Any]]
|
| 127 |
+
self.should_close: bool
|
| 128 |
+
|
| 129 |
+
if self.name == "-":
|
| 130 |
+
self._f, self.should_close = open_stream(filename, mode, encoding, errors)
|
| 131 |
+
else:
|
| 132 |
+
if "r" in mode:
|
| 133 |
+
# Open and close the file in case we're opening it for
|
| 134 |
+
# reading so that we can catch at least some errors in
|
| 135 |
+
# some cases early.
|
| 136 |
+
open(filename, mode).close()
|
| 137 |
+
self._f = None
|
| 138 |
+
self.should_close = True
|
| 139 |
+
|
| 140 |
+
def __getattr__(self, name: str) -> t.Any:
|
| 141 |
+
return getattr(self.open(), name)
|
| 142 |
+
|
| 143 |
+
def __repr__(self) -> str:
|
| 144 |
+
if self._f is not None:
|
| 145 |
+
return repr(self._f)
|
| 146 |
+
return f"<unopened file '{format_filename(self.name)}' {self.mode}>"
|
| 147 |
+
|
| 148 |
+
def open(self) -> t.IO[t.Any]:
|
| 149 |
+
"""Opens the file if it's not yet open. This call might fail with
|
| 150 |
+
a :exc:`FileError`. Not handling this error will produce an error
|
| 151 |
+
that Click shows.
|
| 152 |
+
"""
|
| 153 |
+
if self._f is not None:
|
| 154 |
+
return self._f
|
| 155 |
+
try:
|
| 156 |
+
rv, self.should_close = open_stream(
|
| 157 |
+
self.name, self.mode, self.encoding, self.errors, atomic=self.atomic
|
| 158 |
+
)
|
| 159 |
+
except OSError as e:
|
| 160 |
+
from .exceptions import FileError
|
| 161 |
+
|
| 162 |
+
raise FileError(self.name, hint=e.strerror) from e
|
| 163 |
+
self._f = rv
|
| 164 |
+
return rv
|
| 165 |
+
|
| 166 |
+
def close(self) -> None:
|
| 167 |
+
"""Closes the underlying file, no matter what."""
|
| 168 |
+
if self._f is not None:
|
| 169 |
+
self._f.close()
|
| 170 |
+
|
| 171 |
+
def close_intelligently(self) -> None:
|
| 172 |
+
"""This function only closes the file if it was opened by the lazy
|
| 173 |
+
file wrapper. For instance this will never close stdin.
|
| 174 |
+
"""
|
| 175 |
+
if self.should_close:
|
| 176 |
+
self.close()
|
| 177 |
+
|
| 178 |
+
def __enter__(self) -> "LazyFile":
|
| 179 |
+
return self
|
| 180 |
+
|
| 181 |
+
def __exit__(
|
| 182 |
+
self,
|
| 183 |
+
exc_type: t.Optional[t.Type[BaseException]],
|
| 184 |
+
exc_value: t.Optional[BaseException],
|
| 185 |
+
tb: t.Optional[TracebackType],
|
| 186 |
+
) -> None:
|
| 187 |
+
self.close_intelligently()
|
| 188 |
+
|
| 189 |
+
def __iter__(self) -> t.Iterator[t.AnyStr]:
|
| 190 |
+
self.open()
|
| 191 |
+
return iter(self._f) # type: ignore
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
class KeepOpenFile:
|
| 195 |
+
def __init__(self, file: t.IO[t.Any]) -> None:
|
| 196 |
+
self._file: t.IO[t.Any] = file
|
| 197 |
+
|
| 198 |
+
def __getattr__(self, name: str) -> t.Any:
|
| 199 |
+
return getattr(self._file, name)
|
| 200 |
+
|
| 201 |
+
def __enter__(self) -> "KeepOpenFile":
|
| 202 |
+
return self
|
| 203 |
+
|
| 204 |
+
def __exit__(
|
| 205 |
+
self,
|
| 206 |
+
exc_type: t.Optional[t.Type[BaseException]],
|
| 207 |
+
exc_value: t.Optional[BaseException],
|
| 208 |
+
tb: t.Optional[TracebackType],
|
| 209 |
+
) -> None:
|
| 210 |
+
pass
|
| 211 |
+
|
| 212 |
+
def __repr__(self) -> str:
|
| 213 |
+
return repr(self._file)
|
| 214 |
+
|
| 215 |
+
def __iter__(self) -> t.Iterator[t.AnyStr]:
|
| 216 |
+
return iter(self._file)
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def echo(
|
| 220 |
+
message: t.Optional[t.Any] = None,
|
| 221 |
+
file: t.Optional[t.IO[t.Any]] = None,
|
| 222 |
+
nl: bool = True,
|
| 223 |
+
err: bool = False,
|
| 224 |
+
color: t.Optional[bool] = None,
|
| 225 |
+
) -> None:
|
| 226 |
+
"""Print a message and newline to stdout or a file. This should be
|
| 227 |
+
used instead of :func:`print` because it provides better support
|
| 228 |
+
for different data, files, and environments.
|
| 229 |
+
|
| 230 |
+
Compared to :func:`print`, this does the following:
|
| 231 |
+
|
| 232 |
+
- Ensures that the output encoding is not misconfigured on Linux.
|
| 233 |
+
- Supports Unicode in the Windows console.
|
| 234 |
+
- Supports writing to binary outputs, and supports writing bytes
|
| 235 |
+
to text outputs.
|
| 236 |
+
- Supports colors and styles on Windows.
|
| 237 |
+
- Removes ANSI color and style codes if the output does not look
|
| 238 |
+
like an interactive terminal.
|
| 239 |
+
- Always flushes the output.
|
| 240 |
+
|
| 241 |
+
:param message: The string or bytes to output. Other objects are
|
| 242 |
+
converted to strings.
|
| 243 |
+
:param file: The file to write to. Defaults to ``stdout``.
|
| 244 |
+
:param err: Write to ``stderr`` instead of ``stdout``.
|
| 245 |
+
:param nl: Print a newline after the message. Enabled by default.
|
| 246 |
+
:param color: Force showing or hiding colors and other styles. By
|
| 247 |
+
default Click will remove color if the output does not look like
|
| 248 |
+
an interactive terminal.
|
| 249 |
+
|
| 250 |
+
.. versionchanged:: 6.0
|
| 251 |
+
Support Unicode output on the Windows console. Click does not
|
| 252 |
+
modify ``sys.stdout``, so ``sys.stdout.write()`` and ``print()``
|
| 253 |
+
will still not support Unicode.
|
| 254 |
+
|
| 255 |
+
.. versionchanged:: 4.0
|
| 256 |
+
Added the ``color`` parameter.
|
| 257 |
+
|
| 258 |
+
.. versionadded:: 3.0
|
| 259 |
+
Added the ``err`` parameter.
|
| 260 |
+
|
| 261 |
+
.. versionchanged:: 2.0
|
| 262 |
+
Support colors on Windows if colorama is installed.
|
| 263 |
+
"""
|
| 264 |
+
if file is None:
|
| 265 |
+
if err:
|
| 266 |
+
file = _default_text_stderr()
|
| 267 |
+
else:
|
| 268 |
+
file = _default_text_stdout()
|
| 269 |
+
|
| 270 |
+
# There are no standard streams attached to write to. For example,
|
| 271 |
+
# pythonw on Windows.
|
| 272 |
+
if file is None:
|
| 273 |
+
return
|
| 274 |
+
|
| 275 |
+
# Convert non bytes/text into the native string type.
|
| 276 |
+
if message is not None and not isinstance(message, (str, bytes, bytearray)):
|
| 277 |
+
out: t.Optional[t.Union[str, bytes]] = str(message)
|
| 278 |
+
else:
|
| 279 |
+
out = message
|
| 280 |
+
|
| 281 |
+
if nl:
|
| 282 |
+
out = out or ""
|
| 283 |
+
if isinstance(out, str):
|
| 284 |
+
out += "\n"
|
| 285 |
+
else:
|
| 286 |
+
out += b"\n"
|
| 287 |
+
|
| 288 |
+
if not out:
|
| 289 |
+
file.flush()
|
| 290 |
+
return
|
| 291 |
+
|
| 292 |
+
# If there is a message and the value looks like bytes, we manually
|
| 293 |
+
# need to find the binary stream and write the message in there.
|
| 294 |
+
# This is done separately so that most stream types will work as you
|
| 295 |
+
# would expect. Eg: you can write to StringIO for other cases.
|
| 296 |
+
if isinstance(out, (bytes, bytearray)):
|
| 297 |
+
binary_file = _find_binary_writer(file)
|
| 298 |
+
|
| 299 |
+
if binary_file is not None:
|
| 300 |
+
file.flush()
|
| 301 |
+
binary_file.write(out)
|
| 302 |
+
binary_file.flush()
|
| 303 |
+
return
|
| 304 |
+
|
| 305 |
+
# ANSI style code support. For no message or bytes, nothing happens.
|
| 306 |
+
# When outputting to a file instead of a terminal, strip codes.
|
| 307 |
+
else:
|
| 308 |
+
color = resolve_color_default(color)
|
| 309 |
+
|
| 310 |
+
if should_strip_ansi(file, color):
|
| 311 |
+
out = strip_ansi(out)
|
| 312 |
+
elif WIN:
|
| 313 |
+
if auto_wrap_for_ansi is not None:
|
| 314 |
+
file = auto_wrap_for_ansi(file, color) # type: ignore
|
| 315 |
+
elif not color:
|
| 316 |
+
out = strip_ansi(out)
|
| 317 |
+
|
| 318 |
+
file.write(out) # type: ignore
|
| 319 |
+
file.flush()
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def get_binary_stream(name: "te.Literal['stdin', 'stdout', 'stderr']") -> t.BinaryIO:
|
| 323 |
+
"""Returns a system stream for byte processing.
|
| 324 |
+
|
| 325 |
+
:param name: the name of the stream to open. Valid names are ``'stdin'``,
|
| 326 |
+
``'stdout'`` and ``'stderr'``
|
| 327 |
+
"""
|
| 328 |
+
opener = binary_streams.get(name)
|
| 329 |
+
if opener is None:
|
| 330 |
+
raise TypeError(f"Unknown standard stream '{name}'")
|
| 331 |
+
return opener()
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
def get_text_stream(
|
| 335 |
+
name: "te.Literal['stdin', 'stdout', 'stderr']",
|
| 336 |
+
encoding: t.Optional[str] = None,
|
| 337 |
+
errors: t.Optional[str] = "strict",
|
| 338 |
+
) -> t.TextIO:
|
| 339 |
+
"""Returns a system stream for text processing. This usually returns
|
| 340 |
+
a wrapped stream around a binary stream returned from
|
| 341 |
+
:func:`get_binary_stream` but it also can take shortcuts for already
|
| 342 |
+
correctly configured streams.
|
| 343 |
+
|
| 344 |
+
:param name: the name of the stream to open. Valid names are ``'stdin'``,
|
| 345 |
+
``'stdout'`` and ``'stderr'``
|
| 346 |
+
:param encoding: overrides the detected default encoding.
|
| 347 |
+
:param errors: overrides the default error mode.
|
| 348 |
+
"""
|
| 349 |
+
opener = text_streams.get(name)
|
| 350 |
+
if opener is None:
|
| 351 |
+
raise TypeError(f"Unknown standard stream '{name}'")
|
| 352 |
+
return opener(encoding, errors)
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def open_file(
|
| 356 |
+
filename: t.Union[str, "os.PathLike[str]"],
|
| 357 |
+
mode: str = "r",
|
| 358 |
+
encoding: t.Optional[str] = None,
|
| 359 |
+
errors: t.Optional[str] = "strict",
|
| 360 |
+
lazy: bool = False,
|
| 361 |
+
atomic: bool = False,
|
| 362 |
+
) -> t.IO[t.Any]:
|
| 363 |
+
"""Open a file, with extra behavior to handle ``'-'`` to indicate
|
| 364 |
+
a standard stream, lazy open on write, and atomic write. Similar to
|
| 365 |
+
the behavior of the :class:`~click.File` param type.
|
| 366 |
+
|
| 367 |
+
If ``'-'`` is given to open ``stdout`` or ``stdin``, the stream is
|
| 368 |
+
wrapped so that using it in a context manager will not close it.
|
| 369 |
+
This makes it possible to use the function without accidentally
|
| 370 |
+
closing a standard stream:
|
| 371 |
+
|
| 372 |
+
.. code-block:: python
|
| 373 |
+
|
| 374 |
+
with open_file(filename) as f:
|
| 375 |
+
...
|
| 376 |
+
|
| 377 |
+
:param filename: The name or Path of the file to open, or ``'-'`` for
|
| 378 |
+
``stdin``/``stdout``.
|
| 379 |
+
:param mode: The mode in which to open the file.
|
| 380 |
+
:param encoding: The encoding to decode or encode a file opened in
|
| 381 |
+
text mode.
|
| 382 |
+
:param errors: The error handling mode.
|
| 383 |
+
:param lazy: Wait to open the file until it is accessed. For read
|
| 384 |
+
mode, the file is temporarily opened to raise access errors
|
| 385 |
+
early, then closed until it is read again.
|
| 386 |
+
:param atomic: Write to a temporary file and replace the given file
|
| 387 |
+
on close.
|
| 388 |
+
|
| 389 |
+
.. versionadded:: 3.0
|
| 390 |
+
"""
|
| 391 |
+
if lazy:
|
| 392 |
+
return t.cast(
|
| 393 |
+
t.IO[t.Any], LazyFile(filename, mode, encoding, errors, atomic=atomic)
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
f, should_close = open_stream(filename, mode, encoding, errors, atomic=atomic)
|
| 397 |
+
|
| 398 |
+
if not should_close:
|
| 399 |
+
f = t.cast(t.IO[t.Any], KeepOpenFile(f))
|
| 400 |
+
|
| 401 |
+
return f
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
def format_filename(
|
| 405 |
+
filename: "t.Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]",
|
| 406 |
+
shorten: bool = False,
|
| 407 |
+
) -> str:
|
| 408 |
+
"""Format a filename as a string for display. Ensures the filename can be
|
| 409 |
+
displayed by replacing any invalid bytes or surrogate escapes in the name
|
| 410 |
+
with the replacement character ``�``.
|
| 411 |
+
|
| 412 |
+
Invalid bytes or surrogate escapes will raise an error when written to a
|
| 413 |
+
stream with ``errors="strict"``. This will typically happen with ``stdout``
|
| 414 |
+
when the locale is something like ``en_GB.UTF-8``.
|
| 415 |
+
|
| 416 |
+
Many scenarios *are* safe to write surrogates though, due to PEP 538 and
|
| 417 |
+
PEP 540, including:
|
| 418 |
+
|
| 419 |
+
- Writing to ``stderr``, which uses ``errors="backslashreplace"``.
|
| 420 |
+
- The system has ``LANG=C.UTF-8``, ``C``, or ``POSIX``. Python opens
|
| 421 |
+
stdout and stderr with ``errors="surrogateescape"``.
|
| 422 |
+
- None of ``LANG/LC_*`` are set. Python assumes ``LANG=C.UTF-8``.
|
| 423 |
+
- Python is started in UTF-8 mode with ``PYTHONUTF8=1`` or ``-X utf8``.
|
| 424 |
+
Python opens stdout and stderr with ``errors="surrogateescape"``.
|
| 425 |
+
|
| 426 |
+
:param filename: formats a filename for UI display. This will also convert
|
| 427 |
+
the filename into unicode without failing.
|
| 428 |
+
:param shorten: this optionally shortens the filename to strip of the
|
| 429 |
+
path that leads up to it.
|
| 430 |
+
"""
|
| 431 |
+
if shorten:
|
| 432 |
+
filename = os.path.basename(filename)
|
| 433 |
+
else:
|
| 434 |
+
filename = os.fspath(filename)
|
| 435 |
+
|
| 436 |
+
if isinstance(filename, bytes):
|
| 437 |
+
filename = filename.decode(sys.getfilesystemencoding(), "replace")
|
| 438 |
+
else:
|
| 439 |
+
filename = filename.encode("utf-8", "surrogateescape").decode(
|
| 440 |
+
"utf-8", "replace"
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
return filename
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
def get_app_dir(app_name: str, roaming: bool = True, force_posix: bool = False) -> str:
|
| 447 |
+
r"""Returns the config folder for the application. The default behavior
|
| 448 |
+
is to return whatever is most appropriate for the operating system.
|
| 449 |
+
|
| 450 |
+
To give you an idea, for an app called ``"Foo Bar"``, something like
|
| 451 |
+
the following folders could be returned:
|
| 452 |
+
|
| 453 |
+
Mac OS X:
|
| 454 |
+
``~/Library/Application Support/Foo Bar``
|
| 455 |
+
Mac OS X (POSIX):
|
| 456 |
+
``~/.foo-bar``
|
| 457 |
+
Unix:
|
| 458 |
+
``~/.config/foo-bar``
|
| 459 |
+
Unix (POSIX):
|
| 460 |
+
``~/.foo-bar``
|
| 461 |
+
Windows (roaming):
|
| 462 |
+
``C:\Users\<user>\AppData\Roaming\Foo Bar``
|
| 463 |
+
Windows (not roaming):
|
| 464 |
+
``C:\Users\<user>\AppData\Local\Foo Bar``
|
| 465 |
+
|
| 466 |
+
.. versionadded:: 2.0
|
| 467 |
+
|
| 468 |
+
:param app_name: the application name. This should be properly capitalized
|
| 469 |
+
and can contain whitespace.
|
| 470 |
+
:param roaming: controls if the folder should be roaming or not on Windows.
|
| 471 |
+
Has no effect otherwise.
|
| 472 |
+
:param force_posix: if this is set to `True` then on any POSIX system the
|
| 473 |
+
folder will be stored in the home folder with a leading
|
| 474 |
+
dot instead of the XDG config home or darwin's
|
| 475 |
+
application support folder.
|
| 476 |
+
"""
|
| 477 |
+
if WIN:
|
| 478 |
+
key = "APPDATA" if roaming else "LOCALAPPDATA"
|
| 479 |
+
folder = os.environ.get(key)
|
| 480 |
+
if folder is None:
|
| 481 |
+
folder = os.path.expanduser("~")
|
| 482 |
+
return os.path.join(folder, app_name)
|
| 483 |
+
if force_posix:
|
| 484 |
+
return os.path.join(os.path.expanduser(f"~/.{_posixify(app_name)}"))
|
| 485 |
+
if sys.platform == "darwin":
|
| 486 |
+
return os.path.join(
|
| 487 |
+
os.path.expanduser("~/Library/Application Support"), app_name
|
| 488 |
+
)
|
| 489 |
+
return os.path.join(
|
| 490 |
+
os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")),
|
| 491 |
+
_posixify(app_name),
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
class PacifyFlushWrapper:
|
| 496 |
+
"""This wrapper is used to catch and suppress BrokenPipeErrors resulting
|
| 497 |
+
from ``.flush()`` being called on broken pipe during the shutdown/final-GC
|
| 498 |
+
of the Python interpreter. Notably ``.flush()`` is always called on
|
| 499 |
+
``sys.stdout`` and ``sys.stderr``. So as to have minimal impact on any
|
| 500 |
+
other cleanup code, and the case where the underlying file is not a broken
|
| 501 |
+
pipe, all calls and attributes are proxied.
|
| 502 |
+
"""
|
| 503 |
+
|
| 504 |
+
def __init__(self, wrapped: t.IO[t.Any]) -> None:
|
| 505 |
+
self.wrapped = wrapped
|
| 506 |
+
|
| 507 |
+
def flush(self) -> None:
|
| 508 |
+
try:
|
| 509 |
+
self.wrapped.flush()
|
| 510 |
+
except OSError as e:
|
| 511 |
+
import errno
|
| 512 |
+
|
| 513 |
+
if e.errno != errno.EPIPE:
|
| 514 |
+
raise
|
| 515 |
+
|
| 516 |
+
def __getattr__(self, attr: str) -> t.Any:
|
| 517 |
+
return getattr(self.wrapped, attr)
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
def _detect_program_name(
|
| 521 |
+
path: t.Optional[str] = None, _main: t.Optional[ModuleType] = None
|
| 522 |
+
) -> str:
|
| 523 |
+
"""Determine the command used to run the program, for use in help
|
| 524 |
+
text. If a file or entry point was executed, the file name is
|
| 525 |
+
returned. If ``python -m`` was used to execute a module or package,
|
| 526 |
+
``python -m name`` is returned.
|
| 527 |
+
|
| 528 |
+
This doesn't try to be too precise, the goal is to give a concise
|
| 529 |
+
name for help text. Files are only shown as their name without the
|
| 530 |
+
path. ``python`` is only shown for modules, and the full path to
|
| 531 |
+
``sys.executable`` is not shown.
|
| 532 |
+
|
| 533 |
+
:param path: The Python file being executed. Python puts this in
|
| 534 |
+
``sys.argv[0]``, which is used by default.
|
| 535 |
+
:param _main: The ``__main__`` module. This should only be passed
|
| 536 |
+
during internal testing.
|
| 537 |
+
|
| 538 |
+
.. versionadded:: 8.0
|
| 539 |
+
Based on command args detection in the Werkzeug reloader.
|
| 540 |
+
|
| 541 |
+
:meta private:
|
| 542 |
+
"""
|
| 543 |
+
if _main is None:
|
| 544 |
+
_main = sys.modules["__main__"]
|
| 545 |
+
|
| 546 |
+
if not path:
|
| 547 |
+
path = sys.argv[0]
|
| 548 |
+
|
| 549 |
+
# The value of __package__ indicates how Python was called. It may
|
| 550 |
+
# not exist if a setuptools script is installed as an egg. It may be
|
| 551 |
+
# set incorrectly for entry points created with pip on Windows.
|
| 552 |
+
# It is set to "" inside a Shiv or PEX zipapp.
|
| 553 |
+
if getattr(_main, "__package__", None) in {None, ""} or (
|
| 554 |
+
os.name == "nt"
|
| 555 |
+
and _main.__package__ == ""
|
| 556 |
+
and not os.path.exists(path)
|
| 557 |
+
and os.path.exists(f"{path}.exe")
|
| 558 |
+
):
|
| 559 |
+
# Executed a file, like "python app.py".
|
| 560 |
+
return os.path.basename(path)
|
| 561 |
+
|
| 562 |
+
# Executed a module, like "python -m example".
|
| 563 |
+
# Rewritten by Python from "-m script" to "/path/to/script.py".
|
| 564 |
+
# Need to look at main module to determine how it was executed.
|
| 565 |
+
py_module = t.cast(str, _main.__package__)
|
| 566 |
+
name = os.path.splitext(os.path.basename(path))[0]
|
| 567 |
+
|
| 568 |
+
# A submodule like "example.cli".
|
| 569 |
+
if name != "__main__":
|
| 570 |
+
py_module = f"{py_module}.{name}"
|
| 571 |
+
|
| 572 |
+
return f"python -m {py_module.lstrip('.')}"
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
def _expand_args(
|
| 576 |
+
args: t.Iterable[str],
|
| 577 |
+
*,
|
| 578 |
+
user: bool = True,
|
| 579 |
+
env: bool = True,
|
| 580 |
+
glob_recursive: bool = True,
|
| 581 |
+
) -> t.List[str]:
|
| 582 |
+
"""Simulate Unix shell expansion with Python functions.
|
| 583 |
+
|
| 584 |
+
See :func:`glob.glob`, :func:`os.path.expanduser`, and
|
| 585 |
+
:func:`os.path.expandvars`.
|
| 586 |
+
|
| 587 |
+
This is intended for use on Windows, where the shell does not do any
|
| 588 |
+
expansion. It may not exactly match what a Unix shell would do.
|
| 589 |
+
|
| 590 |
+
:param args: List of command line arguments to expand.
|
| 591 |
+
:param user: Expand user home directory.
|
| 592 |
+
:param env: Expand environment variables.
|
| 593 |
+
:param glob_recursive: ``**`` matches directories recursively.
|
| 594 |
+
|
| 595 |
+
.. versionchanged:: 8.1
|
| 596 |
+
Invalid glob patterns are treated as empty expansions rather
|
| 597 |
+
than raising an error.
|
| 598 |
+
|
| 599 |
+
.. versionadded:: 8.0
|
| 600 |
+
|
| 601 |
+
:meta private:
|
| 602 |
+
"""
|
| 603 |
+
from glob import glob
|
| 604 |
+
|
| 605 |
+
out = []
|
| 606 |
+
|
| 607 |
+
for arg in args:
|
| 608 |
+
if user:
|
| 609 |
+
arg = os.path.expanduser(arg)
|
| 610 |
+
|
| 611 |
+
if env:
|
| 612 |
+
arg = os.path.expandvars(arg)
|
| 613 |
+
|
| 614 |
+
try:
|
| 615 |
+
matches = glob(arg, recursive=glob_recursive)
|
| 616 |
+
except re.error:
|
| 617 |
+
matches = []
|
| 618 |
+
|
| 619 |
+
if not matches:
|
| 620 |
+
out.append(arg)
|
| 621 |
+
else:
|
| 622 |
+
out.extend(matches)
|
| 623 |
+
|
| 624 |
+
return out
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
try:
|
| 5 |
+
from ._version import version as __version__
|
| 6 |
+
except ImportError:
|
| 7 |
+
__version__ = 'unknown'
|
| 8 |
+
|
| 9 |
+
__all__ = ['easter', 'parser', 'relativedelta', 'rrule', 'tz',
|
| 10 |
+
'utils', 'zoneinfo']
|
| 11 |
+
|
| 12 |
+
def __getattr__(name):
|
| 13 |
+
import importlib
|
| 14 |
+
|
| 15 |
+
if name in __all__:
|
| 16 |
+
return importlib.import_module("." + name, __name__)
|
| 17 |
+
raise AttributeError(
|
| 18 |
+
"module {!r} has not attribute {!r}".format(__name__, name)
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def __dir__():
|
| 23 |
+
# __dir__ should include all the lazy-importable modules as well.
|
| 24 |
+
return [x for x in globals() if x not in sys.modules] + __all__
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/_common.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Common code used in multiple modules.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class weekday(object):
|
| 7 |
+
__slots__ = ["weekday", "n"]
|
| 8 |
+
|
| 9 |
+
def __init__(self, weekday, n=None):
|
| 10 |
+
self.weekday = weekday
|
| 11 |
+
self.n = n
|
| 12 |
+
|
| 13 |
+
def __call__(self, n):
|
| 14 |
+
if n == self.n:
|
| 15 |
+
return self
|
| 16 |
+
else:
|
| 17 |
+
return self.__class__(self.weekday, n)
|
| 18 |
+
|
| 19 |
+
def __eq__(self, other):
|
| 20 |
+
try:
|
| 21 |
+
if self.weekday != other.weekday or self.n != other.n:
|
| 22 |
+
return False
|
| 23 |
+
except AttributeError:
|
| 24 |
+
return False
|
| 25 |
+
return True
|
| 26 |
+
|
| 27 |
+
def __hash__(self):
|
| 28 |
+
return hash((
|
| 29 |
+
self.weekday,
|
| 30 |
+
self.n,
|
| 31 |
+
))
|
| 32 |
+
|
| 33 |
+
def __ne__(self, other):
|
| 34 |
+
return not (self == other)
|
| 35 |
+
|
| 36 |
+
def __repr__(self):
|
| 37 |
+
s = ("MO", "TU", "WE", "TH", "FR", "SA", "SU")[self.weekday]
|
| 38 |
+
if not self.n:
|
| 39 |
+
return s
|
| 40 |
+
else:
|
| 41 |
+
return "%s(%+d)" % (s, self.n)
|
| 42 |
+
|
| 43 |
+
# vim:ts=4:sw=4:et
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/_version.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# file generated by setuptools_scm
|
| 2 |
+
# don't change, don't track in version control
|
| 3 |
+
__version__ = version = '2.9.0.post0'
|
| 4 |
+
__version_tuple__ = version_tuple = (2, 9, 0)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/easter.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
This module offers a generic Easter computing method for any given year, using
|
| 4 |
+
Western, Orthodox or Julian algorithms.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import datetime
|
| 8 |
+
|
| 9 |
+
__all__ = ["easter", "EASTER_JULIAN", "EASTER_ORTHODOX", "EASTER_WESTERN"]
|
| 10 |
+
|
| 11 |
+
EASTER_JULIAN = 1
|
| 12 |
+
EASTER_ORTHODOX = 2
|
| 13 |
+
EASTER_WESTERN = 3
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def easter(year, method=EASTER_WESTERN):
|
| 17 |
+
"""
|
| 18 |
+
This method was ported from the work done by GM Arts,
|
| 19 |
+
on top of the algorithm by Claus Tondering, which was
|
| 20 |
+
based in part on the algorithm of Ouding (1940), as
|
| 21 |
+
quoted in "Explanatory Supplement to the Astronomical
|
| 22 |
+
Almanac", P. Kenneth Seidelmann, editor.
|
| 23 |
+
|
| 24 |
+
This algorithm implements three different Easter
|
| 25 |
+
calculation methods:
|
| 26 |
+
|
| 27 |
+
1. Original calculation in Julian calendar, valid in
|
| 28 |
+
dates after 326 AD
|
| 29 |
+
2. Original method, with date converted to Gregorian
|
| 30 |
+
calendar, valid in years 1583 to 4099
|
| 31 |
+
3. Revised method, in Gregorian calendar, valid in
|
| 32 |
+
years 1583 to 4099 as well
|
| 33 |
+
|
| 34 |
+
These methods are represented by the constants:
|
| 35 |
+
|
| 36 |
+
* ``EASTER_JULIAN = 1``
|
| 37 |
+
* ``EASTER_ORTHODOX = 2``
|
| 38 |
+
* ``EASTER_WESTERN = 3``
|
| 39 |
+
|
| 40 |
+
The default method is method 3.
|
| 41 |
+
|
| 42 |
+
More about the algorithm may be found at:
|
| 43 |
+
|
| 44 |
+
`GM Arts: Easter Algorithms <http://www.gmarts.org/index.php?go=415>`_
|
| 45 |
+
|
| 46 |
+
and
|
| 47 |
+
|
| 48 |
+
`The Calendar FAQ: Easter <https://www.tondering.dk/claus/cal/easter.php>`_
|
| 49 |
+
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
if not (1 <= method <= 3):
|
| 53 |
+
raise ValueError("invalid method")
|
| 54 |
+
|
| 55 |
+
# g - Golden year - 1
|
| 56 |
+
# c - Century
|
| 57 |
+
# h - (23 - Epact) mod 30
|
| 58 |
+
# i - Number of days from March 21 to Paschal Full Moon
|
| 59 |
+
# j - Weekday for PFM (0=Sunday, etc)
|
| 60 |
+
# p - Number of days from March 21 to Sunday on or before PFM
|
| 61 |
+
# (-6 to 28 methods 1 & 3, to 56 for method 2)
|
| 62 |
+
# e - Extra days to add for method 2 (converting Julian
|
| 63 |
+
# date to Gregorian date)
|
| 64 |
+
|
| 65 |
+
y = year
|
| 66 |
+
g = y % 19
|
| 67 |
+
e = 0
|
| 68 |
+
if method < 3:
|
| 69 |
+
# Old method
|
| 70 |
+
i = (19*g + 15) % 30
|
| 71 |
+
j = (y + y//4 + i) % 7
|
| 72 |
+
if method == 2:
|
| 73 |
+
# Extra dates to convert Julian to Gregorian date
|
| 74 |
+
e = 10
|
| 75 |
+
if y > 1600:
|
| 76 |
+
e = e + y//100 - 16 - (y//100 - 16)//4
|
| 77 |
+
else:
|
| 78 |
+
# New method
|
| 79 |
+
c = y//100
|
| 80 |
+
h = (c - c//4 - (8*c + 13)//25 + 19*g + 15) % 30
|
| 81 |
+
i = h - (h//28)*(1 - (h//28)*(29//(h + 1))*((21 - g)//11))
|
| 82 |
+
j = (y + y//4 + i + 2 - c + c//4) % 7
|
| 83 |
+
|
| 84 |
+
# p can be from -6 to 56 corresponding to dates 22 March to 23 May
|
| 85 |
+
# (later dates apply to method 2, although 23 May never actually occurs)
|
| 86 |
+
p = i - j + e
|
| 87 |
+
d = 1 + (p + 27 + (p + 6)//40) % 31
|
| 88 |
+
m = 3 + (p + 26)//30
|
| 89 |
+
return datetime.date(int(y), int(m), int(d))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/dateutil/relativedelta.py
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
import datetime
|
| 3 |
+
import calendar
|
| 4 |
+
|
| 5 |
+
import operator
|
| 6 |
+
from math import copysign
|
| 7 |
+
|
| 8 |
+
from six import integer_types
|
| 9 |
+
from warnings import warn
|
| 10 |
+
|
| 11 |
+
from ._common import weekday
|
| 12 |
+
|
| 13 |
+
MO, TU, WE, TH, FR, SA, SU = weekdays = tuple(weekday(x) for x in range(7))
|
| 14 |
+
|
| 15 |
+
__all__ = ["relativedelta", "MO", "TU", "WE", "TH", "FR", "SA", "SU"]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class relativedelta(object):
|
| 19 |
+
"""
|
| 20 |
+
The relativedelta type is designed to be applied to an existing datetime and
|
| 21 |
+
can replace specific components of that datetime, or represents an interval
|
| 22 |
+
of time.
|
| 23 |
+
|
| 24 |
+
It is based on the specification of the excellent work done by M.-A. Lemburg
|
| 25 |
+
in his
|
| 26 |
+
`mx.DateTime <https://www.egenix.com/products/python/mxBase/mxDateTime/>`_ extension.
|
| 27 |
+
However, notice that this type does *NOT* implement the same algorithm as
|
| 28 |
+
his work. Do *NOT* expect it to behave like mx.DateTime's counterpart.
|
| 29 |
+
|
| 30 |
+
There are two different ways to build a relativedelta instance. The
|
| 31 |
+
first one is passing it two date/datetime classes::
|
| 32 |
+
|
| 33 |
+
relativedelta(datetime1, datetime2)
|
| 34 |
+
|
| 35 |
+
The second one is passing it any number of the following keyword arguments::
|
| 36 |
+
|
| 37 |
+
relativedelta(arg1=x,arg2=y,arg3=z...)
|
| 38 |
+
|
| 39 |
+
year, month, day, hour, minute, second, microsecond:
|
| 40 |
+
Absolute information (argument is singular); adding or subtracting a
|
| 41 |
+
relativedelta with absolute information does not perform an arithmetic
|
| 42 |
+
operation, but rather REPLACES the corresponding value in the
|
| 43 |
+
original datetime with the value(s) in relativedelta.
|
| 44 |
+
|
| 45 |
+
years, months, weeks, days, hours, minutes, seconds, microseconds:
|
| 46 |
+
Relative information, may be negative (argument is plural); adding
|
| 47 |
+
or subtracting a relativedelta with relative information performs
|
| 48 |
+
the corresponding arithmetic operation on the original datetime value
|
| 49 |
+
with the information in the relativedelta.
|
| 50 |
+
|
| 51 |
+
weekday:
|
| 52 |
+
One of the weekday instances (MO, TU, etc) available in the
|
| 53 |
+
relativedelta module. These instances may receive a parameter N,
|
| 54 |
+
specifying the Nth weekday, which could be positive or negative
|
| 55 |
+
(like MO(+1) or MO(-2)). Not specifying it is the same as specifying
|
| 56 |
+
+1. You can also use an integer, where 0=MO. This argument is always
|
| 57 |
+
relative e.g. if the calculated date is already Monday, using MO(1)
|
| 58 |
+
or MO(-1) won't change the day. To effectively make it absolute, use
|
| 59 |
+
it in combination with the day argument (e.g. day=1, MO(1) for first
|
| 60 |
+
Monday of the month).
|
| 61 |
+
|
| 62 |
+
leapdays:
|
| 63 |
+
Will add given days to the date found, if year is a leap
|
| 64 |
+
year, and the date found is post 28 of february.
|
| 65 |
+
|
| 66 |
+
yearday, nlyearday:
|
| 67 |
+
Set the yearday or the non-leap year day (jump leap days).
|
| 68 |
+
These are converted to day/month/leapdays information.
|
| 69 |
+
|
| 70 |
+
There are relative and absolute forms of the keyword
|
| 71 |
+
arguments. The plural is relative, and the singular is
|
| 72 |
+
absolute. For each argument in the order below, the absolute form
|
| 73 |
+
is applied first (by setting each attribute to that value) and
|
| 74 |
+
then the relative form (by adding the value to the attribute).
|
| 75 |
+
|
| 76 |
+
The order of attributes considered when this relativedelta is
|
| 77 |
+
added to a datetime is:
|
| 78 |
+
|
| 79 |
+
1. Year
|
| 80 |
+
2. Month
|
| 81 |
+
3. Day
|
| 82 |
+
4. Hours
|
| 83 |
+
5. Minutes
|
| 84 |
+
6. Seconds
|
| 85 |
+
7. Microseconds
|
| 86 |
+
|
| 87 |
+
Finally, weekday is applied, using the rule described above.
|
| 88 |
+
|
| 89 |
+
For example
|
| 90 |
+
|
| 91 |
+
>>> from datetime import datetime
|
| 92 |
+
>>> from dateutil.relativedelta import relativedelta, MO
|
| 93 |
+
>>> dt = datetime(2018, 4, 9, 13, 37, 0)
|
| 94 |
+
>>> delta = relativedelta(hours=25, day=1, weekday=MO(1))
|
| 95 |
+
>>> dt + delta
|
| 96 |
+
datetime.datetime(2018, 4, 2, 14, 37)
|
| 97 |
+
|
| 98 |
+
First, the day is set to 1 (the first of the month), then 25 hours
|
| 99 |
+
are added, to get to the 2nd day and 14th hour, finally the
|
| 100 |
+
weekday is applied, but since the 2nd is already a Monday there is
|
| 101 |
+
no effect.
|
| 102 |
+
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
def __init__(self, dt1=None, dt2=None,
|
| 106 |
+
years=0, months=0, days=0, leapdays=0, weeks=0,
|
| 107 |
+
hours=0, minutes=0, seconds=0, microseconds=0,
|
| 108 |
+
year=None, month=None, day=None, weekday=None,
|
| 109 |
+
yearday=None, nlyearday=None,
|
| 110 |
+
hour=None, minute=None, second=None, microsecond=None):
|
| 111 |
+
|
| 112 |
+
if dt1 and dt2:
|
| 113 |
+
# datetime is a subclass of date. So both must be date
|
| 114 |
+
if not (isinstance(dt1, datetime.date) and
|
| 115 |
+
isinstance(dt2, datetime.date)):
|
| 116 |
+
raise TypeError("relativedelta only diffs datetime/date")
|
| 117 |
+
|
| 118 |
+
# We allow two dates, or two datetimes, so we coerce them to be
|
| 119 |
+
# of the same type
|
| 120 |
+
if (isinstance(dt1, datetime.datetime) !=
|
| 121 |
+
isinstance(dt2, datetime.datetime)):
|
| 122 |
+
if not isinstance(dt1, datetime.datetime):
|
| 123 |
+
dt1 = datetime.datetime.fromordinal(dt1.toordinal())
|
| 124 |
+
elif not isinstance(dt2, datetime.datetime):
|
| 125 |
+
dt2 = datetime.datetime.fromordinal(dt2.toordinal())
|
| 126 |
+
|
| 127 |
+
self.years = 0
|
| 128 |
+
self.months = 0
|
| 129 |
+
self.days = 0
|
| 130 |
+
self.leapdays = 0
|
| 131 |
+
self.hours = 0
|
| 132 |
+
self.minutes = 0
|
| 133 |
+
self.seconds = 0
|
| 134 |
+
self.microseconds = 0
|
| 135 |
+
self.year = None
|
| 136 |
+
self.month = None
|
| 137 |
+
self.day = None
|
| 138 |
+
self.weekday = None
|
| 139 |
+
self.hour = None
|
| 140 |
+
self.minute = None
|
| 141 |
+
self.second = None
|
| 142 |
+
self.microsecond = None
|
| 143 |
+
self._has_time = 0
|
| 144 |
+
|
| 145 |
+
# Get year / month delta between the two
|
| 146 |
+
months = (dt1.year - dt2.year) * 12 + (dt1.month - dt2.month)
|
| 147 |
+
self._set_months(months)
|
| 148 |
+
|
| 149 |
+
# Remove the year/month delta so the timedelta is just well-defined
|
| 150 |
+
# time units (seconds, days and microseconds)
|
| 151 |
+
dtm = self.__radd__(dt2)
|
| 152 |
+
|
| 153 |
+
# If we've overshot our target, make an adjustment
|
| 154 |
+
if dt1 < dt2:
|
| 155 |
+
compare = operator.gt
|
| 156 |
+
increment = 1
|
| 157 |
+
else:
|
| 158 |
+
compare = operator.lt
|
| 159 |
+
increment = -1
|
| 160 |
+
|
| 161 |
+
while compare(dt1, dtm):
|
| 162 |
+
months += increment
|
| 163 |
+
self._set_months(months)
|
| 164 |
+
dtm = self.__radd__(dt2)
|
| 165 |
+
|
| 166 |
+
# Get the timedelta between the "months-adjusted" date and dt1
|
| 167 |
+
delta = dt1 - dtm
|
| 168 |
+
self.seconds = delta.seconds + delta.days * 86400
|
| 169 |
+
self.microseconds = delta.microseconds
|
| 170 |
+
else:
|
| 171 |
+
# Check for non-integer values in integer-only quantities
|
| 172 |
+
if any(x is not None and x != int(x) for x in (years, months)):
|
| 173 |
+
raise ValueError("Non-integer years and months are "
|
| 174 |
+
"ambiguous and not currently supported.")
|
| 175 |
+
|
| 176 |
+
# Relative information
|
| 177 |
+
self.years = int(years)
|
| 178 |
+
self.months = int(months)
|
| 179 |
+
self.days = days + weeks * 7
|
| 180 |
+
self.leapdays = leapdays
|
| 181 |
+
self.hours = hours
|
| 182 |
+
self.minutes = minutes
|
| 183 |
+
self.seconds = seconds
|
| 184 |
+
self.microseconds = microseconds
|
| 185 |
+
|
| 186 |
+
# Absolute information
|
| 187 |
+
self.year = year
|
| 188 |
+
self.month = month
|
| 189 |
+
self.day = day
|
| 190 |
+
self.hour = hour
|
| 191 |
+
self.minute = minute
|
| 192 |
+
self.second = second
|
| 193 |
+
self.microsecond = microsecond
|
| 194 |
+
|
| 195 |
+
if any(x is not None and int(x) != x
|
| 196 |
+
for x in (year, month, day, hour,
|
| 197 |
+
minute, second, microsecond)):
|
| 198 |
+
# For now we'll deprecate floats - later it'll be an error.
|
| 199 |
+
warn("Non-integer value passed as absolute information. " +
|
| 200 |
+
"This is not a well-defined condition and will raise " +
|
| 201 |
+
"errors in future versions.", DeprecationWarning)
|
| 202 |
+
|
| 203 |
+
if isinstance(weekday, integer_types):
|
| 204 |
+
self.weekday = weekdays[weekday]
|
| 205 |
+
else:
|
| 206 |
+
self.weekday = weekday
|
| 207 |
+
|
| 208 |
+
yday = 0
|
| 209 |
+
if nlyearday:
|
| 210 |
+
yday = nlyearday
|
| 211 |
+
elif yearday:
|
| 212 |
+
yday = yearday
|
| 213 |
+
if yearday > 59:
|
| 214 |
+
self.leapdays = -1
|
| 215 |
+
if yday:
|
| 216 |
+
ydayidx = [31, 59, 90, 120, 151, 181, 212,
|
| 217 |
+
243, 273, 304, 334, 366]
|
| 218 |
+
for idx, ydays in enumerate(ydayidx):
|
| 219 |
+
if yday <= ydays:
|
| 220 |
+
self.month = idx+1
|
| 221 |
+
if idx == 0:
|
| 222 |
+
self.day = yday
|
| 223 |
+
else:
|
| 224 |
+
self.day = yday-ydayidx[idx-1]
|
| 225 |
+
break
|
| 226 |
+
else:
|
| 227 |
+
raise ValueError("invalid year day (%d)" % yday)
|
| 228 |
+
|
| 229 |
+
self._fix()
|
| 230 |
+
|
| 231 |
+
def _fix(self):
|
| 232 |
+
if abs(self.microseconds) > 999999:
|
| 233 |
+
s = _sign(self.microseconds)
|
| 234 |
+
div, mod = divmod(self.microseconds * s, 1000000)
|
| 235 |
+
self.microseconds = mod * s
|
| 236 |
+
self.seconds += div * s
|
| 237 |
+
if abs(self.seconds) > 59:
|
| 238 |
+
s = _sign(self.seconds)
|
| 239 |
+
div, mod = divmod(self.seconds * s, 60)
|
| 240 |
+
self.seconds = mod * s
|
| 241 |
+
self.minutes += div * s
|
| 242 |
+
if abs(self.minutes) > 59:
|
| 243 |
+
s = _sign(self.minutes)
|
| 244 |
+
div, mod = divmod(self.minutes * s, 60)
|
| 245 |
+
self.minutes = mod * s
|
| 246 |
+
self.hours += div * s
|
| 247 |
+
if abs(self.hours) > 23:
|
| 248 |
+
s = _sign(self.hours)
|
| 249 |
+
div, mod = divmod(self.hours * s, 24)
|
| 250 |
+
self.hours = mod * s
|
| 251 |
+
self.days += div * s
|
| 252 |
+
if abs(self.months) > 11:
|
| 253 |
+
s = _sign(self.months)
|
| 254 |
+
div, mod = divmod(self.months * s, 12)
|
| 255 |
+
self.months = mod * s
|
| 256 |
+
self.years += div * s
|
| 257 |
+
if (self.hours or self.minutes or self.seconds or self.microseconds
|
| 258 |
+
or self.hour is not None or self.minute is not None or
|
| 259 |
+
self.second is not None or self.microsecond is not None):
|
| 260 |
+
self._has_time = 1
|
| 261 |
+
else:
|
| 262 |
+
self._has_time = 0
|
| 263 |
+
|
| 264 |
+
@property
|
| 265 |
+
def weeks(self):
|
| 266 |
+
return int(self.days / 7.0)
|
| 267 |
+
|
| 268 |
+
@weeks.setter
|
| 269 |
+
def weeks(self, value):
|
| 270 |
+
self.days = self.days - (self.weeks * 7) + value * 7
|
| 271 |
+
|
| 272 |
+
def _set_months(self, months):
|
| 273 |
+
self.months = months
|
| 274 |
+
if abs(self.months) > 11:
|
| 275 |
+
s = _sign(self.months)
|
| 276 |
+
div, mod = divmod(self.months * s, 12)
|
| 277 |
+
self.months = mod * s
|
| 278 |
+
self.years = div * s
|
| 279 |
+
else:
|
| 280 |
+
self.years = 0
|
| 281 |
+
|
| 282 |
+
def normalized(self):
|
| 283 |
+
"""
|
| 284 |
+
Return a version of this object represented entirely using integer
|
| 285 |
+
values for the relative attributes.
|
| 286 |
+
|
| 287 |
+
>>> relativedelta(days=1.5, hours=2).normalized()
|
| 288 |
+
relativedelta(days=+1, hours=+14)
|
| 289 |
+
|
| 290 |
+
:return:
|
| 291 |
+
Returns a :class:`dateutil.relativedelta.relativedelta` object.
|
| 292 |
+
"""
|
| 293 |
+
# Cascade remainders down (rounding each to roughly nearest microsecond)
|
| 294 |
+
days = int(self.days)
|
| 295 |
+
|
| 296 |
+
hours_f = round(self.hours + 24 * (self.days - days), 11)
|
| 297 |
+
hours = int(hours_f)
|
| 298 |
+
|
| 299 |
+
minutes_f = round(self.minutes + 60 * (hours_f - hours), 10)
|
| 300 |
+
minutes = int(minutes_f)
|
| 301 |
+
|
| 302 |
+
seconds_f = round(self.seconds + 60 * (minutes_f - minutes), 8)
|
| 303 |
+
seconds = int(seconds_f)
|
| 304 |
+
|
| 305 |
+
microseconds = round(self.microseconds + 1e6 * (seconds_f - seconds))
|
| 306 |
+
|
| 307 |
+
# Constructor carries overflow back up with call to _fix()
|
| 308 |
+
return self.__class__(years=self.years, months=self.months,
|
| 309 |
+
days=days, hours=hours, minutes=minutes,
|
| 310 |
+
seconds=seconds, microseconds=microseconds,
|
| 311 |
+
leapdays=self.leapdays, year=self.year,
|
| 312 |
+
month=self.month, day=self.day,
|
| 313 |
+
weekday=self.weekday, hour=self.hour,
|
| 314 |
+
minute=self.minute, second=self.second,
|
| 315 |
+
microsecond=self.microsecond)
|
| 316 |
+
|
| 317 |
+
def __add__(self, other):
|
| 318 |
+
if isinstance(other, relativedelta):
|
| 319 |
+
return self.__class__(years=other.years + self.years,
|
| 320 |
+
months=other.months + self.months,
|
| 321 |
+
days=other.days + self.days,
|
| 322 |
+
hours=other.hours + self.hours,
|
| 323 |
+
minutes=other.minutes + self.minutes,
|
| 324 |
+
seconds=other.seconds + self.seconds,
|
| 325 |
+
microseconds=(other.microseconds +
|
| 326 |
+
self.microseconds),
|
| 327 |
+
leapdays=other.leapdays or self.leapdays,
|
| 328 |
+
year=(other.year if other.year is not None
|
| 329 |
+
else self.year),
|
| 330 |
+
month=(other.month if other.month is not None
|
| 331 |
+
else self.month),
|
| 332 |
+
day=(other.day if other.day is not None
|
| 333 |
+
else self.day),
|
| 334 |
+
weekday=(other.weekday if other.weekday is not None
|
| 335 |
+
else self.weekday),
|
| 336 |
+
hour=(other.hour if other.hour is not None
|
| 337 |
+
else self.hour),
|
| 338 |
+
minute=(other.minute if other.minute is not None
|
| 339 |
+
else self.minute),
|
| 340 |
+
second=(other.second if other.second is not None
|
| 341 |
+
else self.second),
|
| 342 |
+
microsecond=(other.microsecond if other.microsecond
|
| 343 |
+
is not None else
|
| 344 |
+
self.microsecond))
|
| 345 |
+
if isinstance(other, datetime.timedelta):
|
| 346 |
+
return self.__class__(years=self.years,
|
| 347 |
+
months=self.months,
|
| 348 |
+
days=self.days + other.days,
|
| 349 |
+
hours=self.hours,
|
| 350 |
+
minutes=self.minutes,
|
| 351 |
+
seconds=self.seconds + other.seconds,
|
| 352 |
+
microseconds=self.microseconds + other.microseconds,
|
| 353 |
+
leapdays=self.leapdays,
|
| 354 |
+
year=self.year,
|
| 355 |
+
month=self.month,
|
| 356 |
+
day=self.day,
|
| 357 |
+
weekday=self.weekday,
|
| 358 |
+
hour=self.hour,
|
| 359 |
+
minute=self.minute,
|
| 360 |
+
second=self.second,
|
| 361 |
+
microsecond=self.microsecond)
|
| 362 |
+
if not isinstance(other, datetime.date):
|
| 363 |
+
return NotImplemented
|
| 364 |
+
elif self._has_time and not isinstance(other, datetime.datetime):
|
| 365 |
+
other = datetime.datetime.fromordinal(other.toordinal())
|
| 366 |
+
year = (self.year or other.year)+self.years
|
| 367 |
+
month = self.month or other.month
|
| 368 |
+
if self.months:
|
| 369 |
+
assert 1 <= abs(self.months) <= 12
|
| 370 |
+
month += self.months
|
| 371 |
+
if month > 12:
|
| 372 |
+
year += 1
|
| 373 |
+
month -= 12
|
| 374 |
+
elif month < 1:
|
| 375 |
+
year -= 1
|
| 376 |
+
month += 12
|
| 377 |
+
day = min(calendar.monthrange(year, month)[1],
|
| 378 |
+
self.day or other.day)
|
| 379 |
+
repl = {"year": year, "month": month, "day": day}
|
| 380 |
+
for attr in ["hour", "minute", "second", "microsecond"]:
|
| 381 |
+
value = getattr(self, attr)
|
| 382 |
+
if value is not None:
|
| 383 |
+
repl[attr] = value
|
| 384 |
+
days = self.days
|
| 385 |
+
if self.leapdays and month > 2 and calendar.isleap(year):
|
| 386 |
+
days += self.leapdays
|
| 387 |
+
ret = (other.replace(**repl)
|
| 388 |
+
+ datetime.timedelta(days=days,
|
| 389 |
+
hours=self.hours,
|
| 390 |
+
minutes=self.minutes,
|
| 391 |
+
seconds=self.seconds,
|
| 392 |
+
microseconds=self.microseconds))
|
| 393 |
+
if self.weekday:
|
| 394 |
+
weekday, nth = self.weekday.weekday, self.weekday.n or 1
|
| 395 |
+
jumpdays = (abs(nth) - 1) * 7
|
| 396 |
+
if nth > 0:
|
| 397 |
+
jumpdays += (7 - ret.weekday() + weekday) % 7
|
| 398 |
+
else:
|
| 399 |
+
jumpdays += (ret.weekday() - weekday) % 7
|
| 400 |
+
jumpdays *= -1
|
| 401 |
+
ret += datetime.timedelta(days=jumpdays)
|
| 402 |
+
return ret
|
| 403 |
+
|
| 404 |
+
def __radd__(self, other):
|
| 405 |
+
return self.__add__(other)
|
| 406 |
+
|
| 407 |
+
def __rsub__(self, other):
|
| 408 |
+
return self.__neg__().__radd__(other)
|
| 409 |
+
|
| 410 |
+
def __sub__(self, other):
|
| 411 |
+
if not isinstance(other, relativedelta):
|
| 412 |
+
return NotImplemented # In case the other object defines __rsub__
|
| 413 |
+
return self.__class__(years=self.years - other.years,
|
| 414 |
+
months=self.months - other.months,
|
| 415 |
+
days=self.days - other.days,
|
| 416 |
+
hours=self.hours - other.hours,
|
| 417 |
+
minutes=self.minutes - other.minutes,
|
| 418 |
+
seconds=self.seconds - other.seconds,
|
| 419 |
+
microseconds=self.microseconds - other.microseconds,
|
| 420 |
+
leapdays=self.leapdays or other.leapdays,
|
| 421 |
+
year=(self.year if self.year is not None
|
| 422 |
+
else other.year),
|
| 423 |
+
month=(self.month if self.month is not None else
|
| 424 |
+
other.month),
|
| 425 |
+
day=(self.day if self.day is not None else
|
| 426 |
+
other.day),
|
| 427 |
+
weekday=(self.weekday if self.weekday is not None else
|
| 428 |
+
other.weekday),
|
| 429 |
+
hour=(self.hour if self.hour is not None else
|
| 430 |
+
other.hour),
|
| 431 |
+
minute=(self.minute if self.minute is not None else
|
| 432 |
+
other.minute),
|
| 433 |
+
second=(self.second if self.second is not None else
|
| 434 |
+
other.second),
|
| 435 |
+
microsecond=(self.microsecond if self.microsecond
|
| 436 |
+
is not None else
|
| 437 |
+
other.microsecond))
|
| 438 |
+
|
| 439 |
+
def __abs__(self):
|
| 440 |
+
return self.__class__(years=abs(self.years),
|
| 441 |
+
months=abs(self.months),
|
| 442 |
+
days=abs(self.days),
|
| 443 |
+
hours=abs(self.hours),
|
| 444 |
+
minutes=abs(self.minutes),
|
| 445 |
+
seconds=abs(self.seconds),
|
| 446 |
+
microseconds=abs(self.microseconds),
|
| 447 |
+
leapdays=self.leapdays,
|
| 448 |
+
year=self.year,
|
| 449 |
+
month=self.month,
|
| 450 |
+
day=self.day,
|
| 451 |
+
weekday=self.weekday,
|
| 452 |
+
hour=self.hour,
|
| 453 |
+
minute=self.minute,
|
| 454 |
+
second=self.second,
|
| 455 |
+
microsecond=self.microsecond)
|
| 456 |
+
|
| 457 |
+
def __neg__(self):
|
| 458 |
+
return self.__class__(years=-self.years,
|
| 459 |
+
months=-self.months,
|
| 460 |
+
days=-self.days,
|
| 461 |
+
hours=-self.hours,
|
| 462 |
+
minutes=-self.minutes,
|
| 463 |
+
seconds=-self.seconds,
|
| 464 |
+
microseconds=-self.microseconds,
|
| 465 |
+
leapdays=self.leapdays,
|
| 466 |
+
year=self.year,
|
| 467 |
+
month=self.month,
|
| 468 |
+
day=self.day,
|
| 469 |
+
weekday=self.weekday,
|
| 470 |
+
hour=self.hour,
|
| 471 |
+
minute=self.minute,
|
| 472 |
+
second=self.second,
|
| 473 |
+
microsecond=self.microsecond)
|
| 474 |
+
|
| 475 |
+
def __bool__(self):
|
| 476 |
+
return not (not self.years and
|
| 477 |
+
not self.months and
|
| 478 |
+
not self.days and
|
| 479 |
+
not self.hours and
|
| 480 |
+
not self.minutes and
|
| 481 |
+
not self.seconds and
|
| 482 |
+
not self.microseconds and
|
| 483 |
+
not self.leapdays and
|
| 484 |
+
self.year is None and
|
| 485 |
+
self.month is None and
|
| 486 |
+
self.day is None and
|
| 487 |
+
self.weekday is None and
|
| 488 |
+
self.hour is None and
|
| 489 |
+
self.minute is None and
|
| 490 |
+
self.second is None and
|
| 491 |
+
self.microsecond is None)
|
| 492 |
+
# Compatibility with Python 2.x
|
| 493 |
+
__nonzero__ = __bool__
|
| 494 |
+
|
| 495 |
+
def __mul__(self, other):
|
| 496 |
+
try:
|
| 497 |
+
f = float(other)
|
| 498 |
+
except TypeError:
|
| 499 |
+
return NotImplemented
|
| 500 |
+
|
| 501 |
+
return self.__class__(years=int(self.years * f),
|
| 502 |
+
months=int(self.months * f),
|
| 503 |
+
days=int(self.days * f),
|
| 504 |
+
hours=int(self.hours * f),
|
| 505 |
+
minutes=int(self.minutes * f),
|
| 506 |
+
seconds=int(self.seconds * f),
|
| 507 |
+
microseconds=int(self.microseconds * f),
|
| 508 |
+
leapdays=self.leapdays,
|
| 509 |
+
year=self.year,
|
| 510 |
+
month=self.month,
|
| 511 |
+
day=self.day,
|
| 512 |
+
weekday=self.weekday,
|
| 513 |
+
hour=self.hour,
|
| 514 |
+
minute=self.minute,
|
| 515 |
+
second=self.second,
|
| 516 |
+
microsecond=self.microsecond)
|
| 517 |
+
|
| 518 |
+
__rmul__ = __mul__
|
| 519 |
+
|
| 520 |
+
def __eq__(self, other):
|
| 521 |
+
if not isinstance(other, relativedelta):
|
| 522 |
+
return NotImplemented
|
| 523 |
+
if self.weekday or other.weekday:
|
| 524 |
+
if not self.weekday or not other.weekday:
|
| 525 |
+
return False
|
| 526 |
+
if self.weekday.weekday != other.weekday.weekday:
|
| 527 |
+
return False
|
| 528 |
+
n1, n2 = self.weekday.n, other.weekday.n
|
| 529 |
+
if n1 != n2 and not ((not n1 or n1 == 1) and (not n2 or n2 == 1)):
|
| 530 |
+
return False
|
| 531 |
+
return (self.years == other.years and
|
| 532 |
+
self.months == other.months and
|
| 533 |
+
self.days == other.days and
|
| 534 |
+
self.hours == other.hours and
|
| 535 |
+
self.minutes == other.minutes and
|
| 536 |
+
self.seconds == other.seconds and
|
| 537 |
+
self.microseconds == other.microseconds and
|
| 538 |
+
self.leapdays == other.leapdays and
|
| 539 |
+
self.year == other.year and
|
| 540 |
+
self.month == other.month and
|
| 541 |
+
self.day == other.day and
|
| 542 |
+
self.hour == other.hour and
|
| 543 |
+
self.minute == other.minute and
|
| 544 |
+
self.second == other.second and
|
| 545 |
+
self.microsecond == other.microsecond)
|
| 546 |
+
|
| 547 |
+
def __hash__(self):
|
| 548 |
+
return hash((
|
| 549 |
+
self.weekday,
|
| 550 |
+
self.years,
|
| 551 |
+
self.months,
|
| 552 |
+
self.days,
|
| 553 |
+
self.hours,
|
| 554 |
+
self.minutes,
|
| 555 |
+
self.seconds,
|
| 556 |
+
self.microseconds,
|
| 557 |
+
self.leapdays,
|
| 558 |
+
self.year,
|
| 559 |
+
self.month,
|
| 560 |
+
self.day,
|
| 561 |
+
self.hour,
|
| 562 |
+
self.minute,
|
| 563 |
+
self.second,
|
| 564 |
+
self.microsecond,
|
| 565 |
+
))
|
| 566 |
+
|
| 567 |
+
def __ne__(self, other):
|
| 568 |
+
return not self.__eq__(other)
|
| 569 |
+
|
| 570 |
+
def __div__(self, other):
|
| 571 |
+
try:
|
| 572 |
+
reciprocal = 1 / float(other)
|
| 573 |
+
except TypeError:
|
| 574 |
+
return NotImplemented
|
| 575 |
+
|
| 576 |
+
return self.__mul__(reciprocal)
|
| 577 |
+
|
| 578 |
+
__truediv__ = __div__
|
| 579 |
+
|
| 580 |
+
def __repr__(self):
|
| 581 |
+
l = []
|
| 582 |
+
for attr in ["years", "months", "days", "leapdays",
|
| 583 |
+
"hours", "minutes", "seconds", "microseconds"]:
|
| 584 |
+
value = getattr(self, attr)
|
| 585 |
+
if value:
|
| 586 |
+
l.append("{attr}={value:+g}".format(attr=attr, value=value))
|
| 587 |
+
for attr in ["year", "month", "day", "weekday",
|
| 588 |
+
"hour", "minute", "second", "microsecond"]:
|
| 589 |
+
value = getattr(self, attr)
|
| 590 |
+
if value is not None:
|
| 591 |
+
l.append("{attr}={value}".format(attr=attr, value=repr(value)))
|
| 592 |
+
return "{classname}({attrs})".format(classname=self.__class__.__name__,
|
| 593 |
+
attrs=", ".join(l))
|
| 594 |
+
|
| 595 |
+
|
| 596 |
+
def _sign(x):
|
| 597 |
+
return int(copysign(1, x))
|
| 598 |
+
|
| 599 |
+
# vim:ts=4:sw=4:et
|