
    AHj                    v   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZmZmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ d d
l%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@mAZAmBZB ddlCmDZDmEZE ddl2mFZFmGZGmHZHmIZI ddlJmKZKmLZLmMZMmNZNmOZO ej                  dk\  r e"deEeE      ZQn
 e"deE      ZQer?d dlRmSZS  G d de!d       ZT G d! d"eeQ   e!d       ZU G d# d$e!d       ZV G d% d&eVd       ZWn G d' d(      ZX eX       ZSeYeZeZf   ZTe!ZUe!e!cZVZWed)   Z[ed*   Z\d8d+Z]d9d:d,Z^d9d;d-Z_ed.   Z`e G d/ d0             Zad<d1Zb G d2 d3eeQ         Zc G d4 d5eceQ         Zd G d6 d7eceQ         Zey)=    )annotationsN)AsyncGeneratorCallable	Generator)ThreadPoolExecutor)asynccontextmanagercontextmanagersuppress)	dataclass)	timedelta)BytesIO)TYPE_CHECKINGGenericLiteralOptional	TypedDictTypeVarUnioncast)urlparse   )	AsyncCurl)
CurlFollowCurlHttpVersionCurlInfoCurlOpt)Curl	CurlErrorCurlMime)CurlCffiWarning   )CookiesCookieTypes
CurlMorsel)RequestExceptionSessionClosed
code2error)HeadersHeaderTypes)BrowserTypeLiteralExtraFingerprintsExtraFpDict)
STREAM_ENDResponse)NOT_SETHttpVersionLiteral
NotSetTypeset_curl_options)AsyncWebSocketAsyncWebSocketContext	WebSocketWebSocketErrorWebSocketRetryStrategy)      R)bounddefault)r;   )Unpackc                  @    e Zd ZU ded<   ded<   ded<   ded<   ded<   y)	ProxySpecstrallhttphttpswswssN__name__
__module____qualname____annotations__     R/root/tools/cai/cai_env/lib/python3.12/site-packages/curl_cffi/requests/session.pyr?   r?   9   s    	
rL   r?   F)totalc                  :   e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   d	ed<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   d	ed<   d	ed<   d	ed<   ded <   ded!<   d"ed#<   ded$<   d%ed&<   d'ed(<   ded)<   d	ed*<   d+ed,<   d-ed.<   ded/<   ded0<   y1)2BaseSessionParamsOptional[HeaderTypes]headersOptional[CookieTypes]cookiesOptional[tuple[str, str]]authOptional[ProxySpec]proxiesOptional[str]proxy
proxy_authbase_urlOptional[dict]paramsboolverify!Union[float, tuple[float, float]]timeout	trust_envUnion[bool, CurlFollow, str]allow_redirectsintmax_redirectszUnion[int, RetryStrategy]retryOptional[BrowserTypeLiteral]impersonateja3akamaiperk/Optional[Union[ExtraFingerprints, ExtraFpDict]]extra_fpdefault_headers"Union[str, Callable[[bytes], str]]default_encodingcurl_optionszOptional[list]
curl_infos4Optional[Union[CurlHttpVersion, HttpVersionLiteral]]http_versiondebug	interface%Optional[Union[str, tuple[str, str]]]certOptional[type[R]]response_classdiscard_cookiesraise_for_statusNrF   rK   rL   rM   rP   rP   @   s    &&&&''$$--2255((11AA<<$$""JJ  33))rL   rP   c                  D   e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   d ed!<   ded"<   ded#<   ded$<   d%ed&<   ded'<   d(ed)<   d*ed+<   d,ed-<   ded.<   d/ed0<   d1ed2<   d3ed4<   d5ed6<   y7)8StreamRequestParams"Optional[Union[dict, list, tuple]]r^   AOptional[Union[dict[str, str], list[tuple], str, BytesIO, bytes]]dataOptional[dict | list]jsonrQ   rR   rS   rT   r]   filesrU   rV   3Optional[Union[float, tuple[float, float], object]]rb   &Optional[Union[bool, CurlFollow, str]]re   Optional[int]rg   rW   rX   rY   rZ   r[   Optional[bool]r`   refereraccept_encodingOptional[Callable]content_callbackri   rj   rk   rl   rm   rn   ro   rp   rq   rr   Union[str, Literal[False]]quoteru   rv   rx   ry   rz   rf   max_recv_speedOptional[CurlMime]	multipartr_   r}   NrF   rK   rL   rM   r   r   `   s    22OO##&&&&''DD??$$$$--&&,,11AA''<<))JJ  33%%rL   r   c                      e Zd ZU ded<   y)RequestParamsr   streamNrF   rK   rL   rM   r   r      s    rL   r   c                      e Zd Zed        Zy)_Unpackc                      y NrK   )argskwargss     rM   __getitem__z_Unpack.__getitem__   s    rL   N)rG   rH   rI   staticmethodr   rK   rL   rM   r   r      s    		 
	rL   r   )eventletgevent)	GETPOSTPUTDELETEOPTIONSHEADTRACEPATCHQUERYc                ^    t        |       }t        |j                  xr |j                        S )z,Check if the provided url is an absolute url)r   r_   schemehostname)url
