
    T>qj                      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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%m&Z& d d
l'm(Z( 	 d dlm)Z) ddl,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@mAZAmBZB ddlCmDZDmEZE ddlFmGZGmHZHmIZI ddlJmKZK ddlLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZU ddl7mVZVmWZWmXZXmYZY ddlZm[Z[m\Z\m]Z]m^Z^m_Z_ ej                  dk\  r e$deKeK      Zan
 e$deK      ZaerEd dl+m)Z) ddlbmcZc  G d  d!e#d"#      Zd G d$ d%e ea   e#d"#      Ze G d& d'e#d"#      Zf G d( d)efd"#      Zgn G d* d+      Zh eh       Z)eiejejf   Zde#Zee#e#cZfZge!d,   Zke!d-   Zld9d.Zme!d/   Zne G d0 d1             Zod:d2Zp G d3 d4e ea         Zq G d5 d6eqea         Zr G d7 d8eqea         Zsy# e*$ r
 d dl+m)Z) Y nw xY w);    )annotationsN)AsyncGeneratorAsyncIterableCallable	Generator)ThreadPoolExecutor)asynccontextmanagercontextmanagersuppress)	dataclass)	timedelta)BytesIO)	TYPE_CHECKINGAnyGenericLiteralOptional	TypedDictTypeVarUnioncast)urlparse)Unpack   )	AsyncCurl)
CurlFollowCurlHttpVersionCurlInfoCurlOpt)Curl	CurlErrorCurlMime)CurlCffiWarning   )	CacheSpecnormalize_cache_backend)CookiesCookieTypes)RequestExceptionSessionClosed
code2error)HeadersHeaderTypes)BrowserTypeLiteralExtraFingerprintsExtraFpDict)Response)	
STREAM_ENDRequestContentRequestDataSyncRequestContent_AsyncIterableReader_capture_body_position_peek_aio_queue_peek_queue_rewind_body)NOT_SETHttpVersionLiteral
NotSetTypeset_curl_options)AsyncWebSocketAsyncWebSocketContext	WebSocketWebSocketErrorWebSocketRetryStrategy)      R)bounddefault)rG   )Fingerprintc                  @    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__     Y/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/curl_cffi/requests/session.pyrK   rK   W   s    	
rX   rK   F)totalc                  N   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<   ded1<   d2ed3<   y4)5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]retry5Optional[Union[BrowserTypeLiteral, str, Fingerprint]]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doh_url%Optional[Union[str, tuple[str, str]]]certOptional[type[R]]response_classdiscard_cookiesraise_for_statusOptional[CacheSpec]cacheNrR   rW   rX   rY   r\   r\   ^   s    &&&&''$$--2255((JJAA<<$$""JJ  33))""rX   r\   c                  X   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<   ded1<   d2ed3<   d4ed5<   d6ed7<   d8ed9<   y:);StreamRequestParams"Optional[Union[dict, list, tuple]]rj   Optional[RequestData]dataOptional[RequestContent]contentOptional[dict | list]jsonr]   r^   r_   r`   ri   filesra   rb   3Optional[Union[float, tuple[float, float], object]]rn   &Optional[Union[bool, CurlFollow, str]]rq   Optional[int]rs   rc   rd   re   rf   rg   Optional[bool]rl   refereraccept_encodingOptional[Callable]content_callbackru   rv   rw   rx   ry   rz   r{   r|   r}   r~   Union[str, Literal[False]]quoter   r   r   r   r   r   rr   max_recv_speedOptional[CurlMime]	multipartrk   r   NrR   rW   rX   rY   r   r      s    22##))##&&&&''DD??$$$$--&&,,JJAA''<<))JJ  33%%rX   r   c                      e Zd ZU ded<   y)RequestParamsr   streamNrR   rW   rX   rY   r   r      s    rX   r   c                      e Zd Zed        Zy)_Unpackc                      y NrW   )argskwargss     rY   __getitem__z_Unpack.__getitem__   s    rX   N)rS   rT   rU   staticmethodr   rW   rX   rY   r   r      s    		 
	rX   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   rk   schemehostname)url
parsed_urls     rY   _is_absolute_urlr      s'    #J
!!9j&9&9::rX   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
)RetryStrategyrr   count        floatdelayjitterr   RetryBackoffbackoffN)rS   rT   rU   rV   r   r   r   rW   rX   rY   r   r      s%    JE5FE$G\$rX   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   rr   	TypeErrorr   
ValueErrorr   r   r   )rt   strategys     rY   _normalize_retryr      s    }%'	E3	 u-?@@~~344~~34445588JKKOrX   c            !      T   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 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	 	 	 	 	 	 	 	 	 	 	 	 dd
Zd Z	 	 	 	 	 	 d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) r^   r`   rb   rd   rf   rg   rh   rj   rl   rn   ro   rq   rs   rt   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   r   r   c                   t        |      | _        t        |      | _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        t        |      | _        || _        || _        || _        || _        || _        || _        || _        |xs i | _        |xs g | _        || _        || _        || _        || _        || _        t9        |       | _        |!t=        |t>              du rtA        d| d      |xs t>        | _!        || _"        || _#        |r|rtA        d      |rd|i}|xs i | _$        || _%        | j
                  r tM        | j
                        stO        d      d| _(        | j                  du s| j                  TtR        jT                  jW                  d      xs- tR        jT                  jW                  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'rM   z2You need to provide an absolute url for 'base_url'TREQUESTS_CA_BUNDLECURL_CA_BUNDLE),r,   r^   r'   _cookiesrb   rh   rj   rl   rn   ro   rq   rs   r   rt   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r&   _cache
issubclassr1   r   r   r   r   rd   rg   r   r   _closedosenvironget)!selfr^   r`   rb   rd   rf   rg   rh   rj   rl   rn   ro   rq   rs   rt   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   r   r   s!                                    rY   __init__zBaseSession.__init__   s   H w'(	 ".*%e,
&	 . 0(.B$*(
"	-e4%*^X*NRW*W  ./q2 
 -8. 0WGHHenG")-R$==!1$--!@QRR ;;$$++"5

34 ::>>"23;; K #6rX   c                0   |}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 }	g }
d}d}|D ]  }|j%                         s|j'                  d      rY|r|
j)                  |||	f       	 t        |j+                  d      d         }|j1                  |      j                  d	
      }g }	~|j'                  d      s|j'                  d      r|	dxx   |z  cc<   |	j)                  |        |r|
