(
self,
params: QueryTypes = None,
headers: HeaderTypes = None,
cookies: CookieTypes = None,
version: str | HTTPVersion = HTTPVersion.H11,
timeout: TimeoutTypes | UnsetType = UNSET,
proxy: str | None = None,
)
| 60 | class Session(HTTPClientSession): |
| 61 | @override |
| 62 | def __init__( |
| 63 | self, |
| 64 | params: QueryTypes = None, |
| 65 | headers: HeaderTypes = None, |
| 66 | cookies: CookieTypes = None, |
| 67 | version: str | HTTPVersion = HTTPVersion.H11, |
| 68 | timeout: TimeoutTypes | UnsetType = UNSET, |
| 69 | proxy: str | None = None, |
| 70 | ): |
| 71 | self._client: aiohttp.ClientSession | None = None |
| 72 | |
| 73 | self._params = URL.build(query=params).query if params is not None else None |
| 74 | |
| 75 | self._headers = CIMultiDict(headers) if headers is not None else None |
| 76 | self._cookies = tuple( |
| 77 | (cookie.name, cookie.value) |
| 78 | for cookie in Cookies(cookies) |
| 79 | if cookie.value is not None |
| 80 | ) |
| 81 | |
| 82 | version = HTTPVersion(version) |
| 83 | if version == HTTPVersion.H10: |
| 84 | self._version = aiohttp.HttpVersion10 |
| 85 | elif version == HTTPVersion.H11: |
| 86 | self._version = aiohttp.HttpVersion11 |
| 87 | else: |
| 88 | raise RuntimeError(f"Unsupported HTTP version: {version}") |
| 89 | |
| 90 | _timeout = None |
| 91 | if isinstance(timeout, Timeout): |
| 92 | timeout_kwargs: dict[str, float | None] = exclude_unset( |
| 93 | { |
| 94 | "total": timeout.total, |
| 95 | "connect": timeout.connect, |
| 96 | "sock_read": timeout.read, |
| 97 | } |
| 98 | ) |
| 99 | if timeout_kwargs: |
| 100 | _timeout = aiohttp.ClientTimeout(**timeout_kwargs) # type: ignore |
| 101 | elif timeout is not UNSET: |
| 102 | _timeout = aiohttp.ClientTimeout(connect=timeout, sock_read=timeout) |
| 103 | |
| 104 | if _timeout is None: |
| 105 | _timeout = aiohttp.ClientTimeout( |
| 106 | **exclude_unset( |
| 107 | { |
| 108 | "total": DEFAULT_TIMEOUT.total, |
| 109 | "connect": DEFAULT_TIMEOUT.connect, |
| 110 | "sock_read": DEFAULT_TIMEOUT.read, |
| 111 | } |
| 112 | ) |
| 113 | ) |
| 114 | |
| 115 | self._timeout = _timeout |
| 116 | self._proxy = proxy |
| 117 | |
| 118 | @property |
| 119 | def client(self) -> aiohttp.ClientSession: |
no test coverage detected