
    hw(                        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
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 n# e$ r	 d dlmZ Y nw xY w ee          5  d dlmZ d dlZ ddd           n# 1 swxY w Y    ej!        d          Z" e#            Z$dej%        fdZ& G d d          Z' G d d          Z(dS )    )suppressN)Future)AnyCallableOptionalUnion)	Awaitable   )Curl)CurlCffiWarning   )Cookies)	HTTPErrorRequestException)Headers)loads)markdownifyzcharset=([\w-]+)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    W/var/www/html/marketdash/venv/lib/python3.11/site-packages/curl_cffi/requests/models.pyclear_queuer      s    	
  		##%%%                 s   :AAAc                   &    e Zd ZdZdededefdZdS )RequestzRepresenting a sent 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____doc__strr   r%    r&   r   r   r   $   sC        &&C ' 3      r&   r   c                   Z   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dS )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.
        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.
    Ncurlrequestc                    || _         || _        d| _        d| _        d| _        d| _        d| _        t                      | _        t                      | _
        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        g | _        i | _        d | _        d | _        d | _        d | _        d S )	N r&      OKTg        utf-8r   )r/   r0   r    contentstatus_codereasonokr   r!   r   cookies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)r$   r/   r0   s      r   r%   zResponse.__init__J   s    	yyyyDK!!" -/%'
,0
-115r&   returnc                     | j         S )zAlias for encoding.)encodingr$   s    r   charsetzResponse.charsetd   s     }r&   c                     t          | d          sb| j        }|Pt          | j        t                    r| j        }n.t          | j                  r|                     | j                  }|p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.
        	_encodingNr5   )hasattrcharset_encoding
isinstancer<   r+   callabler6   rO   )r$   rK   s     r   rK   zResponse.encodingi   s     t[)) 	1,Hd3S99 C#4HHd344 C#44T\BBH%0DN~r&   valuec                 R    t          | d          rt          d          || _        d S )N_textz0Cannot set encoding after text has been accessed)rP   
ValueErrorrO   )r$   rT   s     r   rK   zResponse.encoding   s/    4!! 	QOPPPr&   c                     | j                             d          }|r3t                              |          }|r|                    d          ndS dS )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   rQ   zResponse.charset_encoding   sX     |''77 	E&--l;;M-:D=&&q)))Dtr&   c                     t          | d          s.| j        sd| _        n|                     | j                  | _        | j        S )NrV   r2   )rP   r6   rV   _decoderL   s    r   textzResponse.text   sD    tW%% 	8< 8

!\\$,77
zr&   c                     t          j        | j                  }|                                }|                    d          }t          d| d| d          }|S )NT)html_partialz<h1>z</h1><main>z</main>)rdDocumentr6   titlesummarymd)r$   docrf   rg   
body_as_mds        r   markdownzResponse.markdown   sZ    k$,''		++4+00AuAAAAABB
r&   r6   c                     	 |                     | j        d          S # t          t          f$ r |                     d          cY S w xY w)Nreplace)errorsz	utf-8-sig)decoderK   UnicodeDecodeErrorLookupError)r$   r6   s     r   r`   zResponse._decode   sW    	/>>$-	>BBB"K0 	/ 	/ 	/>>+.....	/s    &AAc                 V    | j         s!t          d| j         d| j         d|           dS )z2Raise an error if status code is not in [200, 400)zHTTP Error z: r   N)r9   r   r7   r8   rL   s    r   raise_for_statuszResponse.raise_for_status   sB    w 	VK$*:KKdkKKQPTUUU	V 	Vr&   Fc              #   :  K   d}|                      ||          D ]v}|||z   }|r|                    |          n|                                }|r6|d         r.|r,|d         d         |d         k    r|                                nd}|E d{V  w||V  dS dS 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$   rv   rw   	delimiterpendingchunkliness          r   
iter_lineszResponse.iter_lines   s       &&!. ' 
 
 	 	E "%.7OEKK	***U=M=M=O=OE "2Y+05:2Yr]eBi5O5O 		  MMMMM r&   c              #   F  K   |rt          j        dt          d           |rt                      | j        r| j        s
