|
27 | 27 | from pip._internal.index.sources import _FlatDirectorySource, _IndexDirectorySource
|
28 | 28 | from pip._internal.models.candidate import InstallationCandidate
|
29 | 29 | from pip._internal.models.index import PyPI
|
30 |
| -from pip._internal.models.link import Link, _clean_link, _clean_url_path |
| 30 | +from pip._internal.models.link import Link, _clean_url_path |
31 | 31 | from pip._internal.network.session import PipSession
|
32 | 32 | from tests.lib import TestData, make_test_link_collector
|
33 | 33 | from tests.lib.path import Path
|
34 | 34 |
|
35 | 35 |
|
| 36 | +def _clean_link(url: str) -> str: |
| 37 | + """ |
| 38 | + Make sure a link is fully quoted. |
| 39 | + For example, if ' ' occurs in the URL, it will be replaced with "%20", |
| 40 | + and without double-quoting other characters. |
| 41 | + """ |
| 42 | + # Split the URL into parts according to the general structure |
| 43 | + # `scheme://netloc/path;parameters?query#fragment`. |
| 44 | + result = urllib.parse.urlparse(url) |
| 45 | + # If the netloc is empty, then the URL refers to a local filesystem path. |
| 46 | + is_local_path = not result.netloc |
| 47 | + path = _clean_url_path(result.path, is_local_path=is_local_path) |
| 48 | + return urllib.parse.urlunparse(result._replace(path=path)) |
| 49 | + |
| 50 | + |
36 | 51 | @pytest.mark.parametrize(
|
37 | 52 | "url",
|
38 | 53 | [
|
@@ -414,7 +429,7 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
|
414 | 429 | ],
|
415 | 430 | )
|
416 | 431 | def test_clean_link(url: str, clean_url: str) -> None:
|
417 |
| - assert _clean_link(Link(url)).parsed == urllib.parse.urlsplit(clean_url) |
| 432 | + assert _clean_link(url) == clean_url |
418 | 433 |
|
419 | 434 |
|
420 | 435 | def _test_parse_links_data_attribute(
|
|
0 commit comments