parsed_urls     rM   _is_absolute_urlr      s'    #J
!!9j&9&9::rL   c                D    	 | j                   d   S # t        $ r |cY S w xY wNr   )queue
IndexErrorqr<   s     rM   _peek_queuer      s)    wwqz     c                D    	 | j                   d   S # t        $ r |cY S w xY wr   )_queuer   r   s     rM   _peek_aio_queuer      s)    xx{ r   linearexponentialc                  B    e Zd ZU ded<   dZded<   dZded<   dZded	<   y
)RetryStrategyrf   count        floatdelayjitterr   RetryBackoffbackoffN)rG   rH   rI   rJ   r   r   r   rK   rL   rM   r   r      s%    JE5FE$G\$rL   r   c                R   | d} t        | t              r| }n(t        | t              rt        |       }nt        d      |j                  dk  rt        d      |j                  dk  rt        d      |j                  dk  rt        d      |j                  dvrt        d      |S )	Nr   )r   z%retry must be an int or RetryStrategyzretry.count must be >= 0zretry.delay must be >= 0zretry.jitter must be >= 0r   z/retry.backoff must be 'linear' or 'exponential')	
isinstancer   rf   	TypeErrorr   
ValueErrorr   r   r   )rh   strategys     rM   _normalize_retryr      s    }%'	E3	 u-?@@~~344~~34445588JKKOrL   c                  4   e Zd ZdZddddddddddddddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	 	 	 	 	 	 	 	 	 	 	 	 dd
Zd ZddZedd       Z	e	j                  dd       Z	y)BaseSessionzMProvide common methods for setting curl options and reading info in sessions.NT   r   utf-8F)rR   rT   rV   rX   rZ   r[   r\   r^   r`   rb   rc   re   rg   rh   rj   rk   rl   rm   ro   rp   rr   rs   rt   rv   rw   rx   rz   r|   r}   r~   c                  t        |      | _        t        |      | _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        t        |      | _        || _        || _        || _        || _        || _        || _        || _        |xs i | _        |xs g | _        || _        || _        || _        || _        |!t7        |t8              du rt;        d| d      |xs t8        | _        || _        || _         |r|rt;        d      |rd|i}|xs i | _!        || _"        | j
                  r tG        | j
                        stI        d      d| _%        | j                  du s| j                  TtL        jN                  jQ                  d      xs- tL        jN                  jQ                  d	      xs | j                  | _        y y )
NFzZ`response_class` must be a subclass of `curl_cffi.requests.models.Response`, not of type ``z)Cannot specify both 'proxy' and 'proxies'rA   z2You need to provide an absolute url for 'base_url'TREQUESTS_CA_BUNDLECURL_CA_BUNDLE))r(   rR   r"   _cookiesrV   r\   r^   r`   rb   rc   re   rg   r   rh   rj   rk   rl   rm   ro   rp   rr   rs   rt   rv   rw   rx   rz   
issubclassr.   r   r|   r}   r~   rX   r[   r   r   _closedosenvironget)selfrR   rT   rV   rX   rZ   r[   r\   r^   r`   rb   rc   re   rg   rh   rj   rk   rl   rm   ro   rp   rr   rs   rt   rv   rw   rx   rz   r|   r}   r~   s                                  rM   __init__zBaseSession.__init__   s   D w'(	 ".*%e,
&	 . 0(.B$*(
"	%*^X*NRW*W  ./q2 
 -8. 0WGHHenG")-R$==!1$--!@QRR ;;$$++"5

34 ::>>"23;; K #6rL   c                   |}t        t        | j                  |            }t        t        |j	                  t
        j                              j                         |_        |r|j                         |_
        t        t        |j	                  t
        j                              |_        t        t        |j	                  t
        j                              |_        d|j                  cxk  xr dk  nc |_        |j                         j#                         }g }	|D ]  }
|
j%                         s|
j'                  d      r'|j)                  |
      j                         |_        g }	L|
j'                  d      s|
j'                  d      r|	dxx   |
z  cc<   ||	j-                  |
        t/        |	      |_        t3               |_        |j0                  j7                  d      }|D ]  }	 t8        j4                  j;                         }|j=                  |       |j?                         D ]g  \  }}|j4                  jA                  ||jB                  |jE                  dd	      |jE                  d
d      tG        |jE                  d                   i  |xs | jJ                  }|sZ|j	                  t
        jL                        D cg c]  }tO        jP                  |       }}| jR                  jU                  |       t        t        j	                  t
        jV                              j                         |_,        t        t        |j	                  t
        jZ                              |_.        t        t        |j	                  t
        j^                              j                         |_0        t        t        |j	                  t
        jb                              |_2        ||_3        ti        t        tj        |j	                  t
        jl                                    |_7        t        t        |j	                  t
        jp                              |_9        t        t        |j	                  t
        jt                              }	 |j                         |_;        t        t        |j	                  t
        jz                              |_>        t        t        |j	                  t
        j~                              |_@        t        t        |j	                  t
        j                              |_B        t        t        |j	                  t
        j                              |_D        |j|                  |j                  z   |_E        | j                  D ]   }|j	                  |      |j                  |<   " |S # tH        $ r Y w xY wc c}w # tx        $ r |j                  d      |_;        Y Nw xY w)N   i  s   HTTP/       	z
set-cookiedomain path/secure)r   r   r   )secondszlatin-1)Hr   r:   r|   bytesgetinfor   EFFECTIVE_URLdecoder   getvaluecontentrf   HTTP_VERSIONrv   RESPONSE_CODEstatus_codeok
splitlinesstrip
startswithget_reason_phrasereasonappendr(   rR   r"   rT   get_listrB   SimpleCookieloaditemssetvaluer   r_   	Exceptionr}   
COOKIELISTr$   from_curl_formatr   update_cookies_from_curl
PRIMARY_IP
primary_ipPRIMARY_PORTprimary_portLOCAL_IPlocal_ip
LOCAL_PORT
local_portrr   r   r   
TOTAL_TIMEelapsedREDIRECT_COUNTredirect_countREDIRECT_URLredirect_urlUnicodeDecodeErrorSIZE_DOWNLOAD_Tdownload_sizeSIZE_UPLOAD_Tupload_sizeHEADER_SIZEheader_sizeREQUEST_SIZErequest_sizeresponse_sizert   infos)r   curlbufferheader_bufferrr   r}   crspheader_linesheader_listheader_lineset_cookie_headers
set_cookiecookienamemorselmorselsredirect_url_bytesinfos                      rM   _parse_responsezBaseSession._parse_response&  sq    1d))!,-uaii(>(>?@GGI //+CKQYYx/D/D%EFsAIIh.D.D$EF-#-$--/::< $&' 	,K$$&%%h/00=DDF
 %%d+{/E/Ee/LB;.{+	, k* i [[11,?, 	J224J'$*LLN LD&KKOO%zz(B7#ZZ4#FJJx$89 $ 		  *AT-A-A89		(BUBU8V34
++A.G  MM227;eQYYx/B/B%CDKKMQYYx/D/D%EFE199X->->#?@GGIc199X-@-@#AB/UAIIh>Q>Q4R(ST!#qyy1H1H'IJ!%83H3H)IJ	D188:C !aii0H0H&IJsAIIh.D.D$EFsAIIh.B.B$CDQYYx/D/D%EF--? OO 	.DiioCIIdO	. 
E   " 	D188CC	Ds+   -B)V7WW 7	WWW/.W/c                2    | j                   rt        d      y )Nz'Session is closed, cannot send request.)r   r&   r   s    rM   _check_session_closedz!BaseSession._check_session_closed|  s    << IJJ rL   c                    | j                   }|j                  dk(  r|j                  d|dz
  z  z  }n|j                  |z  }|j                  r#|t	        j
                  d|j                        z  }|S )Nr   r   r!   r   )rh   r   r   r   randomuniform)r   attemptr   r   s       rM   _retry_delayzBaseSession._retry_delay  sc    ::},NNaGaK&89ENNW,E??V^^C99ErL   c                    | j                   S r   )r   r-  s    rM   rT   zBaseSession.cookies  s    }}rL   c                $    t        |      | _        y r   )r"   r   )r   rT   s     rM   rT   zBaseSession.cookies  s      (rL   )<rR   rQ   rT   rS   rV   rU   rX   rW   rZ   rY   r[   rU   r\   rY   r^   zOptional[dict[str, object]]r`   r_   rb   ra   rc   r_   re   rd   rg   rf   rh   #Optional[Union[int, RetryStrategy]]rj   ri   rk   rY   rl   rY   rm   rY   ro   rn   rp   r_   rr   rq   rs   zOptional[dict[CurlOpt, str]]rt   zOptional[list[object]]rv   ru   rw   r_   rx   rY   rz   ry   r|   r{   r}   r_   r~   r_   )r  r   r  r   r  r   rr   rq   r}   r_   returnr:   )r2  rf   r7  r   )r7  r"   )rT   r#   r7  None)rG   rH   rI   __doc__r   r+  r.  r3  propertyrT   setterrK   rL   rM   r   r      s5   W
 *.)-*.'+#04"&.2578<5648! $"DH $?F59-1MQ#'6:,0 %!&AW 'W '	W
 (W %W W .W  W ,W W 3W W 6W W  3!W" 2#W$ %W& 'W( )W* B+W, -W. =/W0 31W2 +3W4 K5W6 7W8 !9W: 4;W< *=W> ?W@ AWrTT T 	T
 =T T 
TlK   ^^) )rL   r   c                       e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 d fdZed        Zed        Zd ZddZ	ddZ
e	 	 	 	 	 	 	 	 dd	       Z	 	 	 	 d 	 	 	 d!d
Zd"dZdddddddeddddddddddddddddddddddddf 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#dZdddddddeddddddddddddddddddddddddf 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d$dZd%dZd%dZd%dZd%dZd%dZd%dZd%dZd%dZd%dZ xZS )&SessionzA request session, cookies and connections will be reused. This object is
    thread-safe, but it's recommended to use a separate session for each thread.Nc                `   t        |   di | || _        || _        d| _        d| _        |rat        j                         | _        |rd| _	        || j                  _
        yd| _	        t        | j                        | j                  _
        y|r|nt        | j                        | _        y)ag  
        Parameters set in the ``__init__`` method will be overridden by the same
        parameter in request method.

        Args:
            curl: curl object to use in the session. If not provided, a new one will be
                created. Also, a fresh curl object will always be created when accessed
                from another thread.
            thread: thread engine to use for working with other thread implementations.
                choices: eventlet, gevent.
            headers: headers to use in the session.
            cookies: cookies to add in the session.
            auth: HTTP basic auth, a tuple of (username, password), only basic auth is
                supported.
            proxies: dict of proxies to use, prefer to use proxy if they are the same.
                format: ``{"http": proxy_url, "https": proxy_url}``.
            proxy: proxy to use, format: "http://proxy_url".
                Cannot be used with the above parameter.
            proxy_auth: HTTP basic auth for proxy, a tuple of (username, password).
            base_url: absolute url to use as base for relative urls.
            params: query string for the session.
            verify: whether to verify https certs.
            timeout: how many seconds to wait before giving up.
            trust_env: use http_proxy/https_proxy and other environments, default True.
            allow_redirects: whether to allow redirection. Can be a bool, a
                ``CurlFollow`` value, or the string ``"safe"``. Use
                ``CurlFollow.SAFE`` or ``"safe"`` to reject redirects to
                internal/private IP addresses (SSRF protection).
            max_redirects: max redirect counts, default 30, use -1 for unlimited.
            retry: number of retries or ``RetryStrategy`` for failed requests.
            impersonate: which browser version to impersonate in the session.
            ja3: ja3 string to impersonate in the session.
            akamai: akamai string to impersonate in the session.
            perk: perk string to impersonate in the session.
            extra_fp: extra fingerprints options, in complement to ja3 and akamai str.
            interface: which interface use.
            default_encoding: encoding for decoding response content if charset is not
                found in headers. Defaults to "utf-8". Can be set to a callable for
                automatic detection.
            cert: a tuple of (cert, key) filenames for client cert.
            response_class: A customized subtype of ``Response`` to use.
            raise_for_status: automatically raise an HTTPError for 4xx and 5xx
                status codes.

        Notes:
            This class can be used as a context manager.

        .. code-block:: python

            from curl_cffi.requests import Session

            with Session() as s:
                r = s.get("https://example.com")
        NTFrw   rK   )superr   _thread_use_thread_local_curlr   	_executor	threadinglocal_local_is_customized_curlr  r   rw   _curl)r   r  threaduse_thread_local_curlr   	__class__s        rM   r   zSession.__init__  s    z 	"6"&;# #//+DK+/(#' +0(#'djj#9 !%4djj+ADJrL   c                &   | j                   rz| j                  rt        j                  dt        d       t        | j                  dd       s%t        | j                        | j                  _	        | j                  j                  S | j                  S )Nz/Creating fresh curl handle in different thread.r   )
