11from __future__ import annotations
22
33from typing import Optional
4+ from warnings import warn
5+
6+ from httpx import AsyncClient
47
58from storage3 .constants import DEFAULT_TIMEOUT
69
7- from ..utils import AsyncClient
810from ..version import __version__
911from .bucket import AsyncStorageBucketAPI
1012from .file_api import AsyncBucketProxy
@@ -21,15 +23,46 @@ def __init__(
2123 self ,
2224 url : str ,
2325 headers : dict [str , str ],
24- timeout : int = DEFAULT_TIMEOUT ,
25- verify : bool = True ,
26+ timeout : Optional [ int ] = None ,
27+ verify : Optional [ bool ] = None ,
2628 proxy : Optional [str ] = None ,
29+ http_client : Optional [AsyncClient ] = None ,
2730 ) -> None :
2831 headers = {
2932 "User-Agent" : f"supabase-py/storage3 v{ __version__ } " ,
3033 ** headers ,
3134 }
32- self .session = self ._create_session (url , headers , timeout , verify , proxy )
35+
36+ if timeout is not None :
37+ warn (
38+ "The 'timeout' parameter is deprecated. Please configure it in the http client instead." ,
39+ DeprecationWarning ,
40+ stacklevel = 2 ,
41+ )
42+ if verify is not None :
43+ warn (
44+ "The 'verify' parameter is deprecated. Please configure it in the http client instead." ,
45+ DeprecationWarning ,
46+ stacklevel = 2 ,
47+ )
48+ if proxy is not None :
49+ warn (
50+ "The 'proxy' parameter is deprecated. Please configure it in the http client instead." ,
51+ DeprecationWarning ,
52+ stacklevel = 2 ,
53+ )
54+
55+ self .verify = bool (verify ) if verify is not None else True
56+ self .timeout = int (abs (timeout )) if timeout is not None else DEFAULT_TIMEOUT
57+
58+ self .session = self ._create_session (
59+ base_url = url ,
60+ headers = headers ,
61+ timeout = self .timeout ,
62+ verify = self .verify ,
63+ proxy = proxy ,
64+ http_client = http_client ,
65+ )
3366 super ().__init__ (self .session )
3467
3568 def _create_session (
@@ -39,13 +72,19 @@ def _create_session(
3972 timeout : int ,
4073 verify : bool = True ,
4174 proxy : Optional [str ] = None ,
75+ http_client : Optional [AsyncClient ] = None ,
4276 ) -> AsyncClient :
77+ if http_client is not None :
78+ http_client .base_url = base_url
79+ http_client .headers .update ({** headers })
80+ return http_client
81+
4382 return AsyncClient (
4483 base_url = base_url ,
4584 headers = headers ,
4685 timeout = timeout ,
4786 proxy = proxy ,
48- verify = bool ( verify ) ,
87+ verify = verify ,
4988 follow_redirects = True ,
5089 http2 = True ,
5190 )
@@ -54,9 +93,6 @@ async def __aenter__(self) -> AsyncStorageClient:
5493 return self
5594
5695 async def __aexit__ (self , exc_type , exc , tb ) -> None :
57- await self .aclose ()
58-
59- async def aclose (self ) -> None :
6096 await self .session .aclose ()
6197
6298 def from_ (self , id : str ) -> AsyncBucketProxy :
0 commit comments