
    >OOf$                         d dl Z d dlZd dl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 ddlmZ ddlmZ dd	lmZ dd
lmZ  ej.                  d      Zde j2                  fdZ G d d      Z G d d      Zy)    N)Future)loads)Any	AwaitableCallableDictListOptionalUnion   )Curl   )Cookies)RequestsError)Headersz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    Z/var/www/premiumrankchecker/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                   &   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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: how many seconds the request cost.
        encoding: http body encoding.
        charset: alias for encoding.
        charset_encoding: encoding specified by the Content-Type header.
        default_encoding: user-defined encoding used for decoding content if charset is not found in headers.
        redirect_count: how many redirects happened.
        redirect_url: the final redirected url.
        http_version: http version used.
        history: history redirections, only headers are available.
    Ncurlrequestc                 <   || _         || _        d| _        d| _        d| _        d| _        d| _        t               | _        t               | _
        d| _        d| _        d| _        d| _        d| _        g | _        i | _        d | _        d | _        d | _        d | _        y )	N r$      OKTg        utf-8r   )r-   r.   r   contentstatus_codereasonokr   r   r   cookieselapseddefault_encodingredirect_countredirect_urlhttp_versionhistoryinfosr   stream_taskastream_taskquit_now)r"   r-   r.   s      r   r#   zResponse.__init__7   s    	yyDK-/%'
,0
-115r$   returnc                     | j                   S )zAlias for encoding.)encodingr"   s    r   charsetzResponse.charsetM   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.
        	_encodingr3   )hasattrcharset_encoding
isinstancer:   r)   callabler4   rI   )r"   rE   s     r   rE   zResponse.encodingR   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)rJ   
ValueErrorrI   )r"   rN   s     r   rE   zResponse.encodingg   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   rK   zResponse.charset_encodingm   sF     ||''7&--l;M-:=&&q)DDr$   c                     t        | d      s?| j                  sd| _        | j                  S | j                  | j                        | _        | j                  S )NrP   r0   )rJ   r4   rP   _decoderF   s    r   textzResponse.textv   sF    tW%<<
 zz "\\$,,7
zzr$   r4   c                     	 |j                  | j                  d      S # t        t        f$ r |j                  d      cY S w xY w)Nreplace)errorsz	utf-8-sig)decoderE   UnicodeDecodeErrorLookupError)r"   r4   s     r   rZ   zResponse._decode   sA    	/>>$--	>BB"K0 	/>>+..	/s     AAc                 f    | j                   s%t        d| j                   d| j                         y)z2Raise an error if status code is not in [200, 400)zHTTP Error z: N)r7   r   r5   r6   rF   s    r   raise_for_statuszResponse.raise_for_status   s1    ww+d.>.>-?r$++ OPP r$   c              #     K   d}| j                  ||      D ]a  }|||z   }|r|j                  |      }n|j                         }|r&|d   r!|r|d   d   |d   k(  r|j                         }nd}|E d{    c || 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"   rf   rg   	delimiterpendingchunkliness          r   
iter_lineszResponse.iter_lines   s      &&*^&\ 	E"%I.((*rur2%)1K))+	 M  s   A3B5B6Bc              #   `  K   |rt        j                  d       |r
t               | j                  r| j                  sJ d       	 | j                  j                         }t        |t              r| j                  j                          ||| j                  j                          y| hwzD
        iterate streaming content chunk by chunk in bytes.
        z9chunk_size is ignored, there is no way to tell curl that.zstream mode is not enabled.N)	warningswarnNotImplementedErrorr   r-   rS   rL   r   resetr"   rf   rg   ro   s       r   ri   zResponse.iter_content   s      MMUV%''zzdiiF)FF'JJNN$E %/		! }		!K s   B,B.c                 .    t        | j                  fi |S )z+return a parsed json object of the content.)r   r4   )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)rB   setr@   resultrF   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 ]  }| 	 k7 f6 || yywre   )aiter_contentrj   rk   rl   )r"   rf   rg   rm   rn   ro   rp   lines           r   aiter_lineszResponse.aiter_lines   s      --Tb-c 	 	%"%I.((*rur2%)1K))+ 
	c M s&   BBBBA#BB
Bc                v  K   |rt        j                  d       |r
t               | j                  r| j                  sJ d       	 | j                  j                          d{   }t        |t              r| j                          d{    ||| j                          d{    y| m7 O7 )7 wrs   )	rt   ru   rv   r   r-   rS   rL   r   acloserx   s       r   r   zResponse.aiter_content   s      MMUV%''zzdiiF)FF'**..**E %/kkm## }kkm##K * $
 $s6   A!B9#B3$'B9B5B9'B7(B95B97B9c                 \   K   | j                  | j                          d{         S 7 w)z*
        Return a decoded string.
        N)rZ   acontentrF   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.Nr$   )r   appendjoin)r"   chunksro   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}   )rA   rF   s    r   r   zResponse.aclose  s(      #### #s   '%'c                 "    d| j                    dS )Nz<Response [z]>)r5   rF   s    r   __repr__zResponse.__repr__  s    T--.b11r$   )NN)NFN)NF)r%   r&   r'   r(   r
   r   r   r#   propertyr)   rG   rE   setterrK   r[   bytesrZ   rc   rq   ri   r{   r   r   r   r   r   r   r   r*   r$   r   r,   r,       s   ,Xd^ Xg=N ,    #  ( __c d  
 (3-   c  /u / /Q
44)&643S 3   $2# 2r$   r,   )r   rert   concurrent.futuresr   r{   r   typingr   r   r   r   r	   r
   r   r0   r   r8   r   r^   r   r   r   compilerT   Queuer   r   r,   r*   r$   r   <module>r      s`     	  %  H H H   ! RZZ+,
5;;  u2 u2r$   