stacklevelr  r?  )rB  rG  warningswarnr    getattrrF  r   rw   r  rH  r-  s    rM   r  zSession.curl  sj    &&''E# 
 4;;5#'djj#9 ;;###::rL   c                P    | j                   t               | _         | j                   S r   )rC  r   r-  s    rM   executorzSession.executor  s     >>!/1DN~~rL   c                    | S r   rK   r-  s    rM   	__enter__zSession.__enter__  s    rL   c                $    | j                          y r   closer   r   s     rM   __exit__zSession.__exit__  s    

rL   c                F    d| _         | j                  j                          y)Close the session.TN)r   r  rW  r-  s    rM   rW  zSession.close   s    		rL   c              +     K    | j                   d||d|ddi}	 | |j                          y# |j                          w xY ww)z6Equivalent to ``with request(..., stream=True) as r:``methodr   r   TNrK   )requestrW  r   r^  r   r   r  s        rM   r   zSession.stream  sC      dllI&cIVIDI	IIIKCIIKs   A2 AAAc                   | j                          | j                  j                         }| j                  j                          t	        |||||| j
                        }t        t        dz  |j                  d            }	|	,t        | j                        }
|
j                  |	       |
|d<   n| j                  |d<    |j                  |fi | |S )a"  Connects to a websocket url.

        Note: This method is deprecated, use WebSocket instead.

        Args:
            url: the ws url to connect.
            on_message: message callback, ``def on_message(ws, str)``
            on_error: error callback, ``def on_error(ws, error)``
            on_open: open callback, ``def on_open(ws)``
            on_close: close callback, ``def on_close(ws)``

        Other parameters are the same as ``.request``

        Returns:
            a WebSocket instance to communicate with the server.
        )r  
on_messageon_erroron_openon_closerw   NrT   )r.  r  	duphandleresetr5   rw   r   r"   r   rT   updateconnect)r   r   rb  rc  rd  re  r   r  rD   user_cookiesmerged_cookiess              rM   
ws_connectzSession.ws_connect  s    2 	""$yy""$		!!**
 GdNFJJy,AB#$T\\2N!!,/ .F9 $F9

