Skip to content

Commit

Permalink
Properly yield results from html5lib parsing
Browse files Browse the repository at this point in the history
The earlier variant _returned_ an iterable object from a generator. This
did not properly handle the fallback, resulting in the html5lib code
path not being executed.
  • Loading branch information
pradyunsg committed Jan 30, 2022
1 parent 6cc96c2 commit ad0f754
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/10846.bugfix.rst
@@ -0,0 +1 @@
Restore equivalence with earlier version of pip, in `--use-deprecated=html5lib`.
3 changes: 2 additions & 1 deletion src/pip/_internal/index/collector.py
Expand Up @@ -343,7 +343,8 @@ def parse_links(page: "HTMLPage", use_deprecated_html5lib: bool) -> Iterable[Lin
Parse an HTML document, and yield its anchor elements as Link objects.
"""
if use_deprecated_html5lib:
return _parse_links_html5lib(page)
yield from _parse_links_html5lib(page)
return

parser = HTMLLinkParser()
encoding = page.encoding or "utf-8"
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_collector.py
Expand Up @@ -2,6 +2,7 @@
import logging
import os.path
import re
import textwrap
import urllib.request
import uuid
from textwrap import dedent
Expand Down Expand Up @@ -539,6 +540,18 @@ def test_parse_links_caches_same_page_by_url() -> None:
assert "pkg2" in parsed_links_3[0].url


def test_parse_link_handles_deprecated_usage_properly() -> None:
html = b'<a href="/pkg1-1.0.tar.gz"><a href="/pkg1-2.0.tar.gz">'
url = "https://example.com/simple/"
page = HTMLPage(html, encoding=None, url=url)

parsed_links = list(parse_links(page, use_deprecated_html5lib=True))

assert len(parsed_links) == 2
assert "pkg1-1.0" in parsed_links[0].url
assert "pkg1-2.0" in parsed_links[1].url


@mock.patch("pip._internal.index.collector.raise_for_status")
def test_request_http_error(
mock_raise_for_status: mock.Mock, caplog: pytest.LogCaptureFixture
Expand Down

0 comments on commit ad0f754

Please sign in to comment.