
    di?*                        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  ee      5  d dlmZ  d dl!Z"ddd        ejF                  d      Z$ e%       Z&dejN                  fdZ( G d d      Z) G d d      Z*y# e$ r	 d dlmZ Y fw xY w# 1 sw Y   XxY w)    )suppressN)Future)AnyOptionalUnion)	AwaitableCallable)	timedelta   )Curl)CurlCffiWarning   )Cookies)	HTTPErrorRequestException)Headers)loads)markdownifyzcharset=([\w-]+)qc                     | j                   5  | j                  j                          | j                  j	                          d| _        d d d        y # 1 sw Y   y xY w)Nr   )mutexqueueclearall_tasks_done
notify_allunfinished_tasks)r   s    P/root/funda.leads/venv/lib/python3.12/site-packages/curl_cffi/requests/models.pyclear_queuer      sE    	
 		##%  s   <AAc                   $    e Zd ZdZdededefdZy)RequestzRepresenting a sent request.urlheadersmethodc                 .    || _         || _        || _        y )N)r!   r"   r#   )selfr!   r"   r#   s       r   __init__zRequest.__init__(   s        N)__name__
__module____qualname____doc__strr   r&    r'   r   r    r    %   s    &C ' 3 r'   r    c                   2   e Zd ZdZddee   dee   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ddZddZd Z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: history redirections, only headers are 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| _        y )N r'      OKTutf-8r   ) r0   r1   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infosr   stream_taskastream_taskquit_nowdownload_sizeupload_sizeheader_sizerequest_sizeresponse_size)r%   r0   r1   s      r   r&   zResponse.__init__P   s    	yy"++DK!!" -/%'
,0
-115"# ! !!""#r'   returnc                     | j                   S )zAlias for encoding.)encodingr%   s    r   charsetzResponse.charseto   s     }}r'   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.
        	_encodingr6   )hasattrcharset_encoding
isinstancer=   r,   callabler7   rU   )r%   rQ   s     r   rQ   zResponse.encodingt   sr     t[),,Hd33S9#44Hd334#44T\\BH%0DN~~r'   valuec                 @    t        | d      rt        d      || _        y )N_textz0Cannot set encoding after text has been accessed)rV   
ValueErrorrU   )r%   rZ   s     r   rQ   zResponse.encoding   s    4!OPPr'   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   rW   zResponse.charset_encoding   sF     ||''7&--l;M-:=&&q)DDr'   c                     t        | d      s?| j                  sd| _        | j                  S | j                  | j                        | _        | j                  S )Nr\   r3   )rV   r7   r\   _decoderR   s    r   textzResponse.text   sF    tW%<<
 zz "\\$,,7
zzr'   c                     t        j                  | j                        }|j                         }|j	                  d      }t        d| d| d      }|S )NT)html_partialz<h1>z</h1><main>z</main>)rdDocumentr7   titlesummarymd)r%   docrl   rm   
body_as_mds        r   markdownzResponse.markdown   sN    kk$,,'		++4+0$ug[	AB
r'   r7   c                     	 |j                  | j                  d      S # t        t        f$ r |j                  d      cY S w xY w)Nreplace)errorsz	utf-8-sig)decoderQ   UnicodeDecodeErrorLookupError)r%   r7   s     r   rf   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)r:   r   r8   r9   rR   s    r   raise_for_statuszResponse.raise_for_status   s6    wwk$*:*:);2dkk]KQPTUU r'   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
splitlinespop)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              #   F  K   |rt        j                  dt        d       |r
t               | j                  r| j
                  sJ d       	 | j                  j                         }t        |t              r| j
                  j                          ||t        u ry| T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   NotImplementedErrorr   r0   r_   rX   r   reset
STREAM_END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                 .    t        | j                  fi |S )z+return a parsed json object of the content.)r   r7   )r%   kws     r   jsonzResponse.json   s    T\\(R((r'   c                     | j                   r| j                   j                          | j                  r| j                  j                          yyz:Close the streaming connection, only valid in stream mode.N)rI   setrG   resultrR   s    r   closezResponse.close   s;     ==MM##% r'   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   r   )r%   r|   r}   r   r   r   r   lines           r   aiter_lineszResponse.aiter_lines   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   r   r0   r_   rX   r   acloser   r   s       r   r   zResponse.aiter_content  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)rf   acontentrR   s    r   atextzResponse.atext0  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.Nr'   )r   appendjoin)r%   chunksr   s      r   r   zResponse.acontent6  sG     --/ 	! 	!%MM% 	!/xxs   A202A2Ac                 R   K   | j                   r| j                    d{    yy7 wr   )rH   rR   s    r   r   zResponse.aclose=  s(      #### #s   '%'c                 "    d| j                    dS )Nz<Response [z]>)r8   rR   s    r   __repr__zResponse.__repr__D  s    T--.b11r'   )NN)NFN)NF)r(   r)   r*   r+   r   r   r    r&   propertyr,   rS   rQ   setterrW   rg   rq   bytesrf   ry   r   r   r   r   r   r   r   r   r   r   r-   r'   r   r/   r/   .   s&   B$Xd^ $Xg=N $>    #  * __c d  
 (3-   c  # /u / /V
4:)&6<3S 3   $2# 2r'   r/   )+
contextlibr   r   rer   concurrent.futuresr   typingr   r   r   collections.abcr   r	   datetimer
   r0   r   utilsr   r;   r   
exceptionsr   r   r"   r   orjsonr   ImportErrorr   r   rn   readabilityrj   compiler`   objectr   Queuer   r    r/   r-   r'   r   <module>r      s      	  % ' ' /   #  3  k - RZZ+,
X
5;;  W2 W27   s   B1  C1B?>B?C