3!&!	rL   c                6    | j                   j                         S r   )r  upkeepr-  s    rM   rn  zSession.upkeepF  s    yy!!rL   gzip, deflate, brr   r   r   Fc#           	        "-./012 |r5 j                   j                         . j                   j                         }#n j                   .t        .fi d|d|d j                  |gd j
                  d|d|d j                  |gd j                  |gd	|d
|	xs  j                  d|
t        u r j                  n|
d| j                  n|d| j                  n|d j                  |gd|d|xs  j                  d j                  |gd|d|d|d|xs  j                   d|xs  j"                  d|xs  j$                  d|xs  j&                  d|xs  j(                  d| j*                  n|d|d|xs  j,                  d|xs  j.                  d|d| d |!d!|xs  j0                  d" j2                  d#t4        j6                  d$t8        j:                  \  2-/10}$|rֈ-."/012 f	d%}% j<                  j?                  |%      }&0jA                           jC                  .-/"      }'tE        1      }(tG        |(tH              r4|$r|$jK                          |&jM                          .jO                          |(2|'_(        |&|'_)        |$|'_*        1|'_         jV                  r|'jW                          |'S 	  jX                  d&k(  r*d'd l-})|)j\                  j_                  .j`                         ne jX                  d(k(  rFd'd l1}*|*je                         jf                  ji                  .j`                        jk                          n.ja                           jC                  .-/"      }'2|'_(         jV                  r|'jW                          |'.j                          S # tl        $ r^}+ jC                  .-/"      }'2|'_(        to        |+jp                  ts        |+            }, |,ts        |+      |+jp                  |'      |+d }+~+ww xY w# .j                          w xY w))Nr^  r   params_listr\   r   r   headers_listcookies_listr   rV   rb   re   rg   proxies_listrZ   r[   verify_listr   r   r   rj   rk   rl   rm   ro   rp   r   rv   rx   r   r   r   rz   rs   queue_classevent_classc                   	 	 j                          t        t        j                        j                         s(t        t        j                        j                          j                  t               y # t        $ rU} 
j                        }	|_        j	                  t        t        |       | j                  |             Y d } ~ d } ~ ww xY w# t        t        j                        j                         s(t        t        j                        j                          j                  t               w xY wr   )performr   r+  r_  
put_nowaitr%   r@   coder   rD  Eventis_setr   putr-   )er  r  r  rr   r}   r  header_recvedr   reqr   s     rM   ry  z&Session._request_once.<locals>.perform  s    &IIK  	?FFHY__m<@@BEE*% ! H..6=2BOC #&CKLL!1#a&!&&#!FGGH  	?FFHY__m<@@BEE*%s+   A9 9	CACC CC A'Er   r   r   ):r  rf  rg  r2   r^   r\   rR   r   rV   r/   rb   re   rg   rX   r[   r`   rj   rk   rl   rm   ro   rp   rv   rx   rz   rs   r   QueuerD  r|  rR  submitwaitr+  r   r   r%   r   resultrW  r_  stream_taskquit_nowr~   rA  eventlet.tpooltpoolexecutery  r   get_hub
threadpoolspawnr   r   r'   r{  r@   )3r   r^  r   r^   r   r   rR   rT   r   rV   rb   re   rg   rX   rZ   r[   r`   r   r   r   rj   rk   rl   rm   ro   rp   rr   r   rv   rx   rz   r   r   r   r}   _r  ry  r  r  first_elementr   r   r  errorr  r  r  r  r   r  s3   `                         `       `          @@@@@@rM   _request_oncezSession._request_onceI  s   T 		##%A		!A		AAQ,B
,B
 ,B
 f-	,B

 ]],B
 ,B
 ,B
 ,,0,B
 --1,B
 ,B
 ",B
 %,w$6DLLG,B
 )8(?$$_,B
" '4&;""#,B
& ,,0',B
( ),B
* "4T__+,B
, f--,B
. /,B
0 ,1,B
2 .3,B
4 $7t'7'75,B
6 txx7,B
8 (T[[9,B
: ";,B
< .=,B
@ )8(?$$_A,B
D E,B
F &:):):G,B
H  14>>I,B
J K,B
L *M,B
N  O,B
P "Q,B
R **S,B
T U,B
V "W,B
>V]A}h\ & & --..w7K  &&6=*:OC
 (NM-)9:LLN""$	##CK)CO#CLCI$$$$&J<<:-)NN**1995\\X-!NN$//55aii@DDFIIK **v}.> "((((*	!  8**v}.> ""1663q62CFAFFC0a78  	s,   BO 79P+ 	P(
AP##P((P+ +P=c#                   | j                          | j                  }#t        |#j                  dz         D ]z  }$	  | j                  d%i d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d |d!| d"|!d#|"c S  y$# t
        $ r> |$|#j                  k(  r | j                  |$dz         }%|%rt        j                  |%       Y w xY w)&zESend the request, see ``requests.request`` for details on parameters.r!   r^  r   r^   r   r   rR   rT   r   rV   rb   re   rg   rX   rZ   r[   r`   r   r   r   rj   rk   rl   rm   ro   rp   rr   r   rv   rx   rz   r   r   r   r}   NrK   )	r.  rh   ranger   r  r%   r3  timesleep&r   r^  r   r^   r   r   rR   rT   r   rV   rb   re   rg   rX   rZ   r[   r`   r   r   r   rj   rk   rl   rm   ro   rp   rr   r   rv   rx   rz   r   r   r   r}   r   r2  r   s&                                         rM   r_  zSession.request  s   N 	""$::X^^a/0 +	&G*&)t)) #!## "# 	#
 # $# $#  # # $# %4# #0# $#  #  *#  "!#" $##$ %4%#& &6'#( !,)#* +#, "-#. /#0 &1#2 %43#4 &65#6  7#8 ".9#: (;#< =#> "?#@ $2A#B (C#D %4E# #+	&L $ &hnn,))'A+6JJu%&s   A5B33AC:9C:c                ,     | j                   dd|d|S Nr   r]  rK   r_  r   r   r   s      rM   headzSession.headF      t||=6s=f==rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   r   zSession.getI      t||<5c<V<<rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   postzSession.postL  r  rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   r~  zSession.putO  r  rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   patchzSession.patchR      t||>7>v>>rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   deletezSession.deleteU  s    t||?8???rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   optionszSession.optionsX  s    t||@9#@@@rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   tracezSession.trace[  r  rL   c                ,     | j                   dd|d|S Nr   r]  rK   r  r  s      rM   queryzSession.query^  r  rL   )NNT)
