...
 
Commits (37)
    https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/6c3db098ff0b6e537157eff53b1aba79fa7fa4b0 Fix parsing of JSON index dist-info-metadata values 2023-06-07T20:58:40+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/cc554edab8897749c87495333018754080d06781 Add a news file 2023-06-07T21:01:10+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/8f89997d0dad1644b258297e2e3b9cc70d44e51d Fix types to be 3.7-compatible 2023-06-07T21:11:34+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/cfb4923d5d016dc58dc4e4b896992c476f0ddce8 Fix bad test data in test_parse_links_json 2023-06-07T21:21:32+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/93b274eee79b9c114728f0864a29751ee7698fca Missed a change to one of the tests 2023-06-07T21:44:48+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/232cc9dd5284fbc7554bcd291bf14e31413da78a Parse hash data before passing to MetadataFile 2023-06-08T10:09:09+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/5168881b438b2851ae4c9459a8c06beee2058639 Implement PEP 714 - rename dist-info-metadata 2023-06-08T10:10:15+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/7e3f74f16dcd4bc02f24ca6628056bfd633ac418 Merge branch 'main' into core_metadata 2023-06-08T14:22:42+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/67deaf7576a9aa14f37bd6ebef5bdce038069b60 Add permission check before configuration 2023-06-14T22:36:15+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/19b41050efdcb2b8e74c16fded3064abb96f95fa Add permission check before configuration 2023-06-14T23:00:03+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/dafca3f7e3985ce2f2351d168efbd91fa5b2f4b2 Add permission check before configuration 2023-06-15T19:11:20+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/f77661e478d3169e43fd2ba540a0c9778e924a45 Add permission check before configuration 2023-06-15T19:35:46+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/090ad5cf315f547a2ec94d4ddc76ad7e4ddc96f1 Merge branch 'main' into main 2023-06-16T21:31:30+08:00 JasonMo 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/f74650725b7fa57a5b17f2b839624fa36622ba7e Add permission check before configuration 2023-06-17T11:23:10+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/920bcd0c631be649317b5a1e00019ad029353d5c Add permission check before configuration 2023-06-17T11:23:10+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/2dbda58efc6bfd0b9115626d294ab95b11712e9a Add permission check before configuration 2023-06-17T11:23:10+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/17147b8fd36a851da7897da26eef8f68aec364a0 Add permission check before configuration 2023-06-17T11:23:10+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/5986dd27c5797245c70daf922f89bddc16ee656e Add permission check before configuration 2023-06-17T11:23:10+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/05fe41747425162634531930cb6551f0b700975f Add permission check before configuration5 2023-06-17T11:39:30+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/05e936aecb6427403c6a99dcbcefa63514b98425 Add permission check before configuration7 2023-06-17T12:16:25+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/8747268d44250b164957f3a7671bd30ef9f250c7 Add permission check before configuration8 2023-06-17T12:30:36+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/81c8a3ffbca1aca2c7bfae1433d0dd52050fc9b3 Add permission check before configuration9 2023-06-17T12:42:47+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/c57bad63da242068f74e1eb96c97c3bc800b7f88 Add permission check before configuration10 2023-06-22T11:27:48+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/c4709d2b2251528647e19be0d0f8ea83d1011e24 Add permission check before configuration11 2023-06-22T11:31:43+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/7572dbc09581c139199496adc57fefb9f404a6b2 Add IO check before save configuration1 2023-06-22T12:03:58+08:00 JasonMo1 111677135+JasonMo1@users.noreply.github.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/97cc6a4c604afbebf726bacf4b20897c24c206ca Merge branch 'main' into core_metadata 2023-06-27T10:17:59+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/a0976d8832f52c2f14472f7b20b1cf1776a63ac8 Fix lint issues 2023-06-27T14:47:09+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/c7daa07f6a65c73173f623c1be34ed2956628715 Reword the check for no hashes 2023-06-27T14:47:39+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/a934f38ff7bab9fdd70646afb3796a51bbe34822 Merge branch 'main' into core_metadata 2023-06-27T15:42:42+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/778b42ff81c00e914a397eb8ed56d516e00509db Merge pull request #12078 from pfmoore/core_metadata 2023-06-27T21:50:53+01:00 Paul Moore p.f.moore@gmail.com Fix parsing of JSON index dist-info-metadata values https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/26953e695f028afb6d38074dc61ce5828a6b2c07 Merge branch 'main' into main 2023-06-28T17:12:50+08:00 Tzu-ping Chung uranusjr@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/6507734aac0f3c0972aef5097b8d0b4defb791f8 Fix string formatting 2023-06-29T16:51:11+08:00 Tzu-ping Chung uranusjr@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/41f138e43a6c54804b7c7fe3d4a8477508ef4a97 Minimize changeset 2023-06-29T16:51:34+08:00 Tzu-ping Chung uranusjr@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/256af8f6912799ebf66b2ebc6707aae2e0487fe1 Catch OSError instead of IOError 2023-06-29T17:28:16+08:00 Tzu-ping Chung uranusjr@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/21440081bf9c01ebcb538e0dded0a6dca7583af0 Merge pull request #12089 from JasonMo1/main 2023-06-30T13:40:27+08:00 Tzu-ping Chung uranusjr@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/5d0c2773b8bf0cc569c82e6d3697fe7b89c71192 Stop using a RAM disk for the Windows tests 2023-06-30T16:17:16+01:00 Paul Moore p.f.moore@gmail.com https://gitcode.net/awesome-mirrors/pypa/pip/-/commit/4ac0d3d4a1dfeaa35d5f57739d3edfb47863d807 Merge pull request #12115 from pfmoore/ramdisk_test 2023-06-30T20:39:36+01:00 Paul Moore p.f.moore@gmail.com Stop using a RAM disk for the Windows tests
