
    )Jf.                         d dl Z d dlmZ d dlmZ d dlZddlmZ ddlm	Z	 ddl
mZ dd	lmZ d
ej        fdZ G d d          Z G d d          ZdS )    N)loads)Optional   )Curl   )Headers)Cookies)RequestsErrorqc                     | j         5  | j                                         | j                                         d| _        d d d            d S # 1 swxY w Y   d S )Nr   )mutexqueueclearall_tasks_done
notify_allunfinished_tasks)r   s    \/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/curl_cffi/requests/models.pyclear_queuer      s    	
  		##%%%                 s   :AAAc                   "    e Zd ZdededefdZdS )Requesturlheadersmethodc                 0    || _         || _        || _        d S N)r   r   r   )selfr   r   r   s       r   __init__zRequest.__init__   s        N)__name__
__module____qualname__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dede	fdZ
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S )Responsea  Contains information the server sends.

    Attributes:
        url: url used in the request.
        content: response body in bytes.
        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.
        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                 X   || _         || _        d| _        d| _        d| _        d| _        d| _        t                      | _        t                      | _
        d| _        d| _        | j        | _        d| _        d| _        d| _        g | _        i | _        d | _        d | _        d | _        d S )	N r      OKTg        zutf-8r   )r&   r'   r   contentstatus_codereasonokr   r   r	   cookieselapsedencodingcharsetredirect_countredirect_urlhttp_versionhistoryinfosr   stream_taskquit_now)r   r&   r'   s      r   r   zResponse.__init__.   s    	yyyy}
,0
r   r,   returnc                     	 |                     | j        d          S # t          t          f$ r |                     d          cY S w xY w)Nreplace)errorsz	utf-8-sig)decoder3   UnicodeDecodeErrorLookupError)r   r,   s     r   _decodezResponse._decodeD   sW    	/>>$,y>AAA"K0 	/ 	/ 	/>>+.....	/s    &AAc                 6    |                      | j                  S r   )rB   r,   r   s    r   textzResponse.textJ   s    ||DL)))r   c                 R    | j         st          d| j         d| j                   d S )NzHTTP Error z: )r/   r
   r-   r.   rD   s    r   raise_for_statuszResponse.raise_for_statusN   s=    w 	Q Od.> O O$+ O OPPP	Q 	Qr   Fc              #   >  K   d}|                      ||          D ]x}|||z   }|r|                    |          }n|                                }|r7|d         r/|r-|d         d         |d         k    r|                                }nd}|E d{V  y||V  dS dS z
        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   rJ   rK   	delimiterpendingchunkliness          r   
iter_lineszResponse.iter_linesR   s      
 &&!. ' 
 
 	 	E "% +I..((** r u r2%)1K1K))++MMMMM r   c              #   *  K   |rt          j        d           |rt                      	 | j                                        }t          |t                    r| j                                         ||| j                                         d S |V  kNz9chunk_size is ignored, there is no way to tell curl that.)	warningswarnNotImplementedErrorr   get
isinstancer
   r&   resetr   rJ   rK   rS   s       r   rM   zResponse.iter_contentl   s       	WMUVVV 	(%'''	JNN$$E %// 	!!! }	!!!KKK	r   c                 &    t          | j        fi |S r   )r   r,   )r   kws     r   jsonzResponse.json   s    T\((R(((r   c                 j    | j                                          | j                                         d S r   )r:   setr9   resultrD   s    r   closezResponse.close   s1    !!!!!r   c                P  K   d}|                      ||          2 3 d{V }|||z   }|r|                    |          }n|                                }|r7|d         r/|r-|d         d         |d         k    r|                                }nd}|D ]}|W V  6 ||W V  dS dS rI   )aiter_contentrN   rO   rP   )r   rJ   rK   rQ   rR   rS   rT   lines           r   aiter_lineszResponse.aiter_lines   s     
 --!. . 
 
 	 	 	 	 	 	 	% "% +I..((** r u r2%)1K1K))++  





" MMMMMM s   Bc                <  K   |rt          j        d           |rt                      	 | j                                         d {V }t          |t                    r|                                  d {V  |||                                  d {V  d S |W V  trW   )rX   rY   rZ   r   r[   r\   r
   acloser^   s       r   rg   zResponse.aiter_content   s       	WMUVVV 	(%'''	*..********E %// kkmm####### }kkmm#######KKKK	r   c                 `   K   |                      |                                  d {V           S r   )rB   acontentrD   s    r   atextzResponse.atext   s2      ||$--//111111222r   c                    K   g }|                                  2 3 d {V }|                    |           6 d                    |          S )Nr   )rg   appendjoin)r   chunksrS   s      r   rm   zResponse.acontent   sk      --// 	! 	! 	! 	! 	! 	! 	!%MM%     0xxs   6c                 $   K   | j          d {V  d S r   )r9   rD   s    r   rk   zResponse.aclose   s'      r   )NN)NFN)NF)r   r    r!   __doc__r   r   r   r   bytesr"   rB   propertyrE   rG   rU   rM   ra   re   ri   rg   rn   rm   rk   r#   r   r   r%   r%      s\        & Xd^ Xg=N    ,/u / / / / / *c * * * X*Q Q Q   4   () ) )" " "   6   *3S 3 3 3 3             r   r%   )rX   ra   r   typingr   r   r)   r   r   r   r0   r	   r>   r
   Queuer   r   r%   r#   r   r   <module>ry      s                                   ! ! ! ! ! !5;           g g g g g g g g g gr   