From f22cf8c9a604b3a1a8456e34cb43aa47908c5d90 Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt <3165388245@qq.com> Date: Mon, 18 Dec 2023 22:20:10 +0800 Subject: [PATCH] chore(core): bump version --- .mina/console.toml | 4 ++-- .mina/core.toml | 2 +- avilla/core/builtins/resource_fetch.py | 23 +++++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.mina/console.toml b/.mina/console.toml index 3f7923cf..588736e9 100644 --- a/.mina/console.toml +++ b/.mina/console.toml @@ -1,11 +1,11 @@ includes = ["avilla/console"] raw-dependencies = [ - "avilla-core >= 1.0.0a6", + "avilla-core >= 1.0.0a18", ] [project] name = "avilla-console" -version = "1.0.0a9" # WIP for release. +version = "1.0.0a18" # WIP for release. authors = [ {name = "RF-Tar-Railt", email = "rf_tar_railt@qq.com"}, ] diff --git a/.mina/core.toml b/.mina/core.toml index dbc91835..e8a57a39 100644 --- a/.mina/core.toml +++ b/.mina/core.toml @@ -7,7 +7,7 @@ includes = [ [project] name = "avilla-core" -version = "1.0.0a17" +version = "1.0.0a18" authors = [ {name = "GreyElaina", email = "GreyElaina@outlook.com"}, {name = "BlueGlassBlock", email = "blueglassblock@outlook.com"}, diff --git a/avilla/core/builtins/resource_fetch.py b/avilla/core/builtins/resource_fetch.py index 1fb7fe06..d14c096a 100644 --- a/avilla/core/builtins/resource_fetch.py +++ b/avilla/core/builtins/resource_fetch.py @@ -1,9 +1,15 @@ from __future__ import annotations -from aiohttp import ClientSession from avilla.core.resource import LocalFileResource, RawResource, UrlResource from avilla.core.ryanvk.collector.application import ApplicationCollector +try: + from aiohttp import ClientSession + aio = True +except ImportError: + ClientSession = None + aio = False + from .capability import CoreCapability @@ -16,8 +22,13 @@ async def fetch_localfile(self, resource: LocalFileResource): async def fetch_raw(self, resource: RawResource): return resource.data - @m.entity(CoreCapability.fetch, resource=UrlResource) - async def fetch_url(self, resource: UrlResource): - async with ClientSession() as session: - async with session.get(resource.url) as resp: - return await resp.read() + if aio: + @m.entity(CoreCapability.fetch, resource=UrlResource) + async def fetch_url(self, resource: UrlResource): + async with ClientSession() as session: + async with session.get(resource.url) as resp: + return await resp.read() + else: + @m.entity(CoreCapability.fetch, resource=UrlResource) + async def fetch_url(self, resource: UrlResource): + raise NotImplementedError("aiohttp is not installed")