PaiGram/utils/patch/aiohttp.py
洛水居室 233e7ab58d
♻️ PaiGram V4
Co-authored-by: luoshuijs <luoshuijs@outlook.com>
Co-authored-by: Karako <karakohear@gmail.com>
Co-authored-by: xtaodada <xtao@xtaolink.cn>
2023-03-14 09:27:22 +08:00

22 lines
510 B
Python

import asyncio
from typing import Optional
import aiohttp # pylint: disable=W0406
from aiohttp import ClientError
from utils.patch.methods import patch, patchable
class AioHttpTimeoutException(ClientError):
pass
@patch(aiohttp.helpers.TimerContext)
class TimerContext:
@patchable
def __exit__(self, *args, **kwargs) -> Optional[bool]:
try:
return self.old___exit__(*args, **kwargs)
except asyncio.TimeoutError:
raise AioHttpTimeoutException from None