mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-24 18:05:06 +00:00
Rename HTTPClient.ratelimited to is_ratelimited and fix typing
This commit is contained in:
parent
65560956a5
commit
907d97b569
1 changed files with 7 additions and 4 deletions
|
@ -94,7 +94,7 @@ class HTTPClient:
|
||||||
_last_ping: float
|
_last_ping: float
|
||||||
_latency: float
|
_latency: float
|
||||||
|
|
||||||
def __new__(cls, **kwargs) -> Awaitable[Self]:
|
def __new__(cls, **kwargs) -> Awaitable[HTTPClient]:
|
||||||
# Basically async def __init__
|
# Basically async def __init__
|
||||||
return cls.__async_init(**kwargs)
|
return cls.__async_init(**kwargs)
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class HTTPClient:
|
||||||
async def on_request_start(
|
async def on_request_start(
|
||||||
_: ClientSession, __: SimpleNamespace, params: TraceRequestStartParams
|
_: ClientSession, __: SimpleNamespace, params: TraceRequestStartParams
|
||||||
) -> None:
|
) -> None:
|
||||||
if self.ratelimited:
|
if self.is_ratelimited:
|
||||||
log.info(
|
log.info(
|
||||||
"Ratelimit exceeded, trying again in"
|
"Ratelimit exceeded, trying again in"
|
||||||
f" {human_readable_time_until(self._rates.reset_time - datetime.now(timezone.utc))} (URL:"
|
f" {human_readable_time_until(self._rates.reset_time - datetime.now(timezone.utc))} (URL:"
|
||||||
|
@ -174,8 +174,11 @@ class HTTPClient:
|
||||||
async def __aexit__(self, *_) -> None:
|
async def __aexit__(self, *_) -> None:
|
||||||
await self.__session.close()
|
await self.__session.close()
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"<{self.__class__.__name__}>"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ratelimited(self) -> bool:
|
def is_ratelimited(self) -> bool:
|
||||||
remaining = self._rates.remaining
|
remaining = self._rates.remaining
|
||||||
return remaining is not None and remaining < 2
|
return remaining is not None and remaining < 2
|
||||||
|
|
||||||
|
@ -185,7 +188,7 @@ class HTTPClient:
|
||||||
last_ping = self._last_ping
|
last_ping = self._last_ping
|
||||||
|
|
||||||
# If there was no ping or the last ping was more than 5 seconds ago.
|
# If there was no ping or the last ping was more than 5 seconds ago.
|
||||||
if not last_ping or time.monotonic() > last_ping + 5 or self.ratelimited:
|
if not last_ping or time.monotonic() > last_ping + 5 or self.is_ratelimited:
|
||||||
self._last_ping = time.monotonic()
|
self._last_ping = time.monotonic()
|
||||||
|
|
||||||
start = time.monotonic()
|
start = time.monotonic()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue