22from contextlib import asynccontextmanager
33from pathlib import PurePosixPath
44from typing import Literal
5- from urllib .parse import unquote , urljoin
5+ from urllib .parse import urljoin
66
77import httpx
88
1818 FinalRequestOptions ,
1919)
2020from aidial_client ._utils ._dict import remove_none
21- from aidial_client .helpers .storage_resource import (
22- DialStorageResourceMixin ,
23- percent_encode_resource_url ,
24- )
21+ from aidial_client .helpers .storage_resource import DialStorageResourceMixin
2522from aidial_client .resources .base import AsyncResource , Resource
2623from aidial_client .resources .metadata import AsyncMetadata , Metadata
2724from aidial_client .types .file import FileDownloadResponse
2825from aidial_client .types .metadata import FileItem , FileMetadata
2926
3027
31- def _prepare_file_download (
32- resource : DialStorageResourceMixin ,
33- url : str | PurePosixPath ,
34- etag_if_match : str | None ,
35- ) -> tuple [FinalRequestOptions , str ]:
36- """Build a download request from an encoded path, decoded filename."""
37- options , filename = resource ._prepare_download_request (
38- percent_encode_resource_url (str (url )), etag_if_match
39- )
40- return options , unquote (filename )
41-
42-
4328def _move_copy_body (
4429 resource : DialStorageResourceMixin ,
4530 source : str | PurePosixPath ,
@@ -99,7 +84,7 @@ def download(
9984 url : str | PurePosixPath ,
10085 etag_if_match : str | None = None ,
10186 ) -> FileDownloadResponse :
102- options , filename = _prepare_file_download ( self , url , etag_if_match )
87+ options , filename = self . _prepare_download_request ( url , etag_if_match )
10388 response = self .http_client .request (
10489 cast_to = httpx .Response ,
10590 options = options ,
@@ -205,7 +190,7 @@ async def download(
205190 url : str | PurePosixPath ,
206191 etag_if_match : str | None = None ,
207192 ) -> FileDownloadResponse :
208- options , filename = _prepare_file_download ( self , url , etag_if_match )
193+ options , filename = self . _prepare_download_request ( url , etag_if_match )
209194 response = await self .http_client .request (
210195 cast_to = httpx .Response ,
211196 options = options ,
@@ -219,7 +204,7 @@ async def stream_download(
219204 url : str | PurePosixPath ,
220205 etag_if_match : str | None = None ,
221206 ) -> AsyncIterator [FileDownloadResponse ]:
222- options , filename = _prepare_file_download ( self , url , etag_if_match )
207+ options , filename = self . _prepare_download_request ( url , etag_if_match )
223208 async with self .http_client .stream (
224209 options = options ,
225210 on_http_error = _files_error_processor ,
0 commit comments