J d            	 | j                                        }t          |t                    r| j        	                                 ||t          u rdS |V  Y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.TN)warningswarnr   NotImplementedErrorr   r/   rY   rR   r   reset
STREAM_ENDr$   rv   rw   r   s       r   ry   zResponse.iter_content   s        	MK   
  	(%'''zFdiFF)FFFF	JNN$$E %!122 	!!! 
""KKK	r&   c                 &    t          | j        fi |S )z+return a parsed json object of the content.)r   r6   )r$   kws     r   jsonzResponse.json   s    T\((R(((r&   c                     | j         r| j                                          | j        r| j                                         dS dS z:Close the streaming connection, only valid in stream mode.N)rH   setrF   resultrL   s    r   closezResponse.close   sR     = 	 M 	&##%%%%%	& 	&r&   c                L  K   d}|                      ||          2 3 d{V }|||z   }|r|                    |          n|                                }|r6|d         r.|r,|d         d         |d         k    r|                                nd}|D ]}|W V  ~6 ||W V  dS dS ru   )aiter_contentrz   r{   r|   )r$   rv   rw   r}   r~   r   r   lines           r   aiter_lineszResponse.aiter_lines   s      --!. . 
 
 	 	 	 	 	 	 	% "%.7OEKK	***U=M=M=O=OE "2Y+05:2Yr]eBi5O5O 		    





 MMMMMM s   Bc                  K   |rt          j        dt          d           |rt                      | j        r| j        s
J d            	 | j                                         d{V }t          |t                    r| 	                                 d{V  ||t          u r| 	                                 d{V  dS |W V  {r   )r   r   r   r   r   r/   rY   rR   r   acloser   r   s       r   r   zResponse.aiter_content  s
       	MK   
  	(%'''zFdiFF)FFFF	*..********E %!122 kkmm####### 
""kkmm#######KKKK	r&   c                 `   K   |                      |                                  d{V           S )z*
        Return a decoded string.
        N)r`   acontentrL   s    r   atextzResponse.atext%  s4       ||$--//111111222r&   c                    K   g }|                                  2 3 d{V }|                    |           6 d                    |          S )z8wait and read the streaming content in one bytes object.Nr&   )r   appendjoin)r$   chunksr   s      r   r   zResponse.acontent+  sk      --// 	! 	! 	! 	! 	! 	! 	!%MM%     0xxs   6c                 6   K   | j         r| j          d{V  dS dS r   )rG   rL   s    r   r   zResponse.aclose2  s>        	$##########	$ 	$r&   c                     d| j          dS )Nz<Response [z]>)r7   rL   s    r   __repr__zResponse.__repr__9  s    1T-1111r&   )NN)NFN)NF)r'   r(   r)   r*   r   r   r   r%   propertyr+   rM   rK   setterrQ   ra   rk   bytesr`   rs   r   ry   r   r   r   r   r   r   r   r   r,   r&   r   r.   r.   -   s;        8 Xd^ Xg=N    4     X #    X* _c d    _
 (3-    X c    X#    /u / / / / /V V V
   4   :) ) )& & &   6   <3S 3 3 3 3         $ $ $2# 2 2 2 2 2 2r&   r.   ))
contextlibr   r   rer   concurrent.futuresr   typingr   r   r   r   collections.abcr	   r/   r   utilsr   r:   r   
exceptionsr   r   r!   r   orjsonr   ImportErrorr   r   rh   readabilityrd   compilerZ   objectr   Queuer   r   r.   r,   r&   r   <module>r      sL          				  % % % % % % 1 1 1 1 1 1 1 1 1 1 1 1 % % % % % %       # # # # # #       3 3 3 3 3 3 3 3          Xk  ------               RZ+,,
VXX
5;           M2 M2 M2 M2 M2 M2 M2 M2 M2 M2s$   A A! A!/BB
B
