Datasets:
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/site-packages/pip/_internal/utils/__init__.py +0 -0
- .venv/Lib/site-packages/pip/_internal/utils/_jaraco_text.py +109 -0
- .venv/Lib/site-packages/pip/_internal/utils/_log.py +38 -0
- .venv/Lib/site-packages/pip/_internal/utils/models.py +39 -0
- .venv/Lib/site-packages/pip/_internal/utils/packaging.py +57 -0
- .venv/Lib/site-packages/pip/_internal/utils/setuptools_build.py +146 -0
- .venv/Lib/site-packages/pip/_internal/utils/subprocess.py +260 -0
- .venv/Lib/site-packages/pip/_internal/utils/temp_dir.py +246 -0
- .venv/Lib/site-packages/pip/_internal/utils/unpacking.py +257 -0
- .venv/Lib/site-packages/pip/_internal/utils/urls.py +62 -0
- .venv/Lib/site-packages/pip/_internal/utils/virtualenv.py +104 -0
- .venv/Lib/site-packages/pip/_internal/utils/wheel.py +136 -0
- .venv/Lib/site-packages/pip/_internal/vcs/__init__.py +15 -0
- .venv/Lib/site-packages/pip/_internal/vcs/bazaar.py +112 -0
- .venv/Lib/site-packages/pip/_internal/vcs/git.py +526 -0
- .venv/Lib/site-packages/pip/_internal/vcs/mercurial.py +163 -0
- .venv/Lib/site-packages/pip/_internal/vcs/subversion.py +324 -0
- .venv/Lib/site-packages/pip/_internal/vcs/versioncontrol.py +705 -0
- .venv/Lib/site-packages/pip/_vendor/__init__.py +120 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/__init__.py +18 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/_cmd.py +61 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/adapter.py +137 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/cache.py +65 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/__init__.py +9 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py +188 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/redis_cache.py +39 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/compat.py +32 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/controller.py +439 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/filewrapper.py +111 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/heuristics.py +139 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/serialize.py +190 -0
- .venv/Lib/site-packages/pip/_vendor/cachecontrol/wrapper.py +33 -0
- .venv/Lib/site-packages/pip/_vendor/certifi/__init__.py +4 -0
- .venv/Lib/site-packages/pip/_vendor/certifi/__main__.py +12 -0
- .venv/Lib/site-packages/pip/_vendor/certifi/cacert.pem +0 -0
- .venv/Lib/site-packages/pip/_vendor/certifi/core.py +108 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/big5freq.py +386 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/big5prober.py +47 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/chardistribution.py +261 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/charsetgroupprober.py +106 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/charsetprober.py +147 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/codingstatemachine.py +90 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/codingstatemachinedict.py +19 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/cp949prober.py +49 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/enums.py +85 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/escprober.py +102 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/escsm.py +261 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/eucjpprober.py +102 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/euckrfreq.py +196 -0
- .venv/Lib/site-packages/pip/_vendor/chardet/euckrprober.py +47 -0
.venv/Lib/site-packages/pip/_internal/utils/__init__.py
ADDED
|
File without changes
|
.venv/Lib/site-packages/pip/_internal/utils/_jaraco_text.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions brought over from jaraco.text.
|
| 2 |
+
|
| 3 |
+
These functions are not supposed to be used within `pip._internal`. These are
|
| 4 |
+
helper functions brought over from `jaraco.text` to enable vendoring newer
|
| 5 |
+
copies of `pkg_resources` without having to vendor `jaraco.text` and its entire
|
| 6 |
+
dependency cone; something that our vendoring setup is not currently capable of
|
| 7 |
+
handling.
|
| 8 |
+
|
| 9 |
+
License reproduced from original source below:
|
| 10 |
+
|
| 11 |
+
Copyright Jason R. Coombs
|
| 12 |
+
|
| 13 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 14 |
+
of this software and associated documentation files (the "Software"), to
|
| 15 |
+
deal in the Software without restriction, including without limitation the
|
| 16 |
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 17 |
+
sell copies of the Software, and to permit persons to whom the Software is
|
| 18 |
+
furnished to do so, subject to the following conditions:
|
| 19 |
+
|
| 20 |
+
The above copyright notice and this permission notice shall be included in
|
| 21 |
+
all copies or substantial portions of the Software.
|
| 22 |
+
|
| 23 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 24 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 25 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 26 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 27 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 28 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 29 |
+
IN THE SOFTWARE.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
import functools
|
| 33 |
+
import itertools
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _nonblank(str):
|
| 37 |
+
return str and not str.startswith("#")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@functools.singledispatch
|
| 41 |
+
def yield_lines(iterable):
|
| 42 |
+
r"""
|
| 43 |
+
Yield valid lines of a string or iterable.
|
| 44 |
+
|
| 45 |
+
>>> list(yield_lines(''))
|
| 46 |
+
[]
|
| 47 |
+
>>> list(yield_lines(['foo', 'bar']))
|
| 48 |
+
['foo', 'bar']
|
| 49 |
+
>>> list(yield_lines('foo\nbar'))
|
| 50 |
+
['foo', 'bar']
|
| 51 |
+
>>> list(yield_lines('\nfoo\n#bar\nbaz #comment'))
|
| 52 |
+
['foo', 'baz #comment']
|
| 53 |
+
>>> list(yield_lines(['foo\nbar', 'baz', 'bing\n\n\n']))
|
| 54 |
+
['foo', 'bar', 'baz', 'bing']
|
| 55 |
+
"""
|
| 56 |
+
return itertools.chain.from_iterable(map(yield_lines, iterable))
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
@yield_lines.register(str)
|
| 60 |
+
def _(text):
|
| 61 |
+
return filter(_nonblank, map(str.strip, text.splitlines()))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def drop_comment(line):
|
| 65 |
+
"""
|
| 66 |
+
Drop comments.
|
| 67 |
+
|
| 68 |
+
>>> drop_comment('foo # bar')
|
| 69 |
+
'foo'
|
| 70 |
+
|
| 71 |
+
A hash without a space may be in a URL.
|
| 72 |
+
|
| 73 |
+
>>> drop_comment('http://example.com/foo#bar')
|
| 74 |
+
'http://example.com/foo#bar'
|
| 75 |
+
"""
|
| 76 |
+
return line.partition(" #")[0]
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def join_continuation(lines):
|
| 80 |
+
r"""
|
| 81 |
+
Join lines continued by a trailing backslash.
|
| 82 |
+
|
| 83 |
+
>>> list(join_continuation(['foo \\', 'bar', 'baz']))
|
| 84 |
+
['foobar', 'baz']
|
| 85 |
+
>>> list(join_continuation(['foo \\', 'bar', 'baz']))
|
| 86 |
+
['foobar', 'baz']
|
| 87 |
+
>>> list(join_continuation(['foo \\', 'bar \\', 'baz']))
|
| 88 |
+
['foobarbaz']
|
| 89 |
+
|
| 90 |
+
Not sure why, but...
|
| 91 |
+
The character preceeding the backslash is also elided.
|
| 92 |
+
|
| 93 |
+
>>> list(join_continuation(['goo\\', 'dly']))
|
| 94 |
+
['godly']
|
| 95 |
+
|
| 96 |
+
A terrible idea, but...
|
| 97 |
+
If no line is available to continue, suppress the lines.
|
| 98 |
+
|
| 99 |
+
>>> list(join_continuation(['foo', 'bar\\', 'baz\\']))
|
| 100 |
+
['foo']
|
| 101 |
+
"""
|
| 102 |
+
lines = iter(lines)
|
| 103 |
+
for item in lines:
|
| 104 |
+
while item.endswith("\\"):
|
| 105 |
+
try:
|
| 106 |
+
item = item[:-2].strip() + next(lines)
|
| 107 |
+
except StopIteration:
|
| 108 |
+
return
|
| 109 |
+
yield item
|
.venv/Lib/site-packages/pip/_internal/utils/_log.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Customize logging
|
| 2 |
+
|
| 3 |
+
Defines custom logger class for the `logger.verbose(...)` method.
|
| 4 |
+
|
| 5 |
+
init_logging() must be called before any other modules that call logging.getLogger.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import logging
|
| 9 |
+
from typing import Any, cast
|
| 10 |
+
|
| 11 |
+
# custom log level for `--verbose` output
|
| 12 |
+
# between DEBUG and INFO
|
| 13 |
+
VERBOSE = 15
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class VerboseLogger(logging.Logger):
|
| 17 |
+
"""Custom Logger, defining a verbose log-level
|
| 18 |
+
|
| 19 |
+
VERBOSE is between INFO and DEBUG.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
def verbose(self, msg: str, *args: Any, **kwargs: Any) -> None:
|
| 23 |
+
return self.log(VERBOSE, msg, *args, **kwargs)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def getLogger(name: str) -> VerboseLogger:
|
| 27 |
+
"""logging.getLogger, but ensures our VerboseLogger class is returned"""
|
| 28 |
+
return cast(VerboseLogger, logging.getLogger(name))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def init_logging() -> None:
|
| 32 |
+
"""Register our VerboseLogger and VERBOSE log level.
|
| 33 |
+
|
| 34 |
+
Should be called before any calls to getLogger(),
|
| 35 |
+
i.e. in pip._internal.__init__
|
| 36 |
+
"""
|
| 37 |
+
logging.setLoggerClass(VerboseLogger)
|
| 38 |
+
logging.addLevelName(VERBOSE, "VERBOSE")
|
.venv/Lib/site-packages/pip/_internal/utils/models.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utilities for defining models
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import operator
|
| 5 |
+
from typing import Any, Callable, Type
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class KeyBasedCompareMixin:
|
| 9 |
+
"""Provides comparison capabilities that is based on a key"""
|
| 10 |
+
|
| 11 |
+
__slots__ = ["_compare_key", "_defining_class"]
|
| 12 |
+
|
| 13 |
+
def __init__(self, key: Any, defining_class: Type["KeyBasedCompareMixin"]) -> None:
|
| 14 |
+
self._compare_key = key
|
| 15 |
+
self._defining_class = defining_class
|
| 16 |
+
|
| 17 |
+
def __hash__(self) -> int:
|
| 18 |
+
return hash(self._compare_key)
|
| 19 |
+
|
| 20 |
+
def __lt__(self, other: Any) -> bool:
|
| 21 |
+
return self._compare(other, operator.__lt__)
|
| 22 |
+
|
| 23 |
+
def __le__(self, other: Any) -> bool:
|
| 24 |
+
return self._compare(other, operator.__le__)
|
| 25 |
+
|
| 26 |
+
def __gt__(self, other: Any) -> bool:
|
| 27 |
+
return self._compare(other, operator.__gt__)
|
| 28 |
+
|
| 29 |
+
def __ge__(self, other: Any) -> bool:
|
| 30 |
+
return self._compare(other, operator.__ge__)
|
| 31 |
+
|
| 32 |
+
def __eq__(self, other: Any) -> bool:
|
| 33 |
+
return self._compare(other, operator.__eq__)
|
| 34 |
+
|
| 35 |
+
def _compare(self, other: Any, method: Callable[[Any, Any], bool]) -> bool:
|
| 36 |
+
if not isinstance(other, self._defining_class):
|
| 37 |
+
return NotImplemented
|
| 38 |
+
|
| 39 |
+
return method(self._compare_key, other._compare_key)
|
.venv/Lib/site-packages/pip/_internal/utils/packaging.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import logging
|
| 3 |
+
import re
|
| 4 |
+
from typing import NewType, Optional, Tuple, cast
|
| 5 |
+
|
| 6 |
+
from pip._vendor.packaging import specifiers, version
|
| 7 |
+
from pip._vendor.packaging.requirements import Requirement
|
| 8 |
+
|
| 9 |
+
NormalizedExtra = NewType("NormalizedExtra", str)
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def check_requires_python(
|
| 15 |
+
requires_python: Optional[str], version_info: Tuple[int, ...]
|
| 16 |
+
) -> bool:
|
| 17 |
+
"""
|
| 18 |
+
Check if the given Python version matches a "Requires-Python" specifier.
|
| 19 |
+
|
| 20 |
+
:param version_info: A 3-tuple of ints representing a Python
|
| 21 |
+
major-minor-micro version to check (e.g. `sys.version_info[:3]`).
|
| 22 |
+
|
| 23 |
+
:return: `True` if the given Python version satisfies the requirement.
|
| 24 |
+
Otherwise, return `False`.
|
| 25 |
+
|
| 26 |
+
:raises InvalidSpecifier: If `requires_python` has an invalid format.
|
| 27 |
+
"""
|
| 28 |
+
if requires_python is None:
|
| 29 |
+
# The package provides no information
|
| 30 |
+
return True
|
| 31 |
+
requires_python_specifier = specifiers.SpecifierSet(requires_python)
|
| 32 |
+
|
| 33 |
+
python_version = version.parse(".".join(map(str, version_info)))
|
| 34 |
+
return python_version in requires_python_specifier
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@functools.lru_cache(maxsize=512)
|
| 38 |
+
def get_requirement(req_string: str) -> Requirement:
|
| 39 |
+
"""Construct a packaging.Requirement object with caching"""
|
| 40 |
+
# Parsing requirement strings is expensive, and is also expected to happen
|
| 41 |
+
# with a low diversity of different arguments (at least relative the number
|
| 42 |
+
# constructed). This method adds a cache to requirement object creation to
|
| 43 |
+
# minimize repeated parsing of the same string to construct equivalent
|
| 44 |
+
# Requirement objects.
|
| 45 |
+
return Requirement(req_string)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def safe_extra(extra: str) -> NormalizedExtra:
|
| 49 |
+
"""Convert an arbitrary string to a standard 'extra' name
|
| 50 |
+
|
| 51 |
+
Any runs of non-alphanumeric characters are replaced with a single '_',
|
| 52 |
+
and the result is always lowercased.
|
| 53 |
+
|
| 54 |
+
This function is duplicated from ``pkg_resources``. Note that this is not
|
| 55 |
+
the same to either ``canonicalize_name`` or ``_egg_link_name``.
|
| 56 |
+
"""
|
| 57 |
+
return cast(NormalizedExtra, re.sub("[^A-Za-z0-9.-]+", "_", extra).lower())
|
.venv/Lib/site-packages/pip/_internal/utils/setuptools_build.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import textwrap
|
| 3 |
+
from typing import List, Optional, Sequence
|
| 4 |
+
|
| 5 |
+
# Shim to wrap setup.py invocation with setuptools
|
| 6 |
+
# Note that __file__ is handled via two {!r} *and* %r, to ensure that paths on
|
| 7 |
+
# Windows are correctly handled (it should be "C:\\Users" not "C:\Users").
|
| 8 |
+
_SETUPTOOLS_SHIM = textwrap.dedent(
|
| 9 |
+
"""
|
| 10 |
+
exec(compile('''
|
| 11 |
+
# This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py
|
| 12 |
+
#
|
| 13 |
+
# - It imports setuptools before invoking setup.py, to enable projects that directly
|
| 14 |
+
# import from `distutils.core` to work with newer packaging standards.
|
| 15 |
+
# - It provides a clear error message when setuptools is not installed.
|
| 16 |
+
# - It sets `sys.argv[0]` to the underlying `setup.py`, when invoking `setup.py` so
|
| 17 |
+
# setuptools doesn't think the script is `-c`. This avoids the following warning:
|
| 18 |
+
# manifest_maker: standard file '-c' not found".
|
| 19 |
+
# - It generates a shim setup.py, for handling setup.cfg-only projects.
|
| 20 |
+
import os, sys, tokenize
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
import setuptools
|
| 24 |
+
except ImportError as error:
|
| 25 |
+
print(
|
| 26 |
+
"ERROR: Can not execute `setup.py` since setuptools is not available in "
|
| 27 |
+
"the build environment.",
|
| 28 |
+
file=sys.stderr,
|
| 29 |
+
)
|
| 30 |
+
sys.exit(1)
|
| 31 |
+
|
| 32 |
+
__file__ = %r
|
| 33 |
+
sys.argv[0] = __file__
|
| 34 |
+
|
| 35 |
+
if os.path.exists(__file__):
|
| 36 |
+
filename = __file__
|
| 37 |
+
with tokenize.open(__file__) as f:
|
| 38 |
+
setup_py_code = f.read()
|
| 39 |
+
else:
|
| 40 |
+
filename = "<auto-generated setuptools caller>"
|
| 41 |
+
setup_py_code = "from setuptools import setup; setup()"
|
| 42 |
+
|
| 43 |
+
exec(compile(setup_py_code, filename, "exec"))
|
| 44 |
+
''' % ({!r},), "<pip-setuptools-caller>", "exec"))
|
| 45 |
+
"""
|
| 46 |
+
).rstrip()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def make_setuptools_shim_args(
|
| 50 |
+
setup_py_path: str,
|
| 51 |
+
global_options: Optional[Sequence[str]] = None,
|
| 52 |
+
no_user_config: bool = False,
|
| 53 |
+
unbuffered_output: bool = False,
|
| 54 |
+
) -> List[str]:
|
| 55 |
+
"""
|
| 56 |
+
Get setuptools command arguments with shim wrapped setup file invocation.
|
| 57 |
+
|
| 58 |
+
:param setup_py_path: The path to setup.py to be wrapped.
|
| 59 |
+
:param global_options: Additional global options.
|
| 60 |
+
:param no_user_config: If True, disables personal user configuration.
|
| 61 |
+
:param unbuffered_output: If True, adds the unbuffered switch to the
|
| 62 |
+
argument list.
|
| 63 |
+
"""
|
| 64 |
+
args = [sys.executable]
|
| 65 |
+
if unbuffered_output:
|
| 66 |
+
args += ["-u"]
|
| 67 |
+
args += ["-c", _SETUPTOOLS_SHIM.format(setup_py_path)]
|
| 68 |
+
if global_options:
|
| 69 |
+
args += global_options
|
| 70 |
+
if no_user_config:
|
| 71 |
+
args += ["--no-user-cfg"]
|
| 72 |
+
return args
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def make_setuptools_bdist_wheel_args(
|
| 76 |
+
setup_py_path: str,
|
| 77 |
+
global_options: Sequence[str],
|
| 78 |
+
build_options: Sequence[str],
|
| 79 |
+
destination_dir: str,
|
| 80 |
+
) -> List[str]:
|
| 81 |
+
# NOTE: Eventually, we'd want to also -S to the flags here, when we're
|
| 82 |
+
# isolating. Currently, it breaks Python in virtualenvs, because it
|
| 83 |
+
# relies on site.py to find parts of the standard library outside the
|
| 84 |
+
# virtualenv.
|
| 85 |
+
args = make_setuptools_shim_args(
|
| 86 |
+
setup_py_path, global_options=global_options, unbuffered_output=True
|
| 87 |
+
)
|
| 88 |
+
args += ["bdist_wheel", "-d", destination_dir]
|
| 89 |
+
args += build_options
|
| 90 |
+
return args
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def make_setuptools_clean_args(
|
| 94 |
+
setup_py_path: str,
|
| 95 |
+
global_options: Sequence[str],
|
| 96 |
+
) -> List[str]:
|
| 97 |
+
args = make_setuptools_shim_args(
|
| 98 |
+
setup_py_path, global_options=global_options, unbuffered_output=True
|
| 99 |
+
)
|
| 100 |
+
args += ["clean", "--all"]
|
| 101 |
+
return args
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def make_setuptools_develop_args(
|
| 105 |
+
setup_py_path: str,
|
| 106 |
+
*,
|
| 107 |
+
global_options: Sequence[str],
|
| 108 |
+
no_user_config: bool,
|
| 109 |
+
prefix: Optional[str],
|
| 110 |
+
home: Optional[str],
|
| 111 |
+
use_user_site: bool,
|
| 112 |
+
) -> List[str]:
|
| 113 |
+
assert not (use_user_site and prefix)
|
| 114 |
+
|
| 115 |
+
args = make_setuptools_shim_args(
|
| 116 |
+
setup_py_path,
|
| 117 |
+
global_options=global_options,
|
| 118 |
+
no_user_config=no_user_config,
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
args += ["develop", "--no-deps"]
|
| 122 |
+
|
| 123 |
+
if prefix:
|
| 124 |
+
args += ["--prefix", prefix]
|
| 125 |
+
if home is not None:
|
| 126 |
+
args += ["--install-dir", home]
|
| 127 |
+
|
| 128 |
+
if use_user_site:
|
| 129 |
+
args += ["--user", "--prefix="]
|
| 130 |
+
|
| 131 |
+
return args
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def make_setuptools_egg_info_args(
|
| 135 |
+
setup_py_path: str,
|
| 136 |
+
egg_info_dir: Optional[str],
|
| 137 |
+
no_user_config: bool,
|
| 138 |
+
) -> List[str]:
|
| 139 |
+
args = make_setuptools_shim_args(setup_py_path, no_user_config=no_user_config)
|
| 140 |
+
|
| 141 |
+
args += ["egg_info"]
|
| 142 |
+
|
| 143 |
+
if egg_info_dir:
|
| 144 |
+
args += ["--egg-base", egg_info_dir]
|
| 145 |
+
|
| 146 |
+
return args
|
.venv/Lib/site-packages/pip/_internal/utils/subprocess.py
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import shlex
|
| 4 |
+
import subprocess
|
| 5 |
+
from typing import (
|
| 6 |
+
TYPE_CHECKING,
|
| 7 |
+
Any,
|
| 8 |
+
Callable,
|
| 9 |
+
Iterable,
|
| 10 |
+
List,
|
| 11 |
+
Mapping,
|
| 12 |
+
Optional,
|
| 13 |
+
Union,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
from pip._vendor.rich.markup import escape
|
| 17 |
+
|
| 18 |
+
from pip._internal.cli.spinners import SpinnerInterface, open_spinner
|
| 19 |
+
from pip._internal.exceptions import InstallationSubprocessError
|
| 20 |
+
from pip._internal.utils.logging import VERBOSE, subprocess_logger
|
| 21 |
+
from pip._internal.utils.misc import HiddenText
|
| 22 |
+
|
| 23 |
+
if TYPE_CHECKING:
|
| 24 |
+
# Literal was introduced in Python 3.8.
|
| 25 |
+
#
|
| 26 |
+
# TODO: Remove `if TYPE_CHECKING` when dropping support for Python 3.7.
|
| 27 |
+
from typing import Literal
|
| 28 |
+
|
| 29 |
+
CommandArgs = List[Union[str, HiddenText]]
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def make_command(*args: Union[str, HiddenText, CommandArgs]) -> CommandArgs:
|
| 33 |
+
"""
|
| 34 |
+
Create a CommandArgs object.
|
| 35 |
+
"""
|
| 36 |
+
command_args: CommandArgs = []
|
| 37 |
+
for arg in args:
|
| 38 |
+
# Check for list instead of CommandArgs since CommandArgs is
|
| 39 |
+
# only known during type-checking.
|
| 40 |
+
if isinstance(arg, list):
|
| 41 |
+
command_args.extend(arg)
|
| 42 |
+
else:
|
| 43 |
+
# Otherwise, arg is str or HiddenText.
|
| 44 |
+
command_args.append(arg)
|
| 45 |
+
|
| 46 |
+
return command_args
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def format_command_args(args: Union[List[str], CommandArgs]) -> str:
|
| 50 |
+
"""
|
| 51 |
+
Format command arguments for display.
|
| 52 |
+
"""
|
| 53 |
+
# For HiddenText arguments, display the redacted form by calling str().
|
| 54 |
+
# Also, we don't apply str() to arguments that aren't HiddenText since
|
| 55 |
+
# this can trigger a UnicodeDecodeError in Python 2 if the argument
|
| 56 |
+
# has type unicode and includes a non-ascii character. (The type
|
| 57 |
+
# checker doesn't ensure the annotations are correct in all cases.)
|
| 58 |
+
return " ".join(
|
| 59 |
+
shlex.quote(str(arg)) if isinstance(arg, HiddenText) else shlex.quote(arg)
|
| 60 |
+
for arg in args
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def reveal_command_args(args: Union[List[str], CommandArgs]) -> List[str]:
|
| 65 |
+
"""
|
| 66 |
+
Return the arguments in their raw, unredacted form.
|
| 67 |
+
"""
|
| 68 |
+
return [arg.secret if isinstance(arg, HiddenText) else arg for arg in args]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def call_subprocess(
|
| 72 |
+
cmd: Union[List[str], CommandArgs],
|
| 73 |
+
show_stdout: bool = False,
|
| 74 |
+
cwd: Optional[str] = None,
|
| 75 |
+
on_returncode: 'Literal["raise", "warn", "ignore"]' = "raise",
|
| 76 |
+
extra_ok_returncodes: Optional[Iterable[int]] = None,
|
| 77 |
+
extra_environ: Optional[Mapping[str, Any]] = None,
|
| 78 |
+
unset_environ: Optional[Iterable[str]] = None,
|
| 79 |
+
spinner: Optional[SpinnerInterface] = None,
|
| 80 |
+
log_failed_cmd: Optional[bool] = True,
|
| 81 |
+
stdout_only: Optional[bool] = False,
|
| 82 |
+
*,
|
| 83 |
+
command_desc: str,
|
| 84 |
+
) -> str:
|
| 85 |
+
"""
|
| 86 |
+
Args:
|
| 87 |
+
show_stdout: if true, use INFO to log the subprocess's stderr and
|
| 88 |
+
stdout streams. Otherwise, use DEBUG. Defaults to False.
|
| 89 |
+
extra_ok_returncodes: an iterable of integer return codes that are
|
| 90 |
+
acceptable, in addition to 0. Defaults to None, which means [].
|
| 91 |
+
unset_environ: an iterable of environment variable names to unset
|
| 92 |
+
prior to calling subprocess.Popen().
|
| 93 |
+
log_failed_cmd: if false, failed commands are not logged, only raised.
|
| 94 |
+
stdout_only: if true, return only stdout, else return both. When true,
|
| 95 |
+
logging of both stdout and stderr occurs when the subprocess has
|
| 96 |
+
terminated, else logging occurs as subprocess output is produced.
|
| 97 |
+
"""
|
| 98 |
+
if extra_ok_returncodes is None:
|
| 99 |
+
extra_ok_returncodes = []
|
| 100 |
+
if unset_environ is None:
|
| 101 |
+
unset_environ = []
|
| 102 |
+
# Most places in pip use show_stdout=False. What this means is--
|
| 103 |
+
#
|
| 104 |
+
# - We connect the child's output (combined stderr and stdout) to a
|
| 105 |
+
# single pipe, which we read.
|
| 106 |
+
# - We log this output to stderr at DEBUG level as it is received.
|
| 107 |
+
# - If DEBUG logging isn't enabled (e.g. if --verbose logging wasn't
|
| 108 |
+
# requested), then we show a spinner so the user can still see the
|
| 109 |
+
# subprocess is in progress.
|
| 110 |
+
# - If the subprocess exits with an error, we log the output to stderr
|
| 111 |
+
# at ERROR level if it hasn't already been displayed to the console
|
| 112 |
+
# (e.g. if --verbose logging wasn't enabled). This way we don't log
|
| 113 |
+
# the output to the console twice.
|
| 114 |
+
#
|
| 115 |
+
# If show_stdout=True, then the above is still done, but with DEBUG
|
| 116 |
+
# replaced by INFO.
|
| 117 |
+
if show_stdout:
|
| 118 |
+
# Then log the subprocess output at INFO level.
|
| 119 |
+
log_subprocess: Callable[..., None] = subprocess_logger.info
|
| 120 |
+
used_level = logging.INFO
|
| 121 |
+
else:
|
| 122 |
+
# Then log the subprocess output using VERBOSE. This also ensures
|
| 123 |
+
# it will be logged to the log file (aka user_log), if enabled.
|
| 124 |
+
log_subprocess = subprocess_logger.verbose
|
| 125 |
+
used_level = VERBOSE
|
| 126 |
+
|
| 127 |
+
# Whether the subprocess will be visible in the console.
|
| 128 |
+
showing_subprocess = subprocess_logger.getEffectiveLevel() <= used_level
|
| 129 |
+
|
| 130 |
+
# Only use the spinner if we're not showing the subprocess output
|
| 131 |
+
# and we have a spinner.
|
| 132 |
+
use_spinner = not showing_subprocess and spinner is not None
|
| 133 |
+
|
| 134 |
+
log_subprocess("Running command %s", command_desc)
|
| 135 |
+
env = os.environ.copy()
|
| 136 |
+
if extra_environ:
|
| 137 |
+
env.update(extra_environ)
|
| 138 |
+
for name in unset_environ:
|
| 139 |
+
env.pop(name, None)
|
| 140 |
+
try:
|
| 141 |
+
proc = subprocess.Popen(
|
| 142 |
+
# Convert HiddenText objects to the underlying str.
|
| 143 |
+
reveal_command_args(cmd),
|
| 144 |
+
stdin=subprocess.PIPE,
|
| 145 |
+
stdout=subprocess.PIPE,
|
| 146 |
+
stderr=subprocess.STDOUT if not stdout_only else subprocess.PIPE,
|
| 147 |
+
cwd=cwd,
|
| 148 |
+
env=env,
|
| 149 |
+
errors="backslashreplace",
|
| 150 |
+
)
|
| 151 |
+
except Exception as exc:
|
| 152 |
+
if log_failed_cmd:
|
| 153 |
+
subprocess_logger.critical(
|
| 154 |
+
"Error %s while executing command %s",
|
| 155 |
+
exc,
|
| 156 |
+
command_desc,
|
| 157 |
+
)
|
| 158 |
+
raise
|
| 159 |
+
all_output = []
|
| 160 |
+
if not stdout_only:
|
| 161 |
+
assert proc.stdout
|
| 162 |
+
assert proc.stdin
|
| 163 |
+
proc.stdin.close()
|
| 164 |
+
# In this mode, stdout and stderr are in the same pipe.
|
| 165 |
+
while True:
|
| 166 |
+
line: str = proc.stdout.readline()
|
| 167 |
+
if not line:
|
| 168 |
+
break
|
| 169 |
+
line = line.rstrip()
|
| 170 |
+
all_output.append(line + "\n")
|
| 171 |
+
|
| 172 |
+
# Show the line immediately.
|
| 173 |
+
log_subprocess(line)
|
| 174 |
+
# Update the spinner.
|
| 175 |
+
if use_spinner:
|
| 176 |
+
assert spinner
|
| 177 |
+
spinner.spin()
|
| 178 |
+
try:
|
| 179 |
+
proc.wait()
|
| 180 |
+
finally:
|
| 181 |
+
if proc.stdout:
|
| 182 |
+
proc.stdout.close()
|
| 183 |
+
output = "".join(all_output)
|
| 184 |
+
else:
|
| 185 |
+
# In this mode, stdout and stderr are in different pipes.
|
| 186 |
+
# We must use communicate() which is the only safe way to read both.
|
| 187 |
+
out, err = proc.communicate()
|
| 188 |
+
# log line by line to preserve pip log indenting
|
| 189 |
+
for out_line in out.splitlines():
|
| 190 |
+
log_subprocess(out_line)
|
| 191 |
+
all_output.append(out)
|
| 192 |
+
for err_line in err.splitlines():
|
| 193 |
+
log_subprocess(err_line)
|
| 194 |
+
all_output.append(err)
|
| 195 |
+
output = out
|
| 196 |
+
|
| 197 |
+
proc_had_error = proc.returncode and proc.returncode not in extra_ok_returncodes
|
| 198 |
+
if use_spinner:
|
| 199 |
+
assert spinner
|
| 200 |
+
if proc_had_error:
|
| 201 |
+
spinner.finish("error")
|
| 202 |
+
else:
|
| 203 |
+
spinner.finish("done")
|
| 204 |
+
if proc_had_error:
|
| 205 |
+
if on_returncode == "raise":
|
| 206 |
+
error = InstallationSubprocessError(
|
| 207 |
+
command_description=command_desc,
|
| 208 |
+
exit_code=proc.returncode,
|
| 209 |
+
output_lines=all_output if not showing_subprocess else None,
|
| 210 |
+
)
|
| 211 |
+
if log_failed_cmd:
|
| 212 |
+
subprocess_logger.error("[present-rich] %s", error)
|
| 213 |
+
subprocess_logger.verbose(
|
| 214 |
+
"[bold magenta]full command[/]: [blue]%s[/]",
|
| 215 |
+
escape(format_command_args(cmd)),
|
| 216 |
+
extra={"markup": True},
|
| 217 |
+
)
|
| 218 |
+
subprocess_logger.verbose(
|
| 219 |
+
"[bold magenta]cwd[/]: %s",
|
| 220 |
+
escape(cwd or "[inherit]"),
|
| 221 |
+
extra={"markup": True},
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
raise error
|
| 225 |
+
elif on_returncode == "warn":
|
| 226 |
+
subprocess_logger.warning(
|
| 227 |
+
'Command "%s" had error code %s in %s',
|
| 228 |
+
command_desc,
|
| 229 |
+
proc.returncode,
|
| 230 |
+
cwd,
|
| 231 |
+
)
|
| 232 |
+
elif on_returncode == "ignore":
|
| 233 |
+
pass
|
| 234 |
+
else:
|
| 235 |
+
raise ValueError(f"Invalid value: on_returncode={on_returncode!r}")
|
| 236 |
+
return output
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def runner_with_spinner_message(message: str) -> Callable[..., None]:
|
| 240 |
+
"""Provide a subprocess_runner that shows a spinner message.
|
| 241 |
+
|
| 242 |
+
Intended for use with for BuildBackendHookCaller. Thus, the runner has
|
| 243 |
+
an API that matches what's expected by BuildBackendHookCaller.subprocess_runner.
|
| 244 |
+
"""
|
| 245 |
+
|
| 246 |
+
def runner(
|
| 247 |
+
cmd: List[str],
|
| 248 |
+
cwd: Optional[str] = None,
|
| 249 |
+
extra_environ: Optional[Mapping[str, Any]] = None,
|
| 250 |
+
) -> None:
|
| 251 |
+
with open_spinner(message) as spinner:
|
| 252 |
+
call_subprocess(
|
| 253 |
+
cmd,
|
| 254 |
+
command_desc=message,
|
| 255 |
+
cwd=cwd,
|
| 256 |
+
extra_environ=extra_environ,
|
| 257 |
+
spinner=spinner,
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
return runner
|
.venv/Lib/site-packages/pip/_internal/utils/temp_dir.py
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import errno
|
| 2 |
+
import itertools
|
| 3 |
+
import logging
|
| 4 |
+
import os.path
|
| 5 |
+
import tempfile
|
| 6 |
+
from contextlib import ExitStack, contextmanager
|
| 7 |
+
from typing import Any, Dict, Generator, Optional, TypeVar, Union
|
| 8 |
+
|
| 9 |
+
from pip._internal.utils.misc import enum, rmtree
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
_T = TypeVar("_T", bound="TempDirectory")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Kinds of temporary directories. Only needed for ones that are
|
| 17 |
+
# globally-managed.
|
| 18 |
+
tempdir_kinds = enum(
|
| 19 |
+
BUILD_ENV="build-env",
|
| 20 |
+
EPHEM_WHEEL_CACHE="ephem-wheel-cache",
|
| 21 |
+
REQ_BUILD="req-build",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
_tempdir_manager: Optional[ExitStack] = None
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@contextmanager
|
| 29 |
+
def global_tempdir_manager() -> Generator[None, None, None]:
|
| 30 |
+
global _tempdir_manager
|
| 31 |
+
with ExitStack() as stack:
|
| 32 |
+
old_tempdir_manager, _tempdir_manager = _tempdir_manager, stack
|
| 33 |
+
try:
|
| 34 |
+
yield
|
| 35 |
+
finally:
|
| 36 |
+
_tempdir_manager = old_tempdir_manager
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class TempDirectoryTypeRegistry:
|
| 40 |
+
"""Manages temp directory behavior"""
|
| 41 |
+
|
| 42 |
+
def __init__(self) -> None:
|
| 43 |
+
self._should_delete: Dict[str, bool] = {}
|
| 44 |
+
|
| 45 |
+
def set_delete(self, kind: str, value: bool) -> None:
|
| 46 |
+
"""Indicate whether a TempDirectory of the given kind should be
|
| 47 |
+
auto-deleted.
|
| 48 |
+
"""
|
| 49 |
+
self._should_delete[kind] = value
|
| 50 |
+
|
| 51 |
+
def get_delete(self, kind: str) -> bool:
|
| 52 |
+
"""Get configured auto-delete flag for a given TempDirectory type,
|
| 53 |
+
default True.
|
| 54 |
+
"""
|
| 55 |
+
return self._should_delete.get(kind, True)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
_tempdir_registry: Optional[TempDirectoryTypeRegistry] = None
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@contextmanager
|
| 62 |
+
def tempdir_registry() -> Generator[TempDirectoryTypeRegistry, None, None]:
|
| 63 |
+
"""Provides a scoped global tempdir registry that can be used to dictate
|
| 64 |
+
whether directories should be deleted.
|
| 65 |
+
"""
|
| 66 |
+
global _tempdir_registry
|
| 67 |
+
old_tempdir_registry = _tempdir_registry
|
| 68 |
+
_tempdir_registry = TempDirectoryTypeRegistry()
|
| 69 |
+
try:
|
| 70 |
+
yield _tempdir_registry
|
| 71 |
+
finally:
|
| 72 |
+
_tempdir_registry = old_tempdir_registry
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class _Default:
|
| 76 |
+
pass
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
_default = _Default()
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class TempDirectory:
|
| 83 |
+
"""Helper class that owns and cleans up a temporary directory.
|
| 84 |
+
|
| 85 |
+
This class can be used as a context manager or as an OO representation of a
|
| 86 |
+
temporary directory.
|
| 87 |
+
|
| 88 |
+
Attributes:
|
| 89 |
+
path
|
| 90 |
+
Location to the created temporary directory
|
| 91 |
+
delete
|
| 92 |
+
Whether the directory should be deleted when exiting
|
| 93 |
+
(when used as a contextmanager)
|
| 94 |
+
|
| 95 |
+
Methods:
|
| 96 |
+
cleanup()
|
| 97 |
+
Deletes the temporary directory
|
| 98 |
+
|
| 99 |
+
When used as a context manager, if the delete attribute is True, on
|
| 100 |
+
exiting the context the temporary directory is deleted.
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
def __init__(
|
| 104 |
+
self,
|
| 105 |
+
path: Optional[str] = None,
|
| 106 |
+
delete: Union[bool, None, _Default] = _default,
|
| 107 |
+
kind: str = "temp",
|
| 108 |
+
globally_managed: bool = False,
|
| 109 |
+
):
|
| 110 |
+
super().__init__()
|
| 111 |
+
|
| 112 |
+
if delete is _default:
|
| 113 |
+
if path is not None:
|
| 114 |
+
# If we were given an explicit directory, resolve delete option
|
| 115 |
+
# now.
|
| 116 |
+
delete = False
|
| 117 |
+
else:
|
| 118 |
+
# Otherwise, we wait until cleanup and see what
|
| 119 |
+
# tempdir_registry says.
|
| 120 |
+
delete = None
|
| 121 |
+
|
| 122 |
+
# The only time we specify path is in for editables where it
|
| 123 |
+
# is the value of the --src option.
|
| 124 |
+
if path is None:
|
| 125 |
+
path = self._create(kind)
|
| 126 |
+
|
| 127 |
+
self._path = path
|
| 128 |
+
self._deleted = False
|
| 129 |
+
self.delete = delete
|
| 130 |
+
self.kind = kind
|
| 131 |
+
|
| 132 |
+
if globally_managed:
|
| 133 |
+
assert _tempdir_manager is not None
|
| 134 |
+
_tempdir_manager.enter_context(self)
|
| 135 |
+
|
| 136 |
+
@property
|
| 137 |
+
def path(self) -> str:
|
| 138 |
+
assert not self._deleted, f"Attempted to access deleted path: {self._path}"
|
| 139 |
+
return self._path
|
| 140 |
+
|
| 141 |
+
def __repr__(self) -> str:
|
| 142 |
+
return f"<{self.__class__.__name__} {self.path!r}>"
|
| 143 |
+
|
| 144 |
+
def __enter__(self: _T) -> _T:
|
| 145 |
+
return self
|
| 146 |
+
|
| 147 |
+
def __exit__(self, exc: Any, value: Any, tb: Any) -> None:
|
| 148 |
+
if self.delete is not None:
|
| 149 |
+
delete = self.delete
|
| 150 |
+
elif _tempdir_registry:
|
| 151 |
+
delete = _tempdir_registry.get_delete(self.kind)
|
| 152 |
+
else:
|
| 153 |
+
delete = True
|
| 154 |
+
|
| 155 |
+
if delete:
|
| 156 |
+
self.cleanup()
|
| 157 |
+
|
| 158 |
+
def _create(self, kind: str) -> str:
|
| 159 |
+
"""Create a temporary directory and store its path in self.path"""
|
| 160 |
+
# We realpath here because some systems have their default tmpdir
|
| 161 |
+
# symlinked to another directory. This tends to confuse build
|
| 162 |
+
# scripts, so we canonicalize the path by traversing potential
|
| 163 |
+
# symlinks here.
|
| 164 |
+
path = os.path.realpath(tempfile.mkdtemp(prefix=f"pip-{kind}-"))
|
| 165 |
+
logger.debug("Created temporary directory: %s", path)
|
| 166 |
+
return path
|
| 167 |
+
|
| 168 |
+
def cleanup(self) -> None:
|
| 169 |
+
"""Remove the temporary directory created and reset state"""
|
| 170 |
+
self._deleted = True
|
| 171 |
+
if not os.path.exists(self._path):
|
| 172 |
+
return
|
| 173 |
+
rmtree(self._path)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class AdjacentTempDirectory(TempDirectory):
|
| 177 |
+
"""Helper class that creates a temporary directory adjacent to a real one.
|
| 178 |
+
|
| 179 |
+
Attributes:
|
| 180 |
+
original
|
| 181 |
+
The original directory to create a temp directory for.
|
| 182 |
+
path
|
| 183 |
+
After calling create() or entering, contains the full
|
| 184 |
+
path to the temporary directory.
|
| 185 |
+
delete
|
| 186 |
+
Whether the directory should be deleted when exiting
|
| 187 |
+
(when used as a contextmanager)
|
| 188 |
+
|
| 189 |
+
"""
|
| 190 |
+
|
| 191 |
+
# The characters that may be used to name the temp directory
|
| 192 |
+
# We always prepend a ~ and then rotate through these until
|
| 193 |
+
# a usable name is found.
|
| 194 |
+
# pkg_resources raises a different error for .dist-info folder
|
| 195 |
+
# with leading '-' and invalid metadata
|
| 196 |
+
LEADING_CHARS = "-~.=%0123456789"
|
| 197 |
+
|
| 198 |
+
def __init__(self, original: str, delete: Optional[bool] = None) -> None:
|
| 199 |
+
self.original = original.rstrip("/\\")
|
| 200 |
+
super().__init__(delete=delete)
|
| 201 |
+
|
| 202 |
+
@classmethod
|
| 203 |
+
def _generate_names(cls, name: str) -> Generator[str, None, None]:
|
| 204 |
+
"""Generates a series of temporary names.
|
| 205 |
+
|
| 206 |
+
The algorithm replaces the leading characters in the name
|
| 207 |
+
with ones that are valid filesystem characters, but are not
|
| 208 |
+
valid package names (for both Python and pip definitions of
|
| 209 |
+
package).
|
| 210 |
+
"""
|
| 211 |
+
for i in range(1, len(name)):
|
| 212 |
+
for candidate in itertools.combinations_with_replacement(
|
| 213 |
+
cls.LEADING_CHARS, i - 1
|
| 214 |
+
):
|
| 215 |
+
new_name = "~" + "".join(candidate) + name[i:]
|
| 216 |
+
if new_name != name:
|
| 217 |
+
yield new_name
|
| 218 |
+
|
| 219 |
+
# If we make it this far, we will have to make a longer name
|
| 220 |
+
for i in range(len(cls.LEADING_CHARS)):
|
| 221 |
+
for candidate in itertools.combinations_with_replacement(
|
| 222 |
+
cls.LEADING_CHARS, i
|
| 223 |
+
):
|
| 224 |
+
new_name = "~" + "".join(candidate) + name
|
| 225 |
+
if new_name != name:
|
| 226 |
+
yield new_name
|
| 227 |
+
|
| 228 |
+
def _create(self, kind: str) -> str:
|
| 229 |
+
root, name = os.path.split(self.original)
|
| 230 |
+
for candidate in self._generate_names(name):
|
| 231 |
+
path = os.path.join(root, candidate)
|
| 232 |
+
try:
|
| 233 |
+
os.mkdir(path)
|
| 234 |
+
except OSError as ex:
|
| 235 |
+
# Continue if the name exists already
|
| 236 |
+
if ex.errno != errno.EEXIST:
|
| 237 |
+
raise
|
| 238 |
+
else:
|
| 239 |
+
path = os.path.realpath(path)
|
| 240 |
+
break
|
| 241 |
+
else:
|
| 242 |
+
# Final fallback on the default behavior.
|
| 243 |
+
path = os.path.realpath(tempfile.mkdtemp(prefix=f"pip-{kind}-"))
|
| 244 |
+
|
| 245 |
+
logger.debug("Created temporary directory: %s", path)
|
| 246 |
+
return path
|
.venv/Lib/site-packages/pip/_internal/utils/unpacking.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utilities related archives.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
+
import stat
|
| 8 |
+
import tarfile
|
| 9 |
+
import zipfile
|
| 10 |
+
from typing import Iterable, List, Optional
|
| 11 |
+
from zipfile import ZipInfo
|
| 12 |
+
|
| 13 |
+
from pip._internal.exceptions import InstallationError
|
| 14 |
+
from pip._internal.utils.filetypes import (
|
| 15 |
+
BZ2_EXTENSIONS,
|
| 16 |
+
TAR_EXTENSIONS,
|
| 17 |
+
XZ_EXTENSIONS,
|
| 18 |
+
ZIP_EXTENSIONS,
|
| 19 |
+
)
|
| 20 |
+
from pip._internal.utils.misc import ensure_dir
|
| 21 |
+
|
| 22 |
+
logger = logging.getLogger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + TAR_EXTENSIONS
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
import bz2 # noqa
|
| 29 |
+
|
| 30 |
+
SUPPORTED_EXTENSIONS += BZ2_EXTENSIONS
|
| 31 |
+
except ImportError:
|
| 32 |
+
logger.debug("bz2 module is not available")
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
# Only for Python 3.3+
|
| 36 |
+
import lzma # noqa
|
| 37 |
+
|
| 38 |
+
SUPPORTED_EXTENSIONS += XZ_EXTENSIONS
|
| 39 |
+
except ImportError:
|
| 40 |
+
logger.debug("lzma module is not available")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def current_umask() -> int:
|
| 44 |
+
"""Get the current umask which involves having to set it temporarily."""
|
| 45 |
+
mask = os.umask(0)
|
| 46 |
+
os.umask(mask)
|
| 47 |
+
return mask
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def split_leading_dir(path: str) -> List[str]:
|
| 51 |
+
path = path.lstrip("/").lstrip("\\")
|
| 52 |
+
if "/" in path and (
|
| 53 |
+
("\\" in path and path.find("/") < path.find("\\")) or "\\" not in path
|
| 54 |
+
):
|
| 55 |
+
return path.split("/", 1)
|
| 56 |
+
elif "\\" in path:
|
| 57 |
+
return path.split("\\", 1)
|
| 58 |
+
else:
|
| 59 |
+
return [path, ""]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def has_leading_dir(paths: Iterable[str]) -> bool:
|
| 63 |
+
"""Returns true if all the paths have the same leading path name
|
| 64 |
+
(i.e., everything is in one subdirectory in an archive)"""
|
| 65 |
+
common_prefix = None
|
| 66 |
+
for path in paths:
|
| 67 |
+
prefix, rest = split_leading_dir(path)
|
| 68 |
+
if not prefix:
|
| 69 |
+
return False
|
| 70 |
+
elif common_prefix is None:
|
| 71 |
+
common_prefix = prefix
|
| 72 |
+
elif prefix != common_prefix:
|
| 73 |
+
return False
|
| 74 |
+
return True
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def is_within_directory(directory: str, target: str) -> bool:
|
| 78 |
+
"""
|
| 79 |
+
Return true if the absolute path of target is within the directory
|
| 80 |
+
"""
|
| 81 |
+
abs_directory = os.path.abspath(directory)
|
| 82 |
+
abs_target = os.path.abspath(target)
|
| 83 |
+
|
| 84 |
+
prefix = os.path.commonprefix([abs_directory, abs_target])
|
| 85 |
+
return prefix == abs_directory
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def set_extracted_file_to_default_mode_plus_executable(path: str) -> None:
|
| 89 |
+
"""
|
| 90 |
+
Make file present at path have execute for user/group/world
|
| 91 |
+
(chmod +x) is no-op on windows per python docs
|
| 92 |
+
"""
|
| 93 |
+
os.chmod(path, (0o777 & ~current_umask() | 0o111))
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def zip_item_is_executable(info: ZipInfo) -> bool:
|
| 97 |
+
mode = info.external_attr >> 16
|
| 98 |
+
# if mode and regular file and any execute permissions for
|
| 99 |
+
# user/group/world?
|
| 100 |
+
return bool(mode and stat.S_ISREG(mode) and mode & 0o111)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def unzip_file(filename: str, location: str, flatten: bool = True) -> None:
|
| 104 |
+
"""
|
| 105 |
+
Unzip the file (with path `filename`) to the destination `location`. All
|
| 106 |
+
files are written based on system defaults and umask (i.e. permissions are
|
| 107 |
+
not preserved), except that regular file members with any execute
|
| 108 |
+
permissions (user, group, or world) have "chmod +x" applied after being
|
| 109 |
+
written. Note that for windows, any execute changes using os.chmod are
|
| 110 |
+
no-ops per the python docs.
|
| 111 |
+
"""
|
| 112 |
+
ensure_dir(location)
|
| 113 |
+
zipfp = open(filename, "rb")
|
| 114 |
+
try:
|
| 115 |
+
zip = zipfile.ZipFile(zipfp, allowZip64=True)
|
| 116 |
+
leading = has_leading_dir(zip.namelist()) and flatten
|
| 117 |
+
for info in zip.infolist():
|
| 118 |
+
name = info.filename
|
| 119 |
+
fn = name
|
| 120 |
+
if leading:
|
| 121 |
+
fn = split_leading_dir(name)[1]
|
| 122 |
+
fn = os.path.join(location, fn)
|
| 123 |
+
dir = os.path.dirname(fn)
|
| 124 |
+
if not is_within_directory(location, fn):
|
| 125 |
+
message = (
|
| 126 |
+
"The zip file ({}) has a file ({}) trying to install "
|
| 127 |
+
"outside target directory ({})"
|
| 128 |
+
)
|
| 129 |
+
raise InstallationError(message.format(filename, fn, location))
|
| 130 |
+
if fn.endswith("/") or fn.endswith("\\"):
|
| 131 |
+
# A directory
|
| 132 |
+
ensure_dir(fn)
|
| 133 |
+
else:
|
| 134 |
+
ensure_dir(dir)
|
| 135 |
+
# Don't use read() to avoid allocating an arbitrarily large
|
| 136 |
+
# chunk of memory for the file's content
|
| 137 |
+
fp = zip.open(name)
|
| 138 |
+
try:
|
| 139 |
+
with open(fn, "wb") as destfp:
|
| 140 |
+
shutil.copyfileobj(fp, destfp)
|
| 141 |
+
finally:
|
| 142 |
+
fp.close()
|
| 143 |
+
if zip_item_is_executable(info):
|
| 144 |
+
set_extracted_file_to_default_mode_plus_executable(fn)
|
| 145 |
+
finally:
|
| 146 |
+
zipfp.close()
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def untar_file(filename: str, location: str) -> None:
|
| 150 |
+
"""
|
| 151 |
+
Untar the file (with path `filename`) to the destination `location`.
|
| 152 |
+
All files are written based on system defaults and umask (i.e. permissions
|
| 153 |
+
are not preserved), except that regular file members with any execute
|
| 154 |
+
permissions (user, group, or world) have "chmod +x" applied after being
|
| 155 |
+
written. Note that for windows, any execute changes using os.chmod are
|
| 156 |
+
no-ops per the python docs.
|
| 157 |
+
"""
|
| 158 |
+
ensure_dir(location)
|
| 159 |
+
if filename.lower().endswith(".gz") or filename.lower().endswith(".tgz"):
|
| 160 |
+
mode = "r:gz"
|
| 161 |
+
elif filename.lower().endswith(BZ2_EXTENSIONS):
|
| 162 |
+
mode = "r:bz2"
|
| 163 |
+
elif filename.lower().endswith(XZ_EXTENSIONS):
|
| 164 |
+
mode = "r:xz"
|
| 165 |
+
elif filename.lower().endswith(".tar"):
|
| 166 |
+
mode = "r"
|
| 167 |
+
else:
|
| 168 |
+
logger.warning(
|
| 169 |
+
"Cannot determine compression type for file %s",
|
| 170 |
+
filename,
|
| 171 |
+
)
|
| 172 |
+
mode = "r:*"
|
| 173 |
+
tar = tarfile.open(filename, mode, encoding="utf-8")
|
| 174 |
+
try:
|
| 175 |
+
leading = has_leading_dir([member.name for member in tar.getmembers()])
|
| 176 |
+
for member in tar.getmembers():
|
| 177 |
+
fn = member.name
|
| 178 |
+
if leading:
|
| 179 |
+
fn = split_leading_dir(fn)[1]
|
| 180 |
+
path = os.path.join(location, fn)
|
| 181 |
+
if not is_within_directory(location, path):
|
| 182 |
+
message = (
|
| 183 |
+
"The tar file ({}) has a file ({}) trying to install "
|
| 184 |
+
"outside target directory ({})"
|
| 185 |
+
)
|
| 186 |
+
raise InstallationError(message.format(filename, path, location))
|
| 187 |
+
if member.isdir():
|
| 188 |
+
ensure_dir(path)
|
| 189 |
+
elif member.issym():
|
| 190 |
+
try:
|
| 191 |
+
tar._extract_member(member, path)
|
| 192 |
+
except Exception as exc:
|
| 193 |
+
# Some corrupt tar files seem to produce this
|
| 194 |
+
# (specifically bad symlinks)
|
| 195 |
+
logger.warning(
|
| 196 |
+
"In the tar file %s the member %s is invalid: %s",
|
| 197 |
+
filename,
|
| 198 |
+
member.name,
|
| 199 |
+
exc,
|
| 200 |
+
)
|
| 201 |
+
continue
|
| 202 |
+
else:
|
| 203 |
+
try:
|
| 204 |
+
fp = tar.extractfile(member)
|
| 205 |
+
except (KeyError, AttributeError) as exc:
|
| 206 |
+
# Some corrupt tar files seem to produce this
|
| 207 |
+
# (specifically bad symlinks)
|
| 208 |
+
logger.warning(
|
| 209 |
+
"In the tar file %s the member %s is invalid: %s",
|
| 210 |
+
filename,
|
| 211 |
+
member.name,
|
| 212 |
+
exc,
|
| 213 |
+
)
|
| 214 |
+
continue
|
| 215 |
+
ensure_dir(os.path.dirname(path))
|
| 216 |
+
assert fp is not None
|
| 217 |
+
with open(path, "wb") as destfp:
|
| 218 |
+
shutil.copyfileobj(fp, destfp)
|
| 219 |
+
fp.close()
|
| 220 |
+
# Update the timestamp (useful for cython compiled files)
|
| 221 |
+
tar.utime(member, path)
|
| 222 |
+
# member have any execute permissions for user/group/world?
|
| 223 |
+
if member.mode & 0o111:
|
| 224 |
+
set_extracted_file_to_default_mode_plus_executable(path)
|
| 225 |
+
finally:
|
| 226 |
+
tar.close()
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def unpack_file(
|
| 230 |
+
filename: str,
|
| 231 |
+
location: str,
|
| 232 |
+
content_type: Optional[str] = None,
|
| 233 |
+
) -> None:
|
| 234 |
+
filename = os.path.realpath(filename)
|
| 235 |
+
if (
|
| 236 |
+
content_type == "application/zip"
|
| 237 |
+
or filename.lower().endswith(ZIP_EXTENSIONS)
|
| 238 |
+
or zipfile.is_zipfile(filename)
|
| 239 |
+
):
|
| 240 |
+
unzip_file(filename, location, flatten=not filename.endswith(".whl"))
|
| 241 |
+
elif (
|
| 242 |
+
content_type == "application/x-gzip"
|
| 243 |
+
or tarfile.is_tarfile(filename)
|
| 244 |
+
or filename.lower().endswith(TAR_EXTENSIONS + BZ2_EXTENSIONS + XZ_EXTENSIONS)
|
| 245 |
+
):
|
| 246 |
+
untar_file(filename, location)
|
| 247 |
+
else:
|
| 248 |
+
# FIXME: handle?
|
| 249 |
+
# FIXME: magic signatures?
|
| 250 |
+
logger.critical(
|
| 251 |
+
"Cannot unpack file %s (downloaded from %s, content-type: %s); "
|
| 252 |
+
"cannot detect archive format",
|
| 253 |
+
filename,
|
| 254 |
+
location,
|
| 255 |
+
content_type,
|
| 256 |
+
)
|
| 257 |
+
raise InstallationError(f"Cannot determine archive format of {location}")
|
.venv/Lib/site-packages/pip/_internal/utils/urls.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import string
|
| 3 |
+
import urllib.parse
|
| 4 |
+
import urllib.request
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
from .compat import WINDOWS
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def get_url_scheme(url: str) -> Optional[str]:
|
| 11 |
+
if ":" not in url:
|
| 12 |
+
return None
|
| 13 |
+
return url.split(":", 1)[0].lower()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def path_to_url(path: str) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Convert a path to a file: URL. The path will be made absolute and have
|
| 19 |
+
quoted path parts.
|
| 20 |
+
"""
|
| 21 |
+
path = os.path.normpath(os.path.abspath(path))
|
| 22 |
+
url = urllib.parse.urljoin("file:", urllib.request.pathname2url(path))
|
| 23 |
+
return url
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def url_to_path(url: str) -> str:
|
| 27 |
+
"""
|
| 28 |
+
Convert a file: URL to a path.
|
| 29 |
+
"""
|
| 30 |
+
assert url.startswith(
|
| 31 |
+
"file:"
|
| 32 |
+
), f"You can only turn file: urls into filenames (not {url!r})"
|
| 33 |
+
|
| 34 |
+
_, netloc, path, _, _ = urllib.parse.urlsplit(url)
|
| 35 |
+
|
| 36 |
+
if not netloc or netloc == "localhost":
|
| 37 |
+
# According to RFC 8089, same as empty authority.
|
| 38 |
+
netloc = ""
|
| 39 |
+
elif WINDOWS:
|
| 40 |
+
# If we have a UNC path, prepend UNC share notation.
|
| 41 |
+
netloc = "\\\\" + netloc
|
| 42 |
+
else:
|
| 43 |
+
raise ValueError(
|
| 44 |
+
f"non-local file URIs are not supported on this platform: {url!r}"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
path = urllib.request.url2pathname(netloc + path)
|
| 48 |
+
|
| 49 |
+
# On Windows, urlsplit parses the path as something like "/C:/Users/foo".
|
| 50 |
+
# This creates issues for path-related functions like io.open(), so we try
|
| 51 |
+
# to detect and strip the leading slash.
|
| 52 |
+
if (
|
| 53 |
+
WINDOWS
|
| 54 |
+
and not netloc # Not UNC.
|
| 55 |
+
and len(path) >= 3
|
| 56 |
+
and path[0] == "/" # Leading slash to strip.
|
| 57 |
+
and path[1] in string.ascii_letters # Drive letter.
|
| 58 |
+
and path[2:4] in (":", ":/") # Colon + end of string, or colon + absolute path.
|
| 59 |
+
):
|
| 60 |
+
path = path[1:]
|
| 61 |
+
|
| 62 |
+
return path
|
.venv/Lib/site-packages/pip/_internal/utils/virtualenv.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import re
|
| 4 |
+
import site
|
| 5 |
+
import sys
|
| 6 |
+
from typing import List, Optional
|
| 7 |
+
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
_INCLUDE_SYSTEM_SITE_PACKAGES_REGEX = re.compile(
|
| 10 |
+
r"include-system-site-packages\s*=\s*(?P<value>true|false)"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _running_under_venv() -> bool:
|
| 15 |
+
"""Checks if sys.base_prefix and sys.prefix match.
|
| 16 |
+
|
| 17 |
+
This handles PEP 405 compliant virtual environments.
|
| 18 |
+
"""
|
| 19 |
+
return sys.prefix != getattr(sys, "base_prefix", sys.prefix)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _running_under_legacy_virtualenv() -> bool:
|
| 23 |
+
"""Checks if sys.real_prefix is set.
|
| 24 |
+
|
| 25 |
+
This handles virtual environments created with pypa's virtualenv.
|
| 26 |
+
"""
|
| 27 |
+
# pypa/virtualenv case
|
| 28 |
+
return hasattr(sys, "real_prefix")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def running_under_virtualenv() -> bool:
|
| 32 |
+
"""True if we're running inside a virtual environment, False otherwise."""
|
| 33 |
+
return _running_under_venv() or _running_under_legacy_virtualenv()
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _get_pyvenv_cfg_lines() -> Optional[List[str]]:
|
| 37 |
+
"""Reads {sys.prefix}/pyvenv.cfg and returns its contents as list of lines
|
| 38 |
+
|
| 39 |
+
Returns None, if it could not read/access the file.
|
| 40 |
+
"""
|
| 41 |
+
pyvenv_cfg_file = os.path.join(sys.prefix, "pyvenv.cfg")
|
| 42 |
+
try:
|
| 43 |
+
# Although PEP 405 does not specify, the built-in venv module always
|
| 44 |
+
# writes with UTF-8. (pypa/pip#8717)
|
| 45 |
+
with open(pyvenv_cfg_file, encoding="utf-8") as f:
|
| 46 |
+
return f.read().splitlines() # avoids trailing newlines
|
| 47 |
+
except OSError:
|
| 48 |
+
return None
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _no_global_under_venv() -> bool:
|
| 52 |
+
"""Check `{sys.prefix}/pyvenv.cfg` for system site-packages inclusion
|
| 53 |
+
|
| 54 |
+
PEP 405 specifies that when system site-packages are not supposed to be
|
| 55 |
+
visible from a virtual environment, `pyvenv.cfg` must contain the following
|
| 56 |
+
line:
|
| 57 |
+
|
| 58 |
+
include-system-site-packages = false
|
| 59 |
+
|
| 60 |
+
Additionally, log a warning if accessing the file fails.
|
| 61 |
+
"""
|
| 62 |
+
cfg_lines = _get_pyvenv_cfg_lines()
|
| 63 |
+
if cfg_lines is None:
|
| 64 |
+
# We're not in a "sane" venv, so assume there is no system
|
| 65 |
+
# site-packages access (since that's PEP 405's default state).
|
| 66 |
+
logger.warning(
|
| 67 |
+
"Could not access 'pyvenv.cfg' despite a virtual environment "
|
| 68 |
+
"being active. Assuming global site-packages is not accessible "
|
| 69 |
+
"in this environment."
|
| 70 |
+
)
|
| 71 |
+
return True
|
| 72 |
+
|
| 73 |
+
for line in cfg_lines:
|
| 74 |
+
match = _INCLUDE_SYSTEM_SITE_PACKAGES_REGEX.match(line)
|
| 75 |
+
if match is not None and match.group("value") == "false":
|
| 76 |
+
return True
|
| 77 |
+
return False
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _no_global_under_legacy_virtualenv() -> bool:
|
| 81 |
+
"""Check if "no-global-site-packages.txt" exists beside site.py
|
| 82 |
+
|
| 83 |
+
This mirrors logic in pypa/virtualenv for determining whether system
|
| 84 |
+
site-packages are visible in the virtual environment.
|
| 85 |
+
"""
|
| 86 |
+
site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
|
| 87 |
+
no_global_site_packages_file = os.path.join(
|
| 88 |
+
site_mod_dir,
|
| 89 |
+
"no-global-site-packages.txt",
|
| 90 |
+
)
|
| 91 |
+
return os.path.exists(no_global_site_packages_file)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def virtualenv_no_global() -> bool:
|
| 95 |
+
"""Returns a boolean, whether running in venv with no system site-packages."""
|
| 96 |
+
# PEP 405 compliance needs to be checked first since virtualenv >=20 would
|
| 97 |
+
# return True for both checks, but is only able to use the PEP 405 config.
|
| 98 |
+
if _running_under_venv():
|
| 99 |
+
return _no_global_under_venv()
|
| 100 |
+
|
| 101 |
+
if _running_under_legacy_virtualenv():
|
| 102 |
+
return _no_global_under_legacy_virtualenv()
|
| 103 |
+
|
| 104 |
+
return False
|
.venv/Lib/site-packages/pip/_internal/utils/wheel.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Support functions for working with wheel files.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
from email.message import Message
|
| 6 |
+
from email.parser import Parser
|
| 7 |
+
from typing import Tuple
|
| 8 |
+
from zipfile import BadZipFile, ZipFile
|
| 9 |
+
|
| 10 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 11 |
+
|
| 12 |
+
from pip._internal.exceptions import UnsupportedWheel
|
| 13 |
+
|
| 14 |
+
VERSION_COMPATIBLE = (1, 0)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
logger = logging.getLogger(__name__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def parse_wheel(wheel_zip: ZipFile, name: str) -> Tuple[str, Message]:
|
| 21 |
+
"""Extract information from the provided wheel, ensuring it meets basic
|
| 22 |
+
standards.
|
| 23 |
+
|
| 24 |
+
Returns the name of the .dist-info directory and the parsed WHEEL metadata.
|
| 25 |
+
"""
|
| 26 |
+
try:
|
| 27 |
+
info_dir = wheel_dist_info_dir(wheel_zip, name)
|
| 28 |
+
metadata = wheel_metadata(wheel_zip, info_dir)
|
| 29 |
+
version = wheel_version(metadata)
|
| 30 |
+
except UnsupportedWheel as e:
|
| 31 |
+
raise UnsupportedWheel("{} has an invalid wheel, {}".format(name, str(e)))
|
| 32 |
+
|
| 33 |
+
check_compatibility(version, name)
|
| 34 |
+
|
| 35 |
+
return info_dir, metadata
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def wheel_dist_info_dir(source: ZipFile, name: str) -> str:
|
| 39 |
+
"""Returns the name of the contained .dist-info directory.
|
| 40 |
+
|
| 41 |
+
Raises AssertionError or UnsupportedWheel if not found, >1 found, or
|
| 42 |
+
it doesn't match the provided name.
|
| 43 |
+
"""
|
| 44 |
+
# Zip file path separators must be /
|
| 45 |
+
subdirs = {p.split("/", 1)[0] for p in source.namelist()}
|
| 46 |
+
|
| 47 |
+
info_dirs = [s for s in subdirs if s.endswith(".dist-info")]
|
| 48 |
+
|
| 49 |
+
if not info_dirs:
|
| 50 |
+
raise UnsupportedWheel(".dist-info directory not found")
|
| 51 |
+
|
| 52 |
+
if len(info_dirs) > 1:
|
| 53 |
+
raise UnsupportedWheel(
|
| 54 |
+
"multiple .dist-info directories found: {}".format(", ".join(info_dirs))
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
info_dir = info_dirs[0]
|
| 58 |
+
|
| 59 |
+
info_dir_name = canonicalize_name(info_dir)
|
| 60 |
+
canonical_name = canonicalize_name(name)
|
| 61 |
+
if not info_dir_name.startswith(canonical_name):
|
| 62 |
+
raise UnsupportedWheel(
|
| 63 |
+
".dist-info directory {!r} does not start with {!r}".format(
|
| 64 |
+
info_dir, canonical_name
|
| 65 |
+
)
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
return info_dir
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def read_wheel_metadata_file(source: ZipFile, path: str) -> bytes:
|
| 72 |
+
try:
|
| 73 |
+
return source.read(path)
|
| 74 |
+
# BadZipFile for general corruption, KeyError for missing entry,
|
| 75 |
+
# and RuntimeError for password-protected files
|
| 76 |
+
except (BadZipFile, KeyError, RuntimeError) as e:
|
| 77 |
+
raise UnsupportedWheel(f"could not read {path!r} file: {e!r}")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def wheel_metadata(source: ZipFile, dist_info_dir: str) -> Message:
|
| 81 |
+
"""Return the WHEEL metadata of an extracted wheel, if possible.
|
| 82 |
+
Otherwise, raise UnsupportedWheel.
|
| 83 |
+
"""
|
| 84 |
+
path = f"{dist_info_dir}/WHEEL"
|
| 85 |
+
# Zip file path separators must be /
|
| 86 |
+
wheel_contents = read_wheel_metadata_file(source, path)
|
| 87 |
+
|
| 88 |
+
try:
|
| 89 |
+
wheel_text = wheel_contents.decode()
|
| 90 |
+
except UnicodeDecodeError as e:
|
| 91 |
+
raise UnsupportedWheel(f"error decoding {path!r}: {e!r}")
|
| 92 |
+
|
| 93 |
+
# FeedParser (used by Parser) does not raise any exceptions. The returned
|
| 94 |
+
# message may have .defects populated, but for backwards-compatibility we
|
| 95 |
+
# currently ignore them.
|
| 96 |
+
return Parser().parsestr(wheel_text)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def wheel_version(wheel_data: Message) -> Tuple[int, ...]:
|
| 100 |
+
"""Given WHEEL metadata, return the parsed Wheel-Version.
|
| 101 |
+
Otherwise, raise UnsupportedWheel.
|
| 102 |
+
"""
|
| 103 |
+
version_text = wheel_data["Wheel-Version"]
|
| 104 |
+
if version_text is None:
|
| 105 |
+
raise UnsupportedWheel("WHEEL is missing Wheel-Version")
|
| 106 |
+
|
| 107 |
+
version = version_text.strip()
|
| 108 |
+
|
| 109 |
+
try:
|
| 110 |
+
return tuple(map(int, version.split(".")))
|
| 111 |
+
except ValueError:
|
| 112 |
+
raise UnsupportedWheel(f"invalid Wheel-Version: {version!r}")
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def check_compatibility(version: Tuple[int, ...], name: str) -> None:
|
| 116 |
+
"""Raises errors or warns if called with an incompatible Wheel-Version.
|
| 117 |
+
|
| 118 |
+
pip should refuse to install a Wheel-Version that's a major series
|
| 119 |
+
ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
|
| 120 |
+
installing a version only minor version ahead (e.g 1.2 > 1.1).
|
| 121 |
+
|
| 122 |
+
version: a 2-tuple representing a Wheel-Version (Major, Minor)
|
| 123 |
+
name: name of wheel or package to raise exception about
|
| 124 |
+
|
| 125 |
+
:raises UnsupportedWheel: when an incompatible Wheel-Version is given
|
| 126 |
+
"""
|
| 127 |
+
if version[0] > VERSION_COMPATIBLE[0]:
|
| 128 |
+
raise UnsupportedWheel(
|
| 129 |
+
"{}'s Wheel-Version ({}) is not compatible with this version "
|
| 130 |
+
"of pip".format(name, ".".join(map(str, version)))
|
| 131 |
+
)
|
| 132 |
+
elif version > VERSION_COMPATIBLE:
|
| 133 |
+
logger.warning(
|
| 134 |
+
"Installing from a newer Wheel-Version (%s)",
|
| 135 |
+
".".join(map(str, version)),
|
| 136 |
+
)
|
.venv/Lib/site-packages/pip/_internal/vcs/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Expose a limited set of classes and functions so callers outside of
|
| 2 |
+
# the vcs package don't need to import deeper than `pip._internal.vcs`.
|
| 3 |
+
# (The test directory may still need to import from a vcs sub-package.)
|
| 4 |
+
# Import all vcs modules to register each VCS in the VcsSupport object.
|
| 5 |
+
import pip._internal.vcs.bazaar
|
| 6 |
+
import pip._internal.vcs.git
|
| 7 |
+
import pip._internal.vcs.mercurial
|
| 8 |
+
import pip._internal.vcs.subversion # noqa: F401
|
| 9 |
+
from pip._internal.vcs.versioncontrol import ( # noqa: F401
|
| 10 |
+
RemoteNotFoundError,
|
| 11 |
+
RemoteNotValidError,
|
| 12 |
+
is_url,
|
| 13 |
+
make_vcs_requirement_url,
|
| 14 |
+
vcs,
|
| 15 |
+
)
|
.venv/Lib/site-packages/pip/_internal/vcs/bazaar.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from typing import List, Optional, Tuple
|
| 3 |
+
|
| 4 |
+
from pip._internal.utils.misc import HiddenText, display_path
|
| 5 |
+
from pip._internal.utils.subprocess import make_command
|
| 6 |
+
from pip._internal.utils.urls import path_to_url
|
| 7 |
+
from pip._internal.vcs.versioncontrol import (
|
| 8 |
+
AuthInfo,
|
| 9 |
+
RemoteNotFoundError,
|
| 10 |
+
RevOptions,
|
| 11 |
+
VersionControl,
|
| 12 |
+
vcs,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
logger = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Bazaar(VersionControl):
|
| 19 |
+
name = "bzr"
|
| 20 |
+
dirname = ".bzr"
|
| 21 |
+
repo_name = "branch"
|
| 22 |
+
schemes = (
|
| 23 |
+
"bzr+http",
|
| 24 |
+
"bzr+https",
|
| 25 |
+
"bzr+ssh",
|
| 26 |
+
"bzr+sftp",
|
| 27 |
+
"bzr+ftp",
|
| 28 |
+
"bzr+lp",
|
| 29 |
+
"bzr+file",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def get_base_rev_args(rev: str) -> List[str]:
|
| 34 |
+
return ["-r", rev]
|
| 35 |
+
|
| 36 |
+
def fetch_new(
|
| 37 |
+
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
| 38 |
+
) -> None:
|
| 39 |
+
rev_display = rev_options.to_display()
|
| 40 |
+
logger.info(
|
| 41 |
+
"Checking out %s%s to %s",
|
| 42 |
+
url,
|
| 43 |
+
rev_display,
|
| 44 |
+
display_path(dest),
|
| 45 |
+
)
|
| 46 |
+
if verbosity <= 0:
|
| 47 |
+
flag = "--quiet"
|
| 48 |
+
elif verbosity == 1:
|
| 49 |
+
flag = ""
|
| 50 |
+
else:
|
| 51 |
+
flag = f"-{'v'*verbosity}"
|
| 52 |
+
cmd_args = make_command(
|
| 53 |
+
"checkout", "--lightweight", flag, rev_options.to_args(), url, dest
|
| 54 |
+
)
|
| 55 |
+
self.run_command(cmd_args)
|
| 56 |
+
|
| 57 |
+
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 58 |
+
self.run_command(make_command("switch", url), cwd=dest)
|
| 59 |
+
|
| 60 |
+
def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 61 |
+
output = self.run_command(
|
| 62 |
+
make_command("info"), show_stdout=False, stdout_only=True, cwd=dest
|
| 63 |
+
)
|
| 64 |
+
if output.startswith("Standalone "):
|
| 65 |
+
# Older versions of pip used to create standalone branches.
|
| 66 |
+
# Convert the standalone branch to a checkout by calling "bzr bind".
|
| 67 |
+
cmd_args = make_command("bind", "-q", url)
|
| 68 |
+
self.run_command(cmd_args, cwd=dest)
|
| 69 |
+
|
| 70 |
+
cmd_args = make_command("update", "-q", rev_options.to_args())
|
| 71 |
+
self.run_command(cmd_args, cwd=dest)
|
| 72 |
+
|
| 73 |
+
@classmethod
|
| 74 |
+
def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
|
| 75 |
+
# hotfix the URL scheme after removing bzr+ from bzr+ssh:// re-add it
|
| 76 |
+
url, rev, user_pass = super().get_url_rev_and_auth(url)
|
| 77 |
+
if url.startswith("ssh://"):
|
| 78 |
+
url = "bzr+" + url
|
| 79 |
+
return url, rev, user_pass
|
| 80 |
+
|
| 81 |
+
@classmethod
|
| 82 |
+
def get_remote_url(cls, location: str) -> str:
|
| 83 |
+
urls = cls.run_command(
|
| 84 |
+
["info"], show_stdout=False, stdout_only=True, cwd=location
|
| 85 |
+
)
|
| 86 |
+
for line in urls.splitlines():
|
| 87 |
+
line = line.strip()
|
| 88 |
+
for x in ("checkout of branch: ", "parent branch: "):
|
| 89 |
+
if line.startswith(x):
|
| 90 |
+
repo = line.split(x)[1]
|
| 91 |
+
if cls._is_local_repository(repo):
|
| 92 |
+
return path_to_url(repo)
|
| 93 |
+
return repo
|
| 94 |
+
raise RemoteNotFoundError
|
| 95 |
+
|
| 96 |
+
@classmethod
|
| 97 |
+
def get_revision(cls, location: str) -> str:
|
| 98 |
+
revision = cls.run_command(
|
| 99 |
+
["revno"],
|
| 100 |
+
show_stdout=False,
|
| 101 |
+
stdout_only=True,
|
| 102 |
+
cwd=location,
|
| 103 |
+
)
|
| 104 |
+
return revision.splitlines()[-1]
|
| 105 |
+
|
| 106 |
+
@classmethod
|
| 107 |
+
def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
|
| 108 |
+
"""Always assume the versions don't match"""
|
| 109 |
+
return False
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
vcs.register(Bazaar)
|
.venv/Lib/site-packages/pip/_internal/vcs/git.py
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os.path
|
| 3 |
+
import pathlib
|
| 4 |
+
import re
|
| 5 |
+
import urllib.parse
|
| 6 |
+
import urllib.request
|
| 7 |
+
from typing import List, Optional, Tuple
|
| 8 |
+
|
| 9 |
+
from pip._internal.exceptions import BadCommand, InstallationError
|
| 10 |
+
from pip._internal.utils.misc import HiddenText, display_path, hide_url
|
| 11 |
+
from pip._internal.utils.subprocess import make_command
|
| 12 |
+
from pip._internal.vcs.versioncontrol import (
|
| 13 |
+
AuthInfo,
|
| 14 |
+
RemoteNotFoundError,
|
| 15 |
+
RemoteNotValidError,
|
| 16 |
+
RevOptions,
|
| 17 |
+
VersionControl,
|
| 18 |
+
find_path_to_project_root_from_repo_root,
|
| 19 |
+
vcs,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
urlsplit = urllib.parse.urlsplit
|
| 23 |
+
urlunsplit = urllib.parse.urlunsplit
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
logger = logging.getLogger(__name__)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
GIT_VERSION_REGEX = re.compile(
|
| 30 |
+
r"^git version " # Prefix.
|
| 31 |
+
r"(\d+)" # Major.
|
| 32 |
+
r"\.(\d+)" # Dot, minor.
|
| 33 |
+
r"(?:\.(\d+))?" # Optional dot, patch.
|
| 34 |
+
r".*$" # Suffix, including any pre- and post-release segments we don't care about.
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
HASH_REGEX = re.compile("^[a-fA-F0-9]{40}$")
|
| 38 |
+
|
| 39 |
+
# SCP (Secure copy protocol) shorthand. e.g. 'git@example.com:foo/bar.git'
|
| 40 |
+
SCP_REGEX = re.compile(
|
| 41 |
+
r"""^
|
| 42 |
+
# Optional user, e.g. 'git@'
|
| 43 |
+
(\w+@)?
|
| 44 |
+
# Server, e.g. 'github.com'.
|
| 45 |
+
([^/:]+):
|
| 46 |
+
# The server-side path. e.g. 'user/project.git'. Must start with an
|
| 47 |
+
# alphanumeric character so as not to be confusable with a Windows paths
|
| 48 |
+
# like 'C:/foo/bar' or 'C:\foo\bar'.
|
| 49 |
+
(\w[^:]*)
|
| 50 |
+
$""",
|
| 51 |
+
re.VERBOSE,
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def looks_like_hash(sha: str) -> bool:
|
| 56 |
+
return bool(HASH_REGEX.match(sha))
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class Git(VersionControl):
|
| 60 |
+
name = "git"
|
| 61 |
+
dirname = ".git"
|
| 62 |
+
repo_name = "clone"
|
| 63 |
+
schemes = (
|
| 64 |
+
"git+http",
|
| 65 |
+
"git+https",
|
| 66 |
+
"git+ssh",
|
| 67 |
+
"git+git",
|
| 68 |
+
"git+file",
|
| 69 |
+
)
|
| 70 |
+
# Prevent the user's environment variables from interfering with pip:
|
| 71 |
+
# https://github.com/pypa/pip/issues/1130
|
| 72 |
+
unset_environ = ("GIT_DIR", "GIT_WORK_TREE")
|
| 73 |
+
default_arg_rev = "HEAD"
|
| 74 |
+
|
| 75 |
+
@staticmethod
|
| 76 |
+
def get_base_rev_args(rev: str) -> List[str]:
|
| 77 |
+
return [rev]
|
| 78 |
+
|
| 79 |
+
def is_immutable_rev_checkout(self, url: str, dest: str) -> bool:
|
| 80 |
+
_, rev_options = self.get_url_rev_options(hide_url(url))
|
| 81 |
+
if not rev_options.rev:
|
| 82 |
+
return False
|
| 83 |
+
if not self.is_commit_id_equal(dest, rev_options.rev):
|
| 84 |
+
# the current commit is different from rev,
|
| 85 |
+
# which means rev was something else than a commit hash
|
| 86 |
+
return False
|
| 87 |
+
# return False in the rare case rev is both a commit hash
|
| 88 |
+
# and a tag or a branch; we don't want to cache in that case
|
| 89 |
+
# because that branch/tag could point to something else in the future
|
| 90 |
+
is_tag_or_branch = bool(self.get_revision_sha(dest, rev_options.rev)[0])
|
| 91 |
+
return not is_tag_or_branch
|
| 92 |
+
|
| 93 |
+
def get_git_version(self) -> Tuple[int, ...]:
|
| 94 |
+
version = self.run_command(
|
| 95 |
+
["version"],
|
| 96 |
+
command_desc="git version",
|
| 97 |
+
show_stdout=False,
|
| 98 |
+
stdout_only=True,
|
| 99 |
+
)
|
| 100 |
+
match = GIT_VERSION_REGEX.match(version)
|
| 101 |
+
if not match:
|
| 102 |
+
logger.warning("Can't parse git version: %s", version)
|
| 103 |
+
return ()
|
| 104 |
+
return tuple(int(c) for c in match.groups())
|
| 105 |
+
|
| 106 |
+
@classmethod
|
| 107 |
+
def get_current_branch(cls, location: str) -> Optional[str]:
|
| 108 |
+
"""
|
| 109 |
+
Return the current branch, or None if HEAD isn't at a branch
|
| 110 |
+
(e.g. detached HEAD).
|
| 111 |
+
"""
|
| 112 |
+
# git-symbolic-ref exits with empty stdout if "HEAD" is a detached
|
| 113 |
+
# HEAD rather than a symbolic ref. In addition, the -q causes the
|
| 114 |
+
# command to exit with status code 1 instead of 128 in this case
|
| 115 |
+
# and to suppress the message to stderr.
|
| 116 |
+
args = ["symbolic-ref", "-q", "HEAD"]
|
| 117 |
+
output = cls.run_command(
|
| 118 |
+
args,
|
| 119 |
+
extra_ok_returncodes=(1,),
|
| 120 |
+
show_stdout=False,
|
| 121 |
+
stdout_only=True,
|
| 122 |
+
cwd=location,
|
| 123 |
+
)
|
| 124 |
+
ref = output.strip()
|
| 125 |
+
|
| 126 |
+
if ref.startswith("refs/heads/"):
|
| 127 |
+
return ref[len("refs/heads/") :]
|
| 128 |
+
|
| 129 |
+
return None
|
| 130 |
+
|
| 131 |
+
@classmethod
|
| 132 |
+
def get_revision_sha(cls, dest: str, rev: str) -> Tuple[Optional[str], bool]:
|
| 133 |
+
"""
|
| 134 |
+
Return (sha_or_none, is_branch), where sha_or_none is a commit hash
|
| 135 |
+
if the revision names a remote branch or tag, otherwise None.
|
| 136 |
+
|
| 137 |
+
Args:
|
| 138 |
+
dest: the repository directory.
|
| 139 |
+
rev: the revision name.
|
| 140 |
+
"""
|
| 141 |
+
# Pass rev to pre-filter the list.
|
| 142 |
+
output = cls.run_command(
|
| 143 |
+
["show-ref", rev],
|
| 144 |
+
cwd=dest,
|
| 145 |
+
show_stdout=False,
|
| 146 |
+
stdout_only=True,
|
| 147 |
+
on_returncode="ignore",
|
| 148 |
+
)
|
| 149 |
+
refs = {}
|
| 150 |
+
# NOTE: We do not use splitlines here since that would split on other
|
| 151 |
+
# unicode separators, which can be maliciously used to install a
|
| 152 |
+
# different revision.
|
| 153 |
+
for line in output.strip().split("\n"):
|
| 154 |
+
line = line.rstrip("\r")
|
| 155 |
+
if not line:
|
| 156 |
+
continue
|
| 157 |
+
try:
|
| 158 |
+
ref_sha, ref_name = line.split(" ", maxsplit=2)
|
| 159 |
+
except ValueError:
|
| 160 |
+
# Include the offending line to simplify troubleshooting if
|
| 161 |
+
# this error ever occurs.
|
| 162 |
+
raise ValueError(f"unexpected show-ref line: {line!r}")
|
| 163 |
+
|
| 164 |
+
refs[ref_name] = ref_sha
|
| 165 |
+
|
| 166 |
+
branch_ref = f"refs/remotes/origin/{rev}"
|
| 167 |
+
tag_ref = f"refs/tags/{rev}"
|
| 168 |
+
|
| 169 |
+
sha = refs.get(branch_ref)
|
| 170 |
+
if sha is not None:
|
| 171 |
+
return (sha, True)
|
| 172 |
+
|
| 173 |
+
sha = refs.get(tag_ref)
|
| 174 |
+
|
| 175 |
+
return (sha, False)
|
| 176 |
+
|
| 177 |
+
@classmethod
|
| 178 |
+
def _should_fetch(cls, dest: str, rev: str) -> bool:
|
| 179 |
+
"""
|
| 180 |
+
Return true if rev is a ref or is a commit that we don't have locally.
|
| 181 |
+
|
| 182 |
+
Branches and tags are not considered in this method because they are
|
| 183 |
+
assumed to be always available locally (which is a normal outcome of
|
| 184 |
+
``git clone`` and ``git fetch --tags``).
|
| 185 |
+
"""
|
| 186 |
+
if rev.startswith("refs/"):
|
| 187 |
+
# Always fetch remote refs.
|
| 188 |
+
return True
|
| 189 |
+
|
| 190 |
+
if not looks_like_hash(rev):
|
| 191 |
+
# Git fetch would fail with abbreviated commits.
|
| 192 |
+
return False
|
| 193 |
+
|
| 194 |
+
if cls.has_commit(dest, rev):
|
| 195 |
+
# Don't fetch if we have the commit locally.
|
| 196 |
+
return False
|
| 197 |
+
|
| 198 |
+
return True
|
| 199 |
+
|
| 200 |
+
@classmethod
|
| 201 |
+
def resolve_revision(
|
| 202 |
+
cls, dest: str, url: HiddenText, rev_options: RevOptions
|
| 203 |
+
) -> RevOptions:
|
| 204 |
+
"""
|
| 205 |
+
Resolve a revision to a new RevOptions object with the SHA1 of the
|
| 206 |
+
branch, tag, or ref if found.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
rev_options: a RevOptions object.
|
| 210 |
+
"""
|
| 211 |
+
rev = rev_options.arg_rev
|
| 212 |
+
# The arg_rev property's implementation for Git ensures that the
|
| 213 |
+
# rev return value is always non-None.
|
| 214 |
+
assert rev is not None
|
| 215 |
+
|
| 216 |
+
sha, is_branch = cls.get_revision_sha(dest, rev)
|
| 217 |
+
|
| 218 |
+
if sha is not None:
|
| 219 |
+
rev_options = rev_options.make_new(sha)
|
| 220 |
+
rev_options.branch_name = rev if is_branch else None
|
| 221 |
+
|
| 222 |
+
return rev_options
|
| 223 |
+
|
| 224 |
+
# Do not show a warning for the common case of something that has
|
| 225 |
+
# the form of a Git commit hash.
|
| 226 |
+
if not looks_like_hash(rev):
|
| 227 |
+
logger.warning(
|
| 228 |
+
"Did not find branch or tag '%s', assuming revision or ref.",
|
| 229 |
+
rev,
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
if not cls._should_fetch(dest, rev):
|
| 233 |
+
return rev_options
|
| 234 |
+
|
| 235 |
+
# fetch the requested revision
|
| 236 |
+
cls.run_command(
|
| 237 |
+
make_command("fetch", "-q", url, rev_options.to_args()),
|
| 238 |
+
cwd=dest,
|
| 239 |
+
)
|
| 240 |
+
# Change the revision to the SHA of the ref we fetched
|
| 241 |
+
sha = cls.get_revision(dest, rev="FETCH_HEAD")
|
| 242 |
+
rev_options = rev_options.make_new(sha)
|
| 243 |
+
|
| 244 |
+
return rev_options
|
| 245 |
+
|
| 246 |
+
@classmethod
|
| 247 |
+
def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
|
| 248 |
+
"""
|
| 249 |
+
Return whether the current commit hash equals the given name.
|
| 250 |
+
|
| 251 |
+
Args:
|
| 252 |
+
dest: the repository directory.
|
| 253 |
+
name: a string name.
|
| 254 |
+
"""
|
| 255 |
+
if not name:
|
| 256 |
+
# Then avoid an unnecessary subprocess call.
|
| 257 |
+
return False
|
| 258 |
+
|
| 259 |
+
return cls.get_revision(dest) == name
|
| 260 |
+
|
| 261 |
+
def fetch_new(
|
| 262 |
+
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
| 263 |
+
) -> None:
|
| 264 |
+
rev_display = rev_options.to_display()
|
| 265 |
+
logger.info("Cloning %s%s to %s", url, rev_display, display_path(dest))
|
| 266 |
+
if verbosity <= 0:
|
| 267 |
+
flags: Tuple[str, ...] = ("--quiet",)
|
| 268 |
+
elif verbosity == 1:
|
| 269 |
+
flags = ()
|
| 270 |
+
else:
|
| 271 |
+
flags = ("--verbose", "--progress")
|
| 272 |
+
if self.get_git_version() >= (2, 17):
|
| 273 |
+
# Git added support for partial clone in 2.17
|
| 274 |
+
# https://git-scm.com/docs/partial-clone
|
| 275 |
+
# Speeds up cloning by functioning without a complete copy of repository
|
| 276 |
+
self.run_command(
|
| 277 |
+
make_command(
|
| 278 |
+
"clone",
|
| 279 |
+
"--filter=blob:none",
|
| 280 |
+
*flags,
|
| 281 |
+
url,
|
| 282 |
+
dest,
|
| 283 |
+
)
|
| 284 |
+
)
|
| 285 |
+
else:
|
| 286 |
+
self.run_command(make_command("clone", *flags, url, dest))
|
| 287 |
+
|
| 288 |
+
if rev_options.rev:
|
| 289 |
+
# Then a specific revision was requested.
|
| 290 |
+
rev_options = self.resolve_revision(dest, url, rev_options)
|
| 291 |
+
branch_name = getattr(rev_options, "branch_name", None)
|
| 292 |
+
logger.debug("Rev options %s, branch_name %s", rev_options, branch_name)
|
| 293 |
+
if branch_name is None:
|
| 294 |
+
# Only do a checkout if the current commit id doesn't match
|
| 295 |
+
# the requested revision.
|
| 296 |
+
if not self.is_commit_id_equal(dest, rev_options.rev):
|
| 297 |
+
cmd_args = make_command(
|
| 298 |
+
"checkout",
|
| 299 |
+
"-q",
|
| 300 |
+
rev_options.to_args(),
|
| 301 |
+
)
|
| 302 |
+
self.run_command(cmd_args, cwd=dest)
|
| 303 |
+
elif self.get_current_branch(dest) != branch_name:
|
| 304 |
+
# Then a specific branch was requested, and that branch
|
| 305 |
+
# is not yet checked out.
|
| 306 |
+
track_branch = f"origin/{branch_name}"
|
| 307 |
+
cmd_args = [
|
| 308 |
+
"checkout",
|
| 309 |
+
"-b",
|
| 310 |
+
branch_name,
|
| 311 |
+
"--track",
|
| 312 |
+
track_branch,
|
| 313 |
+
]
|
| 314 |
+
self.run_command(cmd_args, cwd=dest)
|
| 315 |
+
else:
|
| 316 |
+
sha = self.get_revision(dest)
|
| 317 |
+
rev_options = rev_options.make_new(sha)
|
| 318 |
+
|
| 319 |
+
logger.info("Resolved %s to commit %s", url, rev_options.rev)
|
| 320 |
+
|
| 321 |
+
#: repo may contain submodules
|
| 322 |
+
self.update_submodules(dest)
|
| 323 |
+
|
| 324 |
+
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 325 |
+
self.run_command(
|
| 326 |
+
make_command("config", "remote.origin.url", url),
|
| 327 |
+
cwd=dest,
|
| 328 |
+
)
|
| 329 |
+
cmd_args = make_command("checkout", "-q", rev_options.to_args())
|
| 330 |
+
self.run_command(cmd_args, cwd=dest)
|
| 331 |
+
|
| 332 |
+
self.update_submodules(dest)
|
| 333 |
+
|
| 334 |
+
def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 335 |
+
# First fetch changes from the default remote
|
| 336 |
+
if self.get_git_version() >= (1, 9):
|
| 337 |
+
# fetch tags in addition to everything else
|
| 338 |
+
self.run_command(["fetch", "-q", "--tags"], cwd=dest)
|
| 339 |
+
else:
|
| 340 |
+
self.run_command(["fetch", "-q"], cwd=dest)
|
| 341 |
+
# Then reset to wanted revision (maybe even origin/master)
|
| 342 |
+
rev_options = self.resolve_revision(dest, url, rev_options)
|
| 343 |
+
cmd_args = make_command("reset", "--hard", "-q", rev_options.to_args())
|
| 344 |
+
self.run_command(cmd_args, cwd=dest)
|
| 345 |
+
#: update submodules
|
| 346 |
+
self.update_submodules(dest)
|
| 347 |
+
|
| 348 |
+
@classmethod
|
| 349 |
+
def get_remote_url(cls, location: str) -> str:
|
| 350 |
+
"""
|
| 351 |
+
Return URL of the first remote encountered.
|
| 352 |
+
|
| 353 |
+
Raises RemoteNotFoundError if the repository does not have a remote
|
| 354 |
+
url configured.
|
| 355 |
+
"""
|
| 356 |
+
# We need to pass 1 for extra_ok_returncodes since the command
|
| 357 |
+
# exits with return code 1 if there are no matching lines.
|
| 358 |
+
stdout = cls.run_command(
|
| 359 |
+
["config", "--get-regexp", r"remote\..*\.url"],
|
| 360 |
+
extra_ok_returncodes=(1,),
|
| 361 |
+
show_stdout=False,
|
| 362 |
+
stdout_only=True,
|
| 363 |
+
cwd=location,
|
| 364 |
+
)
|
| 365 |
+
remotes = stdout.splitlines()
|
| 366 |
+
try:
|
| 367 |
+
found_remote = remotes[0]
|
| 368 |
+
except IndexError:
|
| 369 |
+
raise RemoteNotFoundError
|
| 370 |
+
|
| 371 |
+
for remote in remotes:
|
| 372 |
+
if remote.startswith("remote.origin.url "):
|
| 373 |
+
found_remote = remote
|
| 374 |
+
break
|
| 375 |
+
url = found_remote.split(" ")[1]
|
| 376 |
+
return cls._git_remote_to_pip_url(url.strip())
|
| 377 |
+
|
| 378 |
+
@staticmethod
|
| 379 |
+
def _git_remote_to_pip_url(url: str) -> str:
|
| 380 |
+
"""
|
| 381 |
+
Convert a remote url from what git uses to what pip accepts.
|
| 382 |
+
|
| 383 |
+
There are 3 legal forms **url** may take:
|
| 384 |
+
|
| 385 |
+
1. A fully qualified url: ssh://git@example.com/foo/bar.git
|
| 386 |
+
2. A local project.git folder: /path/to/bare/repository.git
|
| 387 |
+
3. SCP shorthand for form 1: git@example.com:foo/bar.git
|
| 388 |
+
|
| 389 |
+
Form 1 is output as-is. Form 2 must be converted to URI and form 3 must
|
| 390 |
+
be converted to form 1.
|
| 391 |
+
|
| 392 |
+
See the corresponding test test_git_remote_url_to_pip() for examples of
|
| 393 |
+
sample inputs/outputs.
|
| 394 |
+
"""
|
| 395 |
+
if re.match(r"\w+://", url):
|
| 396 |
+
# This is already valid. Pass it though as-is.
|
| 397 |
+
return url
|
| 398 |
+
if os.path.exists(url):
|
| 399 |
+
# A local bare remote (git clone --mirror).
|
| 400 |
+
# Needs a file:// prefix.
|
| 401 |
+
return pathlib.PurePath(url).as_uri()
|
| 402 |
+
scp_match = SCP_REGEX.match(url)
|
| 403 |
+
if scp_match:
|
| 404 |
+
# Add an ssh:// prefix and replace the ':' with a '/'.
|
| 405 |
+
return scp_match.expand(r"ssh://\1\2/\3")
|
| 406 |
+
# Otherwise, bail out.
|
| 407 |
+
raise RemoteNotValidError(url)
|
| 408 |
+
|
| 409 |
+
@classmethod
|
| 410 |
+
def has_commit(cls, location: str, rev: str) -> bool:
|
| 411 |
+
"""
|
| 412 |
+
Check if rev is a commit that is available in the local repository.
|
| 413 |
+
"""
|
| 414 |
+
try:
|
| 415 |
+
cls.run_command(
|
| 416 |
+
["rev-parse", "-q", "--verify", "sha^" + rev],
|
| 417 |
+
cwd=location,
|
| 418 |
+
log_failed_cmd=False,
|
| 419 |
+
)
|
| 420 |
+
except InstallationError:
|
| 421 |
+
return False
|
| 422 |
+
else:
|
| 423 |
+
return True
|
| 424 |
+
|
| 425 |
+
@classmethod
|
| 426 |
+
def get_revision(cls, location: str, rev: Optional[str] = None) -> str:
|
| 427 |
+
if rev is None:
|
| 428 |
+
rev = "HEAD"
|
| 429 |
+
current_rev = cls.run_command(
|
| 430 |
+
["rev-parse", rev],
|
| 431 |
+
show_stdout=False,
|
| 432 |
+
stdout_only=True,
|
| 433 |
+
cwd=location,
|
| 434 |
+
)
|
| 435 |
+
return current_rev.strip()
|
| 436 |
+
|
| 437 |
+
@classmethod
|
| 438 |
+
def get_subdirectory(cls, location: str) -> Optional[str]:
|
| 439 |
+
"""
|
| 440 |
+
Return the path to Python project root, relative to the repo root.
|
| 441 |
+
Return None if the project root is in the repo root.
|
| 442 |
+
"""
|
| 443 |
+
# find the repo root
|
| 444 |
+
git_dir = cls.run_command(
|
| 445 |
+
["rev-parse", "--git-dir"],
|
| 446 |
+
show_stdout=False,
|
| 447 |
+
stdout_only=True,
|
| 448 |
+
cwd=location,
|
| 449 |
+
).strip()
|
| 450 |
+
if not os.path.isabs(git_dir):
|
| 451 |
+
git_dir = os.path.join(location, git_dir)
|
| 452 |
+
repo_root = os.path.abspath(os.path.join(git_dir, ".."))
|
| 453 |
+
return find_path_to_project_root_from_repo_root(location, repo_root)
|
| 454 |
+
|
| 455 |
+
@classmethod
|
| 456 |
+
def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
|
| 457 |
+
"""
|
| 458 |
+
Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'.
|
| 459 |
+
That's required because although they use SSH they sometimes don't
|
| 460 |
+
work with a ssh:// scheme (e.g. GitHub). But we need a scheme for
|
| 461 |
+
parsing. Hence we remove it again afterwards and return it as a stub.
|
| 462 |
+
"""
|
| 463 |
+
# Works around an apparent Git bug
|
| 464 |
+
# (see https://article.gmane.org/gmane.comp.version-control.git/146500)
|
| 465 |
+
scheme, netloc, path, query, fragment = urlsplit(url)
|
| 466 |
+
if scheme.endswith("file"):
|
| 467 |
+
initial_slashes = path[: -len(path.lstrip("/"))]
|
| 468 |
+
newpath = initial_slashes + urllib.request.url2pathname(path).replace(
|
| 469 |
+
"\\", "/"
|
| 470 |
+
).lstrip("/")
|
| 471 |
+
after_plus = scheme.find("+") + 1
|
| 472 |
+
url = scheme[:after_plus] + urlunsplit(
|
| 473 |
+
(scheme[after_plus:], netloc, newpath, query, fragment),
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
if "://" not in url:
|
| 477 |
+
assert "file:" not in url
|
| 478 |
+
url = url.replace("git+", "git+ssh://")
|
| 479 |
+
url, rev, user_pass = super().get_url_rev_and_auth(url)
|
| 480 |
+
url = url.replace("ssh://", "")
|
| 481 |
+
else:
|
| 482 |
+
url, rev, user_pass = super().get_url_rev_and_auth(url)
|
| 483 |
+
|
| 484 |
+
return url, rev, user_pass
|
| 485 |
+
|
| 486 |
+
@classmethod
|
| 487 |
+
def update_submodules(cls, location: str) -> None:
|
| 488 |
+
if not os.path.exists(os.path.join(location, ".gitmodules")):
|
| 489 |
+
return
|
| 490 |
+
cls.run_command(
|
| 491 |
+
["submodule", "update", "--init", "--recursive", "-q"],
|
| 492 |
+
cwd=location,
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
+
@classmethod
|
| 496 |
+
def get_repository_root(cls, location: str) -> Optional[str]:
|
| 497 |
+
loc = super().get_repository_root(location)
|
| 498 |
+
if loc:
|
| 499 |
+
return loc
|
| 500 |
+
try:
|
| 501 |
+
r = cls.run_command(
|
| 502 |
+
["rev-parse", "--show-toplevel"],
|
| 503 |
+
cwd=location,
|
| 504 |
+
show_stdout=False,
|
| 505 |
+
stdout_only=True,
|
| 506 |
+
on_returncode="raise",
|
| 507 |
+
log_failed_cmd=False,
|
| 508 |
+
)
|
| 509 |
+
except BadCommand:
|
| 510 |
+
logger.debug(
|
| 511 |
+
"could not determine if %s is under git control "
|
| 512 |
+
"because git is not available",
|
| 513 |
+
location,
|
| 514 |
+
)
|
| 515 |
+
return None
|
| 516 |
+
except InstallationError:
|
| 517 |
+
return None
|
| 518 |
+
return os.path.normpath(r.rstrip("\r\n"))
|
| 519 |
+
|
| 520 |
+
@staticmethod
|
| 521 |
+
def should_add_vcs_url_prefix(repo_url: str) -> bool:
|
| 522 |
+
"""In either https or ssh form, requirements must be prefixed with git+."""
|
| 523 |
+
return True
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
vcs.register(Git)
|
.venv/Lib/site-packages/pip/_internal/vcs/mercurial.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import configparser
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
from typing import List, Optional, Tuple
|
| 5 |
+
|
| 6 |
+
from pip._internal.exceptions import BadCommand, InstallationError
|
| 7 |
+
from pip._internal.utils.misc import HiddenText, display_path
|
| 8 |
+
from pip._internal.utils.subprocess import make_command
|
| 9 |
+
from pip._internal.utils.urls import path_to_url
|
| 10 |
+
from pip._internal.vcs.versioncontrol import (
|
| 11 |
+
RevOptions,
|
| 12 |
+
VersionControl,
|
| 13 |
+
find_path_to_project_root_from_repo_root,
|
| 14 |
+
vcs,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
logger = logging.getLogger(__name__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class Mercurial(VersionControl):
|
| 21 |
+
name = "hg"
|
| 22 |
+
dirname = ".hg"
|
| 23 |
+
repo_name = "clone"
|
| 24 |
+
schemes = (
|
| 25 |
+
"hg+file",
|
| 26 |
+
"hg+http",
|
| 27 |
+
"hg+https",
|
| 28 |
+
"hg+ssh",
|
| 29 |
+
"hg+static-http",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def get_base_rev_args(rev: str) -> List[str]:
|
| 34 |
+
return ["-r", rev]
|
| 35 |
+
|
| 36 |
+
def fetch_new(
|
| 37 |
+
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
| 38 |
+
) -> None:
|
| 39 |
+
rev_display = rev_options.to_display()
|
| 40 |
+
logger.info(
|
| 41 |
+
"Cloning hg %s%s to %s",
|
| 42 |
+
url,
|
| 43 |
+
rev_display,
|
| 44 |
+
display_path(dest),
|
| 45 |
+
)
|
| 46 |
+
if verbosity <= 0:
|
| 47 |
+
flags: Tuple[str, ...] = ("--quiet",)
|
| 48 |
+
elif verbosity == 1:
|
| 49 |
+
flags = ()
|
| 50 |
+
elif verbosity == 2:
|
| 51 |
+
flags = ("--verbose",)
|
| 52 |
+
else:
|
| 53 |
+
flags = ("--verbose", "--debug")
|
| 54 |
+
self.run_command(make_command("clone", "--noupdate", *flags, url, dest))
|
| 55 |
+
self.run_command(
|
| 56 |
+
make_command("update", *flags, rev_options.to_args()),
|
| 57 |
+
cwd=dest,
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 61 |
+
repo_config = os.path.join(dest, self.dirname, "hgrc")
|
| 62 |
+
config = configparser.RawConfigParser()
|
| 63 |
+
try:
|
| 64 |
+
config.read(repo_config)
|
| 65 |
+
config.set("paths", "default", url.secret)
|
| 66 |
+
with open(repo_config, "w") as config_file:
|
| 67 |
+
config.write(config_file)
|
| 68 |
+
except (OSError, configparser.NoSectionError) as exc:
|
| 69 |
+
logger.warning("Could not switch Mercurial repository to %s: %s", url, exc)
|
| 70 |
+
else:
|
| 71 |
+
cmd_args = make_command("update", "-q", rev_options.to_args())
|
| 72 |
+
self.run_command(cmd_args, cwd=dest)
|
| 73 |
+
|
| 74 |
+
def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 75 |
+
self.run_command(["pull", "-q"], cwd=dest)
|
| 76 |
+
cmd_args = make_command("update", "-q", rev_options.to_args())
|
| 77 |
+
self.run_command(cmd_args, cwd=dest)
|
| 78 |
+
|
| 79 |
+
@classmethod
|
| 80 |
+
def get_remote_url(cls, location: str) -> str:
|
| 81 |
+
url = cls.run_command(
|
| 82 |
+
["showconfig", "paths.default"],
|
| 83 |
+
show_stdout=False,
|
| 84 |
+
stdout_only=True,
|
| 85 |
+
cwd=location,
|
| 86 |
+
).strip()
|
| 87 |
+
if cls._is_local_repository(url):
|
| 88 |
+
url = path_to_url(url)
|
| 89 |
+
return url.strip()
|
| 90 |
+
|
| 91 |
+
@classmethod
|
| 92 |
+
def get_revision(cls, location: str) -> str:
|
| 93 |
+
"""
|
| 94 |
+
Return the repository-local changeset revision number, as an integer.
|
| 95 |
+
"""
|
| 96 |
+
current_revision = cls.run_command(
|
| 97 |
+
["parents", "--template={rev}"],
|
| 98 |
+
show_stdout=False,
|
| 99 |
+
stdout_only=True,
|
| 100 |
+
cwd=location,
|
| 101 |
+
).strip()
|
| 102 |
+
return current_revision
|
| 103 |
+
|
| 104 |
+
@classmethod
|
| 105 |
+
def get_requirement_revision(cls, location: str) -> str:
|
| 106 |
+
"""
|
| 107 |
+
Return the changeset identification hash, as a 40-character
|
| 108 |
+
hexadecimal string
|
| 109 |
+
"""
|
| 110 |
+
current_rev_hash = cls.run_command(
|
| 111 |
+
["parents", "--template={node}"],
|
| 112 |
+
show_stdout=False,
|
| 113 |
+
stdout_only=True,
|
| 114 |
+
cwd=location,
|
| 115 |
+
).strip()
|
| 116 |
+
return current_rev_hash
|
| 117 |
+
|
| 118 |
+
@classmethod
|
| 119 |
+
def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
|
| 120 |
+
"""Always assume the versions don't match"""
|
| 121 |
+
return False
|
| 122 |
+
|
| 123 |
+
@classmethod
|
| 124 |
+
def get_subdirectory(cls, location: str) -> Optional[str]:
|
| 125 |
+
"""
|
| 126 |
+
Return the path to Python project root, relative to the repo root.
|
| 127 |
+
Return None if the project root is in the repo root.
|
| 128 |
+
"""
|
| 129 |
+
# find the repo root
|
| 130 |
+
repo_root = cls.run_command(
|
| 131 |
+
["root"], show_stdout=False, stdout_only=True, cwd=location
|
| 132 |
+
).strip()
|
| 133 |
+
if not os.path.isabs(repo_root):
|
| 134 |
+
repo_root = os.path.abspath(os.path.join(location, repo_root))
|
| 135 |
+
return find_path_to_project_root_from_repo_root(location, repo_root)
|
| 136 |
+
|
| 137 |
+
@classmethod
|
| 138 |
+
def get_repository_root(cls, location: str) -> Optional[str]:
|
| 139 |
+
loc = super().get_repository_root(location)
|
| 140 |
+
if loc:
|
| 141 |
+
return loc
|
| 142 |
+
try:
|
| 143 |
+
r = cls.run_command(
|
| 144 |
+
["root"],
|
| 145 |
+
cwd=location,
|
| 146 |
+
show_stdout=False,
|
| 147 |
+
stdout_only=True,
|
| 148 |
+
on_returncode="raise",
|
| 149 |
+
log_failed_cmd=False,
|
| 150 |
+
)
|
| 151 |
+
except BadCommand:
|
| 152 |
+
logger.debug(
|
| 153 |
+
"could not determine if %s is under hg control "
|
| 154 |
+
"because hg is not available",
|
| 155 |
+
location,
|
| 156 |
+
)
|
| 157 |
+
return None
|
| 158 |
+
except InstallationError:
|
| 159 |
+
return None
|
| 160 |
+
return os.path.normpath(r.rstrip("\r\n"))
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
vcs.register(Mercurial)
|
.venv/Lib/site-packages/pip/_internal/vcs/subversion.py
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import re
|
| 4 |
+
from typing import List, Optional, Tuple
|
| 5 |
+
|
| 6 |
+
from pip._internal.utils.misc import (
|
| 7 |
+
HiddenText,
|
| 8 |
+
display_path,
|
| 9 |
+
is_console_interactive,
|
| 10 |
+
is_installable_dir,
|
| 11 |
+
split_auth_from_netloc,
|
| 12 |
+
)
|
| 13 |
+
from pip._internal.utils.subprocess import CommandArgs, make_command
|
| 14 |
+
from pip._internal.vcs.versioncontrol import (
|
| 15 |
+
AuthInfo,
|
| 16 |
+
RemoteNotFoundError,
|
| 17 |
+
RevOptions,
|
| 18 |
+
VersionControl,
|
| 19 |
+
vcs,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
logger = logging.getLogger(__name__)
|
| 23 |
+
|
| 24 |
+
_svn_xml_url_re = re.compile('url="([^"]+)"')
|
| 25 |
+
_svn_rev_re = re.compile(r'committed-rev="(\d+)"')
|
| 26 |
+
_svn_info_xml_rev_re = re.compile(r'\s*revision="(\d+)"')
|
| 27 |
+
_svn_info_xml_url_re = re.compile(r"<url>(.*)</url>")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class Subversion(VersionControl):
|
| 31 |
+
name = "svn"
|
| 32 |
+
dirname = ".svn"
|
| 33 |
+
repo_name = "checkout"
|
| 34 |
+
schemes = ("svn+ssh", "svn+http", "svn+https", "svn+svn", "svn+file")
|
| 35 |
+
|
| 36 |
+
@classmethod
|
| 37 |
+
def should_add_vcs_url_prefix(cls, remote_url: str) -> bool:
|
| 38 |
+
return True
|
| 39 |
+
|
| 40 |
+
@staticmethod
|
| 41 |
+
def get_base_rev_args(rev: str) -> List[str]:
|
| 42 |
+
return ["-r", rev]
|
| 43 |
+
|
| 44 |
+
@classmethod
|
| 45 |
+
def get_revision(cls, location: str) -> str:
|
| 46 |
+
"""
|
| 47 |
+
Return the maximum revision for all files under a given location
|
| 48 |
+
"""
|
| 49 |
+
# Note: taken from setuptools.command.egg_info
|
| 50 |
+
revision = 0
|
| 51 |
+
|
| 52 |
+
for base, dirs, _ in os.walk(location):
|
| 53 |
+
if cls.dirname not in dirs:
|
| 54 |
+
dirs[:] = []
|
| 55 |
+
continue # no sense walking uncontrolled subdirs
|
| 56 |
+
dirs.remove(cls.dirname)
|
| 57 |
+
entries_fn = os.path.join(base, cls.dirname, "entries")
|
| 58 |
+
if not os.path.exists(entries_fn):
|
| 59 |
+
# FIXME: should we warn?
|
| 60 |
+
continue
|
| 61 |
+
|
| 62 |
+
dirurl, localrev = cls._get_svn_url_rev(base)
|
| 63 |
+
|
| 64 |
+
if base == location:
|
| 65 |
+
assert dirurl is not None
|
| 66 |
+
base = dirurl + "/" # save the root url
|
| 67 |
+
elif not dirurl or not dirurl.startswith(base):
|
| 68 |
+
dirs[:] = []
|
| 69 |
+
continue # not part of the same svn tree, skip it
|
| 70 |
+
revision = max(revision, localrev)
|
| 71 |
+
return str(revision)
|
| 72 |
+
|
| 73 |
+
@classmethod
|
| 74 |
+
def get_netloc_and_auth(
|
| 75 |
+
cls, netloc: str, scheme: str
|
| 76 |
+
) -> Tuple[str, Tuple[Optional[str], Optional[str]]]:
|
| 77 |
+
"""
|
| 78 |
+
This override allows the auth information to be passed to svn via the
|
| 79 |
+
--username and --password options instead of via the URL.
|
| 80 |
+
"""
|
| 81 |
+
if scheme == "ssh":
|
| 82 |
+
# The --username and --password options can't be used for
|
| 83 |
+
# svn+ssh URLs, so keep the auth information in the URL.
|
| 84 |
+
return super().get_netloc_and_auth(netloc, scheme)
|
| 85 |
+
|
| 86 |
+
return split_auth_from_netloc(netloc)
|
| 87 |
+
|
| 88 |
+
@classmethod
|
| 89 |
+
def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
|
| 90 |
+
# hotfix the URL scheme after removing svn+ from svn+ssh:// re-add it
|
| 91 |
+
url, rev, user_pass = super().get_url_rev_and_auth(url)
|
| 92 |
+
if url.startswith("ssh://"):
|
| 93 |
+
url = "svn+" + url
|
| 94 |
+
return url, rev, user_pass
|
| 95 |
+
|
| 96 |
+
@staticmethod
|
| 97 |
+
def make_rev_args(
|
| 98 |
+
username: Optional[str], password: Optional[HiddenText]
|
| 99 |
+
) -> CommandArgs:
|
| 100 |
+
extra_args: CommandArgs = []
|
| 101 |
+
if username:
|
| 102 |
+
extra_args += ["--username", username]
|
| 103 |
+
if password:
|
| 104 |
+
extra_args += ["--password", password]
|
| 105 |
+
|
| 106 |
+
return extra_args
|
| 107 |
+
|
| 108 |
+
@classmethod
|
| 109 |
+
def get_remote_url(cls, location: str) -> str:
|
| 110 |
+
# In cases where the source is in a subdirectory, we have to look up in
|
| 111 |
+
# the location until we find a valid project root.
|
| 112 |
+
orig_location = location
|
| 113 |
+
while not is_installable_dir(location):
|
| 114 |
+
last_location = location
|
| 115 |
+
location = os.path.dirname(location)
|
| 116 |
+
if location == last_location:
|
| 117 |
+
# We've traversed up to the root of the filesystem without
|
| 118 |
+
# finding a Python project.
|
| 119 |
+
logger.warning(
|
| 120 |
+
"Could not find Python project for directory %s (tried all "
|
| 121 |
+
"parent directories)",
|
| 122 |
+
orig_location,
|
| 123 |
+
)
|
| 124 |
+
raise RemoteNotFoundError
|
| 125 |
+
|
| 126 |
+
url, _rev = cls._get_svn_url_rev(location)
|
| 127 |
+
if url is None:
|
| 128 |
+
raise RemoteNotFoundError
|
| 129 |
+
|
| 130 |
+
return url
|
| 131 |
+
|
| 132 |
+
@classmethod
|
| 133 |
+
def _get_svn_url_rev(cls, location: str) -> Tuple[Optional[str], int]:
|
| 134 |
+
from pip._internal.exceptions import InstallationError
|
| 135 |
+
|
| 136 |
+
entries_path = os.path.join(location, cls.dirname, "entries")
|
| 137 |
+
if os.path.exists(entries_path):
|
| 138 |
+
with open(entries_path) as f:
|
| 139 |
+
data = f.read()
|
| 140 |
+
else: # subversion >= 1.7 does not have the 'entries' file
|
| 141 |
+
data = ""
|
| 142 |
+
|
| 143 |
+
url = None
|
| 144 |
+
if data.startswith("8") or data.startswith("9") or data.startswith("10"):
|
| 145 |
+
entries = list(map(str.splitlines, data.split("\n\x0c\n")))
|
| 146 |
+
del entries[0][0] # get rid of the '8'
|
| 147 |
+
url = entries[0][3]
|
| 148 |
+
revs = [int(d[9]) for d in entries if len(d) > 9 and d[9]] + [0]
|
| 149 |
+
elif data.startswith("<?xml"):
|
| 150 |
+
match = _svn_xml_url_re.search(data)
|
| 151 |
+
if not match:
|
| 152 |
+
raise ValueError(f"Badly formatted data: {data!r}")
|
| 153 |
+
url = match.group(1) # get repository URL
|
| 154 |
+
revs = [int(m.group(1)) for m in _svn_rev_re.finditer(data)] + [0]
|
| 155 |
+
else:
|
| 156 |
+
try:
|
| 157 |
+
# subversion >= 1.7
|
| 158 |
+
# Note that using get_remote_call_options is not necessary here
|
| 159 |
+
# because `svn info` is being run against a local directory.
|
| 160 |
+
# We don't need to worry about making sure interactive mode
|
| 161 |
+
# is being used to prompt for passwords, because passwords
|
| 162 |
+
# are only potentially needed for remote server requests.
|
| 163 |
+
xml = cls.run_command(
|
| 164 |
+
["info", "--xml", location],
|
| 165 |
+
show_stdout=False,
|
| 166 |
+
stdout_only=True,
|
| 167 |
+
)
|
| 168 |
+
match = _svn_info_xml_url_re.search(xml)
|
| 169 |
+
assert match is not None
|
| 170 |
+
url = match.group(1)
|
| 171 |
+
revs = [int(m.group(1)) for m in _svn_info_xml_rev_re.finditer(xml)]
|
| 172 |
+
except InstallationError:
|
| 173 |
+
url, revs = None, []
|
| 174 |
+
|
| 175 |
+
if revs:
|
| 176 |
+
rev = max(revs)
|
| 177 |
+
else:
|
| 178 |
+
rev = 0
|
| 179 |
+
|
| 180 |
+
return url, rev
|
| 181 |
+
|
| 182 |
+
@classmethod
|
| 183 |
+
def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
|
| 184 |
+
"""Always assume the versions don't match"""
|
| 185 |
+
return False
|
| 186 |
+
|
| 187 |
+
def __init__(self, use_interactive: Optional[bool] = None) -> None:
|
| 188 |
+
if use_interactive is None:
|
| 189 |
+
use_interactive = is_console_interactive()
|
| 190 |
+
self.use_interactive = use_interactive
|
| 191 |
+
|
| 192 |
+
# This member is used to cache the fetched version of the current
|
| 193 |
+
# ``svn`` client.
|
| 194 |
+
# Special value definitions:
|
| 195 |
+
# None: Not evaluated yet.
|
| 196 |
+
# Empty tuple: Could not parse version.
|
| 197 |
+
self._vcs_version: Optional[Tuple[int, ...]] = None
|
| 198 |
+
|
| 199 |
+
super().__init__()
|
| 200 |
+
|
| 201 |
+
def call_vcs_version(self) -> Tuple[int, ...]:
|
| 202 |
+
"""Query the version of the currently installed Subversion client.
|
| 203 |
+
|
| 204 |
+
:return: A tuple containing the parts of the version information or
|
| 205 |
+
``()`` if the version returned from ``svn`` could not be parsed.
|
| 206 |
+
:raises: BadCommand: If ``svn`` is not installed.
|
| 207 |
+
"""
|
| 208 |
+
# Example versions:
|
| 209 |
+
# svn, version 1.10.3 (r1842928)
|
| 210 |
+
# compiled Feb 25 2019, 14:20:39 on x86_64-apple-darwin17.0.0
|
| 211 |
+
# svn, version 1.7.14 (r1542130)
|
| 212 |
+
# compiled Mar 28 2018, 08:49:13 on x86_64-pc-linux-gnu
|
| 213 |
+
# svn, version 1.12.0-SlikSvn (SlikSvn/1.12.0)
|
| 214 |
+
# compiled May 28 2019, 13:44:56 on x86_64-microsoft-windows6.2
|
| 215 |
+
version_prefix = "svn, version "
|
| 216 |
+
version = self.run_command(["--version"], show_stdout=False, stdout_only=True)
|
| 217 |
+
if not version.startswith(version_prefix):
|
| 218 |
+
return ()
|
| 219 |
+
|
| 220 |
+
version = version[len(version_prefix) :].split()[0]
|
| 221 |
+
version_list = version.partition("-")[0].split(".")
|
| 222 |
+
try:
|
| 223 |
+
parsed_version = tuple(map(int, version_list))
|
| 224 |
+
except ValueError:
|
| 225 |
+
return ()
|
| 226 |
+
|
| 227 |
+
return parsed_version
|
| 228 |
+
|
| 229 |
+
def get_vcs_version(self) -> Tuple[int, ...]:
|
| 230 |
+
"""Return the version of the currently installed Subversion client.
|
| 231 |
+
|
| 232 |
+
If the version of the Subversion client has already been queried,
|
| 233 |
+
a cached value will be used.
|
| 234 |
+
|
| 235 |
+
:return: A tuple containing the parts of the version information or
|
| 236 |
+
``()`` if the version returned from ``svn`` could not be parsed.
|
| 237 |
+
:raises: BadCommand: If ``svn`` is not installed.
|
| 238 |
+
"""
|
| 239 |
+
if self._vcs_version is not None:
|
| 240 |
+
# Use cached version, if available.
|
| 241 |
+
# If parsing the version failed previously (empty tuple),
|
| 242 |
+
# do not attempt to parse it again.
|
| 243 |
+
return self._vcs_version
|
| 244 |
+
|
| 245 |
+
vcs_version = self.call_vcs_version()
|
| 246 |
+
self._vcs_version = vcs_version
|
| 247 |
+
return vcs_version
|
| 248 |
+
|
| 249 |
+
def get_remote_call_options(self) -> CommandArgs:
|
| 250 |
+
"""Return options to be used on calls to Subversion that contact the server.
|
| 251 |
+
|
| 252 |
+
These options are applicable for the following ``svn`` subcommands used
|
| 253 |
+
in this class.
|
| 254 |
+
|
| 255 |
+
- checkout
|
| 256 |
+
- switch
|
| 257 |
+
- update
|
| 258 |
+
|
| 259 |
+
:return: A list of command line arguments to pass to ``svn``.
|
| 260 |
+
"""
|
| 261 |
+
if not self.use_interactive:
|
| 262 |
+
# --non-interactive switch is available since Subversion 0.14.4.
|
| 263 |
+
# Subversion < 1.8 runs in interactive mode by default.
|
| 264 |
+
return ["--non-interactive"]
|
| 265 |
+
|
| 266 |
+
svn_version = self.get_vcs_version()
|
| 267 |
+
# By default, Subversion >= 1.8 runs in non-interactive mode if
|
| 268 |
+
# stdin is not a TTY. Since that is how pip invokes SVN, in
|
| 269 |
+
# call_subprocess(), pip must pass --force-interactive to ensure
|
| 270 |
+
# the user can be prompted for a password, if required.
|
| 271 |
+
# SVN added the --force-interactive option in SVN 1.8. Since
|
| 272 |
+
# e.g. RHEL/CentOS 7, which is supported until 2024, ships with
|
| 273 |
+
# SVN 1.7, pip should continue to support SVN 1.7. Therefore, pip
|
| 274 |
+
# can't safely add the option if the SVN version is < 1.8 (or unknown).
|
| 275 |
+
if svn_version >= (1, 8):
|
| 276 |
+
return ["--force-interactive"]
|
| 277 |
+
|
| 278 |
+
return []
|
| 279 |
+
|
| 280 |
+
def fetch_new(
|
| 281 |
+
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
| 282 |
+
) -> None:
|
| 283 |
+
rev_display = rev_options.to_display()
|
| 284 |
+
logger.info(
|
| 285 |
+
"Checking out %s%s to %s",
|
| 286 |
+
url,
|
| 287 |
+
rev_display,
|
| 288 |
+
display_path(dest),
|
| 289 |
+
)
|
| 290 |
+
if verbosity <= 0:
|
| 291 |
+
flag = "--quiet"
|
| 292 |
+
else:
|
| 293 |
+
flag = ""
|
| 294 |
+
cmd_args = make_command(
|
| 295 |
+
"checkout",
|
| 296 |
+
flag,
|
| 297 |
+
self.get_remote_call_options(),
|
| 298 |
+
rev_options.to_args(),
|
| 299 |
+
url,
|
| 300 |
+
dest,
|
| 301 |
+
)
|
| 302 |
+
self.run_command(cmd_args)
|
| 303 |
+
|
| 304 |
+
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 305 |
+
cmd_args = make_command(
|
| 306 |
+
"switch",
|
| 307 |
+
self.get_remote_call_options(),
|
| 308 |
+
rev_options.to_args(),
|
| 309 |
+
url,
|
| 310 |
+
dest,
|
| 311 |
+
)
|
| 312 |
+
self.run_command(cmd_args)
|
| 313 |
+
|
| 314 |
+
def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 315 |
+
cmd_args = make_command(
|
| 316 |
+
"update",
|
| 317 |
+
self.get_remote_call_options(),
|
| 318 |
+
rev_options.to_args(),
|
| 319 |
+
dest,
|
| 320 |
+
)
|
| 321 |
+
self.run_command(cmd_args)
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
vcs.register(Subversion)
|
.venv/Lib/site-packages/pip/_internal/vcs/versioncontrol.py
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Handles all VCS (version control) support"""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import shutil
|
| 6 |
+
import sys
|
| 7 |
+
import urllib.parse
|
| 8 |
+
from typing import (
|
| 9 |
+
TYPE_CHECKING,
|
| 10 |
+
Any,
|
| 11 |
+
Dict,
|
| 12 |
+
Iterable,
|
| 13 |
+
Iterator,
|
| 14 |
+
List,
|
| 15 |
+
Mapping,
|
| 16 |
+
Optional,
|
| 17 |
+
Tuple,
|
| 18 |
+
Type,
|
| 19 |
+
Union,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
from pip._internal.cli.spinners import SpinnerInterface
|
| 23 |
+
from pip._internal.exceptions import BadCommand, InstallationError
|
| 24 |
+
from pip._internal.utils.misc import (
|
| 25 |
+
HiddenText,
|
| 26 |
+
ask_path_exists,
|
| 27 |
+
backup_dir,
|
| 28 |
+
display_path,
|
| 29 |
+
hide_url,
|
| 30 |
+
hide_value,
|
| 31 |
+
is_installable_dir,
|
| 32 |
+
rmtree,
|
| 33 |
+
)
|
| 34 |
+
from pip._internal.utils.subprocess import (
|
| 35 |
+
CommandArgs,
|
| 36 |
+
call_subprocess,
|
| 37 |
+
format_command_args,
|
| 38 |
+
make_command,
|
| 39 |
+
)
|
| 40 |
+
from pip._internal.utils.urls import get_url_scheme
|
| 41 |
+
|
| 42 |
+
if TYPE_CHECKING:
|
| 43 |
+
# Literal was introduced in Python 3.8.
|
| 44 |
+
#
|
| 45 |
+
# TODO: Remove `if TYPE_CHECKING` when dropping support for Python 3.7.
|
| 46 |
+
from typing import Literal
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
__all__ = ["vcs"]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
logger = logging.getLogger(__name__)
|
| 53 |
+
|
| 54 |
+
AuthInfo = Tuple[Optional[str], Optional[str]]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def is_url(name: str) -> bool:
|
| 58 |
+
"""
|
| 59 |
+
Return true if the name looks like a URL.
|
| 60 |
+
"""
|
| 61 |
+
scheme = get_url_scheme(name)
|
| 62 |
+
if scheme is None:
|
| 63 |
+
return False
|
| 64 |
+
return scheme in ["http", "https", "file", "ftp"] + vcs.all_schemes
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def make_vcs_requirement_url(
|
| 68 |
+
repo_url: str, rev: str, project_name: str, subdir: Optional[str] = None
|
| 69 |
+
) -> str:
|
| 70 |
+
"""
|
| 71 |
+
Return the URL for a VCS requirement.
|
| 72 |
+
|
| 73 |
+
Args:
|
| 74 |
+
repo_url: the remote VCS url, with any needed VCS prefix (e.g. "git+").
|
| 75 |
+
project_name: the (unescaped) project name.
|
| 76 |
+
"""
|
| 77 |
+
egg_project_name = project_name.replace("-", "_")
|
| 78 |
+
req = f"{repo_url}@{rev}#egg={egg_project_name}"
|
| 79 |
+
if subdir:
|
| 80 |
+
req += f"&subdirectory={subdir}"
|
| 81 |
+
|
| 82 |
+
return req
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def find_path_to_project_root_from_repo_root(
|
| 86 |
+
location: str, repo_root: str
|
| 87 |
+
) -> Optional[str]:
|
| 88 |
+
"""
|
| 89 |
+
Find the the Python project's root by searching up the filesystem from
|
| 90 |
+
`location`. Return the path to project root relative to `repo_root`.
|
| 91 |
+
Return None if the project root is `repo_root`, or cannot be found.
|
| 92 |
+
"""
|
| 93 |
+
# find project root.
|
| 94 |
+
orig_location = location
|
| 95 |
+
while not is_installable_dir(location):
|
| 96 |
+
last_location = location
|
| 97 |
+
location = os.path.dirname(location)
|
| 98 |
+
if location == last_location:
|
| 99 |
+
# We've traversed up to the root of the filesystem without
|
| 100 |
+
# finding a Python project.
|
| 101 |
+
logger.warning(
|
| 102 |
+
"Could not find a Python project for directory %s (tried all "
|
| 103 |
+
"parent directories)",
|
| 104 |
+
orig_location,
|
| 105 |
+
)
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
if os.path.samefile(repo_root, location):
|
| 109 |
+
return None
|
| 110 |
+
|
| 111 |
+
return os.path.relpath(location, repo_root)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
class RemoteNotFoundError(Exception):
|
| 115 |
+
pass
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class RemoteNotValidError(Exception):
|
| 119 |
+
def __init__(self, url: str):
|
| 120 |
+
super().__init__(url)
|
| 121 |
+
self.url = url
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class RevOptions:
|
| 125 |
+
|
| 126 |
+
"""
|
| 127 |
+
Encapsulates a VCS-specific revision to install, along with any VCS
|
| 128 |
+
install options.
|
| 129 |
+
|
| 130 |
+
Instances of this class should be treated as if immutable.
|
| 131 |
+
"""
|
| 132 |
+
|
| 133 |
+
def __init__(
|
| 134 |
+
self,
|
| 135 |
+
vc_class: Type["VersionControl"],
|
| 136 |
+
rev: Optional[str] = None,
|
| 137 |
+
extra_args: Optional[CommandArgs] = None,
|
| 138 |
+
) -> None:
|
| 139 |
+
"""
|
| 140 |
+
Args:
|
| 141 |
+
vc_class: a VersionControl subclass.
|
| 142 |
+
rev: the name of the revision to install.
|
| 143 |
+
extra_args: a list of extra options.
|
| 144 |
+
"""
|
| 145 |
+
if extra_args is None:
|
| 146 |
+
extra_args = []
|
| 147 |
+
|
| 148 |
+
self.extra_args = extra_args
|
| 149 |
+
self.rev = rev
|
| 150 |
+
self.vc_class = vc_class
|
| 151 |
+
self.branch_name: Optional[str] = None
|
| 152 |
+
|
| 153 |
+
def __repr__(self) -> str:
|
| 154 |
+
return f"<RevOptions {self.vc_class.name}: rev={self.rev!r}>"
|
| 155 |
+
|
| 156 |
+
@property
|
| 157 |
+
def arg_rev(self) -> Optional[str]:
|
| 158 |
+
if self.rev is None:
|
| 159 |
+
return self.vc_class.default_arg_rev
|
| 160 |
+
|
| 161 |
+
return self.rev
|
| 162 |
+
|
| 163 |
+
def to_args(self) -> CommandArgs:
|
| 164 |
+
"""
|
| 165 |
+
Return the VCS-specific command arguments.
|
| 166 |
+
"""
|
| 167 |
+
args: CommandArgs = []
|
| 168 |
+
rev = self.arg_rev
|
| 169 |
+
if rev is not None:
|
| 170 |
+
args += self.vc_class.get_base_rev_args(rev)
|
| 171 |
+
args += self.extra_args
|
| 172 |
+
|
| 173 |
+
return args
|
| 174 |
+
|
| 175 |
+
def to_display(self) -> str:
|
| 176 |
+
if not self.rev:
|
| 177 |
+
return ""
|
| 178 |
+
|
| 179 |
+
return f" (to revision {self.rev})"
|
| 180 |
+
|
| 181 |
+
def make_new(self, rev: str) -> "RevOptions":
|
| 182 |
+
"""
|
| 183 |
+
Make a copy of the current instance, but with a new rev.
|
| 184 |
+
|
| 185 |
+
Args:
|
| 186 |
+
rev: the name of the revision for the new object.
|
| 187 |
+
"""
|
| 188 |
+
return self.vc_class.make_rev_options(rev, extra_args=self.extra_args)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
class VcsSupport:
|
| 192 |
+
_registry: Dict[str, "VersionControl"] = {}
|
| 193 |
+
schemes = ["ssh", "git", "hg", "bzr", "sftp", "svn"]
|
| 194 |
+
|
| 195 |
+
def __init__(self) -> None:
|
| 196 |
+
# Register more schemes with urlparse for various version control
|
| 197 |
+
# systems
|
| 198 |
+
urllib.parse.uses_netloc.extend(self.schemes)
|
| 199 |
+
super().__init__()
|
| 200 |
+
|
| 201 |
+
def __iter__(self) -> Iterator[str]:
|
| 202 |
+
return self._registry.__iter__()
|
| 203 |
+
|
| 204 |
+
@property
|
| 205 |
+
def backends(self) -> List["VersionControl"]:
|
| 206 |
+
return list(self._registry.values())
|
| 207 |
+
|
| 208 |
+
@property
|
| 209 |
+
def dirnames(self) -> List[str]:
|
| 210 |
+
return [backend.dirname for backend in self.backends]
|
| 211 |
+
|
| 212 |
+
@property
|
| 213 |
+
def all_schemes(self) -> List[str]:
|
| 214 |
+
schemes: List[str] = []
|
| 215 |
+
for backend in self.backends:
|
| 216 |
+
schemes.extend(backend.schemes)
|
| 217 |
+
return schemes
|
| 218 |
+
|
| 219 |
+
def register(self, cls: Type["VersionControl"]) -> None:
|
| 220 |
+
if not hasattr(cls, "name"):
|
| 221 |
+
logger.warning("Cannot register VCS %s", cls.__name__)
|
| 222 |
+
return
|
| 223 |
+
if cls.name not in self._registry:
|
| 224 |
+
self._registry[cls.name] = cls()
|
| 225 |
+
logger.debug("Registered VCS backend: %s", cls.name)
|
| 226 |
+
|
| 227 |
+
def unregister(self, name: str) -> None:
|
| 228 |
+
if name in self._registry:
|
| 229 |
+
del self._registry[name]
|
| 230 |
+
|
| 231 |
+
def get_backend_for_dir(self, location: str) -> Optional["VersionControl"]:
|
| 232 |
+
"""
|
| 233 |
+
Return a VersionControl object if a repository of that type is found
|
| 234 |
+
at the given directory.
|
| 235 |
+
"""
|
| 236 |
+
vcs_backends = {}
|
| 237 |
+
for vcs_backend in self._registry.values():
|
| 238 |
+
repo_path = vcs_backend.get_repository_root(location)
|
| 239 |
+
if not repo_path:
|
| 240 |
+
continue
|
| 241 |
+
logger.debug("Determine that %s uses VCS: %s", location, vcs_backend.name)
|
| 242 |
+
vcs_backends[repo_path] = vcs_backend
|
| 243 |
+
|
| 244 |
+
if not vcs_backends:
|
| 245 |
+
return None
|
| 246 |
+
|
| 247 |
+
# Choose the VCS in the inner-most directory. Since all repository
|
| 248 |
+
# roots found here would be either `location` or one of its
|
| 249 |
+
# parents, the longest path should have the most path components,
|
| 250 |
+
# i.e. the backend representing the inner-most repository.
|
| 251 |
+
inner_most_repo_path = max(vcs_backends, key=len)
|
| 252 |
+
return vcs_backends[inner_most_repo_path]
|
| 253 |
+
|
| 254 |
+
def get_backend_for_scheme(self, scheme: str) -> Optional["VersionControl"]:
|
| 255 |
+
"""
|
| 256 |
+
Return a VersionControl object or None.
|
| 257 |
+
"""
|
| 258 |
+
for vcs_backend in self._registry.values():
|
| 259 |
+
if scheme in vcs_backend.schemes:
|
| 260 |
+
return vcs_backend
|
| 261 |
+
return None
|
| 262 |
+
|
| 263 |
+
def get_backend(self, name: str) -> Optional["VersionControl"]:
|
| 264 |
+
"""
|
| 265 |
+
Return a VersionControl object or None.
|
| 266 |
+
"""
|
| 267 |
+
name = name.lower()
|
| 268 |
+
return self._registry.get(name)
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
vcs = VcsSupport()
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
class VersionControl:
|
| 275 |
+
name = ""
|
| 276 |
+
dirname = ""
|
| 277 |
+
repo_name = ""
|
| 278 |
+
# List of supported schemes for this Version Control
|
| 279 |
+
schemes: Tuple[str, ...] = ()
|
| 280 |
+
# Iterable of environment variable names to pass to call_subprocess().
|
| 281 |
+
unset_environ: Tuple[str, ...] = ()
|
| 282 |
+
default_arg_rev: Optional[str] = None
|
| 283 |
+
|
| 284 |
+
@classmethod
|
| 285 |
+
def should_add_vcs_url_prefix(cls, remote_url: str) -> bool:
|
| 286 |
+
"""
|
| 287 |
+
Return whether the vcs prefix (e.g. "git+") should be added to a
|
| 288 |
+
repository's remote url when used in a requirement.
|
| 289 |
+
"""
|
| 290 |
+
return not remote_url.lower().startswith(f"{cls.name}:")
|
| 291 |
+
|
| 292 |
+
@classmethod
|
| 293 |
+
def get_subdirectory(cls, location: str) -> Optional[str]:
|
| 294 |
+
"""
|
| 295 |
+
Return the path to Python project root, relative to the repo root.
|
| 296 |
+
Return None if the project root is in the repo root.
|
| 297 |
+
"""
|
| 298 |
+
return None
|
| 299 |
+
|
| 300 |
+
@classmethod
|
| 301 |
+
def get_requirement_revision(cls, repo_dir: str) -> str:
|
| 302 |
+
"""
|
| 303 |
+
Return the revision string that should be used in a requirement.
|
| 304 |
+
"""
|
| 305 |
+
return cls.get_revision(repo_dir)
|
| 306 |
+
|
| 307 |
+
@classmethod
|
| 308 |
+
def get_src_requirement(cls, repo_dir: str, project_name: str) -> str:
|
| 309 |
+
"""
|
| 310 |
+
Return the requirement string to use to redownload the files
|
| 311 |
+
currently at the given repository directory.
|
| 312 |
+
|
| 313 |
+
Args:
|
| 314 |
+
project_name: the (unescaped) project name.
|
| 315 |
+
|
| 316 |
+
The return value has a form similar to the following:
|
| 317 |
+
|
| 318 |
+
{repository_url}@{revision}#egg={project_name}
|
| 319 |
+
"""
|
| 320 |
+
repo_url = cls.get_remote_url(repo_dir)
|
| 321 |
+
|
| 322 |
+
if cls.should_add_vcs_url_prefix(repo_url):
|
| 323 |
+
repo_url = f"{cls.name}+{repo_url}"
|
| 324 |
+
|
| 325 |
+
revision = cls.get_requirement_revision(repo_dir)
|
| 326 |
+
subdir = cls.get_subdirectory(repo_dir)
|
| 327 |
+
req = make_vcs_requirement_url(repo_url, revision, project_name, subdir=subdir)
|
| 328 |
+
|
| 329 |
+
return req
|
| 330 |
+
|
| 331 |
+
@staticmethod
|
| 332 |
+
def get_base_rev_args(rev: str) -> List[str]:
|
| 333 |
+
"""
|
| 334 |
+
Return the base revision arguments for a vcs command.
|
| 335 |
+
|
| 336 |
+
Args:
|
| 337 |
+
rev: the name of a revision to install. Cannot be None.
|
| 338 |
+
"""
|
| 339 |
+
raise NotImplementedError
|
| 340 |
+
|
| 341 |
+
def is_immutable_rev_checkout(self, url: str, dest: str) -> bool:
|
| 342 |
+
"""
|
| 343 |
+
Return true if the commit hash checked out at dest matches
|
| 344 |
+
the revision in url.
|
| 345 |
+
|
| 346 |
+
Always return False, if the VCS does not support immutable commit
|
| 347 |
+
hashes.
|
| 348 |
+
|
| 349 |
+
This method does not check if there are local uncommitted changes
|
| 350 |
+
in dest after checkout, as pip currently has no use case for that.
|
| 351 |
+
"""
|
| 352 |
+
return False
|
| 353 |
+
|
| 354 |
+
@classmethod
|
| 355 |
+
def make_rev_options(
|
| 356 |
+
cls, rev: Optional[str] = None, extra_args: Optional[CommandArgs] = None
|
| 357 |
+
) -> RevOptions:
|
| 358 |
+
"""
|
| 359 |
+
Return a RevOptions object.
|
| 360 |
+
|
| 361 |
+
Args:
|
| 362 |
+
rev: the name of a revision to install.
|
| 363 |
+
extra_args: a list of extra options.
|
| 364 |
+
"""
|
| 365 |
+
return RevOptions(cls, rev, extra_args=extra_args)
|
| 366 |
+
|
| 367 |
+
@classmethod
|
| 368 |
+
def _is_local_repository(cls, repo: str) -> bool:
|
| 369 |
+
"""
|
| 370 |
+
posix absolute paths start with os.path.sep,
|
| 371 |
+
win32 ones start with drive (like c:\\folder)
|
| 372 |
+
"""
|
| 373 |
+
drive, tail = os.path.splitdrive(repo)
|
| 374 |
+
return repo.startswith(os.path.sep) or bool(drive)
|
| 375 |
+
|
| 376 |
+
@classmethod
|
| 377 |
+
def get_netloc_and_auth(
|
| 378 |
+
cls, netloc: str, scheme: str
|
| 379 |
+
) -> Tuple[str, Tuple[Optional[str], Optional[str]]]:
|
| 380 |
+
"""
|
| 381 |
+
Parse the repository URL's netloc, and return the new netloc to use
|
| 382 |
+
along with auth information.
|
| 383 |
+
|
| 384 |
+
Args:
|
| 385 |
+
netloc: the original repository URL netloc.
|
| 386 |
+
scheme: the repository URL's scheme without the vcs prefix.
|
| 387 |
+
|
| 388 |
+
This is mainly for the Subversion class to override, so that auth
|
| 389 |
+
information can be provided via the --username and --password options
|
| 390 |
+
instead of through the URL. For other subclasses like Git without
|
| 391 |
+
such an option, auth information must stay in the URL.
|
| 392 |
+
|
| 393 |
+
Returns: (netloc, (username, password)).
|
| 394 |
+
"""
|
| 395 |
+
return netloc, (None, None)
|
| 396 |
+
|
| 397 |
+
@classmethod
|
| 398 |
+
def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
|
| 399 |
+
"""
|
| 400 |
+
Parse the repository URL to use, and return the URL, revision,
|
| 401 |
+
and auth info to use.
|
| 402 |
+
|
| 403 |
+
Returns: (url, rev, (username, password)).
|
| 404 |
+
"""
|
| 405 |
+
scheme, netloc, path, query, frag = urllib.parse.urlsplit(url)
|
| 406 |
+
if "+" not in scheme:
|
| 407 |
+
raise ValueError(
|
| 408 |
+
"Sorry, {!r} is a malformed VCS url. "
|
| 409 |
+
"The format is <vcs>+<protocol>://<url>, "
|
| 410 |
+
"e.g. svn+http://myrepo/svn/MyApp#egg=MyApp".format(url)
|
| 411 |
+
)
|
| 412 |
+
# Remove the vcs prefix.
|
| 413 |
+
scheme = scheme.split("+", 1)[1]
|
| 414 |
+
netloc, user_pass = cls.get_netloc_and_auth(netloc, scheme)
|
| 415 |
+
rev = None
|
| 416 |
+
if "@" in path:
|
| 417 |
+
path, rev = path.rsplit("@", 1)
|
| 418 |
+
if not rev:
|
| 419 |
+
raise InstallationError(
|
| 420 |
+
"The URL {!r} has an empty revision (after @) "
|
| 421 |
+
"which is not supported. Include a revision after @ "
|
| 422 |
+
"or remove @ from the URL.".format(url)
|
| 423 |
+
)
|
| 424 |
+
url = urllib.parse.urlunsplit((scheme, netloc, path, query, ""))
|
| 425 |
+
return url, rev, user_pass
|
| 426 |
+
|
| 427 |
+
@staticmethod
|
| 428 |
+
def make_rev_args(
|
| 429 |
+
username: Optional[str], password: Optional[HiddenText]
|
| 430 |
+
) -> CommandArgs:
|
| 431 |
+
"""
|
| 432 |
+
Return the RevOptions "extra arguments" to use in obtain().
|
| 433 |
+
"""
|
| 434 |
+
return []
|
| 435 |
+
|
| 436 |
+
def get_url_rev_options(self, url: HiddenText) -> Tuple[HiddenText, RevOptions]:
|
| 437 |
+
"""
|
| 438 |
+
Return the URL and RevOptions object to use in obtain(),
|
| 439 |
+
as a tuple (url, rev_options).
|
| 440 |
+
"""
|
| 441 |
+
secret_url, rev, user_pass = self.get_url_rev_and_auth(url.secret)
|
| 442 |
+
username, secret_password = user_pass
|
| 443 |
+
password: Optional[HiddenText] = None
|
| 444 |
+
if secret_password is not None:
|
| 445 |
+
password = hide_value(secret_password)
|
| 446 |
+
extra_args = self.make_rev_args(username, password)
|
| 447 |
+
rev_options = self.make_rev_options(rev, extra_args=extra_args)
|
| 448 |
+
|
| 449 |
+
return hide_url(secret_url), rev_options
|
| 450 |
+
|
| 451 |
+
@staticmethod
|
| 452 |
+
def normalize_url(url: str) -> str:
|
| 453 |
+
"""
|
| 454 |
+
Normalize a URL for comparison by unquoting it and removing any
|
| 455 |
+
trailing slash.
|
| 456 |
+
"""
|
| 457 |
+
return urllib.parse.unquote(url).rstrip("/")
|
| 458 |
+
|
| 459 |
+
@classmethod
|
| 460 |
+
def compare_urls(cls, url1: str, url2: str) -> bool:
|
| 461 |
+
"""
|
| 462 |
+
Compare two repo URLs for identity, ignoring incidental differences.
|
| 463 |
+
"""
|
| 464 |
+
return cls.normalize_url(url1) == cls.normalize_url(url2)
|
| 465 |
+
|
| 466 |
+
def fetch_new(
|
| 467 |
+
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
| 468 |
+
) -> None:
|
| 469 |
+
"""
|
| 470 |
+
Fetch a revision from a repository, in the case that this is the
|
| 471 |
+
first fetch from the repository.
|
| 472 |
+
|
| 473 |
+
Args:
|
| 474 |
+
dest: the directory to fetch the repository to.
|
| 475 |
+
rev_options: a RevOptions object.
|
| 476 |
+
verbosity: verbosity level.
|
| 477 |
+
"""
|
| 478 |
+
raise NotImplementedError
|
| 479 |
+
|
| 480 |
+
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 481 |
+
"""
|
| 482 |
+
Switch the repo at ``dest`` to point to ``URL``.
|
| 483 |
+
|
| 484 |
+
Args:
|
| 485 |
+
rev_options: a RevOptions object.
|
| 486 |
+
"""
|
| 487 |
+
raise NotImplementedError
|
| 488 |
+
|
| 489 |
+
def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
| 490 |
+
"""
|
| 491 |
+
Update an already-existing repo to the given ``rev_options``.
|
| 492 |
+
|
| 493 |
+
Args:
|
| 494 |
+
rev_options: a RevOptions object.
|
| 495 |
+
"""
|
| 496 |
+
raise NotImplementedError
|
| 497 |
+
|
| 498 |
+
@classmethod
|
| 499 |
+
def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
|
| 500 |
+
"""
|
| 501 |
+
Return whether the id of the current commit equals the given name.
|
| 502 |
+
|
| 503 |
+
Args:
|
| 504 |
+
dest: the repository directory.
|
| 505 |
+
name: a string name.
|
| 506 |
+
"""
|
| 507 |
+
raise NotImplementedError
|
| 508 |
+
|
| 509 |
+
def obtain(self, dest: str, url: HiddenText, verbosity: int) -> None:
|
| 510 |
+
"""
|
| 511 |
+
Install or update in editable mode the package represented by this
|
| 512 |
+
VersionControl object.
|
| 513 |
+
|
| 514 |
+
:param dest: the repository directory in which to install or update.
|
| 515 |
+
:param url: the repository URL starting with a vcs prefix.
|
| 516 |
+
:param verbosity: verbosity level.
|
| 517 |
+
"""
|
| 518 |
+
url, rev_options = self.get_url_rev_options(url)
|
| 519 |
+
|
| 520 |
+
if not os.path.exists(dest):
|
| 521 |
+
self.fetch_new(dest, url, rev_options, verbosity=verbosity)
|
| 522 |
+
return
|
| 523 |
+
|
| 524 |
+
rev_display = rev_options.to_display()
|
| 525 |
+
if self.is_repository_directory(dest):
|
| 526 |
+
existing_url = self.get_remote_url(dest)
|
| 527 |
+
if self.compare_urls(existing_url, url.secret):
|
| 528 |
+
logger.debug(
|
| 529 |
+
"%s in %s exists, and has correct URL (%s)",
|
| 530 |
+
self.repo_name.title(),
|
| 531 |
+
display_path(dest),
|
| 532 |
+
url,
|
| 533 |
+
)
|
| 534 |
+
if not self.is_commit_id_equal(dest, rev_options.rev):
|
| 535 |
+
logger.info(
|
| 536 |
+
"Updating %s %s%s",
|
| 537 |
+
display_path(dest),
|
| 538 |
+
self.repo_name,
|
| 539 |
+
rev_display,
|
| 540 |
+
)
|
| 541 |
+
self.update(dest, url, rev_options)
|
| 542 |
+
else:
|
| 543 |
+
logger.info("Skipping because already up-to-date.")
|
| 544 |
+
return
|
| 545 |
+
|
| 546 |
+
logger.warning(
|
| 547 |
+
"%s %s in %s exists with URL %s",
|
| 548 |
+
self.name,
|
| 549 |
+
self.repo_name,
|
| 550 |
+
display_path(dest),
|
| 551 |
+
existing_url,
|
| 552 |
+
)
|
| 553 |
+
prompt = ("(s)witch, (i)gnore, (w)ipe, (b)ackup ", ("s", "i", "w", "b"))
|
| 554 |
+
else:
|
| 555 |
+
logger.warning(
|
| 556 |
+
"Directory %s already exists, and is not a %s %s.",
|
| 557 |
+
dest,
|
| 558 |
+
self.name,
|
| 559 |
+
self.repo_name,
|
| 560 |
+
)
|
| 561 |
+
# https://github.com/python/mypy/issues/1174
|
| 562 |
+
prompt = ("(i)gnore, (w)ipe, (b)ackup ", ("i", "w", "b")) # type: ignore
|
| 563 |
+
|
| 564 |
+
logger.warning(
|
| 565 |
+
"The plan is to install the %s repository %s",
|
| 566 |
+
self.name,
|
| 567 |
+
url,
|
| 568 |
+
)
|
| 569 |
+
response = ask_path_exists("What to do? {}".format(prompt[0]), prompt[1])
|
| 570 |
+
|
| 571 |
+
if response == "a":
|
| 572 |
+
sys.exit(-1)
|
| 573 |
+
|
| 574 |
+
if response == "w":
|
| 575 |
+
logger.warning("Deleting %s", display_path(dest))
|
| 576 |
+
rmtree(dest)
|
| 577 |
+
self.fetch_new(dest, url, rev_options, verbosity=verbosity)
|
| 578 |
+
return
|
| 579 |
+
|
| 580 |
+
if response == "b":
|
| 581 |
+
dest_dir = backup_dir(dest)
|
| 582 |
+
logger.warning("Backing up %s to %s", display_path(dest), dest_dir)
|
| 583 |
+
shutil.move(dest, dest_dir)
|
| 584 |
+
self.fetch_new(dest, url, rev_options, verbosity=verbosity)
|
| 585 |
+
return
|
| 586 |
+
|
| 587 |
+
# Do nothing if the response is "i".
|
| 588 |
+
if response == "s":
|
| 589 |
+
logger.info(
|
| 590 |
+
"Switching %s %s to %s%s",
|
| 591 |
+
self.repo_name,
|
| 592 |
+
display_path(dest),
|
| 593 |
+
url,
|
| 594 |
+
rev_display,
|
| 595 |
+
)
|
| 596 |
+
self.switch(dest, url, rev_options)
|
| 597 |
+
|
| 598 |
+
def unpack(self, location: str, url: HiddenText, verbosity: int) -> None:
|
| 599 |
+
"""
|
| 600 |
+
Clean up current location and download the url repository
|
| 601 |
+
(and vcs infos) into location
|
| 602 |
+
|
| 603 |
+
:param url: the repository URL starting with a vcs prefix.
|
| 604 |
+
:param verbosity: verbosity level.
|
| 605 |
+
"""
|
| 606 |
+
if os.path.exists(location):
|
| 607 |
+
rmtree(location)
|
| 608 |
+
self.obtain(location, url=url, verbosity=verbosity)
|
| 609 |
+
|
| 610 |
+
@classmethod
|
| 611 |
+
def get_remote_url(cls, location: str) -> str:
|
| 612 |
+
"""
|
| 613 |
+
Return the url used at location
|
| 614 |
+
|
| 615 |
+
Raises RemoteNotFoundError if the repository does not have a remote
|
| 616 |
+
url configured.
|
| 617 |
+
"""
|
| 618 |
+
raise NotImplementedError
|
| 619 |
+
|
| 620 |
+
@classmethod
|
| 621 |
+
def get_revision(cls, location: str) -> str:
|
| 622 |
+
"""
|
| 623 |
+
Return the current commit id of the files at the given location.
|
| 624 |
+
"""
|
| 625 |
+
raise NotImplementedError
|
| 626 |
+
|
| 627 |
+
@classmethod
|
| 628 |
+
def run_command(
|
| 629 |
+
cls,
|
| 630 |
+
cmd: Union[List[str], CommandArgs],
|
| 631 |
+
show_stdout: bool = True,
|
| 632 |
+
cwd: Optional[str] = None,
|
| 633 |
+
on_returncode: 'Literal["raise", "warn", "ignore"]' = "raise",
|
| 634 |
+
extra_ok_returncodes: Optional[Iterable[int]] = None,
|
| 635 |
+
command_desc: Optional[str] = None,
|
| 636 |
+
extra_environ: Optional[Mapping[str, Any]] = None,
|
| 637 |
+
spinner: Optional[SpinnerInterface] = None,
|
| 638 |
+
log_failed_cmd: bool = True,
|
| 639 |
+
stdout_only: bool = False,
|
| 640 |
+
) -> str:
|
| 641 |
+
"""
|
| 642 |
+
Run a VCS subcommand
|
| 643 |
+
This is simply a wrapper around call_subprocess that adds the VCS
|
| 644 |
+
command name, and checks that the VCS is available
|
| 645 |
+
"""
|
| 646 |
+
cmd = make_command(cls.name, *cmd)
|
| 647 |
+
if command_desc is None:
|
| 648 |
+
command_desc = format_command_args(cmd)
|
| 649 |
+
try:
|
| 650 |
+
return call_subprocess(
|
| 651 |
+
cmd,
|
| 652 |
+
show_stdout,
|
| 653 |
+
cwd,
|
| 654 |
+
on_returncode=on_returncode,
|
| 655 |
+
extra_ok_returncodes=extra_ok_returncodes,
|
| 656 |
+
command_desc=command_desc,
|
| 657 |
+
extra_environ=extra_environ,
|
| 658 |
+
unset_environ=cls.unset_environ,
|
| 659 |
+
spinner=spinner,
|
| 660 |
+
log_failed_cmd=log_failed_cmd,
|
| 661 |
+
stdout_only=stdout_only,
|
| 662 |
+
)
|
| 663 |
+
except FileNotFoundError:
|
| 664 |
+
# errno.ENOENT = no such file or directory
|
| 665 |
+
# In other words, the VCS executable isn't available
|
| 666 |
+
raise BadCommand(
|
| 667 |
+
f"Cannot find command {cls.name!r} - do you have "
|
| 668 |
+
f"{cls.name!r} installed and in your PATH?"
|
| 669 |
+
)
|
| 670 |
+
except PermissionError:
|
| 671 |
+
# errno.EACCES = Permission denied
|
| 672 |
+
# This error occurs, for instance, when the command is installed
|
| 673 |
+
# only for another user. So, the current user don't have
|
| 674 |
+
# permission to call the other user command.
|
| 675 |
+
raise BadCommand(
|
| 676 |
+
f"No permission to execute {cls.name!r} - install it "
|
| 677 |
+
f"locally, globally (ask admin), or check your PATH. "
|
| 678 |
+
f"See possible solutions at "
|
| 679 |
+
f"https://pip.pypa.io/en/latest/reference/pip_freeze/"
|
| 680 |
+
f"#fixing-permission-denied."
|
| 681 |
+
)
|
| 682 |
+
|
| 683 |
+
@classmethod
|
| 684 |
+
def is_repository_directory(cls, path: str) -> bool:
|
| 685 |
+
"""
|
| 686 |
+
Return whether a directory path is a repository directory.
|
| 687 |
+
"""
|
| 688 |
+
logger.debug("Checking in %s for %s (%s)...", path, cls.dirname, cls.name)
|
| 689 |
+
return os.path.exists(os.path.join(path, cls.dirname))
|
| 690 |
+
|
| 691 |
+
@classmethod
|
| 692 |
+
def get_repository_root(cls, location: str) -> Optional[str]:
|
| 693 |
+
"""
|
| 694 |
+
Return the "root" (top-level) directory controlled by the vcs,
|
| 695 |
+
or `None` if the directory is not in any.
|
| 696 |
+
|
| 697 |
+
It is meant to be overridden to implement smarter detection
|
| 698 |
+
mechanisms for specific vcs.
|
| 699 |
+
|
| 700 |
+
This can do more than is_repository_directory() alone. For
|
| 701 |
+
example, the Git override checks that Git is actually available.
|
| 702 |
+
"""
|
| 703 |
+
if cls.is_repository_directory(location):
|
| 704 |
+
return location
|
| 705 |
+
return None
|
.venv/Lib/site-packages/pip/_vendor/__init__.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("urllib3")
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
"""CacheControl import Interface.
|
| 6 |
+
|
| 7 |
+
Make it easy to import from cachecontrol without long namespaces.
|
| 8 |
+
"""
|
| 9 |
+
__author__ = "Eric Larson"
|
| 10 |
+
__email__ = "eric@ionrock.org"
|
| 11 |
+
__version__ = "0.12.11"
|
| 12 |
+
|
| 13 |
+
from .wrapper import CacheControl
|
| 14 |
+
from .adapter import CacheControlAdapter
|
| 15 |
+
from .controller import CacheController
|
| 16 |
+
|
| 17 |
+
import logging
|
| 18 |
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/_cmd.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
from pip._vendor import requests
|
| 8 |
+
|
| 9 |
+
from pip._vendor.cachecontrol.adapter import CacheControlAdapter
|
| 10 |
+
from pip._vendor.cachecontrol.cache import DictCache
|
| 11 |
+
from pip._vendor.cachecontrol.controller import logger
|
| 12 |
+
|
| 13 |
+
from argparse import ArgumentParser
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def setup_logging():
|
| 17 |
+
logger.setLevel(logging.DEBUG)
|
| 18 |
+
handler = logging.StreamHandler()
|
| 19 |
+
logger.addHandler(handler)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def get_session():
|
| 23 |
+
adapter = CacheControlAdapter(
|
| 24 |
+
DictCache(), cache_etags=True, serializer=None, heuristic=None
|
| 25 |
+
)
|
| 26 |
+
sess = requests.Session()
|
| 27 |
+
sess.mount("http://", adapter)
|
| 28 |
+
sess.mount("https://", adapter)
|
| 29 |
+
|
| 30 |
+
sess.cache_controller = adapter.controller
|
| 31 |
+
return sess
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def get_args():
|
| 35 |
+
parser = ArgumentParser()
|
| 36 |
+
parser.add_argument("url", help="The URL to try and cache")
|
| 37 |
+
return parser.parse_args()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def main(args=None):
|
| 41 |
+
args = get_args()
|
| 42 |
+
sess = get_session()
|
| 43 |
+
|
| 44 |
+
# Make a request to get a response
|
| 45 |
+
resp = sess.get(args.url)
|
| 46 |
+
|
| 47 |
+
# Turn on logging
|
| 48 |
+
setup_logging()
|
| 49 |
+
|
| 50 |
+
# try setting the cache
|
| 51 |
+
sess.cache_controller.cache_response(resp.request, resp.raw)
|
| 52 |
+
|
| 53 |
+
# Now try to get it
|
| 54 |
+
if sess.cache_controller.cached_request(resp.request):
|
| 55 |
+
print("Cached!")
|
| 56 |
+
else:
|
| 57 |
+
print("Not cached :(")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
main()
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/adapter.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
import types
|
| 6 |
+
import functools
|
| 7 |
+
import zlib
|
| 8 |
+
|
| 9 |
+
from pip._vendor.requests.adapters import HTTPAdapter
|
| 10 |
+
|
| 11 |
+
from .controller import CacheController, PERMANENT_REDIRECT_STATUSES
|
| 12 |
+
from .cache import DictCache
|
| 13 |
+
from .filewrapper import CallbackFileWrapper
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class CacheControlAdapter(HTTPAdapter):
|
| 17 |
+
invalidating_methods = {"PUT", "PATCH", "DELETE"}
|
| 18 |
+
|
| 19 |
+
def __init__(
|
| 20 |
+
self,
|
| 21 |
+
cache=None,
|
| 22 |
+
cache_etags=True,
|
| 23 |
+
controller_class=None,
|
| 24 |
+
serializer=None,
|
| 25 |
+
heuristic=None,
|
| 26 |
+
cacheable_methods=None,
|
| 27 |
+
*args,
|
| 28 |
+
**kw
|
| 29 |
+
):
|
| 30 |
+
super(CacheControlAdapter, self).__init__(*args, **kw)
|
| 31 |
+
self.cache = DictCache() if cache is None else cache
|
| 32 |
+
self.heuristic = heuristic
|
| 33 |
+
self.cacheable_methods = cacheable_methods or ("GET",)
|
| 34 |
+
|
| 35 |
+
controller_factory = controller_class or CacheController
|
| 36 |
+
self.controller = controller_factory(
|
| 37 |
+
self.cache, cache_etags=cache_etags, serializer=serializer
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
def send(self, request, cacheable_methods=None, **kw):
|
| 41 |
+
"""
|
| 42 |
+
Send a request. Use the request information to see if it
|
| 43 |
+
exists in the cache and cache the response if we need to and can.
|
| 44 |
+
"""
|
| 45 |
+
cacheable = cacheable_methods or self.cacheable_methods
|
| 46 |
+
if request.method in cacheable:
|
| 47 |
+
try:
|
| 48 |
+
cached_response = self.controller.cached_request(request)
|
| 49 |
+
except zlib.error:
|
| 50 |
+
cached_response = None
|
| 51 |
+
if cached_response:
|
| 52 |
+
return self.build_response(request, cached_response, from_cache=True)
|
| 53 |
+
|
| 54 |
+
# check for etags and add headers if appropriate
|
| 55 |
+
request.headers.update(self.controller.conditional_headers(request))
|
| 56 |
+
|
| 57 |
+
resp = super(CacheControlAdapter, self).send(request, **kw)
|
| 58 |
+
|
| 59 |
+
return resp
|
| 60 |
+
|
| 61 |
+
def build_response(
|
| 62 |
+
self, request, response, from_cache=False, cacheable_methods=None
|
| 63 |
+
):
|
| 64 |
+
"""
|
| 65 |
+
Build a response by making a request or using the cache.
|
| 66 |
+
|
| 67 |
+
This will end up calling send and returning a potentially
|
| 68 |
+
cached response
|
| 69 |
+
"""
|
| 70 |
+
cacheable = cacheable_methods or self.cacheable_methods
|
| 71 |
+
if not from_cache and request.method in cacheable:
|
| 72 |
+
# Check for any heuristics that might update headers
|
| 73 |
+
# before trying to cache.
|
| 74 |
+
if self.heuristic:
|
| 75 |
+
response = self.heuristic.apply(response)
|
| 76 |
+
|
| 77 |
+
# apply any expiration heuristics
|
| 78 |
+
if response.status == 304:
|
| 79 |
+
# We must have sent an ETag request. This could mean
|
| 80 |
+
# that we've been expired already or that we simply
|
| 81 |
+
# have an etag. In either case, we want to try and
|
| 82 |
+
# update the cache if that is the case.
|
| 83 |
+
cached_response = self.controller.update_cached_response(
|
| 84 |
+
request, response
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
if cached_response is not response:
|
| 88 |
+
from_cache = True
|
| 89 |
+
|
| 90 |
+
# We are done with the server response, read a
|
| 91 |
+
# possible response body (compliant servers will
|
| 92 |
+
# not return one, but we cannot be 100% sure) and
|
| 93 |
+
# release the connection back to the pool.
|
| 94 |
+
response.read(decode_content=False)
|
| 95 |
+
response.release_conn()
|
| 96 |
+
|
| 97 |
+
response = cached_response
|
| 98 |
+
|
| 99 |
+
# We always cache the 301 responses
|
| 100 |
+
elif int(response.status) in PERMANENT_REDIRECT_STATUSES:
|
| 101 |
+
self.controller.cache_response(request, response)
|
| 102 |
+
else:
|
| 103 |
+
# Wrap the response file with a wrapper that will cache the
|
| 104 |
+
# response when the stream has been consumed.
|
| 105 |
+
response._fp = CallbackFileWrapper(
|
| 106 |
+
response._fp,
|
| 107 |
+
functools.partial(
|
| 108 |
+
self.controller.cache_response, request, response
|
| 109 |
+
),
|
| 110 |
+
)
|
| 111 |
+
if response.chunked:
|
| 112 |
+
super_update_chunk_length = response._update_chunk_length
|
| 113 |
+
|
| 114 |
+
def _update_chunk_length(self):
|
| 115 |
+
super_update_chunk_length()
|
| 116 |
+
if self.chunk_left == 0:
|
| 117 |
+
self._fp._close()
|
| 118 |
+
|
| 119 |
+
response._update_chunk_length = types.MethodType(
|
| 120 |
+
_update_chunk_length, response
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
resp = super(CacheControlAdapter, self).build_response(request, response)
|
| 124 |
+
|
| 125 |
+
# See if we should invalidate the cache.
|
| 126 |
+
if request.method in self.invalidating_methods and resp.ok:
|
| 127 |
+
cache_url = self.controller.cache_url(request.url)
|
| 128 |
+
self.cache.delete(cache_url)
|
| 129 |
+
|
| 130 |
+
# Give the request a from_cache attr to let people use it
|
| 131 |
+
resp.from_cache = from_cache
|
| 132 |
+
|
| 133 |
+
return resp
|
| 134 |
+
|
| 135 |
+
def close(self):
|
| 136 |
+
self.cache.close()
|
| 137 |
+
super(CacheControlAdapter, self).close()
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/cache.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
The cache object API for implementing caches. The default is a thread
|
| 7 |
+
safe in-memory dictionary.
|
| 8 |
+
"""
|
| 9 |
+
from threading import Lock
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class BaseCache(object):
|
| 13 |
+
|
| 14 |
+
def get(self, key):
|
| 15 |
+
raise NotImplementedError()
|
| 16 |
+
|
| 17 |
+
def set(self, key, value, expires=None):
|
| 18 |
+
raise NotImplementedError()
|
| 19 |
+
|
| 20 |
+
def delete(self, key):
|
| 21 |
+
raise NotImplementedError()
|
| 22 |
+
|
| 23 |
+
def close(self):
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class DictCache(BaseCache):
|
| 28 |
+
|
| 29 |
+
def __init__(self, init_dict=None):
|
| 30 |
+
self.lock = Lock()
|
| 31 |
+
self.data = init_dict or {}
|
| 32 |
+
|
| 33 |
+
def get(self, key):
|
| 34 |
+
return self.data.get(key, None)
|
| 35 |
+
|
| 36 |
+
def set(self, key, value, expires=None):
|
| 37 |
+
with self.lock:
|
| 38 |
+
self.data.update({key: value})
|
| 39 |
+
|
| 40 |
+
def delete(self, key):
|
| 41 |
+
with self.lock:
|
| 42 |
+
if key in self.data:
|
| 43 |
+
self.data.pop(key)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class SeparateBodyBaseCache(BaseCache):
|
| 47 |
+
"""
|
| 48 |
+
In this variant, the body is not stored mixed in with the metadata, but is
|
| 49 |
+
passed in (as a bytes-like object) in a separate call to ``set_body()``.
|
| 50 |
+
|
| 51 |
+
That is, the expected interaction pattern is::
|
| 52 |
+
|
| 53 |
+
cache.set(key, serialized_metadata)
|
| 54 |
+
cache.set_body(key)
|
| 55 |
+
|
| 56 |
+
Similarly, the body should be loaded separately via ``get_body()``.
|
| 57 |
+
"""
|
| 58 |
+
def set_body(self, key, body):
|
| 59 |
+
raise NotImplementedError()
|
| 60 |
+
|
| 61 |
+
def get_body(self, key):
|
| 62 |
+
"""
|
| 63 |
+
Return the body as file-like object.
|
| 64 |
+
"""
|
| 65 |
+
raise NotImplementedError()
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
from .file_cache import FileCache, SeparateBodyFileCache
|
| 6 |
+
from .redis_cache import RedisCache
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
__all__ = ["FileCache", "SeparateBodyFileCache", "RedisCache"]
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
import hashlib
|
| 6 |
+
import os
|
| 7 |
+
from textwrap import dedent
|
| 8 |
+
|
| 9 |
+
from ..cache import BaseCache, SeparateBodyBaseCache
|
| 10 |
+
from ..controller import CacheController
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
FileNotFoundError
|
| 14 |
+
except NameError:
|
| 15 |
+
# py2.X
|
| 16 |
+
FileNotFoundError = (IOError, OSError)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _secure_open_write(filename, fmode):
|
| 20 |
+
# We only want to write to this file, so open it in write only mode
|
| 21 |
+
flags = os.O_WRONLY
|
| 22 |
+
|
| 23 |
+
# os.O_CREAT | os.O_EXCL will fail if the file already exists, so we only
|
| 24 |
+
# will open *new* files.
|
| 25 |
+
# We specify this because we want to ensure that the mode we pass is the
|
| 26 |
+
# mode of the file.
|
| 27 |
+
flags |= os.O_CREAT | os.O_EXCL
|
| 28 |
+
|
| 29 |
+
# Do not follow symlinks to prevent someone from making a symlink that
|
| 30 |
+
# we follow and insecurely open a cache file.
|
| 31 |
+
if hasattr(os, "O_NOFOLLOW"):
|
| 32 |
+
flags |= os.O_NOFOLLOW
|
| 33 |
+
|
| 34 |
+
# On Windows we'll mark this file as binary
|
| 35 |
+
if hasattr(os, "O_BINARY"):
|
| 36 |
+
flags |= os.O_BINARY
|
| 37 |
+
|
| 38 |
+
# Before we open our file, we want to delete any existing file that is
|
| 39 |
+
# there
|
| 40 |
+
try:
|
| 41 |
+
os.remove(filename)
|
| 42 |
+
except (IOError, OSError):
|
| 43 |
+
# The file must not exist already, so we can just skip ahead to opening
|
| 44 |
+
pass
|
| 45 |
+
|
| 46 |
+
# Open our file, the use of os.O_CREAT | os.O_EXCL will ensure that if a
|
| 47 |
+
# race condition happens between the os.remove and this line, that an
|
| 48 |
+
# error will be raised. Because we utilize a lockfile this should only
|
| 49 |
+
# happen if someone is attempting to attack us.
|
| 50 |
+
fd = os.open(filename, flags, fmode)
|
| 51 |
+
try:
|
| 52 |
+
return os.fdopen(fd, "wb")
|
| 53 |
+
|
| 54 |
+
except:
|
| 55 |
+
# An error occurred wrapping our FD in a file object
|
| 56 |
+
os.close(fd)
|
| 57 |
+
raise
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class _FileCacheMixin:
|
| 61 |
+
"""Shared implementation for both FileCache variants."""
|
| 62 |
+
|
| 63 |
+
def __init__(
|
| 64 |
+
self,
|
| 65 |
+
directory,
|
| 66 |
+
forever=False,
|
| 67 |
+
filemode=0o0600,
|
| 68 |
+
dirmode=0o0700,
|
| 69 |
+
use_dir_lock=None,
|
| 70 |
+
lock_class=None,
|
| 71 |
+
):
|
| 72 |
+
|
| 73 |
+
if use_dir_lock is not None and lock_class is not None:
|
| 74 |
+
raise ValueError("Cannot use use_dir_lock and lock_class together")
|
| 75 |
+
|
| 76 |
+
try:
|
| 77 |
+
from lockfile import LockFile
|
| 78 |
+
from lockfile.mkdirlockfile import MkdirLockFile
|
| 79 |
+
except ImportError:
|
| 80 |
+
notice = dedent(
|
| 81 |
+
"""
|
| 82 |
+
NOTE: In order to use the FileCache you must have
|
| 83 |
+
lockfile installed. You can install it via pip:
|
| 84 |
+
pip install lockfile
|
| 85 |
+
"""
|
| 86 |
+
)
|
| 87 |
+
raise ImportError(notice)
|
| 88 |
+
|
| 89 |
+
else:
|
| 90 |
+
if use_dir_lock:
|
| 91 |
+
lock_class = MkdirLockFile
|
| 92 |
+
|
| 93 |
+
elif lock_class is None:
|
| 94 |
+
lock_class = LockFile
|
| 95 |
+
|
| 96 |
+
self.directory = directory
|
| 97 |
+
self.forever = forever
|
| 98 |
+
self.filemode = filemode
|
| 99 |
+
self.dirmode = dirmode
|
| 100 |
+
self.lock_class = lock_class
|
| 101 |
+
|
| 102 |
+
@staticmethod
|
| 103 |
+
def encode(x):
|
| 104 |
+
return hashlib.sha224(x.encode()).hexdigest()
|
| 105 |
+
|
| 106 |
+
def _fn(self, name):
|
| 107 |
+
# NOTE: This method should not change as some may depend on it.
|
| 108 |
+
# See: https://github.com/ionrock/cachecontrol/issues/63
|
| 109 |
+
hashed = self.encode(name)
|
| 110 |
+
parts = list(hashed[:5]) + [hashed]
|
| 111 |
+
return os.path.join(self.directory, *parts)
|
| 112 |
+
|
| 113 |
+
def get(self, key):
|
| 114 |
+
name = self._fn(key)
|
| 115 |
+
try:
|
| 116 |
+
with open(name, "rb") as fh:
|
| 117 |
+
return fh.read()
|
| 118 |
+
|
| 119 |
+
except FileNotFoundError:
|
| 120 |
+
return None
|
| 121 |
+
|
| 122 |
+
def set(self, key, value, expires=None):
|
| 123 |
+
name = self._fn(key)
|
| 124 |
+
self._write(name, value)
|
| 125 |
+
|
| 126 |
+
def _write(self, path, data: bytes):
|
| 127 |
+
"""
|
| 128 |
+
Safely write the data to the given path.
|
| 129 |
+
"""
|
| 130 |
+
# Make sure the directory exists
|
| 131 |
+
try:
|
| 132 |
+
os.makedirs(os.path.dirname(path), self.dirmode)
|
| 133 |
+
except (IOError, OSError):
|
| 134 |
+
pass
|
| 135 |
+
|
| 136 |
+
with self.lock_class(path) as lock:
|
| 137 |
+
# Write our actual file
|
| 138 |
+
with _secure_open_write(lock.path, self.filemode) as fh:
|
| 139 |
+
fh.write(data)
|
| 140 |
+
|
| 141 |
+
def _delete(self, key, suffix):
|
| 142 |
+
name = self._fn(key) + suffix
|
| 143 |
+
if not self.forever:
|
| 144 |
+
try:
|
| 145 |
+
os.remove(name)
|
| 146 |
+
except FileNotFoundError:
|
| 147 |
+
pass
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class FileCache(_FileCacheMixin, BaseCache):
|
| 151 |
+
"""
|
| 152 |
+
Traditional FileCache: body is stored in memory, so not suitable for large
|
| 153 |
+
downloads.
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
+
def delete(self, key):
|
| 157 |
+
self._delete(key, "")
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class SeparateBodyFileCache(_FileCacheMixin, SeparateBodyBaseCache):
|
| 161 |
+
"""
|
| 162 |
+
Memory-efficient FileCache: body is stored in a separate file, reducing
|
| 163 |
+
peak memory usage.
|
| 164 |
+
"""
|
| 165 |
+
|
| 166 |
+
def get_body(self, key):
|
| 167 |
+
name = self._fn(key) + ".body"
|
| 168 |
+
try:
|
| 169 |
+
return open(name, "rb")
|
| 170 |
+
except FileNotFoundError:
|
| 171 |
+
return None
|
| 172 |
+
|
| 173 |
+
def set_body(self, key, body):
|
| 174 |
+
name = self._fn(key) + ".body"
|
| 175 |
+
self._write(name, body)
|
| 176 |
+
|
| 177 |
+
def delete(self, key):
|
| 178 |
+
self._delete(key, "")
|
| 179 |
+
self._delete(key, ".body")
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def url_to_file_path(url, filecache):
|
| 183 |
+
"""Return the file cache path based on the URL.
|
| 184 |
+
|
| 185 |
+
This does not ensure the file exists!
|
| 186 |
+
"""
|
| 187 |
+
key = CacheController.cache_url(url)
|
| 188 |
+
return filecache._fn(key)
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/redis_cache.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
from __future__ import division
|
| 6 |
+
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
from pip._vendor.cachecontrol.cache import BaseCache
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class RedisCache(BaseCache):
|
| 12 |
+
|
| 13 |
+
def __init__(self, conn):
|
| 14 |
+
self.conn = conn
|
| 15 |
+
|
| 16 |
+
def get(self, key):
|
| 17 |
+
return self.conn.get(key)
|
| 18 |
+
|
| 19 |
+
def set(self, key, value, expires=None):
|
| 20 |
+
if not expires:
|
| 21 |
+
self.conn.set(key, value)
|
| 22 |
+
elif isinstance(expires, datetime):
|
| 23 |
+
expires = expires - datetime.utcnow()
|
| 24 |
+
self.conn.setex(key, int(expires.total_seconds()), value)
|
| 25 |
+
else:
|
| 26 |
+
self.conn.setex(key, expires, value)
|
| 27 |
+
|
| 28 |
+
def delete(self, key):
|
| 29 |
+
self.conn.delete(key)
|
| 30 |
+
|
| 31 |
+
def clear(self):
|
| 32 |
+
"""Helper for clearing all the keys in a database. Use with
|
| 33 |
+
caution!"""
|
| 34 |
+
for key in self.conn.keys():
|
| 35 |
+
self.conn.delete(key)
|
| 36 |
+
|
| 37 |
+
def close(self):
|
| 38 |
+
"""Redis uses connection pooling, no need to close the connection."""
|
| 39 |
+
pass
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/compat.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
from urllib.parse import urljoin
|
| 7 |
+
except ImportError:
|
| 8 |
+
from urlparse import urljoin
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
import cPickle as pickle
|
| 13 |
+
except ImportError:
|
| 14 |
+
import pickle
|
| 15 |
+
|
| 16 |
+
# Handle the case where the requests module has been patched to not have
|
| 17 |
+
# urllib3 bundled as part of its source.
|
| 18 |
+
try:
|
| 19 |
+
from pip._vendor.requests.packages.urllib3.response import HTTPResponse
|
| 20 |
+
except ImportError:
|
| 21 |
+
from pip._vendor.urllib3.response import HTTPResponse
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
from pip._vendor.requests.packages.urllib3.util import is_fp_closed
|
| 25 |
+
except ImportError:
|
| 26 |
+
from pip._vendor.urllib3.util import is_fp_closed
|
| 27 |
+
|
| 28 |
+
# Replicate some six behaviour
|
| 29 |
+
try:
|
| 30 |
+
text_type = unicode
|
| 31 |
+
except NameError:
|
| 32 |
+
text_type = str
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/controller.py
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
The httplib2 algorithms ported for use with requests.
|
| 7 |
+
"""
|
| 8 |
+
import logging
|
| 9 |
+
import re
|
| 10 |
+
import calendar
|
| 11 |
+
import time
|
| 12 |
+
from email.utils import parsedate_tz
|
| 13 |
+
|
| 14 |
+
from pip._vendor.requests.structures import CaseInsensitiveDict
|
| 15 |
+
|
| 16 |
+
from .cache import DictCache, SeparateBodyBaseCache
|
| 17 |
+
from .serialize import Serializer
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
logger = logging.getLogger(__name__)
|
| 21 |
+
|
| 22 |
+
URI = re.compile(r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?")
|
| 23 |
+
|
| 24 |
+
PERMANENT_REDIRECT_STATUSES = (301, 308)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def parse_uri(uri):
|
| 28 |
+
"""Parses a URI using the regex given in Appendix B of RFC 3986.
|
| 29 |
+
|
| 30 |
+
(scheme, authority, path, query, fragment) = parse_uri(uri)
|
| 31 |
+
"""
|
| 32 |
+
groups = URI.match(uri).groups()
|
| 33 |
+
return (groups[1], groups[3], groups[4], groups[6], groups[8])
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class CacheController(object):
|
| 37 |
+
"""An interface to see if request should cached or not."""
|
| 38 |
+
|
| 39 |
+
def __init__(
|
| 40 |
+
self, cache=None, cache_etags=True, serializer=None, status_codes=None
|
| 41 |
+
):
|
| 42 |
+
self.cache = DictCache() if cache is None else cache
|
| 43 |
+
self.cache_etags = cache_etags
|
| 44 |
+
self.serializer = serializer or Serializer()
|
| 45 |
+
self.cacheable_status_codes = status_codes or (200, 203, 300, 301, 308)
|
| 46 |
+
|
| 47 |
+
@classmethod
|
| 48 |
+
def _urlnorm(cls, uri):
|
| 49 |
+
"""Normalize the URL to create a safe key for the cache"""
|
| 50 |
+
(scheme, authority, path, query, fragment) = parse_uri(uri)
|
| 51 |
+
if not scheme or not authority:
|
| 52 |
+
raise Exception("Only absolute URIs are allowed. uri = %s" % uri)
|
| 53 |
+
|
| 54 |
+
scheme = scheme.lower()
|
| 55 |
+
authority = authority.lower()
|
| 56 |
+
|
| 57 |
+
if not path:
|
| 58 |
+
path = "/"
|
| 59 |
+
|
| 60 |
+
# Could do syntax based normalization of the URI before
|
| 61 |
+
# computing the digest. See Section 6.2.2 of Std 66.
|
| 62 |
+
request_uri = query and "?".join([path, query]) or path
|
| 63 |
+
defrag_uri = scheme + "://" + authority + request_uri
|
| 64 |
+
|
| 65 |
+
return defrag_uri
|
| 66 |
+
|
| 67 |
+
@classmethod
|
| 68 |
+
def cache_url(cls, uri):
|
| 69 |
+
return cls._urlnorm(uri)
|
| 70 |
+
|
| 71 |
+
def parse_cache_control(self, headers):
|
| 72 |
+
known_directives = {
|
| 73 |
+
# https://tools.ietf.org/html/rfc7234#section-5.2
|
| 74 |
+
"max-age": (int, True),
|
| 75 |
+
"max-stale": (int, False),
|
| 76 |
+
"min-fresh": (int, True),
|
| 77 |
+
"no-cache": (None, False),
|
| 78 |
+
"no-store": (None, False),
|
| 79 |
+
"no-transform": (None, False),
|
| 80 |
+
"only-if-cached": (None, False),
|
| 81 |
+
"must-revalidate": (None, False),
|
| 82 |
+
"public": (None, False),
|
| 83 |
+
"private": (None, False),
|
| 84 |
+
"proxy-revalidate": (None, False),
|
| 85 |
+
"s-maxage": (int, True),
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
cc_headers = headers.get("cache-control", headers.get("Cache-Control", ""))
|
| 89 |
+
|
| 90 |
+
retval = {}
|
| 91 |
+
|
| 92 |
+
for cc_directive in cc_headers.split(","):
|
| 93 |
+
if not cc_directive.strip():
|
| 94 |
+
continue
|
| 95 |
+
|
| 96 |
+
parts = cc_directive.split("=", 1)
|
| 97 |
+
directive = parts[0].strip()
|
| 98 |
+
|
| 99 |
+
try:
|
| 100 |
+
typ, required = known_directives[directive]
|
| 101 |
+
except KeyError:
|
| 102 |
+
logger.debug("Ignoring unknown cache-control directive: %s", directive)
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
if not typ or not required:
|
| 106 |
+
retval[directive] = None
|
| 107 |
+
if typ:
|
| 108 |
+
try:
|
| 109 |
+
retval[directive] = typ(parts[1].strip())
|
| 110 |
+
except IndexError:
|
| 111 |
+
if required:
|
| 112 |
+
logger.debug(
|
| 113 |
+
"Missing value for cache-control " "directive: %s",
|
| 114 |
+
directive,
|
| 115 |
+
)
|
| 116 |
+
except ValueError:
|
| 117 |
+
logger.debug(
|
| 118 |
+
"Invalid value for cache-control directive " "%s, must be %s",
|
| 119 |
+
directive,
|
| 120 |
+
typ.__name__,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
return retval
|
| 124 |
+
|
| 125 |
+
def cached_request(self, request):
|
| 126 |
+
"""
|
| 127 |
+
Return a cached response if it exists in the cache, otherwise
|
| 128 |
+
return False.
|
| 129 |
+
"""
|
| 130 |
+
cache_url = self.cache_url(request.url)
|
| 131 |
+
logger.debug('Looking up "%s" in the cache', cache_url)
|
| 132 |
+
cc = self.parse_cache_control(request.headers)
|
| 133 |
+
|
| 134 |
+
# Bail out if the request insists on fresh data
|
| 135 |
+
if "no-cache" in cc:
|
| 136 |
+
logger.debug('Request header has "no-cache", cache bypassed')
|
| 137 |
+
return False
|
| 138 |
+
|
| 139 |
+
if "max-age" in cc and cc["max-age"] == 0:
|
| 140 |
+
logger.debug('Request header has "max_age" as 0, cache bypassed')
|
| 141 |
+
return False
|
| 142 |
+
|
| 143 |
+
# Request allows serving from the cache, let's see if we find something
|
| 144 |
+
cache_data = self.cache.get(cache_url)
|
| 145 |
+
if cache_data is None:
|
| 146 |
+
logger.debug("No cache entry available")
|
| 147 |
+
return False
|
| 148 |
+
|
| 149 |
+
if isinstance(self.cache, SeparateBodyBaseCache):
|
| 150 |
+
body_file = self.cache.get_body(cache_url)
|
| 151 |
+
else:
|
| 152 |
+
body_file = None
|
| 153 |
+
|
| 154 |
+
# Check whether it can be deserialized
|
| 155 |
+
resp = self.serializer.loads(request, cache_data, body_file)
|
| 156 |
+
if not resp:
|
| 157 |
+
logger.warning("Cache entry deserialization failed, entry ignored")
|
| 158 |
+
return False
|
| 159 |
+
|
| 160 |
+
# If we have a cached permanent redirect, return it immediately. We
|
| 161 |
+
# don't need to test our response for other headers b/c it is
|
| 162 |
+
# intrinsically "cacheable" as it is Permanent.
|
| 163 |
+
#
|
| 164 |
+
# See:
|
| 165 |
+
# https://tools.ietf.org/html/rfc7231#section-6.4.2
|
| 166 |
+
#
|
| 167 |
+
# Client can try to refresh the value by repeating the request
|
| 168 |
+
# with cache busting headers as usual (ie no-cache).
|
| 169 |
+
if int(resp.status) in PERMANENT_REDIRECT_STATUSES:
|
| 170 |
+
msg = (
|
| 171 |
+
"Returning cached permanent redirect response "
|
| 172 |
+
"(ignoring date and etag information)"
|
| 173 |
+
)
|
| 174 |
+
logger.debug(msg)
|
| 175 |
+
return resp
|
| 176 |
+
|
| 177 |
+
headers = CaseInsensitiveDict(resp.headers)
|
| 178 |
+
if not headers or "date" not in headers:
|
| 179 |
+
if "etag" not in headers:
|
| 180 |
+
# Without date or etag, the cached response can never be used
|
| 181 |
+
# and should be deleted.
|
| 182 |
+
logger.debug("Purging cached response: no date or etag")
|
| 183 |
+
self.cache.delete(cache_url)
|
| 184 |
+
logger.debug("Ignoring cached response: no date")
|
| 185 |
+
return False
|
| 186 |
+
|
| 187 |
+
now = time.time()
|
| 188 |
+
date = calendar.timegm(parsedate_tz(headers["date"]))
|
| 189 |
+
current_age = max(0, now - date)
|
| 190 |
+
logger.debug("Current age based on date: %i", current_age)
|
| 191 |
+
|
| 192 |
+
# TODO: There is an assumption that the result will be a
|
| 193 |
+
# urllib3 response object. This may not be best since we
|
| 194 |
+
# could probably avoid instantiating or constructing the
|
| 195 |
+
# response until we know we need it.
|
| 196 |
+
resp_cc = self.parse_cache_control(headers)
|
| 197 |
+
|
| 198 |
+
# determine freshness
|
| 199 |
+
freshness_lifetime = 0
|
| 200 |
+
|
| 201 |
+
# Check the max-age pragma in the cache control header
|
| 202 |
+
if "max-age" in resp_cc:
|
| 203 |
+
freshness_lifetime = resp_cc["max-age"]
|
| 204 |
+
logger.debug("Freshness lifetime from max-age: %i", freshness_lifetime)
|
| 205 |
+
|
| 206 |
+
# If there isn't a max-age, check for an expires header
|
| 207 |
+
elif "expires" in headers:
|
| 208 |
+
expires = parsedate_tz(headers["expires"])
|
| 209 |
+
if expires is not None:
|
| 210 |
+
expire_time = calendar.timegm(expires) - date
|
| 211 |
+
freshness_lifetime = max(0, expire_time)
|
| 212 |
+
logger.debug("Freshness lifetime from expires: %i", freshness_lifetime)
|
| 213 |
+
|
| 214 |
+
# Determine if we are setting freshness limit in the
|
| 215 |
+
# request. Note, this overrides what was in the response.
|
| 216 |
+
if "max-age" in cc:
|
| 217 |
+
freshness_lifetime = cc["max-age"]
|
| 218 |
+
logger.debug(
|
| 219 |
+
"Freshness lifetime from request max-age: %i", freshness_lifetime
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
if "min-fresh" in cc:
|
| 223 |
+
min_fresh = cc["min-fresh"]
|
| 224 |
+
# adjust our current age by our min fresh
|
| 225 |
+
current_age += min_fresh
|
| 226 |
+
logger.debug("Adjusted current age from min-fresh: %i", current_age)
|
| 227 |
+
|
| 228 |
+
# Return entry if it is fresh enough
|
| 229 |
+
if freshness_lifetime > current_age:
|
| 230 |
+
logger.debug('The response is "fresh", returning cached response')
|
| 231 |
+
logger.debug("%i > %i", freshness_lifetime, current_age)
|
| 232 |
+
return resp
|
| 233 |
+
|
| 234 |
+
# we're not fresh. If we don't have an Etag, clear it out
|
| 235 |
+
if "etag" not in headers:
|
| 236 |
+
logger.debug('The cached response is "stale" with no etag, purging')
|
| 237 |
+
self.cache.delete(cache_url)
|
| 238 |
+
|
| 239 |
+
# return the original handler
|
| 240 |
+
return False
|
| 241 |
+
|
| 242 |
+
def conditional_headers(self, request):
|
| 243 |
+
cache_url = self.cache_url(request.url)
|
| 244 |
+
resp = self.serializer.loads(request, self.cache.get(cache_url))
|
| 245 |
+
new_headers = {}
|
| 246 |
+
|
| 247 |
+
if resp:
|
| 248 |
+
headers = CaseInsensitiveDict(resp.headers)
|
| 249 |
+
|
| 250 |
+
if "etag" in headers:
|
| 251 |
+
new_headers["If-None-Match"] = headers["ETag"]
|
| 252 |
+
|
| 253 |
+
if "last-modified" in headers:
|
| 254 |
+
new_headers["If-Modified-Since"] = headers["Last-Modified"]
|
| 255 |
+
|
| 256 |
+
return new_headers
|
| 257 |
+
|
| 258 |
+
def _cache_set(self, cache_url, request, response, body=None, expires_time=None):
|
| 259 |
+
"""
|
| 260 |
+
Store the data in the cache.
|
| 261 |
+
"""
|
| 262 |
+
if isinstance(self.cache, SeparateBodyBaseCache):
|
| 263 |
+
# We pass in the body separately; just put a placeholder empty
|
| 264 |
+
# string in the metadata.
|
| 265 |
+
self.cache.set(
|
| 266 |
+
cache_url,
|
| 267 |
+
self.serializer.dumps(request, response, b""),
|
| 268 |
+
expires=expires_time,
|
| 269 |
+
)
|
| 270 |
+
self.cache.set_body(cache_url, body)
|
| 271 |
+
else:
|
| 272 |
+
self.cache.set(
|
| 273 |
+
cache_url,
|
| 274 |
+
self.serializer.dumps(request, response, body),
|
| 275 |
+
expires=expires_time,
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
def cache_response(self, request, response, body=None, status_codes=None):
|
| 279 |
+
"""
|
| 280 |
+
Algorithm for caching requests.
|
| 281 |
+
|
| 282 |
+
This assumes a requests Response object.
|
| 283 |
+
"""
|
| 284 |
+
# From httplib2: Don't cache 206's since we aren't going to
|
| 285 |
+
# handle byte range requests
|
| 286 |
+
cacheable_status_codes = status_codes or self.cacheable_status_codes
|
| 287 |
+
if response.status not in cacheable_status_codes:
|
| 288 |
+
logger.debug(
|
| 289 |
+
"Status code %s not in %s", response.status, cacheable_status_codes
|
| 290 |
+
)
|
| 291 |
+
return
|
| 292 |
+
|
| 293 |
+
response_headers = CaseInsensitiveDict(response.headers)
|
| 294 |
+
|
| 295 |
+
if "date" in response_headers:
|
| 296 |
+
date = calendar.timegm(parsedate_tz(response_headers["date"]))
|
| 297 |
+
else:
|
| 298 |
+
date = 0
|
| 299 |
+
|
| 300 |
+
# If we've been given a body, our response has a Content-Length, that
|
| 301 |
+
# Content-Length is valid then we can check to see if the body we've
|
| 302 |
+
# been given matches the expected size, and if it doesn't we'll just
|
| 303 |
+
# skip trying to cache it.
|
| 304 |
+
if (
|
| 305 |
+
body is not None
|
| 306 |
+
and "content-length" in response_headers
|
| 307 |
+
and response_headers["content-length"].isdigit()
|
| 308 |
+
and int(response_headers["content-length"]) != len(body)
|
| 309 |
+
):
|
| 310 |
+
return
|
| 311 |
+
|
| 312 |
+
cc_req = self.parse_cache_control(request.headers)
|
| 313 |
+
cc = self.parse_cache_control(response_headers)
|
| 314 |
+
|
| 315 |
+
cache_url = self.cache_url(request.url)
|
| 316 |
+
logger.debug('Updating cache with response from "%s"', cache_url)
|
| 317 |
+
|
| 318 |
+
# Delete it from the cache if we happen to have it stored there
|
| 319 |
+
no_store = False
|
| 320 |
+
if "no-store" in cc:
|
| 321 |
+
no_store = True
|
| 322 |
+
logger.debug('Response header has "no-store"')
|
| 323 |
+
if "no-store" in cc_req:
|
| 324 |
+
no_store = True
|
| 325 |
+
logger.debug('Request header has "no-store"')
|
| 326 |
+
if no_store and self.cache.get(cache_url):
|
| 327 |
+
logger.debug('Purging existing cache entry to honor "no-store"')
|
| 328 |
+
self.cache.delete(cache_url)
|
| 329 |
+
if no_store:
|
| 330 |
+
return
|
| 331 |
+
|
| 332 |
+
# https://tools.ietf.org/html/rfc7234#section-4.1:
|
| 333 |
+
# A Vary header field-value of "*" always fails to match.
|
| 334 |
+
# Storing such a response leads to a deserialization warning
|
| 335 |
+
# during cache lookup and is not allowed to ever be served,
|
| 336 |
+
# so storing it can be avoided.
|
| 337 |
+
if "*" in response_headers.get("vary", ""):
|
| 338 |
+
logger.debug('Response header has "Vary: *"')
|
| 339 |
+
return
|
| 340 |
+
|
| 341 |
+
# If we've been given an etag, then keep the response
|
| 342 |
+
if self.cache_etags and "etag" in response_headers:
|
| 343 |
+
expires_time = 0
|
| 344 |
+
if response_headers.get("expires"):
|
| 345 |
+
expires = parsedate_tz(response_headers["expires"])
|
| 346 |
+
if expires is not None:
|
| 347 |
+
expires_time = calendar.timegm(expires) - date
|
| 348 |
+
|
| 349 |
+
expires_time = max(expires_time, 14 * 86400)
|
| 350 |
+
|
| 351 |
+
logger.debug("etag object cached for {0} seconds".format(expires_time))
|
| 352 |
+
logger.debug("Caching due to etag")
|
| 353 |
+
self._cache_set(cache_url, request, response, body, expires_time)
|
| 354 |
+
|
| 355 |
+
# Add to the cache any permanent redirects. We do this before looking
|
| 356 |
+
# that the Date headers.
|
| 357 |
+
elif int(response.status) in PERMANENT_REDIRECT_STATUSES:
|
| 358 |
+
logger.debug("Caching permanent redirect")
|
| 359 |
+
self._cache_set(cache_url, request, response, b"")
|
| 360 |
+
|
| 361 |
+
# Add to the cache if the response headers demand it. If there
|
| 362 |
+
# is no date header then we can't do anything about expiring
|
| 363 |
+
# the cache.
|
| 364 |
+
elif "date" in response_headers:
|
| 365 |
+
date = calendar.timegm(parsedate_tz(response_headers["date"]))
|
| 366 |
+
# cache when there is a max-age > 0
|
| 367 |
+
if "max-age" in cc and cc["max-age"] > 0:
|
| 368 |
+
logger.debug("Caching b/c date exists and max-age > 0")
|
| 369 |
+
expires_time = cc["max-age"]
|
| 370 |
+
self._cache_set(
|
| 371 |
+
cache_url,
|
| 372 |
+
request,
|
| 373 |
+
response,
|
| 374 |
+
body,
|
| 375 |
+
expires_time,
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
# If the request can expire, it means we should cache it
|
| 379 |
+
# in the meantime.
|
| 380 |
+
elif "expires" in response_headers:
|
| 381 |
+
if response_headers["expires"]:
|
| 382 |
+
expires = parsedate_tz(response_headers["expires"])
|
| 383 |
+
if expires is not None:
|
| 384 |
+
expires_time = calendar.timegm(expires) - date
|
| 385 |
+
else:
|
| 386 |
+
expires_time = None
|
| 387 |
+
|
| 388 |
+
logger.debug(
|
| 389 |
+
"Caching b/c of expires header. expires in {0} seconds".format(
|
| 390 |
+
expires_time
|
| 391 |
+
)
|
| 392 |
+
)
|
| 393 |
+
self._cache_set(
|
| 394 |
+
cache_url,
|
| 395 |
+
request,
|
| 396 |
+
response,
|
| 397 |
+
body,
|
| 398 |
+
expires_time,
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
def update_cached_response(self, request, response):
|
| 402 |
+
"""On a 304 we will get a new set of headers that we want to
|
| 403 |
+
update our cached value with, assuming we have one.
|
| 404 |
+
|
| 405 |
+
This should only ever be called when we've sent an ETag and
|
| 406 |
+
gotten a 304 as the response.
|
| 407 |
+
"""
|
| 408 |
+
cache_url = self.cache_url(request.url)
|
| 409 |
+
|
| 410 |
+
cached_response = self.serializer.loads(request, self.cache.get(cache_url))
|
| 411 |
+
|
| 412 |
+
if not cached_response:
|
| 413 |
+
# we didn't have a cached response
|
| 414 |
+
return response
|
| 415 |
+
|
| 416 |
+
# Lets update our headers with the headers from the new request:
|
| 417 |
+
# http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-26#section-4.1
|
| 418 |
+
#
|
| 419 |
+
# The server isn't supposed to send headers that would make
|
| 420 |
+
# the cached body invalid. But... just in case, we'll be sure
|
| 421 |
+
# to strip out ones we know that might be problmatic due to
|
| 422 |
+
# typical assumptions.
|
| 423 |
+
excluded_headers = ["content-length"]
|
| 424 |
+
|
| 425 |
+
cached_response.headers.update(
|
| 426 |
+
dict(
|
| 427 |
+
(k, v)
|
| 428 |
+
for k, v in response.headers.items()
|
| 429 |
+
if k.lower() not in excluded_headers
|
| 430 |
+
)
|
| 431 |
+
)
|
| 432 |
+
|
| 433 |
+
# we want a 200 b/c we have content via the cache
|
| 434 |
+
cached_response.status = 200
|
| 435 |
+
|
| 436 |
+
# update our cache
|
| 437 |
+
self._cache_set(cache_url, request, cached_response)
|
| 438 |
+
|
| 439 |
+
return cached_response
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/filewrapper.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
from tempfile import NamedTemporaryFile
|
| 6 |
+
import mmap
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class CallbackFileWrapper(object):
|
| 10 |
+
"""
|
| 11 |
+
Small wrapper around a fp object which will tee everything read into a
|
| 12 |
+
buffer, and when that file is closed it will execute a callback with the
|
| 13 |
+
contents of that buffer.
|
| 14 |
+
|
| 15 |
+
All attributes are proxied to the underlying file object.
|
| 16 |
+
|
| 17 |
+
This class uses members with a double underscore (__) leading prefix so as
|
| 18 |
+
not to accidentally shadow an attribute.
|
| 19 |
+
|
| 20 |
+
The data is stored in a temporary file until it is all available. As long
|
| 21 |
+
as the temporary files directory is disk-based (sometimes it's a
|
| 22 |
+
memory-backed-``tmpfs`` on Linux), data will be unloaded to disk if memory
|
| 23 |
+
pressure is high. For small files the disk usually won't be used at all,
|
| 24 |
+
it'll all be in the filesystem memory cache, so there should be no
|
| 25 |
+
performance impact.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def __init__(self, fp, callback):
|
| 29 |
+
self.__buf = NamedTemporaryFile("rb+", delete=True)
|
| 30 |
+
self.__fp = fp
|
| 31 |
+
self.__callback = callback
|
| 32 |
+
|
| 33 |
+
def __getattr__(self, name):
|
| 34 |
+
# The vaguaries of garbage collection means that self.__fp is
|
| 35 |
+
# not always set. By using __getattribute__ and the private
|
| 36 |
+
# name[0] allows looking up the attribute value and raising an
|
| 37 |
+
# AttributeError when it doesn't exist. This stop thigns from
|
| 38 |
+
# infinitely recursing calls to getattr in the case where
|
| 39 |
+
# self.__fp hasn't been set.
|
| 40 |
+
#
|
| 41 |
+
# [0] https://docs.python.org/2/reference/expressions.html#atom-identifiers
|
| 42 |
+
fp = self.__getattribute__("_CallbackFileWrapper__fp")
|
| 43 |
+
return getattr(fp, name)
|
| 44 |
+
|
| 45 |
+
def __is_fp_closed(self):
|
| 46 |
+
try:
|
| 47 |
+
return self.__fp.fp is None
|
| 48 |
+
|
| 49 |
+
except AttributeError:
|
| 50 |
+
pass
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
return self.__fp.closed
|
| 54 |
+
|
| 55 |
+
except AttributeError:
|
| 56 |
+
pass
|
| 57 |
+
|
| 58 |
+
# We just don't cache it then.
|
| 59 |
+
# TODO: Add some logging here...
|
| 60 |
+
return False
|
| 61 |
+
|
| 62 |
+
def _close(self):
|
| 63 |
+
if self.__callback:
|
| 64 |
+
if self.__buf.tell() == 0:
|
| 65 |
+
# Empty file:
|
| 66 |
+
result = b""
|
| 67 |
+
else:
|
| 68 |
+
# Return the data without actually loading it into memory,
|
| 69 |
+
# relying on Python's buffer API and mmap(). mmap() just gives
|
| 70 |
+
# a view directly into the filesystem's memory cache, so it
|
| 71 |
+
# doesn't result in duplicate memory use.
|
| 72 |
+
self.__buf.seek(0, 0)
|
| 73 |
+
result = memoryview(
|
| 74 |
+
mmap.mmap(self.__buf.fileno(), 0, access=mmap.ACCESS_READ)
|
| 75 |
+
)
|
| 76 |
+
self.__callback(result)
|
| 77 |
+
|
| 78 |
+
# We assign this to None here, because otherwise we can get into
|
| 79 |
+
# really tricky problems where the CPython interpreter dead locks
|
| 80 |
+
# because the callback is holding a reference to something which
|
| 81 |
+
# has a __del__ method. Setting this to None breaks the cycle
|
| 82 |
+
# and allows the garbage collector to do it's thing normally.
|
| 83 |
+
self.__callback = None
|
| 84 |
+
|
| 85 |
+
# Closing the temporary file releases memory and frees disk space.
|
| 86 |
+
# Important when caching big files.
|
| 87 |
+
self.__buf.close()
|
| 88 |
+
|
| 89 |
+
def read(self, amt=None):
|
| 90 |
+
data = self.__fp.read(amt)
|
| 91 |
+
if data:
|
| 92 |
+
# We may be dealing with b'', a sign that things are over:
|
| 93 |
+
# it's passed e.g. after we've already closed self.__buf.
|
| 94 |
+
self.__buf.write(data)
|
| 95 |
+
if self.__is_fp_closed():
|
| 96 |
+
self._close()
|
| 97 |
+
|
| 98 |
+
return data
|
| 99 |
+
|
| 100 |
+
def _safe_read(self, amt):
|
| 101 |
+
data = self.__fp._safe_read(amt)
|
| 102 |
+
if amt == 2 and data == b"\r\n":
|
| 103 |
+
# urllib executes this read to toss the CRLF at the end
|
| 104 |
+
# of the chunk.
|
| 105 |
+
return data
|
| 106 |
+
|
| 107 |
+
self.__buf.write(data)
|
| 108 |
+
if self.__is_fp_closed():
|
| 109 |
+
self._close()
|
| 110 |
+
|
| 111 |
+
return data
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/heuristics.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
import calendar
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
from email.utils import formatdate, parsedate, parsedate_tz
|
| 9 |
+
|
| 10 |
+
from datetime import datetime, timedelta
|
| 11 |
+
|
| 12 |
+
TIME_FMT = "%a, %d %b %Y %H:%M:%S GMT"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def expire_after(delta, date=None):
|
| 16 |
+
date = date or datetime.utcnow()
|
| 17 |
+
return date + delta
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def datetime_to_header(dt):
|
| 21 |
+
return formatdate(calendar.timegm(dt.timetuple()))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class BaseHeuristic(object):
|
| 25 |
+
|
| 26 |
+
def warning(self, response):
|
| 27 |
+
"""
|
| 28 |
+
Return a valid 1xx warning header value describing the cache
|
| 29 |
+
adjustments.
|
| 30 |
+
|
| 31 |
+
The response is provided too allow warnings like 113
|
| 32 |
+
http://tools.ietf.org/html/rfc7234#section-5.5.4 where we need
|
| 33 |
+
to explicitly say response is over 24 hours old.
|
| 34 |
+
"""
|
| 35 |
+
return '110 - "Response is Stale"'
|
| 36 |
+
|
| 37 |
+
def update_headers(self, response):
|
| 38 |
+
"""Update the response headers with any new headers.
|
| 39 |
+
|
| 40 |
+
NOTE: This SHOULD always include some Warning header to
|
| 41 |
+
signify that the response was cached by the client, not
|
| 42 |
+
by way of the provided headers.
|
| 43 |
+
"""
|
| 44 |
+
return {}
|
| 45 |
+
|
| 46 |
+
def apply(self, response):
|
| 47 |
+
updated_headers = self.update_headers(response)
|
| 48 |
+
|
| 49 |
+
if updated_headers:
|
| 50 |
+
response.headers.update(updated_headers)
|
| 51 |
+
warning_header_value = self.warning(response)
|
| 52 |
+
if warning_header_value is not None:
|
| 53 |
+
response.headers.update({"Warning": warning_header_value})
|
| 54 |
+
|
| 55 |
+
return response
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class OneDayCache(BaseHeuristic):
|
| 59 |
+
"""
|
| 60 |
+
Cache the response by providing an expires 1 day in the
|
| 61 |
+
future.
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
def update_headers(self, response):
|
| 65 |
+
headers = {}
|
| 66 |
+
|
| 67 |
+
if "expires" not in response.headers:
|
| 68 |
+
date = parsedate(response.headers["date"])
|
| 69 |
+
expires = expire_after(timedelta(days=1), date=datetime(*date[:6]))
|
| 70 |
+
headers["expires"] = datetime_to_header(expires)
|
| 71 |
+
headers["cache-control"] = "public"
|
| 72 |
+
return headers
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class ExpiresAfter(BaseHeuristic):
|
| 76 |
+
"""
|
| 77 |
+
Cache **all** requests for a defined time period.
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
def __init__(self, **kw):
|
| 81 |
+
self.delta = timedelta(**kw)
|
| 82 |
+
|
| 83 |
+
def update_headers(self, response):
|
| 84 |
+
expires = expire_after(self.delta)
|
| 85 |
+
return {"expires": datetime_to_header(expires), "cache-control": "public"}
|
| 86 |
+
|
| 87 |
+
def warning(self, response):
|
| 88 |
+
tmpl = "110 - Automatically cached for %s. Response might be stale"
|
| 89 |
+
return tmpl % self.delta
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class LastModified(BaseHeuristic):
|
| 93 |
+
"""
|
| 94 |
+
If there is no Expires header already, fall back on Last-Modified
|
| 95 |
+
using the heuristic from
|
| 96 |
+
http://tools.ietf.org/html/rfc7234#section-4.2.2
|
| 97 |
+
to calculate a reasonable value.
|
| 98 |
+
|
| 99 |
+
Firefox also does something like this per
|
| 100 |
+
https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching_FAQ
|
| 101 |
+
http://lxr.mozilla.org/mozilla-release/source/netwerk/protocol/http/nsHttpResponseHead.cpp#397
|
| 102 |
+
Unlike mozilla we limit this to 24-hr.
|
| 103 |
+
"""
|
| 104 |
+
cacheable_by_default_statuses = {
|
| 105 |
+
200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
def update_headers(self, resp):
|
| 109 |
+
headers = resp.headers
|
| 110 |
+
|
| 111 |
+
if "expires" in headers:
|
| 112 |
+
return {}
|
| 113 |
+
|
| 114 |
+
if "cache-control" in headers and headers["cache-control"] != "public":
|
| 115 |
+
return {}
|
| 116 |
+
|
| 117 |
+
if resp.status not in self.cacheable_by_default_statuses:
|
| 118 |
+
return {}
|
| 119 |
+
|
| 120 |
+
if "date" not in headers or "last-modified" not in headers:
|
| 121 |
+
return {}
|
| 122 |
+
|
| 123 |
+
date = calendar.timegm(parsedate_tz(headers["date"]))
|
| 124 |
+
last_modified = parsedate(headers["last-modified"])
|
| 125 |
+
if date is None or last_modified is None:
|
| 126 |
+
return {}
|
| 127 |
+
|
| 128 |
+
now = time.time()
|
| 129 |
+
current_age = max(0, now - date)
|
| 130 |
+
delta = date - calendar.timegm(last_modified)
|
| 131 |
+
freshness_lifetime = max(0, min(delta / 10, 24 * 3600))
|
| 132 |
+
if freshness_lifetime <= current_age:
|
| 133 |
+
return {}
|
| 134 |
+
|
| 135 |
+
expires = date + freshness_lifetime
|
| 136 |
+
return {"expires": time.strftime(TIME_FMT, time.gmtime(expires))}
|
| 137 |
+
|
| 138 |
+
def warning(self, resp):
|
| 139 |
+
return None
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/serialize.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
import base64
|
| 6 |
+
import io
|
| 7 |
+
import json
|
| 8 |
+
import zlib
|
| 9 |
+
|
| 10 |
+
from pip._vendor import msgpack
|
| 11 |
+
from pip._vendor.requests.structures import CaseInsensitiveDict
|
| 12 |
+
|
| 13 |
+
from .compat import HTTPResponse, pickle, text_type
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _b64_decode_bytes(b):
|
| 17 |
+
return base64.b64decode(b.encode("ascii"))
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _b64_decode_str(s):
|
| 21 |
+
return _b64_decode_bytes(s).decode("utf8")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
_default_body_read = object()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Serializer(object):
|
| 28 |
+
def dumps(self, request, response, body=None):
|
| 29 |
+
response_headers = CaseInsensitiveDict(response.headers)
|
| 30 |
+
|
| 31 |
+
if body is None:
|
| 32 |
+
# When a body isn't passed in, we'll read the response. We
|
| 33 |
+
# also update the response with a new file handler to be
|
| 34 |
+
# sure it acts as though it was never read.
|
| 35 |
+
body = response.read(decode_content=False)
|
| 36 |
+
response._fp = io.BytesIO(body)
|
| 37 |
+
|
| 38 |
+
# NOTE: This is all a bit weird, but it's really important that on
|
| 39 |
+
# Python 2.x these objects are unicode and not str, even when
|
| 40 |
+
# they contain only ascii. The problem here is that msgpack
|
| 41 |
+
# understands the difference between unicode and bytes and we
|
| 42 |
+
# have it set to differentiate between them, however Python 2
|
| 43 |
+
# doesn't know the difference. Forcing these to unicode will be
|
| 44 |
+
# enough to have msgpack know the difference.
|
| 45 |
+
data = {
|
| 46 |
+
u"response": {
|
| 47 |
+
u"body": body, # Empty bytestring if body is stored separately
|
| 48 |
+
u"headers": dict(
|
| 49 |
+
(text_type(k), text_type(v)) for k, v in response.headers.items()
|
| 50 |
+
),
|
| 51 |
+
u"status": response.status,
|
| 52 |
+
u"version": response.version,
|
| 53 |
+
u"reason": text_type(response.reason),
|
| 54 |
+
u"strict": response.strict,
|
| 55 |
+
u"decode_content": response.decode_content,
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Construct our vary headers
|
| 60 |
+
data[u"vary"] = {}
|
| 61 |
+
if u"vary" in response_headers:
|
| 62 |
+
varied_headers = response_headers[u"vary"].split(",")
|
| 63 |
+
for header in varied_headers:
|
| 64 |
+
header = text_type(header).strip()
|
| 65 |
+
header_value = request.headers.get(header, None)
|
| 66 |
+
if header_value is not None:
|
| 67 |
+
header_value = text_type(header_value)
|
| 68 |
+
data[u"vary"][header] = header_value
|
| 69 |
+
|
| 70 |
+
return b",".join([b"cc=4", msgpack.dumps(data, use_bin_type=True)])
|
| 71 |
+
|
| 72 |
+
def loads(self, request, data, body_file=None):
|
| 73 |
+
# Short circuit if we've been given an empty set of data
|
| 74 |
+
if not data:
|
| 75 |
+
return
|
| 76 |
+
|
| 77 |
+
# Determine what version of the serializer the data was serialized
|
| 78 |
+
# with
|
| 79 |
+
try:
|
| 80 |
+
ver, data = data.split(b",", 1)
|
| 81 |
+
except ValueError:
|
| 82 |
+
ver = b"cc=0"
|
| 83 |
+
|
| 84 |
+
# Make sure that our "ver" is actually a version and isn't a false
|
| 85 |
+
# positive from a , being in the data stream.
|
| 86 |
+
if ver[:3] != b"cc=":
|
| 87 |
+
data = ver + data
|
| 88 |
+
ver = b"cc=0"
|
| 89 |
+
|
| 90 |
+
# Get the version number out of the cc=N
|
| 91 |
+
ver = ver.split(b"=", 1)[-1].decode("ascii")
|
| 92 |
+
|
| 93 |
+
# Dispatch to the actual load method for the given version
|
| 94 |
+
try:
|
| 95 |
+
return getattr(self, "_loads_v{}".format(ver))(request, data, body_file)
|
| 96 |
+
|
| 97 |
+
except AttributeError:
|
| 98 |
+
# This is a version we don't have a loads function for, so we'll
|
| 99 |
+
# just treat it as a miss and return None
|
| 100 |
+
return
|
| 101 |
+
|
| 102 |
+
def prepare_response(self, request, cached, body_file=None):
|
| 103 |
+
"""Verify our vary headers match and construct a real urllib3
|
| 104 |
+
HTTPResponse object.
|
| 105 |
+
"""
|
| 106 |
+
# Special case the '*' Vary value as it means we cannot actually
|
| 107 |
+
# determine if the cached response is suitable for this request.
|
| 108 |
+
# This case is also handled in the controller code when creating
|
| 109 |
+
# a cache entry, but is left here for backwards compatibility.
|
| 110 |
+
if "*" in cached.get("vary", {}):
|
| 111 |
+
return
|
| 112 |
+
|
| 113 |
+
# Ensure that the Vary headers for the cached response match our
|
| 114 |
+
# request
|
| 115 |
+
for header, value in cached.get("vary", {}).items():
|
| 116 |
+
if request.headers.get(header, None) != value:
|
| 117 |
+
return
|
| 118 |
+
|
| 119 |
+
body_raw = cached["response"].pop("body")
|
| 120 |
+
|
| 121 |
+
headers = CaseInsensitiveDict(data=cached["response"]["headers"])
|
| 122 |
+
if headers.get("transfer-encoding", "") == "chunked":
|
| 123 |
+
headers.pop("transfer-encoding")
|
| 124 |
+
|
| 125 |
+
cached["response"]["headers"] = headers
|
| 126 |
+
|
| 127 |
+
try:
|
| 128 |
+
if body_file is None:
|
| 129 |
+
body = io.BytesIO(body_raw)
|
| 130 |
+
else:
|
| 131 |
+
body = body_file
|
| 132 |
+
except TypeError:
|
| 133 |
+
# This can happen if cachecontrol serialized to v1 format (pickle)
|
| 134 |
+
# using Python 2. A Python 2 str(byte string) will be unpickled as
|
| 135 |
+
# a Python 3 str (unicode string), which will cause the above to
|
| 136 |
+
# fail with:
|
| 137 |
+
#
|
| 138 |
+
# TypeError: 'str' does not support the buffer interface
|
| 139 |
+
body = io.BytesIO(body_raw.encode("utf8"))
|
| 140 |
+
|
| 141 |
+
return HTTPResponse(body=body, preload_content=False, **cached["response"])
|
| 142 |
+
|
| 143 |
+
def _loads_v0(self, request, data, body_file=None):
|
| 144 |
+
# The original legacy cache data. This doesn't contain enough
|
| 145 |
+
# information to construct everything we need, so we'll treat this as
|
| 146 |
+
# a miss.
|
| 147 |
+
return
|
| 148 |
+
|
| 149 |
+
def _loads_v1(self, request, data, body_file=None):
|
| 150 |
+
try:
|
| 151 |
+
cached = pickle.loads(data)
|
| 152 |
+
except ValueError:
|
| 153 |
+
return
|
| 154 |
+
|
| 155 |
+
return self.prepare_response(request, cached, body_file)
|
| 156 |
+
|
| 157 |
+
def _loads_v2(self, request, data, body_file=None):
|
| 158 |
+
assert body_file is None
|
| 159 |
+
try:
|
| 160 |
+
cached = json.loads(zlib.decompress(data).decode("utf8"))
|
| 161 |
+
except (ValueError, zlib.error):
|
| 162 |
+
return
|
| 163 |
+
|
| 164 |
+
# We need to decode the items that we've base64 encoded
|
| 165 |
+
cached["response"]["body"] = _b64_decode_bytes(cached["response"]["body"])
|
| 166 |
+
cached["response"]["headers"] = dict(
|
| 167 |
+
(_b64_decode_str(k), _b64_decode_str(v))
|
| 168 |
+
for k, v in cached["response"]["headers"].items()
|
| 169 |
+
)
|
| 170 |
+
cached["response"]["reason"] = _b64_decode_str(cached["response"]["reason"])
|
| 171 |
+
cached["vary"] = dict(
|
| 172 |
+
(_b64_decode_str(k), _b64_decode_str(v) if v is not None else v)
|
| 173 |
+
for k, v in cached["vary"].items()
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
return self.prepare_response(request, cached, body_file)
|
| 177 |
+
|
| 178 |
+
def _loads_v3(self, request, data, body_file):
|
| 179 |
+
# Due to Python 2 encoding issues, it's impossible to know for sure
|
| 180 |
+
# exactly how to load v3 entries, thus we'll treat these as a miss so
|
| 181 |
+
# that they get rewritten out as v4 entries.
|
| 182 |
+
return
|
| 183 |
+
|
| 184 |
+
def _loads_v4(self, request, data, body_file=None):
|
| 185 |
+
try:
|
| 186 |
+
cached = msgpack.loads(data, raw=False)
|
| 187 |
+
except ValueError:
|
| 188 |
+
return
|
| 189 |
+
|
| 190 |
+
return self.prepare_response(request, cached, body_file)
|
.venv/Lib/site-packages/pip/_vendor/cachecontrol/wrapper.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2015 Eric Larson
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
from .adapter import CacheControlAdapter
|
| 6 |
+
from .cache import DictCache
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def CacheControl(
|
| 10 |
+
sess,
|
| 11 |
+
cache=None,
|
| 12 |
+
cache_etags=True,
|
| 13 |
+
serializer=None,
|
| 14 |
+
heuristic=None,
|
| 15 |
+
controller_class=None,
|
| 16 |
+
adapter_class=None,
|
| 17 |
+
cacheable_methods=None,
|
| 18 |
+
):
|
| 19 |
+
|
| 20 |
+
cache = DictCache() if cache is None else cache
|
| 21 |
+
adapter_class = adapter_class or CacheControlAdapter
|
| 22 |
+
adapter = adapter_class(
|
| 23 |
+
cache,
|
| 24 |
+
cache_etags=cache_etags,
|
| 25 |
+
serializer=serializer,
|
| 26 |
+
heuristic=heuristic,
|
| 27 |
+
controller_class=controller_class,
|
| 28 |
+
cacheable_methods=cacheable_methods,
|
| 29 |
+
)
|
| 30 |
+
sess.mount("http://", adapter)
|
| 31 |
+
sess.mount("https://", adapter)
|
| 32 |
+
|
| 33 |
+
return sess
|
.venv/Lib/site-packages/pip/_vendor/certifi/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .core import contents, where
|
| 2 |
+
|
| 3 |
+
__all__ = ["contents", "where"]
|
| 4 |
+
__version__ = "2023.05.07"
|
.venv/Lib/site-packages/pip/_vendor/certifi/__main__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
|
| 3 |
+
from pip._vendor.certifi import contents, where
|
| 4 |
+
|
| 5 |
+
parser = argparse.ArgumentParser()
|
| 6 |
+
parser.add_argument("-c", "--contents", action="store_true")
|
| 7 |
+
args = parser.parse_args()
|
| 8 |
+
|
| 9 |
+
if args.contents:
|
| 10 |
+
print(contents())
|
| 11 |
+
else:
|
| 12 |
+
print(where())
|
.venv/Lib/site-packages/pip/_vendor/certifi/cacert.pem
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
.venv/Lib/site-packages/pip/_vendor/certifi/core.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
certifi.py
|
| 3 |
+
~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
This module returns the installation location of cacert.pem or its contents.
|
| 6 |
+
"""
|
| 7 |
+
import sys
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if sys.version_info >= (3, 11):
|
| 11 |
+
|
| 12 |
+
from importlib.resources import as_file, files
|
| 13 |
+
|
| 14 |
+
_CACERT_CTX = None
|
| 15 |
+
_CACERT_PATH = None
|
| 16 |
+
|
| 17 |
+
def where() -> str:
|
| 18 |
+
# This is slightly terrible, but we want to delay extracting the file
|
| 19 |
+
# in cases where we're inside of a zipimport situation until someone
|
| 20 |
+
# actually calls where(), but we don't want to re-extract the file
|
| 21 |
+
# on every call of where(), so we'll do it once then store it in a
|
| 22 |
+
# global variable.
|
| 23 |
+
global _CACERT_CTX
|
| 24 |
+
global _CACERT_PATH
|
| 25 |
+
if _CACERT_PATH is None:
|
| 26 |
+
# This is slightly janky, the importlib.resources API wants you to
|
| 27 |
+
# manage the cleanup of this file, so it doesn't actually return a
|
| 28 |
+
# path, it returns a context manager that will give you the path
|
| 29 |
+
# when you enter it and will do any cleanup when you leave it. In
|
| 30 |
+
# the common case of not needing a temporary file, it will just
|
| 31 |
+
# return the file system location and the __exit__() is a no-op.
|
| 32 |
+
#
|
| 33 |
+
# We also have to hold onto the actual context manager, because
|
| 34 |
+
# it will do the cleanup whenever it gets garbage collected, so
|
| 35 |
+
# we will also store that at the global level as well.
|
| 36 |
+
_CACERT_CTX = as_file(files("pip._vendor.certifi").joinpath("cacert.pem"))
|
| 37 |
+
_CACERT_PATH = str(_CACERT_CTX.__enter__())
|
| 38 |
+
|
| 39 |
+
return _CACERT_PATH
|
| 40 |
+
|
| 41 |
+
def contents() -> str:
|
| 42 |
+
return files("pip._vendor.certifi").joinpath("cacert.pem").read_text(encoding="ascii")
|
| 43 |
+
|
| 44 |
+
elif sys.version_info >= (3, 7):
|
| 45 |
+
|
| 46 |
+
from importlib.resources import path as get_path, read_text
|
| 47 |
+
|
| 48 |
+
_CACERT_CTX = None
|
| 49 |
+
_CACERT_PATH = None
|
| 50 |
+
|
| 51 |
+
def where() -> str:
|
| 52 |
+
# This is slightly terrible, but we want to delay extracting the
|
| 53 |
+
# file in cases where we're inside of a zipimport situation until
|
| 54 |
+
# someone actually calls where(), but we don't want to re-extract
|
| 55 |
+
# the file on every call of where(), so we'll do it once then store
|
| 56 |
+
# it in a global variable.
|
| 57 |
+
global _CACERT_CTX
|
| 58 |
+
global _CACERT_PATH
|
| 59 |
+
if _CACERT_PATH is None:
|
| 60 |
+
# This is slightly janky, the importlib.resources API wants you
|
| 61 |
+
# to manage the cleanup of this file, so it doesn't actually
|
| 62 |
+
# return a path, it returns a context manager that will give
|
| 63 |
+
# you the path when you enter it and will do any cleanup when
|
| 64 |
+
# you leave it. In the common case of not needing a temporary
|
| 65 |
+
# file, it will just return the file system location and the
|
| 66 |
+
# __exit__() is a no-op.
|
| 67 |
+
#
|
| 68 |
+
# We also have to hold onto the actual context manager, because
|
| 69 |
+
# it will do the cleanup whenever it gets garbage collected, so
|
| 70 |
+
# we will also store that at the global level as well.
|
| 71 |
+
_CACERT_CTX = get_path("pip._vendor.certifi", "cacert.pem")
|
| 72 |
+
_CACERT_PATH = str(_CACERT_CTX.__enter__())
|
| 73 |
+
|
| 74 |
+
return _CACERT_PATH
|
| 75 |
+
|
| 76 |
+
def contents() -> str:
|
| 77 |
+
return read_text("pip._vendor.certifi", "cacert.pem", encoding="ascii")
|
| 78 |
+
|
| 79 |
+
else:
|
| 80 |
+
import os
|
| 81 |
+
import types
|
| 82 |
+
from typing import Union
|
| 83 |
+
|
| 84 |
+
Package = Union[types.ModuleType, str]
|
| 85 |
+
Resource = Union[str, "os.PathLike"]
|
| 86 |
+
|
| 87 |
+
# This fallback will work for Python versions prior to 3.7 that lack the
|
| 88 |
+
# importlib.resources module but relies on the existing `where` function
|
| 89 |
+
# so won't address issues with environments like PyOxidizer that don't set
|
| 90 |
+
# __file__ on modules.
|
| 91 |
+
def read_text(
|
| 92 |
+
package: Package,
|
| 93 |
+
resource: Resource,
|
| 94 |
+
encoding: str = 'utf-8',
|
| 95 |
+
errors: str = 'strict'
|
| 96 |
+
) -> str:
|
| 97 |
+
with open(where(), encoding=encoding) as data:
|
| 98 |
+
return data.read()
|
| 99 |
+
|
| 100 |
+
# If we don't have importlib.resources, then we will just do the old logic
|
| 101 |
+
# of assuming we're on the filesystem and munge the path directly.
|
| 102 |
+
def where() -> str:
|
| 103 |
+
f = os.path.dirname(__file__)
|
| 104 |
+
|
| 105 |
+
return os.path.join(f, "cacert.pem")
|
| 106 |
+
|
| 107 |
+
def contents() -> str:
|
| 108 |
+
return read_text("pip._vendor.certifi", "cacert.pem", encoding="ascii")
|
.venv/Lib/site-packages/pip/_vendor/chardet/big5freq.py
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Big5 frequency table
|
| 29 |
+
# by Taiwan's Mandarin Promotion Council
|
| 30 |
+
# <http://www.edu.tw:81/mandr/>
|
| 31 |
+
#
|
| 32 |
+
# 128 --> 0.42261
|
| 33 |
+
# 256 --> 0.57851
|
| 34 |
+
# 512 --> 0.74851
|
| 35 |
+
# 1024 --> 0.89384
|
| 36 |
+
# 2048 --> 0.97583
|
| 37 |
+
#
|
| 38 |
+
# Ideal Distribution Ratio = 0.74851/(1-0.74851) =2.98
|
| 39 |
+
# Random Distribution Ration = 512/(5401-512)=0.105
|
| 40 |
+
#
|
| 41 |
+
# Typical Distribution Ratio about 25% of Ideal one, still much higher than RDR
|
| 42 |
+
|
| 43 |
+
BIG5_TYPICAL_DISTRIBUTION_RATIO = 0.75
|
| 44 |
+
|
| 45 |
+
# Char to FreqOrder table
|
| 46 |
+
BIG5_TABLE_SIZE = 5376
|
| 47 |
+
# fmt: off
|
| 48 |
+
BIG5_CHAR_TO_FREQ_ORDER = (
|
| 49 |
+
1,1801,1506, 255,1431, 198, 9, 82, 6,5008, 177, 202,3681,1256,2821, 110, # 16
|
| 50 |
+
3814, 33,3274, 261, 76, 44,2114, 16,2946,2187,1176, 659,3971, 26,3451,2653, # 32
|
| 51 |
+
1198,3972,3350,4202, 410,2215, 302, 590, 361,1964, 8, 204, 58,4510,5009,1932, # 48
|
| 52 |
+
63,5010,5011, 317,1614, 75, 222, 159,4203,2417,1480,5012,3555,3091, 224,2822, # 64
|
| 53 |
+
3682, 3, 10,3973,1471, 29,2787,1135,2866,1940, 873, 130,3275,1123, 312,5013, # 80
|
| 54 |
+
4511,2052, 507, 252, 682,5014, 142,1915, 124, 206,2947, 34,3556,3204, 64, 604, # 96
|
| 55 |
+
5015,2501,1977,1978, 155,1991, 645, 641,1606,5016,3452, 337, 72, 406,5017, 80, # 112
|
| 56 |
+
630, 238,3205,1509, 263, 939,1092,2654, 756,1440,1094,3453, 449, 69,2987, 591, # 128
|
| 57 |
+
179,2096, 471, 115,2035,1844, 60, 50,2988, 134, 806,1869, 734,2036,3454, 180, # 144
|
| 58 |
+
995,1607, 156, 537,2907, 688,5018, 319,1305, 779,2145, 514,2379, 298,4512, 359, # 160
|
| 59 |
+
2502, 90,2716,1338, 663, 11, 906,1099,2553, 20,2441, 182, 532,1716,5019, 732, # 176
|
| 60 |
+
1376,4204,1311,1420,3206, 25,2317,1056, 113, 399, 382,1950, 242,3455,2474, 529, # 192
|
| 61 |
+
3276, 475,1447,3683,5020, 117, 21, 656, 810,1297,2300,2334,3557,5021, 126,4205, # 208
|
| 62 |
+
706, 456, 150, 613,4513, 71,1118,2037,4206, 145,3092, 85, 835, 486,2115,1246, # 224
|
| 63 |
+
1426, 428, 727,1285,1015, 800, 106, 623, 303,1281,5022,2128,2359, 347,3815, 221, # 240
|
| 64 |
+
3558,3135,5023,1956,1153,4207, 83, 296,1199,3093, 192, 624, 93,5024, 822,1898, # 256
|
| 65 |
+
2823,3136, 795,2065, 991,1554,1542,1592, 27, 43,2867, 859, 139,1456, 860,4514, # 272
|
| 66 |
+
437, 712,3974, 164,2397,3137, 695, 211,3037,2097, 195,3975,1608,3559,3560,3684, # 288
|
| 67 |
+
3976, 234, 811,2989,2098,3977,2233,1441,3561,1615,2380, 668,2077,1638, 305, 228, # 304
|
| 68 |
+
1664,4515, 467, 415,5025, 262,2099,1593, 239, 108, 300, 200,1033, 512,1247,2078, # 320
|
| 69 |
+
5026,5027,2176,3207,3685,2682, 593, 845,1062,3277, 88,1723,2038,3978,1951, 212, # 336
|
| 70 |
+
266, 152, 149, 468,1899,4208,4516, 77, 187,5028,3038, 37, 5,2990,5029,3979, # 352
|
| 71 |
+
5030,5031, 39,2524,4517,2908,3208,2079, 55, 148, 74,4518, 545, 483,1474,1029, # 368
|
| 72 |
+
1665, 217,1870,1531,3138,1104,2655,4209, 24, 172,3562, 900,3980,3563,3564,4519, # 384
|
| 73 |
+
32,1408,2824,1312, 329, 487,2360,2251,2717, 784,2683, 4,3039,3351,1427,1789, # 400
|
| 74 |
+
188, 109, 499,5032,3686,1717,1790, 888,1217,3040,4520,5033,3565,5034,3352,1520, # 416
|
| 75 |
+
3687,3981, 196,1034, 775,5035,5036, 929,1816, 249, 439, 38,5037,1063,5038, 794, # 432
|
| 76 |
+
3982,1435,2301, 46, 178,3278,2066,5039,2381,5040, 214,1709,4521, 804, 35, 707, # 448
|
| 77 |
+
324,3688,1601,2554, 140, 459,4210,5041,5042,1365, 839, 272, 978,2262,2580,3456, # 464
|
| 78 |
+
2129,1363,3689,1423, 697, 100,3094, 48, 70,1231, 495,3139,2196,5043,1294,5044, # 480
|
| 79 |
+
2080, 462, 586,1042,3279, 853, 256, 988, 185,2382,3457,1698, 434,1084,5045,3458, # 496
|
| 80 |
+
314,2625,2788,4522,2335,2336, 569,2285, 637,1817,2525, 757,1162,1879,1616,3459, # 512
|
| 81 |
+
287,1577,2116, 768,4523,1671,2868,3566,2526,1321,3816, 909,2418,5046,4211, 933, # 528
|
| 82 |
+
3817,4212,2053,2361,1222,4524, 765,2419,1322, 786,4525,5047,1920,1462,1677,2909, # 544
|
| 83 |
+
1699,5048,4526,1424,2442,3140,3690,2600,3353,1775,1941,3460,3983,4213, 309,1369, # 560
|
| 84 |
+
1130,2825, 364,2234,1653,1299,3984,3567,3985,3986,2656, 525,1085,3041, 902,2001, # 576
|
| 85 |
+
1475, 964,4527, 421,1845,1415,1057,2286, 940,1364,3141, 376,4528,4529,1381, 7, # 592
|
| 86 |
+
2527, 983,2383, 336,1710,2684,1846, 321,3461, 559,1131,3042,2752,1809,1132,1313, # 608
|
| 87 |
+
265,1481,1858,5049, 352,1203,2826,3280, 167,1089, 420,2827, 776, 792,1724,3568, # 624
|
| 88 |
+
4214,2443,3281,5050,4215,5051, 446, 229, 333,2753, 901,3818,1200,1557,4530,2657, # 640
|
| 89 |
+
1921, 395,2754,2685,3819,4216,1836, 125, 916,3209,2626,4531,5052,5053,3820,5054, # 656
|
| 90 |
+
5055,5056,4532,3142,3691,1133,2555,1757,3462,1510,2318,1409,3569,5057,2146, 438, # 672
|
| 91 |
+
2601,2910,2384,3354,1068, 958,3043, 461, 311,2869,2686,4217,1916,3210,4218,1979, # 688
|
| 92 |
+
383, 750,2755,2627,4219, 274, 539, 385,1278,1442,5058,1154,1965, 384, 561, 210, # 704
|
| 93 |
+
98,1295,2556,3570,5059,1711,2420,1482,3463,3987,2911,1257, 129,5060,3821, 642, # 720
|
| 94 |
+
523,2789,2790,2658,5061, 141,2235,1333, 68, 176, 441, 876, 907,4220, 603,2602, # 736
|
| 95 |
+
710, 171,3464, 404, 549, 18,3143,2398,1410,3692,1666,5062,3571,4533,2912,4534, # 752
|
| 96 |
+
5063,2991, 368,5064, 146, 366, 99, 871,3693,1543, 748, 807,1586,1185, 22,2263, # 768
|
| 97 |
+
379,3822,3211,5065,3212, 505,1942,2628,1992,1382,2319,5066, 380,2362, 218, 702, # 784
|
| 98 |
+
1818,1248,3465,3044,3572,3355,3282,5067,2992,3694, 930,3283,3823,5068, 59,5069, # 800
|
| 99 |
+
585, 601,4221, 497,3466,1112,1314,4535,1802,5070,1223,1472,2177,5071, 749,1837, # 816
|
| 100 |
+
690,1900,3824,1773,3988,1476, 429,1043,1791,2236,2117, 917,4222, 447,1086,1629, # 832
|
| 101 |
+
5072, 556,5073,5074,2021,1654, 844,1090, 105, 550, 966,1758,2828,1008,1783, 686, # 848
|
| 102 |
+
1095,5075,2287, 793,1602,5076,3573,2603,4536,4223,2948,2302,4537,3825, 980,2503, # 864
|
| 103 |
+
544, 353, 527,4538, 908,2687,2913,5077, 381,2629,1943,1348,5078,1341,1252, 560, # 880
|
| 104 |
+
3095,5079,3467,2870,5080,2054, 973, 886,2081, 143,4539,5081,5082, 157,3989, 496, # 896
|
| 105 |
+
4224, 57, 840, 540,2039,4540,4541,3468,2118,1445, 970,2264,1748,1966,2082,4225, # 912
|
| 106 |
+
3144,1234,1776,3284,2829,3695, 773,1206,2130,1066,2040,1326,3990,1738,1725,4226, # 928
|
| 107 |
+
279,3145, 51,1544,2604, 423,1578,2131,2067, 173,4542,1880,5083,5084,1583, 264, # 944
|
| 108 |
+
610,3696,4543,2444, 280, 154,5085,5086,5087,1739, 338,1282,3096, 693,2871,1411, # 960
|
| 109 |
+
1074,3826,2445,5088,4544,5089,5090,1240, 952,2399,5091,2914,1538,2688, 685,1483, # 976
|
| 110 |
+
4227,2475,1436, 953,4228,2055,4545, 671,2400, 79,4229,2446,3285, 608, 567,2689, # 992
|
| 111 |
+
3469,4230,4231,1691, 393,1261,1792,2401,5092,4546,5093,5094,5095,5096,1383,1672, # 1008
|
| 112 |
+
3827,3213,1464, 522,1119, 661,1150, 216, 675,4547,3991,1432,3574, 609,4548,2690, # 1024
|
| 113 |
+
2402,5097,5098,5099,4232,3045, 0,5100,2476, 315, 231,2447, 301,3356,4549,2385, # 1040
|
| 114 |
+
5101, 233,4233,3697,1819,4550,4551,5102, 96,1777,1315,2083,5103, 257,5104,1810, # 1056
|
| 115 |
+
3698,2718,1139,1820,4234,2022,1124,2164,2791,1778,2659,5105,3097, 363,1655,3214, # 1072
|
| 116 |
+
5106,2993,5107,5108,5109,3992,1567,3993, 718, 103,3215, 849,1443, 341,3357,2949, # 1088
|
| 117 |
+
1484,5110,1712, 127, 67, 339,4235,2403, 679,1412, 821,5111,5112, 834, 738, 351, # 1104
|
| 118 |
+
2994,2147, 846, 235,1497,1881, 418,1993,3828,2719, 186,1100,2148,2756,3575,1545, # 1120
|
| 119 |
+
1355,2950,2872,1377, 583,3994,4236,2581,2995,5113,1298,3699,1078,2557,3700,2363, # 1136
|
| 120 |
+
78,3829,3830, 267,1289,2100,2002,1594,4237, 348, 369,1274,2197,2178,1838,4552, # 1152
|
| 121 |
+
1821,2830,3701,2757,2288,2003,4553,2951,2758, 144,3358, 882,4554,3995,2759,3470, # 1168
|
| 122 |
+
4555,2915,5114,4238,1726, 320,5115,3996,3046, 788,2996,5116,2831,1774,1327,2873, # 1184
|
| 123 |
+
3997,2832,5117,1306,4556,2004,1700,3831,3576,2364,2660, 787,2023, 506, 824,3702, # 1200
|
| 124 |
+
534, 323,4557,1044,3359,2024,1901, 946,3471,5118,1779,1500,1678,5119,1882,4558, # 1216
|
| 125 |
+
165, 243,4559,3703,2528, 123, 683,4239, 764,4560, 36,3998,1793, 589,2916, 816, # 1232
|
| 126 |
+
626,1667,3047,2237,1639,1555,1622,3832,3999,5120,4000,2874,1370,1228,1933, 891, # 1248
|
| 127 |
+
2084,2917, 304,4240,5121, 292,2997,2720,3577, 691,2101,4241,1115,4561, 118, 662, # 1264
|
| 128 |
+
5122, 611,1156, 854,2386,1316,2875, 2, 386, 515,2918,5123,5124,3286, 868,2238, # 1280
|
| 129 |
+
1486, 855,2661, 785,2216,3048,5125,1040,3216,3578,5126,3146, 448,5127,1525,5128, # 1296
|
| 130 |
+
2165,4562,5129,3833,5130,4242,2833,3579,3147, 503, 818,4001,3148,1568, 814, 676, # 1312
|
| 131 |
+
1444, 306,1749,5131,3834,1416,1030, 197,1428, 805,2834,1501,4563,5132,5133,5134, # 1328
|
| 132 |
+
1994,5135,4564,5136,5137,2198, 13,2792,3704,2998,3149,1229,1917,5138,3835,2132, # 1344
|
| 133 |
+
5139,4243,4565,2404,3580,5140,2217,1511,1727,1120,5141,5142, 646,3836,2448, 307, # 1360
|
| 134 |
+
5143,5144,1595,3217,5145,5146,5147,3705,1113,1356,4002,1465,2529,2530,5148, 519, # 1376
|
| 135 |
+
5149, 128,2133, 92,2289,1980,5150,4003,1512, 342,3150,2199,5151,2793,2218,1981, # 1392
|
| 136 |
+
3360,4244, 290,1656,1317, 789, 827,2365,5152,3837,4566, 562, 581,4004,5153, 401, # 1408
|
| 137 |
+
4567,2252, 94,4568,5154,1399,2794,5155,1463,2025,4569,3218,1944,5156, 828,1105, # 1424
|
| 138 |
+
4245,1262,1394,5157,4246, 605,4570,5158,1784,2876,5159,2835, 819,2102, 578,2200, # 1440
|
| 139 |
+
2952,5160,1502, 436,3287,4247,3288,2836,4005,2919,3472,3473,5161,2721,2320,5162, # 1456
|
| 140 |
+
5163,2337,2068, 23,4571, 193, 826,3838,2103, 699,1630,4248,3098, 390,1794,1064, # 1472
|
| 141 |
+
3581,5164,1579,3099,3100,1400,5165,4249,1839,1640,2877,5166,4572,4573, 137,4250, # 1488
|
| 142 |
+
598,3101,1967, 780, 104, 974,2953,5167, 278, 899, 253, 402, 572, 504, 493,1339, # 1504
|
| 143 |
+
5168,4006,1275,4574,2582,2558,5169,3706,3049,3102,2253, 565,1334,2722, 863, 41, # 1520
|
| 144 |
+
5170,5171,4575,5172,1657,2338, 19, 463,2760,4251, 606,5173,2999,3289,1087,2085, # 1536
|
| 145 |
+
1323,2662,3000,5174,1631,1623,1750,4252,2691,5175,2878, 791,2723,2663,2339, 232, # 1552
|
| 146 |
+
2421,5176,3001,1498,5177,2664,2630, 755,1366,3707,3290,3151,2026,1609, 119,1918, # 1568
|
| 147 |
+
3474, 862,1026,4253,5178,4007,3839,4576,4008,4577,2265,1952,2477,5179,1125, 817, # 1584
|
| 148 |
+
4254,4255,4009,1513,1766,2041,1487,4256,3050,3291,2837,3840,3152,5180,5181,1507, # 1600
|
| 149 |
+
5182,2692, 733, 40,1632,1106,2879, 345,4257, 841,2531, 230,4578,3002,1847,3292, # 1616
|
| 150 |
+
3475,5183,1263, 986,3476,5184, 735, 879, 254,1137, 857, 622,1300,1180,1388,1562, # 1632
|
| 151 |
+
4010,4011,2954, 967,2761,2665,1349, 592,2134,1692,3361,3003,1995,4258,1679,4012, # 1648
|
| 152 |
+
1902,2188,5185, 739,3708,2724,1296,1290,5186,4259,2201,2202,1922,1563,2605,2559, # 1664
|
| 153 |
+
1871,2762,3004,5187, 435,5188, 343,1108, 596, 17,1751,4579,2239,3477,3709,5189, # 1680
|
| 154 |
+
4580, 294,3582,2955,1693, 477, 979, 281,2042,3583, 643,2043,3710,2631,2795,2266, # 1696
|
| 155 |
+
1031,2340,2135,2303,3584,4581, 367,1249,2560,5190,3585,5191,4582,1283,3362,2005, # 1712
|
| 156 |
+
240,1762,3363,4583,4584, 836,1069,3153, 474,5192,2149,2532, 268,3586,5193,3219, # 1728
|
| 157 |
+
1521,1284,5194,1658,1546,4260,5195,3587,3588,5196,4261,3364,2693,1685,4262, 961, # 1744
|
| 158 |
+
1673,2632, 190,2006,2203,3841,4585,4586,5197, 570,2504,3711,1490,5198,4587,2633, # 1760
|
| 159 |
+
3293,1957,4588, 584,1514, 396,1045,1945,5199,4589,1968,2449,5200,5201,4590,4013, # 1776
|
| 160 |
+
619,5202,3154,3294, 215,2007,2796,2561,3220,4591,3221,4592, 763,4263,3842,4593, # 1792
|
| 161 |
+
5203,5204,1958,1767,2956,3365,3712,1174, 452,1477,4594,3366,3155,5205,2838,1253, # 1808
|
| 162 |
+
2387,2189,1091,2290,4264, 492,5206, 638,1169,1825,2136,1752,4014, 648, 926,1021, # 1824
|
| 163 |
+
1324,4595, 520,4596, 997, 847,1007, 892,4597,3843,2267,1872,3713,2405,1785,4598, # 1840
|
| 164 |
+
1953,2957,3103,3222,1728,4265,2044,3714,4599,2008,1701,3156,1551, 30,2268,4266, # 1856
|
| 165 |
+
5207,2027,4600,3589,5208, 501,5209,4267, 594,3478,2166,1822,3590,3479,3591,3223, # 1872
|
| 166 |
+
829,2839,4268,5210,1680,3157,1225,4269,5211,3295,4601,4270,3158,2341,5212,4602, # 1888
|
| 167 |
+
4271,5213,4015,4016,5214,1848,2388,2606,3367,5215,4603, 374,4017, 652,4272,4273, # 1904
|
| 168 |
+
375,1140, 798,5216,5217,5218,2366,4604,2269, 546,1659, 138,3051,2450,4605,5219, # 1920
|
| 169 |
+
2254, 612,1849, 910, 796,3844,1740,1371, 825,3845,3846,5220,2920,2562,5221, 692, # 1936
|
| 170 |
+
444,3052,2634, 801,4606,4274,5222,1491, 244,1053,3053,4275,4276, 340,5223,4018, # 1952
|
| 171 |
+
1041,3005, 293,1168, 87,1357,5224,1539, 959,5225,2240, 721, 694,4277,3847, 219, # 1968
|
| 172 |
+
1478, 644,1417,3368,2666,1413,1401,1335,1389,4019,5226,5227,3006,2367,3159,1826, # 1984
|
| 173 |
+
730,1515, 184,2840, 66,4607,5228,1660,2958, 246,3369, 378,1457, 226,3480, 975, # 2000
|
| 174 |
+
4020,2959,1264,3592, 674, 696,5229, 163,5230,1141,2422,2167, 713,3593,3370,4608, # 2016
|
| 175 |
+
4021,5231,5232,1186, 15,5233,1079,1070,5234,1522,3224,3594, 276,1050,2725, 758, # 2032
|
| 176 |
+
1126, 653,2960,3296,5235,2342, 889,3595,4022,3104,3007, 903,1250,4609,4023,3481, # 2048
|
| 177 |
+
3596,1342,1681,1718, 766,3297, 286, 89,2961,3715,5236,1713,5237,2607,3371,3008, # 2064
|
| 178 |
+
5238,2962,2219,3225,2880,5239,4610,2505,2533, 181, 387,1075,4024, 731,2190,3372, # 2080
|
| 179 |
+
5240,3298, 310, 313,3482,2304, 770,4278, 54,3054, 189,4611,3105,3848,4025,5241, # 2096
|
| 180 |
+
1230,1617,1850, 355,3597,4279,4612,3373, 111,4280,3716,1350,3160,3483,3055,4281, # 2112
|
| 181 |
+
2150,3299,3598,5242,2797,4026,4027,3009, 722,2009,5243,1071, 247,1207,2343,2478, # 2128
|
| 182 |
+
1378,4613,2010, 864,1437,1214,4614, 373,3849,1142,2220, 667,4615, 442,2763,2563, # 2144
|
| 183 |
+
3850,4028,1969,4282,3300,1840, 837, 170,1107, 934,1336,1883,5244,5245,2119,4283, # 2160
|
| 184 |
+
2841, 743,1569,5246,4616,4284, 582,2389,1418,3484,5247,1803,5248, 357,1395,1729, # 2176
|
| 185 |
+
3717,3301,2423,1564,2241,5249,3106,3851,1633,4617,1114,2086,4285,1532,5250, 482, # 2192
|
| 186 |
+
2451,4618,5251,5252,1492, 833,1466,5253,2726,3599,1641,2842,5254,1526,1272,3718, # 2208
|
| 187 |
+
4286,1686,1795, 416,2564,1903,1954,1804,5255,3852,2798,3853,1159,2321,5256,2881, # 2224
|
| 188 |
+
4619,1610,1584,3056,2424,2764, 443,3302,1163,3161,5257,5258,4029,5259,4287,2506, # 2240
|
| 189 |
+
3057,4620,4030,3162,2104,1647,3600,2011,1873,4288,5260,4289, 431,3485,5261, 250, # 2256
|
| 190 |
+
97, 81,4290,5262,1648,1851,1558, 160, 848,5263, 866, 740,1694,5264,2204,2843, # 2272
|
| 191 |
+
3226,4291,4621,3719,1687, 950,2479, 426, 469,3227,3720,3721,4031,5265,5266,1188, # 2288
|
| 192 |
+
424,1996, 861,3601,4292,3854,2205,2694, 168,1235,3602,4293,5267,2087,1674,4622, # 2304
|
| 193 |
+
3374,3303, 220,2565,1009,5268,3855, 670,3010, 332,1208, 717,5269,5270,3603,2452, # 2320
|
| 194 |
+
4032,3375,5271, 513,5272,1209,2882,3376,3163,4623,1080,5273,5274,5275,5276,2534, # 2336
|
| 195 |
+
3722,3604, 815,1587,4033,4034,5277,3605,3486,3856,1254,4624,1328,3058,1390,4035, # 2352
|
| 196 |
+
1741,4036,3857,4037,5278, 236,3858,2453,3304,5279,5280,3723,3859,1273,3860,4625, # 2368
|
| 197 |
+
5281, 308,5282,4626, 245,4627,1852,2480,1307,2583, 430, 715,2137,2454,5283, 270, # 2384
|
| 198 |
+
199,2883,4038,5284,3606,2727,1753, 761,1754, 725,1661,1841,4628,3487,3724,5285, # 2400
|
| 199 |
+
5286, 587, 14,3305, 227,2608, 326, 480,2270, 943,2765,3607, 291, 650,1884,5287, # 2416
|
| 200 |
+
1702,1226, 102,1547, 62,3488, 904,4629,3489,1164,4294,5288,5289,1224,1548,2766, # 2432
|
| 201 |
+
391, 498,1493,5290,1386,1419,5291,2056,1177,4630, 813, 880,1081,2368, 566,1145, # 2448
|
| 202 |
+
4631,2291,1001,1035,2566,2609,2242, 394,1286,5292,5293,2069,5294, 86,1494,1730, # 2464
|
| 203 |
+
4039, 491,1588, 745, 897,2963, 843,3377,4040,2767,2884,3306,1768, 998,2221,2070, # 2480
|
| 204 |
+
397,1827,1195,1970,3725,3011,3378, 284,5295,3861,2507,2138,2120,1904,5296,4041, # 2496
|
| 205 |
+
2151,4042,4295,1036,3490,1905, 114,2567,4296, 209,1527,5297,5298,2964,2844,2635, # 2512
|
| 206 |
+
2390,2728,3164, 812,2568,5299,3307,5300,1559, 737,1885,3726,1210, 885, 28,2695, # 2528
|
| 207 |
+
3608,3862,5301,4297,1004,1780,4632,5302, 346,1982,2222,2696,4633,3863,1742, 797, # 2544
|
| 208 |
+
1642,4043,1934,1072,1384,2152, 896,4044,3308,3727,3228,2885,3609,5303,2569,1959, # 2560
|
| 209 |
+
4634,2455,1786,5304,5305,5306,4045,4298,1005,1308,3728,4299,2729,4635,4636,1528, # 2576
|
| 210 |
+
2610, 161,1178,4300,1983, 987,4637,1101,4301, 631,4046,1157,3229,2425,1343,1241, # 2592
|
| 211 |
+
1016,2243,2570, 372, 877,2344,2508,1160, 555,1935, 911,4047,5307, 466,1170, 169, # 2608
|
| 212 |
+
1051,2921,2697,3729,2481,3012,1182,2012,2571,1251,2636,5308, 992,2345,3491,1540, # 2624
|
| 213 |
+
2730,1201,2071,2406,1997,2482,5309,4638, 528,1923,2191,1503,1874,1570,2369,3379, # 2640
|
| 214 |
+
3309,5310, 557,1073,5311,1828,3492,2088,2271,3165,3059,3107, 767,3108,2799,4639, # 2656
|
| 215 |
+
1006,4302,4640,2346,1267,2179,3730,3230, 778,4048,3231,2731,1597,2667,5312,4641, # 2672
|
| 216 |
+
5313,3493,5314,5315,5316,3310,2698,1433,3311, 131, 95,1504,4049, 723,4303,3166, # 2688
|
| 217 |
+
1842,3610,2768,2192,4050,2028,2105,3731,5317,3013,4051,1218,5318,3380,3232,4052, # 2704
|
| 218 |
+
4304,2584, 248,1634,3864, 912,5319,2845,3732,3060,3865, 654, 53,5320,3014,5321, # 2720
|
| 219 |
+
1688,4642, 777,3494,1032,4053,1425,5322, 191, 820,2121,2846, 971,4643, 931,3233, # 2736
|
| 220 |
+
135, 664, 783,3866,1998, 772,2922,1936,4054,3867,4644,2923,3234, 282,2732, 640, # 2752
|
| 221 |
+
1372,3495,1127, 922, 325,3381,5323,5324, 711,2045,5325,5326,4055,2223,2800,1937, # 2768
|
| 222 |
+
4056,3382,2224,2255,3868,2305,5327,4645,3869,1258,3312,4057,3235,2139,2965,4058, # 2784
|
| 223 |
+
4059,5328,2225, 258,3236,4646, 101,1227,5329,3313,1755,5330,1391,3314,5331,2924, # 2800
|
| 224 |
+
2057, 893,5332,5333,5334,1402,4305,2347,5335,5336,3237,3611,5337,5338, 878,1325, # 2816
|
| 225 |
+
1781,2801,4647, 259,1385,2585, 744,1183,2272,4648,5339,4060,2509,5340, 684,1024, # 2832
|
| 226 |
+
4306,5341, 472,3612,3496,1165,3315,4061,4062, 322,2153, 881, 455,1695,1152,1340, # 2848
|
| 227 |
+
660, 554,2154,4649,1058,4650,4307, 830,1065,3383,4063,4651,1924,5342,1703,1919, # 2864
|
| 228 |
+
5343, 932,2273, 122,5344,4652, 947, 677,5345,3870,2637, 297,1906,1925,2274,4653, # 2880
|
| 229 |
+
2322,3316,5346,5347,4308,5348,4309, 84,4310, 112, 989,5349, 547,1059,4064, 701, # 2896
|
| 230 |
+
3613,1019,5350,4311,5351,3497, 942, 639, 457,2306,2456, 993,2966, 407, 851, 494, # 2912
|
| 231 |
+
4654,3384, 927,5352,1237,5353,2426,3385, 573,4312, 680, 921,2925,1279,1875, 285, # 2928
|
| 232 |
+
790,1448,1984, 719,2168,5354,5355,4655,4065,4066,1649,5356,1541, 563,5357,1077, # 2944
|
| 233 |
+
5358,3386,3061,3498, 511,3015,4067,4068,3733,4069,1268,2572,3387,3238,4656,4657, # 2960
|
| 234 |
+
5359, 535,1048,1276,1189,2926,2029,3167,1438,1373,2847,2967,1134,2013,5360,4313, # 2976
|
| 235 |
+
1238,2586,3109,1259,5361, 700,5362,2968,3168,3734,4314,5363,4315,1146,1876,1907, # 2992
|
| 236 |
+
4658,2611,4070, 781,2427, 132,1589, 203, 147, 273,2802,2407, 898,1787,2155,4071, # 3008
|
| 237 |
+
4072,5364,3871,2803,5365,5366,4659,4660,5367,3239,5368,1635,3872, 965,5369,1805, # 3024
|
| 238 |
+
2699,1516,3614,1121,1082,1329,3317,4073,1449,3873, 65,1128,2848,2927,2769,1590, # 3040
|
| 239 |
+
3874,5370,5371, 12,2668, 45, 976,2587,3169,4661, 517,2535,1013,1037,3240,5372, # 3056
|
| 240 |
+
3875,2849,5373,3876,5374,3499,5375,2612, 614,1999,2323,3877,3110,2733,2638,5376, # 3072
|
| 241 |
+
2588,4316, 599,1269,5377,1811,3735,5378,2700,3111, 759,1060, 489,1806,3388,3318, # 3088
|
| 242 |
+
1358,5379,5380,2391,1387,1215,2639,2256, 490,5381,5382,4317,1759,2392,2348,5383, # 3104
|
| 243 |
+
4662,3878,1908,4074,2640,1807,3241,4663,3500,3319,2770,2349, 874,5384,5385,3501, # 3120
|
| 244 |
+
3736,1859, 91,2928,3737,3062,3879,4664,5386,3170,4075,2669,5387,3502,1202,1403, # 3136
|
| 245 |
+
3880,2969,2536,1517,2510,4665,3503,2511,5388,4666,5389,2701,1886,1495,1731,4076, # 3152
|
| 246 |
+
2370,4667,5390,2030,5391,5392,4077,2702,1216, 237,2589,4318,2324,4078,3881,4668, # 3168
|
| 247 |
+
4669,2703,3615,3504, 445,4670,5393,5394,5395,5396,2771, 61,4079,3738,1823,4080, # 3184
|
| 248 |
+
5397, 687,2046, 935, 925, 405,2670, 703,1096,1860,2734,4671,4081,1877,1367,2704, # 3200
|
| 249 |
+
3389, 918,2106,1782,2483, 334,3320,1611,1093,4672, 564,3171,3505,3739,3390, 945, # 3216
|
| 250 |
+
2641,2058,4673,5398,1926, 872,4319,5399,3506,2705,3112, 349,4320,3740,4082,4674, # 3232
|
| 251 |
+
3882,4321,3741,2156,4083,4675,4676,4322,4677,2408,2047, 782,4084, 400, 251,4323, # 3248
|
| 252 |
+
1624,5400,5401, 277,3742, 299,1265, 476,1191,3883,2122,4324,4325,1109, 205,5402, # 3264
|
| 253 |
+
2590,1000,2157,3616,1861,5403,5404,5405,4678,5406,4679,2573, 107,2484,2158,4085, # 3280
|
| 254 |
+
3507,3172,5407,1533, 541,1301, 158, 753,4326,2886,3617,5408,1696, 370,1088,4327, # 3296
|
| 255 |
+
4680,3618, 579, 327, 440, 162,2244, 269,1938,1374,3508, 968,3063, 56,1396,3113, # 3312
|
| 256 |
+
2107,3321,3391,5409,1927,2159,4681,3016,5410,3619,5411,5412,3743,4682,2485,5413, # 3328
|
| 257 |
+
2804,5414,1650,4683,5415,2613,5416,5417,4086,2671,3392,1149,3393,4087,3884,4088, # 3344
|
| 258 |
+
5418,1076, 49,5419, 951,3242,3322,3323, 450,2850, 920,5420,1812,2805,2371,4328, # 3360
|
| 259 |
+
1909,1138,2372,3885,3509,5421,3243,4684,1910,1147,1518,2428,4685,3886,5422,4686, # 3376
|
| 260 |
+
2393,2614, 260,1796,3244,5423,5424,3887,3324, 708,5425,3620,1704,5426,3621,1351, # 3392
|
| 261 |
+
1618,3394,3017,1887, 944,4329,3395,4330,3064,3396,4331,5427,3744, 422, 413,1714, # 3408
|
| 262 |
+
3325, 500,2059,2350,4332,2486,5428,1344,1911, 954,5429,1668,5430,5431,4089,2409, # 3424
|
| 263 |
+
4333,3622,3888,4334,5432,2307,1318,2512,3114, 133,3115,2887,4687, 629, 31,2851, # 3440
|
| 264 |
+
2706,3889,4688, 850, 949,4689,4090,2970,1732,2089,4335,1496,1853,5433,4091, 620, # 3456
|
| 265 |
+
3245, 981,1242,3745,3397,1619,3746,1643,3326,2140,2457,1971,1719,3510,2169,5434, # 3472
|
| 266 |
+
3246,5435,5436,3398,1829,5437,1277,4690,1565,2048,5438,1636,3623,3116,5439, 869, # 3488
|
| 267 |
+
2852, 655,3890,3891,3117,4092,3018,3892,1310,3624,4691,5440,5441,5442,1733, 558, # 3504
|
| 268 |
+
4692,3747, 335,1549,3065,1756,4336,3748,1946,3511,1830,1291,1192, 470,2735,2108, # 3520
|
| 269 |
+
2806, 913,1054,4093,5443,1027,5444,3066,4094,4693, 982,2672,3399,3173,3512,3247, # 3536
|
| 270 |
+
3248,1947,2807,5445, 571,4694,5446,1831,5447,3625,2591,1523,2429,5448,2090, 984, # 3552
|
| 271 |
+
4695,3749,1960,5449,3750, 852, 923,2808,3513,3751, 969,1519, 999,2049,2325,1705, # 3568
|
| 272 |
+
5450,3118, 615,1662, 151, 597,4095,2410,2326,1049, 275,4696,3752,4337, 568,3753, # 3584
|
| 273 |
+
3626,2487,4338,3754,5451,2430,2275, 409,3249,5452,1566,2888,3514,1002, 769,2853, # 3600
|
| 274 |
+
194,2091,3174,3755,2226,3327,4339, 628,1505,5453,5454,1763,2180,3019,4096, 521, # 3616
|
| 275 |
+
1161,2592,1788,2206,2411,4697,4097,1625,4340,4341, 412, 42,3119, 464,5455,2642, # 3632
|
| 276 |
+
4698,3400,1760,1571,2889,3515,2537,1219,2207,3893,2643,2141,2373,4699,4700,3328, # 3648
|
| 277 |
+
1651,3401,3627,5456,5457,3628,2488,3516,5458,3756,5459,5460,2276,2092, 460,5461, # 3664
|
| 278 |
+
4701,5462,3020, 962, 588,3629, 289,3250,2644,1116, 52,5463,3067,1797,5464,5465, # 3680
|
| 279 |
+
5466,1467,5467,1598,1143,3757,4342,1985,1734,1067,4702,1280,3402, 465,4703,1572, # 3696
|
| 280 |
+
510,5468,1928,2245,1813,1644,3630,5469,4704,3758,5470,5471,2673,1573,1534,5472, # 3712
|
| 281 |
+
5473, 536,1808,1761,3517,3894,3175,2645,5474,5475,5476,4705,3518,2929,1912,2809, # 3728
|
| 282 |
+
5477,3329,1122, 377,3251,5478, 360,5479,5480,4343,1529, 551,5481,2060,3759,1769, # 3744
|
| 283 |
+
2431,5482,2930,4344,3330,3120,2327,2109,2031,4706,1404, 136,1468,1479, 672,1171, # 3760
|
| 284 |
+
3252,2308, 271,3176,5483,2772,5484,2050, 678,2736, 865,1948,4707,5485,2014,4098, # 3776
|
| 285 |
+
2971,5486,2737,2227,1397,3068,3760,4708,4709,1735,2931,3403,3631,5487,3895, 509, # 3792
|
| 286 |
+
2854,2458,2890,3896,5488,5489,3177,3178,4710,4345,2538,4711,2309,1166,1010, 552, # 3808
|
| 287 |
+
681,1888,5490,5491,2972,2973,4099,1287,1596,1862,3179, 358, 453, 736, 175, 478, # 3824
|
| 288 |
+
1117, 905,1167,1097,5492,1854,1530,5493,1706,5494,2181,3519,2292,3761,3520,3632, # 3840
|
| 289 |
+
4346,2093,4347,5495,3404,1193,2489,4348,1458,2193,2208,1863,1889,1421,3331,2932, # 3856
|
| 290 |
+
3069,2182,3521, 595,2123,5496,4100,5497,5498,4349,1707,2646, 223,3762,1359, 751, # 3872
|
| 291 |
+
3121, 183,3522,5499,2810,3021, 419,2374, 633, 704,3897,2394, 241,5500,5501,5502, # 3888
|
| 292 |
+
838,3022,3763,2277,2773,2459,3898,1939,2051,4101,1309,3122,2246,1181,5503,1136, # 3904
|
| 293 |
+
2209,3899,2375,1446,4350,2310,4712,5504,5505,4351,1055,2615, 484,3764,5506,4102, # 3920
|
| 294 |
+
625,4352,2278,3405,1499,4353,4103,5507,4104,4354,3253,2279,2280,3523,5508,5509, # 3936
|
| 295 |
+
2774, 808,2616,3765,3406,4105,4355,3123,2539, 526,3407,3900,4356, 955,5510,1620, # 3952
|
| 296 |
+
4357,2647,2432,5511,1429,3766,1669,1832, 994, 928,5512,3633,1260,5513,5514,5515, # 3968
|
| 297 |
+
1949,2293, 741,2933,1626,4358,2738,2460, 867,1184, 362,3408,1392,5516,5517,4106, # 3984
|
| 298 |
+
4359,1770,1736,3254,2934,4713,4714,1929,2707,1459,1158,5518,3070,3409,2891,1292, # 4000
|
| 299 |
+
1930,2513,2855,3767,1986,1187,2072,2015,2617,4360,5519,2574,2514,2170,3768,2490, # 4016
|
| 300 |
+
3332,5520,3769,4715,5521,5522, 666,1003,3023,1022,3634,4361,5523,4716,1814,2257, # 4032
|
| 301 |
+
574,3901,1603, 295,1535, 705,3902,4362, 283, 858, 417,5524,5525,3255,4717,4718, # 4048
|
| 302 |
+
3071,1220,1890,1046,2281,2461,4107,1393,1599, 689,2575, 388,4363,5526,2491, 802, # 4064
|
| 303 |
+
5527,2811,3903,2061,1405,2258,5528,4719,3904,2110,1052,1345,3256,1585,5529, 809, # 4080
|
| 304 |
+
5530,5531,5532, 575,2739,3524, 956,1552,1469,1144,2328,5533,2329,1560,2462,3635, # 4096
|
| 305 |
+
3257,4108, 616,2210,4364,3180,2183,2294,5534,1833,5535,3525,4720,5536,1319,3770, # 4112
|
| 306 |
+
3771,1211,3636,1023,3258,1293,2812,5537,5538,5539,3905, 607,2311,3906, 762,2892, # 4128
|
| 307 |
+
1439,4365,1360,4721,1485,3072,5540,4722,1038,4366,1450,2062,2648,4367,1379,4723, # 4144
|
| 308 |
+
2593,5541,5542,4368,1352,1414,2330,2935,1172,5543,5544,3907,3908,4724,1798,1451, # 4160
|
| 309 |
+
5545,5546,5547,5548,2936,4109,4110,2492,2351, 411,4111,4112,3637,3333,3124,4725, # 4176
|
| 310 |
+
1561,2674,1452,4113,1375,5549,5550, 47,2974, 316,5551,1406,1591,2937,3181,5552, # 4192
|
| 311 |
+
1025,2142,3125,3182, 354,2740, 884,2228,4369,2412, 508,3772, 726,3638, 996,2433, # 4208
|
| 312 |
+
3639, 729,5553, 392,2194,1453,4114,4726,3773,5554,5555,2463,3640,2618,1675,2813, # 4224
|
| 313 |
+
919,2352,2975,2353,1270,4727,4115, 73,5556,5557, 647,5558,3259,2856,2259,1550, # 4240
|
| 314 |
+
1346,3024,5559,1332, 883,3526,5560,5561,5562,5563,3334,2775,5564,1212, 831,1347, # 4256
|
| 315 |
+
4370,4728,2331,3909,1864,3073, 720,3910,4729,4730,3911,5565,4371,5566,5567,4731, # 4272
|
| 316 |
+
5568,5569,1799,4732,3774,2619,4733,3641,1645,2376,4734,5570,2938, 669,2211,2675, # 4288
|
| 317 |
+
2434,5571,2893,5572,5573,1028,3260,5574,4372,2413,5575,2260,1353,5576,5577,4735, # 4304
|
| 318 |
+
3183, 518,5578,4116,5579,4373,1961,5580,2143,4374,5581,5582,3025,2354,2355,3912, # 4320
|
| 319 |
+
516,1834,1454,4117,2708,4375,4736,2229,2620,1972,1129,3642,5583,2776,5584,2976, # 4336
|
| 320 |
+
1422, 577,1470,3026,1524,3410,5585,5586, 432,4376,3074,3527,5587,2594,1455,2515, # 4352
|
| 321 |
+
2230,1973,1175,5588,1020,2741,4118,3528,4737,5589,2742,5590,1743,1361,3075,3529, # 4368
|
| 322 |
+
2649,4119,4377,4738,2295, 895, 924,4378,2171, 331,2247,3076, 166,1627,3077,1098, # 4384
|
| 323 |
+
5591,1232,2894,2231,3411,4739, 657, 403,1196,2377, 542,3775,3412,1600,4379,3530, # 4400
|
| 324 |
+
5592,4740,2777,3261, 576, 530,1362,4741,4742,2540,2676,3776,4120,5593, 842,3913, # 4416
|
| 325 |
+
5594,2814,2032,1014,4121, 213,2709,3413, 665, 621,4380,5595,3777,2939,2435,5596, # 4432
|
| 326 |
+
2436,3335,3643,3414,4743,4381,2541,4382,4744,3644,1682,4383,3531,1380,5597, 724, # 4448
|
| 327 |
+
2282, 600,1670,5598,1337,1233,4745,3126,2248,5599,1621,4746,5600, 651,4384,5601, # 4464
|
| 328 |
+
1612,4385,2621,5602,2857,5603,2743,2312,3078,5604, 716,2464,3079, 174,1255,2710, # 4480
|
| 329 |
+
4122,3645, 548,1320,1398, 728,4123,1574,5605,1891,1197,3080,4124,5606,3081,3082, # 4496
|
| 330 |
+
3778,3646,3779, 747,5607, 635,4386,4747,5608,5609,5610,4387,5611,5612,4748,5613, # 4512
|
| 331 |
+
3415,4749,2437, 451,5614,3780,2542,2073,4388,2744,4389,4125,5615,1764,4750,5616, # 4528
|
| 332 |
+
4390, 350,4751,2283,2395,2493,5617,4391,4126,2249,1434,4127, 488,4752, 458,4392, # 4544
|
| 333 |
+
4128,3781, 771,1330,2396,3914,2576,3184,2160,2414,1553,2677,3185,4393,5618,2494, # 4560
|
| 334 |
+
2895,2622,1720,2711,4394,3416,4753,5619,2543,4395,5620,3262,4396,2778,5621,2016, # 4576
|
| 335 |
+
2745,5622,1155,1017,3782,3915,5623,3336,2313, 201,1865,4397,1430,5624,4129,5625, # 4592
|
| 336 |
+
5626,5627,5628,5629,4398,1604,5630, 414,1866, 371,2595,4754,4755,3532,2017,3127, # 4608
|
| 337 |
+
4756,1708, 960,4399, 887, 389,2172,1536,1663,1721,5631,2232,4130,2356,2940,1580, # 4624
|
| 338 |
+
5632,5633,1744,4757,2544,4758,4759,5634,4760,5635,2074,5636,4761,3647,3417,2896, # 4640
|
| 339 |
+
4400,5637,4401,2650,3418,2815, 673,2712,2465, 709,3533,4131,3648,4402,5638,1148, # 4656
|
| 340 |
+
502, 634,5639,5640,1204,4762,3649,1575,4763,2623,3783,5641,3784,3128, 948,3263, # 4672
|
| 341 |
+
121,1745,3916,1110,5642,4403,3083,2516,3027,4132,3785,1151,1771,3917,1488,4133, # 4688
|
| 342 |
+
1987,5643,2438,3534,5644,5645,2094,5646,4404,3918,1213,1407,2816, 531,2746,2545, # 4704
|
| 343 |
+
3264,1011,1537,4764,2779,4405,3129,1061,5647,3786,3787,1867,2897,5648,2018, 120, # 4720
|
| 344 |
+
4406,4407,2063,3650,3265,2314,3919,2678,3419,1955,4765,4134,5649,3535,1047,2713, # 4736
|
| 345 |
+
1266,5650,1368,4766,2858, 649,3420,3920,2546,2747,1102,2859,2679,5651,5652,2000, # 4752
|
| 346 |
+
5653,1111,3651,2977,5654,2495,3921,3652,2817,1855,3421,3788,5655,5656,3422,2415, # 4768
|
| 347 |
+
2898,3337,3266,3653,5657,2577,5658,3654,2818,4135,1460, 856,5659,3655,5660,2899, # 4784
|
| 348 |
+
2978,5661,2900,3922,5662,4408, 632,2517, 875,3923,1697,3924,2296,5663,5664,4767, # 4800
|
| 349 |
+
3028,1239, 580,4768,4409,5665, 914, 936,2075,1190,4136,1039,2124,5666,5667,5668, # 4816
|
| 350 |
+
5669,3423,1473,5670,1354,4410,3925,4769,2173,3084,4137, 915,3338,4411,4412,3339, # 4832
|
| 351 |
+
1605,1835,5671,2748, 398,3656,4413,3926,4138, 328,1913,2860,4139,3927,1331,4414, # 4848
|
| 352 |
+
3029, 937,4415,5672,3657,4140,4141,3424,2161,4770,3425, 524, 742, 538,3085,1012, # 4864
|
| 353 |
+
5673,5674,3928,2466,5675, 658,1103, 225,3929,5676,5677,4771,5678,4772,5679,3267, # 4880
|
| 354 |
+
1243,5680,4142, 963,2250,4773,5681,2714,3658,3186,5682,5683,2596,2332,5684,4774, # 4896
|
| 355 |
+
5685,5686,5687,3536, 957,3426,2547,2033,1931,2941,2467, 870,2019,3659,1746,2780, # 4912
|
| 356 |
+
2781,2439,2468,5688,3930,5689,3789,3130,3790,3537,3427,3791,5690,1179,3086,5691, # 4928
|
| 357 |
+
3187,2378,4416,3792,2548,3188,3131,2749,4143,5692,3428,1556,2549,2297, 977,2901, # 4944
|
| 358 |
+
2034,4144,1205,3429,5693,1765,3430,3189,2125,1271, 714,1689,4775,3538,5694,2333, # 4960
|
| 359 |
+
3931, 533,4417,3660,2184, 617,5695,2469,3340,3539,2315,5696,5697,3190,5698,5699, # 4976
|
| 360 |
+
3932,1988, 618, 427,2651,3540,3431,5700,5701,1244,1690,5702,2819,4418,4776,5703, # 4992
|
| 361 |
+
3541,4777,5704,2284,1576, 473,3661,4419,3432, 972,5705,3662,5706,3087,5707,5708, # 5008
|
| 362 |
+
4778,4779,5709,3793,4145,4146,5710, 153,4780, 356,5711,1892,2902,4420,2144, 408, # 5024
|
| 363 |
+
803,2357,5712,3933,5713,4421,1646,2578,2518,4781,4782,3934,5714,3935,4422,5715, # 5040
|
| 364 |
+
2416,3433, 752,5716,5717,1962,3341,2979,5718, 746,3030,2470,4783,4423,3794, 698, # 5056
|
| 365 |
+
4784,1893,4424,3663,2550,4785,3664,3936,5719,3191,3434,5720,1824,1302,4147,2715, # 5072
|
| 366 |
+
3937,1974,4425,5721,4426,3192, 823,1303,1288,1236,2861,3542,4148,3435, 774,3938, # 5088
|
| 367 |
+
5722,1581,4786,1304,2862,3939,4787,5723,2440,2162,1083,3268,4427,4149,4428, 344, # 5104
|
| 368 |
+
1173, 288,2316, 454,1683,5724,5725,1461,4788,4150,2597,5726,5727,4789, 985, 894, # 5120
|
| 369 |
+
5728,3436,3193,5729,1914,2942,3795,1989,5730,2111,1975,5731,4151,5732,2579,1194, # 5136
|
| 370 |
+
425,5733,4790,3194,1245,3796,4429,5734,5735,2863,5736, 636,4791,1856,3940, 760, # 5152
|
| 371 |
+
1800,5737,4430,2212,1508,4792,4152,1894,1684,2298,5738,5739,4793,4431,4432,2213, # 5168
|
| 372 |
+
479,5740,5741, 832,5742,4153,2496,5743,2980,2497,3797, 990,3132, 627,1815,2652, # 5184
|
| 373 |
+
4433,1582,4434,2126,2112,3543,4794,5744, 799,4435,3195,5745,4795,2113,1737,3031, # 5200
|
| 374 |
+
1018, 543, 754,4436,3342,1676,4796,4797,4154,4798,1489,5746,3544,5747,2624,2903, # 5216
|
| 375 |
+
4155,5748,5749,2981,5750,5751,5752,5753,3196,4799,4800,2185,1722,5754,3269,3270, # 5232
|
| 376 |
+
1843,3665,1715, 481, 365,1976,1857,5755,5756,1963,2498,4801,5757,2127,3666,3271, # 5248
|
| 377 |
+
433,1895,2064,2076,5758, 602,2750,5759,5760,5761,5762,5763,3032,1628,3437,5764, # 5264
|
| 378 |
+
3197,4802,4156,2904,4803,2519,5765,2551,2782,5766,5767,5768,3343,4804,2905,5769, # 5280
|
| 379 |
+
4805,5770,2864,4806,4807,1221,2982,4157,2520,5771,5772,5773,1868,1990,5774,5775, # 5296
|
| 380 |
+
5776,1896,5777,5778,4808,1897,4158, 318,5779,2095,4159,4437,5780,5781, 485,5782, # 5312
|
| 381 |
+
938,3941, 553,2680, 116,5783,3942,3667,5784,3545,2681,2783,3438,3344,2820,5785, # 5328
|
| 382 |
+
3668,2943,4160,1747,2944,2983,5786,5787, 207,5788,4809,5789,4810,2521,5790,3033, # 5344
|
| 383 |
+
890,3669,3943,5791,1878,3798,3439,5792,2186,2358,3440,1652,5793,5794,5795, 941, # 5360
|
| 384 |
+
2299, 208,3546,4161,2020, 330,4438,3944,2906,2499,3799,4439,4811,5796,5797,5798, # 5376
|
| 385 |
+
)
|
| 386 |
+
# fmt: on
|
.venv/Lib/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/site-packages/pip/_vendor/chardet/chardistribution.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Tuple, Union
|
| 29 |
+
|
| 30 |
+
from .big5freq import (
|
| 31 |
+
BIG5_CHAR_TO_FREQ_ORDER,
|
| 32 |
+
BIG5_TABLE_SIZE,
|
| 33 |
+
BIG5_TYPICAL_DISTRIBUTION_RATIO,
|
| 34 |
+
)
|
| 35 |
+
from .euckrfreq import (
|
| 36 |
+
EUCKR_CHAR_TO_FREQ_ORDER,
|
| 37 |
+
EUCKR_TABLE_SIZE,
|
| 38 |
+
EUCKR_TYPICAL_DISTRIBUTION_RATIO,
|
| 39 |
+
)
|
| 40 |
+
from .euctwfreq import (
|
| 41 |
+
EUCTW_CHAR_TO_FREQ_ORDER,
|
| 42 |
+
EUCTW_TABLE_SIZE,
|
| 43 |
+
EUCTW_TYPICAL_DISTRIBUTION_RATIO,
|
| 44 |
+
)
|
| 45 |
+
from .gb2312freq import (
|
| 46 |
+
GB2312_CHAR_TO_FREQ_ORDER,
|
| 47 |
+
GB2312_TABLE_SIZE,
|
| 48 |
+
GB2312_TYPICAL_DISTRIBUTION_RATIO,
|
| 49 |
+
)
|
| 50 |
+
from .jisfreq import (
|
| 51 |
+
JIS_CHAR_TO_FREQ_ORDER,
|
| 52 |
+
JIS_TABLE_SIZE,
|
| 53 |
+
JIS_TYPICAL_DISTRIBUTION_RATIO,
|
| 54 |
+
)
|
| 55 |
+
from .johabfreq import JOHAB_TO_EUCKR_ORDER_TABLE
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class CharDistributionAnalysis:
|
| 59 |
+
ENOUGH_DATA_THRESHOLD = 1024
|
| 60 |
+
SURE_YES = 0.99
|
| 61 |
+
SURE_NO = 0.01
|
| 62 |
+
MINIMUM_DATA_THRESHOLD = 3
|
| 63 |
+
|
| 64 |
+
def __init__(self) -> None:
|
| 65 |
+
# Mapping table to get frequency order from char order (get from
|
| 66 |
+
# GetOrder())
|
| 67 |
+
self._char_to_freq_order: Tuple[int, ...] = tuple()
|
| 68 |
+
self._table_size = 0 # Size of above table
|
| 69 |
+
# This is a constant value which varies from language to language,
|
| 70 |
+
# used in calculating confidence. See
|
| 71 |
+
# http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html
|
| 72 |
+
# for further detail.
|
| 73 |
+
self.typical_distribution_ratio = 0.0
|
| 74 |
+
self._done = False
|
| 75 |
+
self._total_chars = 0
|
| 76 |
+
self._freq_chars = 0
|
| 77 |
+
self.reset()
|
| 78 |
+
|
| 79 |
+
def reset(self) -> None:
|
| 80 |
+
"""reset analyser, clear any state"""
|
| 81 |
+
# If this flag is set to True, detection is done and conclusion has
|
| 82 |
+
# been made
|
| 83 |
+
self._done = False
|
| 84 |
+
self._total_chars = 0 # Total characters encountered
|
| 85 |
+
# The number of characters whose frequency order is less than 512
|
| 86 |
+
self._freq_chars = 0
|
| 87 |
+
|
| 88 |
+
def feed(self, char: Union[bytes, bytearray], char_len: int) -> None:
|
| 89 |
+
"""feed a character with known length"""
|
| 90 |
+
if char_len == 2:
|
| 91 |
+
# we only care about 2-bytes character in our distribution analysis
|
| 92 |
+
order = self.get_order(char)
|
| 93 |
+
else:
|
| 94 |
+
order = -1
|
| 95 |
+
if order >= 0:
|
| 96 |
+
self._total_chars += 1
|
| 97 |
+
# order is valid
|
| 98 |
+
if order < self._table_size:
|
| 99 |
+
if 512 > self._char_to_freq_order[order]:
|
| 100 |
+
self._freq_chars += 1
|
| 101 |
+
|
| 102 |
+
def get_confidence(self) -> float:
|
| 103 |
+
"""return confidence based on existing data"""
|
| 104 |
+
# if we didn't receive any character in our consideration range,
|
| 105 |
+
# return negative answer
|
| 106 |
+
if self._total_chars <= 0 or self._freq_chars <= self.MINIMUM_DATA_THRESHOLD:
|
| 107 |
+
return self.SURE_NO
|
| 108 |
+
|
| 109 |
+
if self._total_chars != self._freq_chars:
|
| 110 |
+
r = self._freq_chars / (
|
| 111 |
+
(self._total_chars - self._freq_chars) * self.typical_distribution_ratio
|
| 112 |
+
)
|
| 113 |
+
if r < self.SURE_YES:
|
| 114 |
+
return r
|
| 115 |
+
|
| 116 |
+
# normalize confidence (we don't want to be 100% sure)
|
| 117 |
+
return self.SURE_YES
|
| 118 |
+
|
| 119 |
+
def got_enough_data(self) -> bool:
|
| 120 |
+
# It is not necessary to receive all data to draw conclusion.
|
| 121 |
+
# For charset detection, certain amount of data is enough
|
| 122 |
+
return self._total_chars > self.ENOUGH_DATA_THRESHOLD
|
| 123 |
+
|
| 124 |
+
def get_order(self, _: Union[bytes, bytearray]) -> int:
|
| 125 |
+
# We do not handle characters based on the original encoding string,
|
| 126 |
+
# but convert this encoding string to a number, here called order.
|
| 127 |
+
# This allows multiple encodings of a language to share one frequency
|
| 128 |
+
# table.
|
| 129 |
+
return -1
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class EUCTWDistributionAnalysis(CharDistributionAnalysis):
|
| 133 |
+
def __init__(self) -> None:
|
| 134 |
+
super().__init__()
|
| 135 |
+
self._char_to_freq_order = EUCTW_CHAR_TO_FREQ_ORDER
|
| 136 |
+
self._table_size = EUCTW_TABLE_SIZE
|
| 137 |
+
self.typical_distribution_ratio = EUCTW_TYPICAL_DISTRIBUTION_RATIO
|
| 138 |
+
|
| 139 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 140 |
+
# for euc-TW encoding, we are interested
|
| 141 |
+
# first byte range: 0xc4 -- 0xfe
|
| 142 |
+
# second byte range: 0xa1 -- 0xfe
|
| 143 |
+
# no validation needed here. State machine has done that
|
| 144 |
+
first_char = byte_str[0]
|
| 145 |
+
if first_char >= 0xC4:
|
| 146 |
+
return 94 * (first_char - 0xC4) + byte_str[1] - 0xA1
|
| 147 |
+
return -1
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class EUCKRDistributionAnalysis(CharDistributionAnalysis):
|
| 151 |
+
def __init__(self) -> None:
|
| 152 |
+
super().__init__()
|
| 153 |
+
self._char_to_freq_order = EUCKR_CHAR_TO_FREQ_ORDER
|
| 154 |
+
self._table_size = EUCKR_TABLE_SIZE
|
| 155 |
+
self.typical_distribution_ratio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
|
| 156 |
+
|
| 157 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 158 |
+
# for euc-KR encoding, we are interested
|
| 159 |
+
# first byte range: 0xb0 -- 0xfe
|
| 160 |
+
# second byte range: 0xa1 -- 0xfe
|
| 161 |
+
# no validation needed here. State machine has done that
|
| 162 |
+
first_char = byte_str[0]
|
| 163 |
+
if first_char >= 0xB0:
|
| 164 |
+
return 94 * (first_char - 0xB0) + byte_str[1] - 0xA1
|
| 165 |
+
return -1
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class JOHABDistributionAnalysis(CharDistributionAnalysis):
|
| 169 |
+
def __init__(self) -> None:
|
| 170 |
+
super().__init__()
|
| 171 |
+
self._char_to_freq_order = EUCKR_CHAR_TO_FREQ_ORDER
|
| 172 |
+
self._table_size = EUCKR_TABLE_SIZE
|
| 173 |
+
self.typical_distribution_ratio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
|
| 174 |
+
|
| 175 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 176 |
+
first_char = byte_str[0]
|
| 177 |
+
if 0x88 <= first_char < 0xD4:
|
| 178 |
+
code = first_char * 256 + byte_str[1]
|
| 179 |
+
return JOHAB_TO_EUCKR_ORDER_TABLE.get(code, -1)
|
| 180 |
+
return -1
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class GB2312DistributionAnalysis(CharDistributionAnalysis):
|
| 184 |
+
def __init__(self) -> None:
|
| 185 |
+
super().__init__()
|
| 186 |
+
self._char_to_freq_order = GB2312_CHAR_TO_FREQ_ORDER
|
| 187 |
+
self._table_size = GB2312_TABLE_SIZE
|
| 188 |
+
self.typical_distribution_ratio = GB2312_TYPICAL_DISTRIBUTION_RATIO
|
| 189 |
+
|
| 190 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 191 |
+
# for GB2312 encoding, we are interested
|
| 192 |
+
# first byte range: 0xb0 -- 0xfe
|
| 193 |
+
# second byte range: 0xa1 -- 0xfe
|
| 194 |
+
# no validation needed here. State machine has done that
|
| 195 |
+
first_char, second_char = byte_str[0], byte_str[1]
|
| 196 |
+
if (first_char >= 0xB0) and (second_char >= 0xA1):
|
| 197 |
+
return 94 * (first_char - 0xB0) + second_char - 0xA1
|
| 198 |
+
return -1
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class Big5DistributionAnalysis(CharDistributionAnalysis):
|
| 202 |
+
def __init__(self) -> None:
|
| 203 |
+
super().__init__()
|
| 204 |
+
self._char_to_freq_order = BIG5_CHAR_TO_FREQ_ORDER
|
| 205 |
+
self._table_size = BIG5_TABLE_SIZE
|
| 206 |
+
self.typical_distribution_ratio = BIG5_TYPICAL_DISTRIBUTION_RATIO
|
| 207 |
+
|
| 208 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 209 |
+
# for big5 encoding, we are interested
|
| 210 |
+
# first byte range: 0xa4 -- 0xfe
|
| 211 |
+
# second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe
|
| 212 |
+
# no validation needed here. State machine has done that
|
| 213 |
+
first_char, second_char = byte_str[0], byte_str[1]
|
| 214 |
+
if first_char >= 0xA4:
|
| 215 |
+
if second_char >= 0xA1:
|
| 216 |
+
return 157 * (first_char - 0xA4) + second_char - 0xA1 + 63
|
| 217 |
+
return 157 * (first_char - 0xA4) + second_char - 0x40
|
| 218 |
+
return -1
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
class SJISDistributionAnalysis(CharDistributionAnalysis):
|
| 222 |
+
def __init__(self) -> None:
|
| 223 |
+
super().__init__()
|
| 224 |
+
self._char_to_freq_order = JIS_CHAR_TO_FREQ_ORDER
|
| 225 |
+
self._table_size = JIS_TABLE_SIZE
|
| 226 |
+
self.typical_distribution_ratio = JIS_TYPICAL_DISTRIBUTION_RATIO
|
| 227 |
+
|
| 228 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 229 |
+
# for sjis encoding, we are interested
|
| 230 |
+
# first byte range: 0x81 -- 0x9f , 0xe0 -- 0xfe
|
| 231 |
+
# second byte range: 0x40 -- 0x7e, 0x81 -- oxfe
|
| 232 |
+
# no validation needed here. State machine has done that
|
| 233 |
+
first_char, second_char = byte_str[0], byte_str[1]
|
| 234 |
+
if 0x81 <= first_char <= 0x9F:
|
| 235 |
+
order = 188 * (first_char - 0x81)
|
| 236 |
+
elif 0xE0 <= first_char <= 0xEF:
|
| 237 |
+
order = 188 * (first_char - 0xE0 + 31)
|
| 238 |
+
else:
|
| 239 |
+
return -1
|
| 240 |
+
order = order + second_char - 0x40
|
| 241 |
+
if second_char > 0x7F:
|
| 242 |
+
order = -1
|
| 243 |
+
return order
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class EUCJPDistributionAnalysis(CharDistributionAnalysis):
|
| 247 |
+
def __init__(self) -> None:
|
| 248 |
+
super().__init__()
|
| 249 |
+
self._char_to_freq_order = JIS_CHAR_TO_FREQ_ORDER
|
| 250 |
+
self._table_size = JIS_TABLE_SIZE
|
| 251 |
+
self.typical_distribution_ratio = JIS_TYPICAL_DISTRIBUTION_RATIO
|
| 252 |
+
|
| 253 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 254 |
+
# for euc-JP encoding, we are interested
|
| 255 |
+
# first byte range: 0xa0 -- 0xfe
|
| 256 |
+
# second byte range: 0xa1 -- 0xfe
|
| 257 |
+
# no validation needed here. State machine has done that
|
| 258 |
+
char = byte_str[0]
|
| 259 |
+
if char >= 0xA0:
|
| 260 |
+
return 94 * (char - 0xA1) + byte_str[1] - 0xA1
|
| 261 |
+
return -1
|
.venv/Lib/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/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/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/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/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/site-packages/pip/_vendor/chardet/enums.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
All of the Enums that are used throughout the chardet package.
|
| 3 |
+
|
| 4 |
+
:author: Dan Blanchard (dan.blanchard@gmail.com)
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from enum import Enum, Flag
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class InputState:
|
| 11 |
+
"""
|
| 12 |
+
This enum represents the different states a universal detector can be in.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
PURE_ASCII = 0
|
| 16 |
+
ESC_ASCII = 1
|
| 17 |
+
HIGH_BYTE = 2
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class LanguageFilter(Flag):
|
| 21 |
+
"""
|
| 22 |
+
This enum represents the different language filters we can apply to a
|
| 23 |
+
``UniversalDetector``.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
NONE = 0x00
|
| 27 |
+
CHINESE_SIMPLIFIED = 0x01
|
| 28 |
+
CHINESE_TRADITIONAL = 0x02
|
| 29 |
+
JAPANESE = 0x04
|
| 30 |
+
KOREAN = 0x08
|
| 31 |
+
NON_CJK = 0x10
|
| 32 |
+
ALL = 0x1F
|
| 33 |
+
CHINESE = CHINESE_SIMPLIFIED | CHINESE_TRADITIONAL
|
| 34 |
+
CJK = CHINESE | JAPANESE | KOREAN
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class ProbingState(Enum):
|
| 38 |
+
"""
|
| 39 |
+
This enum represents the different states a prober can be in.
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
DETECTING = 0
|
| 43 |
+
FOUND_IT = 1
|
| 44 |
+
NOT_ME = 2
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class MachineState:
|
| 48 |
+
"""
|
| 49 |
+
This enum represents the different states a state machine can be in.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
START = 0
|
| 53 |
+
ERROR = 1
|
| 54 |
+
ITS_ME = 2
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class SequenceLikelihood:
|
| 58 |
+
"""
|
| 59 |
+
This enum represents the likelihood of a character following the previous one.
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
NEGATIVE = 0
|
| 63 |
+
UNLIKELY = 1
|
| 64 |
+
LIKELY = 2
|
| 65 |
+
POSITIVE = 3
|
| 66 |
+
|
| 67 |
+
@classmethod
|
| 68 |
+
def get_num_categories(cls) -> int:
|
| 69 |
+
""":returns: The number of likelihood categories in the enum."""
|
| 70 |
+
return 4
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class CharacterCategory:
|
| 74 |
+
"""
|
| 75 |
+
This enum represents the different categories language models for
|
| 76 |
+
``SingleByteCharsetProber`` put characters into.
|
| 77 |
+
|
| 78 |
+
Anything less than CONTROL is considered a letter.
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
UNDEFINED = 255
|
| 82 |
+
LINE_BREAK = 254
|
| 83 |
+
SYMBOL = 253
|
| 84 |
+
DIGIT = 252
|
| 85 |
+
CONTROL = 251
|
.venv/Lib/site-packages/pip/_vendor/chardet/escprober.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 typing import Optional, Union
|
| 29 |
+
|
| 30 |
+
from .charsetprober import CharSetProber
|
| 31 |
+
from .codingstatemachine import CodingStateMachine
|
| 32 |
+
from .enums import LanguageFilter, MachineState, ProbingState
|
| 33 |
+
from .escsm import (
|
| 34 |
+
HZ_SM_MODEL,
|
| 35 |
+
ISO2022CN_SM_MODEL,
|
| 36 |
+
ISO2022JP_SM_MODEL,
|
| 37 |
+
ISO2022KR_SM_MODEL,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class EscCharSetProber(CharSetProber):
|
| 42 |
+
"""
|
| 43 |
+
This CharSetProber uses a "code scheme" approach for detecting encodings,
|
| 44 |
+
whereby easily recognizable escape or shift sequences are relied on to
|
| 45 |
+
identify these encodings.
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
def __init__(self, lang_filter: LanguageFilter = LanguageFilter.NONE) -> None:
|
| 49 |
+
super().__init__(lang_filter=lang_filter)
|
| 50 |
+
self.coding_sm = []
|
| 51 |
+
if self.lang_filter & LanguageFilter.CHINESE_SIMPLIFIED:
|
| 52 |
+
self.coding_sm.append(CodingStateMachine(HZ_SM_MODEL))
|
| 53 |
+
self.coding_sm.append(CodingStateMachine(ISO2022CN_SM_MODEL))
|
| 54 |
+
if self.lang_filter & LanguageFilter.JAPANESE:
|
| 55 |
+
self.coding_sm.append(CodingStateMachine(ISO2022JP_SM_MODEL))
|
| 56 |
+
if self.lang_filter & LanguageFilter.KOREAN:
|
| 57 |
+
self.coding_sm.append(CodingStateMachine(ISO2022KR_SM_MODEL))
|
| 58 |
+
self.active_sm_count = 0
|
| 59 |
+
self._detected_charset: Optional[str] = None
|
| 60 |
+
self._detected_language: Optional[str] = None
|
| 61 |
+
self._state = ProbingState.DETECTING
|
| 62 |
+
self.reset()
|
| 63 |
+
|
| 64 |
+
def reset(self) -> None:
|
| 65 |
+
super().reset()
|
| 66 |
+
for coding_sm in self.coding_sm:
|
| 67 |
+
coding_sm.active = True
|
| 68 |
+
coding_sm.reset()
|
| 69 |
+
self.active_sm_count = len(self.coding_sm)
|
| 70 |
+
self._detected_charset = None
|
| 71 |
+
self._detected_language = None
|
| 72 |
+
|
| 73 |
+
@property
|
| 74 |
+
def charset_name(self) -> Optional[str]:
|
| 75 |
+
return self._detected_charset
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def language(self) -> Optional[str]:
|
| 79 |
+
return self._detected_language
|
| 80 |
+
|
| 81 |
+
def get_confidence(self) -> float:
|
| 82 |
+
return 0.99 if self._detected_charset else 0.00
|
| 83 |
+
|
| 84 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 85 |
+
for c in byte_str:
|
| 86 |
+
for coding_sm in self.coding_sm:
|
| 87 |
+
if not coding_sm.active:
|
| 88 |
+
continue
|
| 89 |
+
coding_state = coding_sm.next_state(c)
|
| 90 |
+
if coding_state == MachineState.ERROR:
|
| 91 |
+
coding_sm.active = False
|
| 92 |
+
self.active_sm_count -= 1
|
| 93 |
+
if self.active_sm_count <= 0:
|
| 94 |
+
self._state = ProbingState.NOT_ME
|
| 95 |
+
return self.state
|
| 96 |
+
elif coding_state == MachineState.ITS_ME:
|
| 97 |
+
self._state = ProbingState.FOUND_IT
|
| 98 |
+
self._detected_charset = coding_sm.get_coding_state_machine()
|
| 99 |
+
self._detected_language = coding_sm.language
|
| 100 |
+
return self.state
|
| 101 |
+
|
| 102 |
+
return self.state
|
.venv/Lib/site-packages/pip/_vendor/chardet/escsm.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 .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, 0, 0, 0, # 30 - 37
|
| 40 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 38 - 3f
|
| 41 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 40 - 47
|
| 42 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 48 - 4f
|
| 43 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 50 - 57
|
| 44 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 58 - 5f
|
| 45 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 60 - 67
|
| 46 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 68 - 6f
|
| 47 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 70 - 77
|
| 48 |
+
0, 0, 0, 4, 0, 5, 2, 0, # 78 - 7f
|
| 49 |
+
1, 1, 1, 1, 1, 1, 1, 1, # 80 - 87
|
| 50 |
+
1, 1, 1, 1, 1, 1, 1, 1, # 88 - 8f
|
| 51 |
+
1, 1, 1, 1, 1, 1, 1, 1, # 90 - 97
|
| 52 |
+
1, 1, 1, 1, 1, 1, 1, 1, # 98 - 9f
|
| 53 |
+
1, 1, 1, 1, 1, 1, 1, 1, # a0 - a7
|
| 54 |
+
1, 1, 1, 1, 1, 1, 1, 1, # a8 - af
|
| 55 |
+
1, 1, 1, 1, 1, 1, 1, 1, # b0 - b7
|
| 56 |
+
1, 1, 1, 1, 1, 1, 1, 1, # b8 - bf
|
| 57 |
+
1, 1, 1, 1, 1, 1, 1, 1, # c0 - c7
|
| 58 |
+
1, 1, 1, 1, 1, 1, 1, 1, # c8 - cf
|
| 59 |
+
1, 1, 1, 1, 1, 1, 1, 1, # d0 - d7
|
| 60 |
+
1, 1, 1, 1, 1, 1, 1, 1, # d8 - df
|
| 61 |
+
1, 1, 1, 1, 1, 1, 1, 1, # e0 - e7
|
| 62 |
+
1, 1, 1, 1, 1, 1, 1, 1, # e8 - ef
|
| 63 |
+
1, 1, 1, 1, 1, 1, 1, 1, # f0 - f7
|
| 64 |
+
1, 1, 1, 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/site-packages/pip/_vendor/chardet/eucjpprober.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 typing import Union
|
| 29 |
+
|
| 30 |
+
from .chardistribution import EUCJPDistributionAnalysis
|
| 31 |
+
from .codingstatemachine import CodingStateMachine
|
| 32 |
+
from .enums import MachineState, ProbingState
|
| 33 |
+
from .jpcntx import EUCJPContextAnalysis
|
| 34 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 35 |
+
from .mbcssm import EUCJP_SM_MODEL
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class EUCJPProber(MultiByteCharSetProber):
|
| 39 |
+
def __init__(self) -> None:
|
| 40 |
+
super().__init__()
|
| 41 |
+
self.coding_sm = CodingStateMachine(EUCJP_SM_MODEL)
|
| 42 |
+
self.distribution_analyzer = EUCJPDistributionAnalysis()
|
| 43 |
+
self.context_analyzer = EUCJPContextAnalysis()
|
| 44 |
+
self.reset()
|
| 45 |
+
|
| 46 |
+
def reset(self) -> None:
|
| 47 |
+
super().reset()
|
| 48 |
+
self.context_analyzer.reset()
|
| 49 |
+
|
| 50 |
+
@property
|
| 51 |
+
def charset_name(self) -> str:
|
| 52 |
+
return "EUC-JP"
|
| 53 |
+
|
| 54 |
+
@property
|
| 55 |
+
def language(self) -> str:
|
| 56 |
+
return "Japanese"
|
| 57 |
+
|
| 58 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 59 |
+
assert self.coding_sm is not None
|
| 60 |
+
assert self.distribution_analyzer is not None
|
| 61 |
+
|
| 62 |
+
for i, byte in enumerate(byte_str):
|
| 63 |
+
# PY3K: byte_str is a byte array, so byte is an int, not a byte
|
| 64 |
+
coding_state = self.coding_sm.next_state(byte)
|
| 65 |
+
if coding_state == MachineState.ERROR:
|
| 66 |
+
self.logger.debug(
|
| 67 |
+
"%s %s prober hit error at byte %s",
|
| 68 |
+
self.charset_name,
|
| 69 |
+
self.language,
|
| 70 |
+
i,
|
| 71 |
+
)
|
| 72 |
+
self._state = ProbingState.NOT_ME
|
| 73 |
+
break
|
| 74 |
+
if coding_state == MachineState.ITS_ME:
|
| 75 |
+
self._state = ProbingState.FOUND_IT
|
| 76 |
+
break
|
| 77 |
+
if coding_state == MachineState.START:
|
| 78 |
+
char_len = self.coding_sm.get_current_charlen()
|
| 79 |
+
if i == 0:
|
| 80 |
+
self._last_char[1] = byte
|
| 81 |
+
self.context_analyzer.feed(self._last_char, char_len)
|
| 82 |
+
self.distribution_analyzer.feed(self._last_char, char_len)
|
| 83 |
+
else:
|
| 84 |
+
self.context_analyzer.feed(byte_str[i - 1 : i + 1], char_len)
|
| 85 |
+
self.distribution_analyzer.feed(byte_str[i - 1 : i + 1], char_len)
|
| 86 |
+
|
| 87 |
+
self._last_char[0] = byte_str[-1]
|
| 88 |
+
|
| 89 |
+
if self.state == ProbingState.DETECTING:
|
| 90 |
+
if self.context_analyzer.got_enough_data() and (
|
| 91 |
+
self.get_confidence() > self.SHORTCUT_THRESHOLD
|
| 92 |
+
):
|
| 93 |
+
self._state = ProbingState.FOUND_IT
|
| 94 |
+
|
| 95 |
+
return self.state
|
| 96 |
+
|
| 97 |
+
def get_confidence(self) -> float:
|
| 98 |
+
assert self.distribution_analyzer is not None
|
| 99 |
+
|
| 100 |
+
context_conf = self.context_analyzer.get_confidence()
|
| 101 |
+
distrib_conf = self.distribution_analyzer.get_confidence()
|
| 102 |
+
return max(context_conf, distrib_conf)
|
.venv/Lib/site-packages/pip/_vendor/chardet/euckrfreq.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Sampling from about 20M text materials include literature and computer technology
|
| 29 |
+
|
| 30 |
+
# 128 --> 0.79
|
| 31 |
+
# 256 --> 0.92
|
| 32 |
+
# 512 --> 0.986
|
| 33 |
+
# 1024 --> 0.99944
|
| 34 |
+
# 2048 --> 0.99999
|
| 35 |
+
#
|
| 36 |
+
# Idea Distribution Ratio = 0.98653 / (1-0.98653) = 73.24
|
| 37 |
+
# Random Distribution Ration = 512 / (2350-512) = 0.279.
|
| 38 |
+
#
|
| 39 |
+
# Typical Distribution Ratio
|
| 40 |
+
|
| 41 |
+
EUCKR_TYPICAL_DISTRIBUTION_RATIO = 6.0
|
| 42 |
+
|
| 43 |
+
EUCKR_TABLE_SIZE = 2352
|
| 44 |
+
|
| 45 |
+
# Char to FreqOrder table ,
|
| 46 |
+
# fmt: off
|
| 47 |
+
EUCKR_CHAR_TO_FREQ_ORDER = (
|
| 48 |
+
13, 130, 120,1396, 481,1719,1720, 328, 609, 212,1721, 707, 400, 299,1722, 87,
|
| 49 |
+
1397,1723, 104, 536,1117,1203,1724,1267, 685,1268, 508,1725,1726,1727,1728,1398,
|
| 50 |
+
1399,1729,1730,1731, 141, 621, 326,1057, 368,1732, 267, 488, 20,1733,1269,1734,
|
| 51 |
+
945,1400,1735, 47, 904,1270,1736,1737, 773, 248,1738, 409, 313, 786, 429,1739,
|
| 52 |
+
116, 987, 813,1401, 683, 75,1204, 145,1740,1741,1742,1743, 16, 847, 667, 622,
|
| 53 |
+
708,1744,1745,1746, 966, 787, 304, 129,1747, 60, 820, 123, 676,1748,1749,1750,
|
| 54 |
+
1751, 617,1752, 626,1753,1754,1755,1756, 653,1757,1758,1759,1760,1761,1762, 856,
|
| 55 |
+
344,1763,1764,1765,1766, 89, 401, 418, 806, 905, 848,1767,1768,1769, 946,1205,
|
| 56 |
+
709,1770,1118,1771, 241,1772,1773,1774,1271,1775, 569,1776, 999,1777,1778,1779,
|
| 57 |
+
1780, 337, 751,1058, 28, 628, 254,1781, 177, 906, 270, 349, 891,1079,1782, 19,
|
| 58 |
+
1783, 379,1784, 315,1785, 629, 754,1402, 559,1786, 636, 203,1206,1787, 710, 567,
|
| 59 |
+
1788, 935, 814,1789,1790,1207, 766, 528,1791,1792,1208,1793,1794,1795,1796,1797,
|
| 60 |
+
1403,1798,1799, 533,1059,1404,1405,1156,1406, 936, 884,1080,1800, 351,1801,1802,
|
| 61 |
+
1803,1804,1805, 801,1806,1807,1808,1119,1809,1157, 714, 474,1407,1810, 298, 899,
|
| 62 |
+
885,1811,1120, 802,1158,1812, 892,1813,1814,1408, 659,1815,1816,1121,1817,1818,
|
| 63 |
+
1819,1820,1821,1822, 319,1823, 594, 545,1824, 815, 937,1209,1825,1826, 573,1409,
|
| 64 |
+
1022,1827,1210,1828,1829,1830,1831,1832,1833, 556, 722, 807,1122,1060,1834, 697,
|
| 65 |
+
1835, 900, 557, 715,1836,1410, 540,1411, 752,1159, 294, 597,1211, 976, 803, 770,
|
| 66 |
+
1412,1837,1838, 39, 794,1413, 358,1839, 371, 925,1840, 453, 661, 788, 531, 723,
|
| 67 |
+
544,1023,1081, 869, 91,1841, 392, 430, 790, 602,1414, 677,1082, 457,1415,1416,
|
| 68 |
+
1842,1843, 475, 327,1024,1417, 795, 121,1844, 733, 403,1418,1845,1846,1847, 300,
|
| 69 |
+
119, 711,1212, 627,1848,1272, 207,1849,1850, 796,1213, 382,1851, 519,1852,1083,
|
| 70 |
+
893,1853,1854,1855, 367, 809, 487, 671,1856, 663,1857,1858, 956, 471, 306, 857,
|
| 71 |
+
1859,1860,1160,1084,1861,1862,1863,1864,1865,1061,1866,1867,1868,1869,1870,1871,
|
| 72 |
+
282, 96, 574,1872, 502,1085,1873,1214,1874, 907,1875,1876, 827, 977,1419,1420,
|
| 73 |
+
1421, 268,1877,1422,1878,1879,1880, 308,1881, 2, 537,1882,1883,1215,1884,1885,
|
| 74 |
+
127, 791,1886,1273,1423,1887, 34, 336, 404, 643,1888, 571, 654, 894, 840,1889,
|
| 75 |
+
0, 886,1274, 122, 575, 260, 908, 938,1890,1275, 410, 316,1891,1892, 100,1893,
|
| 76 |
+
1894,1123, 48,1161,1124,1025,1895, 633, 901,1276,1896,1897, 115, 816,1898, 317,
|
| 77 |
+
1899, 694,1900, 909, 734,1424, 572, 866,1425, 691, 85, 524,1010, 543, 394, 841,
|
| 78 |
+
1901,1902,1903,1026,1904,1905,1906,1907,1908,1909, 30, 451, 651, 988, 310,1910,
|
| 79 |
+
1911,1426, 810,1216, 93,1912,1913,1277,1217,1914, 858, 759, 45, 58, 181, 610,
|
| 80 |
+
269,1915,1916, 131,1062, 551, 443,1000, 821,1427, 957, 895,1086,1917,1918, 375,
|
| 81 |
+
1919, 359,1920, 687,1921, 822,1922, 293,1923,1924, 40, 662, 118, 692, 29, 939,
|
| 82 |
+
887, 640, 482, 174,1925, 69,1162, 728,1428, 910,1926,1278,1218,1279, 386, 870,
|
| 83 |
+
217, 854,1163, 823,1927,1928,1929,1930, 834,1931, 78,1932, 859,1933,1063,1934,
|
| 84 |
+
1935,1936,1937, 438,1164, 208, 595,1938,1939,1940,1941,1219,1125,1942, 280, 888,
|
| 85 |
+
1429,1430,1220,1431,1943,1944,1945,1946,1947,1280, 150, 510,1432,1948,1949,1950,
|
| 86 |
+
1951,1952,1953,1954,1011,1087,1955,1433,1043,1956, 881,1957, 614, 958,1064,1065,
|
| 87 |
+
1221,1958, 638,1001, 860, 967, 896,1434, 989, 492, 553,1281,1165,1959,1282,1002,
|
| 88 |
+
1283,1222,1960,1961,1962,1963, 36, 383, 228, 753, 247, 454,1964, 876, 678,1965,
|
| 89 |
+
1966,1284, 126, 464, 490, 835, 136, 672, 529, 940,1088,1435, 473,1967,1968, 467,
|
| 90 |
+
50, 390, 227, 587, 279, 378, 598, 792, 968, 240, 151, 160, 849, 882,1126,1285,
|
| 91 |
+
639,1044, 133, 140, 288, 360, 811, 563,1027, 561, 142, 523,1969,1970,1971, 7,
|
| 92 |
+
103, 296, 439, 407, 506, 634, 990,1972,1973,1974,1975, 645,1976,1977,1978,1979,
|
| 93 |
+
1980,1981, 236,1982,1436,1983,1984,1089, 192, 828, 618, 518,1166, 333,1127,1985,
|
| 94 |
+
818,1223,1986,1987,1988,1989,1990,1991,1992,1993, 342,1128,1286, 746, 842,1994,
|
| 95 |
+
1995, 560, 223,1287, 98, 8, 189, 650, 978,1288,1996,1437,1997, 17, 345, 250,
|
| 96 |
+
423, 277, 234, 512, 226, 97, 289, 42, 167,1998, 201,1999,2000, 843, 836, 824,
|
| 97 |
+
532, 338, 783,1090, 182, 576, 436,1438,1439, 527, 500,2001, 947, 889,2002,2003,
|
| 98 |
+
2004,2005, 262, 600, 314, 447,2006, 547,2007, 693, 738,1129,2008, 71,1440, 745,
|
| 99 |
+
619, 688,2009, 829,2010,2011, 147,2012, 33, 948,2013,2014, 74, 224,2015, 61,
|
| 100 |
+
191, 918, 399, 637,2016,1028,1130, 257, 902,2017,2018,2019,2020,2021,2022,2023,
|
| 101 |
+
2024,2025,2026, 837,2027,2028,2029,2030, 179, 874, 591, 52, 724, 246,2031,2032,
|
| 102 |
+
2033,2034,1167, 969,2035,1289, 630, 605, 911,1091,1168,2036,2037,2038,1441, 912,
|
| 103 |
+
2039, 623,2040,2041, 253,1169,1290,2042,1442, 146, 620, 611, 577, 433,2043,1224,
|
| 104 |
+
719,1170, 959, 440, 437, 534, 84, 388, 480,1131, 159, 220, 198, 679,2044,1012,
|
| 105 |
+
819,1066,1443, 113,1225, 194, 318,1003,1029,2045,2046,2047,2048,1067,2049,2050,
|
| 106 |
+
2051,2052,2053, 59, 913, 112,2054, 632,2055, 455, 144, 739,1291,2056, 273, 681,
|
| 107 |
+
499,2057, 448,2058,2059, 760,2060,2061, 970, 384, 169, 245,1132,2062,2063, 414,
|
| 108 |
+
1444,2064,2065, 41, 235,2066, 157, 252, 877, 568, 919, 789, 580,2067, 725,2068,
|
| 109 |
+
2069,1292,2070,2071,1445,2072,1446,2073,2074, 55, 588, 66,1447, 271,1092,2075,
|
| 110 |
+
1226,2076, 960,1013, 372,2077,2078,2079,2080,2081,1293,2082,2083,2084,2085, 850,
|
| 111 |
+
2086,2087,2088,2089,2090, 186,2091,1068, 180,2092,2093,2094, 109,1227, 522, 606,
|
| 112 |
+
2095, 867,1448,1093, 991,1171, 926, 353,1133,2096, 581,2097,2098,2099,1294,1449,
|
| 113 |
+
1450,2100, 596,1172,1014,1228,2101,1451,1295,1173,1229,2102,2103,1296,1134,1452,
|
| 114 |
+
949,1135,2104,2105,1094,1453,1454,1455,2106,1095,2107,2108,2109,2110,2111,2112,
|
| 115 |
+
2113,2114,2115,2116,2117, 804,2118,2119,1230,1231, 805,1456, 405,1136,2120,2121,
|
| 116 |
+
2122,2123,2124, 720, 701,1297, 992,1457, 927,1004,2125,2126,2127,2128,2129,2130,
|
| 117 |
+
22, 417,2131, 303,2132, 385,2133, 971, 520, 513,2134,1174, 73,1096, 231, 274,
|
| 118 |
+
962,1458, 673,2135,1459,2136, 152,1137,2137,2138,2139,2140,1005,1138,1460,1139,
|
| 119 |
+
2141,2142,2143,2144, 11, 374, 844,2145, 154,1232, 46,1461,2146, 838, 830, 721,
|
| 120 |
+
1233, 106,2147, 90, 428, 462, 578, 566,1175, 352,2148,2149, 538,1234, 124,1298,
|
| 121 |
+
2150,1462, 761, 565,2151, 686,2152, 649,2153, 72, 173,2154, 460, 415,2155,1463,
|
| 122 |
+
2156,1235, 305,2157,2158,2159,2160,2161,2162, 579,2163,2164,2165,2166,2167, 747,
|
| 123 |
+
2168,2169,2170,2171,1464, 669,2172,2173,2174,2175,2176,1465,2177, 23, 530, 285,
|
| 124 |
+
2178, 335, 729,2179, 397,2180,2181,2182,1030,2183,2184, 698,2185,2186, 325,2187,
|
| 125 |
+
2188, 369,2189, 799,1097,1015, 348,2190,1069, 680,2191, 851,1466,2192,2193, 10,
|
| 126 |
+
2194, 613, 424,2195, 979, 108, 449, 589, 27, 172, 81,1031, 80, 774, 281, 350,
|
| 127 |
+
1032, 525, 301, 582,1176,2196, 674,1045,2197,2198,1467, 730, 762,2199,2200,2201,
|
| 128 |
+
2202,1468,2203, 993,2204,2205, 266,1070, 963,1140,2206,2207,2208, 664,1098, 972,
|
| 129 |
+
2209,2210,2211,1177,1469,1470, 871,2212,2213,2214,2215,2216,1471,2217,2218,2219,
|
| 130 |
+
2220,2221,2222,2223,2224,2225,2226,2227,1472,1236,2228,2229,2230,2231,2232,2233,
|
| 131 |
+
2234,2235,1299,2236,2237, 200,2238, 477, 373,2239,2240, 731, 825, 777,2241,2242,
|
| 132 |
+
2243, 521, 486, 548,2244,2245,2246,1473,1300, 53, 549, 137, 875, 76, 158,2247,
|
| 133 |
+
1301,1474, 469, 396,1016, 278, 712,2248, 321, 442, 503, 767, 744, 941,1237,1178,
|
| 134 |
+
1475,2249, 82, 178,1141,1179, 973,2250,1302,2251, 297,2252,2253, 570,2254,2255,
|
| 135 |
+
2256, 18, 450, 206,2257, 290, 292,1142,2258, 511, 162, 99, 346, 164, 735,2259,
|
| 136 |
+
1476,1477, 4, 554, 343, 798,1099,2260,1100,2261, 43, 171,1303, 139, 215,2262,
|
| 137 |
+
2263, 717, 775,2264,1033, 322, 216,2265, 831,2266, 149,2267,1304,2268,2269, 702,
|
| 138 |
+
1238, 135, 845, 347, 309,2270, 484,2271, 878, 655, 238,1006,1478,2272, 67,2273,
|
| 139 |
+
295,2274,2275, 461,2276, 478, 942, 412,2277,1034,2278,2279,2280, 265,2281, 541,
|
| 140 |
+
2282,2283,2284,2285,2286, 70, 852,1071,2287,2288,2289,2290, 21, 56, 509, 117,
|
| 141 |
+
432,2291,2292, 331, 980, 552,1101, 148, 284, 105, 393,1180,1239, 755,2293, 187,
|
| 142 |
+
2294,1046,1479,2295, 340,2296, 63,1047, 230,2297,2298,1305, 763,1306, 101, 800,
|
| 143 |
+
808, 494,2299,2300,2301, 903,2302, 37,1072, 14, 5,2303, 79, 675,2304, 312,
|
| 144 |
+
2305,2306,2307,2308,2309,1480, 6,1307,2310,2311,2312, 1, 470, 35, 24, 229,
|
| 145 |
+
2313, 695, 210, 86, 778, 15, 784, 592, 779, 32, 77, 855, 964,2314, 259,2315,
|
| 146 |
+
501, 380,2316,2317, 83, 981, 153, 689,1308,1481,1482,1483,2318,2319, 716,1484,
|
| 147 |
+
2320,2321,2322,2323,2324,2325,1485,2326,2327, 128, 57, 68, 261,1048, 211, 170,
|
| 148 |
+
1240, 31,2328, 51, 435, 742,2329,2330,2331, 635,2332, 264, 456,2333,2334,2335,
|
| 149 |
+
425,2336,1486, 143, 507, 263, 943,2337, 363, 920,1487, 256,1488,1102, 243, 601,
|
| 150 |
+
1489,2338,2339,2340,2341,2342,2343,2344, 861,2345,2346,2347,2348,2349,2350, 395,
|
| 151 |
+
2351,1490,1491, 62, 535, 166, 225,2352,2353, 668, 419,1241, 138, 604, 928,2354,
|
| 152 |
+
1181,2355,1492,1493,2356,2357,2358,1143,2359, 696,2360, 387, 307,1309, 682, 476,
|
| 153 |
+
2361,2362, 332, 12, 222, 156,2363, 232,2364, 641, 276, 656, 517,1494,1495,1035,
|
| 154 |
+
416, 736,1496,2365,1017, 586,2366,2367,2368,1497,2369, 242,2370,2371,2372,1498,
|
| 155 |
+
2373, 965, 713,2374,2375,2376,2377, 740, 982,1499, 944,1500,1007,2378,2379,1310,
|
| 156 |
+
1501,2380,2381,2382, 785, 329,2383,2384,1502,2385,2386,2387, 932,2388,1503,2389,
|
| 157 |
+
2390,2391,2392,1242,2393,2394,2395,2396,2397, 994, 950,2398,2399,2400,2401,1504,
|
| 158 |
+
1311,2402,2403,2404,2405,1049, 749,2406,2407, 853, 718,1144,1312,2408,1182,1505,
|
| 159 |
+
2409,2410, 255, 516, 479, 564, 550, 214,1506,1507,1313, 413, 239, 444, 339,1145,
|
| 160 |
+
1036,1508,1509,1314,1037,1510,1315,2411,1511,2412,2413,2414, 176, 703, 497, 624,
|
| 161 |
+
593, 921, 302,2415, 341, 165,1103,1512,2416,1513,2417,2418,2419, 376,2420, 700,
|
| 162 |
+
2421,2422,2423, 258, 768,1316,2424,1183,2425, 995, 608,2426,2427,2428,2429, 221,
|
| 163 |
+
2430,2431,2432,2433,2434,2435,2436,2437, 195, 323, 726, 188, 897, 983,1317, 377,
|
| 164 |
+
644,1050, 879,2438, 452,2439,2440,2441,2442,2443,2444, 914,2445,2446,2447,2448,
|
| 165 |
+
915, 489,2449,1514,1184,2450,2451, 515, 64, 427, 495,2452, 583,2453, 483, 485,
|
| 166 |
+
1038, 562, 213,1515, 748, 666,2454,2455,2456,2457, 334,2458, 780, 996,1008, 705,
|
| 167 |
+
1243,2459,2460,2461,2462,2463, 114,2464, 493,1146, 366, 163,1516, 961,1104,2465,
|
| 168 |
+
291,2466,1318,1105,2467,1517, 365,2468, 355, 951,1244,2469,1319,2470, 631,2471,
|
| 169 |
+
2472, 218,1320, 364, 320, 756,1518,1519,1321,1520,1322,2473,2474,2475,2476, 997,
|
| 170 |
+
2477,2478,2479,2480, 665,1185,2481, 916,1521,2482,2483,2484, 584, 684,2485,2486,
|
| 171 |
+
797,2487,1051,1186,2488,2489,2490,1522,2491,2492, 370,2493,1039,1187, 65,2494,
|
| 172 |
+
434, 205, 463,1188,2495, 125, 812, 391, 402, 826, 699, 286, 398, 155, 781, 771,
|
| 173 |
+
585,2496, 590, 505,1073,2497, 599, 244, 219, 917,1018, 952, 646,1523,2498,1323,
|
| 174 |
+
2499,2500, 49, 984, 354, 741,2501, 625,2502,1324,2503,1019, 190, 357, 757, 491,
|
| 175 |
+
95, 782, 868,2504,2505,2506,2507,2508,2509, 134,1524,1074, 422,1525, 898,2510,
|
| 176 |
+
161,2511,2512,2513,2514, 769,2515,1526,2516,2517, 411,1325,2518, 472,1527,2519,
|
| 177 |
+
2520,2521,2522,2523,2524, 985,2525,2526,2527,2528,2529,2530, 764,2531,1245,2532,
|
| 178 |
+
2533, 25, 204, 311,2534, 496,2535,1052,2536,2537,2538,2539,2540,2541,2542, 199,
|
| 179 |
+
704, 504, 468, 758, 657,1528, 196, 44, 839,1246, 272, 750,2543, 765, 862,2544,
|
| 180 |
+
2545,1326,2546, 132, 615, 933,2547, 732,2548,2549,2550,1189,1529,2551, 283,1247,
|
| 181 |
+
1053, 607, 929,2552,2553,2554, 930, 183, 872, 616,1040,1147,2555,1148,1020, 441,
|
| 182 |
+
249,1075,2556,2557,2558, 466, 743,2559,2560,2561, 92, 514, 426, 420, 526,2562,
|
| 183 |
+
2563,2564,2565,2566,2567,2568, 185,2569,2570,2571,2572, 776,1530, 658,2573, 362,
|
| 184 |
+
2574, 361, 922,1076, 793,2575,2576,2577,2578,2579,2580,1531, 251,2581,2582,2583,
|
| 185 |
+
2584,1532, 54, 612, 237,1327,2585,2586, 275, 408, 647, 111,2587,1533,1106, 465,
|
| 186 |
+
3, 458, 9, 38,2588, 107, 110, 890, 209, 26, 737, 498,2589,1534,2590, 431,
|
| 187 |
+
202, 88,1535, 356, 287,1107, 660,1149,2591, 381,1536, 986,1150, 445,1248,1151,
|
| 188 |
+
974,2592,2593, 846,2594, 446, 953, 184,1249,1250, 727,2595, 923, 193, 883,2596,
|
| 189 |
+
2597,2598, 102, 324, 539, 817,2599, 421,1041,2600, 832,2601, 94, 175, 197, 406,
|
| 190 |
+
2602, 459,2603,2604,2605,2606,2607, 330, 555,2608,2609,2610, 706,1108, 389,2611,
|
| 191 |
+
2612,2613,2614, 233,2615, 833, 558, 931, 954,1251,2616,2617,1537, 546,2618,2619,
|
| 192 |
+
1009,2620,2621,2622,1538, 690,1328,2623, 955,2624,1539,2625,2626, 772,2627,2628,
|
| 193 |
+
2629,2630,2631, 924, 648, 863, 603,2632,2633, 934,1540, 864, 865,2634, 642,1042,
|
| 194 |
+
670,1190,2635,2636,2637,2638, 168,2639, 652, 873, 542,1054,1541,2640,2641,2642, # 512, 256
|
| 195 |
+
)
|
| 196 |
+
# fmt: on
|
.venv/Lib/site-packages/pip/_vendor/chardet/euckrprober.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 EUCKR_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class EUCKRProber(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(EUCKR_SM_MODEL)
|
| 38 |
+
self.distribution_analyzer = EUCKRDistributionAnalysis()
|
| 39 |
+
self.reset()
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def charset_name(self) -> str:
|
| 43 |
+
return "EUC-KR"
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def language(self) -> str:
|
| 47 |
+
return "Korean"
|