Skip to content

Commit

Permalink
Fixed broken changes made a year ago
Browse files Browse the repository at this point in the history
  • Loading branch information
sousa-andre committed Dec 9, 2022
1 parent e4b1e46 commit 65bf219
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 55 deletions.
13 changes: 5 additions & 8 deletions lcu_driver/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .exceptions import EarlyPerform
from .utils import parse_cmdline_args
from .loop import LoopSensitiveManager

logger = logging.getLogger('lcu-driver')

Expand All @@ -27,6 +26,7 @@ def __init__(self, connector, process_or_string: Union[Process, str]):
self._ws = None
self.locals = {}
self.closed = False
self.session = None

self._headers = {
'Content-Type': 'application/json',
Expand All @@ -52,23 +52,21 @@ def __init__(self, connector, process_or_string: Union[Process, str]):
self._auth_key = lockfile_parts[3]
self._installation_path = None

self.session = LoopSensitiveManager(
factory=lambda: aiohttp.ClientSession(auth=aiohttp.BasicAuth('riot', self._auth_key), headers=self._headers),
callback=lambda x: x.close(),
)

async def init(self):
"""Initialize the connection. It's called by the connector when it finds a connection
:rtype: none
"""
self.session = aiohttp.ClientSession(auth=aiohttp.BasicAuth('riot', self._auth_key), headers=self._headers)

setattr(self, 'request', self.request)

self._connector.register_connection(self)
tasks = [asyncio.create_task(self._connector.run_event('open', self))]
await self._wait_api_ready()

tasks.append(asyncio.create_task(self._connector.run_event('ready', self)))

try:
if self._connector.should_run_ws:
await self.run_ws()
Expand Down Expand Up @@ -162,8 +160,7 @@ async def request(self, method: str, endpoint: str, **kwargs):
url = self._produce_url(endpoint, **kwargs)
if kwargs.get('data'):
kwargs['data'] = dumps(kwargs['data'])
session = await self.session.get()
return session.request(method, url, verify_ssl=False, **kwargs)
return await self.session.request(method, url, verify_ssl=False, **kwargs)

async def run_ws(self):
"""Start the websoocket connection. This is responsible to raise Connector close event and
Expand Down
1 change: 1 addition & 0 deletions lcu_driver/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def wrapper():
wrapper()
except KeyboardInterrupt:
logger.info('Event loop interrupted by keyboard')
self.loop.close()

async def stop(self) -> None:
"""Flag the connector to don't look for more clients once the connection finishes his job.
Expand Down
47 changes: 0 additions & 47 deletions lcu_driver/loop.py

This file was deleted.

0 comments on commit 65bf219

Please sign in to comment.