Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- venv/lib/python3.10/site-packages/pip/_internal/distributions/__init__.py +21 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/base.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/installed.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/sdist.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/wheel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/base.py +36 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/installed.py +20 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py +127 -0
- venv/lib/python3.10/site-packages/pip/_internal/distributions/wheel.py +31 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/__init__.py +2 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/collector.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/package_finder.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/sources.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/collector.py +648 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/package_finder.py +1004 -0
- venv/lib/python3.10/site-packages/pip/_internal/index/sources.py +224 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/index.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/__init__.py +111 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__init__.py +83 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/big5freq.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/big5prober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/chardistribution.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/charsetgroupprober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/charsetprober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/codingstatemachine.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/compat.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/cp949prober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/enums.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/escprober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/escsm.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/eucjpprober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euckrfreq.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euckrprober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euctwfreq.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euctwprober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/gb2312freq.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/gb2312prober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/hebrewprober.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/jisfreq.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/jpcntx.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langbulgarianmodel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langgreekmodel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langhebrewmodel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langhungarianmodel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langrussianmodel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langthaimodel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langturkishmodel.cpython-310.pyc +0 -0
venv/lib/python3.10/site-packages/pip/_internal/distributions/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 2 |
+
from pip._internal.distributions.sdist import SourceDistribution
|
| 3 |
+
from pip._internal.distributions.wheel import WheelDistribution
|
| 4 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def make_distribution_for_install_requirement(
|
| 8 |
+
install_req: InstallRequirement,
|
| 9 |
+
) -> AbstractDistribution:
|
| 10 |
+
"""Returns a Distribution for the given InstallRequirement"""
|
| 11 |
+
# Editable requirements will always be source distributions. They use the
|
| 12 |
+
# legacy logic until we create a modern standard for them.
|
| 13 |
+
if install_req.editable:
|
| 14 |
+
return SourceDistribution(install_req)
|
| 15 |
+
|
| 16 |
+
# If it's a wheel, it's a WheelDistribution
|
| 17 |
+
if install_req.is_wheel:
|
| 18 |
+
return WheelDistribution(install_req)
|
| 19 |
+
|
| 20 |
+
# Otherwise, a SourceDistribution
|
| 21 |
+
return SourceDistribution(install_req)
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (803 Bytes). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (1.86 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/installed.cpython-310.pyc
ADDED
|
Binary file (1.24 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/sdist.cpython-310.pyc
ADDED
|
Binary file (4.45 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/__pycache__/wheel.cpython-310.pyc
ADDED
|
Binary file (1.6 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/base.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import abc
|
| 2 |
+
|
| 3 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 4 |
+
from pip._internal.metadata.base import BaseDistribution
|
| 5 |
+
from pip._internal.req import InstallRequirement
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class AbstractDistribution(metaclass=abc.ABCMeta):
|
| 9 |
+
"""A base class for handling installable artifacts.
|
| 10 |
+
|
| 11 |
+
The requirements for anything installable are as follows:
|
| 12 |
+
|
| 13 |
+
- we must be able to determine the requirement name
|
| 14 |
+
(or we can't correctly handle the non-upgrade case).
|
| 15 |
+
|
| 16 |
+
- for packages with setup requirements, we must also be able
|
| 17 |
+
to determine their requirements without installing additional
|
| 18 |
+
packages (for the same reason as run-time dependencies)
|
| 19 |
+
|
| 20 |
+
- we must be able to create a Distribution object exposing the
|
| 21 |
+
above metadata.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
def __init__(self, req: InstallRequirement) -> None:
|
| 25 |
+
super().__init__()
|
| 26 |
+
self.req = req
|
| 27 |
+
|
| 28 |
+
@abc.abstractmethod
|
| 29 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 30 |
+
raise NotImplementedError()
|
| 31 |
+
|
| 32 |
+
@abc.abstractmethod
|
| 33 |
+
def prepare_distribution_metadata(
|
| 34 |
+
self, finder: PackageFinder, build_isolation: bool
|
| 35 |
+
) -> None:
|
| 36 |
+
raise NotImplementedError()
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/installed.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 2 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 3 |
+
from pip._internal.metadata import BaseDistribution
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class InstalledDistribution(AbstractDistribution):
|
| 7 |
+
"""Represents an installed package.
|
| 8 |
+
|
| 9 |
+
This does not need any preparation as the required information has already
|
| 10 |
+
been computed.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 14 |
+
assert self.req.satisfied_by is not None, "not actually installed"
|
| 15 |
+
return self.req.satisfied_by
|
| 16 |
+
|
| 17 |
+
def prepare_distribution_metadata(
|
| 18 |
+
self, finder: PackageFinder, build_isolation: bool
|
| 19 |
+
) -> None:
|
| 20 |
+
pass
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from typing import Iterable, Set, Tuple
|
| 3 |
+
|
| 4 |
+
from pip._internal.build_env import BuildEnvironment
|
| 5 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 6 |
+
from pip._internal.exceptions import InstallationError
|
| 7 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 8 |
+
from pip._internal.metadata import BaseDistribution
|
| 9 |
+
from pip._internal.utils.subprocess import runner_with_spinner_message
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class SourceDistribution(AbstractDistribution):
|
| 15 |
+
"""Represents a source distribution.
|
| 16 |
+
|
| 17 |
+
The preparation step for these needs metadata for the packages to be
|
| 18 |
+
generated, either using PEP 517 or using the legacy `setup.py egg_info`.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 22 |
+
return self.req.get_dist()
|
| 23 |
+
|
| 24 |
+
def prepare_distribution_metadata(
|
| 25 |
+
self, finder: PackageFinder, build_isolation: bool
|
| 26 |
+
) -> None:
|
| 27 |
+
# Load pyproject.toml, to determine whether PEP 517 is to be used
|
| 28 |
+
self.req.load_pyproject_toml()
|
| 29 |
+
|
| 30 |
+
# Set up the build isolation, if this requirement should be isolated
|
| 31 |
+
should_isolate = self.req.use_pep517 and build_isolation
|
| 32 |
+
if should_isolate:
|
| 33 |
+
# Setup an isolated environment and install the build backend static
|
| 34 |
+
# requirements in it.
|
| 35 |
+
self._prepare_build_backend(finder)
|
| 36 |
+
# Check that if the requirement is editable, it either supports PEP 660 or
|
| 37 |
+
# has a setup.py or a setup.cfg. This cannot be done earlier because we need
|
| 38 |
+
# to setup the build backend to verify it supports build_editable, nor can
|
| 39 |
+
# it be done later, because we want to avoid installing build requirements
|
| 40 |
+
# needlessly. Doing it here also works around setuptools generating
|
| 41 |
+
# UNKNOWN.egg-info when running get_requires_for_build_wheel on a directory
|
| 42 |
+
# without setup.py nor setup.cfg.
|
| 43 |
+
self.req.isolated_editable_sanity_check()
|
| 44 |
+
# Install the dynamic build requirements.
|
| 45 |
+
self._install_build_reqs(finder)
|
| 46 |
+
|
| 47 |
+
self.req.prepare_metadata()
|
| 48 |
+
|
| 49 |
+
def _prepare_build_backend(self, finder: PackageFinder) -> None:
|
| 50 |
+
# Isolate in a BuildEnvironment and install the build-time
|
| 51 |
+
# requirements.
|
| 52 |
+
pyproject_requires = self.req.pyproject_requires
|
| 53 |
+
assert pyproject_requires is not None
|
| 54 |
+
|
| 55 |
+
self.req.build_env = BuildEnvironment()
|
| 56 |
+
self.req.build_env.install_requirements(
|
| 57 |
+
finder, pyproject_requires, "overlay", kind="build dependencies"
|
| 58 |
+
)
|
| 59 |
+
conflicting, missing = self.req.build_env.check_requirements(
|
| 60 |
+
self.req.requirements_to_check
|
| 61 |
+
)
|
| 62 |
+
if conflicting:
|
| 63 |
+
self._raise_conflicts("PEP 517/518 supported requirements", conflicting)
|
| 64 |
+
if missing:
|
| 65 |
+
logger.warning(
|
| 66 |
+
"Missing build requirements in pyproject.toml for %s.",
|
| 67 |
+
self.req,
|
| 68 |
+
)
|
| 69 |
+
logger.warning(
|
| 70 |
+
"The project does not specify a build backend, and "
|
| 71 |
+
"pip cannot fall back to setuptools without %s.",
|
| 72 |
+
" and ".join(map(repr, sorted(missing))),
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
def _get_build_requires_wheel(self) -> Iterable[str]:
|
| 76 |
+
with self.req.build_env:
|
| 77 |
+
runner = runner_with_spinner_message("Getting requirements to build wheel")
|
| 78 |
+
backend = self.req.pep517_backend
|
| 79 |
+
assert backend is not None
|
| 80 |
+
with backend.subprocess_runner(runner):
|
| 81 |
+
return backend.get_requires_for_build_wheel()
|
| 82 |
+
|
| 83 |
+
def _get_build_requires_editable(self) -> Iterable[str]:
|
| 84 |
+
with self.req.build_env:
|
| 85 |
+
runner = runner_with_spinner_message(
|
| 86 |
+
"Getting requirements to build editable"
|
| 87 |
+
)
|
| 88 |
+
backend = self.req.pep517_backend
|
| 89 |
+
assert backend is not None
|
| 90 |
+
with backend.subprocess_runner(runner):
|
| 91 |
+
return backend.get_requires_for_build_editable()
|
| 92 |
+
|
| 93 |
+
def _install_build_reqs(self, finder: PackageFinder) -> None:
|
| 94 |
+
# Install any extra build dependencies that the backend requests.
|
| 95 |
+
# This must be done in a second pass, as the pyproject.toml
|
| 96 |
+
# dependencies must be installed before we can call the backend.
|
| 97 |
+
if (
|
| 98 |
+
self.req.editable
|
| 99 |
+
and self.req.permit_editable_wheels
|
| 100 |
+
and self.req.supports_pyproject_editable()
|
| 101 |
+
):
|
| 102 |
+
build_reqs = self._get_build_requires_editable()
|
| 103 |
+
else:
|
| 104 |
+
build_reqs = self._get_build_requires_wheel()
|
| 105 |
+
conflicting, missing = self.req.build_env.check_requirements(build_reqs)
|
| 106 |
+
if conflicting:
|
| 107 |
+
self._raise_conflicts("the backend dependencies", conflicting)
|
| 108 |
+
self.req.build_env.install_requirements(
|
| 109 |
+
finder, missing, "normal", kind="backend dependencies"
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
def _raise_conflicts(
|
| 113 |
+
self, conflicting_with: str, conflicting_reqs: Set[Tuple[str, str]]
|
| 114 |
+
) -> None:
|
| 115 |
+
format_string = (
|
| 116 |
+
"Some build dependencies for {requirement} "
|
| 117 |
+
"conflict with {conflicting_with}: {description}."
|
| 118 |
+
)
|
| 119 |
+
error_message = format_string.format(
|
| 120 |
+
requirement=self.req,
|
| 121 |
+
conflicting_with=conflicting_with,
|
| 122 |
+
description=", ".join(
|
| 123 |
+
f"{installed} is incompatible with {wanted}"
|
| 124 |
+
for installed, wanted in sorted(conflicting_reqs)
|
| 125 |
+
),
|
| 126 |
+
)
|
| 127 |
+
raise InstallationError(error_message)
|
venv/lib/python3.10/site-packages/pip/_internal/distributions/wheel.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 2 |
+
|
| 3 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 4 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 5 |
+
from pip._internal.metadata import (
|
| 6 |
+
BaseDistribution,
|
| 7 |
+
FilesystemWheel,
|
| 8 |
+
get_wheel_distribution,
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class WheelDistribution(AbstractDistribution):
|
| 13 |
+
"""Represents a wheel distribution.
|
| 14 |
+
|
| 15 |
+
This does not need any preparation as wheels can be directly unpacked.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 19 |
+
"""Loads the metadata from the wheel file into memory and returns a
|
| 20 |
+
Distribution that uses it, not relying on the wheel file or
|
| 21 |
+
requirement.
|
| 22 |
+
"""
|
| 23 |
+
assert self.req.local_file_path, "Set as part of preparation during download"
|
| 24 |
+
assert self.req.name, "Wheels are never unnamed"
|
| 25 |
+
wheel = FilesystemWheel(self.req.local_file_path)
|
| 26 |
+
return get_wheel_distribution(wheel, canonicalize_name(self.req.name))
|
| 27 |
+
|
| 28 |
+
def prepare_distribution_metadata(
|
| 29 |
+
self, finder: PackageFinder, build_isolation: bool
|
| 30 |
+
) -> None:
|
| 31 |
+
pass
|
venv/lib/python3.10/site-packages/pip/_internal/index/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Index interaction code
|
| 2 |
+
"""
|
venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (230 Bytes). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/collector.cpython-310.pyc
ADDED
|
Binary file (19.3 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/package_finder.cpython-310.pyc
ADDED
|
Binary file (28.1 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/index/__pycache__/sources.cpython-310.pyc
ADDED
|
Binary file (7.12 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_internal/index/collector.py
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
The main purpose of this module is to expose LinkCollector.collect_sources().
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import cgi
|
| 6 |
+
import collections
|
| 7 |
+
import functools
|
| 8 |
+
import itertools
|
| 9 |
+
import logging
|
| 10 |
+
import os
|
| 11 |
+
import re
|
| 12 |
+
import urllib.parse
|
| 13 |
+
import urllib.request
|
| 14 |
+
import xml.etree.ElementTree
|
| 15 |
+
from html.parser import HTMLParser
|
| 16 |
+
from optparse import Values
|
| 17 |
+
from typing import (
|
| 18 |
+
TYPE_CHECKING,
|
| 19 |
+
Any,
|
| 20 |
+
Callable,
|
| 21 |
+
Dict,
|
| 22 |
+
Iterable,
|
| 23 |
+
List,
|
| 24 |
+
MutableMapping,
|
| 25 |
+
NamedTuple,
|
| 26 |
+
Optional,
|
| 27 |
+
Sequence,
|
| 28 |
+
Tuple,
|
| 29 |
+
Union,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
from pip._vendor import html5lib, requests
|
| 33 |
+
from pip._vendor.requests import Response
|
| 34 |
+
from pip._vendor.requests.exceptions import RetryError, SSLError
|
| 35 |
+
|
| 36 |
+
from pip._internal.exceptions import NetworkConnectionError
|
| 37 |
+
from pip._internal.models.link import Link
|
| 38 |
+
from pip._internal.models.search_scope import SearchScope
|
| 39 |
+
from pip._internal.network.session import PipSession
|
| 40 |
+
from pip._internal.network.utils import raise_for_status
|
| 41 |
+
from pip._internal.utils.deprecation import deprecated
|
| 42 |
+
from pip._internal.utils.filetypes import is_archive_file
|
| 43 |
+
from pip._internal.utils.misc import pairwise, redact_auth_from_url
|
| 44 |
+
from pip._internal.vcs import vcs
|
| 45 |
+
|
| 46 |
+
from .sources import CandidatesFromPage, LinkSource, build_source
|
| 47 |
+
|
| 48 |
+
if TYPE_CHECKING:
|
| 49 |
+
from typing import Protocol
|
| 50 |
+
else:
|
| 51 |
+
Protocol = object
|
| 52 |
+
|
| 53 |
+
logger = logging.getLogger(__name__)
|
| 54 |
+
|
| 55 |
+
HTMLElement = xml.etree.ElementTree.Element
|
| 56 |
+
ResponseHeaders = MutableMapping[str, str]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _match_vcs_scheme(url: str) -> Optional[str]:
|
| 60 |
+
"""Look for VCS schemes in the URL.
|
| 61 |
+
|
| 62 |
+
Returns the matched VCS scheme, or None if there's no match.
|
| 63 |
+
"""
|
| 64 |
+
for scheme in vcs.schemes:
|
| 65 |
+
if url.lower().startswith(scheme) and url[len(scheme)] in "+:":
|
| 66 |
+
return scheme
|
| 67 |
+
return None
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class _NotHTML(Exception):
|
| 71 |
+
def __init__(self, content_type: str, request_desc: str) -> None:
|
| 72 |
+
super().__init__(content_type, request_desc)
|
| 73 |
+
self.content_type = content_type
|
| 74 |
+
self.request_desc = request_desc
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _ensure_html_header(response: Response) -> None:
|
| 78 |
+
"""Check the Content-Type header to ensure the response contains HTML.
|
| 79 |
+
|
| 80 |
+
Raises `_NotHTML` if the content type is not text/html.
|
| 81 |
+
"""
|
| 82 |
+
content_type = response.headers.get("Content-Type", "")
|
| 83 |
+
if not content_type.lower().startswith("text/html"):
|
| 84 |
+
raise _NotHTML(content_type, response.request.method)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class _NotHTTP(Exception):
|
| 88 |
+
pass
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _ensure_html_response(url: str, session: PipSession) -> None:
|
| 92 |
+
"""Send a HEAD request to the URL, and ensure the response contains HTML.
|
| 93 |
+
|
| 94 |
+
Raises `_NotHTTP` if the URL is not available for a HEAD request, or
|
| 95 |
+
`_NotHTML` if the content type is not text/html.
|
| 96 |
+
"""
|
| 97 |
+
scheme, netloc, path, query, fragment = urllib.parse.urlsplit(url)
|
| 98 |
+
if scheme not in {"http", "https"}:
|
| 99 |
+
raise _NotHTTP()
|
| 100 |
+
|
| 101 |
+
resp = session.head(url, allow_redirects=True)
|
| 102 |
+
raise_for_status(resp)
|
| 103 |
+
|
| 104 |
+
_ensure_html_header(resp)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def _get_html_response(url: str, session: PipSession) -> Response:
|
| 108 |
+
"""Access an HTML page with GET, and return the response.
|
| 109 |
+
|
| 110 |
+
This consists of three parts:
|
| 111 |
+
|
| 112 |
+
1. If the URL looks suspiciously like an archive, send a HEAD first to
|
| 113 |
+
check the Content-Type is HTML, to avoid downloading a large file.
|
| 114 |
+
Raise `_NotHTTP` if the content type cannot be determined, or
|
| 115 |
+
`_NotHTML` if it is not HTML.
|
| 116 |
+
2. Actually perform the request. Raise HTTP exceptions on network failures.
|
| 117 |
+
3. Check the Content-Type header to make sure we got HTML, and raise
|
| 118 |
+
`_NotHTML` otherwise.
|
| 119 |
+
"""
|
| 120 |
+
if is_archive_file(Link(url).filename):
|
| 121 |
+
_ensure_html_response(url, session=session)
|
| 122 |
+
|
| 123 |
+
logger.debug("Getting page %s", redact_auth_from_url(url))
|
| 124 |
+
|
| 125 |
+
resp = session.get(
|
| 126 |
+
url,
|
| 127 |
+
headers={
|
| 128 |
+
"Accept": "text/html",
|
| 129 |
+
# We don't want to blindly returned cached data for
|
| 130 |
+
# /simple/, because authors generally expecting that
|
| 131 |
+
# twine upload && pip install will function, but if
|
| 132 |
+
# they've done a pip install in the last ~10 minutes
|
| 133 |
+
# it won't. Thus by setting this to zero we will not
|
| 134 |
+
# blindly use any cached data, however the benefit of
|
| 135 |
+
# using max-age=0 instead of no-cache, is that we will
|
| 136 |
+
# still support conditional requests, so we will still
|
| 137 |
+
# minimize traffic sent in cases where the page hasn't
|
| 138 |
+
# changed at all, we will just always incur the round
|
| 139 |
+
# trip for the conditional GET now instead of only
|
| 140 |
+
# once per 10 minutes.
|
| 141 |
+
# For more information, please see pypa/pip#5670.
|
| 142 |
+
"Cache-Control": "max-age=0",
|
| 143 |
+
},
|
| 144 |
+
)
|
| 145 |
+
raise_for_status(resp)
|
| 146 |
+
|
| 147 |
+
# The check for archives above only works if the url ends with
|
| 148 |
+
# something that looks like an archive. However that is not a
|
| 149 |
+
# requirement of an url. Unless we issue a HEAD request on every
|
| 150 |
+
# url we cannot know ahead of time for sure if something is HTML
|
| 151 |
+
# or not. However we can check after we've downloaded it.
|
| 152 |
+
_ensure_html_header(resp)
|
| 153 |
+
|
| 154 |
+
return resp
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def _get_encoding_from_headers(headers: ResponseHeaders) -> Optional[str]:
|
| 158 |
+
"""Determine if we have any encoding information in our headers."""
|
| 159 |
+
if headers and "Content-Type" in headers:
|
| 160 |
+
content_type, params = cgi.parse_header(headers["Content-Type"])
|
| 161 |
+
if "charset" in params:
|
| 162 |
+
return params["charset"]
|
| 163 |
+
return None
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _determine_base_url(document: HTMLElement, page_url: str) -> str:
|
| 167 |
+
"""Determine the HTML document's base URL.
|
| 168 |
+
|
| 169 |
+
This looks for a ``<base>`` tag in the HTML document. If present, its href
|
| 170 |
+
attribute denotes the base URL of anchor tags in the document. If there is
|
| 171 |
+
no such tag (or if it does not have a valid href attribute), the HTML
|
| 172 |
+
file's URL is used as the base URL.
|
| 173 |
+
|
| 174 |
+
:param document: An HTML document representation. The current
|
| 175 |
+
implementation expects the result of ``html5lib.parse()``.
|
| 176 |
+
:param page_url: The URL of the HTML document.
|
| 177 |
+
|
| 178 |
+
TODO: Remove when `html5lib` is dropped.
|
| 179 |
+
"""
|
| 180 |
+
for base in document.findall(".//base"):
|
| 181 |
+
href = base.get("href")
|
| 182 |
+
if href is not None:
|
| 183 |
+
return href
|
| 184 |
+
return page_url
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def _clean_url_path_part(part: str) -> str:
|
| 188 |
+
"""
|
| 189 |
+
Clean a "part" of a URL path (i.e. after splitting on "@" characters).
|
| 190 |
+
"""
|
| 191 |
+
# We unquote prior to quoting to make sure nothing is double quoted.
|
| 192 |
+
return urllib.parse.quote(urllib.parse.unquote(part))
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def _clean_file_url_path(part: str) -> str:
|
| 196 |
+
"""
|
| 197 |
+
Clean the first part of a URL path that corresponds to a local
|
| 198 |
+
filesystem path (i.e. the first part after splitting on "@" characters).
|
| 199 |
+
"""
|
| 200 |
+
# We unquote prior to quoting to make sure nothing is double quoted.
|
| 201 |
+
# Also, on Windows the path part might contain a drive letter which
|
| 202 |
+
# should not be quoted. On Linux where drive letters do not
|
| 203 |
+
# exist, the colon should be quoted. We rely on urllib.request
|
| 204 |
+
# to do the right thing here.
|
| 205 |
+
return urllib.request.pathname2url(urllib.request.url2pathname(part))
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
# percent-encoded: /
|
| 209 |
+
_reserved_chars_re = re.compile("(@|%2F)", re.IGNORECASE)
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def _clean_url_path(path: str, is_local_path: bool) -> str:
|
| 213 |
+
"""
|
| 214 |
+
Clean the path portion of a URL.
|
| 215 |
+
"""
|
| 216 |
+
if is_local_path:
|
| 217 |
+
clean_func = _clean_file_url_path
|
| 218 |
+
else:
|
| 219 |
+
clean_func = _clean_url_path_part
|
| 220 |
+
|
| 221 |
+
# Split on the reserved characters prior to cleaning so that
|
| 222 |
+
# revision strings in VCS URLs are properly preserved.
|
| 223 |
+
parts = _reserved_chars_re.split(path)
|
| 224 |
+
|
| 225 |
+
cleaned_parts = []
|
| 226 |
+
for to_clean, reserved in pairwise(itertools.chain(parts, [""])):
|
| 227 |
+
cleaned_parts.append(clean_func(to_clean))
|
| 228 |
+
# Normalize %xx escapes (e.g. %2f -> %2F)
|
| 229 |
+
cleaned_parts.append(reserved.upper())
|
| 230 |
+
|
| 231 |
+
return "".join(cleaned_parts)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def _clean_link(url: str) -> str:
|
| 235 |
+
"""
|
| 236 |
+
Make sure a link is fully quoted.
|
| 237 |
+
For example, if ' ' occurs in the URL, it will be replaced with "%20",
|
| 238 |
+
and without double-quoting other characters.
|
| 239 |
+
"""
|
| 240 |
+
# Split the URL into parts according to the general structure
|
| 241 |
+
# `scheme://netloc/path;parameters?query#fragment`.
|
| 242 |
+
result = urllib.parse.urlparse(url)
|
| 243 |
+
# If the netloc is empty, then the URL refers to a local filesystem path.
|
| 244 |
+
is_local_path = not result.netloc
|
| 245 |
+
path = _clean_url_path(result.path, is_local_path=is_local_path)
|
| 246 |
+
return urllib.parse.urlunparse(result._replace(path=path))
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def _create_link_from_element(
|
| 250 |
+
element_attribs: Dict[str, Optional[str]],
|
| 251 |
+
page_url: str,
|
| 252 |
+
base_url: str,
|
| 253 |
+
) -> Optional[Link]:
|
| 254 |
+
"""
|
| 255 |
+
Convert an anchor element's attributes in a simple repository page to a Link.
|
| 256 |
+
"""
|
| 257 |
+
href = element_attribs.get("href")
|
| 258 |
+
if not href:
|
| 259 |
+
return None
|
| 260 |
+
|
| 261 |
+
url = _clean_link(urllib.parse.urljoin(base_url, href))
|
| 262 |
+
pyrequire = element_attribs.get("data-requires-python")
|
| 263 |
+
yanked_reason = element_attribs.get("data-yanked")
|
| 264 |
+
|
| 265 |
+
link = Link(
|
| 266 |
+
url,
|
| 267 |
+
comes_from=page_url,
|
| 268 |
+
requires_python=pyrequire,
|
| 269 |
+
yanked_reason=yanked_reason,
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
return link
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
class CacheablePageContent:
|
| 276 |
+
def __init__(self, page: "HTMLPage") -> None:
|
| 277 |
+
assert page.cache_link_parsing
|
| 278 |
+
self.page = page
|
| 279 |
+
|
| 280 |
+
def __eq__(self, other: object) -> bool:
|
| 281 |
+
return isinstance(other, type(self)) and self.page.url == other.page.url
|
| 282 |
+
|
| 283 |
+
def __hash__(self) -> int:
|
| 284 |
+
return hash(self.page.url)
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class ParseLinks(Protocol):
|
| 288 |
+
def __call__(
|
| 289 |
+
self, page: "HTMLPage", use_deprecated_html5lib: bool
|
| 290 |
+
) -> Iterable[Link]:
|
| 291 |
+
...
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def with_cached_html_pages(fn: ParseLinks) -> ParseLinks:
|
| 295 |
+
"""
|
| 296 |
+
Given a function that parses an Iterable[Link] from an HTMLPage, cache the
|
| 297 |
+
function's result (keyed by CacheablePageContent), unless the HTMLPage
|
| 298 |
+
`page` has `page.cache_link_parsing == False`.
|
| 299 |
+
"""
|
| 300 |
+
|
| 301 |
+
@functools.lru_cache(maxsize=None)
|
| 302 |
+
def wrapper(
|
| 303 |
+
cacheable_page: CacheablePageContent, use_deprecated_html5lib: bool
|
| 304 |
+
) -> List[Link]:
|
| 305 |
+
return list(fn(cacheable_page.page, use_deprecated_html5lib))
|
| 306 |
+
|
| 307 |
+
@functools.wraps(fn)
|
| 308 |
+
def wrapper_wrapper(page: "HTMLPage", use_deprecated_html5lib: bool) -> List[Link]:
|
| 309 |
+
if page.cache_link_parsing:
|
| 310 |
+
return wrapper(CacheablePageContent(page), use_deprecated_html5lib)
|
| 311 |
+
return list(fn(page, use_deprecated_html5lib))
|
| 312 |
+
|
| 313 |
+
return wrapper_wrapper
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def _parse_links_html5lib(page: "HTMLPage") -> Iterable[Link]:
|
| 317 |
+
"""
|
| 318 |
+
Parse an HTML document, and yield its anchor elements as Link objects.
|
| 319 |
+
|
| 320 |
+
TODO: Remove when `html5lib` is dropped.
|
| 321 |
+
"""
|
| 322 |
+
document = html5lib.parse(
|
| 323 |
+
page.content,
|
| 324 |
+
transport_encoding=page.encoding,
|
| 325 |
+
namespaceHTMLElements=False,
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
url = page.url
|
| 329 |
+
base_url = _determine_base_url(document, url)
|
| 330 |
+
for anchor in document.findall(".//a"):
|
| 331 |
+
link = _create_link_from_element(
|
| 332 |
+
anchor.attrib,
|
| 333 |
+
page_url=url,
|
| 334 |
+
base_url=base_url,
|
| 335 |
+
)
|
| 336 |
+
if link is None:
|
| 337 |
+
continue
|
| 338 |
+
yield link
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
@with_cached_html_pages
|
| 342 |
+
def parse_links(page: "HTMLPage", use_deprecated_html5lib: bool) -> Iterable[Link]:
|
| 343 |
+
"""
|
| 344 |
+
Parse an HTML document, and yield its anchor elements as Link objects.
|
| 345 |
+
"""
|
| 346 |
+
encoding = page.encoding or "utf-8"
|
| 347 |
+
|
| 348 |
+
# Check if the page starts with a valid doctype, to decide whether to use
|
| 349 |
+
# http.parser or (deprecated) html5lib for parsing -- unless explicitly
|
| 350 |
+
# requested to use html5lib.
|
| 351 |
+
if not use_deprecated_html5lib:
|
| 352 |
+
expected_doctype = "<!doctype html>".encode(encoding)
|
| 353 |
+
actual_start = page.content[: len(expected_doctype)]
|
| 354 |
+
if actual_start.decode(encoding).lower() != "<!doctype html>":
|
| 355 |
+
deprecated(
|
| 356 |
+
reason=(
|
| 357 |
+
f"The HTML index page being used ({page.url}) is not a proper "
|
| 358 |
+
"HTML 5 document. This is in violation of PEP 503 which requires "
|
| 359 |
+
"these pages to be well-formed HTML 5 documents. Please reach out "
|
| 360 |
+
"to the owners of this index page, and ask them to update this "
|
| 361 |
+
"index page to a valid HTML 5 document."
|
| 362 |
+
),
|
| 363 |
+
replacement=None,
|
| 364 |
+
gone_in="22.2",
|
| 365 |
+
issue=10825,
|
| 366 |
+
)
|
| 367 |
+
use_deprecated_html5lib = True
|
| 368 |
+
|
| 369 |
+
if use_deprecated_html5lib:
|
| 370 |
+
yield from _parse_links_html5lib(page)
|
| 371 |
+
return
|
| 372 |
+
|
| 373 |
+
parser = HTMLLinkParser()
|
| 374 |
+
parser.feed(page.content.decode(encoding))
|
| 375 |
+
|
| 376 |
+
url = page.url
|
| 377 |
+
base_url = parser.base_url or url
|
| 378 |
+
for anchor in parser.anchors:
|
| 379 |
+
link = _create_link_from_element(
|
| 380 |
+
anchor,
|
| 381 |
+
page_url=url,
|
| 382 |
+
base_url=base_url,
|
| 383 |
+
)
|
| 384 |
+
if link is None:
|
| 385 |
+
continue
|
| 386 |
+
yield link
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
class HTMLPage:
|
| 390 |
+
"""Represents one page, along with its URL"""
|
| 391 |
+
|
| 392 |
+
def __init__(
|
| 393 |
+
self,
|
| 394 |
+
content: bytes,
|
| 395 |
+
encoding: Optional[str],
|
| 396 |
+
url: str,
|
| 397 |
+
cache_link_parsing: bool = True,
|
| 398 |
+
) -> None:
|
| 399 |
+
"""
|
| 400 |
+
:param encoding: the encoding to decode the given content.
|
| 401 |
+
:param url: the URL from which the HTML was downloaded.
|
| 402 |
+
:param cache_link_parsing: whether links parsed from this page's url
|
| 403 |
+
should be cached. PyPI index urls should
|
| 404 |
+
have this set to False, for example.
|
| 405 |
+
"""
|
| 406 |
+
self.content = content
|
| 407 |
+
self.encoding = encoding
|
| 408 |
+
self.url = url
|
| 409 |
+
self.cache_link_parsing = cache_link_parsing
|
| 410 |
+
|
| 411 |
+
def __str__(self) -> str:
|
| 412 |
+
return redact_auth_from_url(self.url)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
class HTMLLinkParser(HTMLParser):
|
| 416 |
+
"""
|
| 417 |
+
HTMLParser that keeps the first base HREF and a list of all anchor
|
| 418 |
+
elements' attributes.
|
| 419 |
+
"""
|
| 420 |
+
|
| 421 |
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
| 422 |
+
super().__init__(*args, **kwargs)
|
| 423 |
+
self._seen_decl = False
|
| 424 |
+
self.base_url: Optional[str] = None
|
| 425 |
+
self.anchors: List[Dict[str, Optional[str]]] = []
|
| 426 |
+
|
| 427 |
+
def handle_decl(self, decl: str) -> None:
|
| 428 |
+
if decl.lower() != "doctype html":
|
| 429 |
+
self._raise_error()
|
| 430 |
+
self._seen_decl = True
|
| 431 |
+
|
| 432 |
+
def handle_starttag(self, tag: str, attrs: List[Tuple[str, Optional[str]]]) -> None:
|
| 433 |
+
if not self._seen_decl:
|
| 434 |
+
self._raise_error()
|
| 435 |
+
|
| 436 |
+
if tag == "base" and self.base_url is None:
|
| 437 |
+
href = self.get_href(attrs)
|
| 438 |
+
if href is not None:
|
| 439 |
+
self.base_url = href
|
| 440 |
+
elif tag == "a":
|
| 441 |
+
self.anchors.append(dict(attrs))
|
| 442 |
+
|
| 443 |
+
def get_href(self, attrs: List[Tuple[str, Optional[str]]]) -> Optional[str]:
|
| 444 |
+
for name, value in attrs:
|
| 445 |
+
if name == "href":
|
| 446 |
+
return value
|
| 447 |
+
return None
|
| 448 |
+
|
| 449 |
+
def _raise_error(self) -> None:
|
| 450 |
+
raise ValueError(
|
| 451 |
+
"HTML doctype missing or incorrect. Expected <!DOCTYPE html>.\n\n"
|
| 452 |
+
"If you believe this error to be incorrect, try passing the "
|
| 453 |
+
"command line option --use-deprecated=html5lib and please leave "
|
| 454 |
+
"a comment on the pip issue at https://github.com/pypa/pip/issues/10825."
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def _handle_get_page_fail(
|
| 459 |
+
link: Link,
|
| 460 |
+
reason: Union[str, Exception],
|
| 461 |
+
meth: Optional[Callable[..., None]] = None,
|
| 462 |
+
) -> None:
|
| 463 |
+
if meth is None:
|
| 464 |
+
meth = logger.debug
|
| 465 |
+
meth("Could not fetch URL %s: %s - skipping", link, reason)
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
def _make_html_page(response: Response, cache_link_parsing: bool = True) -> HTMLPage:
|
| 469 |
+
encoding = _get_encoding_from_headers(response.headers)
|
| 470 |
+
return HTMLPage(
|
| 471 |
+
response.content,
|
| 472 |
+
encoding=encoding,
|
| 473 |
+
url=response.url,
|
| 474 |
+
cache_link_parsing=cache_link_parsing,
|
| 475 |
+
)
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def _get_html_page(
|
| 479 |
+
link: Link, session: Optional[PipSession] = None
|
| 480 |
+
) -> Optional["HTMLPage"]:
|
| 481 |
+
if session is None:
|
| 482 |
+
raise TypeError(
|
| 483 |
+
"_get_html_page() missing 1 required keyword argument: 'session'"
|
| 484 |
+
)
|
| 485 |
+
|
| 486 |
+
url = link.url.split("#", 1)[0]
|
| 487 |
+
|
| 488 |
+
# Check for VCS schemes that do not support lookup as web pages.
|
| 489 |
+
vcs_scheme = _match_vcs_scheme(url)
|
| 490 |
+
if vcs_scheme:
|
| 491 |
+
logger.warning(
|
| 492 |
+
"Cannot look at %s URL %s because it does not support lookup as web pages.",
|
| 493 |
+
vcs_scheme,
|
| 494 |
+
link,
|
| 495 |
+
)
|
| 496 |
+
return None
|
| 497 |
+
|
| 498 |
+
# Tack index.html onto file:// URLs that point to directories
|
| 499 |
+
scheme, _, path, _, _, _ = urllib.parse.urlparse(url)
|
| 500 |
+
if scheme == "file" and os.path.isdir(urllib.request.url2pathname(path)):
|
| 501 |
+
# add trailing slash if not present so urljoin doesn't trim
|
| 502 |
+
# final segment
|
| 503 |
+
if not url.endswith("/"):
|
| 504 |
+
url += "/"
|
| 505 |
+
url = urllib.parse.urljoin(url, "index.html")
|
| 506 |
+
logger.debug(" file: URL is directory, getting %s", url)
|
| 507 |
+
|
| 508 |
+
try:
|
| 509 |
+
resp = _get_html_response(url, session=session)
|
| 510 |
+
except _NotHTTP:
|
| 511 |
+
logger.warning(
|
| 512 |
+
"Skipping page %s because it looks like an archive, and cannot "
|
| 513 |
+
"be checked by a HTTP HEAD request.",
|
| 514 |
+
link,
|
| 515 |
+
)
|
| 516 |
+
except _NotHTML as exc:
|
| 517 |
+
logger.warning(
|
| 518 |
+
"Skipping page %s because the %s request got Content-Type: %s."
|
| 519 |
+
"The only supported Content-Type is text/html",
|
| 520 |
+
link,
|
| 521 |
+
exc.request_desc,
|
| 522 |
+
exc.content_type,
|
| 523 |
+
)
|
| 524 |
+
except NetworkConnectionError as exc:
|
| 525 |
+
_handle_get_page_fail(link, exc)
|
| 526 |
+
except RetryError as exc:
|
| 527 |
+
_handle_get_page_fail(link, exc)
|
| 528 |
+
except SSLError as exc:
|
| 529 |
+
reason = "There was a problem confirming the ssl certificate: "
|
| 530 |
+
reason += str(exc)
|
| 531 |
+
_handle_get_page_fail(link, reason, meth=logger.info)
|
| 532 |
+
except requests.ConnectionError as exc:
|
| 533 |
+
_handle_get_page_fail(link, f"connection error: {exc}")
|
| 534 |
+
except requests.Timeout:
|
| 535 |
+
_handle_get_page_fail(link, "timed out")
|
| 536 |
+
else:
|
| 537 |
+
return _make_html_page(resp, cache_link_parsing=link.cache_link_parsing)
|
| 538 |
+
return None
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
class CollectedSources(NamedTuple):
|
| 542 |
+
find_links: Sequence[Optional[LinkSource]]
|
| 543 |
+
index_urls: Sequence[Optional[LinkSource]]
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
class LinkCollector:
|
| 547 |
+
|
| 548 |
+
"""
|
| 549 |
+
Responsible for collecting Link objects from all configured locations,
|
| 550 |
+
making network requests as needed.
|
| 551 |
+
|
| 552 |
+
The class's main method is its collect_sources() method.
|
| 553 |
+
"""
|
| 554 |
+
|
| 555 |
+
def __init__(
|
| 556 |
+
self,
|
| 557 |
+
session: PipSession,
|
| 558 |
+
search_scope: SearchScope,
|
| 559 |
+
) -> None:
|
| 560 |
+
self.search_scope = search_scope
|
| 561 |
+
self.session = session
|
| 562 |
+
|
| 563 |
+
@classmethod
|
| 564 |
+
def create(
|
| 565 |
+
cls,
|
| 566 |
+
session: PipSession,
|
| 567 |
+
options: Values,
|
| 568 |
+
suppress_no_index: bool = False,
|
| 569 |
+
) -> "LinkCollector":
|
| 570 |
+
"""
|
| 571 |
+
:param session: The Session to use to make requests.
|
| 572 |
+
:param suppress_no_index: Whether to ignore the --no-index option
|
| 573 |
+
when constructing the SearchScope object.
|
| 574 |
+
"""
|
| 575 |
+
index_urls = [options.index_url] + options.extra_index_urls
|
| 576 |
+
if options.no_index and not suppress_no_index:
|
| 577 |
+
logger.debug(
|
| 578 |
+
"Ignoring indexes: %s",
|
| 579 |
+
",".join(redact_auth_from_url(url) for url in index_urls),
|
| 580 |
+
)
|
| 581 |
+
index_urls = []
|
| 582 |
+
|
| 583 |
+
# Make sure find_links is a list before passing to create().
|
| 584 |
+
find_links = options.find_links or []
|
| 585 |
+
|
| 586 |
+
search_scope = SearchScope.create(
|
| 587 |
+
find_links=find_links,
|
| 588 |
+
index_urls=index_urls,
|
| 589 |
+
)
|
| 590 |
+
link_collector = LinkCollector(
|
| 591 |
+
session=session,
|
| 592 |
+
search_scope=search_scope,
|
| 593 |
+
)
|
| 594 |
+
return link_collector
|
| 595 |
+
|
| 596 |
+
@property
|
| 597 |
+
def find_links(self) -> List[str]:
|
| 598 |
+
return self.search_scope.find_links
|
| 599 |
+
|
| 600 |
+
def fetch_page(self, location: Link) -> Optional[HTMLPage]:
|
| 601 |
+
"""
|
| 602 |
+
Fetch an HTML page containing package links.
|
| 603 |
+
"""
|
| 604 |
+
return _get_html_page(location, session=self.session)
|
| 605 |
+
|
| 606 |
+
def collect_sources(
|
| 607 |
+
self,
|
| 608 |
+
project_name: str,
|
| 609 |
+
candidates_from_page: CandidatesFromPage,
|
| 610 |
+
) -> CollectedSources:
|
| 611 |
+
# The OrderedDict calls deduplicate sources by URL.
|
| 612 |
+
index_url_sources = collections.OrderedDict(
|
| 613 |
+
build_source(
|
| 614 |
+
loc,
|
| 615 |
+
candidates_from_page=candidates_from_page,
|
| 616 |
+
page_validator=self.session.is_secure_origin,
|
| 617 |
+
expand_dir=False,
|
| 618 |
+
cache_link_parsing=False,
|
| 619 |
+
)
|
| 620 |
+
for loc in self.search_scope.get_index_urls_locations(project_name)
|
| 621 |
+
).values()
|
| 622 |
+
find_links_sources = collections.OrderedDict(
|
| 623 |
+
build_source(
|
| 624 |
+
loc,
|
| 625 |
+
candidates_from_page=candidates_from_page,
|
| 626 |
+
page_validator=self.session.is_secure_origin,
|
| 627 |
+
expand_dir=True,
|
| 628 |
+
cache_link_parsing=True,
|
| 629 |
+
)
|
| 630 |
+
for loc in self.find_links
|
| 631 |
+
).values()
|
| 632 |
+
|
| 633 |
+
if logger.isEnabledFor(logging.DEBUG):
|
| 634 |
+
lines = [
|
| 635 |
+
f"* {s.link}"
|
| 636 |
+
for s in itertools.chain(find_links_sources, index_url_sources)
|
| 637 |
+
if s is not None and s.link is not None
|
| 638 |
+
]
|
| 639 |
+
lines = [
|
| 640 |
+
f"{len(lines)} location(s) to search "
|
| 641 |
+
f"for versions of {project_name}:"
|
| 642 |
+
] + lines
|
| 643 |
+
logger.debug("\n".join(lines))
|
| 644 |
+
|
| 645 |
+
return CollectedSources(
|
| 646 |
+
find_links=list(find_links_sources),
|
| 647 |
+
index_urls=list(index_url_sources),
|
| 648 |
+
)
|
venv/lib/python3.10/site-packages/pip/_internal/index/package_finder.py
ADDED
|
@@ -0,0 +1,1004 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Routines related to PyPI, indexes"""
|
| 2 |
+
|
| 3 |
+
# The following comment should be removed at some point in the future.
|
| 4 |
+
# mypy: strict-optional=False
|
| 5 |
+
|
| 6 |
+
import functools
|
| 7 |
+
import itertools
|
| 8 |
+
import logging
|
| 9 |
+
import re
|
| 10 |
+
from typing import FrozenSet, Iterable, List, Optional, Set, Tuple, Union
|
| 11 |
+
|
| 12 |
+
from pip._vendor.packaging import specifiers
|
| 13 |
+
from pip._vendor.packaging.tags import Tag
|
| 14 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 15 |
+
from pip._vendor.packaging.version import _BaseVersion
|
| 16 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 17 |
+
|
| 18 |
+
from pip._internal.exceptions import (
|
| 19 |
+
BestVersionAlreadyInstalled,
|
| 20 |
+
DistributionNotFound,
|
| 21 |
+
InvalidWheelFilename,
|
| 22 |
+
UnsupportedWheel,
|
| 23 |
+
)
|
| 24 |
+
from pip._internal.index.collector import LinkCollector, parse_links
|
| 25 |
+
from pip._internal.models.candidate import InstallationCandidate
|
| 26 |
+
from pip._internal.models.format_control import FormatControl
|
| 27 |
+
from pip._internal.models.link import Link
|
| 28 |
+
from pip._internal.models.search_scope import SearchScope
|
| 29 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 30 |
+
from pip._internal.models.target_python import TargetPython
|
| 31 |
+
from pip._internal.models.wheel import Wheel
|
| 32 |
+
from pip._internal.req import InstallRequirement
|
| 33 |
+
from pip._internal.utils._log import getLogger
|
| 34 |
+
from pip._internal.utils.filetypes import WHEEL_EXTENSION
|
| 35 |
+
from pip._internal.utils.hashes import Hashes
|
| 36 |
+
from pip._internal.utils.logging import indent_log
|
| 37 |
+
from pip._internal.utils.misc import build_netloc
|
| 38 |
+
from pip._internal.utils.packaging import check_requires_python
|
| 39 |
+
from pip._internal.utils.unpacking import SUPPORTED_EXTENSIONS
|
| 40 |
+
|
| 41 |
+
__all__ = ["FormatControl", "BestCandidateResult", "PackageFinder"]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
logger = getLogger(__name__)
|
| 45 |
+
|
| 46 |
+
BuildTag = Union[Tuple[()], Tuple[int, str]]
|
| 47 |
+
CandidateSortingKey = Tuple[int, int, int, _BaseVersion, Optional[int], BuildTag]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _check_link_requires_python(
|
| 51 |
+
link: Link,
|
| 52 |
+
version_info: Tuple[int, int, int],
|
| 53 |
+
ignore_requires_python: bool = False,
|
| 54 |
+
) -> bool:
|
| 55 |
+
"""
|
| 56 |
+
Return whether the given Python version is compatible with a link's
|
| 57 |
+
"Requires-Python" value.
|
| 58 |
+
|
| 59 |
+
:param version_info: A 3-tuple of ints representing the Python
|
| 60 |
+
major-minor-micro version to check.
|
| 61 |
+
:param ignore_requires_python: Whether to ignore the "Requires-Python"
|
| 62 |
+
value if the given Python version isn't compatible.
|
| 63 |
+
"""
|
| 64 |
+
try:
|
| 65 |
+
is_compatible = check_requires_python(
|
| 66 |
+
link.requires_python,
|
| 67 |
+
version_info=version_info,
|
| 68 |
+
)
|
| 69 |
+
except specifiers.InvalidSpecifier:
|
| 70 |
+
logger.debug(
|
| 71 |
+
"Ignoring invalid Requires-Python (%r) for link: %s",
|
| 72 |
+
link.requires_python,
|
| 73 |
+
link,
|
| 74 |
+
)
|
| 75 |
+
else:
|
| 76 |
+
if not is_compatible:
|
| 77 |
+
version = ".".join(map(str, version_info))
|
| 78 |
+
if not ignore_requires_python:
|
| 79 |
+
logger.verbose(
|
| 80 |
+
"Link requires a different Python (%s not in: %r): %s",
|
| 81 |
+
version,
|
| 82 |
+
link.requires_python,
|
| 83 |
+
link,
|
| 84 |
+
)
|
| 85 |
+
return False
|
| 86 |
+
|
| 87 |
+
logger.debug(
|
| 88 |
+
"Ignoring failed Requires-Python check (%s not in: %r) for link: %s",
|
| 89 |
+
version,
|
| 90 |
+
link.requires_python,
|
| 91 |
+
link,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
return True
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class LinkEvaluator:
|
| 98 |
+
|
| 99 |
+
"""
|
| 100 |
+
Responsible for evaluating links for a particular project.
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
_py_version_re = re.compile(r"-py([123]\.?[0-9]?)$")
|
| 104 |
+
|
| 105 |
+
# Don't include an allow_yanked default value to make sure each call
|
| 106 |
+
# site considers whether yanked releases are allowed. This also causes
|
| 107 |
+
# that decision to be made explicit in the calling code, which helps
|
| 108 |
+
# people when reading the code.
|
| 109 |
+
def __init__(
|
| 110 |
+
self,
|
| 111 |
+
project_name: str,
|
| 112 |
+
canonical_name: str,
|
| 113 |
+
formats: FrozenSet[str],
|
| 114 |
+
target_python: TargetPython,
|
| 115 |
+
allow_yanked: bool,
|
| 116 |
+
ignore_requires_python: Optional[bool] = None,
|
| 117 |
+
) -> None:
|
| 118 |
+
"""
|
| 119 |
+
:param project_name: The user supplied package name.
|
| 120 |
+
:param canonical_name: The canonical package name.
|
| 121 |
+
:param formats: The formats allowed for this package. Should be a set
|
| 122 |
+
with 'binary' or 'source' or both in it.
|
| 123 |
+
:param target_python: The target Python interpreter to use when
|
| 124 |
+
evaluating link compatibility. This is used, for example, to
|
| 125 |
+
check wheel compatibility, as well as when checking the Python
|
| 126 |
+
version, e.g. the Python version embedded in a link filename
|
| 127 |
+
(or egg fragment) and against an HTML link's optional PEP 503
|
| 128 |
+
"data-requires-python" attribute.
|
| 129 |
+
:param allow_yanked: Whether files marked as yanked (in the sense
|
| 130 |
+
of PEP 592) are permitted to be candidates for install.
|
| 131 |
+
:param ignore_requires_python: Whether to ignore incompatible
|
| 132 |
+
PEP 503 "data-requires-python" values in HTML links. Defaults
|
| 133 |
+
to False.
|
| 134 |
+
"""
|
| 135 |
+
if ignore_requires_python is None:
|
| 136 |
+
ignore_requires_python = False
|
| 137 |
+
|
| 138 |
+
self._allow_yanked = allow_yanked
|
| 139 |
+
self._canonical_name = canonical_name
|
| 140 |
+
self._ignore_requires_python = ignore_requires_python
|
| 141 |
+
self._formats = formats
|
| 142 |
+
self._target_python = target_python
|
| 143 |
+
|
| 144 |
+
self.project_name = project_name
|
| 145 |
+
|
| 146 |
+
def evaluate_link(self, link: Link) -> Tuple[bool, Optional[str]]:
|
| 147 |
+
"""
|
| 148 |
+
Determine whether a link is a candidate for installation.
|
| 149 |
+
|
| 150 |
+
:return: A tuple (is_candidate, result), where `result` is (1) a
|
| 151 |
+
version string if `is_candidate` is True, and (2) if
|
| 152 |
+
`is_candidate` is False, an optional string to log the reason
|
| 153 |
+
the link fails to qualify.
|
| 154 |
+
"""
|
| 155 |
+
version = None
|
| 156 |
+
if link.is_yanked and not self._allow_yanked:
|
| 157 |
+
reason = link.yanked_reason or "<none given>"
|
| 158 |
+
return (False, f"yanked for reason: {reason}")
|
| 159 |
+
|
| 160 |
+
if link.egg_fragment:
|
| 161 |
+
egg_info = link.egg_fragment
|
| 162 |
+
ext = link.ext
|
| 163 |
+
else:
|
| 164 |
+
egg_info, ext = link.splitext()
|
| 165 |
+
if not ext:
|
| 166 |
+
return (False, "not a file")
|
| 167 |
+
if ext not in SUPPORTED_EXTENSIONS:
|
| 168 |
+
return (False, f"unsupported archive format: {ext}")
|
| 169 |
+
if "binary" not in self._formats and ext == WHEEL_EXTENSION:
|
| 170 |
+
reason = "No binaries permitted for {}".format(self.project_name)
|
| 171 |
+
return (False, reason)
|
| 172 |
+
if "macosx10" in link.path and ext == ".zip":
|
| 173 |
+
return (False, "macosx10 one")
|
| 174 |
+
if ext == WHEEL_EXTENSION:
|
| 175 |
+
try:
|
| 176 |
+
wheel = Wheel(link.filename)
|
| 177 |
+
except InvalidWheelFilename:
|
| 178 |
+
return (False, "invalid wheel filename")
|
| 179 |
+
if canonicalize_name(wheel.name) != self._canonical_name:
|
| 180 |
+
reason = "wrong project name (not {})".format(self.project_name)
|
| 181 |
+
return (False, reason)
|
| 182 |
+
|
| 183 |
+
supported_tags = self._target_python.get_tags()
|
| 184 |
+
if not wheel.supported(supported_tags):
|
| 185 |
+
# Include the wheel's tags in the reason string to
|
| 186 |
+
# simplify troubleshooting compatibility issues.
|
| 187 |
+
file_tags = wheel.get_formatted_file_tags()
|
| 188 |
+
reason = (
|
| 189 |
+
"none of the wheel's tags ({}) are compatible "
|
| 190 |
+
"(run pip debug --verbose to show compatible tags)".format(
|
| 191 |
+
", ".join(file_tags)
|
| 192 |
+
)
|
| 193 |
+
)
|
| 194 |
+
return (False, reason)
|
| 195 |
+
|
| 196 |
+
version = wheel.version
|
| 197 |
+
|
| 198 |
+
# This should be up by the self.ok_binary check, but see issue 2700.
|
| 199 |
+
if "source" not in self._formats and ext != WHEEL_EXTENSION:
|
| 200 |
+
reason = f"No sources permitted for {self.project_name}"
|
| 201 |
+
return (False, reason)
|
| 202 |
+
|
| 203 |
+
if not version:
|
| 204 |
+
version = _extract_version_from_fragment(
|
| 205 |
+
egg_info,
|
| 206 |
+
self._canonical_name,
|
| 207 |
+
)
|
| 208 |
+
if not version:
|
| 209 |
+
reason = f"Missing project version for {self.project_name}"
|
| 210 |
+
return (False, reason)
|
| 211 |
+
|
| 212 |
+
match = self._py_version_re.search(version)
|
| 213 |
+
if match:
|
| 214 |
+
version = version[: match.start()]
|
| 215 |
+
py_version = match.group(1)
|
| 216 |
+
if py_version != self._target_python.py_version:
|
| 217 |
+
return (False, "Python version is incorrect")
|
| 218 |
+
|
| 219 |
+
supports_python = _check_link_requires_python(
|
| 220 |
+
link,
|
| 221 |
+
version_info=self._target_python.py_version_info,
|
| 222 |
+
ignore_requires_python=self._ignore_requires_python,
|
| 223 |
+
)
|
| 224 |
+
if not supports_python:
|
| 225 |
+
# Return None for the reason text to suppress calling
|
| 226 |
+
# _log_skipped_link().
|
| 227 |
+
return (False, None)
|
| 228 |
+
|
| 229 |
+
logger.debug("Found link %s, version: %s", link, version)
|
| 230 |
+
|
| 231 |
+
return (True, version)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def filter_unallowed_hashes(
|
| 235 |
+
candidates: List[InstallationCandidate],
|
| 236 |
+
hashes: Hashes,
|
| 237 |
+
project_name: str,
|
| 238 |
+
) -> List[InstallationCandidate]:
|
| 239 |
+
"""
|
| 240 |
+
Filter out candidates whose hashes aren't allowed, and return a new
|
| 241 |
+
list of candidates.
|
| 242 |
+
|
| 243 |
+
If at least one candidate has an allowed hash, then all candidates with
|
| 244 |
+
either an allowed hash or no hash specified are returned. Otherwise,
|
| 245 |
+
the given candidates are returned.
|
| 246 |
+
|
| 247 |
+
Including the candidates with no hash specified when there is a match
|
| 248 |
+
allows a warning to be logged if there is a more preferred candidate
|
| 249 |
+
with no hash specified. Returning all candidates in the case of no
|
| 250 |
+
matches lets pip report the hash of the candidate that would otherwise
|
| 251 |
+
have been installed (e.g. permitting the user to more easily update
|
| 252 |
+
their requirements file with the desired hash).
|
| 253 |
+
"""
|
| 254 |
+
if not hashes:
|
| 255 |
+
logger.debug(
|
| 256 |
+
"Given no hashes to check %s links for project %r: "
|
| 257 |
+
"discarding no candidates",
|
| 258 |
+
len(candidates),
|
| 259 |
+
project_name,
|
| 260 |
+
)
|
| 261 |
+
# Make sure we're not returning back the given value.
|
| 262 |
+
return list(candidates)
|
| 263 |
+
|
| 264 |
+
matches_or_no_digest = []
|
| 265 |
+
# Collect the non-matches for logging purposes.
|
| 266 |
+
non_matches = []
|
| 267 |
+
match_count = 0
|
| 268 |
+
for candidate in candidates:
|
| 269 |
+
link = candidate.link
|
| 270 |
+
if not link.has_hash:
|
| 271 |
+
pass
|
| 272 |
+
elif link.is_hash_allowed(hashes=hashes):
|
| 273 |
+
match_count += 1
|
| 274 |
+
else:
|
| 275 |
+
non_matches.append(candidate)
|
| 276 |
+
continue
|
| 277 |
+
|
| 278 |
+
matches_or_no_digest.append(candidate)
|
| 279 |
+
|
| 280 |
+
if match_count:
|
| 281 |
+
filtered = matches_or_no_digest
|
| 282 |
+
else:
|
| 283 |
+
# Make sure we're not returning back the given value.
|
| 284 |
+
filtered = list(candidates)
|
| 285 |
+
|
| 286 |
+
if len(filtered) == len(candidates):
|
| 287 |
+
discard_message = "discarding no candidates"
|
| 288 |
+
else:
|
| 289 |
+
discard_message = "discarding {} non-matches:\n {}".format(
|
| 290 |
+
len(non_matches),
|
| 291 |
+
"\n ".join(str(candidate.link) for candidate in non_matches),
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
logger.debug(
|
| 295 |
+
"Checked %s links for project %r against %s hashes "
|
| 296 |
+
"(%s matches, %s no digest): %s",
|
| 297 |
+
len(candidates),
|
| 298 |
+
project_name,
|
| 299 |
+
hashes.digest_count,
|
| 300 |
+
match_count,
|
| 301 |
+
len(matches_or_no_digest) - match_count,
|
| 302 |
+
discard_message,
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
return filtered
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
class CandidatePreferences:
|
| 309 |
+
|
| 310 |
+
"""
|
| 311 |
+
Encapsulates some of the preferences for filtering and sorting
|
| 312 |
+
InstallationCandidate objects.
|
| 313 |
+
"""
|
| 314 |
+
|
| 315 |
+
def __init__(
|
| 316 |
+
self,
|
| 317 |
+
prefer_binary: bool = False,
|
| 318 |
+
allow_all_prereleases: bool = False,
|
| 319 |
+
) -> None:
|
| 320 |
+
"""
|
| 321 |
+
:param allow_all_prereleases: Whether to allow all pre-releases.
|
| 322 |
+
"""
|
| 323 |
+
self.allow_all_prereleases = allow_all_prereleases
|
| 324 |
+
self.prefer_binary = prefer_binary
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class BestCandidateResult:
|
| 328 |
+
"""A collection of candidates, returned by `PackageFinder.find_best_candidate`.
|
| 329 |
+
|
| 330 |
+
This class is only intended to be instantiated by CandidateEvaluator's
|
| 331 |
+
`compute_best_candidate()` method.
|
| 332 |
+
"""
|
| 333 |
+
|
| 334 |
+
def __init__(
|
| 335 |
+
self,
|
| 336 |
+
candidates: List[InstallationCandidate],
|
| 337 |
+
applicable_candidates: List[InstallationCandidate],
|
| 338 |
+
best_candidate: Optional[InstallationCandidate],
|
| 339 |
+
) -> None:
|
| 340 |
+
"""
|
| 341 |
+
:param candidates: A sequence of all available candidates found.
|
| 342 |
+
:param applicable_candidates: The applicable candidates.
|
| 343 |
+
:param best_candidate: The most preferred candidate found, or None
|
| 344 |
+
if no applicable candidates were found.
|
| 345 |
+
"""
|
| 346 |
+
assert set(applicable_candidates) <= set(candidates)
|
| 347 |
+
|
| 348 |
+
if best_candidate is None:
|
| 349 |
+
assert not applicable_candidates
|
| 350 |
+
else:
|
| 351 |
+
assert best_candidate in applicable_candidates
|
| 352 |
+
|
| 353 |
+
self._applicable_candidates = applicable_candidates
|
| 354 |
+
self._candidates = candidates
|
| 355 |
+
|
| 356 |
+
self.best_candidate = best_candidate
|
| 357 |
+
|
| 358 |
+
def iter_all(self) -> Iterable[InstallationCandidate]:
|
| 359 |
+
"""Iterate through all candidates."""
|
| 360 |
+
return iter(self._candidates)
|
| 361 |
+
|
| 362 |
+
def iter_applicable(self) -> Iterable[InstallationCandidate]:
|
| 363 |
+
"""Iterate through the applicable candidates."""
|
| 364 |
+
return iter(self._applicable_candidates)
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
class CandidateEvaluator:
|
| 368 |
+
|
| 369 |
+
"""
|
| 370 |
+
Responsible for filtering and sorting candidates for installation based
|
| 371 |
+
on what tags are valid.
|
| 372 |
+
"""
|
| 373 |
+
|
| 374 |
+
@classmethod
|
| 375 |
+
def create(
|
| 376 |
+
cls,
|
| 377 |
+
project_name: str,
|
| 378 |
+
target_python: Optional[TargetPython] = None,
|
| 379 |
+
prefer_binary: bool = False,
|
| 380 |
+
allow_all_prereleases: bool = False,
|
| 381 |
+
specifier: Optional[specifiers.BaseSpecifier] = None,
|
| 382 |
+
hashes: Optional[Hashes] = None,
|
| 383 |
+
) -> "CandidateEvaluator":
|
| 384 |
+
"""Create a CandidateEvaluator object.
|
| 385 |
+
|
| 386 |
+
:param target_python: The target Python interpreter to use when
|
| 387 |
+
checking compatibility. If None (the default), a TargetPython
|
| 388 |
+
object will be constructed from the running Python.
|
| 389 |
+
:param specifier: An optional object implementing `filter`
|
| 390 |
+
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
|
| 391 |
+
versions.
|
| 392 |
+
:param hashes: An optional collection of allowed hashes.
|
| 393 |
+
"""
|
| 394 |
+
if target_python is None:
|
| 395 |
+
target_python = TargetPython()
|
| 396 |
+
if specifier is None:
|
| 397 |
+
specifier = specifiers.SpecifierSet()
|
| 398 |
+
|
| 399 |
+
supported_tags = target_python.get_tags()
|
| 400 |
+
|
| 401 |
+
return cls(
|
| 402 |
+
project_name=project_name,
|
| 403 |
+
supported_tags=supported_tags,
|
| 404 |
+
specifier=specifier,
|
| 405 |
+
prefer_binary=prefer_binary,
|
| 406 |
+
allow_all_prereleases=allow_all_prereleases,
|
| 407 |
+
hashes=hashes,
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
def __init__(
|
| 411 |
+
self,
|
| 412 |
+
project_name: str,
|
| 413 |
+
supported_tags: List[Tag],
|
| 414 |
+
specifier: specifiers.BaseSpecifier,
|
| 415 |
+
prefer_binary: bool = False,
|
| 416 |
+
allow_all_prereleases: bool = False,
|
| 417 |
+
hashes: Optional[Hashes] = None,
|
| 418 |
+
) -> None:
|
| 419 |
+
"""
|
| 420 |
+
:param supported_tags: The PEP 425 tags supported by the target
|
| 421 |
+
Python in order of preference (most preferred first).
|
| 422 |
+
"""
|
| 423 |
+
self._allow_all_prereleases = allow_all_prereleases
|
| 424 |
+
self._hashes = hashes
|
| 425 |
+
self._prefer_binary = prefer_binary
|
| 426 |
+
self._project_name = project_name
|
| 427 |
+
self._specifier = specifier
|
| 428 |
+
self._supported_tags = supported_tags
|
| 429 |
+
# Since the index of the tag in the _supported_tags list is used
|
| 430 |
+
# as a priority, precompute a map from tag to index/priority to be
|
| 431 |
+
# used in wheel.find_most_preferred_tag.
|
| 432 |
+
self._wheel_tag_preferences = {
|
| 433 |
+
tag: idx for idx, tag in enumerate(supported_tags)
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
def get_applicable_candidates(
|
| 437 |
+
self,
|
| 438 |
+
candidates: List[InstallationCandidate],
|
| 439 |
+
) -> List[InstallationCandidate]:
|
| 440 |
+
"""
|
| 441 |
+
Return the applicable candidates from a list of candidates.
|
| 442 |
+
"""
|
| 443 |
+
# Using None infers from the specifier instead.
|
| 444 |
+
allow_prereleases = self._allow_all_prereleases or None
|
| 445 |
+
specifier = self._specifier
|
| 446 |
+
versions = {
|
| 447 |
+
str(v)
|
| 448 |
+
for v in specifier.filter(
|
| 449 |
+
# We turn the version object into a str here because otherwise
|
| 450 |
+
# when we're debundled but setuptools isn't, Python will see
|
| 451 |
+
# packaging.version.Version and
|
| 452 |
+
# pkg_resources._vendor.packaging.version.Version as different
|
| 453 |
+
# types. This way we'll use a str as a common data interchange
|
| 454 |
+
# format. If we stop using the pkg_resources provided specifier
|
| 455 |
+
# and start using our own, we can drop the cast to str().
|
| 456 |
+
(str(c.version) for c in candidates),
|
| 457 |
+
prereleases=allow_prereleases,
|
| 458 |
+
)
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
# Again, converting version to str to deal with debundling.
|
| 462 |
+
applicable_candidates = [c for c in candidates if str(c.version) in versions]
|
| 463 |
+
|
| 464 |
+
filtered_applicable_candidates = filter_unallowed_hashes(
|
| 465 |
+
candidates=applicable_candidates,
|
| 466 |
+
hashes=self._hashes,
|
| 467 |
+
project_name=self._project_name,
|
| 468 |
+
)
|
| 469 |
+
|
| 470 |
+
return sorted(filtered_applicable_candidates, key=self._sort_key)
|
| 471 |
+
|
| 472 |
+
def _sort_key(self, candidate: InstallationCandidate) -> CandidateSortingKey:
|
| 473 |
+
"""
|
| 474 |
+
Function to pass as the `key` argument to a call to sorted() to sort
|
| 475 |
+
InstallationCandidates by preference.
|
| 476 |
+
|
| 477 |
+
Returns a tuple such that tuples sorting as greater using Python's
|
| 478 |
+
default comparison operator are more preferred.
|
| 479 |
+
|
| 480 |
+
The preference is as follows:
|
| 481 |
+
|
| 482 |
+
First and foremost, candidates with allowed (matching) hashes are
|
| 483 |
+
always preferred over candidates without matching hashes. This is
|
| 484 |
+
because e.g. if the only candidate with an allowed hash is yanked,
|
| 485 |
+
we still want to use that candidate.
|
| 486 |
+
|
| 487 |
+
Second, excepting hash considerations, candidates that have been
|
| 488 |
+
yanked (in the sense of PEP 592) are always less preferred than
|
| 489 |
+
candidates that haven't been yanked. Then:
|
| 490 |
+
|
| 491 |
+
If not finding wheels, they are sorted by version only.
|
| 492 |
+
If finding wheels, then the sort order is by version, then:
|
| 493 |
+
1. existing installs
|
| 494 |
+
2. wheels ordered via Wheel.support_index_min(self._supported_tags)
|
| 495 |
+
3. source archives
|
| 496 |
+
If prefer_binary was set, then all wheels are sorted above sources.
|
| 497 |
+
|
| 498 |
+
Note: it was considered to embed this logic into the Link
|
| 499 |
+
comparison operators, but then different sdist links
|
| 500 |
+
with the same version, would have to be considered equal
|
| 501 |
+
"""
|
| 502 |
+
valid_tags = self._supported_tags
|
| 503 |
+
support_num = len(valid_tags)
|
| 504 |
+
build_tag: BuildTag = ()
|
| 505 |
+
binary_preference = 0
|
| 506 |
+
link = candidate.link
|
| 507 |
+
if link.is_wheel:
|
| 508 |
+
# can raise InvalidWheelFilename
|
| 509 |
+
wheel = Wheel(link.filename)
|
| 510 |
+
try:
|
| 511 |
+
pri = -(
|
| 512 |
+
wheel.find_most_preferred_tag(
|
| 513 |
+
valid_tags, self._wheel_tag_preferences
|
| 514 |
+
)
|
| 515 |
+
)
|
| 516 |
+
except ValueError:
|
| 517 |
+
raise UnsupportedWheel(
|
| 518 |
+
"{} is not a supported wheel for this platform. It "
|
| 519 |
+
"can't be sorted.".format(wheel.filename)
|
| 520 |
+
)
|
| 521 |
+
if self._prefer_binary:
|
| 522 |
+
binary_preference = 1
|
| 523 |
+
if wheel.build_tag is not None:
|
| 524 |
+
match = re.match(r"^(\d+)(.*)$", wheel.build_tag)
|
| 525 |
+
build_tag_groups = match.groups()
|
| 526 |
+
build_tag = (int(build_tag_groups[0]), build_tag_groups[1])
|
| 527 |
+
else: # sdist
|
| 528 |
+
pri = -(support_num)
|
| 529 |
+
has_allowed_hash = int(link.is_hash_allowed(self._hashes))
|
| 530 |
+
yank_value = -1 * int(link.is_yanked) # -1 for yanked.
|
| 531 |
+
return (
|
| 532 |
+
has_allowed_hash,
|
| 533 |
+
yank_value,
|
| 534 |
+
binary_preference,
|
| 535 |
+
candidate.version,
|
| 536 |
+
pri,
|
| 537 |
+
build_tag,
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
def sort_best_candidate(
|
| 541 |
+
self,
|
| 542 |
+
candidates: List[InstallationCandidate],
|
| 543 |
+
) -> Optional[InstallationCandidate]:
|
| 544 |
+
"""
|
| 545 |
+
Return the best candidate per the instance's sort order, or None if
|
| 546 |
+
no candidate is acceptable.
|
| 547 |
+
"""
|
| 548 |
+
if not candidates:
|
| 549 |
+
return None
|
| 550 |
+
best_candidate = max(candidates, key=self._sort_key)
|
| 551 |
+
return best_candidate
|
| 552 |
+
|
| 553 |
+
def compute_best_candidate(
|
| 554 |
+
self,
|
| 555 |
+
candidates: List[InstallationCandidate],
|
| 556 |
+
) -> BestCandidateResult:
|
| 557 |
+
"""
|
| 558 |
+
Compute and return a `BestCandidateResult` instance.
|
| 559 |
+
"""
|
| 560 |
+
applicable_candidates = self.get_applicable_candidates(candidates)
|
| 561 |
+
|
| 562 |
+
best_candidate = self.sort_best_candidate(applicable_candidates)
|
| 563 |
+
|
| 564 |
+
return BestCandidateResult(
|
| 565 |
+
candidates,
|
| 566 |
+
applicable_candidates=applicable_candidates,
|
| 567 |
+
best_candidate=best_candidate,
|
| 568 |
+
)
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
class PackageFinder:
|
| 572 |
+
"""This finds packages.
|
| 573 |
+
|
| 574 |
+
This is meant to match easy_install's technique for looking for
|
| 575 |
+
packages, by reading pages and looking for appropriate links.
|
| 576 |
+
"""
|
| 577 |
+
|
| 578 |
+
def __init__(
|
| 579 |
+
self,
|
| 580 |
+
link_collector: LinkCollector,
|
| 581 |
+
target_python: TargetPython,
|
| 582 |
+
allow_yanked: bool,
|
| 583 |
+
use_deprecated_html5lib: bool,
|
| 584 |
+
format_control: Optional[FormatControl] = None,
|
| 585 |
+
candidate_prefs: Optional[CandidatePreferences] = None,
|
| 586 |
+
ignore_requires_python: Optional[bool] = None,
|
| 587 |
+
) -> None:
|
| 588 |
+
"""
|
| 589 |
+
This constructor is primarily meant to be used by the create() class
|
| 590 |
+
method and from tests.
|
| 591 |
+
|
| 592 |
+
:param format_control: A FormatControl object, used to control
|
| 593 |
+
the selection of source packages / binary packages when consulting
|
| 594 |
+
the index and links.
|
| 595 |
+
:param candidate_prefs: Options to use when creating a
|
| 596 |
+
CandidateEvaluator object.
|
| 597 |
+
"""
|
| 598 |
+
if candidate_prefs is None:
|
| 599 |
+
candidate_prefs = CandidatePreferences()
|
| 600 |
+
|
| 601 |
+
format_control = format_control or FormatControl(set(), set())
|
| 602 |
+
|
| 603 |
+
self._allow_yanked = allow_yanked
|
| 604 |
+
self._candidate_prefs = candidate_prefs
|
| 605 |
+
self._ignore_requires_python = ignore_requires_python
|
| 606 |
+
self._link_collector = link_collector
|
| 607 |
+
self._target_python = target_python
|
| 608 |
+
self._use_deprecated_html5lib = use_deprecated_html5lib
|
| 609 |
+
|
| 610 |
+
self.format_control = format_control
|
| 611 |
+
|
| 612 |
+
# These are boring links that have already been logged somehow.
|
| 613 |
+
self._logged_links: Set[Link] = set()
|
| 614 |
+
|
| 615 |
+
# Don't include an allow_yanked default value to make sure each call
|
| 616 |
+
# site considers whether yanked releases are allowed. This also causes
|
| 617 |
+
# that decision to be made explicit in the calling code, which helps
|
| 618 |
+
# people when reading the code.
|
| 619 |
+
@classmethod
|
| 620 |
+
def create(
|
| 621 |
+
cls,
|
| 622 |
+
link_collector: LinkCollector,
|
| 623 |
+
selection_prefs: SelectionPreferences,
|
| 624 |
+
target_python: Optional[TargetPython] = None,
|
| 625 |
+
*,
|
| 626 |
+
use_deprecated_html5lib: bool,
|
| 627 |
+
) -> "PackageFinder":
|
| 628 |
+
"""Create a PackageFinder.
|
| 629 |
+
|
| 630 |
+
:param selection_prefs: The candidate selection preferences, as a
|
| 631 |
+
SelectionPreferences object.
|
| 632 |
+
:param target_python: The target Python interpreter to use when
|
| 633 |
+
checking compatibility. If None (the default), a TargetPython
|
| 634 |
+
object will be constructed from the running Python.
|
| 635 |
+
"""
|
| 636 |
+
if target_python is None:
|
| 637 |
+
target_python = TargetPython()
|
| 638 |
+
|
| 639 |
+
candidate_prefs = CandidatePreferences(
|
| 640 |
+
prefer_binary=selection_prefs.prefer_binary,
|
| 641 |
+
allow_all_prereleases=selection_prefs.allow_all_prereleases,
|
| 642 |
+
)
|
| 643 |
+
|
| 644 |
+
return cls(
|
| 645 |
+
candidate_prefs=candidate_prefs,
|
| 646 |
+
link_collector=link_collector,
|
| 647 |
+
target_python=target_python,
|
| 648 |
+
allow_yanked=selection_prefs.allow_yanked,
|
| 649 |
+
format_control=selection_prefs.format_control,
|
| 650 |
+
ignore_requires_python=selection_prefs.ignore_requires_python,
|
| 651 |
+
use_deprecated_html5lib=use_deprecated_html5lib,
|
| 652 |
+
)
|
| 653 |
+
|
| 654 |
+
@property
|
| 655 |
+
def target_python(self) -> TargetPython:
|
| 656 |
+
return self._target_python
|
| 657 |
+
|
| 658 |
+
@property
|
| 659 |
+
def search_scope(self) -> SearchScope:
|
| 660 |
+
return self._link_collector.search_scope
|
| 661 |
+
|
| 662 |
+
@search_scope.setter
|
| 663 |
+
def search_scope(self, search_scope: SearchScope) -> None:
|
| 664 |
+
self._link_collector.search_scope = search_scope
|
| 665 |
+
|
| 666 |
+
@property
|
| 667 |
+
def find_links(self) -> List[str]:
|
| 668 |
+
return self._link_collector.find_links
|
| 669 |
+
|
| 670 |
+
@property
|
| 671 |
+
def index_urls(self) -> List[str]:
|
| 672 |
+
return self.search_scope.index_urls
|
| 673 |
+
|
| 674 |
+
@property
|
| 675 |
+
def trusted_hosts(self) -> Iterable[str]:
|
| 676 |
+
for host_port in self._link_collector.session.pip_trusted_origins:
|
| 677 |
+
yield build_netloc(*host_port)
|
| 678 |
+
|
| 679 |
+
@property
|
| 680 |
+
def allow_all_prereleases(self) -> bool:
|
| 681 |
+
return self._candidate_prefs.allow_all_prereleases
|
| 682 |
+
|
| 683 |
+
def set_allow_all_prereleases(self) -> None:
|
| 684 |
+
self._candidate_prefs.allow_all_prereleases = True
|
| 685 |
+
|
| 686 |
+
@property
|
| 687 |
+
def prefer_binary(self) -> bool:
|
| 688 |
+
return self._candidate_prefs.prefer_binary
|
| 689 |
+
|
| 690 |
+
def set_prefer_binary(self) -> None:
|
| 691 |
+
self._candidate_prefs.prefer_binary = True
|
| 692 |
+
|
| 693 |
+
def make_link_evaluator(self, project_name: str) -> LinkEvaluator:
|
| 694 |
+
canonical_name = canonicalize_name(project_name)
|
| 695 |
+
formats = self.format_control.get_allowed_formats(canonical_name)
|
| 696 |
+
|
| 697 |
+
return LinkEvaluator(
|
| 698 |
+
project_name=project_name,
|
| 699 |
+
canonical_name=canonical_name,
|
| 700 |
+
formats=formats,
|
| 701 |
+
target_python=self._target_python,
|
| 702 |
+
allow_yanked=self._allow_yanked,
|
| 703 |
+
ignore_requires_python=self._ignore_requires_python,
|
| 704 |
+
)
|
| 705 |
+
|
| 706 |
+
def _sort_links(self, links: Iterable[Link]) -> List[Link]:
|
| 707 |
+
"""
|
| 708 |
+
Returns elements of links in order, non-egg links first, egg links
|
| 709 |
+
second, while eliminating duplicates
|
| 710 |
+
"""
|
| 711 |
+
eggs, no_eggs = [], []
|
| 712 |
+
seen: Set[Link] = set()
|
| 713 |
+
for link in links:
|
| 714 |
+
if link not in seen:
|
| 715 |
+
seen.add(link)
|
| 716 |
+
if link.egg_fragment:
|
| 717 |
+
eggs.append(link)
|
| 718 |
+
else:
|
| 719 |
+
no_eggs.append(link)
|
| 720 |
+
return no_eggs + eggs
|
| 721 |
+
|
| 722 |
+
def _log_skipped_link(self, link: Link, reason: str) -> None:
|
| 723 |
+
if link not in self._logged_links:
|
| 724 |
+
# Put the link at the end so the reason is more visible and because
|
| 725 |
+
# the link string is usually very long.
|
| 726 |
+
logger.debug("Skipping link: %s: %s", reason, link)
|
| 727 |
+
self._logged_links.add(link)
|
| 728 |
+
|
| 729 |
+
def get_install_candidate(
|
| 730 |
+
self, link_evaluator: LinkEvaluator, link: Link
|
| 731 |
+
) -> Optional[InstallationCandidate]:
|
| 732 |
+
"""
|
| 733 |
+
If the link is a candidate for install, convert it to an
|
| 734 |
+
InstallationCandidate and return it. Otherwise, return None.
|
| 735 |
+
"""
|
| 736 |
+
is_candidate, result = link_evaluator.evaluate_link(link)
|
| 737 |
+
if not is_candidate:
|
| 738 |
+
if result:
|
| 739 |
+
self._log_skipped_link(link, reason=result)
|
| 740 |
+
return None
|
| 741 |
+
|
| 742 |
+
return InstallationCandidate(
|
| 743 |
+
name=link_evaluator.project_name,
|
| 744 |
+
link=link,
|
| 745 |
+
version=result,
|
| 746 |
+
)
|
| 747 |
+
|
| 748 |
+
def evaluate_links(
|
| 749 |
+
self, link_evaluator: LinkEvaluator, links: Iterable[Link]
|
| 750 |
+
) -> List[InstallationCandidate]:
|
| 751 |
+
"""
|
| 752 |
+
Convert links that are candidates to InstallationCandidate objects.
|
| 753 |
+
"""
|
| 754 |
+
candidates = []
|
| 755 |
+
for link in self._sort_links(links):
|
| 756 |
+
candidate = self.get_install_candidate(link_evaluator, link)
|
| 757 |
+
if candidate is not None:
|
| 758 |
+
candidates.append(candidate)
|
| 759 |
+
|
| 760 |
+
return candidates
|
| 761 |
+
|
| 762 |
+
def process_project_url(
|
| 763 |
+
self, project_url: Link, link_evaluator: LinkEvaluator
|
| 764 |
+
) -> List[InstallationCandidate]:
|
| 765 |
+
logger.debug(
|
| 766 |
+
"Fetching project page and analyzing links: %s",
|
| 767 |
+
project_url,
|
| 768 |
+
)
|
| 769 |
+
html_page = self._link_collector.fetch_page(project_url)
|
| 770 |
+
if html_page is None:
|
| 771 |
+
return []
|
| 772 |
+
|
| 773 |
+
page_links = list(parse_links(html_page, self._use_deprecated_html5lib))
|
| 774 |
+
|
| 775 |
+
with indent_log():
|
| 776 |
+
package_links = self.evaluate_links(
|
| 777 |
+
link_evaluator,
|
| 778 |
+
links=page_links,
|
| 779 |
+
)
|
| 780 |
+
|
| 781 |
+
return package_links
|
| 782 |
+
|
| 783 |
+
@functools.lru_cache(maxsize=None)
|
| 784 |
+
def find_all_candidates(self, project_name: str) -> List[InstallationCandidate]:
|
| 785 |
+
"""Find all available InstallationCandidate for project_name
|
| 786 |
+
|
| 787 |
+
This checks index_urls and find_links.
|
| 788 |
+
All versions found are returned as an InstallationCandidate list.
|
| 789 |
+
|
| 790 |
+
See LinkEvaluator.evaluate_link() for details on which files
|
| 791 |
+
are accepted.
|
| 792 |
+
"""
|
| 793 |
+
link_evaluator = self.make_link_evaluator(project_name)
|
| 794 |
+
|
| 795 |
+
collected_sources = self._link_collector.collect_sources(
|
| 796 |
+
project_name=project_name,
|
| 797 |
+
candidates_from_page=functools.partial(
|
| 798 |
+
self.process_project_url,
|
| 799 |
+
link_evaluator=link_evaluator,
|
| 800 |
+
),
|
| 801 |
+
)
|
| 802 |
+
|
| 803 |
+
page_candidates_it = itertools.chain.from_iterable(
|
| 804 |
+
source.page_candidates()
|
| 805 |
+
for sources in collected_sources
|
| 806 |
+
for source in sources
|
| 807 |
+
if source is not None
|
| 808 |
+
)
|
| 809 |
+
page_candidates = list(page_candidates_it)
|
| 810 |
+
|
| 811 |
+
file_links_it = itertools.chain.from_iterable(
|
| 812 |
+
source.file_links()
|
| 813 |
+
for sources in collected_sources
|
| 814 |
+
for source in sources
|
| 815 |
+
if source is not None
|
| 816 |
+
)
|
| 817 |
+
file_candidates = self.evaluate_links(
|
| 818 |
+
link_evaluator,
|
| 819 |
+
sorted(file_links_it, reverse=True),
|
| 820 |
+
)
|
| 821 |
+
|
| 822 |
+
if logger.isEnabledFor(logging.DEBUG) and file_candidates:
|
| 823 |
+
paths = []
|
| 824 |
+
for candidate in file_candidates:
|
| 825 |
+
assert candidate.link.url # we need to have a URL
|
| 826 |
+
try:
|
| 827 |
+
paths.append(candidate.link.file_path)
|
| 828 |
+
except Exception:
|
| 829 |
+
paths.append(candidate.link.url) # it's not a local file
|
| 830 |
+
|
| 831 |
+
logger.debug("Local files found: %s", ", ".join(paths))
|
| 832 |
+
|
| 833 |
+
# This is an intentional priority ordering
|
| 834 |
+
return file_candidates + page_candidates
|
| 835 |
+
|
| 836 |
+
def make_candidate_evaluator(
|
| 837 |
+
self,
|
| 838 |
+
project_name: str,
|
| 839 |
+
specifier: Optional[specifiers.BaseSpecifier] = None,
|
| 840 |
+
hashes: Optional[Hashes] = None,
|
| 841 |
+
) -> CandidateEvaluator:
|
| 842 |
+
"""Create a CandidateEvaluator object to use."""
|
| 843 |
+
candidate_prefs = self._candidate_prefs
|
| 844 |
+
return CandidateEvaluator.create(
|
| 845 |
+
project_name=project_name,
|
| 846 |
+
target_python=self._target_python,
|
| 847 |
+
prefer_binary=candidate_prefs.prefer_binary,
|
| 848 |
+
allow_all_prereleases=candidate_prefs.allow_all_prereleases,
|
| 849 |
+
specifier=specifier,
|
| 850 |
+
hashes=hashes,
|
| 851 |
+
)
|
| 852 |
+
|
| 853 |
+
@functools.lru_cache(maxsize=None)
|
| 854 |
+
def find_best_candidate(
|
| 855 |
+
self,
|
| 856 |
+
project_name: str,
|
| 857 |
+
specifier: Optional[specifiers.BaseSpecifier] = None,
|
| 858 |
+
hashes: Optional[Hashes] = None,
|
| 859 |
+
) -> BestCandidateResult:
|
| 860 |
+
"""Find matches for the given project and specifier.
|
| 861 |
+
|
| 862 |
+
:param specifier: An optional object implementing `filter`
|
| 863 |
+
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
|
| 864 |
+
versions.
|
| 865 |
+
|
| 866 |
+
:return: A `BestCandidateResult` instance.
|
| 867 |
+
"""
|
| 868 |
+
candidates = self.find_all_candidates(project_name)
|
| 869 |
+
candidate_evaluator = self.make_candidate_evaluator(
|
| 870 |
+
project_name=project_name,
|
| 871 |
+
specifier=specifier,
|
| 872 |
+
hashes=hashes,
|
| 873 |
+
)
|
| 874 |
+
return candidate_evaluator.compute_best_candidate(candidates)
|
| 875 |
+
|
| 876 |
+
def find_requirement(
|
| 877 |
+
self, req: InstallRequirement, upgrade: bool
|
| 878 |
+
) -> Optional[InstallationCandidate]:
|
| 879 |
+
"""Try to find a Link matching req
|
| 880 |
+
|
| 881 |
+
Expects req, an InstallRequirement and upgrade, a boolean
|
| 882 |
+
Returns a InstallationCandidate if found,
|
| 883 |
+
Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise
|
| 884 |
+
"""
|
| 885 |
+
hashes = req.hashes(trust_internet=False)
|
| 886 |
+
best_candidate_result = self.find_best_candidate(
|
| 887 |
+
req.name,
|
| 888 |
+
specifier=req.specifier,
|
| 889 |
+
hashes=hashes,
|
| 890 |
+
)
|
| 891 |
+
best_candidate = best_candidate_result.best_candidate
|
| 892 |
+
|
| 893 |
+
installed_version: Optional[_BaseVersion] = None
|
| 894 |
+
if req.satisfied_by is not None:
|
| 895 |
+
installed_version = req.satisfied_by.version
|
| 896 |
+
|
| 897 |
+
def _format_versions(cand_iter: Iterable[InstallationCandidate]) -> str:
|
| 898 |
+
# This repeated parse_version and str() conversion is needed to
|
| 899 |
+
# handle different vendoring sources from pip and pkg_resources.
|
| 900 |
+
# If we stop using the pkg_resources provided specifier and start
|
| 901 |
+
# using our own, we can drop the cast to str().
|
| 902 |
+
return (
|
| 903 |
+
", ".join(
|
| 904 |
+
sorted(
|
| 905 |
+
{str(c.version) for c in cand_iter},
|
| 906 |
+
key=parse_version,
|
| 907 |
+
)
|
| 908 |
+
)
|
| 909 |
+
or "none"
|
| 910 |
+
)
|
| 911 |
+
|
| 912 |
+
if installed_version is None and best_candidate is None:
|
| 913 |
+
logger.critical(
|
| 914 |
+
"Could not find a version that satisfies the requirement %s "
|
| 915 |
+
"(from versions: %s)",
|
| 916 |
+
req,
|
| 917 |
+
_format_versions(best_candidate_result.iter_all()),
|
| 918 |
+
)
|
| 919 |
+
|
| 920 |
+
raise DistributionNotFound(
|
| 921 |
+
"No matching distribution found for {}".format(req)
|
| 922 |
+
)
|
| 923 |
+
|
| 924 |
+
best_installed = False
|
| 925 |
+
if installed_version and (
|
| 926 |
+
best_candidate is None or best_candidate.version <= installed_version
|
| 927 |
+
):
|
| 928 |
+
best_installed = True
|
| 929 |
+
|
| 930 |
+
if not upgrade and installed_version is not None:
|
| 931 |
+
if best_installed:
|
| 932 |
+
logger.debug(
|
| 933 |
+
"Existing installed version (%s) is most up-to-date and "
|
| 934 |
+
"satisfies requirement",
|
| 935 |
+
installed_version,
|
| 936 |
+
)
|
| 937 |
+
else:
|
| 938 |
+
logger.debug(
|
| 939 |
+
"Existing installed version (%s) satisfies requirement "
|
| 940 |
+
"(most up-to-date version is %s)",
|
| 941 |
+
installed_version,
|
| 942 |
+
best_candidate.version,
|
| 943 |
+
)
|
| 944 |
+
return None
|
| 945 |
+
|
| 946 |
+
if best_installed:
|
| 947 |
+
# We have an existing version, and its the best version
|
| 948 |
+
logger.debug(
|
| 949 |
+
"Installed version (%s) is most up-to-date (past versions: %s)",
|
| 950 |
+
installed_version,
|
| 951 |
+
_format_versions(best_candidate_result.iter_applicable()),
|
| 952 |
+
)
|
| 953 |
+
raise BestVersionAlreadyInstalled
|
| 954 |
+
|
| 955 |
+
logger.debug(
|
| 956 |
+
"Using version %s (newest of versions: %s)",
|
| 957 |
+
best_candidate.version,
|
| 958 |
+
_format_versions(best_candidate_result.iter_applicable()),
|
| 959 |
+
)
|
| 960 |
+
return best_candidate
|
| 961 |
+
|
| 962 |
+
|
| 963 |
+
def _find_name_version_sep(fragment: str, canonical_name: str) -> int:
|
| 964 |
+
"""Find the separator's index based on the package's canonical name.
|
| 965 |
+
|
| 966 |
+
:param fragment: A <package>+<version> filename "fragment" (stem) or
|
| 967 |
+
egg fragment.
|
| 968 |
+
:param canonical_name: The package's canonical name.
|
| 969 |
+
|
| 970 |
+
This function is needed since the canonicalized name does not necessarily
|
| 971 |
+
have the same length as the egg info's name part. An example::
|
| 972 |
+
|
| 973 |
+
>>> fragment = 'foo__bar-1.0'
|
| 974 |
+
>>> canonical_name = 'foo-bar'
|
| 975 |
+
>>> _find_name_version_sep(fragment, canonical_name)
|
| 976 |
+
8
|
| 977 |
+
"""
|
| 978 |
+
# Project name and version must be separated by one single dash. Find all
|
| 979 |
+
# occurrences of dashes; if the string in front of it matches the canonical
|
| 980 |
+
# name, this is the one separating the name and version parts.
|
| 981 |
+
for i, c in enumerate(fragment):
|
| 982 |
+
if c != "-":
|
| 983 |
+
continue
|
| 984 |
+
if canonicalize_name(fragment[:i]) == canonical_name:
|
| 985 |
+
return i
|
| 986 |
+
raise ValueError(f"{fragment} does not match {canonical_name}")
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
def _extract_version_from_fragment(fragment: str, canonical_name: str) -> Optional[str]:
|
| 990 |
+
"""Parse the version string from a <package>+<version> filename
|
| 991 |
+
"fragment" (stem) or egg fragment.
|
| 992 |
+
|
| 993 |
+
:param fragment: The string to parse. E.g. foo-2.1
|
| 994 |
+
:param canonical_name: The canonicalized name of the package this
|
| 995 |
+
belongs to.
|
| 996 |
+
"""
|
| 997 |
+
try:
|
| 998 |
+
version_start = _find_name_version_sep(fragment, canonical_name) + 1
|
| 999 |
+
except ValueError:
|
| 1000 |
+
return None
|
| 1001 |
+
version = fragment[version_start:]
|
| 1002 |
+
if not version:
|
| 1003 |
+
return None
|
| 1004 |
+
return version
|
venv/lib/python3.10/site-packages/pip/_internal/index/sources.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import mimetypes
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
from typing import Callable, Iterable, Optional, Tuple
|
| 6 |
+
|
| 7 |
+
from pip._internal.models.candidate import InstallationCandidate
|
| 8 |
+
from pip._internal.models.link import Link
|
| 9 |
+
from pip._internal.utils.urls import path_to_url, url_to_path
|
| 10 |
+
from pip._internal.vcs import is_url
|
| 11 |
+
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
FoundCandidates = Iterable[InstallationCandidate]
|
| 15 |
+
FoundLinks = Iterable[Link]
|
| 16 |
+
CandidatesFromPage = Callable[[Link], Iterable[InstallationCandidate]]
|
| 17 |
+
PageValidator = Callable[[Link], bool]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class LinkSource:
|
| 21 |
+
@property
|
| 22 |
+
def link(self) -> Optional[Link]:
|
| 23 |
+
"""Returns the underlying link, if there's one."""
|
| 24 |
+
raise NotImplementedError()
|
| 25 |
+
|
| 26 |
+
def page_candidates(self) -> FoundCandidates:
|
| 27 |
+
"""Candidates found by parsing an archive listing HTML file."""
|
| 28 |
+
raise NotImplementedError()
|
| 29 |
+
|
| 30 |
+
def file_links(self) -> FoundLinks:
|
| 31 |
+
"""Links found by specifying archives directly."""
|
| 32 |
+
raise NotImplementedError()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _is_html_file(file_url: str) -> bool:
|
| 36 |
+
return mimetypes.guess_type(file_url, strict=False)[0] == "text/html"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class _FlatDirectorySource(LinkSource):
|
| 40 |
+
"""Link source specified by ``--find-links=<path-to-dir>``.
|
| 41 |
+
|
| 42 |
+
This looks the content of the directory, and returns:
|
| 43 |
+
|
| 44 |
+
* ``page_candidates``: Links listed on each HTML file in the directory.
|
| 45 |
+
* ``file_candidates``: Archives in the directory.
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
def __init__(
|
| 49 |
+
self,
|
| 50 |
+
candidates_from_page: CandidatesFromPage,
|
| 51 |
+
path: str,
|
| 52 |
+
) -> None:
|
| 53 |
+
self._candidates_from_page = candidates_from_page
|
| 54 |
+
self._path = pathlib.Path(os.path.realpath(path))
|
| 55 |
+
|
| 56 |
+
@property
|
| 57 |
+
def link(self) -> Optional[Link]:
|
| 58 |
+
return None
|
| 59 |
+
|
| 60 |
+
def page_candidates(self) -> FoundCandidates:
|
| 61 |
+
for path in self._path.iterdir():
|
| 62 |
+
url = path_to_url(str(path))
|
| 63 |
+
if not _is_html_file(url):
|
| 64 |
+
continue
|
| 65 |
+
yield from self._candidates_from_page(Link(url))
|
| 66 |
+
|
| 67 |
+
def file_links(self) -> FoundLinks:
|
| 68 |
+
for path in self._path.iterdir():
|
| 69 |
+
url = path_to_url(str(path))
|
| 70 |
+
if _is_html_file(url):
|
| 71 |
+
continue
|
| 72 |
+
yield Link(url)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class _LocalFileSource(LinkSource):
|
| 76 |
+
"""``--find-links=<path-or-url>`` or ``--[extra-]index-url=<path-or-url>``.
|
| 77 |
+
|
| 78 |
+
If a URL is supplied, it must be a ``file:`` URL. If a path is supplied to
|
| 79 |
+
the option, it is converted to a URL first. This returns:
|
| 80 |
+
|
| 81 |
+
* ``page_candidates``: Links listed on an HTML file.
|
| 82 |
+
* ``file_candidates``: The non-HTML file.
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
def __init__(
|
| 86 |
+
self,
|
| 87 |
+
candidates_from_page: CandidatesFromPage,
|
| 88 |
+
link: Link,
|
| 89 |
+
) -> None:
|
| 90 |
+
self._candidates_from_page = candidates_from_page
|
| 91 |
+
self._link = link
|
| 92 |
+
|
| 93 |
+
@property
|
| 94 |
+
def link(self) -> Optional[Link]:
|
| 95 |
+
return self._link
|
| 96 |
+
|
| 97 |
+
def page_candidates(self) -> FoundCandidates:
|
| 98 |
+
if not _is_html_file(self._link.url):
|
| 99 |
+
return
|
| 100 |
+
yield from self._candidates_from_page(self._link)
|
| 101 |
+
|
| 102 |
+
def file_links(self) -> FoundLinks:
|
| 103 |
+
if _is_html_file(self._link.url):
|
| 104 |
+
return
|
| 105 |
+
yield self._link
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class _RemoteFileSource(LinkSource):
|
| 109 |
+
"""``--find-links=<url>`` or ``--[extra-]index-url=<url>``.
|
| 110 |
+
|
| 111 |
+
This returns:
|
| 112 |
+
|
| 113 |
+
* ``page_candidates``: Links listed on an HTML file.
|
| 114 |
+
* ``file_candidates``: The non-HTML file.
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
def __init__(
|
| 118 |
+
self,
|
| 119 |
+
candidates_from_page: CandidatesFromPage,
|
| 120 |
+
page_validator: PageValidator,
|
| 121 |
+
link: Link,
|
| 122 |
+
) -> None:
|
| 123 |
+
self._candidates_from_page = candidates_from_page
|
| 124 |
+
self._page_validator = page_validator
|
| 125 |
+
self._link = link
|
| 126 |
+
|
| 127 |
+
@property
|
| 128 |
+
def link(self) -> Optional[Link]:
|
| 129 |
+
return self._link
|
| 130 |
+
|
| 131 |
+
def page_candidates(self) -> FoundCandidates:
|
| 132 |
+
if not self._page_validator(self._link):
|
| 133 |
+
return
|
| 134 |
+
yield from self._candidates_from_page(self._link)
|
| 135 |
+
|
| 136 |
+
def file_links(self) -> FoundLinks:
|
| 137 |
+
yield self._link
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
class _IndexDirectorySource(LinkSource):
|
| 141 |
+
"""``--[extra-]index-url=<path-to-directory>``.
|
| 142 |
+
|
| 143 |
+
This is treated like a remote URL; ``candidates_from_page`` contains logic
|
| 144 |
+
for this by appending ``index.html`` to the link.
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
def __init__(
|
| 148 |
+
self,
|
| 149 |
+
candidates_from_page: CandidatesFromPage,
|
| 150 |
+
link: Link,
|
| 151 |
+
) -> None:
|
| 152 |
+
self._candidates_from_page = candidates_from_page
|
| 153 |
+
self._link = link
|
| 154 |
+
|
| 155 |
+
@property
|
| 156 |
+
def link(self) -> Optional[Link]:
|
| 157 |
+
return self._link
|
| 158 |
+
|
| 159 |
+
def page_candidates(self) -> FoundCandidates:
|
| 160 |
+
yield from self._candidates_from_page(self._link)
|
| 161 |
+
|
| 162 |
+
def file_links(self) -> FoundLinks:
|
| 163 |
+
return ()
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def build_source(
|
| 167 |
+
location: str,
|
| 168 |
+
*,
|
| 169 |
+
candidates_from_page: CandidatesFromPage,
|
| 170 |
+
page_validator: PageValidator,
|
| 171 |
+
expand_dir: bool,
|
| 172 |
+
cache_link_parsing: bool,
|
| 173 |
+
) -> Tuple[Optional[str], Optional[LinkSource]]:
|
| 174 |
+
|
| 175 |
+
path: Optional[str] = None
|
| 176 |
+
url: Optional[str] = None
|
| 177 |
+
if os.path.exists(location): # Is a local path.
|
| 178 |
+
url = path_to_url(location)
|
| 179 |
+
path = location
|
| 180 |
+
elif location.startswith("file:"): # A file: URL.
|
| 181 |
+
url = location
|
| 182 |
+
path = url_to_path(location)
|
| 183 |
+
elif is_url(location):
|
| 184 |
+
url = location
|
| 185 |
+
|
| 186 |
+
if url is None:
|
| 187 |
+
msg = (
|
| 188 |
+
"Location '%s' is ignored: "
|
| 189 |
+
"it is either a non-existing path or lacks a specific scheme."
|
| 190 |
+
)
|
| 191 |
+
logger.warning(msg, location)
|
| 192 |
+
return (None, None)
|
| 193 |
+
|
| 194 |
+
if path is None:
|
| 195 |
+
source: LinkSource = _RemoteFileSource(
|
| 196 |
+
candidates_from_page=candidates_from_page,
|
| 197 |
+
page_validator=page_validator,
|
| 198 |
+
link=Link(url, cache_link_parsing=cache_link_parsing),
|
| 199 |
+
)
|
| 200 |
+
return (url, source)
|
| 201 |
+
|
| 202 |
+
if os.path.isdir(path):
|
| 203 |
+
if expand_dir:
|
| 204 |
+
source = _FlatDirectorySource(
|
| 205 |
+
candidates_from_page=candidates_from_page,
|
| 206 |
+
path=path,
|
| 207 |
+
)
|
| 208 |
+
else:
|
| 209 |
+
source = _IndexDirectorySource(
|
| 210 |
+
candidates_from_page=candidates_from_page,
|
| 211 |
+
link=Link(url, cache_link_parsing=cache_link_parsing),
|
| 212 |
+
)
|
| 213 |
+
return (url, source)
|
| 214 |
+
elif os.path.isfile(path):
|
| 215 |
+
source = _LocalFileSource(
|
| 216 |
+
candidates_from_page=candidates_from_page,
|
| 217 |
+
link=Link(url, cache_link_parsing=cache_link_parsing),
|
| 218 |
+
)
|
| 219 |
+
return (url, source)
|
| 220 |
+
logger.warning(
|
| 221 |
+
"Location '%s' is ignored: it is neither a file nor a directory.",
|
| 222 |
+
location,
|
| 223 |
+
)
|
| 224 |
+
return (url, None)
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/index.cpython-310.pyc
ADDED
|
Binary file (1.23 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/__init__.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("html5lib")
|
| 67 |
+
vendored("six")
|
| 68 |
+
vendored("six.moves")
|
| 69 |
+
vendored("six.moves.urllib")
|
| 70 |
+
vendored("six.moves.urllib.parse")
|
| 71 |
+
vendored("packaging")
|
| 72 |
+
vendored("packaging.version")
|
| 73 |
+
vendored("packaging.specifiers")
|
| 74 |
+
vendored("pep517")
|
| 75 |
+
vendored("pkg_resources")
|
| 76 |
+
vendored("platformdirs")
|
| 77 |
+
vendored("progress")
|
| 78 |
+
vendored("requests")
|
| 79 |
+
vendored("requests.exceptions")
|
| 80 |
+
vendored("requests.packages")
|
| 81 |
+
vendored("requests.packages.urllib3")
|
| 82 |
+
vendored("requests.packages.urllib3._collections")
|
| 83 |
+
vendored("requests.packages.urllib3.connection")
|
| 84 |
+
vendored("requests.packages.urllib3.connectionpool")
|
| 85 |
+
vendored("requests.packages.urllib3.contrib")
|
| 86 |
+
vendored("requests.packages.urllib3.contrib.ntlmpool")
|
| 87 |
+
vendored("requests.packages.urllib3.contrib.pyopenssl")
|
| 88 |
+
vendored("requests.packages.urllib3.exceptions")
|
| 89 |
+
vendored("requests.packages.urllib3.fields")
|
| 90 |
+
vendored("requests.packages.urllib3.filepost")
|
| 91 |
+
vendored("requests.packages.urllib3.packages")
|
| 92 |
+
vendored("requests.packages.urllib3.packages.ordered_dict")
|
| 93 |
+
vendored("requests.packages.urllib3.packages.six")
|
| 94 |
+
vendored("requests.packages.urllib3.packages.ssl_match_hostname")
|
| 95 |
+
vendored("requests.packages.urllib3.packages.ssl_match_hostname."
|
| 96 |
+
"_implementation")
|
| 97 |
+
vendored("requests.packages.urllib3.poolmanager")
|
| 98 |
+
vendored("requests.packages.urllib3.request")
|
| 99 |
+
vendored("requests.packages.urllib3.response")
|
| 100 |
+
vendored("requests.packages.urllib3.util")
|
| 101 |
+
vendored("requests.packages.urllib3.util.connection")
|
| 102 |
+
vendored("requests.packages.urllib3.util.request")
|
| 103 |
+
vendored("requests.packages.urllib3.util.response")
|
| 104 |
+
vendored("requests.packages.urllib3.util.retry")
|
| 105 |
+
vendored("requests.packages.urllib3.util.ssl_")
|
| 106 |
+
vendored("requests.packages.urllib3.util.timeout")
|
| 107 |
+
vendored("requests.packages.urllib3.util.url")
|
| 108 |
+
vendored("resolvelib")
|
| 109 |
+
vendored("tenacity")
|
| 110 |
+
vendored("tomli")
|
| 111 |
+
vendored("urllib3")
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__init__.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# This library is free software; you can redistribute it and/or
|
| 3 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 4 |
+
# License as published by the Free Software Foundation; either
|
| 5 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 6 |
+
#
|
| 7 |
+
# This library is distributed in the hope that it will be useful,
|
| 8 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 10 |
+
# Lesser General Public License for more details.
|
| 11 |
+
#
|
| 12 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 13 |
+
# License along with this library; if not, write to the Free Software
|
| 14 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 15 |
+
# 02110-1301 USA
|
| 16 |
+
######################### END LICENSE BLOCK #########################
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
from .universaldetector import UniversalDetector
|
| 20 |
+
from .enums import InputState
|
| 21 |
+
from .version import __version__, VERSION
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
__all__ = ['UniversalDetector', 'detect', 'detect_all', '__version__', 'VERSION']
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def detect(byte_str):
|
| 28 |
+
"""
|
| 29 |
+
Detect the encoding of the given byte string.
|
| 30 |
+
|
| 31 |
+
:param byte_str: The byte sequence to examine.
|
| 32 |
+
:type byte_str: ``bytes`` or ``bytearray``
|
| 33 |
+
"""
|
| 34 |
+
if not isinstance(byte_str, bytearray):
|
| 35 |
+
if not isinstance(byte_str, bytes):
|
| 36 |
+
raise TypeError('Expected object of type bytes or bytearray, got: '
|
| 37 |
+
'{}'.format(type(byte_str)))
|
| 38 |
+
else:
|
| 39 |
+
byte_str = bytearray(byte_str)
|
| 40 |
+
detector = UniversalDetector()
|
| 41 |
+
detector.feed(byte_str)
|
| 42 |
+
return detector.close()
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def detect_all(byte_str):
|
| 46 |
+
"""
|
| 47 |
+
Detect all the possible encodings of the given byte string.
|
| 48 |
+
|
| 49 |
+
:param byte_str: The byte sequence to examine.
|
| 50 |
+
:type byte_str: ``bytes`` or ``bytearray``
|
| 51 |
+
"""
|
| 52 |
+
if not isinstance(byte_str, bytearray):
|
| 53 |
+
if not isinstance(byte_str, bytes):
|
| 54 |
+
raise TypeError('Expected object of type bytes or bytearray, got: '
|
| 55 |
+
'{}'.format(type(byte_str)))
|
| 56 |
+
else:
|
| 57 |
+
byte_str = bytearray(byte_str)
|
| 58 |
+
|
| 59 |
+
detector = UniversalDetector()
|
| 60 |
+
detector.feed(byte_str)
|
| 61 |
+
detector.close()
|
| 62 |
+
|
| 63 |
+
if detector._input_state == InputState.HIGH_BYTE:
|
| 64 |
+
results = []
|
| 65 |
+
for prober in detector._charset_probers:
|
| 66 |
+
if prober.get_confidence() > detector.MINIMUM_THRESHOLD:
|
| 67 |
+
charset_name = prober.charset_name
|
| 68 |
+
lower_charset_name = prober.charset_name.lower()
|
| 69 |
+
# Use Windows encoding name instead of ISO-8859 if we saw any
|
| 70 |
+
# extra Windows-specific bytes
|
| 71 |
+
if lower_charset_name.startswith('iso-8859'):
|
| 72 |
+
if detector._has_win_bytes:
|
| 73 |
+
charset_name = detector.ISO_WIN_MAP.get(lower_charset_name,
|
| 74 |
+
charset_name)
|
| 75 |
+
results.append({
|
| 76 |
+
'encoding': charset_name,
|
| 77 |
+
'confidence': prober.get_confidence(),
|
| 78 |
+
'language': prober.language,
|
| 79 |
+
})
|
| 80 |
+
if len(results) > 0:
|
| 81 |
+
return sorted(results, key=lambda result: -result['confidence'])
|
| 82 |
+
|
| 83 |
+
return [detector.result]
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.9 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/big5freq.cpython-310.pyc
ADDED
|
Binary file (27.2 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/big5prober.cpython-310.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/chardistribution.cpython-310.pyc
ADDED
|
Binary file (5.74 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/charsetgroupprober.cpython-310.pyc
ADDED
|
Binary file (2.23 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/charsetprober.cpython-310.pyc
ADDED
|
Binary file (3.49 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/codingstatemachine.cpython-310.pyc
ADDED
|
Binary file (2.91 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/compat.cpython-310.pyc
ADDED
|
Binary file (404 Bytes). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/cp949prober.cpython-310.pyc
ADDED
|
Binary file (1.14 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/enums.cpython-310.pyc
ADDED
|
Binary file (2.59 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/escprober.cpython-310.pyc
ADDED
|
Binary file (2.63 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/escsm.cpython-310.pyc
ADDED
|
Binary file (8.38 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/eucjpprober.cpython-310.pyc
ADDED
|
Binary file (2.44 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euckrfreq.cpython-310.pyc
ADDED
|
Binary file (12.1 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euckrprober.cpython-310.pyc
ADDED
|
Binary file (1.14 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euctwfreq.cpython-310.pyc
ADDED
|
Binary file (27.2 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/euctwprober.cpython-310.pyc
ADDED
|
Binary file (1.14 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/gb2312freq.cpython-310.pyc
ADDED
|
Binary file (19.1 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/gb2312prober.cpython-310.pyc
ADDED
|
Binary file (1.15 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/hebrewprober.cpython-310.pyc
ADDED
|
Binary file (3.02 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/jisfreq.cpython-310.pyc
ADDED
|
Binary file (22.1 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/jpcntx.cpython-310.pyc
ADDED
|
Binary file (37.6 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langbulgarianmodel.cpython-310.pyc
ADDED
|
Binary file (47.9 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langgreekmodel.cpython-310.pyc
ADDED
|
Binary file (46.1 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langhebrewmodel.cpython-310.pyc
ADDED
|
Binary file (44.6 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langhungarianmodel.cpython-310.pyc
ADDED
|
Binary file (47.9 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langrussianmodel.cpython-310.pyc
ADDED
|
Binary file (61 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langthaimodel.cpython-310.pyc
ADDED
|
Binary file (44.7 kB). View file
|
|
|
venv/lib/python3.10/site-packages/pip/_vendor/chardet/__pycache__/langturkishmodel.cpython-310.pyc
ADDED
|
Binary file (44.6 kB). View file
|
|
|