r  zOptional[Curl]rI  zOptional[ThreadType]rJ  r_   r   Unpack[BaseSessionParams[R]]r7  r8  r7  r8  )r^  
HttpMethodr   r@   r   Unpack[StreamRequestParams]r7  zGenerator[R, None, None])NNNN)r   r@   r7  r5   )r7  rf   )Fr^  r  r   r@   r^   zDOptional[Union[dict[str, object], list[object], tuple[object, ...]]]r   zNOptional[Union[dict[str, str], list[tuple[object, ...]], str, BytesIO, bytes]]r   r   rR   rQ   rT   rS   r   r]   rV   rU   rb   r   re   r   rg   r   rX   rW   rZ   rY   r[   rU   r`   r   r   rY   r   rY   r   zOptional[Callable[..., object]]rj   ri   rk   rY   rl   rY   rm   rY   ro   rn   rp   r   rr   rq   r   r   rv   +CurlHttpVersion | HttpVersionLiteral | Nonerx   rY   rz   ry   r   r   r   rf   r   r   r}   r_   r7  r:   )Dr^  r  r   r@   r^   r   r   r   r   r   rR   rQ   rT   rS   r   r]   rV   rU   rb   r   re   r   rg   r   rX   rW   rZ   rY   r[   rU   r`   r   r   rY   r   rY   r   r   rj   ri   rk   rY   rl   rY   rm   rY   ro   rn   rp   r   rr   rq   r   r   rv   ru   rx   rY   rz   ry   r   r   r   rf   r   r   r}   r_   r   r@   r   zUnpack[RequestParams]r7  r:   )rG   rH   rI   r9  r   r:  r  rR  rT  rY  rW  r	   r   rl  rn  r/   r  r_  r  r   r  r~  r  r  r  r  r  __classcell__rK  s   @rM   r=  r=    s   T
  $'+&*	KBKB %KB  $	KB
 /KB 
KBZ    

   .	
 
"   11 
1f"  &*)-)- $*.GNBF'+'+#04!%!%)<<@48! $"DH*.?F,.DH#'6:!%(, %Odd d
	d
d $d 'd 'd d (d Ed  @!d" %#d$ %%d& 'd( .)d* +d, -d. '/d0 :1d2 23d4 5d6 7d8 9d: B;d< (=d> =?d@ *AdB BCdD !EdF 4GdH IdJ KdL &MdN OdP 
QdT 6:RV&*)-)- $*.GNBF'+'+#04!%!%)</348! $"DH*.?F,.MQ#'6:!%(, %GU&U& U& 3	U&
 PU& $U& 'U& 'U& U& (U& EU& @U& %U& %U& U&  .!U&" #U&$ %U&& ''U&( -)U&* 2+U&, -U&. /U&0 1U&2 B3U&4 (5U&6 =7U&8 *9U&: K;U&< !=U&> 4?U&@ AU&B CU&D &EU&F GU&n>=>=?@A??rL   r=  c            $          e Zd ZdZdddd	 	 	 	 	 	 	 	 	 d' fdZed(d       Zed)d       Zd Zd*d	Z	d+d
Z
d Zd,dZd,dZd-dZe	 	 	 	 	 	 	 	 d.d       Zdddddeddddddddddddddddddddddddddddddf$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/dZdddddddeddddddddddddddddddddddddf 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0dZdddddddeddddddddddddddddddddddddf 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0dZd1dZd1dZd1d Zd1d!Zd1d"Zd1d#Zd1d$Zd1d%Zd1d&Z xZS )2AsyncSessionzAAn async request session, cookies and connections will be reused.N
   )loop
async_curlmax_clientsc               n    t        |   di | || _        || _        || _        | j                          y)a  
        Parameters set in the ``__init__`` method are overridden by the same parameter
        in request method.

        Parameters:
            loop: loop to use, if not provided, the running loop will be used.
            async_curl: [AsyncCurl](/api/curl_cffi#curl_cffi.AsyncCurl) object to use.
            max_clients: maxmium curl handle to use in the session,
                this will affect the concurrency ratio.
            headers: headers to use in the session.
            cookies: cookies to add in the session.
            auth: HTTP basic auth, a tuple of (username, password), only basic auth is
                supported.
            proxies: dict of proxies to use, prefer to use ``proxy`` if they are the
                same. format: ``{"http": proxy_url, "https": proxy_url}``.
            proxy: proxy to use, format: "http://proxy_url".
                Cannot be used with the above parameter.
            proxy_auth: HTTP basic auth for proxy, a tuple of (username, password).
            base_url: absolute url to use for relative urls.
            params: query string for the session.
            verify: whether to verify https certs.
            timeout: how many seconds to wait before giving up.
            trust_env: use http_proxy/https_proxy and other environments, default True.
            allow_redirects: whether to allow redirection. Can be a bool, a
                ``CurlFollow`` value, or the string ``"safe"``. Use
                ``CurlFollow.SAFE`` or ``"safe"`` to reject redirects to
                internal/private IP addresses (SSRF protection).
            max_redirects: max redirect counts, default 30, use -1 for unlimited.
            retry: number of retries or ``RetryStrategy`` for failed requests.
            impersonate: which browser version to impersonate in the session.
            ja3: ja3 string to impersonate in the session.
            akamai: akamai string to impersonate in the session.
            perk: perk string to impersonate in the session.
            extra_fp: extra fingerprints options, in complement to ja3 and akamai str.
            default_encoding: encoding for decoding response content if charset is not
                found in headers. Defaults to "utf-8". Can be set to a callable for
                automatic detection.
            cert: a tuple of (cert, key) filenames for client cert.
            response_class: A customized subtype of ``Response`` to use.
            raise_for_status: automatically raise an HTTPError for 4xx and 5xx
                status codes.

        Notes:
            This class can be used as a context manager, and it's recommended to use via
            ``async with``.
            However, unlike aiohttp, it is not required to use ``with``.

        .. code-block:: python

            from curl_cffi.requests import AsyncSession

            # recommended.
            async with AsyncSession() as s:
                r = await s.get("https://example.com")

            s = AsyncSession()  # it also works.
        NrK   )r@  r   _loop_acurlr  	init_pool)r   r  r  r  r   rK  s        rM   r   zAsyncSession.__init__e  s6    B 	"6"7;
