Skip to content

Commit

Permalink
Merge pull request #19 from 201st-Luka/correcting_errors
Browse files Browse the repository at this point in the history
Correcting errors
  • Loading branch information
201st-Luka authored Jul 26, 2023
2 parents ed03ad9 + eb8ff85 commit c591156
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ exclude
.pytest_cache
tests/.pytest_cache
build
pyclasher.egg-info
testing
32 changes: 18 additions & 14 deletions pyclasher/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def __repr__(self):
MISSING = Missing()


class ApiCode(Exception):
class PyClasherException(Exception):
pass


class ApiCode(PyClasherException):
"""
exception class to handle ClashOfClans API client errors
"""
Expand All @@ -41,23 +45,23 @@ def __repr__(self):
return f"ApiException(code={self.code})"


class RequestNotDone(Exception):
class RequestNotDone(PyClasherException):
def __str__(self):
return "The request was not done."


class NoneToken(Exception):
class NoneToken(PyClasherException):
def __str__(self):
return "The token must be passed to the client. " \
"You can do this in the initialisation process or pass the tokens to the start function."


class InvalidLoginData(Exception):
class InvalidLoginData(PyClasherException):
def __str__(self):
return "The login data is invalid."


class InvalidType(Exception):
class InvalidType(PyClasherException):
def __init__(self, element, allowed_types):
super().__init__()
self.element = element
Expand All @@ -68,32 +72,32 @@ def __str__(self):
return f"{self.element} is of invalid type\nallowed types are {self.types}."


class LoginNotDone(Exception):
class LoginNotDone(PyClasherException):
def __str__(self):
return "The login was not done. You need to login first."


class ClientIsRunning(Exception):
class ClientIsRunning(PyClasherException):
def __str__(self):
return "The client is already running."


class ClientIsNotRunning(Exception):
class ClientIsNotRunning(PyClasherException):
def __str__(self):
return "The client is not running."


class ClientAlreadyInitialised(Exception):
class ClientAlreadyInitialised(PyClasherException):
def __str__(self):
return "The PyClasherClient has already been initialised."


class NoClient(Exception):
class NoClient(PyClasherException):
def __str__(self):
return "No client has been initialised."


class InvalidTimeFormat(Exception):
class InvalidTimeFormat(PyClasherException):
def __init__(self, value, time_format):
super().__init__()
self.value = value
Expand All @@ -104,16 +108,16 @@ def __str__(self):
return f"The time {self.value} does not match the format '{self.time_format}'."


class ClientRunningOverwrite(Exception):
class ClientRunningOverwrite(PyClasherException):
def __str__(self):
return "You cannot overwrite the parameter of a running client."


class InvalidSeasonFormat(Exception):
class InvalidSeasonFormat(PyClasherException):
def __str__(self):
return "The season string is not valid. It must be follow the following format: <yyyy-mm> where <yyyy> is the year and <mm> is the month."


class RequestTimeout(Exception):
class RequestTimeout(PyClasherException):
def __str__(self):
return "The request took to much time and was cancelled."
4 changes: 4 additions & 0 deletions pyclasher/Exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Missing:
MISSING = Missing()


class PyClasherException(Exception):
pass


class ApiCode(Exception):
"""
exception class to handle ClashOfClans API exceptions
Expand Down
2 changes: 1 addition & 1 deletion pyclasher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from .Exceptions import ApiCode, ClientIsRunning, ClientIsNotRunning, ClientAlreadyInitialised, NoClient, \
InvalidType, InvalidLoginData, LoginNotDone, NoneToken, RequestNotDone, InvalidTimeFormat, \
InvalidSeasonFormat, Missing, MISSING
InvalidSeasonFormat, Missing, MISSING, PyClasherException
from .client import RequestMethods, Status, Auth, Developer, Login, Consumer, PyClasherClient
from .requests import *
10 changes: 5 additions & 5 deletions pyclasher/bulk_requests/BulkPlayer.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable
from typing import Iterable, Coroutine, Any

from .BulkRequestModel import BulkRequestModel
from ..models import BaseClan, ClanMemberList, ClanWarMemberList, ClanWarLeagueClanMemberList, ClanCapitalRaidSeasonMemberList
Expand Down Expand Up @@ -41,13 +41,13 @@ class PlayerBulkRequest(BulkRequestModel):
...

@classmethod
def from_clan(cls, clan: BaseClan | str) -> PlayerBulkRequest:
def from_clan(cls, clan: BaseClan | str) -> PlayerBulkRequest | Coroutine[Any, Any, PlayerBulkRequest]:
"""
class method to create an instance using a clan or a clan tag
:param cls: PlayerBulkRequest
:param clan: clan or clan tag
:rtype: PlayerBulkRequest
:rtype: PlayerBulkRequest | Coroutine[Any, Any, PlayerBulkRequest]
"""
...

Expand All @@ -66,7 +66,7 @@ class PlayerBulkRequest(BulkRequestModel):
"""
...

def __getitem__(self, item: int) -> _request_model:
def __getitem__(self, item: int) -> PlayerRequest:
"""
getter for a player of the bulk request
Expand All @@ -75,7 +75,7 @@ class PlayerBulkRequest(BulkRequestModel):
"""
...

def __next__(self) -> _request_model:
def __next__(self) -> PlayerRequest:
"""
returns the next player of the bulk request if an iterator is used
"""
Expand Down
2 changes: 1 addition & 1 deletion pyclasher/bulk_requests/BulkRequestModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __iter__(self):
return self

def __next__(self):
return self._request_model(next(self._iter))
return next(self._iter)

