Skip to content

Commit

Permalink
Merge pull request #24 from thatch/metadata-true
Browse files Browse the repository at this point in the history
Support `data-core-metadata="true"`
  • Loading branch information
jwodder committed Feb 17, 2024
2 parents a1347d5 + 88e7734 commit bcd0cea
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/pypi_simple/classes.py
Expand Up @@ -143,11 +143,13 @@ def from_link(
has_sig = None
mddigest = link.get_str_attrib("data-core-metadata")
metadata_digests: Optional[dict[str, str]]
has_metadata = None
if mddigest is not None:
metadata_digests = {}
m = re.fullmatch(r"(\w+)=([0-9A-Fa-f]+)", mddigest)
if m:
metadata_digests[m[1]] = m[2]
has_metadata = bool(m) or mddigest.lower() == "true"
else:
metadata_digests = None
yanked_reason = link.get_str_attrib("data-yanked")
Expand All @@ -163,7 +165,7 @@ def from_link(
yanked_reason=yanked_reason,
digests=digests,
metadata_digests=metadata_digests,
has_metadata=metadata_digests is not None,
has_metadata=has_metadata,
)

@classmethod
Expand Down
34 changes: 17 additions & 17 deletions test/test_client.py
Expand Up @@ -91,7 +91,7 @@ def test_session(mocker: MockerFixture, content_type: str) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
DistributionPackage(
filename="in_place-0.1.1.tar.gz",
Expand All @@ -107,7 +107,7 @@ def test_session(mocker: MockerFixture, content_type: str) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
DistributionPackage(
filename="in_place-0.2.0-py2.py3-none-any.whl",
Expand All @@ -123,7 +123,7 @@ def test_session(mocker: MockerFixture, content_type: str) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
DistributionPackage(
filename="in_place-0.2.0.tar.gz",
Expand All @@ -139,7 +139,7 @@ def test_session(mocker: MockerFixture, content_type: str) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
DistributionPackage(
filename="in_place-0.3.0-py2.py3-none-any.whl",
Expand All @@ -155,7 +155,7 @@ def test_session(mocker: MockerFixture, content_type: str) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
DistributionPackage(
filename="in_place-0.3.0.tar.gz",
Expand All @@ -171,7 +171,7 @@ def test_session(mocker: MockerFixture, content_type: str) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
],
last_serial="54321",
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_project_hint_received() -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
DistributionPackage(
filename="aws-adfs-ebsco-0.3.7-1.tar.gz",
Expand All @@ -236,7 +236,7 @@ def test_project_hint_received() -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
],
last_serial=None,
Expand Down Expand Up @@ -296,7 +296,7 @@ def test_redirected_project_page() -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
],
last_serial=None,
Expand Down Expand Up @@ -340,7 +340,7 @@ def test_utf8_declarations(content_type: str, body_decl: bytes) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
],
last_serial=None,
Expand Down Expand Up @@ -387,7 +387,7 @@ def test_latin2_declarations(content_type: str, body_decl: bytes) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
],
last_serial=None,
Expand Down Expand Up @@ -630,7 +630,7 @@ def test_download(tmp_path: Path) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
)
dest = tmp_path / str(pkg.project) / pkg.filename
simple.download_package(pkg, dest)
Expand Down Expand Up @@ -660,7 +660,7 @@ def test_download_no_digests(tmp_path: Path) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
)
dest = tmp_path / str(pkg.project) / pkg.filename
with pytest.raises(NoDigestsError) as excinfo:
Expand Down Expand Up @@ -692,7 +692,7 @@ def test_download_bad_digests(tmp_path: Path) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
)
dest = tmp_path / str(pkg.project) / pkg.filename
with pytest.raises(DigestMismatchError) as excinfo:
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_download_bad_digests_keep(tmp_path: Path) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
)
dest = tmp_path / str(pkg.project) / pkg.filename
with pytest.raises(DigestMismatchError) as excinfo:
Expand Down Expand Up @@ -774,7 +774,7 @@ def test_download_bad_digests_no_verify(
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
)
dest = tmp_path / str(pkg.project) / pkg.filename
simple.download_package(pkg, dest, verify=False)
Expand Down Expand Up @@ -830,7 +830,7 @@ def test_download_progress(tmp_path: Path) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
)
dest = tmp_path / str(pkg.project) / pkg.filename
spy = SpyingProgressTracker()
Expand Down
4 changes: 2 additions & 2 deletions test/test_distrib_pkg.py
Expand Up @@ -84,7 +84,7 @@ def test_get_sig_url(has_sig: bool) -> None:
is_yanked=False,
yanked_reason=None,
metadata_digests=None,
has_metadata=False,
has_metadata=None,
),
),
(
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_get_sig_url(has_sig: bool) -> None:
url="https://files.pythonhosted.org/packages/82/fc/9e25534641d7f63be93079bc07fa92bab136ddf5d4181059a1308a346f96/qypi-0.1.0-py3-none-any.whl#sha256=da69d28dcd527c0e372b3fa7b92fc333b327f8470175f035abc4e351b539189f",
attrs={
"data-gpg-sig": "false",
"data-core-metadata": "sha256=true",
"data-core-metadata": "true",
},
),
DistributionPackage(
Expand Down

0 comments on commit bcd0cea

Please sign in to comment.