j)                  |||	f       |
r|
d   \  }|_        }	t5        |	      |_        t        t8        t           |j	                  t
        j:                              }d}|D ]  }	 |j+                  dd      \  }}t        |      }|j                  d	
      }d}t5               }t?        |tA        |
            D ]$  }|
|   \  }}}||k(  s|}t5        |      }|dz   } n t        t        | j                  d             }||_        ||_        ||_        d|cxk  xr dk  nc |_        ||_        ||_!        |jD                  j)                  |        tG               |_$        |j6                  jK                  d      }|D ]  }	 tL        jH                  jO                         }|jQ                  |       |jS                         D ]g  \  } }!|jH                  jU                  | |!jV                  |!jY                  dd      |!jY                  dd      t[        |!jY                  d                   i  |xs | j^                  }|sOt        t8        t           |j	                  t
        j`                              }"| jb                  je                  |"       t        t        |j	                  t
        jf                              j                         |_4        t        t        |j	                  t
        jj                              |_6        t        t        |j	                  t
        jn                              j                         |_8        t        t        |j	                  t
        jr                              |_:        ||_!        tw        t        tx        |j	                  t
        jz                                    |_>        t        t        |j	                  t
        j~                              |_@        t        t        |j	                  t
        j                              }#	 |#j                         |_B        t        t        |j	                  t
        j                              |_E        t        t        |j	                  t
        j                              |_G        t        t        |j	                  t
        j                              |_I        t        t        |j	                  t
        j                              |_K        |j                  |j                  z   |_L        | j                  D ]   }$|j	                  |$      |j                  |$<   " |S # t,        t.        f$ r d}Y w xY w# t<        t.        f$ r Y w xY w# t\        $ r Y w xY w# t        $ r |#j                  d      |_B        Y ww xY w)N   i  r    s   HTTP/r   )maxsplitr$   replace)errors       	z
set-cookiedomainpath/secure)r   r   r   )secondszlatin-1)Or   rF   r   bytesgetinfor   EFFECTIVE_URLdecoder   getvaluer   rr   HTTP_VERSIONr   RESPONSE_CODEstatus_codeok
splitlinesstrip
startswithappendsplit
IndexErrorr   get_reason_phrasereasonr,   r^   listREDIRECT_HISTORYr   rangelenr~   historyr'   r`   get_listrN   SimpleCookieloaditemssetvaluer   rk   	Exceptionr   COOKIECHANGESr    update_cookies_from_curl_changes
PRIMARY_IP
primary_ipPRIMARY_PORTprimary_portLOCAL_IPlocal_ip
LOCAL_PORT
local_portr   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_sizer   infos)%r   curlbufferheader_bufferr~   r   crspheader_linesheader_listheader_blocksheader_statusheader_reasonheader_line_redirect_historyblock_indexitemstatus_byteshistory_url_byteshistory_statushistory_urlhistory_reasonhistory_headersindexstatusr  r^   history_responseset_cookie_headers
set_cookiecookienamemorselchangesredirect_url_bytesinfos%                                        rY   _parse_responsezBaseSession._parse_response>  s@    1d))!,-uaii(>(>?@GGI //+CKQYYx/D/D%EFsAIIh.D.D$EF-#-$--/::<#%<>' 	,K$$&%%h/ !((-)TU&$'(9(91(9(Ea(H$IM !" 3 3K @ G G$ !H ! !%%d+{/E/Ee/LB;.{+'	,(   -!LM)6r):&Asz;k*UQYYx7P7P-QR$ 	1D26**UA2F//!$\!2 ,22)2DKN%iO{C,>? *7*>'^+%+N&-g&6O"'!)K  $At':':4'@A#. +9(&4#"%"=#"='6$0@-KK/03	18 i [[11,?, 	J224J'$*LLN LD&KKOO%zz(B7#ZZ4#FJJx$89 $ 		  *AT-A-A4;		(2H2H(IJGMM::7C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	. 
} #J/ &$%M&0 z* L  & " 	D188CC	DsI    \4 ]5B)]"]2 4]	]	]]"	]/.]/2^^c                2    | j                   rt        d      y )Nz'Session is closed, cannot send request.)r   r*   r   s    rY   _check_session_closedz!BaseSession._check_session_closed  s    << IJJ rX   c               ~    t        | j                  xr' | j                  j                  |t        |      |            S )Nr   r   )rk   r   should_cache_request)r   requestr   r   s       rY   _cache_enabledzBaseSession._cache_enabled  sA     KK 00F|!1 1 
 	
rX   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   )rt   r   r   r   randomuniform)r   attemptr   r   s       rY   _retry_delayzBaseSession._retry_delay  sc    ::},NNaGaK&89ENNW,E??V^^C99ErX   c                    | j                   S r   )r   rL  s    rY   r`   zBaseSession.cookies  s    }}rX   c                $    t        |      | _        y r   )r'   r   )r   r`   s     rY   r`   zBaseSession.cookies  s      (rX   )@r^   r]   r`   r_   rb   ra   rd   rc   rf   re   rg   ra   rh   re   rj   zOptional[dict[str, object]]rl   rk   rn   rm   ro   rk   rq   rp   rs   rr   rt   #Optional[Union[int, RetryStrategy]]rv   ru   rw   re   rx   re   ry   re   r{   rz   r|   rk   r~   r}   r   zOptional[dict[CurlOpt, str]]r   zOptional[list[object]]r   r   r   rk   r   re   r   re   r   r   r   r   r   rk   r   rk   r   r   )r*  r    r+  r   r,  r   r~   r}   r   rk   returnrF   )r   r   r   Optional[Callable[..., object]]r[  rk   )rV  rr   r[  r   )r[  r'   )r`   r(   r[  None)rS   rT   rU   __doc__r   rJ  rM  rR  rW  propertyr`   setterrW   rX   rY   r   r      sy   W
 *.)-*.'+#04"&.2578<56MQ! $"DH $?F59-1MQ#'!%6:,0 %!&%)E[ '[ '	[
 ([ %[ [ .[  [ ,[ [ 3[ [ 6[ [  3![" K#[$ %[& '[( )[* B+[, -[. =/[0 31[2 +3[4 K5[6 7[8 !9[: ;[< 4=[> *?[@ A[B C[D #E[z|| | 	|
 =| | 
||K
 	

 :
 

    ^^) )rX   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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f"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#dZd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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)a  
        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 or fingerprint 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: interface name or local IP to bind to (bare IP = source address).
            doh_url: DNS-over-HTTPS server url, e.g. https://1.1.1.1/dns-query.
            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r   rW   )superr   _thread_use_thread_local_curl_queue	_executor	threadinglocal_local_is_customized_curlr*  r    r   _curl)r   r*  threaduse_thread_local_curlr   	__class__s        rY   r   zSession.__init__  s    ~ 	"6"&;# #//+DK+/(#' +0(#'djj#9 !%4djj+ADJrX   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*  rd  )rg  rm  warningswarnr#   getattrrl  r    r   r*  rn  rL  s    rY   r*  zSession.curl7  sj    &&''E# 
 4;;5#'djj#9 ;;###::rX   c                P    | j                   t               | _         | j                   S r   )ri  r   rL  s    rY   executorzSession.executorF  s     >>!/1DN~~rX   c                    | S r   rW   rL  s    rY   	__enter__zSession.__enter__L  s    rX   c                $    | j                          y r   closer   r   s     rY   __exit__zSession.__exit__O  s    

rX   c                F    d| _         | j                  j                          y)Close the session.TN)r   r*  r}  rL  s    rY   r}  zSession.closeR  s    		rX   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   TNrW   )rQ  r}  r   r  r   r   r.  s        rY   r   zSession.streamW  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_closer   Nr`   )rM  r*  	duphandleresetrA   r   r   r'   r   r`   updateconnect)r   r   r  r  r  r  r   r*  rP   user_cookiesmerged_cookiess              rY   
ws_connectzSession.ws_connecte  s    2 	""$yy""$		!!**
 GdNFJJy,AB#$T\\2N!!,/ .F9 $F9

3!&!	rX   c                6    | j                   j                         S r   )r*  upkeeprL  s    rY   r  zSession.upkeep  s    yy!!rX   gzip, deflate, brr   r   r   Fc%           	     `
   $012345 |!r5 j                   j                         1 j                   j                         }%n j                   1t        1fi d|d|d j                  |gd j
                  d|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|xs  j0                  d |!d!|"d"|#d#| xs  j2                  d$ j4                  d%t6        j8                  d&t:        j<                  \  50243}& j?                  5|!|'      r j@                  jC                  5 jD                  (      }'|'o$s1 jF                  s% j                  jI                  |'jJ                          jL                  r|'jM                          1j                          tO        tP        |'      S |!rֈ01$2345 f	d)}( jR                  jU                  |(      })3jW                           jY                  102$      }*t[        4      }+t]        |+t^              r4|&r|&ja                          |)jc                          1je                          |+5|*_3        |)|*_4        |&|*_5        4|*_         jL                  r|*jM                          |*S 	  jl                  d*k(  r*d+d l7},|,jp                  js                  1jt                         ne jl                  d,k(  rFd+d l;}-|-jy                         jz                  j}                  1jt                        jC                          n1ju                           jY                  102$      }*5|*_3         j?                  5|!|'      r j@                  ja                  5|*        jL                  r|*jM                          |*1j                          S # t~        $ r^}. jY                  102$      }*5|*_3        t        |.j                  t        |.            }/ |/t        |.      |.j                  |*      |.d }.~.ww xY w# 1j                          w xY w)-Nr  r   params_listrh   r   r   r   headers_listcookies_listr   rb   rn   rq   rs   proxies_listrf   rg   verify_listr   r   r   rv   rw   rx   ry   r{   r|   r   r   r   r   r   r   r   r   r   queue_classevent_classrO  )r   c                   	 	 j                          t        t        j                        j                         s(t        t        j                        j                          	j                  t               y # t        $ rq} j                        }
|_        t	        | j
                  t        |             }	j                   |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!   rJ  rQ  r+   coderL   
put_nowaitr   rj  Eventis_setr  putr2   )er.  errorr+  r-  r~   r   r,  header_recvedqreqr   s      rY   r  z&Session._request_once.<locals>.perform
  s    &IIK  	?FFHY__m<@@BEE*% ! =..6=2BOC #&CK&qvvs1v6ELLs1vqvvs!;<<=  	?FFHY__m<@@BEE*%s+   A9 9	C3A'C.)C6 .C33C6 6A'Er   r   r   )Cr*  r  r  r>   rj   rh   r^   r   rb   r;   rn   rq   rs   rd   rg   rl   rv   rw   rx   ry   r{   r|   r   r   r   r   r   queueQueuerj  r  rR  r   r   r   r   r  r`   r   r   rF   rx  submitwaitrJ  r9   r   r)   r  resultr}  rQ  stream_taskquit_nowrf  eventlet.tpooltpoolexecuter  r   get_hub
threadpoolspawnr!   r+   r  rL   )6r   r  r   rj   r   r   r   r^   r`   r   rb   rn   rq   rs   rd   rf   rg   rl   r   r   r   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   r5  r  cached_responser  r  r.  first_elementr   r   r  r  r+  r-  r,  r  r  r  s6   `                          `        `           @@@@@@rY   _request_oncezSession._request_once  s   T 		##%A		!A		AAQ.B
.B
 .B
 f-	.B

 ]].B
 .B
 .B
 .B
 ,,0.B
 --1.B
 .B
 ".B
 %,w$6DLLG.B
 )8(?$$_.B
$ '4&;""%.B
( ,,0).B
* +.B
, "4T__-.B
. f-/.B
0 1.B
2 ,3.B
4 .5.B
6 $7t'7'77.B
8 txx9.B
: (T[[;.B
< "=.B
> .?.B
B )8(?$$_C.B
F G.B
H &:):):I.B
J  14>>K.B
L +t||M.B
N O.B
P *Q.B
R  S.B
T "U.B
V **W.B
X Y.B
Z "[.B
>V]A}h` s6DTU"kkoo#22 . O *'4+?+?MM(()@)@A((#446	A//& & --..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}.> "&&9I '  KKOOC-((((*	)  8**v}.> ""1663q62CFAFFC0a78( 	s-   BR1 7A)T 1	T:ATTT T-c%                L   | j                          ||n|}%t        ||      }&| j                  }'t        |'j                  dz         D ]  }(|(dkD  rt        |%|&       	  | 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&|#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.Nr$   r   r  r   rj   r   r   r   r^   r`   r   rb   rn   rq   rs   rd   rf   rg   rl   r   r   r   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   rW   )rM  r7   rt   r  r   r:   r  r)   rW  timesleep*r   r  r   rj   r   r   r   r^   r`   r   rb   rn   rq   rs   rd   rf   rg   rl   r   r   r   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   bodybody_positionr   rV  r   s*                                             rY   rQ  zSession.requestU  s-   R 	""$!-w4.tW=::X^^a/0 /	&G{T=1,&)t)) %!%% "% 	%
 $% % $% $%  % % $% %4% #0% $%  %   *!%" "#%$ $%%& %4'%( &6)%* !,+%, -%. "/%0 1%2 &3%4 %45%6 &67%8  9%: ".;%< (=%> $?%@ A%B "C%D $2E%F (G%H %4I% %	/	&T $ &hnn,))'A+6JJu%&s   A;CAD#"D#c                ,     | j                   dd|d|S Nr   r  rW   rQ  r   r   r   s      rY   headzSession.head      t||=6s=f==rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   r   zSession.get      t||<5c<V<<rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   postzSession.post  r  rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   r  zSession.put  r  rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   patchzSession.patch      t||>7>v>>rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   deletezSession.delete  s    t||?8???rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   optionszSession.options  s    t||@9#@@@rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   tracezSession.trace  r  rX   c                ,     | j                   dd|d|S Nr   r  rW   r  r  s      rY   queryzSession.query  r  rX   )NNT)
r*  zOptional[Curl]ro  zOptional[ThreadType]rp  rk   r   Unpack[BaseSessionParams[R]]r[  r]  r[  r]  )r  
HttpMethodr   rL   r   Unpack[StreamRequestParams]r[  zGenerator[R, None, None])NNNN)r   rL   r[  rA   )r[  rr   )Jr  r  r   rL   rj   zDOptional[Union[dict[str, object], list[object], tuple[object, ...]]]r   r   r   Optional[SyncRequestContent]r   r   r^   r]   r`   r_   r   ri   rb   ra   rn   r   rq   r   rs   r   rd   rc   rf   re   rg   ra   rl   r   r   re   r   re   r   r\  rv   ru   rw   re   rx   re   ry   re   r{   rz   r|   r   r~   r}   r   r   r   +CurlHttpVersion | HttpVersionLiteral | Noner   re   r   re   r   r   r   r   r   rr   r   r   r   rk   r[  rF   )Hr  r  r   rL   rj   r   r   r   r   r  r   r   r^   r]   r`   r_   r   ri   rb   ra   rn   r   rq   r   rs   r   rd   rc   rf   re   rg   ra   rl   r   r   re   r   re   r   r   rv   0Optional[Union[BrowserTypeLiteral, Fingerprint]]rw   re   rx   re   ry   re   r{   rz   r|   r   r~   r}   r   r   r   r   r   re   r   re   r   r   r   r   r   rr   r   r   r   rk   r   rL   r   zUnpack[RequestParams]r[  rF   )rS   rT   rU   r^  r   r_  r*  rx  rz  r  r}  r
   r   r  r  r;   r  rQ  r  r   r  r  r  r  r  r  r  __classcell__rq  s   @rY   rb  rb    sH   T
  $'+&*	MBMB %MB  $	MB
 /MB 
MB^    

   .	
 
"   11 
1f" &*04&*)-)- $*.GNBF'+'+#04!%!%)<<@MQ! $"DH*.?F,.DH#'!%6:!%(, %Oxx x
	x $x .x $x 'x 'x x (x Ex @x  %!x" %#x$ %x& .'x( )x* +x, '-x. :/x0 K1x2 3x4 5x6 7x8 B9x: (;x< ==x> *?x@ BAxB !CxD ExF 4GxH IxJ KxL &MxN OxP 
Qx| 6:&*04&*)-)- $*.GNBF'+'+#04!%!%)</3HL! $"DH*.?F,.MQ#'!%6:!%(, %K]&]& ]& 3	]&
 $]& .]& $]& ']& ']& ]& (]& E]& @]& %]& %]&  !]&" .#]&$ %]&& ']&( ')]&* -+]&, F-]&. /]&0 1]&2 3]&4 B5]&6 (7]&8 =9]&: *;]&< K=]&> !?]&@ A]&B 4C]&D E]&F G]&H &I]&J K]&~>=>=?@A??rX   rb  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d/dZe	 	 	 	 	 	 	 	 d0d       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df%	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1dZd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df"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2dZd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df"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3dZd4dZd4d Zd4d!Zd4d"Zd4d#Zd4d$Zd4d%Zd4d&Zd4d'Z xZS )5AsyncSessionzAAn async request session, cookies and connections will be reused.N
   )loop
async_curlmax_clientsc                   |j                  d      t        d      t        |   di | || _        || _        |du | _        || _        | 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 or fingerprint 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.
        r   NzMAsyncSession does not support cache yet because CacheBackend I/O is blocking.rW   )	r   NotImplementedErrorre  r   _loop_acurl_owns_acurlr  	init_pool)r   r  r  r  r   rq  s        rY   r   zAsyncSession.__init__  sf    D ::g*% 
 	"6"7;
(2!+t!3 +rX   c                d    | j                   t        j                         | _         | j                   S )z"Returns a reference to event loop.)r  asyncioget_running_looprL  s    rY   r  zAsyncSession.loop"  s(     :: 113DJzzrX   c                h    | j                   t        | j                        | _         | j                   S )N)r  )r  r   r  rL  s    rY   acurlzAsyncSession.acurl)  s&    ;;#3DK{{rX   c                    t        j                  | j                        | _        	 	 | j                  j	                  d        # t         j
                  $ r Y y w xY wr   )r  	LifoQueuer  poolr  	QueueFullrL  s    rY   r  zAsyncSession.init_pool/  sS    4;4E4EdFVFV4W			$$T*  $$ s   A AAc                   K   | j                   j                          d {   }|+t        | j                  j                  | j
                        }|S 7 3w)N)cacertr   )r  r   r    r  _cacertr   r   r*  s     rY   pop_curlzAsyncSession.pop_curl7  sA     "&))--/1<tzz11DD 2s   AA4Ac                    t        t        j                        5  | j                  j	                  |       d d d        y # 1 sw Y   y xY wr   )r   r  r  r  r  r  s     rY   	push_curlzAsyncSession.push_curl=  s7    g''( 	'II  &	' 	' 	's	   ?Ac                   K   | S wr   rW   rL  s    rY   
__aenter__zAsyncSession.__aenter__A  s     s   c                @   K   | j                          d {    y 7 wr   r|  r~  s     rY   	__aexit__zAsyncSession.__aexit__D  s     jjl 	s   c                  K   | j                   r"| j                  j                          d{    d| _        	 	 | j                  j                         }|r|j                          .7 :# t        j                  $ r Y yw xY ww)r  NT)r  r  r}  r   r  
get_nowaitr  
QueueEmptyr  s     rY   r}  zAsyncSession.closeH  su     **""$$$yy++-JJL	  % %% s2   *BA'B,A) &B)A?<B>A??Bc                  K   | j                          g }g }	 	 | j                  j                         }|j                  |       |r5|j                  | j                  j                  d|j                               d# t        j                  $ r Y nw xY w	 t        t        j                  |  d{  7        |D ]  }| j                  |        S # |D ]  }| j                  |        w xY ww)a  
        Performs connection upkeep for all idle connections in the pool.

        This is done by calling `curl_easy_upkeep` on each underlying curl handle.
        This function can be used to keep connections alive. For example, HTTP/2
        connections can be kept alive by sending PING frames.

        Returns:
            A list of curl return codes from `curl_easy_upkeep`.
        N)rM  r  r  r  r	  r   r  run_in_executorr  r  gatherr  )r   pooled_curlstasksr*  s       rY   r  zAsyncSession.upkeepU  s      	""$yy++- %TYY66tT[[IJ  %% 	%gnne4445$ %t$% %t$%sL   C/A< A	C/<BC/BC/C 0B31C 9C/C,,C/c                    |j                          | j                  s=| j                  j                  |       |j	                          | j                  |       y |j                          y r   )clean_handles_and_buffersr   r  remove_handler  r  r}  r  s     rY   release_curlzAsyncSession.release_curls  sE    &&(||JJ$$T*JJLNN4 JJLrX   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   TNrW   )rQ  acloser  s        rY   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%Tr  r   r      @   Fg{Gz?g{Gzt?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 or fingerprint 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: interface name or local IP to bind to (bare IP = source address).
            doh_url: DNS-over-HTTPS server url, e.g. https://1.1.1.1/dns-query.
            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.01`` (10ms).
            send_time_slice: The maximum duration (in seconds) to process outgoing
                messages before yielding to the event loop.
                Defaults to ``0.005`` (5ms).
            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                   '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xs #j,                  dd	xs #j.                  dt0        j2                  dt0        j4                  d d!}| j7                  t8        j:                  d"      }| j7                  t8        j<                  d#      }	 #j>                  jA                  d | jB                         d {   }tK        tM        tN        tP           #      |  $
)!%#jR                  $      }	 |jU                          |S 7 T7 R# tD        $ r# | jG                          #jI                  d         w xY w# tV        $ r |jY                           w xY ww)&Nr*  r  r   r   rh   r  r  r  rb   rn   rq   rs   r  rf   rg   r  r   r   rv   rw   rx   r{   r|   r   r   r   r   r   r   r  r  r   ry   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_fullr   rW   )-rM  r   r>   rh   rj   r^   r`   rb   r;   rn   rq   rs   rd   rg   rl   rv   rw   rx   r{   r|   r   r   r   r   r  r  r  setoptr   TCP_NODELAYCONNECT_ONLYr  r  r  r  r}  r  r?   r   r  r1   r   _start_io_tasksrB   	terminate)*r*  r5  rP   r   rx   rq   rb   r  r#  r   r  r`   r   r|   r   r"  r{   r^   r   rv   r   rw   r!  r   rs   r  rj   ry   rd   rf   rg   r   r  r  r   r   r  r   rn   r   rl   r  s*      rY   _connect_coroz.AsyncSession.ws_connect.<locals>._connect_coro  sP    &&(#}}.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~~?'@  /4<<A'B  .C'D &TYYE'F $MMG'H $MMI'J *K'L M'AP G//3A$$A
))33D$,,GG "0\(+T2# / /$7 /! / /!1-)Ajj"B"""$
 I[ /` H 

t$0 " sR   $KI;GK)J  +I>,J  08K)J/ 9K>J   ,J,,K/K

K)r[  r?   )r@   )(r   r   r  rj   r^   r`   rb   rn   rq   rs   rd   rf   rg   rl   r   r   rv   rw   rx   ry   r{   r|   r   r   r   r   r   r   r  r  r  r  r  r  r   r!  r"  r#  r   r)  s(   ``````````````````````````````````````` rY   r  zAsyncSession.ws_connect  s<    bP	 P	 P	 P	 P	 P	d %]_55rX   r   c%                .	   $./0123456K    j                          d {   0d .|}%t        |t              rt        |0      .t	        t
        .      }%	 t        d,i d0d|d|d j                  |gd j                  d|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| j0                  n|d|d|xs  j2                  d|xs  j4                  d |xs  j6                  d!|!d"|"d#|#d$| xs  j8                  d% j:                  d&t<        j>                  d't<        j@                  \  5/243}&..jG                          |!r jH                  jK                  0      6d(1d-./0$2345 6fd)}'01 fd*}(t=        jL                   |'             })|)jO                  |(       t	        t<        j@                  3      jQ                          d {     jS                  0/2$      }*tU        4      }+t        |+tV              r1s jE                  0       d+1|+5|*_,        |)|*_-        |&|*_.        4|*_/         j`                  r|*ja                          |*S 	  jH                  jK                  0      66 d {     jS                  0/2$      }*5|*_,         j`                  r|*ja                          |*..jc                          d {     jE                  0       S 7 # tB        $ r  jE                  0        w xY w7 37 7 =# td        $ r^}, jS                  0/2$      }*5|*_,        tg        |,jh                  tk        |,            }- |-tk        |,      |,jh                  |*      |,d },~,ww xY w# ..jc                          d {  7    jE                  0       w xY ww).Nr*  r  r   r  rh   r   r   r   r  r  r   rb   rn   rq   rs   r  rf   rg   r  r   r   r   rv   rw   rx   ry   r{   r|   r   r   r   r   r   r   r   r   r   r  r  Fc                 T  K   	  d {    j                          d {    t        t        j                  	      j                         s(t        t        j                  	      j                          
j                  t               d {    y 7 # t         $ rq} j                        }|_        t        | j                  t        |             }
j                   |t        |       | j                  |             Y d } ~ d } ~ ww xY w7 7 # j                          d {  7   t        t        j                  	      j                         s(t        t        j                  	      j                          
j                  t               d {  7   w xY wwr   )r!   rJ  rQ  r+   r  rL   r  r}  r   r  r  r  r  r  r2   )r  r.  r  async_readerr+  r*  r~   r   r,  r  r  r  r   tasks      rY   r  z+AsyncSession._request_once.<locals>.perform  sA    ,JJ $/*00222}=DDFW]]M:>>@%%
+++   =..fm5EC #&CK&qvvs1v6ELLs1vqvvs!;<<= 3 ,	 $/*00222}=DDFW]]M:>>@%%
+++s   F(B BB F(DA,F(DF(B 	D"A'D	D DD F(F(F%0D31A-F%F!F%%F(c                0    sj                         dy )NT)r  )futr*  curl_releasedr   s    rY   cleanupz+AsyncSession._request_once.<locals>.cleanup  s    $%%d+ $rX   TrW   r  )6r   r   r   r6   r   r5   r>   rj   rh   r^   r`   rb   r;   rn   rq   rs   rd   rg   rl   rv   rw   rx   ry   r{   r|   r   r   r   r   r   r  r  r  BaseExceptionr  startr  
add_handlecreate_taskadd_done_callbackr  rJ  r8   r)   rQ  astream_taskr  r  r   r}  r!   r+   r  rL   )7r   r  r   rj   r   r   r   r^   r`   r   rb   rn   rq   rs   rd   rf   rg   rl   r   r   r   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   request_contentr  r  r1  r  r.  r  r  r  r,  r+  r*  r0  r,  r  r  r  r-  s7   `                          `        `         @@@@@@@@@rY   r  zAsyncSession._request_onceO  s_    N ]]_$48!g}-/>L"#5|DO3	EU .F.F.F .F "[[&1	.F
 .F .F (.F .F #llG4.F #llG4.F .F &TYY.F )07(:.F -<,CD((.F$ +8*?D&&]%.F( #llG4).F* +.F, &8-.F. "[[&1/.F0  1.F2 !03.F4 "25.F6 (;4+;+;7.F8 O4889.F: ,;.F< &TYY=.F> "2T]]?.FB -<,CD((C.FF G.FH *>T->->I.FJ $5t~~K.FL  /4<<M.FN O.FP  .Q.FR $S.FT &TYYU.FV "..W.FX $MMY.FZ $MM[.FBC=(f # ::((.D!M, ,"% "--gi8K))'2w}}m499;;; &&fm-=C ,A.M-)9:$%%d+ $##CK*C#CLCI$$$$&J(zz,,T2

 **&-1A? "((((*+&,,...!!$'Q %n  	d#	F <6 $ /#  8**&-1A? ""1663q62CFAFFC0a78   +&,,...!!$'s   RO4RG	O !BR O3BR O: 'O6(O: ,9Q$ %R:O8;RO00R6O: 8R:	Q!AQQ!!Q$ $R:Q=;RRc%                t  K   | j                          ||n|}%t        ||      }&| j                  }'t        |'j                  dz         D ]  }(|(rt        |%|&       	  | 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%|#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.Nr$   r  r   rj   r   r   r   r^   r`   r   rb   rn   rq   rs   rd   rf   rg   rl   r   r   r   rv   rw   rx   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   rW   )rM  r7   rt   r  r   r:   r  r)   rW  r  r  r  s*                                             rY   rQ  zAsyncSession.request   s<    V 	""$!-w4.tW=::X^^a/0 /	/GT=1,//T// %!%% "% 	%
 $% % $% $%  % % $% %4% #0% $%  %   *!%" "#%$ $%%& %4'%( &6)%* !,+%, -%. "/%0 1%2 &3%4 %45%6 &67%8  9%: ".;%< (=%> $?%@ A%B "C%D $2E%F (G%H %4I% % %	/	/%L $ /hnn,))'A+6!--.../sJ   AD8A?C%C#C%D8#C%%AD5,D/-D52D84D55D8c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.heada  '     !T\\CSCFCCCC   " "c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r   zAsyncSession.getd  '     !T\\BCB6BBBBr<  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.postg  r;  r<  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.putj  r>  r<  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.patchm  '     !T\\DcDVDDDDr<  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.deletep  s'     !T\\EsEfEEEEr<  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.optionss  s'     !T\\FFvFFFFr<  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.tracev  rB  r<  c                H   K    | j                   dd|d| d {   S 7 wr  r  r  s      rY   r  zAsyncSession.queryy  rB  r<  )
r  z asyncio.AbstractEventLoop | Noner  zAsyncCurl | Noner  rr   r   r  r[  r]  )r[  zasyncio.AbstractEventLoop)r[  r   )r[  r    )r*  zCurl | Noner[  r]  r  )r[  z	list[int])r*  r    r[  r]  )r  r  r   rL   r   r  r[  zAsyncGenerator[R, None, None])Nr   rL   r  rk   rj   z<dict[str, object] | list[object] | tuple[object, ...] | Noner^   zHeaderTypes | Noner`   zCookieTypes | Nonerb   tuple[str, str] | Nonern   z/float | tuple[float, float] | NotSetType | Nonerq   zbool | CurlFollow | str | Noners   z
int | Nonerd   zProxySpec | Nonerf   
str | Nonerg   rG  rl   bool | Noner   rH  r   rH  rv   z-BrowserTypeLiteral | str | Fingerprint | Nonerw   rH  rx   rH  ry   rH  r{   z&ExtraFingerprints | ExtraFpDict | Noner|   rI  r   zstr | Literal[False]r   r  r   rH  r   rH  r   zstr | tuple[str, str] | Noner   rr   r  rr   r  rr   r  rr   r  rk   r  zWebSocketRetryStrategy | Noner  r   r   r   r!  rr   r"  rk   r#  rk   r   zdict[CurlOpt, str] | Noner[  r@   )Jr  r  r   rL   rj   r   r   r   r   r   r   r   r^   r]   r`   r_   r   ri   rb   ra   rn   r   rq   r   rs   r   rd   rc   rf   re   rg   ra   rl   r   r   re   r   re   r   r   rv   ru   rw   re   rx   re   ry   re   r{   rz   r|   r   r~   r}   r   r   r   r   r   re   r   re   r   r   r   r   r   rr   r   r   r   rk   r[  rF   )Jr  r  r   rL   rj   zSOptional[Union[dict[str, str], list[tuple[str, str]], tuple[tuple[str, str], ...]]]r   r   r   r   r   z*Optional[Union[dict[str, Any], list[Any]]]r^   r]   r`   r_   r   zOptional[dict[str, Any]]rb   ra   rn   r   rq   r   rs   r   rd   rc   rf   re   rg   ra   rl   r   r   re   r   re   r   zOptional[Callable[..., Any]]rv   r  rw   re   rx   re   ry   re   r{   rz   r|   r   r~   r}   r   r   r   r   r   re   r   re   r   r   r   r   r   rr   r   r   r   rk   r[  rF   r  ) rS   rT   rU   r^  r   r_  r  r  r  r   r  r  r  r}  r  r  r	   r   r;   r  r  rQ  r  r   r  r  r  r  r  r  r  r  r  s   @rY   r  r    s}   K
 26'+M /M %	M
 M /M 
M^    
'%<   .	
 
'   OS&*&*'+CJ:>$($( -1""&9EI!;?'+&(DH $"-1""#% %26!%!& /$)-26OC6C6 C6 M	C6
 $C6 $C6 %C6 AC6 8C6 "C6 "C6 C6 +C6 C6 C6  $!C6" C#C6$ %C6& 'C6( )C6* 9+C6, %-C6. $/C60 B1C62 3C64 5C66 +7C68 9C6: ;C6< =C6> !?C6@ AC6B 0CC6D EC6F GC6H IC6J KC6L #'MC6N 0OC6P 
QC6R 6:&*,0&*)-)- $*.GNBF'+'+#04!%!%)</3MQ! $"DH*.?F,.MQ#'!%6:!%(, %Ko(o( o( 3	o(
 $o( *o( $o( 'o( 'o( o( (o( Eo( @o( %o( %o(  !o(" .#o($ %o(& 'o(( ')o(* -+o(, K-o(. /o(0 1o(2 3o(4 B5o(6 (7o(8 =9o(: *;o(< K=o(> !?o(@ Ao(B 4Co(D Eo(F Go(H &Io(J Ko(L 
Mo(n &*,0;?)-)-*.*.GNBF'+'+#04!%!%)<9=HL! $"DH*.?F,.MQ#'!%6:!%(, %O_/_/ _/
	_/ $_/ *_/ 9_/ '_/ '_/ (_/ (_/ E_/ @_/  %!_/" %#_/$ %_/& .'_/( )_/* +_/, '-_/. 7/_/0 F1_/2 3_/4 5_/6 7_/8 B9_/: (;_/< ==_/> *?_/@ KA_/B !C_/D E_/F 4G_/H I_/J K_/L &M_/N O_/P 
Q_/BDCDCEFGEErX   r  )r   rL   r[  rk   )rt   rZ  r[  r   )t
__future__r   r  http.cookiesrN   r   r  rT  sysrj  r  rt  collections.abcr   r   r   r   concurrent.futuresr   
contextlibr	   r
   r   dataclassesr   datetimer   ior   typingr   r   r   r   r   r   r   r   r   urllib.parser   r   ImportErrortyping_extensionsaior   constr   r   r   r   r*  r    r!   r"   utilsr#   r   r%   r&   r`   r'   r(   
exceptionsr)   r*   r+   r^   r,   r-   rv   r.   r/   r0   modelsr1   streamsr2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   
websocketsr?   r@   rA   rB   rC   version_inforF   fingerprintsrI   rK   r\   r   r   r   dictrL   
ThreadTyper  r   r   r   r   r   rb  r  rW   rX   rY   <module>rb     s   "   	   
     2 D D !  
 
 
 ")  B B , , # 5 ) 
 * K K 
 
 
 M L  w8X6A8$A(*IU  #GAJ	  #D!iu !F+5 
 
 YFS#XI!)2I&)*
P

; ./ % % %(C)'!* C)Li?k!n i?Xj
E;q> j
ES  )(()s   6G G+*G+