Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- venv/lib/python3.12/site-packages/httpx/_api.py +438 -0
- venv/lib/python3.12/site-packages/httpx/_auth.py +348 -0
- venv/lib/python3.12/site-packages/httpx/_client.py +2019 -0
- venv/lib/python3.12/site-packages/httpx/_content.py +240 -0
- venv/lib/python3.12/site-packages/httpx/_decoders.py +393 -0
- venv/lib/python3.12/site-packages/httpx/_exceptions.py +379 -0
- venv/lib/python3.12/site-packages/httpx/_main.py +506 -0
- venv/lib/python3.12/site-packages/httpx/_multipart.py +300 -0
- venv/lib/python3.12/site-packages/httpx/_status_codes.py +162 -0
- venv/lib/python3.12/site-packages/httpx/_types.py +114 -0
- venv/lib/python3.12/site-packages/httpx/_urlparse.py +527 -0
- venv/lib/python3.12/site-packages/httpx/_urls.py +641 -0
- venv/lib/python3.12/site-packages/pip/__pycache__/__init__.cpython-312.pyc +0 -0
- venv/lib/python3.12/site-packages/pip/__pycache__/__main__.cpython-312.pyc +0 -0
- venv/lib/python3.12/site-packages/pip/__pycache__/__pip-runner__.cpython-312.pyc +0 -0
- venv/lib/python3.12/site-packages/pip/_internal/__init__.py +18 -0
- venv/lib/python3.12/site-packages/pip/_internal/build_env.py +311 -0
- venv/lib/python3.12/site-packages/pip/_internal/cache.py +290 -0
- venv/lib/python3.12/site-packages/pip/_internal/configuration.py +383 -0
- venv/lib/python3.12/site-packages/pip/_internal/exceptions.py +728 -0
- venv/lib/python3.12/site-packages/pip/_internal/main.py +12 -0
- venv/lib/python3.12/site-packages/pip/_internal/pyproject.py +179 -0
- venv/lib/python3.12/site-packages/pip/_internal/self_outdated_check.py +248 -0
- venv/lib/python3.12/site-packages/pip/_internal/wheel_builder.py +354 -0
- venv/lib/python3.12/site-packages/pip/_vendor/__init__.py +121 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/__init__.py +115 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/big5prober.py +47 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/charsetgroupprober.py +106 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/charsetprober.py +147 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/codingstatemachine.py +90 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/codingstatemachinedict.py +19 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/cp949prober.py +49 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/escsm.py +261 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/langgreekmodel.py +0 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/langrussianmodel.py +0 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/langturkishmodel.py +4380 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/mbcsgroupprober.py +57 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/resultdict.py +16 -0
- venv/lib/python3.12/site-packages/pip/_vendor/chardet/sbcharsetprober.py +162 -0
- venv/lib/python3.12/site-packages/pip/_vendor/msgpack/__init__.py +57 -0
- venv/lib/python3.12/site-packages/pip/_vendor/msgpack/exceptions.py +48 -0
- venv/lib/python3.12/site-packages/pip/_vendor/msgpack/ext.py +193 -0
- venv/lib/python3.12/site-packages/pip/_vendor/msgpack/fallback.py +1010 -0
- venv/lib/python3.12/site-packages/pip/_vendor/packaging/__about__.py +26 -0
- venv/lib/python3.12/site-packages/pip/_vendor/packaging/__init__.py +25 -0
- venv/lib/python3.12/site-packages/pip/_vendor/packaging/_manylinux.py +301 -0
- venv/lib/python3.12/site-packages/pip/_vendor/packaging/_musllinux.py +136 -0
- venv/lib/python3.12/site-packages/pip/_vendor/packaging/_structures.py +61 -0
- venv/lib/python3.12/site-packages/pip/_vendor/packaging/markers.py +304 -0
- venv/lib/python3.12/site-packages/pip/_vendor/packaging/requirements.py +146 -0
venv/lib/python3.12/site-packages/httpx/_api.py
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import typing
|
| 4 |
+
from contextlib import contextmanager
|
| 5 |
+
|
| 6 |
+
from ._client import Client
|
| 7 |
+
from ._config import DEFAULT_TIMEOUT_CONFIG
|
| 8 |
+
from ._models import Response
|
| 9 |
+
from ._types import (
|
| 10 |
+
AuthTypes,
|
| 11 |
+
CookieTypes,
|
| 12 |
+
HeaderTypes,
|
| 13 |
+
ProxyTypes,
|
| 14 |
+
QueryParamTypes,
|
| 15 |
+
RequestContent,
|
| 16 |
+
RequestData,
|
| 17 |
+
RequestFiles,
|
| 18 |
+
TimeoutTypes,
|
| 19 |
+
)
|
| 20 |
+
from ._urls import URL
|
| 21 |
+
|
| 22 |
+
if typing.TYPE_CHECKING:
|
| 23 |
+
import ssl # pragma: no cover
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__all__ = [
|
| 27 |
+
"delete",
|
| 28 |
+
"get",
|
| 29 |
+
"head",
|
| 30 |
+
"options",
|
| 31 |
+
"patch",
|
| 32 |
+
"post",
|
| 33 |
+
"put",
|
| 34 |
+
"request",
|
| 35 |
+
"stream",
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def request(
|
| 40 |
+
method: str,
|
| 41 |
+
url: URL | str,
|
| 42 |
+
*,
|
| 43 |
+
params: QueryParamTypes | None = None,
|
| 44 |
+
content: RequestContent | None = None,
|
| 45 |
+
data: RequestData | None = None,
|
| 46 |
+
files: RequestFiles | None = None,
|
| 47 |
+
json: typing.Any | None = None,
|
| 48 |
+
headers: HeaderTypes | None = None,
|
| 49 |
+
cookies: CookieTypes | None = None,
|
| 50 |
+
auth: AuthTypes | None = None,
|
| 51 |
+
proxy: ProxyTypes | None = None,
|
| 52 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 53 |
+
follow_redirects: bool = False,
|
| 54 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 55 |
+
trust_env: bool = True,
|
| 56 |
+
) -> Response:
|
| 57 |
+
"""
|
| 58 |
+
Sends an HTTP request.
|
| 59 |
+
|
| 60 |
+
**Parameters:**
|
| 61 |
+
|
| 62 |
+
* **method** - HTTP method for the new `Request` object: `GET`, `OPTIONS`,
|
| 63 |
+
`HEAD`, `POST`, `PUT`, `PATCH`, or `DELETE`.
|
| 64 |
+
* **url** - URL for the new `Request` object.
|
| 65 |
+
* **params** - *(optional)* Query parameters to include in the URL, as a
|
| 66 |
+
string, dictionary, or sequence of two-tuples.
|
| 67 |
+
* **content** - *(optional)* Binary content to include in the body of the
|
| 68 |
+
request, as bytes or a byte iterator.
|
| 69 |
+
* **data** - *(optional)* Form data to include in the body of the request,
|
| 70 |
+
as a dictionary.
|
| 71 |
+
* **files** - *(optional)* A dictionary of upload files to include in the
|
| 72 |
+
body of the request.
|
| 73 |
+
* **json** - *(optional)* A JSON serializable object to include in the body
|
| 74 |
+
of the request.
|
| 75 |
+
* **headers** - *(optional)* Dictionary of HTTP headers to include in the
|
| 76 |
+
request.
|
| 77 |
+
* **cookies** - *(optional)* Dictionary of Cookie items to include in the
|
| 78 |
+
request.
|
| 79 |
+
* **auth** - *(optional)* An authentication class to use when sending the
|
| 80 |
+
request.
|
| 81 |
+
* **proxy** - *(optional)* A proxy URL where all the traffic should be routed.
|
| 82 |
+
* **timeout** - *(optional)* The timeout configuration to use when sending
|
| 83 |
+
the request.
|
| 84 |
+
* **follow_redirects** - *(optional)* Enables or disables HTTP redirects.
|
| 85 |
+
* **verify** - *(optional)* Either `True` to use an SSL context with the
|
| 86 |
+
default CA bundle, `False` to disable verification, or an instance of
|
| 87 |
+
`ssl.SSLContext` to use a custom context.
|
| 88 |
+
* **trust_env** - *(optional)* Enables or disables usage of environment
|
| 89 |
+
variables for configuration.
|
| 90 |
+
|
| 91 |
+
**Returns:** `Response`
|
| 92 |
+
|
| 93 |
+
Usage:
|
| 94 |
+
|
| 95 |
+
```
|
| 96 |
+
>>> import httpx
|
| 97 |
+
>>> response = httpx.request('GET', 'https://httpbin.org/get')
|
| 98 |
+
>>> response
|
| 99 |
+
<Response [200 OK]>
|
| 100 |
+
```
|
| 101 |
+
"""
|
| 102 |
+
with Client(
|
| 103 |
+
cookies=cookies,
|
| 104 |
+
proxy=proxy,
|
| 105 |
+
verify=verify,
|
| 106 |
+
timeout=timeout,
|
| 107 |
+
trust_env=trust_env,
|
| 108 |
+
) as client:
|
| 109 |
+
return client.request(
|
| 110 |
+
method=method,
|
| 111 |
+
url=url,
|
| 112 |
+
content=content,
|
| 113 |
+
data=data,
|
| 114 |
+
files=files,
|
| 115 |
+
json=json,
|
| 116 |
+
params=params,
|
| 117 |
+
headers=headers,
|
| 118 |
+
auth=auth,
|
| 119 |
+
follow_redirects=follow_redirects,
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
@contextmanager
|
| 124 |
+
def stream(
|
| 125 |
+
method: str,
|
| 126 |
+
url: URL | str,
|
| 127 |
+
*,
|
| 128 |
+
params: QueryParamTypes | None = None,
|
| 129 |
+
content: RequestContent | None = None,
|
| 130 |
+
data: RequestData | None = None,
|
| 131 |
+
files: RequestFiles | None = None,
|
| 132 |
+
json: typing.Any | None = None,
|
| 133 |
+
headers: HeaderTypes | None = None,
|
| 134 |
+
cookies: CookieTypes | None = None,
|
| 135 |
+
auth: AuthTypes | None = None,
|
| 136 |
+
proxy: ProxyTypes | None = None,
|
| 137 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 138 |
+
follow_redirects: bool = False,
|
| 139 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 140 |
+
trust_env: bool = True,
|
| 141 |
+
) -> typing.Iterator[Response]:
|
| 142 |
+
"""
|
| 143 |
+
Alternative to `httpx.request()` that streams the response body
|
| 144 |
+
instead of loading it into memory at once.
|
| 145 |
+
|
| 146 |
+
**Parameters**: See `httpx.request`.
|
| 147 |
+
|
| 148 |
+
See also: [Streaming Responses][0]
|
| 149 |
+
|
| 150 |
+
[0]: /quickstart#streaming-responses
|
| 151 |
+
"""
|
| 152 |
+
with Client(
|
| 153 |
+
cookies=cookies,
|
| 154 |
+
proxy=proxy,
|
| 155 |
+
verify=verify,
|
| 156 |
+
timeout=timeout,
|
| 157 |
+
trust_env=trust_env,
|
| 158 |
+
) as client:
|
| 159 |
+
with client.stream(
|
| 160 |
+
method=method,
|
| 161 |
+
url=url,
|
| 162 |
+
content=content,
|
| 163 |
+
data=data,
|
| 164 |
+
files=files,
|
| 165 |
+
json=json,
|
| 166 |
+
params=params,
|
| 167 |
+
headers=headers,
|
| 168 |
+
auth=auth,
|
| 169 |
+
follow_redirects=follow_redirects,
|
| 170 |
+
) as response:
|
| 171 |
+
yield response
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def get(
|
| 175 |
+
url: URL | str,
|
| 176 |
+
*,
|
| 177 |
+
params: QueryParamTypes | None = None,
|
| 178 |
+
headers: HeaderTypes | None = None,
|
| 179 |
+
cookies: CookieTypes | None = None,
|
| 180 |
+
auth: AuthTypes | None = None,
|
| 181 |
+
proxy: ProxyTypes | None = None,
|
| 182 |
+
follow_redirects: bool = False,
|
| 183 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 184 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 185 |
+
trust_env: bool = True,
|
| 186 |
+
) -> Response:
|
| 187 |
+
"""
|
| 188 |
+
Sends a `GET` request.
|
| 189 |
+
|
| 190 |
+
**Parameters**: See `httpx.request`.
|
| 191 |
+
|
| 192 |
+
Note that the `data`, `files`, `json` and `content` parameters are not available
|
| 193 |
+
on this function, as `GET` requests should not include a request body.
|
| 194 |
+
"""
|
| 195 |
+
return request(
|
| 196 |
+
"GET",
|
| 197 |
+
url,
|
| 198 |
+
params=params,
|
| 199 |
+
headers=headers,
|
| 200 |
+
cookies=cookies,
|
| 201 |
+
auth=auth,
|
| 202 |
+
proxy=proxy,
|
| 203 |
+
follow_redirects=follow_redirects,
|
| 204 |
+
verify=verify,
|
| 205 |
+
timeout=timeout,
|
| 206 |
+
trust_env=trust_env,
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def options(
|
| 211 |
+
url: URL | str,
|
| 212 |
+
*,
|
| 213 |
+
params: QueryParamTypes | None = None,
|
| 214 |
+
headers: HeaderTypes | None = None,
|
| 215 |
+
cookies: CookieTypes | None = None,
|
| 216 |
+
auth: AuthTypes | None = None,
|
| 217 |
+
proxy: ProxyTypes | None = None,
|
| 218 |
+
follow_redirects: bool = False,
|
| 219 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 220 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 221 |
+
trust_env: bool = True,
|
| 222 |
+
) -> Response:
|
| 223 |
+
"""
|
| 224 |
+
Sends an `OPTIONS` request.
|
| 225 |
+
|
| 226 |
+
**Parameters**: See `httpx.request`.
|
| 227 |
+
|
| 228 |
+
Note that the `data`, `files`, `json` and `content` parameters are not available
|
| 229 |
+
on this function, as `OPTIONS` requests should not include a request body.
|
| 230 |
+
"""
|
| 231 |
+
return request(
|
| 232 |
+
"OPTIONS",
|
| 233 |
+
url,
|
| 234 |
+
params=params,
|
| 235 |
+
headers=headers,
|
| 236 |
+
cookies=cookies,
|
| 237 |
+
auth=auth,
|
| 238 |
+
proxy=proxy,
|
| 239 |
+
follow_redirects=follow_redirects,
|
| 240 |
+
verify=verify,
|
| 241 |
+
timeout=timeout,
|
| 242 |
+
trust_env=trust_env,
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def head(
|
| 247 |
+
url: URL | str,
|
| 248 |
+
*,
|
| 249 |
+
params: QueryParamTypes | None = None,
|
| 250 |
+
headers: HeaderTypes | None = None,
|
| 251 |
+
cookies: CookieTypes | None = None,
|
| 252 |
+
auth: AuthTypes | None = None,
|
| 253 |
+
proxy: ProxyTypes | None = None,
|
| 254 |
+
follow_redirects: bool = False,
|
| 255 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 256 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 257 |
+
trust_env: bool = True,
|
| 258 |
+
) -> Response:
|
| 259 |
+
"""
|
| 260 |
+
Sends a `HEAD` request.
|
| 261 |
+
|
| 262 |
+
**Parameters**: See `httpx.request`.
|
| 263 |
+
|
| 264 |
+
Note that the `data`, `files`, `json` and `content` parameters are not available
|
| 265 |
+
on this function, as `HEAD` requests should not include a request body.
|
| 266 |
+
"""
|
| 267 |
+
return request(
|
| 268 |
+
"HEAD",
|
| 269 |
+
url,
|
| 270 |
+
params=params,
|
| 271 |
+
headers=headers,
|
| 272 |
+
cookies=cookies,
|
| 273 |
+
auth=auth,
|
| 274 |
+
proxy=proxy,
|
| 275 |
+
follow_redirects=follow_redirects,
|
| 276 |
+
verify=verify,
|
| 277 |
+
timeout=timeout,
|
| 278 |
+
trust_env=trust_env,
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def post(
|
| 283 |
+
url: URL | str,
|
| 284 |
+
*,
|
| 285 |
+
content: RequestContent | None = None,
|
| 286 |
+
data: RequestData | None = None,
|
| 287 |
+
files: RequestFiles | None = None,
|
| 288 |
+
json: typing.Any | None = None,
|
| 289 |
+
params: QueryParamTypes | None = None,
|
| 290 |
+
headers: HeaderTypes | None = None,
|
| 291 |
+
cookies: CookieTypes | None = None,
|
| 292 |
+
auth: AuthTypes | None = None,
|
| 293 |
+
proxy: ProxyTypes | None = None,
|
| 294 |
+
follow_redirects: bool = False,
|
| 295 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 296 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 297 |
+
trust_env: bool = True,
|
| 298 |
+
) -> Response:
|
| 299 |
+
"""
|
| 300 |
+
Sends a `POST` request.
|
| 301 |
+
|
| 302 |
+
**Parameters**: See `httpx.request`.
|
| 303 |
+
"""
|
| 304 |
+
return request(
|
| 305 |
+
"POST",
|
| 306 |
+
url,
|
| 307 |
+
content=content,
|
| 308 |
+
data=data,
|
| 309 |
+
files=files,
|
| 310 |
+
json=json,
|
| 311 |
+
params=params,
|
| 312 |
+
headers=headers,
|
| 313 |
+
cookies=cookies,
|
| 314 |
+
auth=auth,
|
| 315 |
+
proxy=proxy,
|
| 316 |
+
follow_redirects=follow_redirects,
|
| 317 |
+
verify=verify,
|
| 318 |
+
timeout=timeout,
|
| 319 |
+
trust_env=trust_env,
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def put(
|
| 324 |
+
url: URL | str,
|
| 325 |
+
*,
|
| 326 |
+
content: RequestContent | None = None,
|
| 327 |
+
data: RequestData | None = None,
|
| 328 |
+
files: RequestFiles | None = None,
|
| 329 |
+
json: typing.Any | None = None,
|
| 330 |
+
params: QueryParamTypes | None = None,
|
| 331 |
+
headers: HeaderTypes | None = None,
|
| 332 |
+
cookies: CookieTypes | None = None,
|
| 333 |
+
auth: AuthTypes | None = None,
|
| 334 |
+
proxy: ProxyTypes | None = None,
|
| 335 |
+
follow_redirects: bool = False,
|
| 336 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 337 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 338 |
+
trust_env: bool = True,
|
| 339 |
+
) -> Response:
|
| 340 |
+
"""
|
| 341 |
+
Sends a `PUT` request.
|
| 342 |
+
|
| 343 |
+
**Parameters**: See `httpx.request`.
|
| 344 |
+
"""
|
| 345 |
+
return request(
|
| 346 |
+
"PUT",
|
| 347 |
+
url,
|
| 348 |
+
content=content,
|
| 349 |
+
data=data,
|
| 350 |
+
files=files,
|
| 351 |
+
json=json,
|
| 352 |
+
params=params,
|
| 353 |
+
headers=headers,
|
| 354 |
+
cookies=cookies,
|
| 355 |
+
auth=auth,
|
| 356 |
+
proxy=proxy,
|
| 357 |
+
follow_redirects=follow_redirects,
|
| 358 |
+
verify=verify,
|
| 359 |
+
timeout=timeout,
|
| 360 |
+
trust_env=trust_env,
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def patch(
|
| 365 |
+
url: URL | str,
|
| 366 |
+
*,
|
| 367 |
+
content: RequestContent | None = None,
|
| 368 |
+
data: RequestData | None = None,
|
| 369 |
+
files: RequestFiles | None = None,
|
| 370 |
+
json: typing.Any | None = None,
|
| 371 |
+
params: QueryParamTypes | None = None,
|
| 372 |
+
headers: HeaderTypes | None = None,
|
| 373 |
+
cookies: CookieTypes | None = None,
|
| 374 |
+
auth: AuthTypes | None = None,
|
| 375 |
+
proxy: ProxyTypes | None = None,
|
| 376 |
+
follow_redirects: bool = False,
|
| 377 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 378 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 379 |
+
trust_env: bool = True,
|
| 380 |
+
) -> Response:
|
| 381 |
+
"""
|
| 382 |
+
Sends a `PATCH` request.
|
| 383 |
+
|
| 384 |
+
**Parameters**: See `httpx.request`.
|
| 385 |
+
"""
|
| 386 |
+
return request(
|
| 387 |
+
"PATCH",
|
| 388 |
+
url,
|
| 389 |
+
content=content,
|
| 390 |
+
data=data,
|
| 391 |
+
files=files,
|
| 392 |
+
json=json,
|
| 393 |
+
params=params,
|
| 394 |
+
headers=headers,
|
| 395 |
+
cookies=cookies,
|
| 396 |
+
auth=auth,
|
| 397 |
+
proxy=proxy,
|
| 398 |
+
follow_redirects=follow_redirects,
|
| 399 |
+
verify=verify,
|
| 400 |
+
timeout=timeout,
|
| 401 |
+
trust_env=trust_env,
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def delete(
|
| 406 |
+
url: URL | str,
|
| 407 |
+
*,
|
| 408 |
+
params: QueryParamTypes | None = None,
|
| 409 |
+
headers: HeaderTypes | None = None,
|
| 410 |
+
cookies: CookieTypes | None = None,
|
| 411 |
+
auth: AuthTypes | None = None,
|
| 412 |
+
proxy: ProxyTypes | None = None,
|
| 413 |
+
follow_redirects: bool = False,
|
| 414 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 415 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 416 |
+
trust_env: bool = True,
|
| 417 |
+
) -> Response:
|
| 418 |
+
"""
|
| 419 |
+
Sends a `DELETE` request.
|
| 420 |
+
|
| 421 |
+
**Parameters**: See `httpx.request`.
|
| 422 |
+
|
| 423 |
+
Note that the `data`, `files`, `json` and `content` parameters are not available
|
| 424 |
+
on this function, as `DELETE` requests should not include a request body.
|
| 425 |
+
"""
|
| 426 |
+
return request(
|
| 427 |
+
"DELETE",
|
| 428 |
+
url,
|
| 429 |
+
params=params,
|
| 430 |
+
headers=headers,
|
| 431 |
+
cookies=cookies,
|
| 432 |
+
auth=auth,
|
| 433 |
+
proxy=proxy,
|
| 434 |
+
follow_redirects=follow_redirects,
|
| 435 |
+
verify=verify,
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
import time
|
| 7 |
+
import typing
|
| 8 |
+
from base64 import b64encode
|
| 9 |
+
from urllib.request import parse_http_list
|
| 10 |
+
|
| 11 |
+
from ._exceptions import ProtocolError
|
| 12 |
+
from ._models import Cookies, Request, Response
|
| 13 |
+
from ._utils import to_bytes, to_str, unquote
|
| 14 |
+
|
| 15 |
+
if typing.TYPE_CHECKING: # pragma: no cover
|
| 16 |
+
from hashlib import _Hash
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
__all__ = ["Auth", "BasicAuth", "DigestAuth", "NetRCAuth"]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class Auth:
|
| 23 |
+
"""
|
| 24 |
+
Base class for all authentication schemes.
|
| 25 |
+
|
| 26 |
+
To implement a custom authentication scheme, subclass `Auth` and override
|
| 27 |
+
the `.auth_flow()` method.
|
| 28 |
+
|
| 29 |
+
If the authentication scheme does I/O such as disk access or network calls, or uses
|
| 30 |
+
synchronization primitives such as locks, you should override `.sync_auth_flow()`
|
| 31 |
+
and/or `.async_auth_flow()` instead of `.auth_flow()` to provide specialized
|
| 32 |
+
implementations that will be used by `Client` and `AsyncClient` respectively.
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
requires_request_body = False
|
| 36 |
+
requires_response_body = False
|
| 37 |
+
|
| 38 |
+
def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
|
| 39 |
+
"""
|
| 40 |
+
Execute the authentication flow.
|
| 41 |
+
|
| 42 |
+
To dispatch a request, `yield` it:
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
yield request
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
The client will `.send()` the response back into the flow generator. You can
|
| 49 |
+
access it like so:
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
response = yield request
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
A `return` (or reaching the end of the generator) will result in the
|
| 56 |
+
client returning the last response obtained from the server.
|
| 57 |
+
|
| 58 |
+
You can dispatch as many requests as is necessary.
|
| 59 |
+
"""
|
| 60 |
+
yield request
|
| 61 |
+
|
| 62 |
+
def sync_auth_flow(
|
| 63 |
+
self, request: Request
|
| 64 |
+
) -> typing.Generator[Request, Response, None]:
|
| 65 |
+
"""
|
| 66 |
+
Execute the authentication flow synchronously.
|
| 67 |
+
|
| 68 |
+
By default, this defers to `.auth_flow()`. You should override this method
|
| 69 |
+
when the authentication scheme does I/O and/or uses concurrency primitives.
|
| 70 |
+
"""
|
| 71 |
+
if self.requires_request_body:
|
| 72 |
+
request.read()
|
| 73 |
+
|
| 74 |
+
flow = self.auth_flow(request)
|
| 75 |
+
request = next(flow)
|
| 76 |
+
|
| 77 |
+
while True:
|
| 78 |
+
response = yield request
|
| 79 |
+
if self.requires_response_body:
|
| 80 |
+
response.read()
|
| 81 |
+
|
| 82 |
+
try:
|
| 83 |
+
request = flow.send(response)
|
| 84 |
+
except StopIteration:
|
| 85 |
+
break
|
| 86 |
+
|
| 87 |
+
async def async_auth_flow(
|
| 88 |
+
self, request: Request
|
| 89 |
+
) -> typing.AsyncGenerator[Request, Response]:
|
| 90 |
+
"""
|
| 91 |
+
Execute the authentication flow asynchronously.
|
| 92 |
+
|
| 93 |
+
By default, this defers to `.auth_flow()`. You should override this method
|
| 94 |
+
when the authentication scheme does I/O and/or uses concurrency primitives.
|
| 95 |
+
"""
|
| 96 |
+
if self.requires_request_body:
|
| 97 |
+
await request.aread()
|
| 98 |
+
|
| 99 |
+
flow = self.auth_flow(request)
|
| 100 |
+
request = next(flow)
|
| 101 |
+
|
| 102 |
+
while True:
|
| 103 |
+
response = yield request
|
| 104 |
+
if self.requires_response_body:
|
| 105 |
+
await response.aread()
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
request = flow.send(response)
|
| 109 |
+
except StopIteration:
|
| 110 |
+
break
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class FunctionAuth(Auth):
|
| 114 |
+
"""
|
| 115 |
+
Allows the 'auth' argument to be passed as a simple callable function,
|
| 116 |
+
that takes the request, and returns a new, modified request.
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
def __init__(self, func: typing.Callable[[Request], Request]) -> None:
|
| 120 |
+
self._func = func
|
| 121 |
+
|
| 122 |
+
def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
|
| 123 |
+
yield self._func(request)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
class BasicAuth(Auth):
|
| 127 |
+
"""
|
| 128 |
+
Allows the 'auth' argument to be passed as a (username, password) pair,
|
| 129 |
+
and uses HTTP Basic authentication.
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
def __init__(self, username: str | bytes, password: str | bytes) -> None:
|
| 133 |
+
self._auth_header = self._build_auth_header(username, password)
|
| 134 |
+
|
| 135 |
+
def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
|
| 136 |
+
request.headers["Authorization"] = self._auth_header
|
| 137 |
+
yield request
|
| 138 |
+
|
| 139 |
+
def _build_auth_header(self, username: str | bytes, password: str | bytes) -> str:
|
| 140 |
+
userpass = b":".join((to_bytes(username), to_bytes(password)))
|
| 141 |
+
token = b64encode(userpass).decode()
|
| 142 |
+
return f"Basic {token}"
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class NetRCAuth(Auth):
|
| 146 |
+
"""
|
| 147 |
+
Use a 'netrc' file to lookup basic auth credentials based on the url host.
|
| 148 |
+
"""
|
| 149 |
+
|
| 150 |
+
def __init__(self, file: str | None = None) -> None:
|
| 151 |
+
# Lazily import 'netrc'.
|
| 152 |
+
# There's no need for us to load this module unless 'NetRCAuth' is being used.
|
| 153 |
+
import netrc
|
| 154 |
+
|
| 155 |
+
self._netrc_info = netrc.netrc(file)
|
| 156 |
+
|
| 157 |
+
def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
|
| 158 |
+
auth_info = self._netrc_info.authenticators(request.url.host)
|
| 159 |
+
if auth_info is None or not auth_info[2]:
|
| 160 |
+
# The netrc file did not have authentication credentials for this host.
|
| 161 |
+
yield request
|
| 162 |
+
else:
|
| 163 |
+
# Build a basic auth header with credentials from the netrc file.
|
| 164 |
+
request.headers["Authorization"] = self._build_auth_header(
|
| 165 |
+
username=auth_info[0], password=auth_info[2]
|
| 166 |
+
)
|
| 167 |
+
yield request
|
| 168 |
+
|
| 169 |
+
def _build_auth_header(self, username: str | bytes, password: str | bytes) -> str:
|
| 170 |
+
userpass = b":".join((to_bytes(username), to_bytes(password)))
|
| 171 |
+
token = b64encode(userpass).decode()
|
| 172 |
+
return f"Basic {token}"
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class DigestAuth(Auth):
|
| 176 |
+
_ALGORITHM_TO_HASH_FUNCTION: dict[str, typing.Callable[[bytes], _Hash]] = {
|
| 177 |
+
"MD5": hashlib.md5,
|
| 178 |
+
"MD5-SESS": hashlib.md5,
|
| 179 |
+
"SHA": hashlib.sha1,
|
| 180 |
+
"SHA-SESS": hashlib.sha1,
|
| 181 |
+
"SHA-256": hashlib.sha256,
|
| 182 |
+
"SHA-256-SESS": hashlib.sha256,
|
| 183 |
+
"SHA-512": hashlib.sha512,
|
| 184 |
+
"SHA-512-SESS": hashlib.sha512,
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
def __init__(self, username: str | bytes, password: str | bytes) -> None:
|
| 188 |
+
self._username = to_bytes(username)
|
| 189 |
+
self._password = to_bytes(password)
|
| 190 |
+
self._last_challenge: _DigestAuthChallenge | None = None
|
| 191 |
+
self._nonce_count = 1
|
| 192 |
+
|
| 193 |
+
def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
|
| 194 |
+
if self._last_challenge:
|
| 195 |
+
request.headers["Authorization"] = self._build_auth_header(
|
| 196 |
+
request, self._last_challenge
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
response = yield request
|
| 200 |
+
|
| 201 |
+
if response.status_code != 401 or "www-authenticate" not in response.headers:
|
| 202 |
+
# If the response is not a 401 then we don't
|
| 203 |
+
# need to build an authenticated request.
|
| 204 |
+
return
|
| 205 |
+
|
| 206 |
+
for auth_header in response.headers.get_list("www-authenticate"):
|
| 207 |
+
if auth_header.lower().startswith("digest "):
|
| 208 |
+
break
|
| 209 |
+
else:
|
| 210 |
+
# If the response does not include a 'WWW-Authenticate: Digest ...'
|
| 211 |
+
# header, then we don't need to build an authenticated request.
|
| 212 |
+
return
|
| 213 |
+
|
| 214 |
+
self._last_challenge = self._parse_challenge(request, response, auth_header)
|
| 215 |
+
self._nonce_count = 1
|
| 216 |
+
|
| 217 |
+
request.headers["Authorization"] = self._build_auth_header(
|
| 218 |
+
request, self._last_challenge
|
| 219 |
+
)
|
| 220 |
+
if response.cookies:
|
| 221 |
+
Cookies(response.cookies).set_cookie_header(request=request)
|
| 222 |
+
yield request
|
| 223 |
+
|
| 224 |
+
def _parse_challenge(
|
| 225 |
+
self, request: Request, response: Response, auth_header: str
|
| 226 |
+
) -> _DigestAuthChallenge:
|
| 227 |
+
"""
|
| 228 |
+
Returns a challenge from a Digest WWW-Authenticate header.
|
| 229 |
+
These take the form of:
|
| 230 |
+
`Digest realm="realm@host.com",qop="auth,auth-int",nonce="abc",opaque="xyz"`
|
| 231 |
+
"""
|
| 232 |
+
scheme, _, fields = auth_header.partition(" ")
|
| 233 |
+
|
| 234 |
+
# This method should only ever have been called with a Digest auth header.
|
| 235 |
+
assert scheme.lower() == "digest"
|
| 236 |
+
|
| 237 |
+
header_dict: dict[str, str] = {}
|
| 238 |
+
for field in parse_http_list(fields):
|
| 239 |
+
key, value = field.strip().split("=", 1)
|
| 240 |
+
header_dict[key] = unquote(value)
|
| 241 |
+
|
| 242 |
+
try:
|
| 243 |
+
realm = header_dict["realm"].encode()
|
| 244 |
+
nonce = header_dict["nonce"].encode()
|
| 245 |
+
algorithm = header_dict.get("algorithm", "MD5")
|
| 246 |
+
opaque = header_dict["opaque"].encode() if "opaque" in header_dict else None
|
| 247 |
+
qop = header_dict["qop"].encode() if "qop" in header_dict else None
|
| 248 |
+
return _DigestAuthChallenge(
|
| 249 |
+
realm=realm, nonce=nonce, algorithm=algorithm, opaque=opaque, qop=qop
|
| 250 |
+
)
|
| 251 |
+
except KeyError as exc:
|
| 252 |
+
message = "Malformed Digest WWW-Authenticate header"
|
| 253 |
+
raise ProtocolError(message, request=request) from exc
|
| 254 |
+
|
| 255 |
+
def _build_auth_header(
|
| 256 |
+
self, request: Request, challenge: _DigestAuthChallenge
|
| 257 |
+
) -> str:
|
| 258 |
+
hash_func = self._ALGORITHM_TO_HASH_FUNCTION[challenge.algorithm.upper()]
|
| 259 |
+
|
| 260 |
+
def digest(data: bytes) -> bytes:
|
| 261 |
+
return hash_func(data).hexdigest().encode()
|
| 262 |
+
|
| 263 |
+
A1 = b":".join((self._username, challenge.realm, self._password))
|
| 264 |
+
|
| 265 |
+
path = request.url.raw_path
|
| 266 |
+
A2 = b":".join((request.method.encode(), path))
|
| 267 |
+
# TODO: implement auth-int
|
| 268 |
+
HA2 = digest(A2)
|
| 269 |
+
|
| 270 |
+
nc_value = b"%08x" % self._nonce_count
|
| 271 |
+
cnonce = self._get_client_nonce(self._nonce_count, challenge.nonce)
|
| 272 |
+
self._nonce_count += 1
|
| 273 |
+
|
| 274 |
+
HA1 = digest(A1)
|
| 275 |
+
if challenge.algorithm.lower().endswith("-sess"):
|
| 276 |
+
HA1 = digest(b":".join((HA1, challenge.nonce, cnonce)))
|
| 277 |
+
|
| 278 |
+
qop = self._resolve_qop(challenge.qop, request=request)
|
| 279 |
+
if qop is None:
|
| 280 |
+
# Following RFC 2069
|
| 281 |
+
digest_data = [HA1, challenge.nonce, HA2]
|
| 282 |
+
else:
|
| 283 |
+
# Following RFC 2617/7616
|
| 284 |
+
digest_data = [HA1, challenge.nonce, nc_value, cnonce, qop, HA2]
|
| 285 |
+
|
| 286 |
+
format_args = {
|
| 287 |
+
"username": self._username,
|
| 288 |
+
"realm": challenge.realm,
|
| 289 |
+
"nonce": challenge.nonce,
|
| 290 |
+
"uri": path,
|
| 291 |
+
"response": digest(b":".join(digest_data)),
|
| 292 |
+
"algorithm": challenge.algorithm.encode(),
|
| 293 |
+
}
|
| 294 |
+
if challenge.opaque:
|
| 295 |
+
format_args["opaque"] = challenge.opaque
|
| 296 |
+
if qop:
|
| 297 |
+
format_args["qop"] = b"auth"
|
| 298 |
+
format_args["nc"] = nc_value
|
| 299 |
+
format_args["cnonce"] = cnonce
|
| 300 |
+
|
| 301 |
+
return "Digest " + self._get_header_value(format_args)
|
| 302 |
+
|
| 303 |
+
def _get_client_nonce(self, nonce_count: int, nonce: bytes) -> bytes:
|
| 304 |
+
s = str(nonce_count).encode()
|
| 305 |
+
s += nonce
|
| 306 |
+
s += time.ctime().encode()
|
| 307 |
+
s += os.urandom(8)
|
| 308 |
+
|
| 309 |
+
return hashlib.sha1(s).hexdigest()[:16].encode()
|
| 310 |
+
|
| 311 |
+
def _get_header_value(self, header_fields: dict[str, bytes]) -> str:
|
| 312 |
+
NON_QUOTED_FIELDS = ("algorithm", "qop", "nc")
|
| 313 |
+
QUOTED_TEMPLATE = '{}="{}"'
|
| 314 |
+
NON_QUOTED_TEMPLATE = "{}={}"
|
| 315 |
+
|
| 316 |
+
header_value = ""
|
| 317 |
+
for i, (field, value) in enumerate(header_fields.items()):
|
| 318 |
+
if i > 0:
|
| 319 |
+
header_value += ", "
|
| 320 |
+
template = (
|
| 321 |
+
QUOTED_TEMPLATE
|
| 322 |
+
if field not in NON_QUOTED_FIELDS
|
| 323 |
+
else NON_QUOTED_TEMPLATE
|
| 324 |
+
)
|
| 325 |
+
header_value += template.format(field, to_str(value))
|
| 326 |
+
|
| 327 |
+
return header_value
|
| 328 |
+
|
| 329 |
+
def _resolve_qop(self, qop: bytes | None, request: Request) -> bytes | None:
|
| 330 |
+
if qop is None:
|
| 331 |
+
return None
|
| 332 |
+
qops = re.split(b", ?", qop)
|
| 333 |
+
if b"auth" in qops:
|
| 334 |
+
return b"auth"
|
| 335 |
+
|
| 336 |
+
if qops == [b"auth-int"]:
|
| 337 |
+
raise NotImplementedError("Digest auth-int support is not yet implemented")
|
| 338 |
+
|
| 339 |
+
message = f'Unexpected qop value "{qop!r}" in digest auth'
|
| 340 |
+
raise ProtocolError(message, request=request)
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
class _DigestAuthChallenge(typing.NamedTuple):
|
| 344 |
+
realm: bytes
|
| 345 |
+
nonce: bytes
|
| 346 |
+
algorithm: str
|
| 347 |
+
opaque: bytes | None
|
| 348 |
+
qop: bytes | None
|
venv/lib/python3.12/site-packages/httpx/_client.py
ADDED
|
@@ -0,0 +1,2019 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import datetime
|
| 4 |
+
import enum
|
| 5 |
+
import logging
|
| 6 |
+
import time
|
| 7 |
+
import typing
|
| 8 |
+
import warnings
|
| 9 |
+
from contextlib import asynccontextmanager, contextmanager
|
| 10 |
+
from types import TracebackType
|
| 11 |
+
|
| 12 |
+
from .__version__ import __version__
|
| 13 |
+
from ._auth import Auth, BasicAuth, FunctionAuth
|
| 14 |
+
from ._config import (
|
| 15 |
+
DEFAULT_LIMITS,
|
| 16 |
+
DEFAULT_MAX_REDIRECTS,
|
| 17 |
+
DEFAULT_TIMEOUT_CONFIG,
|
| 18 |
+
Limits,
|
| 19 |
+
Proxy,
|
| 20 |
+
Timeout,
|
| 21 |
+
)
|
| 22 |
+
from ._decoders import SUPPORTED_DECODERS
|
| 23 |
+
from ._exceptions import (
|
| 24 |
+
InvalidURL,
|
| 25 |
+
RemoteProtocolError,
|
| 26 |
+
TooManyRedirects,
|
| 27 |
+
request_context,
|
| 28 |
+
)
|
| 29 |
+
from ._models import Cookies, Headers, Request, Response
|
| 30 |
+
from ._status_codes import codes
|
| 31 |
+
from ._transports.base import AsyncBaseTransport, BaseTransport
|
| 32 |
+
from ._transports.default import AsyncHTTPTransport, HTTPTransport
|
| 33 |
+
from ._types import (
|
| 34 |
+
AsyncByteStream,
|
| 35 |
+
AuthTypes,
|
| 36 |
+
CertTypes,
|
| 37 |
+
CookieTypes,
|
| 38 |
+
HeaderTypes,
|
| 39 |
+
ProxyTypes,
|
| 40 |
+
QueryParamTypes,
|
| 41 |
+
RequestContent,
|
| 42 |
+
RequestData,
|
| 43 |
+
RequestExtensions,
|
| 44 |
+
RequestFiles,
|
| 45 |
+
SyncByteStream,
|
| 46 |
+
TimeoutTypes,
|
| 47 |
+
)
|
| 48 |
+
from ._urls import URL, QueryParams
|
| 49 |
+
from ._utils import URLPattern, get_environment_proxies
|
| 50 |
+
|
| 51 |
+
if typing.TYPE_CHECKING:
|
| 52 |
+
import ssl # pragma: no cover
|
| 53 |
+
|
| 54 |
+
__all__ = ["USE_CLIENT_DEFAULT", "AsyncClient", "Client"]
|
| 55 |
+
|
| 56 |
+
# The type annotation for @classmethod and context managers here follows PEP 484
|
| 57 |
+
# https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods
|
| 58 |
+
T = typing.TypeVar("T", bound="Client")
|
| 59 |
+
U = typing.TypeVar("U", bound="AsyncClient")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _is_https_redirect(url: URL, location: URL) -> bool:
|
| 63 |
+
"""
|
| 64 |
+
Return 'True' if 'location' is a HTTPS upgrade of 'url'
|
| 65 |
+
"""
|
| 66 |
+
if url.host != location.host:
|
| 67 |
+
return False
|
| 68 |
+
|
| 69 |
+
return (
|
| 70 |
+
url.scheme == "http"
|
| 71 |
+
and _port_or_default(url) == 80
|
| 72 |
+
and location.scheme == "https"
|
| 73 |
+
and _port_or_default(location) == 443
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _port_or_default(url: URL) -> int | None:
|
| 78 |
+
if url.port is not None:
|
| 79 |
+
return url.port
|
| 80 |
+
return {"http": 80, "https": 443}.get(url.scheme)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _same_origin(url: URL, other: URL) -> bool:
|
| 84 |
+
"""
|
| 85 |
+
Return 'True' if the given URLs share the same origin.
|
| 86 |
+
"""
|
| 87 |
+
return (
|
| 88 |
+
url.scheme == other.scheme
|
| 89 |
+
and url.host == other.host
|
| 90 |
+
and _port_or_default(url) == _port_or_default(other)
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class UseClientDefault:
|
| 95 |
+
"""
|
| 96 |
+
For some parameters such as `auth=...` and `timeout=...` we need to be able
|
| 97 |
+
to indicate the default "unset" state, in a way that is distinctly different
|
| 98 |
+
to using `None`.
|
| 99 |
+
|
| 100 |
+
The default "unset" state indicates that whatever default is set on the
|
| 101 |
+
client should be used. This is different to setting `None`, which
|
| 102 |
+
explicitly disables the parameter, possibly overriding a client default.
|
| 103 |
+
|
| 104 |
+
For example we use `timeout=USE_CLIENT_DEFAULT` in the `request()` signature.
|
| 105 |
+
Omitting the `timeout` parameter will send a request using whatever default
|
| 106 |
+
timeout has been configured on the client. Including `timeout=None` will
|
| 107 |
+
ensure no timeout is used.
|
| 108 |
+
|
| 109 |
+
Note that user code shouldn't need to use the `USE_CLIENT_DEFAULT` constant,
|
| 110 |
+
but it is used internally when a parameter is not included.
|
| 111 |
+
"""
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
USE_CLIENT_DEFAULT = UseClientDefault()
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
logger = logging.getLogger("httpx")
|
| 118 |
+
|
| 119 |
+
USER_AGENT = f"python-httpx/{__version__}"
|
| 120 |
+
ACCEPT_ENCODING = ", ".join(
|
| 121 |
+
[key for key in SUPPORTED_DECODERS.keys() if key != "identity"]
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class ClientState(enum.Enum):
|
| 126 |
+
# UNOPENED:
|
| 127 |
+
# The client has been instantiated, but has not been used to send a request,
|
| 128 |
+
# or been opened by entering the context of a `with` block.
|
| 129 |
+
UNOPENED = 1
|
| 130 |
+
# OPENED:
|
| 131 |
+
# The client has either sent a request, or is within a `with` block.
|
| 132 |
+
OPENED = 2
|
| 133 |
+
# CLOSED:
|
| 134 |
+
# The client has either exited the `with` block, or `close()` has
|
| 135 |
+
# been called explicitly.
|
| 136 |
+
CLOSED = 3
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
class BoundSyncStream(SyncByteStream):
|
| 140 |
+
"""
|
| 141 |
+
A byte stream that is bound to a given response instance, and that
|
| 142 |
+
ensures the `response.elapsed` is set once the response is closed.
|
| 143 |
+
"""
|
| 144 |
+
|
| 145 |
+
def __init__(
|
| 146 |
+
self, stream: SyncByteStream, response: Response, start: float
|
| 147 |
+
) -> None:
|
| 148 |
+
self._stream = stream
|
| 149 |
+
self._response = response
|
| 150 |
+
self._start = start
|
| 151 |
+
|
| 152 |
+
def __iter__(self) -> typing.Iterator[bytes]:
|
| 153 |
+
for chunk in self._stream:
|
| 154 |
+
yield chunk
|
| 155 |
+
|
| 156 |
+
def close(self) -> None:
|
| 157 |
+
elapsed = time.perf_counter() - self._start
|
| 158 |
+
self._response.elapsed = datetime.timedelta(seconds=elapsed)
|
| 159 |
+
self._stream.close()
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class BoundAsyncStream(AsyncByteStream):
|
| 163 |
+
"""
|
| 164 |
+
An async byte stream that is bound to a given response instance, and that
|
| 165 |
+
ensures the `response.elapsed` is set once the response is closed.
|
| 166 |
+
"""
|
| 167 |
+
|
| 168 |
+
def __init__(
|
| 169 |
+
self, stream: AsyncByteStream, response: Response, start: float
|
| 170 |
+
) -> None:
|
| 171 |
+
self._stream = stream
|
| 172 |
+
self._response = response
|
| 173 |
+
self._start = start
|
| 174 |
+
|
| 175 |
+
async def __aiter__(self) -> typing.AsyncIterator[bytes]:
|
| 176 |
+
async for chunk in self._stream:
|
| 177 |
+
yield chunk
|
| 178 |
+
|
| 179 |
+
async def aclose(self) -> None:
|
| 180 |
+
elapsed = time.perf_counter() - self._start
|
| 181 |
+
self._response.elapsed = datetime.timedelta(seconds=elapsed)
|
| 182 |
+
await self._stream.aclose()
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
EventHook = typing.Callable[..., typing.Any]
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class BaseClient:
|
| 189 |
+
def __init__(
|
| 190 |
+
self,
|
| 191 |
+
*,
|
| 192 |
+
auth: AuthTypes | None = None,
|
| 193 |
+
params: QueryParamTypes | None = None,
|
| 194 |
+
headers: HeaderTypes | None = None,
|
| 195 |
+
cookies: CookieTypes | None = None,
|
| 196 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 197 |
+
follow_redirects: bool = False,
|
| 198 |
+
max_redirects: int = DEFAULT_MAX_REDIRECTS,
|
| 199 |
+
event_hooks: None | (typing.Mapping[str, list[EventHook]]) = None,
|
| 200 |
+
base_url: URL | str = "",
|
| 201 |
+
trust_env: bool = True,
|
| 202 |
+
default_encoding: str | typing.Callable[[bytes], str] = "utf-8",
|
| 203 |
+
) -> None:
|
| 204 |
+
event_hooks = {} if event_hooks is None else event_hooks
|
| 205 |
+
|
| 206 |
+
self._base_url = self._enforce_trailing_slash(URL(base_url))
|
| 207 |
+
|
| 208 |
+
self._auth = self._build_auth(auth)
|
| 209 |
+
self._params = QueryParams(params)
|
| 210 |
+
self.headers = Headers(headers)
|
| 211 |
+
self._cookies = Cookies(cookies)
|
| 212 |
+
self._timeout = Timeout(timeout)
|
| 213 |
+
self.follow_redirects = follow_redirects
|
| 214 |
+
self.max_redirects = max_redirects
|
| 215 |
+
self._event_hooks = {
|
| 216 |
+
"request": list(event_hooks.get("request", [])),
|
| 217 |
+
"response": list(event_hooks.get("response", [])),
|
| 218 |
+
}
|
| 219 |
+
self._trust_env = trust_env
|
| 220 |
+
self._default_encoding = default_encoding
|
| 221 |
+
self._state = ClientState.UNOPENED
|
| 222 |
+
|
| 223 |
+
@property
|
| 224 |
+
def is_closed(self) -> bool:
|
| 225 |
+
"""
|
| 226 |
+
Check if the client being closed
|
| 227 |
+
"""
|
| 228 |
+
return self._state == ClientState.CLOSED
|
| 229 |
+
|
| 230 |
+
@property
|
| 231 |
+
def trust_env(self) -> bool:
|
| 232 |
+
return self._trust_env
|
| 233 |
+
|
| 234 |
+
def _enforce_trailing_slash(self, url: URL) -> URL:
|
| 235 |
+
if url.raw_path.endswith(b"/"):
|
| 236 |
+
return url
|
| 237 |
+
return url.copy_with(raw_path=url.raw_path + b"/")
|
| 238 |
+
|
| 239 |
+
def _get_proxy_map(
|
| 240 |
+
self, proxy: ProxyTypes | None, allow_env_proxies: bool
|
| 241 |
+
) -> dict[str, Proxy | None]:
|
| 242 |
+
if proxy is None:
|
| 243 |
+
if allow_env_proxies:
|
| 244 |
+
return {
|
| 245 |
+
key: None if url is None else Proxy(url=url)
|
| 246 |
+
for key, url in get_environment_proxies().items()
|
| 247 |
+
}
|
| 248 |
+
return {}
|
| 249 |
+
else:
|
| 250 |
+
proxy = Proxy(url=proxy) if isinstance(proxy, (str, URL)) else proxy
|
| 251 |
+
return {"all://": proxy}
|
| 252 |
+
|
| 253 |
+
@property
|
| 254 |
+
def timeout(self) -> Timeout:
|
| 255 |
+
return self._timeout
|
| 256 |
+
|
| 257 |
+
@timeout.setter
|
| 258 |
+
def timeout(self, timeout: TimeoutTypes) -> None:
|
| 259 |
+
self._timeout = Timeout(timeout)
|
| 260 |
+
|
| 261 |
+
@property
|
| 262 |
+
def event_hooks(self) -> dict[str, list[EventHook]]:
|
| 263 |
+
return self._event_hooks
|
| 264 |
+
|
| 265 |
+
@event_hooks.setter
|
| 266 |
+
def event_hooks(self, event_hooks: dict[str, list[EventHook]]) -> None:
|
| 267 |
+
self._event_hooks = {
|
| 268 |
+
"request": list(event_hooks.get("request", [])),
|
| 269 |
+
"response": list(event_hooks.get("response", [])),
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
@property
|
| 273 |
+
def auth(self) -> Auth | None:
|
| 274 |
+
"""
|
| 275 |
+
Authentication class used when none is passed at the request-level.
|
| 276 |
+
|
| 277 |
+
See also [Authentication][0].
|
| 278 |
+
|
| 279 |
+
[0]: /quickstart/#authentication
|
| 280 |
+
"""
|
| 281 |
+
return self._auth
|
| 282 |
+
|
| 283 |
+
@auth.setter
|
| 284 |
+
def auth(self, auth: AuthTypes) -> None:
|
| 285 |
+
self._auth = self._build_auth(auth)
|
| 286 |
+
|
| 287 |
+
@property
|
| 288 |
+
def base_url(self) -> URL:
|
| 289 |
+
"""
|
| 290 |
+
Base URL to use when sending requests with relative URLs.
|
| 291 |
+
"""
|
| 292 |
+
return self._base_url
|
| 293 |
+
|
| 294 |
+
@base_url.setter
|
| 295 |
+
def base_url(self, url: URL | str) -> None:
|
| 296 |
+
self._base_url = self._enforce_trailing_slash(URL(url))
|
| 297 |
+
|
| 298 |
+
@property
|
| 299 |
+
def headers(self) -> Headers:
|
| 300 |
+
"""
|
| 301 |
+
HTTP headers to include when sending requests.
|
| 302 |
+
"""
|
| 303 |
+
return self._headers
|
| 304 |
+
|
| 305 |
+
@headers.setter
|
| 306 |
+
def headers(self, headers: HeaderTypes) -> None:
|
| 307 |
+
client_headers = Headers(
|
| 308 |
+
{
|
| 309 |
+
b"Accept": b"*/*",
|
| 310 |
+
b"Accept-Encoding": ACCEPT_ENCODING.encode("ascii"),
|
| 311 |
+
b"Connection": b"keep-alive",
|
| 312 |
+
b"User-Agent": USER_AGENT.encode("ascii"),
|
| 313 |
+
}
|
| 314 |
+
)
|
| 315 |
+
client_headers.update(headers)
|
| 316 |
+
self._headers = client_headers
|
| 317 |
+
|
| 318 |
+
@property
|
| 319 |
+
def cookies(self) -> Cookies:
|
| 320 |
+
"""
|
| 321 |
+
Cookie values to include when sending requests.
|
| 322 |
+
"""
|
| 323 |
+
return self._cookies
|
| 324 |
+
|
| 325 |
+
@cookies.setter
|
| 326 |
+
def cookies(self, cookies: CookieTypes) -> None:
|
| 327 |
+
self._cookies = Cookies(cookies)
|
| 328 |
+
|
| 329 |
+
@property
|
| 330 |
+
def params(self) -> QueryParams:
|
| 331 |
+
"""
|
| 332 |
+
Query parameters to include in the URL when sending requests.
|
| 333 |
+
"""
|
| 334 |
+
return self._params
|
| 335 |
+
|
| 336 |
+
@params.setter
|
| 337 |
+
def params(self, params: QueryParamTypes) -> None:
|
| 338 |
+
self._params = QueryParams(params)
|
| 339 |
+
|
| 340 |
+
def build_request(
|
| 341 |
+
self,
|
| 342 |
+
method: str,
|
| 343 |
+
url: URL | str,
|
| 344 |
+
*,
|
| 345 |
+
content: RequestContent | None = None,
|
| 346 |
+
data: RequestData | None = None,
|
| 347 |
+
files: RequestFiles | None = None,
|
| 348 |
+
json: typing.Any | None = None,
|
| 349 |
+
params: QueryParamTypes | None = None,
|
| 350 |
+
headers: HeaderTypes | None = None,
|
| 351 |
+
cookies: CookieTypes | None = None,
|
| 352 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 353 |
+
extensions: RequestExtensions | None = None,
|
| 354 |
+
) -> Request:
|
| 355 |
+
"""
|
| 356 |
+
Build and return a request instance.
|
| 357 |
+
|
| 358 |
+
* The `params`, `headers` and `cookies` arguments
|
| 359 |
+
are merged with any values set on the client.
|
| 360 |
+
* The `url` argument is merged with any `base_url` set on the client.
|
| 361 |
+
|
| 362 |
+
See also: [Request instances][0]
|
| 363 |
+
|
| 364 |
+
[0]: /advanced/clients/#request-instances
|
| 365 |
+
"""
|
| 366 |
+
url = self._merge_url(url)
|
| 367 |
+
headers = self._merge_headers(headers)
|
| 368 |
+
cookies = self._merge_cookies(cookies)
|
| 369 |
+
params = self._merge_queryparams(params)
|
| 370 |
+
extensions = {} if extensions is None else extensions
|
| 371 |
+
if "timeout" not in extensions:
|
| 372 |
+
timeout = (
|
| 373 |
+
self.timeout
|
| 374 |
+
if isinstance(timeout, UseClientDefault)
|
| 375 |
+
else Timeout(timeout)
|
| 376 |
+
)
|
| 377 |
+
extensions = dict(**extensions, timeout=timeout.as_dict())
|
| 378 |
+
return Request(
|
| 379 |
+
method,
|
| 380 |
+
url,
|
| 381 |
+
content=content,
|
| 382 |
+
data=data,
|
| 383 |
+
files=files,
|
| 384 |
+
json=json,
|
| 385 |
+
params=params,
|
| 386 |
+
headers=headers,
|
| 387 |
+
cookies=cookies,
|
| 388 |
+
extensions=extensions,
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
def _merge_url(self, url: URL | str) -> URL:
|
| 392 |
+
"""
|
| 393 |
+
Merge a URL argument together with any 'base_url' on the client,
|
| 394 |
+
to create the URL used for the outgoing request.
|
| 395 |
+
"""
|
| 396 |
+
merge_url = URL(url)
|
| 397 |
+
if merge_url.is_relative_url:
|
| 398 |
+
# To merge URLs we always append to the base URL. To get this
|
| 399 |
+
# behaviour correct we always ensure the base URL ends in a '/'
|
| 400 |
+
# separator, and strip any leading '/' from the merge URL.
|
| 401 |
+
#
|
| 402 |
+
# So, eg...
|
| 403 |
+
#
|
| 404 |
+
# >>> client = Client(base_url="https://www.example.com/subpath")
|
| 405 |
+
# >>> client.base_url
|
| 406 |
+
# URL('https://www.example.com/subpath/')
|
| 407 |
+
# >>> client.build_request("GET", "/path").url
|
| 408 |
+
# URL('https://www.example.com/subpath/path')
|
| 409 |
+
merge_raw_path = self.base_url.raw_path + merge_url.raw_path.lstrip(b"/")
|
| 410 |
+
return self.base_url.copy_with(raw_path=merge_raw_path)
|
| 411 |
+
return merge_url
|
| 412 |
+
|
| 413 |
+
def _merge_cookies(self, cookies: CookieTypes | None = None) -> CookieTypes | None:
|
| 414 |
+
"""
|
| 415 |
+
Merge a cookies argument together with any cookies on the client,
|
| 416 |
+
to create the cookies used for the outgoing request.
|
| 417 |
+
"""
|
| 418 |
+
if cookies or self.cookies:
|
| 419 |
+
merged_cookies = Cookies(self.cookies)
|
| 420 |
+
merged_cookies.update(cookies)
|
| 421 |
+
return merged_cookies
|
| 422 |
+
return cookies
|
| 423 |
+
|
| 424 |
+
def _merge_headers(self, headers: HeaderTypes | None = None) -> HeaderTypes | None:
|
| 425 |
+
"""
|
| 426 |
+
Merge a headers argument together with any headers on the client,
|
| 427 |
+
to create the headers used for the outgoing request.
|
| 428 |
+
"""
|
| 429 |
+
merged_headers = Headers(self.headers)
|
| 430 |
+
merged_headers.update(headers)
|
| 431 |
+
return merged_headers
|
| 432 |
+
|
| 433 |
+
def _merge_queryparams(
|
| 434 |
+
self, params: QueryParamTypes | None = None
|
| 435 |
+
) -> QueryParamTypes | None:
|
| 436 |
+
"""
|
| 437 |
+
Merge a queryparams argument together with any queryparams on the client,
|
| 438 |
+
to create the queryparams used for the outgoing request.
|
| 439 |
+
"""
|
| 440 |
+
if params or self.params:
|
| 441 |
+
merged_queryparams = QueryParams(self.params)
|
| 442 |
+
return merged_queryparams.merge(params)
|
| 443 |
+
return params
|
| 444 |
+
|
| 445 |
+
def _build_auth(self, auth: AuthTypes | None) -> Auth | None:
|
| 446 |
+
if auth is None:
|
| 447 |
+
return None
|
| 448 |
+
elif isinstance(auth, tuple):
|
| 449 |
+
return BasicAuth(username=auth[0], password=auth[1])
|
| 450 |
+
elif isinstance(auth, Auth):
|
| 451 |
+
return auth
|
| 452 |
+
elif callable(auth):
|
| 453 |
+
return FunctionAuth(func=auth)
|
| 454 |
+
else:
|
| 455 |
+
raise TypeError(f'Invalid "auth" argument: {auth!r}')
|
| 456 |
+
|
| 457 |
+
def _build_request_auth(
|
| 458 |
+
self,
|
| 459 |
+
request: Request,
|
| 460 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 461 |
+
) -> Auth:
|
| 462 |
+
auth = (
|
| 463 |
+
self._auth if isinstance(auth, UseClientDefault) else self._build_auth(auth)
|
| 464 |
+
)
|
| 465 |
+
|
| 466 |
+
if auth is not None:
|
| 467 |
+
return auth
|
| 468 |
+
|
| 469 |
+
username, password = request.url.username, request.url.password
|
| 470 |
+
if username or password:
|
| 471 |
+
return BasicAuth(username=username, password=password)
|
| 472 |
+
|
| 473 |
+
return Auth()
|
| 474 |
+
|
| 475 |
+
def _build_redirect_request(self, request: Request, response: Response) -> Request:
|
| 476 |
+
"""
|
| 477 |
+
Given a request and a redirect response, return a new request that
|
| 478 |
+
should be used to effect the redirect.
|
| 479 |
+
"""
|
| 480 |
+
method = self._redirect_method(request, response)
|
| 481 |
+
url = self._redirect_url(request, response)
|
| 482 |
+
headers = self._redirect_headers(request, url, method)
|
| 483 |
+
stream = self._redirect_stream(request, method)
|
| 484 |
+
cookies = Cookies(self.cookies)
|
| 485 |
+
return Request(
|
| 486 |
+
method=method,
|
| 487 |
+
url=url,
|
| 488 |
+
headers=headers,
|
| 489 |
+
cookies=cookies,
|
| 490 |
+
stream=stream,
|
| 491 |
+
extensions=request.extensions,
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
def _redirect_method(self, request: Request, response: Response) -> str:
|
| 495 |
+
"""
|
| 496 |
+
When being redirected we may want to change the method of the request
|
| 497 |
+
based on certain specs or browser behavior.
|
| 498 |
+
"""
|
| 499 |
+
method = request.method
|
| 500 |
+
|
| 501 |
+
# https://tools.ietf.org/html/rfc7231#section-6.4.4
|
| 502 |
+
if response.status_code == codes.SEE_OTHER and method != "HEAD":
|
| 503 |
+
method = "GET"
|
| 504 |
+
|
| 505 |
+
# Do what the browsers do, despite standards...
|
| 506 |
+
# Turn 302s into GETs.
|
| 507 |
+
if response.status_code == codes.FOUND and method != "HEAD":
|
| 508 |
+
method = "GET"
|
| 509 |
+
|
| 510 |
+
# If a POST is responded to with a 301, turn it into a GET.
|
| 511 |
+
# This bizarre behaviour is explained in 'requests' issue 1704.
|
| 512 |
+
if response.status_code == codes.MOVED_PERMANENTLY and method == "POST":
|
| 513 |
+
method = "GET"
|
| 514 |
+
|
| 515 |
+
return method
|
| 516 |
+
|
| 517 |
+
def _redirect_url(self, request: Request, response: Response) -> URL:
|
| 518 |
+
"""
|
| 519 |
+
Return the URL for the redirect to follow.
|
| 520 |
+
"""
|
| 521 |
+
location = response.headers["Location"]
|
| 522 |
+
|
| 523 |
+
try:
|
| 524 |
+
url = URL(location)
|
| 525 |
+
except InvalidURL as exc:
|
| 526 |
+
raise RemoteProtocolError(
|
| 527 |
+
f"Invalid URL in location header: {exc}.", request=request
|
| 528 |
+
) from None
|
| 529 |
+
|
| 530 |
+
# Handle malformed 'Location' headers that are "absolute" form, have no host.
|
| 531 |
+
# See: https://github.com/encode/httpx/issues/771
|
| 532 |
+
if url.scheme and not url.host:
|
| 533 |
+
url = url.copy_with(host=request.url.host)
|
| 534 |
+
|
| 535 |
+
# Facilitate relative 'Location' headers, as allowed by RFC 7231.
|
| 536 |
+
# (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')
|
| 537 |
+
if url.is_relative_url:
|
| 538 |
+
url = request.url.join(url)
|
| 539 |
+
|
| 540 |
+
# Attach previous fragment if needed (RFC 7231 7.1.2)
|
| 541 |
+
if request.url.fragment and not url.fragment:
|
| 542 |
+
url = url.copy_with(fragment=request.url.fragment)
|
| 543 |
+
|
| 544 |
+
return url
|
| 545 |
+
|
| 546 |
+
def _redirect_headers(self, request: Request, url: URL, method: str) -> Headers:
|
| 547 |
+
"""
|
| 548 |
+
Return the headers that should be used for the redirect request.
|
| 549 |
+
"""
|
| 550 |
+
headers = Headers(request.headers)
|
| 551 |
+
|
| 552 |
+
if not _same_origin(url, request.url):
|
| 553 |
+
if not _is_https_redirect(request.url, url):
|
| 554 |
+
# Strip Authorization headers when responses are redirected
|
| 555 |
+
# away from the origin. (Except for direct HTTP to HTTPS redirects.)
|
| 556 |
+
headers.pop("Authorization", None)
|
| 557 |
+
|
| 558 |
+
# Update the Host header.
|
| 559 |
+
headers["Host"] = url.netloc.decode("ascii")
|
| 560 |
+
|
| 561 |
+
if method != request.method and method == "GET":
|
| 562 |
+
# If we've switch to a 'GET' request, then strip any headers which
|
| 563 |
+
# are only relevant to the request body.
|
| 564 |
+
headers.pop("Content-Length", None)
|
| 565 |
+
headers.pop("Transfer-Encoding", None)
|
| 566 |
+
|
| 567 |
+
# We should use the client cookie store to determine any cookie header,
|
| 568 |
+
# rather than whatever was on the original outgoing request.
|
| 569 |
+
headers.pop("Cookie", None)
|
| 570 |
+
|
| 571 |
+
return headers
|
| 572 |
+
|
| 573 |
+
def _redirect_stream(
|
| 574 |
+
self, request: Request, method: str
|
| 575 |
+
) -> SyncByteStream | AsyncByteStream | None:
|
| 576 |
+
"""
|
| 577 |
+
Return the body that should be used for the redirect request.
|
| 578 |
+
"""
|
| 579 |
+
if method != request.method and method == "GET":
|
| 580 |
+
return None
|
| 581 |
+
|
| 582 |
+
return request.stream
|
| 583 |
+
|
| 584 |
+
def _set_timeout(self, request: Request) -> None:
|
| 585 |
+
if "timeout" not in request.extensions:
|
| 586 |
+
timeout = (
|
| 587 |
+
self.timeout
|
| 588 |
+
if isinstance(self.timeout, UseClientDefault)
|
| 589 |
+
else Timeout(self.timeout)
|
| 590 |
+
)
|
| 591 |
+
request.extensions = dict(**request.extensions, timeout=timeout.as_dict())
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
class Client(BaseClient):
|
| 595 |
+
"""
|
| 596 |
+
An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.
|
| 597 |
+
|
| 598 |
+
It can be shared between threads.
|
| 599 |
+
|
| 600 |
+
Usage:
|
| 601 |
+
|
| 602 |
+
```python
|
| 603 |
+
>>> client = httpx.Client()
|
| 604 |
+
>>> response = client.get('https://example.org')
|
| 605 |
+
```
|
| 606 |
+
|
| 607 |
+
**Parameters:**
|
| 608 |
+
|
| 609 |
+
* **auth** - *(optional)* An authentication class to use when sending
|
| 610 |
+
requests.
|
| 611 |
+
* **params** - *(optional)* Query parameters to include in request URLs, as
|
| 612 |
+
a string, dictionary, or sequence of two-tuples.
|
| 613 |
+
* **headers** - *(optional)* Dictionary of HTTP headers to include when
|
| 614 |
+
sending requests.
|
| 615 |
+
* **cookies** - *(optional)* Dictionary of Cookie items to include when
|
| 616 |
+
sending requests.
|
| 617 |
+
* **verify** - *(optional)* Either `True` to use an SSL context with the
|
| 618 |
+
default CA bundle, `False` to disable verification, or an instance of
|
| 619 |
+
`ssl.SSLContext` to use a custom context.
|
| 620 |
+
* **http2** - *(optional)* A boolean indicating if HTTP/2 support should be
|
| 621 |
+
enabled. Defaults to `False`.
|
| 622 |
+
* **proxy** - *(optional)* A proxy URL where all the traffic should be routed.
|
| 623 |
+
* **timeout** - *(optional)* The timeout configuration to use when sending
|
| 624 |
+
requests.
|
| 625 |
+
* **limits** - *(optional)* The limits configuration to use.
|
| 626 |
+
* **max_redirects** - *(optional)* The maximum number of redirect responses
|
| 627 |
+
that should be followed.
|
| 628 |
+
* **base_url** - *(optional)* A URL to use as the base when building
|
| 629 |
+
request URLs.
|
| 630 |
+
* **transport** - *(optional)* A transport class to use for sending requests
|
| 631 |
+
over the network.
|
| 632 |
+
* **trust_env** - *(optional)* Enables or disables usage of environment
|
| 633 |
+
variables for configuration.
|
| 634 |
+
* **default_encoding** - *(optional)* The default encoding to use for decoding
|
| 635 |
+
response text, if no charset information is included in a response Content-Type
|
| 636 |
+
header. Set to a callable for automatic character set detection. Default: "utf-8".
|
| 637 |
+
"""
|
| 638 |
+
|
| 639 |
+
def __init__(
|
| 640 |
+
self,
|
| 641 |
+
*,
|
| 642 |
+
auth: AuthTypes | None = None,
|
| 643 |
+
params: QueryParamTypes | None = None,
|
| 644 |
+
headers: HeaderTypes | None = None,
|
| 645 |
+
cookies: CookieTypes | None = None,
|
| 646 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 647 |
+
cert: CertTypes | None = None,
|
| 648 |
+
trust_env: bool = True,
|
| 649 |
+
http1: bool = True,
|
| 650 |
+
http2: bool = False,
|
| 651 |
+
proxy: ProxyTypes | None = None,
|
| 652 |
+
mounts: None | (typing.Mapping[str, BaseTransport | None]) = None,
|
| 653 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 654 |
+
follow_redirects: bool = False,
|
| 655 |
+
limits: Limits = DEFAULT_LIMITS,
|
| 656 |
+
max_redirects: int = DEFAULT_MAX_REDIRECTS,
|
| 657 |
+
event_hooks: None | (typing.Mapping[str, list[EventHook]]) = None,
|
| 658 |
+
base_url: URL | str = "",
|
| 659 |
+
transport: BaseTransport | None = None,
|
| 660 |
+
default_encoding: str | typing.Callable[[bytes], str] = "utf-8",
|
| 661 |
+
) -> None:
|
| 662 |
+
super().__init__(
|
| 663 |
+
auth=auth,
|
| 664 |
+
params=params,
|
| 665 |
+
headers=headers,
|
| 666 |
+
cookies=cookies,
|
| 667 |
+
timeout=timeout,
|
| 668 |
+
follow_redirects=follow_redirects,
|
| 669 |
+
max_redirects=max_redirects,
|
| 670 |
+
event_hooks=event_hooks,
|
| 671 |
+
base_url=base_url,
|
| 672 |
+
trust_env=trust_env,
|
| 673 |
+
default_encoding=default_encoding,
|
| 674 |
+
)
|
| 675 |
+
|
| 676 |
+
if http2:
|
| 677 |
+
try:
|
| 678 |
+
import h2 # noqa
|
| 679 |
+
except ImportError: # pragma: no cover
|
| 680 |
+
raise ImportError(
|
| 681 |
+
"Using http2=True, but the 'h2' package is not installed. "
|
| 682 |
+
"Make sure to install httpx using `pip install httpx[http2]`."
|
| 683 |
+
) from None
|
| 684 |
+
|
| 685 |
+
allow_env_proxies = trust_env and transport is None
|
| 686 |
+
proxy_map = self._get_proxy_map(proxy, allow_env_proxies)
|
| 687 |
+
|
| 688 |
+
self._transport = self._init_transport(
|
| 689 |
+
verify=verify,
|
| 690 |
+
cert=cert,
|
| 691 |
+
trust_env=trust_env,
|
| 692 |
+
http1=http1,
|
| 693 |
+
http2=http2,
|
| 694 |
+
limits=limits,
|
| 695 |
+
transport=transport,
|
| 696 |
+
)
|
| 697 |
+
self._mounts: dict[URLPattern, BaseTransport | None] = {
|
| 698 |
+
URLPattern(key): None
|
| 699 |
+
if proxy is None
|
| 700 |
+
else self._init_proxy_transport(
|
| 701 |
+
proxy,
|
| 702 |
+
verify=verify,
|
| 703 |
+
cert=cert,
|
| 704 |
+
trust_env=trust_env,
|
| 705 |
+
http1=http1,
|
| 706 |
+
http2=http2,
|
| 707 |
+
limits=limits,
|
| 708 |
+
)
|
| 709 |
+
for key, proxy in proxy_map.items()
|
| 710 |
+
}
|
| 711 |
+
if mounts is not None:
|
| 712 |
+
self._mounts.update(
|
| 713 |
+
{URLPattern(key): transport for key, transport in mounts.items()}
|
| 714 |
+
)
|
| 715 |
+
|
| 716 |
+
self._mounts = dict(sorted(self._mounts.items()))
|
| 717 |
+
|
| 718 |
+
def _init_transport(
|
| 719 |
+
self,
|
| 720 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 721 |
+
cert: CertTypes | None = None,
|
| 722 |
+
trust_env: bool = True,
|
| 723 |
+
http1: bool = True,
|
| 724 |
+
http2: bool = False,
|
| 725 |
+
limits: Limits = DEFAULT_LIMITS,
|
| 726 |
+
transport: BaseTransport | None = None,
|
| 727 |
+
) -> BaseTransport:
|
| 728 |
+
if transport is not None:
|
| 729 |
+
return transport
|
| 730 |
+
|
| 731 |
+
return HTTPTransport(
|
| 732 |
+
verify=verify,
|
| 733 |
+
cert=cert,
|
| 734 |
+
trust_env=trust_env,
|
| 735 |
+
http1=http1,
|
| 736 |
+
http2=http2,
|
| 737 |
+
limits=limits,
|
| 738 |
+
)
|
| 739 |
+
|
| 740 |
+
def _init_proxy_transport(
|
| 741 |
+
self,
|
| 742 |
+
proxy: Proxy,
|
| 743 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 744 |
+
cert: CertTypes | None = None,
|
| 745 |
+
trust_env: bool = True,
|
| 746 |
+
http1: bool = True,
|
| 747 |
+
http2: bool = False,
|
| 748 |
+
limits: Limits = DEFAULT_LIMITS,
|
| 749 |
+
) -> BaseTransport:
|
| 750 |
+
return HTTPTransport(
|
| 751 |
+
verify=verify,
|
| 752 |
+
cert=cert,
|
| 753 |
+
trust_env=trust_env,
|
| 754 |
+
http1=http1,
|
| 755 |
+
http2=http2,
|
| 756 |
+
limits=limits,
|
| 757 |
+
proxy=proxy,
|
| 758 |
+
)
|
| 759 |
+
|
| 760 |
+
def _transport_for_url(self, url: URL) -> BaseTransport:
|
| 761 |
+
"""
|
| 762 |
+
Returns the transport instance that should be used for a given URL.
|
| 763 |
+
This will either be the standard connection pool, or a proxy.
|
| 764 |
+
"""
|
| 765 |
+
for pattern, transport in self._mounts.items():
|
| 766 |
+
if pattern.matches(url):
|
| 767 |
+
return self._transport if transport is None else transport
|
| 768 |
+
|
| 769 |
+
return self._transport
|
| 770 |
+
|
| 771 |
+
def request(
|
| 772 |
+
self,
|
| 773 |
+
method: str,
|
| 774 |
+
url: URL | str,
|
| 775 |
+
*,
|
| 776 |
+
content: RequestContent | None = None,
|
| 777 |
+
data: RequestData | None = None,
|
| 778 |
+
files: RequestFiles | None = None,
|
| 779 |
+
json: typing.Any | None = None,
|
| 780 |
+
params: QueryParamTypes | None = None,
|
| 781 |
+
headers: HeaderTypes | None = None,
|
| 782 |
+
cookies: CookieTypes | None = None,
|
| 783 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 784 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 785 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 786 |
+
extensions: RequestExtensions | None = None,
|
| 787 |
+
) -> Response:
|
| 788 |
+
"""
|
| 789 |
+
Build and send a request.
|
| 790 |
+
|
| 791 |
+
Equivalent to:
|
| 792 |
+
|
| 793 |
+
```python
|
| 794 |
+
request = client.build_request(...)
|
| 795 |
+
response = client.send(request, ...)
|
| 796 |
+
```
|
| 797 |
+
|
| 798 |
+
See `Client.build_request()`, `Client.send()` and
|
| 799 |
+
[Merging of configuration][0] for how the various parameters
|
| 800 |
+
are merged with client-level configuration.
|
| 801 |
+
|
| 802 |
+
[0]: /advanced/clients/#merging-of-configuration
|
| 803 |
+
"""
|
| 804 |
+
if cookies is not None:
|
| 805 |
+
message = (
|
| 806 |
+
"Setting per-request cookies=<...> is being deprecated, because "
|
| 807 |
+
"the expected behaviour on cookie persistence is ambiguous. Set "
|
| 808 |
+
"cookies directly on the client instance instead."
|
| 809 |
+
)
|
| 810 |
+
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
| 811 |
+
|
| 812 |
+
request = self.build_request(
|
| 813 |
+
method=method,
|
| 814 |
+
url=url,
|
| 815 |
+
content=content,
|
| 816 |
+
data=data,
|
| 817 |
+
files=files,
|
| 818 |
+
json=json,
|
| 819 |
+
params=params,
|
| 820 |
+
headers=headers,
|
| 821 |
+
cookies=cookies,
|
| 822 |
+
timeout=timeout,
|
| 823 |
+
extensions=extensions,
|
| 824 |
+
)
|
| 825 |
+
return self.send(request, auth=auth, follow_redirects=follow_redirects)
|
| 826 |
+
|
| 827 |
+
@contextmanager
|
| 828 |
+
def stream(
|
| 829 |
+
self,
|
| 830 |
+
method: str,
|
| 831 |
+
url: URL | str,
|
| 832 |
+
*,
|
| 833 |
+
content: RequestContent | None = None,
|
| 834 |
+
data: RequestData | None = None,
|
| 835 |
+
files: RequestFiles | None = None,
|
| 836 |
+
json: typing.Any | None = None,
|
| 837 |
+
params: QueryParamTypes | None = None,
|
| 838 |
+
headers: HeaderTypes | None = None,
|
| 839 |
+
cookies: CookieTypes | None = None,
|
| 840 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 841 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 842 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 843 |
+
extensions: RequestExtensions | None = None,
|
| 844 |
+
) -> typing.Iterator[Response]:
|
| 845 |
+
"""
|
| 846 |
+
Alternative to `httpx.request()` that streams the response body
|
| 847 |
+
instead of loading it into memory at once.
|
| 848 |
+
|
| 849 |
+
**Parameters**: See `httpx.request`.
|
| 850 |
+
|
| 851 |
+
See also: [Streaming Responses][0]
|
| 852 |
+
|
| 853 |
+
[0]: /quickstart#streaming-responses
|
| 854 |
+
"""
|
| 855 |
+
request = self.build_request(
|
| 856 |
+
method=method,
|
| 857 |
+
url=url,
|
| 858 |
+
content=content,
|
| 859 |
+
data=data,
|
| 860 |
+
files=files,
|
| 861 |
+
json=json,
|
| 862 |
+
params=params,
|
| 863 |
+
headers=headers,
|
| 864 |
+
cookies=cookies,
|
| 865 |
+
timeout=timeout,
|
| 866 |
+
extensions=extensions,
|
| 867 |
+
)
|
| 868 |
+
response = self.send(
|
| 869 |
+
request=request,
|
| 870 |
+
auth=auth,
|
| 871 |
+
follow_redirects=follow_redirects,
|
| 872 |
+
stream=True,
|
| 873 |
+
)
|
| 874 |
+
try:
|
| 875 |
+
yield response
|
| 876 |
+
finally:
|
| 877 |
+
response.close()
|
| 878 |
+
|
| 879 |
+
def send(
|
| 880 |
+
self,
|
| 881 |
+
request: Request,
|
| 882 |
+
*,
|
| 883 |
+
stream: bool = False,
|
| 884 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 885 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 886 |
+
) -> Response:
|
| 887 |
+
"""
|
| 888 |
+
Send a request.
|
| 889 |
+
|
| 890 |
+
The request is sent as-is, unmodified.
|
| 891 |
+
|
| 892 |
+
Typically you'll want to build one with `Client.build_request()`
|
| 893 |
+
so that any client-level configuration is merged into the request,
|
| 894 |
+
but passing an explicit `httpx.Request()` is supported as well.
|
| 895 |
+
|
| 896 |
+
See also: [Request instances][0]
|
| 897 |
+
|
| 898 |
+
[0]: /advanced/clients/#request-instances
|
| 899 |
+
"""
|
| 900 |
+
if self._state == ClientState.CLOSED:
|
| 901 |
+
raise RuntimeError("Cannot send a request, as the client has been closed.")
|
| 902 |
+
|
| 903 |
+
self._state = ClientState.OPENED
|
| 904 |
+
follow_redirects = (
|
| 905 |
+
self.follow_redirects
|
| 906 |
+
if isinstance(follow_redirects, UseClientDefault)
|
| 907 |
+
else follow_redirects
|
| 908 |
+
)
|
| 909 |
+
|
| 910 |
+
self._set_timeout(request)
|
| 911 |
+
|
| 912 |
+
auth = self._build_request_auth(request, auth)
|
| 913 |
+
|
| 914 |
+
response = self._send_handling_auth(
|
| 915 |
+
request,
|
| 916 |
+
auth=auth,
|
| 917 |
+
follow_redirects=follow_redirects,
|
| 918 |
+
history=[],
|
| 919 |
+
)
|
| 920 |
+
try:
|
| 921 |
+
if not stream:
|
| 922 |
+
response.read()
|
| 923 |
+
|
| 924 |
+
return response
|
| 925 |
+
|
| 926 |
+
except BaseException as exc:
|
| 927 |
+
response.close()
|
| 928 |
+
raise exc
|
| 929 |
+
|
| 930 |
+
def _send_handling_auth(
|
| 931 |
+
self,
|
| 932 |
+
request: Request,
|
| 933 |
+
auth: Auth,
|
| 934 |
+
follow_redirects: bool,
|
| 935 |
+
history: list[Response],
|
| 936 |
+
) -> Response:
|
| 937 |
+
auth_flow = auth.sync_auth_flow(request)
|
| 938 |
+
try:
|
| 939 |
+
request = next(auth_flow)
|
| 940 |
+
|
| 941 |
+
while True:
|
| 942 |
+
response = self._send_handling_redirects(
|
| 943 |
+
request,
|
| 944 |
+
follow_redirects=follow_redirects,
|
| 945 |
+
history=history,
|
| 946 |
+
)
|
| 947 |
+
try:
|
| 948 |
+
try:
|
| 949 |
+
next_request = auth_flow.send(response)
|
| 950 |
+
except StopIteration:
|
| 951 |
+
return response
|
| 952 |
+
|
| 953 |
+
response.history = list(history)
|
| 954 |
+
response.read()
|
| 955 |
+
request = next_request
|
| 956 |
+
history.append(response)
|
| 957 |
+
|
| 958 |
+
except BaseException as exc:
|
| 959 |
+
response.close()
|
| 960 |
+
raise exc
|
| 961 |
+
finally:
|
| 962 |
+
auth_flow.close()
|
| 963 |
+
|
| 964 |
+
def _send_handling_redirects(
|
| 965 |
+
self,
|
| 966 |
+
request: Request,
|
| 967 |
+
follow_redirects: bool,
|
| 968 |
+
history: list[Response],
|
| 969 |
+
) -> Response:
|
| 970 |
+
while True:
|
| 971 |
+
if len(history) > self.max_redirects:
|
| 972 |
+
raise TooManyRedirects(
|
| 973 |
+
"Exceeded maximum allowed redirects.", request=request
|
| 974 |
+
)
|
| 975 |
+
|
| 976 |
+
for hook in self._event_hooks["request"]:
|
| 977 |
+
hook(request)
|
| 978 |
+
|
| 979 |
+
response = self._send_single_request(request)
|
| 980 |
+
try:
|
| 981 |
+
for hook in self._event_hooks["response"]:
|
| 982 |
+
hook(response)
|
| 983 |
+
response.history = list(history)
|
| 984 |
+
|
| 985 |
+
if not response.has_redirect_location:
|
| 986 |
+
return response
|
| 987 |
+
|
| 988 |
+
request = self._build_redirect_request(request, response)
|
| 989 |
+
history = history + [response]
|
| 990 |
+
|
| 991 |
+
if follow_redirects:
|
| 992 |
+
response.read()
|
| 993 |
+
else:
|
| 994 |
+
response.next_request = request
|
| 995 |
+
return response
|
| 996 |
+
|
| 997 |
+
except BaseException as exc:
|
| 998 |
+
response.close()
|
| 999 |
+
raise exc
|
| 1000 |
+
|
| 1001 |
+
def _send_single_request(self, request: Request) -> Response:
|
| 1002 |
+
"""
|
| 1003 |
+
Sends a single request, without handling any redirections.
|
| 1004 |
+
"""
|
| 1005 |
+
transport = self._transport_for_url(request.url)
|
| 1006 |
+
start = time.perf_counter()
|
| 1007 |
+
|
| 1008 |
+
if not isinstance(request.stream, SyncByteStream):
|
| 1009 |
+
raise RuntimeError(
|
| 1010 |
+
"Attempted to send an async request with a sync Client instance."
|
| 1011 |
+
)
|
| 1012 |
+
|
| 1013 |
+
with request_context(request=request):
|
| 1014 |
+
response = transport.handle_request(request)
|
| 1015 |
+
|
| 1016 |
+
assert isinstance(response.stream, SyncByteStream)
|
| 1017 |
+
|
| 1018 |
+
response.request = request
|
| 1019 |
+
response.stream = BoundSyncStream(
|
| 1020 |
+
response.stream, response=response, start=start
|
| 1021 |
+
)
|
| 1022 |
+
self.cookies.extract_cookies(response)
|
| 1023 |
+
response.default_encoding = self._default_encoding
|
| 1024 |
+
|
| 1025 |
+
logger.info(
|
| 1026 |
+
'HTTP Request: %s %s "%s %d %s"',
|
| 1027 |
+
request.method,
|
| 1028 |
+
request.url,
|
| 1029 |
+
response.http_version,
|
| 1030 |
+
response.status_code,
|
| 1031 |
+
response.reason_phrase,
|
| 1032 |
+
)
|
| 1033 |
+
|
| 1034 |
+
return response
|
| 1035 |
+
|
| 1036 |
+
def get(
|
| 1037 |
+
self,
|
| 1038 |
+
url: URL | str,
|
| 1039 |
+
*,
|
| 1040 |
+
params: QueryParamTypes | None = None,
|
| 1041 |
+
headers: HeaderTypes | None = None,
|
| 1042 |
+
cookies: CookieTypes | None = None,
|
| 1043 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 1044 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1045 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1046 |
+
extensions: RequestExtensions | None = None,
|
| 1047 |
+
) -> Response:
|
| 1048 |
+
"""
|
| 1049 |
+
Send a `GET` request.
|
| 1050 |
+
|
| 1051 |
+
**Parameters**: See `httpx.request`.
|
| 1052 |
+
"""
|
| 1053 |
+
return self.request(
|
| 1054 |
+
"GET",
|
| 1055 |
+
url,
|
| 1056 |
+
params=params,
|
| 1057 |
+
headers=headers,
|
| 1058 |
+
cookies=cookies,
|
| 1059 |
+
auth=auth,
|
| 1060 |
+
follow_redirects=follow_redirects,
|
| 1061 |
+
timeout=timeout,
|
| 1062 |
+
extensions=extensions,
|
| 1063 |
+
)
|
| 1064 |
+
|
| 1065 |
+
def options(
|
| 1066 |
+
self,
|
| 1067 |
+
url: URL | str,
|
| 1068 |
+
*,
|
| 1069 |
+
params: QueryParamTypes | None = None,
|
| 1070 |
+
headers: HeaderTypes | None = None,
|
| 1071 |
+
cookies: CookieTypes | None = None,
|
| 1072 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1073 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1074 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1075 |
+
extensions: RequestExtensions | None = None,
|
| 1076 |
+
) -> Response:
|
| 1077 |
+
"""
|
| 1078 |
+
Send an `OPTIONS` request.
|
| 1079 |
+
|
| 1080 |
+
**Parameters**: See `httpx.request`.
|
| 1081 |
+
"""
|
| 1082 |
+
return self.request(
|
| 1083 |
+
"OPTIONS",
|
| 1084 |
+
url,
|
| 1085 |
+
params=params,
|
| 1086 |
+
headers=headers,
|
| 1087 |
+
cookies=cookies,
|
| 1088 |
+
auth=auth,
|
| 1089 |
+
follow_redirects=follow_redirects,
|
| 1090 |
+
timeout=timeout,
|
| 1091 |
+
extensions=extensions,
|
| 1092 |
+
)
|
| 1093 |
+
|
| 1094 |
+
def head(
|
| 1095 |
+
self,
|
| 1096 |
+
url: URL | str,
|
| 1097 |
+
*,
|
| 1098 |
+
params: QueryParamTypes | None = None,
|
| 1099 |
+
headers: HeaderTypes | None = None,
|
| 1100 |
+
cookies: CookieTypes | None = None,
|
| 1101 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1102 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1103 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1104 |
+
extensions: RequestExtensions | None = None,
|
| 1105 |
+
) -> Response:
|
| 1106 |
+
"""
|
| 1107 |
+
Send a `HEAD` request.
|
| 1108 |
+
|
| 1109 |
+
**Parameters**: See `httpx.request`.
|
| 1110 |
+
"""
|
| 1111 |
+
return self.request(
|
| 1112 |
+
"HEAD",
|
| 1113 |
+
url,
|
| 1114 |
+
params=params,
|
| 1115 |
+
headers=headers,
|
| 1116 |
+
cookies=cookies,
|
| 1117 |
+
auth=auth,
|
| 1118 |
+
follow_redirects=follow_redirects,
|
| 1119 |
+
timeout=timeout,
|
| 1120 |
+
extensions=extensions,
|
| 1121 |
+
)
|
| 1122 |
+
|
| 1123 |
+
def post(
|
| 1124 |
+
self,
|
| 1125 |
+
url: URL | str,
|
| 1126 |
+
*,
|
| 1127 |
+
content: RequestContent | None = None,
|
| 1128 |
+
data: RequestData | None = None,
|
| 1129 |
+
files: RequestFiles | None = None,
|
| 1130 |
+
json: typing.Any | None = None,
|
| 1131 |
+
params: QueryParamTypes | None = None,
|
| 1132 |
+
headers: HeaderTypes | None = None,
|
| 1133 |
+
cookies: CookieTypes | None = None,
|
| 1134 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1135 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1136 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1137 |
+
extensions: RequestExtensions | None = None,
|
| 1138 |
+
) -> Response:
|
| 1139 |
+
"""
|
| 1140 |
+
Send a `POST` request.
|
| 1141 |
+
|
| 1142 |
+
**Parameters**: See `httpx.request`.
|
| 1143 |
+
"""
|
| 1144 |
+
return self.request(
|
| 1145 |
+
"POST",
|
| 1146 |
+
url,
|
| 1147 |
+
content=content,
|
| 1148 |
+
data=data,
|
| 1149 |
+
files=files,
|
| 1150 |
+
json=json,
|
| 1151 |
+
params=params,
|
| 1152 |
+
headers=headers,
|
| 1153 |
+
cookies=cookies,
|
| 1154 |
+
auth=auth,
|
| 1155 |
+
follow_redirects=follow_redirects,
|
| 1156 |
+
timeout=timeout,
|
| 1157 |
+
extensions=extensions,
|
| 1158 |
+
)
|
| 1159 |
+
|
| 1160 |
+
def put(
|
| 1161 |
+
self,
|
| 1162 |
+
url: URL | str,
|
| 1163 |
+
*,
|
| 1164 |
+
content: RequestContent | None = None,
|
| 1165 |
+
data: RequestData | None = None,
|
| 1166 |
+
files: RequestFiles | None = None,
|
| 1167 |
+
json: typing.Any | None = None,
|
| 1168 |
+
params: QueryParamTypes | None = None,
|
| 1169 |
+
headers: HeaderTypes | None = None,
|
| 1170 |
+
cookies: CookieTypes | None = None,
|
| 1171 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1172 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1173 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1174 |
+
extensions: RequestExtensions | None = None,
|
| 1175 |
+
) -> Response:
|
| 1176 |
+
"""
|
| 1177 |
+
Send a `PUT` request.
|
| 1178 |
+
|
| 1179 |
+
**Parameters**: See `httpx.request`.
|
| 1180 |
+
"""
|
| 1181 |
+
return self.request(
|
| 1182 |
+
"PUT",
|
| 1183 |
+
url,
|
| 1184 |
+
content=content,
|
| 1185 |
+
data=data,
|
| 1186 |
+
files=files,
|
| 1187 |
+
json=json,
|
| 1188 |
+
params=params,
|
| 1189 |
+
headers=headers,
|
| 1190 |
+
cookies=cookies,
|
| 1191 |
+
auth=auth,
|
| 1192 |
+
follow_redirects=follow_redirects,
|
| 1193 |
+
timeout=timeout,
|
| 1194 |
+
extensions=extensions,
|
| 1195 |
+
)
|
| 1196 |
+
|
| 1197 |
+
def patch(
|
| 1198 |
+
self,
|
| 1199 |
+
url: URL | str,
|
| 1200 |
+
*,
|
| 1201 |
+
content: RequestContent | None = None,
|
| 1202 |
+
data: RequestData | None = None,
|
| 1203 |
+
files: RequestFiles | None = None,
|
| 1204 |
+
json: typing.Any | None = None,
|
| 1205 |
+
params: QueryParamTypes | None = None,
|
| 1206 |
+
headers: HeaderTypes | None = None,
|
| 1207 |
+
cookies: CookieTypes | None = None,
|
| 1208 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1209 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1210 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1211 |
+
extensions: RequestExtensions | None = None,
|
| 1212 |
+
) -> Response:
|
| 1213 |
+
"""
|
| 1214 |
+
Send a `PATCH` request.
|
| 1215 |
+
|
| 1216 |
+
**Parameters**: See `httpx.request`.
|
| 1217 |
+
"""
|
| 1218 |
+
return self.request(
|
| 1219 |
+
"PATCH",
|
| 1220 |
+
url,
|
| 1221 |
+
content=content,
|
| 1222 |
+
data=data,
|
| 1223 |
+
files=files,
|
| 1224 |
+
json=json,
|
| 1225 |
+
params=params,
|
| 1226 |
+
headers=headers,
|
| 1227 |
+
cookies=cookies,
|
| 1228 |
+
auth=auth,
|
| 1229 |
+
follow_redirects=follow_redirects,
|
| 1230 |
+
timeout=timeout,
|
| 1231 |
+
extensions=extensions,
|
| 1232 |
+
)
|
| 1233 |
+
|
| 1234 |
+
def delete(
|
| 1235 |
+
self,
|
| 1236 |
+
url: URL | str,
|
| 1237 |
+
*,
|
| 1238 |
+
params: QueryParamTypes | None = None,
|
| 1239 |
+
headers: HeaderTypes | None = None,
|
| 1240 |
+
cookies: CookieTypes | None = None,
|
| 1241 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1242 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1243 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1244 |
+
extensions: RequestExtensions | None = None,
|
| 1245 |
+
) -> Response:
|
| 1246 |
+
"""
|
| 1247 |
+
Send a `DELETE` request.
|
| 1248 |
+
|
| 1249 |
+
**Parameters**: See `httpx.request`.
|
| 1250 |
+
"""
|
| 1251 |
+
return self.request(
|
| 1252 |
+
"DELETE",
|
| 1253 |
+
url,
|
| 1254 |
+
params=params,
|
| 1255 |
+
headers=headers,
|
| 1256 |
+
cookies=cookies,
|
| 1257 |
+
auth=auth,
|
| 1258 |
+
follow_redirects=follow_redirects,
|
| 1259 |
+
timeout=timeout,
|
| 1260 |
+
extensions=extensions,
|
| 1261 |
+
)
|
| 1262 |
+
|
| 1263 |
+
def close(self) -> None:
|
| 1264 |
+
"""
|
| 1265 |
+
Close transport and proxies.
|
| 1266 |
+
"""
|
| 1267 |
+
if self._state != ClientState.CLOSED:
|
| 1268 |
+
self._state = ClientState.CLOSED
|
| 1269 |
+
|
| 1270 |
+
self._transport.close()
|
| 1271 |
+
for transport in self._mounts.values():
|
| 1272 |
+
if transport is not None:
|
| 1273 |
+
transport.close()
|
| 1274 |
+
|
| 1275 |
+
def __enter__(self: T) -> T:
|
| 1276 |
+
if self._state != ClientState.UNOPENED:
|
| 1277 |
+
msg = {
|
| 1278 |
+
ClientState.OPENED: "Cannot open a client instance more than once.",
|
| 1279 |
+
ClientState.CLOSED: (
|
| 1280 |
+
"Cannot reopen a client instance, once it has been closed."
|
| 1281 |
+
),
|
| 1282 |
+
}[self._state]
|
| 1283 |
+
raise RuntimeError(msg)
|
| 1284 |
+
|
| 1285 |
+
self._state = ClientState.OPENED
|
| 1286 |
+
|
| 1287 |
+
self._transport.__enter__()
|
| 1288 |
+
for transport in self._mounts.values():
|
| 1289 |
+
if transport is not None:
|
| 1290 |
+
transport.__enter__()
|
| 1291 |
+
return self
|
| 1292 |
+
|
| 1293 |
+
def __exit__(
|
| 1294 |
+
self,
|
| 1295 |
+
exc_type: type[BaseException] | None = None,
|
| 1296 |
+
exc_value: BaseException | None = None,
|
| 1297 |
+
traceback: TracebackType | None = None,
|
| 1298 |
+
) -> None:
|
| 1299 |
+
self._state = ClientState.CLOSED
|
| 1300 |
+
|
| 1301 |
+
self._transport.__exit__(exc_type, exc_value, traceback)
|
| 1302 |
+
for transport in self._mounts.values():
|
| 1303 |
+
if transport is not None:
|
| 1304 |
+
transport.__exit__(exc_type, exc_value, traceback)
|
| 1305 |
+
|
| 1306 |
+
|
| 1307 |
+
class AsyncClient(BaseClient):
|
| 1308 |
+
"""
|
| 1309 |
+
An asynchronous HTTP client, with connection pooling, HTTP/2, redirects,
|
| 1310 |
+
cookie persistence, etc.
|
| 1311 |
+
|
| 1312 |
+
It can be shared between tasks.
|
| 1313 |
+
|
| 1314 |
+
Usage:
|
| 1315 |
+
|
| 1316 |
+
```python
|
| 1317 |
+
>>> async with httpx.AsyncClient() as client:
|
| 1318 |
+
>>> response = await client.get('https://example.org')
|
| 1319 |
+
```
|
| 1320 |
+
|
| 1321 |
+
**Parameters:**
|
| 1322 |
+
|
| 1323 |
+
* **auth** - *(optional)* An authentication class to use when sending
|
| 1324 |
+
requests.
|
| 1325 |
+
* **params** - *(optional)* Query parameters to include in request URLs, as
|
| 1326 |
+
a string, dictionary, or sequence of two-tuples.
|
| 1327 |
+
* **headers** - *(optional)* Dictionary of HTTP headers to include when
|
| 1328 |
+
sending requests.
|
| 1329 |
+
* **cookies** - *(optional)* Dictionary of Cookie items to include when
|
| 1330 |
+
sending requests.
|
| 1331 |
+
* **verify** - *(optional)* Either `True` to use an SSL context with the
|
| 1332 |
+
default CA bundle, `False` to disable verification, or an instance of
|
| 1333 |
+
`ssl.SSLContext` to use a custom context.
|
| 1334 |
+
* **http2** - *(optional)* A boolean indicating if HTTP/2 support should be
|
| 1335 |
+
enabled. Defaults to `False`.
|
| 1336 |
+
* **proxy** - *(optional)* A proxy URL where all the traffic should be routed.
|
| 1337 |
+
* **timeout** - *(optional)* The timeout configuration to use when sending
|
| 1338 |
+
requests.
|
| 1339 |
+
* **limits** - *(optional)* The limits configuration to use.
|
| 1340 |
+
* **max_redirects** - *(optional)* The maximum number of redirect responses
|
| 1341 |
+
that should be followed.
|
| 1342 |
+
* **base_url** - *(optional)* A URL to use as the base when building
|
| 1343 |
+
request URLs.
|
| 1344 |
+
* **transport** - *(optional)* A transport class to use for sending requests
|
| 1345 |
+
over the network.
|
| 1346 |
+
* **trust_env** - *(optional)* Enables or disables usage of environment
|
| 1347 |
+
variables for configuration.
|
| 1348 |
+
* **default_encoding** - *(optional)* The default encoding to use for decoding
|
| 1349 |
+
response text, if no charset information is included in a response Content-Type
|
| 1350 |
+
header. Set to a callable for automatic character set detection. Default: "utf-8".
|
| 1351 |
+
"""
|
| 1352 |
+
|
| 1353 |
+
def __init__(
|
| 1354 |
+
self,
|
| 1355 |
+
*,
|
| 1356 |
+
auth: AuthTypes | None = None,
|
| 1357 |
+
params: QueryParamTypes | None = None,
|
| 1358 |
+
headers: HeaderTypes | None = None,
|
| 1359 |
+
cookies: CookieTypes | None = None,
|
| 1360 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 1361 |
+
cert: CertTypes | None = None,
|
| 1362 |
+
http1: bool = True,
|
| 1363 |
+
http2: bool = False,
|
| 1364 |
+
proxy: ProxyTypes | None = None,
|
| 1365 |
+
mounts: None | (typing.Mapping[str, AsyncBaseTransport | None]) = None,
|
| 1366 |
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
| 1367 |
+
follow_redirects: bool = False,
|
| 1368 |
+
limits: Limits = DEFAULT_LIMITS,
|
| 1369 |
+
max_redirects: int = DEFAULT_MAX_REDIRECTS,
|
| 1370 |
+
event_hooks: None | (typing.Mapping[str, list[EventHook]]) = None,
|
| 1371 |
+
base_url: URL | str = "",
|
| 1372 |
+
transport: AsyncBaseTransport | None = None,
|
| 1373 |
+
trust_env: bool = True,
|
| 1374 |
+
default_encoding: str | typing.Callable[[bytes], str] = "utf-8",
|
| 1375 |
+
) -> None:
|
| 1376 |
+
super().__init__(
|
| 1377 |
+
auth=auth,
|
| 1378 |
+
params=params,
|
| 1379 |
+
headers=headers,
|
| 1380 |
+
cookies=cookies,
|
| 1381 |
+
timeout=timeout,
|
| 1382 |
+
follow_redirects=follow_redirects,
|
| 1383 |
+
max_redirects=max_redirects,
|
| 1384 |
+
event_hooks=event_hooks,
|
| 1385 |
+
base_url=base_url,
|
| 1386 |
+
trust_env=trust_env,
|
| 1387 |
+
default_encoding=default_encoding,
|
| 1388 |
+
)
|
| 1389 |
+
|
| 1390 |
+
if http2:
|
| 1391 |
+
try:
|
| 1392 |
+
import h2 # noqa
|
| 1393 |
+
except ImportError: # pragma: no cover
|
| 1394 |
+
raise ImportError(
|
| 1395 |
+
"Using http2=True, but the 'h2' package is not installed. "
|
| 1396 |
+
"Make sure to install httpx using `pip install httpx[http2]`."
|
| 1397 |
+
) from None
|
| 1398 |
+
|
| 1399 |
+
allow_env_proxies = trust_env and transport is None
|
| 1400 |
+
proxy_map = self._get_proxy_map(proxy, allow_env_proxies)
|
| 1401 |
+
|
| 1402 |
+
self._transport = self._init_transport(
|
| 1403 |
+
verify=verify,
|
| 1404 |
+
cert=cert,
|
| 1405 |
+
trust_env=trust_env,
|
| 1406 |
+
http1=http1,
|
| 1407 |
+
http2=http2,
|
| 1408 |
+
limits=limits,
|
| 1409 |
+
transport=transport,
|
| 1410 |
+
)
|
| 1411 |
+
|
| 1412 |
+
self._mounts: dict[URLPattern, AsyncBaseTransport | None] = {
|
| 1413 |
+
URLPattern(key): None
|
| 1414 |
+
if proxy is None
|
| 1415 |
+
else self._init_proxy_transport(
|
| 1416 |
+
proxy,
|
| 1417 |
+
verify=verify,
|
| 1418 |
+
cert=cert,
|
| 1419 |
+
trust_env=trust_env,
|
| 1420 |
+
http1=http1,
|
| 1421 |
+
http2=http2,
|
| 1422 |
+
limits=limits,
|
| 1423 |
+
)
|
| 1424 |
+
for key, proxy in proxy_map.items()
|
| 1425 |
+
}
|
| 1426 |
+
if mounts is not None:
|
| 1427 |
+
self._mounts.update(
|
| 1428 |
+
{URLPattern(key): transport for key, transport in mounts.items()}
|
| 1429 |
+
)
|
| 1430 |
+
self._mounts = dict(sorted(self._mounts.items()))
|
| 1431 |
+
|
| 1432 |
+
def _init_transport(
|
| 1433 |
+
self,
|
| 1434 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 1435 |
+
cert: CertTypes | None = None,
|
| 1436 |
+
trust_env: bool = True,
|
| 1437 |
+
http1: bool = True,
|
| 1438 |
+
http2: bool = False,
|
| 1439 |
+
limits: Limits = DEFAULT_LIMITS,
|
| 1440 |
+
transport: AsyncBaseTransport | None = None,
|
| 1441 |
+
) -> AsyncBaseTransport:
|
| 1442 |
+
if transport is not None:
|
| 1443 |
+
return transport
|
| 1444 |
+
|
| 1445 |
+
return AsyncHTTPTransport(
|
| 1446 |
+
verify=verify,
|
| 1447 |
+
cert=cert,
|
| 1448 |
+
trust_env=trust_env,
|
| 1449 |
+
http1=http1,
|
| 1450 |
+
http2=http2,
|
| 1451 |
+
limits=limits,
|
| 1452 |
+
)
|
| 1453 |
+
|
| 1454 |
+
def _init_proxy_transport(
|
| 1455 |
+
self,
|
| 1456 |
+
proxy: Proxy,
|
| 1457 |
+
verify: ssl.SSLContext | str | bool = True,
|
| 1458 |
+
cert: CertTypes | None = None,
|
| 1459 |
+
trust_env: bool = True,
|
| 1460 |
+
http1: bool = True,
|
| 1461 |
+
http2: bool = False,
|
| 1462 |
+
limits: Limits = DEFAULT_LIMITS,
|
| 1463 |
+
) -> AsyncBaseTransport:
|
| 1464 |
+
return AsyncHTTPTransport(
|
| 1465 |
+
verify=verify,
|
| 1466 |
+
cert=cert,
|
| 1467 |
+
trust_env=trust_env,
|
| 1468 |
+
http1=http1,
|
| 1469 |
+
http2=http2,
|
| 1470 |
+
limits=limits,
|
| 1471 |
+
proxy=proxy,
|
| 1472 |
+
)
|
| 1473 |
+
|
| 1474 |
+
def _transport_for_url(self, url: URL) -> AsyncBaseTransport:
|
| 1475 |
+
"""
|
| 1476 |
+
Returns the transport instance that should be used for a given URL.
|
| 1477 |
+
This will either be the standard connection pool, or a proxy.
|
| 1478 |
+
"""
|
| 1479 |
+
for pattern, transport in self._mounts.items():
|
| 1480 |
+
if pattern.matches(url):
|
| 1481 |
+
return self._transport if transport is None else transport
|
| 1482 |
+
|
| 1483 |
+
return self._transport
|
| 1484 |
+
|
| 1485 |
+
async def request(
|
| 1486 |
+
self,
|
| 1487 |
+
method: str,
|
| 1488 |
+
url: URL | str,
|
| 1489 |
+
*,
|
| 1490 |
+
content: RequestContent | None = None,
|
| 1491 |
+
data: RequestData | None = None,
|
| 1492 |
+
files: RequestFiles | None = None,
|
| 1493 |
+
json: typing.Any | None = None,
|
| 1494 |
+
params: QueryParamTypes | None = None,
|
| 1495 |
+
headers: HeaderTypes | None = None,
|
| 1496 |
+
cookies: CookieTypes | None = None,
|
| 1497 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 1498 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1499 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1500 |
+
extensions: RequestExtensions | None = None,
|
| 1501 |
+
) -> Response:
|
| 1502 |
+
"""
|
| 1503 |
+
Build and send a request.
|
| 1504 |
+
|
| 1505 |
+
Equivalent to:
|
| 1506 |
+
|
| 1507 |
+
```python
|
| 1508 |
+
request = client.build_request(...)
|
| 1509 |
+
response = await client.send(request, ...)
|
| 1510 |
+
```
|
| 1511 |
+
|
| 1512 |
+
See `AsyncClient.build_request()`, `AsyncClient.send()`
|
| 1513 |
+
and [Merging of configuration][0] for how the various parameters
|
| 1514 |
+
are merged with client-level configuration.
|
| 1515 |
+
|
| 1516 |
+
[0]: /advanced/clients/#merging-of-configuration
|
| 1517 |
+
"""
|
| 1518 |
+
|
| 1519 |
+
if cookies is not None: # pragma: no cover
|
| 1520 |
+
message = (
|
| 1521 |
+
"Setting per-request cookies=<...> is being deprecated, because "
|
| 1522 |
+
"the expected behaviour on cookie persistence is ambiguous. Set "
|
| 1523 |
+
"cookies directly on the client instance instead."
|
| 1524 |
+
)
|
| 1525 |
+
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
| 1526 |
+
|
| 1527 |
+
request = self.build_request(
|
| 1528 |
+
method=method,
|
| 1529 |
+
url=url,
|
| 1530 |
+
content=content,
|
| 1531 |
+
data=data,
|
| 1532 |
+
files=files,
|
| 1533 |
+
json=json,
|
| 1534 |
+
params=params,
|
| 1535 |
+
headers=headers,
|
| 1536 |
+
cookies=cookies,
|
| 1537 |
+
timeout=timeout,
|
| 1538 |
+
extensions=extensions,
|
| 1539 |
+
)
|
| 1540 |
+
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
|
| 1541 |
+
|
| 1542 |
+
@asynccontextmanager
|
| 1543 |
+
async def stream(
|
| 1544 |
+
self,
|
| 1545 |
+
method: str,
|
| 1546 |
+
url: URL | str,
|
| 1547 |
+
*,
|
| 1548 |
+
content: RequestContent | None = None,
|
| 1549 |
+
data: RequestData | None = None,
|
| 1550 |
+
files: RequestFiles | None = None,
|
| 1551 |
+
json: typing.Any | None = None,
|
| 1552 |
+
params: QueryParamTypes | None = None,
|
| 1553 |
+
headers: HeaderTypes | None = None,
|
| 1554 |
+
cookies: CookieTypes | None = None,
|
| 1555 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 1556 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1557 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1558 |
+
extensions: RequestExtensions | None = None,
|
| 1559 |
+
) -> typing.AsyncIterator[Response]:
|
| 1560 |
+
"""
|
| 1561 |
+
Alternative to `httpx.request()` that streams the response body
|
| 1562 |
+
instead of loading it into memory at once.
|
| 1563 |
+
|
| 1564 |
+
**Parameters**: See `httpx.request`.
|
| 1565 |
+
|
| 1566 |
+
See also: [Streaming Responses][0]
|
| 1567 |
+
|
| 1568 |
+
[0]: /quickstart#streaming-responses
|
| 1569 |
+
"""
|
| 1570 |
+
request = self.build_request(
|
| 1571 |
+
method=method,
|
| 1572 |
+
url=url,
|
| 1573 |
+
content=content,
|
| 1574 |
+
data=data,
|
| 1575 |
+
files=files,
|
| 1576 |
+
json=json,
|
| 1577 |
+
params=params,
|
| 1578 |
+
headers=headers,
|
| 1579 |
+
cookies=cookies,
|
| 1580 |
+
timeout=timeout,
|
| 1581 |
+
extensions=extensions,
|
| 1582 |
+
)
|
| 1583 |
+
response = await self.send(
|
| 1584 |
+
request=request,
|
| 1585 |
+
auth=auth,
|
| 1586 |
+
follow_redirects=follow_redirects,
|
| 1587 |
+
stream=True,
|
| 1588 |
+
)
|
| 1589 |
+
try:
|
| 1590 |
+
yield response
|
| 1591 |
+
finally:
|
| 1592 |
+
await response.aclose()
|
| 1593 |
+
|
| 1594 |
+
async def send(
|
| 1595 |
+
self,
|
| 1596 |
+
request: Request,
|
| 1597 |
+
*,
|
| 1598 |
+
stream: bool = False,
|
| 1599 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 1600 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1601 |
+
) -> Response:
|
| 1602 |
+
"""
|
| 1603 |
+
Send a request.
|
| 1604 |
+
|
| 1605 |
+
The request is sent as-is, unmodified.
|
| 1606 |
+
|
| 1607 |
+
Typically you'll want to build one with `AsyncClient.build_request()`
|
| 1608 |
+
so that any client-level configuration is merged into the request,
|
| 1609 |
+
but passing an explicit `httpx.Request()` is supported as well.
|
| 1610 |
+
|
| 1611 |
+
See also: [Request instances][0]
|
| 1612 |
+
|
| 1613 |
+
[0]: /advanced/clients/#request-instances
|
| 1614 |
+
"""
|
| 1615 |
+
if self._state == ClientState.CLOSED:
|
| 1616 |
+
raise RuntimeError("Cannot send a request, as the client has been closed.")
|
| 1617 |
+
|
| 1618 |
+
self._state = ClientState.OPENED
|
| 1619 |
+
follow_redirects = (
|
| 1620 |
+
self.follow_redirects
|
| 1621 |
+
if isinstance(follow_redirects, UseClientDefault)
|
| 1622 |
+
else follow_redirects
|
| 1623 |
+
)
|
| 1624 |
+
|
| 1625 |
+
self._set_timeout(request)
|
| 1626 |
+
|
| 1627 |
+
auth = self._build_request_auth(request, auth)
|
| 1628 |
+
|
| 1629 |
+
response = await self._send_handling_auth(
|
| 1630 |
+
request,
|
| 1631 |
+
auth=auth,
|
| 1632 |
+
follow_redirects=follow_redirects,
|
| 1633 |
+
history=[],
|
| 1634 |
+
)
|
| 1635 |
+
try:
|
| 1636 |
+
if not stream:
|
| 1637 |
+
await response.aread()
|
| 1638 |
+
|
| 1639 |
+
return response
|
| 1640 |
+
|
| 1641 |
+
except BaseException as exc:
|
| 1642 |
+
await response.aclose()
|
| 1643 |
+
raise exc
|
| 1644 |
+
|
| 1645 |
+
async def _send_handling_auth(
|
| 1646 |
+
self,
|
| 1647 |
+
request: Request,
|
| 1648 |
+
auth: Auth,
|
| 1649 |
+
follow_redirects: bool,
|
| 1650 |
+
history: list[Response],
|
| 1651 |
+
) -> Response:
|
| 1652 |
+
auth_flow = auth.async_auth_flow(request)
|
| 1653 |
+
try:
|
| 1654 |
+
request = await auth_flow.__anext__()
|
| 1655 |
+
|
| 1656 |
+
while True:
|
| 1657 |
+
response = await self._send_handling_redirects(
|
| 1658 |
+
request,
|
| 1659 |
+
follow_redirects=follow_redirects,
|
| 1660 |
+
history=history,
|
| 1661 |
+
)
|
| 1662 |
+
try:
|
| 1663 |
+
try:
|
| 1664 |
+
next_request = await auth_flow.asend(response)
|
| 1665 |
+
except StopAsyncIteration:
|
| 1666 |
+
return response
|
| 1667 |
+
|
| 1668 |
+
response.history = list(history)
|
| 1669 |
+
await response.aread()
|
| 1670 |
+
request = next_request
|
| 1671 |
+
history.append(response)
|
| 1672 |
+
|
| 1673 |
+
except BaseException as exc:
|
| 1674 |
+
await response.aclose()
|
| 1675 |
+
raise exc
|
| 1676 |
+
finally:
|
| 1677 |
+
await auth_flow.aclose()
|
| 1678 |
+
|
| 1679 |
+
async def _send_handling_redirects(
|
| 1680 |
+
self,
|
| 1681 |
+
request: Request,
|
| 1682 |
+
follow_redirects: bool,
|
| 1683 |
+
history: list[Response],
|
| 1684 |
+
) -> Response:
|
| 1685 |
+
while True:
|
| 1686 |
+
if len(history) > self.max_redirects:
|
| 1687 |
+
raise TooManyRedirects(
|
| 1688 |
+
"Exceeded maximum allowed redirects.", request=request
|
| 1689 |
+
)
|
| 1690 |
+
|
| 1691 |
+
for hook in self._event_hooks["request"]:
|
| 1692 |
+
await hook(request)
|
| 1693 |
+
|
| 1694 |
+
response = await self._send_single_request(request)
|
| 1695 |
+
try:
|
| 1696 |
+
for hook in self._event_hooks["response"]:
|
| 1697 |
+
await hook(response)
|
| 1698 |
+
|
| 1699 |
+
response.history = list(history)
|
| 1700 |
+
|
| 1701 |
+
if not response.has_redirect_location:
|
| 1702 |
+
return response
|
| 1703 |
+
|
| 1704 |
+
request = self._build_redirect_request(request, response)
|
| 1705 |
+
history = history + [response]
|
| 1706 |
+
|
| 1707 |
+
if follow_redirects:
|
| 1708 |
+
await response.aread()
|
| 1709 |
+
else:
|
| 1710 |
+
response.next_request = request
|
| 1711 |
+
return response
|
| 1712 |
+
|
| 1713 |
+
except BaseException as exc:
|
| 1714 |
+
await response.aclose()
|
| 1715 |
+
raise exc
|
| 1716 |
+
|
| 1717 |
+
async def _send_single_request(self, request: Request) -> Response:
|
| 1718 |
+
"""
|
| 1719 |
+
Sends a single request, without handling any redirections.
|
| 1720 |
+
"""
|
| 1721 |
+
transport = self._transport_for_url(request.url)
|
| 1722 |
+
start = time.perf_counter()
|
| 1723 |
+
|
| 1724 |
+
if not isinstance(request.stream, AsyncByteStream):
|
| 1725 |
+
raise RuntimeError(
|
| 1726 |
+
"Attempted to send an sync request with an AsyncClient instance."
|
| 1727 |
+
)
|
| 1728 |
+
|
| 1729 |
+
with request_context(request=request):
|
| 1730 |
+
response = await transport.handle_async_request(request)
|
| 1731 |
+
|
| 1732 |
+
assert isinstance(response.stream, AsyncByteStream)
|
| 1733 |
+
response.request = request
|
| 1734 |
+
response.stream = BoundAsyncStream(
|
| 1735 |
+
response.stream, response=response, start=start
|
| 1736 |
+
)
|
| 1737 |
+
self.cookies.extract_cookies(response)
|
| 1738 |
+
response.default_encoding = self._default_encoding
|
| 1739 |
+
|
| 1740 |
+
logger.info(
|
| 1741 |
+
'HTTP Request: %s %s "%s %d %s"',
|
| 1742 |
+
request.method,
|
| 1743 |
+
request.url,
|
| 1744 |
+
response.http_version,
|
| 1745 |
+
response.status_code,
|
| 1746 |
+
response.reason_phrase,
|
| 1747 |
+
)
|
| 1748 |
+
|
| 1749 |
+
return response
|
| 1750 |
+
|
| 1751 |
+
async def get(
|
| 1752 |
+
self,
|
| 1753 |
+
url: URL | str,
|
| 1754 |
+
*,
|
| 1755 |
+
params: QueryParamTypes | None = None,
|
| 1756 |
+
headers: HeaderTypes | None = None,
|
| 1757 |
+
cookies: CookieTypes | None = None,
|
| 1758 |
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
| 1759 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1760 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1761 |
+
extensions: RequestExtensions | None = None,
|
| 1762 |
+
) -> Response:
|
| 1763 |
+
"""
|
| 1764 |
+
Send a `GET` request.
|
| 1765 |
+
|
| 1766 |
+
**Parameters**: See `httpx.request`.
|
| 1767 |
+
"""
|
| 1768 |
+
return await self.request(
|
| 1769 |
+
"GET",
|
| 1770 |
+
url,
|
| 1771 |
+
params=params,
|
| 1772 |
+
headers=headers,
|
| 1773 |
+
cookies=cookies,
|
| 1774 |
+
auth=auth,
|
| 1775 |
+
follow_redirects=follow_redirects,
|
| 1776 |
+
timeout=timeout,
|
| 1777 |
+
extensions=extensions,
|
| 1778 |
+
)
|
| 1779 |
+
|
| 1780 |
+
async def options(
|
| 1781 |
+
self,
|
| 1782 |
+
url: URL | str,
|
| 1783 |
+
*,
|
| 1784 |
+
params: QueryParamTypes | None = None,
|
| 1785 |
+
headers: HeaderTypes | None = None,
|
| 1786 |
+
cookies: CookieTypes | None = None,
|
| 1787 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1788 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1789 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1790 |
+
extensions: RequestExtensions | None = None,
|
| 1791 |
+
) -> Response:
|
| 1792 |
+
"""
|
| 1793 |
+
Send an `OPTIONS` request.
|
| 1794 |
+
|
| 1795 |
+
**Parameters**: See `httpx.request`.
|
| 1796 |
+
"""
|
| 1797 |
+
return await self.request(
|
| 1798 |
+
"OPTIONS",
|
| 1799 |
+
url,
|
| 1800 |
+
params=params,
|
| 1801 |
+
headers=headers,
|
| 1802 |
+
cookies=cookies,
|
| 1803 |
+
auth=auth,
|
| 1804 |
+
follow_redirects=follow_redirects,
|
| 1805 |
+
timeout=timeout,
|
| 1806 |
+
extensions=extensions,
|
| 1807 |
+
)
|
| 1808 |
+
|
| 1809 |
+
async def head(
|
| 1810 |
+
self,
|
| 1811 |
+
url: URL | str,
|
| 1812 |
+
*,
|
| 1813 |
+
params: QueryParamTypes | None = None,
|
| 1814 |
+
headers: HeaderTypes | None = None,
|
| 1815 |
+
cookies: CookieTypes | None = None,
|
| 1816 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1817 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1818 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1819 |
+
extensions: RequestExtensions | None = None,
|
| 1820 |
+
) -> Response:
|
| 1821 |
+
"""
|
| 1822 |
+
Send a `HEAD` request.
|
| 1823 |
+
|
| 1824 |
+
**Parameters**: See `httpx.request`.
|
| 1825 |
+
"""
|
| 1826 |
+
return await self.request(
|
| 1827 |
+
"HEAD",
|
| 1828 |
+
url,
|
| 1829 |
+
params=params,
|
| 1830 |
+
headers=headers,
|
| 1831 |
+
cookies=cookies,
|
| 1832 |
+
auth=auth,
|
| 1833 |
+
follow_redirects=follow_redirects,
|
| 1834 |
+
timeout=timeout,
|
| 1835 |
+
extensions=extensions,
|
| 1836 |
+
)
|
| 1837 |
+
|
| 1838 |
+
async def post(
|
| 1839 |
+
self,
|
| 1840 |
+
url: URL | str,
|
| 1841 |
+
*,
|
| 1842 |
+
content: RequestContent | None = None,
|
| 1843 |
+
data: RequestData | None = None,
|
| 1844 |
+
files: RequestFiles | None = None,
|
| 1845 |
+
json: typing.Any | None = None,
|
| 1846 |
+
params: QueryParamTypes | None = None,
|
| 1847 |
+
headers: HeaderTypes | None = None,
|
| 1848 |
+
cookies: CookieTypes | None = None,
|
| 1849 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1850 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1851 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1852 |
+
extensions: RequestExtensions | None = None,
|
| 1853 |
+
) -> Response:
|
| 1854 |
+
"""
|
| 1855 |
+
Send a `POST` request.
|
| 1856 |
+
|
| 1857 |
+
**Parameters**: See `httpx.request`.
|
| 1858 |
+
"""
|
| 1859 |
+
return await self.request(
|
| 1860 |
+
"POST",
|
| 1861 |
+
url,
|
| 1862 |
+
content=content,
|
| 1863 |
+
data=data,
|
| 1864 |
+
files=files,
|
| 1865 |
+
json=json,
|
| 1866 |
+
params=params,
|
| 1867 |
+
headers=headers,
|
| 1868 |
+
cookies=cookies,
|
| 1869 |
+
auth=auth,
|
| 1870 |
+
follow_redirects=follow_redirects,
|
| 1871 |
+
timeout=timeout,
|
| 1872 |
+
extensions=extensions,
|
| 1873 |
+
)
|
| 1874 |
+
|
| 1875 |
+
async def put(
|
| 1876 |
+
self,
|
| 1877 |
+
url: URL | str,
|
| 1878 |
+
*,
|
| 1879 |
+
content: RequestContent | None = None,
|
| 1880 |
+
data: RequestData | None = None,
|
| 1881 |
+
files: RequestFiles | None = None,
|
| 1882 |
+
json: typing.Any | None = None,
|
| 1883 |
+
params: QueryParamTypes | None = None,
|
| 1884 |
+
headers: HeaderTypes | None = None,
|
| 1885 |
+
cookies: CookieTypes | None = None,
|
| 1886 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1887 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1888 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1889 |
+
extensions: RequestExtensions | None = None,
|
| 1890 |
+
) -> Response:
|
| 1891 |
+
"""
|
| 1892 |
+
Send a `PUT` request.
|
| 1893 |
+
|
| 1894 |
+
**Parameters**: See `httpx.request`.
|
| 1895 |
+
"""
|
| 1896 |
+
return await self.request(
|
| 1897 |
+
"PUT",
|
| 1898 |
+
url,
|
| 1899 |
+
content=content,
|
| 1900 |
+
data=data,
|
| 1901 |
+
files=files,
|
| 1902 |
+
json=json,
|
| 1903 |
+
params=params,
|
| 1904 |
+
headers=headers,
|
| 1905 |
+
cookies=cookies,
|
| 1906 |
+
auth=auth,
|
| 1907 |
+
follow_redirects=follow_redirects,
|
| 1908 |
+
timeout=timeout,
|
| 1909 |
+
extensions=extensions,
|
| 1910 |
+
)
|
| 1911 |
+
|
| 1912 |
+
async def patch(
|
| 1913 |
+
self,
|
| 1914 |
+
url: URL | str,
|
| 1915 |
+
*,
|
| 1916 |
+
content: RequestContent | None = None,
|
| 1917 |
+
data: RequestData | None = None,
|
| 1918 |
+
files: RequestFiles | None = None,
|
| 1919 |
+
json: typing.Any | None = None,
|
| 1920 |
+
params: QueryParamTypes | None = None,
|
| 1921 |
+
headers: HeaderTypes | None = None,
|
| 1922 |
+
cookies: CookieTypes | None = None,
|
| 1923 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1924 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1925 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1926 |
+
extensions: RequestExtensions | None = None,
|
| 1927 |
+
) -> Response:
|
| 1928 |
+
"""
|
| 1929 |
+
Send a `PATCH` request.
|
| 1930 |
+
|
| 1931 |
+
**Parameters**: See `httpx.request`.
|
| 1932 |
+
"""
|
| 1933 |
+
return await self.request(
|
| 1934 |
+
"PATCH",
|
| 1935 |
+
url,
|
| 1936 |
+
content=content,
|
| 1937 |
+
data=data,
|
| 1938 |
+
files=files,
|
| 1939 |
+
json=json,
|
| 1940 |
+
params=params,
|
| 1941 |
+
headers=headers,
|
| 1942 |
+
cookies=cookies,
|
| 1943 |
+
auth=auth,
|
| 1944 |
+
follow_redirects=follow_redirects,
|
| 1945 |
+
timeout=timeout,
|
| 1946 |
+
extensions=extensions,
|
| 1947 |
+
)
|
| 1948 |
+
|
| 1949 |
+
async def delete(
|
| 1950 |
+
self,
|
| 1951 |
+
url: URL | str,
|
| 1952 |
+
*,
|
| 1953 |
+
params: QueryParamTypes | None = None,
|
| 1954 |
+
headers: HeaderTypes | None = None,
|
| 1955 |
+
cookies: CookieTypes | None = None,
|
| 1956 |
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1957 |
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1958 |
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
| 1959 |
+
extensions: RequestExtensions | None = None,
|
| 1960 |
+
) -> Response:
|
| 1961 |
+
"""
|
| 1962 |
+
Send a `DELETE` request.
|
| 1963 |
+
|
| 1964 |
+
**Parameters**: See `httpx.request`.
|
| 1965 |
+
"""
|
| 1966 |
+
return await self.request(
|
| 1967 |
+
"DELETE",
|
| 1968 |
+
url,
|
| 1969 |
+
params=params,
|
| 1970 |
+
headers=headers,
|
| 1971 |
+
cookies=cookies,
|
| 1972 |
+
auth=auth,
|
| 1973 |
+
follow_redirects=follow_redirects,
|
| 1974 |
+
timeout=timeout,
|
| 1975 |
+
extensions=extensions,
|
| 1976 |
+
)
|
| 1977 |
+
|
| 1978 |
+
async def aclose(self) -> None:
|
| 1979 |
+
"""
|
| 1980 |
+
Close transport and proxies.
|
| 1981 |
+
"""
|
| 1982 |
+
if self._state != ClientState.CLOSED:
|
| 1983 |
+
self._state = ClientState.CLOSED
|
| 1984 |
+
|
| 1985 |
+
await self._transport.aclose()
|
| 1986 |
+
for proxy in self._mounts.values():
|
| 1987 |
+
if proxy is not None:
|
| 1988 |
+
await proxy.aclose()
|
| 1989 |
+
|
| 1990 |
+
async def __aenter__(self: U) -> U:
|
| 1991 |
+
if self._state != ClientState.UNOPENED:
|
| 1992 |
+
msg = {
|
| 1993 |
+
ClientState.OPENED: "Cannot open a client instance more than once.",
|
| 1994 |
+
ClientState.CLOSED: (
|
| 1995 |
+
"Cannot reopen a client instance, once it has been closed."
|
| 1996 |
+
),
|
| 1997 |
+
}[self._state]
|
| 1998 |
+
raise RuntimeError(msg)
|
| 1999 |
+
|
| 2000 |
+
self._state = ClientState.OPENED
|
| 2001 |
+
|
| 2002 |
+
await self._transport.__aenter__()
|
| 2003 |
+
for proxy in self._mounts.values():
|
| 2004 |
+
if proxy is not None:
|
| 2005 |
+
await proxy.__aenter__()
|
| 2006 |
+
return self
|
| 2007 |
+
|
| 2008 |
+
async def __aexit__(
|
| 2009 |
+
self,
|
| 2010 |
+
exc_type: type[BaseException] | None = None,
|
| 2011 |
+
exc_value: BaseException | None = None,
|
| 2012 |
+
traceback: TracebackType | None = None,
|
| 2013 |
+
) -> None:
|
| 2014 |
+
self._state = ClientState.CLOSED
|
| 2015 |
+
|
| 2016 |
+
await self._transport.__aexit__(exc_type, exc_value, traceback)
|
| 2017 |
+
for proxy in self._mounts.values():
|
| 2018 |
+
if proxy is not None:
|
| 2019 |
+
await proxy.__aexit__(exc_type, exc_value, traceback)
|
venv/lib/python3.12/site-packages/httpx/_content.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
import warnings
|
| 5 |
+
from json import dumps as json_dumps
|
| 6 |
+
from typing import (
|
| 7 |
+
Any,
|
| 8 |
+
AsyncIterable,
|
| 9 |
+
AsyncIterator,
|
| 10 |
+
Iterable,
|
| 11 |
+
Iterator,
|
| 12 |
+
Mapping,
|
| 13 |
+
)
|
| 14 |
+
from urllib.parse import urlencode
|
| 15 |
+
|
| 16 |
+
from ._exceptions import StreamClosed, StreamConsumed
|
| 17 |
+
from ._multipart import MultipartStream
|
| 18 |
+
from ._types import (
|
| 19 |
+
AsyncByteStream,
|
| 20 |
+
RequestContent,
|
| 21 |
+
RequestData,
|
| 22 |
+
RequestFiles,
|
| 23 |
+
ResponseContent,
|
| 24 |
+
SyncByteStream,
|
| 25 |
+
)
|
| 26 |
+
from ._utils import peek_filelike_length, primitive_value_to_str
|
| 27 |
+
|
| 28 |
+
__all__ = ["ByteStream"]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ByteStream(AsyncByteStream, SyncByteStream):
|
| 32 |
+
def __init__(self, stream: bytes) -> None:
|
| 33 |
+
self._stream = stream
|
| 34 |
+
|
| 35 |
+
def __iter__(self) -> Iterator[bytes]:
|
| 36 |
+
yield self._stream
|
| 37 |
+
|
| 38 |
+
async def __aiter__(self) -> AsyncIterator[bytes]:
|
| 39 |
+
yield self._stream
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class IteratorByteStream(SyncByteStream):
|
| 43 |
+
CHUNK_SIZE = 65_536
|
| 44 |
+
|
| 45 |
+
def __init__(self, stream: Iterable[bytes]) -> None:
|
| 46 |
+
self._stream = stream
|
| 47 |
+
self._is_stream_consumed = False
|
| 48 |
+
self._is_generator = inspect.isgenerator(stream)
|
| 49 |
+
|
| 50 |
+
def __iter__(self) -> Iterator[bytes]:
|
| 51 |
+
if self._is_stream_consumed and self._is_generator:
|
| 52 |
+
raise StreamConsumed()
|
| 53 |
+
|
| 54 |
+
self._is_stream_consumed = True
|
| 55 |
+
if hasattr(self._stream, "read"):
|
| 56 |
+
# File-like interfaces should use 'read' directly.
|
| 57 |
+
chunk = self._stream.read(self.CHUNK_SIZE)
|
| 58 |
+
while chunk:
|
| 59 |
+
yield chunk
|
| 60 |
+
chunk = self._stream.read(self.CHUNK_SIZE)
|
| 61 |
+
else:
|
| 62 |
+
# Otherwise iterate.
|
| 63 |
+
for part in self._stream:
|
| 64 |
+
yield part
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class AsyncIteratorByteStream(AsyncByteStream):
|
| 68 |
+
CHUNK_SIZE = 65_536
|
| 69 |
+
|
| 70 |
+
def __init__(self, stream: AsyncIterable[bytes]) -> None:
|
| 71 |
+
self._stream = stream
|
| 72 |
+
self._is_stream_consumed = False
|
| 73 |
+
self._is_generator = inspect.isasyncgen(stream)
|
| 74 |
+
|
| 75 |
+
async def __aiter__(self) -> AsyncIterator[bytes]:
|
| 76 |
+
if self._is_stream_consumed and self._is_generator:
|
| 77 |
+
raise StreamConsumed()
|
| 78 |
+
|
| 79 |
+
self._is_stream_consumed = True
|
| 80 |
+
if hasattr(self._stream, "aread"):
|
| 81 |
+
# File-like interfaces should use 'aread' directly.
|
| 82 |
+
chunk = await self._stream.aread(self.CHUNK_SIZE)
|
| 83 |
+
while chunk:
|
| 84 |
+
yield chunk
|
| 85 |
+
chunk = await self._stream.aread(self.CHUNK_SIZE)
|
| 86 |
+
else:
|
| 87 |
+
# Otherwise iterate.
|
| 88 |
+
async for part in self._stream:
|
| 89 |
+
yield part
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class UnattachedStream(AsyncByteStream, SyncByteStream):
|
| 93 |
+
"""
|
| 94 |
+
If a request or response is serialized using pickle, then it is no longer
|
| 95 |
+
attached to a stream for I/O purposes. Any stream operations should result
|
| 96 |
+
in `httpx.StreamClosed`.
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
def __iter__(self) -> Iterator[bytes]:
|
| 100 |
+
raise StreamClosed()
|
| 101 |
+
|
| 102 |
+
async def __aiter__(self) -> AsyncIterator[bytes]:
|
| 103 |
+
raise StreamClosed()
|
| 104 |
+
yield b"" # pragma: no cover
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def encode_content(
|
| 108 |
+
content: str | bytes | Iterable[bytes] | AsyncIterable[bytes],
|
| 109 |
+
) -> tuple[dict[str, str], SyncByteStream | AsyncByteStream]:
|
| 110 |
+
if isinstance(content, (bytes, str)):
|
| 111 |
+
body = content.encode("utf-8") if isinstance(content, str) else content
|
| 112 |
+
content_length = len(body)
|
| 113 |
+
headers = {"Content-Length": str(content_length)} if body else {}
|
| 114 |
+
return headers, ByteStream(body)
|
| 115 |
+
|
| 116 |
+
elif isinstance(content, Iterable) and not isinstance(content, dict):
|
| 117 |
+
# `not isinstance(content, dict)` is a bit oddly specific, but it
|
| 118 |
+
# catches a case that's easy for users to make in error, and would
|
| 119 |
+
# otherwise pass through here, like any other bytes-iterable,
|
| 120 |
+
# because `dict` happens to be iterable. See issue #2491.
|
| 121 |
+
content_length_or_none = peek_filelike_length(content)
|
| 122 |
+
|
| 123 |
+
if content_length_or_none is None:
|
| 124 |
+
headers = {"Transfer-Encoding": "chunked"}
|
| 125 |
+
else:
|
| 126 |
+
headers = {"Content-Length": str(content_length_or_none)}
|
| 127 |
+
return headers, IteratorByteStream(content) # type: ignore
|
| 128 |
+
|
| 129 |
+
elif isinstance(content, AsyncIterable):
|
| 130 |
+
headers = {"Transfer-Encoding": "chunked"}
|
| 131 |
+
return headers, AsyncIteratorByteStream(content)
|
| 132 |
+
|
| 133 |
+
raise TypeError(f"Unexpected type for 'content', {type(content)!r}")
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def encode_urlencoded_data(
|
| 137 |
+
data: RequestData,
|
| 138 |
+
) -> tuple[dict[str, str], ByteStream]:
|
| 139 |
+
plain_data = []
|
| 140 |
+
for key, value in data.items():
|
| 141 |
+
if isinstance(value, (list, tuple)):
|
| 142 |
+
plain_data.extend([(key, primitive_value_to_str(item)) for item in value])
|
| 143 |
+
else:
|
| 144 |
+
plain_data.append((key, primitive_value_to_str(value)))
|
| 145 |
+
body = urlencode(plain_data, doseq=True).encode("utf-8")
|
| 146 |
+
content_length = str(len(body))
|
| 147 |
+
content_type = "application/x-www-form-urlencoded"
|
| 148 |
+
headers = {"Content-Length": content_length, "Content-Type": content_type}
|
| 149 |
+
return headers, ByteStream(body)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def encode_multipart_data(
|
| 153 |
+
data: RequestData, files: RequestFiles, boundary: bytes | None
|
| 154 |
+
) -> tuple[dict[str, str], MultipartStream]:
|
| 155 |
+
multipart = MultipartStream(data=data, files=files, boundary=boundary)
|
| 156 |
+
headers = multipart.get_headers()
|
| 157 |
+
return headers, multipart
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def encode_text(text: str) -> tuple[dict[str, str], ByteStream]:
|
| 161 |
+
body = text.encode("utf-8")
|
| 162 |
+
content_length = str(len(body))
|
| 163 |
+
content_type = "text/plain; charset=utf-8"
|
| 164 |
+
headers = {"Content-Length": content_length, "Content-Type": content_type}
|
| 165 |
+
return headers, ByteStream(body)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def encode_html(html: str) -> tuple[dict[str, str], ByteStream]:
|
| 169 |
+
body = html.encode("utf-8")
|
| 170 |
+
content_length = str(len(body))
|
| 171 |
+
content_type = "text/html; charset=utf-8"
|
| 172 |
+
headers = {"Content-Length": content_length, "Content-Type": content_type}
|
| 173 |
+
return headers, ByteStream(body)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def encode_json(json: Any) -> tuple[dict[str, str], ByteStream]:
|
| 177 |
+
body = json_dumps(
|
| 178 |
+
json, ensure_ascii=False, separators=(",", ":"), allow_nan=False
|
| 179 |
+
).encode("utf-8")
|
| 180 |
+
content_length = str(len(body))
|
| 181 |
+
content_type = "application/json"
|
| 182 |
+
headers = {"Content-Length": content_length, "Content-Type": content_type}
|
| 183 |
+
return headers, ByteStream(body)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def encode_request(
|
| 187 |
+
content: RequestContent | None = None,
|
| 188 |
+
data: RequestData | None = None,
|
| 189 |
+
files: RequestFiles | None = None,
|
| 190 |
+
json: Any | None = None,
|
| 191 |
+
boundary: bytes | None = None,
|
| 192 |
+
) -> tuple[dict[str, str], SyncByteStream | AsyncByteStream]:
|
| 193 |
+
"""
|
| 194 |
+
Handles encoding the given `content`, `data`, `files`, and `json`,
|
| 195 |
+
returning a two-tuple of (<headers>, <stream>).
|
| 196 |
+
"""
|
| 197 |
+
if data is not None and not isinstance(data, Mapping):
|
| 198 |
+
# We prefer to separate `content=<bytes|str|byte iterator|bytes aiterator>`
|
| 199 |
+
# for raw request content, and `data=<form data>` for url encoded or
|
| 200 |
+
# multipart form content.
|
| 201 |
+
#
|
| 202 |
+
# However for compat with requests, we *do* still support
|
| 203 |
+
# `data=<bytes...>` usages. We deal with that case here, treating it
|
| 204 |
+
# as if `content=<...>` had been supplied instead.
|
| 205 |
+
message = "Use 'content=<...>' to upload raw bytes/text content."
|
| 206 |
+
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
| 207 |
+
return encode_content(data)
|
| 208 |
+
|
| 209 |
+
if content is not None:
|
| 210 |
+
return encode_content(content)
|
| 211 |
+
elif files:
|
| 212 |
+
return encode_multipart_data(data or {}, files, boundary)
|
| 213 |
+
elif data:
|
| 214 |
+
return encode_urlencoded_data(data)
|
| 215 |
+
elif json is not None:
|
| 216 |
+
return encode_json(json)
|
| 217 |
+
|
| 218 |
+
return {}, ByteStream(b"")
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def encode_response(
|
| 222 |
+
content: ResponseContent | None = None,
|
| 223 |
+
text: str | None = None,
|
| 224 |
+
html: str | None = None,
|
| 225 |
+
json: Any | None = None,
|
| 226 |
+
) -> tuple[dict[str, str], SyncByteStream | AsyncByteStream]:
|
| 227 |
+
"""
|
| 228 |
+
Handles encoding the given `content`, returning a two-tuple of
|
| 229 |
+
(<headers>, <stream>).
|
| 230 |
+
"""
|
| 231 |
+
if content is not None:
|
| 232 |
+
return encode_content(content)
|
| 233 |
+
elif text is not None:
|
| 234 |
+
return encode_text(text)
|
| 235 |
+
elif html is not None:
|
| 236 |
+
return encode_html(html)
|
| 237 |
+
elif json is not None:
|
| 238 |
+
return encode_json(json)
|
| 239 |
+
|
| 240 |
+
return {}, ByteStream(b"")
|
venv/lib/python3.12/site-packages/httpx/_decoders.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Handlers for Content-Encoding.
|
| 3 |
+
|
| 4 |
+
See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import codecs
|
| 10 |
+
import io
|
| 11 |
+
import typing
|
| 12 |
+
import zlib
|
| 13 |
+
|
| 14 |
+
from ._exceptions import DecodingError
|
| 15 |
+
|
| 16 |
+
# Brotli support is optional
|
| 17 |
+
try:
|
| 18 |
+
# The C bindings in `brotli` are recommended for CPython.
|
| 19 |
+
import brotli
|
| 20 |
+
except ImportError: # pragma: no cover
|
| 21 |
+
try:
|
| 22 |
+
# The CFFI bindings in `brotlicffi` are recommended for PyPy
|
| 23 |
+
# and other environments.
|
| 24 |
+
import brotlicffi as brotli
|
| 25 |
+
except ImportError:
|
| 26 |
+
brotli = None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Zstandard support is optional
|
| 30 |
+
try:
|
| 31 |
+
import zstandard
|
| 32 |
+
except ImportError: # pragma: no cover
|
| 33 |
+
zstandard = None # type: ignore
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class ContentDecoder:
|
| 37 |
+
def decode(self, data: bytes) -> bytes:
|
| 38 |
+
raise NotImplementedError() # pragma: no cover
|
| 39 |
+
|
| 40 |
+
def flush(self) -> bytes:
|
| 41 |
+
raise NotImplementedError() # pragma: no cover
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class IdentityDecoder(ContentDecoder):
|
| 45 |
+
"""
|
| 46 |
+
Handle unencoded data.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
def decode(self, data: bytes) -> bytes:
|
| 50 |
+
return data
|
| 51 |
+
|
| 52 |
+
def flush(self) -> bytes:
|
| 53 |
+
return b""
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class DeflateDecoder(ContentDecoder):
|
| 57 |
+
"""
|
| 58 |
+
Handle 'deflate' decoding.
|
| 59 |
+
|
| 60 |
+
See: https://stackoverflow.com/questions/1838699
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
def __init__(self) -> None:
|
| 64 |
+
self.first_attempt = True
|
| 65 |
+
self.decompressor = zlib.decompressobj()
|
| 66 |
+
|
| 67 |
+
def decode(self, data: bytes) -> bytes:
|
| 68 |
+
was_first_attempt = self.first_attempt
|
| 69 |
+
self.first_attempt = False
|
| 70 |
+
try:
|
| 71 |
+
return self.decompressor.decompress(data)
|
| 72 |
+
except zlib.error as exc:
|
| 73 |
+
if was_first_attempt:
|
| 74 |
+
self.decompressor = zlib.decompressobj(-zlib.MAX_WBITS)
|
| 75 |
+
return self.decode(data)
|
| 76 |
+
raise DecodingError(str(exc)) from exc
|
| 77 |
+
|
| 78 |
+
def flush(self) -> bytes:
|
| 79 |
+
try:
|
| 80 |
+
return self.decompressor.flush()
|
| 81 |
+
except zlib.error as exc: # pragma: no cover
|
| 82 |
+
raise DecodingError(str(exc)) from exc
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class GZipDecoder(ContentDecoder):
|
| 86 |
+
"""
|
| 87 |
+
Handle 'gzip' decoding.
|
| 88 |
+
|
| 89 |
+
See: https://stackoverflow.com/questions/1838699
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
def __init__(self) -> None:
|
| 93 |
+
self.decompressor = zlib.decompressobj(zlib.MAX_WBITS | 16)
|
| 94 |
+
|
| 95 |
+
def decode(self, data: bytes) -> bytes:
|
| 96 |
+
try:
|
| 97 |
+
return self.decompressor.decompress(data)
|
| 98 |
+
except zlib.error as exc:
|
| 99 |
+
raise DecodingError(str(exc)) from exc
|
| 100 |
+
|
| 101 |
+
def flush(self) -> bytes:
|
| 102 |
+
try:
|
| 103 |
+
return self.decompressor.flush()
|
| 104 |
+
except zlib.error as exc: # pragma: no cover
|
| 105 |
+
raise DecodingError(str(exc)) from exc
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class BrotliDecoder(ContentDecoder):
|
| 109 |
+
"""
|
| 110 |
+
Handle 'brotli' decoding.
|
| 111 |
+
|
| 112 |
+
Requires `pip install brotlipy`. See: https://brotlipy.readthedocs.io/
|
| 113 |
+
or `pip install brotli`. See https://github.com/google/brotli
|
| 114 |
+
Supports both 'brotlipy' and 'Brotli' packages since they share an import
|
| 115 |
+
name. The top branches are for 'brotlipy' and bottom branches for 'Brotli'
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
def __init__(self) -> None:
|
| 119 |
+
if brotli is None: # pragma: no cover
|
| 120 |
+
raise ImportError(
|
| 121 |
+
"Using 'BrotliDecoder', but neither of the 'brotlicffi' or 'brotli' "
|
| 122 |
+
"packages have been installed. "
|
| 123 |
+
"Make sure to install httpx using `pip install httpx[brotli]`."
|
| 124 |
+
) from None
|
| 125 |
+
|
| 126 |
+
self.decompressor = brotli.Decompressor()
|
| 127 |
+
self.seen_data = False
|
| 128 |
+
self._decompress: typing.Callable[[bytes], bytes]
|
| 129 |
+
if hasattr(self.decompressor, "decompress"):
|
| 130 |
+
# The 'brotlicffi' package.
|
| 131 |
+
self._decompress = self.decompressor.decompress # pragma: no cover
|
| 132 |
+
else:
|
| 133 |
+
# The 'brotli' package.
|
| 134 |
+
self._decompress = self.decompressor.process # pragma: no cover
|
| 135 |
+
|
| 136 |
+
def decode(self, data: bytes) -> bytes:
|
| 137 |
+
if not data:
|
| 138 |
+
return b""
|
| 139 |
+
self.seen_data = True
|
| 140 |
+
try:
|
| 141 |
+
return self._decompress(data)
|
| 142 |
+
except brotli.error as exc:
|
| 143 |
+
raise DecodingError(str(exc)) from exc
|
| 144 |
+
|
| 145 |
+
def flush(self) -> bytes:
|
| 146 |
+
if not self.seen_data:
|
| 147 |
+
return b""
|
| 148 |
+
try:
|
| 149 |
+
if hasattr(self.decompressor, "finish"):
|
| 150 |
+
# Only available in the 'brotlicffi' package.
|
| 151 |
+
|
| 152 |
+
# As the decompressor decompresses eagerly, this
|
| 153 |
+
# will never actually emit any data. However, it will potentially throw
|
| 154 |
+
# errors if a truncated or damaged data stream has been used.
|
| 155 |
+
self.decompressor.finish() # pragma: no cover
|
| 156 |
+
return b""
|
| 157 |
+
except brotli.error as exc: # pragma: no cover
|
| 158 |
+
raise DecodingError(str(exc)) from exc
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class ZStandardDecoder(ContentDecoder):
|
| 162 |
+
"""
|
| 163 |
+
Handle 'zstd' RFC 8878 decoding.
|
| 164 |
+
|
| 165 |
+
Requires `pip install zstandard`.
|
| 166 |
+
Can be installed as a dependency of httpx using `pip install httpx[zstd]`.
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
# inspired by the ZstdDecoder implementation in urllib3
|
| 170 |
+
def __init__(self) -> None:
|
| 171 |
+
if zstandard is None: # pragma: no cover
|
| 172 |
+
raise ImportError(
|
| 173 |
+
"Using 'ZStandardDecoder', ..."
|
| 174 |
+
"Make sure to install httpx using `pip install httpx[zstd]`."
|
| 175 |
+
) from None
|
| 176 |
+
|
| 177 |
+
self.decompressor = zstandard.ZstdDecompressor().decompressobj()
|
| 178 |
+
self.seen_data = False
|
| 179 |
+
|
| 180 |
+
def decode(self, data: bytes) -> bytes:
|
| 181 |
+
assert zstandard is not None
|
| 182 |
+
self.seen_data = True
|
| 183 |
+
output = io.BytesIO()
|
| 184 |
+
try:
|
| 185 |
+
output.write(self.decompressor.decompress(data))
|
| 186 |
+
while self.decompressor.eof and self.decompressor.unused_data:
|
| 187 |
+
unused_data = self.decompressor.unused_data
|
| 188 |
+
self.decompressor = zstandard.ZstdDecompressor().decompressobj()
|
| 189 |
+
output.write(self.decompressor.decompress(unused_data))
|
| 190 |
+
except zstandard.ZstdError as exc:
|
| 191 |
+
raise DecodingError(str(exc)) from exc
|
| 192 |
+
return output.getvalue()
|
| 193 |
+
|
| 194 |
+
def flush(self) -> bytes:
|
| 195 |
+
if not self.seen_data:
|
| 196 |
+
return b""
|
| 197 |
+
ret = self.decompressor.flush() # note: this is a no-op
|
| 198 |
+
if not self.decompressor.eof:
|
| 199 |
+
raise DecodingError("Zstandard data is incomplete") # pragma: no cover
|
| 200 |
+
return bytes(ret)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
class MultiDecoder(ContentDecoder):
|
| 204 |
+
"""
|
| 205 |
+
Handle the case where multiple encodings have been applied.
|
| 206 |
+
"""
|
| 207 |
+
|
| 208 |
+
def __init__(self, children: typing.Sequence[ContentDecoder]) -> None:
|
| 209 |
+
"""
|
| 210 |
+
'children' should be a sequence of decoders in the order in which
|
| 211 |
+
each was applied.
|
| 212 |
+
"""
|
| 213 |
+
# Note that we reverse the order for decoding.
|
| 214 |
+
self.children = list(reversed(children))
|
| 215 |
+
|
| 216 |
+
def decode(self, data: bytes) -> bytes:
|
| 217 |
+
for child in self.children:
|
| 218 |
+
data = child.decode(data)
|
| 219 |
+
return data
|
| 220 |
+
|
| 221 |
+
def flush(self) -> bytes:
|
| 222 |
+
data = b""
|
| 223 |
+
for child in self.children:
|
| 224 |
+
data = child.decode(data) + child.flush()
|
| 225 |
+
return data
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
class ByteChunker:
|
| 229 |
+
"""
|
| 230 |
+
Handles returning byte content in fixed-size chunks.
|
| 231 |
+
"""
|
| 232 |
+
|
| 233 |
+
def __init__(self, chunk_size: int | None = None) -> None:
|
| 234 |
+
self._buffer = io.BytesIO()
|
| 235 |
+
self._chunk_size = chunk_size
|
| 236 |
+
|
| 237 |
+
def decode(self, content: bytes) -> list[bytes]:
|
| 238 |
+
if self._chunk_size is None:
|
| 239 |
+
return [content] if content else []
|
| 240 |
+
|
| 241 |
+
self._buffer.write(content)
|
| 242 |
+
if self._buffer.tell() >= self._chunk_size:
|
| 243 |
+
value = self._buffer.getvalue()
|
| 244 |
+
chunks = [
|
| 245 |
+
value[i : i + self._chunk_size]
|
| 246 |
+
for i in range(0, len(value), self._chunk_size)
|
| 247 |
+
]
|
| 248 |
+
if len(chunks[-1]) == self._chunk_size:
|
| 249 |
+
self._buffer.seek(0)
|
| 250 |
+
self._buffer.truncate()
|
| 251 |
+
return chunks
|
| 252 |
+
else:
|
| 253 |
+
self._buffer.seek(0)
|
| 254 |
+
self._buffer.write(chunks[-1])
|
| 255 |
+
self._buffer.truncate()
|
| 256 |
+
return chunks[:-1]
|
| 257 |
+
else:
|
| 258 |
+
return []
|
| 259 |
+
|
| 260 |
+
def flush(self) -> list[bytes]:
|
| 261 |
+
value = self._buffer.getvalue()
|
| 262 |
+
self._buffer.seek(0)
|
| 263 |
+
self._buffer.truncate()
|
| 264 |
+
return [value] if value else []
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
class TextChunker:
|
| 268 |
+
"""
|
| 269 |
+
Handles returning text content in fixed-size chunks.
|
| 270 |
+
"""
|
| 271 |
+
|
| 272 |
+
def __init__(self, chunk_size: int | None = None) -> None:
|
| 273 |
+
self._buffer = io.StringIO()
|
| 274 |
+
self._chunk_size = chunk_size
|
| 275 |
+
|
| 276 |
+
def decode(self, content: str) -> list[str]:
|
| 277 |
+
if self._chunk_size is None:
|
| 278 |
+
return [content] if content else []
|
| 279 |
+
|
| 280 |
+
self._buffer.write(content)
|
| 281 |
+
if self._buffer.tell() >= self._chunk_size:
|
| 282 |
+
value = self._buffer.getvalue()
|
| 283 |
+
chunks = [
|
| 284 |
+
value[i : i + self._chunk_size]
|
| 285 |
+
for i in range(0, len(value), self._chunk_size)
|
| 286 |
+
]
|
| 287 |
+
if len(chunks[-1]) == self._chunk_size:
|
| 288 |
+
self._buffer.seek(0)
|
| 289 |
+
self._buffer.truncate()
|
| 290 |
+
return chunks
|
| 291 |
+
else:
|
| 292 |
+
self._buffer.seek(0)
|
| 293 |
+
self._buffer.write(chunks[-1])
|
| 294 |
+
self._buffer.truncate()
|
| 295 |
+
return chunks[:-1]
|
| 296 |
+
else:
|
| 297 |
+
return []
|
| 298 |
+
|
| 299 |
+
def flush(self) -> list[str]:
|
| 300 |
+
value = self._buffer.getvalue()
|
| 301 |
+
self._buffer.seek(0)
|
| 302 |
+
self._buffer.truncate()
|
| 303 |
+
return [value] if value else []
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
class TextDecoder:
|
| 307 |
+
"""
|
| 308 |
+
Handles incrementally decoding bytes into text
|
| 309 |
+
"""
|
| 310 |
+
|
| 311 |
+
def __init__(self, encoding: str = "utf-8") -> None:
|
| 312 |
+
self.decoder = codecs.getincrementaldecoder(encoding)(errors="replace")
|
| 313 |
+
|
| 314 |
+
def decode(self, data: bytes) -> str:
|
| 315 |
+
return self.decoder.decode(data)
|
| 316 |
+
|
| 317 |
+
def flush(self) -> str:
|
| 318 |
+
return self.decoder.decode(b"", True)
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
class LineDecoder:
|
| 322 |
+
"""
|
| 323 |
+
Handles incrementally reading lines from text.
|
| 324 |
+
|
| 325 |
+
Has the same behaviour as the stdllib splitlines,
|
| 326 |
+
but handling the input iteratively.
|
| 327 |
+
"""
|
| 328 |
+
|
| 329 |
+
def __init__(self) -> None:
|
| 330 |
+
self.buffer: list[str] = []
|
| 331 |
+
self.trailing_cr: bool = False
|
| 332 |
+
|
| 333 |
+
def decode(self, text: str) -> list[str]:
|
| 334 |
+
# See https://docs.python.org/3/library/stdtypes.html#str.splitlines
|
| 335 |
+
NEWLINE_CHARS = "\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029"
|
| 336 |
+
|
| 337 |
+
# We always push a trailing `\r` into the next decode iteration.
|
| 338 |
+
if self.trailing_cr:
|
| 339 |
+
text = "\r" + text
|
| 340 |
+
self.trailing_cr = False
|
| 341 |
+
if text.endswith("\r"):
|
| 342 |
+
self.trailing_cr = True
|
| 343 |
+
text = text[:-1]
|
| 344 |
+
|
| 345 |
+
if not text:
|
| 346 |
+
# NOTE: the edge case input of empty text doesn't occur in practice,
|
| 347 |
+
# because other httpx internals filter out this value
|
| 348 |
+
return [] # pragma: no cover
|
| 349 |
+
|
| 350 |
+
trailing_newline = text[-1] in NEWLINE_CHARS
|
| 351 |
+
lines = text.splitlines()
|
| 352 |
+
|
| 353 |
+
if len(lines) == 1 and not trailing_newline:
|
| 354 |
+
# No new lines, buffer the input and continue.
|
| 355 |
+
self.buffer.append(lines[0])
|
| 356 |
+
return []
|
| 357 |
+
|
| 358 |
+
if self.buffer:
|
| 359 |
+
# Include any existing buffer in the first portion of the
|
| 360 |
+
# splitlines result.
|
| 361 |
+
lines = ["".join(self.buffer) + lines[0]] + lines[1:]
|
| 362 |
+
self.buffer = []
|
| 363 |
+
|
| 364 |
+
if not trailing_newline:
|
| 365 |
+
# If the last segment of splitlines is not newline terminated,
|
| 366 |
+
# then drop it from our output and start a new buffer.
|
| 367 |
+
self.buffer = [lines.pop()]
|
| 368 |
+
|
| 369 |
+
return lines
|
| 370 |
+
|
| 371 |
+
def flush(self) -> list[str]:
|
| 372 |
+
if not self.buffer and not self.trailing_cr:
|
| 373 |
+
return []
|
| 374 |
+
|
| 375 |
+
lines = ["".join(self.buffer)]
|
| 376 |
+
self.buffer = []
|
| 377 |
+
self.trailing_cr = False
|
| 378 |
+
return lines
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
SUPPORTED_DECODERS = {
|
| 382 |
+
"identity": IdentityDecoder,
|
| 383 |
+
"gzip": GZipDecoder,
|
| 384 |
+
"deflate": DeflateDecoder,
|
| 385 |
+
"br": BrotliDecoder,
|
| 386 |
+
"zstd": ZStandardDecoder,
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
if brotli is None:
|
| 391 |
+
SUPPORTED_DECODERS.pop("br") # pragma: no cover
|
| 392 |
+
if zstandard is None:
|
| 393 |
+
SUPPORTED_DECODERS.pop("zstd") # pragma: no cover
|
venv/lib/python3.12/site-packages/httpx/_exceptions.py
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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nectError
|
| 14 |
+
· ReadError
|
| 15 |
+
· WriteError
|
| 16 |
+
· CloseError
|
| 17 |
+
- ProtocolError
|
| 18 |
+
· LocalProtocolError
|
| 19 |
+
· RemoteProtocolError
|
| 20 |
+
- ProxyError
|
| 21 |
+
- UnsupportedProtocol
|
| 22 |
+
+ DecodingError
|
| 23 |
+
+ TooManyRedirects
|
| 24 |
+
x HTTPStatusError
|
| 25 |
+
* InvalidURL
|
| 26 |
+
* CookieConflict
|
| 27 |
+
* StreamError
|
| 28 |
+
x StreamConsumed
|
| 29 |
+
x StreamClosed
|
| 30 |
+
x ResponseNotRead
|
| 31 |
+
x RequestNotRead
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
from __future__ import annotations
|
| 35 |
+
|
| 36 |
+
import contextlib
|
| 37 |
+
import typing
|
| 38 |
+
|
| 39 |
+
if typing.TYPE_CHECKING:
|
| 40 |
+
from ._models import Request, Response # pragma: no cover
|
| 41 |
+
|
| 42 |
+
__all__ = [
|
| 43 |
+
"CloseError",
|
| 44 |
+
"ConnectError",
|
| 45 |
+
"ConnectTimeout",
|
| 46 |
+
"CookieConflict",
|
| 47 |
+
"DecodingError",
|
| 48 |
+
"HTTPError",
|
| 49 |
+
"HTTPStatusError",
|
| 50 |
+
"InvalidURL",
|
| 51 |
+
"LocalProtocolError",
|
| 52 |
+
"NetworkError",
|
| 53 |
+
"PoolTimeout",
|
| 54 |
+
"ProtocolError",
|
| 55 |
+
"ProxyError",
|
| 56 |
+
"ReadError",
|
| 57 |
+
"ReadTimeout",
|
| 58 |
+
"RemoteProtocolError",
|
| 59 |
+
"RequestError",
|
| 60 |
+
"RequestNotRead",
|
| 61 |
+
"ResponseNotRead",
|
| 62 |
+
"StreamClosed",
|
| 63 |
+
"StreamConsumed",
|
| 64 |
+
"StreamError",
|
| 65 |
+
"TimeoutException",
|
| 66 |
+
"TooManyRedirects",
|
| 67 |
+
"TransportError",
|
| 68 |
+
"UnsupportedProtocol",
|
| 69 |
+
"WriteError",
|
| 70 |
+
"WriteTimeout",
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class HTTPError(Exception):
|
| 75 |
+
"""
|
| 76 |
+
Base class for `RequestError` and `HTTPStatusError`.
|
| 77 |
+
|
| 78 |
+
Useful for `try...except` blocks when issuing a request,
|
| 79 |
+
and then calling `.raise_for_status()`.
|
| 80 |
+
|
| 81 |
+
For example:
|
| 82 |
+
|
| 83 |
+
```
|
| 84 |
+
try:
|
| 85 |
+
response = httpx.get("https://www.example.com")
|
| 86 |
+
response.raise_for_status()
|
| 87 |
+
except httpx.HTTPError as exc:
|
| 88 |
+
print(f"HTTP Exception for {exc.request.url} - {exc}")
|
| 89 |
+
```
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
def __init__(self, message: str) -> None:
|
| 93 |
+
super().__init__(message)
|
| 94 |
+
self._request: Request | None = None
|
| 95 |
+
|
| 96 |
+
@property
|
| 97 |
+
def request(self) -> Request:
|
| 98 |
+
if self._request is None:
|
| 99 |
+
raise RuntimeError("The .request property has not been set.")
|
| 100 |
+
return self._request
|
| 101 |
+
|
| 102 |
+
@request.setter
|
| 103 |
+
def request(self, request: Request) -> None:
|
| 104 |
+
self._request = request
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class RequestError(HTTPError):
|
| 108 |
+
"""
|
| 109 |
+
Base class for all exceptions that may occur when issuing a `.request()`.
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
def __init__(self, message: str, *, request: Request | None = None) -> None:
|
| 113 |
+
super().__init__(message)
|
| 114 |
+
# At the point an exception is raised we won't typically have a request
|
| 115 |
+
# instance to associate it with.
|
| 116 |
+
#
|
| 117 |
+
# The 'request_context' context manager is used within the Client and
|
| 118 |
+
# Response methods in order to ensure that any raised exceptions
|
| 119 |
+
# have a `.request` property set on them.
|
| 120 |
+
self._request = request
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
class TransportError(RequestError):
|
| 124 |
+
"""
|
| 125 |
+
Base class for all exceptions that occur at the level of the Transport API.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
# Timeout exceptions...
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class TimeoutException(TransportError):
|
| 133 |
+
"""
|
| 134 |
+
The base class for timeout errors.
|
| 135 |
+
|
| 136 |
+
An operation has timed out.
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
class ConnectTimeout(TimeoutException):
|
| 141 |
+
"""
|
| 142 |
+
Timed out while connecting to the host.
|
| 143 |
+
"""
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class ReadTimeout(TimeoutException):
|
| 147 |
+
"""
|
| 148 |
+
Timed out while receiving data from the host.
|
| 149 |
+
"""
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
class WriteTimeout(TimeoutException):
|
| 153 |
+
"""
|
| 154 |
+
Timed out while sending data to the host.
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class PoolTimeout(TimeoutException):
|
| 159 |
+
"""
|
| 160 |
+
Timed out waiting to acquire a connection from the pool.
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
# Core networking exceptions...
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
class NetworkError(TransportError):
|
| 168 |
+
"""
|
| 169 |
+
The base class for network-related errors.
|
| 170 |
+
|
| 171 |
+
An error occurred while interacting with the network.
|
| 172 |
+
"""
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class ReadError(NetworkError):
|
| 176 |
+
"""
|
| 177 |
+
Failed to receive data from the network.
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class WriteError(NetworkError):
|
| 182 |
+
"""
|
| 183 |
+
Failed to send data through the network.
|
| 184 |
+
"""
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
class ConnectError(NetworkError):
|
| 188 |
+
"""
|
| 189 |
+
Failed to establish a connection.
|
| 190 |
+
"""
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
class CloseError(NetworkError):
|
| 194 |
+
"""
|
| 195 |
+
Failed to close a connection.
|
| 196 |
+
"""
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# Other transport exceptions...
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class ProxyError(TransportError):
|
| 203 |
+
"""
|
| 204 |
+
An error occurred while establishing a proxy connection.
|
| 205 |
+
"""
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
class UnsupportedProtocol(TransportError):
|
| 209 |
+
"""
|
| 210 |
+
Attempted to make a request to an unsupported protocol.
|
| 211 |
+
|
| 212 |
+
For example issuing a request to `ftp://www.example.com`.
|
| 213 |
+
"""
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class ProtocolError(TransportError):
|
| 217 |
+
"""
|
| 218 |
+
The protocol was violated.
|
| 219 |
+
"""
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
class LocalProtocolError(ProtocolError):
|
| 223 |
+
"""
|
| 224 |
+
A protocol was violated by the client.
|
| 225 |
+
|
| 226 |
+
For example if the user instantiated a `Request` instance explicitly,
|
| 227 |
+
failed to include the mandatory `Host:` header, and then issued it directly
|
| 228 |
+
using `client.send()`.
|
| 229 |
+
"""
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class RemoteProtocolError(ProtocolError):
|
| 233 |
+
"""
|
| 234 |
+
The protocol was violated by the server.
|
| 235 |
+
|
| 236 |
+
For example, returning malformed HTTP.
|
| 237 |
+
"""
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
# Other request exceptions...
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
class DecodingError(RequestError):
|
| 244 |
+
"""
|
| 245 |
+
Decoding of the response failed, due to a malformed encoding.
|
| 246 |
+
"""
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
class TooManyRedirects(RequestError):
|
| 250 |
+
"""
|
| 251 |
+
Too many redirects.
|
| 252 |
+
"""
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
# Client errors
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
class HTTPStatusError(HTTPError):
|
| 259 |
+
"""
|
| 260 |
+
The response had an error HTTP status of 4xx or 5xx.
|
| 261 |
+
|
| 262 |
+
May be raised when calling `response.raise_for_status()`
|
| 263 |
+
"""
|
| 264 |
+
|
| 265 |
+
def __init__(self, message: str, *, request: Request, response: Response) -> None:
|
| 266 |
+
super().__init__(message)
|
| 267 |
+
self.request = request
|
| 268 |
+
self.response = response
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
class InvalidURL(Exception):
|
| 272 |
+
"""
|
| 273 |
+
URL is improperly formed or cannot be parsed.
|
| 274 |
+
"""
|
| 275 |
+
|
| 276 |
+
def __init__(self, message: str) -> None:
|
| 277 |
+
super().__init__(message)
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
class CookieConflict(Exception):
|
| 281 |
+
"""
|
| 282 |
+
Attempted to lookup a cookie by name, but multiple cookies existed.
|
| 283 |
+
|
| 284 |
+
Can occur when calling `response.cookies.get(...)`.
|
| 285 |
+
"""
|
| 286 |
+
|
| 287 |
+
def __init__(self, message: str) -> None:
|
| 288 |
+
super().__init__(message)
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
# Stream exceptions...
|
| 292 |
+
|
| 293 |
+
# These may occur as the result of a programming error, by accessing
|
| 294 |
+
# the request/response stream in an invalid manner.
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class StreamError(RuntimeError):
|
| 298 |
+
"""
|
| 299 |
+
The base class for stream exceptions.
|
| 300 |
+
|
| 301 |
+
The developer made an error in accessing the request stream in
|
| 302 |
+
an invalid way.
|
| 303 |
+
"""
|
| 304 |
+
|
| 305 |
+
def __init__(self, message: str) -> None:
|
| 306 |
+
super().__init__(message)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
class StreamConsumed(StreamError):
|
| 310 |
+
"""
|
| 311 |
+
Attempted to read or stream content, but the content has already
|
| 312 |
+
been streamed.
|
| 313 |
+
"""
|
| 314 |
+
|
| 315 |
+
def __init__(self) -> None:
|
| 316 |
+
message = (
|
| 317 |
+
"Attempted to read or stream some content, but the content has "
|
| 318 |
+
"already been streamed. For requests, this could be due to passing "
|
| 319 |
+
"a generator as request content, and then receiving a redirect "
|
| 320 |
+
"response or a secondary request as part of an authentication flow."
|
| 321 |
+
"For responses, this could be due to attempting to stream the response "
|
| 322 |
+
"content more than once."
|
| 323 |
+
)
|
| 324 |
+
super().__init__(message)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class StreamClosed(StreamError):
|
| 328 |
+
"""
|
| 329 |
+
Attempted to read or stream response content, but the request has been
|
| 330 |
+
closed.
|
| 331 |
+
"""
|
| 332 |
+
|
| 333 |
+
def __init__(self) -> None:
|
| 334 |
+
message = (
|
| 335 |
+
"Attempted to read or stream content, but the stream has " "been closed."
|
| 336 |
+
)
|
| 337 |
+
super().__init__(message)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
class ResponseNotRead(StreamError):
|
| 341 |
+
"""
|
| 342 |
+
Attempted to access streaming response content, without having called `read()`.
|
| 343 |
+
"""
|
| 344 |
+
|
| 345 |
+
def __init__(self) -> None:
|
| 346 |
+
message = (
|
| 347 |
+
"Attempted to access streaming response content,"
|
| 348 |
+
" without having called `read()`."
|
| 349 |
+
)
|
| 350 |
+
super().__init__(message)
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
class RequestNotRead(StreamError):
|
| 354 |
+
"""
|
| 355 |
+
Attempted to access streaming request content, without having called `read()`.
|
| 356 |
+
"""
|
| 357 |
+
|
| 358 |
+
def __init__(self) -> None:
|
| 359 |
+
message = (
|
| 360 |
+
"Attempted to access streaming request content,"
|
| 361 |
+
" without having called `read()`."
|
| 362 |
+
)
|
| 363 |
+
super().__init__(message)
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
@contextlib.contextmanager
|
| 367 |
+
def request_context(
|
| 368 |
+
request: Request | None = None,
|
| 369 |
+
) -> typing.Iterator[None]:
|
| 370 |
+
"""
|
| 371 |
+
A context manager that can be used to attach the given request context
|
| 372 |
+
to any `RequestError` exceptions that are raised within the block.
|
| 373 |
+
"""
|
| 374 |
+
try:
|
| 375 |
+
yield
|
| 376 |
+
except RequestError as exc:
|
| 377 |
+
if request is not None:
|
| 378 |
+
exc.request = request
|
| 379 |
+
raise exc
|
venv/lib/python3.12/site-packages/httpx/_main.py
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import functools
|
| 4 |
+
import json
|
| 5 |
+
import sys
|
| 6 |
+
import typing
|
| 7 |
+
|
| 8 |
+
import click
|
| 9 |
+
import pygments.lexers
|
| 10 |
+
import pygments.util
|
| 11 |
+
import rich.console
|
| 12 |
+
import rich.markup
|
| 13 |
+
import rich.progress
|
| 14 |
+
import rich.syntax
|
| 15 |
+
import rich.table
|
| 16 |
+
|
| 17 |
+
from ._client import Client
|
| 18 |
+
from ._exceptions import RequestError
|
| 19 |
+
from ._models import Response
|
| 20 |
+
from ._status_codes import codes
|
| 21 |
+
|
| 22 |
+
if typing.TYPE_CHECKING:
|
| 23 |
+
import httpcore # pragma: no cover
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def print_help() -> None:
|
| 27 |
+
console = rich.console.Console()
|
| 28 |
+
|
| 29 |
+
console.print("[bold]HTTPX :butterfly:", justify="center")
|
| 30 |
+
console.print()
|
| 31 |
+
console.print("A next generation HTTP client.", justify="center")
|
| 32 |
+
console.print()
|
| 33 |
+
console.print(
|
| 34 |
+
"Usage: [bold]httpx[/bold] [cyan]<URL> [OPTIONS][/cyan] ", justify="left"
|
| 35 |
+
)
|
| 36 |
+
console.print()
|
| 37 |
+
|
| 38 |
+
table = rich.table.Table.grid(padding=1, pad_edge=True)
|
| 39 |
+
table.add_column("Parameter", no_wrap=True, justify="left", style="bold")
|
| 40 |
+
table.add_column("Description")
|
| 41 |
+
table.add_row(
|
| 42 |
+
"-m, --method [cyan]METHOD",
|
| 43 |
+
"Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD.\n"
|
| 44 |
+
"[Default: GET, or POST if a request body is included]",
|
| 45 |
+
)
|
| 46 |
+
table.add_row(
|
| 47 |
+
"-p, --params [cyan]<NAME VALUE> ...",
|
| 48 |
+
"Query parameters to include in the request URL.",
|
| 49 |
+
)
|
| 50 |
+
table.add_row(
|
| 51 |
+
"-c, --content [cyan]TEXT", "Byte content to include in the request body."
|
| 52 |
+
)
|
| 53 |
+
table.add_row(
|
| 54 |
+
"-d, --data [cyan]<NAME VALUE> ...", "Form data to include in the request body."
|
| 55 |
+
)
|
| 56 |
+
table.add_row(
|
| 57 |
+
"-f, --files [cyan]<NAME FILENAME> ...",
|
| 58 |
+
"Form files to include in the request body.",
|
| 59 |
+
)
|
| 60 |
+
table.add_row("-j, --json [cyan]TEXT", "JSON data to include in the request body.")
|
| 61 |
+
table.add_row(
|
| 62 |
+
"-h, --headers [cyan]<NAME VALUE> ...",
|
| 63 |
+
"Include additional HTTP headers in the request.",
|
| 64 |
+
)
|
| 65 |
+
table.add_row(
|
| 66 |
+
"--cookies [cyan]<NAME VALUE> ...", "Cookies to include in the request."
|
| 67 |
+
)
|
| 68 |
+
table.add_row(
|
| 69 |
+
"--auth [cyan]<USER PASS>",
|
| 70 |
+
"Username and password to include in the request. Specify '-' for the password"
|
| 71 |
+
" to use a password prompt. Note that using --verbose/-v will expose"
|
| 72 |
+
" the Authorization header, including the password encoding"
|
| 73 |
+
" in a trivially reversible format.",
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
table.add_row(
|
| 77 |
+
"--proxy [cyan]URL",
|
| 78 |
+
"Send the request via a proxy. Should be the URL giving the proxy address.",
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
table.add_row(
|
| 82 |
+
"--timeout [cyan]FLOAT",
|
| 83 |
+
"Timeout value to use for network operations, such as establishing the"
|
| 84 |
+
" connection, reading some data, etc... [Default: 5.0]",
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
table.add_row("--follow-redirects", "Automatically follow redirects.")
|
| 88 |
+
table.add_row("--no-verify", "Disable SSL verification.")
|
| 89 |
+
table.add_row(
|
| 90 |
+
"--http2", "Send the request using HTTP/2, if the remote server supports it."
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
table.add_row(
|
| 94 |
+
"--download [cyan]FILE",
|
| 95 |
+
"Save the response content as a file, rather than displaying it.",
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
table.add_row("-v, --verbose", "Verbose output. Show request as well as response.")
|
| 99 |
+
table.add_row("--help", "Show this message and exit.")
|
| 100 |
+
console.print(table)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def get_lexer_for_response(response: Response) -> str:
|
| 104 |
+
content_type = response.headers.get("Content-Type")
|
| 105 |
+
if content_type is not None:
|
| 106 |
+
mime_type, _, _ = content_type.partition(";")
|
| 107 |
+
try:
|
| 108 |
+
return typing.cast(
|
| 109 |
+
str, pygments.lexers.get_lexer_for_mimetype(mime_type.strip()).name
|
| 110 |
+
)
|
| 111 |
+
except pygments.util.ClassNotFound: # pragma: no cover
|
| 112 |
+
pass
|
| 113 |
+
return "" # pragma: no cover
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def format_request_headers(request: httpcore.Request, http2: bool = False) -> str:
|
| 117 |
+
version = "HTTP/2" if http2 else "HTTP/1.1"
|
| 118 |
+
headers = [
|
| 119 |
+
(name.lower() if http2 else name, value) for name, value in request.headers
|
| 120 |
+
]
|
| 121 |
+
method = request.method.decode("ascii")
|
| 122 |
+
target = request.url.target.decode("ascii")
|
| 123 |
+
lines = [f"{method} {target} {version}"] + [
|
| 124 |
+
f"{name.decode('ascii')}: {value.decode('ascii')}" for name, value in headers
|
| 125 |
+
]
|
| 126 |
+
return "\n".join(lines)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def format_response_headers(
|
| 130 |
+
http_version: bytes,
|
| 131 |
+
status: int,
|
| 132 |
+
reason_phrase: bytes | None,
|
| 133 |
+
headers: list[tuple[bytes, bytes]],
|
| 134 |
+
) -> str:
|
| 135 |
+
version = http_version.decode("ascii")
|
| 136 |
+
reason = (
|
| 137 |
+
codes.get_reason_phrase(status)
|
| 138 |
+
if reason_phrase is None
|
| 139 |
+
else reason_phrase.decode("ascii")
|
| 140 |
+
)
|
| 141 |
+
lines = [f"{version} {status} {reason}"] + [
|
| 142 |
+
f"{name.decode('ascii')}: {value.decode('ascii')}" for name, value in headers
|
| 143 |
+
]
|
| 144 |
+
return "\n".join(lines)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def print_request_headers(request: httpcore.Request, http2: bool = False) -> None:
|
| 148 |
+
console = rich.console.Console()
|
| 149 |
+
http_text = format_request_headers(request, http2=http2)
|
| 150 |
+
syntax = rich.syntax.Syntax(http_text, "http", theme="ansi_dark", word_wrap=True)
|
| 151 |
+
console.print(syntax)
|
| 152 |
+
syntax = rich.syntax.Syntax("", "http", theme="ansi_dark", word_wrap=True)
|
| 153 |
+
console.print(syntax)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def print_response_headers(
|
| 157 |
+
http_version: bytes,
|
| 158 |
+
status: int,
|
| 159 |
+
reason_phrase: bytes | None,
|
| 160 |
+
headers: list[tuple[bytes, bytes]],
|
| 161 |
+
) -> None:
|
| 162 |
+
console = rich.console.Console()
|
| 163 |
+
http_text = format_response_headers(http_version, status, reason_phrase, headers)
|
| 164 |
+
syntax = rich.syntax.Syntax(http_text, "http", theme="ansi_dark", word_wrap=True)
|
| 165 |
+
console.print(syntax)
|
| 166 |
+
syntax = rich.syntax.Syntax("", "http", theme="ansi_dark", word_wrap=True)
|
| 167 |
+
console.print(syntax)
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def print_response(response: Response) -> None:
|
| 171 |
+
console = rich.console.Console()
|
| 172 |
+
lexer_name = get_lexer_for_response(response)
|
| 173 |
+
if lexer_name:
|
| 174 |
+
if lexer_name.lower() == "json":
|
| 175 |
+
try:
|
| 176 |
+
data = response.json()
|
| 177 |
+
text = json.dumps(data, indent=4)
|
| 178 |
+
except ValueError: # pragma: no cover
|
| 179 |
+
text = response.text
|
| 180 |
+
else:
|
| 181 |
+
text = response.text
|
| 182 |
+
|
| 183 |
+
syntax = rich.syntax.Syntax(text, lexer_name, theme="ansi_dark", word_wrap=True)
|
| 184 |
+
console.print(syntax)
|
| 185 |
+
else:
|
| 186 |
+
console.print(f"<{len(response.content)} bytes of binary data>")
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
_PCTRTT = typing.Tuple[typing.Tuple[str, str], ...]
|
| 190 |
+
_PCTRTTT = typing.Tuple[_PCTRTT, ...]
|
| 191 |
+
_PeerCertRetDictType = typing.Dict[str, typing.Union[str, _PCTRTTT, _PCTRTT]]
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def format_certificate(cert: _PeerCertRetDictType) -> str: # pragma: no cover
|
| 195 |
+
lines = []
|
| 196 |
+
for key, value in cert.items():
|
| 197 |
+
if isinstance(value, (list, tuple)):
|
| 198 |
+
lines.append(f"* {key}:")
|
| 199 |
+
for item in value:
|
| 200 |
+
if key in ("subject", "issuer"):
|
| 201 |
+
for sub_item in item:
|
| 202 |
+
lines.append(f"* {sub_item[0]}: {sub_item[1]!r}")
|
| 203 |
+
elif isinstance(item, tuple) and len(item) == 2:
|
| 204 |
+
lines.append(f"* {item[0]}: {item[1]!r}")
|
| 205 |
+
else:
|
| 206 |
+
lines.append(f"* {item!r}")
|
| 207 |
+
else:
|
| 208 |
+
lines.append(f"* {key}: {value!r}")
|
| 209 |
+
return "\n".join(lines)
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def trace(
|
| 213 |
+
name: str, info: typing.Mapping[str, typing.Any], verbose: bool = False
|
| 214 |
+
) -> None:
|
| 215 |
+
console = rich.console.Console()
|
| 216 |
+
if name == "connection.connect_tcp.started" and verbose:
|
| 217 |
+
host = info["host"]
|
| 218 |
+
console.print(f"* Connecting to {host!r}")
|
| 219 |
+
elif name == "connection.connect_tcp.complete" and verbose:
|
| 220 |
+
stream = info["return_value"]
|
| 221 |
+
server_addr = stream.get_extra_info("server_addr")
|
| 222 |
+
console.print(f"* Connected to {server_addr[0]!r} on port {server_addr[1]}")
|
| 223 |
+
elif name == "connection.start_tls.complete" and verbose: # pragma: no cover
|
| 224 |
+
stream = info["return_value"]
|
| 225 |
+
ssl_object = stream.get_extra_info("ssl_object")
|
| 226 |
+
version = ssl_object.version()
|
| 227 |
+
cipher = ssl_object.cipher()
|
| 228 |
+
server_cert = ssl_object.getpeercert()
|
| 229 |
+
alpn = ssl_object.selected_alpn_protocol()
|
| 230 |
+
console.print(f"* SSL established using {version!r} / {cipher[0]!r}")
|
| 231 |
+
console.print(f"* Selected ALPN protocol: {alpn!r}")
|
| 232 |
+
if server_cert:
|
| 233 |
+
console.print("* Server certificate:")
|
| 234 |
+
console.print(format_certificate(server_cert))
|
| 235 |
+
elif name == "http11.send_request_headers.started" and verbose:
|
| 236 |
+
request = info["request"]
|
| 237 |
+
print_request_headers(request, http2=False)
|
| 238 |
+
elif name == "http2.send_request_headers.started" and verbose: # pragma: no cover
|
| 239 |
+
request = info["request"]
|
| 240 |
+
print_request_headers(request, http2=True)
|
| 241 |
+
elif name == "http11.receive_response_headers.complete":
|
| 242 |
+
http_version, status, reason_phrase, headers = info["return_value"]
|
| 243 |
+
print_response_headers(http_version, status, reason_phrase, headers)
|
| 244 |
+
elif name == "http2.receive_response_headers.complete": # pragma: no cover
|
| 245 |
+
status, headers = info["return_value"]
|
| 246 |
+
http_version = b"HTTP/2"
|
| 247 |
+
reason_phrase = None
|
| 248 |
+
print_response_headers(http_version, status, reason_phrase, headers)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def download_response(response: Response, download: typing.BinaryIO) -> None:
|
| 252 |
+
console = rich.console.Console()
|
| 253 |
+
console.print()
|
| 254 |
+
content_length = response.headers.get("Content-Length")
|
| 255 |
+
with rich.progress.Progress(
|
| 256 |
+
"[progress.description]{task.description}",
|
| 257 |
+
"[progress.percentage]{task.percentage:>3.0f}%",
|
| 258 |
+
rich.progress.BarColumn(bar_width=None),
|
| 259 |
+
rich.progress.DownloadColumn(),
|
| 260 |
+
rich.progress.TransferSpeedColumn(),
|
| 261 |
+
) as progress:
|
| 262 |
+
description = f"Downloading [bold]{rich.markup.escape(download.name)}"
|
| 263 |
+
download_task = progress.add_task(
|
| 264 |
+
description,
|
| 265 |
+
total=int(content_length or 0),
|
| 266 |
+
start=content_length is not None,
|
| 267 |
+
)
|
| 268 |
+
for chunk in response.iter_bytes():
|
| 269 |
+
download.write(chunk)
|
| 270 |
+
progress.update(download_task, completed=response.num_bytes_downloaded)
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def validate_json(
|
| 274 |
+
ctx: click.Context,
|
| 275 |
+
param: click.Option | click.Parameter,
|
| 276 |
+
value: typing.Any,
|
| 277 |
+
) -> typing.Any:
|
| 278 |
+
if value is None:
|
| 279 |
+
return None
|
| 280 |
+
|
| 281 |
+
try:
|
| 282 |
+
return json.loads(value)
|
| 283 |
+
except json.JSONDecodeError: # pragma: no cover
|
| 284 |
+
raise click.BadParameter("Not valid JSON")
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def validate_auth(
|
| 288 |
+
ctx: click.Context,
|
| 289 |
+
param: click.Option | click.Parameter,
|
| 290 |
+
value: typing.Any,
|
| 291 |
+
) -> typing.Any:
|
| 292 |
+
if value == (None, None):
|
| 293 |
+
return None
|
| 294 |
+
|
| 295 |
+
username, password = value
|
| 296 |
+
if password == "-": # pragma: no cover
|
| 297 |
+
password = click.prompt("Password", hide_input=True)
|
| 298 |
+
return (username, password)
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def handle_help(
|
| 302 |
+
ctx: click.Context,
|
| 303 |
+
param: click.Option | click.Parameter,
|
| 304 |
+
value: typing.Any,
|
| 305 |
+
) -> None:
|
| 306 |
+
if not value or ctx.resilient_parsing:
|
| 307 |
+
return
|
| 308 |
+
|
| 309 |
+
print_help()
|
| 310 |
+
ctx.exit()
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
@click.command(add_help_option=False)
|
| 314 |
+
@click.argument("url", type=str)
|
| 315 |
+
@click.option(
|
| 316 |
+
"--method",
|
| 317 |
+
"-m",
|
| 318 |
+
"method",
|
| 319 |
+
type=str,
|
| 320 |
+
help=(
|
| 321 |
+
"Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD. "
|
| 322 |
+
"[Default: GET, or POST if a request body is included]"
|
| 323 |
+
),
|
| 324 |
+
)
|
| 325 |
+
@click.option(
|
| 326 |
+
"--params",
|
| 327 |
+
"-p",
|
| 328 |
+
"params",
|
| 329 |
+
type=(str, str),
|
| 330 |
+
multiple=True,
|
| 331 |
+
help="Query parameters to include in the request URL.",
|
| 332 |
+
)
|
| 333 |
+
@click.option(
|
| 334 |
+
"--content",
|
| 335 |
+
"-c",
|
| 336 |
+
"content",
|
| 337 |
+
type=str,
|
| 338 |
+
help="Byte content to include in the request body.",
|
| 339 |
+
)
|
| 340 |
+
@click.option(
|
| 341 |
+
"--data",
|
| 342 |
+
"-d",
|
| 343 |
+
"data",
|
| 344 |
+
type=(str, str),
|
| 345 |
+
multiple=True,
|
| 346 |
+
help="Form data to include in the request body.",
|
| 347 |
+
)
|
| 348 |
+
@click.option(
|
| 349 |
+
"--files",
|
| 350 |
+
"-f",
|
| 351 |
+
"files",
|
| 352 |
+
type=(str, click.File(mode="rb")),
|
| 353 |
+
multiple=True,
|
| 354 |
+
help="Form files to include in the request body.",
|
| 355 |
+
)
|
| 356 |
+
@click.option(
|
| 357 |
+
"--json",
|
| 358 |
+
"-j",
|
| 359 |
+
"json",
|
| 360 |
+
type=str,
|
| 361 |
+
callback=validate_json,
|
| 362 |
+
help="JSON data to include in the request body.",
|
| 363 |
+
)
|
| 364 |
+
@click.option(
|
| 365 |
+
"--headers",
|
| 366 |
+
"-h",
|
| 367 |
+
"headers",
|
| 368 |
+
type=(str, str),
|
| 369 |
+
multiple=True,
|
| 370 |
+
help="Include additional HTTP headers in the request.",
|
| 371 |
+
)
|
| 372 |
+
@click.option(
|
| 373 |
+
"--cookies",
|
| 374 |
+
"cookies",
|
| 375 |
+
type=(str, str),
|
| 376 |
+
multiple=True,
|
| 377 |
+
help="Cookies to include in the request.",
|
| 378 |
+
)
|
| 379 |
+
@click.option(
|
| 380 |
+
"--auth",
|
| 381 |
+
"auth",
|
| 382 |
+
type=(str, str),
|
| 383 |
+
default=(None, None),
|
| 384 |
+
callback=validate_auth,
|
| 385 |
+
help=(
|
| 386 |
+
"Username and password to include in the request. "
|
| 387 |
+
"Specify '-' for the password to use a password prompt. "
|
| 388 |
+
"Note that using --verbose/-v will expose the Authorization header, "
|
| 389 |
+
"including the password encoding in a trivially reversible format."
|
| 390 |
+
),
|
| 391 |
+
)
|
| 392 |
+
@click.option(
|
| 393 |
+
"--proxy",
|
| 394 |
+
"proxy",
|
| 395 |
+
type=str,
|
| 396 |
+
default=None,
|
| 397 |
+
help="Send the request via a proxy. Should be the URL giving the proxy address.",
|
| 398 |
+
)
|
| 399 |
+
@click.option(
|
| 400 |
+
"--timeout",
|
| 401 |
+
"timeout",
|
| 402 |
+
type=float,
|
| 403 |
+
default=5.0,
|
| 404 |
+
help=(
|
| 405 |
+
"Timeout value to use for network operations, such as establishing the "
|
| 406 |
+
"connection, reading some data, etc... [Default: 5.0]"
|
| 407 |
+
),
|
| 408 |
+
)
|
| 409 |
+
@click.option(
|
| 410 |
+
"--follow-redirects",
|
| 411 |
+
"follow_redirects",
|
| 412 |
+
is_flag=True,
|
| 413 |
+
default=False,
|
| 414 |
+
help="Automatically follow redirects.",
|
| 415 |
+
)
|
| 416 |
+
@click.option(
|
| 417 |
+
"--no-verify",
|
| 418 |
+
"verify",
|
| 419 |
+
is_flag=True,
|
| 420 |
+
default=True,
|
| 421 |
+
help="Disable SSL verification.",
|
| 422 |
+
)
|
| 423 |
+
@click.option(
|
| 424 |
+
"--http2",
|
| 425 |
+
"http2",
|
| 426 |
+
type=bool,
|
| 427 |
+
is_flag=True,
|
| 428 |
+
default=False,
|
| 429 |
+
help="Send the request using HTTP/2, if the remote server supports it.",
|
| 430 |
+
)
|
| 431 |
+
@click.option(
|
| 432 |
+
"--download",
|
| 433 |
+
type=click.File("wb"),
|
| 434 |
+
help="Save the response content as a file, rather than displaying it.",
|
| 435 |
+
)
|
| 436 |
+
@click.option(
|
| 437 |
+
"--verbose",
|
| 438 |
+
"-v",
|
| 439 |
+
type=bool,
|
| 440 |
+
is_flag=True,
|
| 441 |
+
default=False,
|
| 442 |
+
help="Verbose. Show request as well as response.",
|
| 443 |
+
)
|
| 444 |
+
@click.option(
|
| 445 |
+
"--help",
|
| 446 |
+
is_flag=True,
|
| 447 |
+
is_eager=True,
|
| 448 |
+
expose_value=False,
|
| 449 |
+
callback=handle_help,
|
| 450 |
+
help="Show this message and exit.",
|
| 451 |
+
)
|
| 452 |
+
def main(
|
| 453 |
+
url: str,
|
| 454 |
+
method: str,
|
| 455 |
+
params: list[tuple[str, str]],
|
| 456 |
+
content: str,
|
| 457 |
+
data: list[tuple[str, str]],
|
| 458 |
+
files: list[tuple[str, click.File]],
|
| 459 |
+
json: str,
|
| 460 |
+
headers: list[tuple[str, str]],
|
| 461 |
+
cookies: list[tuple[str, str]],
|
| 462 |
+
auth: tuple[str, str] | None,
|
| 463 |
+
proxy: str,
|
| 464 |
+
timeout: float,
|
| 465 |
+
follow_redirects: bool,
|
| 466 |
+
verify: bool,
|
| 467 |
+
http2: bool,
|
| 468 |
+
download: typing.BinaryIO | None,
|
| 469 |
+
verbose: bool,
|
| 470 |
+
) -> None:
|
| 471 |
+
"""
|
| 472 |
+
An HTTP command line client.
|
| 473 |
+
Sends a request and displays the response.
|
| 474 |
+
"""
|
| 475 |
+
if not method:
|
| 476 |
+
method = "POST" if content or data or files or json else "GET"
|
| 477 |
+
|
| 478 |
+
try:
|
| 479 |
+
with Client(proxy=proxy, timeout=timeout, http2=http2, verify=verify) as client:
|
| 480 |
+
with client.stream(
|
| 481 |
+
method,
|
| 482 |
+
url,
|
| 483 |
+
params=list(params),
|
| 484 |
+
content=content,
|
| 485 |
+
data=dict(data),
|
| 486 |
+
files=files, # type: ignore
|
| 487 |
+
json=json,
|
| 488 |
+
headers=headers,
|
| 489 |
+
cookies=dict(cookies),
|
| 490 |
+
auth=auth,
|
| 491 |
+
follow_redirects=follow_redirects,
|
| 492 |
+
extensions={"trace": functools.partial(trace, verbose=verbose)},
|
| 493 |
+
) as response:
|
| 494 |
+
if download is not None:
|
| 495 |
+
download_response(response, download)
|
| 496 |
+
else:
|
| 497 |
+
response.read()
|
| 498 |
+
if response.content:
|
| 499 |
+
print_response(response)
|
| 500 |
+
|
| 501 |
+
except RequestError as exc:
|
| 502 |
+
console = rich.console.Console()
|
| 503 |
+
console.print(f"[red]{type(exc).__name__}[/red]: {exc}")
|
| 504 |
+
sys.exit(1)
|
| 505 |
+
|
| 506 |
+
sys.exit(0 if response.is_success else 1)
|
venv/lib/python3.12/site-packages/httpx/_multipart.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import io
|
| 4 |
+
import mimetypes
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
import typing
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
from ._types import (
|
| 11 |
+
AsyncByteStream,
|
| 12 |
+
FileContent,
|
| 13 |
+
FileTypes,
|
| 14 |
+
RequestData,
|
| 15 |
+
RequestFiles,
|
| 16 |
+
SyncByteStream,
|
| 17 |
+
)
|
| 18 |
+
from ._utils import (
|
| 19 |
+
peek_filelike_length,
|
| 20 |
+
primitive_value_to_str,
|
| 21 |
+
to_bytes,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
_HTML5_FORM_ENCODING_REPLACEMENTS = {'"': "%22", "\\": "\\\\"}
|
| 25 |
+
_HTML5_FORM_ENCODING_REPLACEMENTS.update(
|
| 26 |
+
{chr(c): "%{:02X}".format(c) for c in range(0x1F + 1) if c != 0x1B}
|
| 27 |
+
)
|
| 28 |
+
_HTML5_FORM_ENCODING_RE = re.compile(
|
| 29 |
+
r"|".join([re.escape(c) for c in _HTML5_FORM_ENCODING_REPLACEMENTS.keys()])
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _format_form_param(name: str, value: str) -> bytes:
|
| 34 |
+
"""
|
| 35 |
+
Encode a name/value pair within a multipart form.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
def replacer(match: typing.Match[str]) -> str:
|
| 39 |
+
return _HTML5_FORM_ENCODING_REPLACEMENTS[match.group(0)]
|
| 40 |
+
|
| 41 |
+
value = _HTML5_FORM_ENCODING_RE.sub(replacer, value)
|
| 42 |
+
return f'{name}="{value}"'.encode()
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def _guess_content_type(filename: str | None) -> str | None:
|
| 46 |
+
"""
|
| 47 |
+
Guesses the mimetype based on a filename. Defaults to `application/octet-stream`.
|
| 48 |
+
|
| 49 |
+
Returns `None` if `filename` is `None` or empty.
|
| 50 |
+
"""
|
| 51 |
+
if filename:
|
| 52 |
+
return mimetypes.guess_type(filename)[0] or "application/octet-stream"
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def get_multipart_boundary_from_content_type(
|
| 57 |
+
content_type: bytes | None,
|
| 58 |
+
) -> bytes | None:
|
| 59 |
+
if not content_type or not content_type.startswith(b"multipart/form-data"):
|
| 60 |
+
return None
|
| 61 |
+
# parse boundary according to
|
| 62 |
+
# https://www.rfc-editor.org/rfc/rfc2046#section-5.1.1
|
| 63 |
+
if b";" in content_type:
|
| 64 |
+
for section in content_type.split(b";"):
|
| 65 |
+
if section.strip().lower().startswith(b"boundary="):
|
| 66 |
+
return section.strip()[len(b"boundary=") :].strip(b'"')
|
| 67 |
+
return None
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class DataField:
|
| 71 |
+
"""
|
| 72 |
+
A single form field item, within a multipart form field.
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
def __init__(self, name: str, value: str | bytes | int | float | None) -> None:
|
| 76 |
+
if not isinstance(name, str):
|
| 77 |
+
raise TypeError(
|
| 78 |
+
f"Invalid type for name. Expected str, got {type(name)}: {name!r}"
|
| 79 |
+
)
|
| 80 |
+
if value is not None and not isinstance(value, (str, bytes, int, float)):
|
| 81 |
+
raise TypeError(
|
| 82 |
+
"Invalid type for value. Expected primitive type,"
|
| 83 |
+
f" got {type(value)}: {value!r}"
|
| 84 |
+
)
|
| 85 |
+
self.name = name
|
| 86 |
+
self.value: str | bytes = (
|
| 87 |
+
value if isinstance(value, bytes) else primitive_value_to_str(value)
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def render_headers(self) -> bytes:
|
| 91 |
+
if not hasattr(self, "_headers"):
|
| 92 |
+
name = _format_form_param("name", self.name)
|
| 93 |
+
self._headers = b"".join(
|
| 94 |
+
[b"Content-Disposition: form-data; ", name, b"\r\n\r\n"]
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
return self._headers
|
| 98 |
+
|
| 99 |
+
def render_data(self) -> bytes:
|
| 100 |
+
if not hasattr(self, "_data"):
|
| 101 |
+
self._data = to_bytes(self.value)
|
| 102 |
+
|
| 103 |
+
return self._data
|
| 104 |
+
|
| 105 |
+
def get_length(self) -> int:
|
| 106 |
+
headers = self.render_headers()
|
| 107 |
+
data = self.render_data()
|
| 108 |
+
return len(headers) + len(data)
|
| 109 |
+
|
| 110 |
+
def render(self) -> typing.Iterator[bytes]:
|
| 111 |
+
yield self.render_headers()
|
| 112 |
+
yield self.render_data()
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class FileField:
|
| 116 |
+
"""
|
| 117 |
+
A single file field item, within a multipart form field.
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
CHUNK_SIZE = 64 * 1024
|
| 121 |
+
|
| 122 |
+
def __init__(self, name: str, value: FileTypes) -> None:
|
| 123 |
+
self.name = name
|
| 124 |
+
|
| 125 |
+
fileobj: FileContent
|
| 126 |
+
|
| 127 |
+
headers: dict[str, str] = {}
|
| 128 |
+
content_type: str | None = None
|
| 129 |
+
|
| 130 |
+
# This large tuple based API largely mirror's requests' API
|
| 131 |
+
# It would be good to think of better APIs for this that we could
|
| 132 |
+
# include in httpx 2.0 since variable length tuples(especially of 4 elements)
|
| 133 |
+
# are quite unwieldly
|
| 134 |
+
if isinstance(value, tuple):
|
| 135 |
+
if len(value) == 2:
|
| 136 |
+
# neither the 3rd parameter (content_type) nor the 4th (headers)
|
| 137 |
+
# was included
|
| 138 |
+
filename, fileobj = value
|
| 139 |
+
elif len(value) == 3:
|
| 140 |
+
filename, fileobj, content_type = value
|
| 141 |
+
else:
|
| 142 |
+
# all 4 parameters included
|
| 143 |
+
filename, fileobj, content_type, headers = value # type: ignore
|
| 144 |
+
else:
|
| 145 |
+
filename = Path(str(getattr(value, "name", "upload"))).name
|
| 146 |
+
fileobj = value
|
| 147 |
+
|
| 148 |
+
if content_type is None:
|
| 149 |
+
content_type = _guess_content_type(filename)
|
| 150 |
+
|
| 151 |
+
has_content_type_header = any("content-type" in key.lower() for key in headers)
|
| 152 |
+
if content_type is not None and not has_content_type_header:
|
| 153 |
+
# note that unlike requests, we ignore the content_type provided in the 3rd
|
| 154 |
+
# tuple element if it is also included in the headers requests does
|
| 155 |
+
# the opposite (it overwrites the headerwith the 3rd tuple element)
|
| 156 |
+
headers["Content-Type"] = content_type
|
| 157 |
+
|
| 158 |
+
if isinstance(fileobj, io.StringIO):
|
| 159 |
+
raise TypeError(
|
| 160 |
+
"Multipart file uploads require 'io.BytesIO', not 'io.StringIO'."
|
| 161 |
+
)
|
| 162 |
+
if isinstance(fileobj, io.TextIOBase):
|
| 163 |
+
raise TypeError(
|
| 164 |
+
"Multipart file uploads must be opened in binary mode, not text mode."
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
self.filename = filename
|
| 168 |
+
self.file = fileobj
|
| 169 |
+
self.headers = headers
|
| 170 |
+
|
| 171 |
+
def get_length(self) -> int | None:
|
| 172 |
+
headers = self.render_headers()
|
| 173 |
+
|
| 174 |
+
if isinstance(self.file, (str, bytes)):
|
| 175 |
+
return len(headers) + len(to_bytes(self.file))
|
| 176 |
+
|
| 177 |
+
file_length = peek_filelike_length(self.file)
|
| 178 |
+
|
| 179 |
+
# If we can't determine the filesize without reading it into memory,
|
| 180 |
+
# then return `None` here, to indicate an unknown file length.
|
| 181 |
+
if file_length is None:
|
| 182 |
+
return None
|
| 183 |
+
|
| 184 |
+
return len(headers) + file_length
|
| 185 |
+
|
| 186 |
+
def render_headers(self) -> bytes:
|
| 187 |
+
if not hasattr(self, "_headers"):
|
| 188 |
+
parts = [
|
| 189 |
+
b"Content-Disposition: form-data; ",
|
| 190 |
+
_format_form_param("name", self.name),
|
| 191 |
+
]
|
| 192 |
+
if self.filename:
|
| 193 |
+
filename = _format_form_param("filename", self.filename)
|
| 194 |
+
parts.extend([b"; ", filename])
|
| 195 |
+
for header_name, header_value in self.headers.items():
|
| 196 |
+
key, val = f"\r\n{header_name}: ".encode(), header_value.encode()
|
| 197 |
+
parts.extend([key, val])
|
| 198 |
+
parts.append(b"\r\n\r\n")
|
| 199 |
+
self._headers = b"".join(parts)
|
| 200 |
+
|
| 201 |
+
return self._headers
|
| 202 |
+
|
| 203 |
+
def render_data(self) -> typing.Iterator[bytes]:
|
| 204 |
+
if isinstance(self.file, (str, bytes)):
|
| 205 |
+
yield to_bytes(self.file)
|
| 206 |
+
return
|
| 207 |
+
|
| 208 |
+
if hasattr(self.file, "seek"):
|
| 209 |
+
try:
|
| 210 |
+
self.file.seek(0)
|
| 211 |
+
except io.UnsupportedOperation:
|
| 212 |
+
pass
|
| 213 |
+
|
| 214 |
+
chunk = self.file.read(self.CHUNK_SIZE)
|
| 215 |
+
while chunk:
|
| 216 |
+
yield to_bytes(chunk)
|
| 217 |
+
chunk = self.file.read(self.CHUNK_SIZE)
|
| 218 |
+
|
| 219 |
+
def render(self) -> typing.Iterator[bytes]:
|
| 220 |
+
yield self.render_headers()
|
| 221 |
+
yield from self.render_data()
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
class MultipartStream(SyncByteStream, AsyncByteStream):
|
| 225 |
+
"""
|
| 226 |
+
Request content as streaming multipart encoded form data.
|
| 227 |
+
"""
|
| 228 |
+
|
| 229 |
+
def __init__(
|
| 230 |
+
self,
|
| 231 |
+
data: RequestData,
|
| 232 |
+
files: RequestFiles,
|
| 233 |
+
boundary: bytes | None = None,
|
| 234 |
+
) -> None:
|
| 235 |
+
if boundary is None:
|
| 236 |
+
boundary = os.urandom(16).hex().encode("ascii")
|
| 237 |
+
|
| 238 |
+
self.boundary = boundary
|
| 239 |
+
self.content_type = "multipart/form-data; boundary=%s" % boundary.decode(
|
| 240 |
+
"ascii"
|
| 241 |
+
)
|
| 242 |
+
self.fields = list(self._iter_fields(data, files))
|
| 243 |
+
|
| 244 |
+
def _iter_fields(
|
| 245 |
+
self, data: RequestData, files: RequestFiles
|
| 246 |
+
) -> typing.Iterator[FileField | DataField]:
|
| 247 |
+
for name, value in data.items():
|
| 248 |
+
if isinstance(value, (tuple, list)):
|
| 249 |
+
for item in value:
|
| 250 |
+
yield DataField(name=name, value=item)
|
| 251 |
+
else:
|
| 252 |
+
yield DataField(name=name, value=value)
|
| 253 |
+
|
| 254 |
+
file_items = files.items() if isinstance(files, typing.Mapping) else files
|
| 255 |
+
for name, value in file_items:
|
| 256 |
+
yield FileField(name=name, value=value)
|
| 257 |
+
|
| 258 |
+
def iter_chunks(self) -> typing.Iterator[bytes]:
|
| 259 |
+
for field in self.fields:
|
| 260 |
+
yield b"--%s\r\n" % self.boundary
|
| 261 |
+
yield from field.render()
|
| 262 |
+
yield b"\r\n"
|
| 263 |
+
yield b"--%s--\r\n" % self.boundary
|
| 264 |
+
|
| 265 |
+
def get_content_length(self) -> int | None:
|
| 266 |
+
"""
|
| 267 |
+
Return the length of the multipart encoded content, or `None` if
|
| 268 |
+
any of the files have a length that cannot be determined upfront.
|
| 269 |
+
"""
|
| 270 |
+
boundary_length = len(self.boundary)
|
| 271 |
+
length = 0
|
| 272 |
+
|
| 273 |
+
for field in self.fields:
|
| 274 |
+
field_length = field.get_length()
|
| 275 |
+
if field_length is None:
|
| 276 |
+
return None
|
| 277 |
+
|
| 278 |
+
length += 2 + boundary_length + 2 # b"--{boundary}\r\n"
|
| 279 |
+
length += field_length
|
| 280 |
+
length += 2 # b"\r\n"
|
| 281 |
+
|
| 282 |
+
length += 2 + boundary_length + 4 # b"--{boundary}--\r\n"
|
| 283 |
+
return length
|
| 284 |
+
|
| 285 |
+
# Content stream interface.
|
| 286 |
+
|
| 287 |
+
def get_headers(self) -> dict[str, str]:
|
| 288 |
+
content_length = self.get_content_length()
|
| 289 |
+
content_type = self.content_type
|
| 290 |
+
if content_length is None:
|
| 291 |
+
return {"Transfer-Encoding": "chunked", "Content-Type": content_type}
|
| 292 |
+
return {"Content-Length": str(content_length), "Content-Type": content_type}
|
| 293 |
+
|
| 294 |
+
def __iter__(self) -> typing.Iterator[bytes]:
|
| 295 |
+
for chunk in self.iter_chunks():
|
| 296 |
+
yield chunk
|
| 297 |
+
|
| 298 |
+
async def __aiter__(self) -> typing.AsyncIterator[bytes]:
|
| 299 |
+
for chunk in self.iter_chunks():
|
| 300 |
+
yield chunk
|
venv/lib/python3.12/site-packages/httpx/_status_codes.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from enum import IntEnum
|
| 4 |
+
|
| 5 |
+
__all__ = ["codes"]
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class codes(IntEnum):
|
| 9 |
+
"""HTTP status codes and reason phrases
|
| 10 |
+
|
| 11 |
+
Status codes from the following RFCs are all observed:
|
| 12 |
+
|
| 13 |
+
* RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616
|
| 14 |
+
* RFC 6585: Additional HTTP Status Codes
|
| 15 |
+
* RFC 3229: Delta encoding in HTTP
|
| 16 |
+
* RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518
|
| 17 |
+
* RFC 5842: Binding Extensions to WebDAV
|
| 18 |
+
* RFC 7238: Permanent Redirect
|
| 19 |
+
* RFC 2295: Transparent Content Negotiation in HTTP
|
| 20 |
+
* RFC 2774: An HTTP Extension Framework
|
| 21 |
+
* RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2)
|
| 22 |
+
* RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)
|
| 23 |
+
* RFC 7725: An HTTP Status Code to Report Legal Obstacles
|
| 24 |
+
* RFC 8297: An HTTP Status Code for Indicating Hints
|
| 25 |
+
* RFC 8470: Using Early Data in HTTP
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def __new__(cls, value: int, phrase: str = "") -> codes:
|
| 29 |
+
obj = int.__new__(cls, value)
|
| 30 |
+
obj._value_ = value
|
| 31 |
+
|
| 32 |
+
obj.phrase = phrase # type: ignore[attr-defined]
|
| 33 |
+
return obj
|
| 34 |
+
|
| 35 |
+
def __str__(self) -> str:
|
| 36 |
+
return str(self.value)
|
| 37 |
+
|
| 38 |
+
@classmethod
|
| 39 |
+
def get_reason_phrase(cls, value: int) -> str:
|
| 40 |
+
try:
|
| 41 |
+
return codes(value).phrase # type: ignore
|
| 42 |
+
except ValueError:
|
| 43 |
+
return ""
|
| 44 |
+
|
| 45 |
+
@classmethod
|
| 46 |
+
def is_informational(cls, value: int) -> bool:
|
| 47 |
+
"""
|
| 48 |
+
Returns `True` for 1xx status codes, `False` otherwise.
|
| 49 |
+
"""
|
| 50 |
+
return 100 <= value <= 199
|
| 51 |
+
|
| 52 |
+
@classmethod
|
| 53 |
+
def is_success(cls, value: int) -> bool:
|
| 54 |
+
"""
|
| 55 |
+
Returns `True` for 2xx status codes, `False` otherwise.
|
| 56 |
+
"""
|
| 57 |
+
return 200 <= value <= 299
|
| 58 |
+
|
| 59 |
+
@classmethod
|
| 60 |
+
def is_redirect(cls, value: int) -> bool:
|
| 61 |
+
"""
|
| 62 |
+
Returns `True` for 3xx status codes, `False` otherwise.
|
| 63 |
+
"""
|
| 64 |
+
return 300 <= value <= 399
|
| 65 |
+
|
| 66 |
+
@classmethod
|
| 67 |
+
def is_client_error(cls, value: int) -> bool:
|
| 68 |
+
"""
|
| 69 |
+
Returns `True` for 4xx status codes, `False` otherwise.
|
| 70 |
+
"""
|
| 71 |
+
return 400 <= value <= 499
|
| 72 |
+
|
| 73 |
+
@classmethod
|
| 74 |
+
def is_server_error(cls, value: int) -> bool:
|
| 75 |
+
"""
|
| 76 |
+
Returns `True` for 5xx status codes, `False` otherwise.
|
| 77 |
+
"""
|
| 78 |
+
return 500 <= value <= 599
|
| 79 |
+
|
| 80 |
+
@classmethod
|
| 81 |
+
def is_error(cls, value: int) -> bool:
|
| 82 |
+
"""
|
| 83 |
+
Returns `True` for 4xx or 5xx status codes, `False` otherwise.
|
| 84 |
+
"""
|
| 85 |
+
return 400 <= value <= 599
|
| 86 |
+
|
| 87 |
+
# informational
|
| 88 |
+
CONTINUE = 100, "Continue"
|
| 89 |
+
SWITCHING_PROTOCOLS = 101, "Switching Protocols"
|
| 90 |
+
PROCESSING = 102, "Processing"
|
| 91 |
+
EARLY_HINTS = 103, "Early Hints"
|
| 92 |
+
|
| 93 |
+
# success
|
| 94 |
+
OK = 200, "OK"
|
| 95 |
+
CREATED = 201, "Created"
|
| 96 |
+
ACCEPTED = 202, "Accepted"
|
| 97 |
+
NON_AUTHORITATIVE_INFORMATION = 203, "Non-Authoritative Information"
|
| 98 |
+
NO_CONTENT = 204, "No Content"
|
| 99 |
+
RESET_CONTENT = 205, "Reset Content"
|
| 100 |
+
PARTIAL_CONTENT = 206, "Partial Content"
|
| 101 |
+
MULTI_STATUS = 207, "Multi-Status"
|
| 102 |
+
ALREADY_REPORTED = 208, "Already Reported"
|
| 103 |
+
IM_USED = 226, "IM Used"
|
| 104 |
+
|
| 105 |
+
# redirection
|
| 106 |
+
MULTIPLE_CHOICES = 300, "Multiple Choices"
|
| 107 |
+
MOVED_PERMANENTLY = 301, "Moved Permanently"
|
| 108 |
+
FOUND = 302, "Found"
|
| 109 |
+
SEE_OTHER = 303, "See Other"
|
| 110 |
+
NOT_MODIFIED = 304, "Not Modified"
|
| 111 |
+
USE_PROXY = 305, "Use Proxy"
|
| 112 |
+
TEMPORARY_REDIRECT = 307, "Temporary Redirect"
|
| 113 |
+
PERMANENT_REDIRECT = 308, "Permanent Redirect"
|
| 114 |
+
|
| 115 |
+
# client error
|
| 116 |
+
BAD_REQUEST = 400, "Bad Request"
|
| 117 |
+
UNAUTHORIZED = 401, "Unauthorized"
|
| 118 |
+
PAYMENT_REQUIRED = 402, "Payment Required"
|
| 119 |
+
FORBIDDEN = 403, "Forbidden"
|
| 120 |
+
NOT_FOUND = 404, "Not Found"
|
| 121 |
+
METHOD_NOT_ALLOWED = 405, "Method Not Allowed"
|
| 122 |
+
NOT_ACCEPTABLE = 406, "Not Acceptable"
|
| 123 |
+
PROXY_AUTHENTICATION_REQUIRED = 407, "Proxy Authentication Required"
|
| 124 |
+
REQUEST_TIMEOUT = 408, "Request Timeout"
|
| 125 |
+
CONFLICT = 409, "Conflict"
|
| 126 |
+
GONE = 410, "Gone"
|
| 127 |
+
LENGTH_REQUIRED = 411, "Length Required"
|
| 128 |
+
PRECONDITION_FAILED = 412, "Precondition Failed"
|
| 129 |
+
REQUEST_ENTITY_TOO_LARGE = 413, "Request Entity Too Large"
|
| 130 |
+
REQUEST_URI_TOO_LONG = 414, "Request-URI Too Long"
|
| 131 |
+
UNSUPPORTED_MEDIA_TYPE = 415, "Unsupported Media Type"
|
| 132 |
+
REQUESTED_RANGE_NOT_SATISFIABLE = 416, "Requested Range Not Satisfiable"
|
| 133 |
+
EXPECTATION_FAILED = 417, "Expectation Failed"
|
| 134 |
+
IM_A_TEAPOT = 418, "I'm a teapot"
|
| 135 |
+
MISDIRECTED_REQUEST = 421, "Misdirected Request"
|
| 136 |
+
UNPROCESSABLE_ENTITY = 422, "Unprocessable Entity"
|
| 137 |
+
LOCKED = 423, "Locked"
|
| 138 |
+
FAILED_DEPENDENCY = 424, "Failed Dependency"
|
| 139 |
+
TOO_EARLY = 425, "Too Early"
|
| 140 |
+
UPGRADE_REQUIRED = 426, "Upgrade Required"
|
| 141 |
+
PRECONDITION_REQUIRED = 428, "Precondition Required"
|
| 142 |
+
TOO_MANY_REQUESTS = 429, "Too Many Requests"
|
| 143 |
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431, "Request Header Fields Too Large"
|
| 144 |
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451, "Unavailable For Legal Reasons"
|
| 145 |
+
|
| 146 |
+
# server errors
|
| 147 |
+
INTERNAL_SERVER_ERROR = 500, "Internal Server Error"
|
| 148 |
+
NOT_IMPLEMENTED = 501, "Not Implemented"
|
| 149 |
+
BAD_GATEWAY = 502, "Bad Gateway"
|
| 150 |
+
SERVICE_UNAVAILABLE = 503, "Service Unavailable"
|
| 151 |
+
GATEWAY_TIMEOUT = 504, "Gateway Timeout"
|
| 152 |
+
HTTP_VERSION_NOT_SUPPORTED = 505, "HTTP Version Not Supported"
|
| 153 |
+
VARIANT_ALSO_NEGOTIATES = 506, "Variant Also Negotiates"
|
| 154 |
+
INSUFFICIENT_STORAGE = 507, "Insufficient Storage"
|
| 155 |
+
LOOP_DETECTED = 508, "Loop Detected"
|
| 156 |
+
NOT_EXTENDED = 510, "Not Extended"
|
| 157 |
+
NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required"
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
# Include lower-case styles for `requests` compatibility.
|
| 161 |
+
for code in codes:
|
| 162 |
+
setattr(codes, code._name_.lower(), int(code))
|
venv/lib/python3.12/site-packages/httpx/_types.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Type definitions for type checking purposes.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from http.cookiejar import CookieJar
|
| 6 |
+
from typing import (
|
| 7 |
+
IO,
|
| 8 |
+
TYPE_CHECKING,
|
| 9 |
+
Any,
|
| 10 |
+
AsyncIterable,
|
| 11 |
+
AsyncIterator,
|
| 12 |
+
Callable,
|
| 13 |
+
Dict,
|
| 14 |
+
Iterable,
|
| 15 |
+
Iterator,
|
| 16 |
+
List,
|
| 17 |
+
Mapping,
|
| 18 |
+
Optional,
|
| 19 |
+
Sequence,
|
| 20 |
+
Tuple,
|
| 21 |
+
Union,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
if TYPE_CHECKING: # pragma: no cover
|
| 25 |
+
from ._auth import Auth # noqa: F401
|
| 26 |
+
from ._config import Proxy, Timeout # noqa: F401
|
| 27 |
+
from ._models import Cookies, Headers, Request # noqa: F401
|
| 28 |
+
from ._urls import URL, QueryParams # noqa: F401
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
PrimitiveData = Optional[Union[str, int, float, bool]]
|
| 32 |
+
|
| 33 |
+
URLTypes = Union["URL", str]
|
| 34 |
+
|
| 35 |
+
QueryParamTypes = Union[
|
| 36 |
+
"QueryParams",
|
| 37 |
+
Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]],
|
| 38 |
+
List[Tuple[str, PrimitiveData]],
|
| 39 |
+
Tuple[Tuple[str, PrimitiveData], ...],
|
| 40 |
+
str,
|
| 41 |
+
bytes,
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
HeaderTypes = Union[
|
| 45 |
+
"Headers",
|
| 46 |
+
Mapping[str, str],
|
| 47 |
+
Mapping[bytes, bytes],
|
| 48 |
+
Sequence[Tuple[str, str]],
|
| 49 |
+
Sequence[Tuple[bytes, bytes]],
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
CookieTypes = Union["Cookies", CookieJar, Dict[str, str], List[Tuple[str, str]]]
|
| 53 |
+
|
| 54 |
+
TimeoutTypes = Union[
|
| 55 |
+
Optional[float],
|
| 56 |
+
Tuple[Optional[float], Optional[float], Optional[float], Optional[float]],
|
| 57 |
+
"Timeout",
|
| 58 |
+
]
|
| 59 |
+
ProxyTypes = Union["URL", str, "Proxy"]
|
| 60 |
+
CertTypes = Union[str, Tuple[str, str], Tuple[str, str, str]]
|
| 61 |
+
|
| 62 |
+
AuthTypes = Union[
|
| 63 |
+
Tuple[Union[str, bytes], Union[str, bytes]],
|
| 64 |
+
Callable[["Request"], "Request"],
|
| 65 |
+
"Auth",
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
RequestContent = Union[str, bytes, Iterable[bytes], AsyncIterable[bytes]]
|
| 69 |
+
ResponseContent = Union[str, bytes, Iterable[bytes], AsyncIterable[bytes]]
|
| 70 |
+
ResponseExtensions = Mapping[str, Any]
|
| 71 |
+
|
| 72 |
+
RequestData = Mapping[str, Any]
|
| 73 |
+
|
| 74 |
+
FileContent = Union[IO[bytes], bytes, str]
|
| 75 |
+
FileTypes = Union[
|
| 76 |
+
# file (or bytes)
|
| 77 |
+
FileContent,
|
| 78 |
+
# (filename, file (or bytes))
|
| 79 |
+
Tuple[Optional[str], FileContent],
|
| 80 |
+
# (filename, file (or bytes), content_type)
|
| 81 |
+
Tuple[Optional[str], FileContent, Optional[str]],
|
| 82 |
+
# (filename, file (or bytes), content_type, headers)
|
| 83 |
+
Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]],
|
| 84 |
+
]
|
| 85 |
+
RequestFiles = Union[Mapping[str, FileTypes], Sequence[Tuple[str, FileTypes]]]
|
| 86 |
+
|
| 87 |
+
RequestExtensions = Mapping[str, Any]
|
| 88 |
+
|
| 89 |
+
__all__ = ["AsyncByteStream", "SyncByteStream"]
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class SyncByteStream:
|
| 93 |
+
def __iter__(self) -> Iterator[bytes]:
|
| 94 |
+
raise NotImplementedError(
|
| 95 |
+
"The '__iter__' method must be implemented."
|
| 96 |
+
) # pragma: no cover
|
| 97 |
+
yield b"" # pragma: no cover
|
| 98 |
+
|
| 99 |
+
def close(self) -> None:
|
| 100 |
+
"""
|
| 101 |
+
Subclasses can override this method to release any network resources
|
| 102 |
+
after a request/response cycle is complete.
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class AsyncByteStream:
|
| 107 |
+
async def __aiter__(self) -> AsyncIterator[bytes]:
|
| 108 |
+
raise NotImplementedError(
|
| 109 |
+
"The '__aiter__' method must be implemented."
|
| 110 |
+
) # pragma: no cover
|
| 111 |
+
yield b"" # pragma: no cover
|
| 112 |
+
|
| 113 |
+
async def aclose(self) -> None:
|
| 114 |
+
pass
|
venv/lib/python3.12/site-packages/httpx/_urlparse.py
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
An implementation of `urlparse` that provides URL validation and normalization
|
| 3 |
+
as described by RFC3986.
|
| 4 |
+
|
| 5 |
+
We rely on this implementation rather than the one in Python's stdlib, because:
|
| 6 |
+
|
| 7 |
+
* It provides more complete URL validation.
|
| 8 |
+
* It properly differentiates between an empty querystring and an absent querystring,
|
| 9 |
+
to distinguish URLs with a trailing '?'.
|
| 10 |
+
* It handles scheme, hostname, port, and path normalization.
|
| 11 |
+
* It supports IDNA hostnames, normalizing them to their encoded form.
|
| 12 |
+
* The API supports passing individual components, as well as the complete URL string.
|
| 13 |
+
|
| 14 |
+
Previously we relied on the excellent `rfc3986` package to handle URL parsing and
|
| 15 |
+
validation, but this module provides a simpler alternative, with less indirection
|
| 16 |
+
required.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
from __future__ import annotations
|
| 20 |
+
|
| 21 |
+
import ipaddress
|
| 22 |
+
import re
|
| 23 |
+
import typing
|
| 24 |
+
|
| 25 |
+
import idna
|
| 26 |
+
|
| 27 |
+
from ._exceptions import InvalidURL
|
| 28 |
+
|
| 29 |
+
MAX_URL_LENGTH = 65536
|
| 30 |
+
|
| 31 |
+
# https://datatracker.ietf.org/doc/html/rfc3986.html#section-2.3
|
| 32 |
+
UNRESERVED_CHARACTERS = (
|
| 33 |
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
|
| 34 |
+
)
|
| 35 |
+
SUB_DELIMS = "!$&'()*+,;="
|
| 36 |
+
|
| 37 |
+
PERCENT_ENCODED_REGEX = re.compile("%[A-Fa-f0-9]{2}")
|
| 38 |
+
|
| 39 |
+
# https://url.spec.whatwg.org/#percent-encoded-bytes
|
| 40 |
+
|
| 41 |
+
# The fragment percent-encode set is the C0 control percent-encode set
|
| 42 |
+
# and U+0020 SPACE, U+0022 ("), U+003C (<), U+003E (>), and U+0060 (`).
|
| 43 |
+
FRAG_SAFE = "".join(
|
| 44 |
+
[chr(i) for i in range(0x20, 0x7F) if i not in (0x20, 0x22, 0x3C, 0x3E, 0x60)]
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# The query percent-encode set is the C0 control percent-encode set
|
| 48 |
+
# and U+0020 SPACE, U+0022 ("), U+0023 (#), U+003C (<), and U+003E (>).
|
| 49 |
+
QUERY_SAFE = "".join(
|
| 50 |
+
[chr(i) for i in range(0x20, 0x7F) if i not in (0x20, 0x22, 0x23, 0x3C, 0x3E)]
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# The path percent-encode set is the query percent-encode set
|
| 54 |
+
# and U+003F (?), U+0060 (`), U+007B ({), and U+007D (}).
|
| 55 |
+
PATH_SAFE = "".join(
|
| 56 |
+
[
|
| 57 |
+
chr(i)
|
| 58 |
+
for i in range(0x20, 0x7F)
|
| 59 |
+
if i not in (0x20, 0x22, 0x23, 0x3C, 0x3E) + (0x3F, 0x60, 0x7B, 0x7D)
|
| 60 |
+
]
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# The userinfo percent-encode set is the path percent-encode set
|
| 64 |
+
# and U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@),
|
| 65 |
+
# U+005B ([) to U+005E (^), inclusive, and U+007C (|).
|
| 66 |
+
USERNAME_SAFE = "".join(
|
| 67 |
+
[
|
| 68 |
+
chr(i)
|
| 69 |
+
for i in range(0x20, 0x7F)
|
| 70 |
+
if i
|
| 71 |
+
not in (0x20, 0x22, 0x23, 0x3C, 0x3E)
|
| 72 |
+
+ (0x3F, 0x60, 0x7B, 0x7D)
|
| 73 |
+
+ (0x2F, 0x3A, 0x3B, 0x3D, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x7C)
|
| 74 |
+
]
|
| 75 |
+
)
|
| 76 |
+
PASSWORD_SAFE = "".join(
|
| 77 |
+
[
|
| 78 |
+
chr(i)
|
| 79 |
+
for i in range(0x20, 0x7F)
|
| 80 |
+
if i
|
| 81 |
+
not in (0x20, 0x22, 0x23, 0x3C, 0x3E)
|
| 82 |
+
+ (0x3F, 0x60, 0x7B, 0x7D)
|
| 83 |
+
+ (0x2F, 0x3A, 0x3B, 0x3D, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x7C)
|
| 84 |
+
]
|
| 85 |
+
)
|
| 86 |
+
# Note... The terminology 'userinfo' percent-encode set in the WHATWG document
|
| 87 |
+
# is used for the username and password quoting. For the joint userinfo component
|
| 88 |
+
# we remove U+003A (:) from the safe set.
|
| 89 |
+
USERINFO_SAFE = "".join(
|
| 90 |
+
[
|
| 91 |
+
chr(i)
|
| 92 |
+
for i in range(0x20, 0x7F)
|
| 93 |
+
if i
|
| 94 |
+
not in (0x20, 0x22, 0x23, 0x3C, 0x3E)
|
| 95 |
+
+ (0x3F, 0x60, 0x7B, 0x7D)
|
| 96 |
+
+ (0x2F, 0x3B, 0x3D, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x7C)
|
| 97 |
+
]
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# {scheme}: (optional)
|
| 102 |
+
# //{authority} (optional)
|
| 103 |
+
# {path}
|
| 104 |
+
# ?{query} (optional)
|
| 105 |
+
# #{fragment} (optional)
|
| 106 |
+
URL_REGEX = re.compile(
|
| 107 |
+
(
|
| 108 |
+
r"(?:(?P<scheme>{scheme}):)?"
|
| 109 |
+
r"(?://(?P<authority>{authority}))?"
|
| 110 |
+
r"(?P<path>{path})"
|
| 111 |
+
r"(?:\?(?P<query>{query}))?"
|
| 112 |
+
r"(?:#(?P<fragment>{fragment}))?"
|
| 113 |
+
).format(
|
| 114 |
+
scheme="([a-zA-Z][a-zA-Z0-9+.-]*)?",
|
| 115 |
+
authority="[^/?#]*",
|
| 116 |
+
path="[^?#]*",
|
| 117 |
+
query="[^#]*",
|
| 118 |
+
fragment=".*",
|
| 119 |
+
)
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
# {userinfo}@ (optional)
|
| 123 |
+
# {host}
|
| 124 |
+
# :{port} (optional)
|
| 125 |
+
AUTHORITY_REGEX = re.compile(
|
| 126 |
+
(
|
| 127 |
+
r"(?:(?P<userinfo>{userinfo})@)?" r"(?P<host>{host})" r":?(?P<port>{port})?"
|
| 128 |
+
).format(
|
| 129 |
+
userinfo=".*", # Any character sequence.
|
| 130 |
+
host="(\\[.*\\]|[^:@]*)", # Either any character sequence excluding ':' or '@',
|
| 131 |
+
# or an IPv6 address enclosed within square brackets.
|
| 132 |
+
port=".*", # Any character sequence.
|
| 133 |
+
)
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
# If we call urlparse with an individual component, then we need to regex
|
| 138 |
+
# validate that component individually.
|
| 139 |
+
# Note that we're duplicating the same strings as above. Shock! Horror!!
|
| 140 |
+
COMPONENT_REGEX = {
|
| 141 |
+
"scheme": re.compile("([a-zA-Z][a-zA-Z0-9+.-]*)?"),
|
| 142 |
+
"authority": re.compile("[^/?#]*"),
|
| 143 |
+
"path": re.compile("[^?#]*"),
|
| 144 |
+
"query": re.compile("[^#]*"),
|
| 145 |
+
"fragment": re.compile(".*"),
|
| 146 |
+
"userinfo": re.compile("[^@]*"),
|
| 147 |
+
"host": re.compile("(\\[.*\\]|[^:]*)"),
|
| 148 |
+
"port": re.compile(".*"),
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# We use these simple regexs as a first pass before handing off to
|
| 153 |
+
# the stdlib 'ipaddress' module for IP address validation.
|
| 154 |
+
IPv4_STYLE_HOSTNAME = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$")
|
| 155 |
+
IPv6_STYLE_HOSTNAME = re.compile(r"^\[.*\]$")
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class ParseResult(typing.NamedTuple):
|
| 159 |
+
scheme: str
|
| 160 |
+
userinfo: str
|
| 161 |
+
host: str
|
| 162 |
+
port: int | None
|
| 163 |
+
path: str
|
| 164 |
+
query: str | None
|
| 165 |
+
fragment: str | None
|
| 166 |
+
|
| 167 |
+
@property
|
| 168 |
+
def authority(self) -> str:
|
| 169 |
+
return "".join(
|
| 170 |
+
[
|
| 171 |
+
f"{self.userinfo}@" if self.userinfo else "",
|
| 172 |
+
f"[{self.host}]" if ":" in self.host else self.host,
|
| 173 |
+
f":{self.port}" if self.port is not None else "",
|
| 174 |
+
]
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
@property
|
| 178 |
+
def netloc(self) -> str:
|
| 179 |
+
return "".join(
|
| 180 |
+
[
|
| 181 |
+
f"[{self.host}]" if ":" in self.host else self.host,
|
| 182 |
+
f":{self.port}" if self.port is not None else "",
|
| 183 |
+
]
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
def copy_with(self, **kwargs: str | None) -> ParseResult:
|
| 187 |
+
if not kwargs:
|
| 188 |
+
return self
|
| 189 |
+
|
| 190 |
+
defaults = {
|
| 191 |
+
"scheme": self.scheme,
|
| 192 |
+
"authority": self.authority,
|
| 193 |
+
"path": self.path,
|
| 194 |
+
"query": self.query,
|
| 195 |
+
"fragment": self.fragment,
|
| 196 |
+
}
|
| 197 |
+
defaults.update(kwargs)
|
| 198 |
+
return urlparse("", **defaults)
|
| 199 |
+
|
| 200 |
+
def __str__(self) -> str:
|
| 201 |
+
authority = self.authority
|
| 202 |
+
return "".join(
|
| 203 |
+
[
|
| 204 |
+
f"{self.scheme}:" if self.scheme else "",
|
| 205 |
+
f"//{authority}" if authority else "",
|
| 206 |
+
self.path,
|
| 207 |
+
f"?{self.query}" if self.query is not None else "",
|
| 208 |
+
f"#{self.fragment}" if self.fragment is not None else "",
|
| 209 |
+
]
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def urlparse(url: str = "", **kwargs: str | None) -> ParseResult:
|
| 214 |
+
# Initial basic checks on allowable URLs.
|
| 215 |
+
# ---------------------------------------
|
| 216 |
+
|
| 217 |
+
# Hard limit the maximum allowable URL length.
|
| 218 |
+
if len(url) > MAX_URL_LENGTH:
|
| 219 |
+
raise InvalidURL("URL too long")
|
| 220 |
+
|
| 221 |
+
# If a URL includes any ASCII control characters including \t, \r, \n,
|
| 222 |
+
# then treat it as invalid.
|
| 223 |
+
if any(char.isascii() and not char.isprintable() for char in url):
|
| 224 |
+
char = next(char for char in url if char.isascii() and not char.isprintable())
|
| 225 |
+
idx = url.find(char)
|
| 226 |
+
error = (
|
| 227 |
+
f"Invalid non-printable ASCII character in URL, {char!r} at position {idx}."
|
| 228 |
+
)
|
| 229 |
+
raise InvalidURL(error)
|
| 230 |
+
|
| 231 |
+
# Some keyword arguments require special handling.
|
| 232 |
+
# ------------------------------------------------
|
| 233 |
+
|
| 234 |
+
# Coerce "port" to a string, if it is provided as an integer.
|
| 235 |
+
if "port" in kwargs:
|
| 236 |
+
port = kwargs["port"]
|
| 237 |
+
kwargs["port"] = str(port) if isinstance(port, int) else port
|
| 238 |
+
|
| 239 |
+
# Replace "netloc" with "host and "port".
|
| 240 |
+
if "netloc" in kwargs:
|
| 241 |
+
netloc = kwargs.pop("netloc") or ""
|
| 242 |
+
kwargs["host"], _, kwargs["port"] = netloc.partition(":")
|
| 243 |
+
|
| 244 |
+
# Replace "username" and/or "password" with "userinfo".
|
| 245 |
+
if "username" in kwargs or "password" in kwargs:
|
| 246 |
+
username = quote(kwargs.pop("username", "") or "", safe=USERNAME_SAFE)
|
| 247 |
+
password = quote(kwargs.pop("password", "") or "", safe=PASSWORD_SAFE)
|
| 248 |
+
kwargs["userinfo"] = f"{username}:{password}" if password else username
|
| 249 |
+
|
| 250 |
+
# Replace "raw_path" with "path" and "query".
|
| 251 |
+
if "raw_path" in kwargs:
|
| 252 |
+
raw_path = kwargs.pop("raw_path") or ""
|
| 253 |
+
kwargs["path"], seperator, kwargs["query"] = raw_path.partition("?")
|
| 254 |
+
if not seperator:
|
| 255 |
+
kwargs["query"] = None
|
| 256 |
+
|
| 257 |
+
# Ensure that IPv6 "host" addresses are always escaped with "[...]".
|
| 258 |
+
if "host" in kwargs:
|
| 259 |
+
host = kwargs.get("host") or ""
|
| 260 |
+
if ":" in host and not (host.startswith("[") and host.endswith("]")):
|
| 261 |
+
kwargs["host"] = f"[{host}]"
|
| 262 |
+
|
| 263 |
+
# If any keyword arguments are provided, ensure they are valid.
|
| 264 |
+
# -------------------------------------------------------------
|
| 265 |
+
|
| 266 |
+
for key, value in kwargs.items():
|
| 267 |
+
if value is not None:
|
| 268 |
+
if len(value) > MAX_URL_LENGTH:
|
| 269 |
+
raise InvalidURL(f"URL component '{key}' too long")
|
| 270 |
+
|
| 271 |
+
# If a component includes any ASCII control characters including \t, \r, \n,
|
| 272 |
+
# then treat it as invalid.
|
| 273 |
+
if any(char.isascii() and not char.isprintable() for char in value):
|
| 274 |
+
char = next(
|
| 275 |
+
char for char in value if char.isascii() and not char.isprintable()
|
| 276 |
+
)
|
| 277 |
+
idx = value.find(char)
|
| 278 |
+
error = (
|
| 279 |
+
f"Invalid non-printable ASCII character in URL {key} component, "
|
| 280 |
+
f"{char!r} at position {idx}."
|
| 281 |
+
)
|
| 282 |
+
raise InvalidURL(error)
|
| 283 |
+
|
| 284 |
+
# Ensure that keyword arguments match as a valid regex.
|
| 285 |
+
if not COMPONENT_REGEX[key].fullmatch(value):
|
| 286 |
+
raise InvalidURL(f"Invalid URL component '{key}'")
|
| 287 |
+
|
| 288 |
+
# The URL_REGEX will always match, but may have empty components.
|
| 289 |
+
url_match = URL_REGEX.match(url)
|
| 290 |
+
assert url_match is not None
|
| 291 |
+
url_dict = url_match.groupdict()
|
| 292 |
+
|
| 293 |
+
# * 'scheme', 'authority', and 'path' may be empty strings.
|
| 294 |
+
# * 'query' may be 'None', indicating no trailing "?" portion.
|
| 295 |
+
# Any string including the empty string, indicates a trailing "?".
|
| 296 |
+
# * 'fragment' may be 'None', indicating no trailing "#" portion.
|
| 297 |
+
# Any string including the empty string, indicates a trailing "#".
|
| 298 |
+
scheme = kwargs.get("scheme", url_dict["scheme"]) or ""
|
| 299 |
+
authority = kwargs.get("authority", url_dict["authority"]) or ""
|
| 300 |
+
path = kwargs.get("path", url_dict["path"]) or ""
|
| 301 |
+
query = kwargs.get("query", url_dict["query"])
|
| 302 |
+
frag = kwargs.get("fragment", url_dict["fragment"])
|
| 303 |
+
|
| 304 |
+
# The AUTHORITY_REGEX will always match, but may have empty components.
|
| 305 |
+
authority_match = AUTHORITY_REGEX.match(authority)
|
| 306 |
+
assert authority_match is not None
|
| 307 |
+
authority_dict = authority_match.groupdict()
|
| 308 |
+
|
| 309 |
+
# * 'userinfo' and 'host' may be empty strings.
|
| 310 |
+
# * 'port' may be 'None'.
|
| 311 |
+
userinfo = kwargs.get("userinfo", authority_dict["userinfo"]) or ""
|
| 312 |
+
host = kwargs.get("host", authority_dict["host"]) or ""
|
| 313 |
+
port = kwargs.get("port", authority_dict["port"])
|
| 314 |
+
|
| 315 |
+
# Normalize and validate each component.
|
| 316 |
+
# We end up with a parsed representation of the URL,
|
| 317 |
+
# with components that are plain ASCII bytestrings.
|
| 318 |
+
parsed_scheme: str = scheme.lower()
|
| 319 |
+
parsed_userinfo: str = quote(userinfo, safe=USERINFO_SAFE)
|
| 320 |
+
parsed_host: str = encode_host(host)
|
| 321 |
+
parsed_port: int | None = normalize_port(port, scheme)
|
| 322 |
+
|
| 323 |
+
has_scheme = parsed_scheme != ""
|
| 324 |
+
has_authority = (
|
| 325 |
+
parsed_userinfo != "" or parsed_host != "" or parsed_port is not None
|
| 326 |
+
)
|
| 327 |
+
validate_path(path, has_scheme=has_scheme, has_authority=has_authority)
|
| 328 |
+
if has_scheme or has_authority:
|
| 329 |
+
path = normalize_path(path)
|
| 330 |
+
|
| 331 |
+
parsed_path: str = quote(path, safe=PATH_SAFE)
|
| 332 |
+
parsed_query: str | None = None if query is None else quote(query, safe=QUERY_SAFE)
|
| 333 |
+
parsed_frag: str | None = None if frag is None else quote(frag, safe=FRAG_SAFE)
|
| 334 |
+
|
| 335 |
+
# The parsed ASCII bytestrings are our canonical form.
|
| 336 |
+
# All properties of the URL are derived from these.
|
| 337 |
+
return ParseResult(
|
| 338 |
+
parsed_scheme,
|
| 339 |
+
parsed_userinfo,
|
| 340 |
+
parsed_host,
|
| 341 |
+
parsed_port,
|
| 342 |
+
parsed_path,
|
| 343 |
+
parsed_query,
|
| 344 |
+
parsed_frag,
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def encode_host(host: str) -> str:
|
| 349 |
+
if not host:
|
| 350 |
+
return ""
|
| 351 |
+
|
| 352 |
+
elif IPv4_STYLE_HOSTNAME.match(host):
|
| 353 |
+
# Validate IPv4 hostnames like #.#.#.#
|
| 354 |
+
#
|
| 355 |
+
# From https://datatracker.ietf.org/doc/html/rfc3986/#section-3.2.2
|
| 356 |
+
#
|
| 357 |
+
# IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
|
| 358 |
+
try:
|
| 359 |
+
ipaddress.IPv4Address(host)
|
| 360 |
+
except ipaddress.AddressValueError:
|
| 361 |
+
raise InvalidURL(f"Invalid IPv4 address: {host!r}")
|
| 362 |
+
return host
|
| 363 |
+
|
| 364 |
+
elif IPv6_STYLE_HOSTNAME.match(host):
|
| 365 |
+
# Validate IPv6 hostnames like [...]
|
| 366 |
+
#
|
| 367 |
+
# From https://datatracker.ietf.org/doc/html/rfc3986/#section-3.2.2
|
| 368 |
+
#
|
| 369 |
+
# "A host identified by an Internet Protocol literal address, version 6
|
| 370 |
+
# [RFC3513] or later, is distinguished by enclosing the IP literal
|
| 371 |
+
# within square brackets ("[" and "]"). This is the only place where
|
| 372 |
+
# square bracket characters are allowed in the URI syntax."
|
| 373 |
+
try:
|
| 374 |
+
ipaddress.IPv6Address(host[1:-1])
|
| 375 |
+
except ipaddress.AddressValueError:
|
| 376 |
+
raise InvalidURL(f"Invalid IPv6 address: {host!r}")
|
| 377 |
+
return host[1:-1]
|
| 378 |
+
|
| 379 |
+
elif host.isascii():
|
| 380 |
+
# Regular ASCII hostnames
|
| 381 |
+
#
|
| 382 |
+
# From https://datatracker.ietf.org/doc/html/rfc3986/#section-3.2.2
|
| 383 |
+
#
|
| 384 |
+
# reg-name = *( unreserved / pct-encoded / sub-delims )
|
| 385 |
+
WHATWG_SAFE = '"`{}%|\\'
|
| 386 |
+
return quote(host.lower(), safe=SUB_DELIMS + WHATWG_SAFE)
|
| 387 |
+
|
| 388 |
+
# IDNA hostnames
|
| 389 |
+
try:
|
| 390 |
+
return idna.encode(host.lower()).decode("ascii")
|
| 391 |
+
except idna.IDNAError:
|
| 392 |
+
raise InvalidURL(f"Invalid IDNA hostname: {host!r}")
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
def normalize_port(port: str | int | None, scheme: str) -> int | None:
|
| 396 |
+
# From https://tools.ietf.org/html/rfc3986#section-3.2.3
|
| 397 |
+
#
|
| 398 |
+
# "A scheme may define a default port. For example, the "http" scheme
|
| 399 |
+
# defines a default port of "80", corresponding to its reserved TCP
|
| 400 |
+
# port number. The type of port designated by the port number (e.g.,
|
| 401 |
+
# TCP, UDP, SCTP) is defined by the URI scheme. URI producers and
|
| 402 |
+
# normalizers should omit the port component and its ":" delimiter if
|
| 403 |
+
# port is empty or if its value would be the same as that of the
|
| 404 |
+
# scheme's default."
|
| 405 |
+
if port is None or port == "":
|
| 406 |
+
return None
|
| 407 |
+
|
| 408 |
+
try:
|
| 409 |
+
port_as_int = int(port)
|
| 410 |
+
except ValueError:
|
| 411 |
+
raise InvalidURL(f"Invalid port: {port!r}")
|
| 412 |
+
|
| 413 |
+
# See https://url.spec.whatwg.org/#url-miscellaneous
|
| 414 |
+
default_port = {"ftp": 21, "http": 80, "https": 443, "ws": 80, "wss": 443}.get(
|
| 415 |
+
scheme
|
| 416 |
+
)
|
| 417 |
+
if port_as_int == default_port:
|
| 418 |
+
return None
|
| 419 |
+
return port_as_int
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
def validate_path(path: str, has_scheme: bool, has_authority: bool) -> None:
|
| 423 |
+
"""
|
| 424 |
+
Path validation rules that depend on if the URL contains
|
| 425 |
+
a scheme or authority component.
|
| 426 |
+
|
| 427 |
+
See https://datatracker.ietf.org/doc/html/rfc3986.html#section-3.3
|
| 428 |
+
"""
|
| 429 |
+
if has_authority:
|
| 430 |
+
# If a URI contains an authority component, then the path component
|
| 431 |
+
# must either be empty or begin with a slash ("/") character."
|
| 432 |
+
if path and not path.startswith("/"):
|
| 433 |
+
raise InvalidURL("For absolute URLs, path must be empty or begin with '/'")
|
| 434 |
+
|
| 435 |
+
if not has_scheme and not has_authority:
|
| 436 |
+
# If a URI does not contain an authority component, then the path cannot begin
|
| 437 |
+
# with two slash characters ("//").
|
| 438 |
+
if path.startswith("//"):
|
| 439 |
+
raise InvalidURL("Relative URLs cannot have a path starting with '//'")
|
| 440 |
+
|
| 441 |
+
# In addition, a URI reference (Section 4.1) may be a relative-path reference,
|
| 442 |
+
# in which case the first path segment cannot contain a colon (":") character.
|
| 443 |
+
if path.startswith(":"):
|
| 444 |
+
raise InvalidURL("Relative URLs cannot have a path starting with ':'")
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
def normalize_path(path: str) -> str:
|
| 448 |
+
"""
|
| 449 |
+
Drop "." and ".." segments from a URL path.
|
| 450 |
+
|
| 451 |
+
For example:
|
| 452 |
+
|
| 453 |
+
normalize_path("/path/./to/somewhere/..") == "/path/to"
|
| 454 |
+
"""
|
| 455 |
+
# Fast return when no '.' characters in the path.
|
| 456 |
+
if "." not in path:
|
| 457 |
+
return path
|
| 458 |
+
|
| 459 |
+
components = path.split("/")
|
| 460 |
+
|
| 461 |
+
# Fast return when no '.' or '..' components in the path.
|
| 462 |
+
if "." not in components and ".." not in components:
|
| 463 |
+
return path
|
| 464 |
+
|
| 465 |
+
# https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4
|
| 466 |
+
output: list[str] = []
|
| 467 |
+
for component in components:
|
| 468 |
+
if component == ".":
|
| 469 |
+
pass
|
| 470 |
+
elif component == "..":
|
| 471 |
+
if output and output != [""]:
|
| 472 |
+
output.pop()
|
| 473 |
+
else:
|
| 474 |
+
output.append(component)
|
| 475 |
+
return "/".join(output)
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def PERCENT(string: str) -> str:
|
| 479 |
+
return "".join([f"%{byte:02X}" for byte in string.encode("utf-8")])
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
def percent_encoded(string: str, safe: str) -> str:
|
| 483 |
+
"""
|
| 484 |
+
Use percent-encoding to quote a string.
|
| 485 |
+
"""
|
| 486 |
+
NON_ESCAPED_CHARS = UNRESERVED_CHARACTERS + safe
|
| 487 |
+
|
| 488 |
+
# Fast path for strings that don't need escaping.
|
| 489 |
+
if not string.rstrip(NON_ESCAPED_CHARS):
|
| 490 |
+
return string
|
| 491 |
+
|
| 492 |
+
return "".join(
|
| 493 |
+
[char if char in NON_ESCAPED_CHARS else PERCENT(char) for char in string]
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def quote(string: str, safe: str) -> str:
|
| 498 |
+
"""
|
| 499 |
+
Use percent-encoding to quote a string, omitting existing '%xx' escape sequences.
|
| 500 |
+
|
| 501 |
+
See: https://www.rfc-editor.org/rfc/rfc3986#section-2.1
|
| 502 |
+
|
| 503 |
+
* `string`: The string to be percent-escaped.
|
| 504 |
+
* `safe`: A string containing characters that may be treated as safe, and do not
|
| 505 |
+
need to be escaped. Unreserved characters are always treated as safe.
|
| 506 |
+
See: https://www.rfc-editor.org/rfc/rfc3986#section-2.3
|
| 507 |
+
"""
|
| 508 |
+
parts = []
|
| 509 |
+
current_position = 0
|
| 510 |
+
for match in re.finditer(PERCENT_ENCODED_REGEX, string):
|
| 511 |
+
start_position, end_position = match.start(), match.end()
|
| 512 |
+
matched_text = match.group(0)
|
| 513 |
+
# Add any text up to the '%xx' escape sequence.
|
| 514 |
+
if start_position != current_position:
|
| 515 |
+
leading_text = string[current_position:start_position]
|
| 516 |
+
parts.append(percent_encoded(leading_text, safe=safe))
|
| 517 |
+
|
| 518 |
+
# Add the '%xx' escape sequence.
|
| 519 |
+
parts.append(matched_text)
|
| 520 |
+
current_position = end_position
|
| 521 |
+
|
| 522 |
+
# Add any text after the final '%xx' escape sequence.
|
| 523 |
+
if current_position != len(string):
|
| 524 |
+
trailing_text = string[current_position:]
|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amTypes
|
| 9 |
+
from ._urlparse import urlparse
|
| 10 |
+
from ._utils import primitive_value_to_str
|
| 11 |
+
|
| 12 |
+
__all__ = ["URL", "QueryParams"]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class URL:
|
| 16 |
+
"""
|
| 17 |
+
url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink")
|
| 18 |
+
|
| 19 |
+
assert url.scheme == "https"
|
| 20 |
+
assert url.username == "jo@email.com"
|
| 21 |
+
assert url.password == "a secret"
|
| 22 |
+
assert url.userinfo == b"jo%40email.com:a%20secret"
|
| 23 |
+
assert url.host == "müller.de"
|
| 24 |
+
assert url.raw_host == b"xn--mller-kva.de"
|
| 25 |
+
assert url.port == 1234
|
| 26 |
+
assert url.netloc == b"xn--mller-kva.de:1234"
|
| 27 |
+
assert url.path == "/pa th"
|
| 28 |
+
assert url.query == b"?search=ab"
|
| 29 |
+
assert url.raw_path == b"/pa%20th?search=ab"
|
| 30 |
+
assert url.fragment == "anchorlink"
|
| 31 |
+
|
| 32 |
+
The components of a URL are broken down like this:
|
| 33 |
+
|
| 34 |
+
https://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink
|
| 35 |
+
[scheme] [ username ] [password] [ host ][port][ path ] [ query ] [fragment]
|
| 36 |
+
[ userinfo ] [ netloc ][ raw_path ]
|
| 37 |
+
|
| 38 |
+
Note that:
|
| 39 |
+
|
| 40 |
+
* `url.scheme` is normalized to always be lowercased.
|
| 41 |
+
|
| 42 |
+
* `url.host` is normalized to always be lowercased. Internationalized domain
|
| 43 |
+
names are represented in unicode, without IDNA encoding applied. For instance:
|
| 44 |
+
|
| 45 |
+
url = httpx.URL("http://中国.icom.museum")
|
| 46 |
+
assert url.host == "中国.icom.museum"
|
| 47 |
+
url = httpx.URL("http://xn--fiqs8s.icom.museum")
|
| 48 |
+
assert url.host == "中国.icom.museum"
|
| 49 |
+
|
| 50 |
+
* `url.raw_host` is normalized to always be lowercased, and is IDNA encoded.
|
| 51 |
+
|
| 52 |
+
url = httpx.URL("http://中国.icom.museum")
|
| 53 |
+
assert url.raw_host == b"xn--fiqs8s.icom.museum"
|
| 54 |
+
url = httpx.URL("http://xn--fiqs8s.icom.museum")
|
| 55 |
+
assert url.raw_host == b"xn--fiqs8s.icom.museum"
|
| 56 |
+
|
| 57 |
+
* `url.port` is either None or an integer. URLs that include the default port for
|
| 58 |
+
"http", "https", "ws", "wss", and "ftp" schemes have their port
|
| 59 |
+
normalized to `None`.
|
| 60 |
+
|
| 61 |
+
assert httpx.URL("http://example.com") == httpx.URL("http://example.com:80")
|
| 62 |
+
assert httpx.URL("http://example.com").port is None
|
| 63 |
+
assert httpx.URL("http://example.com:80").port is None
|
| 64 |
+
|
| 65 |
+
* `url.userinfo` is raw bytes, without URL escaping. Usually you'll want to work
|
| 66 |
+
with `url.username` and `url.password` instead, which handle the URL escaping.
|
| 67 |
+
|
| 68 |
+
* `url.raw_path` is raw bytes of both the path and query, without URL escaping.
|
| 69 |
+
This portion is used as the target when constructing HTTP requests. Usually you'll
|
| 70 |
+
want to work with `url.path` instead.
|
| 71 |
+
|
| 72 |
+
* `url.query` is raw bytes, without URL escaping. A URL query string portion can
|
| 73 |
+
only be properly URL escaped when decoding the parameter names and values
|
| 74 |
+
themselves.
|
| 75 |
+
"""
|
| 76 |
+
|
| 77 |
+
def __init__(self, url: URL | str = "", **kwargs: typing.Any) -> None:
|
| 78 |
+
if kwargs:
|
| 79 |
+
allowed = {
|
| 80 |
+
"scheme": str,
|
| 81 |
+
"username": str,
|
| 82 |
+
"password": str,
|
| 83 |
+
"userinfo": bytes,
|
| 84 |
+
"host": str,
|
| 85 |
+
"port": int,
|
| 86 |
+
"netloc": bytes,
|
| 87 |
+
"path": str,
|
| 88 |
+
"query": bytes,
|
| 89 |
+
"raw_path": bytes,
|
| 90 |
+
"fragment": str,
|
| 91 |
+
"params": object,
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# Perform type checking for all supported keyword arguments.
|
| 95 |
+
for key, value in kwargs.items():
|
| 96 |
+
if key not in allowed:
|
| 97 |
+
message = f"{key!r} is an invalid keyword argument for URL()"
|
| 98 |
+
raise TypeError(message)
|
| 99 |
+
if value is not None and not isinstance(value, allowed[key]):
|
| 100 |
+
expected = allowed[key].__name__
|
| 101 |
+
seen = type(value).__name__
|
| 102 |
+
message = f"Argument {key!r} must be {expected} but got {seen}"
|
| 103 |
+
raise TypeError(message)
|
| 104 |
+
if isinstance(value, bytes):
|
| 105 |
+
kwargs[key] = value.decode("ascii")
|
| 106 |
+
|
| 107 |
+
if "params" in kwargs:
|
| 108 |
+
# Replace any "params" keyword with the raw "query" instead.
|
| 109 |
+
#
|
| 110 |
+
# Ensure that empty params use `kwargs["query"] = None` rather
|
| 111 |
+
# than `kwargs["query"] = ""`, so that generated URLs do not
|
| 112 |
+
# include an empty trailing "?".
|
| 113 |
+
params = kwargs.pop("params")
|
| 114 |
+
kwargs["query"] = None if not params else str(QueryParams(params))
|
| 115 |
+
|
| 116 |
+
if isinstance(url, str):
|
| 117 |
+
self._uri_reference = urlparse(url, **kwargs)
|
| 118 |
+
elif isinstance(url, URL):
|
| 119 |
+
self._uri_reference = url._uri_reference.copy_with(**kwargs)
|
| 120 |
+
else:
|
| 121 |
+
raise TypeError(
|
| 122 |
+
"Invalid type for url. Expected str or httpx.URL,"
|
| 123 |
+
f" got {type(url)}: {url!r}"
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
@property
|
| 127 |
+
def scheme(self) -> str:
|
| 128 |
+
"""
|
| 129 |
+
The URL scheme, such as "http", "https".
|
| 130 |
+
Always normalised to lowercase.
|
| 131 |
+
"""
|
| 132 |
+
return self._uri_reference.scheme
|
| 133 |
+
|
| 134 |
+
@property
|
| 135 |
+
def raw_scheme(self) -> bytes:
|
| 136 |
+
"""
|
| 137 |
+
The raw bytes representation of the URL scheme, such as b"http", b"https".
|
| 138 |
+
Always normalised to lowercase.
|
| 139 |
+
"""
|
| 140 |
+
return self._uri_reference.scheme.encode("ascii")
|
| 141 |
+
|
| 142 |
+
@property
|
| 143 |
+
def userinfo(self) -> bytes:
|
| 144 |
+
"""
|
| 145 |
+
The URL userinfo as a raw bytestring.
|
| 146 |
+
For example: b"jo%40email.com:a%20secret".
|
| 147 |
+
"""
|
| 148 |
+
return self._uri_reference.userinfo.encode("ascii")
|
| 149 |
+
|
| 150 |
+
@property
|
| 151 |
+
def username(self) -> str:
|
| 152 |
+
"""
|
| 153 |
+
The URL username as a string, with URL decoding applied.
|
| 154 |
+
For example: "jo@email.com"
|
| 155 |
+
"""
|
| 156 |
+
userinfo = self._uri_reference.userinfo
|
| 157 |
+
return unquote(userinfo.partition(":")[0])
|
| 158 |
+
|
| 159 |
+
@property
|
| 160 |
+
def password(self) -> str:
|
| 161 |
+
"""
|
| 162 |
+
The URL password as a string, with URL decoding applied.
|
| 163 |
+
For example: "a secret"
|
| 164 |
+
"""
|
| 165 |
+
userinfo = self._uri_reference.userinfo
|
| 166 |
+
return unquote(userinfo.partition(":")[2])
|
| 167 |
+
|
| 168 |
+
@property
|
| 169 |
+
def host(self) -> str:
|
| 170 |
+
"""
|
| 171 |
+
The URL host as a string.
|
| 172 |
+
Always normalized to lowercase, with IDNA hosts decoded into unicode.
|
| 173 |
+
|
| 174 |
+
Examples:
|
| 175 |
+
|
| 176 |
+
url = httpx.URL("http://www.EXAMPLE.org")
|
| 177 |
+
assert url.host == "www.example.org"
|
| 178 |
+
|
| 179 |
+
url = httpx.URL("http://中国.icom.museum")
|
| 180 |
+
assert url.host == "中国.icom.museum"
|
| 181 |
+
|
| 182 |
+
url = httpx.URL("http://xn--fiqs8s.icom.museum")
|
| 183 |
+
assert url.host == "中国.icom.museum"
|
| 184 |
+
|
| 185 |
+
url = httpx.URL("https://[::ffff:192.168.0.1]")
|
| 186 |
+
assert url.host == "::ffff:192.168.0.1"
|
| 187 |
+
"""
|
| 188 |
+
host: str = self._uri_reference.host
|
| 189 |
+
|
| 190 |
+
if host.startswith("xn--"):
|
| 191 |
+
host = idna.decode(host)
|
| 192 |
+
|
| 193 |
+
return host
|
| 194 |
+
|
| 195 |
+
@property
|
| 196 |
+
def raw_host(self) -> bytes:
|
| 197 |
+
"""
|
| 198 |
+
The raw bytes representation of the URL host.
|
| 199 |
+
Always normalized to lowercase, and IDNA encoded.
|
| 200 |
+
|
| 201 |
+
Examples:
|
| 202 |
+
|
| 203 |
+
url = httpx.URL("http://www.EXAMPLE.org")
|
| 204 |
+
assert url.raw_host == b"www.example.org"
|
| 205 |
+
|
| 206 |
+
url = httpx.URL("http://中国.icom.museum")
|
| 207 |
+
assert url.raw_host == b"xn--fiqs8s.icom.museum"
|
| 208 |
+
|
| 209 |
+
url = httpx.URL("http://xn--fiqs8s.icom.museum")
|
| 210 |
+
assert url.raw_host == b"xn--fiqs8s.icom.museum"
|
| 211 |
+
|
| 212 |
+
url = httpx.URL("https://[::ffff:192.168.0.1]")
|
| 213 |
+
assert url.raw_host == b"::ffff:192.168.0.1"
|
| 214 |
+
"""
|
| 215 |
+
return self._uri_reference.host.encode("ascii")
|
| 216 |
+
|
| 217 |
+
@property
|
| 218 |
+
def port(self) -> int | None:
|
| 219 |
+
"""
|
| 220 |
+
The URL port as an integer.
|
| 221 |
+
|
| 222 |
+
Note that the URL class performs port normalization as per the WHATWG spec.
|
| 223 |
+
Default ports for "http", "https", "ws", "wss", and "ftp" schemes are always
|
| 224 |
+
treated as `None`.
|
| 225 |
+
|
| 226 |
+
For example:
|
| 227 |
+
|
| 228 |
+
assert httpx.URL("http://www.example.com") == httpx.URL("http://www.example.com:80")
|
| 229 |
+
assert httpx.URL("http://www.example.com:80").port is None
|
| 230 |
+
"""
|
| 231 |
+
return self._uri_reference.port
|
| 232 |
+
|
| 233 |
+
@property
|
| 234 |
+
def netloc(self) -> bytes:
|
| 235 |
+
"""
|
| 236 |
+
Either `<host>` or `<host>:<port>` as bytes.
|
| 237 |
+
Always normalized to lowercase, and IDNA encoded.
|
| 238 |
+
|
| 239 |
+
This property may be used for generating the value of a request
|
| 240 |
+
"Host" header.
|
| 241 |
+
"""
|
| 242 |
+
return self._uri_reference.netloc.encode("ascii")
|
| 243 |
+
|
| 244 |
+
@property
|
| 245 |
+
def path(self) -> str:
|
| 246 |
+
"""
|
| 247 |
+
The URL path as a string. Excluding the query string, and URL decoded.
|
| 248 |
+
|
| 249 |
+
For example:
|
| 250 |
+
|
| 251 |
+
url = httpx.URL("https://example.com/pa%20th")
|
| 252 |
+
assert url.path == "/pa th"
|
| 253 |
+
"""
|
| 254 |
+
path = self._uri_reference.path or "/"
|
| 255 |
+
return unquote(path)
|
| 256 |
+
|
| 257 |
+
@property
|
| 258 |
+
def query(self) -> bytes:
|
| 259 |
+
"""
|
| 260 |
+
The URL query string, as raw bytes, excluding the leading b"?".
|
| 261 |
+
|
| 262 |
+
This is necessarily a bytewise interface, because we cannot
|
| 263 |
+
perform URL decoding of this representation until we've parsed
|
| 264 |
+
the keys and values into a QueryParams instance.
|
| 265 |
+
|
| 266 |
+
For example:
|
| 267 |
+
|
| 268 |
+
url = httpx.URL("https://example.com/?filter=some%20search%20terms")
|
| 269 |
+
assert url.query == b"filter=some%20search%20terms"
|
| 270 |
+
"""
|
| 271 |
+
query = self._uri_reference.query or ""
|
| 272 |
+
return query.encode("ascii")
|
| 273 |
+
|
| 274 |
+
@property
|
| 275 |
+
def params(self) -> QueryParams:
|
| 276 |
+
"""
|
| 277 |
+
The URL query parameters, neatly parsed and packaged into an immutable
|
| 278 |
+
multidict representation.
|
| 279 |
+
"""
|
| 280 |
+
return QueryParams(self._uri_reference.query)
|
| 281 |
+
|
| 282 |
+
@property
|
| 283 |
+
def raw_path(self) -> bytes:
|
| 284 |
+
"""
|
| 285 |
+
The complete URL path and query string as raw bytes.
|
| 286 |
+
Used as the target when constructing HTTP requests.
|
| 287 |
+
|
| 288 |
+
For example:
|
| 289 |
+
|
| 290 |
+
GET /users?search=some%20text HTTP/1.1
|
| 291 |
+
Host: www.example.org
|
| 292 |
+
Connection: close
|
| 293 |
+
"""
|
| 294 |
+
path = self._uri_reference.path or "/"
|
| 295 |
+
if self._uri_reference.query is not None:
|
| 296 |
+
path += "?" + self._uri_reference.query
|
| 297 |
+
return path.encode("ascii")
|
| 298 |
+
|
| 299 |
+
@property
|
| 300 |
+
def fragment(self) -> str:
|
| 301 |
+
"""
|
| 302 |
+
The URL fragments, as used in HTML anchors.
|
| 303 |
+
As a string, without the leading '#'.
|
| 304 |
+
"""
|
| 305 |
+
return unquote(self._uri_reference.fragment or "")
|
| 306 |
+
|
| 307 |
+
@property
|
| 308 |
+
def is_absolute_url(self) -> bool:
|
| 309 |
+
"""
|
| 310 |
+
Return `True` for absolute URLs such as 'http://example.com/path',
|
| 311 |
+
and `False` for relative URLs such as '/path'.
|
| 312 |
+
"""
|
| 313 |
+
# We don't use `.is_absolute` from `rfc3986` because it treats
|
| 314 |
+
# URLs with a fragment portion as not absolute.
|
| 315 |
+
# What we actually care about is if the URL provides
|
| 316 |
+
# a scheme and hostname to which connections should be made.
|
| 317 |
+
return bool(self._uri_reference.scheme and self._uri_reference.host)
|
| 318 |
+
|
| 319 |
+
@property
|
| 320 |
+
def is_relative_url(self) -> bool:
|
| 321 |
+
"""
|
| 322 |
+
Return `False` for absolute URLs such as 'http://example.com/path',
|
| 323 |
+
and `True` for relative URLs such as '/path'.
|
| 324 |
+
"""
|
| 325 |
+
return not self.is_absolute_url
|
| 326 |
+
|
| 327 |
+
def copy_with(self, **kwargs: typing.Any) -> URL:
|
| 328 |
+
"""
|
| 329 |
+
Copy this URL, returning a new URL with some components altered.
|
| 330 |
+
Accepts the same set of parameters as the components that are made
|
| 331 |
+
available via properties on the `URL` class.
|
| 332 |
+
|
| 333 |
+
For example:
|
| 334 |
+
|
| 335 |
+
url = httpx.URL("https://www.example.com").copy_with(
|
| 336 |
+
username="jo@gmail.com", password="a secret"
|
| 337 |
+
)
|
| 338 |
+
assert url == "https://jo%40email.com:a%20secret@www.example.com"
|
| 339 |
+
"""
|
| 340 |
+
return URL(self, **kwargs)
|
| 341 |
+
|
| 342 |
+
def copy_set_param(self, key: str, value: typing.Any = None) -> URL:
|
| 343 |
+
return self.copy_with(params=self.params.set(key, value))
|
| 344 |
+
|
| 345 |
+
def copy_add_param(self, key: str, value: typing.Any = None) -> URL:
|
| 346 |
+
return self.copy_with(params=self.params.add(key, value))
|
| 347 |
+
|
| 348 |
+
def copy_remove_param(self, key: str) -> URL:
|
| 349 |
+
return self.copy_with(params=self.params.remove(key))
|
| 350 |
+
|
| 351 |
+
def copy_merge_params(self, params: QueryParamTypes) -> URL:
|
| 352 |
+
return self.copy_with(params=self.params.merge(params))
|
| 353 |
+
|
| 354 |
+
def join(self, url: URL | str) -> URL:
|
| 355 |
+
"""
|
| 356 |
+
Return an absolute URL, using this URL as the base.
|
| 357 |
+
|
| 358 |
+
Eg.
|
| 359 |
+
|
| 360 |
+
url = httpx.URL("https://www.example.com/test")
|
| 361 |
+
url = url.join("/new/path")
|
| 362 |
+
assert url == "https://www.example.com/new/path"
|
| 363 |
+
"""
|
| 364 |
+
from urllib.parse import urljoin
|
| 365 |
+
|
| 366 |
+
return URL(urljoin(str(self), str(URL(url))))
|
| 367 |
+
|
| 368 |
+
def __hash__(self) -> int:
|
| 369 |
+
return hash(str(self))
|
| 370 |
+
|
| 371 |
+
def __eq__(self, other: typing.Any) -> bool:
|
| 372 |
+
return isinstance(other, (URL, str)) and str(self) == str(URL(other))
|
| 373 |
+
|
| 374 |
+
def __str__(self) -> str:
|
| 375 |
+
return str(self._uri_reference)
|
| 376 |
+
|
| 377 |
+
def __repr__(self) -> str:
|
| 378 |
+
scheme, userinfo, host, port, path, query, fragment = self._uri_reference
|
| 379 |
+
|
| 380 |
+
if ":" in userinfo:
|
| 381 |
+
# Mask any password component.
|
| 382 |
+
userinfo = f'{userinfo.split(":")[0]}:[secure]'
|
| 383 |
+
|
| 384 |
+
authority = "".join(
|
| 385 |
+
[
|
| 386 |
+
f"{userinfo}@" if userinfo else "",
|
| 387 |
+
f"[{host}]" if ":" in host else host,
|
| 388 |
+
f":{port}" if port is not None else "",
|
| 389 |
+
]
|
| 390 |
+
)
|
| 391 |
+
url = "".join(
|
| 392 |
+
[
|
| 393 |
+
f"{self.scheme}:" if scheme else "",
|
| 394 |
+
f"//{authority}" if authority else "",
|
| 395 |
+
path,
|
| 396 |
+
f"?{query}" if query is not None else "",
|
| 397 |
+
f"#{fragment}" if fragment is not None else "",
|
| 398 |
+
]
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
return f"{self.__class__.__name__}({url!r})"
|
| 402 |
+
|
| 403 |
+
@property
|
| 404 |
+
def raw(self) -> tuple[bytes, bytes, int, bytes]: # pragma: nocover
|
| 405 |
+
import collections
|
| 406 |
+
import warnings
|
| 407 |
+
|
| 408 |
+
warnings.warn("URL.raw is deprecated.")
|
| 409 |
+
RawURL = collections.namedtuple(
|
| 410 |
+
"RawURL", ["raw_scheme", "raw_host", "port", "raw_path"]
|
| 411 |
+
)
|
| 412 |
+
return RawURL(
|
| 413 |
+
raw_scheme=self.raw_scheme,
|
| 414 |
+
raw_host=self.raw_host,
|
| 415 |
+
port=self.port,
|
| 416 |
+
raw_path=self.raw_path,
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
class QueryParams(typing.Mapping[str, str]):
|
| 421 |
+
"""
|
| 422 |
+
URL query parameters, as a multi-dict.
|
| 423 |
+
"""
|
| 424 |
+
|
| 425 |
+
def __init__(self, *args: QueryParamTypes | None, **kwargs: typing.Any) -> None:
|
| 426 |
+
assert len(args) < 2, "Too many arguments."
|
| 427 |
+
assert not (args and kwargs), "Cannot mix named and unnamed arguments."
|
| 428 |
+
|
| 429 |
+
value = args[0] if args else kwargs
|
| 430 |
+
|
| 431 |
+
if value is None or isinstance(value, (str, bytes)):
|
| 432 |
+
value = value.decode("ascii") if isinstance(value, bytes) else value
|
| 433 |
+
self._dict = parse_qs(value, keep_blank_values=True)
|
| 434 |
+
elif isinstance(value, QueryParams):
|
| 435 |
+
self._dict = {k: list(v) for k, v in value._dict.items()}
|
| 436 |
+
else:
|
| 437 |
+
dict_value: dict[typing.Any, list[typing.Any]] = {}
|
| 438 |
+
if isinstance(value, (list, tuple)):
|
| 439 |
+
# Convert list inputs like:
|
| 440 |
+
# [("a", "123"), ("a", "456"), ("b", "789")]
|
| 441 |
+
# To a dict representation, like:
|
| 442 |
+
# {"a": ["123", "456"], "b": ["789"]}
|
| 443 |
+
for item in value:
|
| 444 |
+
dict_value.setdefault(item[0], []).append(item[1])
|
| 445 |
+
else:
|
| 446 |
+
# Convert dict inputs like:
|
| 447 |
+
# {"a": "123", "b": ["456", "789"]}
|
| 448 |
+
# To dict inputs where values are always lists, like:
|
| 449 |
+
# {"a": ["123"], "b": ["456", "789"]}
|
| 450 |
+
dict_value = {
|
| 451 |
+
k: list(v) if isinstance(v, (list, tuple)) else [v]
|
| 452 |
+
for k, v in value.items()
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
# Ensure that keys and values are neatly coerced to strings.
|
| 456 |
+
# We coerce values `True` and `False` to JSON-like "true" and "false"
|
| 457 |
+
# representations, and coerce `None` values to the empty string.
|
| 458 |
+
self._dict = {
|
| 459 |
+
str(k): [primitive_value_to_str(item) for item in v]
|
| 460 |
+
for k, v in dict_value.items()
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
def keys(self) -> typing.KeysView[str]:
|
| 464 |
+
"""
|
| 465 |
+
Return all the keys in the query params.
|
| 466 |
+
|
| 467 |
+
Usage:
|
| 468 |
+
|
| 469 |
+
q = httpx.QueryParams("a=123&a=456&b=789")
|
| 470 |
+
assert list(q.keys()) == ["a", "b"]
|
| 471 |
+
"""
|
| 472 |
+
return self._dict.keys()
|
| 473 |
+
|
| 474 |
+
def values(self) -> typing.ValuesView[str]:
|
| 475 |
+
"""
|
| 476 |
+
Return all the values in the query params. If a key occurs more than once
|
| 477 |
+
only the first item for that key is returned.
|
| 478 |
+
|
| 479 |
+
Usage:
|
| 480 |
+
|
| 481 |
+
q = httpx.QueryParams("a=123&a=456&b=789")
|
| 482 |
+
assert list(q.values()) == ["123", "789"]
|
| 483 |
+
"""
|
| 484 |
+
return {k: v[0] for k, v in self._dict.items()}.values()
|
| 485 |
+
|
| 486 |
+
def items(self) -> typing.ItemsView[str, str]:
|
| 487 |
+
"""
|
| 488 |
+
Return all items in the query params. If a key occurs more than once
|
| 489 |
+
only the first item for that key is returned.
|
| 490 |
+
|
| 491 |
+
Usage:
|
| 492 |
+
|
| 493 |
+
q = httpx.QueryParams("a=123&a=456&b=789")
|
| 494 |
+
assert list(q.items()) == [("a", "123"), ("b", "789")]
|
| 495 |
+
"""
|
| 496 |
+
return {k: v[0] for k, v in self._dict.items()}.items()
|
| 497 |
+
|
| 498 |
+
def multi_items(self) -> list[tuple[str, str]]:
|
| 499 |
+
"""
|
| 500 |
+
Return all items in the query params. Allow duplicate keys to occur.
|
| 501 |
+
|
| 502 |
+
Usage:
|
| 503 |
+
|
| 504 |
+
q = httpx.QueryParams("a=123&a=456&b=789")
|
| 505 |
+
assert list(q.multi_items()) == [("a", "123"), ("a", "456"), ("b", "789")]
|
| 506 |
+
"""
|
| 507 |
+
multi_items: list[tuple[str, str]] = []
|
| 508 |
+
for k, v in self._dict.items():
|
| 509 |
+
multi_items.extend([(k, i) for i in v])
|
| 510 |
+
return multi_items
|
| 511 |
+
|
| 512 |
+
def get(self, key: typing.Any, default: typing.Any = None) -> typing.Any:
|
| 513 |
+
"""
|
| 514 |
+
Get a value from the query param for a given key. If the key occurs
|
| 515 |
+
more than once, then only the first value is returned.
|
| 516 |
+
|
| 517 |
+
Usage:
|
| 518 |
+
|
| 519 |
+
q = httpx.QueryParams("a=123&a=456&b=789")
|
| 520 |
+
assert q.get("a") == "123"
|
| 521 |
+
"""
|
| 522 |
+
if key in self._dict:
|
| 523 |
+
return self._dict[str(key)][0]
|
| 524 |
+
return default
|
| 525 |
+
|
| 526 |
+
def get_list(self, key: str) -> list[str]:
|
| 527 |
+
"""
|
| 528 |
+
Get all values from the query param for a given key.
|
| 529 |
+
|
| 530 |
+
Usage:
|
| 531 |
+
|
| 532 |
+
q = httpx.QueryParams("a=123&a=456&b=789")
|
| 533 |
+
assert q.get_list("a") == ["123", "456"]
|
| 534 |
+
"""
|
| 535 |
+
return list(self._dict.get(str(key), []))
|
| 536 |
+
|
| 537 |
+
def set(self, key: str, value: typing.Any = None) -> QueryParams:
|
| 538 |
+
"""
|
| 539 |
+
Return a new QueryParams instance, setting the value of a key.
|
| 540 |
+
|
| 541 |
+
Usage:
|
| 542 |
+
|
| 543 |
+
q = httpx.QueryParams("a=123")
|
| 544 |
+
q = q.set("a", "456")
|
| 545 |
+
assert q == httpx.QueryParams("a=456")
|
| 546 |
+
"""
|
| 547 |
+
q = QueryParams()
|
| 548 |
+
q._dict = dict(self._dict)
|
| 549 |
+
q._dict[str(key)] = [primitive_value_to_str(value)]
|
| 550 |
+
return q
|
| 551 |
+
|
| 552 |
+
def add(self, key: str, value: typing.Any = None) -> QueryParams:
|
| 553 |
+
"""
|
| 554 |
+
Return a new QueryParams instance, setting or appending the value of a key.
|
| 555 |
+
|
| 556 |
+
Usage:
|
| 557 |
+
|
| 558 |
+
q = httpx.QueryParams("a=123")
|
| 559 |
+
q = q.add("a", "456")
|
| 560 |
+
assert q == httpx.QueryParams("a=123&a=456")
|
| 561 |
+
"""
|
| 562 |
+
q = QueryParams()
|
| 563 |
+
q._dict = dict(self._dict)
|
| 564 |
+
q._dict[str(key)] = q.get_list(key) + [primitive_value_to_str(value)]
|
| 565 |
+
return q
|
| 566 |
+
|
| 567 |
+
def remove(self, key: str) -> QueryParams:
|
| 568 |
+
"""
|
| 569 |
+
Return a new QueryParams instance, removing the value of a key.
|
| 570 |
+
|
| 571 |
+
Usage:
|
| 572 |
+
|
| 573 |
+
q = httpx.QueryParams("a=123")
|
| 574 |
+
q = q.remove("a")
|
| 575 |
+
assert q == httpx.QueryParams("")
|
| 576 |
+
"""
|
| 577 |
+
q = QueryParams()
|
| 578 |
+
q._dict = dict(self._dict)
|
| 579 |
+
q._dict.pop(str(key), None)
|
| 580 |
+
return q
|
| 581 |
+
|
| 582 |
+
def merge(self, params: QueryParamTypes | None = None) -> QueryParams:
|
| 583 |
+
"""
|
| 584 |
+
Return a new QueryParams instance, updated with.
|
| 585 |
+
|
| 586 |
+
Usage:
|
| 587 |
+
|
| 588 |
+
q = httpx.QueryParams("a=123")
|
| 589 |
+
q = q.merge({"b": "456"})
|
| 590 |
+
assert q == httpx.QueryParams("a=123&b=456")
|
| 591 |
+
|
| 592 |
+
q = httpx.QueryParams("a=123")
|
| 593 |
+
q = q.merge({"a": "456", "b": "789"})
|
| 594 |
+
assert q == httpx.QueryParams("a=456&b=789")
|
| 595 |
+
"""
|
| 596 |
+
q = QueryParams(params)
|
| 597 |
+
q._dict = {**self._dict, **q._dict}
|
| 598 |
+
return q
|
| 599 |
+
|
| 600 |
+
def __getitem__(self, key: typing.Any) -> str:
|
| 601 |
+
return self._dict[key][0]
|
| 602 |
+
|
| 603 |
+
def __contains__(self, key: typing.Any) -> bool:
|
| 604 |
+
return key in self._dict
|
| 605 |
+
|
| 606 |
+
def __iter__(self) -> typing.Iterator[typing.Any]:
|
| 607 |
+
return iter(self.keys())
|
| 608 |
+
|
| 609 |
+
def __len__(self) -> int:
|
| 610 |
+
return len(self._dict)
|
| 611 |
+
|
| 612 |
+
def __bool__(self) -> bool:
|
| 613 |
+
return bool(self._dict)
|
| 614 |
+
|
| 615 |
+
def __hash__(self) -> int:
|
| 616 |
+
return hash(str(self))
|
| 617 |
+
|
| 618 |
+
def __eq__(self, other: typing.Any) -> bool:
|
| 619 |
+
if not isinstance(other, self.__class__):
|
| 620 |
+
return False
|
| 621 |
+
return sorted(self.multi_items()) == sorted(other.multi_items())
|
| 622 |
+
|
| 623 |
+
def __str__(self) -> str:
|
| 624 |
+
return urlencode(self.multi_items())
|
| 625 |
+
|
| 626 |
+
def __repr__(self) -> str:
|
| 627 |
+
class_name = self.__class__.__name__
|
| 628 |
+
query_string = str(self)
|
| 629 |
+
return f"{class_name}({query_string!r})"
|
| 630 |
+
|
| 631 |
+
def update(self, params: QueryParamTypes | None = None) -> None:
|
| 632 |
+
raise RuntimeError(
|
| 633 |
+
"QueryParams are immutable since 0.18.0. "
|
| 634 |
+
"Use `q = q.merge(...)` to create an updated copy."
|
| 635 |
+
)
|
| 636 |
+
|
| 637 |
+
def __setitem__(self, key: str, value: str) -> None:
|
| 638 |
+
raise RuntimeError(
|
| 639 |
+
"QueryParams are immutable since 0.18.0. "
|
| 640 |
+
"Use `q = q.set(key, value)` to create an updated copy."
|
| 641 |
+
)
|
venv/lib/python3.12/site-packages/pip/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (685 Bytes). View file
|
|
|
venv/lib/python3.12/site-packages/pip/__pycache__/__main__.cpython-312.pyc
ADDED
|
Binary file (841 Bytes). View file
|
|
|
venv/lib/python3.12/site-packages/pip/__pycache__/__pip-runner__.cpython-312.pyc
ADDED
|
Binary file (2.2 kB). View file
|
|
|
venv/lib/python3.12/site-packages/pip/_internal/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional
|
| 2 |
+
|
| 3 |
+
from pip._internal.utils import _log
|
| 4 |
+
|
| 5 |
+
# init_logging() must be called before any call to logging.getLogger()
|
| 6 |
+
# which happens at import of most modules.
|
| 7 |
+
_log.init_logging()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def main(args: (Optional[List[str]]) = None) -> int:
|
| 11 |
+
"""This is preserved for old console scripts that may still be referencing
|
| 12 |
+
it.
|
| 13 |
+
|
| 14 |
+
For additional details, see https://github.com/pypa/pip/issues/7498.
|
| 15 |
+
"""
|
| 16 |
+
from pip._internal.utils.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| 6 |
+
import pathlib
|
| 7 |
+
import site
|
| 8 |
+
import sys
|
| 9 |
+
import textwrap
|
| 10 |
+
from collections import OrderedDict
|
| 11 |
+
from types import TracebackType
|
| 12 |
+
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type, Union
|
| 13 |
+
|
| 14 |
+
from pip._vendor.certifi import where
|
| 15 |
+
from pip._vendor.packaging.requirements import Requirement
|
| 16 |
+
from pip._vendor.packaging.version import Version
|
| 17 |
+
|
| 18 |
+
from pip import __file__ as pip_location
|
| 19 |
+
from pip._internal.cli.spinners import open_spinner
|
| 20 |
+
from pip._internal.locations import get_platlib, get_purelib, get_scheme
|
| 21 |
+
from pip._internal.metadata import get_default_environment, get_environment
|
| 22 |
+
from pip._internal.utils.subprocess import call_subprocess
|
| 23 |
+
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
| 24 |
+
|
| 25 |
+
if TYPE_CHECKING:
|
| 26 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 27 |
+
|
| 28 |
+
logger = logging.getLogger(__name__)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _dedup(a: str, b: str) -> Union[Tuple[str], Tuple[str, str]]:
|
| 32 |
+
return (a, b) if a != b else (a,)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class _Prefix:
|
| 36 |
+
def __init__(self, path: str) -> None:
|
| 37 |
+
self.path = path
|
| 38 |
+
self.setup = False
|
| 39 |
+
scheme = get_scheme("", prefix=path)
|
| 40 |
+
self.bin_dir = scheme.scripts
|
| 41 |
+
self.lib_dirs = _dedup(scheme.purelib, scheme.platlib)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def get_runnable_pip() -> str:
|
| 45 |
+
"""Get a file to pass to a Python executable, to run the currently-running pip.
|
| 46 |
+
|
| 47 |
+
This is used to run a pip subprocess, for installing requirements into the build
|
| 48 |
+
environment.
|
| 49 |
+
"""
|
| 50 |
+
source = pathlib.Path(pip_location).resolve().parent
|
| 51 |
+
|
| 52 |
+
if not source.is_dir():
|
| 53 |
+
# This would happen if someone is using pip from inside a zip file. In that
|
| 54 |
+
# case, we can use that directly.
|
| 55 |
+
return str(source)
|
| 56 |
+
|
| 57 |
+
return os.fsdecode(source / "__pip-runner__.py")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _get_system_sitepackages() -> Set[str]:
|
| 61 |
+
"""Get system site packages
|
| 62 |
+
|
| 63 |
+
Usually from site.getsitepackages,
|
| 64 |
+
but fallback on `get_purelib()/get_platlib()` if unavailable
|
| 65 |
+
(e.g. in a virtualenv created by virtualenv<20)
|
| 66 |
+
|
| 67 |
+
Returns normalized set of strings.
|
| 68 |
+
"""
|
| 69 |
+
if hasattr(site, "getsitepackages"):
|
| 70 |
+
system_sites = site.getsitepackages()
|
| 71 |
+
else:
|
| 72 |
+
# virtualenv < 20 overwrites site.py without getsitepackages
|
| 73 |
+
# fallback on get_purelib/get_platlib.
|
| 74 |
+
# this is known to miss things, but shouldn't in the cases
|
| 75 |
+
# where getsitepackages() has been removed (inside a virtualenv)
|
| 76 |
+
system_sites = [get_purelib(), get_platlib()]
|
| 77 |
+
return {os.path.normcase(path) for path in system_sites}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class BuildEnvironment:
|
| 81 |
+
"""Creates and manages an isolated environment to install build deps"""
|
| 82 |
+
|
| 83 |
+
def __init__(self) -> None:
|
| 84 |
+
temp_dir = TempDirectory(kind=tempdir_kinds.BUILD_ENV, globally_managed=True)
|
| 85 |
+
|
| 86 |
+
self._prefixes = OrderedDict(
|
| 87 |
+
(name, _Prefix(os.path.join(temp_dir.path, name)))
|
| 88 |
+
for name in ("normal", "overlay")
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
self._bin_dirs: List[str] = []
|
| 92 |
+
self._lib_dirs: List[str] = []
|
| 93 |
+
for prefix in reversed(list(self._prefixes.values())):
|
| 94 |
+
self._bin_dirs.append(prefix.bin_dir)
|
| 95 |
+
self._lib_dirs.extend(prefix.lib_dirs)
|
| 96 |
+
|
| 97 |
+
# Customize site to:
|
| 98 |
+
# - ensure .pth files are honored
|
| 99 |
+
# - prevent access to system site packages
|
| 100 |
+
system_sites = _get_system_sitepackages()
|
| 101 |
+
|
| 102 |
+
self._site_dir = os.path.join(temp_dir.path, "site")
|
| 103 |
+
if not os.path.exists(self._site_dir):
|
| 104 |
+
os.mkdir(self._site_dir)
|
| 105 |
+
with open(
|
| 106 |
+
os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
|
| 107 |
+
) as fp:
|
| 108 |
+
fp.write(
|
| 109 |
+
textwrap.dedent(
|
| 110 |
+
"""
|
| 111 |
+
import os, site, sys
|
| 112 |
+
|
| 113 |
+
# First, drop system-sites related paths.
|
| 114 |
+
original_sys_path = sys.path[:]
|
| 115 |
+
known_paths = set()
|
| 116 |
+
for path in {system_sites!r}:
|
| 117 |
+
site.addsitedir(path, known_paths=known_paths)
|
| 118 |
+
system_paths = set(
|
| 119 |
+
os.path.normcase(path)
|
| 120 |
+
for path in sys.path[len(original_sys_path):]
|
| 121 |
+
)
|
| 122 |
+
original_sys_path = [
|
| 123 |
+
path for path in original_sys_path
|
| 124 |
+
if os.path.normcase(path) not in system_paths
|
| 125 |
+
]
|
| 126 |
+
sys.path = original_sys_path
|
| 127 |
+
|
| 128 |
+
# Second, add lib directories.
|
| 129 |
+
# ensuring .pth file are processed.
|
| 130 |
+
for path in {lib_dirs!r}:
|
| 131 |
+
assert not path in sys.path
|
| 132 |
+
site.addsitedir(path)
|
| 133 |
+
"""
|
| 134 |
+
).format(system_sites=system_sites, lib_dirs=self._lib_dirs)
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
def __enter__(self) -> None:
|
| 138 |
+
self._save_env = {
|
| 139 |
+
name: os.environ.get(name, None)
|
| 140 |
+
for name in ("PATH", "PYTHONNOUSERSITE", "PYTHONPATH")
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
path = self._bin_dirs[:]
|
| 144 |
+
old_path = self._save_env["PATH"]
|
| 145 |
+
if old_path:
|
| 146 |
+
path.extend(old_path.split(os.pathsep))
|
| 147 |
+
|
| 148 |
+
pythonpath = [self._site_dir]
|
| 149 |
+
|
| 150 |
+
os.environ.update(
|
| 151 |
+
{
|
| 152 |
+
"PATH": os.pathsep.join(path),
|
| 153 |
+
"PYTHONNOUSERSITE": "1",
|
| 154 |
+
"PYTHONPATH": os.pathsep.join(pythonpath),
|
| 155 |
+
}
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
def __exit__(
|
| 159 |
+
self,
|
| 160 |
+
exc_type: Optional[Type[BaseException]],
|
| 161 |
+
exc_val: Optional[BaseException],
|
| 162 |
+
exc_tb: Optional[TracebackType],
|
| 163 |
+
) -> None:
|
| 164 |
+
for varname, old_value in self._save_env.items():
|
| 165 |
+
if old_value is None:
|
| 166 |
+
os.environ.pop(varname, None)
|
| 167 |
+
else:
|
| 168 |
+
os.environ[varname] = old_value
|
| 169 |
+
|
| 170 |
+
def check_requirements(
|
| 171 |
+
self, reqs: Iterable[str]
|
| 172 |
+
) -> Tuple[Set[Tuple[str, str]], Set[str]]:
|
| 173 |
+
"""Return 2 sets:
|
| 174 |
+
- conflicting requirements: set of (installed, wanted) reqs tuples
|
| 175 |
+
- missing requirements: set of reqs
|
| 176 |
+
"""
|
| 177 |
+
missing = set()
|
| 178 |
+
conflicting = set()
|
| 179 |
+
if reqs:
|
| 180 |
+
env = (
|
| 181 |
+
get_environment(self._lib_dirs)
|
| 182 |
+
if hasattr(self, "_lib_dirs")
|
| 183 |
+
else get_default_environment()
|
| 184 |
+
)
|
| 185 |
+
for req_str in reqs:
|
| 186 |
+
req = Requirement(req_str)
|
| 187 |
+
# We're explicitly evaluating with an empty extra value, since build
|
| 188 |
+
# environments are not provided any mechanism to select specific extras.
|
| 189 |
+
if req.marker is not None and not req.marker.evaluate({"extra": ""}):
|
| 190 |
+
continue
|
| 191 |
+
dist = env.get_distribution(req.name)
|
| 192 |
+
if not dist:
|
| 193 |
+
missing.add(req_str)
|
| 194 |
+
continue
|
| 195 |
+
if isinstance(dist.version, Version):
|
| 196 |
+
installed_req_str = f"{req.name}=={dist.version}"
|
| 197 |
+
else:
|
| 198 |
+
installed_req_str = f"{req.name}==={dist.version}"
|
| 199 |
+
if not req.specifier.contains(dist.version, prereleases=True):
|
| 200 |
+
conflicting.add((installed_req_str, req_str))
|
| 201 |
+
# FIXME: Consider direct URL?
|
| 202 |
+
return conflicting, missing
|
| 203 |
+
|
| 204 |
+
def install_requirements(
|
| 205 |
+
self,
|
| 206 |
+
finder: "PackageFinder",
|
| 207 |
+
requirements: Iterable[str],
|
| 208 |
+
prefix_as_string: str,
|
| 209 |
+
*,
|
| 210 |
+
kind: str,
|
| 211 |
+
) -> None:
|
| 212 |
+
prefix = self._prefixes[prefix_as_string]
|
| 213 |
+
assert not prefix.setup
|
| 214 |
+
prefix.setup = True
|
| 215 |
+
if not requirements:
|
| 216 |
+
return
|
| 217 |
+
self._install_requirements(
|
| 218 |
+
get_runnable_pip(),
|
| 219 |
+
finder,
|
| 220 |
+
requirements,
|
| 221 |
+
prefix,
|
| 222 |
+
kind=kind,
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
@staticmethod
|
| 226 |
+
def _install_requirements(
|
| 227 |
+
pip_runnable: str,
|
| 228 |
+
finder: "PackageFinder",
|
| 229 |
+
requirements: Iterable[str],
|
| 230 |
+
prefix: _Prefix,
|
| 231 |
+
*,
|
| 232 |
+
kind: str,
|
| 233 |
+
) -> None:
|
| 234 |
+
args: List[str] = [
|
| 235 |
+
sys.executable,
|
| 236 |
+
pip_runnable,
|
| 237 |
+
"install",
|
| 238 |
+
"--ignore-installed",
|
| 239 |
+
"--no-user",
|
| 240 |
+
"--prefix",
|
| 241 |
+
prefix.path,
|
| 242 |
+
"--no-warn-script-location",
|
| 243 |
+
]
|
| 244 |
+
if logger.getEffectiveLevel() <= logging.DEBUG:
|
| 245 |
+
args.append("-v")
|
| 246 |
+
for format_control in ("no_binary", "only_binary"):
|
| 247 |
+
formats = getattr(finder.format_control, format_control)
|
| 248 |
+
args.extend(
|
| 249 |
+
(
|
| 250 |
+
"--" + format_control.replace("_", "-"),
|
| 251 |
+
",".join(sorted(formats or {":none:"})),
|
| 252 |
+
)
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
index_urls = finder.index_urls
|
| 256 |
+
if index_urls:
|
| 257 |
+
args.extend(["-i", index_urls[0]])
|
| 258 |
+
for extra_index in index_urls[1:]:
|
| 259 |
+
args.extend(["--extra-index-url", extra_index])
|
| 260 |
+
else:
|
| 261 |
+
args.append("--no-index")
|
| 262 |
+
for link in finder.find_links:
|
| 263 |
+
args.extend(["--find-links", link])
|
| 264 |
+
|
| 265 |
+
for host in finder.trusted_hosts:
|
| 266 |
+
args.extend(["--trusted-host", host])
|
| 267 |
+
if finder.allow_all_prereleases:
|
| 268 |
+
args.append("--pre")
|
| 269 |
+
if finder.prefer_binary:
|
| 270 |
+
args.append("--prefer-binary")
|
| 271 |
+
args.append("--")
|
| 272 |
+
args.extend(requirements)
|
| 273 |
+
extra_environ = {"_PIP_STANDALONE_CERT": where()}
|
| 274 |
+
with open_spinner(f"Installing {kind}") as spinner:
|
| 275 |
+
call_subprocess(
|
| 276 |
+
args,
|
| 277 |
+
command_desc=f"pip subprocess to install {kind}",
|
| 278 |
+
spinner=spinner,
|
| 279 |
+
extra_environ=extra_environ,
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
class NoOpBuildEnvironment(BuildEnvironment):
|
| 284 |
+
"""A no-op drop-in replacement for BuildEnvironment"""
|
| 285 |
+
|
| 286 |
+
def __init__(self) -> None:
|
| 287 |
+
pass
|
| 288 |
+
|
| 289 |
+
def __enter__(self) -> None:
|
| 290 |
+
pass
|
| 291 |
+
|
| 292 |
+
def __exit__(
|
| 293 |
+
self,
|
| 294 |
+
exc_type: Optional[Type[BaseException]],
|
| 295 |
+
exc_val: Optional[BaseException],
|
| 296 |
+
exc_tb: Optional[TracebackType],
|
| 297 |
+
) -> None:
|
| 298 |
+
pass
|
| 299 |
+
|
| 300 |
+
def cleanup(self) -> None:
|
| 301 |
+
pass
|
| 302 |
+
|
| 303 |
+
def install_requirements(
|
| 304 |
+
self,
|
| 305 |
+
finder: "PackageFinder",
|
| 306 |
+
requirements: Iterable[str],
|
| 307 |
+
prefix_as_string: str,
|
| 308 |
+
*,
|
| 309 |
+
kind: str,
|
| 310 |
+
) -> None:
|
| 311 |
+
raise NotImplementedError()
|
venv/lib/python3.12/site-packages/pip/_internal/cache.py
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Cache Management
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any, Dict, List, Optional
|
| 10 |
+
|
| 11 |
+
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
| 12 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 13 |
+
|
| 14 |
+
from pip._internal.exceptions import InvalidWheelFilename
|
| 15 |
+
from pip._internal.models.direct_url import DirectUrl
|
| 16 |
+
from pip._internal.models.link import Link
|
| 17 |
+
from pip._internal.models.wheel import Wheel
|
| 18 |
+
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
| 19 |
+
from pip._internal.utils.urls import path_to_url
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
ORIGIN_JSON_NAME = "origin.json"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _hash_dict(d: Dict[str, str]) -> str:
|
| 27 |
+
"""Return a stable sha224 of a dictionary."""
|
| 28 |
+
s = json.dumps(d, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
|
| 29 |
+
return hashlib.sha224(s.encode("ascii")).hexdigest()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Cache:
|
| 33 |
+
"""An abstract class - provides cache directories for data from links
|
| 34 |
+
|
| 35 |
+
:param cache_dir: The root of the cache.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
def __init__(self, cache_dir: str) -> None:
|
| 39 |
+
super().__init__()
|
| 40 |
+
assert not cache_dir or os.path.isabs(cache_dir)
|
| 41 |
+
self.cache_dir = cache_dir or None
|
| 42 |
+
|
| 43 |
+
def _get_cache_path_parts(self, link: Link) -> List[str]:
|
| 44 |
+
"""Get parts of part that must be os.path.joined with cache_dir"""
|
| 45 |
+
|
| 46 |
+
# We want to generate an url to use as our cache key, we don't want to
|
| 47 |
+
# just re-use the URL because it might have other items in the fragment
|
| 48 |
+
# and we don't care about those.
|
| 49 |
+
key_parts = {"url": link.url_without_fragment}
|
| 50 |
+
if link.hash_name is not None and link.hash is not None:
|
| 51 |
+
key_parts[link.hash_name] = link.hash
|
| 52 |
+
if link.subdirectory_fragment:
|
| 53 |
+
key_parts["subdirectory"] = link.subdirectory_fragment
|
| 54 |
+
|
| 55 |
+
# Include interpreter name, major and minor version in cache key
|
| 56 |
+
# to cope with ill-behaved sdists that build a different wheel
|
| 57 |
+
# depending on the python version their setup.py is being run on,
|
| 58 |
+
# and don't encode the difference in compatibility tags.
|
| 59 |
+
# https://github.com/pypa/pip/issues/7296
|
| 60 |
+
key_parts["interpreter_name"] = interpreter_name()
|
| 61 |
+
key_parts["interpreter_version"] = interpreter_version()
|
| 62 |
+
|
| 63 |
+
# Encode our key url with sha224, we'll use this because it has similar
|
| 64 |
+
# security properties to sha256, but with a shorter total output (and
|
| 65 |
+
# thus less secure). However the differences don't make a lot of
|
| 66 |
+
# difference for our use case here.
|
| 67 |
+
hashed = _hash_dict(key_parts)
|
| 68 |
+
|
| 69 |
+
# We want to nest the directories some to prevent having a ton of top
|
| 70 |
+
# level directories where we might run out of sub directories on some
|
| 71 |
+
# FS.
|
| 72 |
+
parts = [hashed[:2], hashed[2:4], hashed[4:6], hashed[6:]]
|
| 73 |
+
|
| 74 |
+
return parts
|
| 75 |
+
|
| 76 |
+
def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
|
| 77 |
+
can_not_cache = not self.cache_dir or not canonical_package_name or not link
|
| 78 |
+
if can_not_cache:
|
| 79 |
+
return []
|
| 80 |
+
|
| 81 |
+
path = self.get_path_for_link(link)
|
| 82 |
+
if os.path.isdir(path):
|
| 83 |
+
return [(candidate, path) for candidate in os.listdir(path)]
|
| 84 |
+
return []
|
| 85 |
+
|
| 86 |
+
def get_path_for_link(self, link: Link) -> str:
|
| 87 |
+
"""Return a directory to store cached items in for link."""
|
| 88 |
+
raise NotImplementedError()
|
| 89 |
+
|
| 90 |
+
def get(
|
| 91 |
+
self,
|
| 92 |
+
link: Link,
|
| 93 |
+
package_name: Optional[str],
|
| 94 |
+
supported_tags: List[Tag],
|
| 95 |
+
) -> Link:
|
| 96 |
+
"""Returns a link to a cached item if it exists, otherwise returns the
|
| 97 |
+
passed link.
|
| 98 |
+
"""
|
| 99 |
+
raise NotImplementedError()
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class SimpleWheelCache(Cache):
|
| 103 |
+
"""A cache of wheels for future installs."""
|
| 104 |
+
|
| 105 |
+
def __init__(self, cache_dir: str) -> None:
|
| 106 |
+
super().__init__(cache_dir)
|
| 107 |
+
|
| 108 |
+
def get_path_for_link(self, link: Link) -> str:
|
| 109 |
+
"""Return a directory to store cached wheels for link
|
| 110 |
+
|
| 111 |
+
Because there are M wheels for any one sdist, we provide a directory
|
| 112 |
+
to cache them in, and then consult that directory when looking up
|
| 113 |
+
cache hits.
|
| 114 |
+
|
| 115 |
+
We only insert things into the cache if they have plausible version
|
| 116 |
+
numbers, so that we don't contaminate the cache with things that were
|
| 117 |
+
not unique. E.g. ./package might have dozens of installs done for it
|
| 118 |
+
and build a version of 0.0...and if we built and cached a wheel, we'd
|
| 119 |
+
end up using the same wheel even if the source has been edited.
|
| 120 |
+
|
| 121 |
+
:param link: The link of the sdist for which this will cache wheels.
|
| 122 |
+
"""
|
| 123 |
+
parts = self._get_cache_path_parts(link)
|
| 124 |
+
assert self.cache_dir
|
| 125 |
+
# Store wheels within the root cache_dir
|
| 126 |
+
return os.path.join(self.cache_dir, "wheels", *parts)
|
| 127 |
+
|
| 128 |
+
def get(
|
| 129 |
+
self,
|
| 130 |
+
link: Link,
|
| 131 |
+
package_name: Optional[str],
|
| 132 |
+
supported_tags: List[Tag],
|
| 133 |
+
) -> Link:
|
| 134 |
+
candidates = []
|
| 135 |
+
|
| 136 |
+
if not package_name:
|
| 137 |
+
return link
|
| 138 |
+
|
| 139 |
+
canonical_package_name = canonicalize_name(package_name)
|
| 140 |
+
for wheel_name, wheel_dir in self._get_candidates(link, canonical_package_name):
|
| 141 |
+
try:
|
| 142 |
+
wheel = Wheel(wheel_name)
|
| 143 |
+
except InvalidWheelFilename:
|
| 144 |
+
continue
|
| 145 |
+
if canonicalize_name(wheel.name) != canonical_package_name:
|
| 146 |
+
logger.debug(
|
| 147 |
+
"Ignoring cached wheel %s for %s as it "
|
| 148 |
+
"does not match the expected distribution name %s.",
|
| 149 |
+
wheel_name,
|
| 150 |
+
link,
|
| 151 |
+
package_name,
|
| 152 |
+
)
|
| 153 |
+
continue
|
| 154 |
+
if not wheel.supported(supported_tags):
|
| 155 |
+
# Built for a different python/arch/etc
|
| 156 |
+
continue
|
| 157 |
+
candidates.append(
|
| 158 |
+
(
|
| 159 |
+
wheel.support_index_min(supported_tags),
|
| 160 |
+
wheel_name,
|
| 161 |
+
wheel_dir,
|
| 162 |
+
)
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
if not candidates:
|
| 166 |
+
return link
|
| 167 |
+
|
| 168 |
+
_, wheel_name, wheel_dir = min(candidates)
|
| 169 |
+
return Link(path_to_url(os.path.join(wheel_dir, wheel_name)))
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class EphemWheelCache(SimpleWheelCache):
|
| 173 |
+
"""A SimpleWheelCache that creates it's own temporary cache directory"""
|
| 174 |
+
|
| 175 |
+
def __init__(self) -> None:
|
| 176 |
+
self._temp_dir = TempDirectory(
|
| 177 |
+
kind=tempdir_kinds.EPHEM_WHEEL_CACHE,
|
| 178 |
+
globally_managed=True,
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
super().__init__(self._temp_dir.path)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
class CacheEntry:
|
| 185 |
+
def __init__(
|
| 186 |
+
self,
|
| 187 |
+
link: Link,
|
| 188 |
+
persistent: bool,
|
| 189 |
+
):
|
| 190 |
+
self.link = link
|
| 191 |
+
self.persistent = persistent
|
| 192 |
+
self.origin: Optional[DirectUrl] = None
|
| 193 |
+
origin_direct_url_path = Path(self.link.file_path).parent / ORIGIN_JSON_NAME
|
| 194 |
+
if origin_direct_url_path.exists():
|
| 195 |
+
try:
|
| 196 |
+
self.origin = DirectUrl.from_json(
|
| 197 |
+
origin_direct_url_path.read_text(encoding="utf-8")
|
| 198 |
+
)
|
| 199 |
+
except Exception as e:
|
| 200 |
+
logger.warning(
|
| 201 |
+
"Ignoring invalid cache entry origin file %s for %s (%s)",
|
| 202 |
+
origin_direct_url_path,
|
| 203 |
+
link.filename,
|
| 204 |
+
e,
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
class WheelCache(Cache):
|
| 209 |
+
"""Wraps EphemWheelCache and SimpleWheelCache into a single Cache
|
| 210 |
+
|
| 211 |
+
This Cache allows for gracefully degradation, using the ephem wheel cache
|
| 212 |
+
when a certain link is not found in the simple wheel cache first.
|
| 213 |
+
"""
|
| 214 |
+
|
| 215 |
+
def __init__(self, cache_dir: str) -> None:
|
| 216 |
+
super().__init__(cache_dir)
|
| 217 |
+
self._wheel_cache = SimpleWheelCache(cache_dir)
|
| 218 |
+
self._ephem_cache = EphemWheelCache()
|
| 219 |
+
|
| 220 |
+
def get_path_for_link(self, link: Link) -> str:
|
| 221 |
+
return self._wheel_cache.get_path_for_link(link)
|
| 222 |
+
|
| 223 |
+
def get_ephem_path_for_link(self, link: Link) -> str:
|
| 224 |
+
return self._ephem_cache.get_path_for_link(link)
|
| 225 |
+
|
| 226 |
+
def get(
|
| 227 |
+
self,
|
| 228 |
+
link: Link,
|
| 229 |
+
package_name: Optional[str],
|
| 230 |
+
supported_tags: List[Tag],
|
| 231 |
+
) -> Link:
|
| 232 |
+
cache_entry = self.get_cache_entry(link, package_name, supported_tags)
|
| 233 |
+
if cache_entry is None:
|
| 234 |
+
return link
|
| 235 |
+
return cache_entry.link
|
| 236 |
+
|
| 237 |
+
def get_cache_entry(
|
| 238 |
+
self,
|
| 239 |
+
link: Link,
|
| 240 |
+
package_name: Optional[str],
|
| 241 |
+
supported_tags: List[Tag],
|
| 242 |
+
) -> Optional[CacheEntry]:
|
| 243 |
+
"""Returns a CacheEntry with a link to a cached item if it exists or
|
| 244 |
+
None. The cache entry indicates if the item was found in the persistent
|
| 245 |
+
or ephemeral cache.
|
| 246 |
+
"""
|
| 247 |
+
retval = self._wheel_cache.get(
|
| 248 |
+
link=link,
|
| 249 |
+
package_name=package_name,
|
| 250 |
+
supported_tags=supported_tags,
|
| 251 |
+
)
|
| 252 |
+
if retval is not link:
|
| 253 |
+
return CacheEntry(retval, persistent=True)
|
| 254 |
+
|
| 255 |
+
retval = self._ephem_cache.get(
|
| 256 |
+
link=link,
|
| 257 |
+
package_name=package_name,
|
| 258 |
+
supported_tags=supported_tags,
|
| 259 |
+
)
|
| 260 |
+
if retval is not link:
|
| 261 |
+
return CacheEntry(retval, persistent=False)
|
| 262 |
+
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
@staticmethod
|
| 266 |
+
def record_download_origin(cache_dir: str, download_info: DirectUrl) -> None:
|
| 267 |
+
origin_path = Path(cache_dir) / ORIGIN_JSON_NAME
|
| 268 |
+
if origin_path.exists():
|
| 269 |
+
try:
|
| 270 |
+
origin = DirectUrl.from_json(origin_path.read_text(encoding="utf-8"))
|
| 271 |
+
except Exception as e:
|
| 272 |
+
logger.warning(
|
| 273 |
+
"Could not read origin file %s in cache entry (%s). "
|
| 274 |
+
"Will attempt to overwrite it.",
|
| 275 |
+
origin_path,
|
| 276 |
+
e,
|
| 277 |
+
)
|
| 278 |
+
else:
|
| 279 |
+
# TODO: use DirectUrl.equivalent when
|
| 280 |
+
# https://github.com/pypa/pip/pull/10564 is merged.
|
| 281 |
+
if origin.url != download_info.url:
|
| 282 |
+
logger.warning(
|
| 283 |
+
"Origin URL %s in cache entry %s does not match download URL "
|
| 284 |
+
"%s. This is likely a pip bug or a cache corruption issue. "
|
| 285 |
+
"Will overwrite it with the new value.",
|
| 286 |
+
origin.url,
|
| 287 |
+
cache_dir,
|
| 288 |
+
download_info.url,
|
| 289 |
+
)
|
| 290 |
+
origin_path.write_text(download_info.to_json(), encoding="utf-8")
|
venv/lib/python3.12/site-packages/pip/_internal/configuration.py
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration management setup
|
| 2 |
+
|
| 3 |
+
Some terminology:
|
| 4 |
+
- name
|
| 5 |
+
As written in config files.
|
| 6 |
+
- value
|
| 7 |
+
Value associated with a name
|
| 8 |
+
- key
|
| 9 |
+
Name combined with it's section (section.name)
|
| 10 |
+
- variant
|
| 11 |
+
A single word describing where the configuration key-value pair came from
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import configparser
|
| 15 |
+
import locale
|
| 16 |
+
import os
|
| 17 |
+
import sys
|
| 18 |
+
from typing import Any, Dict, Iterable, List, NewType, Optional, Tuple
|
| 19 |
+
|
| 20 |
+
from pip._internal.exceptions import (
|
| 21 |
+
ConfigurationError,
|
| 22 |
+
ConfigurationFileCouldNotBeLoaded,
|
| 23 |
+
)
|
| 24 |
+
from pip._internal.utils import appdirs
|
| 25 |
+
from pip._internal.utils.compat import WINDOWS
|
| 26 |
+
from pip._internal.utils.logging import getLogger
|
| 27 |
+
from pip._internal.utils.misc import ensure_dir, enum
|
| 28 |
+
|
| 29 |
+
RawConfigParser = configparser.RawConfigParser # Shorthand
|
| 30 |
+
Kind = NewType("Kind", str)
|
| 31 |
+
|
| 32 |
+
CONFIG_BASENAME = "pip.ini" if WINDOWS else "pip.conf"
|
| 33 |
+
ENV_NAMES_IGNORED = "version", "help"
|
| 34 |
+
|
| 35 |
+
# The kinds of configurations there are.
|
| 36 |
+
kinds = enum(
|
| 37 |
+
USER="user", # User Specific
|
| 38 |
+
GLOBAL="global", # System Wide
|
| 39 |
+
SITE="site", # [Virtual] Environment Specific
|
| 40 |
+
ENV="env", # from PIP_CONFIG_FILE
|
| 41 |
+
ENV_VAR="env-var", # from Environment Variables
|
| 42 |
+
)
|
| 43 |
+
OVERRIDE_ORDER = kinds.GLOBAL, kinds.USER, kinds.SITE, kinds.ENV, kinds.ENV_VAR
|
| 44 |
+
VALID_LOAD_ONLY = kinds.USER, kinds.GLOBAL, kinds.SITE
|
| 45 |
+
|
| 46 |
+
logger = getLogger(__name__)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# NOTE: Maybe use the optionx attribute to normalize keynames.
|
| 50 |
+
def _normalize_name(name: str) -> str:
|
| 51 |
+
"""Make a name consistent regardless of source (environment or file)"""
|
| 52 |
+
name = name.lower().replace("_", "-")
|
| 53 |
+
if name.startswith("--"):
|
| 54 |
+
name = name[2:] # only prefer long opts
|
| 55 |
+
return name
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _disassemble_key(name: str) -> List[str]:
|
| 59 |
+
if "." not in name:
|
| 60 |
+
error_message = (
|
| 61 |
+
"Key does not contain dot separated section and key. "
|
| 62 |
+
f"Perhaps you wanted to use 'global.{name}' instead?"
|
| 63 |
+
)
|
| 64 |
+
raise ConfigurationError(error_message)
|
| 65 |
+
return name.split(".", 1)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def get_configuration_files() -> Dict[Kind, List[str]]:
|
| 69 |
+
global_config_files = [
|
| 70 |
+
os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip")
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
|
| 74 |
+
legacy_config_file = os.path.join(
|
| 75 |
+
os.path.expanduser("~"),
|
| 76 |
+
"pip" if WINDOWS else ".pip",
|
| 77 |
+
CONFIG_BASENAME,
|
| 78 |
+
)
|
| 79 |
+
new_config_file = os.path.join(appdirs.user_config_dir("pip"), CONFIG_BASENAME)
|
| 80 |
+
return {
|
| 81 |
+
kinds.GLOBAL: global_config_files,
|
| 82 |
+
kinds.SITE: [site_config_file],
|
| 83 |
+
kinds.USER: [legacy_config_file, new_config_file],
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class Configuration:
|
| 88 |
+
"""Handles management of configuration.
|
| 89 |
+
|
| 90 |
+
Provides an interface to accessing and managing configuration files.
|
| 91 |
+
|
| 92 |
+
This class converts provides an API that takes "section.key-name" style
|
| 93 |
+
keys and stores the value associated with it as "key-name" under the
|
| 94 |
+
section "section".
|
| 95 |
+
|
| 96 |
+
This allows for a clean interface wherein the both the section and the
|
| 97 |
+
key-name are preserved in an easy to manage form in the configuration files
|
| 98 |
+
and the data stored is also nice.
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
def __init__(self, isolated: bool, load_only: Optional[Kind] = None) -> None:
|
| 102 |
+
super().__init__()
|
| 103 |
+
|
| 104 |
+
if load_only is not None and load_only not in VALID_LOAD_ONLY:
|
| 105 |
+
raise ConfigurationError(
|
| 106 |
+
"Got invalid value for load_only - should be one of {}".format(
|
| 107 |
+
", ".join(map(repr, VALID_LOAD_ONLY))
|
| 108 |
+
)
|
| 109 |
+
)
|
| 110 |
+
self.isolated = isolated
|
| 111 |
+
self.load_only = load_only
|
| 112 |
+
|
| 113 |
+
# Because we keep track of where we got the data from
|
| 114 |
+
self._parsers: Dict[Kind, List[Tuple[str, RawConfigParser]]] = {
|
| 115 |
+
variant: [] for variant in OVERRIDE_ORDER
|
| 116 |
+
}
|
| 117 |
+
self._config: Dict[Kind, Dict[str, Any]] = {
|
| 118 |
+
variant: {} for variant in OVERRIDE_ORDER
|
| 119 |
+
}
|
| 120 |
+
self._modified_parsers: List[Tuple[str, RawConfigParser]] = []
|
| 121 |
+
|
| 122 |
+
def load(self) -> None:
|
| 123 |
+
"""Loads configuration from configuration files and environment"""
|
| 124 |
+
self._load_config_files()
|
| 125 |
+
if not self.isolated:
|
| 126 |
+
self._load_environment_vars()
|
| 127 |
+
|
| 128 |
+
def get_file_to_edit(self) -> Optional[str]:
|
| 129 |
+
"""Returns the file with highest priority in configuration"""
|
| 130 |
+
assert self.load_only is not None, "Need to be specified a file to be editing"
|
| 131 |
+
|
| 132 |
+
try:
|
| 133 |
+
return self._get_parser_to_modify()[0]
|
| 134 |
+
except IndexError:
|
| 135 |
+
return None
|
| 136 |
+
|
| 137 |
+
def items(self) -> Iterable[Tuple[str, Any]]:
|
| 138 |
+
"""Returns key-value pairs like dict.items() representing the loaded
|
| 139 |
+
configuration
|
| 140 |
+
"""
|
| 141 |
+
return self._dictionary.items()
|
| 142 |
+
|
| 143 |
+
def get_value(self, key: str) -> Any:
|
| 144 |
+
"""Get a value from the configuration."""
|
| 145 |
+
orig_key = key
|
| 146 |
+
key = _normalize_name(key)
|
| 147 |
+
try:
|
| 148 |
+
return self._dictionary[key]
|
| 149 |
+
except KeyError:
|
| 150 |
+
# disassembling triggers a more useful error message than simply
|
| 151 |
+
# "No such key" in the case that the key isn't in the form command.option
|
| 152 |
+
_disassemble_key(key)
|
| 153 |
+
raise ConfigurationError(f"No such key - {orig_key}")
|
| 154 |
+
|
| 155 |
+
def set_value(self, key: str, value: Any) -> None:
|
| 156 |
+
"""Modify a value in the configuration."""
|
| 157 |
+
key = _normalize_name(key)
|
| 158 |
+
self._ensure_have_load_only()
|
| 159 |
+
|
| 160 |
+
assert self.load_only
|
| 161 |
+
fname, parser = self._get_parser_to_modify()
|
| 162 |
+
|
| 163 |
+
if parser is not None:
|
| 164 |
+
section, name = _disassemble_key(key)
|
| 165 |
+
|
| 166 |
+
# Modify the parser and the configuration
|
| 167 |
+
if not parser.has_section(section):
|
| 168 |
+
parser.add_section(section)
|
| 169 |
+
parser.set(section, name, value)
|
| 170 |
+
|
| 171 |
+
self._config[self.load_only][key] = value
|
| 172 |
+
self._mark_as_modified(fname, parser)
|
| 173 |
+
|
| 174 |
+
def unset_value(self, key: str) -> None:
|
| 175 |
+
"""Unset a value in the configuration."""
|
| 176 |
+
orig_key = key
|
| 177 |
+
key = _normalize_name(key)
|
| 178 |
+
self._ensure_have_load_only()
|
| 179 |
+
|
| 180 |
+
assert self.load_only
|
| 181 |
+
if key not in self._config[self.load_only]:
|
| 182 |
+
raise ConfigurationError(f"No such key - {orig_key}")
|
| 183 |
+
|
| 184 |
+
fname, parser = self._get_parser_to_modify()
|
| 185 |
+
|
| 186 |
+
if parser is not None:
|
| 187 |
+
section, name = _disassemble_key(key)
|
| 188 |
+
if not (
|
| 189 |
+
parser.has_section(section) and parser.remove_option(section, name)
|
| 190 |
+
):
|
| 191 |
+
# The option was not removed.
|
| 192 |
+
raise ConfigurationError(
|
| 193 |
+
"Fatal Internal error [id=1]. Please report as a bug."
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
# The section may be empty after the option was removed.
|
| 197 |
+
if not parser.items(section):
|
| 198 |
+
parser.remove_section(section)
|
| 199 |
+
self._mark_as_modified(fname, parser)
|
| 200 |
+
|
| 201 |
+
del self._config[self.load_only][key]
|
| 202 |
+
|
| 203 |
+
def save(self) -> None:
|
| 204 |
+
"""Save the current in-memory state."""
|
| 205 |
+
self._ensure_have_load_only()
|
| 206 |
+
|
| 207 |
+
for fname, parser in self._modified_parsers:
|
| 208 |
+
logger.info("Writing to %s", fname)
|
| 209 |
+
|
| 210 |
+
# Ensure directory exists.
|
| 211 |
+
ensure_dir(os.path.dirname(fname))
|
| 212 |
+
|
| 213 |
+
# Ensure directory's permission(need to be writeable)
|
| 214 |
+
try:
|
| 215 |
+
with open(fname, "w") as f:
|
| 216 |
+
parser.write(f)
|
| 217 |
+
except OSError as error:
|
| 218 |
+
raise ConfigurationError(
|
| 219 |
+
f"An error occurred while writing to the configuration file "
|
| 220 |
+
f"{fname}: {error}"
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
#
|
| 224 |
+
# Private routines
|
| 225 |
+
#
|
| 226 |
+
|
| 227 |
+
def _ensure_have_load_only(self) -> None:
|
| 228 |
+
if self.load_only is None:
|
| 229 |
+
raise ConfigurationError("Needed a specific file to be modifying.")
|
| 230 |
+
logger.debug("Will be working with %s variant only", self.load_only)
|
| 231 |
+
|
| 232 |
+
@property
|
| 233 |
+
def _dictionary(self) -> Dict[str, Any]:
|
| 234 |
+
"""A dictionary representing the loaded configuration."""
|
| 235 |
+
# NOTE: Dictionaries are not populated if not loaded. So, conditionals
|
| 236 |
+
# are not needed here.
|
| 237 |
+
retval = {}
|
| 238 |
+
|
| 239 |
+
for variant in OVERRIDE_ORDER:
|
| 240 |
+
retval.update(self._config[variant])
|
| 241 |
+
|
| 242 |
+
return retval
|
| 243 |
+
|
| 244 |
+
def _load_config_files(self) -> None:
|
| 245 |
+
"""Loads configuration from configuration files"""
|
| 246 |
+
config_files = dict(self.iter_config_files())
|
| 247 |
+
if config_files[kinds.ENV][0:1] == [os.devnull]:
|
| 248 |
+
logger.debug(
|
| 249 |
+
"Skipping loading configuration files due to "
|
| 250 |
+
"environment's PIP_CONFIG_FILE being os.devnull"
|
| 251 |
+
)
|
| 252 |
+
return
|
| 253 |
+
|
| 254 |
+
for variant, files in config_files.items():
|
| 255 |
+
for fname in files:
|
| 256 |
+
# If there's specific variant set in `load_only`, load only
|
| 257 |
+
# that variant, not the others.
|
| 258 |
+
if self.load_only is not None and variant != self.load_only:
|
| 259 |
+
logger.debug("Skipping file '%s' (variant: %s)", fname, variant)
|
| 260 |
+
continue
|
| 261 |
+
|
| 262 |
+
parser = self._load_file(variant, fname)
|
| 263 |
+
|
| 264 |
+
# Keeping track of the parsers used
|
| 265 |
+
self._parsers[variant].append((fname, parser))
|
| 266 |
+
|
| 267 |
+
def _load_file(self, variant: Kind, fname: str) -> RawConfigParser:
|
| 268 |
+
logger.verbose("For variant '%s', will try loading '%s'", variant, fname)
|
| 269 |
+
parser = self._construct_parser(fname)
|
| 270 |
+
|
| 271 |
+
for section in parser.sections():
|
| 272 |
+
items = parser.items(section)
|
| 273 |
+
self._config[variant].update(self._normalized_keys(section, items))
|
| 274 |
+
|
| 275 |
+
return parser
|
| 276 |
+
|
| 277 |
+
def _construct_parser(self, fname: str) -> RawConfigParser:
|
| 278 |
+
parser = configparser.RawConfigParser()
|
| 279 |
+
# If there is no such file, don't bother reading it but create the
|
| 280 |
+
# parser anyway, to hold the data.
|
| 281 |
+
# Doing this is useful when modifying and saving files, where we don't
|
| 282 |
+
# need to construct a parser.
|
| 283 |
+
if os.path.exists(fname):
|
| 284 |
+
locale_encoding = locale.getpreferredencoding(False)
|
| 285 |
+
try:
|
| 286 |
+
parser.read(fname, encoding=locale_encoding)
|
| 287 |
+
except UnicodeDecodeError:
|
| 288 |
+
# See https://github.com/pypa/pip/issues/4963
|
| 289 |
+
raise ConfigurationFileCouldNotBeLoaded(
|
| 290 |
+
reason=f"contains invalid {locale_encoding} characters",
|
| 291 |
+
fname=fname,
|
| 292 |
+
)
|
| 293 |
+
except configparser.Error as error:
|
| 294 |
+
# See https://github.com/pypa/pip/issues/4893
|
| 295 |
+
raise ConfigurationFileCouldNotBeLoaded(error=error)
|
| 296 |
+
return parser
|
| 297 |
+
|
| 298 |
+
def _load_environment_vars(self) -> None:
|
| 299 |
+
"""Loads configuration from environment variables"""
|
| 300 |
+
self._config[kinds.ENV_VAR].update(
|
| 301 |
+
self._normalized_keys(":env:", self.get_environ_vars())
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
def _normalized_keys(
|
| 305 |
+
self, section: str, items: Iterable[Tuple[str, Any]]
|
| 306 |
+
) -> Dict[str, Any]:
|
| 307 |
+
"""Normalizes items to construct a dictionary with normalized keys.
|
| 308 |
+
|
| 309 |
+
This routine is where the names become keys and are made the same
|
| 310 |
+
regardless of source - configuration files or environment.
|
| 311 |
+
"""
|
| 312 |
+
normalized = {}
|
| 313 |
+
for name, val in items:
|
| 314 |
+
key = section + "." + _normalize_name(name)
|
| 315 |
+
normalized[key] = val
|
| 316 |
+
return normalized
|
| 317 |
+
|
| 318 |
+
def get_environ_vars(self) -> Iterable[Tuple[str, str]]:
|
| 319 |
+
"""Returns a generator with all environmental vars with prefix PIP_"""
|
| 320 |
+
for key, val in os.environ.items():
|
| 321 |
+
if key.startswith("PIP_"):
|
| 322 |
+
name = key[4:].lower()
|
| 323 |
+
if name not in ENV_NAMES_IGNORED:
|
| 324 |
+
yield name, val
|
| 325 |
+
|
| 326 |
+
# XXX: This is patched in the tests.
|
| 327 |
+
def iter_config_files(self) -> Iterable[Tuple[Kind, List[str]]]:
|
| 328 |
+
"""Yields variant and configuration files associated with it.
|
| 329 |
+
|
| 330 |
+
This should be treated like items of a dictionary. The order
|
| 331 |
+
here doesn't affect what gets overridden. That is controlled
|
| 332 |
+
by OVERRIDE_ORDER. However this does control the order they are
|
| 333 |
+
displayed to the user. It's probably most ergononmic to display
|
| 334 |
+
things in the same order as OVERRIDE_ORDER
|
| 335 |
+
"""
|
| 336 |
+
# SMELL: Move the conditions out of this function
|
| 337 |
+
|
| 338 |
+
env_config_file = os.environ.get("PIP_CONFIG_FILE", None)
|
| 339 |
+
config_files = get_configuration_files()
|
| 340 |
+
|
| 341 |
+
yield kinds.GLOBAL, config_files[kinds.GLOBAL]
|
| 342 |
+
|
| 343 |
+
# per-user config is not loaded when env_config_file exists
|
| 344 |
+
should_load_user_config = not self.isolated and not (
|
| 345 |
+
env_config_file and os.path.exists(env_config_file)
|
| 346 |
+
)
|
| 347 |
+
if should_load_user_config:
|
| 348 |
+
# The legacy config file is overridden by the new config file
|
| 349 |
+
yield kinds.USER, config_files[kinds.USER]
|
| 350 |
+
|
| 351 |
+
# virtualenv config
|
| 352 |
+
yield kinds.SITE, config_files[kinds.SITE]
|
| 353 |
+
|
| 354 |
+
if env_config_file is not None:
|
| 355 |
+
yield kinds.ENV, [env_config_file]
|
| 356 |
+
else:
|
| 357 |
+
yield kinds.ENV, []
|
| 358 |
+
|
| 359 |
+
def get_values_in_config(self, variant: Kind) -> Dict[str, Any]:
|
| 360 |
+
"""Get values present in a config file"""
|
| 361 |
+
return self._config[variant]
|
| 362 |
+
|
| 363 |
+
def _get_parser_to_modify(self) -> Tuple[str, RawConfigParser]:
|
| 364 |
+
# Determine which parser to modify
|
| 365 |
+
assert self.load_only
|
| 366 |
+
parsers = self._parsers[self.load_only]
|
| 367 |
+
if not parsers:
|
| 368 |
+
# This should not happen if everything works correctly.
|
| 369 |
+
raise ConfigurationError(
|
| 370 |
+
"Fatal Internal error [id=2]. Please report as a bug."
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
# Use the highest priority parser.
|
| 374 |
+
return parsers[-1]
|
| 375 |
+
|
| 376 |
+
# XXX: This is patched in the tests.
|
| 377 |
+
def _mark_as_modified(self, fname: str, parser: RawConfigParser) -> None:
|
| 378 |
+
file_parser_tuple = (fname, parser)
|
| 379 |
+
if file_parser_tuple not in self._modified_parsers:
|
| 380 |
+
self._modified_parsers.append(file_parser_tuple)
|
| 381 |
+
|
| 382 |
+
def __repr__(self) -> str:
|
| 383 |
+
return f"{self.__class__.__name__}({self._dictionary!r})"
|
venv/lib/python3.12/site-packages/pip/_internal/exceptions.py
ADDED
|
@@ -0,0 +1,728 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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Exceptions used throughout package.
|
| 2 |
+
|
| 3 |
+
This module MUST NOT try to import from anything within `pip._internal` to
|
| 4 |
+
operate. This is expected to be importable from any/all files within the
|
| 5 |
+
subpackage and, thus, should not depend on them.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import configparser
|
| 9 |
+
import contextlib
|
| 10 |
+
import locale
|
| 11 |
+
import logging
|
| 12 |
+
import pathlib
|
| 13 |
+
import re
|
| 14 |
+
import sys
|
| 15 |
+
from itertools import chain, groupby, repeat
|
| 16 |
+
from typing import TYPE_CHECKING, Dict, Iterator, List, Optional, Union
|
| 17 |
+
|
| 18 |
+
from pip._vendor.requests.models import Request, Response
|
| 19 |
+
from pip._vendor.rich.console import Console, ConsoleOptions, RenderResult
|
| 20 |
+
from pip._vendor.rich.markup import escape
|
| 21 |
+
from pip._vendor.rich.text import Text
|
| 22 |
+
|
| 23 |
+
if TYPE_CHECKING:
|
| 24 |
+
from hashlib import _Hash
|
| 25 |
+
from typing import Literal
|
| 26 |
+
|
| 27 |
+
from pip._internal.metadata import BaseDistribution
|
| 28 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
#
|
| 34 |
+
# Scaffolding
|
| 35 |
+
#
|
| 36 |
+
def _is_kebab_case(s: str) -> bool:
|
| 37 |
+
return re.match(r"^[a-z]+(-[a-z]+)*$", s) is not None
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _prefix_with_indent(
|
| 41 |
+
s: Union[Text, str],
|
| 42 |
+
console: Console,
|
| 43 |
+
*,
|
| 44 |
+
prefix: str,
|
| 45 |
+
indent: str,
|
| 46 |
+
) -> Text:
|
| 47 |
+
if isinstance(s, Text):
|
| 48 |
+
text = s
|
| 49 |
+
else:
|
| 50 |
+
text = console.render_str(s)
|
| 51 |
+
|
| 52 |
+
return console.render_str(prefix, overflow="ignore") + console.render_str(
|
| 53 |
+
f"\n{indent}", overflow="ignore"
|
| 54 |
+
).join(text.split(allow_blank=True))
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class PipError(Exception):
|
| 58 |
+
"""The base pip error."""
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class DiagnosticPipError(PipError):
|
| 62 |
+
"""An error, that presents diagnostic information to the user.
|
| 63 |
+
|
| 64 |
+
This contains a bunch of logic, to enable pretty presentation of our error
|
| 65 |
+
messages. Each error gets a unique reference. Each error can also include
|
| 66 |
+
additional context, a hint and/or a note -- which are presented with the
|
| 67 |
+
main error message in a consistent style.
|
| 68 |
+
|
| 69 |
+
This is adapted from the error output styling in `sphinx-theme-builder`.
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
reference: str
|
| 73 |
+
|
| 74 |
+
def __init__(
|
| 75 |
+
self,
|
| 76 |
+
*,
|
| 77 |
+
kind: 'Literal["error", "warning"]' = "error",
|
| 78 |
+
reference: Optional[str] = None,
|
| 79 |
+
message: Union[str, Text],
|
| 80 |
+
context: Optional[Union[str, Text]],
|
| 81 |
+
hint_stmt: Optional[Union[str, Text]],
|
| 82 |
+
note_stmt: Optional[Union[str, Text]] = None,
|
| 83 |
+
link: Optional[str] = None,
|
| 84 |
+
) -> None:
|
| 85 |
+
# Ensure a proper reference is provided.
|
| 86 |
+
if reference is None:
|
| 87 |
+
assert hasattr(self, "reference"), "error reference not provided!"
|
| 88 |
+
reference = self.reference
|
| 89 |
+
assert _is_kebab_case(reference), "error reference must be kebab-case!"
|
| 90 |
+
|
| 91 |
+
self.kind = kind
|
| 92 |
+
self.reference = reference
|
| 93 |
+
|
| 94 |
+
self.message = message
|
| 95 |
+
self.context = context
|
| 96 |
+
|
| 97 |
+
self.note_stmt = note_stmt
|
| 98 |
+
self.hint_stmt = hint_stmt
|
| 99 |
+
|
| 100 |
+
self.link = link
|
| 101 |
+
|
| 102 |
+
super().__init__(f"<{self.__class__.__name__}: {self.reference}>")
|
| 103 |
+
|
| 104 |
+
def __repr__(self) -> str:
|
| 105 |
+
return (
|
| 106 |
+
f"<{self.__class__.__name__}("
|
| 107 |
+
f"reference={self.reference!r}, "
|
| 108 |
+
f"message={self.message!r}, "
|
| 109 |
+
f"context={self.context!r}, "
|
| 110 |
+
f"note_stmt={self.note_stmt!r}, "
|
| 111 |
+
f"hint_stmt={self.hint_stmt!r}"
|
| 112 |
+
")>"
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
def __rich_console__(
|
| 116 |
+
self,
|
| 117 |
+
console: Console,
|
| 118 |
+
options: ConsoleOptions,
|
| 119 |
+
) -> RenderResult:
|
| 120 |
+
colour = "red" if self.kind == "error" else "yellow"
|
| 121 |
+
|
| 122 |
+
yield f"[{colour} bold]{self.kind}[/]: [bold]{self.reference}[/]"
|
| 123 |
+
yield ""
|
| 124 |
+
|
| 125 |
+
if not options.ascii_only:
|
| 126 |
+
# Present the main message, with relevant context indented.
|
| 127 |
+
if self.context is not None:
|
| 128 |
+
yield _prefix_with_indent(
|
| 129 |
+
self.message,
|
| 130 |
+
console,
|
| 131 |
+
prefix=f"[{colour}]×[/] ",
|
| 132 |
+
indent=f"[{colour}]│[/] ",
|
| 133 |
+
)
|
| 134 |
+
yield _prefix_with_indent(
|
| 135 |
+
self.context,
|
| 136 |
+
console,
|
| 137 |
+
prefix=f"[{colour}]╰─>[/] ",
|
| 138 |
+
indent=f"[{colour}] [/] ",
|
| 139 |
+
)
|
| 140 |
+
else:
|
| 141 |
+
yield _prefix_with_indent(
|
| 142 |
+
self.message,
|
| 143 |
+
console,
|
| 144 |
+
prefix="[red]×[/] ",
|
| 145 |
+
indent=" ",
|
| 146 |
+
)
|
| 147 |
+
else:
|
| 148 |
+
yield self.message
|
| 149 |
+
if self.context is not None:
|
| 150 |
+
yield ""
|
| 151 |
+
yield self.context
|
| 152 |
+
|
| 153 |
+
if self.note_stmt is not None or self.hint_stmt is not None:
|
| 154 |
+
yield ""
|
| 155 |
+
|
| 156 |
+
if self.note_stmt is not None:
|
| 157 |
+
yield _prefix_with_indent(
|
| 158 |
+
self.note_stmt,
|
| 159 |
+
console,
|
| 160 |
+
prefix="[magenta bold]note[/]: ",
|
| 161 |
+
indent=" ",
|
| 162 |
+
)
|
| 163 |
+
if self.hint_stmt is not None:
|
| 164 |
+
yield _prefix_with_indent(
|
| 165 |
+
self.hint_stmt,
|
| 166 |
+
console,
|
| 167 |
+
prefix="[cyan bold]hint[/]: ",
|
| 168 |
+
indent=" ",
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
if self.link is not None:
|
| 172 |
+
yield ""
|
| 173 |
+
yield f"Link: {self.link}"
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
#
|
| 177 |
+
# Actual Errors
|
| 178 |
+
#
|
| 179 |
+
class ConfigurationError(PipError):
|
| 180 |
+
"""General exception in configuration"""
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class InstallationError(PipError):
|
| 184 |
+
"""General exception during installation"""
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
class UninstallationError(PipError):
|
| 188 |
+
"""General exception during uninstallation"""
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
class MissingPyProjectBuildRequires(DiagnosticPipError):
|
| 192 |
+
"""Raised when pyproject.toml has `build-system`, but no `build-system.requires`."""
|
| 193 |
+
|
| 194 |
+
reference = "missing-pyproject-build-system-requires"
|
| 195 |
+
|
| 196 |
+
def __init__(self, *, package: str) -> None:
|
| 197 |
+
super().__init__(
|
| 198 |
+
message=f"Can not process {escape(package)}",
|
| 199 |
+
context=Text(
|
| 200 |
+
"This package has an invalid pyproject.toml file.\n"
|
| 201 |
+
"The [build-system] table is missing the mandatory `requires` key."
|
| 202 |
+
),
|
| 203 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
| 204 |
+
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
class InvalidPyProjectBuildRequires(DiagnosticPipError):
|
| 209 |
+
"""Raised when pyproject.toml an invalid `build-system.requires`."""
|
| 210 |
+
|
| 211 |
+
reference = "invalid-pyproject-build-system-requires"
|
| 212 |
+
|
| 213 |
+
def __init__(self, *, package: str, reason: str) -> None:
|
| 214 |
+
super().__init__(
|
| 215 |
+
message=f"Can not process {escape(package)}",
|
| 216 |
+
context=Text(
|
| 217 |
+
"This package has an invalid `build-system.requires` key in "
|
| 218 |
+
f"pyproject.toml.\n{reason}"
|
| 219 |
+
),
|
| 220 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
| 221 |
+
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
class NoneMetadataError(PipError):
|
| 226 |
+
"""Raised when accessing a Distribution's "METADATA" or "PKG-INFO".
|
| 227 |
+
|
| 228 |
+
This signifies an inconsistency, when the Distribution claims to have
|
| 229 |
+
the metadata file (if not, raise ``FileNotFoundError`` instead), but is
|
| 230 |
+
not actually able to produce its content. This may be due to permission
|
| 231 |
+
errors.
|
| 232 |
+
"""
|
| 233 |
+
|
| 234 |
+
def __init__(
|
| 235 |
+
self,
|
| 236 |
+
dist: "BaseDistribution",
|
| 237 |
+
metadata_name: str,
|
| 238 |
+
) -> None:
|
| 239 |
+
"""
|
| 240 |
+
:param dist: A Distribution object.
|
| 241 |
+
:param metadata_name: The name of the metadata being accessed
|
| 242 |
+
(can be "METADATA" or "PKG-INFO").
|
| 243 |
+
"""
|
| 244 |
+
self.dist = dist
|
| 245 |
+
self.metadata_name = metadata_name
|
| 246 |
+
|
| 247 |
+
def __str__(self) -> str:
|
| 248 |
+
# Use `dist` in the error message because its stringification
|
| 249 |
+
# includes more information, like the version and location.
|
| 250 |
+
return f"None {self.metadata_name} metadata found for distribution: {self.dist}"
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
class UserInstallationInvalid(InstallationError):
|
| 254 |
+
"""A --user install is requested on an environment without user site."""
|
| 255 |
+
|
| 256 |
+
def __str__(self) -> str:
|
| 257 |
+
return "User base directory is not specified"
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
class InvalidSchemeCombination(InstallationError):
|
| 261 |
+
def __str__(self) -> str:
|
| 262 |
+
before = ", ".join(str(a) for a in self.args[:-1])
|
| 263 |
+
return f"Cannot set {before} and {self.args[-1]} together"
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
class DistributionNotFound(InstallationError):
|
| 267 |
+
"""Raised when a distribution cannot be found to satisfy a requirement"""
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
class RequirementsFileParseError(InstallationError):
|
| 271 |
+
"""Raised when a general error occurs parsing a requirements file line."""
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
class BestVersionAlreadyInstalled(PipError):
|
| 275 |
+
"""Raised when the most up-to-date version of a package is already
|
| 276 |
+
installed."""
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
class BadCommand(PipError):
|
| 280 |
+
"""Raised when virtualenv or a command is not found"""
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
class CommandError(PipError):
|
| 284 |
+
"""Raised when there is an error in command-line arguments"""
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class PreviousBuildDirError(PipError):
|
| 288 |
+
"""Raised when there's a previous conflicting build directory"""
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
class NetworkConnectionError(PipError):
|
| 292 |
+
"""HTTP connection error"""
|
| 293 |
+
|
| 294 |
+
def __init__(
|
| 295 |
+
self,
|
| 296 |
+
error_msg: str,
|
| 297 |
+
response: Optional[Response] = None,
|
| 298 |
+
request: Optional[Request] = None,
|
| 299 |
+
) -> None:
|
| 300 |
+
"""
|
| 301 |
+
Initialize NetworkConnectionError with `request` and `response`
|
| 302 |
+
objects.
|
| 303 |
+
"""
|
| 304 |
+
self.response = response
|
| 305 |
+
self.request = request
|
| 306 |
+
self.error_msg = error_msg
|
| 307 |
+
if (
|
| 308 |
+
self.response is not None
|
| 309 |
+
and not self.request
|
| 310 |
+
and hasattr(response, "request")
|
| 311 |
+
):
|
| 312 |
+
self.request = self.response.request
|
| 313 |
+
super().__init__(error_msg, response, request)
|
| 314 |
+
|
| 315 |
+
def __str__(self) -> str:
|
| 316 |
+
return str(self.error_msg)
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
class InvalidWheelFilename(InstallationError):
|
| 320 |
+
"""Invalid wheel filename."""
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
class UnsupportedWheel(InstallationError):
|
| 324 |
+
"""Unsupported wheel."""
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class InvalidWheel(InstallationError):
|
| 328 |
+
"""Invalid (e.g. corrupt) wheel."""
|
| 329 |
+
|
| 330 |
+
def __init__(self, location: str, name: str):
|
| 331 |
+
self.location = location
|
| 332 |
+
self.name = name
|
| 333 |
+
|
| 334 |
+
def __str__(self) -> str:
|
| 335 |
+
return f"Wheel '{self.name}' located at {self.location} is invalid."
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
class MetadataInconsistent(InstallationError):
|
| 339 |
+
"""Built metadata contains inconsistent information.
|
| 340 |
+
|
| 341 |
+
This is raised when the metadata contains values (e.g. name and version)
|
| 342 |
+
that do not match the information previously obtained from sdist filename,
|
| 343 |
+
user-supplied ``#egg=`` value, or an install requirement name.
|
| 344 |
+
"""
|
| 345 |
+
|
| 346 |
+
def __init__(
|
| 347 |
+
self, ireq: "InstallRequirement", field: str, f_val: str, m_val: str
|
| 348 |
+
) -> None:
|
| 349 |
+
self.ireq = ireq
|
| 350 |
+
self.field = field
|
| 351 |
+
self.f_val = f_val
|
| 352 |
+
self.m_val = m_val
|
| 353 |
+
|
| 354 |
+
def __str__(self) -> str:
|
| 355 |
+
return (
|
| 356 |
+
f"Requested {self.ireq} has inconsistent {self.field}: "
|
| 357 |
+
f"expected {self.f_val!r}, but metadata has {self.m_val!r}"
|
| 358 |
+
)
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
class InstallationSubprocessError(DiagnosticPipError, InstallationError):
|
| 362 |
+
"""A subprocess call failed."""
|
| 363 |
+
|
| 364 |
+
reference = "subprocess-exited-with-error"
|
| 365 |
+
|
| 366 |
+
def __init__(
|
| 367 |
+
self,
|
| 368 |
+
*,
|
| 369 |
+
command_description: str,
|
| 370 |
+
exit_code: int,
|
| 371 |
+
output_lines: Optional[List[str]],
|
| 372 |
+
) -> None:
|
| 373 |
+
if output_lines is None:
|
| 374 |
+
output_prompt = Text("See above for output.")
|
| 375 |
+
else:
|
| 376 |
+
output_prompt = (
|
| 377 |
+
Text.from_markup(f"[red][{len(output_lines)} lines of output][/]\n")
|
| 378 |
+
+ Text("".join(output_lines))
|
| 379 |
+
+ Text.from_markup(R"[red]\[end of output][/]")
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
+
super().__init__(
|
| 383 |
+
message=(
|
| 384 |
+
f"[green]{escape(command_description)}[/] did not run successfully.\n"
|
| 385 |
+
f"exit code: {exit_code}"
|
| 386 |
+
),
|
| 387 |
+
context=output_prompt,
|
| 388 |
+
hint_stmt=None,
|
| 389 |
+
note_stmt=(
|
| 390 |
+
"This error originates from a subprocess, and is likely not a "
|
| 391 |
+
"problem with pip."
|
| 392 |
+
),
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
self.command_description = command_description
|
| 396 |
+
self.exit_code = exit_code
|
| 397 |
+
|
| 398 |
+
def __str__(self) -> str:
|
| 399 |
+
return f"{self.command_description} exited with {self.exit_code}"
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
class MetadataGenerationFailed(InstallationSubprocessError, InstallationError):
|
| 403 |
+
reference = "metadata-generation-failed"
|
| 404 |
+
|
| 405 |
+
def __init__(
|
| 406 |
+
self,
|
| 407 |
+
*,
|
| 408 |
+
package_details: str,
|
| 409 |
+
) -> None:
|
| 410 |
+
super(InstallationSubprocessError, self).__init__(
|
| 411 |
+
message="Encountered error while generating package metadata.",
|
| 412 |
+
context=escape(package_details),
|
| 413 |
+
hint_stmt="See above for details.",
|
| 414 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
| 415 |
+
)
|
| 416 |
+
|
| 417 |
+
def __str__(self) -> str:
|
| 418 |
+
return "metadata generation failed"
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
class HashErrors(InstallationError):
|
| 422 |
+
"""Multiple HashError instances rolled into one for reporting"""
|
| 423 |
+
|
| 424 |
+
def __init__(self) -> None:
|
| 425 |
+
self.errors: List["HashError"] = []
|
| 426 |
+
|
| 427 |
+
def append(self, error: "HashError") -> None:
|
| 428 |
+
self.errors.append(error)
|
| 429 |
+
|
| 430 |
+
def __str__(self) -> str:
|
| 431 |
+
lines = []
|
| 432 |
+
self.errors.sort(key=lambda e: e.order)
|
| 433 |
+
for cls, errors_of_cls in groupby(self.errors, lambda e: e.__class__):
|
| 434 |
+
lines.append(cls.head)
|
| 435 |
+
lines.extend(e.body() for e in errors_of_cls)
|
| 436 |
+
if lines:
|
| 437 |
+
return "\n".join(lines)
|
| 438 |
+
return ""
|
| 439 |
+
|
| 440 |
+
def __bool__(self) -> bool:
|
| 441 |
+
return bool(self.errors)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
class HashError(InstallationError):
|
| 445 |
+
"""
|
| 446 |
+
A failure to verify a package against known-good hashes
|
| 447 |
+
|
| 448 |
+
:cvar order: An int sorting hash exception classes by difficulty of
|
| 449 |
+
recovery (lower being harder), so the user doesn't bother fretting
|
| 450 |
+
about unpinned packages when he has deeper issues, like VCS
|
| 451 |
+
dependencies, to deal with. Also keeps error reports in a
|
| 452 |
+
deterministic order.
|
| 453 |
+
:cvar head: A section heading for display above potentially many
|
| 454 |
+
exceptions of this kind
|
| 455 |
+
:ivar req: The InstallRequirement that triggered this error. This is
|
| 456 |
+
pasted on after the exception is instantiated, because it's not
|
| 457 |
+
typically available earlier.
|
| 458 |
+
|
| 459 |
+
"""
|
| 460 |
+
|
| 461 |
+
req: Optional["InstallRequirement"] = None
|
| 462 |
+
head = ""
|
| 463 |
+
order: int = -1
|
| 464 |
+
|
| 465 |
+
def body(self) -> str:
|
| 466 |
+
"""Return a summary of me for display under the heading.
|
| 467 |
+
|
| 468 |
+
This default implementation simply prints a description of the
|
| 469 |
+
triggering requirement.
|
| 470 |
+
|
| 471 |
+
:param req: The InstallRequirement that provoked this error, with
|
| 472 |
+
its link already populated by the resolver's _populate_link().
|
| 473 |
+
|
| 474 |
+
"""
|
| 475 |
+
return f" {self._requirement_name()}"
|
| 476 |
+
|
| 477 |
+
def __str__(self) -> str:
|
| 478 |
+
return f"{self.head}\n{self.body()}"
|
| 479 |
+
|
| 480 |
+
def _requirement_name(self) -> str:
|
| 481 |
+
"""Return a description of the requirement that triggered me.
|
| 482 |
+
|
| 483 |
+
This default implementation returns long description of the req, with
|
| 484 |
+
line numbers
|
| 485 |
+
|
| 486 |
+
"""
|
| 487 |
+
return str(self.req) if self.req else "unknown package"
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
class VcsHashUnsupported(HashError):
|
| 491 |
+
"""A hash was provided for a version-control-system-based requirement, but
|
| 492 |
+
we don't have a method for hashing those."""
|
| 493 |
+
|
| 494 |
+
order = 0
|
| 495 |
+
head = (
|
| 496 |
+
"Can't verify hashes for these requirements because we don't "
|
| 497 |
+
"have a way to hash version control repositories:"
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
class DirectoryUrlHashUnsupported(HashError):
|
| 502 |
+
"""A hash was provided for a version-control-system-based requirement, but
|
| 503 |
+
we don't have a method for hashing those."""
|
| 504 |
+
|
| 505 |
+
order = 1
|
| 506 |
+
head = (
|
| 507 |
+
"Can't verify hashes for these file:// requirements because they "
|
| 508 |
+
"point to directories:"
|
| 509 |
+
)
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
class HashMissing(HashError):
|
| 513 |
+
"""A hash was needed for a requirement but is absent."""
|
| 514 |
+
|
| 515 |
+
order = 2
|
| 516 |
+
head = (
|
| 517 |
+
"Hashes are required in --require-hashes mode, but they are "
|
| 518 |
+
"missing from some requirements. Here is a list of those "
|
| 519 |
+
"requirements along with the hashes their downloaded archives "
|
| 520 |
+
"actually had. Add lines like these to your requirements files to "
|
| 521 |
+
"prevent tampering. (If you did not enable --require-hashes "
|
| 522 |
+
"manually, note that it turns on automatically when any package "
|
| 523 |
+
"has a hash.)"
|
| 524 |
+
)
|
| 525 |
+
|
| 526 |
+
def __init__(self, gotten_hash: str) -> None:
|
| 527 |
+
"""
|
| 528 |
+
:param gotten_hash: The hash of the (possibly malicious) archive we
|
| 529 |
+
just downloaded
|
| 530 |
+
"""
|
| 531 |
+
self.gotten_hash = gotten_hash
|
| 532 |
+
|
| 533 |
+
def body(self) -> str:
|
| 534 |
+
# Dodge circular import.
|
| 535 |
+
from pip._internal.utils.hashes import FAVORITE_HASH
|
| 536 |
+
|
| 537 |
+
package = None
|
| 538 |
+
if self.req:
|
| 539 |
+
# In the case of URL-based requirements, display the original URL
|
| 540 |
+
# seen in the requirements file rather than the package name,
|
| 541 |
+
# so the output can be directly copied into the requirements file.
|
| 542 |
+
package = (
|
| 543 |
+
self.req.original_link
|
| 544 |
+
if self.req.is_direct
|
| 545 |
+
# In case someone feeds something downright stupid
|
| 546 |
+
# to InstallRequirement's constructor.
|
| 547 |
+
else getattr(self.req, "req", None)
|
| 548 |
+
)
|
| 549 |
+
return " {} --hash={}:{}".format(
|
| 550 |
+
package or "unknown package", FAVORITE_HASH, self.gotten_hash
|
| 551 |
+
)
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
class HashUnpinned(HashError):
|
| 555 |
+
"""A requirement had a hash specified but was not pinned to a specific
|
| 556 |
+
version."""
|
| 557 |
+
|
| 558 |
+
order = 3
|
| 559 |
+
head = (
|
| 560 |
+
"In --require-hashes mode, all requirements must have their "
|
| 561 |
+
"versions pinned with ==. These do not:"
|
| 562 |
+
)
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
class HashMismatch(HashError):
|
| 566 |
+
"""
|
| 567 |
+
Distribution file hash values don't match.
|
| 568 |
+
|
| 569 |
+
:ivar package_name: The name of the package that triggered the hash
|
| 570 |
+
mismatch. Feel free to write to this after the exception is raise to
|
| 571 |
+
improve its error message.
|
| 572 |
+
|
| 573 |
+
"""
|
| 574 |
+
|
| 575 |
+
order = 4
|
| 576 |
+
head = (
|
| 577 |
+
"THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS "
|
| 578 |
+
"FILE. If you have updated the package versions, please update "
|
| 579 |
+
"the hashes. Otherwise, examine the package contents carefully; "
|
| 580 |
+
"someone may have tampered with them."
|
| 581 |
+
)
|
| 582 |
+
|
| 583 |
+
def __init__(self, allowed: Dict[str, List[str]], gots: Dict[str, "_Hash"]) -> None:
|
| 584 |
+
"""
|
| 585 |
+
:param allowed: A dict of algorithm names pointing to lists of allowed
|
| 586 |
+
hex digests
|
| 587 |
+
:param gots: A dict of algorithm names pointing to hashes we
|
| 588 |
+
actually got from the files under suspicion
|
| 589 |
+
"""
|
| 590 |
+
self.allowed = allowed
|
| 591 |
+
self.gots = gots
|
| 592 |
+
|
| 593 |
+
def body(self) -> str:
|
| 594 |
+
return f" {self._requirement_name()}:\n{self._hash_comparison()}"
|
| 595 |
+
|
| 596 |
+
def _hash_comparison(self) -> str:
|
| 597 |
+
"""
|
| 598 |
+
Return a comparison of actual and expected hash values.
|
| 599 |
+
|
| 600 |
+
Example::
|
| 601 |
+
|
| 602 |
+
Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
|
| 603 |
+
or 123451234512345123451234512345123451234512345
|
| 604 |
+
Got bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef
|
| 605 |
+
|
| 606 |
+
"""
|
| 607 |
+
|
| 608 |
+
def hash_then_or(hash_name: str) -> "chain[str]":
|
| 609 |
+
# For now, all the decent hashes have 6-char names, so we can get
|
| 610 |
+
# away with hard-coding space literals.
|
| 611 |
+
return chain([hash_name], repeat(" or"))
|
| 612 |
+
|
| 613 |
+
lines: List[str] = []
|
| 614 |
+
for hash_name, expecteds in self.allowed.items():
|
| 615 |
+
prefix = hash_then_or(hash_name)
|
| 616 |
+
lines.extend((f" Expected {next(prefix)} {e}") for e in expecteds)
|
| 617 |
+
lines.append(
|
| 618 |
+
f" Got {self.gots[hash_name].hexdigest()}\n"
|
| 619 |
+
)
|
| 620 |
+
return "\n".join(lines)
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
class UnsupportedPythonVersion(InstallationError):
|
| 624 |
+
"""Unsupported python version according to Requires-Python package
|
| 625 |
+
metadata."""
|
| 626 |
+
|
| 627 |
+
|
| 628 |
+
class ConfigurationFileCouldNotBeLoaded(ConfigurationError):
|
| 629 |
+
"""When there are errors while loading a configuration file"""
|
| 630 |
+
|
| 631 |
+
def __init__(
|
| 632 |
+
self,
|
| 633 |
+
reason: str = "could not be loaded",
|
| 634 |
+
fname: Optional[str] = None,
|
| 635 |
+
error: Optional[configparser.Error] = None,
|
| 636 |
+
) -> None:
|
| 637 |
+
super().__init__(error)
|
| 638 |
+
self.reason = reason
|
| 639 |
+
self.fname = fname
|
| 640 |
+
self.error = error
|
| 641 |
+
|
| 642 |
+
def __str__(self) -> str:
|
| 643 |
+
if self.fname is not None:
|
| 644 |
+
message_part = f" in {self.fname}."
|
| 645 |
+
else:
|
| 646 |
+
assert self.error is not None
|
| 647 |
+
message_part = f".\n{self.error}\n"
|
| 648 |
+
return f"Configuration file {self.reason}{message_part}"
|
| 649 |
+
|
| 650 |
+
|
| 651 |
+
_DEFAULT_EXTERNALLY_MANAGED_ERROR = f"""\
|
| 652 |
+
The Python environment under {sys.prefix} is managed externally, and may not be
|
| 653 |
+
manipulated by the user. Please use specific tooling from the distributor of
|
| 654 |
+
the Python installation to interact with this environment instead.
|
| 655 |
+
"""
|
| 656 |
+
|
| 657 |
+
|
| 658 |
+
class ExternallyManagedEnvironment(DiagnosticPipError):
|
| 659 |
+
"""The current environment is externally managed.
|
| 660 |
+
|
| 661 |
+
This is raised when the current environment is externally managed, as
|
| 662 |
+
defined by `PEP 668`_. The ``EXTERNALLY-MANAGED`` configuration is checked
|
| 663 |
+
and displayed when the error is bubbled up to the user.
|
| 664 |
+
|
| 665 |
+
:param error: The error message read from ``EXTERNALLY-MANAGED``.
|
| 666 |
+
"""
|
| 667 |
+
|
| 668 |
+
reference = "externally-managed-environment"
|
| 669 |
+
|
| 670 |
+
def __init__(self, error: Optional[str]) -> None:
|
| 671 |
+
if error is None:
|
| 672 |
+
context = Text(_DEFAULT_EXTERNALLY_MANAGED_ERROR)
|
| 673 |
+
else:
|
| 674 |
+
context = Text(error)
|
| 675 |
+
super().__init__(
|
| 676 |
+
message="This environment is externally managed",
|
| 677 |
+
context=context,
|
| 678 |
+
note_stmt=(
|
| 679 |
+
"If you believe this is a mistake, please contact your "
|
| 680 |
+
"Python installation or OS distribution provider. "
|
| 681 |
+
"You can override this, at the risk of breaking your Python "
|
| 682 |
+
"installation or OS, by passing --break-system-packages."
|
| 683 |
+
),
|
| 684 |
+
hint_stmt=Text("See PEP 668 for the detailed specification."),
|
| 685 |
+
)
|
| 686 |
+
|
| 687 |
+
@staticmethod
|
| 688 |
+
def _iter_externally_managed_error_keys() -> Iterator[str]:
|
| 689 |
+
# LC_MESSAGES is in POSIX, but not the C standard. The most common
|
| 690 |
+
# platform that does not implement this category is Windows, where
|
| 691 |
+
# using other categories for console message localization is equally
|
| 692 |
+
# unreliable, so we fall back to the locale-less vendor message. This
|
| 693 |
+
# can always be re-evaluated when a vendor proposes a new alternative.
|
| 694 |
+
try:
|
| 695 |
+
category = locale.LC_MESSAGES
|
| 696 |
+
except AttributeError:
|
| 697 |
+
lang: Optional[str] = None
|
| 698 |
+
else:
|
| 699 |
+
lang, _ = locale.getlocale(category)
|
| 700 |
+
if lang is not None:
|
| 701 |
+
yield f"Error-{lang}"
|
| 702 |
+
for sep in ("-", "_"):
|
| 703 |
+
before, found, _ = lang.partition(sep)
|
| 704 |
+
if not found:
|
| 705 |
+
continue
|
| 706 |
+
yield f"Error-{before}"
|
| 707 |
+
yield "Error"
|
| 708 |
+
|
| 709 |
+
@classmethod
|
| 710 |
+
def from_config(
|
| 711 |
+
cls,
|
| 712 |
+
config: Union[pathlib.Path, str],
|
| 713 |
+
) -> "ExternallyManagedEnvironment":
|
| 714 |
+
parser = configparser.ConfigParser(interpolation=None)
|
| 715 |
+
try:
|
| 716 |
+
parser.read(config, encoding="utf-8")
|
| 717 |
+
section = parser["externally-managed"]
|
| 718 |
+
for key in cls._iter_externally_managed_error_keys():
|
| 719 |
+
with contextlib.suppress(KeyError):
|
| 720 |
+
return cls(section[key])
|
| 721 |
+
except KeyError:
|
| 722 |
+
pass
|
| 723 |
+
except (OSError, UnicodeDecodeError, configparser.ParsingError):
|
| 724 |
+
from pip._internal.utils._log import VERBOSE
|
| 725 |
+
|
| 726 |
+
exc_info = logger.isEnabledFor(VERBOSE)
|
| 727 |
+
logger.warning("Failed to read %s", config, exc_info=exc_info)
|
| 728 |
+
return cls(None)
|
venv/lib/python3.12/site-packages/pip/_internal/main.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def main(args: Optional[List[str]] = None) -> int:
|
| 5 |
+
"""This is preserved for old console scripts that may still be referencing
|
| 6 |
+
it.
|
| 7 |
+
|
| 8 |
+
For additional details, see https://github.com/pypa/pip/issues/7498.
|
| 9 |
+
"""
|
| 10 |
+
from pip._internal.utils.entrypoints import _wrapper
|
| 11 |
+
|
| 12 |
+
return _wrapper(args)
|
venv/lib/python3.12/site-packages/pip/_internal/pyproject.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 5 |
+
|
| 6 |
+
from pip._vendor import tomli
|
| 7 |
+
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
|
| 8 |
+
|
| 9 |
+
from pip._internal.exceptions import (
|
| 10 |
+
InstallationError,
|
| 11 |
+
InvalidPyProjectBuildRequires,
|
| 12 |
+
MissingPyProjectBuildRequires,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _is_list_of_str(obj: Any) -> bool:
|
| 17 |
+
return isinstance(obj, list) and all(isinstance(item, str) for item in obj)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def make_pyproject_path(unpacked_source_directory: str) -> str:
|
| 21 |
+
return os.path.join(unpacked_source_directory, "pyproject.toml")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
BuildSystemDetails = namedtuple(
|
| 25 |
+
"BuildSystemDetails", ["requires", "backend", "check", "backend_path"]
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def load_pyproject_toml(
|
| 30 |
+
use_pep517: Optional[bool], pyproject_toml: str, setup_py: str, req_name: str
|
| 31 |
+
) -> Optional[BuildSystemDetails]:
|
| 32 |
+
"""Load the pyproject.toml file.
|
| 33 |
+
|
| 34 |
+
Parameters:
|
| 35 |
+
use_pep517 - Has the user requested PEP 517 processing? None
|
| 36 |
+
means the user hasn't explicitly specified.
|
| 37 |
+
pyproject_toml - Location of the project's pyproject.toml file
|
| 38 |
+
setup_py - Location of the project's setup.py file
|
| 39 |
+
req_name - The name of the requirement we're processing (for
|
| 40 |
+
error reporting)
|
| 41 |
+
|
| 42 |
+
Returns:
|
| 43 |
+
None if we should use the legacy code path, otherwise a tuple
|
| 44 |
+
(
|
| 45 |
+
requirements from pyproject.toml,
|
| 46 |
+
name of PEP 517 backend,
|
| 47 |
+
requirements we should check are installed after setting
|
| 48 |
+
up the build environment
|
| 49 |
+
directory paths to import the backend from (backend-path),
|
| 50 |
+
relative to the project root.
|
| 51 |
+
)
|
| 52 |
+
"""
|
| 53 |
+
has_pyproject = os.path.isfile(pyproject_toml)
|
| 54 |
+
has_setup = os.path.isfile(setup_py)
|
| 55 |
+
|
| 56 |
+
if not has_pyproject and not has_setup:
|
| 57 |
+
raise InstallationError(
|
| 58 |
+
f"{req_name} does not appear to be a Python project: "
|
| 59 |
+
f"neither 'setup.py' nor 'pyproject.toml' found."
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
if has_pyproject:
|
| 63 |
+
with open(pyproject_toml, encoding="utf-8") as f:
|
| 64 |
+
pp_toml = tomli.loads(f.read())
|
| 65 |
+
build_system = pp_toml.get("build-system")
|
| 66 |
+
else:
|
| 67 |
+
build_system = None
|
| 68 |
+
|
| 69 |
+
# The following cases must use PEP 517
|
| 70 |
+
# We check for use_pep517 being non-None and falsey because that means
|
| 71 |
+
# the user explicitly requested --no-use-pep517. The value 0 as
|
| 72 |
+
# opposed to False can occur when the value is provided via an
|
| 73 |
+
# environment variable or config file option (due to the quirk of
|
| 74 |
+
# strtobool() returning an integer in pip's configuration code).
|
| 75 |
+
if has_pyproject and not has_setup:
|
| 76 |
+
if use_pep517 is not None and not use_pep517:
|
| 77 |
+
raise InstallationError(
|
| 78 |
+
"Disabling PEP 517 processing is invalid: "
|
| 79 |
+
"project does not have a setup.py"
|
| 80 |
+
)
|
| 81 |
+
use_pep517 = True
|
| 82 |
+
elif build_system and "build-backend" in build_system:
|
| 83 |
+
if use_pep517 is not None and not use_pep517:
|
| 84 |
+
raise InstallationError(
|
| 85 |
+
"Disabling PEP 517 processing is invalid: "
|
| 86 |
+
"project specifies a build backend of {} "
|
| 87 |
+
"in pyproject.toml".format(build_system["build-backend"])
|
| 88 |
+
)
|
| 89 |
+
use_pep517 = True
|
| 90 |
+
|
| 91 |
+
# If we haven't worked out whether to use PEP 517 yet,
|
| 92 |
+
# and the user hasn't explicitly stated a preference,
|
| 93 |
+
# we do so if the project has a pyproject.toml file
|
| 94 |
+
# or if we cannot import setuptools or wheels.
|
| 95 |
+
|
| 96 |
+
# We fallback to PEP 517 when without setuptools or without the wheel package,
|
| 97 |
+
# so setuptools can be installed as a default build backend.
|
| 98 |
+
# For more info see:
|
| 99 |
+
# https://discuss.python.org/t/pip-without-setuptools-could-the-experience-be-improved/11810/9
|
| 100 |
+
# https://github.com/pypa/pip/issues/8559
|
| 101 |
+
elif use_pep517 is None:
|
| 102 |
+
use_pep517 = (
|
| 103 |
+
has_pyproject
|
| 104 |
+
or not importlib.util.find_spec("setuptools")
|
| 105 |
+
or not importlib.util.find_spec("wheel")
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# At this point, we know whether we're going to use PEP 517.
|
| 109 |
+
assert use_pep517 is not None
|
| 110 |
+
|
| 111 |
+
# If we're using the legacy code path, there is nothing further
|
| 112 |
+
# for us to do here.
|
| 113 |
+
if not use_pep517:
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
if build_system is None:
|
| 117 |
+
# Either the user has a pyproject.toml with no build-system
|
| 118 |
+
# section, or the user has no pyproject.toml, but has opted in
|
| 119 |
+
# explicitly via --use-pep517.
|
| 120 |
+
# In the absence of any explicit backend specification, we
|
| 121 |
+
# assume the setuptools backend that most closely emulates the
|
| 122 |
+
# traditional direct setup.py execution, and require wheel and
|
| 123 |
+
# a version of setuptools that supports that backend.
|
| 124 |
+
|
| 125 |
+
build_system = {
|
| 126 |
+
"requires": ["setuptools>=40.8.0"],
|
| 127 |
+
"build-backend": "setuptools.build_meta:__legacy__",
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
# If we're using PEP 517, we have build system information (either
|
| 131 |
+
# from pyproject.toml, or defaulted by the code above).
|
| 132 |
+
# Note that at this point, we do not know if the user has actually
|
| 133 |
+
# specified a backend, though.
|
| 134 |
+
assert build_system is not None
|
| 135 |
+
|
| 136 |
+
# Ensure that the build-system section in pyproject.toml conforms
|
| 137 |
+
# to PEP 518.
|
| 138 |
+
|
| 139 |
+
# Specifying the build-system table but not the requires key is invalid
|
| 140 |
+
if "requires" not in build_system:
|
| 141 |
+
raise MissingPyProjectBuildRequires(package=req_name)
|
| 142 |
+
|
| 143 |
+
# Error out if requires is not a list of strings
|
| 144 |
+
requires = build_system["requires"]
|
| 145 |
+
if not _is_list_of_str(requires):
|
| 146 |
+
raise InvalidPyProjectBuildRequires(
|
| 147 |
+
package=req_name,
|
| 148 |
+
reason="It is not a list of strings.",
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
# Each requirement must be valid as per PEP 508
|
| 152 |
+
for requirement in requires:
|
| 153 |
+
try:
|
| 154 |
+
Requirement(requirement)
|
| 155 |
+
except InvalidRequirement as error:
|
| 156 |
+
raise InvalidPyProjectBuildRequires(
|
| 157 |
+
package=req_name,
|
| 158 |
+
reason=f"It contains an invalid requirement: {requirement!r}",
|
| 159 |
+
) from error
|
| 160 |
+
|
| 161 |
+
backend = build_system.get("build-backend")
|
| 162 |
+
backend_path = build_system.get("backend-path", [])
|
| 163 |
+
check: List[str] = []
|
| 164 |
+
if backend is None:
|
| 165 |
+
# If the user didn't specify a backend, we assume they want to use
|
| 166 |
+
# the setuptools backend. But we can't be sure they have included
|
| 167 |
+
# a version of setuptools which supplies the backend. So we
|
| 168 |
+
# make a note to check that this requirement is present once
|
| 169 |
+
# we have set up the environment.
|
| 170 |
+
# This is quite a lot of work to check for a very specific case. But
|
| 171 |
+
# the problem is, that case is potentially quite common - projects that
|
| 172 |
+
# adopted PEP 518 early for the ability to specify requirements to
|
| 173 |
+
# execute setup.py, but never considered needing to mention the build
|
| 174 |
+
# tools themselves. The original PEP 518 code had a similar check (but
|
| 175 |
+
# implemented in a different way).
|
| 176 |
+
backend = "setuptools.build_meta:__legacy__"
|
| 177 |
+
check = ["setuptools>=40.8.0"]
|
| 178 |
+
|
| 179 |
+
return BuildSystemDetails(requires, backend, check, backend_path)
|
venv/lib/python3.12/site-packages/pip/_internal/self_outdated_check.py
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import functools
|
| 3 |
+
import hashlib
|
| 4 |
+
import json
|
| 5 |
+
import logging
|
| 6 |
+
import optparse
|
| 7 |
+
import os.path
|
| 8 |
+
import sys
|
| 9 |
+
from dataclasses import dataclass
|
| 10 |
+
from typing import Any, Callable, Dict, Optional
|
| 11 |
+
|
| 12 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 13 |
+
from pip._vendor.rich.console import Group
|
| 14 |
+
from pip._vendor.rich.markup import escape
|
| 15 |
+
from pip._vendor.rich.text import Text
|
| 16 |
+
|
| 17 |
+
from pip._internal.index.collector import LinkCollector
|
| 18 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 19 |
+
from pip._internal.metadata import get_default_environment
|
| 20 |
+
from pip._internal.metadata.base import DistributionVersion
|
| 21 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 22 |
+
from pip._internal.network.session import PipSession
|
| 23 |
+
from pip._internal.utils.compat import WINDOWS
|
| 24 |
+
from pip._internal.utils.entrypoints import (
|
| 25 |
+
get_best_invocation_for_this_pip,
|
| 26 |
+
get_best_invocation_for_this_python,
|
| 27 |
+
)
|
| 28 |
+
from pip._internal.utils.filesystem import adjacent_tmp_file, check_path_owner, replace
|
| 29 |
+
from pip._internal.utils.misc import ensure_dir
|
| 30 |
+
|
| 31 |
+
_WEEK = datetime.timedelta(days=7)
|
| 32 |
+
|
| 33 |
+
logger = logging.getLogger(__name__)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _get_statefile_name(key: str) -> str:
|
| 37 |
+
key_bytes = key.encode()
|
| 38 |
+
name = hashlib.sha224(key_bytes).hexdigest()
|
| 39 |
+
return name
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _convert_date(isodate: str) -> datetime.datetime:
|
| 43 |
+
"""Convert an ISO format string to a date.
|
| 44 |
+
|
| 45 |
+
Handles the format 2020-01-22T14:24:01Z (trailing Z)
|
| 46 |
+
which is not supported by older versions of fromisoformat.
|
| 47 |
+
"""
|
| 48 |
+
return datetime.datetime.fromisoformat(isodate.replace("Z", "+00:00"))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class SelfCheckState:
|
| 52 |
+
def __init__(self, cache_dir: str) -> None:
|
| 53 |
+
self._state: Dict[str, Any] = {}
|
| 54 |
+
self._statefile_path = None
|
| 55 |
+
|
| 56 |
+
# Try to load the existing state
|
| 57 |
+
if cache_dir:
|
| 58 |
+
self._statefile_path = os.path.join(
|
| 59 |
+
cache_dir, "selfcheck", _get_statefile_name(self.key)
|
| 60 |
+
)
|
| 61 |
+
try:
|
| 62 |
+
with open(self._statefile_path, encoding="utf-8") as statefile:
|
| 63 |
+
self._state = json.load(statefile)
|
| 64 |
+
except (OSError, ValueError, KeyError):
|
| 65 |
+
# Explicitly suppressing exceptions, since we don't want to
|
| 66 |
+
# error out if the cache file is invalid.
|
| 67 |
+
pass
|
| 68 |
+
|
| 69 |
+
@property
|
| 70 |
+
def key(self) -> str:
|
| 71 |
+
return sys.prefix
|
| 72 |
+
|
| 73 |
+
def get(self, current_time: datetime.datetime) -> Optional[str]:
|
| 74 |
+
"""Check if we have a not-outdated version loaded already."""
|
| 75 |
+
if not self._state:
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
if "last_check" not in self._state:
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
if "pypi_version" not in self._state:
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
# Determine if we need to refresh the state
|
| 85 |
+
last_check = _convert_date(self._state["last_check"])
|
| 86 |
+
time_since_last_check = current_time - last_check
|
| 87 |
+
if time_since_last_check > _WEEK:
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
return self._state["pypi_version"]
|
| 91 |
+
|
| 92 |
+
def set(self, pypi_version: str, current_time: datetime.datetime) -> None:
|
| 93 |
+
# If we do not have a path to cache in, don't bother saving.
|
| 94 |
+
if not self._statefile_path:
|
| 95 |
+
return
|
| 96 |
+
|
| 97 |
+
# Check to make sure that we own the directory
|
| 98 |
+
if not check_path_owner(os.path.dirname(self._statefile_path)):
|
| 99 |
+
return
|
| 100 |
+
|
| 101 |
+
# Now that we've ensured the directory is owned by this user, we'll go
|
| 102 |
+
# ahead and make sure that all our directories are created.
|
| 103 |
+
ensure_dir(os.path.dirname(self._statefile_path))
|
| 104 |
+
|
| 105 |
+
state = {
|
| 106 |
+
# Include the key so it's easy to tell which pip wrote the
|
| 107 |
+
# file.
|
| 108 |
+
"key": self.key,
|
| 109 |
+
"last_check": current_time.isoformat(),
|
| 110 |
+
"pypi_version": pypi_version,
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
text = json.dumps(state, sort_keys=True, separators=(",", ":"))
|
| 114 |
+
|
| 115 |
+
with adjacent_tmp_file(self._statefile_path) as f:
|
| 116 |
+
f.write(text.encode())
|
| 117 |
+
|
| 118 |
+
try:
|
| 119 |
+
# Since we have a prefix-specific state file, we can just
|
| 120 |
+
# overwrite whatever is there, no need to check.
|
| 121 |
+
replace(f.name, self._statefile_path)
|
| 122 |
+
except OSError:
|
| 123 |
+
# Best effort.
|
| 124 |
+
pass
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
@dataclass
|
| 128 |
+
class UpgradePrompt:
|
| 129 |
+
old: str
|
| 130 |
+
new: str
|
| 131 |
+
|
| 132 |
+
def __rich__(self) -> Group:
|
| 133 |
+
if WINDOWS:
|
| 134 |
+
pip_cmd = f"{get_best_invocation_for_this_python()} -m pip"
|
| 135 |
+
else:
|
| 136 |
+
pip_cmd = get_best_invocation_for_this_pip()
|
| 137 |
+
|
| 138 |
+
notice = "[bold][[reset][blue]notice[reset][bold]][reset]"
|
| 139 |
+
return Group(
|
| 140 |
+
Text(),
|
| 141 |
+
Text.from_markup(
|
| 142 |
+
f"{notice} A new release of pip is available: "
|
| 143 |
+
f"[red]{self.old}[reset] -> [green]{self.new}[reset]"
|
| 144 |
+
),
|
| 145 |
+
Text.from_markup(
|
| 146 |
+
f"{notice} To update, run: "
|
| 147 |
+
f"[green]{escape(pip_cmd)} install --upgrade pip"
|
| 148 |
+
),
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def was_installed_by_pip(pkg: str) -> bool:
|
| 153 |
+
"""Checks whether pkg was installed by pip
|
| 154 |
+
|
| 155 |
+
This is used not to display the upgrade message when pip is in fact
|
| 156 |
+
installed by system package manager, such as dnf on Fedora.
|
| 157 |
+
"""
|
| 158 |
+
dist = get_default_environment().get_distribution(pkg)
|
| 159 |
+
return dist is not None and "pip" == dist.installer
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def _get_current_remote_pip_version(
|
| 163 |
+
session: PipSession, options: optparse.Values
|
| 164 |
+
) -> Optional[str]:
|
| 165 |
+
# Lets use PackageFinder to see what the latest pip version is
|
| 166 |
+
link_collector = LinkCollector.create(
|
| 167 |
+
session,
|
| 168 |
+
options=options,
|
| 169 |
+
suppress_no_index=True,
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
# Pass allow_yanked=False so we don't suggest upgrading to a
|
| 173 |
+
# yanked version.
|
| 174 |
+
selection_prefs = SelectionPreferences(
|
| 175 |
+
allow_yanked=False,
|
| 176 |
+
allow_all_prereleases=False, # Explicitly set to False
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
finder = PackageFinder.create(
|
| 180 |
+
link_collector=link_collector,
|
| 181 |
+
selection_prefs=selection_prefs,
|
| 182 |
+
)
|
| 183 |
+
best_candidate = finder.find_best_candidate("pip").best_candidate
|
| 184 |
+
if best_candidate is None:
|
| 185 |
+
return None
|
| 186 |
+
|
| 187 |
+
return str(best_candidate.version)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def _self_version_check_logic(
|
| 191 |
+
*,
|
| 192 |
+
state: SelfCheckState,
|
| 193 |
+
current_time: datetime.datetime,
|
| 194 |
+
local_version: DistributionVersion,
|
| 195 |
+
get_remote_version: Callable[[], Optional[str]],
|
| 196 |
+
) -> Optional[UpgradePrompt]:
|
| 197 |
+
remote_version_str = state.get(current_time)
|
| 198 |
+
if remote_version_str is None:
|
| 199 |
+
remote_version_str = get_remote_version()
|
| 200 |
+
if remote_version_str is None:
|
| 201 |
+
logger.debug("No remote pip version found")
|
| 202 |
+
return None
|
| 203 |
+
state.set(remote_version_str, current_time)
|
| 204 |
+
|
| 205 |
+
remote_version = parse_version(remote_version_str)
|
| 206 |
+
logger.debug("Remote version of pip: %s", remote_version)
|
| 207 |
+
logger.debug("Local version of pip: %s", local_version)
|
| 208 |
+
|
| 209 |
+
pip_installed_by_pip = was_installed_by_pip("pip")
|
| 210 |
+
logger.debug("Was pip installed by pip? %s", pip_installed_by_pip)
|
| 211 |
+
if not pip_installed_by_pip:
|
| 212 |
+
return None # Only suggest upgrade if pip is installed by pip.
|
| 213 |
+
|
| 214 |
+
local_version_is_older = (
|
| 215 |
+
local_version < remote_version
|
| 216 |
+
and local_version.base_version != remote_version.base_version
|
| 217 |
+
)
|
| 218 |
+
if local_version_is_older:
|
| 219 |
+
return UpgradePrompt(old=str(local_version), new=remote_version_str)
|
| 220 |
+
|
| 221 |
+
return None
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def pip_self_version_check(session: PipSession, options: optparse.Values) -> None:
|
| 225 |
+
"""Check for an update for pip.
|
| 226 |
+
|
| 227 |
+
Limit the frequency of checks to once per week. State is stored either in
|
| 228 |
+
the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
|
| 229 |
+
of the pip script path.
|
| 230 |
+
"""
|
| 231 |
+
installed_dist = get_default_environment().get_distribution("pip")
|
| 232 |
+
if not installed_dist:
|
| 233 |
+
return
|
| 234 |
+
|
| 235 |
+
try:
|
| 236 |
+
upgrade_prompt = _self_version_check_logic(
|
| 237 |
+
state=SelfCheckState(cache_dir=options.cache_dir),
|
| 238 |
+
current_time=datetime.datetime.now(datetime.timezone.utc),
|
| 239 |
+
local_version=installed_dist.version,
|
| 240 |
+
get_remote_version=functools.partial(
|
| 241 |
+
_get_current_remote_pip_version, session, options
|
| 242 |
+
),
|
| 243 |
+
)
|
| 244 |
+
if upgrade_prompt is not None:
|
| 245 |
+
logger.warning("%s", upgrade_prompt, extra={"rich": True})
|
| 246 |
+
except Exception:
|
| 247 |
+
logger.warning("There was an error checking the latest version of pip.")
|
| 248 |
+
logger.debug("See below for error", exc_info=True)
|
venv/lib/python3.12/site-packages/pip/_internal/wheel_builder.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Orchestrator for building wheels from InstallRequirements.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
import os.path
|
| 6 |
+
import re
|
| 7 |
+
import shutil
|
| 8 |
+
from typing import Iterable, List, Optional, Tuple
|
| 9 |
+
|
| 10 |
+
from pip._vendor.packaging.utils import canonicalize_name, canonicalize_version
|
| 11 |
+
from pip._vendor.packaging.version import InvalidVersion, Version
|
| 12 |
+
|
| 13 |
+
from pip._internal.cache import WheelCache
|
| 14 |
+
from pip._internal.exceptions import InvalidWheelFilename, UnsupportedWheel
|
| 15 |
+
from pip._internal.metadata import FilesystemWheel, get_wheel_distribution
|
| 16 |
+
from pip._internal.models.link import Link
|
| 17 |
+
from pip._internal.models.wheel import Wheel
|
| 18 |
+
from pip._internal.operations.build.wheel import build_wheel_pep517
|
| 19 |
+
from pip._internal.operations.build.wheel_editable import build_wheel_editable
|
| 20 |
+
from pip._internal.operations.build.wheel_legacy import build_wheel_legacy
|
| 21 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 22 |
+
from pip._internal.utils.logging import indent_log
|
| 23 |
+
from pip._internal.utils.misc import ensure_dir, hash_file
|
| 24 |
+
from pip._internal.utils.setuptools_build import make_setuptools_clean_args
|
| 25 |
+
from pip._internal.utils.subprocess import call_subprocess
|
| 26 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 27 |
+
from pip._internal.utils.urls import path_to_url
|
| 28 |
+
from pip._internal.vcs import vcs
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
|
| 32 |
+
_egg_info_re = re.compile(r"([a-z0-9_.]+)-([a-z0-9_.!+-]+)", re.IGNORECASE)
|
| 33 |
+
|
| 34 |
+
BuildResult = Tuple[List[InstallRequirement], List[InstallRequirement]]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _contains_egg_info(s: str) -> bool:
|
| 38 |
+
"""Determine whether the string looks like an egg_info.
|
| 39 |
+
|
| 40 |
+
:param s: The string to parse. E.g. foo-2.1
|
| 41 |
+
"""
|
| 42 |
+
return bool(_egg_info_re.search(s))
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def _should_build(
|
| 46 |
+
req: InstallRequirement,
|
| 47 |
+
need_wheel: bool,
|
| 48 |
+
) -> bool:
|
| 49 |
+
"""Return whether an InstallRequirement should be built into a wheel."""
|
| 50 |
+
if req.constraint:
|
| 51 |
+
# never build requirements that are merely constraints
|
| 52 |
+
return False
|
| 53 |
+
if req.is_wheel:
|
| 54 |
+
if need_wheel:
|
| 55 |
+
logger.info(
|
| 56 |
+
"Skipping %s, due to already being wheel.",
|
| 57 |
+
req.name,
|
| 58 |
+
)
|
| 59 |
+
return False
|
| 60 |
+
|
| 61 |
+
if need_wheel:
|
| 62 |
+
# i.e. pip wheel, not pip install
|
| 63 |
+
return True
|
| 64 |
+
|
| 65 |
+
# From this point, this concerns the pip install command only
|
| 66 |
+
# (need_wheel=False).
|
| 67 |
+
|
| 68 |
+
if not req.source_dir:
|
| 69 |
+
return False
|
| 70 |
+
|
| 71 |
+
if req.editable:
|
| 72 |
+
# we only build PEP 660 editable requirements
|
| 73 |
+
return req.supports_pyproject_editable()
|
| 74 |
+
|
| 75 |
+
return True
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def should_build_for_wheel_command(
|
| 79 |
+
req: InstallRequirement,
|
| 80 |
+
) -> bool:
|
| 81 |
+
return _should_build(req, need_wheel=True)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def should_build_for_install_command(
|
| 85 |
+
req: InstallRequirement,
|
| 86 |
+
) -> bool:
|
| 87 |
+
return _should_build(req, need_wheel=False)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _should_cache(
|
| 91 |
+
req: InstallRequirement,
|
| 92 |
+
) -> Optional[bool]:
|
| 93 |
+
"""
|
| 94 |
+
Return whether a built InstallRequirement can be stored in the persistent
|
| 95 |
+
wheel cache, assuming the wheel cache is available, and _should_build()
|
| 96 |
+
has determined a wheel needs to be built.
|
| 97 |
+
"""
|
| 98 |
+
if req.editable or not req.source_dir:
|
| 99 |
+
# never cache editable requirements
|
| 100 |
+
return False
|
| 101 |
+
|
| 102 |
+
if req.link and req.link.is_vcs:
|
| 103 |
+
# VCS checkout. Do not cache
|
| 104 |
+
# unless it points to an immutable commit hash.
|
| 105 |
+
assert not req.editable
|
| 106 |
+
assert req.source_dir
|
| 107 |
+
vcs_backend = vcs.get_backend_for_scheme(req.link.scheme)
|
| 108 |
+
assert vcs_backend
|
| 109 |
+
if vcs_backend.is_immutable_rev_checkout(req.link.url, req.source_dir):
|
| 110 |
+
return True
|
| 111 |
+
return False
|
| 112 |
+
|
| 113 |
+
assert req.link
|
| 114 |
+
base, ext = req.link.splitext()
|
| 115 |
+
if _contains_egg_info(base):
|
| 116 |
+
return True
|
| 117 |
+
|
| 118 |
+
# Otherwise, do not cache.
|
| 119 |
+
return False
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def _get_cache_dir(
|
| 123 |
+
req: InstallRequirement,
|
| 124 |
+
wheel_cache: WheelCache,
|
| 125 |
+
) -> str:
|
| 126 |
+
"""Return the persistent or temporary cache directory where the built
|
| 127 |
+
wheel need to be stored.
|
| 128 |
+
"""
|
| 129 |
+
cache_available = bool(wheel_cache.cache_dir)
|
| 130 |
+
assert req.link
|
| 131 |
+
if cache_available and _should_cache(req):
|
| 132 |
+
cache_dir = wheel_cache.get_path_for_link(req.link)
|
| 133 |
+
else:
|
| 134 |
+
cache_dir = wheel_cache.get_ephem_path_for_link(req.link)
|
| 135 |
+
return cache_dir
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def _verify_one(req: InstallRequirement, wheel_path: str) -> None:
|
| 139 |
+
canonical_name = canonicalize_name(req.name or "")
|
| 140 |
+
w = Wheel(os.path.basename(wheel_path))
|
| 141 |
+
if canonicalize_name(w.name) != canonical_name:
|
| 142 |
+
raise InvalidWheelFilename(
|
| 143 |
+
f"Wheel has unexpected file name: expected {canonical_name!r}, "
|
| 144 |
+
f"got {w.name!r}",
|
| 145 |
+
)
|
| 146 |
+
dist = get_wheel_distribution(FilesystemWheel(wheel_path), canonical_name)
|
| 147 |
+
dist_verstr = str(dist.version)
|
| 148 |
+
if canonicalize_version(dist_verstr) != canonicalize_version(w.version):
|
| 149 |
+
raise InvalidWheelFilename(
|
| 150 |
+
f"Wheel has unexpected file name: expected {dist_verstr!r}, "
|
| 151 |
+
f"got {w.version!r}",
|
| 152 |
+
)
|
| 153 |
+
metadata_version_value = dist.metadata_version
|
| 154 |
+
if metadata_version_value is None:
|
| 155 |
+
raise UnsupportedWheel("Missing Metadata-Version")
|
| 156 |
+
try:
|
| 157 |
+
metadata_version = Version(metadata_version_value)
|
| 158 |
+
except InvalidVersion:
|
| 159 |
+
msg = f"Invalid Metadata-Version: {metadata_version_value}"
|
| 160 |
+
raise UnsupportedWheel(msg)
|
| 161 |
+
if metadata_version >= Version("1.2") and not isinstance(dist.version, Version):
|
| 162 |
+
raise UnsupportedWheel(
|
| 163 |
+
f"Metadata 1.2 mandates PEP 440 version, but {dist_verstr!r} is not"
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def _build_one(
|
| 168 |
+
req: InstallRequirement,
|
| 169 |
+
output_dir: str,
|
| 170 |
+
verify: bool,
|
| 171 |
+
build_options: List[str],
|
| 172 |
+
global_options: List[str],
|
| 173 |
+
editable: bool,
|
| 174 |
+
) -> Optional[str]:
|
| 175 |
+
"""Build one wheel.
|
| 176 |
+
|
| 177 |
+
:return: The filename of the built wheel, or None if the build failed.
|
| 178 |
+
"""
|
| 179 |
+
artifact = "editable" if editable else "wheel"
|
| 180 |
+
try:
|
| 181 |
+
ensure_dir(output_dir)
|
| 182 |
+
except OSError as e:
|
| 183 |
+
logger.warning(
|
| 184 |
+
"Building %s for %s failed: %s",
|
| 185 |
+
artifact,
|
| 186 |
+
req.name,
|
| 187 |
+
e,
|
| 188 |
+
)
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
# Install build deps into temporary directory (PEP 518)
|
| 192 |
+
with req.build_env:
|
| 193 |
+
wheel_path = _build_one_inside_env(
|
| 194 |
+
req, output_dir, build_options, global_options, editable
|
| 195 |
+
)
|
| 196 |
+
if wheel_path and verify:
|
| 197 |
+
try:
|
| 198 |
+
_verify_one(req, wheel_path)
|
| 199 |
+
except (InvalidWheelFilename, UnsupportedWheel) as e:
|
| 200 |
+
logger.warning("Built %s for %s is invalid: %s", artifact, req.name, e)
|
| 201 |
+
return None
|
| 202 |
+
return wheel_path
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def _build_one_inside_env(
|
| 206 |
+
req: InstallRequirement,
|
| 207 |
+
output_dir: str,
|
| 208 |
+
build_options: List[str],
|
| 209 |
+
global_options: List[str],
|
| 210 |
+
editable: bool,
|
| 211 |
+
) -> Optional[str]:
|
| 212 |
+
with TempDirectory(kind="wheel") as temp_dir:
|
| 213 |
+
assert req.name
|
| 214 |
+
if req.use_pep517:
|
| 215 |
+
assert req.metadata_directory
|
| 216 |
+
assert req.pep517_backend
|
| 217 |
+
if global_options:
|
| 218 |
+
logger.warning(
|
| 219 |
+
"Ignoring --global-option when building %s using PEP 517", req.name
|
| 220 |
+
)
|
| 221 |
+
if build_options:
|
| 222 |
+
logger.warning(
|
| 223 |
+
"Ignoring --build-option when building %s using PEP 517", req.name
|
| 224 |
+
)
|
| 225 |
+
if editable:
|
| 226 |
+
wheel_path = build_wheel_editable(
|
| 227 |
+
name=req.name,
|
| 228 |
+
backend=req.pep517_backend,
|
| 229 |
+
metadata_directory=req.metadata_directory,
|
| 230 |
+
tempd=temp_dir.path,
|
| 231 |
+
)
|
| 232 |
+
else:
|
| 233 |
+
wheel_path = build_wheel_pep517(
|
| 234 |
+
name=req.name,
|
| 235 |
+
backend=req.pep517_backend,
|
| 236 |
+
metadata_directory=req.metadata_directory,
|
| 237 |
+
tempd=temp_dir.path,
|
| 238 |
+
)
|
| 239 |
+
else:
|
| 240 |
+
wheel_path = build_wheel_legacy(
|
| 241 |
+
name=req.name,
|
| 242 |
+
setup_py_path=req.setup_py_path,
|
| 243 |
+
source_dir=req.unpacked_source_directory,
|
| 244 |
+
global_options=global_options,
|
| 245 |
+
build_options=build_options,
|
| 246 |
+
tempd=temp_dir.path,
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
if wheel_path is not None:
|
| 250 |
+
wheel_name = os.path.basename(wheel_path)
|
| 251 |
+
dest_path = os.path.join(output_dir, wheel_name)
|
| 252 |
+
try:
|
| 253 |
+
wheel_hash, length = hash_file(wheel_path)
|
| 254 |
+
shutil.move(wheel_path, dest_path)
|
| 255 |
+
logger.info(
|
| 256 |
+
"Created wheel for %s: filename=%s size=%d sha256=%s",
|
| 257 |
+
req.name,
|
| 258 |
+
wheel_name,
|
| 259 |
+
length,
|
| 260 |
+
wheel_hash.hexdigest(),
|
| 261 |
+
)
|
| 262 |
+
logger.info("Stored in directory: %s", output_dir)
|
| 263 |
+
return dest_path
|
| 264 |
+
except Exception as e:
|
| 265 |
+
logger.warning(
|
| 266 |
+
"Building wheel for %s failed: %s",
|
| 267 |
+
req.name,
|
| 268 |
+
e,
|
| 269 |
+
)
|
| 270 |
+
# Ignore return, we can't do anything else useful.
|
| 271 |
+
if not req.use_pep517:
|
| 272 |
+
_clean_one_legacy(req, global_options)
|
| 273 |
+
return None
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def _clean_one_legacy(req: InstallRequirement, global_options: List[str]) -> bool:
|
| 277 |
+
clean_args = make_setuptools_clean_args(
|
| 278 |
+
req.setup_py_path,
|
| 279 |
+
global_options=global_options,
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
logger.info("Running setup.py clean for %s", req.name)
|
| 283 |
+
try:
|
| 284 |
+
call_subprocess(
|
| 285 |
+
clean_args, command_desc="python setup.py clean", cwd=req.source_dir
|
| 286 |
+
)
|
| 287 |
+
return True
|
| 288 |
+
except Exception:
|
| 289 |
+
logger.error("Failed cleaning build dir for %s", req.name)
|
| 290 |
+
return False
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def build(
|
| 294 |
+
requirements: Iterable[InstallRequirement],
|
| 295 |
+
wheel_cache: WheelCache,
|
| 296 |
+
verify: bool,
|
| 297 |
+
build_options: List[str],
|
| 298 |
+
global_options: List[str],
|
| 299 |
+
) -> BuildResult:
|
| 300 |
+
"""Build wheels.
|
| 301 |
+
|
| 302 |
+
:return: The list of InstallRequirement that succeeded to build and
|
| 303 |
+
the list of InstallRequirement that failed to build.
|
| 304 |
+
"""
|
| 305 |
+
if not requirements:
|
| 306 |
+
return [], []
|
| 307 |
+
|
| 308 |
+
# Build the wheels.
|
| 309 |
+
logger.info(
|
| 310 |
+
"Building wheels for collected packages: %s",
|
| 311 |
+
", ".join(req.name for req in requirements), # type: ignore
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
with indent_log():
|
| 315 |
+
build_successes, build_failures = [], []
|
| 316 |
+
for req in requirements:
|
| 317 |
+
assert req.name
|
| 318 |
+
cache_dir = _get_cache_dir(req, wheel_cache)
|
| 319 |
+
wheel_file = _build_one(
|
| 320 |
+
req,
|
| 321 |
+
cache_dir,
|
| 322 |
+
verify,
|
| 323 |
+
build_options,
|
| 324 |
+
global_options,
|
| 325 |
+
req.editable and req.permit_editable_wheels,
|
| 326 |
+
)
|
| 327 |
+
if wheel_file:
|
| 328 |
+
# Record the download origin in the cache
|
| 329 |
+
if req.download_info is not None:
|
| 330 |
+
# download_info is guaranteed to be set because when we build an
|
| 331 |
+
# InstallRequirement it has been through the preparer before, but
|
| 332 |
+
# let's be cautious.
|
| 333 |
+
wheel_cache.record_download_origin(cache_dir, req.download_info)
|
| 334 |
+
# Update the link for this.
|
| 335 |
+
req.link = Link(path_to_url(wheel_file))
|
| 336 |
+
req.local_file_path = req.link.file_path
|
| 337 |
+
assert req.link.is_wheel
|
| 338 |
+
build_successes.append(req)
|
| 339 |
+
else:
|
| 340 |
+
build_failures.append(req)
|
| 341 |
+
|
| 342 |
+
# notify success/failure
|
| 343 |
+
if build_successes:
|
| 344 |
+
logger.info(
|
| 345 |
+
"Successfully built %s",
|
| 346 |
+
" ".join([req.name for req in build_successes]), # type: ignore
|
| 347 |
+
)
|
| 348 |
+
if build_failures:
|
| 349 |
+
logger.info(
|
| 350 |
+
"Failed to build %s",
|
| 351 |
+
" ".join([req.name for req in build_failures]), # type: ignore
|
| 352 |
+
)
|
| 353 |
+
# Return a list of requirements that failed to build
|
| 354 |
+
return build_successes, build_failures
|
venv/lib/python3.12/site-packages/pip/_vendor/__init__.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pip._vendor is for vendoring dependencies of pip to prevent needing pip to
|
| 3 |
+
depend on something external.
|
| 4 |
+
|
| 5 |
+
Files inside of pip._vendor should be considered immutable and should only be
|
| 6 |
+
updated to versions from upstream.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import absolute_import
|
| 9 |
+
|
| 10 |
+
import glob
|
| 11 |
+
import os.path
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
# Downstream redistributors which have debundled our dependencies should also
|
| 15 |
+
# patch this value to be true. This will trigger the additional patching
|
| 16 |
+
# to cause things like "six" to be available as pip.
|
| 17 |
+
DEBUNDLED = False
|
| 18 |
+
|
| 19 |
+
# By default, look in this directory for a bunch of .whl files which we will
|
| 20 |
+
# add to the beginning of sys.path before attempting to import anything. This
|
| 21 |
+
# is done to support downstream re-distributors like Debian and Fedora who
|
| 22 |
+
# wish to create their own Wheels for our dependencies to aid in debundling.
|
| 23 |
+
WHEEL_DIR = os.path.abspath(os.path.dirname(__file__))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Define a small helper function to alias our vendored modules to the real ones
|
| 27 |
+
# if the vendored ones do not exist. This idea of this was taken from
|
| 28 |
+
# https://github.com/kennethreitz/requests/pull/2567.
|
| 29 |
+
def vendored(modulename):
|
| 30 |
+
vendored_name = "{0}.{1}".format(__name__, modulename)
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
__import__(modulename, globals(), locals(), level=0)
|
| 34 |
+
except ImportError:
|
| 35 |
+
# We can just silently allow import failures to pass here. If we
|
| 36 |
+
# got to this point it means that ``import pip._vendor.whatever``
|
| 37 |
+
# failed and so did ``import whatever``. Since we're importing this
|
| 38 |
+
# upfront in an attempt to alias imports, not erroring here will
|
| 39 |
+
# just mean we get a regular import error whenever pip *actually*
|
| 40 |
+
# tries to import one of these modules to use it, which actually
|
| 41 |
+
# gives us a better error message than we would have otherwise
|
| 42 |
+
# gotten.
|
| 43 |
+
pass
|
| 44 |
+
else:
|
| 45 |
+
sys.modules[vendored_name] = sys.modules[modulename]
|
| 46 |
+
base, head = vendored_name.rsplit(".", 1)
|
| 47 |
+
setattr(sys.modules[base], head, sys.modules[modulename])
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# If we're operating in a debundled setup, then we want to go ahead and trigger
|
| 51 |
+
# the aliasing of our vendored libraries as well as looking for wheels to add
|
| 52 |
+
# to our sys.path. This will cause all of this code to be a no-op typically
|
| 53 |
+
# however downstream redistributors can enable it in a consistent way across
|
| 54 |
+
# all platforms.
|
| 55 |
+
if DEBUNDLED:
|
| 56 |
+
# Actually look inside of WHEEL_DIR to find .whl files and add them to the
|
| 57 |
+
# front of our sys.path.
|
| 58 |
+
sys.path[:] = glob.glob(os.path.join(WHEEL_DIR, "*.whl")) + sys.path
|
| 59 |
+
|
| 60 |
+
# Actually alias all of our vendored dependencies.
|
| 61 |
+
vendored("cachecontrol")
|
| 62 |
+
vendored("certifi")
|
| 63 |
+
vendored("colorama")
|
| 64 |
+
vendored("distlib")
|
| 65 |
+
vendored("distro")
|
| 66 |
+
vendored("six")
|
| 67 |
+
vendored("six.moves")
|
| 68 |
+
vendored("six.moves.urllib")
|
| 69 |
+
vendored("six.moves.urllib.parse")
|
| 70 |
+
vendored("packaging")
|
| 71 |
+
vendored("packaging.version")
|
| 72 |
+
vendored("packaging.specifiers")
|
| 73 |
+
vendored("pep517")
|
| 74 |
+
vendored("pkg_resources")
|
| 75 |
+
vendored("platformdirs")
|
| 76 |
+
vendored("progress")
|
| 77 |
+
vendored("requests")
|
| 78 |
+
vendored("requests.exceptions")
|
| 79 |
+
vendored("requests.packages")
|
| 80 |
+
vendored("requests.packages.urllib3")
|
| 81 |
+
vendored("requests.packages.urllib3._collections")
|
| 82 |
+
vendored("requests.packages.urllib3.connection")
|
| 83 |
+
vendored("requests.packages.urllib3.connectionpool")
|
| 84 |
+
vendored("requests.packages.urllib3.contrib")
|
| 85 |
+
vendored("requests.packages.urllib3.contrib.ntlmpool")
|
| 86 |
+
vendored("requests.packages.urllib3.contrib.pyopenssl")
|
| 87 |
+
vendored("requests.packages.urllib3.exceptions")
|
| 88 |
+
vendored("requests.packages.urllib3.fields")
|
| 89 |
+
vendored("requests.packages.urllib3.filepost")
|
| 90 |
+
vendored("requests.packages.urllib3.packages")
|
| 91 |
+
vendored("requests.packages.urllib3.packages.ordered_dict")
|
| 92 |
+
vendored("requests.packages.urllib3.packages.six")
|
| 93 |
+
vendored("requests.packages.urllib3.packages.ssl_match_hostname")
|
| 94 |
+
vendored("requests.packages.urllib3.packages.ssl_match_hostname."
|
| 95 |
+
"_implementation")
|
| 96 |
+
vendored("requests.packages.urllib3.poolmanager")
|
| 97 |
+
vendored("requests.packages.urllib3.request")
|
| 98 |
+
vendored("requests.packages.urllib3.response")
|
| 99 |
+
vendored("requests.packages.urllib3.util")
|
| 100 |
+
vendored("requests.packages.urllib3.util.connection")
|
| 101 |
+
vendored("requests.packages.urllib3.util.request")
|
| 102 |
+
vendored("requests.packages.urllib3.util.response")
|
| 103 |
+
vendored("requests.packages.urllib3.util.retry")
|
| 104 |
+
vendored("requests.packages.urllib3.util.ssl_")
|
| 105 |
+
vendored("requests.packages.urllib3.util.timeout")
|
| 106 |
+
vendored("requests.packages.urllib3.util.url")
|
| 107 |
+
vendored("resolvelib")
|
| 108 |
+
vendored("rich")
|
| 109 |
+
vendored("rich.console")
|
| 110 |
+
vendored("rich.highlighter")
|
| 111 |
+
vendored("rich.logging")
|
| 112 |
+
vendored("rich.markup")
|
| 113 |
+
vendored("rich.progress")
|
| 114 |
+
vendored("rich.segment")
|
| 115 |
+
vendored("rich.style")
|
| 116 |
+
vendored("rich.text")
|
| 117 |
+
vendored("rich.traceback")
|
| 118 |
+
vendored("tenacity")
|
| 119 |
+
vendored("tomli")
|
| 120 |
+
vendored("truststore")
|
| 121 |
+
vendored("urllib3")
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# This library is free software; you can redistribute it and/or
|
| 3 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 4 |
+
# License as published by the Free Software Foundation; either
|
| 5 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 6 |
+
#
|
| 7 |
+
# This library is distributed in the hope that it will be useful,
|
| 8 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 10 |
+
# Lesser General Public License for more details.
|
| 11 |
+
#
|
| 12 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 13 |
+
# License along with this library; if not, write to the Free Software
|
| 14 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 15 |
+
# 02110-1301 USA
|
| 16 |
+
######################### END LICENSE BLOCK #########################
|
| 17 |
+
|
| 18 |
+
from typing import List, Union
|
| 19 |
+
|
| 20 |
+
from .charsetgroupprober import CharSetGroupProber
|
| 21 |
+
from .charsetprober import CharSetProber
|
| 22 |
+
from .enums import InputState
|
| 23 |
+
from .resultdict import ResultDict
|
| 24 |
+
from .universaldetector import UniversalDetector
|
| 25 |
+
from .version import VERSION, __version__
|
| 26 |
+
|
| 27 |
+
__all__ = ["UniversalDetector", "detect", "detect_all", "__version__", "VERSION"]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def detect(
|
| 31 |
+
byte_str: Union[bytes, bytearray], should_rename_legacy: bool = False
|
| 32 |
+
) -> ResultDict:
|
| 33 |
+
"""
|
| 34 |
+
Detect the encoding of the given byte string.
|
| 35 |
+
|
| 36 |
+
:param byte_str: The byte sequence to examine.
|
| 37 |
+
:type byte_str: ``bytes`` or ``bytearray``
|
| 38 |
+
:param should_rename_legacy: Should we rename legacy encodings
|
| 39 |
+
to their more modern equivalents?
|
| 40 |
+
:type should_rename_legacy: ``bool``
|
| 41 |
+
"""
|
| 42 |
+
if not isinstance(byte_str, bytearray):
|
| 43 |
+
if not isinstance(byte_str, bytes):
|
| 44 |
+
raise TypeError(
|
| 45 |
+
f"Expected object of type bytes or bytearray, got: {type(byte_str)}"
|
| 46 |
+
)
|
| 47 |
+
byte_str = bytearray(byte_str)
|
| 48 |
+
detector = UniversalDetector(should_rename_legacy=should_rename_legacy)
|
| 49 |
+
detector.feed(byte_str)
|
| 50 |
+
return detector.close()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def detect_all(
|
| 54 |
+
byte_str: Union[bytes, bytearray],
|
| 55 |
+
ignore_threshold: bool = False,
|
| 56 |
+
should_rename_legacy: bool = False,
|
| 57 |
+
) -> List[ResultDict]:
|
| 58 |
+
"""
|
| 59 |
+
Detect all the possible encodings of the given byte string.
|
| 60 |
+
|
| 61 |
+
:param byte_str: The byte sequence to examine.
|
| 62 |
+
:type byte_str: ``bytes`` or ``bytearray``
|
| 63 |
+
:param ignore_threshold: Include encodings that are below
|
| 64 |
+
``UniversalDetector.MINIMUM_THRESHOLD``
|
| 65 |
+
in results.
|
| 66 |
+
:type ignore_threshold: ``bool``
|
| 67 |
+
:param should_rename_legacy: Should we rename legacy encodings
|
| 68 |
+
to their more modern equivalents?
|
| 69 |
+
:type should_rename_legacy: ``bool``
|
| 70 |
+
"""
|
| 71 |
+
if not isinstance(byte_str, bytearray):
|
| 72 |
+
if not isinstance(byte_str, bytes):
|
| 73 |
+
raise TypeError(
|
| 74 |
+
f"Expected object of type bytes or bytearray, got: {type(byte_str)}"
|
| 75 |
+
)
|
| 76 |
+
byte_str = bytearray(byte_str)
|
| 77 |
+
|
| 78 |
+
detector = UniversalDetector(should_rename_legacy=should_rename_legacy)
|
| 79 |
+
detector.feed(byte_str)
|
| 80 |
+
detector.close()
|
| 81 |
+
|
| 82 |
+
if detector.input_state == InputState.HIGH_BYTE:
|
| 83 |
+
results: List[ResultDict] = []
|
| 84 |
+
probers: List[CharSetProber] = []
|
| 85 |
+
for prober in detector.charset_probers:
|
| 86 |
+
if isinstance(prober, CharSetGroupProber):
|
| 87 |
+
probers.extend(p for p in prober.probers)
|
| 88 |
+
else:
|
| 89 |
+
probers.append(prober)
|
| 90 |
+
for prober in probers:
|
| 91 |
+
if ignore_threshold or prober.get_confidence() > detector.MINIMUM_THRESHOLD:
|
| 92 |
+
charset_name = prober.charset_name or ""
|
| 93 |
+
lower_charset_name = charset_name.lower()
|
| 94 |
+
# Use Windows encoding name instead of ISO-8859 if we saw any
|
| 95 |
+
# extra Windows-specific bytes
|
| 96 |
+
if lower_charset_name.startswith("iso-8859") and detector.has_win_bytes:
|
| 97 |
+
charset_name = detector.ISO_WIN_MAP.get(
|
| 98 |
+
lower_charset_name, charset_name
|
| 99 |
+
)
|
| 100 |
+
# Rename legacy encodings with superset encodings if asked
|
| 101 |
+
if should_rename_legacy:
|
| 102 |
+
charset_name = detector.LEGACY_MAP.get(
|
| 103 |
+
charset_name.lower(), charset_name
|
| 104 |
+
)
|
| 105 |
+
results.append(
|
| 106 |
+
{
|
| 107 |
+
"encoding": charset_name,
|
| 108 |
+
"confidence": prober.get_confidence(),
|
| 109 |
+
"language": prober.language,
|
| 110 |
+
}
|
| 111 |
+
)
|
| 112 |
+
if len(results) > 0:
|
| 113 |
+
return sorted(results, key=lambda result: -result["confidence"])
|
| 114 |
+
|
| 115 |
+
return [detector.result]
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/big5prober.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import Big5DistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import BIG5_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Big5Prober(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(BIG5_SM_MODEL)
|
| 38 |
+
self.distribution_analyzer = Big5DistributionAnalysis()
|
| 39 |
+
self.reset()
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def charset_name(self) -> str:
|
| 43 |
+
return "Big5"
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def language(self) -> str:
|
| 47 |
+
return "Chinese"
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/charsetgroupprober.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from typing import List, Optional, Union
|
| 29 |
+
|
| 30 |
+
from .charsetprober import CharSetProber
|
| 31 |
+
from .enums import LanguageFilter, ProbingState
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class CharSetGroupProber(CharSetProber):
|
| 35 |
+
def __init__(self, lang_filter: LanguageFilter = LanguageFilter.NONE) -> None:
|
| 36 |
+
super().__init__(lang_filter=lang_filter)
|
| 37 |
+
self._active_num = 0
|
| 38 |
+
self.probers: List[CharSetProber] = []
|
| 39 |
+
self._best_guess_prober: Optional[CharSetProber] = None
|
| 40 |
+
|
| 41 |
+
def reset(self) -> None:
|
| 42 |
+
super().reset()
|
| 43 |
+
self._active_num = 0
|
| 44 |
+
for prober in self.probers:
|
| 45 |
+
prober.reset()
|
| 46 |
+
prober.active = True
|
| 47 |
+
self._active_num += 1
|
| 48 |
+
self._best_guess_prober = None
|
| 49 |
+
|
| 50 |
+
@property
|
| 51 |
+
def charset_name(self) -> Optional[str]:
|
| 52 |
+
if not self._best_guess_prober:
|
| 53 |
+
self.get_confidence()
|
| 54 |
+
if not self._best_guess_prober:
|
| 55 |
+
return None
|
| 56 |
+
return self._best_guess_prober.charset_name
|
| 57 |
+
|
| 58 |
+
@property
|
| 59 |
+
def language(self) -> Optional[str]:
|
| 60 |
+
if not self._best_guess_prober:
|
| 61 |
+
self.get_confidence()
|
| 62 |
+
if not self._best_guess_prober:
|
| 63 |
+
return None
|
| 64 |
+
return self._best_guess_prober.language
|
| 65 |
+
|
| 66 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 67 |
+
for prober in self.probers:
|
| 68 |
+
if not prober.active:
|
| 69 |
+
continue
|
| 70 |
+
state = prober.feed(byte_str)
|
| 71 |
+
if not state:
|
| 72 |
+
continue
|
| 73 |
+
if state == ProbingState.FOUND_IT:
|
| 74 |
+
self._best_guess_prober = prober
|
| 75 |
+
self._state = ProbingState.FOUND_IT
|
| 76 |
+
return self.state
|
| 77 |
+
if state == ProbingState.NOT_ME:
|
| 78 |
+
prober.active = False
|
| 79 |
+
self._active_num -= 1
|
| 80 |
+
if self._active_num <= 0:
|
| 81 |
+
self._state = ProbingState.NOT_ME
|
| 82 |
+
return self.state
|
| 83 |
+
return self.state
|
| 84 |
+
|
| 85 |
+
def get_confidence(self) -> float:
|
| 86 |
+
state = self.state
|
| 87 |
+
if state == ProbingState.FOUND_IT:
|
| 88 |
+
return 0.99
|
| 89 |
+
if state == ProbingState.NOT_ME:
|
| 90 |
+
return 0.01
|
| 91 |
+
best_conf = 0.0
|
| 92 |
+
self._best_guess_prober = None
|
| 93 |
+
for prober in self.probers:
|
| 94 |
+
if not prober.active:
|
| 95 |
+
self.logger.debug("%s not active", prober.charset_name)
|
| 96 |
+
continue
|
| 97 |
+
conf = prober.get_confidence()
|
| 98 |
+
self.logger.debug(
|
| 99 |
+
"%s %s confidence = %s", prober.charset_name, prober.language, conf
|
| 100 |
+
)
|
| 101 |
+
if best_conf < conf:
|
| 102 |
+
best_conf = conf
|
| 103 |
+
self._best_guess_prober = prober
|
| 104 |
+
if not self._best_guess_prober:
|
| 105 |
+
return 0.0
|
| 106 |
+
return best_conf
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/charsetprober.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
#
|
| 13 |
+
# This library is free software; you can redistribute it and/or
|
| 14 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 15 |
+
# License as published by the Free Software Foundation; either
|
| 16 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 17 |
+
#
|
| 18 |
+
# This library is distributed in the hope that it will be useful,
|
| 19 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
+
# Lesser General Public License for more details.
|
| 22 |
+
#
|
| 23 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 24 |
+
# License along with this library; if not, write to the Free Software
|
| 25 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 26 |
+
# 02110-1301 USA
|
| 27 |
+
######################### END LICENSE BLOCK #########################
|
| 28 |
+
|
| 29 |
+
import logging
|
| 30 |
+
import re
|
| 31 |
+
from typing import Optional, Union
|
| 32 |
+
|
| 33 |
+
from .enums import LanguageFilter, ProbingState
|
| 34 |
+
|
| 35 |
+
INTERNATIONAL_WORDS_PATTERN = re.compile(
|
| 36 |
+
b"[a-zA-Z]*[\x80-\xFF]+[a-zA-Z]*[^a-zA-Z\x80-\xFF]?"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class CharSetProber:
|
| 41 |
+
|
| 42 |
+
SHORTCUT_THRESHOLD = 0.95
|
| 43 |
+
|
| 44 |
+
def __init__(self, lang_filter: LanguageFilter = LanguageFilter.NONE) -> None:
|
| 45 |
+
self._state = ProbingState.DETECTING
|
| 46 |
+
self.active = True
|
| 47 |
+
self.lang_filter = lang_filter
|
| 48 |
+
self.logger = logging.getLogger(__name__)
|
| 49 |
+
|
| 50 |
+
def reset(self) -> None:
|
| 51 |
+
self._state = ProbingState.DETECTING
|
| 52 |
+
|
| 53 |
+
@property
|
| 54 |
+
def charset_name(self) -> Optional[str]:
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
@property
|
| 58 |
+
def language(self) -> Optional[str]:
|
| 59 |
+
raise NotImplementedError
|
| 60 |
+
|
| 61 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 62 |
+
raise NotImplementedError
|
| 63 |
+
|
| 64 |
+
@property
|
| 65 |
+
def state(self) -> ProbingState:
|
| 66 |
+
return self._state
|
| 67 |
+
|
| 68 |
+
def get_confidence(self) -> float:
|
| 69 |
+
return 0.0
|
| 70 |
+
|
| 71 |
+
@staticmethod
|
| 72 |
+
def filter_high_byte_only(buf: Union[bytes, bytearray]) -> bytes:
|
| 73 |
+
buf = re.sub(b"([\x00-\x7F])+", b" ", buf)
|
| 74 |
+
return buf
|
| 75 |
+
|
| 76 |
+
@staticmethod
|
| 77 |
+
def filter_international_words(buf: Union[bytes, bytearray]) -> bytearray:
|
| 78 |
+
"""
|
| 79 |
+
We define three types of bytes:
|
| 80 |
+
alphabet: english alphabets [a-zA-Z]
|
| 81 |
+
international: international characters [\x80-\xFF]
|
| 82 |
+
marker: everything else [^a-zA-Z\x80-\xFF]
|
| 83 |
+
The input buffer can be thought to contain a series of words delimited
|
| 84 |
+
by markers. This function works to filter all words that contain at
|
| 85 |
+
least one international character. All contiguous sequences of markers
|
| 86 |
+
are replaced by a single space ascii character.
|
| 87 |
+
This filter applies to all scripts which do not use English characters.
|
| 88 |
+
"""
|
| 89 |
+
filtered = bytearray()
|
| 90 |
+
|
| 91 |
+
# This regex expression filters out only words that have at-least one
|
| 92 |
+
# international character. The word may include one marker character at
|
| 93 |
+
# the end.
|
| 94 |
+
words = INTERNATIONAL_WORDS_PATTERN.findall(buf)
|
| 95 |
+
|
| 96 |
+
for word in words:
|
| 97 |
+
filtered.extend(word[:-1])
|
| 98 |
+
|
| 99 |
+
# If the last character in the word is a marker, replace it with a
|
| 100 |
+
# space as markers shouldn't affect our analysis (they are used
|
| 101 |
+
# similarly across all languages and may thus have similar
|
| 102 |
+
# frequencies).
|
| 103 |
+
last_char = word[-1:]
|
| 104 |
+
if not last_char.isalpha() and last_char < b"\x80":
|
| 105 |
+
last_char = b" "
|
| 106 |
+
filtered.extend(last_char)
|
| 107 |
+
|
| 108 |
+
return filtered
|
| 109 |
+
|
| 110 |
+
@staticmethod
|
| 111 |
+
def remove_xml_tags(buf: Union[bytes, bytearray]) -> bytes:
|
| 112 |
+
"""
|
| 113 |
+
Returns a copy of ``buf`` that retains only the sequences of English
|
| 114 |
+
alphabet and high byte characters that are not between <> characters.
|
| 115 |
+
This filter can be applied to all scripts which contain both English
|
| 116 |
+
characters and extended ASCII characters, but is currently only used by
|
| 117 |
+
``Latin1Prober``.
|
| 118 |
+
"""
|
| 119 |
+
filtered = bytearray()
|
| 120 |
+
in_tag = False
|
| 121 |
+
prev = 0
|
| 122 |
+
buf = memoryview(buf).cast("c")
|
| 123 |
+
|
| 124 |
+
for curr, buf_char in enumerate(buf):
|
| 125 |
+
# Check if we're coming out of or entering an XML tag
|
| 126 |
+
|
| 127 |
+
# https://github.com/python/typeshed/issues/8182
|
| 128 |
+
if buf_char == b">": # type: ignore[comparison-overlap]
|
| 129 |
+
prev = curr + 1
|
| 130 |
+
in_tag = False
|
| 131 |
+
# https://github.com/python/typeshed/issues/8182
|
| 132 |
+
elif buf_char == b"<": # type: ignore[comparison-overlap]
|
| 133 |
+
if curr > prev and not in_tag:
|
| 134 |
+
# Keep everything after last non-extended-ASCII,
|
| 135 |
+
# non-alphabetic character
|
| 136 |
+
filtered.extend(buf[prev:curr])
|
| 137 |
+
# Output a space to delimit stretch we kept
|
| 138 |
+
filtered.extend(b" ")
|
| 139 |
+
in_tag = True
|
| 140 |
+
|
| 141 |
+
# If we're not in a tag...
|
| 142 |
+
if not in_tag:
|
| 143 |
+
# Keep everything after last non-extended-ASCII, non-alphabetic
|
| 144 |
+
# character
|
| 145 |
+
filtered.extend(buf[prev:])
|
| 146 |
+
|
| 147 |
+
return filtered
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/codingstatemachine.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
import logging
|
| 29 |
+
|
| 30 |
+
from .codingstatemachinedict import CodingStateMachineDict
|
| 31 |
+
from .enums import MachineState
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class CodingStateMachine:
|
| 35 |
+
"""
|
| 36 |
+
A state machine to verify a byte sequence for a particular encoding. For
|
| 37 |
+
each byte the detector receives, it will feed that byte to every active
|
| 38 |
+
state machine available, one byte at a time. The state machine changes its
|
| 39 |
+
state based on its previous state and the byte it receives. There are 3
|
| 40 |
+
states in a state machine that are of interest to an auto-detector:
|
| 41 |
+
|
| 42 |
+
START state: This is the state to start with, or a legal byte sequence
|
| 43 |
+
(i.e. a valid code point) for character has been identified.
|
| 44 |
+
|
| 45 |
+
ME state: This indicates that the state machine identified a byte sequence
|
| 46 |
+
that is specific to the charset it is designed for and that
|
| 47 |
+
there is no other possible encoding which can contain this byte
|
| 48 |
+
sequence. This will to lead to an immediate positive answer for
|
| 49 |
+
the detector.
|
| 50 |
+
|
| 51 |
+
ERROR state: This indicates the state machine identified an illegal byte
|
| 52 |
+
sequence for that encoding. This will lead to an immediate
|
| 53 |
+
negative answer for this encoding. Detector will exclude this
|
| 54 |
+
encoding from consideration from here on.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
def __init__(self, sm: CodingStateMachineDict) -> None:
|
| 58 |
+
self._model = sm
|
| 59 |
+
self._curr_byte_pos = 0
|
| 60 |
+
self._curr_char_len = 0
|
| 61 |
+
self._curr_state = MachineState.START
|
| 62 |
+
self.active = True
|
| 63 |
+
self.logger = logging.getLogger(__name__)
|
| 64 |
+
self.reset()
|
| 65 |
+
|
| 66 |
+
def reset(self) -> None:
|
| 67 |
+
self._curr_state = MachineState.START
|
| 68 |
+
|
| 69 |
+
def next_state(self, c: int) -> int:
|
| 70 |
+
# for each byte we get its class
|
| 71 |
+
# if it is first byte, we also get byte length
|
| 72 |
+
byte_class = self._model["class_table"][c]
|
| 73 |
+
if self._curr_state == MachineState.START:
|
| 74 |
+
self._curr_byte_pos = 0
|
| 75 |
+
self._curr_char_len = self._model["char_len_table"][byte_class]
|
| 76 |
+
# from byte's class and state_table, we get its next state
|
| 77 |
+
curr_state = self._curr_state * self._model["class_factor"] + byte_class
|
| 78 |
+
self._curr_state = self._model["state_table"][curr_state]
|
| 79 |
+
self._curr_byte_pos += 1
|
| 80 |
+
return self._curr_state
|
| 81 |
+
|
| 82 |
+
def get_current_charlen(self) -> int:
|
| 83 |
+
return self._curr_char_len
|
| 84 |
+
|
| 85 |
+
def get_coding_state_machine(self) -> str:
|
| 86 |
+
return self._model["name"]
|
| 87 |
+
|
| 88 |
+
@property
|
| 89 |
+
def language(self) -> str:
|
| 90 |
+
return self._model["language"]
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/codingstatemachinedict.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TYPE_CHECKING, Tuple
|
| 2 |
+
|
| 3 |
+
if TYPE_CHECKING:
|
| 4 |
+
# TypedDict was introduced in Python 3.8.
|
| 5 |
+
#
|
| 6 |
+
# TODO: Remove the else block and TYPE_CHECKING check when dropping support
|
| 7 |
+
# for Python 3.7.
|
| 8 |
+
from typing import TypedDict
|
| 9 |
+
|
| 10 |
+
class CodingStateMachineDict(TypedDict, total=False):
|
| 11 |
+
class_table: Tuple[int, ...]
|
| 12 |
+
class_factor: int
|
| 13 |
+
state_table: Tuple[int, ...]
|
| 14 |
+
char_len_table: Tuple[int, ...]
|
| 15 |
+
name: str
|
| 16 |
+
language: str # Optional key
|
| 17 |
+
|
| 18 |
+
else:
|
| 19 |
+
CodingStateMachineDict = dict
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/cp949prober.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import EUCKRDistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import CP949_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class CP949Prober(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(CP949_SM_MODEL)
|
| 38 |
+
# NOTE: CP949 is a superset of EUC-KR, so the distribution should be
|
| 39 |
+
# not different.
|
| 40 |
+
self.distribution_analyzer = EUCKRDistributionAnalysis()
|
| 41 |
+
self.reset()
|
| 42 |
+
|
| 43 |
+
@property
|
| 44 |
+
def charset_name(self) -> str:
|
| 45 |
+
return "CP949"
|
| 46 |
+
|
| 47 |
+
@property
|
| 48 |
+
def language(self) -> str:
|
| 49 |
+
return "Korean"
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/escsm.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .codingstatemachinedict import CodingStateMachineDict
|
| 29 |
+
from .enums import MachineState
|
| 30 |
+
|
| 31 |
+
# fmt: off
|
| 32 |
+
HZ_CLS = (
|
| 33 |
+
1, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 34 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 08 - 0f
|
| 35 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 10 - 17
|
| 36 |
+
0, 0, 0, 1, 0, 0, 0, 0, # 18 - 1f
|
| 37 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 20 - 27
|
| 38 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 28 - 2f
|
| 39 |
+
0, 0, 0, 0, 0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, 1, 1, 1, 1, 1, # f8 - ff
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
HZ_ST = (
|
| 68 |
+
MachineState.START, MachineState.ERROR, 3, MachineState.START, MachineState.START, MachineState.START, MachineState.ERROR, MachineState.ERROR, # 00-07
|
| 69 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 08-0f
|
| 70 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.START, MachineState.START, 4, MachineState.ERROR, # 10-17
|
| 71 |
+
5, MachineState.ERROR, 6, MachineState.ERROR, 5, 5, 4, MachineState.ERROR, # 18-1f
|
| 72 |
+
4, MachineState.ERROR, 4, 4, 4, MachineState.ERROR, 4, MachineState.ERROR, # 20-27
|
| 73 |
+
4, MachineState.ITS_ME, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 28-2f
|
| 74 |
+
)
|
| 75 |
+
# fmt: on
|
| 76 |
+
|
| 77 |
+
HZ_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0)
|
| 78 |
+
|
| 79 |
+
HZ_SM_MODEL: CodingStateMachineDict = {
|
| 80 |
+
"class_table": HZ_CLS,
|
| 81 |
+
"class_factor": 6,
|
| 82 |
+
"state_table": HZ_ST,
|
| 83 |
+
"char_len_table": HZ_CHAR_LEN_TABLE,
|
| 84 |
+
"name": "HZ-GB-2312",
|
| 85 |
+
"language": "Chinese",
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
# fmt: off
|
| 89 |
+
ISO2022CN_CLS = (
|
| 90 |
+
2, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 91 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 08 - 0f
|
| 92 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 10 - 17
|
| 93 |
+
0, 0, 0, 1, 0, 0, 0, 0, # 18 - 1f
|
| 94 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 20 - 27
|
| 95 |
+
0, 3, 0, 0, 0, 0, 0, 0, # 28 - 2f
|
| 96 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 30 - 37
|
| 97 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 38 - 3f
|
| 98 |
+
0, 0, 0, 4, 0, 0, 0, 0, # 40 - 47
|
| 99 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 48 - 4f
|
| 100 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 50 - 57
|
| 101 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 58 - 5f
|
| 102 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 60 - 67
|
| 103 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 68 - 6f
|
| 104 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 70 - 77
|
| 105 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 78 - 7f
|
| 106 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 80 - 87
|
| 107 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 88 - 8f
|
| 108 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 90 - 97
|
| 109 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 98 - 9f
|
| 110 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a0 - a7
|
| 111 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a8 - af
|
| 112 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b0 - b7
|
| 113 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b8 - bf
|
| 114 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c0 - c7
|
| 115 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c8 - cf
|
| 116 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d0 - d7
|
| 117 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d8 - df
|
| 118 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e0 - e7
|
| 119 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e8 - ef
|
| 120 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f0 - f7
|
| 121 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f8 - ff
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
ISO2022CN_ST = (
|
| 125 |
+
MachineState.START, 3, MachineState.ERROR, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 00-07
|
| 126 |
+
MachineState.START, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 08-0f
|
| 127 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 10-17
|
| 128 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 4, MachineState.ERROR, # 18-1f
|
| 129 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 20-27
|
| 130 |
+
5, 6, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 28-2f
|
| 131 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 30-37
|
| 132 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.START, # 38-3f
|
| 133 |
+
)
|
| 134 |
+
# fmt: on
|
| 135 |
+
|
| 136 |
+
ISO2022CN_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0, 0, 0, 0)
|
| 137 |
+
|
| 138 |
+
ISO2022CN_SM_MODEL: CodingStateMachineDict = {
|
| 139 |
+
"class_table": ISO2022CN_CLS,
|
| 140 |
+
"class_factor": 9,
|
| 141 |
+
"state_table": ISO2022CN_ST,
|
| 142 |
+
"char_len_table": ISO2022CN_CHAR_LEN_TABLE,
|
| 143 |
+
"name": "ISO-2022-CN",
|
| 144 |
+
"language": "Chinese",
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
# fmt: off
|
| 148 |
+
ISO2022JP_CLS = (
|
| 149 |
+
2, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 150 |
+
0, 0, 0, 0, 0, 0, 2, 2, # 08 - 0f
|
| 151 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 10 - 17
|
| 152 |
+
0, 0, 0, 1, 0, 0, 0, 0, # 18 - 1f
|
| 153 |
+
0, 0, 0, 0, 7, 0, 0, 0, # 20 - 27
|
| 154 |
+
3, 0, 0, 0, 0, 0, 0, 0, # 28 - 2f
|
| 155 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 30 - 37
|
| 156 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 38 - 3f
|
| 157 |
+
6, 0, 4, 0, 8, 0, 0, 0, # 40 - 47
|
| 158 |
+
0, 9, 5, 0, 0, 0, 0, 0, # 48 - 4f
|
| 159 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 50 - 57
|
| 160 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 58 - 5f
|
| 161 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 60 - 67
|
| 162 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 68 - 6f
|
| 163 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 70 - 77
|
| 164 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 78 - 7f
|
| 165 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 80 - 87
|
| 166 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 88 - 8f
|
| 167 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 90 - 97
|
| 168 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 98 - 9f
|
| 169 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a0 - a7
|
| 170 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a8 - af
|
| 171 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b0 - b7
|
| 172 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b8 - bf
|
| 173 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c0 - c7
|
| 174 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c8 - cf
|
| 175 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d0 - d7
|
| 176 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d8 - df
|
| 177 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e0 - e7
|
| 178 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e8 - ef
|
| 179 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f0 - f7
|
| 180 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f8 - ff
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
ISO2022JP_ST = (
|
| 184 |
+
MachineState.START, 3, MachineState.ERROR, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 00-07
|
| 185 |
+
MachineState.START, MachineState.START, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 08-0f
|
| 186 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 10-17
|
| 187 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, # 18-1f
|
| 188 |
+
MachineState.ERROR, 5, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 4, MachineState.ERROR, MachineState.ERROR, # 20-27
|
| 189 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 6, MachineState.ITS_ME, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, # 28-2f
|
| 190 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, # 30-37
|
| 191 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 38-3f
|
| 192 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.START, MachineState.START, # 40-47
|
| 193 |
+
)
|
| 194 |
+
# fmt: on
|
| 195 |
+
|
| 196 |
+
ISO2022JP_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
| 197 |
+
|
| 198 |
+
ISO2022JP_SM_MODEL: CodingStateMachineDict = {
|
| 199 |
+
"class_table": ISO2022JP_CLS,
|
| 200 |
+
"class_factor": 10,
|
| 201 |
+
"state_table": ISO2022JP_ST,
|
| 202 |
+
"char_len_table": ISO2022JP_CHAR_LEN_TABLE,
|
| 203 |
+
"name": "ISO-2022-JP",
|
| 204 |
+
"language": "Japanese",
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
# fmt: off
|
| 208 |
+
ISO2022KR_CLS = (
|
| 209 |
+
2, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 210 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 08 - 0f
|
| 211 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 10 - 17
|
| 212 |
+
0, 0, 0, 1, 0, 0, 0, 0, # 18 - 1f
|
| 213 |
+
0, 0, 0, 0, 3, 0, 0, 0, # 20 - 27
|
| 214 |
+
0, 4, 0, 0, 0, 0, 0, 0, # 28 - 2f
|
| 215 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 30 - 37
|
| 216 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 38 - 3f
|
| 217 |
+
0, 0, 0, 5, 0, 0, 0, 0, # 40 - 47
|
| 218 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 48 - 4f
|
| 219 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 50 - 57
|
| 220 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 58 - 5f
|
| 221 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 60 - 67
|
| 222 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 68 - 6f
|
| 223 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 70 - 77
|
| 224 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 78 - 7f
|
| 225 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 80 - 87
|
| 226 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 88 - 8f
|
| 227 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 90 - 97
|
| 228 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 98 - 9f
|
| 229 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a0 - a7
|
| 230 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a8 - af
|
| 231 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b0 - b7
|
| 232 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b8 - bf
|
| 233 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c0 - c7
|
| 234 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c8 - cf
|
| 235 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d0 - d7
|
| 236 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d8 - df
|
| 237 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e0 - e7
|
| 238 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e8 - ef
|
| 239 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f0 - f7
|
| 240 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f8 - ff
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
ISO2022KR_ST = (
|
| 244 |
+
MachineState.START, 3, MachineState.ERROR, MachineState.START, MachineState.START, MachineState.START, MachineState.ERROR, MachineState.ERROR, # 00-07
|
| 245 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 08-0f
|
| 246 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 4, MachineState.ERROR, MachineState.ERROR, # 10-17
|
| 247 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 5, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 18-1f
|
| 248 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 20-27
|
| 249 |
+
)
|
| 250 |
+
# fmt: on
|
| 251 |
+
|
| 252 |
+
ISO2022KR_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0)
|
| 253 |
+
|
| 254 |
+
ISO2022KR_SM_MODEL: CodingStateMachineDict = {
|
| 255 |
+
"class_table": ISO2022KR_CLS,
|
| 256 |
+
"class_factor": 6,
|
| 257 |
+
"state_table": ISO2022KR_ST,
|
| 258 |
+
"char_len_table": ISO2022KR_CHAR_LEN_TABLE,
|
| 259 |
+
"name": "ISO-2022-KR",
|
| 260 |
+
"language": "Korean",
|
| 261 |
+
}
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/langgreekmodel.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/langrussianmodel.py
ADDED
|
The diff for this file is too large to render.
See raw diff
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 14 |
+
29: 0, # 'E'
|
| 15 |
+
52: 0, # 'F'
|
| 16 |
+
36: 0, # 'G'
|
| 17 |
+
45: 0, # 'H'
|
| 18 |
+
53: 0, # 'I'
|
| 19 |
+
60: 0, # 'J'
|
| 20 |
+
16: 0, # 'K'
|
| 21 |
+
49: 0, # 'L'
|
| 22 |
+
20: 0, # 'M'
|
| 23 |
+
46: 0, # 'N'
|
| 24 |
+
42: 0, # 'O'
|
| 25 |
+
48: 0, # 'P'
|
| 26 |
+
44: 0, # 'R'
|
| 27 |
+
35: 0, # 'S'
|
| 28 |
+
31: 0, # 'T'
|
| 29 |
+
51: 0, # 'U'
|
| 30 |
+
38: 0, # 'V'
|
| 31 |
+
62: 0, # 'W'
|
| 32 |
+
43: 0, # 'Y'
|
| 33 |
+
56: 0, # 'Z'
|
| 34 |
+
1: 3, # 'a'
|
| 35 |
+
21: 0, # 'b'
|
| 36 |
+
28: 0, # 'c'
|
| 37 |
+
12: 2, # 'd'
|
| 38 |
+
2: 3, # 'e'
|
| 39 |
+
18: 0, # 'f'
|
| 40 |
+
27: 1, # 'g'
|
| 41 |
+
25: 1, # 'h'
|
| 42 |
+
3: 1, # 'i'
|
| 43 |
+
24: 0, # 'j'
|
| 44 |
+
10: 2, # 'k'
|
| 45 |
+
5: 1, # 'l'
|
| 46 |
+
13: 1, # 'm'
|
| 47 |
+
4: 1, # 'n'
|
| 48 |
+
15: 0, # 'o'
|
| 49 |
+
26: 0, # 'p'
|
| 50 |
+
7: 1, # 'r'
|
| 51 |
+
8: 1, # 's'
|
| 52 |
+
9: 1, # 't'
|
| 53 |
+
14: 1, # 'u'
|
| 54 |
+
32: 0, # 'v'
|
| 55 |
+
57: 0, # 'w'
|
| 56 |
+
58: 0, # 'x'
|
| 57 |
+
11: 3, # 'y'
|
| 58 |
+
22: 0, # 'z'
|
| 59 |
+
63: 0, # '·'
|
| 60 |
+
54: 0, # 'Ç'
|
| 61 |
+
50: 0, # 'Ö'
|
| 62 |
+
55: 0, # 'Ü'
|
| 63 |
+
59: 0, # 'â'
|
| 64 |
+
33: 1, # 'ç'
|
| 65 |
+
61: 0, # 'î'
|
| 66 |
+
34: 0, # 'ö'
|
| 67 |
+
17: 0, # 'ü'
|
| 68 |
+
30: 0, # 'ğ'
|
| 69 |
+
41: 0, # 'İ'
|
| 70 |
+
6: 0, # 'ı'
|
| 71 |
+
40: 0, # 'Ş'
|
| 72 |
+
19: 0, # 'ş'
|
| 73 |
+
},
|
| 74 |
+
37: { # 'B'
|
| 75 |
+
23: 0, # 'A'
|
| 76 |
+
37: 0, # 'B'
|
| 77 |
+
47: 2, # 'C'
|
| 78 |
+
39: 0, # 'D'
|
| 79 |
+
29: 0, # 'E'
|
| 80 |
+
52: 2, # 'F'
|
| 81 |
+
36: 0, # 'G'
|
| 82 |
+
45: 0, # 'H'
|
| 83 |
+
53: 0, # 'I'
|
| 84 |
+
60: 0, # 'J'
|
| 85 |
+
16: 1, # 'K'
|
| 86 |
+
49: 0, # 'L'
|
| 87 |
+
20: 0, # 'M'
|
| 88 |
+
46: 0, # 'N'
|
| 89 |
+
42: 0, # 'O'
|
| 90 |
+
48: 1, # 'P'
|
| 91 |
+
44: 0, # 'R'
|
| 92 |
+
35: 1, # 'S'
|
| 93 |
+
31: 0, # 'T'
|
| 94 |
+
51: 0, # 'U'
|
| 95 |
+
38: 1, # 'V'
|
| 96 |
+
62: 0, # 'W'
|
| 97 |
+
43: 1, # 'Y'
|
| 98 |
+
56: 0, # 'Z'
|
| 99 |
+
1: 2, # 'a'
|
| 100 |
+
21: 0, # 'b'
|
| 101 |
+
28: 2, # 'c'
|
| 102 |
+
12: 0, # 'd'
|
| 103 |
+
2: 3, # 'e'
|
| 104 |
+
18: 0, # 'f'
|
| 105 |
+
27: 0, # 'g'
|
| 106 |
+
25: 0, # 'h'
|
| 107 |
+
3: 0, # 'i'
|
| 108 |
+
24: 0, # 'j'
|
| 109 |
+
10: 0, # 'k'
|
| 110 |
+
5: 0, # 'l'
|
| 111 |
+
13: 1, # 'm'
|
| 112 |
+
4: 1, # 'n'
|
| 113 |
+
15: 0, # 'o'
|
| 114 |
+
26: 0, # 'p'
|
| 115 |
+
7: 0, # 'r'
|
| 116 |
+
8: 0, # 's'
|
| 117 |
+
9: 0, # 't'
|
| 118 |
+
14: 2, # 'u'
|
| 119 |
+
32: 0, # 'v'
|
| 120 |
+
57: 0, # 'w'
|
| 121 |
+
58: 0, # 'x'
|
| 122 |
+
11: 0, # 'y'
|
| 123 |
+
22: 1, # 'z'
|
| 124 |
+
63: 0, # '·'
|
| 125 |
+
54: 0, # 'Ç'
|
| 126 |
+
50: 1, # 'Ö'
|
| 127 |
+
55: 0, # 'Ü'
|
| 128 |
+
59: 0, # 'â'
|
| 129 |
+
33: 0, # 'ç'
|
| 130 |
+
61: 0, # 'î'
|
| 131 |
+
34: 1, # 'ö'
|
| 132 |
+
17: 0, # 'ü'
|
| 133 |
+
30: 0, # 'ğ'
|
| 134 |
+
41: 0, # 'İ'
|
| 135 |
+
6: 0, # 'ı'
|
| 136 |
+
40: 1, # 'Ş'
|
| 137 |
+
19: 1, # 'ş'
|
| 138 |
+
},
|
| 139 |
+
47: { # 'C'
|
| 140 |
+
23: 0, # 'A'
|
| 141 |
+
37: 0, # 'B'
|
| 142 |
+
47: 0, # 'C'
|
| 143 |
+
39: 0, # 'D'
|
| 144 |
+
29: 0, # 'E'
|
| 145 |
+
52: 1, # 'F'
|
| 146 |
+
36: 0, # 'G'
|
| 147 |
+
45: 0, # 'H'
|
| 148 |
+
53: 0, # 'I'
|
| 149 |
+
60: 0, # 'J'
|
| 150 |
+
16: 0, # 'K'
|
| 151 |
+
49: 1, # 'L'
|
| 152 |
+
20: 0, # 'M'
|
| 153 |
+
46: 1, # 'N'
|
| 154 |
+
42: 0, # 'O'
|
| 155 |
+
48: 1, # 'P'
|
| 156 |
+
44: 1, # 'R'
|
| 157 |
+
35: 0, # 'S'
|
| 158 |
+
31: 0, # 'T'
|
| 159 |
+
51: 0, # 'U'
|
| 160 |
+
38: 1, # 'V'
|
| 161 |
+
62: 0, # 'W'
|
| 162 |
+
43: 1, # 'Y'
|
| 163 |
+
56: 0, # 'Z'
|
| 164 |
+
1: 3, # 'a'
|
| 165 |
+
21: 0, # 'b'
|
| 166 |
+
28: 2, # 'c'
|
| 167 |
+
12: 0, # 'd'
|
| 168 |
+
2: 3, # 'e'
|
| 169 |
+
18: 0, # 'f'
|
| 170 |
+
27: 0, # 'g'
|
| 171 |
+
25: 0, # 'h'
|
| 172 |
+
3: 0, # 'i'
|
| 173 |
+
24: 2, # 'j'
|
| 174 |
+
10: 1, # 'k'
|
| 175 |
+
5: 2, # 'l'
|
| 176 |
+
13: 2, # 'm'
|
| 177 |
+
4: 2, # 'n'
|
| 178 |
+
15: 1, # 'o'
|
| 179 |
+
26: 0, # 'p'
|
| 180 |
+
7: 2, # 'r'
|
| 181 |
+
8: 0, # 's'
|
| 182 |
+
9: 0, # 't'
|
| 183 |
+
14: 3, # 'u'
|
| 184 |
+
32: 0, # 'v'
|
| 185 |
+
57: 0, # 'w'
|
| 186 |
+
58: 0, # 'x'
|
| 187 |
+
11: 0, # 'y'
|
| 188 |
+
22: 2, # 'z'
|
| 189 |
+
63: 0, # '·'
|
| 190 |
+
54: 0, # 'Ç'
|
| 191 |
+
50: 1, # 'Ö'
|
| 192 |
+
55: 0, # 'Ü'
|
| 193 |
+
59: 0, # 'â'
|
| 194 |
+
33: 1, # 'ç'
|
| 195 |
+
61: 0, # 'î'
|
| 196 |
+
34: 1, # 'ö'
|
| 197 |
+
17: 0, # 'ü'
|
| 198 |
+
30: 0, # 'ğ'
|
| 199 |
+
41: 1, # 'İ'
|
| 200 |
+
6: 3, # 'ı'
|
| 201 |
+
40: 0, # 'Ş'
|
| 202 |
+
19: 0, # 'ş'
|
| 203 |
+
},
|
| 204 |
+
39: { # 'D'
|
| 205 |
+
23: 0, # 'A'
|
| 206 |
+
37: 0, # 'B'
|
| 207 |
+
47: 0, # 'C'
|
| 208 |
+
39: 0, # 'D'
|
| 209 |
+
29: 0, # 'E'
|
| 210 |
+
52: 1, # 'F'
|
| 211 |
+
36: 0, # 'G'
|
| 212 |
+
45: 0, # 'H'
|
| 213 |
+
53: 0, # 'I'
|
| 214 |
+
60: 0, # 'J'
|
| 215 |
+
16: 1, # 'K'
|
| 216 |
+
49: 0, # 'L'
|
| 217 |
+
20: 0, # 'M'
|
| 218 |
+
46: 0, # 'N'
|
| 219 |
+
42: 0, # 'O'
|
| 220 |
+
48: 1, # 'P'
|
| 221 |
+
44: 0, # 'R'
|
| 222 |
+
35: 0, # 'S'
|
| 223 |
+
31: 0, # 'T'
|
| 224 |
+
51: 0, # 'U'
|
| 225 |
+
38: 0, # 'V'
|
| 226 |
+
62: 0, # 'W'
|
| 227 |
+
43: 0, # 'Y'
|
| 228 |
+
56: 0, # 'Z'
|
| 229 |
+
1: 2, # 'a'
|
| 230 |
+
21: 0, # 'b'
|
| 231 |
+
28: 2, # 'c'
|
| 232 |
+
12: 0, # 'd'
|
| 233 |
+
2: 2, # 'e'
|
| 234 |
+
18: 0, # 'f'
|
| 235 |
+
27: 0, # 'g'
|
| 236 |
+
25: 0, # 'h'
|
| 237 |
+
3: 0, # 'i'
|
| 238 |
+
24: 0, # 'j'
|
| 239 |
+
10: 0, # 'k'
|
| 240 |
+
5: 1, # 'l'
|
| 241 |
+
13: 3, # 'm'
|
| 242 |
+
4: 0, # 'n'
|
| 243 |
+
15: 1, # 'o'
|
| 244 |
+
26: 0, # 'p'
|
| 245 |
+
7: 0, # 'r'
|
| 246 |
+
8: 0, # 's'
|
| 247 |
+
9: 0, # 't'
|
| 248 |
+
14: 1, # 'u'
|
| 249 |
+
32: 0, # 'v'
|
| 250 |
+
57: 0, # 'w'
|
| 251 |
+
58: 0, # 'x'
|
| 252 |
+
11: 0, # 'y'
|
| 253 |
+
22: 1, # 'z'
|
| 254 |
+
63: 0, # '·'
|
| 255 |
+
54: 1, # 'Ç'
|
| 256 |
+
50: 0, # 'Ö'
|
| 257 |
+
55: 0, # 'Ü'
|
| 258 |
+
59: 0, # 'â'
|
| 259 |
+
33: 1, # 'ç'
|
| 260 |
+
61: 0, # 'î'
|
| 261 |
+
34: 0, # 'ö'
|
| 262 |
+
17: 0, # 'ü'
|
| 263 |
+
30: 1, # 'ğ'
|
| 264 |
+
41: 0, # 'İ'
|
| 265 |
+
6: 1, # 'ı'
|
| 266 |
+
40: 1, # 'Ş'
|
| 267 |
+
19: 0, # 'ş'
|
| 268 |
+
},
|
| 269 |
+
29: { # 'E'
|
| 270 |
+
23: 0, # 'A'
|
| 271 |
+
37: 0, # 'B'
|
| 272 |
+
47: 0, # 'C'
|
| 273 |
+
39: 0, # 'D'
|
| 274 |
+
29: 1, # 'E'
|
| 275 |
+
52: 0, # 'F'
|
| 276 |
+
36: 0, # 'G'
|
| 277 |
+
45: 0, # 'H'
|
| 278 |
+
53: 0, # 'I'
|
| 279 |
+
60: 0, # 'J'
|
| 280 |
+
16: 3, # 'K'
|
| 281 |
+
49: 0, # 'L'
|
| 282 |
+
20: 1, # 'M'
|
| 283 |
+
46: 0, # 'N'
|
| 284 |
+
42: 0, # 'O'
|
| 285 |
+
48: 0, # 'P'
|
| 286 |
+
44: 0, # 'R'
|
| 287 |
+
35: 0, # 'S'
|
| 288 |
+
31: 0, # 'T'
|
| 289 |
+
51: 0, # 'U'
|
| 290 |
+
38: 0, # 'V'
|
| 291 |
+
62: 0, # 'W'
|
| 292 |
+
43: 0, # 'Y'
|
| 293 |
+
56: 0, # 'Z'
|
| 294 |
+
1: 3, # 'a'
|
| 295 |
+
21: 0, # 'b'
|
| 296 |
+
28: 0, # 'c'
|
| 297 |
+
12: 2, # 'd'
|
| 298 |
+
2: 3, # 'e'
|
| 299 |
+
18: 0, # 'f'
|
| 300 |
+
27: 1, # 'g'
|
| 301 |
+
25: 0, # 'h'
|
| 302 |
+
3: 1, # 'i'
|
| 303 |
+
24: 1, # 'j'
|
| 304 |
+
10: 0, # 'k'
|
| 305 |
+
5: 3, # 'l'
|
| 306 |
+
13: 3, # 'm'
|
| 307 |
+
4: 3, # 'n'
|
| 308 |
+
15: 0, # 'o'
|
| 309 |
+
26: 0, # 'p'
|
| 310 |
+
7: 0, # 'r'
|
| 311 |
+
8: 1, # 's'
|
| 312 |
+
9: 1, # 't'
|
| 313 |
+
14: 1, # 'u'
|
| 314 |
+
32: 1, # 'v'
|
| 315 |
+
57: 0, # 'w'
|
| 316 |
+
58: 0, # 'x'
|
| 317 |
+
11: 2, # 'y'
|
| 318 |
+
22: 0, # 'z'
|
| 319 |
+
63: 0, # '·'
|
| 320 |
+
54: 0, # 'Ç'
|
| 321 |
+
50: 0, # 'Ö'
|
| 322 |
+
55: 0, # 'Ü'
|
| 323 |
+
59: 0, # 'â'
|
| 324 |
+
33: 0, # 'ç'
|
| 325 |
+
61: 0, # 'î'
|
| 326 |
+
34: 0, # 'ö'
|
| 327 |
+
17: 0, # 'ü'
|
| 328 |
+
30: 0, # 'ğ'
|
| 329 |
+
41: 0, # 'İ'
|
| 330 |
+
6: 3, # 'ı'
|
| 331 |
+
40: 0, # 'Ş'
|
| 332 |
+
19: 0, # 'ş'
|
| 333 |
+
},
|
| 334 |
+
52: { # 'F'
|
| 335 |
+
23: 0, # 'A'
|
| 336 |
+
37: 1, # 'B'
|
| 337 |
+
47: 1, # 'C'
|
| 338 |
+
39: 1, # 'D'
|
| 339 |
+
29: 1, # 'E'
|
| 340 |
+
52: 2, # 'F'
|
| 341 |
+
36: 0, # 'G'
|
| 342 |
+
45: 2, # 'H'
|
| 343 |
+
53: 1, # 'I'
|
| 344 |
+
60: 0, # 'J'
|
| 345 |
+
16: 0, # 'K'
|
| 346 |
+
49: 0, # 'L'
|
| 347 |
+
20: 1, # 'M'
|
| 348 |
+
46: 1, # 'N'
|
| 349 |
+
42: 1, # 'O'
|
| 350 |
+
48: 2, # 'P'
|
| 351 |
+
44: 1, # 'R'
|
| 352 |
+
35: 1, # 'S'
|
| 353 |
+
31: 1, # 'T'
|
| 354 |
+
51: 1, # 'U'
|
| 355 |
+
38: 1, # 'V'
|
| 356 |
+
62: 0, # 'W'
|
| 357 |
+
43: 2, # 'Y'
|
| 358 |
+
56: 0, # 'Z'
|
| 359 |
+
1: 0, # 'a'
|
| 360 |
+
21: 1, # 'b'
|
| 361 |
+
28: 1, # 'c'
|
| 362 |
+
12: 1, # 'd'
|
| 363 |
+
2: 0, # 'e'
|
| 364 |
+
18: 1, # 'f'
|
| 365 |
+
27: 0, # 'g'
|
| 366 |
+
25: 0, # 'h'
|
| 367 |
+
3: 2, # 'i'
|
| 368 |
+
24: 1, # 'j'
|
| 369 |
+
10: 0, # 'k'
|
| 370 |
+
5: 0, # 'l'
|
| 371 |
+
13: 1, # 'm'
|
| 372 |
+
4: 2, # 'n'
|
| 373 |
+
15: 1, # 'o'
|
| 374 |
+
26: 0, # 'p'
|
| 375 |
+
7: 2, # 'r'
|
| 376 |
+
8: 1, # 's'
|
| 377 |
+
9: 1, # 't'
|
| 378 |
+
14: 1, # 'u'
|
| 379 |
+
32: 0, # 'v'
|
| 380 |
+
57: 0, # 'w'
|
| 381 |
+
58: 0, # 'x'
|
| 382 |
+
11: 1, # 'y'
|
| 383 |
+
22: 1, # 'z'
|
| 384 |
+
63: 0, # '·'
|
| 385 |
+
54: 0, # 'Ç'
|
| 386 |
+
50: 1, # 'Ö'
|
| 387 |
+
55: 2, # 'Ü'
|
| 388 |
+
59: 0, # 'â'
|
| 389 |
+
33: 0, # 'ç'
|
| 390 |
+
61: 0, # 'î'
|
| 391 |
+
34: 2, # 'ö'
|
| 392 |
+
17: 0, # 'ü'
|
| 393 |
+
30: 1, # 'ğ'
|
| 394 |
+
41: 1, # 'İ'
|
| 395 |
+
6: 2, # 'ı'
|
| 396 |
+
40: 0, # 'Ş'
|
| 397 |
+
19: 2, # 'ş'
|
| 398 |
+
},
|
| 399 |
+
36: { # 'G'
|
| 400 |
+
23: 1, # 'A'
|
| 401 |
+
37: 0, # 'B'
|
| 402 |
+
47: 1, # 'C'
|
| 403 |
+
39: 0, # 'D'
|
| 404 |
+
29: 0, # 'E'
|
| 405 |
+
52: 1, # 'F'
|
| 406 |
+
36: 2, # 'G'
|
| 407 |
+
45: 0, # 'H'
|
| 408 |
+
53: 0, # 'I'
|
| 409 |
+
60: 0, # 'J'
|
| 410 |
+
16: 2, # 'K'
|
| 411 |
+
49: 0, # 'L'
|
| 412 |
+
20: 0, # 'M'
|
| 413 |
+
46: 2, # 'N'
|
| 414 |
+
42: 1, # 'O'
|
| 415 |
+
48: 1, # 'P'
|
| 416 |
+
44: 1, # 'R'
|
| 417 |
+
35: 1, # 'S'
|
| 418 |
+
31: 0, # 'T'
|
| 419 |
+
51: 1, # 'U'
|
| 420 |
+
38: 2, # 'V'
|
| 421 |
+
62: 0, # 'W'
|
| 422 |
+
43: 0, # 'Y'
|
| 423 |
+
56: 0, # 'Z'
|
| 424 |
+
1: 3, # 'a'
|
| 425 |
+
21: 0, # 'b'
|
| 426 |
+
28: 1, # 'c'
|
| 427 |
+
12: 0, # 'd'
|
| 428 |
+
2: 3, # 'e'
|
| 429 |
+
18: 0, # 'f'
|
| 430 |
+
27: 0, # 'g'
|
| 431 |
+
25: 0, # 'h'
|
| 432 |
+
3: 0, # 'i'
|
| 433 |
+
24: 1, # 'j'
|
| 434 |
+
10: 1, # 'k'
|
| 435 |
+
5: 0, # 'l'
|
| 436 |
+
13: 3, # 'm'
|
| 437 |
+
4: 2, # 'n'
|
| 438 |
+
15: 0, # 'o'
|
| 439 |
+
26: 1, # 'p'
|
| 440 |
+
7: 0, # 'r'
|
| 441 |
+
8: 1, # 's'
|
| 442 |
+
9: 1, # 't'
|
| 443 |
+
14: 3, # 'u'
|
| 444 |
+
32: 0, # 'v'
|
| 445 |
+
57: 0, # 'w'
|
| 446 |
+
58: 1, # 'x'
|
| 447 |
+
11: 0, # 'y'
|
| 448 |
+
22: 2, # 'z'
|
| 449 |
+
63: 0, # '·'
|
| 450 |
+
54: 1, # 'Ç'
|
| 451 |
+
50: 2, # 'Ö'
|
| 452 |
+
55: 0, # 'Ü'
|
| 453 |
+
59: 1, # 'â'
|
| 454 |
+
33: 2, # 'ç'
|
| 455 |
+
61: 0, # 'î'
|
| 456 |
+
34: 0, # 'ö'
|
| 457 |
+
17: 0, # 'ü'
|
| 458 |
+
30: 1, # 'ğ'
|
| 459 |
+
41: 1, # 'İ'
|
| 460 |
+
6: 2, # 'ı'
|
| 461 |
+
40: 2, # 'Ş'
|
| 462 |
+
19: 1, # 'ş'
|
| 463 |
+
},
|
| 464 |
+
45: { # 'H'
|
| 465 |
+
23: 0, # 'A'
|
| 466 |
+
37: 1, # 'B'
|
| 467 |
+
47: 0, # 'C'
|
| 468 |
+
39: 0, # 'D'
|
| 469 |
+
29: 0, # 'E'
|
| 470 |
+
52: 2, # 'F'
|
| 471 |
+
36: 2, # 'G'
|
| 472 |
+
45: 1, # 'H'
|
| 473 |
+
53: 1, # 'I'
|
| 474 |
+
60: 0, # 'J'
|
| 475 |
+
16: 2, # 'K'
|
| 476 |
+
49: 1, # 'L'
|
| 477 |
+
20: 0, # 'M'
|
| 478 |
+
46: 1, # 'N'
|
| 479 |
+
42: 1, # 'O'
|
| 480 |
+
48: 1, # 'P'
|
| 481 |
+
44: 0, # 'R'
|
| 482 |
+
35: 2, # 'S'
|
| 483 |
+
31: 0, # 'T'
|
| 484 |
+
51: 1, # 'U'
|
| 485 |
+
38: 2, # 'V'
|
| 486 |
+
62: 0, # 'W'
|
| 487 |
+
43: 0, # 'Y'
|
| 488 |
+
56: 0, # 'Z'
|
| 489 |
+
1: 3, # 'a'
|
| 490 |
+
21: 0, # 'b'
|
| 491 |
+
28: 2, # 'c'
|
| 492 |
+
12: 0, # 'd'
|
| 493 |
+
2: 3, # 'e'
|
| 494 |
+
18: 0, # 'f'
|
| 495 |
+
27: 0, # 'g'
|
| 496 |
+
25: 0, # 'h'
|
| 497 |
+
3: 2, # 'i'
|
| 498 |
+
24: 0, # 'j'
|
| 499 |
+
10: 1, # 'k'
|
| 500 |
+
5: 0, # 'l'
|
| 501 |
+
13: 2, # 'm'
|
| 502 |
+
4: 0, # 'n'
|
| 503 |
+
15: 1, # 'o'
|
| 504 |
+
26: 1, # 'p'
|
| 505 |
+
7: 1, # 'r'
|
| 506 |
+
8: 0, # 's'
|
| 507 |
+
9: 0, # 't'
|
| 508 |
+
14: 3, # 'u'
|
| 509 |
+
32: 0, # 'v'
|
| 510 |
+
57: 0, # 'w'
|
| 511 |
+
58: 0, # 'x'
|
| 512 |
+
11: 0, # 'y'
|
| 513 |
+
22: 2, # 'z'
|
| 514 |
+
63: 0, # '·'
|
| 515 |
+
54: 1, # 'Ç'
|
| 516 |
+
50: 1, # 'Ö'
|
| 517 |
+
55: 0, # 'Ü'
|
| 518 |
+
59: 0, # 'â'
|
| 519 |
+
33: 1, # 'ç'
|
| 520 |
+
61: 0, # 'î'
|
| 521 |
+
34: 1, # 'ö'
|
| 522 |
+
17: 0, # 'ü'
|
| 523 |
+
30: 2, # 'ğ'
|
| 524 |
+
41: 1, # 'İ'
|
| 525 |
+
6: 0, # 'ı'
|
| 526 |
+
40: 2, # 'Ş'
|
| 527 |
+
19: 1, # 'ş'
|
| 528 |
+
},
|
| 529 |
+
53: { # 'I'
|
| 530 |
+
23: 0, # 'A'
|
| 531 |
+
37: 0, # 'B'
|
| 532 |
+
47: 0, # 'C'
|
| 533 |
+
39: 0, # 'D'
|
| 534 |
+
29: 0, # 'E'
|
| 535 |
+
52: 1, # 'F'
|
| 536 |
+
36: 0, # 'G'
|
| 537 |
+
45: 0, # 'H'
|
| 538 |
+
53: 0, # 'I'
|
| 539 |
+
60: 0, # 'J'
|
| 540 |
+
16: 2, # 'K'
|
| 541 |
+
49: 0, # 'L'
|
| 542 |
+
20: 0, # 'M'
|
| 543 |
+
46: 0, # 'N'
|
| 544 |
+
42: 0, # 'O'
|
| 545 |
+
48: 1, # 'P'
|
| 546 |
+
44: 0, # 'R'
|
| 547 |
+
35: 0, # 'S'
|
| 548 |
+
31: 0, # 'T'
|
| 549 |
+
51: 0, # 'U'
|
| 550 |
+
38: 0, # 'V'
|
| 551 |
+
62: 0, # 'W'
|
| 552 |
+
43: 0, # 'Y'
|
| 553 |
+
56: 0, # 'Z'
|
| 554 |
+
1: 2, # 'a'
|
| 555 |
+
21: 0, # 'b'
|
| 556 |
+
28: 2, # 'c'
|
| 557 |
+
12: 0, # 'd'
|
| 558 |
+
2: 2, # 'e'
|
| 559 |
+
18: 0, # 'f'
|
| 560 |
+
27: 0, # 'g'
|
| 561 |
+
25: 0, # 'h'
|
| 562 |
+
3: 0, # 'i'
|
| 563 |
+
24: 0, # 'j'
|
| 564 |
+
10: 0, # 'k'
|
| 565 |
+
5: 2, # 'l'
|
| 566 |
+
13: 2, # 'm'
|
| 567 |
+
4: 0, # 'n'
|
| 568 |
+
15: 0, # 'o'
|
| 569 |
+
26: 0, # 'p'
|
| 570 |
+
7: 0, # 'r'
|
| 571 |
+
8: 0, # 's'
|
| 572 |
+
9: 0, # 't'
|
| 573 |
+
14: 2, # 'u'
|
| 574 |
+
32: 0, # 'v'
|
| 575 |
+
57: 0, # 'w'
|
| 576 |
+
58: 0, # 'x'
|
| 577 |
+
11: 0, # 'y'
|
| 578 |
+
22: 2, # 'z'
|
| 579 |
+
63: 0, # '·'
|
| 580 |
+
54: 1, # 'Ç'
|
| 581 |
+
50: 0, # 'Ö'
|
| 582 |
+
55: 0, # 'Ü'
|
| 583 |
+
59: 0, # 'â'
|
| 584 |
+
33: 2, # 'ç'
|
| 585 |
+
61: 0, # 'î'
|
| 586 |
+
34: 1, # 'ö'
|
| 587 |
+
17: 0, # 'ü'
|
| 588 |
+
30: 0, # 'ğ'
|
| 589 |
+
41: 0, # 'İ'
|
| 590 |
+
6: 0, # 'ı'
|
| 591 |
+
40: 1, # 'Ş'
|
| 592 |
+
19: 1, # 'ş'
|
| 593 |
+
},
|
| 594 |
+
60: { # 'J'
|
| 595 |
+
23: 0, # 'A'
|
| 596 |
+
37: 0, # 'B'
|
| 597 |
+
47: 0, # 'C'
|
| 598 |
+
39: 0, # 'D'
|
| 599 |
+
29: 0, # 'E'
|
| 600 |
+
52: 0, # 'F'
|
| 601 |
+
36: 0, # 'G'
|
| 602 |
+
45: 0, # 'H'
|
| 603 |
+
53: 0, # 'I'
|
| 604 |
+
60: 0, # 'J'
|
| 605 |
+
16: 0, # 'K'
|
| 606 |
+
49: 0, # 'L'
|
| 607 |
+
20: 1, # 'M'
|
| 608 |
+
46: 0, # 'N'
|
| 609 |
+
42: 0, # 'O'
|
| 610 |
+
48: 0, # 'P'
|
| 611 |
+
44: 0, # 'R'
|
| 612 |
+
35: 0, # 'S'
|
| 613 |
+
31: 0, # 'T'
|
| 614 |
+
51: 0, # 'U'
|
| 615 |
+
38: 0, # 'V'
|
| 616 |
+
62: 0, # 'W'
|
| 617 |
+
43: 0, # 'Y'
|
| 618 |
+
56: 0, # 'Z'
|
| 619 |
+
1: 0, # 'a'
|
| 620 |
+
21: 1, # 'b'
|
| 621 |
+
28: 0, # 'c'
|
| 622 |
+
12: 1, # 'd'
|
| 623 |
+
2: 0, # 'e'
|
| 624 |
+
18: 0, # 'f'
|
| 625 |
+
27: 0, # 'g'
|
| 626 |
+
25: 0, # 'h'
|
| 627 |
+
3: 1, # 'i'
|
| 628 |
+
24: 0, # 'j'
|
| 629 |
+
10: 0, # 'k'
|
| 630 |
+
5: 0, # 'l'
|
| 631 |
+
13: 0, # 'm'
|
| 632 |
+
4: 1, # 'n'
|
| 633 |
+
15: 0, # 'o'
|
| 634 |
+
26: 0, # 'p'
|
| 635 |
+
7: 0, # 'r'
|
| 636 |
+
8: 1, # 's'
|
| 637 |
+
9: 0, # 't'
|
| 638 |
+
14: 0, # 'u'
|
| 639 |
+
32: 0, # 'v'
|
| 640 |
+
57: 0, # 'w'
|
| 641 |
+
58: 0, # 'x'
|
| 642 |
+
11: 0, # 'y'
|
| 643 |
+
22: 0, # 'z'
|
| 644 |
+
63: 0, # '·'
|
| 645 |
+
54: 0, # 'Ç'
|
| 646 |
+
50: 0, # 'Ö'
|
| 647 |
+
55: 0, # 'Ü'
|
| 648 |
+
59: 0, # 'â'
|
| 649 |
+
33: 0, # 'ç'
|
| 650 |
+
61: 0, # 'î'
|
| 651 |
+
34: 0, # 'ö'
|
| 652 |
+
17: 0, # 'ü'
|
| 653 |
+
30: 0, # 'ğ'
|
| 654 |
+
41: 0, # 'İ'
|
| 655 |
+
6: 0, # 'ı'
|
| 656 |
+
40: 0, # 'Ş'
|
| 657 |
+
19: 0, # 'ş'
|
| 658 |
+
},
|
| 659 |
+
16: { # 'K'
|
| 660 |
+
23: 0, # 'A'
|
| 661 |
+
37: 0, # 'B'
|
| 662 |
+
47: 0, # 'C'
|
| 663 |
+
39: 0, # 'D'
|
| 664 |
+
29: 3, # 'E'
|
| 665 |
+
52: 0, # 'F'
|
| 666 |
+
36: 0, # 'G'
|
| 667 |
+
45: 0, # 'H'
|
| 668 |
+
53: 0, # 'I'
|
| 669 |
+
60: 0, # 'J'
|
| 670 |
+
16: 0, # 'K'
|
| 671 |
+
49: 0, # 'L'
|
| 672 |
+
20: 2, # 'M'
|
| 673 |
+
46: 0, # 'N'
|
| 674 |
+
42: 0, # 'O'
|
| 675 |
+
48: 0, # 'P'
|
| 676 |
+
44: 0, # 'R'
|
| 677 |
+
35: 0, # 'S'
|
| 678 |
+
31: 2, # 'T'
|
| 679 |
+
51: 0, # 'U'
|
| 680 |
+
38: 0, # 'V'
|
| 681 |
+
62: 0, # 'W'
|
| 682 |
+
43: 0, # 'Y'
|
| 683 |
+
56: 0, # 'Z'
|
| 684 |
+
1: 2, # 'a'
|
| 685 |
+
21: 3, # 'b'
|
| 686 |
+
28: 0, # 'c'
|
| 687 |
+
12: 3, # 'd'
|
| 688 |
+
2: 1, # 'e'
|
| 689 |
+
18: 3, # 'f'
|
| 690 |
+
27: 3, # 'g'
|
| 691 |
+
25: 3, # 'h'
|
| 692 |
+
3: 3, # 'i'
|
| 693 |
+
24: 2, # 'j'
|
| 694 |
+
10: 3, # 'k'
|
| 695 |
+
5: 0, # 'l'
|
| 696 |
+
13: 0, # 'm'
|
| 697 |
+
4: 3, # 'n'
|
| 698 |
+
15: 0, # 'o'
|
| 699 |
+
26: 1, # 'p'
|
| 700 |
+
7: 3, # 'r'
|
| 701 |
+
8: 3, # 's'
|
| 702 |
+
9: 3, # 't'
|
| 703 |
+
14: 0, # 'u'
|
| 704 |
+
32: 3, # 'v'
|
| 705 |
+
57: 0, # 'w'
|
| 706 |
+
58: 0, # 'x'
|
| 707 |
+
11: 2, # 'y'
|
| 708 |
+
22: 1, # 'z'
|
| 709 |
+
63: 0, # '·'
|
| 710 |
+
54: 0, # 'Ç'
|
| 711 |
+
50: 0, # 'Ö'
|
| 712 |
+
55: 0, # 'Ü'
|
| 713 |
+
59: 0, # 'â'
|
| 714 |
+
33: 0, # 'ç'
|
| 715 |
+
61: 0, # 'î'
|
| 716 |
+
34: 0, # 'ö'
|
| 717 |
+
17: 2, # 'ü'
|
| 718 |
+
30: 0, # 'ğ'
|
| 719 |
+
41: 1, # 'İ'
|
| 720 |
+
6: 3, # 'ı'
|
| 721 |
+
40: 0, # 'Ş'
|
| 722 |
+
19: 0, # 'ş'
|
| 723 |
+
},
|
| 724 |
+
49: { # 'L'
|
| 725 |
+
23: 0, # 'A'
|
| 726 |
+
37: 0, # 'B'
|
| 727 |
+
47: 0, # 'C'
|
| 728 |
+
39: 0, # 'D'
|
| 729 |
+
29: 2, # 'E'
|
| 730 |
+
52: 0, # 'F'
|
| 731 |
+
36: 1, # 'G'
|
| 732 |
+
45: 1, # 'H'
|
| 733 |
+
53: 0, # 'I'
|
| 734 |
+
60: 0, # 'J'
|
| 735 |
+
16: 0, # 'K'
|
| 736 |
+
49: 0, # 'L'
|
| 737 |
+
20: 1, # 'M'
|
| 738 |
+
46: 0, # 'N'
|
| 739 |
+
42: 2, # 'O'
|
| 740 |
+
48: 0, # 'P'
|
| 741 |
+
44: 0, # 'R'
|
| 742 |
+
35: 0, # 'S'
|
| 743 |
+
31: 0, # 'T'
|
| 744 |
+
51: 0, # 'U'
|
| 745 |
+
38: 0, # 'V'
|
| 746 |
+
62: 0, # 'W'
|
| 747 |
+
43: 1, # 'Y'
|
| 748 |
+
56: 0, # 'Z'
|
| 749 |
+
1: 0, # 'a'
|
| 750 |
+
21: 3, # 'b'
|
| 751 |
+
28: 0, # 'c'
|
| 752 |
+
12: 2, # 'd'
|
| 753 |
+
2: 0, # 'e'
|
| 754 |
+
18: 0, # 'f'
|
| 755 |
+
27: 0, # 'g'
|
| 756 |
+
25: 0, # 'h'
|
| 757 |
+
3: 2, # 'i'
|
| 758 |
+
24: 0, # 'j'
|
| 759 |
+
10: 1, # 'k'
|
| 760 |
+
5: 0, # 'l'
|
| 761 |
+
13: 0, # 'm'
|
| 762 |
+
4: 2, # 'n'
|
| 763 |
+
15: 1, # 'o'
|
| 764 |
+
26: 1, # 'p'
|
| 765 |
+
7: 1, # 'r'
|
| 766 |
+
8: 1, # 's'
|
| 767 |
+
9: 1, # 't'
|
| 768 |
+
14: 0, # 'u'
|
| 769 |
+
32: 0, # 'v'
|
| 770 |
+
57: 0, # 'w'
|
| 771 |
+
58: 0, # 'x'
|
| 772 |
+
11: 2, # 'y'
|
| 773 |
+
22: 0, # 'z'
|
| 774 |
+
63: 0, # '·'
|
| 775 |
+
54: 0, # 'Ç'
|
| 776 |
+
50: 0, # 'Ö'
|
| 777 |
+
55: 2, # 'Ü'
|
| 778 |
+
59: 0, # 'â'
|
| 779 |
+
33: 0, # 'ç'
|
| 780 |
+
61: 0, # 'î'
|
| 781 |
+
34: 1, # 'ö'
|
| 782 |
+
17: 1, # 'ü'
|
| 783 |
+
30: 1, # 'ğ'
|
| 784 |
+
41: 0, # 'İ'
|
| 785 |
+
6: 2, # 'ı'
|
| 786 |
+
40: 0, # 'Ş'
|
| 787 |
+
19: 0, # 'ş'
|
| 788 |
+
},
|
| 789 |
+
20: { # 'M'
|
| 790 |
+
23: 1, # 'A'
|
| 791 |
+
37: 0, # 'B'
|
| 792 |
+
47: 0, # 'C'
|
| 793 |
+
39: 0, # 'D'
|
| 794 |
+
29: 0, # 'E'
|
| 795 |
+
52: 0, # 'F'
|
| 796 |
+
36: 0, # 'G'
|
| 797 |
+
45: 0, # 'H'
|
| 798 |
+
53: 0, # 'I'
|
| 799 |
+
60: 1, # 'J'
|
| 800 |
+
16: 3, # 'K'
|
| 801 |
+
49: 0, # 'L'
|
| 802 |
+
20: 2, # 'M'
|
| 803 |
+
46: 0, # 'N'
|
| 804 |
+
42: 0, # 'O'
|
| 805 |
+
48: 0, # 'P'
|
| 806 |
+
44: 0, # 'R'
|
| 807 |
+
35: 0, # 'S'
|
| 808 |
+
31: 1, # 'T'
|
| 809 |
+
51: 0, # 'U'
|
| 810 |
+
38: 0, # 'V'
|
| 811 |
+
62: 0, # 'W'
|
| 812 |
+
43: 0, # 'Y'
|
| 813 |
+
56: 0, # 'Z'
|
| 814 |
+
1: 3, # 'a'
|
| 815 |
+
21: 2, # 'b'
|
| 816 |
+
28: 0, # 'c'
|
| 817 |
+
12: 3, # 'd'
|
| 818 |
+
2: 3, # 'e'
|
| 819 |
+
18: 0, # 'f'
|
| 820 |
+
27: 1, # 'g'
|
| 821 |
+
25: 1, # 'h'
|
| 822 |
+
3: 2, # 'i'
|
| 823 |
+
24: 2, # 'j'
|
| 824 |
+
10: 2, # 'k'
|
| 825 |
+
5: 2, # 'l'
|
| 826 |
+
13: 3, # 'm'
|
| 827 |
+
4: 3, # 'n'
|
| 828 |
+
15: 0, # 'o'
|
| 829 |
+
26: 1, # 'p'
|
| 830 |
+
7: 3, # 'r'
|
| 831 |
+
8: 0, # 's'
|
| 832 |
+
9: 2, # 't'
|
| 833 |
+
14: 3, # 'u'
|
| 834 |
+
32: 0, # 'v'
|
| 835 |
+
57: 0, # 'w'
|
| 836 |
+
58: 0, # 'x'
|
| 837 |
+
11: 2, # 'y'
|
| 838 |
+
22: 0, # 'z'
|
| 839 |
+
63: 0, # '·'
|
| 840 |
+
54: 0, # 'Ç'
|
| 841 |
+
50: 0, # 'Ö'
|
| 842 |
+
55: 0, # 'Ü'
|
| 843 |
+
59: 0, # 'â'
|
| 844 |
+
33: 3, # 'ç'
|
| 845 |
+
61: 0, # 'î'
|
| 846 |
+
34: 0, # 'ö'
|
| 847 |
+
17: 0, # 'ü'
|
| 848 |
+
30: 0, # 'ğ'
|
| 849 |
+
41: 0, # 'İ'
|
| 850 |
+
6: 3, # 'ı'
|
| 851 |
+
40: 0, # 'Ş'
|
| 852 |
+
19: 0, # 'ş'
|
| 853 |
+
},
|
| 854 |
+
46: { # 'N'
|
| 855 |
+
23: 0, # 'A'
|
| 856 |
+
37: 1, # 'B'
|
| 857 |
+
47: 0, # 'C'
|
| 858 |
+
39: 0, # 'D'
|
| 859 |
+
29: 0, # 'E'
|
| 860 |
+
52: 1, # 'F'
|
| 861 |
+
36: 1, # 'G'
|
| 862 |
+
45: 1, # 'H'
|
| 863 |
+
53: 0, # 'I'
|
| 864 |
+
60: 0, # 'J'
|
| 865 |
+
16: 2, # 'K'
|
| 866 |
+
49: 0, # 'L'
|
| 867 |
+
20: 0, # 'M'
|
| 868 |
+
46: 1, # 'N'
|
| 869 |
+
42: 0, # 'O'
|
| 870 |
+
48: 0, # 'P'
|
| 871 |
+
44: 1, # 'R'
|
| 872 |
+
35: 1, # 'S'
|
| 873 |
+
31: 0, # 'T'
|
| 874 |
+
51: 1, # 'U'
|
| 875 |
+
38: 2, # 'V'
|
| 876 |
+
62: 0, # 'W'
|
| 877 |
+
43: 1, # 'Y'
|
| 878 |
+
56: 0, # 'Z'
|
| 879 |
+
1: 3, # 'a'
|
| 880 |
+
21: 0, # 'b'
|
| 881 |
+
28: 2, # 'c'
|
| 882 |
+
12: 0, # 'd'
|
| 883 |
+
2: 3, # 'e'
|
| 884 |
+
18: 0, # 'f'
|
| 885 |
+
27: 1, # 'g'
|
| 886 |
+
25: 0, # 'h'
|
| 887 |
+
3: 0, # 'i'
|
| 888 |
+
24: 2, # 'j'
|
| 889 |
+
10: 1, # 'k'
|
| 890 |
+
5: 1, # 'l'
|
| 891 |
+
13: 3, # 'm'
|
| 892 |
+
4: 2, # 'n'
|
| 893 |
+
15: 1, # 'o'
|
| 894 |
+
26: 1, # 'p'
|
| 895 |
+
7: 1, # 'r'
|
| 896 |
+
8: 0, # 's'
|
| 897 |
+
9: 0, # 't'
|
| 898 |
+
14: 3, # 'u'
|
| 899 |
+
32: 0, # 'v'
|
| 900 |
+
57: 0, # 'w'
|
| 901 |
+
58: 1, # 'x'
|
| 902 |
+
11: 1, # 'y'
|
| 903 |
+
22: 2, # 'z'
|
| 904 |
+
63: 0, # '·'
|
| 905 |
+
54: 1, # 'Ç'
|
| 906 |
+
50: 1, # 'Ö'
|
| 907 |
+
55: 0, # 'Ü'
|
| 908 |
+
59: 0, # 'â'
|
| 909 |
+
33: 0, # 'ç'
|
| 910 |
+
61: 0, # 'î'
|
| 911 |
+
34: 1, # 'ö'
|
| 912 |
+
17: 0, # 'ü'
|
| 913 |
+
30: 0, # 'ğ'
|
| 914 |
+
41: 1, # 'İ'
|
| 915 |
+
6: 2, # 'ı'
|
| 916 |
+
40: 1, # 'Ş'
|
| 917 |
+
19: 1, # 'ş'
|
| 918 |
+
},
|
| 919 |
+
42: { # 'O'
|
| 920 |
+
23: 0, # 'A'
|
| 921 |
+
37: 0, # 'B'
|
| 922 |
+
47: 0, # 'C'
|
| 923 |
+
39: 0, # 'D'
|
| 924 |
+
29: 0, # 'E'
|
| 925 |
+
52: 1, # 'F'
|
| 926 |
+
36: 0, # 'G'
|
| 927 |
+
45: 1, # 'H'
|
| 928 |
+
53: 0, # 'I'
|
| 929 |
+
60: 0, # 'J'
|
| 930 |
+
16: 2, # 'K'
|
| 931 |
+
49: 1, # 'L'
|
| 932 |
+
20: 0, # 'M'
|
| 933 |
+
46: 0, # 'N'
|
| 934 |
+
42: 0, # 'O'
|
| 935 |
+
48: 2, # 'P'
|
| 936 |
+
44: 1, # 'R'
|
| 937 |
+
35: 1, # 'S'
|
| 938 |
+
31: 0, # 'T'
|
| 939 |
+
51: 1, # 'U'
|
| 940 |
+
38: 1, # 'V'
|
| 941 |
+
62: 0, # 'W'
|
| 942 |
+
43: 0, # 'Y'
|
| 943 |
+
56: 0, # 'Z'
|
| 944 |
+
1: 3, # 'a'
|
| 945 |
+
21: 0, # 'b'
|
| 946 |
+
28: 2, # 'c'
|
| 947 |
+
12: 0, # 'd'
|
| 948 |
+
2: 2, # 'e'
|
| 949 |
+
18: 0, # 'f'
|
| 950 |
+
27: 0, # 'g'
|
| 951 |
+
25: 0, # 'h'
|
| 952 |
+
3: 0, # 'i'
|
| 953 |
+
24: 0, # 'j'
|
| 954 |
+
10: 0, # 'k'
|
| 955 |
+
5: 3, # 'l'
|
| 956 |
+
13: 3, # 'm'
|
| 957 |
+
4: 0, # 'n'
|
| 958 |
+
15: 1, # 'o'
|
| 959 |
+
26: 0, # 'p'
|
| 960 |
+
7: 0, # 'r'
|
| 961 |
+
8: 0, # 's'
|
| 962 |
+
9: 0, # 't'
|
| 963 |
+
14: 2, # 'u'
|
| 964 |
+
32: 0, # 'v'
|
| 965 |
+
57: 0, # 'w'
|
| 966 |
+
58: 0, # 'x'
|
| 967 |
+
11: 0, # 'y'
|
| 968 |
+
22: 2, # 'z'
|
| 969 |
+
63: 0, # '·'
|
| 970 |
+
54: 2, # 'Ç'
|
| 971 |
+
50: 1, # 'Ö'
|
| 972 |
+
55: 0, # 'Ü'
|
| 973 |
+
59: 0, # 'â'
|
| 974 |
+
33: 2, # 'ç'
|
| 975 |
+
61: 0, # 'î'
|
| 976 |
+
34: 1, # 'ö'
|
| 977 |
+
17: 0, # 'ü'
|
| 978 |
+
30: 1, # 'ğ'
|
| 979 |
+
41: 2, # 'İ'
|
| 980 |
+
6: 1, # 'ı'
|
| 981 |
+
40: 1, # 'Ş'
|
| 982 |
+
19: 1, # 'ş'
|
| 983 |
+
},
|
| 984 |
+
48: { # 'P'
|
| 985 |
+
23: 0, # 'A'
|
| 986 |
+
37: 0, # 'B'
|
| 987 |
+
47: 2, # 'C'
|
| 988 |
+
39: 0, # 'D'
|
| 989 |
+
29: 0, # 'E'
|
| 990 |
+
52: 2, # 'F'
|
| 991 |
+
36: 1, # 'G'
|
| 992 |
+
45: 1, # 'H'
|
| 993 |
+
53: 0, # 'I'
|
| 994 |
+
60: 0, # 'J'
|
| 995 |
+
16: 2, # 'K'
|
| 996 |
+
49: 0, # 'L'
|
| 997 |
+
20: 0, # 'M'
|
| 998 |
+
46: 1, # 'N'
|
| 999 |
+
42: 1, # 'O'
|
| 1000 |
+
48: 1, # 'P'
|
| 1001 |
+
44: 0, # 'R'
|
| 1002 |
+
35: 1, # 'S'
|
| 1003 |
+
31: 0, # 'T'
|
| 1004 |
+
51: 0, # 'U'
|
| 1005 |
+
38: 1, # 'V'
|
| 1006 |
+
62: 0, # 'W'
|
| 1007 |
+
43: 0, # 'Y'
|
| 1008 |
+
56: 0, # 'Z'
|
| 1009 |
+
1: 2, # 'a'
|
| 1010 |
+
21: 0, # 'b'
|
| 1011 |
+
28: 2, # 'c'
|
| 1012 |
+
12: 0, # 'd'
|
| 1013 |
+
2: 3, # 'e'
|
| 1014 |
+
18: 0, # 'f'
|
| 1015 |
+
27: 0, # 'g'
|
| 1016 |
+
25: 0, # 'h'
|
| 1017 |
+
3: 0, # 'i'
|
| 1018 |
+
24: 0, # 'j'
|
| 1019 |
+
10: 1, # 'k'
|
| 1020 |
+
5: 0, # 'l'
|
| 1021 |
+
13: 2, # 'm'
|
| 1022 |
+
4: 0, # 'n'
|
| 1023 |
+
15: 2, # 'o'
|
| 1024 |
+
26: 0, # 'p'
|
| 1025 |
+
7: 0, # 'r'
|
| 1026 |
+
8: 0, # 's'
|
| 1027 |
+
9: 0, # 't'
|
| 1028 |
+
14: 2, # 'u'
|
| 1029 |
+
32: 0, # 'v'
|
| 1030 |
+
57: 0, # 'w'
|
| 1031 |
+
58: 2, # 'x'
|
| 1032 |
+
11: 0, # 'y'
|
| 1033 |
+
22: 2, # 'z'
|
| 1034 |
+
63: 0, # '·'
|
| 1035 |
+
54: 1, # 'Ç'
|
| 1036 |
+
50: 2, # 'Ö'
|
| 1037 |
+
55: 0, # 'Ü'
|
| 1038 |
+
59: 0, # 'â'
|
| 1039 |
+
33: 0, # 'ç'
|
| 1040 |
+
61: 0, # 'î'
|
| 1041 |
+
34: 2, # 'ö'
|
| 1042 |
+
17: 0, # 'ü'
|
| 1043 |
+
30: 1, # 'ğ'
|
| 1044 |
+
41: 1, # 'İ'
|
| 1045 |
+
6: 0, # 'ı'
|
| 1046 |
+
40: 2, # 'Ş'
|
| 1047 |
+
19: 1, # 'ş'
|
| 1048 |
+
},
|
| 1049 |
+
44: { # 'R'
|
| 1050 |
+
23: 0, # 'A'
|
| 1051 |
+
37: 0, # 'B'
|
| 1052 |
+
47: 1, # 'C'
|
| 1053 |
+
39: 0, # 'D'
|
| 1054 |
+
29: 0, # 'E'
|
| 1055 |
+
52: 1, # 'F'
|
| 1056 |
+
36: 0, # 'G'
|
| 1057 |
+
45: 0, # 'H'
|
| 1058 |
+
53: 0, # 'I'
|
| 1059 |
+
60: 0, # 'J'
|
| 1060 |
+
16: 3, # 'K'
|
| 1061 |
+
49: 0, # 'L'
|
| 1062 |
+
20: 0, # 'M'
|
| 1063 |
+
46: 0, # 'N'
|
| 1064 |
+
42: 0, # 'O'
|
| 1065 |
+
48: 1, # 'P'
|
| 1066 |
+
44: 0, # 'R'
|
| 1067 |
+
35: 0, # 'S'
|
| 1068 |
+
31: 0, # 'T'
|
| 1069 |
+
51: 0, # 'U'
|
| 1070 |
+
38: 0, # 'V'
|
| 1071 |
+
62: 0, # 'W'
|
| 1072 |
+
43: 1, # 'Y'
|
| 1073 |
+
56: 0, # 'Z'
|
| 1074 |
+
1: 3, # 'a'
|
| 1075 |
+
21: 1, # 'b'
|
| 1076 |
+
28: 1, # 'c'
|
| 1077 |
+
12: 0, # 'd'
|
| 1078 |
+
2: 2, # 'e'
|
| 1079 |
+
18: 0, # 'f'
|
| 1080 |
+
27: 0, # 'g'
|
| 1081 |
+
25: 0, # 'h'
|
| 1082 |
+
3: 0, # 'i'
|
| 1083 |
+
24: 0, # 'j'
|
| 1084 |
+
10: 1, # 'k'
|
| 1085 |
+
5: 2, # 'l'
|
| 1086 |
+
13: 2, # 'm'
|
| 1087 |
+
4: 0, # 'n'
|
| 1088 |
+
15: 1, # 'o'
|
| 1089 |
+
26: 0, # 'p'
|
| 1090 |
+
7: 0, # 'r'
|
| 1091 |
+
8: 0, # 's'
|
| 1092 |
+
9: 0, # 't'
|
| 1093 |
+
14: 2, # 'u'
|
| 1094 |
+
32: 0, # 'v'
|
| 1095 |
+
57: 0, # 'w'
|
| 1096 |
+
58: 0, # 'x'
|
| 1097 |
+
11: 1, # 'y'
|
| 1098 |
+
22: 2, # 'z'
|
| 1099 |
+
63: 0, # '·'
|
| 1100 |
+
54: 0, # 'Ç'
|
| 1101 |
+
50: 1, # 'Ö'
|
| 1102 |
+
55: 0, # 'Ü'
|
| 1103 |
+
59: 0, # 'â'
|
| 1104 |
+
33: 1, # 'ç'
|
| 1105 |
+
61: 0, # 'î'
|
| 1106 |
+
34: 1, # 'ö'
|
| 1107 |
+
17: 1, # 'ü'
|
| 1108 |
+
30: 1, # 'ğ'
|
| 1109 |
+
41: 0, # 'İ'
|
| 1110 |
+
6: 2, # 'ı'
|
| 1111 |
+
40: 1, # 'Ş'
|
| 1112 |
+
19: 1, # 'ş'
|
| 1113 |
+
},
|
| 1114 |
+
35: { # 'S'
|
| 1115 |
+
23: 0, # 'A'
|
| 1116 |
+
37: 0, # 'B'
|
| 1117 |
+
47: 1, # 'C'
|
| 1118 |
+
39: 0, # 'D'
|
| 1119 |
+
29: 0, # 'E'
|
| 1120 |
+
52: 1, # 'F'
|
| 1121 |
+
36: 1, # 'G'
|
| 1122 |
+
45: 1, # 'H'
|
| 1123 |
+
53: 0, # 'I'
|
| 1124 |
+
60: 0, # 'J'
|
| 1125 |
+
16: 3, # 'K'
|
| 1126 |
+
49: 1, # 'L'
|
| 1127 |
+
20: 1, # 'M'
|
| 1128 |
+
46: 0, # 'N'
|
| 1129 |
+
42: 0, # 'O'
|
| 1130 |
+
48: 1, # 'P'
|
| 1131 |
+
44: 0, # 'R'
|
| 1132 |
+
35: 0, # 'S'
|
| 1133 |
+
31: 0, # 'T'
|
| 1134 |
+
51: 1, # 'U'
|
| 1135 |
+
38: 1, # 'V'
|
| 1136 |
+
62: 0, # 'W'
|
| 1137 |
+
43: 1, # 'Y'
|
| 1138 |
+
56: 0, # 'Z'
|
| 1139 |
+
1: 3, # 'a'
|
| 1140 |
+
21: 0, # 'b'
|
| 1141 |
+
28: 2, # 'c'
|
| 1142 |
+
12: 0, # 'd'
|
| 1143 |
+
2: 3, # 'e'
|
| 1144 |
+
18: 0, # 'f'
|
| 1145 |
+
27: 0, # 'g'
|
| 1146 |
+
25: 0, # 'h'
|
| 1147 |
+
3: 0, # 'i'
|
| 1148 |
+
24: 0, # 'j'
|
| 1149 |
+
10: 1, # 'k'
|
| 1150 |
+
5: 1, # 'l'
|
| 1151 |
+
13: 2, # 'm'
|
| 1152 |
+
4: 1, # 'n'
|
| 1153 |
+
15: 0, # 'o'
|
| 1154 |
+
26: 0, # 'p'
|
| 1155 |
+
7: 0, # 'r'
|
| 1156 |
+
8: 0, # 's'
|
| 1157 |
+
9: 1, # 't'
|
| 1158 |
+
14: 2, # 'u'
|
| 1159 |
+
32: 0, # 'v'
|
| 1160 |
+
57: 0, # 'w'
|
| 1161 |
+
58: 0, # 'x'
|
| 1162 |
+
11: 0, # 'y'
|
| 1163 |
+
22: 1, # 'z'
|
| 1164 |
+
63: 0, # '·'
|
| 1165 |
+
54: 2, # 'Ç'
|
| 1166 |
+
50: 2, # 'Ö'
|
| 1167 |
+
55: 0, # 'Ü'
|
| 1168 |
+
59: 0, # 'â'
|
| 1169 |
+
33: 3, # 'ç'
|
| 1170 |
+
61: 0, # 'î'
|
| 1171 |
+
34: 1, # 'ö'
|
| 1172 |
+
17: 0, # 'ü'
|
| 1173 |
+
30: 0, # 'ğ'
|
| 1174 |
+
41: 0, # 'İ'
|
| 1175 |
+
6: 3, # 'ı'
|
| 1176 |
+
40: 2, # 'Ş'
|
| 1177 |
+
19: 1, # 'ş'
|
| 1178 |
+
},
|
| 1179 |
+
31: { # 'T'
|
| 1180 |
+
23: 0, # 'A'
|
| 1181 |
+
37: 0, # 'B'
|
| 1182 |
+
47: 0, # 'C'
|
| 1183 |
+
39: 0, # 'D'
|
| 1184 |
+
29: 0, # 'E'
|
| 1185 |
+
52: 0, # 'F'
|
| 1186 |
+
36: 0, # 'G'
|
| 1187 |
+
45: 0, # 'H'
|
| 1188 |
+
53: 0, # 'I'
|
| 1189 |
+
60: 1, # 'J'
|
| 1190 |
+
16: 2, # 'K'
|
| 1191 |
+
49: 0, # 'L'
|
| 1192 |
+
20: 1, # 'M'
|
| 1193 |
+
46: 0, # 'N'
|
| 1194 |
+
42: 0, # 'O'
|
| 1195 |
+
48: 0, # 'P'
|
| 1196 |
+
44: 0, # 'R'
|
| 1197 |
+
35: 0, # 'S'
|
| 1198 |
+
31: 2, # 'T'
|
| 1199 |
+
51: 0, # 'U'
|
| 1200 |
+
38: 0, # 'V'
|
| 1201 |
+
62: 0, # 'W'
|
| 1202 |
+
43: 0, # 'Y'
|
| 1203 |
+
56: 0, # 'Z'
|
| 1204 |
+
1: 3, # 'a'
|
| 1205 |
+
21: 2, # 'b'
|
| 1206 |
+
28: 0, # 'c'
|
| 1207 |
+
12: 1, # 'd'
|
| 1208 |
+
2: 3, # 'e'
|
| 1209 |
+
18: 2, # 'f'
|
| 1210 |
+
27: 2, # 'g'
|
| 1211 |
+
25: 0, # 'h'
|
| 1212 |
+
3: 1, # 'i'
|
| 1213 |
+
24: 1, # 'j'
|
| 1214 |
+
10: 2, # 'k'
|
| 1215 |
+
5: 2, # 'l'
|
| 1216 |
+
13: 3, # 'm'
|
| 1217 |
+
4: 3, # 'n'
|
| 1218 |
+
15: 0, # 'o'
|
| 1219 |
+
26: 2, # 'p'
|
| 1220 |
+
7: 2, # 'r'
|
| 1221 |
+
8: 0, # 's'
|
| 1222 |
+
9: 2, # 't'
|
| 1223 |
+
14: 2, # 'u'
|
| 1224 |
+
32: 1, # 'v'
|
| 1225 |
+
57: 1, # 'w'
|
| 1226 |
+
58: 1, # 'x'
|
| 1227 |
+
11: 2, # 'y'
|
| 1228 |
+
22: 0, # 'z'
|
| 1229 |
+
63: 0, # '·'
|
| 1230 |
+
54: 0, # 'Ç'
|
| 1231 |
+
50: 0, # 'Ö'
|
| 1232 |
+
55: 0, # 'Ü'
|
| 1233 |
+
59: 0, # 'â'
|
| 1234 |
+
33: 0, # 'ç'
|
| 1235 |
+
61: 0, # 'î'
|
| 1236 |
+
34: 0, # 'ö'
|
| 1237 |
+
17: 1, # 'ü'
|
| 1238 |
+
30: 0, # 'ğ'
|
| 1239 |
+
41: 0, # 'İ'
|
| 1240 |
+
6: 3, # 'ı'
|
| 1241 |
+
40: 0, # 'Ş'
|
| 1242 |
+
19: 0, # 'ş'
|
| 1243 |
+
},
|
| 1244 |
+
51: { # 'U'
|
| 1245 |
+
23: 0, # 'A'
|
| 1246 |
+
37: 0, # 'B'
|
| 1247 |
+
47: 0, # 'C'
|
| 1248 |
+
39: 0, # 'D'
|
| 1249 |
+
29: 0, # 'E'
|
| 1250 |
+
52: 1, # 'F'
|
| 1251 |
+
36: 1, # 'G'
|
| 1252 |
+
45: 0, # 'H'
|
| 1253 |
+
53: 0, # 'I'
|
| 1254 |
+
60: 0, # 'J'
|
| 1255 |
+
16: 1, # 'K'
|
| 1256 |
+
49: 0, # 'L'
|
| 1257 |
+
20: 0, # 'M'
|
| 1258 |
+
46: 1, # 'N'
|
| 1259 |
+
42: 0, # 'O'
|
| 1260 |
+
48: 1, # 'P'
|
| 1261 |
+
44: 0, # 'R'
|
| 1262 |
+
35: 0, # 'S'
|
| 1263 |
+
31: 0, # 'T'
|
| 1264 |
+
51: 1, # 'U'
|
| 1265 |
+
38: 1, # 'V'
|
| 1266 |
+
62: 0, # 'W'
|
| 1267 |
+
43: 0, # 'Y'
|
| 1268 |
+
56: 0, # 'Z'
|
| 1269 |
+
1: 3, # 'a'
|
| 1270 |
+
21: 0, # 'b'
|
| 1271 |
+
28: 1, # 'c'
|
| 1272 |
+
12: 0, # 'd'
|
| 1273 |
+
2: 3, # 'e'
|
| 1274 |
+
18: 0, # 'f'
|
| 1275 |
+
27: 2, # 'g'
|
| 1276 |
+
25: 0, # 'h'
|
| 1277 |
+
3: 0, # 'i'
|
| 1278 |
+
24: 0, # 'j'
|
| 1279 |
+
10: 1, # 'k'
|
| 1280 |
+
5: 1, # 'l'
|
| 1281 |
+
13: 3, # 'm'
|
| 1282 |
+
4: 2, # 'n'
|
| 1283 |
+
15: 0, # 'o'
|
| 1284 |
+
26: 1, # 'p'
|
| 1285 |
+
7: 0, # 'r'
|
| 1286 |
+
8: 0, # 's'
|
| 1287 |
+
9: 0, # 't'
|
| 1288 |
+
14: 2, # 'u'
|
| 1289 |
+
32: 0, # 'v'
|
| 1290 |
+
57: 0, # 'w'
|
| 1291 |
+
58: 0, # 'x'
|
| 1292 |
+
11: 0, # 'y'
|
| 1293 |
+
22: 2, # 'z'
|
| 1294 |
+
63: 0, # '·'
|
| 1295 |
+
54: 1, # 'Ç'
|
| 1296 |
+
50: 1, # 'Ö'
|
| 1297 |
+
55: 0, # 'Ü'
|
| 1298 |
+
59: 0, # 'â'
|
| 1299 |
+
33: 0, # 'ç'
|
| 1300 |
+
61: 0, # 'î'
|
| 1301 |
+
34: 0, # 'ö'
|
| 1302 |
+
17: 0, # 'ü'
|
| 1303 |
+
30: 1, # 'ğ'
|
| 1304 |
+
41: 1, # 'İ'
|
| 1305 |
+
6: 2, # 'ı'
|
| 1306 |
+
40: 0, # 'Ş'
|
| 1307 |
+
19: 1, # 'ş'
|
| 1308 |
+
},
|
| 1309 |
+
38: { # 'V'
|
| 1310 |
+
23: 1, # 'A'
|
| 1311 |
+
37: 1, # 'B'
|
| 1312 |
+
47: 1, # 'C'
|
| 1313 |
+
39: 0, # 'D'
|
| 1314 |
+
29: 0, # 'E'
|
| 1315 |
+
52: 2, # 'F'
|
| 1316 |
+
36: 0, # 'G'
|
| 1317 |
+
45: 0, # 'H'
|
| 1318 |
+
53: 0, # 'I'
|
| 1319 |
+
60: 0, # 'J'
|
| 1320 |
+
16: 3, # 'K'
|
| 1321 |
+
49: 0, # 'L'
|
| 1322 |
+
20: 3, # 'M'
|
| 1323 |
+
46: 0, # 'N'
|
| 1324 |
+
42: 0, # 'O'
|
| 1325 |
+
48: 1, # 'P'
|
| 1326 |
+
44: 1, # 'R'
|
| 1327 |
+
35: 0, # 'S'
|
| 1328 |
+
31: 0, # 'T'
|
| 1329 |
+
51: 1, # 'U'
|
| 1330 |
+
38: 1, # 'V'
|
| 1331 |
+
62: 0, # 'W'
|
| 1332 |
+
43: 0, # 'Y'
|
| 1333 |
+
56: 0, # 'Z'
|
| 1334 |
+
1: 3, # 'a'
|
| 1335 |
+
21: 0, # 'b'
|
| 1336 |
+
28: 2, # 'c'
|
| 1337 |
+
12: 0, # 'd'
|
| 1338 |
+
2: 3, # 'e'
|
| 1339 |
+
18: 0, # 'f'
|
| 1340 |
+
27: 0, # 'g'
|
| 1341 |
+
25: 0, # 'h'
|
| 1342 |
+
3: 0, # 'i'
|
| 1343 |
+
24: 0, # 'j'
|
| 1344 |
+
10: 0, # 'k'
|
| 1345 |
+
5: 2, # 'l'
|
| 1346 |
+
13: 2, # 'm'
|
| 1347 |
+
4: 0, # 'n'
|
| 1348 |
+
15: 2, # 'o'
|
| 1349 |
+
26: 0, # 'p'
|
| 1350 |
+
7: 0, # 'r'
|
| 1351 |
+
8: 0, # 's'
|
| 1352 |
+
9: 1, # 't'
|
| 1353 |
+
14: 3, # 'u'
|
| 1354 |
+
32: 0, # 'v'
|
| 1355 |
+
57: 0, # 'w'
|
| 1356 |
+
58: 0, # 'x'
|
| 1357 |
+
11: 1, # 'y'
|
| 1358 |
+
22: 2, # 'z'
|
| 1359 |
+
63: 0, # '·'
|
| 1360 |
+
54: 1, # 'Ç'
|
| 1361 |
+
50: 1, # 'Ö'
|
| 1362 |
+
55: 0, # 'Ü'
|
| 1363 |
+
59: 1, # 'â'
|
| 1364 |
+
33: 2, # 'ç'
|
| 1365 |
+
61: 0, # 'î'
|
| 1366 |
+
34: 1, # 'ö'
|
| 1367 |
+
17: 0, # 'ü'
|
| 1368 |
+
30: 1, # 'ğ'
|
| 1369 |
+
41: 1, # 'İ'
|
| 1370 |
+
6: 3, # 'ı'
|
| 1371 |
+
40: 2, # 'Ş'
|
| 1372 |
+
19: 1, # 'ş'
|
| 1373 |
+
},
|
| 1374 |
+
62: { # 'W'
|
| 1375 |
+
23: 0, # 'A'
|
| 1376 |
+
37: 0, # 'B'
|
| 1377 |
+
47: 0, # 'C'
|
| 1378 |
+
39: 0, # 'D'
|
| 1379 |
+
29: 0, # 'E'
|
| 1380 |
+
52: 0, # 'F'
|
| 1381 |
+
36: 0, # 'G'
|
| 1382 |
+
45: 0, # 'H'
|
| 1383 |
+
53: 0, # 'I'
|
| 1384 |
+
60: 0, # 'J'
|
| 1385 |
+
16: 0, # 'K'
|
| 1386 |
+
49: 0, # 'L'
|
| 1387 |
+
20: 0, # 'M'
|
| 1388 |
+
46: 0, # 'N'
|
| 1389 |
+
42: 0, # 'O'
|
| 1390 |
+
48: 0, # 'P'
|
| 1391 |
+
44: 0, # 'R'
|
| 1392 |
+
35: 0, # 'S'
|
| 1393 |
+
31: 0, # 'T'
|
| 1394 |
+
51: 0, # 'U'
|
| 1395 |
+
38: 0, # 'V'
|
| 1396 |
+
62: 0, # 'W'
|
| 1397 |
+
43: 0, # 'Y'
|
| 1398 |
+
56: 0, # 'Z'
|
| 1399 |
+
1: 0, # 'a'
|
| 1400 |
+
21: 0, # 'b'
|
| 1401 |
+
28: 0, # 'c'
|
| 1402 |
+
12: 0, # 'd'
|
| 1403 |
+
2: 0, # 'e'
|
| 1404 |
+
18: 0, # 'f'
|
| 1405 |
+
27: 0, # 'g'
|
| 1406 |
+
25: 0, # 'h'
|
| 1407 |
+
3: 0, # 'i'
|
| 1408 |
+
24: 0, # 'j'
|
| 1409 |
+
10: 0, # 'k'
|
| 1410 |
+
5: 0, # 'l'
|
| 1411 |
+
13: 0, # 'm'
|
| 1412 |
+
4: 0, # 'n'
|
| 1413 |
+
15: 0, # 'o'
|
| 1414 |
+
26: 0, # 'p'
|
| 1415 |
+
7: 0, # 'r'
|
| 1416 |
+
8: 0, # 's'
|
| 1417 |
+
9: 0, # 't'
|
| 1418 |
+
14: 0, # 'u'
|
| 1419 |
+
32: 0, # 'v'
|
| 1420 |
+
57: 0, # 'w'
|
| 1421 |
+
58: 0, # 'x'
|
| 1422 |
+
11: 0, # 'y'
|
| 1423 |
+
22: 0, # 'z'
|
| 1424 |
+
63: 0, # '·'
|
| 1425 |
+
54: 0, # 'Ç'
|
| 1426 |
+
50: 0, # 'Ö'
|
| 1427 |
+
55: 0, # 'Ü'
|
| 1428 |
+
59: 0, # 'â'
|
| 1429 |
+
33: 0, # 'ç'
|
| 1430 |
+
61: 0, # 'î'
|
| 1431 |
+
34: 0, # 'ö'
|
| 1432 |
+
17: 0, # 'ü'
|
| 1433 |
+
30: 0, # 'ğ'
|
| 1434 |
+
41: 0, # 'İ'
|
| 1435 |
+
6: 0, # 'ı'
|
| 1436 |
+
40: 0, # 'Ş'
|
| 1437 |
+
19: 0, # 'ş'
|
| 1438 |
+
},
|
| 1439 |
+
43: { # 'Y'
|
| 1440 |
+
23: 0, # 'A'
|
| 1441 |
+
37: 0, # 'B'
|
| 1442 |
+
47: 1, # 'C'
|
| 1443 |
+
39: 0, # 'D'
|
| 1444 |
+
29: 0, # 'E'
|
| 1445 |
+
52: 2, # 'F'
|
| 1446 |
+
36: 0, # 'G'
|
| 1447 |
+
45: 1, # 'H'
|
| 1448 |
+
53: 1, # 'I'
|
| 1449 |
+
60: 0, # 'J'
|
| 1450 |
+
16: 2, # 'K'
|
| 1451 |
+
49: 0, # 'L'
|
| 1452 |
+
20: 0, # 'M'
|
| 1453 |
+
46: 2, # 'N'
|
| 1454 |
+
42: 0, # 'O'
|
| 1455 |
+
48: 2, # 'P'
|
| 1456 |
+
44: 1, # 'R'
|
| 1457 |
+
35: 1, # 'S'
|
| 1458 |
+
31: 0, # 'T'
|
| 1459 |
+
51: 1, # 'U'
|
| 1460 |
+
38: 2, # 'V'
|
| 1461 |
+
62: 0, # 'W'
|
| 1462 |
+
43: 0, # 'Y'
|
| 1463 |
+
56: 0, # 'Z'
|
| 1464 |
+
1: 3, # 'a'
|
| 1465 |
+
21: 0, # 'b'
|
| 1466 |
+
28: 2, # 'c'
|
| 1467 |
+
12: 0, # 'd'
|
| 1468 |
+
2: 2, # 'e'
|
| 1469 |
+
18: 0, # 'f'
|
| 1470 |
+
27: 0, # 'g'
|
| 1471 |
+
25: 0, # 'h'
|
| 1472 |
+
3: 0, # 'i'
|
| 1473 |
+
24: 1, # 'j'
|
| 1474 |
+
10: 1, # 'k'
|
| 1475 |
+
5: 1, # 'l'
|
| 1476 |
+
13: 3, # 'm'
|
| 1477 |
+
4: 0, # 'n'
|
| 1478 |
+
15: 2, # 'o'
|
| 1479 |
+
26: 0, # 'p'
|
| 1480 |
+
7: 0, # 'r'
|
| 1481 |
+
8: 0, # 's'
|
| 1482 |
+
9: 0, # 't'
|
| 1483 |
+
14: 3, # 'u'
|
| 1484 |
+
32: 0, # 'v'
|
| 1485 |
+
57: 0, # 'w'
|
| 1486 |
+
58: 1, # 'x'
|
| 1487 |
+
11: 0, # 'y'
|
| 1488 |
+
22: 2, # 'z'
|
| 1489 |
+
63: 0, # '·'
|
| 1490 |
+
54: 1, # 'Ç'
|
| 1491 |
+
50: 2, # 'Ö'
|
| 1492 |
+
55: 1, # 'Ü'
|
| 1493 |
+
59: 1, # 'â'
|
| 1494 |
+
33: 0, # 'ç'
|
| 1495 |
+
61: 0, # 'î'
|
| 1496 |
+
34: 1, # 'ö'
|
| 1497 |
+
17: 0, # 'ü'
|
| 1498 |
+
30: 1, # 'ğ'
|
| 1499 |
+
41: 1, # 'İ'
|
| 1500 |
+
6: 0, # 'ı'
|
| 1501 |
+
40: 2, # 'Ş'
|
| 1502 |
+
19: 1, # 'ş'
|
| 1503 |
+
},
|
| 1504 |
+
56: { # 'Z'
|
| 1505 |
+
23: 0, # 'A'
|
| 1506 |
+
37: 0, # 'B'
|
| 1507 |
+
47: 0, # 'C'
|
| 1508 |
+
39: 0, # 'D'
|
| 1509 |
+
29: 0, # 'E'
|
| 1510 |
+
52: 0, # 'F'
|
| 1511 |
+
36: 0, # 'G'
|
| 1512 |
+
45: 0, # 'H'
|
| 1513 |
+
53: 0, # 'I'
|
| 1514 |
+
60: 0, # 'J'
|
| 1515 |
+
16: 0, # 'K'
|
| 1516 |
+
49: 0, # 'L'
|
| 1517 |
+
20: 0, # 'M'
|
| 1518 |
+
46: 0, # 'N'
|
| 1519 |
+
42: 0, # 'O'
|
| 1520 |
+
48: 0, # 'P'
|
| 1521 |
+
44: 0, # 'R'
|
| 1522 |
+
35: 0, # 'S'
|
| 1523 |
+
31: 0, # 'T'
|
| 1524 |
+
51: 0, # 'U'
|
| 1525 |
+
38: 0, # 'V'
|
| 1526 |
+
62: 0, # 'W'
|
| 1527 |
+
43: 0, # 'Y'
|
| 1528 |
+
56: 2, # 'Z'
|
| 1529 |
+
1: 2, # 'a'
|
| 1530 |
+
21: 1, # 'b'
|
| 1531 |
+
28: 0, # 'c'
|
| 1532 |
+
12: 0, # 'd'
|
| 1533 |
+
2: 2, # 'e'
|
| 1534 |
+
18: 0, # 'f'
|
| 1535 |
+
27: 0, # 'g'
|
| 1536 |
+
25: 0, # 'h'
|
| 1537 |
+
3: 2, # 'i'
|
| 1538 |
+
24: 1, # 'j'
|
| 1539 |
+
10: 0, # 'k'
|
| 1540 |
+
5: 0, # 'l'
|
| 1541 |
+
13: 1, # 'm'
|
| 1542 |
+
4: 1, # 'n'
|
| 1543 |
+
15: 0, # 'o'
|
| 1544 |
+
26: 0, # 'p'
|
| 1545 |
+
7: 1, # 'r'
|
| 1546 |
+
8: 1, # 's'
|
| 1547 |
+
9: 0, # 't'
|
| 1548 |
+
14: 2, # 'u'
|
| 1549 |
+
32: 0, # 'v'
|
| 1550 |
+
57: 0, # 'w'
|
| 1551 |
+
58: 0, # 'x'
|
| 1552 |
+
11: 0, # 'y'
|
| 1553 |
+
22: 0, # 'z'
|
| 1554 |
+
63: 0, # '·'
|
| 1555 |
+
54: 0, # 'Ç'
|
| 1556 |
+
50: 0, # 'Ö'
|
| 1557 |
+
55: 0, # 'Ü'
|
| 1558 |
+
59: 0, # 'â'
|
| 1559 |
+
33: 0, # 'ç'
|
| 1560 |
+
61: 0, # 'î'
|
| 1561 |
+
34: 0, # 'ö'
|
| 1562 |
+
17: 1, # 'ü'
|
| 1563 |
+
30: 0, # 'ğ'
|
| 1564 |
+
41: 0, # 'İ'
|
| 1565 |
+
6: 1, # 'ı'
|
| 1566 |
+
40: 0, # 'Ş'
|
| 1567 |
+
19: 0, # 'ş'
|
| 1568 |
+
},
|
| 1569 |
+
1: { # 'a'
|
| 1570 |
+
23: 3, # 'A'
|
| 1571 |
+
37: 0, # 'B'
|
| 1572 |
+
47: 1, # 'C'
|
| 1573 |
+
39: 0, # 'D'
|
| 1574 |
+
29: 3, # 'E'
|
| 1575 |
+
52: 0, # 'F'
|
| 1576 |
+
36: 1, # 'G'
|
| 1577 |
+
45: 1, # 'H'
|
| 1578 |
+
53: 0, # 'I'
|
| 1579 |
+
60: 0, # 'J'
|
| 1580 |
+
16: 0, # 'K'
|
| 1581 |
+
49: 0, # 'L'
|
| 1582 |
+
20: 3, # 'M'
|
| 1583 |
+
46: 1, # 'N'
|
| 1584 |
+
42: 0, # 'O'
|
| 1585 |
+
48: 1, # 'P'
|
| 1586 |
+
44: 0, # 'R'
|
| 1587 |
+
35: 0, # 'S'
|
| 1588 |
+
31: 3, # 'T'
|
| 1589 |
+
51: 0, # 'U'
|
| 1590 |
+
38: 1, # 'V'
|
| 1591 |
+
62: 0, # 'W'
|
| 1592 |
+
43: 0, # 'Y'
|
| 1593 |
+
56: 2, # 'Z'
|
| 1594 |
+
1: 2, # 'a'
|
| 1595 |
+
21: 3, # 'b'
|
| 1596 |
+
28: 0, # 'c'
|
| 1597 |
+
12: 3, # 'd'
|
| 1598 |
+
2: 2, # 'e'
|
| 1599 |
+
18: 3, # 'f'
|
| 1600 |
+
27: 3, # 'g'
|
| 1601 |
+
25: 3, # 'h'
|
| 1602 |
+
3: 3, # 'i'
|
| 1603 |
+
24: 3, # 'j'
|
| 1604 |
+
10: 3, # 'k'
|
| 1605 |
+
5: 0, # 'l'
|
| 1606 |
+
13: 2, # 'm'
|
| 1607 |
+
4: 3, # 'n'
|
| 1608 |
+
15: 1, # 'o'
|
| 1609 |
+
26: 3, # 'p'
|
| 1610 |
+
7: 3, # 'r'
|
| 1611 |
+
8: 3, # 's'
|
| 1612 |
+
9: 3, # 't'
|
| 1613 |
+
14: 3, # 'u'
|
| 1614 |
+
32: 3, # 'v'
|
| 1615 |
+
57: 2, # 'w'
|
| 1616 |
+
58: 0, # 'x'
|
| 1617 |
+
11: 3, # 'y'
|
| 1618 |
+
22: 0, # 'z'
|
| 1619 |
+
63: 1, # '·'
|
| 1620 |
+
54: 0, # 'Ç'
|
| 1621 |
+
50: 0, # 'Ö'
|
| 1622 |
+
55: 0, # 'Ü'
|
| 1623 |
+
59: 0, # 'â'
|
| 1624 |
+
33: 1, # 'ç'
|
| 1625 |
+
61: 1, # 'î'
|
| 1626 |
+
34: 1, # 'ö'
|
| 1627 |
+
17: 3, # 'ü'
|
| 1628 |
+
30: 0, # 'ğ'
|
| 1629 |
+
41: 0, # 'İ'
|
| 1630 |
+
6: 3, # 'ı'
|
| 1631 |
+
40: 0, # 'Ş'
|
| 1632 |
+
19: 1, # 'ş'
|
| 1633 |
+
},
|
| 1634 |
+
21: { # 'b'
|
| 1635 |
+
23: 0, # 'A'
|
| 1636 |
+
37: 0, # 'B'
|
| 1637 |
+
47: 0, # 'C'
|
| 1638 |
+
39: 0, # 'D'
|
| 1639 |
+
29: 0, # 'E'
|
| 1640 |
+
52: 0, # 'F'
|
| 1641 |
+
36: 1, # 'G'
|
| 1642 |
+
45: 0, # 'H'
|
| 1643 |
+
53: 0, # 'I'
|
| 1644 |
+
60: 1, # 'J'
|
| 1645 |
+
16: 2, # 'K'
|
| 1646 |
+
49: 0, # 'L'
|
| 1647 |
+
20: 2, # 'M'
|
| 1648 |
+
46: 0, # 'N'
|
| 1649 |
+
42: 0, # 'O'
|
| 1650 |
+
48: 0, # 'P'
|
| 1651 |
+
44: 0, # 'R'
|
| 1652 |
+
35: 0, # 'S'
|
| 1653 |
+
31: 1, # 'T'
|
| 1654 |
+
51: 0, # 'U'
|
| 1655 |
+
38: 0, # 'V'
|
| 1656 |
+
62: 0, # 'W'
|
| 1657 |
+
43: 1, # 'Y'
|
| 1658 |
+
56: 0, # 'Z'
|
| 1659 |
+
1: 3, # 'a'
|
| 1660 |
+
21: 2, # 'b'
|
| 1661 |
+
28: 0, # 'c'
|
| 1662 |
+
12: 3, # 'd'
|
| 1663 |
+
2: 3, # 'e'
|
| 1664 |
+
18: 0, # 'f'
|
| 1665 |
+
27: 3, # 'g'
|
| 1666 |
+
25: 1, # 'h'
|
| 1667 |
+
3: 3, # 'i'
|
| 1668 |
+
24: 2, # 'j'
|
| 1669 |
+
10: 3, # 'k'
|
| 1670 |
+
5: 3, # 'l'
|
| 1671 |
+
13: 3, # 'm'
|
| 1672 |
+
4: 3, # 'n'
|
| 1673 |
+
15: 0, # 'o'
|
| 1674 |
+
26: 3, # 'p'
|
| 1675 |
+
7: 1, # 'r'
|
| 1676 |
+
8: 2, # 's'
|
| 1677 |
+
9: 2, # 't'
|
| 1678 |
+
14: 2, # 'u'
|
| 1679 |
+
32: 1, # 'v'
|
| 1680 |
+
57: 0, # 'w'
|
| 1681 |
+
58: 1, # 'x'
|
| 1682 |
+
11: 3, # 'y'
|
| 1683 |
+
22: 0, # 'z'
|
| 1684 |
+
63: 0, # '·'
|
| 1685 |
+
54: 0, # 'Ç'
|
| 1686 |
+
50: 0, # 'Ö'
|
| 1687 |
+
55: 0, # 'Ü'
|
| 1688 |
+
59: 0, # 'â'
|
| 1689 |
+
33: 1, # 'ç'
|
| 1690 |
+
61: 0, # 'î'
|
| 1691 |
+
34: 0, # 'ö'
|
| 1692 |
+
17: 0, # 'ü'
|
| 1693 |
+
30: 1, # 'ğ'
|
| 1694 |
+
41: 0, # 'İ'
|
| 1695 |
+
6: 2, # 'ı'
|
| 1696 |
+
40: 0, # 'Ş'
|
| 1697 |
+
19: 0, # 'ş'
|
| 1698 |
+
},
|
| 1699 |
+
28: { # 'c'
|
| 1700 |
+
23: 0, # 'A'
|
| 1701 |
+
37: 1, # 'B'
|
| 1702 |
+
47: 1, # 'C'
|
| 1703 |
+
39: 1, # 'D'
|
| 1704 |
+
29: 2, # 'E'
|
| 1705 |
+
52: 0, # 'F'
|
| 1706 |
+
36: 2, # 'G'
|
| 1707 |
+
45: 2, # 'H'
|
| 1708 |
+
53: 1, # 'I'
|
| 1709 |
+
60: 0, # 'J'
|
| 1710 |
+
16: 0, # 'K'
|
| 1711 |
+
49: 0, # 'L'
|
| 1712 |
+
20: 2, # 'M'
|
| 1713 |
+
46: 1, # 'N'
|
| 1714 |
+
42: 1, # 'O'
|
| 1715 |
+
48: 2, # 'P'
|
| 1716 |
+
44: 1, # 'R'
|
| 1717 |
+
35: 1, # 'S'
|
| 1718 |
+
31: 2, # 'T'
|
| 1719 |
+
51: 2, # 'U'
|
| 1720 |
+
38: 2, # 'V'
|
| 1721 |
+
62: 0, # 'W'
|
| 1722 |
+
43: 3, # 'Y'
|
| 1723 |
+
56: 0, # 'Z'
|
| 1724 |
+
1: 1, # 'a'
|
| 1725 |
+
21: 1, # 'b'
|
| 1726 |
+
28: 2, # 'c'
|
| 1727 |
+
12: 2, # 'd'
|
| 1728 |
+
2: 1, # 'e'
|
| 1729 |
+
18: 1, # 'f'
|
| 1730 |
+
27: 2, # 'g'
|
| 1731 |
+
25: 2, # 'h'
|
| 1732 |
+
3: 3, # 'i'
|
| 1733 |
+
24: 1, # 'j'
|
| 1734 |
+
10: 3, # 'k'
|
| 1735 |
+
5: 0, # 'l'
|
| 1736 |
+
13: 2, # 'm'
|
| 1737 |
+
4: 3, # 'n'
|
| 1738 |
+
15: 2, # 'o'
|
| 1739 |
+
26: 2, # 'p'
|
| 1740 |
+
7: 3, # 'r'
|
| 1741 |
+
8: 3, # 's'
|
| 1742 |
+
9: 3, # 't'
|
| 1743 |
+
14: 1, # 'u'
|
| 1744 |
+
32: 0, # 'v'
|
| 1745 |
+
57: 1, # 'w'
|
| 1746 |
+
58: 0, # 'x'
|
| 1747 |
+
11: 2, # 'y'
|
| 1748 |
+
22: 1, # 'z'
|
| 1749 |
+
63: 1, # '·'
|
| 1750 |
+
54: 0, # 'Ç'
|
| 1751 |
+
50: 0, # 'Ö'
|
| 1752 |
+
55: 1, # 'Ü'
|
| 1753 |
+
59: 0, # 'â'
|
| 1754 |
+
33: 0, # 'ç'
|
| 1755 |
+
61: 1, # 'î'
|
| 1756 |
+
34: 2, # 'ö'
|
| 1757 |
+
17: 2, # 'ü'
|
| 1758 |
+
30: 2, # 'ğ'
|
| 1759 |
+
41: 1, # 'İ'
|
| 1760 |
+
6: 3, # 'ı'
|
| 1761 |
+
40: 0, # 'Ş'
|
| 1762 |
+
19: 2, # 'ş'
|
| 1763 |
+
},
|
| 1764 |
+
12: { # 'd'
|
| 1765 |
+
23: 1, # 'A'
|
| 1766 |
+
37: 0, # 'B'
|
| 1767 |
+
47: 0, # 'C'
|
| 1768 |
+
39: 0, # 'D'
|
| 1769 |
+
29: 0, # 'E'
|
| 1770 |
+
52: 0, # 'F'
|
| 1771 |
+
36: 0, # 'G'
|
| 1772 |
+
45: 0, # 'H'
|
| 1773 |
+
53: 0, # 'I'
|
| 1774 |
+
60: 2, # 'J'
|
| 1775 |
+
16: 3, # 'K'
|
| 1776 |
+
49: 0, # 'L'
|
| 1777 |
+
20: 3, # 'M'
|
| 1778 |
+
46: 0, # 'N'
|
| 1779 |
+
42: 0, # 'O'
|
| 1780 |
+
48: 0, # 'P'
|
| 1781 |
+
44: 0, # 'R'
|
| 1782 |
+
35: 1, # 'S'
|
| 1783 |
+
31: 1, # 'T'
|
| 1784 |
+
51: 0, # 'U'
|
| 1785 |
+
38: 0, # 'V'
|
| 1786 |
+
62: 0, # 'W'
|
| 1787 |
+
43: 0, # 'Y'
|
| 1788 |
+
56: 0, # 'Z'
|
| 1789 |
+
1: 3, # 'a'
|
| 1790 |
+
21: 2, # 'b'
|
| 1791 |
+
28: 1, # 'c'
|
| 1792 |
+
12: 3, # 'd'
|
| 1793 |
+
2: 3, # 'e'
|
| 1794 |
+
18: 1, # 'f'
|
| 1795 |
+
27: 3, # 'g'
|
| 1796 |
+
25: 3, # 'h'
|
| 1797 |
+
3: 2, # 'i'
|
| 1798 |
+
24: 3, # 'j'
|
| 1799 |
+
10: 2, # 'k'
|
| 1800 |
+
5: 3, # 'l'
|
| 1801 |
+
13: 3, # 'm'
|
| 1802 |
+
4: 3, # 'n'
|
| 1803 |
+
15: 1, # 'o'
|
| 1804 |
+
26: 2, # 'p'
|
| 1805 |
+
7: 3, # 'r'
|
| 1806 |
+
8: 2, # 's'
|
| 1807 |
+
9: 2, # 't'
|
| 1808 |
+
14: 3, # 'u'
|
| 1809 |
+
32: 1, # 'v'
|
| 1810 |
+
57: 0, # 'w'
|
| 1811 |
+
58: 1, # 'x'
|
| 1812 |
+
11: 3, # 'y'
|
| 1813 |
+
22: 1, # 'z'
|
| 1814 |
+
63: 1, # '·'
|
| 1815 |
+
54: 0, # 'Ç'
|
| 1816 |
+
50: 0, # 'Ö'
|
| 1817 |
+
55: 0, # 'Ü'
|
| 1818 |
+
59: 0, # 'â'
|
| 1819 |
+
33: 0, # 'ç'
|
| 1820 |
+
61: 0, # 'î'
|
| 1821 |
+
34: 0, # 'ö'
|
| 1822 |
+
17: 1, # 'ü'
|
| 1823 |
+
30: 0, # 'ğ'
|
| 1824 |
+
41: 0, # 'İ'
|
| 1825 |
+
6: 2, # 'ı'
|
| 1826 |
+
40: 0, # 'Ş'
|
| 1827 |
+
19: 0, # 'ş'
|
| 1828 |
+
},
|
| 1829 |
+
2: { # 'e'
|
| 1830 |
+
23: 2, # 'A'
|
| 1831 |
+
37: 0, # 'B'
|
| 1832 |
+
47: 2, # 'C'
|
| 1833 |
+
39: 0, # 'D'
|
| 1834 |
+
29: 3, # 'E'
|
| 1835 |
+
52: 1, # 'F'
|
| 1836 |
+
36: 0, # 'G'
|
| 1837 |
+
45: 0, # 'H'
|
| 1838 |
+
53: 0, # 'I'
|
| 1839 |
+
60: 0, # 'J'
|
| 1840 |
+
16: 1, # 'K'
|
| 1841 |
+
49: 0, # 'L'
|
| 1842 |
+
20: 3, # 'M'
|
| 1843 |
+
46: 1, # 'N'
|
| 1844 |
+
42: 0, # 'O'
|
| 1845 |
+
48: 1, # 'P'
|
| 1846 |
+
44: 1, # 'R'
|
| 1847 |
+
35: 0, # 'S'
|
| 1848 |
+
31: 3, # 'T'
|
| 1849 |
+
51: 0, # 'U'
|
| 1850 |
+
38: 1, # 'V'
|
| 1851 |
+
62: 0, # 'W'
|
| 1852 |
+
43: 1, # 'Y'
|
| 1853 |
+
56: 0, # 'Z'
|
| 1854 |
+
1: 3, # 'a'
|
| 1855 |
+
21: 3, # 'b'
|
| 1856 |
+
28: 0, # 'c'
|
| 1857 |
+
12: 3, # 'd'
|
| 1858 |
+
2: 2, # 'e'
|
| 1859 |
+
18: 3, # 'f'
|
| 1860 |
+
27: 3, # 'g'
|
| 1861 |
+
25: 3, # 'h'
|
| 1862 |
+
3: 3, # 'i'
|
| 1863 |
+
24: 3, # 'j'
|
| 1864 |
+
10: 3, # 'k'
|
| 1865 |
+
5: 0, # 'l'
|
| 1866 |
+
13: 2, # 'm'
|
| 1867 |
+
4: 3, # 'n'
|
| 1868 |
+
15: 1, # 'o'
|
| 1869 |
+
26: 3, # 'p'
|
| 1870 |
+
7: 3, # 'r'
|
| 1871 |
+
8: 3, # 's'
|
| 1872 |
+
9: 3, # 't'
|
| 1873 |
+
14: 3, # 'u'
|
| 1874 |
+
32: 3, # 'v'
|
| 1875 |
+
57: 2, # 'w'
|
| 1876 |
+
58: 0, # 'x'
|
| 1877 |
+
11: 3, # 'y'
|
| 1878 |
+
22: 1, # 'z'
|
| 1879 |
+
63: 1, # '·'
|
| 1880 |
+
54: 0, # 'Ç'
|
| 1881 |
+
50: 0, # 'Ö'
|
| 1882 |
+
55: 0, # 'Ü'
|
| 1883 |
+
59: 0, # 'â'
|
| 1884 |
+
33: 1, # 'ç'
|
| 1885 |
+
61: 0, # 'î'
|
| 1886 |
+
34: 1, # 'ö'
|
| 1887 |
+
17: 3, # 'ü'
|
| 1888 |
+
30: 0, # 'ğ'
|
| 1889 |
+
41: 0, # 'İ'
|
| 1890 |
+
6: 3, # 'ı'
|
| 1891 |
+
40: 0, # 'Ş'
|
| 1892 |
+
19: 0, # 'ş'
|
| 1893 |
+
},
|
| 1894 |
+
18: { # 'f'
|
| 1895 |
+
23: 0, # 'A'
|
| 1896 |
+
37: 0, # 'B'
|
| 1897 |
+
47: 0, # 'C'
|
| 1898 |
+
39: 0, # 'D'
|
| 1899 |
+
29: 0, # 'E'
|
| 1900 |
+
52: 0, # 'F'
|
| 1901 |
+
36: 0, # 'G'
|
| 1902 |
+
45: 0, # 'H'
|
| 1903 |
+
53: 0, # 'I'
|
| 1904 |
+
60: 0, # 'J'
|
| 1905 |
+
16: 2, # 'K'
|
| 1906 |
+
49: 0, # 'L'
|
| 1907 |
+
20: 2, # 'M'
|
| 1908 |
+
46: 0, # 'N'
|
| 1909 |
+
42: 0, # 'O'
|
| 1910 |
+
48: 0, # 'P'
|
| 1911 |
+
44: 0, # 'R'
|
| 1912 |
+
35: 0, # 'S'
|
| 1913 |
+
31: 2, # 'T'
|
| 1914 |
+
51: 0, # 'U'
|
| 1915 |
+
38: 0, # 'V'
|
| 1916 |
+
62: 0, # 'W'
|
| 1917 |
+
43: 0, # 'Y'
|
| 1918 |
+
56: 0, # 'Z'
|
| 1919 |
+
1: 3, # 'a'
|
| 1920 |
+
21: 1, # 'b'
|
| 1921 |
+
28: 0, # 'c'
|
| 1922 |
+
12: 3, # 'd'
|
| 1923 |
+
2: 3, # 'e'
|
| 1924 |
+
18: 2, # 'f'
|
| 1925 |
+
27: 1, # 'g'
|
| 1926 |
+
25: 1, # 'h'
|
| 1927 |
+
3: 1, # 'i'
|
| 1928 |
+
24: 1, # 'j'
|
| 1929 |
+
10: 1, # 'k'
|
| 1930 |
+
5: 3, # 'l'
|
| 1931 |
+
13: 3, # 'm'
|
| 1932 |
+
4: 3, # 'n'
|
| 1933 |
+
15: 0, # 'o'
|
| 1934 |
+
26: 2, # 'p'
|
| 1935 |
+
7: 1, # 'r'
|
| 1936 |
+
8: 3, # 's'
|
| 1937 |
+
9: 3, # 't'
|
| 1938 |
+
14: 1, # 'u'
|
| 1939 |
+
32: 2, # 'v'
|
| 1940 |
+
57: 0, # 'w'
|
| 1941 |
+
58: 0, # 'x'
|
| 1942 |
+
11: 1, # 'y'
|
| 1943 |
+
22: 0, # 'z'
|
| 1944 |
+
63: 0, # '·'
|
| 1945 |
+
54: 0, # 'Ç'
|
| 1946 |
+
50: 0, # 'Ö'
|
| 1947 |
+
55: 0, # 'Ü'
|
| 1948 |
+
59: 0, # 'â'
|
| 1949 |
+
33: 1, # 'ç'
|
| 1950 |
+
61: 0, # 'î'
|
| 1951 |
+
34: 0, # 'ö'
|
| 1952 |
+
17: 1, # 'ü'
|
| 1953 |
+
30: 0, # 'ğ'
|
| 1954 |
+
41: 0, # 'İ'
|
| 1955 |
+
6: 1, # 'ı'
|
| 1956 |
+
40: 0, # 'Ş'
|
| 1957 |
+
19: 0, # 'ş'
|
| 1958 |
+
},
|
| 1959 |
+
27: { # 'g'
|
| 1960 |
+
23: 0, # 'A'
|
| 1961 |
+
37: 0, # 'B'
|
| 1962 |
+
47: 0, # 'C'
|
| 1963 |
+
39: 0, # 'D'
|
| 1964 |
+
29: 0, # 'E'
|
| 1965 |
+
52: 0, # 'F'
|
| 1966 |
+
36: 0, # 'G'
|
| 1967 |
+
45: 0, # 'H'
|
| 1968 |
+
53: 0, # 'I'
|
| 1969 |
+
60: 0, # 'J'
|
| 1970 |
+
16: 3, # 'K'
|
| 1971 |
+
49: 0, # 'L'
|
| 1972 |
+
20: 0, # 'M'
|
| 1973 |
+
46: 0, # 'N'
|
| 1974 |
+
42: 0, # 'O'
|
| 1975 |
+
48: 0, # 'P'
|
| 1976 |
+
44: 0, # 'R'
|
| 1977 |
+
35: 1, # 'S'
|
| 1978 |
+
31: 1, # 'T'
|
| 1979 |
+
51: 0, # 'U'
|
| 1980 |
+
38: 2, # 'V'
|
| 1981 |
+
62: 0, # 'W'
|
| 1982 |
+
43: 0, # 'Y'
|
| 1983 |
+
56: 0, # 'Z'
|
| 1984 |
+
1: 3, # 'a'
|
| 1985 |
+
21: 1, # 'b'
|
| 1986 |
+
28: 0, # 'c'
|
| 1987 |
+
12: 1, # 'd'
|
| 1988 |
+
2: 3, # 'e'
|
| 1989 |
+
18: 0, # 'f'
|
| 1990 |
+
27: 2, # 'g'
|
| 1991 |
+
25: 1, # 'h'
|
| 1992 |
+
3: 2, # 'i'
|
| 1993 |
+
24: 3, # 'j'
|
| 1994 |
+
10: 2, # 'k'
|
| 1995 |
+
5: 3, # 'l'
|
| 1996 |
+
13: 3, # 'm'
|
| 1997 |
+
4: 2, # 'n'
|
| 1998 |
+
15: 0, # 'o'
|
| 1999 |
+
26: 1, # 'p'
|
| 2000 |
+
7: 2, # 'r'
|
| 2001 |
+
8: 2, # 's'
|
| 2002 |
+
9: 3, # 't'
|
| 2003 |
+
14: 3, # 'u'
|
| 2004 |
+
32: 1, # 'v'
|
| 2005 |
+
57: 0, # 'w'
|
| 2006 |
+
58: 0, # 'x'
|
| 2007 |
+
11: 1, # 'y'
|
| 2008 |
+
22: 0, # 'z'
|
| 2009 |
+
63: 1, # '·'
|
| 2010 |
+
54: 0, # 'Ç'
|
| 2011 |
+
50: 0, # 'Ö'
|
| 2012 |
+
55: 0, # 'Ü'
|
| 2013 |
+
59: 0, # 'â'
|
| 2014 |
+
33: 0, # 'ç'
|
| 2015 |
+
61: 0, # 'î'
|
| 2016 |
+
34: 0, # 'ö'
|
| 2017 |
+
17: 0, # 'ü'
|
| 2018 |
+
30: 0, # 'ğ'
|
| 2019 |
+
41: 0, # 'İ'
|
| 2020 |
+
6: 2, # 'ı'
|
| 2021 |
+
40: 0, # 'Ş'
|
| 2022 |
+
19: 0, # 'ş'
|
| 2023 |
+
},
|
| 2024 |
+
25: { # 'h'
|
| 2025 |
+
23: 0, # 'A'
|
| 2026 |
+
37: 0, # 'B'
|
| 2027 |
+
47: 0, # 'C'
|
| 2028 |
+
39: 0, # 'D'
|
| 2029 |
+
29: 0, # 'E'
|
| 2030 |
+
52: 0, # 'F'
|
| 2031 |
+
36: 0, # 'G'
|
| 2032 |
+
45: 0, # 'H'
|
| 2033 |
+
53: 0, # 'I'
|
| 2034 |
+
60: 0, # 'J'
|
| 2035 |
+
16: 2, # 'K'
|
| 2036 |
+
49: 0, # 'L'
|
| 2037 |
+
20: 0, # 'M'
|
| 2038 |
+
46: 0, # 'N'
|
| 2039 |
+
42: 0, # 'O'
|
| 2040 |
+
48: 0, # 'P'
|
| 2041 |
+
44: 0, # 'R'
|
| 2042 |
+
35: 0, # 'S'
|
| 2043 |
+
31: 0, # 'T'
|
| 2044 |
+
51: 0, # 'U'
|
| 2045 |
+
38: 0, # 'V'
|
| 2046 |
+
62: 0, # 'W'
|
| 2047 |
+
43: 0, # 'Y'
|
| 2048 |
+
56: 0, # 'Z'
|
| 2049 |
+
1: 3, # 'a'
|
| 2050 |
+
21: 0, # 'b'
|
| 2051 |
+
28: 0, # 'c'
|
| 2052 |
+
12: 2, # 'd'
|
| 2053 |
+
2: 3, # 'e'
|
| 2054 |
+
18: 0, # 'f'
|
| 2055 |
+
27: 1, # 'g'
|
| 2056 |
+
25: 2, # 'h'
|
| 2057 |
+
3: 2, # 'i'
|
| 2058 |
+
24: 3, # 'j'
|
| 2059 |
+
10: 3, # 'k'
|
| 2060 |
+
5: 3, # 'l'
|
| 2061 |
+
13: 3, # 'm'
|
| 2062 |
+
4: 3, # 'n'
|
| 2063 |
+
15: 1, # 'o'
|
| 2064 |
+
26: 1, # 'p'
|
| 2065 |
+
7: 3, # 'r'
|
| 2066 |
+
8: 3, # 's'
|
| 2067 |
+
9: 2, # 't'
|
| 2068 |
+
14: 3, # 'u'
|
| 2069 |
+
32: 2, # 'v'
|
| 2070 |
+
57: 1, # 'w'
|
| 2071 |
+
58: 0, # 'x'
|
| 2072 |
+
11: 1, # 'y'
|
| 2073 |
+
22: 0, # 'z'
|
| 2074 |
+
63: 0, # '·'
|
| 2075 |
+
54: 0, # 'Ç'
|
| 2076 |
+
50: 0, # 'Ö'
|
| 2077 |
+
55: 0, # 'Ü'
|
| 2078 |
+
59: 0, # 'â'
|
| 2079 |
+
33: 0, # 'ç'
|
| 2080 |
+
61: 0, # 'î'
|
| 2081 |
+
34: 0, # 'ö'
|
| 2082 |
+
17: 0, # 'ü'
|
| 2083 |
+
30: 0, # 'ğ'
|
| 2084 |
+
41: 0, # 'İ'
|
| 2085 |
+
6: 3, # 'ı'
|
| 2086 |
+
40: 0, # 'Ş'
|
| 2087 |
+
19: 0, # 'ş'
|
| 2088 |
+
},
|
| 2089 |
+
3: { # 'i'
|
| 2090 |
+
23: 2, # 'A'
|
| 2091 |
+
37: 0, # 'B'
|
| 2092 |
+
47: 0, # 'C'
|
| 2093 |
+
39: 0, # 'D'
|
| 2094 |
+
29: 0, # 'E'
|
| 2095 |
+
52: 0, # 'F'
|
| 2096 |
+
36: 0, # 'G'
|
| 2097 |
+
45: 0, # 'H'
|
| 2098 |
+
53: 0, # 'I'
|
| 2099 |
+
60: 1, # 'J'
|
| 2100 |
+
16: 3, # 'K'
|
| 2101 |
+
49: 0, # 'L'
|
| 2102 |
+
20: 3, # 'M'
|
| 2103 |
+
46: 0, # 'N'
|
| 2104 |
+
42: 1, # 'O'
|
| 2105 |
+
48: 0, # 'P'
|
| 2106 |
+
44: 0, # 'R'
|
| 2107 |
+
35: 1, # 'S'
|
| 2108 |
+
31: 2, # 'T'
|
| 2109 |
+
51: 0, # 'U'
|
| 2110 |
+
38: 1, # 'V'
|
| 2111 |
+
62: 0, # 'W'
|
| 2112 |
+
43: 0, # 'Y'
|
| 2113 |
+
56: 0, # 'Z'
|
| 2114 |
+
1: 3, # 'a'
|
| 2115 |
+
21: 2, # 'b'
|
| 2116 |
+
28: 0, # 'c'
|
| 2117 |
+
12: 3, # 'd'
|
| 2118 |
+
2: 3, # 'e'
|
| 2119 |
+
18: 2, # 'f'
|
| 2120 |
+
27: 3, # 'g'
|
| 2121 |
+
25: 1, # 'h'
|
| 2122 |
+
3: 3, # 'i'
|
| 2123 |
+
24: 2, # 'j'
|
| 2124 |
+
10: 3, # 'k'
|
| 2125 |
+
5: 3, # 'l'
|
| 2126 |
+
13: 3, # 'm'
|
| 2127 |
+
4: 3, # 'n'
|
| 2128 |
+
15: 1, # 'o'
|
| 2129 |
+
26: 3, # 'p'
|
| 2130 |
+
7: 3, # 'r'
|
| 2131 |
+
8: 3, # 's'
|
| 2132 |
+
9: 3, # 't'
|
| 2133 |
+
14: 3, # 'u'
|
| 2134 |
+
32: 2, # 'v'
|
| 2135 |
+
57: 1, # 'w'
|
| 2136 |
+
58: 1, # 'x'
|
| 2137 |
+
11: 3, # 'y'
|
| 2138 |
+
22: 1, # 'z'
|
| 2139 |
+
63: 1, # '·'
|
| 2140 |
+
54: 0, # 'Ç'
|
| 2141 |
+
50: 0, # 'Ö'
|
| 2142 |
+
55: 1, # 'Ü'
|
| 2143 |
+
59: 0, # 'â'
|
| 2144 |
+
33: 2, # 'ç'
|
| 2145 |
+
61: 0, # 'î'
|
| 2146 |
+
34: 0, # 'ö'
|
| 2147 |
+
17: 3, # 'ü'
|
| 2148 |
+
30: 0, # 'ğ'
|
| 2149 |
+
41: 1, # 'İ'
|
| 2150 |
+
6: 2, # 'ı'
|
| 2151 |
+
40: 0, # 'Ş'
|
| 2152 |
+
19: 0, # 'ş'
|
| 2153 |
+
},
|
| 2154 |
+
24: { # 'j'
|
| 2155 |
+
23: 0, # 'A'
|
| 2156 |
+
37: 0, # 'B'
|
| 2157 |
+
47: 0, # 'C'
|
| 2158 |
+
39: 0, # 'D'
|
| 2159 |
+
29: 0, # 'E'
|
| 2160 |
+
52: 0, # 'F'
|
| 2161 |
+
36: 0, # 'G'
|
| 2162 |
+
45: 0, # 'H'
|
| 2163 |
+
53: 0, # 'I'
|
| 2164 |
+
60: 1, # 'J'
|
| 2165 |
+
16: 2, # 'K'
|
| 2166 |
+
49: 0, # 'L'
|
| 2167 |
+
20: 2, # 'M'
|
| 2168 |
+
46: 0, # 'N'
|
| 2169 |
+
42: 0, # 'O'
|
| 2170 |
+
48: 1, # 'P'
|
| 2171 |
+
44: 0, # 'R'
|
| 2172 |
+
35: 0, # 'S'
|
| 2173 |
+
31: 1, # 'T'
|
| 2174 |
+
51: 0, # 'U'
|
| 2175 |
+
38: 0, # 'V'
|
| 2176 |
+
62: 0, # 'W'
|
| 2177 |
+
43: 0, # 'Y'
|
| 2178 |
+
56: 1, # 'Z'
|
| 2179 |
+
1: 3, # 'a'
|
| 2180 |
+
21: 1, # 'b'
|
| 2181 |
+
28: 1, # 'c'
|
| 2182 |
+
12: 3, # 'd'
|
| 2183 |
+
2: 3, # 'e'
|
| 2184 |
+
18: 2, # 'f'
|
| 2185 |
+
27: 1, # 'g'
|
| 2186 |
+
25: 1, # 'h'
|
| 2187 |
+
3: 2, # 'i'
|
| 2188 |
+
24: 1, # 'j'
|
| 2189 |
+
10: 2, # 'k'
|
| 2190 |
+
5: 2, # 'l'
|
| 2191 |
+
13: 3, # 'm'
|
| 2192 |
+
4: 2, # 'n'
|
| 2193 |
+
15: 0, # 'o'
|
| 2194 |
+
26: 1, # 'p'
|
| 2195 |
+
7: 2, # 'r'
|
| 2196 |
+
8: 3, # 's'
|
| 2197 |
+
9: 2, # 't'
|
| 2198 |
+
14: 3, # 'u'
|
| 2199 |
+
32: 2, # 'v'
|
| 2200 |
+
57: 0, # 'w'
|
| 2201 |
+
58: 2, # 'x'
|
| 2202 |
+
11: 1, # 'y'
|
| 2203 |
+
22: 0, # 'z'
|
| 2204 |
+
63: 0, # '·'
|
| 2205 |
+
54: 0, # 'Ç'
|
| 2206 |
+
50: 0, # 'Ö'
|
| 2207 |
+
55: 0, # 'Ü'
|
| 2208 |
+
59: 0, # 'â'
|
| 2209 |
+
33: 1, # 'ç'
|
| 2210 |
+
61: 0, # 'î'
|
| 2211 |
+
34: 0, # 'ö'
|
| 2212 |
+
17: 1, # 'ü'
|
| 2213 |
+
30: 0, # 'ğ'
|
| 2214 |
+
41: 0, # 'İ'
|
| 2215 |
+
6: 3, # 'ı'
|
| 2216 |
+
40: 0, # 'Ş'
|
| 2217 |
+
19: 0, # 'ş'
|
| 2218 |
+
},
|
| 2219 |
+
10: { # 'k'
|
| 2220 |
+
23: 0, # 'A'
|
| 2221 |
+
37: 0, # 'B'
|
| 2222 |
+
47: 0, # 'C'
|
| 2223 |
+
39: 0, # 'D'
|
| 2224 |
+
29: 0, # 'E'
|
| 2225 |
+
52: 0, # 'F'
|
| 2226 |
+
36: 0, # 'G'
|
| 2227 |
+
45: 0, # 'H'
|
| 2228 |
+
53: 0, # 'I'
|
| 2229 |
+
60: 0, # 'J'
|
| 2230 |
+
16: 3, # 'K'
|
| 2231 |
+
49: 0, # 'L'
|
| 2232 |
+
20: 2, # 'M'
|
| 2233 |
+
46: 0, # 'N'
|
| 2234 |
+
42: 0, # 'O'
|
| 2235 |
+
48: 0, # 'P'
|
| 2236 |
+
44: 0, # 'R'
|
| 2237 |
+
35: 0, # 'S'
|
| 2238 |
+
31: 3, # 'T'
|
| 2239 |
+
51: 0, # 'U'
|
| 2240 |
+
38: 1, # 'V'
|
| 2241 |
+
62: 0, # 'W'
|
| 2242 |
+
43: 0, # 'Y'
|
| 2243 |
+
56: 1, # 'Z'
|
| 2244 |
+
1: 3, # 'a'
|
| 2245 |
+
21: 2, # 'b'
|
| 2246 |
+
28: 0, # 'c'
|
| 2247 |
+
12: 2, # 'd'
|
| 2248 |
+
2: 3, # 'e'
|
| 2249 |
+
18: 1, # 'f'
|
| 2250 |
+
27: 2, # 'g'
|
| 2251 |
+
25: 2, # 'h'
|
| 2252 |
+
3: 3, # 'i'
|
| 2253 |
+
24: 2, # 'j'
|
| 2254 |
+
10: 2, # 'k'
|
| 2255 |
+
5: 3, # 'l'
|
| 2256 |
+
13: 3, # 'm'
|
| 2257 |
+
4: 3, # 'n'
|
| 2258 |
+
15: 0, # 'o'
|
| 2259 |
+
26: 3, # 'p'
|
| 2260 |
+
7: 2, # 'r'
|
| 2261 |
+
8: 2, # 's'
|
| 2262 |
+
9: 2, # 't'
|
| 2263 |
+
14: 3, # 'u'
|
| 2264 |
+
32: 0, # 'v'
|
| 2265 |
+
57: 0, # 'w'
|
| 2266 |
+
58: 1, # 'x'
|
| 2267 |
+
11: 3, # 'y'
|
| 2268 |
+
22: 0, # 'z'
|
| 2269 |
+
63: 1, # '·'
|
| 2270 |
+
54: 0, # 'Ç'
|
| 2271 |
+
50: 0, # 'Ö'
|
| 2272 |
+
55: 0, # 'Ü'
|
| 2273 |
+
59: 0, # 'â'
|
| 2274 |
+
33: 3, # 'ç'
|
| 2275 |
+
61: 0, # 'î'
|
| 2276 |
+
34: 1, # 'ö'
|
| 2277 |
+
17: 3, # 'ü'
|
| 2278 |
+
30: 1, # 'ğ'
|
| 2279 |
+
41: 0, # 'İ'
|
| 2280 |
+
6: 3, # 'ı'
|
| 2281 |
+
40: 0, # 'Ş'
|
| 2282 |
+
19: 1, # 'ş'
|
| 2283 |
+
},
|
| 2284 |
+
5: { # 'l'
|
| 2285 |
+
23: 0, # 'A'
|
| 2286 |
+
37: 0, # 'B'
|
| 2287 |
+
47: 0, # 'C'
|
| 2288 |
+
39: 0, # 'D'
|
| 2289 |
+
29: 3, # 'E'
|
| 2290 |
+
52: 0, # 'F'
|
| 2291 |
+
36: 0, # 'G'
|
| 2292 |
+
45: 0, # 'H'
|
| 2293 |
+
53: 0, # 'I'
|
| 2294 |
+
60: 0, # 'J'
|
| 2295 |
+
16: 0, # 'K'
|
| 2296 |
+
49: 0, # 'L'
|
| 2297 |
+
20: 2, # 'M'
|
| 2298 |
+
46: 0, # 'N'
|
| 2299 |
+
42: 0, # 'O'
|
| 2300 |
+
48: 0, # 'P'
|
| 2301 |
+
44: 0, # 'R'
|
| 2302 |
+
35: 0, # 'S'
|
| 2303 |
+
31: 1, # 'T'
|
| 2304 |
+
51: 0, # 'U'
|
| 2305 |
+
38: 0, # 'V'
|
| 2306 |
+
62: 0, # 'W'
|
| 2307 |
+
43: 0, # 'Y'
|
| 2308 |
+
56: 0, # 'Z'
|
| 2309 |
+
1: 0, # 'a'
|
| 2310 |
+
21: 3, # 'b'
|
| 2311 |
+
28: 0, # 'c'
|
| 2312 |
+
12: 3, # 'd'
|
| 2313 |
+
2: 1, # 'e'
|
| 2314 |
+
18: 3, # 'f'
|
| 2315 |
+
27: 3, # 'g'
|
| 2316 |
+
25: 2, # 'h'
|
| 2317 |
+
3: 3, # 'i'
|
| 2318 |
+
24: 2, # 'j'
|
| 2319 |
+
10: 3, # 'k'
|
| 2320 |
+
5: 1, # 'l'
|
| 2321 |
+
13: 1, # 'm'
|
| 2322 |
+
4: 3, # 'n'
|
| 2323 |
+
15: 0, # 'o'
|
| 2324 |
+
26: 2, # 'p'
|
| 2325 |
+
7: 3, # 'r'
|
| 2326 |
+
8: 3, # 's'
|
| 2327 |
+
9: 3, # 't'
|
| 2328 |
+
14: 2, # 'u'
|
| 2329 |
+
32: 2, # 'v'
|
| 2330 |
+
57: 0, # 'w'
|
| 2331 |
+
58: 0, # 'x'
|
| 2332 |
+
11: 3, # 'y'
|
| 2333 |
+
22: 0, # 'z'
|
| 2334 |
+
63: 0, # '·'
|
| 2335 |
+
54: 0, # 'Ç'
|
| 2336 |
+
50: 0, # 'Ö'
|
| 2337 |
+
55: 0, # 'Ü'
|
| 2338 |
+
59: 0, # 'â'
|
| 2339 |
+
33: 1, # 'ç'
|
| 2340 |
+
61: 0, # 'î'
|
| 2341 |
+
34: 0, # 'ö'
|
| 2342 |
+
17: 2, # 'ü'
|
| 2343 |
+
30: 0, # 'ğ'
|
| 2344 |
+
41: 0, # 'İ'
|
| 2345 |
+
6: 3, # 'ı'
|
| 2346 |
+
40: 0, # 'Ş'
|
| 2347 |
+
19: 0, # 'ş'
|
| 2348 |
+
},
|
| 2349 |
+
13: { # 'm'
|
| 2350 |
+
23: 1, # 'A'
|
| 2351 |
+
37: 0, # 'B'
|
| 2352 |
+
47: 0, # 'C'
|
| 2353 |
+
39: 0, # 'D'
|
| 2354 |
+
29: 3, # 'E'
|
| 2355 |
+
52: 0, # 'F'
|
| 2356 |
+
36: 0, # 'G'
|
| 2357 |
+
45: 0, # 'H'
|
| 2358 |
+
53: 0, # 'I'
|
| 2359 |
+
60: 0, # 'J'
|
| 2360 |
+
16: 0, # 'K'
|
| 2361 |
+
49: 0, # 'L'
|
| 2362 |
+
20: 3, # 'M'
|
| 2363 |
+
46: 0, # 'N'
|
| 2364 |
+
42: 0, # 'O'
|
| 2365 |
+
48: 0, # 'P'
|
| 2366 |
+
44: 0, # 'R'
|
| 2367 |
+
35: 0, # 'S'
|
| 2368 |
+
31: 3, # 'T'
|
| 2369 |
+
51: 0, # 'U'
|
| 2370 |
+
38: 0, # 'V'
|
| 2371 |
+
62: 0, # 'W'
|
| 2372 |
+
43: 1, # 'Y'
|
| 2373 |
+
56: 0, # 'Z'
|
| 2374 |
+
1: 2, # 'a'
|
| 2375 |
+
21: 3, # 'b'
|
| 2376 |
+
28: 0, # 'c'
|
| 2377 |
+
12: 3, # 'd'
|
| 2378 |
+
2: 2, # 'e'
|
| 2379 |
+
18: 3, # 'f'
|
| 2380 |
+
27: 3, # 'g'
|
| 2381 |
+
25: 3, # 'h'
|
| 2382 |
+
3: 3, # 'i'
|
| 2383 |
+
24: 3, # 'j'
|
| 2384 |
+
10: 3, # 'k'
|
| 2385 |
+
5: 0, # 'l'
|
| 2386 |
+
13: 2, # 'm'
|
| 2387 |
+
4: 3, # 'n'
|
| 2388 |
+
15: 1, # 'o'
|
| 2389 |
+
26: 2, # 'p'
|
| 2390 |
+
7: 3, # 'r'
|
| 2391 |
+
8: 3, # 's'
|
| 2392 |
+
9: 3, # 't'
|
| 2393 |
+
14: 2, # 'u'
|
| 2394 |
+
32: 2, # 'v'
|
| 2395 |
+
57: 1, # 'w'
|
| 2396 |
+
58: 0, # 'x'
|
| 2397 |
+
11: 3, # 'y'
|
| 2398 |
+
22: 0, # 'z'
|
| 2399 |
+
63: 0, # '·'
|
| 2400 |
+
54: 0, # 'Ç'
|
| 2401 |
+
50: 0, # 'Ö'
|
| 2402 |
+
55: 0, # 'Ü'
|
| 2403 |
+
59: 0, # 'â'
|
| 2404 |
+
33: 0, # 'ç'
|
| 2405 |
+
61: 0, # 'î'
|
| 2406 |
+
34: 0, # 'ö'
|
| 2407 |
+
17: 3, # 'ü'
|
| 2408 |
+
30: 0, # 'ğ'
|
| 2409 |
+
41: 0, # 'İ'
|
| 2410 |
+
6: 3, # 'ı'
|
| 2411 |
+
40: 0, # 'Ş'
|
| 2412 |
+
19: 1, # 'ş'
|
| 2413 |
+
},
|
| 2414 |
+
4: { # 'n'
|
| 2415 |
+
23: 1, # 'A'
|
| 2416 |
+
37: 0, # 'B'
|
| 2417 |
+
47: 0, # 'C'
|
| 2418 |
+
39: 0, # 'D'
|
| 2419 |
+
29: 0, # 'E'
|
| 2420 |
+
52: 0, # 'F'
|
| 2421 |
+
36: 0, # 'G'
|
| 2422 |
+
45: 1, # 'H'
|
| 2423 |
+
53: 0, # 'I'
|
| 2424 |
+
60: 2, # 'J'
|
| 2425 |
+
16: 3, # 'K'
|
| 2426 |
+
49: 0, # 'L'
|
| 2427 |
+
20: 3, # 'M'
|
| 2428 |
+
46: 0, # 'N'
|
| 2429 |
+
42: 0, # 'O'
|
| 2430 |
+
48: 0, # 'P'
|
| 2431 |
+
44: 0, # 'R'
|
| 2432 |
+
35: 0, # 'S'
|
| 2433 |
+
31: 2, # 'T'
|
| 2434 |
+
51: 0, # 'U'
|
| 2435 |
+
38: 0, # 'V'
|
| 2436 |
+
62: 0, # 'W'
|
| 2437 |
+
43: 0, # 'Y'
|
| 2438 |
+
56: 0, # 'Z'
|
| 2439 |
+
1: 3, # 'a'
|
| 2440 |
+
21: 2, # 'b'
|
| 2441 |
+
28: 1, # 'c'
|
| 2442 |
+
12: 3, # 'd'
|
| 2443 |
+
2: 3, # 'e'
|
| 2444 |
+
18: 1, # 'f'
|
| 2445 |
+
27: 2, # 'g'
|
| 2446 |
+
25: 3, # 'h'
|
| 2447 |
+
3: 2, # 'i'
|
| 2448 |
+
24: 2, # 'j'
|
| 2449 |
+
10: 3, # 'k'
|
| 2450 |
+
5: 3, # 'l'
|
| 2451 |
+
13: 3, # 'm'
|
| 2452 |
+
4: 3, # 'n'
|
| 2453 |
+
15: 1, # 'o'
|
| 2454 |
+
26: 3, # 'p'
|
| 2455 |
+
7: 2, # 'r'
|
| 2456 |
+
8: 3, # 's'
|
| 2457 |
+
9: 3, # 't'
|
| 2458 |
+
14: 3, # 'u'
|
| 2459 |
+
32: 2, # 'v'
|
| 2460 |
+
57: 0, # 'w'
|
| 2461 |
+
58: 2, # 'x'
|
| 2462 |
+
11: 3, # 'y'
|
| 2463 |
+
22: 0, # 'z'
|
| 2464 |
+
63: 0, # '·'
|
| 2465 |
+
54: 0, # 'Ç'
|
| 2466 |
+
50: 0, # 'Ö'
|
| 2467 |
+
55: 0, # 'Ü'
|
| 2468 |
+
59: 0, # 'â'
|
| 2469 |
+
33: 1, # 'ç'
|
| 2470 |
+
61: 0, # 'î'
|
| 2471 |
+
34: 0, # 'ö'
|
| 2472 |
+
17: 2, # 'ü'
|
| 2473 |
+
30: 0, # 'ğ'
|
| 2474 |
+
41: 0, # 'İ'
|
| 2475 |
+
6: 1, # 'ı'
|
| 2476 |
+
40: 0, # 'Ş'
|
| 2477 |
+
19: 0, # 'ş'
|
| 2478 |
+
},
|
| 2479 |
+
15: { # 'o'
|
| 2480 |
+
23: 0, # 'A'
|
| 2481 |
+
37: 0, # 'B'
|
| 2482 |
+
47: 1, # 'C'
|
| 2483 |
+
39: 0, # 'D'
|
| 2484 |
+
29: 0, # 'E'
|
| 2485 |
+
52: 2, # 'F'
|
| 2486 |
+
36: 1, # 'G'
|
| 2487 |
+
45: 1, # 'H'
|
| 2488 |
+
53: 1, # 'I'
|
| 2489 |
+
60: 0, # 'J'
|
| 2490 |
+
16: 3, # 'K'
|
| 2491 |
+
49: 2, # 'L'
|
| 2492 |
+
20: 0, # 'M'
|
| 2493 |
+
46: 2, # 'N'
|
| 2494 |
+
42: 1, # 'O'
|
| 2495 |
+
48: 2, # 'P'
|
| 2496 |
+
44: 1, # 'R'
|
| 2497 |
+
35: 0, # 'S'
|
| 2498 |
+
31: 0, # 'T'
|
| 2499 |
+
51: 0, # 'U'
|
| 2500 |
+
38: 0, # 'V'
|
| 2501 |
+
62: 0, # 'W'
|
| 2502 |
+
43: 0, # 'Y'
|
| 2503 |
+
56: 0, # 'Z'
|
| 2504 |
+
1: 3, # 'a'
|
| 2505 |
+
21: 0, # 'b'
|
| 2506 |
+
28: 2, # 'c'
|
| 2507 |
+
12: 0, # 'd'
|
| 2508 |
+
2: 3, # 'e'
|
| 2509 |
+
18: 0, # 'f'
|
| 2510 |
+
27: 0, # 'g'
|
| 2511 |
+
25: 0, # 'h'
|
| 2512 |
+
3: 1, # 'i'
|
| 2513 |
+
24: 2, # 'j'
|
| 2514 |
+
10: 1, # 'k'
|
| 2515 |
+
5: 3, # 'l'
|
| 2516 |
+
13: 3, # 'm'
|
| 2517 |
+
4: 2, # 'n'
|
| 2518 |
+
15: 2, # 'o'
|
| 2519 |
+
26: 0, # 'p'
|
| 2520 |
+
7: 1, # 'r'
|
| 2521 |
+
8: 0, # 's'
|
| 2522 |
+
9: 0, # 't'
|
| 2523 |
+
14: 3, # 'u'
|
| 2524 |
+
32: 0, # 'v'
|
| 2525 |
+
57: 0, # 'w'
|
| 2526 |
+
58: 2, # 'x'
|
| 2527 |
+
11: 0, # 'y'
|
| 2528 |
+
22: 2, # 'z'
|
| 2529 |
+
63: 0, # '·'
|
| 2530 |
+
54: 1, # 'Ç'
|
| 2531 |
+
50: 2, # 'Ö'
|
| 2532 |
+
55: 0, # 'Ü'
|
| 2533 |
+
59: 0, # 'â'
|
| 2534 |
+
33: 3, # 'ç'
|
| 2535 |
+
61: 0, # 'î'
|
| 2536 |
+
34: 1, # 'ö'
|
| 2537 |
+
17: 0, # 'ü'
|
| 2538 |
+
30: 2, # 'ğ'
|
| 2539 |
+
41: 2, # 'İ'
|
| 2540 |
+
6: 3, # 'ı'
|
| 2541 |
+
40: 2, # 'Ş'
|
| 2542 |
+
19: 2, # 'ş'
|
| 2543 |
+
},
|
| 2544 |
+
26: { # 'p'
|
| 2545 |
+
23: 0, # 'A'
|
| 2546 |
+
37: 0, # 'B'
|
| 2547 |
+
47: 0, # 'C'
|
| 2548 |
+
39: 0, # 'D'
|
| 2549 |
+
29: 0, # 'E'
|
| 2550 |
+
52: 0, # 'F'
|
| 2551 |
+
36: 0, # 'G'
|
| 2552 |
+
45: 0, # 'H'
|
| 2553 |
+
53: 0, # 'I'
|
| 2554 |
+
60: 0, # 'J'
|
| 2555 |
+
16: 3, # 'K'
|
| 2556 |
+
49: 0, # 'L'
|
| 2557 |
+
20: 1, # 'M'
|
| 2558 |
+
46: 0, # 'N'
|
| 2559 |
+
42: 0, # 'O'
|
| 2560 |
+
48: 0, # 'P'
|
| 2561 |
+
44: 0, # 'R'
|
| 2562 |
+
35: 0, # 'S'
|
| 2563 |
+
31: 0, # 'T'
|
| 2564 |
+
51: 0, # 'U'
|
| 2565 |
+
38: 0, # 'V'
|
| 2566 |
+
62: 0, # 'W'
|
| 2567 |
+
43: 0, # 'Y'
|
| 2568 |
+
56: 0, # 'Z'
|
| 2569 |
+
1: 3, # 'a'
|
| 2570 |
+
21: 1, # 'b'
|
| 2571 |
+
28: 0, # 'c'
|
| 2572 |
+
12: 1, # 'd'
|
| 2573 |
+
2: 3, # 'e'
|
| 2574 |
+
18: 0, # 'f'
|
| 2575 |
+
27: 1, # 'g'
|
| 2576 |
+
25: 1, # 'h'
|
| 2577 |
+
3: 2, # 'i'
|
| 2578 |
+
24: 3, # 'j'
|
| 2579 |
+
10: 1, # 'k'
|
| 2580 |
+
5: 3, # 'l'
|
| 2581 |
+
13: 3, # 'm'
|
| 2582 |
+
4: 2, # 'n'
|
| 2583 |
+
15: 0, # 'o'
|
| 2584 |
+
26: 2, # 'p'
|
| 2585 |
+
7: 2, # 'r'
|
| 2586 |
+
8: 1, # 's'
|
| 2587 |
+
9: 1, # 't'
|
| 2588 |
+
14: 3, # 'u'
|
| 2589 |
+
32: 0, # 'v'
|
| 2590 |
+
57: 0, # 'w'
|
| 2591 |
+
58: 1, # 'x'
|
| 2592 |
+
11: 1, # 'y'
|
| 2593 |
+
22: 0, # 'z'
|
| 2594 |
+
63: 0, # '·'
|
| 2595 |
+
54: 0, # 'Ç'
|
| 2596 |
+
50: 0, # 'Ö'
|
| 2597 |
+
55: 0, # 'Ü'
|
| 2598 |
+
59: 0, # 'â'
|
| 2599 |
+
33: 3, # 'ç'
|
| 2600 |
+
61: 0, # 'î'
|
| 2601 |
+
34: 0, # 'ö'
|
| 2602 |
+
17: 1, # 'ü'
|
| 2603 |
+
30: 0, # 'ğ'
|
| 2604 |
+
41: 0, # 'İ'
|
| 2605 |
+
6: 3, # 'ı'
|
| 2606 |
+
40: 0, # 'Ş'
|
| 2607 |
+
19: 0, # 'ş'
|
| 2608 |
+
},
|
| 2609 |
+
7: { # 'r'
|
| 2610 |
+
23: 0, # 'A'
|
| 2611 |
+
37: 0, # 'B'
|
| 2612 |
+
47: 0, # 'C'
|
| 2613 |
+
39: 0, # 'D'
|
| 2614 |
+
29: 0, # 'E'
|
| 2615 |
+
52: 1, # 'F'
|
| 2616 |
+
36: 0, # 'G'
|
| 2617 |
+
45: 0, # 'H'
|
| 2618 |
+
53: 0, # 'I'
|
| 2619 |
+
60: 2, # 'J'
|
| 2620 |
+
16: 3, # 'K'
|
| 2621 |
+
49: 0, # 'L'
|
| 2622 |
+
20: 2, # 'M'
|
| 2623 |
+
46: 0, # 'N'
|
| 2624 |
+
42: 0, # 'O'
|
| 2625 |
+
48: 0, # 'P'
|
| 2626 |
+
44: 0, # 'R'
|
| 2627 |
+
35: 0, # 'S'
|
| 2628 |
+
31: 2, # 'T'
|
| 2629 |
+
51: 1, # 'U'
|
| 2630 |
+
38: 0, # 'V'
|
| 2631 |
+
62: 0, # 'W'
|
| 2632 |
+
43: 0, # 'Y'
|
| 2633 |
+
56: 1, # 'Z'
|
| 2634 |
+
1: 3, # 'a'
|
| 2635 |
+
21: 1, # 'b'
|
| 2636 |
+
28: 0, # 'c'
|
| 2637 |
+
12: 3, # 'd'
|
| 2638 |
+
2: 3, # 'e'
|
| 2639 |
+
18: 0, # 'f'
|
| 2640 |
+
27: 2, # 'g'
|
| 2641 |
+
25: 3, # 'h'
|
| 2642 |
+
3: 2, # 'i'
|
| 2643 |
+
24: 2, # 'j'
|
| 2644 |
+
10: 3, # 'k'
|
| 2645 |
+
5: 3, # 'l'
|
| 2646 |
+
13: 3, # 'm'
|
| 2647 |
+
4: 3, # 'n'
|
| 2648 |
+
15: 0, # 'o'
|
| 2649 |
+
26: 2, # 'p'
|
| 2650 |
+
7: 3, # 'r'
|
| 2651 |
+
8: 3, # 's'
|
| 2652 |
+
9: 3, # 't'
|
| 2653 |
+
14: 3, # 'u'
|
| 2654 |
+
32: 2, # 'v'
|
| 2655 |
+
57: 0, # 'w'
|
| 2656 |
+
58: 1, # 'x'
|
| 2657 |
+
11: 2, # 'y'
|
| 2658 |
+
22: 0, # 'z'
|
| 2659 |
+
63: 1, # '·'
|
| 2660 |
+
54: 0, # 'Ç'
|
| 2661 |
+
50: 0, # 'Ö'
|
| 2662 |
+
55: 0, # 'Ü'
|
| 2663 |
+
59: 0, # 'â'
|
| 2664 |
+
33: 2, # 'ç'
|
| 2665 |
+
61: 0, # 'î'
|
| 2666 |
+
34: 0, # 'ö'
|
| 2667 |
+
17: 3, # 'ü'
|
| 2668 |
+
30: 0, # 'ğ'
|
| 2669 |
+
41: 0, # 'İ'
|
| 2670 |
+
6: 2, # 'ı'
|
| 2671 |
+
40: 0, # 'Ş'
|
| 2672 |
+
19: 0, # 'ş'
|
| 2673 |
+
},
|
| 2674 |
+
8: { # 's'
|
| 2675 |
+
23: 1, # 'A'
|
| 2676 |
+
37: 0, # 'B'
|
| 2677 |
+
47: 0, # 'C'
|
| 2678 |
+
39: 0, # 'D'
|
| 2679 |
+
29: 0, # 'E'
|
| 2680 |
+
52: 0, # 'F'
|
| 2681 |
+
36: 1, # 'G'
|
| 2682 |
+
45: 0, # 'H'
|
| 2683 |
+
53: 0, # 'I'
|
| 2684 |
+
60: 0, # 'J'
|
| 2685 |
+
16: 3, # 'K'
|
| 2686 |
+
49: 0, # 'L'
|
| 2687 |
+
20: 3, # 'M'
|
| 2688 |
+
46: 0, # 'N'
|
| 2689 |
+
42: 0, # 'O'
|
| 2690 |
+
48: 0, # 'P'
|
| 2691 |
+
44: 0, # 'R'
|
| 2692 |
+
35: 0, # 'S'
|
| 2693 |
+
31: 2, # 'T'
|
| 2694 |
+
51: 0, # 'U'
|
| 2695 |
+
38: 0, # 'V'
|
| 2696 |
+
62: 0, # 'W'
|
| 2697 |
+
43: 0, # 'Y'
|
| 2698 |
+
56: 1, # 'Z'
|
| 2699 |
+
1: 3, # 'a'
|
| 2700 |
+
21: 2, # 'b'
|
| 2701 |
+
28: 1, # 'c'
|
| 2702 |
+
12: 3, # 'd'
|
| 2703 |
+
2: 3, # 'e'
|
| 2704 |
+
18: 0, # 'f'
|
| 2705 |
+
27: 2, # 'g'
|
| 2706 |
+
25: 2, # 'h'
|
| 2707 |
+
3: 2, # 'i'
|
| 2708 |
+
24: 3, # 'j'
|
| 2709 |
+
10: 3, # 'k'
|
| 2710 |
+
5: 3, # 'l'
|
| 2711 |
+
13: 3, # 'm'
|
| 2712 |
+
4: 3, # 'n'
|
| 2713 |
+
15: 0, # 'o'
|
| 2714 |
+
26: 3, # 'p'
|
| 2715 |
+
7: 3, # 'r'
|
| 2716 |
+
8: 3, # 's'
|
| 2717 |
+
9: 3, # 't'
|
| 2718 |
+
14: 3, # 'u'
|
| 2719 |
+
32: 2, # 'v'
|
| 2720 |
+
57: 0, # 'w'
|
| 2721 |
+
58: 1, # 'x'
|
| 2722 |
+
11: 2, # 'y'
|
| 2723 |
+
22: 1, # 'z'
|
| 2724 |
+
63: 0, # '·'
|
| 2725 |
+
54: 0, # 'Ç'
|
| 2726 |
+
50: 0, # 'Ö'
|
| 2727 |
+
55: 0, # 'Ü'
|
| 2728 |
+
59: 0, # 'â'
|
| 2729 |
+
33: 2, # 'ç'
|
| 2730 |
+
61: 0, # 'î'
|
| 2731 |
+
34: 0, # 'ö'
|
| 2732 |
+
17: 2, # 'ü'
|
| 2733 |
+
30: 0, # 'ğ'
|
| 2734 |
+
41: 0, # 'İ'
|
| 2735 |
+
6: 3, # 'ı'
|
| 2736 |
+
40: 0, # 'Ş'
|
| 2737 |
+
19: 1, # 'ş'
|
| 2738 |
+
},
|
| 2739 |
+
9: { # 't'
|
| 2740 |
+
23: 0, # 'A'
|
| 2741 |
+
37: 0, # 'B'
|
| 2742 |
+
47: 0, # 'C'
|
| 2743 |
+
39: 0, # 'D'
|
| 2744 |
+
29: 0, # 'E'
|
| 2745 |
+
52: 0, # 'F'
|
| 2746 |
+
36: 0, # 'G'
|
| 2747 |
+
45: 0, # 'H'
|
| 2748 |
+
53: 0, # 'I'
|
| 2749 |
+
60: 1, # 'J'
|
| 2750 |
+
16: 3, # 'K'
|
| 2751 |
+
49: 0, # 'L'
|
| 2752 |
+
20: 2, # 'M'
|
| 2753 |
+
46: 0, # 'N'
|
| 2754 |
+
42: 0, # 'O'
|
| 2755 |
+
48: 0, # 'P'
|
| 2756 |
+
44: 0, # 'R'
|
| 2757 |
+
35: 0, # 'S'
|
| 2758 |
+
31: 2, # 'T'
|
| 2759 |
+
51: 0, # 'U'
|
| 2760 |
+
38: 0, # 'V'
|
| 2761 |
+
62: 0, # 'W'
|
| 2762 |
+
43: 0, # 'Y'
|
| 2763 |
+
56: 1, # 'Z'
|
| 2764 |
+
1: 3, # 'a'
|
| 2765 |
+
21: 3, # 'b'
|
| 2766 |
+
28: 0, # 'c'
|
| 2767 |
+
12: 3, # 'd'
|
| 2768 |
+
2: 3, # 'e'
|
| 2769 |
+
18: 2, # 'f'
|
| 2770 |
+
27: 2, # 'g'
|
| 2771 |
+
25: 2, # 'h'
|
| 2772 |
+
3: 2, # 'i'
|
| 2773 |
+
24: 2, # 'j'
|
| 2774 |
+
10: 3, # 'k'
|
| 2775 |
+
5: 3, # 'l'
|
| 2776 |
+
13: 3, # 'm'
|
| 2777 |
+
4: 3, # 'n'
|
| 2778 |
+
15: 0, # 'o'
|
| 2779 |
+
26: 2, # 'p'
|
| 2780 |
+
7: 3, # 'r'
|
| 2781 |
+
8: 3, # 's'
|
| 2782 |
+
9: 3, # 't'
|
| 2783 |
+
14: 3, # 'u'
|
| 2784 |
+
32: 3, # 'v'
|
| 2785 |
+
57: 0, # 'w'
|
| 2786 |
+
58: 2, # 'x'
|
| 2787 |
+
11: 2, # 'y'
|
| 2788 |
+
22: 0, # 'z'
|
| 2789 |
+
63: 0, # '·'
|
| 2790 |
+
54: 0, # 'Ç'
|
| 2791 |
+
50: 0, # 'Ö'
|
| 2792 |
+
55: 0, # 'Ü'
|
| 2793 |
+
59: 0, # 'â'
|
| 2794 |
+
33: 3, # 'ç'
|
| 2795 |
+
61: 0, # 'î'
|
| 2796 |
+
34: 0, # 'ö'
|
| 2797 |
+
17: 2, # 'ü'
|
| 2798 |
+
30: 0, # 'ğ'
|
| 2799 |
+
41: 0, # 'İ'
|
| 2800 |
+
6: 3, # 'ı'
|
| 2801 |
+
40: 0, # 'Ş'
|
| 2802 |
+
19: 0, # 'ş'
|
| 2803 |
+
},
|
| 2804 |
+
14: { # 'u'
|
| 2805 |
+
23: 3, # 'A'
|
| 2806 |
+
37: 0, # 'B'
|
| 2807 |
+
47: 0, # 'C'
|
| 2808 |
+
39: 0, # 'D'
|
| 2809 |
+
29: 3, # 'E'
|
| 2810 |
+
52: 0, # 'F'
|
| 2811 |
+
36: 0, # 'G'
|
| 2812 |
+
45: 1, # 'H'
|
| 2813 |
+
53: 0, # 'I'
|
| 2814 |
+
60: 1, # 'J'
|
| 2815 |
+
16: 0, # 'K'
|
| 2816 |
+
49: 0, # 'L'
|
| 2817 |
+
20: 3, # 'M'
|
| 2818 |
+
46: 2, # 'N'
|
| 2819 |
+
42: 0, # 'O'
|
| 2820 |
+
48: 1, # 'P'
|
| 2821 |
+
44: 0, # 'R'
|
| 2822 |
+
35: 0, # 'S'
|
| 2823 |
+
31: 3, # 'T'
|
| 2824 |
+
51: 0, # 'U'
|
| 2825 |
+
38: 0, # 'V'
|
| 2826 |
+
62: 0, # 'W'
|
| 2827 |
+
43: 1, # 'Y'
|
| 2828 |
+
56: 2, # 'Z'
|
| 2829 |
+
1: 2, # 'a'
|
| 2830 |
+
21: 3, # 'b'
|
| 2831 |
+
28: 0, # 'c'
|
| 2832 |
+
12: 3, # 'd'
|
| 2833 |
+
2: 2, # 'e'
|
| 2834 |
+
18: 2, # 'f'
|
| 2835 |
+
27: 3, # 'g'
|
| 2836 |
+
25: 3, # 'h'
|
| 2837 |
+
3: 3, # 'i'
|
| 2838 |
+
24: 2, # 'j'
|
| 2839 |
+
10: 3, # 'k'
|
| 2840 |
+
5: 0, # 'l'
|
| 2841 |
+
13: 3, # 'm'
|
| 2842 |
+
4: 3, # 'n'
|
| 2843 |
+
15: 0, # 'o'
|
| 2844 |
+
26: 3, # 'p'
|
| 2845 |
+
7: 3, # 'r'
|
| 2846 |
+
8: 3, # 's'
|
| 2847 |
+
9: 3, # 't'
|
| 2848 |
+
14: 3, # 'u'
|
| 2849 |
+
32: 2, # 'v'
|
| 2850 |
+
57: 2, # 'w'
|
| 2851 |
+
58: 0, # 'x'
|
| 2852 |
+
11: 3, # 'y'
|
| 2853 |
+
22: 0, # 'z'
|
| 2854 |
+
63: 1, # '·'
|
| 2855 |
+
54: 0, # 'Ç'
|
| 2856 |
+
50: 0, # 'Ö'
|
| 2857 |
+
55: 0, # 'Ü'
|
| 2858 |
+
59: 0, # 'â'
|
| 2859 |
+
33: 0, # 'ç'
|
| 2860 |
+
61: 0, # 'î'
|
| 2861 |
+
34: 0, # 'ö'
|
| 2862 |
+
17: 3, # 'ü'
|
| 2863 |
+
30: 1, # 'ğ'
|
| 2864 |
+
41: 0, # 'İ'
|
| 2865 |
+
6: 3, # 'ı'
|
| 2866 |
+
40: 0, # 'Ş'
|
| 2867 |
+
19: 0, # 'ş'
|
| 2868 |
+
},
|
| 2869 |
+
32: { # 'v'
|
| 2870 |
+
23: 0, # 'A'
|
| 2871 |
+
37: 0, # 'B'
|
| 2872 |
+
47: 0, # 'C'
|
| 2873 |
+
39: 0, # 'D'
|
| 2874 |
+
29: 0, # 'E'
|
| 2875 |
+
52: 0, # 'F'
|
| 2876 |
+
36: 0, # 'G'
|
| 2877 |
+
45: 0, # 'H'
|
| 2878 |
+
53: 0, # 'I'
|
| 2879 |
+
60: 0, # 'J'
|
| 2880 |
+
16: 3, # 'K'
|
| 2881 |
+
49: 0, # 'L'
|
| 2882 |
+
20: 1, # 'M'
|
| 2883 |
+
46: 0, # 'N'
|
| 2884 |
+
42: 0, # 'O'
|
| 2885 |
+
48: 0, # 'P'
|
| 2886 |
+
44: 0, # 'R'
|
| 2887 |
+
35: 0, # 'S'
|
| 2888 |
+
31: 0, # 'T'
|
| 2889 |
+
51: 0, # 'U'
|
| 2890 |
+
38: 0, # 'V'
|
| 2891 |
+
62: 0, # 'W'
|
| 2892 |
+
43: 0, # 'Y'
|
| 2893 |
+
56: 0, # 'Z'
|
| 2894 |
+
1: 3, # 'a'
|
| 2895 |
+
21: 0, # 'b'
|
| 2896 |
+
28: 0, # 'c'
|
| 2897 |
+
12: 3, # 'd'
|
| 2898 |
+
2: 3, # 'e'
|
| 2899 |
+
18: 0, # 'f'
|
| 2900 |
+
27: 0, # 'g'
|
| 2901 |
+
25: 0, # 'h'
|
| 2902 |
+
3: 0, # 'i'
|
| 2903 |
+
24: 1, # 'j'
|
| 2904 |
+
10: 1, # 'k'
|
| 2905 |
+
5: 3, # 'l'
|
| 2906 |
+
13: 2, # 'm'
|
| 2907 |
+
4: 3, # 'n'
|
| 2908 |
+
15: 0, # 'o'
|
| 2909 |
+
26: 1, # 'p'
|
| 2910 |
+
7: 1, # 'r'
|
| 2911 |
+
8: 2, # 's'
|
| 2912 |
+
9: 3, # 't'
|
| 2913 |
+
14: 3, # 'u'
|
| 2914 |
+
32: 1, # 'v'
|
| 2915 |
+
57: 0, # 'w'
|
| 2916 |
+
58: 0, # 'x'
|
| 2917 |
+
11: 0, # 'y'
|
| 2918 |
+
22: 0, # 'z'
|
| 2919 |
+
63: 0, # '·'
|
| 2920 |
+
54: 0, # 'Ç'
|
| 2921 |
+
50: 0, # 'Ö'
|
| 2922 |
+
55: 0, # 'Ü'
|
| 2923 |
+
59: 0, # 'â'
|
| 2924 |
+
33: 2, # 'ç'
|
| 2925 |
+
61: 0, # 'î'
|
| 2926 |
+
34: 0, # 'ö'
|
| 2927 |
+
17: 0, # 'ü'
|
| 2928 |
+
30: 0, # 'ğ'
|
| 2929 |
+
41: 0, # 'İ'
|
| 2930 |
+
6: 1, # 'ı'
|
| 2931 |
+
40: 0, # 'Ş'
|
| 2932 |
+
19: 0, # 'ş'
|
| 2933 |
+
},
|
| 2934 |
+
57: { # 'w'
|
| 2935 |
+
23: 0, # 'A'
|
| 2936 |
+
37: 0, # 'B'
|
| 2937 |
+
47: 0, # 'C'
|
| 2938 |
+
39: 0, # 'D'
|
| 2939 |
+
29: 0, # 'E'
|
| 2940 |
+
52: 0, # 'F'
|
| 2941 |
+
36: 0, # 'G'
|
| 2942 |
+
45: 0, # 'H'
|
| 2943 |
+
53: 0, # 'I'
|
| 2944 |
+
60: 0, # 'J'
|
| 2945 |
+
16: 0, # 'K'
|
| 2946 |
+
49: 0, # 'L'
|
| 2947 |
+
20: 0, # 'M'
|
| 2948 |
+
46: 0, # 'N'
|
| 2949 |
+
42: 0, # 'O'
|
| 2950 |
+
48: 0, # 'P'
|
| 2951 |
+
44: 0, # 'R'
|
| 2952 |
+
35: 0, # 'S'
|
| 2953 |
+
31: 0, # 'T'
|
| 2954 |
+
51: 1, # 'U'
|
| 2955 |
+
38: 0, # 'V'
|
| 2956 |
+
62: 0, # 'W'
|
| 2957 |
+
43: 0, # 'Y'
|
| 2958 |
+
56: 0, # 'Z'
|
| 2959 |
+
1: 1, # 'a'
|
| 2960 |
+
21: 0, # 'b'
|
| 2961 |
+
28: 0, # 'c'
|
| 2962 |
+
12: 0, # 'd'
|
| 2963 |
+
2: 2, # 'e'
|
| 2964 |
+
18: 0, # 'f'
|
| 2965 |
+
27: 0, # 'g'
|
| 2966 |
+
25: 1, # 'h'
|
| 2967 |
+
3: 0, # 'i'
|
| 2968 |
+
24: 0, # 'j'
|
| 2969 |
+
10: 1, # 'k'
|
| 2970 |
+
5: 0, # 'l'
|
| 2971 |
+
13: 0, # 'm'
|
| 2972 |
+
4: 1, # 'n'
|
| 2973 |
+
15: 0, # 'o'
|
| 2974 |
+
26: 0, # 'p'
|
| 2975 |
+
7: 0, # 'r'
|
| 2976 |
+
8: 1, # 's'
|
| 2977 |
+
9: 0, # 't'
|
| 2978 |
+
14: 1, # 'u'
|
| 2979 |
+
32: 0, # 'v'
|
| 2980 |
+
57: 2, # 'w'
|
| 2981 |
+
58: 0, # 'x'
|
| 2982 |
+
11: 0, # 'y'
|
| 2983 |
+
22: 0, # 'z'
|
| 2984 |
+
63: 1, # '·'
|
| 2985 |
+
54: 0, # 'Ç'
|
| 2986 |
+
50: 0, # 'Ö'
|
| 2987 |
+
55: 0, # 'Ü'
|
| 2988 |
+
59: 0, # 'â'
|
| 2989 |
+
33: 0, # 'ç'
|
| 2990 |
+
61: 0, # 'î'
|
| 2991 |
+
34: 0, # 'ö'
|
| 2992 |
+
17: 1, # 'ü'
|
| 2993 |
+
30: 0, # 'ğ'
|
| 2994 |
+
41: 0, # 'İ'
|
| 2995 |
+
6: 0, # 'ı'
|
| 2996 |
+
40: 0, # 'Ş'
|
| 2997 |
+
19: 0, # 'ş'
|
| 2998 |
+
},
|
| 2999 |
+
58: { # 'x'
|
| 3000 |
+
23: 0, # 'A'
|
| 3001 |
+
37: 0, # 'B'
|
| 3002 |
+
47: 0, # 'C'
|
| 3003 |
+
39: 0, # 'D'
|
| 3004 |
+
29: 1, # 'E'
|
| 3005 |
+
52: 0, # 'F'
|
| 3006 |
+
36: 0, # 'G'
|
| 3007 |
+
45: 0, # 'H'
|
| 3008 |
+
53: 0, # 'I'
|
| 3009 |
+
60: 1, # 'J'
|
| 3010 |
+
16: 0, # 'K'
|
| 3011 |
+
49: 0, # 'L'
|
| 3012 |
+
20: 1, # 'M'
|
| 3013 |
+
46: 0, # 'N'
|
| 3014 |
+
42: 0, # 'O'
|
| 3015 |
+
48: 0, # 'P'
|
| 3016 |
+
44: 0, # 'R'
|
| 3017 |
+
35: 0, # 'S'
|
| 3018 |
+
31: 0, # 'T'
|
| 3019 |
+
51: 0, # 'U'
|
| 3020 |
+
38: 0, # 'V'
|
| 3021 |
+
62: 0, # 'W'
|
| 3022 |
+
43: 0, # 'Y'
|
| 3023 |
+
56: 0, # 'Z'
|
| 3024 |
+
1: 0, # 'a'
|
| 3025 |
+
21: 1, # 'b'
|
| 3026 |
+
28: 0, # 'c'
|
| 3027 |
+
12: 2, # 'd'
|
| 3028 |
+
2: 1, # 'e'
|
| 3029 |
+
18: 0, # 'f'
|
| 3030 |
+
27: 0, # 'g'
|
| 3031 |
+
25: 0, # 'h'
|
| 3032 |
+
3: 2, # 'i'
|
| 3033 |
+
24: 2, # 'j'
|
| 3034 |
+
10: 1, # 'k'
|
| 3035 |
+
5: 0, # 'l'
|
| 3036 |
+
13: 0, # 'm'
|
| 3037 |
+
4: 2, # 'n'
|
| 3038 |
+
15: 0, # 'o'
|
| 3039 |
+
26: 0, # 'p'
|
| 3040 |
+
7: 1, # 'r'
|
| 3041 |
+
8: 2, # 's'
|
| 3042 |
+
9: 1, # 't'
|
| 3043 |
+
14: 0, # 'u'
|
| 3044 |
+
32: 0, # 'v'
|
| 3045 |
+
57: 0, # 'w'
|
| 3046 |
+
58: 0, # 'x'
|
| 3047 |
+
11: 2, # 'y'
|
| 3048 |
+
22: 0, # 'z'
|
| 3049 |
+
63: 0, # '·'
|
| 3050 |
+
54: 0, # 'Ç'
|
| 3051 |
+
50: 0, # 'Ö'
|
| 3052 |
+
55: 0, # 'Ü'
|
| 3053 |
+
59: 0, # 'â'
|
| 3054 |
+
33: 0, # 'ç'
|
| 3055 |
+
61: 0, # 'î'
|
| 3056 |
+
34: 0, # 'ö'
|
| 3057 |
+
17: 1, # 'ü'
|
| 3058 |
+
30: 0, # 'ğ'
|
| 3059 |
+
41: 0, # 'İ'
|
| 3060 |
+
6: 2, # 'ı'
|
| 3061 |
+
40: 0, # 'Ş'
|
| 3062 |
+
19: 0, # 'ş'
|
| 3063 |
+
},
|
| 3064 |
+
11: { # 'y'
|
| 3065 |
+
23: 1, # 'A'
|
| 3066 |
+
37: 0, # 'B'
|
| 3067 |
+
47: 0, # 'C'
|
| 3068 |
+
39: 0, # 'D'
|
| 3069 |
+
29: 0, # 'E'
|
| 3070 |
+
52: 0, # 'F'
|
| 3071 |
+
36: 0, # 'G'
|
| 3072 |
+
45: 0, # 'H'
|
| 3073 |
+
53: 0, # 'I'
|
| 3074 |
+
60: 1, # 'J'
|
| 3075 |
+
16: 3, # 'K'
|
| 3076 |
+
49: 0, # 'L'
|
| 3077 |
+
20: 1, # 'M'
|
| 3078 |
+
46: 0, # 'N'
|
| 3079 |
+
42: 0, # 'O'
|
| 3080 |
+
48: 0, # 'P'
|
| 3081 |
+
44: 0, # 'R'
|
| 3082 |
+
35: 0, # 'S'
|
| 3083 |
+
31: 1, # 'T'
|
| 3084 |
+
51: 0, # 'U'
|
| 3085 |
+
38: 0, # 'V'
|
| 3086 |
+
62: 0, # 'W'
|
| 3087 |
+
43: 1, # 'Y'
|
| 3088 |
+
56: 1, # 'Z'
|
| 3089 |
+
1: 3, # 'a'
|
| 3090 |
+
21: 1, # 'b'
|
| 3091 |
+
28: 0, # 'c'
|
| 3092 |
+
12: 2, # 'd'
|
| 3093 |
+
2: 3, # 'e'
|
| 3094 |
+
18: 0, # 'f'
|
| 3095 |
+
27: 2, # 'g'
|
| 3096 |
+
25: 2, # 'h'
|
| 3097 |
+
3: 2, # 'i'
|
| 3098 |
+
24: 1, # 'j'
|
| 3099 |
+
10: 2, # 'k'
|
| 3100 |
+
5: 3, # 'l'
|
| 3101 |
+
13: 3, # 'm'
|
| 3102 |
+
4: 3, # 'n'
|
| 3103 |
+
15: 0, # 'o'
|
| 3104 |
+
26: 1, # 'p'
|
| 3105 |
+
7: 2, # 'r'
|
| 3106 |
+
8: 1, # 's'
|
| 3107 |
+
9: 2, # 't'
|
| 3108 |
+
14: 3, # 'u'
|
| 3109 |
+
32: 0, # 'v'
|
| 3110 |
+
57: 0, # 'w'
|
| 3111 |
+
58: 1, # 'x'
|
| 3112 |
+
11: 3, # 'y'
|
| 3113 |
+
22: 0, # 'z'
|
| 3114 |
+
63: 0, # '·'
|
| 3115 |
+
54: 0, # 'Ç'
|
| 3116 |
+
50: 0, # 'Ö'
|
| 3117 |
+
55: 0, # 'Ü'
|
| 3118 |
+
59: 0, # 'â'
|
| 3119 |
+
33: 3, # 'ç'
|
| 3120 |
+
61: 0, # 'î'
|
| 3121 |
+
34: 0, # 'ö'
|
| 3122 |
+
17: 2, # 'ü'
|
| 3123 |
+
30: 0, # 'ğ'
|
| 3124 |
+
41: 0, # 'İ'
|
| 3125 |
+
6: 3, # 'ı'
|
| 3126 |
+
40: 0, # 'Ş'
|
| 3127 |
+
19: 0, # 'ş'
|
| 3128 |
+
},
|
| 3129 |
+
22: { # 'z'
|
| 3130 |
+
23: 2, # 'A'
|
| 3131 |
+
37: 2, # 'B'
|
| 3132 |
+
47: 1, # 'C'
|
| 3133 |
+
39: 2, # 'D'
|
| 3134 |
+
29: 3, # 'E'
|
| 3135 |
+
52: 1, # 'F'
|
| 3136 |
+
36: 2, # 'G'
|
| 3137 |
+
45: 2, # 'H'
|
| 3138 |
+
53: 1, # 'I'
|
| 3139 |
+
60: 0, # 'J'
|
| 3140 |
+
16: 0, # 'K'
|
| 3141 |
+
49: 0, # 'L'
|
| 3142 |
+
20: 3, # 'M'
|
| 3143 |
+
46: 2, # 'N'
|
| 3144 |
+
42: 2, # 'O'
|
| 3145 |
+
48: 2, # 'P'
|
| 3146 |
+
44: 1, # 'R'
|
| 3147 |
+
35: 1, # 'S'
|
| 3148 |
+
31: 3, # 'T'
|
| 3149 |
+
51: 2, # 'U'
|
| 3150 |
+
38: 2, # 'V'
|
| 3151 |
+
62: 0, # 'W'
|
| 3152 |
+
43: 2, # 'Y'
|
| 3153 |
+
56: 1, # 'Z'
|
| 3154 |
+
1: 1, # 'a'
|
| 3155 |
+
21: 2, # 'b'
|
| 3156 |
+
28: 1, # 'c'
|
| 3157 |
+
12: 2, # 'd'
|
| 3158 |
+
2: 2, # 'e'
|
| 3159 |
+
18: 3, # 'f'
|
| 3160 |
+
27: 2, # 'g'
|
| 3161 |
+
25: 2, # 'h'
|
| 3162 |
+
3: 3, # 'i'
|
| 3163 |
+
24: 2, # 'j'
|
| 3164 |
+
10: 3, # 'k'
|
| 3165 |
+
5: 0, # 'l'
|
| 3166 |
+
13: 2, # 'm'
|
| 3167 |
+
4: 3, # 'n'
|
| 3168 |
+
15: 2, # 'o'
|
| 3169 |
+
26: 2, # 'p'
|
| 3170 |
+
7: 3, # 'r'
|
| 3171 |
+
8: 3, # 's'
|
| 3172 |
+
9: 3, # 't'
|
| 3173 |
+
14: 0, # 'u'
|
| 3174 |
+
32: 2, # 'v'
|
| 3175 |
+
57: 0, # 'w'
|
| 3176 |
+
58: 0, # 'x'
|
| 3177 |
+
11: 3, # 'y'
|
| 3178 |
+
22: 2, # 'z'
|
| 3179 |
+
63: 1, # '·'
|
| 3180 |
+
54: 0, # 'Ç'
|
| 3181 |
+
50: 0, # 'Ö'
|
| 3182 |
+
55: 2, # 'Ü'
|
| 3183 |
+
59: 1, # 'â'
|
| 3184 |
+
33: 0, # 'ç'
|
| 3185 |
+
61: 0, # 'î'
|
| 3186 |
+
34: 2, # 'ö'
|
| 3187 |
+
17: 2, # 'ü'
|
| 3188 |
+
30: 2, # 'ğ'
|
| 3189 |
+
41: 1, # 'İ'
|
| 3190 |
+
6: 3, # 'ı'
|
| 3191 |
+
40: 1, # 'Ş'
|
| 3192 |
+
19: 2, # 'ş'
|
| 3193 |
+
},
|
| 3194 |
+
63: { # '·'
|
| 3195 |
+
23: 0, # 'A'
|
| 3196 |
+
37: 0, # 'B'
|
| 3197 |
+
47: 0, # 'C'
|
| 3198 |
+
39: 0, # 'D'
|
| 3199 |
+
29: 0, # 'E'
|
| 3200 |
+
52: 0, # 'F'
|
| 3201 |
+
36: 0, # 'G'
|
| 3202 |
+
45: 0, # 'H'
|
| 3203 |
+
53: 0, # 'I'
|
| 3204 |
+
60: 0, # 'J'
|
| 3205 |
+
16: 0, # 'K'
|
| 3206 |
+
49: 0, # 'L'
|
| 3207 |
+
20: 0, # 'M'
|
| 3208 |
+
46: 0, # 'N'
|
| 3209 |
+
42: 0, # 'O'
|
| 3210 |
+
48: 0, # 'P'
|
| 3211 |
+
44: 0, # 'R'
|
| 3212 |
+
35: 0, # 'S'
|
| 3213 |
+
31: 0, # 'T'
|
| 3214 |
+
51: 0, # 'U'
|
| 3215 |
+
38: 0, # 'V'
|
| 3216 |
+
62: 0, # 'W'
|
| 3217 |
+
43: 0, # 'Y'
|
| 3218 |
+
56: 0, # 'Z'
|
| 3219 |
+
1: 0, # 'a'
|
| 3220 |
+
21: 0, # 'b'
|
| 3221 |
+
28: 0, # 'c'
|
| 3222 |
+
12: 0, # 'd'
|
| 3223 |
+
2: 1, # 'e'
|
| 3224 |
+
18: 0, # 'f'
|
| 3225 |
+
27: 0, # 'g'
|
| 3226 |
+
25: 0, # 'h'
|
| 3227 |
+
3: 0, # 'i'
|
| 3228 |
+
24: 0, # 'j'
|
| 3229 |
+
10: 0, # 'k'
|
| 3230 |
+
5: 0, # 'l'
|
| 3231 |
+
13: 2, # 'm'
|
| 3232 |
+
4: 0, # 'n'
|
| 3233 |
+
15: 0, # 'o'
|
| 3234 |
+
26: 0, # 'p'
|
| 3235 |
+
7: 0, # 'r'
|
| 3236 |
+
8: 0, # 's'
|
| 3237 |
+
9: 0, # 't'
|
| 3238 |
+
14: 2, # 'u'
|
| 3239 |
+
32: 0, # 'v'
|
| 3240 |
+
57: 0, # 'w'
|
| 3241 |
+
58: 0, # 'x'
|
| 3242 |
+
11: 0, # 'y'
|
| 3243 |
+
22: 0, # 'z'
|
| 3244 |
+
63: 0, # '·'
|
| 3245 |
+
54: 0, # 'Ç'
|
| 3246 |
+
50: 0, # 'Ö'
|
| 3247 |
+
55: 0, # 'Ü'
|
| 3248 |
+
59: 0, # 'â'
|
| 3249 |
+
33: 0, # 'ç'
|
| 3250 |
+
61: 0, # 'î'
|
| 3251 |
+
34: 0, # 'ö'
|
| 3252 |
+
17: 0, # 'ü'
|
| 3253 |
+
30: 0, # 'ğ'
|
| 3254 |
+
41: 0, # 'İ'
|
| 3255 |
+
6: 0, # 'ı'
|
| 3256 |
+
40: 0, # 'Ş'
|
| 3257 |
+
19: 0, # 'ş'
|
| 3258 |
+
},
|
| 3259 |
+
54: { # 'Ç'
|
| 3260 |
+
23: 0, # 'A'
|
| 3261 |
+
37: 0, # 'B'
|
| 3262 |
+
47: 1, # 'C'
|
| 3263 |
+
39: 1, # 'D'
|
| 3264 |
+
29: 0, # 'E'
|
| 3265 |
+
52: 0, # 'F'
|
| 3266 |
+
36: 1, # 'G'
|
| 3267 |
+
45: 1, # 'H'
|
| 3268 |
+
53: 1, # 'I'
|
| 3269 |
+
60: 0, # 'J'
|
| 3270 |
+
16: 0, # 'K'
|
| 3271 |
+
49: 0, # 'L'
|
| 3272 |
+
20: 0, # 'M'
|
| 3273 |
+
46: 0, # 'N'
|
| 3274 |
+
42: 1, # 'O'
|
| 3275 |
+
48: 1, # 'P'
|
| 3276 |
+
44: 0, # 'R'
|
| 3277 |
+
35: 0, # 'S'
|
| 3278 |
+
31: 0, # 'T'
|
| 3279 |
+
51: 1, # 'U'
|
| 3280 |
+
38: 1, # 'V'
|
| 3281 |
+
62: 0, # 'W'
|
| 3282 |
+
43: 2, # 'Y'
|
| 3283 |
+
56: 0, # 'Z'
|
| 3284 |
+
1: 0, # 'a'
|
| 3285 |
+
21: 1, # 'b'
|
| 3286 |
+
28: 0, # 'c'
|
| 3287 |
+
12: 1, # 'd'
|
| 3288 |
+
2: 0, # 'e'
|
| 3289 |
+
18: 0, # 'f'
|
| 3290 |
+
27: 1, # 'g'
|
| 3291 |
+
25: 0, # 'h'
|
| 3292 |
+
3: 3, # 'i'
|
| 3293 |
+
24: 0, # 'j'
|
| 3294 |
+
10: 1, # 'k'
|
| 3295 |
+
5: 0, # 'l'
|
| 3296 |
+
13: 0, # 'm'
|
| 3297 |
+
4: 2, # 'n'
|
| 3298 |
+
15: 1, # 'o'
|
| 3299 |
+
26: 0, # 'p'
|
| 3300 |
+
7: 2, # 'r'
|
| 3301 |
+
8: 0, # 's'
|
| 3302 |
+
9: 1, # 't'
|
| 3303 |
+
14: 0, # 'u'
|
| 3304 |
+
32: 2, # 'v'
|
| 3305 |
+
57: 0, # 'w'
|
| 3306 |
+
58: 0, # 'x'
|
| 3307 |
+
11: 0, # 'y'
|
| 3308 |
+
22: 0, # 'z'
|
| 3309 |
+
63: 0, # '·'
|
| 3310 |
+
54: 0, # 'Ç'
|
| 3311 |
+
50: 0, # 'Ö'
|
| 3312 |
+
55: 2, # 'Ü'
|
| 3313 |
+
59: 0, # 'â'
|
| 3314 |
+
33: 0, # 'ç'
|
| 3315 |
+
61: 0, # 'î'
|
| 3316 |
+
34: 1, # 'ö'
|
| 3317 |
+
17: 0, # 'ü'
|
| 3318 |
+
30: 0, # 'ğ'
|
| 3319 |
+
41: 0, # 'İ'
|
| 3320 |
+
6: 2, # 'ı'
|
| 3321 |
+
40: 0, # 'Ş'
|
| 3322 |
+
19: 1, # 'ş'
|
| 3323 |
+
},
|
| 3324 |
+
50: { # 'Ö'
|
| 3325 |
+
23: 0, # 'A'
|
| 3326 |
+
37: 0, # 'B'
|
| 3327 |
+
47: 1, # 'C'
|
| 3328 |
+
39: 1, # 'D'
|
| 3329 |
+
29: 2, # 'E'
|
| 3330 |
+
52: 0, # 'F'
|
| 3331 |
+
36: 1, # 'G'
|
| 3332 |
+
45: 2, # 'H'
|
| 3333 |
+
53: 0, # 'I'
|
| 3334 |
+
60: 0, # 'J'
|
| 3335 |
+
16: 0, # 'K'
|
| 3336 |
+
49: 0, # 'L'
|
| 3337 |
+
20: 1, # 'M'
|
| 3338 |
+
46: 1, # 'N'
|
| 3339 |
+
42: 2, # 'O'
|
| 3340 |
+
48: 2, # 'P'
|
| 3341 |
+
44: 1, # 'R'
|
| 3342 |
+
35: 0, # 'S'
|
| 3343 |
+
31: 0, # 'T'
|
| 3344 |
+
51: 1, # 'U'
|
| 3345 |
+
38: 1, # 'V'
|
| 3346 |
+
62: 0, # 'W'
|
| 3347 |
+
43: 2, # 'Y'
|
| 3348 |
+
56: 0, # 'Z'
|
| 3349 |
+
1: 0, # 'a'
|
| 3350 |
+
21: 2, # 'b'
|
| 3351 |
+
28: 1, # 'c'
|
| 3352 |
+
12: 2, # 'd'
|
| 3353 |
+
2: 0, # 'e'
|
| 3354 |
+
18: 1, # 'f'
|
| 3355 |
+
27: 1, # 'g'
|
| 3356 |
+
25: 1, # 'h'
|
| 3357 |
+
3: 2, # 'i'
|
| 3358 |
+
24: 0, # 'j'
|
| 3359 |
+
10: 2, # 'k'
|
| 3360 |
+
5: 0, # 'l'
|
| 3361 |
+
13: 0, # 'm'
|
| 3362 |
+
4: 3, # 'n'
|
| 3363 |
+
15: 2, # 'o'
|
| 3364 |
+
26: 2, # 'p'
|
| 3365 |
+
7: 3, # 'r'
|
| 3366 |
+
8: 1, # 's'
|
| 3367 |
+
9: 2, # 't'
|
| 3368 |
+
14: 0, # 'u'
|
| 3369 |
+
32: 1, # 'v'
|
| 3370 |
+
57: 0, # 'w'
|
| 3371 |
+
58: 0, # 'x'
|
| 3372 |
+
11: 0, # 'y'
|
| 3373 |
+
22: 1, # 'z'
|
| 3374 |
+
63: 0, # '·'
|
| 3375 |
+
54: 0, # 'Ç'
|
| 3376 |
+
50: 0, # 'Ö'
|
| 3377 |
+
55: 0, # 'Ü'
|
| 3378 |
+
59: 0, # 'â'
|
| 3379 |
+
33: 0, # 'ç'
|
| 3380 |
+
61: 0, # 'î'
|
| 3381 |
+
34: 2, # 'ö'
|
| 3382 |
+
17: 2, # 'ü'
|
| 3383 |
+
30: 1, # 'ğ'
|
| 3384 |
+
41: 0, # 'İ'
|
| 3385 |
+
6: 2, # 'ı'
|
| 3386 |
+
40: 0, # 'Ş'
|
| 3387 |
+
19: 1, # 'ş'
|
| 3388 |
+
},
|
| 3389 |
+
55: { # 'Ü'
|
| 3390 |
+
23: 0, # 'A'
|
| 3391 |
+
37: 0, # 'B'
|
| 3392 |
+
47: 0, # 'C'
|
| 3393 |
+
39: 0, # 'D'
|
| 3394 |
+
29: 0, # 'E'
|
| 3395 |
+
52: 2, # 'F'
|
| 3396 |
+
36: 0, # 'G'
|
| 3397 |
+
45: 0, # 'H'
|
| 3398 |
+
53: 0, # 'I'
|
| 3399 |
+
60: 0, # 'J'
|
| 3400 |
+
16: 1, # 'K'
|
| 3401 |
+
49: 0, # 'L'
|
| 3402 |
+
20: 0, # 'M'
|
| 3403 |
+
46: 0, # 'N'
|
| 3404 |
+
42: 0, # 'O'
|
| 3405 |
+
48: 1, # 'P'
|
| 3406 |
+
44: 0, # 'R'
|
| 3407 |
+
35: 0, # 'S'
|
| 3408 |
+
31: 0, # 'T'
|
| 3409 |
+
51: 0, # 'U'
|
| 3410 |
+
38: 1, # 'V'
|
| 3411 |
+
62: 0, # 'W'
|
| 3412 |
+
43: 0, # 'Y'
|
| 3413 |
+
56: 0, # 'Z'
|
| 3414 |
+
1: 2, # 'a'
|
| 3415 |
+
21: 0, # 'b'
|
| 3416 |
+
28: 2, # 'c'
|
| 3417 |
+
12: 0, # 'd'
|
| 3418 |
+
2: 2, # 'e'
|
| 3419 |
+
18: 0, # 'f'
|
| 3420 |
+
27: 1, # 'g'
|
| 3421 |
+
25: 0, # 'h'
|
| 3422 |
+
3: 0, # 'i'
|
| 3423 |
+
24: 0, # 'j'
|
| 3424 |
+
10: 0, # 'k'
|
| 3425 |
+
5: 1, # 'l'
|
| 3426 |
+
13: 1, # 'm'
|
| 3427 |
+
4: 1, # 'n'
|
| 3428 |
+
15: 0, # 'o'
|
| 3429 |
+
26: 0, # 'p'
|
| 3430 |
+
7: 0, # 'r'
|
| 3431 |
+
8: 0, # 's'
|
| 3432 |
+
9: 1, # 't'
|
| 3433 |
+
14: 2, # 'u'
|
| 3434 |
+
32: 0, # 'v'
|
| 3435 |
+
57: 0, # 'w'
|
| 3436 |
+
58: 0, # 'x'
|
| 3437 |
+
11: 0, # 'y'
|
| 3438 |
+
22: 1, # 'z'
|
| 3439 |
+
63: 0, # '·'
|
| 3440 |
+
54: 0, # 'Ç'
|
| 3441 |
+
50: 1, # 'Ö'
|
| 3442 |
+
55: 0, # 'Ü'
|
| 3443 |
+
59: 0, # 'â'
|
| 3444 |
+
33: 0, # 'ç'
|
| 3445 |
+
61: 0, # 'î'
|
| 3446 |
+
34: 1, # 'ö'
|
| 3447 |
+
17: 0, # 'ü'
|
| 3448 |
+
30: 1, # 'ğ'
|
| 3449 |
+
41: 1, # 'İ'
|
| 3450 |
+
6: 0, # 'ı'
|
| 3451 |
+
40: 0, # 'Ş'
|
| 3452 |
+
19: 1, # 'ş'
|
| 3453 |
+
},
|
| 3454 |
+
59: { # 'â'
|
| 3455 |
+
23: 0, # 'A'
|
| 3456 |
+
37: 0, # 'B'
|
| 3457 |
+
47: 0, # 'C'
|
| 3458 |
+
39: 0, # 'D'
|
| 3459 |
+
29: 0, # 'E'
|
| 3460 |
+
52: 0, # 'F'
|
| 3461 |
+
36: 1, # 'G'
|
| 3462 |
+
45: 0, # 'H'
|
| 3463 |
+
53: 0, # 'I'
|
| 3464 |
+
60: 0, # 'J'
|
| 3465 |
+
16: 1, # 'K'
|
| 3466 |
+
49: 0, # 'L'
|
| 3467 |
+
20: 0, # 'M'
|
| 3468 |
+
46: 0, # 'N'
|
| 3469 |
+
42: 0, # 'O'
|
| 3470 |
+
48: 0, # 'P'
|
| 3471 |
+
44: 0, # 'R'
|
| 3472 |
+
35: 0, # 'S'
|
| 3473 |
+
31: 0, # 'T'
|
| 3474 |
+
51: 0, # 'U'
|
| 3475 |
+
38: 0, # 'V'
|
| 3476 |
+
62: 0, # 'W'
|
| 3477 |
+
43: 0, # 'Y'
|
| 3478 |
+
56: 0, # 'Z'
|
| 3479 |
+
1: 2, # 'a'
|
| 3480 |
+
21: 0, # 'b'
|
| 3481 |
+
28: 0, # 'c'
|
| 3482 |
+
12: 0, # 'd'
|
| 3483 |
+
2: 2, # 'e'
|
| 3484 |
+
18: 0, # 'f'
|
| 3485 |
+
27: 0, # 'g'
|
| 3486 |
+
25: 0, # 'h'
|
| 3487 |
+
3: 0, # 'i'
|
| 3488 |
+
24: 0, # 'j'
|
| 3489 |
+
10: 0, # 'k'
|
| 3490 |
+
5: 0, # 'l'
|
| 3491 |
+
13: 2, # 'm'
|
| 3492 |
+
4: 0, # 'n'
|
| 3493 |
+
15: 1, # 'o'
|
| 3494 |
+
26: 0, # 'p'
|
| 3495 |
+
7: 0, # 'r'
|
| 3496 |
+
8: 0, # 's'
|
| 3497 |
+
9: 0, # 't'
|
| 3498 |
+
14: 2, # 'u'
|
| 3499 |
+
32: 0, # 'v'
|
| 3500 |
+
57: 0, # 'w'
|
| 3501 |
+
58: 0, # 'x'
|
| 3502 |
+
11: 0, # 'y'
|
| 3503 |
+
22: 1, # 'z'
|
| 3504 |
+
63: 0, # '·'
|
| 3505 |
+
54: 0, # 'Ç'
|
| 3506 |
+
50: 0, # 'Ö'
|
| 3507 |
+
55: 0, # 'Ü'
|
| 3508 |
+
59: 0, # 'â'
|
| 3509 |
+
33: 0, # 'ç'
|
| 3510 |
+
61: 0, # 'î'
|
| 3511 |
+
34: 0, # 'ö'
|
| 3512 |
+
17: 0, # 'ü'
|
| 3513 |
+
30: 0, # 'ğ'
|
| 3514 |
+
41: 0, # 'İ'
|
| 3515 |
+
6: 1, # 'ı'
|
| 3516 |
+
40: 1, # 'Ş'
|
| 3517 |
+
19: 0, # 'ş'
|
| 3518 |
+
},
|
| 3519 |
+
33: { # 'ç'
|
| 3520 |
+
23: 0, # 'A'
|
| 3521 |
+
37: 0, # 'B'
|
| 3522 |
+
47: 0, # 'C'
|
| 3523 |
+
39: 0, # 'D'
|
| 3524 |
+
29: 3, # 'E'
|
| 3525 |
+
52: 0, # 'F'
|
| 3526 |
+
36: 0, # 'G'
|
| 3527 |
+
45: 0, # 'H'
|
| 3528 |
+
53: 0, # 'I'
|
| 3529 |
+
60: 0, # 'J'
|
| 3530 |
+
16: 0, # 'K'
|
| 3531 |
+
49: 0, # 'L'
|
| 3532 |
+
20: 1, # 'M'
|
| 3533 |
+
46: 0, # 'N'
|
| 3534 |
+
42: 0, # 'O'
|
| 3535 |
+
48: 0, # 'P'
|
| 3536 |
+
44: 0, # 'R'
|
| 3537 |
+
35: 0, # 'S'
|
| 3538 |
+
31: 2, # 'T'
|
| 3539 |
+
51: 0, # 'U'
|
| 3540 |
+
38: 1, # 'V'
|
| 3541 |
+
62: 0, # 'W'
|
| 3542 |
+
43: 0, # 'Y'
|
| 3543 |
+
56: 0, # 'Z'
|
| 3544 |
+
1: 0, # 'a'
|
| 3545 |
+
21: 3, # 'b'
|
| 3546 |
+
28: 0, # 'c'
|
| 3547 |
+
12: 2, # 'd'
|
| 3548 |
+
2: 0, # 'e'
|
| 3549 |
+
18: 2, # 'f'
|
| 3550 |
+
27: 1, # 'g'
|
| 3551 |
+
25: 3, # 'h'
|
| 3552 |
+
3: 3, # 'i'
|
| 3553 |
+
24: 0, # 'j'
|
| 3554 |
+
10: 3, # 'k'
|
| 3555 |
+
5: 0, # 'l'
|
| 3556 |
+
13: 0, # 'm'
|
| 3557 |
+
4: 3, # 'n'
|
| 3558 |
+
15: 0, # 'o'
|
| 3559 |
+
26: 1, # 'p'
|
| 3560 |
+
7: 3, # 'r'
|
| 3561 |
+
8: 2, # 's'
|
| 3562 |
+
9: 3, # 't'
|
| 3563 |
+
14: 0, # 'u'
|
| 3564 |
+
32: 2, # 'v'
|
| 3565 |
+
57: 0, # 'w'
|
| 3566 |
+
58: 0, # 'x'
|
| 3567 |
+
11: 2, # 'y'
|
| 3568 |
+
22: 0, # 'z'
|
| 3569 |
+
63: 0, # '·'
|
| 3570 |
+
54: 0, # 'Ç'
|
| 3571 |
+
50: 0, # 'Ö'
|
| 3572 |
+
55: 0, # 'Ü'
|
| 3573 |
+
59: 0, # 'â'
|
| 3574 |
+
33: 0, # 'ç'
|
| 3575 |
+
61: 0, # 'î'
|
| 3576 |
+
34: 0, # 'ö'
|
| 3577 |
+
17: 1, # 'ü'
|
| 3578 |
+
30: 0, # 'ğ'
|
| 3579 |
+
41: 0, # 'İ'
|
| 3580 |
+
6: 3, # 'ı'
|
| 3581 |
+
40: 0, # 'Ş'
|
| 3582 |
+
19: 0, # 'ş'
|
| 3583 |
+
},
|
| 3584 |
+
61: { # 'î'
|
| 3585 |
+
23: 0, # 'A'
|
| 3586 |
+
37: 0, # 'B'
|
| 3587 |
+
47: 0, # 'C'
|
| 3588 |
+
39: 0, # 'D'
|
| 3589 |
+
29: 0, # 'E'
|
| 3590 |
+
52: 0, # 'F'
|
| 3591 |
+
36: 0, # 'G'
|
| 3592 |
+
45: 0, # 'H'
|
| 3593 |
+
53: 0, # 'I'
|
| 3594 |
+
60: 0, # 'J'
|
| 3595 |
+
16: 0, # 'K'
|
| 3596 |
+
49: 0, # 'L'
|
| 3597 |
+
20: 0, # 'M'
|
| 3598 |
+
46: 0, # 'N'
|
| 3599 |
+
42: 0, # 'O'
|
| 3600 |
+
48: 0, # 'P'
|
| 3601 |
+
44: 0, # 'R'
|
| 3602 |
+
35: 0, # 'S'
|
| 3603 |
+
31: 0, # 'T'
|
| 3604 |
+
51: 0, # 'U'
|
| 3605 |
+
38: 0, # 'V'
|
| 3606 |
+
62: 0, # 'W'
|
| 3607 |
+
43: 0, # 'Y'
|
| 3608 |
+
56: 1, # 'Z'
|
| 3609 |
+
1: 2, # 'a'
|
| 3610 |
+
21: 0, # 'b'
|
| 3611 |
+
28: 0, # 'c'
|
| 3612 |
+
12: 0, # 'd'
|
| 3613 |
+
2: 2, # 'e'
|
| 3614 |
+
18: 0, # 'f'
|
| 3615 |
+
27: 0, # 'g'
|
| 3616 |
+
25: 0, # 'h'
|
| 3617 |
+
3: 0, # 'i'
|
| 3618 |
+
24: 1, # 'j'
|
| 3619 |
+
10: 0, # 'k'
|
| 3620 |
+
5: 0, # 'l'
|
| 3621 |
+
13: 1, # 'm'
|
| 3622 |
+
4: 1, # 'n'
|
| 3623 |
+
15: 0, # 'o'
|
| 3624 |
+
26: 0, # 'p'
|
| 3625 |
+
7: 0, # 'r'
|
| 3626 |
+
8: 0, # 's'
|
| 3627 |
+
9: 0, # 't'
|
| 3628 |
+
14: 1, # 'u'
|
| 3629 |
+
32: 0, # 'v'
|
| 3630 |
+
57: 0, # 'w'
|
| 3631 |
+
58: 0, # 'x'
|
| 3632 |
+
11: 0, # 'y'
|
| 3633 |
+
22: 1, # 'z'
|
| 3634 |
+
63: 0, # '·'
|
| 3635 |
+
54: 0, # 'Ç'
|
| 3636 |
+
50: 0, # 'Ö'
|
| 3637 |
+
55: 0, # 'Ü'
|
| 3638 |
+
59: 0, # 'â'
|
| 3639 |
+
33: 0, # 'ç'
|
| 3640 |
+
61: 1, # 'î'
|
| 3641 |
+
34: 0, # 'ö'
|
| 3642 |
+
17: 0, # 'ü'
|
| 3643 |
+
30: 0, # 'ğ'
|
| 3644 |
+
41: 0, # 'İ'
|
| 3645 |
+
6: 1, # 'ı'
|
| 3646 |
+
40: 0, # 'Ş'
|
| 3647 |
+
19: 0, # 'ş'
|
| 3648 |
+
},
|
| 3649 |
+
34: { # 'ö'
|
| 3650 |
+
23: 0, # 'A'
|
| 3651 |
+
37: 1, # 'B'
|
| 3652 |
+
47: 1, # 'C'
|
| 3653 |
+
39: 0, # 'D'
|
| 3654 |
+
29: 0, # 'E'
|
| 3655 |
+
52: 2, # 'F'
|
| 3656 |
+
36: 1, # 'G'
|
| 3657 |
+
45: 1, # 'H'
|
| 3658 |
+
53: 0, # 'I'
|
| 3659 |
+
60: 0, # 'J'
|
| 3660 |
+
16: 3, # 'K'
|
| 3661 |
+
49: 1, # 'L'
|
| 3662 |
+
20: 0, # 'M'
|
| 3663 |
+
46: 1, # 'N'
|
| 3664 |
+
42: 1, # 'O'
|
| 3665 |
+
48: 2, # 'P'
|
| 3666 |
+
44: 1, # 'R'
|
| 3667 |
+
35: 1, # 'S'
|
| 3668 |
+
31: 1, # 'T'
|
| 3669 |
+
51: 1, # 'U'
|
| 3670 |
+
38: 1, # 'V'
|
| 3671 |
+
62: 0, # 'W'
|
| 3672 |
+
43: 0, # 'Y'
|
| 3673 |
+
56: 1, # 'Z'
|
| 3674 |
+
1: 3, # 'a'
|
| 3675 |
+
21: 1, # 'b'
|
| 3676 |
+
28: 2, # 'c'
|
| 3677 |
+
12: 1, # 'd'
|
| 3678 |
+
2: 3, # 'e'
|
| 3679 |
+
18: 0, # 'f'
|
| 3680 |
+
27: 2, # 'g'
|
| 3681 |
+
25: 2, # 'h'
|
| 3682 |
+
3: 1, # 'i'
|
| 3683 |
+
24: 2, # 'j'
|
| 3684 |
+
10: 1, # 'k'
|
| 3685 |
+
5: 2, # 'l'
|
| 3686 |
+
13: 3, # 'm'
|
| 3687 |
+
4: 2, # 'n'
|
| 3688 |
+
15: 2, # 'o'
|
| 3689 |
+
26: 0, # 'p'
|
| 3690 |
+
7: 0, # 'r'
|
| 3691 |
+
8: 3, # 's'
|
| 3692 |
+
9: 1, # 't'
|
| 3693 |
+
14: 3, # 'u'
|
| 3694 |
+
32: 0, # 'v'
|
| 3695 |
+
57: 0, # 'w'
|
| 3696 |
+
58: 0, # 'x'
|
| 3697 |
+
11: 1, # 'y'
|
| 3698 |
+
22: 2, # 'z'
|
| 3699 |
+
63: 0, # '·'
|
| 3700 |
+
54: 1, # 'Ç'
|
| 3701 |
+
50: 2, # 'Ö'
|
| 3702 |
+
55: 0, # 'Ü'
|
| 3703 |
+
59: 0, # 'â'
|
| 3704 |
+
33: 2, # 'ç'
|
| 3705 |
+
61: 0, # 'î'
|
| 3706 |
+
34: 2, # 'ö'
|
| 3707 |
+
17: 0, # 'ü'
|
| 3708 |
+
30: 2, # 'ğ'
|
| 3709 |
+
41: 1, # 'İ'
|
| 3710 |
+
6: 1, # 'ı'
|
| 3711 |
+
40: 2, # 'Ş'
|
| 3712 |
+
19: 1, # 'ş'
|
| 3713 |
+
},
|
| 3714 |
+
17: { # 'ü'
|
| 3715 |
+
23: 0, # 'A'
|
| 3716 |
+
37: 0, # 'B'
|
| 3717 |
+
47: 1, # 'C'
|
| 3718 |
+
39: 0, # 'D'
|
| 3719 |
+
29: 0, # 'E'
|
| 3720 |
+
52: 0, # 'F'
|
| 3721 |
+
36: 0, # 'G'
|
| 3722 |
+
45: 0, # 'H'
|
| 3723 |
+
53: 0, # 'I'
|
| 3724 |
+
60: 1, # 'J'
|
| 3725 |
+
16: 1, # 'K'
|
| 3726 |
+
49: 0, # 'L'
|
| 3727 |
+
20: 1, # 'M'
|
| 3728 |
+
46: 0, # 'N'
|
| 3729 |
+
42: 0, # 'O'
|
| 3730 |
+
48: 0, # 'P'
|
| 3731 |
+
44: 0, # 'R'
|
| 3732 |
+
35: 0, # 'S'
|
| 3733 |
+
31: 1, # 'T'
|
| 3734 |
+
51: 0, # 'U'
|
| 3735 |
+
38: 0, # 'V'
|
| 3736 |
+
62: 0, # 'W'
|
| 3737 |
+
43: 0, # 'Y'
|
| 3738 |
+
56: 1, # 'Z'
|
| 3739 |
+
1: 3, # 'a'
|
| 3740 |
+
21: 0, # 'b'
|
| 3741 |
+
28: 0, # 'c'
|
| 3742 |
+
12: 1, # 'd'
|
| 3743 |
+
2: 3, # 'e'
|
| 3744 |
+
18: 1, # 'f'
|
| 3745 |
+
27: 2, # 'g'
|
| 3746 |
+
25: 0, # 'h'
|
| 3747 |
+
3: 1, # 'i'
|
| 3748 |
+
24: 1, # 'j'
|
| 3749 |
+
10: 2, # 'k'
|
| 3750 |
+
5: 3, # 'l'
|
| 3751 |
+
13: 2, # 'm'
|
| 3752 |
+
4: 3, # 'n'
|
| 3753 |
+
15: 0, # 'o'
|
| 3754 |
+
26: 2, # 'p'
|
| 3755 |
+
7: 2, # 'r'
|
| 3756 |
+
8: 3, # 's'
|
| 3757 |
+
9: 2, # 't'
|
| 3758 |
+
14: 3, # 'u'
|
| 3759 |
+
32: 1, # 'v'
|
| 3760 |
+
57: 1, # 'w'
|
| 3761 |
+
58: 0, # 'x'
|
| 3762 |
+
11: 0, # 'y'
|
| 3763 |
+
22: 0, # 'z'
|
| 3764 |
+
63: 0, # '·'
|
| 3765 |
+
54: 0, # 'Ç'
|
| 3766 |
+
50: 0, # 'Ö'
|
| 3767 |
+
55: 0, # 'Ü'
|
| 3768 |
+
59: 0, # 'â'
|
| 3769 |
+
33: 1, # 'ç'
|
| 3770 |
+
61: 0, # 'î'
|
| 3771 |
+
34: 0, # 'ö'
|
| 3772 |
+
17: 2, # 'ü'
|
| 3773 |
+
30: 0, # 'ğ'
|
| 3774 |
+
41: 0, # 'İ'
|
| 3775 |
+
6: 2, # 'ı'
|
| 3776 |
+
40: 0, # 'Ş'
|
| 3777 |
+
19: 0, # 'ş'
|
| 3778 |
+
},
|
| 3779 |
+
30: { # 'ğ'
|
| 3780 |
+
23: 0, # 'A'
|
| 3781 |
+
37: 2, # 'B'
|
| 3782 |
+
47: 1, # 'C'
|
| 3783 |
+
39: 0, # 'D'
|
| 3784 |
+
29: 0, # 'E'
|
| 3785 |
+
52: 2, # 'F'
|
| 3786 |
+
36: 1, # 'G'
|
| 3787 |
+
45: 0, # 'H'
|
| 3788 |
+
53: 1, # 'I'
|
| 3789 |
+
60: 0, # 'J'
|
| 3790 |
+
16: 3, # 'K'
|
| 3791 |
+
49: 0, # 'L'
|
| 3792 |
+
20: 1, # 'M'
|
| 3793 |
+
46: 2, # 'N'
|
| 3794 |
+
42: 2, # 'O'
|
| 3795 |
+
48: 1, # 'P'
|
| 3796 |
+
44: 1, # 'R'
|
| 3797 |
+
35: 0, # 'S'
|
| 3798 |
+
31: 1, # 'T'
|
| 3799 |
+
51: 0, # 'U'
|
| 3800 |
+
38: 2, # 'V'
|
| 3801 |
+
62: 0, # 'W'
|
| 3802 |
+
43: 2, # 'Y'
|
| 3803 |
+
56: 0, # 'Z'
|
| 3804 |
+
1: 3, # 'a'
|
| 3805 |
+
21: 0, # 'b'
|
| 3806 |
+
28: 2, # 'c'
|
| 3807 |
+
12: 0, # 'd'
|
| 3808 |
+
2: 2, # 'e'
|
| 3809 |
+
18: 0, # 'f'
|
| 3810 |
+
27: 0, # 'g'
|
| 3811 |
+
25: 0, # 'h'
|
| 3812 |
+
3: 0, # 'i'
|
| 3813 |
+
24: 3, # 'j'
|
| 3814 |
+
10: 1, # 'k'
|
| 3815 |
+
5: 2, # 'l'
|
| 3816 |
+
13: 3, # 'm'
|
| 3817 |
+
4: 0, # 'n'
|
| 3818 |
+
15: 1, # 'o'
|
| 3819 |
+
26: 0, # 'p'
|
| 3820 |
+
7: 1, # 'r'
|
| 3821 |
+
8: 0, # 's'
|
| 3822 |
+
9: 0, # 't'
|
| 3823 |
+
14: 3, # 'u'
|
| 3824 |
+
32: 0, # 'v'
|
| 3825 |
+
57: 0, # 'w'
|
| 3826 |
+
58: 0, # 'x'
|
| 3827 |
+
11: 0, # 'y'
|
| 3828 |
+
22: 2, # 'z'
|
| 3829 |
+
63: 0, # '·'
|
| 3830 |
+
54: 2, # 'Ç'
|
| 3831 |
+
50: 2, # 'Ö'
|
| 3832 |
+
55: 0, # 'Ü'
|
| 3833 |
+
59: 0, # 'â'
|
| 3834 |
+
33: 1, # 'ç'
|
| 3835 |
+
61: 0, # 'î'
|
| 3836 |
+
34: 2, # 'ö'
|
| 3837 |
+
17: 0, # 'ü'
|
| 3838 |
+
30: 1, # 'ğ'
|
| 3839 |
+
41: 2, # 'İ'
|
| 3840 |
+
6: 2, # 'ı'
|
| 3841 |
+
40: 2, # 'Ş'
|
| 3842 |
+
19: 1, # 'ş'
|
| 3843 |
+
},
|
| 3844 |
+
41: { # 'İ'
|
| 3845 |
+
23: 0, # 'A'
|
| 3846 |
+
37: 0, # 'B'
|
| 3847 |
+
47: 1, # 'C'
|
| 3848 |
+
39: 1, # 'D'
|
| 3849 |
+
29: 1, # 'E'
|
| 3850 |
+
52: 0, # 'F'
|
| 3851 |
+
36: 2, # 'G'
|
| 3852 |
+
45: 2, # 'H'
|
| 3853 |
+
53: 0, # 'I'
|
| 3854 |
+
60: 0, # 'J'
|
| 3855 |
+
16: 0, # 'K'
|
| 3856 |
+
49: 0, # 'L'
|
| 3857 |
+
20: 2, # 'M'
|
| 3858 |
+
46: 1, # 'N'
|
| 3859 |
+
42: 1, # 'O'
|
| 3860 |
+
48: 2, # 'P'
|
| 3861 |
+
44: 0, # 'R'
|
| 3862 |
+
35: 1, # 'S'
|
| 3863 |
+
31: 1, # 'T'
|
| 3864 |
+
51: 1, # 'U'
|
| 3865 |
+
38: 1, # 'V'
|
| 3866 |
+
62: 0, # 'W'
|
| 3867 |
+
43: 2, # 'Y'
|
| 3868 |
+
56: 0, # 'Z'
|
| 3869 |
+
1: 1, # 'a'
|
| 3870 |
+
21: 2, # 'b'
|
| 3871 |
+
28: 1, # 'c'
|
| 3872 |
+
12: 2, # 'd'
|
| 3873 |
+
2: 1, # 'e'
|
| 3874 |
+
18: 0, # 'f'
|
| 3875 |
+
27: 3, # 'g'
|
| 3876 |
+
25: 2, # 'h'
|
| 3877 |
+
3: 2, # 'i'
|
| 3878 |
+
24: 2, # 'j'
|
| 3879 |
+
10: 2, # 'k'
|
| 3880 |
+
5: 0, # 'l'
|
| 3881 |
+
13: 1, # 'm'
|
| 3882 |
+
4: 3, # 'n'
|
| 3883 |
+
15: 1, # 'o'
|
| 3884 |
+
26: 1, # 'p'
|
| 3885 |
+
7: 3, # 'r'
|
| 3886 |
+
8: 3, # 's'
|
| 3887 |
+
9: 2, # 't'
|
| 3888 |
+
14: 0, # 'u'
|
| 3889 |
+
32: 0, # 'v'
|
| 3890 |
+
57: 1, # 'w'
|
| 3891 |
+
58: 0, # 'x'
|
| 3892 |
+
11: 2, # 'y'
|
| 3893 |
+
22: 0, # 'z'
|
| 3894 |
+
63: 0, # '·'
|
| 3895 |
+
54: 0, # 'Ç'
|
| 3896 |
+
50: 0, # 'Ö'
|
| 3897 |
+
55: 1, # 'Ü'
|
| 3898 |
+
59: 1, # 'â'
|
| 3899 |
+
33: 0, # 'ç'
|
| 3900 |
+
61: 0, # 'î'
|
| 3901 |
+
34: 1, # 'ö'
|
| 3902 |
+
17: 1, # 'ü'
|
| 3903 |
+
30: 2, # 'ğ'
|
| 3904 |
+
41: 0, # 'İ'
|
| 3905 |
+
6: 3, # 'ı'
|
| 3906 |
+
40: 0, # 'Ş'
|
| 3907 |
+
19: 1, # 'ş'
|
| 3908 |
+
},
|
| 3909 |
+
6: { # 'ı'
|
| 3910 |
+
23: 2, # 'A'
|
| 3911 |
+
37: 0, # 'B'
|
| 3912 |
+
47: 0, # 'C'
|
| 3913 |
+
39: 0, # 'D'
|
| 3914 |
+
29: 0, # 'E'
|
| 3915 |
+
52: 0, # 'F'
|
| 3916 |
+
36: 1, # 'G'
|
| 3917 |
+
45: 0, # 'H'
|
| 3918 |
+
53: 0, # 'I'
|
| 3919 |
+
60: 2, # 'J'
|
| 3920 |
+
16: 3, # 'K'
|
| 3921 |
+
49: 0, # 'L'
|
| 3922 |
+
20: 3, # 'M'
|
| 3923 |
+
46: 1, # 'N'
|
| 3924 |
+
42: 0, # 'O'
|
| 3925 |
+
48: 0, # 'P'
|
| 3926 |
+
44: 0, # 'R'
|
| 3927 |
+
35: 0, # 'S'
|
| 3928 |
+
31: 2, # 'T'
|
| 3929 |
+
51: 0, # 'U'
|
| 3930 |
+
38: 0, # 'V'
|
| 3931 |
+
62: 0, # 'W'
|
| 3932 |
+
43: 2, # 'Y'
|
| 3933 |
+
56: 1, # 'Z'
|
| 3934 |
+
1: 3, # 'a'
|
| 3935 |
+
21: 2, # 'b'
|
| 3936 |
+
28: 1, # 'c'
|
| 3937 |
+
12: 3, # 'd'
|
| 3938 |
+
2: 3, # 'e'
|
| 3939 |
+
18: 3, # 'f'
|
| 3940 |
+
27: 3, # 'g'
|
| 3941 |
+
25: 2, # 'h'
|
| 3942 |
+
3: 3, # 'i'
|
| 3943 |
+
24: 3, # 'j'
|
| 3944 |
+
10: 3, # 'k'
|
| 3945 |
+
5: 3, # 'l'
|
| 3946 |
+
13: 3, # 'm'
|
| 3947 |
+
4: 3, # 'n'
|
| 3948 |
+
15: 0, # 'o'
|
| 3949 |
+
26: 3, # 'p'
|
| 3950 |
+
7: 3, # 'r'
|
| 3951 |
+
8: 3, # 's'
|
| 3952 |
+
9: 3, # 't'
|
| 3953 |
+
14: 3, # 'u'
|
| 3954 |
+
32: 3, # 'v'
|
| 3955 |
+
57: 1, # 'w'
|
| 3956 |
+
58: 1, # 'x'
|
| 3957 |
+
11: 3, # 'y'
|
| 3958 |
+
22: 0, # 'z'
|
| 3959 |
+
63: 1, # '·'
|
| 3960 |
+
54: 0, # 'Ç'
|
| 3961 |
+
50: 0, # 'Ö'
|
| 3962 |
+
55: 0, # 'Ü'
|
| 3963 |
+
59: 0, # 'â'
|
| 3964 |
+
33: 2, # 'ç'
|
| 3965 |
+
61: 0, # 'î'
|
| 3966 |
+
34: 0, # 'ö'
|
| 3967 |
+
17: 3, # 'ü'
|
| 3968 |
+
30: 0, # 'ğ'
|
| 3969 |
+
41: 0, # 'İ'
|
| 3970 |
+
6: 3, # 'ı'
|
| 3971 |
+
40: 0, # 'Ş'
|
| 3972 |
+
19: 0, # 'ş'
|
| 3973 |
+
},
|
| 3974 |
+
40: { # 'Ş'
|
| 3975 |
+
23: 0, # 'A'
|
| 3976 |
+
37: 0, # 'B'
|
| 3977 |
+
47: 1, # 'C'
|
| 3978 |
+
39: 1, # 'D'
|
| 3979 |
+
29: 1, # 'E'
|
| 3980 |
+
52: 0, # 'F'
|
| 3981 |
+
36: 1, # 'G'
|
| 3982 |
+
45: 2, # 'H'
|
| 3983 |
+
53: 1, # 'I'
|
| 3984 |
+
60: 0, # 'J'
|
| 3985 |
+
16: 0, # 'K'
|
| 3986 |
+
49: 0, # 'L'
|
| 3987 |
+
20: 2, # 'M'
|
| 3988 |
+
46: 1, # 'N'
|
| 3989 |
+
42: 1, # 'O'
|
| 3990 |
+
48: 2, # 'P'
|
| 3991 |
+
44: 2, # 'R'
|
| 3992 |
+
35: 1, # 'S'
|
| 3993 |
+
31: 1, # 'T'
|
| 3994 |
+
51: 0, # 'U'
|
| 3995 |
+
38: 1, # 'V'
|
| 3996 |
+
62: 0, # 'W'
|
| 3997 |
+
43: 2, # 'Y'
|
| 3998 |
+
56: 1, # 'Z'
|
| 3999 |
+
1: 0, # 'a'
|
| 4000 |
+
21: 2, # 'b'
|
| 4001 |
+
28: 0, # 'c'
|
| 4002 |
+
12: 2, # 'd'
|
| 4003 |
+
2: 0, # 'e'
|
| 4004 |
+
18: 3, # 'f'
|
| 4005 |
+
27: 0, # 'g'
|
| 4006 |
+
25: 2, # 'h'
|
| 4007 |
+
3: 3, # 'i'
|
| 4008 |
+
24: 2, # 'j'
|
| 4009 |
+
10: 1, # 'k'
|
| 4010 |
+
5: 0, # 'l'
|
| 4011 |
+
13: 1, # 'm'
|
| 4012 |
+
4: 3, # 'n'
|
| 4013 |
+
15: 2, # 'o'
|
| 4014 |
+
26: 0, # 'p'
|
| 4015 |
+
7: 3, # 'r'
|
| 4016 |
+
8: 2, # 's'
|
| 4017 |
+
9: 2, # 't'
|
| 4018 |
+
14: 1, # 'u'
|
| 4019 |
+
32: 3, # 'v'
|
| 4020 |
+
57: 0, # 'w'
|
| 4021 |
+
58: 0, # 'x'
|
| 4022 |
+
11: 2, # 'y'
|
| 4023 |
+
22: 0, # 'z'
|
| 4024 |
+
63: 0, # '·'
|
| 4025 |
+
54: 0, # 'Ç'
|
| 4026 |
+
50: 0, # 'Ö'
|
| 4027 |
+
55: 1, # 'Ü'
|
| 4028 |
+
59: 0, # 'â'
|
| 4029 |
+
33: 0, # 'ç'
|
| 4030 |
+
61: 0, # 'î'
|
| 4031 |
+
34: 2, # 'ö'
|
| 4032 |
+
17: 1, # 'ü'
|
| 4033 |
+
30: 2, # 'ğ'
|
| 4034 |
+
41: 0, # 'İ'
|
| 4035 |
+
6: 2, # 'ı'
|
| 4036 |
+
40: 1, # 'Ş'
|
| 4037 |
+
19: 2, # 'ş'
|
| 4038 |
+
},
|
| 4039 |
+
19: { # 'ş'
|
| 4040 |
+
23: 0, # 'A'
|
| 4041 |
+
37: 0, # 'B'
|
| 4042 |
+
47: 1, # 'C'
|
| 4043 |
+
39: 0, # 'D'
|
| 4044 |
+
29: 0, # 'E'
|
| 4045 |
+
52: 2, # 'F'
|
| 4046 |
+
36: 1, # 'G'
|
| 4047 |
+
45: 0, # 'H'
|
| 4048 |
+
53: 0, # 'I'
|
| 4049 |
+
60: 0, # 'J'
|
| 4050 |
+
16: 3, # 'K'
|
| 4051 |
+
49: 2, # 'L'
|
| 4052 |
+
20: 0, # 'M'
|
| 4053 |
+
46: 1, # 'N'
|
| 4054 |
+
42: 1, # 'O'
|
| 4055 |
+
48: 1, # 'P'
|
| 4056 |
+
44: 1, # 'R'
|
| 4057 |
+
35: 1, # 'S'
|
| 4058 |
+
31: 0, # 'T'
|
| 4059 |
+
51: 1, # 'U'
|
| 4060 |
+
38: 1, # 'V'
|
| 4061 |
+
62: 0, # 'W'
|
| 4062 |
+
43: 1, # 'Y'
|
| 4063 |
+
56: 0, # 'Z'
|
| 4064 |
+
1: 3, # 'a'
|
| 4065 |
+
21: 1, # 'b'
|
| 4066 |
+
28: 2, # 'c'
|
| 4067 |
+
12: 0, # 'd'
|
| 4068 |
+
2: 3, # 'e'
|
| 4069 |
+
18: 0, # 'f'
|
| 4070 |
+
27: 2, # 'g'
|
| 4071 |
+
25: 1, # 'h'
|
| 4072 |
+
3: 1, # 'i'
|
| 4073 |
+
24: 0, # 'j'
|
| 4074 |
+
10: 2, # 'k'
|
| 4075 |
+
5: 2, # 'l'
|
| 4076 |
+
13: 3, # 'm'
|
| 4077 |
+
4: 0, # 'n'
|
| 4078 |
+
15: 0, # 'o'
|
| 4079 |
+
26: 1, # 'p'
|
| 4080 |
+
7: 3, # 'r'
|
| 4081 |
+
8: 0, # 's'
|
| 4082 |
+
9: 0, # 't'
|
| 4083 |
+
14: 3, # 'u'
|
| 4084 |
+
32: 0, # 'v'
|
| 4085 |
+
57: 0, # 'w'
|
| 4086 |
+
58: 0, # 'x'
|
| 4087 |
+
11: 0, # 'y'
|
| 4088 |
+
22: 2, # 'z'
|
| 4089 |
+
63: 0, # '·'
|
| 4090 |
+
54: 1, # 'Ç'
|
| 4091 |
+
50: 2, # 'Ö'
|
| 4092 |
+
55: 0, # 'Ü'
|
| 4093 |
+
59: 0, # 'â'
|
| 4094 |
+
33: 1, # 'ç'
|
| 4095 |
+
61: 1, # 'î'
|
| 4096 |
+
34: 2, # 'ö'
|
| 4097 |
+
17: 0, # 'ü'
|
| 4098 |
+
30: 1, # 'ğ'
|
| 4099 |
+
41: 1, # 'İ'
|
| 4100 |
+
6: 1, # 'ı'
|
| 4101 |
+
40: 1, # 'Ş'
|
| 4102 |
+
19: 1, # 'ş'
|
| 4103 |
+
},
|
| 4104 |
+
}
|
| 4105 |
+
|
| 4106 |
+
# 255: Undefined characters that did not exist in training text
|
| 4107 |
+
# 254: Carriage/Return
|
| 4108 |
+
# 253: symbol (punctuation) that does not belong to word
|
| 4109 |
+
# 252: 0 - 9
|
| 4110 |
+
# 251: Control characters
|
| 4111 |
+
|
| 4112 |
+
# Character Mapping Table(s):
|
| 4113 |
+
ISO_8859_9_TURKISH_CHAR_TO_ORDER = {
|
| 4114 |
+
0: 255, # '\x00'
|
| 4115 |
+
1: 255, # '\x01'
|
| 4116 |
+
2: 255, # '\x02'
|
| 4117 |
+
3: 255, # '\x03'
|
| 4118 |
+
4: 255, # '\x04'
|
| 4119 |
+
5: 255, # '\x05'
|
| 4120 |
+
6: 255, # '\x06'
|
| 4121 |
+
7: 255, # '\x07'
|
| 4122 |
+
8: 255, # '\x08'
|
| 4123 |
+
9: 255, # '\t'
|
| 4124 |
+
10: 255, # '\n'
|
| 4125 |
+
11: 255, # '\x0b'
|
| 4126 |
+
12: 255, # '\x0c'
|
| 4127 |
+
13: 255, # '\r'
|
| 4128 |
+
14: 255, # '\x0e'
|
| 4129 |
+
15: 255, # '\x0f'
|
| 4130 |
+
16: 255, # '\x10'
|
| 4131 |
+
17: 255, # '\x11'
|
| 4132 |
+
18: 255, # '\x12'
|
| 4133 |
+
19: 255, # '\x13'
|
| 4134 |
+
20: 255, # '\x14'
|
| 4135 |
+
21: 255, # '\x15'
|
| 4136 |
+
22: 255, # '\x16'
|
| 4137 |
+
23: 255, # '\x17'
|
| 4138 |
+
24: 255, # '\x18'
|
| 4139 |
+
25: 255, # '\x19'
|
| 4140 |
+
26: 255, # '\x1a'
|
| 4141 |
+
27: 255, # '\x1b'
|
| 4142 |
+
28: 255, # '\x1c'
|
| 4143 |
+
29: 255, # '\x1d'
|
| 4144 |
+
30: 255, # '\x1e'
|
| 4145 |
+
31: 255, # '\x1f'
|
| 4146 |
+
32: 255, # ' '
|
| 4147 |
+
33: 255, # '!'
|
| 4148 |
+
34: 255, # '"'
|
| 4149 |
+
35: 255, # '#'
|
| 4150 |
+
36: 255, # '$'
|
| 4151 |
+
37: 255, # '%'
|
| 4152 |
+
38: 255, # '&'
|
| 4153 |
+
39: 255, # "'"
|
| 4154 |
+
40: 255, # '('
|
| 4155 |
+
41: 255, # ')'
|
| 4156 |
+
42: 255, # '*'
|
| 4157 |
+
43: 255, # '+'
|
| 4158 |
+
44: 255, # ','
|
| 4159 |
+
45: 255, # '-'
|
| 4160 |
+
46: 255, # '.'
|
| 4161 |
+
47: 255, # '/'
|
| 4162 |
+
48: 255, # '0'
|
| 4163 |
+
49: 255, # '1'
|
| 4164 |
+
50: 255, # '2'
|
| 4165 |
+
51: 255, # '3'
|
| 4166 |
+
52: 255, # '4'
|
| 4167 |
+
53: 255, # '5'
|
| 4168 |
+
54: 255, # '6'
|
| 4169 |
+
55: 255, # '7'
|
| 4170 |
+
56: 255, # '8'
|
| 4171 |
+
57: 255, # '9'
|
| 4172 |
+
58: 255, # ':'
|
| 4173 |
+
59: 255, # ';'
|
| 4174 |
+
60: 255, # '<'
|
| 4175 |
+
61: 255, # '='
|
| 4176 |
+
62: 255, # '>'
|
| 4177 |
+
63: 255, # '?'
|
| 4178 |
+
64: 255, # '@'
|
| 4179 |
+
65: 23, # 'A'
|
| 4180 |
+
66: 37, # 'B'
|
| 4181 |
+
67: 47, # 'C'
|
| 4182 |
+
68: 39, # 'D'
|
| 4183 |
+
69: 29, # 'E'
|
| 4184 |
+
70: 52, # 'F'
|
| 4185 |
+
71: 36, # 'G'
|
| 4186 |
+
72: 45, # 'H'
|
| 4187 |
+
73: 53, # 'I'
|
| 4188 |
+
74: 60, # 'J'
|
| 4189 |
+
75: 16, # 'K'
|
| 4190 |
+
76: 49, # 'L'
|
| 4191 |
+
77: 20, # 'M'
|
| 4192 |
+
78: 46, # 'N'
|
| 4193 |
+
79: 42, # 'O'
|
| 4194 |
+
80: 48, # 'P'
|
| 4195 |
+
81: 69, # 'Q'
|
| 4196 |
+
82: 44, # 'R'
|
| 4197 |
+
83: 35, # 'S'
|
| 4198 |
+
84: 31, # 'T'
|
| 4199 |
+
85: 51, # 'U'
|
| 4200 |
+
86: 38, # 'V'
|
| 4201 |
+
87: 62, # 'W'
|
| 4202 |
+
88: 65, # 'X'
|
| 4203 |
+
89: 43, # 'Y'
|
| 4204 |
+
90: 56, # 'Z'
|
| 4205 |
+
91: 255, # '['
|
| 4206 |
+
92: 255, # '\\'
|
| 4207 |
+
93: 255, # ']'
|
| 4208 |
+
94: 255, # '^'
|
| 4209 |
+
95: 255, # '_'
|
| 4210 |
+
96: 255, # '`'
|
| 4211 |
+
97: 1, # 'a'
|
| 4212 |
+
98: 21, # 'b'
|
| 4213 |
+
99: 28, # 'c'
|
| 4214 |
+
100: 12, # 'd'
|
| 4215 |
+
101: 2, # 'e'
|
| 4216 |
+
102: 18, # 'f'
|
| 4217 |
+
103: 27, # 'g'
|
| 4218 |
+
104: 25, # 'h'
|
| 4219 |
+
105: 3, # 'i'
|
| 4220 |
+
106: 24, # 'j'
|
| 4221 |
+
107: 10, # 'k'
|
| 4222 |
+
108: 5, # 'l'
|
| 4223 |
+
109: 13, # 'm'
|
| 4224 |
+
110: 4, # 'n'
|
| 4225 |
+
111: 15, # 'o'
|
| 4226 |
+
112: 26, # 'p'
|
| 4227 |
+
113: 64, # 'q'
|
| 4228 |
+
114: 7, # 'r'
|
| 4229 |
+
115: 8, # 's'
|
| 4230 |
+
116: 9, # 't'
|
| 4231 |
+
117: 14, # 'u'
|
| 4232 |
+
118: 32, # 'v'
|
| 4233 |
+
119: 57, # 'w'
|
| 4234 |
+
120: 58, # 'x'
|
| 4235 |
+
121: 11, # 'y'
|
| 4236 |
+
122: 22, # 'z'
|
| 4237 |
+
123: 255, # '{'
|
| 4238 |
+
124: 255, # '|'
|
| 4239 |
+
125: 255, # '}'
|
| 4240 |
+
126: 255, # '~'
|
| 4241 |
+
127: 255, # '\x7f'
|
| 4242 |
+
128: 180, # '\x80'
|
| 4243 |
+
129: 179, # '\x81'
|
| 4244 |
+
130: 178, # '\x82'
|
| 4245 |
+
131: 177, # '\x83'
|
| 4246 |
+
132: 176, # '\x84'
|
| 4247 |
+
133: 175, # '\x85'
|
| 4248 |
+
134: 174, # '\x86'
|
| 4249 |
+
135: 173, # '\x87'
|
| 4250 |
+
136: 172, # '\x88'
|
| 4251 |
+
137: 171, # '\x89'
|
| 4252 |
+
138: 170, # '\x8a'
|
| 4253 |
+
139: 169, # '\x8b'
|
| 4254 |
+
140: 168, # '\x8c'
|
| 4255 |
+
141: 167, # '\x8d'
|
| 4256 |
+
142: 166, # '\x8e'
|
| 4257 |
+
143: 165, # '\x8f'
|
| 4258 |
+
144: 164, # '\x90'
|
| 4259 |
+
145: 163, # '\x91'
|
| 4260 |
+
146: 162, # '\x92'
|
| 4261 |
+
147: 161, # '\x93'
|
| 4262 |
+
148: 160, # '\x94'
|
| 4263 |
+
149: 159, # '\x95'
|
| 4264 |
+
150: 101, # '\x96'
|
| 4265 |
+
151: 158, # '\x97'
|
| 4266 |
+
152: 157, # '\x98'
|
| 4267 |
+
153: 156, # '\x99'
|
| 4268 |
+
154: 155, # '\x9a'
|
| 4269 |
+
155: 154, # '\x9b'
|
| 4270 |
+
156: 153, # '\x9c'
|
| 4271 |
+
157: 152, # '\x9d'
|
| 4272 |
+
158: 151, # '\x9e'
|
| 4273 |
+
159: 106, # '\x9f'
|
| 4274 |
+
160: 150, # '\xa0'
|
| 4275 |
+
161: 149, # '¡'
|
| 4276 |
+
162: 148, # '¢'
|
| 4277 |
+
163: 147, # '£'
|
| 4278 |
+
164: 146, # '¤'
|
| 4279 |
+
165: 145, # '¥'
|
| 4280 |
+
166: 144, # '¦'
|
| 4281 |
+
167: 100, # '§'
|
| 4282 |
+
168: 143, # '¨'
|
| 4283 |
+
169: 142, # '©'
|
| 4284 |
+
170: 141, # 'ª'
|
| 4285 |
+
171: 140, # '«'
|
| 4286 |
+
172: 139, # '¬'
|
| 4287 |
+
173: 138, # '\xad'
|
| 4288 |
+
174: 137, # '®'
|
| 4289 |
+
175: 136, # '¯'
|
| 4290 |
+
176: 94, # '°'
|
| 4291 |
+
177: 80, # '±'
|
| 4292 |
+
178: 93, # '²'
|
| 4293 |
+
179: 135, # '³'
|
| 4294 |
+
180: 105, # '´'
|
| 4295 |
+
181: 134, # 'µ'
|
| 4296 |
+
182: 133, # '¶'
|
| 4297 |
+
183: 63, # '·'
|
| 4298 |
+
184: 132, # '¸'
|
| 4299 |
+
185: 131, # '¹'
|
| 4300 |
+
186: 130, # 'º'
|
| 4301 |
+
187: 129, # '»'
|
| 4302 |
+
188: 128, # '¼'
|
| 4303 |
+
189: 127, # '½'
|
| 4304 |
+
190: 126, # '¾'
|
| 4305 |
+
191: 125, # '¿'
|
| 4306 |
+
192: 124, # 'À'
|
| 4307 |
+
193: 104, # 'Á'
|
| 4308 |
+
194: 73, # 'Â'
|
| 4309 |
+
195: 99, # 'Ã'
|
| 4310 |
+
196: 79, # 'Ä'
|
| 4311 |
+
197: 85, # 'Å'
|
| 4312 |
+
198: 123, # 'Æ'
|
| 4313 |
+
199: 54, # 'Ç'
|
| 4314 |
+
200: 122, # 'È'
|
| 4315 |
+
201: 98, # 'É'
|
| 4316 |
+
202: 92, # 'Ê'
|
| 4317 |
+
203: 121, # 'Ë'
|
| 4318 |
+
204: 120, # 'Ì'
|
| 4319 |
+
205: 91, # 'Í'
|
| 4320 |
+
206: 103, # 'Î'
|
| 4321 |
+
207: 119, # 'Ï'
|
| 4322 |
+
208: 68, # 'Ğ'
|
| 4323 |
+
209: 118, # 'Ñ'
|
| 4324 |
+
210: 117, # 'Ò'
|
| 4325 |
+
211: 97, # 'Ó'
|
| 4326 |
+
212: 116, # 'Ô'
|
| 4327 |
+
213: 115, # 'Õ'
|
| 4328 |
+
214: 50, # 'Ö'
|
| 4329 |
+
215: 90, # '×'
|
| 4330 |
+
216: 114, # 'Ø'
|
| 4331 |
+
217: 113, # 'Ù'
|
| 4332 |
+
218: 112, # 'Ú'
|
| 4333 |
+
219: 111, # 'Û'
|
| 4334 |
+
220: 55, # 'Ü'
|
| 4335 |
+
221: 41, # 'İ'
|
| 4336 |
+
222: 40, # 'Ş'
|
| 4337 |
+
223: 86, # 'ß'
|
| 4338 |
+
224: 89, # 'à'
|
| 4339 |
+
225: 70, # 'á'
|
| 4340 |
+
226: 59, # 'â'
|
| 4341 |
+
227: 78, # 'ã'
|
| 4342 |
+
228: 71, # 'ä'
|
| 4343 |
+
229: 82, # 'å'
|
| 4344 |
+
230: 88, # 'æ'
|
| 4345 |
+
231: 33, # 'ç'
|
| 4346 |
+
232: 77, # 'è'
|
| 4347 |
+
233: 66, # 'é'
|
| 4348 |
+
234: 84, # 'ê'
|
| 4349 |
+
235: 83, # 'ë'
|
| 4350 |
+
236: 110, # 'ì'
|
| 4351 |
+
237: 75, # 'í'
|
| 4352 |
+
238: 61, # 'î'
|
| 4353 |
+
239: 96, # 'ï'
|
| 4354 |
+
240: 30, # 'ğ'
|
| 4355 |
+
241: 67, # 'ñ'
|
| 4356 |
+
242: 109, # 'ò'
|
| 4357 |
+
243: 74, # 'ó'
|
| 4358 |
+
244: 87, # 'ô'
|
| 4359 |
+
245: 102, # 'õ'
|
| 4360 |
+
246: 34, # 'ö'
|
| 4361 |
+
247: 95, # '÷'
|
| 4362 |
+
248: 81, # 'ø'
|
| 4363 |
+
249: 108, # 'ù'
|
| 4364 |
+
250: 76, # 'ú'
|
| 4365 |
+
251: 72, # 'û'
|
| 4366 |
+
252: 17, # 'ü'
|
| 4367 |
+
253: 6, # 'ı'
|
| 4368 |
+
254: 19, # 'ş'
|
| 4369 |
+
255: 107, # 'ÿ'
|
| 4370 |
+
}
|
| 4371 |
+
|
| 4372 |
+
ISO_8859_9_TURKISH_MODEL = SingleByteCharSetModel(
|
| 4373 |
+
charset_name="ISO-8859-9",
|
| 4374 |
+
language="Turkish",
|
| 4375 |
+
char_to_order_map=ISO_8859_9_TURKISH_CHAR_TO_ORDER,
|
| 4376 |
+
language_model=TURKISH_LANG_MODEL,
|
| 4377 |
+
typical_positive_ratio=0.97029,
|
| 4378 |
+
keep_ascii_letters=True,
|
| 4379 |
+
alphabet="ABCDEFGHIJKLMNOPRSTUVYZabcdefghijklmnoprstuvyzÂÇÎÖÛÜâçîöûüĞğİıŞş",
|
| 4380 |
+
)
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/mbcsgroupprober.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
# Proofpoint, Inc.
|
| 13 |
+
#
|
| 14 |
+
# This library is free software; you can redistribute it and/or
|
| 15 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 16 |
+
# License as published by the Free Software Foundation; either
|
| 17 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 18 |
+
#
|
| 19 |
+
# This library is distributed in the hope that it will be useful,
|
| 20 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 21 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 22 |
+
# Lesser General Public License for more details.
|
| 23 |
+
#
|
| 24 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 25 |
+
# License along with this library; if not, write to the Free Software
|
| 26 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 27 |
+
# 02110-1301 USA
|
| 28 |
+
######################### END LICENSE BLOCK #########################
|
| 29 |
+
|
| 30 |
+
from .big5prober import Big5Prober
|
| 31 |
+
from .charsetgroupprober import CharSetGroupProber
|
| 32 |
+
from .cp949prober import CP949Prober
|
| 33 |
+
from .enums import LanguageFilter
|
| 34 |
+
from .eucjpprober import EUCJPProber
|
| 35 |
+
from .euckrprober import EUCKRProber
|
| 36 |
+
from .euctwprober import EUCTWProber
|
| 37 |
+
from .gb2312prober import GB2312Prober
|
| 38 |
+
from .johabprober import JOHABProber
|
| 39 |
+
from .sjisprober import SJISProber
|
| 40 |
+
from .utf8prober import UTF8Prober
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class MBCSGroupProber(CharSetGroupProber):
|
| 44 |
+
def __init__(self, lang_filter: LanguageFilter = LanguageFilter.NONE) -> None:
|
| 45 |
+
super().__init__(lang_filter=lang_filter)
|
| 46 |
+
self.probers = [
|
| 47 |
+
UTF8Prober(),
|
| 48 |
+
SJISProber(),
|
| 49 |
+
EUCJPProber(),
|
| 50 |
+
GB2312Prober(),
|
| 51 |
+
EUCKRProber(),
|
| 52 |
+
CP949Prober(),
|
| 53 |
+
Big5Prober(),
|
| 54 |
+
EUCTWProber(),
|
| 55 |
+
JOHABProber(),
|
| 56 |
+
]
|
| 57 |
+
self.reset()
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/resultdict.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TYPE_CHECKING, Optional
|
| 2 |
+
|
| 3 |
+
if TYPE_CHECKING:
|
| 4 |
+
# TypedDict was introduced in Python 3.8.
|
| 5 |
+
#
|
| 6 |
+
# TODO: Remove the else block and TYPE_CHECKING check when dropping support
|
| 7 |
+
# for Python 3.7.
|
| 8 |
+
from typing import TypedDict
|
| 9 |
+
|
| 10 |
+
class ResultDict(TypedDict):
|
| 11 |
+
encoding: Optional[str]
|
| 12 |
+
confidence: float
|
| 13 |
+
language: Optional[str]
|
| 14 |
+
|
| 15 |
+
else:
|
| 16 |
+
ResultDict = dict
|
venv/lib/python3.12/site-packages/pip/_vendor/chardet/sbcharsetprober.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
#
|
| 13 |
+
# This library is free software; you can redistribute it and/or
|
| 14 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 15 |
+
# License as published by the Free Software Foundation; either
|
| 16 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 17 |
+
#
|
| 18 |
+
# This library is distributed in the hope that it will be useful,
|
| 19 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
+
# Lesser General Public License for more details.
|
| 22 |
+
#
|
| 23 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 24 |
+
# License along with this library; if not, write to the Free Software
|
| 25 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 26 |
+
# 02110-1301 USA
|
| 27 |
+
######################### END LICENSE BLOCK #########################
|
| 28 |
+
|
| 29 |
+
from typing import Dict, List, NamedTuple, Optional, Union
|
| 30 |
+
|
| 31 |
+
from .charsetprober import CharSetProber
|
| 32 |
+
from .enums import CharacterCategory, ProbingState, SequenceLikelihood
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class SingleByteCharSetModel(NamedTuple):
|
| 36 |
+
charset_name: str
|
| 37 |
+
language: str
|
| 38 |
+
char_to_order_map: Dict[int, int]
|
| 39 |
+
language_model: Dict[int, Dict[int, int]]
|
| 40 |
+
typical_positive_ratio: float
|
| 41 |
+
keep_ascii_letters: bool
|
| 42 |
+
alphabet: str
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class SingleByteCharSetProber(CharSetProber):
|
| 46 |
+
SAMPLE_SIZE = 64
|
| 47 |
+
SB_ENOUGH_REL_THRESHOLD = 1024 # 0.25 * SAMPLE_SIZE^2
|
| 48 |
+
POSITIVE_SHORTCUT_THRESHOLD = 0.95
|
| 49 |
+
NEGATIVE_SHORTCUT_THRESHOLD = 0.05
|
| 50 |
+
|
| 51 |
+
def __init__(
|
| 52 |
+
self,
|
| 53 |
+
model: SingleByteCharSetModel,
|
| 54 |
+
is_reversed: bool = False,
|
| 55 |
+
name_prober: Optional[CharSetProber] = None,
|
| 56 |
+
) -> None:
|
| 57 |
+
super().__init__()
|
| 58 |
+
self._model = model
|
| 59 |
+
# TRUE if we need to reverse every pair in the model lookup
|
| 60 |
+
self._reversed = is_reversed
|
| 61 |
+
# Optional auxiliary prober for name decision
|
| 62 |
+
self._name_prober = name_prober
|
| 63 |
+
self._last_order = 255
|
| 64 |
+
self._seq_counters: List[int] = []
|
| 65 |
+
self._total_seqs = 0
|
| 66 |
+
self._total_char = 0
|
| 67 |
+
self._control_char = 0
|
| 68 |
+
self._freq_char = 0
|
| 69 |
+
self.reset()
|
| 70 |
+
|
| 71 |
+
def reset(self) -> None:
|
| 72 |
+
super().reset()
|
| 73 |
+
# char order of last character
|
| 74 |
+
self._last_order = 255
|
| 75 |
+
self._seq_counters = [0] * SequenceLikelihood.get_num_categories()
|
| 76 |
+
self._total_seqs = 0
|
| 77 |
+
self._total_char = 0
|
| 78 |
+
self._control_char = 0
|
| 79 |
+
# characters that fall in our sampling range
|
| 80 |
+
self._freq_char = 0
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def charset_name(self) -> Optional[str]:
|
| 84 |
+
if self._name_prober:
|
| 85 |
+
return self._name_prober.charset_name
|
| 86 |
+
return self._model.charset_name
|
| 87 |
+
|
| 88 |
+
@property
|
| 89 |
+
def language(self) -> Optional[str]:
|
| 90 |
+
if self._name_prober:
|
| 91 |
+
return self._name_prober.language
|
| 92 |
+
return self._model.language
|
| 93 |
+
|
| 94 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 95 |
+
# TODO: Make filter_international_words keep things in self.alphabet
|
| 96 |
+
if not self._model.keep_ascii_letters:
|
| 97 |
+
byte_str = self.filter_international_words(byte_str)
|
| 98 |
+
else:
|
| 99 |
+
byte_str = self.remove_xml_tags(byte_str)
|
| 100 |
+
if not byte_str:
|
| 101 |
+
return self.state
|
| 102 |
+
char_to_order_map = self._model.char_to_order_map
|
| 103 |
+
language_model = self._model.language_model
|
| 104 |
+
for char in byte_str:
|
| 105 |
+
order = char_to_order_map.get(char, CharacterCategory.UNDEFINED)
|
| 106 |
+
# XXX: This was SYMBOL_CAT_ORDER before, with a value of 250, but
|
| 107 |
+
# CharacterCategory.SYMBOL is actually 253, so we use CONTROL
|
| 108 |
+
# to make it closer to the original intent. The only difference
|
| 109 |
+
# is whether or not we count digits and control characters for
|
| 110 |
+
# _total_char purposes.
|
| 111 |
+
if order < CharacterCategory.CONTROL:
|
| 112 |
+
self._total_char += 1
|
| 113 |
+
if order < self.SAMPLE_SIZE:
|
| 114 |
+
self._freq_char += 1
|
| 115 |
+
if self._last_order < self.SAMPLE_SIZE:
|
| 116 |
+
self._total_seqs += 1
|
| 117 |
+
if not self._reversed:
|
| 118 |
+
lm_cat = language_model[self._last_order][order]
|
| 119 |
+
else:
|
| 120 |
+
lm_cat = language_model[order][self._last_order]
|
| 121 |
+
self._seq_counters[lm_cat] += 1
|
| 122 |
+
self._last_order = order
|
| 123 |
+
|
| 124 |
+
charset_name = self._model.charset_name
|
| 125 |
+
if self.state == ProbingState.DETECTING:
|
| 126 |
+
if self._total_seqs > self.SB_ENOUGH_REL_THRESHOLD:
|
| 127 |
+
confidence = self.get_confidence()
|
| 128 |
+
if confidence > self.POSITIVE_SHORTCUT_THRESHOLD:
|
| 129 |
+
self.logger.debug(
|
| 130 |
+
"%s confidence = %s, we have a winner", charset_name, confidence
|
| 131 |
+
)
|
| 132 |
+
self._state = ProbingState.FOUND_IT
|
| 133 |
+
elif confidence < self.NEGATIVE_SHORTCUT_THRESHOLD:
|
| 134 |
+
self.logger.debug(
|
| 135 |
+
"%s confidence = %s, below negative shortcut threshold %s",
|
| 136 |
+
charset_name,
|
| 137 |
+
confidence,
|
| 138 |
+
self.NEGATIVE_SHORTCUT_THRESHOLD,
|
| 139 |
+
)
|
| 140 |
+
self._state = ProbingState.NOT_ME
|
| 141 |
+
|
| 142 |
+
return self.state
|
| 143 |
+
|
| 144 |
+
def get_confidence(self) -> float:
|
| 145 |
+
r = 0.01
|
| 146 |
+
if self._total_seqs > 0:
|
| 147 |
+
r = (
|
| 148 |
+
(
|
| 149 |
+
self._seq_counters[SequenceLikelihood.POSITIVE]
|
| 150 |
+
+ 0.25 * self._seq_counters[SequenceLikelihood.LIKELY]
|
| 151 |
+
)
|
| 152 |
+
/ self._total_seqs
|
| 153 |
+
/ self._model.typical_positive_ratio
|
| 154 |
+
)
|
| 155 |
+
# The more control characters (proportionnaly to the size
|
| 156 |
+
# of the text), the less confident we become in the current
|
| 157 |
+
# charset.
|
| 158 |
+
r = r * (self._total_char - self._control_char) / self._total_char
|
| 159 |
+
r = r * self._freq_char / self._total_char
|
| 160 |
+
if r >= 1.0:
|
| 161 |
+
r = 0.99
|
| 162 |
+
return r
|
venv/lib/python3.12/site-packages/pip/_vendor/msgpack/__init__.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding: utf-8
|
| 2 |
+
from .exceptions import *
|
| 3 |
+
from .ext import ExtType, Timestamp
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
version = (1, 0, 5)
|
| 10 |
+
__version__ = "1.0.5"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if os.environ.get("MSGPACK_PUREPYTHON") or sys.version_info[0] == 2:
|
| 14 |
+
from .fallback import Packer, unpackb, Unpacker
|
| 15 |
+
else:
|
| 16 |
+
try:
|
| 17 |
+
from ._cmsgpack import Packer, unpackb, Unpacker
|
| 18 |
+
except ImportError:
|
| 19 |
+
from .fallback import Packer, unpackb, Unpacker
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def pack(o, stream, **kwargs):
|
| 23 |
+
"""
|
| 24 |
+
Pack object `o` and write it to `stream`
|
| 25 |
+
|
| 26 |
+
See :class:`Packer` for options.
|
| 27 |
+
"""
|
| 28 |
+
packer = Packer(**kwargs)
|
| 29 |
+
stream.write(packer.pack(o))
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def packb(o, **kwargs):
|
| 33 |
+
"""
|
| 34 |
+
Pack object `o` and return packed bytes
|
| 35 |
+
|
| 36 |
+
See :class:`Packer` for options.
|
| 37 |
+
"""
|
| 38 |
+
return Packer(**kwargs).pack(o)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def unpack(stream, **kwargs):
|
| 42 |
+
"""
|
| 43 |
+
Unpack an object from `stream`.
|
| 44 |
+
|
| 45 |
+
Raises `ExtraData` when `stream` contains extra bytes.
|
| 46 |
+
See :class:`Unpacker` for options.
|
| 47 |
+
"""
|
| 48 |
+
data = stream.read()
|
| 49 |
+
return unpackb(data, **kwargs)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# alias for compatibility to simplejson/marshal/pickle.
|
| 53 |
+
load = unpack
|
| 54 |
+
loads = unpackb
|
| 55 |
+
|
| 56 |
+
dump = pack
|
| 57 |
+
dumps = packb
|
venv/lib/python3.12/site-packages/pip/_vendor/msgpack/exceptions.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class UnpackException(Exception):
|
| 2 |
+
"""Base class for some exceptions raised while unpacking.
|
| 3 |
+
|
| 4 |
+
NOTE: unpack may raise exception other than subclass of
|
| 5 |
+
UnpackException. If you want to catch all error, catch
|
| 6 |
+
Exception instead.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class BufferFull(UnpackException):
|
| 11 |
+
pass
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class OutOfData(UnpackException):
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class FormatError(ValueError, UnpackException):
|
| 19 |
+
"""Invalid msgpack format"""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class StackError(ValueError, UnpackException):
|
| 23 |
+
"""Too nested"""
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Deprecated. Use ValueError instead
|
| 27 |
+
UnpackValueError = ValueError
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class ExtraData(UnpackValueError):
|
| 31 |
+
"""ExtraData is raised when there is trailing data.
|
| 32 |
+
|
| 33 |
+
This exception is raised while only one-shot (not streaming)
|
| 34 |
+
unpack.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
def __init__(self, unpacked, extra):
|
| 38 |
+
self.unpacked = unpacked
|
| 39 |
+
self.extra = extra
|
| 40 |
+
|
| 41 |
+
def __str__(self):
|
| 42 |
+
return "unpack(b) received extra data."
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# Deprecated. Use Exception instead to catch all exception during packing.
|
| 46 |
+
PackException = Exception
|
| 47 |
+
PackValueError = ValueError
|
| 48 |
+
PackOverflowError = OverflowError
|
venv/lib/python3.12/site-packages/pip/_vendor/msgpack/ext.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding: utf-8
|
| 2 |
+
from collections import namedtuple
|
| 3 |
+
import datetime
|
| 4 |
+
import sys
|
| 5 |
+
import struct
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
PY2 = sys.version_info[0] == 2
|
| 9 |
+
|
| 10 |
+
if PY2:
|
| 11 |
+
int_types = (int, long)
|
| 12 |
+
_utc = None
|
| 13 |
+
else:
|
| 14 |
+
int_types = int
|
| 15 |
+
try:
|
| 16 |
+
_utc = datetime.timezone.utc
|
| 17 |
+
except AttributeError:
|
| 18 |
+
_utc = datetime.timezone(datetime.timedelta(0))
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class ExtType(namedtuple("ExtType", "code data")):
|
| 22 |
+
"""ExtType represents ext type in msgpack."""
|
| 23 |
+
|
| 24 |
+
def __new__(cls, code, data):
|
| 25 |
+
if not isinstance(code, int):
|
| 26 |
+
raise TypeError("code must be int")
|
| 27 |
+
if not isinstance(data, bytes):
|
| 28 |
+
raise TypeError("data must be bytes")
|
| 29 |
+
if not 0 <= code <= 127:
|
| 30 |
+
raise ValueError("code must be 0~127")
|
| 31 |
+
return super(ExtType, cls).__new__(cls, code, data)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Timestamp(object):
|
| 35 |
+
"""Timestamp represents the Timestamp extension type in msgpack.
|
| 36 |
+
|
| 37 |
+
When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python
|
| 38 |
+
msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`.
|
| 39 |
+
|
| 40 |
+
This class is immutable: Do not override seconds and nanoseconds.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
__slots__ = ["seconds", "nanoseconds"]
|
| 44 |
+
|
| 45 |
+
def __init__(self, seconds, nanoseconds=0):
|
| 46 |
+
"""Initialize a Timestamp object.
|
| 47 |
+
|
| 48 |
+
:param int seconds:
|
| 49 |
+
Number of seconds since the UNIX epoch (00:00:00 UTC Jan 1 1970, minus leap seconds).
|
| 50 |
+
May be negative.
|
| 51 |
+
|
| 52 |
+
:param int nanoseconds:
|
| 53 |
+
Number of nanoseconds to add to `seconds` to get fractional time.
|
| 54 |
+
Maximum is 999_999_999. Default is 0.
|
| 55 |
+
|
| 56 |
+
Note: Negative times (before the UNIX epoch) are represented as negative seconds + positive ns.
|
| 57 |
+
"""
|
| 58 |
+
if not isinstance(seconds, int_types):
|
| 59 |
+
raise TypeError("seconds must be an integer")
|
| 60 |
+
if not isinstance(nanoseconds, int_types):
|
| 61 |
+
raise TypeError("nanoseconds must be an integer")
|
| 62 |
+
if not (0 <= nanoseconds < 10**9):
|
| 63 |
+
raise ValueError(
|
| 64 |
+
"nanoseconds must be a non-negative integer less than 999999999."
|
| 65 |
+
)
|
| 66 |
+
self.seconds = seconds
|
| 67 |
+
self.nanoseconds = nanoseconds
|
| 68 |
+
|
| 69 |
+
def __repr__(self):
|
| 70 |
+
"""String representation of Timestamp."""
|
| 71 |
+
return "Timestamp(seconds={0}, nanoseconds={1})".format(
|
| 72 |
+
self.seconds, self.nanoseconds
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
def __eq__(self, other):
|
| 76 |
+
"""Check for equality with another Timestamp object"""
|
| 77 |
+
if type(other) is self.__class__:
|
| 78 |
+
return (
|
| 79 |
+
self.seconds == other.seconds and self.nanoseconds == other.nanoseconds
|
| 80 |
+
)
|
| 81 |
+
return False
|
| 82 |
+
|
| 83 |
+
def __ne__(self, other):
|
| 84 |
+
"""not-equals method (see :func:`__eq__()`)"""
|
| 85 |
+
return not self.__eq__(other)
|
| 86 |
+
|
| 87 |
+
def __hash__(self):
|
| 88 |
+
return hash((self.seconds, self.nanoseconds))
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def from_bytes(b):
|
| 92 |
+
"""Unpack bytes into a `Timestamp` object.
|
| 93 |
+
|
| 94 |
+
Used for pure-Python msgpack unpacking.
|
| 95 |
+
|
| 96 |
+
:param b: Payload from msgpack ext message with code -1
|
| 97 |
+
:type b: bytes
|
| 98 |
+
|
| 99 |
+
:returns: Timestamp object unpacked from msgpack ext payload
|
| 100 |
+
:rtype: Timestamp
|
| 101 |
+
"""
|
| 102 |
+
if len(b) == 4:
|
| 103 |
+
seconds = struct.unpack("!L", b)[0]
|
| 104 |
+
nanoseconds = 0
|
| 105 |
+
elif len(b) == 8:
|
| 106 |
+
data64 = struct.unpack("!Q", b)[0]
|
| 107 |
+
seconds = data64 & 0x00000003FFFFFFFF
|
| 108 |
+
nanoseconds = data64 >> 34
|
| 109 |
+
elif len(b) == 12:
|
| 110 |
+
nanoseconds, seconds = struct.unpack("!Iq", b)
|
| 111 |
+
else:
|
| 112 |
+
raise ValueError(
|
| 113 |
+
"Timestamp type can only be created from 32, 64, or 96-bit byte objects"
|
| 114 |
+
)
|
| 115 |
+
return Timestamp(seconds, nanoseconds)
|
| 116 |
+
|
| 117 |
+
def to_bytes(self):
|
| 118 |
+
"""Pack this Timestamp object into bytes.
|
| 119 |
+
|
| 120 |
+
Used for pure-Python msgpack packing.
|
| 121 |
+
|
| 122 |
+
:returns data: Payload for EXT message with code -1 (timestamp type)
|
| 123 |
+
:rtype: bytes
|
| 124 |
+
"""
|
| 125 |
+
if (self.seconds >> 34) == 0: # seconds is non-negative and fits in 34 bits
|
| 126 |
+
data64 = self.nanoseconds << 34 | self.seconds
|
| 127 |
+
if data64 & 0xFFFFFFFF00000000 == 0:
|
| 128 |
+
# nanoseconds is zero and seconds < 2**32, so timestamp 32
|
| 129 |
+
data = struct.pack("!L", data64)
|
| 130 |
+
else:
|
| 131 |
+
# timestamp 64
|
| 132 |
+
data = struct.pack("!Q", data64)
|
| 133 |
+
else:
|
| 134 |
+
# timestamp 96
|
| 135 |
+
data = struct.pack("!Iq", self.nanoseconds, self.seconds)
|
| 136 |
+
return data
|
| 137 |
+
|
| 138 |
+
@staticmethod
|
| 139 |
+
def from_unix(unix_sec):
|
| 140 |
+
"""Create a Timestamp from posix timestamp in seconds.
|
| 141 |
+
|
| 142 |
+
:param unix_float: Posix timestamp in seconds.
|
| 143 |
+
:type unix_float: int or float.
|
| 144 |
+
"""
|
| 145 |
+
seconds = int(unix_sec // 1)
|
| 146 |
+
nanoseconds = int((unix_sec % 1) * 10**9)
|
| 147 |
+
return Timestamp(seconds, nanoseconds)
|
| 148 |
+
|
| 149 |
+
def to_unix(self):
|
| 150 |
+
"""Get the timestamp as a floating-point value.
|
| 151 |
+
|
| 152 |
+
:returns: posix timestamp
|
| 153 |
+
:rtype: float
|
| 154 |
+
"""
|
| 155 |
+
return self.seconds + self.nanoseconds / 1e9
|
| 156 |
+
|
| 157 |
+
@staticmethod
|
| 158 |
+
def from_unix_nano(unix_ns):
|
| 159 |
+
"""Create a Timestamp from posix timestamp in nanoseconds.
|
| 160 |
+
|
| 161 |
+
:param int unix_ns: Posix timestamp in nanoseconds.
|
| 162 |
+
:rtype: Timestamp
|
| 163 |
+
"""
|
| 164 |
+
return Timestamp(*divmod(unix_ns, 10**9))
|
| 165 |
+
|
| 166 |
+
def to_unix_nano(self):
|
| 167 |
+
"""Get the timestamp as a unixtime in nanoseconds.
|
| 168 |
+
|
| 169 |
+
:returns: posix timestamp in nanoseconds
|
| 170 |
+
:rtype: int
|
| 171 |
+
"""
|
| 172 |
+
return self.seconds * 10**9 + self.nanoseconds
|
| 173 |
+
|
| 174 |
+
def to_datetime(self):
|
| 175 |
+
"""Get the timestamp as a UTC datetime.
|
| 176 |
+
|
| 177 |
+
Python 2 is not supported.
|
| 178 |
+
|
| 179 |
+
:rtype: datetime.
|
| 180 |
+
"""
|
| 181 |
+
return datetime.datetime.fromtimestamp(0, _utc) + datetime.timedelta(
|
| 182 |
+
seconds=self.to_unix()
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
@staticmethod
|
| 186 |
+
def from_datetime(dt):
|
| 187 |
+
"""Create a Timestamp from datetime with t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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fallback pure Python implementation of msgpack"""
|
| 2 |
+
from datetime import datetime as _DateTime
|
| 3 |
+
import sys
|
| 4 |
+
import struct
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
PY2 = sys.version_info[0] == 2
|
| 8 |
+
if PY2:
|
| 9 |
+
int_types = (int, long)
|
| 10 |
+
|
| 11 |
+
def dict_iteritems(d):
|
| 12 |
+
return d.iteritems()
|
| 13 |
+
|
| 14 |
+
else:
|
| 15 |
+
int_types = int
|
| 16 |
+
unicode = str
|
| 17 |
+
xrange = range
|
| 18 |
+
|
| 19 |
+
def dict_iteritems(d):
|
| 20 |
+
return d.items()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
if sys.version_info < (3, 5):
|
| 24 |
+
# Ugly hack...
|
| 25 |
+
RecursionError = RuntimeError
|
| 26 |
+
|
| 27 |
+
def _is_recursionerror(e):
|
| 28 |
+
return (
|
| 29 |
+
len(e.args) == 1
|
| 30 |
+
and isinstance(e.args[0], str)
|
| 31 |
+
and e.args[0].startswith("maximum recursion depth exceeded")
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
else:
|
| 35 |
+
|
| 36 |
+
def _is_recursionerror(e):
|
| 37 |
+
return True
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if hasattr(sys, "pypy_version_info"):
|
| 41 |
+
# StringIO is slow on PyPy, StringIO is faster. However: PyPy's own
|
| 42 |
+
# StringBuilder is fastest.
|
| 43 |
+
from __pypy__ import newlist_hint
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
from __pypy__.builders import BytesBuilder as StringBuilder
|
| 47 |
+
except ImportError:
|
| 48 |
+
from __pypy__.builders import StringBuilder
|
| 49 |
+
USING_STRINGBUILDER = True
|
| 50 |
+
|
| 51 |
+
class StringIO(object):
|
| 52 |
+
def __init__(self, s=b""):
|
| 53 |
+
if s:
|
| 54 |
+
self.builder = StringBuilder(len(s))
|
| 55 |
+
self.builder.append(s)
|
| 56 |
+
else:
|
| 57 |
+
self.builder = StringBuilder()
|
| 58 |
+
|
| 59 |
+
def write(self, s):
|
| 60 |
+
if isinstance(s, memoryview):
|
| 61 |
+
s = s.tobytes()
|
| 62 |
+
elif isinstance(s, bytearray):
|
| 63 |
+
s = bytes(s)
|
| 64 |
+
self.builder.append(s)
|
| 65 |
+
|
| 66 |
+
def getvalue(self):
|
| 67 |
+
return self.builder.build()
|
| 68 |
+
|
| 69 |
+
else:
|
| 70 |
+
USING_STRINGBUILDER = False
|
| 71 |
+
from io import BytesIO as StringIO
|
| 72 |
+
|
| 73 |
+
newlist_hint = lambda size: []
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
from .exceptions import BufferFull, OutOfData, ExtraData, FormatError, StackError
|
| 77 |
+
|
| 78 |
+
from .ext import ExtType, Timestamp
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
EX_SKIP = 0
|
| 82 |
+
EX_CONSTRUCT = 1
|
| 83 |
+
EX_READ_ARRAY_HEADER = 2
|
| 84 |
+
EX_READ_MAP_HEADER = 3
|
| 85 |
+
|
| 86 |
+
TYPE_IMMEDIATE = 0
|
| 87 |
+
TYPE_ARRAY = 1
|
| 88 |
+
TYPE_MAP = 2
|
| 89 |
+
TYPE_RAW = 3
|
| 90 |
+
TYPE_BIN = 4
|
| 91 |
+
TYPE_EXT = 5
|
| 92 |
+
|
| 93 |
+
DEFAULT_RECURSE_LIMIT = 511
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def _check_type_strict(obj, t, type=type, tuple=tuple):
|
| 97 |
+
if type(t) is tuple:
|
| 98 |
+
return type(obj) in t
|
| 99 |
+
else:
|
| 100 |
+
return type(obj) is t
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def _get_data_from_buffer(obj):
|
| 104 |
+
view = memoryview(obj)
|
| 105 |
+
if view.itemsize != 1:
|
| 106 |
+
raise ValueError("cannot unpack from multi-byte object")
|
| 107 |
+
return view
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def unpackb(packed, **kwargs):
|
| 111 |
+
"""
|
| 112 |
+
Unpack an object from `packed`.
|
| 113 |
+
|
| 114 |
+
Raises ``ExtraData`` when *packed* contains extra bytes.
|
| 115 |
+
Raises ``ValueError`` when *packed* is incomplete.
|
| 116 |
+
Raises ``FormatError`` when *packed* is not valid msgpack.
|
| 117 |
+
Raises ``StackError`` when *packed* contains too nested.
|
| 118 |
+
Other exceptions can be raised during unpacking.
|
| 119 |
+
|
| 120 |
+
See :class:`Unpacker` for options.
|
| 121 |
+
"""
|
| 122 |
+
unpacker = Unpacker(None, max_buffer_size=len(packed), **kwargs)
|
| 123 |
+
unpacker.feed(packed)
|
| 124 |
+
try:
|
| 125 |
+
ret = unpacker._unpack()
|
| 126 |
+
except OutOfData:
|
| 127 |
+
raise ValueError("Unpack failed: incomplete input")
|
| 128 |
+
except RecursionError as e:
|
| 129 |
+
if _is_recursionerror(e):
|
| 130 |
+
raise StackError
|
| 131 |
+
raise
|
| 132 |
+
if unpacker._got_extradata():
|
| 133 |
+
raise ExtraData(ret, unpacker._get_extradata())
|
| 134 |
+
return ret
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
if sys.version_info < (2, 7, 6):
|
| 138 |
+
|
| 139 |
+
def _unpack_from(f, b, o=0):
|
| 140 |
+
"""Explicit type cast for legacy struct.unpack_from"""
|
| 141 |
+
return struct.unpack_from(f, bytes(b), o)
|
| 142 |
+
|
| 143 |
+
else:
|
| 144 |
+
_unpack_from = struct.unpack_from
|
| 145 |
+
|
| 146 |
+
_NO_FORMAT_USED = ""
|
| 147 |
+
_MSGPACK_HEADERS = {
|
| 148 |
+
0xC4: (1, _NO_FORMAT_USED, TYPE_BIN),
|
| 149 |
+
0xC5: (2, ">H", TYPE_BIN),
|
| 150 |
+
0xC6: (4, ">I", TYPE_BIN),
|
| 151 |
+
0xC7: (2, "Bb", TYPE_EXT),
|
| 152 |
+
0xC8: (3, ">Hb", TYPE_EXT),
|
| 153 |
+
0xC9: (5, ">Ib", TYPE_EXT),
|
| 154 |
+
0xCA: (4, ">f"),
|
| 155 |
+
0xCB: (8, ">d"),
|
| 156 |
+
0xCC: (1, _NO_FORMAT_USED),
|
| 157 |
+
0xCD: (2, ">H"),
|
| 158 |
+
0xCE: (4, ">I"),
|
| 159 |
+
0xCF: (8, ">Q"),
|
| 160 |
+
0xD0: (1, "b"),
|
| 161 |
+
0xD1: (2, ">h"),
|
| 162 |
+
0xD2: (4, ">i"),
|
| 163 |
+
0xD3: (8, ">q"),
|
| 164 |
+
0xD4: (1, "b1s", TYPE_EXT),
|
| 165 |
+
0xD5: (2, "b2s", TYPE_EXT),
|
| 166 |
+
0xD6: (4, "b4s", TYPE_EXT),
|
| 167 |
+
0xD7: (8, "b8s", TYPE_EXT),
|
| 168 |
+
0xD8: (16, "b16s", TYPE_EXT),
|
| 169 |
+
0xD9: (1, _NO_FORMAT_USED, TYPE_RAW),
|
| 170 |
+
0xDA: (2, ">H", TYPE_RAW),
|
| 171 |
+
0xDB: (4, ">I", TYPE_RAW),
|
| 172 |
+
0xDC: (2, ">H", TYPE_ARRAY),
|
| 173 |
+
0xDD: (4, ">I", TYPE_ARRAY),
|
| 174 |
+
0xDE: (2, ">H", TYPE_MAP),
|
| 175 |
+
0xDF: (4, ">I", TYPE_MAP),
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
class Unpacker(object):
|
| 180 |
+
"""Streaming unpacker.
|
| 181 |
+
|
| 182 |
+
Arguments:
|
| 183 |
+
|
| 184 |
+
:param file_like:
|
| 185 |
+
File-like object having `.read(n)` method.
|
| 186 |
+
If specified, unpacker reads serialized data from it and :meth:`feed()` is not usable.
|
| 187 |
+
|
| 188 |
+
:param int read_size:
|
| 189 |
+
Used as `file_like.read(read_size)`. (default: `min(16*1024, max_buffer_size)`)
|
| 190 |
+
|
| 191 |
+
:param bool use_list:
|
| 192 |
+
If true, unpack msgpack array to Python list.
|
| 193 |
+
Otherwise, unpack to Python tuple. (default: True)
|
| 194 |
+
|
| 195 |
+
:param bool raw:
|
| 196 |
+
If true, unpack msgpack raw to Python bytes.
|
| 197 |
+
Otherwise, unpack to Python str by decoding with UTF-8 encoding (default).
|
| 198 |
+
|
| 199 |
+
:param int timestamp:
|
| 200 |
+
Control how timestamp type is unpacked:
|
| 201 |
+
|
| 202 |
+
0 - Timestamp
|
| 203 |
+
1 - float (Seconds from the EPOCH)
|
| 204 |
+
2 - int (Nanoseconds from the EPOCH)
|
| 205 |
+
3 - datetime.datetime (UTC). Python 2 is not supported.
|
| 206 |
+
|
| 207 |
+
:param bool strict_map_key:
|
| 208 |
+
If true (default), only str or bytes are accepted for map (dict) keys.
|
| 209 |
+
|
| 210 |
+
:param callable object_hook:
|
| 211 |
+
When specified, it should be callable.
|
| 212 |
+
Unpacker calls it with a dict argument after unpacking msgpack map.
|
| 213 |
+
(See also simplejson)
|
| 214 |
+
|
| 215 |
+
:param callable object_pairs_hook:
|
| 216 |
+
When specified, it should be callable.
|
| 217 |
+
Unpacker calls it with a list of key-value pairs after unpacking msgpack map.
|
| 218 |
+
(See also simplejson)
|
| 219 |
+
|
| 220 |
+
:param str unicode_errors:
|
| 221 |
+
The error handler for decoding unicode. (default: 'strict')
|
| 222 |
+
This option should be used only when you have msgpack data which
|
| 223 |
+
contains invalid UTF-8 string.
|
| 224 |
+
|
| 225 |
+
:param int max_buffer_size:
|
| 226 |
+
Limits size of data waiting unpacked. 0 means 2**32-1.
|
| 227 |
+
The default value is 100*1024*1024 (100MiB).
|
| 228 |
+
Raises `BufferFull` exception when it is insufficient.
|
| 229 |
+
You should set this parameter when unpacking data from untrusted source.
|
| 230 |
+
|
| 231 |
+
:param int max_str_len:
|
| 232 |
+
Deprecated, use *max_buffer_size* instead.
|
| 233 |
+
Limits max length of str. (default: max_buffer_size)
|
| 234 |
+
|
| 235 |
+
:param int max_bin_len:
|
| 236 |
+
Deprecated, use *max_buffer_size* instead.
|
| 237 |
+
Limits max length of bin. (default: max_buffer_size)
|
| 238 |
+
|
| 239 |
+
:param int max_array_len:
|
| 240 |
+
Limits max length of array.
|
| 241 |
+
(default: max_buffer_size)
|
| 242 |
+
|
| 243 |
+
:param int max_map_len:
|
| 244 |
+
Limits max length of map.
|
| 245 |
+
(default: max_buffer_size//2)
|
| 246 |
+
|
| 247 |
+
:param int max_ext_len:
|
| 248 |
+
Deprecated, use *max_buffer_size* instead.
|
| 249 |
+
Limits max size of ext type. (default: max_buffer_size)
|
| 250 |
+
|
| 251 |
+
Example of streaming deserialize from file-like object::
|
| 252 |
+
|
| 253 |
+
unpacker = Unpacker(file_like)
|
| 254 |
+
for o in unpacker:
|
| 255 |
+
process(o)
|
| 256 |
+
|
| 257 |
+
Example of streaming deserialize from socket::
|
| 258 |
+
|
| 259 |
+
unpacker = Unpacker()
|
| 260 |
+
while True:
|
| 261 |
+
buf = sock.recv(1024**2)
|
| 262 |
+
if not buf:
|
| 263 |
+
break
|
| 264 |
+
unpacker.feed(buf)
|
| 265 |
+
for o in unpacker:
|
| 266 |
+
process(o)
|
| 267 |
+
|
| 268 |
+
Raises ``ExtraData`` when *packed* contains extra bytes.
|
| 269 |
+
Raises ``OutOfData`` when *packed* is incomplete.
|
| 270 |
+
Raises ``FormatError`` when *packed* is not valid msgpack.
|
| 271 |
+
Raises ``StackError`` when *packed* contains too nested.
|
| 272 |
+
Other exceptions can be raised during unpacking.
|
| 273 |
+
"""
|
| 274 |
+
|
| 275 |
+
def __init__(
|
| 276 |
+
self,
|
| 277 |
+
file_like=None,
|
| 278 |
+
read_size=0,
|
| 279 |
+
use_list=True,
|
| 280 |
+
raw=False,
|
| 281 |
+
timestamp=0,
|
| 282 |
+
strict_map_key=True,
|
| 283 |
+
object_hook=None,
|
| 284 |
+
object_pairs_hook=None,
|
| 285 |
+
list_hook=None,
|
| 286 |
+
unicode_errors=None,
|
| 287 |
+
max_buffer_size=100 * 1024 * 1024,
|
| 288 |
+
ext_hook=ExtType,
|
| 289 |
+
max_str_len=-1,
|
| 290 |
+
max_bin_len=-1,
|
| 291 |
+
max_array_len=-1,
|
| 292 |
+
max_map_len=-1,
|
| 293 |
+
max_ext_len=-1,
|
| 294 |
+
):
|
| 295 |
+
if unicode_errors is None:
|
| 296 |
+
unicode_errors = "strict"
|
| 297 |
+
|
| 298 |
+
if file_like is None:
|
| 299 |
+
self._feeding = True
|
| 300 |
+
else:
|
| 301 |
+
if not callable(file_like.read):
|
| 302 |
+
raise TypeError("`file_like.read` must be callable")
|
| 303 |
+
self.file_like = file_like
|
| 304 |
+
self._feeding = False
|
| 305 |
+
|
| 306 |
+
#: array of bytes fed.
|
| 307 |
+
self._buffer = bytearray()
|
| 308 |
+
#: Which position we currently reads
|
| 309 |
+
self._buff_i = 0
|
| 310 |
+
|
| 311 |
+
# When Unpacker is used as an iterable, between the calls to next(),
|
| 312 |
+
# the buffer is not "consumed" completely, for efficiency sake.
|
| 313 |
+
# Instead, it is done sloppily. To make sure we raise BufferFull at
|
| 314 |
+
# the correct moments, we have to keep track of how sloppy we were.
|
| 315 |
+
# Furthermore, when the buffer is incomplete (that is: in the case
|
| 316 |
+
# we raise an OutOfData) we need to rollback the buffer to the correct
|
| 317 |
+
# state, which _buf_checkpoint records.
|
| 318 |
+
self._buf_checkpoint = 0
|
| 319 |
+
|
| 320 |
+
if not max_buffer_size:
|
| 321 |
+
max_buffer_size = 2**31 - 1
|
| 322 |
+
if max_str_len == -1:
|
| 323 |
+
max_str_len = max_buffer_size
|
| 324 |
+
if max_bin_len == -1:
|
| 325 |
+
max_bin_len = max_buffer_size
|
| 326 |
+
if max_array_len == -1:
|
| 327 |
+
max_array_len = max_buffer_size
|
| 328 |
+
if max_map_len == -1:
|
| 329 |
+
max_map_len = max_buffer_size // 2
|
| 330 |
+
if max_ext_len == -1:
|
| 331 |
+
max_ext_len = max_buffer_size
|
| 332 |
+
|
| 333 |
+
self._max_buffer_size = max_buffer_size
|
| 334 |
+
if read_size > self._max_buffer_size:
|
| 335 |
+
raise ValueError("read_size must be smaller than max_buffer_size")
|
| 336 |
+
self._read_size = read_size or min(self._max_buffer_size, 16 * 1024)
|
| 337 |
+
self._raw = bool(raw)
|
| 338 |
+
self._strict_map_key = bool(strict_map_key)
|
| 339 |
+
self._unicode_errors = unicode_errors
|
| 340 |
+
self._use_list = use_list
|
| 341 |
+
if not (0 <= timestamp <= 3):
|
| 342 |
+
raise ValueError("timestamp must be 0..3")
|
| 343 |
+
self._timestamp = timestamp
|
| 344 |
+
self._list_hook = list_hook
|
| 345 |
+
self._object_hook = object_hook
|
| 346 |
+
self._object_pairs_hook = object_pairs_hook
|
| 347 |
+
self._ext_hook = ext_hook
|
| 348 |
+
self._max_str_len = max_str_len
|
| 349 |
+
self._max_bin_len = max_bin_len
|
| 350 |
+
self._max_array_len = max_array_len
|
| 351 |
+
self._max_map_len = max_map_len
|
| 352 |
+
self._max_ext_len = max_ext_len
|
| 353 |
+
self._stream_offset = 0
|
| 354 |
+
|
| 355 |
+
if list_hook is not None and not callable(list_hook):
|
| 356 |
+
raise TypeError("`list_hook` is not callable")
|
| 357 |
+
if object_hook is not None and not callable(object_hook):
|
| 358 |
+
raise TypeError("`object_hook` is not callable")
|
| 359 |
+
if object_pairs_hook is not None and not callable(object_pairs_hook):
|
| 360 |
+
raise TypeError("`object_pairs_hook` is not callable")
|
| 361 |
+
if object_hook is not None and object_pairs_hook is not None:
|
| 362 |
+
raise TypeError(
|
| 363 |
+
"object_pairs_hook and object_hook are mutually " "exclusive"
|
| 364 |
+
)
|
| 365 |
+
if not callable(ext_hook):
|
| 366 |
+
raise TypeError("`ext_hook` is not callable")
|
| 367 |
+
|
| 368 |
+
def feed(self, next_bytes):
|
| 369 |
+
assert self._feeding
|
| 370 |
+
view = _get_data_from_buffer(next_bytes)
|
| 371 |
+
if len(self._buffer) - self._buff_i + len(view) > self._max_buffer_size:
|
| 372 |
+
raise BufferFull
|
| 373 |
+
|
| 374 |
+
# Strip buffer before checkpoint before reading file.
|
| 375 |
+
if self._buf_checkpoint > 0:
|
| 376 |
+
del self._buffer[: self._buf_checkpoint]
|
| 377 |
+
self._buff_i -= self._buf_checkpoint
|
| 378 |
+
self._buf_checkpoint = 0
|
| 379 |
+
|
| 380 |
+
# Use extend here: INPLACE_ADD += doesn't reliably typecast memoryview in jython
|
| 381 |
+
self._buffer.extend(view)
|
| 382 |
+
|
| 383 |
+
def _consume(self):
|
| 384 |
+
"""Gets rid of the used parts of the buffer."""
|
| 385 |
+
self._stream_offset += self._buff_i - self._buf_checkpoint
|
| 386 |
+
self._buf_checkpoint = self._buff_i
|
| 387 |
+
|
| 388 |
+
def _got_extradata(self):
|
| 389 |
+
return self._buff_i < len(self._buffer)
|
| 390 |
+
|
| 391 |
+
def _get_extradata(self):
|
| 392 |
+
return self._buffer[self._buff_i :]
|
| 393 |
+
|
| 394 |
+
def read_bytes(self, n):
|
| 395 |
+
ret = self._read(n, raise_outofdata=False)
|
| 396 |
+
self._consume()
|
| 397 |
+
return ret
|
| 398 |
+
|
| 399 |
+
def _read(self, n, raise_outofdata=True):
|
| 400 |
+
# (int) -> bytearray
|
| 401 |
+
self._reserve(n, raise_outofdata=raise_outofdata)
|
| 402 |
+
i = self._buff_i
|
| 403 |
+
ret = self._buffer[i : i + n]
|
| 404 |
+
self._buff_i = i + len(ret)
|
| 405 |
+
return ret
|
| 406 |
+
|
| 407 |
+
def _reserve(self, n, raise_outofdata=True):
|
| 408 |
+
remain_bytes = len(self._buffer) - self._buff_i - n
|
| 409 |
+
|
| 410 |
+
# Fast path: buffer has n bytes already
|
| 411 |
+
if remain_bytes >= 0:
|
| 412 |
+
return
|
| 413 |
+
|
| 414 |
+
if self._feeding:
|
| 415 |
+
self._buff_i = self._buf_checkpoint
|
| 416 |
+
raise OutOfData
|
| 417 |
+
|
| 418 |
+
# Strip buffer before checkpoint before reading file.
|
| 419 |
+
if self._buf_checkpoint > 0:
|
| 420 |
+
del self._buffer[: self._buf_checkpoint]
|
| 421 |
+
self._buff_i -= self._buf_checkpoint
|
| 422 |
+
self._buf_checkpoint = 0
|
| 423 |
+
|
| 424 |
+
# Read from file
|
| 425 |
+
remain_bytes = -remain_bytes
|
| 426 |
+
if remain_bytes + len(self._buffer) > self._max_buffer_size:
|
| 427 |
+
raise BufferFull
|
| 428 |
+
while remain_bytes > 0:
|
| 429 |
+
to_read_bytes = max(self._read_size, remain_bytes)
|
| 430 |
+
read_data = self.file_like.read(to_read_bytes)
|
| 431 |
+
if not read_data:
|
| 432 |
+
break
|
| 433 |
+
assert isinstance(read_data, bytes)
|
| 434 |
+
self._buffer += read_data
|
| 435 |
+
remain_bytes -= len(read_data)
|
| 436 |
+
|
| 437 |
+
if len(self._buffer) < n + self._buff_i and raise_outofdata:
|
| 438 |
+
self._buff_i = 0 # rollback
|
| 439 |
+
raise OutOfData
|
| 440 |
+
|
| 441 |
+
def _read_header(self):
|
| 442 |
+
typ = TYPE_IMMEDIATE
|
| 443 |
+
n = 0
|
| 444 |
+
obj = None
|
| 445 |
+
self._reserve(1)
|
| 446 |
+
b = self._buffer[self._buff_i]
|
| 447 |
+
self._buff_i += 1
|
| 448 |
+
if b & 0b10000000 == 0:
|
| 449 |
+
obj = b
|
| 450 |
+
elif b & 0b11100000 == 0b11100000:
|
| 451 |
+
obj = -1 - (b ^ 0xFF)
|
| 452 |
+
elif b & 0b11100000 == 0b10100000:
|
| 453 |
+
n = b & 0b00011111
|
| 454 |
+
typ = TYPE_RAW
|
| 455 |
+
if n > self._max_str_len:
|
| 456 |
+
raise ValueError("%s exceeds max_str_len(%s)" % (n, self._max_str_len))
|
| 457 |
+
obj = self._read(n)
|
| 458 |
+
elif b & 0b11110000 == 0b10010000:
|
| 459 |
+
n = b & 0b00001111
|
| 460 |
+
typ = TYPE_ARRAY
|
| 461 |
+
if n > self._max_array_len:
|
| 462 |
+
raise ValueError(
|
| 463 |
+
"%s exceeds max_array_len(%s)" % (n, self._max_array_len)
|
| 464 |
+
)
|
| 465 |
+
elif b & 0b11110000 == 0b10000000:
|
| 466 |
+
n = b & 0b00001111
|
| 467 |
+
typ = TYPE_MAP
|
| 468 |
+
if n > self._max_map_len:
|
| 469 |
+
raise ValueError("%s exceeds max_map_len(%s)" % (n, self._max_map_len))
|
| 470 |
+
elif b == 0xC0:
|
| 471 |
+
obj = None
|
| 472 |
+
elif b == 0xC2:
|
| 473 |
+
obj = False
|
| 474 |
+
elif b == 0xC3:
|
| 475 |
+
obj = True
|
| 476 |
+
elif 0xC4 <= b <= 0xC6:
|
| 477 |
+
size, fmt, typ = _MSGPACK_HEADERS[b]
|
| 478 |
+
self._reserve(size)
|
| 479 |
+
if len(fmt) > 0:
|
| 480 |
+
n = _unpack_from(fmt, self._buffer, self._buff_i)[0]
|
| 481 |
+
else:
|
| 482 |
+
n = self._buffer[self._buff_i]
|
| 483 |
+
self._buff_i += size
|
| 484 |
+
if n > self._max_bin_len:
|
| 485 |
+
raise ValueError("%s exceeds max_bin_len(%s)" % (n, self._max_bin_len))
|
| 486 |
+
obj = self._read(n)
|
| 487 |
+
elif 0xC7 <= b <= 0xC9:
|
| 488 |
+
size, fmt, typ = _MSGPACK_HEADERS[b]
|
| 489 |
+
self._reserve(size)
|
| 490 |
+
L, n = _unpack_from(fmt, self._buffer, self._buff_i)
|
| 491 |
+
self._buff_i += size
|
| 492 |
+
if L > self._max_ext_len:
|
| 493 |
+
raise ValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len))
|
| 494 |
+
obj = self._read(L)
|
| 495 |
+
elif 0xCA <= b <= 0xD3:
|
| 496 |
+
size, fmt = _MSGPACK_HEADERS[b]
|
| 497 |
+
self._reserve(size)
|
| 498 |
+
if len(fmt) > 0:
|
| 499 |
+
obj = _unpack_from(fmt, self._buffer, self._buff_i)[0]
|
| 500 |
+
else:
|
| 501 |
+
obj = self._buffer[self._buff_i]
|
| 502 |
+
self._buff_i += size
|
| 503 |
+
elif 0xD4 <= b <= 0xD8:
|
| 504 |
+
size, fmt, typ = _MSGPACK_HEADERS[b]
|
| 505 |
+
if self._max_ext_len < size:
|
| 506 |
+
raise ValueError(
|
| 507 |
+
"%s exceeds max_ext_len(%s)" % (size, self._max_ext_len)
|
| 508 |
+
)
|
| 509 |
+
self._reserve(size + 1)
|
| 510 |
+
n, obj = _unpack_from(fmt, self._buffer, self._buff_i)
|
| 511 |
+
self._buff_i += size + 1
|
| 512 |
+
elif 0xD9 <= b <= 0xDB:
|
| 513 |
+
size, fmt, typ = _MSGPACK_HEADERS[b]
|
| 514 |
+
self._reserve(size)
|
| 515 |
+
if len(fmt) > 0:
|
| 516 |
+
(n,) = _unpack_from(fmt, self._buffer, self._buff_i)
|
| 517 |
+
else:
|
| 518 |
+
n = self._buffer[self._buff_i]
|
| 519 |
+
self._buff_i += size
|
| 520 |
+
if n > self._max_str_len:
|
| 521 |
+
raise ValueError("%s exceeds max_str_len(%s)" % (n, self._max_str_len))
|
| 522 |
+
obj = self._read(n)
|
| 523 |
+
elif 0xDC <= b <= 0xDD:
|
| 524 |
+
size, fmt, typ = _MSGPACK_HEADERS[b]
|
| 525 |
+
self._reserve(size)
|
| 526 |
+
(n,) = _unpack_from(fmt, self._buffer, self._buff_i)
|
| 527 |
+
self._buff_i += size
|
| 528 |
+
if n > self._max_array_len:
|
| 529 |
+
raise ValueError(
|
| 530 |
+
"%s exceeds max_array_len(%s)" % (n, self._max_array_len)
|
| 531 |
+
)
|
| 532 |
+
elif 0xDE <= b <= 0xDF:
|
| 533 |
+
size, fmt, typ = _MSGPACK_HEADERS[b]
|
| 534 |
+
self._reserve(size)
|
| 535 |
+
(n,) = _unpack_from(fmt, self._buffer, self._buff_i)
|
| 536 |
+
self._buff_i += size
|
| 537 |
+
if n > self._max_map_len:
|
| 538 |
+
raise ValueError("%s exceeds max_map_len(%s)" % (n, self._max_map_len))
|
| 539 |
+
else:
|
| 540 |
+
raise FormatError("Unknown header: 0x%x" % b)
|
| 541 |
+
return typ, n, obj
|
| 542 |
+
|
| 543 |
+
def _unpack(self, execute=EX_CONSTRUCT):
|
| 544 |
+
typ, n, obj = self._read_header()
|
| 545 |
+
|
| 546 |
+
if execute == EX_READ_ARRAY_HEADER:
|
| 547 |
+
if typ != TYPE_ARRAY:
|
| 548 |
+
raise ValueError("Expected array")
|
| 549 |
+
return n
|
| 550 |
+
if execute == EX_READ_MAP_HEADER:
|
| 551 |
+
if typ != TYPE_MAP:
|
| 552 |
+
raise ValueError("Expected map")
|
| 553 |
+
return n
|
| 554 |
+
# TODO should we eliminate the recursion?
|
| 555 |
+
if typ == TYPE_ARRAY:
|
| 556 |
+
if execute == EX_SKIP:
|
| 557 |
+
for i in xrange(n):
|
| 558 |
+
# TODO check whether we need to call `list_hook`
|
| 559 |
+
self._unpack(EX_SKIP)
|
| 560 |
+
return
|
| 561 |
+
ret = newlist_hint(n)
|
| 562 |
+
for i in xrange(n):
|
| 563 |
+
ret.append(self._unpack(EX_CONSTRUCT))
|
| 564 |
+
if self._list_hook is not None:
|
| 565 |
+
ret = self._list_hook(ret)
|
| 566 |
+
# TODO is the interaction between `list_hook` and `use_list` ok?
|
| 567 |
+
return ret if self._use_list else tuple(ret)
|
| 568 |
+
if typ == TYPE_MAP:
|
| 569 |
+
if execute == EX_SKIP:
|
| 570 |
+
for i in xrange(n):
|
| 571 |
+
# TODO check whether we need to call hooks
|
| 572 |
+
self._unpack(EX_SKIP)
|
| 573 |
+
self._unpack(EX_SKIP)
|
| 574 |
+
return
|
| 575 |
+
if self._object_pairs_hook is not None:
|
| 576 |
+
ret = self._object_pairs_hook(
|
| 577 |
+
(self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT))
|
| 578 |
+
for _ in xrange(n)
|
| 579 |
+
)
|
| 580 |
+
else:
|
| 581 |
+
ret = {}
|
| 582 |
+
for _ in xrange(n):
|
| 583 |
+
key = self._unpack(EX_CONSTRUCT)
|
| 584 |
+
if self._strict_map_key and type(key) not in (unicode, bytes):
|
| 585 |
+
raise ValueError(
|
| 586 |
+
"%s is not allowed for map key" % str(type(key))
|
| 587 |
+
)
|
| 588 |
+
if not PY2 and type(key) is str:
|
| 589 |
+
key = sys.intern(key)
|
| 590 |
+
ret[key] = self._unpack(EX_CONSTRUCT)
|
| 591 |
+
if self._object_hook is not None:
|
| 592 |
+
ret = self._object_hook(ret)
|
| 593 |
+
return ret
|
| 594 |
+
if execute == EX_SKIP:
|
| 595 |
+
return
|
| 596 |
+
if typ == TYPE_RAW:
|
| 597 |
+
if self._raw:
|
| 598 |
+
obj = bytes(obj)
|
| 599 |
+
else:
|
| 600 |
+
obj = obj.decode("utf_8", self._unicode_errors)
|
| 601 |
+
return obj
|
| 602 |
+
if typ == TYPE_BIN:
|
| 603 |
+
return bytes(obj)
|
| 604 |
+
if typ == TYPE_EXT:
|
| 605 |
+
if n == -1: # timestamp
|
| 606 |
+
ts = Timestamp.from_bytes(bytes(obj))
|
| 607 |
+
if self._timestamp == 1:
|
| 608 |
+
return ts.to_unix()
|
| 609 |
+
elif self._timestamp == 2:
|
| 610 |
+
return ts.to_unix_nano()
|
| 611 |
+
elif self._timestamp == 3:
|
| 612 |
+
return ts.to_datetime()
|
| 613 |
+
else:
|
| 614 |
+
return ts
|
| 615 |
+
else:
|
| 616 |
+
return self._ext_hook(n, bytes(obj))
|
| 617 |
+
assert typ == TYPE_IMMEDIATE
|
| 618 |
+
return obj
|
| 619 |
+
|
| 620 |
+
def __iter__(self):
|
| 621 |
+
return self
|
| 622 |
+
|
| 623 |
+
def __next__(self):
|
| 624 |
+
try:
|
| 625 |
+
ret = self._unpack(EX_CONSTRUCT)
|
| 626 |
+
self._consume()
|
| 627 |
+
return ret
|
| 628 |
+
except OutOfData:
|
| 629 |
+
self._consume()
|
| 630 |
+
raise StopIteration
|
| 631 |
+
except RecursionError:
|
| 632 |
+
raise StackError
|
| 633 |
+
|
| 634 |
+
next = __next__
|
| 635 |
+
|
| 636 |
+
def skip(self):
|
| 637 |
+
self._unpack(EX_SKIP)
|
| 638 |
+
self._consume()
|
| 639 |
+
|
| 640 |
+
def unpack(self):
|
| 641 |
+
try:
|
| 642 |
+
ret = self._unpack(EX_CONSTRUCT)
|
| 643 |
+
except RecursionError:
|
| 644 |
+
raise StackError
|
| 645 |
+
self._consume()
|
| 646 |
+
return ret
|
| 647 |
+
|
| 648 |
+
def read_array_header(self):
|
| 649 |
+
ret = self._unpack(EX_READ_ARRAY_HEADER)
|
| 650 |
+
self._consume()
|
| 651 |
+
return ret
|
| 652 |
+
|
| 653 |
+
def read_map_header(self):
|
| 654 |
+
ret = self._unpack(EX_READ_MAP_HEADER)
|
| 655 |
+
self._consume()
|
| 656 |
+
return ret
|
| 657 |
+
|
| 658 |
+
def tell(self):
|
| 659 |
+
return self._stream_offset
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
class Packer(object):
|
| 663 |
+
"""
|
| 664 |
+
MessagePack Packer
|
| 665 |
+
|
| 666 |
+
Usage::
|
| 667 |
+
|
| 668 |
+
packer = Packer()
|
| 669 |
+
astream.write(packer.pack(a))
|
| 670 |
+
astream.write(packer.pack(b))
|
| 671 |
+
|
| 672 |
+
Packer's constructor has some keyword arguments:
|
| 673 |
+
|
| 674 |
+
:param callable default:
|
| 675 |
+
Convert user type to builtin type that Packer supports.
|
| 676 |
+
See also simplejson's document.
|
| 677 |
+
|
| 678 |
+
:param bool use_single_float:
|
| 679 |
+
Use single precision float type for float. (default: False)
|
| 680 |
+
|
| 681 |
+
:param bool autoreset:
|
| 682 |
+
Reset buffer after each pack and return its content as `bytes`. (default: True).
|
| 683 |
+
If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
|
| 684 |
+
|
| 685 |
+
:param bool use_bin_type:
|
| 686 |
+
Use bin type introduced in msgpack spec 2.0 for bytes.
|
| 687 |
+
It also enables str8 type for unicode. (default: True)
|
| 688 |
+
|
| 689 |
+
:param bool strict_types:
|
| 690 |
+
If set to true, types will be checked to be exact. Derived classes
|
| 691 |
+
from serializable types will not be serialized and will be
|
| 692 |
+
treated as unsupported type and forwarded to default.
|
| 693 |
+
Additionally tuples will not be serialized as lists.
|
| 694 |
+
This is useful when trying to implement accurate serialization
|
| 695 |
+
for python types.
|
| 696 |
+
|
| 697 |
+
:param bool datetime:
|
| 698 |
+
If set to true, datetime with tzinfo is packed into Timestamp type.
|
| 699 |
+
Note that the tzinfo is stripped in the timestamp.
|
| 700 |
+
You can get UTC datetime with `timestamp=3` option of the Unpacker.
|
| 701 |
+
(Python 2 is not supported).
|
| 702 |
+
|
| 703 |
+
:param str unicode_errors:
|
| 704 |
+
The error handler for encoding unicode. (default: 'strict')
|
| 705 |
+
DO NOT USE THIS!! This option is kept for very specific usage.
|
| 706 |
+
|
| 707 |
+
Example of streaming deserialize from file-like object::
|
| 708 |
+
|
| 709 |
+
unpacker = Unpacker(file_like)
|
| 710 |
+
for o in unpacker:
|
| 711 |
+
process(o)
|
| 712 |
+
|
| 713 |
+
Example of streaming deserialize from socket::
|
| 714 |
+
|
| 715 |
+
unpacker = Unpacker()
|
| 716 |
+
while True:
|
| 717 |
+
buf = sock.recv(1024**2)
|
| 718 |
+
if not buf:
|
| 719 |
+
break
|
| 720 |
+
unpacker.feed(buf)
|
| 721 |
+
for o in unpacker:
|
| 722 |
+
process(o)
|
| 723 |
+
|
| 724 |
+
Raises ``ExtraData`` when *packed* contains extra bytes.
|
| 725 |
+
Raises ``OutOfData`` when *packed* is incomplete.
|
| 726 |
+
Raises ``FormatError`` when *packed* is not valid msgpack.
|
| 727 |
+
Raises ``StackError`` when *packed* contains too nested.
|
| 728 |
+
Other exceptions can be raised during unpacking.
|
| 729 |
+
"""
|
| 730 |
+
|
| 731 |
+
def __init__(
|
| 732 |
+
self,
|
| 733 |
+
default=None,
|
| 734 |
+
use_single_float=False,
|
| 735 |
+
autoreset=True,
|
| 736 |
+
use_bin_type=True,
|
| 737 |
+
strict_types=False,
|
| 738 |
+
datetime=False,
|
| 739 |
+
unicode_errors=None,
|
| 740 |
+
):
|
| 741 |
+
self._strict_types = strict_types
|
| 742 |
+
self._use_float = use_single_float
|
| 743 |
+
self._autoreset = autoreset
|
| 744 |
+
self._use_bin_type = use_bin_type
|
| 745 |
+
self._buffer = StringIO()
|
| 746 |
+
if PY2 and datetime:
|
| 747 |
+
raise ValueError("datetime is not supported in Python 2")
|
| 748 |
+
self._datetime = bool(datetime)
|
| 749 |
+
self._unicode_errors = unicode_errors or "strict"
|
| 750 |
+
if default is not None:
|
| 751 |
+
if not callable(default):
|
| 752 |
+
raise TypeError("default must be callable")
|
| 753 |
+
self._default = default
|
| 754 |
+
|
| 755 |
+
def _pack(
|
| 756 |
+
self,
|
| 757 |
+
obj,
|
| 758 |
+
nest_limit=DEFAULT_RECURSE_LIMIT,
|
| 759 |
+
check=isinstance,
|
| 760 |
+
check_type_strict=_check_type_strict,
|
| 761 |
+
):
|
| 762 |
+
default_used = False
|
| 763 |
+
if self._strict_types:
|
| 764 |
+
check = check_type_strict
|
| 765 |
+
list_types = list
|
| 766 |
+
else:
|
| 767 |
+
list_types = (list, tuple)
|
| 768 |
+
while True:
|
| 769 |
+
if nest_limit < 0:
|
| 770 |
+
raise ValueError("recursion limit exceeded")
|
| 771 |
+
if obj is None:
|
| 772 |
+
return self._buffer.write(b"\xc0")
|
| 773 |
+
if check(obj, bool):
|
| 774 |
+
if obj:
|
| 775 |
+
return self._buffer.write(b"\xc3")
|
| 776 |
+
return self._buffer.write(b"\xc2")
|
| 777 |
+
if check(obj, int_types):
|
| 778 |
+
if 0 <= obj < 0x80:
|
| 779 |
+
return self._buffer.write(struct.pack("B", obj))
|
| 780 |
+
if -0x20 <= obj < 0:
|
| 781 |
+
return self._buffer.write(struct.pack("b", obj))
|
| 782 |
+
if 0x80 <= obj <= 0xFF:
|
| 783 |
+
return self._buffer.write(struct.pack("BB", 0xCC, obj))
|
| 784 |
+
if -0x80 <= obj < 0:
|
| 785 |
+
return self._buffer.write(struct.pack(">Bb", 0xD0, obj))
|
| 786 |
+
if 0xFF < obj <= 0xFFFF:
|
| 787 |
+
return self._buffer.write(struct.pack(">BH", 0xCD, obj))
|
| 788 |
+
if -0x8000 <= obj < -0x80:
|
| 789 |
+
return self._buffer.write(struct.pack(">Bh", 0xD1, obj))
|
| 790 |
+
if 0xFFFF < obj <= 0xFFFFFFFF:
|
| 791 |
+
return self._buffer.write(struct.pack(">BI", 0xCE, obj))
|
| 792 |
+
if -0x80000000 <= obj < -0x8000:
|
| 793 |
+
return self._buffer.write(struct.pack(">Bi", 0xD2, obj))
|
| 794 |
+
if 0xFFFFFFFF < obj <= 0xFFFFFFFFFFFFFFFF:
|
| 795 |
+
return self._buffer.write(struct.pack(">BQ", 0xCF, obj))
|
| 796 |
+
if -0x8000000000000000 <= obj < -0x80000000:
|
| 797 |
+
return self._buffer.write(struct.pack(">Bq", 0xD3, obj))
|
| 798 |
+
if not default_used and self._default is not None:
|
| 799 |
+
obj = self._default(obj)
|
| 800 |
+
default_used = True
|
| 801 |
+
continue
|
| 802 |
+
raise OverflowError("Integer value out of range")
|
| 803 |
+
if check(obj, (bytes, bytearray)):
|
| 804 |
+
n = len(obj)
|
| 805 |
+
if n >= 2**32:
|
| 806 |
+
raise ValueError("%s is too large" % type(obj).__name__)
|
| 807 |
+
self._pack_bin_header(n)
|
| 808 |
+
return self._buffer.write(obj)
|
| 809 |
+
if check(obj, unicode):
|
| 810 |
+
obj = obj.encode("utf-8", self._unicode_errors)
|
| 811 |
+
n = len(obj)
|
| 812 |
+
if n >= 2**32:
|
| 813 |
+
raise ValueError("String is too large")
|
| 814 |
+
self._pack_raw_header(n)
|
| 815 |
+
return self._buffer.write(obj)
|
| 816 |
+
if check(obj, memoryview):
|
| 817 |
+
n = obj.nbytes
|
| 818 |
+
if n >= 2**32:
|
| 819 |
+
raise ValueError("Memoryview is too large")
|
| 820 |
+
self._pack_bin_header(n)
|
| 821 |
+
return self._buffer.write(obj)
|
| 822 |
+
if check(obj, float):
|
| 823 |
+
if self._use_float:
|
| 824 |
+
return self._buffer.write(struct.pack(">Bf", 0xCA, obj))
|
| 825 |
+
return self._buffer.write(struct.pack(">Bd", 0xCB, obj))
|
| 826 |
+
if check(obj, (ExtType, Timestamp)):
|
| 827 |
+
if check(obj, Timestamp):
|
| 828 |
+
code = -1
|
| 829 |
+
data = obj.to_bytes()
|
| 830 |
+
else:
|
| 831 |
+
code = obj.code
|
| 832 |
+
data = obj.data
|
| 833 |
+
assert isinstance(code, int)
|
| 834 |
+
assert isinstance(data, bytes)
|
| 835 |
+
L = len(data)
|
| 836 |
+
if L == 1:
|
| 837 |
+
self._buffer.write(b"\xd4")
|
| 838 |
+
elif L == 2:
|
| 839 |
+
self._buffer.write(b"\xd5")
|
| 840 |
+
elif L == 4:
|
| 841 |
+
self._buffer.write(b"\xd6")
|
| 842 |
+
elif L == 8:
|
| 843 |
+
self._buffer.write(b"\xd7")
|
| 844 |
+
elif L == 16:
|
| 845 |
+
self._buffer.write(b"\xd8")
|
| 846 |
+
elif L <= 0xFF:
|
| 847 |
+
self._buffer.write(struct.pack(">BB", 0xC7, L))
|
| 848 |
+
elif L <= 0xFFFF:
|
| 849 |
+
self._buffer.write(struct.pack(">BH", 0xC8, L))
|
| 850 |
+
else:
|
| 851 |
+
self._buffer.write(struct.pack(">BI", 0xC9, L))
|
| 852 |
+
self._buffer.write(struct.pack("b", code))
|
| 853 |
+
self._buffer.write(data)
|
| 854 |
+
return
|
| 855 |
+
if check(obj, list_types):
|
| 856 |
+
n = len(obj)
|
| 857 |
+
self._pack_array_header(n)
|
| 858 |
+
for i in xrange(n):
|
| 859 |
+
self._pack(obj[i], nest_limit - 1)
|
| 860 |
+
return
|
| 861 |
+
if check(obj, dict):
|
| 862 |
+
return self._pack_map_pairs(
|
| 863 |
+
len(obj), dict_iteritems(obj), nest_limit - 1
|
| 864 |
+
)
|
| 865 |
+
|
| 866 |
+
if self._datetime and check(obj, _DateTime) and obj.tzinfo is not None:
|
| 867 |
+
obj = Timestamp.from_datetime(obj)
|
| 868 |
+
default_used = 1
|
| 869 |
+
continue
|
| 870 |
+
|
| 871 |
+
if not default_used and self._default is not None:
|
| 872 |
+
obj = self._default(obj)
|
| 873 |
+
default_used = 1
|
| 874 |
+
continue
|
| 875 |
+
|
| 876 |
+
if self._datetime and check(obj, _DateTime):
|
| 877 |
+
raise ValueError("Cannot serialize %r where tzinfo=None" % (obj,))
|
| 878 |
+
|
| 879 |
+
raise TypeError("Cannot serialize %r" % (obj,))
|
| 880 |
+
|
| 881 |
+
def pack(self, obj):
|
| 882 |
+
try:
|
| 883 |
+
self._pack(obj)
|
| 884 |
+
except:
|
| 885 |
+
self._buffer = StringIO() # force reset
|
| 886 |
+
raise
|
| 887 |
+
if self._autoreset:
|
| 888 |
+
ret = self._buffer.getvalue()
|
| 889 |
+
self._buffer = StringIO()
|
| 890 |
+
return ret
|
| 891 |
+
|
| 892 |
+
def pack_map_pairs(self, pairs):
|
| 893 |
+
self._pack_map_pairs(len(pairs), pairs)
|
| 894 |
+
if self._autoreset:
|
| 895 |
+
ret = self._buffer.getvalue()
|
| 896 |
+
self._buffer = StringIO()
|
| 897 |
+
return ret
|
| 898 |
+
|
| 899 |
+
def pack_array_header(self, n):
|
| 900 |
+
if n >= 2**32:
|
| 901 |
+
raise ValueError
|
| 902 |
+
self._pack_array_header(n)
|
| 903 |
+
if self._autoreset:
|
| 904 |
+
ret = self._buffer.getvalue()
|
| 905 |
+
self._buffer = StringIO()
|
| 906 |
+
return ret
|
| 907 |
+
|
| 908 |
+
def pack_map_header(self, n):
|
| 909 |
+
if n >= 2**32:
|
| 910 |
+
raise ValueError
|
| 911 |
+
self._pack_map_header(n)
|
| 912 |
+
if self._autoreset:
|
| 913 |
+
ret = self._buffer.getvalue()
|
| 914 |
+
self._buffer = StringIO()
|
| 915 |
+
return ret
|
| 916 |
+
|
| 917 |
+
def pack_ext_type(self, typecode, data):
|
| 918 |
+
if not isinstance(typecode, int):
|
| 919 |
+
raise TypeError("typecode must have int type.")
|
| 920 |
+
if not 0 <= typecode <= 127:
|
| 921 |
+
raise ValueError("typecode should be 0-127")
|
| 922 |
+
if not isinstance(data, bytes):
|
| 923 |
+
raise TypeError("data must have bytes type")
|
| 924 |
+
L = len(data)
|
| 925 |
+
if L > 0xFFFFFFFF:
|
| 926 |
+
raise ValueError("Too large data")
|
| 927 |
+
if L == 1:
|
| 928 |
+
self._buffer.write(b"\xd4")
|
| 929 |
+
elif L == 2:
|
| 930 |
+
self._buffer.write(b"\xd5")
|
| 931 |
+
elif L == 4:
|
| 932 |
+
self._buffer.write(b"\xd6")
|
| 933 |
+
elif L == 8:
|
| 934 |
+
self._buffer.write(b"\xd7")
|
| 935 |
+
elif L == 16:
|
| 936 |
+
self._buffer.write(b"\xd8")
|
| 937 |
+
elif L <= 0xFF:
|
| 938 |
+
self._buffer.write(b"\xc7" + struct.pack("B", L))
|
| 939 |
+
elif L <= 0xFFFF:
|
| 940 |
+
self._buffer.write(b"\xc8" + struct.pack(">H", L))
|
| 941 |
+
else:
|
| 942 |
+
self._buffer.write(b"\xc9" + struct.pack(">I", L))
|
| 943 |
+
self._buffer.write(struct.pack("B", typecode))
|
| 944 |
+
self._buffer.write(data)
|
| 945 |
+
|
| 946 |
+
def _pack_array_header(self, n):
|
| 947 |
+
if n <= 0x0F:
|
| 948 |
+
return self._buffer.write(struct.pack("B", 0x90 + n))
|
| 949 |
+
if n <= 0xFFFF:
|
| 950 |
+
return self._buffer.write(struct.pack(">BH", 0xDC, n))
|
| 951 |
+
if n <= 0xFFFFFFFF:
|
| 952 |
+
return self._buffer.write(struct.pack(">BI", 0xDD, n))
|
| 953 |
+
raise ValueError("Array is too large")
|
| 954 |
+
|
| 955 |
+
def _pack_map_header(self, n):
|
| 956 |
+
if n <= 0x0F:
|
| 957 |
+
return self._buffer.write(struct.pack("B", 0x80 + n))
|
| 958 |
+
if n <= 0xFFFF:
|
| 959 |
+
return self._buffer.write(struct.pack(">BH", 0xDE, n))
|
| 960 |
+
if n <= 0xFFFFFFFF:
|
| 961 |
+
return self._buffer.write(struct.pack(">BI", 0xDF, n))
|
| 962 |
+
raise ValueError("Dict is too large")
|
| 963 |
+
|
| 964 |
+
def _pack_map_pairs(self, n, pairs, nest_limit=DEFAULT_RECURSE_LIMIT):
|
| 965 |
+
self._pack_map_header(n)
|
| 966 |
+
for (k, v) in pairs:
|
| 967 |
+
self._pack(k, nest_limit - 1)
|
| 968 |
+
self._pack(v, nest_limit - 1)
|
| 969 |
+
|
| 970 |
+
def _pack_raw_header(self, n):
|
| 971 |
+
if n <= 0x1F:
|
| 972 |
+
self._buffer.write(struct.pack("B", 0xA0 + n))
|
| 973 |
+
elif self._use_bin_type and n <= 0xFF:
|
| 974 |
+
self._buffer.write(struct.pack(">BB", 0xD9, n))
|
| 975 |
+
elif n <= 0xFFFF:
|
| 976 |
+
self._buffer.write(struct.pack(">BH", 0xDA, n))
|
| 977 |
+
elif n <= 0xFFFFFFFF:
|
| 978 |
+
self._buffer.write(struct.pack(">BI", 0xDB, n))
|
| 979 |
+
else:
|
| 980 |
+
raise ValueError("Raw is too large")
|
| 981 |
+
|
| 982 |
+
def _pack_bin_header(self, n):
|
| 983 |
+
if not self._use_bin_type:
|
| 984 |
+
return self._pack_raw_header(n)
|
| 985 |
+
elif n <= 0xFF:
|
| 986 |
+
return self._buffer.write(struct.pack(">BB", 0xC4, n))
|
| 987 |
+
elif n <= 0xFFFF:
|
| 988 |
+
return self._buffer.write(struct.pack(">BH", 0xC5, n))
|
| 989 |
+
elif n <= 0xFFFFFFFF:
|
| 990 |
+
return self._buffer.write(struct.pack(">BI", 0xC6, n))
|
| 991 |
+
else:
|
| 992 |
+
raise ValueError("Bin is too large")
|
| 993 |
+
|
| 994 |
+
def bytes(self):
|
| 995 |
+
"""Return internal buffer contents as bytes object"""
|
| 996 |
+
return self._buffer.getvalue()
|
| 997 |
+
|
| 998 |
+
def reset(self):
|
| 999 |
+
"""Reset internal buffer.
|
| 1000 |
+
|
| 1001 |
+
This method is useful only when autoreset=False.
|
| 1002 |
+
"""
|
| 1003 |
+
self._buffer = StringIO()
|
| 1004 |
+
|
| 1005 |
+
def getbuffer(self):
|
| 1006 |
+
"""Return view of internal buffer."""
|
| 1007 |
+
if USING_STRINGBUILDER or PY2:
|
| 1008 |
+
return memoryview(self.bytes())
|
| 1009 |
+
else:
|
| 1010 |
+
return self._buffer.getbuffer()
|
venv/lib/python3.12/site-packages/pip/_vendor/packaging/__about__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
|
| 5 |
+
__all__ = [
|
| 6 |
+
"__title__",
|
| 7 |
+
"__summary__",
|
| 8 |
+
"__uri__",
|
| 9 |
+
"__version__",
|
| 10 |
+
"__author__",
|
| 11 |
+
"__email__",
|
| 12 |
+
"__license__",
|
| 13 |
+
"__copyright__",
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
__title__ = "packaging"
|
| 17 |
+
__summary__ = "Core utilities for Python packages"
|
| 18 |
+
__uri__ = "https://github.com/pypa/packaging"
|
| 19 |
+
|
| 20 |
+
__version__ = "21.3"
|
| 21 |
+
|
| 22 |
+
__author__ = "Donald Stufft and individual contributors"
|
| 23 |
+
__email__ = "donald@stufft.io"
|
| 24 |
+
|
| 25 |
+
__license__ = "BSD-2-Clause or Apache-2.0"
|
| 26 |
+
__copyright__ = "2014-2019 %s" % __author__
|
venv/lib/python3.12/site-packages/pip/_vendor/packaging/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
|
| 5 |
+
from .__about__ import (
|
| 6 |
+
__author__,
|
| 7 |
+
__copyright__,
|
| 8 |
+
__email__,
|
| 9 |
+
__license__,
|
| 10 |
+
__summary__,
|
| 11 |
+
__title__,
|
| 12 |
+
__uri__,
|
| 13 |
+
__version__,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
__all__ = [
|
| 17 |
+
"__title__",
|
| 18 |
+
"__summary__",
|
| 19 |
+
"__uri__",
|
| 20 |
+
"__version__",
|
| 21 |
+
"__author__",
|
| 22 |
+
"__email__",
|
| 23 |
+
"__license__",
|
| 24 |
+
"__copyright__",
|
| 25 |
+
]
|
venv/lib/python3.12/site-packages/pip/_vendor/packaging/_manylinux.py
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections
|
| 2 |
+
import functools
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import struct
|
| 6 |
+
import sys
|
| 7 |
+
import warnings
|
| 8 |
+
from typing import IO, Dict, Iterator, NamedTuple, Optional, Tuple
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# Python does not provide platform information at sufficient granularity to
|
| 12 |
+
# identify the architecture of the running executable in some cases, so we
|
| 13 |
+
# determine it dynamically by reading the information from the running
|
| 14 |
+
# process. This only applies on Linux, which uses the ELF format.
|
| 15 |
+
class _ELFFileHeader:
|
| 16 |
+
# https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
|
| 17 |
+
class _InvalidELFFileHeader(ValueError):
|
| 18 |
+
"""
|
| 19 |
+
An invalid ELF file header was found.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
ELF_MAGIC_NUMBER = 0x7F454C46
|
| 23 |
+
ELFCLASS32 = 1
|
| 24 |
+
ELFCLASS64 = 2
|
| 25 |
+
ELFDATA2LSB = 1
|
| 26 |
+
ELFDATA2MSB = 2
|
| 27 |
+
EM_386 = 3
|
| 28 |
+
EM_S390 = 22
|
| 29 |
+
EM_ARM = 40
|
| 30 |
+
EM_X86_64 = 62
|
| 31 |
+
EF_ARM_ABIMASK = 0xFF000000
|
| 32 |
+
EF_ARM_ABI_VER5 = 0x05000000
|
| 33 |
+
EF_ARM_ABI_FLOAT_HARD = 0x00000400
|
| 34 |
+
|
| 35 |
+
def __init__(self, file: IO[bytes]) -> None:
|
| 36 |
+
def unpack(fmt: str) -> int:
|
| 37 |
+
try:
|
| 38 |
+
data = file.read(struct.calcsize(fmt))
|
| 39 |
+
result: Tuple[int, ...] = struct.unpack(fmt, data)
|
| 40 |
+
except struct.error:
|
| 41 |
+
raise _ELFFileHeader._InvalidELFFileHeader()
|
| 42 |
+
return result[0]
|
| 43 |
+
|
| 44 |
+
self.e_ident_magic = unpack(">I")
|
| 45 |
+
if self.e_ident_magic != self.ELF_MAGIC_NUMBER:
|
| 46 |
+
raise _ELFFileHeader._InvalidELFFileHeader()
|
| 47 |
+
self.e_ident_class = unpack("B")
|
| 48 |
+
if self.e_ident_class not in {self.ELFCLASS32, self.ELFCLASS64}:
|
| 49 |
+
raise _ELFFileHeader._InvalidELFFileHeader()
|
| 50 |
+
self.e_ident_data = unpack("B")
|
| 51 |
+
if self.e_ident_data not in {self.ELFDATA2LSB, self.ELFDATA2MSB}:
|
| 52 |
+
raise _ELFFileHeader._InvalidELFFileHeader()
|
| 53 |
+
self.e_ident_version = unpack("B")
|
| 54 |
+
self.e_ident_osabi = unpack("B")
|
| 55 |
+
self.e_ident_abiversion = unpack("B")
|
| 56 |
+
self.e_ident_pad = file.read(7)
|
| 57 |
+
format_h = "<H" if self.e_ident_data == self.ELFDATA2LSB else ">H"
|
| 58 |
+
format_i = "<I" if self.e_ident_data == self.ELFDATA2LSB else ">I"
|
| 59 |
+
format_q = "<Q" if self.e_ident_data == self.ELFDATA2LSB else ">Q"
|
| 60 |
+
format_p = format_i if self.e_ident_class == self.ELFCLASS32 else format_q
|
| 61 |
+
self.e_type = unpack(format_h)
|
| 62 |
+
self.e_machine = unpack(format_h)
|
| 63 |
+
self.e_version = unpack(format_i)
|
| 64 |
+
self.e_entry = unpack(format_p)
|
| 65 |
+
self.e_phoff = unpack(format_p)
|
| 66 |
+
self.e_shoff = unpack(format_p)
|
| 67 |
+
self.e_flags = unpack(format_i)
|
| 68 |
+
self.e_ehsize = unpack(format_h)
|
| 69 |
+
self.e_phentsize = unpack(format_h)
|
| 70 |
+
self.e_phnum = unpack(format_h)
|
| 71 |
+
self.e_shentsize = unpack(format_h)
|
| 72 |
+
self.e_shnum = unpack(format_h)
|
| 73 |
+
self.e_shstrndx = unpack(format_h)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _get_elf_header() -> Optional[_ELFFileHeader]:
|
| 77 |
+
try:
|
| 78 |
+
with open(sys.executable, "rb") as f:
|
| 79 |
+
elf_header = _ELFFileHeader(f)
|
| 80 |
+
except (OSError, TypeError, _ELFFileHeader._InvalidELFFileHeader):
|
| 81 |
+
return None
|
| 82 |
+
return elf_header
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _is_linux_armhf() -> bool:
|
| 86 |
+
# hard-float ABI can be detected from the ELF header of the running
|
| 87 |
+
# process
|
| 88 |
+
# https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
|
| 89 |
+
elf_header = _get_elf_header()
|
| 90 |
+
if elf_header is None:
|
| 91 |
+
return False
|
| 92 |
+
result = elf_header.e_ident_class == elf_header.ELFCLASS32
|
| 93 |
+
result &= elf_header.e_ident_data == elf_header.ELFDATA2LSB
|
| 94 |
+
result &= elf_header.e_machine == elf_header.EM_ARM
|
| 95 |
+
result &= (
|
| 96 |
+
elf_header.e_flags & elf_header.EF_ARM_ABIMASK
|
| 97 |
+
) == elf_header.EF_ARM_ABI_VER5
|
| 98 |
+
result &= (
|
| 99 |
+
elf_header.e_flags & elf_header.EF_ARM_ABI_FLOAT_HARD
|
| 100 |
+
) == elf_header.EF_ARM_ABI_FLOAT_HARD
|
| 101 |
+
return result
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def _is_linux_i686() -> bool:
|
| 105 |
+
elf_header = _get_elf_header()
|
| 106 |
+
if elf_header is None:
|
| 107 |
+
return False
|
| 108 |
+
result = elf_header.e_ident_class == elf_header.ELFCLASS32
|
| 109 |
+
result &= elf_header.e_ident_data == elf_header.ELFDATA2LSB
|
| 110 |
+
result &= elf_header.e_machine == elf_header.EM_386
|
| 111 |
+
return result
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _have_compatible_abi(arch: str) -> bool:
|
| 115 |
+
if arch == "armv7l":
|
| 116 |
+
return _is_linux_armhf()
|
| 117 |
+
if arch == "i686":
|
| 118 |
+
return _is_linux_i686()
|
| 119 |
+
return arch in {"x86_64", "aarch64", "ppc64", "ppc64le", "s390x"}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
# If glibc ever changes its major version, we need to know what the last
|
| 123 |
+
# minor version was, so we can build the complete list of all versions.
|
| 124 |
+
# For now, guess what the highest minor version might be, assume it will
|
| 125 |
+
# be 50 for testing. Once this actually happens, update the dictionary
|
| 126 |
+
# with the actual value.
|
| 127 |
+
_LAST_GLIBC_MINOR: Dict[int, int] = collections.defaultdict(lambda: 50)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
class _GLibCVersion(NamedTuple):
|
| 131 |
+
major: int
|
| 132 |
+
minor: int
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _glibc_version_string_confstr() -> Optional[str]:
|
| 136 |
+
"""
|
| 137 |
+
Primary implementation of glibc_version_string using os.confstr.
|
| 138 |
+
"""
|
| 139 |
+
# os.confstr is quite a bit faster than ctypes.DLL. It's also less likely
|
| 140 |
+
# to be broken or missing. This strategy is used in the standard library
|
| 141 |
+
# platform module.
|
| 142 |
+
# https://github.com/python/cpython/blob/fcf1d003bf4f0100c/Lib/platform.py#L175-L183
|
| 143 |
+
try:
|
| 144 |
+
# os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17".
|
| 145 |
+
version_string = os.confstr("CS_GNU_LIBC_VERSION")
|
| 146 |
+
assert version_string is not None
|
| 147 |
+
_, version = version_string.split()
|
| 148 |
+
except (AssertionError, AttributeError, OSError, ValueError):
|
| 149 |
+
# os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...
|
| 150 |
+
return None
|
| 151 |
+
return version
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def _glibc_version_string_ctypes() -> Optional[str]:
|
| 155 |
+
"""
|
| 156 |
+
Fallback implementation of glibc_version_string using ctypes.
|
| 157 |
+
"""
|
| 158 |
+
try:
|
| 159 |
+
import ctypes
|
| 160 |
+
except ImportError:
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
# ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
|
| 164 |
+
# manpage says, "If filename is NULL, then the returned handle is for the
|
| 165 |
+
# main program". This way we can let the linker do the work to figure out
|
| 166 |
+
# which libc our process is actually using.
|
| 167 |
+
#
|
| 168 |
+
# We must also handle the special case where the executable is not a
|
| 169 |
+
# dynamically linked executable. This can occur when using musl libc,
|
| 170 |
+
# for example. In this situation, dlopen() will error, leading to an
|
| 171 |
+
# OSError. Interestingly, at least in the case of musl, there is no
|
| 172 |
+
# errno set on the OSError. The single string argument used to construct
|
| 173 |
+
# OSError comes from libc itself and is therefore not portable to
|
| 174 |
+
# hard code here. In any case, failure to call dlopen() means we
|
| 175 |
+
# can proceed, so we bail on our attempt.
|
| 176 |
+
try:
|
| 177 |
+
process_namespace = ctypes.CDLL(None)
|
| 178 |
+
except OSError:
|
| 179 |
+
return None
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
gnu_get_libc_version = process_namespace.gnu_get_libc_version
|
| 183 |
+
except AttributeError:
|
| 184 |
+
# Symbol doesn't exist -> therefore, we are not linked to
|
| 185 |
+
# glibc.
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
# Call gnu_get_libc_version, which returns a string like "2.5"
|
| 189 |
+
gnu_get_libc_version.restype = ctypes.c_char_p
|
| 190 |
+
version_str: str = gnu_get_libc_version()
|
| 191 |
+
# py2 / py3 compatibility:
|
| 192 |
+
if not isinstance(version_str, str):
|
| 193 |
+
version_str = version_str.decode("ascii")
|
| 194 |
+
|
| 195 |
+
return version_str
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def _glibc_version_string() -> Optional[str]:
|
| 199 |
+
"""Returns glibc version string, or None if not using glibc."""
|
| 200 |
+
return _glibc_version_string_confstr() or _glibc_version_string_ctypes()
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def _parse_glibc_version(version_str: str) -> Tuple[int, int]:
|
| 204 |
+
"""Parse glibc version.
|
| 205 |
+
|
| 206 |
+
We use a regexp instead of str.split because we want to discard any
|
| 207 |
+
random junk that might come after the minor version -- this might happen
|
| 208 |
+
in patched/forked versions of glibc (e.g. Linaro's version of glibc
|
| 209 |
+
uses version strings like "2.20-2014.11"). See gh-3588.
|
| 210 |
+
"""
|
| 211 |
+
m = re.match(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)", version_str)
|
| 212 |
+
if not m:
|
| 213 |
+
warnings.warn(
|
| 214 |
+
"Expected glibc version with 2 components major.minor,"
|
| 215 |
+
" got: %s" % version_str,
|
| 216 |
+
RuntimeWarning,
|
| 217 |
+
)
|
| 218 |
+
return -1, -1
|
| 219 |
+
return int(m.group("major")), int(m.group("minor"))
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
@functools.lru_cache()
|
| 223 |
+
def _get_glibc_version() -> Tuple[int, int]:
|
| 224 |
+
version_str = _glibc_version_string()
|
| 225 |
+
if version_str is None:
|
| 226 |
+
return (-1, -1)
|
| 227 |
+
return _parse_glibc_version(version_str)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
# From PEP 513, PEP 600
|
| 231 |
+
def _is_compatible(name: str, arch: str, version: _GLibCVersion) -> bool:
|
| 232 |
+
sys_glibc = _get_glibc_version()
|
| 233 |
+
if sys_glibc < version:
|
| 234 |
+
return False
|
| 235 |
+
# Check for presence of _manylinux module.
|
| 236 |
+
try:
|
| 237 |
+
import _manylinux # noqa
|
| 238 |
+
except ImportError:
|
| 239 |
+
return True
|
| 240 |
+
if hasattr(_manylinux, "manylinux_compatible"):
|
| 241 |
+
result = _manylinux.manylinux_compatible(version[0], version[1], arch)
|
| 242 |
+
if result is not None:
|
| 243 |
+
return bool(result)
|
| 244 |
+
return True
|
| 245 |
+
if version == _GLibCVersion(2, 5):
|
| 246 |
+
if hasattr(_manylinux, "manylinux1_compatible"):
|
| 247 |
+
return bool(_manylinux.manylinux1_compatible)
|
| 248 |
+
if version == _GLibCVersion(2, 12):
|
| 249 |
+
if hasattr(_manylinux, "manylinux2010_compatible"):
|
| 250 |
+
return bool(_manylinux.manylinux2010_compatible)
|
| 251 |
+
if version == _GLibCVersion(2, 17):
|
| 252 |
+
if hasattr(_manylinux, "manylinux2014_compatible"):
|
| 253 |
+
return bool(_manylinux.manylinux2014_compatible)
|
| 254 |
+
return True
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
_LEGACY_MANYLINUX_MAP = {
|
| 258 |
+
# CentOS 7 w/ glibc 2.17 (PEP 599)
|
| 259 |
+
(2, 17): "manylinux2014",
|
| 260 |
+
# CentOS 6 w/ glibc 2.12 (PEP 571)
|
| 261 |
+
(2, 12): "manylinux2010",
|
| 262 |
+
# CentOS 5 w/ glibc 2.5 (PEP 513)
|
| 263 |
+
(2, 5): "manylinux1",
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def platform_tags(linux: str, arch: str) -> Iterator[str]:
|
| 268 |
+
if not _have_compatible_abi(arch):
|
| 269 |
+
return
|
| 270 |
+
# Oldest glibc to be supported regardless of architecture is (2, 17).
|
| 271 |
+
too_old_glibc2 = _GLibCVersion(2, 16)
|
| 272 |
+
if arch in {"x86_64", "i686"}:
|
| 273 |
+
# On x86/i686 also oldest glibc to be supported is (2, 5).
|
| 274 |
+
too_old_glibc2 = _GLibCVersion(2, 4)
|
| 275 |
+
current_glibc = _GLibCVersion(*_get_glibc_version())
|
| 276 |
+
glibc_max_list = [current_glibc]
|
| 277 |
+
# We can assume compatibility across glibc major versions.
|
| 278 |
+
# https://sourceware.org/bugzilla/show_bug.cgi?id=24636
|
| 279 |
+
#
|
| 280 |
+
# Build a list of maximum glibc versions so that we can
|
| 281 |
+
# output the canonical list of all glibc from current_glibc
|
| 282 |
+
# down to too_old_glibc2, including all intermediary versions.
|
| 283 |
+
for glibc_major in range(current_glibc.major - 1, 1, -1):
|
| 284 |
+
glibc_minor = _LAST_GLIBC_MINOR[glibc_major]
|
| 285 |
+
glibc_max_list.append(_GLibCVersion(glibc_major, glibc_minor))
|
| 286 |
+
for glibc_max in glibc_max_list:
|
| 287 |
+
if glibc_max.major == too_old_glibc2.major:
|
| 288 |
+
min_minor = too_old_glibc2.minor
|
| 289 |
+
else:
|
| 290 |
+
# For other glibc major versions oldest supported is (x, 0).
|
| 291 |
+
min_minor = -1
|
| 292 |
+
for glibc_minor in range(glibc_max.minor, min_minor, -1):
|
| 293 |
+
glibc_version = _GLibCVersion(glibc_max.major, glibc_minor)
|
| 294 |
+
tag = "manylinux_{}_{}".format(*glibc_version)
|
| 295 |
+
if _is_compatible(tag, arch, glibc_version):
|
| 296 |
+
yield linux.replace("linux", tag)
|
| 297 |
+
# Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
|
| 298 |
+
if glibc_version in _LEGACY_MANYLINUX_MAP:
|
| 299 |
+
legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
|
| 300 |
+
if _is_compatible(legacy_tag, arch, glibc_version):
|
| 301 |
+
yield linux.replace("linux", legacy_tag)
|
venv/lib/python3.12/site-packages/pip/_vendor/packaging/_musllinux.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""PEP 656 support.
|
| 2 |
+
|
| 3 |
+
This module implements logic to detect if the currently running Python is
|
| 4 |
+
linked against musl, and what musl version is used.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import contextlib
|
| 8 |
+
import functools
|
| 9 |
+
import operator
|
| 10 |
+
import os
|
| 11 |
+
import re
|
| 12 |
+
import struct
|
| 13 |
+
import subprocess
|
| 14 |
+
import sys
|
| 15 |
+
from typing import IO, Iterator, NamedTuple, Optional, Tuple
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _read_unpacked(f: IO[bytes], fmt: str) -> Tuple[int, ...]:
|
| 19 |
+
return struct.unpack(fmt, f.read(struct.calcsize(fmt)))
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _parse_ld_musl_from_elf(f: IO[bytes]) -> Optional[str]:
|
| 23 |
+
"""Detect musl libc location by parsing the Python executable.
|
| 24 |
+
|
| 25 |
+
Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
|
| 26 |
+
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
|
| 27 |
+
"""
|
| 28 |
+
f.seek(0)
|
| 29 |
+
try:
|
| 30 |
+
ident = _read_unpacked(f, "16B")
|
| 31 |
+
except struct.error:
|
| 32 |
+
return None
|
| 33 |
+
if ident[:4] != tuple(b"\x7fELF"): # Invalid magic, not ELF.
|
| 34 |
+
return None
|
| 35 |
+
f.seek(struct.calcsize("HHI"), 1) # Skip file type, machine, and version.
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
# e_fmt: Format for program header.
|
| 39 |
+
# p_fmt: Format for section header.
|
| 40 |
+
# p_idx: Indexes to find p_type, p_offset, and p_filesz.
|
| 41 |
+
e_fmt, p_fmt, p_idx = {
|
| 42 |
+
1: ("IIIIHHH", "IIIIIIII", (0, 1, 4)), # 32-bit.
|
| 43 |
+
2: ("QQQIHHH", "IIQQQQQQ", (0, 2, 5)), # 64-bit.
|
| 44 |
+
}[ident[4]]
|
| 45 |
+
except KeyError:
|
| 46 |
+
return None
|
| 47 |
+
else:
|
| 48 |
+
p_get = operator.itemgetter(*p_idx)
|
| 49 |
+
|
| 50 |
+
# Find the interpreter section and return its content.
|
| 51 |
+
try:
|
| 52 |
+
_, e_phoff, _, _, _, e_phentsize, e_phnum = _read_unpacked(f, e_fmt)
|
| 53 |
+
except struct.error:
|
| 54 |
+
return None
|
| 55 |
+
for i in range(e_phnum + 1):
|
| 56 |
+
f.seek(e_phoff + e_phentsize * i)
|
| 57 |
+
try:
|
| 58 |
+
p_type, p_offset, p_filesz = p_get(_read_unpacked(f, p_fmt))
|
| 59 |
+
except struct.error:
|
| 60 |
+
return None
|
| 61 |
+
if p_type != 3: # Not PT_INTERP.
|
| 62 |
+
continue
|
| 63 |
+
f.seek(p_offset)
|
| 64 |
+
interpreter = os.fsdecode(f.read(p_filesz)).strip("\0")
|
| 65 |
+
if "musl" not in interpreter:
|
| 66 |
+
return None
|
| 67 |
+
return interpreter
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class _MuslVersion(NamedTuple):
|
| 72 |
+
major: int
|
| 73 |
+
minor: int
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _parse_musl_version(output: str) -> Optional[_MuslVersion]:
|
| 77 |
+
lines = [n for n in (n.strip() for n in output.splitlines()) if n]
|
| 78 |
+
if len(lines) < 2 or lines[0][:4] != "musl":
|
| 79 |
+
return None
|
| 80 |
+
m = re.match(r"Version (\d+)\.(\d+)", lines[1])
|
| 81 |
+
if not m:
|
| 82 |
+
return None
|
| 83 |
+
return _MuslVersion(major=int(m.group(1)), minor=int(m.group(2)))
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@functools.lru_cache()
|
| 87 |
+
def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
|
| 88 |
+
"""Detect currently-running musl runtime version.
|
| 89 |
+
|
| 90 |
+
This is done by checking the specified executable's dynamic linking
|
| 91 |
+
information, and invoking the loader to parse its output for a version
|
| 92 |
+
string. If the loader is musl, the output would be something like::
|
| 93 |
+
|
| 94 |
+
musl libc (x86_64)
|
| 95 |
+
Version 1.2.2
|
| 96 |
+
Dynamic Program Loader
|
| 97 |
+
"""
|
| 98 |
+
with contextlib.ExitStack() as stack:
|
| 99 |
+
try:
|
| 100 |
+
f = stack.enter_context(open(executable, "rb"))
|
| 101 |
+
except OSError:
|
| 102 |
+
return None
|
| 103 |
+
ld = _parse_ld_musl_from_elf(f)
|
| 104 |
+
if not ld:
|
| 105 |
+
return None
|
| 106 |
+
proc = subprocess.run([ld], stderr=subprocess.PIPE, universal_newlines=True)
|
| 107 |
+
return _parse_musl_version(proc.stderr)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def platform_tags(arch: str) -> Iterator[str]:
|
| 111 |
+
"""Generate musllinux tags compatible to the current platform.
|
| 112 |
+
|
| 113 |
+
:param arch: Should be the part of platform tag after the ``linux_``
|
| 114 |
+
prefix, e.g. ``x86_64``. The ``linux_`` prefix is assumed as a
|
| 115 |
+
prerequisite for the current platform to be musllinux-compatible.
|
| 116 |
+
|
| 117 |
+
:returns: An iterator of compatible musllinux tags.
|
| 118 |
+
"""
|
| 119 |
+
sys_musl = _get_musl_version(sys.executable)
|
| 120 |
+
if sys_musl is None: # Python not dynamically linked against musl.
|
| 121 |
+
return
|
| 122 |
+
for minor in range(sys_musl.minor, -1, -1):
|
| 123 |
+
yield f"musllinux_{sys_musl.major}_{minor}_{arch}"
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__": # pragma: no cover
|
| 127 |
+
import sysconfig
|
| 128 |
+
|
| 129 |
+
plat = sysconfig.get_platform()
|
| 130 |
+
assert plat.startswith("linux-"), "not linux"
|
| 131 |
+
|
| 132 |
+
print("plat:", plat)
|
| 133 |
+
print("musl:", _get_musl_version(sys.executable))
|
| 134 |
+
print("tags:", end=" ")
|
| 135 |
+
for t in platform_tags(re.sub(r"[.-]", "_", plat.split("-", 1)[-1])):
|
| 136 |
+
print(t, end="\n ")
|
venv/lib/python3.12/site-packages/pip/_vendor/packaging/_structures.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class InfinityType:
|
| 7 |
+
def __repr__(self) -> str:
|
| 8 |
+
return "Infinity"
|
| 9 |
+
|
| 10 |
+
def __hash__(self) -> int:
|
| 11 |
+
return hash(repr(self))
|
| 12 |
+
|
| 13 |
+
def __lt__(self, other: object) -> bool:
|
| 14 |
+
return False
|
| 15 |
+
|
| 16 |
+
def __le__(self, other: object) -> bool:
|
| 17 |
+
return False
|
| 18 |
+
|
| 19 |
+
def __eq__(self, other: object) -> bool:
|
| 20 |
+
return isinstance(other, self.__class__)
|
| 21 |
+
|
| 22 |
+
def __gt__(self, other: object) -> bool:
|
| 23 |
+
return True
|
| 24 |
+
|
| 25 |
+
def __ge__(self, other: object) -> bool:
|
| 26 |
+
return True
|
| 27 |
+
|
| 28 |
+
def __neg__(self: object) -> "NegativeInfinityType":
|
| 29 |
+
return NegativeInfinity
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Infinity = InfinityType()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class NegativeInfinityType:
|
| 36 |
+
def __repr__(self) -> str:
|
| 37 |
+
return "-Infinity"
|
| 38 |
+
|
| 39 |
+
def __hash__(self) -> int:
|
| 40 |
+
return hash(repr(self))
|
| 41 |
+
|
| 42 |
+
def __lt__(self, other: object) -> bool:
|
| 43 |
+
return True
|
| 44 |
+
|
| 45 |
+
def __le__(self, other: object) -> bool:
|
| 46 |
+
return True
|
| 47 |
+
|
| 48 |
+
def __eq__(self, other: object) -> bool:
|
| 49 |
+
return isinstance(other, self.__class__)
|
| 50 |
+
|
| 51 |
+
def __gt__(self, other: object) -> bool:
|
| 52 |
+
return False
|
| 53 |
+
|
| 54 |
+
def __ge__(self, other: object) -> bool:
|
| 55 |
+
return False
|
| 56 |
+
|
| 57 |
+
def __neg__(self: object) -> InfinityType:
|
| 58 |
+
return Infinity
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
NegativeInfinity = NegativeInfinityType()
|
venv/lib/python3.12/site-packages/pip/_vendor/packaging/markers.py
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
|
| 5 |
+
import operator
|
| 6 |
+
import os
|
| 7 |
+
import platform
|
| 8 |
+
import sys
|
| 9 |
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
| 10 |
+
|
| 11 |
+
from pip._vendor.pyparsing import ( # noqa: N817
|
| 12 |
+
Forward,
|
| 13 |
+
Group,
|
| 14 |
+
Literal as L,
|
| 15 |
+
ParseException,
|
| 16 |
+
ParseResults,
|
| 17 |
+
QuotedString,
|
| 18 |
+
ZeroOrMore,
|
| 19 |
+
stringEnd,
|
| 20 |
+
stringStart,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
from .specifiers import InvalidSpecifier, Specifier
|
| 24 |
+
|
| 25 |
+
__all__ = [
|
| 26 |
+
"InvalidMarker",
|
| 27 |
+
"UndefinedComparison",
|
| 28 |
+
"UndefinedEnvironmentName",
|
| 29 |
+
"Marker",
|
| 30 |
+
"default_environment",
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
Operator = Callable[[str, str], bool]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class InvalidMarker(ValueError):
|
| 37 |
+
"""
|
| 38 |
+
An invalid marker was found, users should refer to PEP 508.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class UndefinedComparison(ValueError):
|
| 43 |
+
"""
|
| 44 |
+
An invalid operation was attempted on a value that doesn't support it.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class UndefinedEnvironmentName(ValueError):
|
| 49 |
+
"""
|
| 50 |
+
A name was attempted to be used that does not exist inside of the
|
| 51 |
+
environment.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class Node:
|
| 56 |
+
def __init__(self, value: Any) -> None:
|
| 57 |
+
self.value = value
|
| 58 |
+
|
| 59 |
+
def __str__(self) -> str:
|
| 60 |
+
return str(self.value)
|
| 61 |
+
|
| 62 |
+
def __repr__(self) -> str:
|
| 63 |
+
return f"<{self.__class__.__name__}('{self}')>"
|
| 64 |
+
|
| 65 |
+
def serialize(self) -> str:
|
| 66 |
+
raise NotImplementedError
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class Variable(Node):
|
| 70 |
+
def serialize(self) -> str:
|
| 71 |
+
return str(self)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class Value(Node):
|
| 75 |
+
def serialize(self) -> str:
|
| 76 |
+
return f'"{self}"'
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class Op(Node):
|
| 80 |
+
def serialize(self) -> str:
|
| 81 |
+
return str(self)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
VARIABLE = (
|
| 85 |
+
L("implementation_version")
|
| 86 |
+
| L("platform_python_implementation")
|
| 87 |
+
| L("implementation_name")
|
| 88 |
+
| L("python_full_version")
|
| 89 |
+
| L("platform_release")
|
| 90 |
+
| L("platform_version")
|
| 91 |
+
| L("platform_machine")
|
| 92 |
+
| L("platform_system")
|
| 93 |
+
| L("python_version")
|
| 94 |
+
| L("sys_platform")
|
| 95 |
+
| L("os_name")
|
| 96 |
+
| L("os.name") # PEP-345
|
| 97 |
+
| L("sys.platform") # PEP-345
|
| 98 |
+
| L("platform.version") # PEP-345
|
| 99 |
+
| L("platform.machine") # PEP-345
|
| 100 |
+
| L("platform.python_implementation") # PEP-345
|
| 101 |
+
| L("python_implementation") # undocumented setuptools legacy
|
| 102 |
+
| L("extra") # PEP-508
|
| 103 |
+
)
|
| 104 |
+
ALIASES = {
|
| 105 |
+
"os.name": "os_name",
|
| 106 |
+
"sys.platform": "sys_platform",
|
| 107 |
+
"platform.version": "platform_version",
|
| 108 |
+
"platform.machine": "platform_machine",
|
| 109 |
+
"platform.python_implementation": "platform_python_implementation",
|
| 110 |
+
"python_implementation": "platform_python_implementation",
|
| 111 |
+
}
|
| 112 |
+
VARIABLE.setParseAction(lambda s, l, t: Variable(ALIASES.get(t[0], t[0])))
|
| 113 |
+
|
| 114 |
+
VERSION_CMP = (
|
| 115 |
+
L("===") | L("==") | L(">=") | L("<=") | L("!=") | L("~=") | L(">") | L("<")
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
MARKER_OP = VERSION_CMP | L("not in") | L("in")
|
| 119 |
+
MARKER_OP.setParseAction(lambda s, l, t: Op(t[0]))
|
| 120 |
+
|
| 121 |
+
MARKER_VALUE = QuotedString("'") | QuotedString('"')
|
| 122 |
+
MARKER_VALUE.setParseAction(lambda s, l, t: Value(t[0]))
|
| 123 |
+
|
| 124 |
+
BOOLOP = L("and") | L("or")
|
| 125 |
+
|
| 126 |
+
MARKER_VAR = VARIABLE | MARKER_VALUE
|
| 127 |
+
|
| 128 |
+
MARKER_ITEM = Group(MARKER_VAR + MARKER_OP + MARKER_VAR)
|
| 129 |
+
MARKER_ITEM.setParseAction(lambda s, l, t: tuple(t[0]))
|
| 130 |
+
|
| 131 |
+
LPAREN = L("(").suppress()
|
| 132 |
+
RPAREN = L(")").suppress()
|
| 133 |
+
|
| 134 |
+
MARKER_EXPR = Forward()
|
| 135 |
+
MARKER_ATOM = MARKER_ITEM | Group(LPAREN + MARKER_EXPR + RPAREN)
|
| 136 |
+
MARKER_EXPR << MARKER_ATOM + ZeroOrMore(BOOLOP + MARKER_EXPR)
|
| 137 |
+
|
| 138 |
+
MARKER = stringStart + MARKER_EXPR + stringEnd
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _coerce_parse_result(results: Union[ParseResults, List[Any]]) -> List[Any]:
|
| 142 |
+
if isinstance(results, ParseResults):
|
| 143 |
+
return [_coerce_parse_result(i) for i in results]
|
| 144 |
+
else:
|
| 145 |
+
return results
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def _format_marker(
|
| 149 |
+
marker: Union[List[str], Tuple[Node, ...], str], first: Optional[bool] = True
|
| 150 |
+
) -> str:
|
| 151 |
+
|
| 152 |
+
assert isinstance(marker, (list, tuple, str))
|
| 153 |
+
|
| 154 |
+
# Sometimes we have a structure like [[...]] which is a single item list
|
| 155 |
+
# where the single item is itself it's own list. In that case we want skip
|
| 156 |
+
# the rest of this function so that we don't get extraneous () on the
|
| 157 |
+
# outside.
|
| 158 |
+
if (
|
| 159 |
+
isinstance(marker, list)
|
| 160 |
+
and len(marker) == 1
|
| 161 |
+
and isinstance(marker[0], (list, tuple))
|
| 162 |
+
):
|
| 163 |
+
return _format_marker(marker[0])
|
| 164 |
+
|
| 165 |
+
if isinstance(marker, list):
|
| 166 |
+
inner = (_format_marker(m, first=False) for m in marker)
|
| 167 |
+
if first:
|
| 168 |
+
return " ".join(inner)
|
| 169 |
+
else:
|
| 170 |
+
return "(" + " ".join(inner) + ")"
|
| 171 |
+
elif isinstance(marker, tuple):
|
| 172 |
+
return " ".join([m.serialize() for m in marker])
|
| 173 |
+
else:
|
| 174 |
+
return marker
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
_operators: Dict[str, Operator] = {
|
| 178 |
+
"in": lambda lhs, rhs: lhs in rhs,
|
| 179 |
+
"not in": lambda lhs, rhs: lhs not in rhs,
|
| 180 |
+
"<": operator.lt,
|
| 181 |
+
"<=": operator.le,
|
| 182 |
+
"==": operator.eq,
|
| 183 |
+
"!=": operator.ne,
|
| 184 |
+
">=": operator.ge,
|
| 185 |
+
">": operator.gt,
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _eval_op(lhs: str, op: Op, rhs: str) -> bool:
|
| 190 |
+
try:
|
| 191 |
+
spec = Specifier("".join([op.serialize(), rhs]))
|
| 192 |
+
except InvalidSpecifier:
|
| 193 |
+
pass
|
| 194 |
+
else:
|
| 195 |
+
return spec.contains(lhs)
|
| 196 |
+
|
| 197 |
+
oper: Optional[Operator] = _operators.get(op.serialize())
|
| 198 |
+
if oper is None:
|
| 199 |
+
raise UndefinedComparison(f"Undefined {op!r} on {lhs!r} and {rhs!r}.")
|
| 200 |
+
|
| 201 |
+
return oper(lhs, rhs)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
class Undefined:
|
| 205 |
+
pass
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
_undefined = Undefined()
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def _get_env(environment: Dict[str, str], name: str) -> str:
|
| 212 |
+
value: Union[str, Undefined] = environment.get(name, _undefined)
|
| 213 |
+
|
| 214 |
+
if isinstance(value, Undefined):
|
| 215 |
+
raise UndefinedEnvironmentName(
|
| 216 |
+
f"{name!r} does not exist in evaluation environment."
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
return value
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def _evaluate_markers(markers: List[Any], environment: Dict[str, str]) -> bool:
|
| 223 |
+
groups: List[List[bool]] = [[]]
|
| 224 |
+
|
| 225 |
+
for marker in markers:
|
| 226 |
+
assert isinstance(marker, (list, tuple, str))
|
| 227 |
+
|
| 228 |
+
if isinstance(marker, list):
|
| 229 |
+
groups[-1].append(_evaluate_markers(marker, environment))
|
| 230 |
+
elif isinstance(marker, tuple):
|
| 231 |
+
lhs, op, rhs = marker
|
| 232 |
+
|
| 233 |
+
if isinstance(lhs, Variable):
|
| 234 |
+
lhs_value = _get_env(environment, lhs.value)
|
| 235 |
+
rhs_value = rhs.value
|
| 236 |
+
else:
|
| 237 |
+
lhs_value = lhs.value
|
| 238 |
+
rhs_value = _get_env(environment, rhs.value)
|
| 239 |
+
|
| 240 |
+
groups[-1].append(_eval_op(lhs_value, op, rhs_value))
|
| 241 |
+
else:
|
| 242 |
+
assert marker in ["and", "or"]
|
| 243 |
+
if marker == "or":
|
| 244 |
+
groups.append([])
|
| 245 |
+
|
| 246 |
+
return any(all(item) for item in groups)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def format_full_version(info: "sys._version_info") -> str:
|
| 250 |
+
version = "{0.major}.{0.minor}.{0.micro}".format(info)
|
| 251 |
+
kind = info.releaselevel
|
| 252 |
+
if kind != "final":
|
| 253 |
+
version += kind[0] + str(info.serial)
|
| 254 |
+
return version
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def default_environment() -> Dict[str, str]:
|
| 258 |
+
iver = format_full_version(sys.implementation.version)
|
| 259 |
+
implementation_name = sys.implementation.name
|
| 260 |
+
return {
|
| 261 |
+
"implementation_name": implementation_name,
|
| 262 |
+
"implementation_version": iver,
|
| 263 |
+
"os_name": os.name,
|
| 264 |
+
"platform_machine": platform.machine(),
|
| 265 |
+
"platform_release": platform.release(),
|
| 266 |
+
"platform_system": platform.system(),
|
| 267 |
+
"platform_version": platform.version(),
|
| 268 |
+
"python_full_version": platform.python_version(),
|
| 269 |
+
"platform_python_implementation": platform.python_implementation(),
|
| 270 |
+
"python_version": ".".join(platform.python_version_tuple()[:2]),
|
| 271 |
+
"sys_platform": sys.platform,
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
class Marker:
|
| 276 |
+
def __init__(self, marker: str) -> None:
|
| 277 |
+
try:
|
| 278 |
+
self._markers = _coerce_parse_result(MARKER.parseString(marker))
|
| 279 |
+
except ParseException as e:
|
| 280 |
+
raise InvalidMarker(
|
| 281 |
+
f"Invalid marker: {marker!r}, parse error at "
|
| 282 |
+
f"{marker[e.loc : e.loc + 8]!r}"
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
def __str__(self) -> str:
|
| 286 |
+
return _format_marker(self._markers)
|
| 287 |
+
|
| 288 |
+
def __repr__(self) -> str:
|
| 289 |
+
return f"<Marker('{self}')>"
|
| 290 |
+
|
| 291 |
+
def evaluate(self, environment: Optional[Dict[str, str]] = None) -> bool:
|
| 292 |
+
"""Evaluate a marker.
|
| 293 |
+
|
| 294 |
+
Return the boolean from evaluating the given marker against the
|
| 295 |
+
environment. environment is an optional argument to override all or
|
| 296 |
+
part of the determined environment.
|
| 297 |
+
|
| 298 |
+
The environment is determined from the current Python process.
|
| 299 |
+
"""
|
| 300 |
+
current_environment = default_environment()
|
| 301 |
+
if environment is not None:
|
| 302 |
+
current_environment.update(environment)
|
| 303 |
+
|
| 304 |
+
return _evaluate_markers(self._markers, current_environment)
|
venv/lib/python3.12/site-packages/pip/_vendor/packaging/requirements.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
import string
|
| 7 |
+
import urllib.parse
|
| 8 |
+
from typing import List, Optional as TOptional, Set
|
| 9 |
+
|
| 10 |
+
from pip._vendor.pyparsing import ( # noqa
|
| 11 |
+
Combine,
|
| 12 |
+
Literal as L,
|
| 13 |
+
Optional,
|
| 14 |
+
ParseException,
|
| 15 |
+
Regex,
|
| 16 |
+
Word,
|
| 17 |
+
ZeroOrMore,
|
| 18 |
+
originalTextFor,
|
| 19 |
+
stringEnd,
|
| 20 |
+
stringStart,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
from .markers import MARKER_EXPR, Marker
|
| 24 |
+
from .specifiers import LegacySpecifier, Specifier, SpecifierSet
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class InvalidRequirement(ValueError):
|
| 28 |
+
"""
|
| 29 |
+
An invalid requirement was found, users should refer to PEP 508.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
ALPHANUM = Word(string.ascii_letters + string.digits)
|
| 34 |
+
|
| 35 |
+
LBRACKET = L("[").suppress()
|
| 36 |
+
RBRACKET = L("]").suppress()
|
| 37 |
+
LPAREN = L("(").suppress()
|
| 38 |
+
RPAREN = L(")").suppress()
|
| 39 |
+
COMMA = L(",").suppress()
|
| 40 |
+
SEMICOLON = L(";").suppress()
|
| 41 |
+
AT = L("@").suppress()
|
| 42 |
+
|
| 43 |
+
PUNCTUATION = Word("-_.")
|
| 44 |
+
IDENTIFIER_END = ALPHANUM | (ZeroOrMore(PUNCTUATION) + ALPHANUM)
|
| 45 |
+
IDENTIFIER = Combine(ALPHANUM + ZeroOrMore(IDENTIFIER_END))
|
| 46 |
+
|
| 47 |
+
NAME = IDENTIFIER("name")
|
| 48 |
+
EXTRA = IDENTIFIER
|
| 49 |
+
|
| 50 |
+
URI = Regex(r"[^ ]+")("url")
|
| 51 |
+
URL = AT + URI
|
| 52 |
+
|
| 53 |
+
EXTRAS_LIST = EXTRA + ZeroOrMore(COMMA + EXTRA)
|
| 54 |
+
EXTRAS = (LBRACKET + Optional(EXTRAS_LIST) + RBRACKET)("extras")
|
| 55 |
+
|
| 56 |
+
VERSION_PEP440 = Regex(Specifier._regex_str, re.VERBOSE | re.IGNORECASE)
|
| 57 |
+
VERSION_LEGACY = Regex(LegacySpecifier._regex_str, re.VERBOSE | re.IGNORECASE)
|
| 58 |
+
|
| 59 |
+
VERSION_ONE = VERSION_PEP440 ^ VERSION_LEGACY
|
| 60 |
+
VERSION_MANY = Combine(
|
| 61 |
+
VERSION_ONE + ZeroOrMore(COMMA + VERSION_ONE), joinString=",", adjacent=False
|
| 62 |
+
)("_raw_spec")
|
| 63 |
+
_VERSION_SPEC = Optional((LPAREN + VERSION_MANY + RPAREN) | VERSION_MANY)
|
| 64 |
+
_VERSION_SPEC.setParseAction(lambda s, l, t: t._raw_spec or "")
|
| 65 |
+
|
| 66 |
+
VERSION_SPEC = originalTextFor(_VERSION_SPEC)("specifier")
|
| 67 |
+
VERSION_SPEC.setParseAction(lambda s, l, t: t[1])
|
| 68 |
+
|
| 69 |
+
MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
|
| 70 |
+
MARKER_EXPR.setParseAction(
|
| 71 |
+
lambda s, l, t: Marker(s[t._original_start : t._original_end])
|
| 72 |
+
)
|
| 73 |
+
MARKER_SEPARATOR = SEMICOLON
|
| 74 |
+
MARKER = MARKER_SEPARATOR + MARKER_EXPR
|
| 75 |
+
|
| 76 |
+
VERSION_AND_MARKER = VERSION_SPEC + Optional(MARKER)
|
| 77 |
+
URL_AND_MARKER = URL + Optional(MARKER)
|
| 78 |
+
|
| 79 |
+
NAMED_REQUIREMENT = NAME + Optional(EXTRAS) + (URL_AND_MARKER | VERSION_AND_MARKER)
|
| 80 |
+
|
| 81 |
+
REQUIREMENT = stringStart + NAMED_REQUIREMENT + stringEnd
|
| 82 |
+
# pyparsing isn't thread safe during initialization, so we do it eagerly, see
|
| 83 |
+
# issue #104
|
| 84 |
+
REQUIREMENT.parseString("x[]")
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class Requirement:
|
| 88 |
+
"""Parse a requirement.
|
| 89 |
+
|
| 90 |
+
Parse a given requirement string into its parts, such as name, specifier,
|
| 91 |
+
URL, and extras. Raises InvalidRequirement on a badly-formed requirement
|
| 92 |
+
string.
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
# TODO: Can we test whether something is contained within a requirement?
|
| 96 |
+
# If so how do we do that? Do we need to test against the _name_ of
|
| 97 |
+
# the thing as well as the version? What about the markers?
|
| 98 |
+
# TODO: Can we normalize the name and extra name?
|
| 99 |
+
|
| 100 |
+
def __init__(self, requirement_string: str) -> None:
|
| 101 |
+
try:
|
| 102 |
+
req = REQUIREMENT.parseString(requirement_string)
|
| 103 |
+
except ParseException as e:
|
| 104 |
+
raise InvalidRequirement(
|
| 105 |
+
f'Parse error at "{ requirement_string[e.loc : e.loc + 8]!r}": {e.msg}'
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
self.name: str = req.name
|
| 109 |
+
if req.url:
|
| 110 |
+
parsed_url = urllib.parse.urlparse(req.url)
|
| 111 |
+
if parsed_url.scheme == "file":
|
| 112 |
+
if urllib.parse.urlunparse(parsed_url) != req.url:
|
| 113 |
+
raise InvalidRequirement("Invalid URL given")
|
| 114 |
+
elif not (parsed_url.scheme and parsed_url.netloc) or (
|
| 115 |
+
not parsed_url.scheme and not parsed_url.netloc
|
| 116 |
+
):
|
| 117 |
+
raise InvalidRequirement(f"Invalid URL: {req.url}")
|
| 118 |
+
self.url: TOptional[str] = req.url
|
| 119 |
+
else:
|
| 120 |
+
self.url = None
|
| 121 |
+
self.extras: Set[str] = set(req.extras.asList() if req.extras else [])
|
| 122 |
+
self.specifier: SpecifierSet = SpecifierSet(req.specifier)
|
| 123 |
+
self.marker: TOptional[Marker] = req.marker if req.marker else None
|
| 124 |
+
|
| 125 |
+
def __str__(self) -> str:
|
| 126 |
+
parts: List[str] = [self.name]
|
| 127 |
+
|
| 128 |
+
if self.extras:
|
| 129 |
+
formatted_extras = ",".join(sorted(self.extras))
|
| 130 |
+
parts.append(f"[{formatted_extras}]")
|
| 131 |
+
|
| 132 |
+
if self.specifier:
|
| 133 |
+
parts.append(str(self.specifier))
|
| 134 |
+
|
| 135 |
+
if self.url:
|
| 136 |
+
parts.append(f"@ {self.url}")
|
| 137 |
+
if self.marker:
|
| 138 |
+
parts.append(" ")
|
| 139 |
+
|
| 140 |
+
if self.marker:
|
| 141 |
+
parts.append(f"; {self.marker}")
|
| 142 |
+
|
| 143 |
+
return "".join(parts)
|
| 144 |
+
|
| 145 |
+
def __repr__(self) -> str:
|
| 146 |
+
return f"<Requirement('{self}')>"
|