......@@ -167,24 +167,13 @@ jobs:
with:
python-version: ${{ matrix.python }}
# We use a RAMDisk on Windows, since filesystem IO is a big slowdown
# for our tests.
- name: Create a RAMDisk
run: ./tools/ci/New-RAMDisk.ps1 -Drive R -Size 1GB
- name: Setup RAMDisk permissions
run: |
mkdir R:\Temp
$acl = Get-Acl "R:\Temp"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
"Everyone", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow"
)
$acl.AddAccessRule($rule)
Set-Acl "R:\Temp" $acl
# We use C:\Temp (which is already available on the worker)
# as a temporary directory for all of the tests because the
# default value (under the user dir) is more deeply nested
# and causes tests to fail with "path too long" errors.
- run: pip install nox
env:
TEMP: "R:\\Temp"
TEMP: "C:\\Temp"
# Main check
- name: Run unit tests
......@@ -194,7 +183,7 @@ jobs:
-m unit
--verbose --numprocesses auto --showlocals
env:
TEMP: "R:\\Temp"
TEMP: "C:\\Temp"
- name: Run integration tests (group 1)
if: matrix.group == 1
......@@ -203,7 +192,7 @@ jobs:
-m integration -k "not test_install"
--verbose --numprocesses auto --showlocals
env:
TEMP: "R:\\Temp"
TEMP: "C:\\Temp"
- name: Run integration tests (group 2)
if: matrix.group == 2
......@@ -212,7 +201,7 @@ jobs:
-m integration -k "test_install"
--verbose --numprocesses auto --showlocals
env:
TEMP: "R:\\Temp"
TEMP: "C:\\Temp"
tests-zipapp:
name: tests / zipapp
......
Add permission check before configuration
Correctly parse ``dist-info-metadata`` values from JSON-format index data.
......@@ -210,8 +210,15 @@ class Configuration:
# Ensure directory exists.
ensure_dir(os.path.dirname(fname))
with open(fname, "w") as f:
parser.write(f)
# Ensure directory's permission(need to be writeable)
try:
with open(fname, "w") as f:
parser.write(f)
except OSError as error:
raise ConfigurationError(
f"An error occurred while writing to the configuration file "
f"{fname}: {error}"
)
#
# Private routines
......
......@@ -69,18 +69,6 @@ class LinkHash:
def __post_init__(self) -> None:
assert self.name in _SUPPORTED_HASHES
@classmethod
def parse_pep658_hash(cls, dist_info_metadata: str) -> Optional["LinkHash"]:
"""Parse a PEP 658 data-dist-info-metadata hash."""
if dist_info_metadata == "true":
return None
name, sep, value = dist_info_metadata.partition("=")
if not sep:
return None
if name not in _SUPPORTED_HASHES:
return None
return cls(name=name, value=value)
@classmethod
@functools.lru_cache(maxsize=None)
def find_hash_url_fragment(cls, url: str) -> Optional["LinkHash"]:
......@@ -107,6 +95,28 @@ class LinkHash:
return hashes.is_hash_allowed(self.name, hex_digest=self.value)
@dataclass(frozen=True)
class MetadataFile:
"""Information about a core metadata file associated with a distribution."""
hashes: Optional[Dict[str, str]]
def __post_init__(self) -> None:
if self.hashes is not None:
assert all(name in _SUPPORTED_HASHES for name in self.hashes)
def supported_hashes(hashes: Optional[Dict[str, str]]) -> Optional[Dict[str, str]]:
# Remove any unsupported hash types from the mapping. If this leaves no
# supported hashes, return None
if hashes is None:
return None
hashes = {n: v for n, v in hashes.items() if n in _SUPPORTED_HASHES}
if not hashes:
return None
return hashes
def _clean_url_path_part(part: str) -> str:
"""
Clean a "part" of a URL path (i.e. after splitting on "@" characters).
......@@ -179,7 +189,7 @@ class Link(KeyBasedCompareMixin):
"comes_from",
"requires_python",
"yanked_reason",
"dist_info_metadata",
"metadata_file_data",
"cache_link_parsing",
"egg_fragment",
]
......@@ -190,7 +200,7 @@ class Link(KeyBasedCompareMixin):
comes_from: Optional[Union[str, "IndexContent"]] = None,
requires_python: Optional[str] = None,
yanked_reason: Optional[str] = None,
dist_info_metadata: Optional[str] = None,
metadata_file_data: Optional[MetadataFile] = None,
cache_link_parsing: bool = True,
hashes: Optional[Mapping[str, str]] = None,
) -> None:
......@@ -208,11 +218,10 @@ class Link(KeyBasedCompareMixin):
a simple repository HTML link. If the file has been yanked but
no reason was provided, this should be the empty string. See
PEP 592 for more information and the specification.
:param dist_info_metadata: the metadata attached to the file, or None if no such
metadata is provided. This is the value of the "data-dist-info-metadata"
attribute, if present, in a simple repository HTML link. This may be parsed
into its own `Link` by `self.metadata_link()`. See PEP 658 for more
information and the specification.
:param metadata_file_data: the metadata attached to the file, or None if
no such metadata is provided. This argument, if not None, indicates
that a separate metadata file exists, and also optionally supplies
hashes for that file.
:param cache_link_parsing: A flag that is used elsewhere to determine
whether resources retrieved from this link should be cached. PyPI
URLs should generally have this set to False, for example.
......@@ -220,6 +229,10 @@ class Link(KeyBasedCompareMixin):
determine the validity of a download.
"""
# The comes_from, requires_python, and metadata_file_data arguments are
# only used by classmethods of this class, and are not used in client
# code directly.
# url can be a UNC windows share
if url.startswith("\\\\"):
url = path_to_url(url)
......@@ -239,7 +252,7 @@ class Link(KeyBasedCompareMixin):
self.comes_from = comes_from
self.requires_python = requires_python if requires_python else None
self.yanked_reason = yanked_reason
self.dist_info_metadata = dist_info_metadata
self.metadata_file_data = metadata_file_data
super().__init__(key=url, defining_class=Link)
......@@ -262,9 +275,25 @@ class Link(KeyBasedCompareMixin):
url = _ensure_quoted_url(urllib.parse.urljoin(page_url, file_url))
pyrequire = file_data.get("requires-python")
yanked_reason = file_data.get("yanked")
dist_info_metadata = file_data.get("dist-info-metadata")
hashes = file_data.get("hashes", {})
# PEP 714: Indexes must use the name core-metadata, but
# clients should support the old name as a fallback for compatibility.
metadata_info = file_data.get("core-metadata")
if metadata_info is None:
metadata_info = file_data.get("dist-info-metadata")
# The metadata info value may be a boolean, or a dict of hashes.
if isinstance(metadata_info, dict):
# The file exists, and hashes have been supplied
metadata_file_data = MetadataFile(supported_hashes(metadata_info))
elif metadata_info:
# The file exists, but there are no hashes
metadata_file_data = MetadataFile(None)
else:
# False or not present: the file does not exist
metadata_file_data = None
# The Link.yanked_reason expects an empty string instead of a boolean.
if yanked_reason and not isinstance(yanked_reason, str):
yanked_reason = ""
......@@ -278,7 +307,7 @@ class Link(KeyBasedCompareMixin):
requires_python=pyrequire,
yanked_reason=yanked_reason,
hashes=hashes,
dist_info_metadata=dist_info_metadata,
metadata_file_data=metadata_file_data,
)
@classmethod
......@@ -298,14 +327,39 @@ class Link(KeyBasedCompareMixin):
url = _ensure_quoted_url(urllib.parse.urljoin(base_url, href))
pyrequire = anchor_attribs.get("data-requires-python")
yanked_reason = anchor_attribs.get("data-yanked")
dist_info_metadata = anchor_attribs.get("data-dist-info-metadata")
# PEP 714: Indexes must use the name data-core-metadata, but
# clients should support the old name as a fallback for compatibility.
metadata_info = anchor_attribs.get("data-core-metadata")
if metadata_info is None:
metadata_info = anchor_attribs.get("data-dist-info-metadata")
# The metadata info value may be the string "true", or a string of
# the form "hashname=hashval"
if metadata_info == "true":
# The file exists, but there are no hashes
metadata_file_data = MetadataFile(None)
elif metadata_info is None:
# The file does not exist
metadata_file_data = None
else:
# The file exists, and hashes have been supplied
hashname, sep, hashval = metadata_info.partition("=")
if sep == "=":
metadata_file_data = MetadataFile(supported_hashes({hashname: hashval}))
else:
# Error - data is wrong. Treat as no hashes supplied.
logger.debug(
"Index returned invalid data-dist-info-metadata value: %s",
metadata_info,
)
metadata_file_data = MetadataFile(None)
return cls(
url,
comes_from=page_url,
requires_python=pyrequire,
yanked_reason=yanked_reason,
dist_info_metadata=dist_info_metadata,
metadata_file_data=metadata_file_data,
)
def __str__(self) -> str:
......@@ -407,17 +461,13 @@ class Link(KeyBasedCompareMixin):
return match.group(1)
def metadata_link(self) -> Optional["Link"]:
"""Implementation of PEP 658 parsing."""
# Note that Link.from_element() parsing the "data-dist-info-metadata" attribute
# from an HTML anchor tag is typically how the Link.dist_info_metadata attribute
# gets set.
if self.dist_info_metadata is None:
"""Return a link to the associated core metadata file (if any)."""
if self.metadata_file_data is None:
return None
metadata_url = f"{self.url_without_fragment}.metadata"
metadata_link_hash = LinkHash.parse_pep658_hash(self.dist_info_metadata)
if metadata_link_hash is None:
if self.metadata_file_data.hashes is None:
return Link(metadata_url)
return Link(metadata_url, hashes=metadata_link_hash.as_dict())
return Link(metadata_url, hashes=self.metadata_file_data.hashes)
def as_hashes(self) -> Hashes:
return Hashes({k: [v] for k, v in self._hashes.items()})
......
......@@ -30,6 +30,7 @@ from pip._internal.models.index import PyPI
from pip._internal.models.link import (
Link,
LinkHash,
MetadataFile,
_clean_url_path,
_ensure_quoted_url,
)
......@@ -485,13 +486,30 @@ def test_parse_links_json() -> None:
"requires-python": ">=3.7",
"dist-info-metadata": False,
},
# Same as above, but parsing dist-info-metadata.
# Same as above, but parsing core-metadata.
{
"filename": "holygrail-1.0-py3-none-any.whl",
"url": "/files/holygrail-1.0-py3-none-any.whl",
"hashes": {"sha256": "sha256 hash", "blake2b": "blake2b hash"},
"requires-python": ">=3.7",
"dist-info-metadata": "sha512=aabdd41",
"core-metadata": {"sha512": "aabdd41"},
},
# Ensure fallback to dist-info-metadata works
{
"filename": "holygrail-1.0-py3-none-any.whl",
"url": "/files/holygrail-1.0-py3-none-any.whl",
"hashes": {"sha256": "sha256 hash", "blake2b": "blake2b hash"},
"requires-python": ">=3.7",
"dist-info-metadata": {"sha512": "aabdd41"},
},
# Ensure that core-metadata gets priority.
{
"filename": "holygrail-1.0-py3-none-any.whl",
"url": "/files/holygrail-1.0-py3-none-any.whl",
"hashes": {"sha256": "sha256 hash", "blake2b": "blake2b hash"},
"requires-python": ">=3.7",
"core-metadata": {"sha512": "aabdd41"},
"dist-info-metadata": {"sha512": "this_is_wrong"},
},
],
}
......@@ -527,7 +545,23 @@ def test_parse_links_json() -> None:
requires_python=">=3.7",
yanked_reason=None,
hashes={"sha256": "sha256 hash", "blake2b": "blake2b hash"},
dist_info_metadata="sha512=aabdd41",
metadata_file_data=MetadataFile({"sha512": "aabdd41"}),
),
Link(
"https://example.com/files/holygrail-1.0-py3-none-any.whl",
comes_from=page.url,
requires_python=">=3.7",
yanked_reason=None,
hashes={"sha256": "sha256 hash", "blake2b": "blake2b hash"},
metadata_file_data=MetadataFile({"sha512": "aabdd41"}),
),
Link(
"https://example.com/files/holygrail-1.0-py3-none-any.whl",
comes_from=page.url,
requires_python=">=3.7",
yanked_reason=None,
hashes={"sha256": "sha256 hash", "blake2b": "blake2b hash"},
metadata_file_data=MetadataFile({"sha512": "aabdd41"}),
),
]
......@@ -585,30 +619,42 @@ _pkg1_requirement = Requirement("pkg1==1.0")
),
# Test with value "true".
(
'<a href="/pkg1-1.0.tar.gz" data-dist-info-metadata="true"></a>',
"true",
'<a href="/pkg1-1.0.tar.gz" data-core-metadata="true"></a>',
MetadataFile(None),
{},
),
# Test with a provided hash value.
(
'<a href="/pkg1-1.0.tar.gz" data-dist-info-metadata="sha256=aa113592bbe"></a>', # noqa: E501
"sha256=aa113592bbe",
'<a href="/pkg1-1.0.tar.gz" data-core-metadata="sha256=aa113592bbe"></a>', # noqa: E501
MetadataFile({"sha256": "aa113592bbe"}),
{},
),
# Test with a provided hash value for both the requirement as well as metadata.
(
'<a href="/pkg1-1.0.tar.gz#sha512=abc132409cb" data-dist-info-metadata="sha256=aa113592bbe"></a>', # noqa: E501
"sha256=aa113592bbe",
'<a href="/pkg1-1.0.tar.gz#sha512=abc132409cb" data-core-metadata="sha256=aa113592bbe"></a>', # noqa: E501
MetadataFile({"sha256": "aa113592bbe"}),
{"sha512": "abc132409cb"},
),
# Ensure the fallback to the old name works.
(
'<a href="/pkg1-1.0.tar.gz" data-dist-info-metadata="sha256=aa113592bbe"></a>', # noqa: E501
MetadataFile({"sha256": "aa113592bbe"}),
{},
),
# Ensure that the data-core-metadata name gets priority.
(
'<a href="/pkg1-1.0.tar.gz" data-core-metadata="sha256=aa113592bbe" data-dist-info-metadata="sha256=invalid_value"></a>', # noqa: E501
MetadataFile({"sha256": "aa113592bbe"}),
{},
),
],
)
def test_parse_links__dist_info_metadata(
def test_parse_links__metadata_file_data(
anchor_html: str,
expected: Optional[str],
hashes: Dict[str, str],
) -> None:
link = _test_parse_links_data_attribute(anchor_html, "dist_info_metadata", expected)
link = _test_parse_links_data_attribute(anchor_html, "metadata_file_data", expected)
assert link._hashes == hashes
......@@ -1080,17 +1126,26 @@ def test_link_hash_parsing(url: str, result: Optional[LinkHash]) -> None:
@pytest.mark.parametrize(
"dist_info_metadata, result",
"metadata_attrib, expected",
[
("sha256=aa113592bbe", LinkHash("sha256", "aa113592bbe")),
("sha256=", LinkHash("sha256", "")),
("sha500=aa113592bbe", None),
("true", None),
("", None),
("aa113592bbe", None),
("sha256=aa113592bbe", MetadataFile({"sha256": "aa113592bbe"})),
("sha256=", MetadataFile({"sha256": ""})),
("sha500=aa113592bbe", MetadataFile(None)),
("true", MetadataFile(None)),
(None, None),
# Attribute is present but invalid
("", MetadataFile(None)),
("aa113592bbe", MetadataFile(None)),
],
)
def test_pep658_hash_parsing(
dist_info_metadata: str, result: Optional[LinkHash]
def test_metadata_file_info_parsing_html(
metadata_attrib: str, expected: Optional[MetadataFile]
) -> None:
assert LinkHash.parse_pep658_hash(dist_info_metadata) == result
attribs: Dict[str, Optional[str]] = {
"href": "something",
"data-dist-info-metadata": metadata_attrib,
}
page_url = "dummy_for_comes_from"
base_url = "https://index.url/simple"
link = Link.from_element(attribs, page_url, base_url)
assert link is not None and link.metadata_file_data == expected