Files
AioHTTPX/src/aiohttpx/client.py

69 lines
2.1 KiB
Python

from collections.abc import Callable, Mapping
from logging import getLogger
from ssl import SSLContext
from typing import Any, TypeVar
from httpx import URL, Limits
from httpx import AsyncClient as AsyncHTTPXClient
from httpx import _config as c # type: ignore
from httpx import _types as t # type: ignore
from aiohttpx.transports.cache import AsyncCacheTransport
K = TypeVar('K')
class AioHTTPXClient(AsyncHTTPXClient):
def __init__(
self,
*,
auth: t.AuthTypes | None = None,
params: t.QueryParamTypes | None = None,
headers: t.HeaderTypes | None = None,
cookies: t.CookieTypes | None = None,
verify: SSLContext | str | bool = True,
cert: t.CertTypes | None = None,
proxy: t.ProxyTypes | None = None,
timeout: t.TimeoutTypes = c.DEFAULT_TIMEOUT_CONFIG,
follow_redirects: bool = False,
limits: Limits = c.DEFAULT_LIMITS,
max_redirects: int = c.DEFAULT_MAX_REDIRECTS,
event_hooks: Mapping[str, list[Callable[..., Any]]] | None = None,
base_url: URL | str = '',
trust_env: bool = True,
default_encoding: str | Callable[[bytes], str] = 'utf-8',
redis_url: str | None = None,
key: str | None = None,
limit: int | None = None,
logger: str | None = __name__,
) -> None:
super().__init__(
auth=auth,
params=params,
headers=headers,
cookies=cookies,
verify=verify,
cert=cert,
http1=True,
http2=False,
proxy=proxy,
mounts=None,
timeout=timeout,
follow_redirects=follow_redirects,
limits=limits,
max_redirects=max_redirects,
event_hooks=event_hooks,
base_url=base_url,
transport=AsyncCacheTransport(redis_url, key, limit),
trust_env=trust_env,
default_encoding=default_encoding,
)
self.logger = getLogger(logger)
def clean_dict[K, V](self, params: dict[K, Any | None]):
return {k: v for k, v in params.items() if v is not None}
__all__ = ['AioHTTPXClient']