mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-22 23:02:19 +01:00
The installer ships as the steam_installer package beside steam_backlog_enforcer, with its tests, docs and Proton lock. The enforcer's fast install now starts the installer from this checkout. Both appinfo.vdf readers share one key-value decoder (steam_installer.appinfo_kv), and the duplicated test fixtures and helpers are folded into conftest and _cli_helpers so the whole-tree duplicate-code check is clean. check_requirements_sync treats sibling packages as first-party. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
27 lines
910 B
Python
27 lines
910 B
Python
"""One https-only way to open a URL, shared by the network callers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import contextlib
|
|
from typing import TYPE_CHECKING
|
|
import urllib.request
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Iterator
|
|
from http.client import HTTPResponse
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def open_https(
|
|
url: str, *, timeout: float, user_agent: str | None = None
|
|
) -> Iterator[HTTPResponse]:
|
|
"""Open `url` (https only) with `user_agent`; a context manager."""
|
|
if not url.startswith("https://"):
|
|
msg = f"refusing a non-https URL: {url}"
|
|
raise ValueError(msg)
|
|
# No header when none is given: urllib then sends its own default agent.
|
|
headers = {} if user_agent is None else {"User-Agent": user_agent}
|
|
request = urllib.request.Request(url, headers=headers)
|
|
with urllib.request.urlopen(request, timeout=timeout) as response:
|
|
yield response
|