(2 +rL   c                d    | j                   t        j                         | _         | j                   S )z"Returns a reference to event loop.)r  asyncioget_running_loopr-  s    rM   r  zAsyncSession.loop  s(     :: 113DJzzrL   c                h    | j                   t        | j                        | _         | j                   S )N)r  )r  r   r  r-  s    rM   acurlzAsyncSession.acurl  s&    ;;#3DK{{rL   c                    t        j                  | j                        | _        	 	 | j                  j	                  d        # t         j
                  $ r Y y w xY wr   )r  	LifoQueuer  poolrz  	QueueFullr-  s    rM   r  zAsyncSession.init_pool  sS    4;4E4EdFVFV4W			$$T*  $$ s   A AAc                   K   | j                   j                          d {   }|t        | j                        }|S 7 w)Nr?  )r  r   r   rw   r   r  s     rM   pop_curlzAsyncSession.pop_curl  s5     "&))--/1<djj)D 2s   A?Ac                    t        t        j                        5  | j                  j	                  |       d d d        y # 1 sw Y   y xY wr   )r
   r  r  r  rz  r  s     rM   	push_curlzAsyncSession.push_curl  s7    g''( 	'II  &	' 	' 	's	   ?Ac                   K   | S wr   rK   r-  s    rM   
__aenter__zAsyncSession.__aenter__  s     s   c                @   K   | j                          d {    y 7 wr   rV  rX  s     rM   	__aexit__zAsyncSession.__aexit__  s     jjl 	s   c                   K   | j                   j                          d{    d| _        	 	 | j                  j	                         }|r|j                          .7 :# t
        j                  $ r Y yw xY ww)r[  NT)r  rW  r   r  
get_nowaitr  
QueueEmptyr  s     rM   rW  zAsyncSession.close  sl     jj   yy++-JJL	  	! %% s2   A6AA6,A A6A30A62A33A6c                    |j                          | j                  s=| j                  j                  |       |j	                          | j                  |       y |j                          y r   )clean_handles_and_buffersr   r  remove_handlerg  r  rW  r  s     rM   release_curlzAsyncSession.release_curl  sE    &&(||JJ$$T*JJLNN4 JJLrL   c                  K    | j                   d||d|ddi d{   }	 | |j                          d{    y7 #7 # |j                          d{  7   w xY ww)z<Equivalent to ``async with request(..., stream=True) as r:``r]  r   TNrK   )r_  acloser`  s        rM   r   zAsyncSession.stream  s^      !DLLOCO6O$OO	I**,	 P #**,sA   A%AA%A A%AA%A%A"AA""A%Tro  r   r          Fg{Gzt?gMbP?i  @ c&           &         	
 !"#$% d$%#"	
  !f%d}&t         |&             S )a  Connects to a WebSocket.

        Args:
            url: url for the requests.
            autoclose: whether to close the WebSocket after receiving a close frame.
            params: query string for the requests.
            headers: headers to send.
            cookies: cookies to use.
            auth: HTTP basic auth, a tuple of (username, password), only basic auth is
                supported.
            timeout: how many seconds to wait before giving up.
            allow_redirects: whether to allow redirection. Can be a bool, a
                ``CurlFollow`` value, or the string ``"safe"``. Use
                ``CurlFollow.SAFE`` or ``"safe"`` to reject redirects to
                internal/private IP addresses (SSRF protection).
            max_redirects: max redirect counts, default 30, use -1 for unlimited.
            proxies: dict of proxies to use, prefer to use ``proxy`` if they are the
                same. format: ``{"http": proxy_url, "https": proxy_url}``.
            proxy: proxy to use, format: "http://user@pass:proxy_url".
                Can't be used with `proxies` parameter.
            proxy_auth: HTTP basic auth for proxy, a tuple of (username, password).
            verify: whether to verify https certs.
            referer: shortcut for setting referer header.
            accept_encoding: shortcut for setting accept-encoding header.
            impersonate: which browser version to impersonate.
            ja3: ja3 string to impersonate.
            akamai: akamai string to impersonate.
            perk: perk string to impersonate.
            extra_fp: extra fingerprints options, in complement to ja3 and akamai str.
            default_headers: whether to set default browser headers.
            quote: Set characters to be quoted, i.e. percent-encoded. Default safe
                string is ``!#$%&'()*+,/:;=?@[]~``. If set to a string, the character
                will be removed from the safe string, thus quoted. If set to False, the
                url will be kept as is, without any automatic percent-encoding, you must
                encode the URL yourself.
            http_version: limiting http version, defaults to http2.
            interface: which interface to use.
            cert: a tuple of (cert, key) filenames for client cert.
            max_recv_speed: maximum receive speed, bytes per second.
            recv_queue_size: The maximum number of incoming WebSocket
                messages to buffer internally. This queue stores messages received by
                the Curl socket that are waiting to be consumed on calling ``recv()``.
            send_queue_size: The maximum number of outgoing WebSocket
                messages to buffer before applying network backpressure. When you call
                ``send()`` the message is placed in this queue and transmitted when
                the Curl socket is next available for sending.
            max_send_batch_size: The max batch size for sent frames.
            coalesce_frames: When set, multiple pending messages in the send queue
                may be merged into a single WebSocket frame for improved throughput.
                **Warning:** This breaks the one-to-one mapping of ``send()`` calls
                to frames and should only be used when the application protocol is
                designed to handle concatenated data streams. Defaults to ``False``.
            ws_retry (WebSocketRetryStrategy): Retry policy for WebSocket messages.
            recv_time_slice: The maximum duration (in seconds) to process incoming
                messages before yielding to the event loop.
                Defaults to ``0.005`` (5ms).
            send_time_slice: The maximum duration (in seconds) to process outgoing
                messages before yielding to the event loop.
                Defaults to ``0.001`` (1ms).
            max_message_size: Maximum allowed size for a complete received
                WebSocket message (default: ``4 MiB``).
            drain_on_error: If ``True``, when a connection error occurs,
            attempt to consume all the buffered received messages first,
            before raising the error. Otherwise, raise it immediately (default).
            block_on_recv_queue_full (bool, optional): If ``False``, the connection
                is failed immediately when the receive queue is full. The message that
                caused the overflow is not delivered; any messages already buffered may
                still be drained if ``drain_on_error=True``.
            curl_options: extra curl options to use.
        c                 v  %K   !j                          !j                          d {   } t        d#i d| ddd%d!j                  d!j                  gd!j
                  gd!j                  gd	xs !j                  d