def __str__(self):
return f"{self.__class__.__name__}({self._main_attribute})"
Expand Down
8 changes: 4 additions & 4 deletions pyclasher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
NoneToken, MISSING
from .models import ApiCodes
from .models.BaseModels import BaseModel
from .utils import ExecutionTimer


class RequestMethods(Enum):
Expand Down Expand Up @@ -210,11 +211,10 @@ async def consume(self):
while True:
future, url, method, body, status, error = await self.queue.get()

create_task(self._request(future, url, method.value, body, status, error))
async with ExecutionTimer(self.wait):
create_task(self._request(future, url, method.value, body, status, error))

self.queue.task_done()

await sleep(self.wait)
self.queue.task_done()

async def close(self):
await self.session.close()
Expand Down
4 changes: 2 additions & 2 deletions pyclasher/models/Clan.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class ClanDistrictDataList(IterBaseModel):

_iter_rtype = ClanDistrictData

def __getitem__(self, item: int) -> _iter_rtype:
def __getitem__(self, item: int) -> ClanDistrictData:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanDistrictData:
...


Expand Down
4 changes: 2 additions & 2 deletions pyclasher/models/ClanBuilderBaseRankingList.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class ClanBuilderBaseRankingList(IterBaseModel):

_iter_rtype = ClanBuilderBaseRanking

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanBuilderBaseRanking:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanBuilderBaseRanking:
...
24 changes: 12 additions & 12 deletions pyclasher/models/ClanCapitalRaidSeasons.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class ClanCapitalRaidSeasonAttackList(IterBaseModel):

_iter_rtype = ClanCapitalRaidSeasonAttack

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanCapitalRaidSeasonAttack:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanCapitalRaidSeasonAttack:
...


Expand Down Expand Up @@ -189,10 +189,10 @@ class ClanCapitalRaidSeasonDistrictList(IterBaseModel):

_iter_rtype = ClanCapitalRaidSeasonDistrict

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanCapitalRaidSeasonDistrict:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanCapitalRaidSeasonDistrict:
...


Expand Down Expand Up @@ -317,10 +317,10 @@ class ClanCapitalRaidSeasonDefenseLogList(IterBaseModel):

_iter_rtype = ClanCapitalRaidSeasonDefenseLogEntry

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanCapitalRaidSeasonDefenseLogEntry:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanCapitalRaidSeasonDefenseLogEntry:
...


Expand All @@ -333,10 +333,10 @@ class ClanCapitalRaidSeasonAttackLogList(IterBaseModel):

_iter_rtype = ClanCapitalRaidSeasonAttackLogEntry

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanCapitalRaidSeasonAttackLogEntry:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanCapitalRaidSeasonAttackLogEntry:
...


Expand Down Expand Up @@ -395,10 +395,10 @@ class ClanCapitalRaidSeasonMemberList(IterBaseModel):

_iter_rtype = ClanCapitalRaidSeasonMember

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanCapitalRaidSeasonMember:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanCapitalRaidSeasonMember:
...


Expand Down Expand Up @@ -528,8 +528,8 @@ class ClanCapitalRaidSeasons(IterBaseModel):

_iter_rtype = ClanCapitalRaidSeason

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanCapitalRaidSeason:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanCapitalRaidSeason:
...
4 changes: 2 additions & 2 deletions pyclasher/models/ClanCapitalRankingList.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class ClanCapitalRankingList(IterBaseModel):

_iter_rtype = ClanCapitalRanking

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanCapitalRanking:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanCapitalRanking:
...
4 changes: 2 additions & 2 deletions pyclasher/models/ClanList.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ClanList(IterBaseModel):

_iter_rtype = Clan

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> Clan:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> Clan:
...
4 changes: 2 additions & 2 deletions pyclasher/models/ClanMemberList.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class ClanMemberList(IterBaseModel):

_iter_rtype = ClanMember

def __getitem__(self, item: int | str) -> _iter_rtype:
def __getitem__(self, item: int | str) -> ClanMember:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanMember:
...
12 changes: 6 additions & 6 deletions pyclasher/models/ClanWarLeagueGroup.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class ClanWarLeagueRoundList(IterBaseModel):

_iter_rtype = ClanWarLeagueRound

def __getitem__(self, item: int) -> _iter_rtype:
def __getitem__(self, item: int) -> ClanWarLeagueRound:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanWarLeagueRound:
...


Expand Down Expand Up @@ -59,10 +59,10 @@ class ClanWarLeagueClanMemberList(IterBaseModel):

_iter_rtype = ClanWarLeagueClanMember

def __getitem__(self, item: int) -> _iter_rtype:
def __getitem__(self, item: int) -> ClanWarLeagueClanMember:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanWarLeagueClanMember:
...


Expand Down Expand Up @@ -101,10 +101,10 @@ class ClanWarLeagueClanList(IterBaseModel):

_iter_rtype = ClanWarLeagueClan

def __getitem__(self, item: int) -> _iter_rtype:
def __getitem__(self, item: int) -> ClanWarLeagueClan:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanWarLeagueClan:
...


Expand Down
4 changes: 2 additions & 2 deletions pyclasher/models/ClanWarLog.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class ClanWarLog(IterBaseModel):

_iter_rtype = ClanWarLogEntry

def __getitem__(self, item: int) -> _iter_rtype:
def __getitem__(self, item: int) -> ClanWarLogEntry:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> ClanWarLogEntry:
...
4 changes: 2 additions & 2 deletions pyclasher/models/Labels.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class LabelList(IterBaseModel):

_iter_rtype = Label

def __getitem__(self, item: int) -> _iter_rtype:
def __getitem__(self, item: int) -> Label:
...

def __next__(self) -> _iter_rtype:
def __next__(self) -> Label:
...
Loading

0 comments on commit c591156

Please sign in to comment.