
    nbiO                    0   d dl mZ d dlZd dlZ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 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mZ dd
lmZmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% ej&        rd dl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.  G d de          Z/dS )    )annotationsN)asynccontextmanager)timeout   )HTTPHeaderDict)
_TYPE_BODY)AsyncLowLevelResponse)BaseSSLError	HTTPErrorIncompleteReadProtocolErrorReadTimeoutErrorResponseNotReadySSLErrorMustRedialError)ContentDecoderHTTPResponse)is_fp_closedBytesQueueBuffer)Retry   )AsyncHTTPConnection)Message)AsyncHTTPConnectionPool)AsyncExtensionFromHTTP)AsyncTrafficPolicec                     e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dEdFd#ZdGd&ZedHd(            ZdId)ZedJd+            Z	edKd-            Z
dLd0ZdMd2ZedNd4            ZdOdPd7Z	 dOdPd8Z	 	 dQdRd:Z	 	 	 dSdTd=Z	 dUdVd@ZdIdAZdWdCZdIdDZdS )XAsyncHTTPResponse Nr   Tbodyr   headers>typing.Mapping[str, str] | typing.Mapping[bytes, bytes] | Nonestatusintversionreason
str | Nonepreload_contentbooldecode_contentoriginal_responseAsyncLowLevelResponse | NonepoolAsyncHTTPConnectionPool | None
connectionAsyncHTTPConnection | NonemsgMessage | NoneretriesRetry | Noneenforce_content_lengthrequest_methodrequest_url
auto_closepolice_officer.AsyncTrafficPolice[AsyncHTTPConnection] | NonereturnNonec                   t          |t                    r|| _        nt          |          | _        	 t          |          | _        n# t
          $ r
 d| _        Y nw xY w|| _        || _        || _        d| _	        || _
        d | _        d | _        || _        d| _        d| j        v rW| j                            dd                                          }d |                    d          D             }d|v rd| _        d | _        || _        || _        d | _        d | _        || _        d| _        |t3          j        d	t6          d
           || _        |r#t          |t:          t<          f          r|| _        |	| _        |
| _         tC          |d          r|| _        d | _"        || _#        | $                    | j#                  | _%        tM                      | _'        || _(        || _)        | j(        S| j(        *                    | | j                    | j(        j+        )| j(        j+        *                    | | j                   d S d S d S )Nr   Fztransfer-encodingr   c              3  >   K   | ]}|                                 V  d S N)strip).0encs     n/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/urllib3_future/_async/response.py	<genexpr>z-AsyncHTTPResponse.__init__.<locals>.<genexpr>R   s*      BBBBBBBB    ,chunkedTzjPassing msg=.. is deprecated and no-op in urllib3.future and is scheduled to be removed in a future major.r   )
stacklevelread),
isinstancer   r!   r$   r#   
ValueErrorr%   r&   r*   _has_decoded_content_request_url_retries
_extensionr3   rG   getlowersplit_decoderr5   r8   _body_fp_original_response_fp_bytes_readwarningswarnDeprecationWarningr1   strbytes_pool_connectionhasattr
chunk_left_request_method_init_lengthlength_remainingr   _decoded_buffer_police_officer_preloaded_contentmemorizeparent)selfr    r!   r#   r%   r&   r(   r*   r+   r-   r/   r1   r3   r5   r6   r7   r8   r9   tr_enc	encodingss                       rC   __init__zAsyncHTTPResponse.__init__&   st   ( g~.. 	3"DLL)'22DL	f++DKK 	 	 	DKKK	,$)!(3&*9=$,..\%%&92>>DDFFFBBS0A0ABBBII%%#/3&<#$
IM"3?M|"     	Jtc5\22 	DJ.2
0:4   	DH '+ ,:,0,=,=d>R,S,S  011  	 )8+ ))$0@AAA#*6$+44T4:FFFFF	 ,+ 76s   A AAb	bytearrayc                   K   |                      t          |                     d {V }t          |          dk    rdS ||d t          |          <   t          |          S )Nr   )rI   len)ri   rm   temps      rC   readintozAsyncHTTPResponse.readinto   sb      YYs1vv&&&&&&&&t99>>1!AkD		kNt99rE   !typing.AsyncGenerator[None, None]c               T  K   d}	 	 dW V  n# t           $ r}t          | j        dd          |d}~wt          $ r=}dt	          |          vrt          |          |t          | j        dd          |d}~wt          t          f$ r}t          d||          |d}~ww xY wd}|sF| j	        r| j	        
                                 | j        r| j        
                                 d{V  | j	        r/| j	                                        r|                                  dS dS dS # |sF| j	        r| j	        
                                 | j        r| j        
                                 d{V  | j	        r.| j	                                        r|                                  w w w xY w)z
        Catch low-level python exceptions, instead re-raising urllib3
        variants, so that low-level exceptions are not leaked in the
        high-level api.

        On exit, release the connection back to the pool.
        FNzRead timed out.zread operation timed outzConnection broken: T)SocketTimeoutr   r]   r
   r[   r   OSErrorr   r   rV   closer^   isclosedrelease_conn)ri   
