Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Hide an unimportant abstraction
  • Loading branch information
arhadthedev committed Jun 15, 2022
commit 5a9e8d86aaab522114d6e76f15a205ab998695f2
15 changes: 7 additions & 8 deletions Tools/scripts/checkhtmllinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
from urllib.response import addinfourl


def get_attribute(attribute_name: str, container: list[tuple[str, str]]):
"""Scan a list of (name, value) tuples collecting requested values."""
return (value for name, value in container if name == attribute_name)


class LinkAnalyzer(HTMLParser):
"""Scanner for hyperlink referers and targets.

Expand All @@ -44,11 +39,15 @@ def __init__(self):
self.targets = set()
self.referers = set()

@staticmethod
def _get_attribute(attribute_name: str, container: list[tuple[str, str]]):
return (value for name, value in container if name == attribute_name)

def handle_starttag(self, tag, attrs):
if tag == 'a':
self.referers.update(get_attribute('href', attrs))
self.targets.update(get_attribute('name', attrs))
self.targets.update(get_attribute('id', attrs))
self.referers.update(self._get_attribute('href', attrs))
self.targets.update(self._get_attribute('name', attrs))
self.targets.update(self._get_attribute('id', attrs))


class _NoRedirectHandler(HTTPRedirectHandler):
Expand Down