mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-18 15:05:08 +00:00
Mangle token
This commit is contained in:
parent
15b3546e27
commit
72bd647c9b
3 changed files with 15 additions and 11 deletions
|
@ -74,14 +74,14 @@ class GHClient:
|
||||||
|
|
||||||
if username and token:
|
if username and token:
|
||||||
self.username = username
|
self.username = username
|
||||||
self.token = token
|
self.__token = token
|
||||||
self._auth = aiohttp.BasicAuth(username, token)
|
self.__auth = aiohttp.BasicAuth(username, token)
|
||||||
else:
|
else:
|
||||||
self._auth = None
|
self.__auth = None
|
||||||
self.username = None
|
self.username = None
|
||||||
self.token = None
|
self.__token = None
|
||||||
|
|
||||||
self.http = http(headers=custom_headers, auth=self._auth)
|
self.http = http(headers=custom_headers, auth=self.__auth)
|
||||||
|
|
||||||
self._user_cache = ObjectCache[Any, User](user_cache_size)
|
self._user_cache = ObjectCache[Any, User](user_cache_size)
|
||||||
self._repo_cache = ObjectCache[Any, Repository](repo_cache_size)
|
self._repo_cache = ObjectCache[Any, Repository](repo_cache_size)
|
||||||
|
@ -109,7 +109,7 @@ class GHClient:
|
||||||
raise Exception('HTTP Session doesn\'t exist') from exc
|
raise Exception('HTTP Session doesn\'t exist') from exc
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f'<{self.__class__.__name__} has_auth={bool(self._auth)}>'
|
return f'<{self.__class__.__name__} has_auth={bool(self.__auth)}>'
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def check_limits(self, as_dict: Literal[True] = True) -> Dict[str, Union[str, int]]:
|
def check_limits(self, as_dict: Literal[True] = True) -> Dict[str, Union[str, int]]:
|
||||||
|
@ -167,8 +167,8 @@ class GHClient:
|
||||||
"""
|
"""
|
||||||
if self.has_started:
|
if self.has_started:
|
||||||
raise exceptions.AlreadyStarted
|
raise exceptions.AlreadyStarted
|
||||||
if self._auth:
|
if self.__auth:
|
||||||
self.http = await http(auth=self._auth, headers=self._headers)
|
self.http = await http(auth=self.__auth, headers=self._headers)
|
||||||
try:
|
try:
|
||||||
await self.http.get_self()
|
await self.http.get_self()
|
||||||
except exceptions.InvalidToken as exc:
|
except exceptions.InvalidToken as exc:
|
||||||
|
@ -213,7 +213,7 @@ class GHClient:
|
||||||
# @_cache(type='User')
|
# @_cache(type='User')
|
||||||
async def get_self(self) -> User:
|
async def get_self(self) -> User:
|
||||||
""":class:`User`: Returns the authenticated User object."""
|
""":class:`User`: Returns the authenticated User object."""
|
||||||
if self._auth:
|
if self.__auth:
|
||||||
return User(await self.http.get_self(), self.http)
|
return User(await self.http.get_self(), self.http)
|
||||||
else:
|
else:
|
||||||
raise exceptions.NoAuthProvided
|
raise exceptions.NoAuthProvided
|
||||||
|
|
|
@ -93,8 +93,8 @@ class InvalidToken(ClientException):
|
||||||
class InvalidAuthCombination(ClientException):
|
class InvalidAuthCombination(ClientException):
|
||||||
"""Raised when the username and token are both provided."""
|
"""Raised when the username and token are both provided."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, msg: str):
|
||||||
msg = 'The username and token cannot be used together.'
|
#msg = 'The username and token cannot be used together.'
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -253,6 +253,10 @@ class Repository(APIObject):
|
||||||
def forks(self) -> int:
|
def forks(self) -> int:
|
||||||
return self._response.get('forks')
|
return self._response.get('forks')
|
||||||
|
|
||||||
|
async def delete(self) -> None:
|
||||||
|
"""Deletes the repository."""
|
||||||
|
return await self._http.delete_repo(self.owner.name, self.name,) #type: ignore
|
||||||
|
|
||||||
|
|
||||||
class Issue(APIObject):
|
class Issue(APIObject):
|
||||||
"""Representation of an issue on Github.
|
"""Representation of an issue on Github.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue