
    T>qju3                        d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZmZ d dlmZ ddlmZ dd	lmZ d
dlmZ d
dlmZmZ d
dlmZ d
dlmZ 	 d dlmZ  ee      5  d dl!m!Z" d dl#Z$ddd        ejJ                  d      Z&h dZ'dZ( G d d      Z) G d d      Z*y# e$ r	 d dl mZ Y Uw xY w# 1 sw Y   GxY w)    )suppressN)Future)AnyOptionalUnion)	AwaitableCallable)	timedelta   )Curl)CurlCffiWarning   )Cookies)	HTTPErrorRequestException)Headers)
STREAM_END)loads)markdownifyzcharset=([\w-]+)>   utf-16utf-32utf-16beutf-16leutf-32beutf-32le	utf-16-be	utf-16-le	utf-32-be	utf-32-leutf8utf16utf32utf-8	utf-8-sig)i-  i.  i/  i3  i4  c            
       2    e Zd ZdZ	 ddedededee   fdZy)	RequestzRepresenting a sent request.

    Attributes:
        url: request url.
        headers: request headers.
        method: request http method.
        body: request body as bytes, or None if not provided.
    Nurlheadersmethodbodyc                 <    || _         || _        || _        || _        y N)r'   r(   r)   r*   )selfr'   r(   r)   r*   s        X/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/curl_cffi/requests/models.py__init__zRequest.__init__;   s      	    r,   )	__name__
__module____qualname____doc__strr   r   bytesr/    r0   r.   r&   r&   1   s;     !%

 
 	

 uo
r0   r&   c                      e Zd ZdZd dee   dee   fdZdee	e
f   fdZdee	e
f   ddfd	Zede	fd
       Zede	fd       Zej                   de	ddfd       Zedee	   fd       Zede	fd       Zde	fdZdede	fdZd Zedefd       Zd!dZd"dZd Zd Zd#dZd!dZd"dZde	fdZ defdZ!d Z"de	fdZ#y)$Responsea  Contains information the server sends.

    Attributes:
        url: url used in the request.
        content: response body in bytes.
        text: response body in str.
        status_code: http status code.
        reason: http response reason, such as OK, Not Found.
        ok: is status_code in [200, 400)?
        headers: response headers.
        cookies: response cookies.
        elapsed: timedelta of the request duration.
        encoding: http body encoding.
        charset: alias for encoding.
        primary_ip: primary ip of the server.
        primary_port: primary port of the server.
        local_ip: local ip used in this connection.
        local_port: local port used in this connection.
        charset_encoding: encoding specified by the Content-Type header.
        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.
        redirect_count: how many redirects happened.
        redirect_url: the final redirected url.
        http_version: http version used.
        history: redirect responses, in request order. Response bodies are not
            available.
        download_size: total downloaded bytes (body).
        upload_size: total uploaded bytes (body).
        header_size: total header size.
        request_size: request size.
        response_size: download_size + header_size
    Ncurlrequestc                    || _         || _        d| _        d| _        d| _        d| _        d| _        t               | _        t               | _
        t               | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        g | _        i | _        d | _        d | _        d | _        d | _        d| _        d| _        d| _        d| _        d| _        d| _         y )	N r0      OKTr#   r   F)!r:   r;   r'   contentstatus_codereasonokr   r(   r   cookiesr
   elapseddefault_encodingredirect_countredirect_urlhttp_version
primary_ipprimary_portlocal_ip
local_porthistoryinfosqueuestream_taskastream_taskquit_now_stream_closeddownload_sizeupload_sizeheader_sizerequest_sizeresponse_size)r-   r:   r;   s      r.   r/   zResponse.__init__k   s    	yy"++DK!!" ')%'
,0
-115#"# ! !!""#r0   returnc                     t        d | j                  | j                  | j                  | j                  fD              rt        d      | j                  j                         }dD ]  }|j                  |d         |S )Nc              3   $   K   | ]  }|d u 
 y wr,   r7   ).0values     r.   	<genexpr>z(Response.__getstate__.<locals>.<genexpr>   s      
 
s   ziStreaming responses cannot be pickled; make the request without stream=True before pickling the response.)r:   rP   rQ   rR   rS   )	anyrP   rQ   rR   rS   	TypeError__dict__copypop)r-   state	attributes      r.   __getstate__zResponse.__getstate__   s     
 

  !!	
 
 < 
 ""$
 	'I IIi&	' r0   re   c                     | j                   j                  |       d | _        d | _        d | _        d | _        d | _        d| _        y NT)rb   updater:   rP   rQ   rR   rS   rT   )r-   re   s     r.   __setstate__zResponse.__setstate__   sA    U#	
 "r0   c                     | j                   S )zAlias for encoding.)encodingr-   s    r.   charsetzResponse.charset   s     }}r0   c                    t        | d      sp| j                  }|Wt        | j                  t              r| j                  }n0t        | j                        r| j                  | j                        }|xs d| _        | j                  S )a  
        Determines the encoding to decode byte content into text.

        The method follows a specific priority to decide the encoding:
        1. If ``.encoding`` has been explicitly set, it is used.
        2. The encoding specified by the ``charset`` parameter in the ``Content-Type``
            header.
        3. The encoding specified by the ``default_encoding`` attribute. This can either
            be a string (e.g., "utf-8") or a callable for charset autodetection.
        	_encodingr#   )hasattrcharset_encoding
isinstancerF   r5   callabler@   rq   )r-   rm   s     r.   rm   zResponse.encoding   sr     t[),,Hd33S9#44Hd334#44T\\BH%0DN~~r0   r^   c                 @    t        | d      rt        d      || _        y )N_textz0Cannot set encoding after text has been accessed)rr   
ValueErrorrq   )r-   r^   s     r.   rm   zResponse.encoding   s    4!OPPr0   c                     | j                   j                  d      }|r*t        j                  |      }|r|j	                  d      S dS y)z=Return the encoding, as specified by the Content-Type header.zContent-Typer   N)r(   get
CHARSET_REsearchgroup)r-   content_typecharset_matchs      r.   rs   zResponse.charset_encoding   sF     ||''7&--l;M-:=&&q)DDr0   c                     t        | d      s?| j                  sd| _        | j                  S | j                  | j                        | _        | j                  S )Nrw   r=   )rr   r@   rw   _decodern   s    r.   textzResponse.text   sF    tW%<<
 zz "\\$,,7
zzr0   c                     t        j                  | j                        }|j                         }|j	                  d      }t        d| d| d      }|S )NT)html_partialz<h1>z</h1><main>z</main>)rdDocumentr@   titlesummarymd)r-   docr   r   
body_as_mds        r.   markdownzResponse.markdown   sN    kk$,,'		++4+0$ug[	AB
r0   r@   c                     	 |j                  | j                  d      S # t        t        f$ r |j                  d      cY S w xY w)Nreplace)errorsr$   )decoderm   UnicodeDecodeErrorLookupError)r-   r@   s     r.   r   zResponse._decode   sA    	/>>$--	>BB"K0 	/>>+..	/s     AAc                 j    | j                   s't        d| j                   d| j                   d|       y)z2Raise an error if status code is not in [200, 400)zHTTP Error z: r   N)rC   r   rA   rB   rn   s    r.   raise_for_statuszResponse.raise_for_status   s6    wwk$*:*:);2dkk]KQPTUU r0   c                 F    d| j                   v xr | j                  t        v S )z0Whether this response is a well-formed redirect.location)r(   rA   REDIRECT_STATIrn   s    r.   is_redirectzResponse.is_redirect   s#     T\\)Pd.>.>..PPr0   c              #     K   d}| j                  ||      D ]_  }|||z   }|r|j                  |      n|j                         }|r%|d   r |r|d   d   |d   k(  r|j                         nd}|E d{    a || yy7 wz
        iterate streaming content line by line, separated by ``\n``.

        Copied from: https://requests.readthedocs.io/en/latest/_modules/requests/models/
        which is under the License: Apache 2.0
        N)
chunk_sizedecode_unicode)iter_contentsplit
splitlinesrd   )r-   r   r   	delimiterpendingchunkliness          r.   
iter_lineszResponse.iter_lines   s      &&!. ' 
 	E "%.7EKK	*U=M=M=OE U2Y5U2Yr]eBi5O 		  	 M  s   A1B3B4Bc              #   T  K   |rt        j                  dt        d       |r
t               | j                  r| j
                  sJ d       	 | j                  j                         }t        |t              r| j                          ||t        u rn| J| j                          ywzD
        iterate streaming content chunk by chunk in bytes.
        z9chunk_size is ignored, there is no way to tell curl that.r   )
stacklevelzstream mode is not enabled.N)warningswarnr   NotImplementedErrorrP   r:   rz   rt   r   _finalize_streamr   r-   r   r   r   s       r.   r   zResponse.iter_content  s      MMK
 %''zzdiiF)FF'JJNN$E %!12%%' 
"K  	s   B&B(c                     | j                   }|>|j                         j                  dd      }|t        vrt	        | j
                  fi |S t	        | j                  fi |S )z+return a parsed json object of the content._-)rs   lowerr   JSON_NATIVE_ENCODINGSr   r   r@   )r-   kwrs   rm   s       r.   jsonzResponse.json0  s`    00''--/77SAH44TYY-"--T\\(R((r0   c                 $    | j                          yz:Close the streaming connection, only valid in stream mode.N)r   rn   s    r.   closezResponse.close9  s    r0   c                 \   | j                   ry | j                  | j                  | j                  y d| _         | j                  r| j                  j	                          | j                  r| j                  j                          | j                  r| j                  j                          y y ri   )rT   rP   rQ   rS   setresultr:   r   rn   s    r.   r   zResponse._finalize_stream=  s    ::$"2"2":t}}?T"==MM##%99IIOO r0   c                  K   d}| j                  ||      2 3 d{   }|||z   }|r|j                  |      n|j                         }|r%|d   r |r|d   d   |d   k(  r|j                         nd}|D ]  }| 	 i7 d6 || yywr   )aiter_contentr   r   rd   )r-   r   r   r   r   r   r   lines           r.   aiter_lineszResponse.aiter_linesJ  s      --!. . 
 	 	% "%.7EKK	*U=M=M=OE U2Y5U2Yr]eBi5O 		   
	 
 M s&   BBBBA!BB
Bc                  K   |rt        j                  dt        d       |r
t               | j                  r| j
                  sJ d       	 | j                  j                          d{   }t        |t              r| j                          d{    ||t        u r| j                          d{    y| s7 U7 /7 wr   )r   r   r   r   rP   r:   rz   rt   r   acloser   r   s       r.   r   zResponse.aiter_contente  s      MMK
 %''zzdiiF)FF'**..**E %!12kkm## 
"kkm##K * $
 $s6   A(C*C +'CC!C4C5CCCc                 \   K   | j                  | j                          d{         S 7 w)z*
        Return a decoded string.
        N)r   acontentrn   s    r.   atextzResponse.atext  s#      ||$--/1221s   ,*	,c                    K   g }| j                         2 3 d{   }|j                  |       7 6 dj                  |      S w)z8wait and read the streaming content in one bytes object.Nr0   )r   appendjoin)r-   chunksr   s      r.   r   zResponse.acontent  sG     --/ 	! 	!%MM% 	!/xxs   A202A2Ac                 R   K   | j                   r| j                    d{    yy7 wr   )rR   rn   s    r.   r   zResponse.aclose  s(      #### #s   '%'c                 "    d| j                    dS )Nz<Response [z]>)rA   rn   s    r.   __repr__zResponse.__repr__  s    T--.b11r0   )NN)NFN)NF)rZ   N)$r1   r2   r3   r4   r   r   r&   r/   dictr5   r   rg   rk   propertyro   rm   setterrs   r   r   r6   r   r   boolr   r   r   r   r   r   r   r   r   r   r   r   r7   r0   r.   r9   r9   H   sy    D$Xd^ $Xg=N $@d38n 4#$sCx. #T #    #  * __c d  
 (3-   c  # /u / /V
 QT Q Q4 <) 6<3S 3   $2# 2r0   r9   )+
contextlibr   rP   rer   concurrent.futuresr   typingr   r   r   collections.abcr   r	   datetimer
   r:   r   utilsr   rD   r   
exceptionsr   r   r(   r   streamsr   orjsonr   ImportErrorr   r   r   readabilityr   compiler{   r   r   r&   r9   r7   r0   r.   <module>r      s      	  % ' ' /   #  3   k - RZZ+,
 " + .P2 P2i   s   B& &B7&B43B47C 