diff --git a/dank_mids/helpers/_session.py b/dank_mids/helpers/_session.py index bde344c6..2f57470e 100644 --- a/dank_mids/helpers/_session.py +++ b/dank_mids/helpers/_session.py @@ -9,8 +9,7 @@ from typing import Any, Callable, List, Optional, overload import msgspec -from aiohttp import ClientSession as DefaultClientSession -from aiohttp import ClientTimeout, TCPConnector +from aiohttp import ClientSession, ClientTimeout, TCPConnector from aiohttp.client_exceptions import ClientResponseError from aiohttp.typedefs import DEFAULT_JSON_DECODER, JSONDecoder from aiolimiter import AsyncLimiter @@ -83,10 +82,10 @@ async def post(endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DECODER, session = await get_session() return await session.post(endpoint, *args, loads=loads, **kwargs) -async def get_session() -> "ClientSession": +async def get_session() -> "DankClientSession": return await _get_session_for_thread(get_ident()) -class ClientSession(DefaultClientSession): +class DankClientSession(ClientSession): async def post(self, endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DECODER, _retry_after: float = 1, **kwargs) -> bytes: # type: ignore [override] # Process input arguments. if isinstance(kwargs.get('data'), PartialRequest): @@ -129,12 +128,12 @@ async def post(self, endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DEC tried += 1 @alru_cache(maxsize=None) -async def _get_session_for_thread(thread_ident: int) -> ClientSession: +async def _get_session_for_thread(thread_ident: int) -> DankClientSession: """ This makes our ClientSession threadsafe just in case. Most everything should be run in main thread though. """ - return ClientSession( + return DankClientSession( connector = TCPConnector(limit=32), headers = {'content-type': 'application/json'}, timeout = ClientTimeout(ENVIRONMENT_VARIABLES.AIOHTTP_TIMEOUT), # type: ignore [arg-type, attr-defined] @@ -142,4 +141,4 @@ async def _get_session_for_thread(thread_ident: int) -> ClientSession: read_bufsize=2**20, # 1mb ) -_limited: List[ClientSession] = [] \ No newline at end of file +_limited: List[DankClientSession] = [] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 686b2cb4..0a367107 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dank-mids" -version = "4.20.94" +version = "4.20.95" description = "Multicall batching middleware for asynchronous scripts using web3.py" authors = ["BobTheBuidler "] homepage = "https://github.com/BobTheBuidler/dank_mids"