$t        u r!j                  n$d!j                  nd!j                  nd!j                  gddxs !j                  d!j                  &gd ddxs !j                  dxs !j                   dxs !j"                  dxs !j$                  d!j&                  nddxs !j(                  dxs !j*                  dd	xs !j,                  dt.        j0                  dt.        j2                  d}| j5                  t6        j8                  d       }| j5                  t6        j:                  d!      }	 !j<                  j?                  d | j@                         d {   }tI        tK        tL        tN           !      | "
'#!jP                  "      }	 |jS                          |S 7 @7 R# tB        $ r# | jE                          !jG                  d         w xY w# tT        $ r |jW                           w xY ww)$Nr  r^  r   r   r\   rq  rr  rs  rV   rb   re   rg   rt  rZ   r[   ru  r   r   rj   rk   rl   ro   rp   r   rv   rx   r   rz   rv  rw  rs   r!   r   )	autocloserecv_queue_sizesend_queue_sizemax_send_batch_sizecoalesce_framesws_retryrecv_time_slicesend_time_slicemax_message_sizedrain_on_errorblock_on_recv_queue_fullrw   rK   ),r.  r  r2   r\   r^   rR   rT   rV   r/   rb   re   rg   rX   r[   r`   rj   rk   rl   ro   rp   rv   rx   rz   r  r  r|  setoptr   TCP_NODELAYCONNECT_ONLYr  run_in_executorry  r   rW  r  r3   r   r  r.   rw   _start_io_tasksr6   	terminate)(r  r  rD   r   rl   re   rV   r  r  rz   r  rT   rs   rp   r  ro   rR   rv   rj   rx   rk   r  r   rg   r  r^   rX   rZ   r[   r   r  r  r   r   r  r  rb   r   r`   r  s(      rM   _connect_coroz.AsyncSession.ws_connect.<locals>._connect_corod  s.    &&(#}}.D  %%% % 	%
 "[[&1% #llG4% #llG4% &TYY% )07(:% -<,CD((% +8*?D&&]%  #llG4!%" #%$ &8%%& "[[&1'%(  )%* !0+%, (;4+;+;-%. O488/%0 ,1%2 "2T]]3%6 -<,CD((7%: ;%< *>T->->=%> $5t~~?%@  .A%B &TYYC%D $MME%F $MMG%H *I%AL G//3A$$A
))33D$,,GG "0\(+T2# / /$7 /! / /!1-)Ajj"B"""$
 IW /\ H 

t$0 " sR   $J9I'GJ9.)I, I*I, 8J9J %J9*I, ,,JJ9J66J9)r7  r3   )r4   )'r   r   r  r^   rR   rT   rV   rb   re   rg   rX   rZ   r[   r`   r   r   rj   rk   rl   rm   ro   rp   r   rv   rx   rz   r   r  r  r  r  r  r  r  r  r  r  rs   r  s'   ``````````````````` `````````````````` rM   rl  zAsyncSession.ws_connect  s<    ^N	 N	 N	 N	 N	 N	` %]_55rL   r   c#                   "+,-./01K    j                          d {   ,t        d(i d,d|d|d j                  |gd j                  d|d|d j                  |gd	 j
                  |gd
|d|	xs  j                  d|
t        u r j                  n|
d| j                  n|d| j                  n|d j                  |gd|d|xs  j                  d j                  |gd|d|d|d|xs  j                  d|xs  j                  d|xs  j                   d|xs  j"                  d|xs  j$                  d| j&                  n|d|d|xs  j(                  d|xs  j*                  d|d | d!|!d"|xs  j,                  d# j.                  d$t0        j2                  d%t0        j4                  \  0+-/.}#|r j6                  j9                  ,      1d)+,"-./0 1f
d&}$, fd'}%t1        j:                   |$             }&|&j=                  |%       t?        t0        j4                  .      jA                          d {     jC                  ,+-"      }'tE        /      }(tG        |(tH              r jK                  ,       |(0|'_&        |&|'_'        |#|'_(        /|'_)         jT                  r|'jU                          |'S 	  j6                  j9                  ,      11 d {     jC                  ,+-"      }'0|'_&         jT                  r|'jU                          |' jK                  ,       S 7 67 7 T# tV        $ r^}) jC                  ,+-"      }'0|'_&        tY        |)jZ                  t]        |)            }* |*t]        |)      |)jZ                  |'      |)d })~)ww xY w#  jK                  ,       w xY ww)*Nr  r^  r   rq  r\   r   r   rr  rs  r   rV   rb   re   rg   rt  rZ   r[   ru  r   r   r   rj   rk   rl   rm   ro   rp   r   rv   rx   r   r   r   rz   rs   rv  rw  c                   
K   	  d {    t        t        j                        j                         s(t        t        j                        j                          j                  t               d {    y 7 r# t         $ rU} 
j                        }	|_        j                  t	        t        |       | j                  |             Y d } ~ d } ~ ww xY w7 h# t        t        j                        j                         s(t        t        j                        j                          j                  t               d {  7   w xY wwr   )r   r+  r_  rz  r%   r@   r{  r   r  r|  r}  r   r~  r-   )r  r  r  r  rr   r}   r  r  r   r  r   tasks     rM   ry  z+AsyncSession._request_once.<locals>.perform  s     ,JJ  }=DDFW]]M:>>@%%
+++   H..fm5EC #&CKLL!1#a&!&&#!FGGH ,  }=DDFW]]M:>>@%%
+++sj   EA? A=A? A(E7C 8E=A? ?	CACC" CC"  E"A)EEEEc                (    j                         y r   )r  )futr  r   s    rM   cleanupz+AsyncSession._request_once.<locals>.cleanup  s    !!$'rL   rK   r  )/r  r2   r^   r\   rR   rT   rV   r/   rb   re   rg   rX   r[   r`   rj   rk   rl   rm   ro   rp   rv   rx   rz   rs   r  r  r|  r  
add_handlecreate_taskadd_done_callbackr   r  r+  r   r   r%   r  r_  astream_taskr  r   r~   r   r'   r{  r@   )2r   r^  r   r^   r   r   rR   rT   r   rV   rb   re   rg   rX   rZ   r[   r`   r   r   r   rj   rk   rl   rm   ro   rp   rr   r   rv   rx   rz   r   r   r   r}   r  ry  r  r  r  r  r  r  r  r  r  r  r   r  r  s2   `                         `       `        @@@@@@@rM   r  zAsyncSession._request_once  s    J ]]_$AQ ,B
,B
,B
 ,B
 f-	,B

 ]],B
 ,B
 ,B
 ,,0,B
 ,,0,B
 ,B
 ",B
 %,w$6DLLG,B
 )8(?$$_,B
" '4&;""#,B
& ,,0',B
( ),B
* "4T__+,B
, f--,B
. /,B
0 ,1,B
2 .3,B
4 $7t'7'75,B
6 txx7,B
8 (T[[9,B
: ";,B
< .=,B
@ )8(?$$_A,B
D E,B
F &:):):G,B
H  14>>I,B
J K,B
L *M,B
N  O,B
P "Q,B
R **S,B
T  U,B
V  W,B
>V]A}hZ ::((.D, ,( "--gi8K))'2w}}m499;;; &&fm-=C ,A.M-)9:!!$'##CK*C#CLCI$$$$&J(zz,,T2

 **&-1A? "((((*!!$'_ %J <2  8**&-1A? ""1663q62CFAFFC0a78  !!$'sl   OMIO#M$BO& M MM 9O OOM 	O&AN??OO OOc#                (  K   | j                          | j                  }#t        |#j                  dz         D ]  }$	  | j                  d%i d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d |d!| d"|!d#|" d${   c S  y$7 # t
        $ rG |$|#j                  k(  r | j                  |$dz         }%|%rt        j                  |%       d${  7   Y w xY ww)&zISend the request, see ``curl_cffi.requests.request`` for details on args.r!   r^  r   r^   r   r   rR   rT   r   rV   rb   re   rg   rX   rZ   r[   r`   r   r   r   rj   rk   rl   rm   ro   rp   rr   r   rv   rx   rz   r   r   r   r}   NrK   )	r.  rh   r  r   r  r%   r3  r  r  r  s&                                         rM   r_  zAsyncSession.requestL  s    N 	""$::X^^a/0 +	/G*//T// #!## "# 	#
 # $# $#  # # $# %4# #0# $#  #  *#  "!#" $##$ %4%#& &6'#( !,)#* +#, "-#. /#0 &1#2 %43#4 &65#6  7#8 ".9#: (;#< =#> "?#@ $2A#B (C#D %4E# # #+	/#H $ /hnn,))'A+6!--.../sH   8DA9B?4B=5B?8D=B??ADD	DDDDc                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r  zAsyncSession.head  '     !T\\CSCFCCCC   " "c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r   zAsyncSession.get  '     !T\\BCB6BBBBr  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r  zAsyncSession.post  r  r  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r~  zAsyncSession.put  r  r  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r  zAsyncSession.patch  '     !T\\DcDVDDDDr  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r  zAsyncSession.delete  s'     !T\\EsEfEEEEr  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r  zAsyncSession.options  s'     !T\\FFvFFFFr  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r  zAsyncSession.trace  r  r  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rM   r  zAsyncSession.query  r  r  )
r  z asyncio.AbstractEventLoop | Noner  zAsyncCurl | Noner  rf   r   r  r7  r8  )r7  zasyncio.AbstractEventLoop)r7  r   )r7  r   )r  zCurl | Noner7  r8  r  )r  r   r7  r8  )r^  r  r   r@   r   r  r7  zAsyncGenerator[R, None, None])Lr   r@   r  r_   r^   z<dict[str, object] | list[object] | tuple[object, ...] | NonerR   zHeaderTypes | NonerT   zCookieTypes | NonerV   tuple[str, str] | Nonerb   z/float | tuple[float, float] | NotSetType | Nonere   zbool | CurlFollow | str | Nonerg   z
int | NonerX   zProxySpec | NonerZ   
str | Noner[   r  r`   bool | Noner   r  r   r  rj   zBrowserTypeLiteral | Nonerk   r  rl   r  rm   r  ro   z&ExtraFingerprints | ExtraFpDict | Nonerp   r  r   zstr | Literal[False]rv   r  rx   r  rz   zstr | tuple[str, str] | Noner   rf   r  rf   r  rf   r  rf   r  r_   r  zWebSocketRetryStrategy | Noner  r   r  r   r  rf   r  r_   r  r_   rs   zdict[CurlOpt, str] | Noner7  r4   )Fr^  r  r   r@   r^   r   r   r   r   r   rR   rQ   rT   rS   r   r]   rV   rU   rb   r   re   r   rg   r   rX   rW   rZ   rY   r[   rU   r`   r   r   rY   r   rY   r   r   rj   ri   rk   rY   rl   rY   rm   rY   ro   rn   rp   r   rr   rq   r   r   rv   ru   rx   rY   rz   ry   r   r   r   rf   r   r   r}   r_   r7  r:   r  )rG   rH   rI   r9  r   r:  r  r  r  r  r  r  r  rW  r  r   r   r/   rl  r  r_  r  r   r  r~  r  r  r  r  r  r  r  s   @rM   r  r  b  s#   K
 26'+E /E %	E
 E /E 
EN    
'
   .	
 
'   OS&*&*'+CJ:>$($( -1""&915!;?'+&(DH $-1!!#% %26!&!& /$)-26M66 6 M	6
 $6 $6 %6 A6 86 "6 "6 6 +6 6 6  $!6" /#6$ %6& '6( )6* 9+6, %-6. $/60 B162 364 +566 768 96: ;6< !=6> ?6@ 0A6B C6D E6F G6H I6J #'K6L 0M6N 
O6J 6:RV&*)-)- $*.GNBF'+'+#04!%!%)</348! $"DH*.?F,.MQ#'6:!%(, %GT(T( T( 3	T(
 PT( $T( 'T( 'T( T( (T( ET( @T( %T( %T( T(  .!T(" #T($ %T(& ''T(( -)T(* 2+T(, -T(. /T(0 1T(2 B3T(4 (5T(6 =7T(8 *9T(: K;T(< !=T(> 4?T(@ AT(B CT(D &ET(F GT(H 
IT(t 6:RV&*)-)- $*.GNBF'+'+#04!%!%)</348! $"DH*.?F,.MQ#'6:!%(, %GU/U/ U/ 3	U/
 PU/ $U/ 'U/ 'U/ U/ (U/ EU/ @U/ %U/ %U/ U/  .!U/" #U/$ %U/& ''U/( -)U/* 2+U/, -U/. /U/0 1U/2 B3U/4 (5U/6 =7U/8 *9U/: K;U/< !=U/> 4?U/@ AU/B CU/D &EU/F GU/H 
IU/nDCDCEFGEErL   r  )r   r@   r7  r_   r   )r   zqueue.Queue)r   zasyncio.Queue)rh   r6  r7  r   )f
__future__r   r  http.cookiesrB   r   r   r0  sysrD  r  rN  collections.abcr   r   r   concurrent.futuresr   
contextlibr   r	   r
   dataclassesr   datetimer   ior   typingr   r   r   r   r   r   r   r   urllib.parser   aior   constr   r   r   r   r  r   r   r   utilsr    rT   r"   r#   r$   
exceptionsr%   r&   r'   rR   r(   r)   rj   r*   r+   r,   modelsr-   r.   r/   r0   r1   r2   
websocketsr3   r4   r5   r6   r7   version_infor:   typing_extensionsr=   r?   rP   r   r   r   dictr@   
ThreadTyper  r   r   r   r   r   r   r   r=  r  rK   rL   rM   <module>r(     s   "   	   
    ? ? 1 D D !  	 	 	 "  B B , , # 5 5 C C ) K K ( L L  w8X6A8$A(IU GAJ	 @iu B+5 
 
 YFS#XI!)2I&)*
P

; ./ % % %(G)'!* G)TK?k!n K?\Z	E;q> Z	ErL   