clean_exites      rC   _error_catcherz AsyncHTTPResponse._error_catcher   sG      
+	$K  S S S 'tz49JKKQRR S S S-SVV;;"1++1,&tz49JKKQRR_- K K K#$?!$?$?CCJK J  3 * 4+11333
 # 3*00222222222 & $4+B+K+K+M+M $!!#####$ $ $ $  3 * 4+11333
 # 3*00222222222 & $4+B+K+K+M+M $!!####$ $s;    D' 
B .B 8A33B BB  D' 'B F'c                |   K   	 |                                   d{V  dS # t          t          t          f$ r Y dS w xY w)z
        Read and discard any remaining HTTP response data in the response connection.

        Unread data in the HTTPResponse connection blocks the connection from being released back to the pool.
        N)rI   r   rv   r
   ri   s    rC   
drain_connzAsyncHTTPResponse.drain_conn   sZ      	))++7L1 	 	 	DD	s     ;;HTTPHeaderDict | Nonec                Z    | j         dS t          | j         d          r| j         j        S dS )z
        Retrieve post-response (trailing headers) if any.
        This WILL return None if no HTTP Trailer Headers have been received.
        Ntrailers)rU   r_   r   r~   s    rC   r   zAsyncHTTPResponse.trailers   s5     8448Z(( 	%8$$trE   AsyncExtensionFromHTTP | Nonec                    | j         S r?   )rO   r~   s    rC   	extensionzAsyncHTTPResponse.extension   s
    rE   itemr   c                   K   | j         t          d          t          | j        d          st	                      |                    |            d {V  || _         d S )Nzextension already plugged in_dsa)rO   rv   r_   rU   r   start)ri   r   s     rC   start_extensionz!AsyncHTTPResponse.start_extension   sl      ?&8999tx(( 	%"$$$jjrE   
typing.Anyc                n   K   | j          d{V                     d          }t          j        |          S )a  
        Parses the body of the HTTP response as JSON.

        To use a custom JSON decoder pass the result of :attr:`HTTPResponse.data` to the decoder.

        This method can raise either `UnicodeDecodeError` or `json.JSONDecodeError`.

        Read more :ref:`here <json>`.
        Nzutf-8)datadecode_jsonloads)ri   r   s     rC   jsonzAsyncHTTPResponse.json   s9       i''00{4   rE   r\   c                l   K   | j         r| j         S | j        r|                     d           d {V S d S )NT)cache_content)rT   rU   rI   r~   s    rC   r   zAsyncHTTPResponse.data   sO       : 	:8 	7666666666trE   amt
int | Nonec                  K   | j         sJ d}|r||k    s| j        r| j        |k    rt          j        dk     rt	          j                    }d}||dk    r|t          ||          }||z  }n|}	 t          | j         t                    r!| j         	                    |           d{V }n| j         	                    |          }n# t          $ r Y n%w xY w|sn|                    |           ~||dk    |                                S t          | j         t                    r | j         	                    |           d{V S || j         	                    |          n| j         	                                S )a_  
        Read a response with the thought that reading the number of bytes
        larger than can fit in a 32-bit int at a time via SSL in some
        known cases leads to an overflow error that has to be prevented
        if `amt` or `self.length_remaining` indicate that a problem may
        happen.

        The known cases:
          * 3.8 <= CPython < 3.9.7 because of a bug
            https://github.com/urllib3/urllib3/issues/2513#issuecomment-1152559900.
          * urllib3 injected with pyOpenSSL-backed SSL-support.
          * CPython < 3.10 only when `amt` does not fit 32-bit int.
        i)   
   i   Nr   )rU   rc   sysversion_infoioBytesIOminrJ   r	   rI   rK   writegetvalue)ri   r   	c_int_maxbuffermax_chunk_amt	chunk_amtr   s          rC   _fp_readzAsyncHTTPResponse._fp_read	  s      x	"	N9__% %*.*?)*K*K((Z\\F "M+? #C 7 7I9$CC -I!$(,ABB 8%)X]]9%=%=======#x}}Y77!   E T"""! +" ??$$$ $($9:: 0!X]]3/////////),48==%%%dhmmooMs   0AC 
