common: use aiohttp

This commit is contained in:
Corentin Sechet 2022-03-30 01:22:16 +02:00
parent 3760041e67
commit 2bd37c541f
3 changed files with 10 additions and 4 deletions

View File

@ -71,6 +71,11 @@ class Config:
return config
@property
def remote_source(self) -> Source:
"""get the default source for this context"""
return self.get_source(REMOTE_SOURCE_NAME)
@property
def default_source(self) -> Source:
"""get the default source for this context"""

View File

@ -1,9 +1,8 @@
"""Source for remote files"""
from aiohttp import ClientSession
from abc import ABC, abstractmethod
from re import Pattern
from re import compile as re_compile
from typing import cast
from urllib.request import urlopen
from frontools.cache import DataCache
@ -28,8 +27,9 @@ class CachedSource(Source):
@staticmethod
async def _load_url(url: str) -> bytes:
with urlopen(url) as remote_file:
return cast(bytes, remote_file.read())
async with ClientSession() as session:
async with session.get(url) as response:
return await response.content.read()
class OverrideSource(Source):

View File

@ -35,6 +35,7 @@ bs4 = "^0.0.1"
xdg = "^5.1.1"
playwright = "^1.20.1"
click = "^8.0.4"
aiohttp = "^3.8.1"
[tool.poetry.dev-dependencies]
isort = "^5.10.1"