diff --git a/requirements.txt b/requirements.txt index ee4ba4f..94a5b5f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ aiohttp +aiofiles diff --git a/setup.py b/setup.py index 7085d01..967c8bd 100644 --- a/setup.py +++ b/setup.py @@ -20,8 +20,7 @@ author_email="ivknv0@gmail.com", license="LGPLv3", python_requires=">=3.8", - install_requires=["aiohttp"], - tests_require=["aiofiles"], + install_requires=["aiohttp", "aiofiles"], url="https://github.com/ivknv/yadisk-async", project_urls={"Source code": "https://github.com/ivknv/yadisk-async", "Documentation (EN)": "https://yadisk-async.readthedocs.io/en/latest", diff --git a/yadisk_async/yadisk.py b/yadisk_async/yadisk.py index 6b526a8..e175a6d 100644 --- a/yadisk_async/yadisk.py +++ b/yadisk_async/yadisk.py @@ -12,14 +12,17 @@ from . import settings from .session import SessionWithHeaders from .api import * -from .exceptions import InvalidResponseError, UnauthorizedError, OperationNotFoundError -from .exceptions import PathNotFoundError, WrongResourceTypeError +from .exceptions import ( + InvalidResponseError, UnauthorizedError, OperationNotFoundError, + PathNotFoundError, WrongResourceTypeError) from .utils import get_exception, auto_retry from .objects import ResourceLinkObject, PublicResourceLinkObject from typing import Any, Optional, Union, IO, TYPE_CHECKING from .compat import Callable, AsyncGenerator, List, Awaitable, Dict +import aiofiles + if TYPE_CHECKING: from .objects import ( TokenObject, TokenRevokeStatusObject, DiskInfoObject, @@ -683,7 +686,7 @@ async def _upload(self, try: if isinstance(file_or_path, (str, bytes)): close_file = True - file = open(file_or_path, "rb") + file = await aiofiles.open(file_or_path, "rb") elif inspect.isasyncgenfunction(file_or_path): generator_factory = file_or_path else: @@ -737,7 +740,7 @@ async def attempt(): await auto_retry(attempt, n_retries, retry_interval) finally: if close_file and file is not None: - file.close() + await file.close() async def upload(self, path_or_file: FileOrPath, @@ -849,7 +852,7 @@ async def _download(self, try: if isinstance(file_or_path, (str, bytes)): close_file = True - file = open(file_or_path, "wb") + file = await aiofiles.open(file_or_path, "wb") else: close_file = False file = file_or_path @@ -893,7 +896,7 @@ async def attempt() -> None: return await auto_retry(attempt, n_retries, retry_interval) finally: if close_file and file is not None: - file.close() + await file.close() async def download(self, src_path: str,