mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-18 15:05:08 +00:00
Fixed getpass and del dying
This commit is contained in:
parent
153e1e50d4
commit
ebd9828afa
1 changed files with 12 additions and 8 deletions
|
@ -1,17 +1,18 @@
|
||||||
#== main.py ==#
|
#== main.py ==#
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Github',
|
'GHClient',
|
||||||
)
|
)
|
||||||
|
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import http
|
from . import http
|
||||||
import exceptions
|
from . import exceptions
|
||||||
from objects import User, Repository
|
from .objects import User, Repository
|
||||||
|
|
||||||
class Github:
|
class GHClient:
|
||||||
_auth = None
|
_auth = None
|
||||||
has_started = False
|
has_started = False
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -24,15 +25,18 @@ class Github:
|
||||||
self._headers = custom_headers
|
self._headers = custom_headers
|
||||||
if using_auth:
|
if using_auth:
|
||||||
username = input('Enter your username: ') #these two lines are blocking, but it's probably not a problem
|
username = input('Enter your username: ') #these two lines are blocking, but it's probably not a problem
|
||||||
auth_token = getpass.getpass('Enter your token: ')
|
auth_token = getpass('Enter your token: ')
|
||||||
self._auth = aiohttp.BasicAuth(username, auth_token)
|
self._auth = aiohttp.BasicAuth(username, auth_token)
|
||||||
|
|
||||||
def __await__(self):
|
def __await__(self) -> 'GHClient':
|
||||||
return self.start().__await__()
|
return self.start().__await__()
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f'<Github Client; has_auth={bool(self._auth)}>'
|
return f'<Github Client; has_auth={bool(self._auth)}>'
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
asyncio.create_task(self.session.close())
|
||||||
|
|
||||||
def check_limits(self, as_dict: bool = False) -> dict[str, str | int] | list[str]:
|
def check_limits(self, as_dict: bool = False) -> dict[str, str | int] | list[str]:
|
||||||
if not self.has_started:
|
if not self.has_started:
|
||||||
raise exceptions.NotStarted
|
raise exceptions.NotStarted
|
||||||
|
@ -49,7 +53,7 @@ class Github:
|
||||||
token = getpass('Enter your token: ')
|
token = getpass('Enter your token: ')
|
||||||
self._auth = aiohttp.BasicAuth(username, token)
|
self._auth = aiohttp.BasicAuth(username, token)
|
||||||
|
|
||||||
async def start(self) -> None:
|
async def start(self) -> 'GHClient':
|
||||||
"""Main entry point to the wrapper, this creates the ClientSession."""
|
"""Main entry point to the wrapper, this creates the ClientSession."""
|
||||||
if self.has_started:
|
if self.has_started:
|
||||||
raise exceptions.AlreadyStarted
|
raise exceptions.AlreadyStarted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue