From 63b3dff737c66510e00077c13e59aa5db0ea0ceb Mon Sep 17 00:00:00 2001 From: 201st-Luka Date: Tue, 22 Aug 2023 17:54:40 +0200 Subject: [PATCH 1/4] fix: removed non async support for `Client` some tests where influenced by this change and got changes as well --- pyclasher/client.py | 149 ++++++------------ tests/requests/async_tests/__init__.py | 0 tests/requests/{async_tests => }/conftest.py | 4 +- tests/requests/{async_tests => }/test_clan.py | 2 +- .../{async_tests => }/test_goldpass.py | 0 .../requests/{async_tests => }/test_labels.py | 0 .../{async_tests => }/test_locations.py | 0 .../requests/{async_tests => }/test_player.py | 2 +- tests/test_client.py | 9 +- 9 files changed, 54 insertions(+), 112 deletions(-) delete mode 100644 tests/requests/async_tests/__init__.py rename tests/requests/{async_tests => }/conftest.py (84%) rename tests/requests/{async_tests => }/test_clan.py (99%) rename tests/requests/{async_tests => }/test_goldpass.py (100%) rename tests/requests/{async_tests => }/test_labels.py (100%) rename tests/requests/{async_tests => }/test_locations.py (100%) rename tests/requests/{async_tests => }/test_player.py (98%) diff --git a/pyclasher/client.py b/pyclasher/client.py index 8b432f1..184a18c 100644 --- a/pyclasher/client.py +++ b/pyclasher/client.py @@ -13,16 +13,9 @@ class Client: base_url = "https://api.clashofclans.com" endpoint = "/v1" - queue = None requests_per_second = 5 logger = MISSING initialised = False - __loop = MISSING - __consumers = None - __consume_tasks = None - __temporary_session = False - __tokens = None - __client_running = False def __new__(cls, *args, **kwargs): if cls.__instance is None: @@ -60,48 +53,41 @@ def __init__( self.logger.debug("pyclasher client initialised") self.queue = PcQueue() - self.__loop = new_event_loop() self.request_timeout = request_timeout Client.initialised = True + self.__client_running = False + self.__temporary_session = False + self.__consumers = None + self.__consume_tasks = None + return @classmethod - def from_login(cls, email, password, requests_per_second=5, request_timeout=30, logger=MISSING, login_count=1): + async def from_login(cls, email, password, requests_per_second=5, + request_timeout=30, logger=MISSING, login_count=1): if logger is None: logger = MISSING - async def from_async_login(): - logins = [await Login(email, password).login() for _ in range(login_count)] + logins = [ + await Login(email, password).login() for _ in range(login_count) + ] - logger.info("initialising pyclasher client via login") + logger.info("initialising pyclasher client via login") - self = cls([login.temporary_api_token for login in logins], - requests_per_second, - request_timeout, - swagger_url=logins[0].swagger_url) - self.logger = logger - self.__temporary_session = True - return self - - try: - get_running_loop() - except RuntimeError: - return run(from_async_login()) - else: - return from_async_login() + self = cls([login.temporary_api_token for login in logins], + requests_per_second, + request_timeout, + swagger_url=logins[0].swagger_url) + self.logger = logger + self.__temporary_session = True + return self @property def is_running(self) -> bool: return self.__client_running - def start(self, tokens=None): - async def async_consumer_start(tokens_): - self.__consumers = [PcConsumer(self.queue, token, self.requests_per_second, self.request_timeout, self.base_url) for token in tokens_] - self.__consume_tasks = [create_task(consumer.consume()) for consumer in self.__consumers] - self.logger.debug("pyclasher client started") - return self - + async def start(self, tokens=None): if tokens is None: tokens = self.__tokens @@ -121,55 +107,38 @@ async def async_consumer_start(tokens_): self.__client_running = True self.logger.info("starting pychlasher client") - try: - get_running_loop() - except RuntimeError: - return self.__loop.run_until_complete(async_consumer_start(tokens)) - else: - self.__consumers = [ - PcConsumer( - self.queue, token, self.requests_per_second, self.request_timeout, self.base_url) - for token in tokens - ] - self.__consume_tasks = [create_task(consumer.consume()) for consumer in self.__consumers] - self.logger.debug("pyclasher client started") - return self - - def close(self): - async def async_close(): - self.logger.info("closing pyclasher client") - if not self.__client_running: - self.logger.error("the client is not running") - raise ClientIsNotRunning - else: - self.__client_running = False - - for task in self.__consume_tasks: - task.cancel() - self.__consume_tasks = None - for consumer in self.__consumers: - await consumer.close() - self.__consumers = None - - self.logger.debug("pyclasher client closed") - return self - - try: - get_running_loop() - except RuntimeError: - return self.__loop.run_until_complete(async_close()) + self.__consumers = [ + PcConsumer(self.queue, token, self.requests_per_second, + self.request_timeout, self.base_url) + for token in tokens + ] + self.__consume_tasks = [ + create_task(consumer.consume()) for consumer in self.__consumers + ] + self.logger.debug("pyclasher client started") + + return self + + async def close(self): + self.logger.info("closing pyclasher client") + if not self.__client_running: + self.logger.error("the client is not running") + raise ClientIsNotRunning else: - return async_close() + self.__client_running = False - def __enter__(self): - return self.start() + for task in self.__consume_tasks: + task.cancel() + self.__consume_tasks = None + for consumer in self.__consumers: + await consumer.close() + self.__consumers = None - def __exit__(self, exc_type, exc_val, exc_tb): - self.close() - return + self.logger.debug("pyclasher client closed") + return self async def __aenter__(self): - return self.start() + return await self.start() async def __aexit__(self, exc_type, exc_val, exc_tb): await self.close() @@ -183,30 +152,4 @@ def __del__(self): self.close() self.logger.warning("The client was still running, closed now.") - self.__loop.stop() - self.__loop.close() - return - - @property - def loop(self): - return self.__loop - - def reset_client(self, reset_queue=True, reset_loop=True, reset_tokens=True): - if not self.is_running: - if reset_queue: - del self.queue - self.queue = PcQueue() - - if reset_loop: - self.__loop.stop() - self.__loop.close() - del self.__loop - self.__loop = new_event_loop() - - if reset_tokens: - self.__tokens = None - - return - else: - raise ClientIsRunning diff --git a/tests/requests/async_tests/__init__.py b/tests/requests/async_tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/requests/async_tests/conftest.py b/tests/requests/conftest.py similarity index 84% rename from tests/requests/async_tests/conftest.py rename to tests/requests/conftest.py index 2a4ed7f..7242af8 100644 --- a/tests/requests/async_tests/conftest.py +++ b/tests/requests/conftest.py @@ -4,7 +4,7 @@ from pyclasher import Client -from ...constants import CLASH_OF_CLANS_LOGIN_EMAIL, CLASH_OF_CLANS_LOGIN_PASSWORD +from constants import CLASH_OF_CLANS_LOGIN_EMAIL, CLASH_OF_CLANS_LOGIN_PASSWORD @pytest.fixture(scope="package") @@ -22,7 +22,7 @@ def event_loop(): async def pyclasher_client(event_loop): print("Setting PyClasherClient ...") client = await Client.from_login(CLASH_OF_CLANS_LOGIN_EMAIL, CLASH_OF_CLANS_LOGIN_PASSWORD) - client.start() + await client.start() yield client diff --git a/tests/requests/async_tests/test_clan.py b/tests/requests/test_clan.py similarity index 99% rename from tests/requests/async_tests/test_clan.py rename to tests/requests/test_clan.py index d521919..5ef6a12 100644 --- a/tests/requests/async_tests/test_clan.py +++ b/tests/requests/test_clan.py @@ -9,7 +9,7 @@ ClanCapitalRaidSeasons, ClanCapitalRaidSeasonMemberList, ClanCapitalRaidSeasonAttackLogList, ClanCapitalRaidSeasonDefenseLogList) -from ...constants import TEST_CLAN_TAG, TEST_CLAN_NAME +from constants import TEST_CLAN_TAG, TEST_CLAN_NAME @pytest.mark.asyncio diff --git a/tests/requests/async_tests/test_goldpass.py b/tests/requests/test_goldpass.py similarity index 100% rename from tests/requests/async_tests/test_goldpass.py rename to tests/requests/test_goldpass.py diff --git a/tests/requests/async_tests/test_labels.py b/tests/requests/test_labels.py similarity index 100% rename from tests/requests/async_tests/test_labels.py rename to tests/requests/test_labels.py diff --git a/tests/requests/async_tests/test_locations.py b/tests/requests/test_locations.py similarity index 100% rename from tests/requests/async_tests/test_locations.py rename to tests/requests/test_locations.py diff --git a/tests/requests/async_tests/test_player.py b/tests/requests/test_player.py similarity index 98% rename from tests/requests/async_tests/test_player.py rename to tests/requests/test_player.py index add732d..785519e 100644 --- a/tests/requests/async_tests/test_player.py +++ b/tests/requests/test_player.py @@ -4,7 +4,7 @@ from pyclasher.api.models import (ClanRole, PlayerHouse, PlayerClan, PlayerAchievementProgressList, BuilderBaseLeague, PlayerItemLevelList, LabelList, League, PlayerLegendStatistics, WarPreference) -from ...constants import TEST_PLAYER_TAG +from constants import TEST_PLAYER_TAG @pytest.mark.asyncio diff --git a/tests/test_client.py b/tests/test_client.py index 9953b6e..4edbe4d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,6 +1,6 @@ import pytest -from asyncio import Queue, AbstractEventLoop +from asyncio import Queue from pyclasher import Client @@ -11,16 +11,16 @@ async def test_client(): assert not Client.initialised - client = await Client.from_login(CLASH_OF_CLANS_LOGIN_EMAIL, CLASH_OF_CLANS_LOGIN_PASSWORD) + client = await Client.from_login(CLASH_OF_CLANS_LOGIN_EMAIL, + CLASH_OF_CLANS_LOGIN_PASSWORD) assert Client.initialised assert not client.is_running assert isinstance(client.queue, Queue) - client.start() + await client.start() assert client.is_running - assert isinstance(client.loop, AbstractEventLoop) await client.close() @@ -29,6 +29,5 @@ async def test_client(): async with client: assert client.is_running - assert isinstance(client.loop, AbstractEventLoop) assert not client.is_running From 79e14398354f09391873611bb37c1c8e9640b676 Mon Sep 17 00:00:00 2001 From: 201st-Luka Date: Tue, 22 Aug 2023 18:49:25 +0200 Subject: [PATCH 2/4] fix: removed async support for request models --- .../requests/{request_models.py => abc.py} | 116 ++++++++++-------- .../requests/{request_models.pyi => abc.pyi} | 51 ++++---- 2 files changed, 90 insertions(+), 77 deletions(-) rename pyclasher/api/requests/{request_models.py => abc.py} (63%) rename pyclasher/api/requests/{request_models.pyi => abc.pyi} (61%) diff --git a/pyclasher/api/requests/request_models.py b/pyclasher/api/requests/abc.py similarity index 63% rename from pyclasher/api/requests/request_models.py rename to pyclasher/api/requests/abc.py index c140b8c..d2922c9 100644 --- a/pyclasher/api/requests/request_models.py +++ b/pyclasher/api/requests/abc.py @@ -1,4 +1,4 @@ -from asyncio import Future, get_running_loop +from asyncio import Future from typing import Any from urllib.parse import quote, urlencode @@ -21,7 +21,11 @@ class for requesting _url_kwargs = None _len = None - def __init__(self, raw_url, kwargs=None, request_method=RequestMethods.REQUEST, **url_kwargs): + def __init__(self, + raw_url, + kwargs=None, + request_method=RequestMethods.REQUEST, + **url_kwargs): """ sets up all parameters for a request :param raw_url: the url of the request @@ -34,8 +38,7 @@ def __init__(self, raw_url, kwargs=None, request_method=RequestMethods.REQUEST, global request_id self._request_id = request_id - self.client = Client() - self.client.logger.info(f"request {self._request_id} initialised") + self.client = None self._url = raw_url.format(**url_kwargs) self.request_method = request_method @@ -54,25 +57,45 @@ def to_dict(self): def __make_request_url(self): """ method that returns the request url + :return request_url: full request url :rtype: str """ - - self.client.logger.debug(f"making request url for request {self._request_id}") - request_url = "/".join((self.client.endpoint, quote(self._url))) if self._url_kwargs is not None: - url_args = {key: value for key, value in self._url_kwargs.items() if value is not None} + url_args = { + key: value + for key, value in self._url_kwargs.items() + if value is not None + } if url_args != {}: request_url = f"{request_url}?{urlencode(url_args)}" - self.client.logger.debug(f"url for request {self._request_id} is {request_url}") return request_url - async def _async_request(self): + def __get_properties(self): + return { + name: prop.__get__(self) + for name, prop in vars(self.__class__).items() + if isinstance(prop, property) + } + + def _get_data(self, item): + if self._data is None: + return None + if self._data is MISSING: + raise RequestNotDone + if item in self._data: + return self._data[item] + else: + return MISSING + + async def request(self): """ makes a request to the ClashOfClans API """ + self.client = Client() + if not self.client.is_running: raise ClientIsNotRunning @@ -80,9 +103,16 @@ async def _async_request(self): self.client.logger.debug(f"requesting {self._request_id}") - await self.client.queue.put(future, self.__make_request_url(), self.request_method, None, status, error) + await self.client.queue.put( + future, self.__make_request_url(), + self.request_method, None, + status, + error + ) - self._data, req_status, req_error = await future, await status, await error + self._data, req_status, req_error = (await future, + await status, + await error) if req_status != 200: raise req_error.value @@ -90,62 +120,42 @@ async def _async_request(self): self.client.logger.debug(f"request {self._request_id} done") return self - def __get_properties(self): - return {name: prop.__get__(self) for name, prop in vars(self.__class__).items() if isinstance(prop, property)} - - def _get_data(self, item): - if self._data is None: - return None - if self._data is MISSING: - raise RequestNotDone - if item in self._data: - return self._data[item] - else: - return MISSING - - def request(self): - try: - get_running_loop() - except RuntimeError: - return self.client.loop.run_until_complete(self._async_request()) - else: - return self._async_request() - async def __aenter__(self): - return await self._async_request() + return await self.request() async def __aexit__(self, exc_type, exc_val, exc_tb): return - def __enter__(self): - return self.request() - - def __exit__(self, exc_type, exc_val, exc_tb): - return - def __repr__(self): - if self.__class__.__name__ == "RequestModel": - return f"RequestModel(url={self._url}, url_kwargs={self._url_kwargs})" - else: - return f"{self.__class__.__name__}({', '.join(('='.join((key, str(value))) for key, value in self.__get_properties().items()))})" + props = ', '.join(( + '='.join((key, str(value))) + for key, value in self.__get_properties().items()) + ) + return f"{self.__class__.__name__}({props})" def __str__(self): - if self.__class__.__name__ == "RequestModel": - return f"RequestModel({self.__make_request_url()})" - else: - main_attr = ",".join(self._main_attribute) if isinstance(self._main_attribute, (list, tuple)) else self._main_attribute - return f"{self.__class__.__name__}({main_attr})" + return f"{self.__class__.__name__}()" class IterRequestModel(RequestModel): _iter_rtype: Any = ... _list_rtype: Any = ... - _len = None - async def _async_request(self): - await super()._async_request() + def __init__(self, + raw_url, + kwargs=None, + request_method=RequestMethods.REQUEST, + **url_kwargs): + super().__init__(raw_url, + kwargs=kwargs, + request_method=request_method, + **url_kwargs) + self._len = None + return + + async def request(self): + await super().request() self._len = len(self._get_data('items')) - self._main_attribute = self._len return self @property diff --git a/pyclasher/api/requests/request_models.pyi b/pyclasher/api/requests/abc.pyi similarity index 61% rename from pyclasher/api/requests/request_models.pyi rename to pyclasher/api/requests/abc.pyi index 3da530f..1179366 100644 --- a/pyclasher/api/requests/request_models.pyi +++ b/pyclasher/api/requests/abc.pyi @@ -1,29 +1,33 @@ +from abc import ABC +from logging import Logger from typing import Any, Coroutine, Iterator, Generator from ..models import Paging -from ...client import PyClasherClient, RequestMethods +from ...client import RequestMethods, Client from ...exceptions import MISSING, Missing request_id: int = 0 -class RequestModel: +class RequestModel(ABC): _data: dict = MISSING _main_attribute: Any = None _url: str = None _url_kwargs: dict | None = None _len: int = None - def __init__(self, raw_url: str, kwargs: dict = None, request_method: RequestMethods = RequestMethods.REQUEST, **url_kwargs) -> None: - global request_id - - self._request_id = request_id - self.client = PyClasherClient() - self.client.logger.info(f"request {self._request_id} initialised") - - self._url = raw_url.format(**url_kwargs) - self.request_method = request_method - self._url_kwargs = kwargs + def __init__( + self, + raw_url: str, + kwargs: dict = None, + request_method: RequestMethods = RequestMethods.REQUEST, + **url_kwargs + ) -> None: + self._request_id = ... + self.client: Client | None = ... + self._url: str = ... + self.request_method: RequestMethods = ... + self._url_kwargs: dict = kwargs ... def to_dict(self) -> None | Missing | dict: @@ -32,16 +36,13 @@ class RequestModel: def __make_request_url(self) -> str: ... - async def _async_request(self) -> RequestModel: - ... - def __get_properties(self) -> dict: ... def _get_data(self, item) -> dict: ... - def request(self) -> RequestModel | Coroutine[Any, Any, RequestModel]: + async def request(self) -> RequestModel: ... async def __aenter__(self): @@ -50,12 +51,6 @@ class RequestModel: async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: ... - def __enter__(self): - ... - - def __exit__(self, exc_type, exc_val, exc_tb) -> None: - ... - def __repr__(self) -> str: ... @@ -63,10 +58,18 @@ class RequestModel: ... -class IterRequestModel(RequestModel): +class IterRequestModel(RequestModel, ABC): _iter_rtype: Any = ... _list_rtype: Any = ... - _len = None + + def __init__( + self, + raw_url: str, + kwargs: dict = None, + request_method: RequestMethods = RequestMethods.REQUEST, + **url_kwargs + ) -> None: + self._len: None | int = ... async def _async_request(self) -> IterRequestModel: ... From 2caded9fa2936242ca64e4c910b90a2289848bf5 Mon Sep 17 00:00:00 2001 From: 201st-Luka Date: Tue, 22 Aug 2023 18:49:53 +0200 Subject: [PATCH 3/4] refactor: file name changes renamed request_models to abc --- pyclasher/api/requests/__init__.py | 2 +- pyclasher/api/requests/builder_base_league.py | 2 +- .../api/requests/builder_base_league.pyi | 2 +- .../api/requests/builder_base_leagues.py | 2 +- .../api/requests/builder_base_leagues.pyi | 2 +- pyclasher/api/requests/capital_league.py | 2 +- pyclasher/api/requests/capital_league.pyi | 2 +- .../api/requests/capital_league_seasons.py | 2 +- .../api/requests/capital_league_seasons.pyi | 2 +- pyclasher/api/requests/clan.py | 2 +- pyclasher/api/requests/clan.pyi | 2 +- .../requests/clan_builder_base_rankings.py | 2 +- .../requests/clan_builder_base_rankings.pyi | 2 +- .../api/requests/clan_capital_raid_seasons.py | 2 +- .../requests/clan_capital_raid_seasons.pyi | 2 +- pyclasher/api/requests/clan_current_war.py | 2 +- pyclasher/api/requests/clan_current_war.pyi | 2 +- pyclasher/api/requests/clan_labels.py | 2 +- pyclasher/api/requests/clan_labels.pyi | 2 +- pyclasher/api/requests/clan_members.py | 2 +- pyclasher/api/requests/clan_members.pyi | 2 +- pyclasher/api/requests/clan_rankings.py | 2 +- pyclasher/api/requests/clan_rankings.pyi | 2 +- pyclasher/api/requests/clan_search.py | 2 +- pyclasher/api/requests/clan_search.pyi | 2 +- pyclasher/api/requests/clan_war_log.py | 2 +- pyclasher/api/requests/clan_war_log.pyi | 2 +- pyclasher/api/requests/gold_pass.py | 2 +- pyclasher/api/requests/gold_pass.pyi | 2 +- pyclasher/api/requests/league.py | 2 +- pyclasher/api/requests/league.pyi | 2 +- pyclasher/api/requests/league_season.py | 2 +- pyclasher/api/requests/league_season.pyi | 2 +- pyclasher/api/requests/leagues.py | 2 +- pyclasher/api/requests/leagues.pyi | 2 +- pyclasher/api/requests/location.py | 2 +- pyclasher/api/requests/location.pyi | 2 +- pyclasher/api/requests/locations.py | 2 +- pyclasher/api/requests/locations.pyi | 2 +- pyclasher/api/requests/player.py | 2 +- pyclasher/api/requests/player.pyi | 2 +- .../requests/player_builder_base_rankings.py | 2 +- .../requests/player_builder_base_rankings.pyi | 2 +- pyclasher/api/requests/player_labels.py | 2 +- pyclasher/api/requests/player_labels.pyi | 2 +- pyclasher/api/requests/player_rankings.py | 2 +- pyclasher/api/requests/player_rankings.pyi | 2 +- pyclasher/api/requests/war_league.py | 2 +- pyclasher/api/requests/war_league.pyi | 2 +- pyclasher/api/requests/war_leagues.py | 2 +- pyclasher/api/requests/war_leagues.pyi | 2 +- pyclasher/client.py | 10 +- pyclasher/client.pyi | 122 +++++++----------- 53 files changed, 105 insertions(+), 129 deletions(-) diff --git a/pyclasher/api/requests/__init__.py b/pyclasher/api/requests/__init__.py index d8f1a2d..00cbffd 100644 --- a/pyclasher/api/requests/__init__.py +++ b/pyclasher/api/requests/__init__.py @@ -31,6 +31,6 @@ # labels from .player_labels import PlayerLabelsRequest from .player_rankings import PlayerRankingsRequest -from .request_models import RequestModel, IterRequestModel, request_id +from .abc import RequestModel, IterRequestModel, request_id from .war_league import WarLeagueRequest from .war_leagues import WarLeaguesRequest diff --git a/pyclasher/api/requests/builder_base_league.py b/pyclasher/api/requests/builder_base_league.py index 8c36c3a..089d0fd 100644 --- a/pyclasher/api/requests/builder_base_league.py +++ b/pyclasher/api/requests/builder_base_league.py @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import BuilderBaseLeague diff --git a/pyclasher/api/requests/builder_base_league.pyi b/pyclasher/api/requests/builder_base_league.pyi index 7989284..c858ea4 100644 --- a/pyclasher/api/requests/builder_base_league.pyi +++ b/pyclasher/api/requests/builder_base_league.pyi @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import BuilderBaseLeague diff --git a/pyclasher/api/requests/builder_base_leagues.py b/pyclasher/api/requests/builder_base_leagues.py index 3de8b97..187de10 100644 --- a/pyclasher/api/requests/builder_base_leagues.py +++ b/pyclasher/api/requests/builder_base_leagues.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import BuilderBaseLeagueList, BuilderBaseLeague diff --git a/pyclasher/api/requests/builder_base_leagues.pyi b/pyclasher/api/requests/builder_base_leagues.pyi index e651f97..1f60f46 100644 --- a/pyclasher/api/requests/builder_base_leagues.pyi +++ b/pyclasher/api/requests/builder_base_leagues.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import BuilderBaseLeagueList, BuilderBaseLeague diff --git a/pyclasher/api/requests/capital_league.py b/pyclasher/api/requests/capital_league.py index c7c184e..7a20017 100644 --- a/pyclasher/api/requests/capital_league.py +++ b/pyclasher/api/requests/capital_league.py @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import CapitalLeague diff --git a/pyclasher/api/requests/capital_league.pyi b/pyclasher/api/requests/capital_league.pyi index 95a1095..207c73b 100644 --- a/pyclasher/api/requests/capital_league.pyi +++ b/pyclasher/api/requests/capital_league.pyi @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import CapitalLeague diff --git a/pyclasher/api/requests/capital_league_seasons.py b/pyclasher/api/requests/capital_league_seasons.py index 5cd381c..b35a35a 100644 --- a/pyclasher/api/requests/capital_league_seasons.py +++ b/pyclasher/api/requests/capital_league_seasons.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import CapitalLeagueList, CapitalLeague diff --git a/pyclasher/api/requests/capital_league_seasons.pyi b/pyclasher/api/requests/capital_league_seasons.pyi index 88e77f6..3194e6a 100644 --- a/pyclasher/api/requests/capital_league_seasons.pyi +++ b/pyclasher/api/requests/capital_league_seasons.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import CapitalLeagueList, CapitalLeague diff --git a/pyclasher/api/requests/clan.py b/pyclasher/api/requests/clan.py index f70a2b9..d5a4606 100644 --- a/pyclasher/api/requests/clan.py +++ b/pyclasher/api/requests/clan.py @@ -1,6 +1,6 @@ from asyncio import get_running_loop, run -from .request_models import RequestModel +from .abc import RequestModel from ..models import Clan, BaseClan diff --git a/pyclasher/api/requests/clan.pyi b/pyclasher/api/requests/clan.pyi index 1082b45..c93b858 100644 --- a/pyclasher/api/requests/clan.pyi +++ b/pyclasher/api/requests/clan.pyi @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import Clan, BaseClan diff --git a/pyclasher/api/requests/clan_builder_base_rankings.py b/pyclasher/api/requests/clan_builder_base_rankings.py index b712beb..0b05581 100644 --- a/pyclasher/api/requests/clan_builder_base_rankings.py +++ b/pyclasher/api/requests/clan_builder_base_rankings.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanBuilderBaseRanking, ClanBuilderBaseRankingList diff --git a/pyclasher/api/requests/clan_builder_base_rankings.pyi b/pyclasher/api/requests/clan_builder_base_rankings.pyi index b0eac04..4cb4ba2 100644 --- a/pyclasher/api/requests/clan_builder_base_rankings.pyi +++ b/pyclasher/api/requests/clan_builder_base_rankings.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanBuilderBaseRanking, ClanBuilderBaseRankingList, Location diff --git a/pyclasher/api/requests/clan_capital_raid_seasons.py b/pyclasher/api/requests/clan_capital_raid_seasons.py index a7cec55..7ef7a89 100644 --- a/pyclasher/api/requests/clan_capital_raid_seasons.py +++ b/pyclasher/api/requests/clan_capital_raid_seasons.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanCapitalRaidSeasons, ClanCapitalRaidSeason diff --git a/pyclasher/api/requests/clan_capital_raid_seasons.pyi b/pyclasher/api/requests/clan_capital_raid_seasons.pyi index 03fe475..3c21800 100644 --- a/pyclasher/api/requests/clan_capital_raid_seasons.pyi +++ b/pyclasher/api/requests/clan_capital_raid_seasons.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanCapitalRaidSeasons, ClanCapitalRaidSeason diff --git a/pyclasher/api/requests/clan_current_war.py b/pyclasher/api/requests/clan_current_war.py index ccb7609..12fdfde 100644 --- a/pyclasher/api/requests/clan_current_war.py +++ b/pyclasher/api/requests/clan_current_war.py @@ -1,6 +1,6 @@ from asyncio import get_running_loop, run -from .request_models import RequestModel +from .abc import RequestModel from ..models import ClanWar, BaseClan diff --git a/pyclasher/api/requests/clan_current_war.pyi b/pyclasher/api/requests/clan_current_war.pyi index 917b15d..a722d31 100644 --- a/pyclasher/api/requests/clan_current_war.pyi +++ b/pyclasher/api/requests/clan_current_war.pyi @@ -1,6 +1,6 @@ from typing import Coroutine, Any -from .request_models import RequestModel +from .abc import RequestModel from ..models import ClanWar, BaseClan diff --git a/pyclasher/api/requests/clan_labels.py b/pyclasher/api/requests/clan_labels.py index ee816c1..e612041 100644 --- a/pyclasher/api/requests/clan_labels.py +++ b/pyclasher/api/requests/clan_labels.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import LabelList, Label diff --git a/pyclasher/api/requests/clan_labels.pyi b/pyclasher/api/requests/clan_labels.pyi index e5ba598..80028d2 100644 --- a/pyclasher/api/requests/clan_labels.pyi +++ b/pyclasher/api/requests/clan_labels.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import LabelList, Label diff --git a/pyclasher/api/requests/clan_members.py b/pyclasher/api/requests/clan_members.py index 25459aa..0c49806 100644 --- a/pyclasher/api/requests/clan_members.py +++ b/pyclasher/api/requests/clan_members.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanMember, ClanMemberList diff --git a/pyclasher/api/requests/clan_members.pyi b/pyclasher/api/requests/clan_members.pyi index eb41d91..2a69a6d 100644 --- a/pyclasher/api/requests/clan_members.pyi +++ b/pyclasher/api/requests/clan_members.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanMember, ClanMemberList diff --git a/pyclasher/api/requests/clan_rankings.py b/pyclasher/api/requests/clan_rankings.py index 81f1faa..71fa342 100644 --- a/pyclasher/api/requests/clan_rankings.py +++ b/pyclasher/api/requests/clan_rankings.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanRanking, ClanRankingList diff --git a/pyclasher/api/requests/clan_rankings.pyi b/pyclasher/api/requests/clan_rankings.pyi index eafd39f..e4a8348 100644 --- a/pyclasher/api/requests/clan_rankings.pyi +++ b/pyclasher/api/requests/clan_rankings.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanRanking, ClanRankingList, Location diff --git a/pyclasher/api/requests/clan_search.py b/pyclasher/api/requests/clan_search.py index b7e08d9..f9b6a60 100644 --- a/pyclasher/api/requests/clan_search.py +++ b/pyclasher/api/requests/clan_search.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanList, WarFrequency, Locations, Labels, Clan diff --git a/pyclasher/api/requests/clan_search.pyi b/pyclasher/api/requests/clan_search.pyi index f798b27..c50e0d7 100644 --- a/pyclasher/api/requests/clan_search.pyi +++ b/pyclasher/api/requests/clan_search.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanList, WarFrequency, Locations, Labels, Clan diff --git a/pyclasher/api/requests/clan_war_log.py b/pyclasher/api/requests/clan_war_log.py index a2ed223..5deabe5 100644 --- a/pyclasher/api/requests/clan_war_log.py +++ b/pyclasher/api/requests/clan_war_log.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanWarLog, ClanWarLogEntry diff --git a/pyclasher/api/requests/clan_war_log.pyi b/pyclasher/api/requests/clan_war_log.pyi index 237d5dc..f0e41ac 100644 --- a/pyclasher/api/requests/clan_war_log.pyi +++ b/pyclasher/api/requests/clan_war_log.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import ClanWarLog, ClanWarLogEntry diff --git a/pyclasher/api/requests/gold_pass.py b/pyclasher/api/requests/gold_pass.py index 5f54624..dea66fb 100644 --- a/pyclasher/api/requests/gold_pass.py +++ b/pyclasher/api/requests/gold_pass.py @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import GoldPassSeason diff --git a/pyclasher/api/requests/gold_pass.pyi b/pyclasher/api/requests/gold_pass.pyi index 518d33e..859e0b4 100644 --- a/pyclasher/api/requests/gold_pass.pyi +++ b/pyclasher/api/requests/gold_pass.pyi @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import GoldPassSeason diff --git a/pyclasher/api/requests/league.py b/pyclasher/api/requests/league.py index 26100e8..a86d5b5 100644 --- a/pyclasher/api/requests/league.py +++ b/pyclasher/api/requests/league.py @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import League diff --git a/pyclasher/api/requests/league.pyi b/pyclasher/api/requests/league.pyi index 21039b9..410b31e 100644 --- a/pyclasher/api/requests/league.pyi +++ b/pyclasher/api/requests/league.pyi @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import League diff --git a/pyclasher/api/requests/league_season.py b/pyclasher/api/requests/league_season.py index 23757a9..3c71413 100644 --- a/pyclasher/api/requests/league_season.py +++ b/pyclasher/api/requests/league_season.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import PlayerRanking, PlayerRankingList, Season diff --git a/pyclasher/api/requests/league_season.pyi b/pyclasher/api/requests/league_season.pyi index 3b8b93c..23a53e5 100644 --- a/pyclasher/api/requests/league_season.pyi +++ b/pyclasher/api/requests/league_season.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import PlayerRanking, PlayerRankingList, Leagues, Season diff --git a/pyclasher/api/requests/leagues.py b/pyclasher/api/requests/leagues.py index 32b4db9..e69c1dc 100644 --- a/pyclasher/api/requests/leagues.py +++ b/pyclasher/api/requests/leagues.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import LeagueList, League diff --git a/pyclasher/api/requests/leagues.pyi b/pyclasher/api/requests/leagues.pyi index e4381c2..fec0658 100644 --- a/pyclasher/api/requests/leagues.pyi +++ b/pyclasher/api/requests/leagues.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import LeagueList, League diff --git a/pyclasher/api/requests/location.py b/pyclasher/api/requests/location.py index 3ccb69b..3727b84 100644 --- a/pyclasher/api/requests/location.py +++ b/pyclasher/api/requests/location.py @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import Location diff --git a/pyclasher/api/requests/location.pyi b/pyclasher/api/requests/location.pyi index e990e18..1de39fd 100644 --- a/pyclasher/api/requests/location.pyi +++ b/pyclasher/api/requests/location.pyi @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import Location diff --git a/pyclasher/api/requests/locations.py b/pyclasher/api/requests/locations.py index 17a86ed..8e5c840 100644 --- a/pyclasher/api/requests/locations.py +++ b/pyclasher/api/requests/locations.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import Location, LocationList diff --git a/pyclasher/api/requests/locations.pyi b/pyclasher/api/requests/locations.pyi index d7fc5f3..6cdb202 100644 --- a/pyclasher/api/requests/locations.pyi +++ b/pyclasher/api/requests/locations.pyi @@ -1,6 +1,6 @@ from typing import Self, Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import Location, LocationList diff --git a/pyclasher/api/requests/player.py b/pyclasher/api/requests/player.py index f0bb31c..a4166a7 100644 --- a/pyclasher/api/requests/player.py +++ b/pyclasher/api/requests/player.py @@ -1,7 +1,7 @@ from asyncio import Future, get_running_loop, run from urllib.parse import quote -from .request_models import RequestModel +from .abc import RequestModel from ..models import Player, VerifyTokenRequest, VerifyTokenResponse from ...utils.request_methods import RequestMethods from ...exceptions import ClientIsNotRunning, ApiCode diff --git a/pyclasher/api/requests/player.pyi b/pyclasher/api/requests/player.pyi index 39147e2..1cee5b7 100644 --- a/pyclasher/api/requests/player.pyi +++ b/pyclasher/api/requests/player.pyi @@ -1,6 +1,6 @@ from typing import Coroutine, Any -from .request_models import RequestModel +from .abc import RequestModel from ..models import Player, VerifyTokenResponse diff --git a/pyclasher/api/requests/player_builder_base_rankings.py b/pyclasher/api/requests/player_builder_base_rankings.py index aa70ec5..8b9b97e 100644 --- a/pyclasher/api/requests/player_builder_base_rankings.py +++ b/pyclasher/api/requests/player_builder_base_rankings.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import PlayerBuilderBaseRanking, PlayerBuilderBaseRankingList diff --git a/pyclasher/api/requests/player_builder_base_rankings.pyi b/pyclasher/api/requests/player_builder_base_rankings.pyi index 94eedbd..06907d9 100644 --- a/pyclasher/api/requests/player_builder_base_rankings.pyi +++ b/pyclasher/api/requests/player_builder_base_rankings.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import PlayerBuilderBaseRanking, PlayerBuilderBaseRankingList, Location diff --git a/pyclasher/api/requests/player_labels.py b/pyclasher/api/requests/player_labels.py index 2ac1350..1bef6e0 100644 --- a/pyclasher/api/requests/player_labels.py +++ b/pyclasher/api/requests/player_labels.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import LabelList, Label diff --git a/pyclasher/api/requests/player_labels.pyi b/pyclasher/api/requests/player_labels.pyi index 21588d0..cd57aff 100644 --- a/pyclasher/api/requests/player_labels.pyi +++ b/pyclasher/api/requests/player_labels.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import LabelList, Label diff --git a/pyclasher/api/requests/player_rankings.py b/pyclasher/api/requests/player_rankings.py index 5f06da2..7b0831d 100644 --- a/pyclasher/api/requests/player_rankings.py +++ b/pyclasher/api/requests/player_rankings.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import PlayerRanking, PlayerRankingList diff --git a/pyclasher/api/requests/player_rankings.pyi b/pyclasher/api/requests/player_rankings.pyi index cbb234b..cd1a569 100644 --- a/pyclasher/api/requests/player_rankings.pyi +++ b/pyclasher/api/requests/player_rankings.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import PlayerRanking, PlayerRankingList, Location diff --git a/pyclasher/api/requests/war_league.py b/pyclasher/api/requests/war_league.py index a008cb7..13002e3 100644 --- a/pyclasher/api/requests/war_league.py +++ b/pyclasher/api/requests/war_league.py @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import WarLeague diff --git a/pyclasher/api/requests/war_league.pyi b/pyclasher/api/requests/war_league.pyi index 47a2429..a6396f0 100644 --- a/pyclasher/api/requests/war_league.pyi +++ b/pyclasher/api/requests/war_league.pyi @@ -1,4 +1,4 @@ -from .request_models import RequestModel +from .abc import RequestModel from ..models import WarLeague diff --git a/pyclasher/api/requests/war_leagues.py b/pyclasher/api/requests/war_leagues.py index d228b8b..b98b890 100644 --- a/pyclasher/api/requests/war_leagues.py +++ b/pyclasher/api/requests/war_leagues.py @@ -1,4 +1,4 @@ -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import WarLeagueList, WarLeague diff --git a/pyclasher/api/requests/war_leagues.pyi b/pyclasher/api/requests/war_leagues.pyi index 043fa19..02bbb6a 100644 --- a/pyclasher/api/requests/war_leagues.pyi +++ b/pyclasher/api/requests/war_leagues.pyi @@ -1,6 +1,6 @@ from typing import Iterator -from .request_models import IterRequestModel +from .abc import IterRequestModel from ..models import WarLeagueList, WarLeague diff --git a/pyclasher/client.py b/pyclasher/client.py index 184a18c..eef7f21 100644 --- a/pyclasher/client.py +++ b/pyclasher/client.py @@ -1,4 +1,4 @@ -from asyncio import run, create_task, get_running_loop, new_event_loop +from asyncio import create_task from typing import Iterable from urllib.parse import urlparse @@ -83,10 +83,6 @@ async def from_login(cls, email, password, requests_per_second=5, self.__temporary_session = True return self - @property - def is_running(self) -> bool: - return self.__client_running - async def start(self, tokens=None): if tokens is None: tokens = self.__tokens @@ -153,3 +149,7 @@ def __del__(self): self.logger.warning("The client was still running, closed now.") return + + @property + def is_running(self) -> bool: + return self.__client_running diff --git a/pyclasher/client.pyi b/pyclasher/client.pyi index eb3994b..be3ddf6 100644 --- a/pyclasher/client.pyi +++ b/pyclasher/client.pyi @@ -1,66 +1,47 @@ -from asyncio import Queue, Future, Task, AbstractEventLoop -from enum import Enum from logging import Logger -from typing import Iterable, Coroutine, Any +from typing import Iterable -from aiohttp import ClientSession - -from .api.models import BaseModel from .exceptions import MISSING +from .request_queue import PcQueue - - - - - - -class PyClasherClient: +class Client: """ this is the class for the ClashOfClans API client :cvar __instance: the private instance of the client - :type __instance: PyClasherClient + :type __instance: Client :cvar base_url: the public base URL for the requests (usually https://api.clashofclans.com) :type base_url: str :cvar endpoint: the public endpoint URL for the requests (usually /v1) :type endpoint: str - :cvar queue: the public request_queue where the requests are enqueued - :type queue: RequestQueue :cvar requests_per_second: the public number of requests done per consumer/token per second (usually 5) :type requests_per_second: int :cvar logger: public logger to log the requests, ... (usually MISSING) :type logger: Logger :cvar initialised: public boolean that indicates if the :type initialised: bool - :cvar __loop: abstract event loop that is used for making requests if no loop is running - :type __loop: AbstractEventLoop - :cvar __consumers: private list of consumers of the request_queue and requests + :ivar queue: the public request_queue where the requests are enqueued + :type queue: RequestQueue + :ivar __consumers: private list of consumers of the request_queue and requests :type __consumers: list[Consumer] - :cvar __consume_tasks: private list of tasks of the consumer + :ivar __consume_tasks: private list of tasks of the consumer :type __consume_tasks: list[Task] - :cvar __temporary_session: private boolean that indicates if the session is temporary or not + :ivar __temporary_session: private boolean that indicates if the session is temporary or not :type __temporary_session: bool - :cvar __tokens: private list of tokens + :ivar __tokens: private list of tokens :type __tokens: list[str] - :cvar __client_running: private boolean that indicates if the client is running or not + :ivar __client_running: private boolean that indicates if the client is running or not :type __client_running: bool """ - __instance: PyClasherClient = None + __instance: Client = None base_url: str = "https://api.clashofclans.com" endpoint: str = "/v1" - queue: RequestQueue = None requests_per_second: int = 5 logger: Logger = MISSING initialised = False - __loop: AbstractEventLoop = MISSING - __consumers: list[Consumer] = None - __consume_tasks: list[Task] = None - __temporary_session: bool = False - __tokens: list[str] | None = None - __client_running: bool = False def __new__(cls, *args, **kwargs): ... @@ -93,18 +74,26 @@ class PyClasherClient: :return: None :rtype: None """ - self.request_timeout = request_timeout + self.logger: Logger = ... + self.__tokens: list[str] = ... + self.requests_per_second: int = ... + self.queue: PcQueue = ... + self.request_timeout: float = ... + self.__client_running: bool = ... + self.__temporary_session: bool = ... + self.__consumers: list = ... + self.__consume_tasks: list = ... ... @classmethod - def from_login(cls, - email: str, - password: str, - requests_per_second: int = 5, - request_timeout: float = 30, - logger: Logger = MISSING, - login_count: int = 1 - ) -> PyClasherClient | Coroutine[Any, Any, PyClasherClient]: + async def from_login(cls, + email: str, + password: str, + requests_per_second: int = 5, + request_timeout: float = 30, + logger: Logger = MISSING, + login_count: int = 1 + ) -> Client: """ login via the ClashOfClans login API to retrieve a temporary session (usually 1 hour) @@ -113,26 +102,17 @@ class PyClasherClient: :param requests_per_second: number of requests per token per second :param request_timeout: seconds until the request is cancelled due to a timeout :param logger: logger - :param login_count: number of logins that should be done (having more logins results more tokens and this leads to more requests that can be executed in parallel) - .. note:: do not set the ``login_count`` to high, otherwise the account could be banned (5 works fine) - :return: an instance of the pyclasher client or a coroutine that returns an instance of the pyclasher client - :rtype: PyClasherClient | Coroutine[Any, Any, PyClasherClient] + :param login_count: number of logins that should be done (having more logins results more tokens + and this leads to more requests that can be executed in parallel) + .. note:: do not set the ``login_count`` to high, otherwise the account could be banned + (5 works fine) + :return: an instance of the pyclasher client or a coroutine that returns an instance of + the pyclasher client + :rtype: Client """ ... - @property - def is_running(self) -> bool: - """ - property that indicates if the client is running - - status changes if the client is started or stopped - - :return: boolean indicating if the client is running, True if running else otherwise - :rtype: bool - """ - ... - - def start(self, tokens: str | Iterable[str] = None) -> PyClasherClient: + async def start(self, tokens: str | Iterable[str] = None) -> Client: """ start the client @@ -143,36 +123,32 @@ class PyClasherClient: """ ... - def close(self) -> PyClasherClient | Coroutine[Any, Any, PyClasherClient]: + async def close(self) -> Client: """ close the client - this method can be used in an asynchronous context using the ``await`` keyword - but can also be used in non-asynchronous context without awaiting the method - :return: the instance of the client - :rtype: PyClasherClient | Coroutine[Any, Any, PyClasherClient] + :rtype: Client """ ... - def __enter__(self) -> PyClasherClient: + async def __aenter__(self) -> Client: ... - def __exit__(self, exc_type, exc_val, exc_tb) -> PyClasherClient: - ... - - async def __aenter__(self) -> PyClasherClient: - ... - - async def __aexit__(self, exc_type, exc_val, exc_tb) -> PyClasherClient: + async def __aexit__(self, exc_type, exc_val, exc_tb) -> Client: ... def __del__(self) -> None: ... @property - def loop(self) -> AbstractEventLoop: - ... + def is_running(self) -> bool: + """ + property that indicates if the client is running + + status changes if the client is started or stopped - def reset_client(self, reset_queue: bool = True, reset_loop: bool = True, reset_tokens: bool = True) -> None: + :return: boolean indicating if the client is running, True if running else otherwise + :rtype: bool + """ ... From 60fad416df1de03048a8a032e9193682c04cd42f Mon Sep 17 00:00:00 2001 From: 201st-Luka Date: Tue, 22 Aug 2023 19:02:25 +0200 Subject: [PATCH 4/4] tests: fixed crash --- tests/requests/conftest.py | 3 ++- tests/requests/test_clan.py | 24 ++++++++++++++---------- tests/requests/test_player.py | 9 ++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/requests/conftest.py b/tests/requests/conftest.py index 7242af8..b341ce1 100644 --- a/tests/requests/conftest.py +++ b/tests/requests/conftest.py @@ -4,7 +4,8 @@ from pyclasher import Client -from constants import CLASH_OF_CLANS_LOGIN_EMAIL, CLASH_OF_CLANS_LOGIN_PASSWORD +from ..constants import (CLASH_OF_CLANS_LOGIN_EMAIL, + CLASH_OF_CLANS_LOGIN_PASSWORD) @pytest.fixture(scope="package") diff --git a/tests/requests/test_clan.py b/tests/requests/test_clan.py index 5ef6a12..66507d9 100644 --- a/tests/requests/test_clan.py +++ b/tests/requests/test_clan.py @@ -1,15 +1,19 @@ import pytest -from pyclasher import (ClanRequest, ClanMembersRequest, Missing, ClanCurrentWarRequest, ClanWarLogRequest, - ClanSearchRequest, ClanCapitalRaidSeasonsRequest) -from pyclasher.api.models import (ClanType, WarFrequency, BadgeUrls, WarLeague, CapitalLeague, Language, ClanCapital, - LabelList, Location, ClanMemberList, Paging, BuilderBaseLeague, League, PlayerHouse, - ClanRole, ClanMember, ClanWarState, WarClan, Time, ClanWarLog, ClanWarResult, - ClanList, - ClanCapitalRaidSeasons, ClanCapitalRaidSeasonMemberList, - ClanCapitalRaidSeasonAttackLogList, ClanCapitalRaidSeasonDefenseLogList) - -from constants import TEST_CLAN_TAG, TEST_CLAN_NAME +from pyclasher import ( + ClanRequest, ClanMembersRequest, Missing, ClanCurrentWarRequest, + ClanWarLogRequest, ClanSearchRequest, ClanCapitalRaidSeasonsRequest +) +from pyclasher.api.models import ( + ClanType, WarFrequency, BadgeUrls, WarLeague, CapitalLeague, Language, + ClanCapital, LabelList, Location, ClanMemberList, Paging, + BuilderBaseLeague, League, PlayerHouse, ClanRole, ClanMember, + ClanWarState, WarClan, Time, ClanWarLog, ClanWarResult, ClanList, + ClanCapitalRaidSeasons, ClanCapitalRaidSeasonMemberList, + ClanCapitalRaidSeasonAttackLogList, ClanCapitalRaidSeasonDefenseLogList +) + +from ..constants import TEST_CLAN_TAG, TEST_CLAN_NAME @pytest.mark.asyncio diff --git a/tests/requests/test_player.py b/tests/requests/test_player.py index 785519e..bc2f2f7 100644 --- a/tests/requests/test_player.py +++ b/tests/requests/test_player.py @@ -1,10 +1,13 @@ import pytest from pyclasher import PlayerRequest, Missing -from pyclasher.api.models import (ClanRole, PlayerHouse, PlayerClan, PlayerAchievementProgressList, BuilderBaseLeague, - PlayerItemLevelList, LabelList, League, PlayerLegendStatistics, WarPreference) +from pyclasher.api.models import ( + ClanRole, PlayerHouse, PlayerClan, PlayerAchievementProgressList, + BuilderBaseLeague, PlayerItemLevelList, LabelList, League, + PlayerLegendStatistics,WarPreference +) -from constants import TEST_PLAYER_TAG +from ..constants import TEST_PLAYER_TAG @pytest.mark.asyncio