CCc                  K   | j         dS t          | j         dd          }|                                 4 d{V  |s|                     |           d{V nd}|du ot          | j         dd          du }||dk    r|r|r|rA| xj        t          |          z  c_        | j        | xj        t          |          z  c_        | j                                          | j        r,| j        %| j        dk    rt          | j        | j                  	 ddd          d{V  n# 1 d{V swxY w Y   |rC|sA| xj        t          |          z  c_        | j        | xj        t          |          z  c_        |S )z7
        Reads `amt` of bytes from the socket.
        NclosedFrE   r   )
rU   getattrr|   r   rW   rp   rc   rw   r5   r   )ri   r   	fp_closedr   is_foreign_fp_uncloseds        rC   	_raw_readzAsyncHTTPResponse._raw_read=  sd      84DHh66	&&(( #	U #	U #	U #	U #	U #	U #	U #	U5>G$--,,,,,,,,,CD tK(E B Be K # C1HHTH>TH) ;''3t994'',8--T:--    /
U-9-22 ))<d>STTTTG#	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	U #	UJ  	3. 	33t99,$0%%T2%%s   CD&&
D03D0bool | Nonec                   K   |                      |pd|           d{V }|Gt          |          |k    r4| j                            |           | j                            |          S |S )a  
        Similar to ``http.client.HTTPResponse.read1`` and documented
        in :meth:`io.BufferedReader.read1`, but with an additional parameter:
        ``decode_content``.

        :param amt:
            How much of the content to read.

        :param decode_content:
            If True, will attempt to decode the body based on the
            'content-encoding' header.
        r   r*   N)rI   rp   rd   putrP   ri   r   r*   r   s       rC   read1zAsyncHTTPResponse.read1u  s      $ YY	r)  
 
 
 
 
 
 
 

 ?s4yy3 $$T***'++C000rE   Fr   c                ,  K   	 |                                   || j        }|d}|dk     rt          | j                  r| j                            t          | j                            | j        r~t          | j        d          rj| j        j        r_| j        Yt          | j        d          r| j        j	        | j        j	        j
        du r&| j                            |            d | _        S S S S S S d|cxk     rt          | j                  k    rn n| j                            |          | j        r~t          | j        d          rj| j        j        r_| j        Yt          | j        d          r| j        j	        | j        j	        j
        du r&| j                            |            d | _        S S S S S S | j        `| j                            |           4 d {V  |                     |           d {V }d d d           d {V  n# 1 d {V swxY w Y   n|                     |           d {V }|r|dk     rt          |          }d}|d}n
|dk    r|sd}|st          | j                  dk    r|| j        r~t          | j        d          rj| j        j        r_| j        Yt          | j        d          r| j        j	        | j        j	        j
        du r&| j                            |            d | _        S S S S S S |"|                     |||          }|r|| _        n|s| j        rt#          d          || j        r~t          | j        d          rj| j        j        r_| j        Yt          | j        d          r| j        j	        | j        j	        j
        du r&| j                            |            d | _        S S S S S S |                     |||          }| j                            |           t          | j                  |k     r|r| j        `| j                            |           4 d {V  |                     |           d {V }d d d           d {V  n# 1 d {V swxY w Y   n|                     |           d {V }|                     |||          }| j                            |           t          | j                  |k     r|| j                            |          }|| j        r~t          | j        d          rj| j        j        r_| j        Yt          | j        d          r| j        j	        | j        j	        j
        du r&| j                            |            d | _        S S S S S S # | j        r}t          | j        d          rh| j        j        r\| j        Ut          | j        d          r| j        j	        | j        j	        j
        du r!| j                            |            d | _        w xY w)NFr   _eotr   Tz_Calling read(decode_content=False) is not supported after read(decode_content=True) was called.)_init_decoderr*   rp   rd   rP   rU   r_   r   re   r   r   forgetborrowr   _decoderT   rL   RuntimeErrorr   )ri   r   r*   r   r   flush_decoderdecoded_datas          rC   rI   zAsyncHTTPResponse.read  s(     N	0   %!%!4 %77s4#7887/33C8L4M4MNNr 0DHf--0 HM0 (4  &110x},x}+t33(//555+/D((0 0 0 5 4A s7777c$"67777777/33C88l 0DHf--0 HM0 (4  &110x},x}+t33(//555+/D((0 0 0 5 4{ #//66t<< 5 5 5 5 5 5 5 5!%!4!4444444D5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 "^^C00000000  sQww$ii!M{ $$ $ C 455::H 0DHf--0 HM0 (4  &110x},x}+t33(//555+/D((0 0 0 5 4W {||D.-HH  &!%DJ &  0 *D    , 0DHf--0 HM0 (4  &110x},x}+t33(//555+/D((0 0 0 5 4;  $||D.-PP$((666$.//#55$5 +7#'#7#>#>t#D#D = = = = = = = =)-)<)<#<#<#<#<#<#<D= = = = = = = = = = = = = = = = = = = = = = = = = = = &*^^C%8%8888888#'<<nm#T#TL(,,\::: $.//#55$5 +//44 0DHf--0 HM0 (4  &110x},x}+t33(//555+/D((0 0 0 5 4 0DHf--0 HM0 (4  &110x},x}+t33(//555+/D(////sp   A'V 5;V :'V !H=V 
HV HA"V 	=V A2V Q0V 0
Q::V =Q:>BV BX   "typing.AsyncGenerator[bytes, None]c                 K   | j         d S t          | j                   rt          | j                  dk    rR|                     ||           d {V }|r|W V  t          | j                   8t          | j                  dk    Pd S d S )Nr   r   )rU   r   rp   rd   rI   r   s       rC   streamzAsyncHTTPResponse.stream  s       8Ftx(( 	C0D,E,E,I,Is>JJJJJJJJD 



	 tx(( 	C0D,E,E,I,I,I,I,I,IrE   c                \  K   | j         -| j         j        du r| j                                          d {V  | j        s | j        r| j                                         | j        r| j                                         d {V  | j        s!t          j                            |            d S d S )NF)r   r   rw   rU   r^   r8   r   IOBaser~   s    rC   rw   zAsyncHTTPResponse.close  s      >%$.*?5*H*H.&&((((((((({ 	tx 	HNN 	+"((********* 	"IOOD!!!!!	" 	"rE   typing.AsyncIterator[bytes]c               ~  K   g }|                      dd          2 3 d {V }d|v rc|                    d          }d                    |          |d         z   dz   W V  |dd         D ]
}|dz   W V  |d         r
|d         g}kg }n|                    |           6 |rd                    |          W V  d S d S )Nr   T)r*      
rE   r   r   )r   rR   joinappend)ri   r   chunkchunksxs        rC   	__aiter__zAsyncHTTPResponse.__aiter__   s      ;;r$;?? 	% 	% 	% 	% 	% 	% 	%%~~U++hhv&&2U:::::" $ $Ae)OOOOO":  $Rj\FFFFe$$$$ @  	#((6""""""""	# 	#s   B c                    | j         sO| j         s | j        r| j                                         | j        s#t          j                            |            d S d S d S r?   )r   rU   rw   r8   r   r   r~   s    rC   __del__zAsyncHTTPResponse.__del__  si    { 	&; !48 !   ? &	%%%%%	& 	&& &rE   )r   Nr   r   NTTNNNNNTNNTN)$r    r   r!   r"   r#   r$   r%   r$   r&   r'   r(   r)   r*   r)   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r)   r6   r'   r7   r'   r8   r)   r9   r:   r;   r<   )rm   rn   r;   r$   )r;   rs   )r;   r<   )r;   r   )r;   r   )r   r   r;   r<   )r;   r   )r;   r\   r?   )r   r   r;   r\   )NN)r   r   r*   r   r;   r\   )NNF)r   r   r*   r   r   r)   r;   r\   )r   N)r   r   r*   r   r;   r   )r;   r   )__name__
__module____qualname__rl   rr   r   r|   r   propertyr   r   r   r   r   r   r   r   rI   r   rw   r   r    rE   rC   r   r   %   s$        RV! $#:>/315" $'+%)"&IM%aG aG aG aG aGF    5$ 5$ 5$ 5$n	 	 	 	    X    X	 	 	 	! ! ! !    X2N 2N 2N 2N 2Nl 6 6 6 6 6t &*    > &*#	T0 T0 T0 T0 T0n FJ	 	 	 	 	" " " "# # # #"& & & & & &rE   r   )0
__future__r   r   r   r   r   typingrX   
contextlibr   socketr   ru   _collectionsr   _typingr   backend._asyncr	   
exceptionsr
   r   r   r   r   r   r   r   responser   r   util.responser   r   
util.retryr   r/   r   TYPE_CHECKINGemail.messager   _async.connectionpoolr   contrib.webextensions._asyncr   util._async.traffic_policer   r   r   rE   rC   <module>r      s   " " " " " " 				     



   * * * * * * + + + + + + ) ) ) ) ) )             2 2 2 2 2 2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 4 3 3 3 3 3 3 3 : : : : : : : :       + + + + + +	 @%%%%%%??????EEEEEE??????r& r& r& r& r& r& r& r& r& r&rE   