Coverage for meta_tags_parser/download.py: 100%
10 statements
« prev ^ index » next coverage.py v7.10.3, created at 2026-08-22 19:08 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2026-08-22 19:08 +0000
1import types
2import typing
4import httpx
7DEFAULT_REQUEST_TIMEOUT: typing.Final = 10.0
8DEFAULT_REQUEST_HEADERS: typing.Final[typing.Mapping[str, str]] = types.MappingProxyType(
9 {"user-agent": "meta-tags-parser (+https://github.com/xfenix/meta-tags-parser)"}
10)
13def download_page_sync(uri_of_page: str, *, request_timeout: float = DEFAULT_REQUEST_TIMEOUT) -> str:
14 return httpx.get(
15 uri_of_page,
16 timeout=request_timeout,
17 follow_redirects=True,
18 headers=dict(DEFAULT_REQUEST_HEADERS),
19 ).text
22async def download_page_async(uri_of_page: str, *, request_timeout: float = DEFAULT_REQUEST_TIMEOUT) -> str:
23 async with httpx.AsyncClient(
24 timeout=request_timeout,
25 follow_redirects=True,
26 headers=dict(DEFAULT_REQUEST_HEADERS),
27 ) as client:
28 return (await client.get(uri_of_page)).text