o
    `g7                     @   s\  d dl Z d dlZd dlZd dl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
mZmZ d dlmZmZmZ d dlmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z  d dl!Z!d dl"m#Z#m$Z$m%Z%m&Z& d dl'm(Z( dd	l)m*Z*m+Z+m,Z,m-Z-m.Z. dd
l/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl+m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF ddl,mGZGmHZHmIZImJZJmKZK ddlLmMZM ddlNmOZO ddlPmQZQmRZRmSZSmTZTmUZUmVZV zd dlWZWd dlWmXZX W n eYy   dZWeZZXY nw dZ[erddl\m]Z] ddl^m_Z_ ddl`maZa ebdZcebdZddeefddZfe!jgddddG dd  d ZhG d!d" d"eZiG d#d$ d$eiZjG d%d& d&ZkeWdur]eWjXelekemdfZnnelemdfZnd'e d(elekf d)eel d*ed( d+eeo de d(elekf f
d,d-Zpeqd.ZrG d/d0 d0eZsd1eed2eedelfd3d4ZtG d5d6 d6Zue2d7ZvG d8d9 d9e?ZwdS ):    N)md5sha1sha256)CookieErrorMorselSimpleCookie)MappingProxyTypeTracebackType)TYPE_CHECKINGAnyCallableDictIterableListMapping
NamedTupleOptionalTupleTypeUnion)CIMultiDictCIMultiDictProxy	MultiDictMultiDictProxy)URL   )hdrshelpershttp	multipartpayload)AbstractStreamWriter)ClientConnectionErrorClientOSErrorClientResponseErrorContentTypeError
InvalidURLServerFingerprintMismatch
HAS_BROTLI)FormData)	_SENTINELBaseTimerContext	BasicAuthHeadersMixin	TimerNoopbasicauth_from_netrcnetrc_from_envnoopreifyset_exception
set_result)SERVER_SOFTWAREHttpVersionHttpVersion10HttpVersion11StreamWriter)client_logger)StreamReader)DEFAULT_JSON_DECODERJSONDecoderLooseCookiesLooseHeadersQuery
RawHeaders)
SSLContext)ClientRequestClientResponseRequestInfoFingerprint)ClientSession)
Connection)Tracez[^-!#$%&'*+.^_`|~0-9a-zA-Z]z!^application/(?:[\w.+-]+?\+)?jsonreturnc                   C   s   t rdS dS )Nzgzip, deflate, brzgzip, deflater(    rL   rL   P/var/www/html/propose/venv/lib/python3.10/site-packages/aiohttp/client_reqrep.py_gen_default_accept_encoding`      rN   T)auto_attribsfrozenslotsc                   @   s.   e Zd ZU ee ed< ded< ee ed< dS )ContentDispositiontypezMappingProxyType[str, str]
parametersfilenameN)__name__
__module____qualname__r   str__annotations__rL   rL   rL   rM   rS   d   s   
 rS   c                   @   s.   e Zd ZU eed< eed< ded< eed< dS )_RequestInfourlmethodCIMultiDictProxy[str]headersreal_urlN)rW   rX   rY   r   r[   rZ   rL   rL   rL   rM   r\   k   s
   
 r\   c                   @   s.   e Zd Zefdededddedd f
ddZd	S )
rF   r]   r^   r`   r_   ra   rK   c                 C   s$   t | ||||tu r|fS |fS )zuCreate a new RequestInfo instance.

        For backwards compatibility, the real_url parameter is optional.
        )tuple__new__r+   )clsr]   r^   r`   ra   rL   rL   rM   rc   t   s
   zRequestInfo.__new__N)rW   rX   rY   r+   r   rZ   rc   rL   rL   rL   rM   rF   r   s    rF   c                   @   sP   e Zd ZeeedZdeddfddZe	defddZ
d	ejddfd
dZdS )rG   )          fingerprintrK   Nc                 C   sH   t |}| j|}|std|tu s|tu rtd|| _|| _d S )Nzfingerprint has invalid lengthz8md5 and sha1 are insecure and not supported. Use sha256.)lenHASHFUNC_BY_DIGESTLENget
ValueErrorr   r   	_hashfunc_fingerprint)selfrh   	digestlenhashfuncrL   rL   rM   __init__   s   
zFingerprint.__init__c                 C      | j S N)rn   ro   rL   rL   rM   rh         zFingerprint.fingerprint	transportc                 C   s`   | dsd S | d}|jdd}| | }|| jkr.| d^}}}t| j|||d S )N
sslcontext
ssl_objectT)binary_formpeername)get_extra_infogetpeercertrm   digestrn   r'   )ro   rw   sslobjcertgothostport_rL   rL   rM   check   s   


zFingerprint.check)rW   rX   rY   r   r   r   rj   bytesrr   propertyrh   asyncio	Transportr   rL   rL   rL   rM   rG      s    
rG   sslrC   
verify_sslssl_contextrh   c                 C   s   | d u rd} |d ur|st jdtdd | durtdd} |d ur4t jdtdd | dur2td|} |d urLt jdtdd | durHtdt|} t| tsXtd	| | S )
NTz/verify_ssl is deprecated, use ssl=False instead   
stacklevelzNverify_ssl, ssl_context, fingerprint and ssl parameters are mutually exclusiveFz2ssl_context is deprecated, use ssl=context insteadzCfingerprint is deprecated, use ssl=Fingerprint(fingerprint) insteadzFssl should be SSLContext, bool, Fingerprint or None, got {!r} instead.)	warningswarnDeprecationWarningrl   rG   
isinstanceSSL_ALLOWED_TYPES	TypeErrorformat)r   r   r   rh   rL   rL   rM   _merge_ssl_params   sR   
r   )httpswssc                   @   s`   e Zd ZU eed< ee ed< eed< ee	ee
f ed< ee ed< ee ed< ee ed< dS )	ConnectionKeyr   r   is_sslr   proxy
proxy_authproxy_headers_hashN)rW   rX   rY   rZ   r[   r   intboolr   rC   rG   r   r-   rL   rL   rL   rM   r      s   
 r   response_content_typeexpected_content_typec                 C   s   |dkrt | d uS || v S )Napplication/json)json_rematch)r   r   rL   rL   rM   _is_expected_content_type   s   r   c                0   @   s  e Zd ZU ejejejejhZej	ej
ejhZeeejhZejdeje iZdZeed< dZdZdZdZdZed ed< ddddddejddddddddddddddd	d
ede de!dee" dee#e  dedee$ dee% dej&de'ee(df dee( de(dee)j* dee+d  dee  dee% dee, ded de'e-e(e.f dee" d ee/d!  d"e(d#ee f.d$d%Z0ded&e1d'dfd(d)Z2e3d'e4d fd*d+Z5e3d'ed, fd-d.Z6e6j7dfd0d.Z6d'e(fd1d2Z8e3d'e'd3e(e.f fd4d5Z9e3d'e:fd6d7Z;e3d'efd8d9Z<e3d'ee= fd:d;Z>e3d'e?fd<d=Z@de d'dfd>d?ZAde'ej&ef d'dfd@dAZBdee" d'dfdBdCZCdee#e  d'dfdDdEZDdee$ d'dfdFdGZEded'dfdHdIZFdgdJdKZGdhdee% d"e(d'dfdLdMZHded'dfdNdOZIdhdPe(d'dfdQdRZJdee  dee% dee" d'dfdSdTZKd/eLdUdVd'dfdWdXZMdidYdZZNdgd[d\ZOdgd]d^ZPd
ede d_eQd'dfd`daZRd
ede ddbd'dfdcddZSdS )jrD   z*/*    bodyNzCIMultiDict[None]_skip_auto_headersFT)paramsr`   skip_auto_headersdatacookiesauthversioncompresschunked	expect100loopresponse_classr   r   timersessionr   proxy_headerstraces	trust_envserver_hostnamer^   r]   r   r`   r   r   r   r   r   r   r   r   r   r   rE   r   r   r   r   rH   r   r   r   rJ   r   r   c                C   s  |d u rt  }t| }rtd|d| dt|tu s&J ||d ur4t|tu s4J |tr<|d us<J || _	|rF|
|}|| _|jrQ|d n|| _| | _|| _|
| _|| _d | _|d u rlt}n|}|| _|d urw|nt | _|d ur|nd| _|| _| rttd| _ | !|	 | "| | #| | $| | %| | &| | '|| | (||| | )| |d us| j| j*vr| +  | ,| |d u rg | _-d S || _-d S )Nz+Method cannot contain non-token characters z (found at least )Tr   ).r   get_event_loop_CONTAINS_CONTROL_CHAR_REsearchrl   grouprT   r   r
   _sessionextend_queryoriginal_urlraw_fragmentwith_fragmentr]   upperr^   r   r   r   lengthrE   r   r/   _timer_sslr   	get_debug	tracebackextract_stacksys	_getframe_source_tracebackupdate_versionupdate_hostupdate_headersupdate_auto_headersupdate_cookiesupdate_content_encodingupdate_authupdate_proxyupdate_body_from_dataGET_METHODSupdate_transfer_encodingupdate_expect_continue_traces)ro   r^   r]   r   r`   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   real_response_classrL   rL   rM   rr     sZ   









zClientRequest.__init__r   rK   c                 C   
   d | _ d S rt   _ClientRequest__writerro   r   rL   rL   rM   __reset_writerh     
zClientRequest.__reset_writerc                 C   s   | j pt S rt   )r   r   ru   rL   rL   rM   r   k  s   zClientRequest.skip_auto_headersasyncio.Task[None]c                 C   rs   rt   r   ru   rL   rL   rM   _writero  rv   zClientRequest._writerwriterc                 C   s.   | j d ur| j | j || _ || j d S rt   )r   remove_done_callback_ClientRequest__reset_writeradd_done_callbackro   r   rL   rL   rM   r   s  s   
c                 C   s   | j jtv S rt   )r]   scheme_SSL_SCHEMESru   rL   rL   rM   r   z  rO   zClientRequest.is_sslrC   c                 C   rs   rt   )r   ru   rL   rL   rM   r   }  rv   zClientRequest.sslc              
   C   sT   | j  }rtt| }nd }| j}tt|jpd|j|j	t
v | j| j| j|fS )N )r   hashrb   itemsr]   rc   r   raw_hostr   r   r   r   r   r   )ro   r   hr]   rL   rL   rM   connection_key  s   
zClientRequest.connection_keyc                 C   s   | j j}|d us
J |S rt   )r]   r   )ro   retrL   rL   rM   r     s   zClientRequest.hostc                 C   s   | j jS rt   )r]   r   ru   rL   rL   rM   r     s   zClientRequest.portc                 C   s$   t | j}tt| j| j|| jfS rt   )r   r`   rb   rc   rF   r]   r^   r   )ro   r`   rL   rL   rM   request_info  s   
zClientRequest.request_infoc                 C   s<   |j st||js|jrt|jpd|jpd| _dS dS )z8Update destination host, port and connection type (ssl).r   N)	r   r&   raw_userraw_passwordr   r-   userpasswordr   )ro   r]   rL   rL   rM   r     s
   zClientRequest.update_hostc                 C   sj   t |tr0dd |ddD }ztt|d t|d }W n ty/   td| dw || _dS )zdConvert request version to two elements tuple.

        parser HTTP version '1.1' => (1, 1)
        c                 S   s   g | ]}|  qS rL   )strip).0partrL   rL   rM   
<listcomp>  s    z0ClientRequest.update_version.<locals>.<listcomp>.r   r   z#Can not parse http version number: N)r   rZ   splitr   r7   r   rl   r   )ro   r   vrL   rL   rM   r     s   
 
zClientRequest.update_versionc                 C   s~   t  | _| jj}|dusJ || jtj< |sdS t|ttt	fr$|
 }|D ]\}}|tjv r5|| j|< q&| j|| q&dS )zUpdate request headers.N)r   r`   r]   host_port_subcomponentr   HOSTr   dictr   r   r   HOST_ALLadd)ro   r`   r   keyvaluerL   rL   rM   r     s   
zClientRequest.update_headersc                 C   s   |d urt dd t|D | _| j }|| j n| j}| j D ]\}}||vr1|| j|< q$tj	|vr?t
| jtj	< d S d S )Nc                 s   s    | ]}|d fV  qd S rt   rL   )r   hdrrL   rL   rM   	<genexpr>  s    
z4ClientRequest.update_auto_headers.<locals>.<genexpr>)r   sortedr   r`   copyextendDEFAULT_HEADERSr   r   
USER_AGENTr6   )ro   r   used_headersr  valrL   rL   rM   r     s   



z!ClientRequest.update_auto_headersc                 C   s   |sdS t  }tj| jv r|| jtjd | jtj= t|tr'| }n|}|D ]$\}}t|t	rK||j
t	 }||j
|j|j |||< q+|||< q+|jddd | jtj< dS )zUpdate request cookies header.Nr   ;)headersep)r   r   COOKIEr`   loadrk   r   r   r   r   r  setr  coded_valueoutputr   )ro   r   citer_cookiesnamer  mrsl_valrL   rL   rM   r     s    





zClientRequest.update_cookiesc                 C   sb   |sd| _ dS | jtjr| j rtddS | j r/t| j ts#d| _ | j | jtj< d| _dS dS )zSet request content encoding.Nz9compress can not be set if Content-Encoding header is setdeflateT)	r   r`   rk   r   CONTENT_ENCODINGrl   r   rZ   r   )ro   r   rL   rL   rM   r     s   
z%ClientRequest.update_content_encodingc                 C   s   | j tjd }d|v r| jrtddS | jr,tj| j v r$tdd| j tj< dS tj| j vr?tt	| j
| j tj< dS dS )z!Analyze transfer-encoding header.r   r   zDchunked can not be set if "Transfer-Encoding: chunked" header is setz6chunked can not be set if Content-Length header is setN)r`   rk   r   TRANSFER_ENCODINGlowerr   rl   CONTENT_LENGTHrZ   ri   r   )ro   terL   rL   rM   r     s    z&ClientRequest.update_transfer_encodingc                 C   s   |du r| j }|du r2|r2| jjdur2t }tt t|| jj}W d   n1 s-w   Y  |du r8dS t|t	j
sBtd| | jtj< dS )zSet basic auth.Nz%BasicAuth() tuple is required instead)r   r]   r   r1   
contextlibsuppressLookupErrorr0   r   r   r-   r   encoder`   r   AUTHORIZATION)ro   r   r   	netrc_objrL   rL   rM   r   0  s   zClientRequest.update_authc                 C   s   |d u rd S t |tr| }z
tjj|d d}W n tjy'   t| }Y nw || _| jsGtj	| j
vrG|j }d urDt|| j
tj	< nd| _|j
sLJ | j
}| j}|j
 D ]\}}||v sg|d urh||v rhqW|||< qWd S )N)dispositionT)r   r*   r    PAYLOAD_REGISTRYrk   r#  r   r   r   r  r`   sizerZ   r   r   )ro   r   r)  r`   skip_headersr  r  rL   rL   rM   r   @  s,   


z#ClientRequest.update_body_from_dataexpectc                 C   sN   |r	d| j tj< ntj| j v r| j tj  dkrd}|r%| j | _d S d S )Nz100-continueT)r`   r   EXPECTr  r   create_future	_continue)ro   r+  rL   rL   rM   r   _  s   z$ClientRequest.update_expect_continuec                 C   sd   || _ |d u rd | _d | _d S |rt|tjstd|| _|d ur-t|ttfs-t	|}|| _d S )Nz,proxy_auth must be None or BasicAuth() tuple)
r   r   r   r   r   r-   rl   r   r   r   )ro   r   r   r   rL   rL   rM   r   k  s   

zClientRequest.update_proxyconnrI   c              
      sh  | j dur| I dH  | j I dH  |j}|dusJ z.t| jtjr.| j|I dH  nt| jtt	fr;| jf| _| jD ]
}||I dH  q>W n\ t
y} } z'|}|jdup_t|tj }|rlt|jd| j}t||| W Y d}~dS d}~w tjy   |    ty } zt|td|| W Y d}~dS d}~ww | I dH  |  dS )z-Support coroutines that yields bytes objects.NzCan not write request body for z4Failed to send bytes into the underlying connection )r.  drainprotocolr   r   r    Payloadwriter   	bytearrayOSErrorerrnor   TimeoutErrorr#   r]   r4   CancelledErrorclose	Exceptionr"   	write_eofstart_timeout)ro   r   r/  r1  chunkunderlying_excreraised_excexc_is_not_timeoutrL   rL   rM   write_bytes  sR   



	zClientRequest.write_bytesc                    sB  | j tjkr| jj}|d usJ | d| jj }n| jr(|  s(t| j}n| jj	}|j
}|d us5J t|| j| jrFt| j| j | jnd | jrTt| j| j | jnd d}| jra|| j | jd urj|  | j | jv r| jd u s{tj| jvrtj| jvrd| jtj< | j}tj| jvr|jjr|tkrd| jtj< n
|tkrd| jtj< | j  d| d|j  d|j! }|"|| jI d H  | j#s| j$d us|j%r| &||}t'j(d	krt)j*|| jd
d}	n| j+|}	|	, rd }	n|	| _-n
|.  |/  d }	| j0}
|
d usJ |
| j | j1|	| j$| j2| j3| j| j| j4d	| _5| j5S )N:)on_chunk_senton_headers_sentzapplication/octet-streamr9  z
keep-alive z HTTP/r   )r      T)r   eager_start)r   continue100r   r   r   r   r   )6r^   r   METH_CONNECTr]   host_subcomponentr   r   r   rZ   raw_path_qsr1  r:   r   r   	functoolspartial_on_chunk_request_sent_on_headers_request_sentr   enable_compressionr   enable_chunkingPOST_METHODSr   CONTENT_TYPEr`   r   
CONNECTION
_connectorforce_closer9   r8   majorminorwrite_headersr   r.  writing_pausedrA  r   version_infor   Taskcreate_taskdoner   r<  set_eofr   r   r   r   r   response)ro   r/  connect_hostpathr1  r   r   status_linecorotaskr   rL   rL   rM   send  s   

 
zClientRequest.sendc                    sf   | j d ur1z	| j I d H  W d S  tjy0   tjdkr't  }r*| r- Y d S Y d S Y d S w d S N)r      )r   r   r8  r   r[  current_task
cancellingro   re  rL   rL   rM   r9    s   


zClientRequest.closec                 C   s:   | j d ur| j s| j   | j | j d | _ d S d S rt   )r   r   	is_closedcancelr   r   ru   rL   rL   rM   	terminate  s   



zClientRequest.terminater=  c                    &   | j D ]}||||I d H  qd S rt   )r   send_request_chunk_sent)ro   r^   r]   r=  tracerL   rL   rM   rN  %  s   
z$ClientRequest._on_chunk_request_sentzCIMultiDict[str]c                    ro  rt   )r   send_request_headers)ro   r^   r]   r`   rq  rL   rL   rM   rO  )  s   
z&ClientRequest._on_headers_request_sentrt   )r   r   rK   NrK   N)F)r/  rI   rK   rE   )TrW   rX   rY   r   METH_GET	METH_HEADMETH_OPTIONS
METH_TRACEr   
METH_PATCH	METH_POSTMETH_PUTrR  unionMETH_DELETEALL_METHODSACCEPTACCEPT_ENCODINGrN   r  r   r   r[   r   r`  r   r.  r   r   r   r9   rZ   r   rA   r@   r   r?   r-   r7   r   r   r   AbstractEventLoopr   r,   rC   rG   r   rr   objectr   r   r   r   r   setterr   r   r   r   r   r   r   rF   r   r   r   r   r   r   r   r   r   r   r   r   r!   rA  rf  r9  rn  r   rN  rO  rL   rL   rL   rM   rD      s  
 
	



O





1
`
rD   Connection closedc                   @   s  e Zd ZU dZee ed< dZeed< dZ	ee
 ed< dZeed< dZee ed< dZee
 ed< dZed	 ed
< dZeed< dZed ed< dZee ed< dZed ed< dZeej ed< dZed ed< dZdZdZdd Z e!d ege
f ed< dZ"ed ed< de
de#ddded d e$d!e%d"e&d# d$e'j(d%dd&dfd'd(Z)dd)e*d&dfd*d+Z+e,d&ed fd,d-Z-e-j.ded d&dfd.d-Z-e,d&efd/d0Z/e/j.d1ed&dfd2d0Z/e0d&e#fd3d4Z1e0d&e#fd5d6Z2e0d&e#fd7d8Z3e0d&e
fd9d:Z4e0dd<d=Z5e0d&efd>d?Z6e0d&e%fd@dAZ7e0d&ee8 fdBdCZ9e:fdDe;d&dfdEdFZ<d&e
fdGdHZ=e,d&ed fdIdJZ>e0d&ed	 fdKdLZ?e0ddNdOZ@ddQdRZAddSdTZBe,d&eCfdUdVZDddWdXZEd&e;fdYdZZFe,d&eCfd[d\ZGdd]d^ZHdd_d`ZIddadbZJddcddZKddedfZLddgdhZMd&efdidjZNd&e
fdkdlZOddnee
 doe
d&e
fdpdqZPdeQdrdsdnee
 dteRduee
 d&e;fdvdwZSddxdyZTdzeeUeV  d{eeV d|eeW d&dfd}d~ZXdS )rE   Nr   statusreasoncontent_body_headersrL   )rE   ._history_raw_headersrI   _connection_cookieszasyncio.Future[bool]r.  r   rH   r   TFc                  G   s   dS )Nutf-8rL   )r   rL   rL   rM   <lambda>N  s    zClientResponse.<lambda>_resolve_charsetr   _ClientResponse__writerr^   r]   r   zOptional[asyncio.Task[None]]rH  r   r   r   rJ   r   r   rK   c          
      C   s   t |tu sJ || _|| _|jr|d n|| _|d ur || _|d ur'|| _|| _	|d ur0|nt
 | _i | _|| _|| _|	d urH|	| _|	j| _| rWttd| _d S d S )Nr   )rT   r   r^   	_real_urlr   r   _urlr   r.  _request_infor/   r   _cacher   _loopr   r  r   r   r   r   r   r   )
ro   r^   r]   r   rH  r   r   r   r   r   rL   rL   rM   rr   R  s&   zClientResponse.__init__r   c                 C   r   rt   r  r   rL   rL   rM   r   y  r   zClientResponse.__reset_writerc                 C   rs   )zThe writer task for streaming data.

        _writer is only provided for backwards compatibility
        for subclasses that may need to access it.
        r  ru   rL   rL   rM   r   |  s   zClientResponse._writerc                 C   sL   | j dur| j | j || _ |du rdS | rd| _ dS || j dS )z'Set the writer task for streaming data.N)r  r   _ClientResponse__reset_writerr^  r   r   rL   rL   rM   r     s   

c                 C   s   | j d u r	t | _ | j S rt   )r  r   ru   rL   rL   rM   r     s   
zClientResponse.cookiesr   c                 C   s
   || _ d S rt   )r  )ro   r   rL   rL   rM   r     s   
c                 C   rs   rt   )r  ru   rL   rL   rM   r]     rv   zClientResponse.urlc                 C   s   t jdtdd | jS )NzDeprecated, use .url #1654   r   )r   r   r   r  ru   rL   rL   rM   url_obj  s   zClientResponse.url_objc                 C   rs   rt   )r  ru   rL   rL   rM   ra     rv   zClientResponse.real_urlc                 C   s   | j jd usJ | j jS rt   )r  r   ru   rL   rL   rM   r     s   zClientResponse.hostr_   c                 C   rs   rt   )r  ru   rL   rL   rM   r`     rv   zClientResponse.headersc                 C   rs   rt   )r  ru   rL   rL   rM   raw_headers  rv   zClientResponse.raw_headersc                 C   rs   rt   )r  ru   rL   rL   rM   r     rv   zClientResponse.request_infoc                 C   sF   | j tj}|d u rd S t|\}}t|}t|}t|||S rt   )	r  rk   r   CONTENT_DISPOSITIONr   parse_content_dispositionr   content_disposition_filenamerS   )ro   rawdisposition_type
params_dctr   rV   rL   rL   rM   content_disposition  s   
z"ClientResponse.content_disposition	_warningsc                 C   s   | j rd S | jd ur>| j  |   | j r@d| i}|jd| tfi | | dd}| jr6| j|d< | j	| d S d S d S )NsourcezUnclosed response zUnclosed response)client_responsemessagesource_traceback)
_closedr  release_cleanup_writerr  r   r   ResourceWarningr   call_exception_handler)ro   r  kwargscontextrL   rL   rM   __del__  s   




zClientResponse.__del__c                 C   s`   t  }t| j}| jr| jddd}nd}td|| j	||d t| j
|d | S )NasciibackslashreplaceNonez<ClientResponse({}) [{} {}]>)file)ioStringIOrZ   r]   r  r$  decodeprintr   r  r`   getvalue)ro   outascii_encodable_urlascii_encodable_reasonrL   rL   rM   __repr__  s"   
zClientResponse.__repr__c                 C   rs   rt   )r  ru   rL   rL   rM   
connection  rv   zClientResponse.connectionc                 C   rs   )z2A sequence of of responses, if redirects occurred.)r  ru   rL   rL   rM   history  s   zClientResponse.history/MultiDictProxy[MultiDictProxy[Union[str, URL]]]c                 C   s   d | jdg }|stt S t }td|D ][}td|}|d u r'q| \}}|ddd  }t }|D ]}	td|	tj	}|d u rJq;| \}
}}}|
|
| q;|d|}
|
d	| j t| |
t|
t| qt|S )
Nz, linkz	,(?=\s*<)z\s*<(.*)>(.*)r  r   z%^\s*(\S*)\s*=\s*(['\"]?)(.*?)(\2)\s*$relr]   )joinr`   getallr   r   rer   r   groupsMr  rk   r]   r   rZ   )ro   	links_strlinksr  r   r]   
params_strr   r  paramr  r   r  rL   rL   rM   r    s*   
zClientResponse.linksr  c           	         sx  d| _ |j| _|| _| jS 	 z| j}| I dH \}}W n tjy: } zt| j	| j
|j|j|jd|d}~ww |jdk sJ|jdksJ|jdkrKn| jdurYt| jd d| _qW d   n1 sdw   Y  || j |j| _|j| _|j| _|j| _|j| _|| _| jtjd }rt }|D ]!}z|| W q ty } zt d	| W Y d}~qd}~ww || _!| S )
zStart response processing.FTNr  r  r`   d      e   rL   z!Can not load response cookies: %s)"r  r1  	_protocolr  r   readr   HttpProcessingErrorr$   r   r  coder  r`   r.  r5   on_eof_response_eofr   r  r  r  r  r  r  r  r   
SET_COOKIEr   r  r   r;   warningr  )	ro   r  r1  r  r    exccookie_hdrsr   r  rL   rL   rM   start  s^   	
zClientResponse.startc                 C   sD   | j rd S | jo| jj}|d ur|jrd S d| _ |   |   d S NT)r  r  r1  upgradedr  _release_connection)ro   r1  rL   rL   rM   r  J  s   zClientResponse._response_eofc                 C   rs   rt   )r  ru   rL   rL   rM   closedW  rv   zClientResponse.closedc                 C   sV   | j s|   d| _| jd u s| j rd S |   | jd ur)| j  d | _d S d S r  )	_released_notify_contentr  r  rl  r  r  r9  ru   rL   rL   rM   r9  [  s   


zClientResponse.closec                 C   s*   | j s|   d| _|   |   t S r  )r  r  r  r  r  r2   ru   rL   rL   rM   r  h  s   zClientResponse.releasec                 C   s
   d| j kS )zReturns ``True`` if ``status`` is less than ``400``, ``False`` if not.

        This is **not** a check for ``200 OK`` but a check that the response
        status is under 400.
        i  )r  ru   rL   rL   rM   okr  s   
zClientResponse.okc                 C   sB   | j s| jd us
J | js|   t| j| j| j| j| jdd S )Nr  )	r  r  _in_contextr  r$   r   r  r  r`   ru   rL   rL   rM   raise_for_status{  s   zClientResponse.raise_for_statusc                    sD    j d ur  jd u r j   d  _ d S  j fdd d S d S )Nc                    s      S rt   )r  )fru   rL   rM   r    s    z4ClientResponse._release_connection.<locals>.<lambda>)r  r  r  r   ru   rL   ru   rM   r    s   



z"ClientResponse._release_connectionc                    ^   | j d ur)z| j I d H  W n tjy(   tjdkr&t  }r&| r& Y nw |   d S rg  )r  r   r8  r   r[  ri  rj  r  rk  rL   rL   rM   _wait_released     


zClientResponse._wait_releasedc                 C   s   | j d ur
| j   d | _d S rt   )r  rm  r   ru   rL   rL   rM   r    s   


zClientResponse._cleanup_writerc                 C   s*   | j }|r| d u rt|t d| _d S r  )r  	exceptionr4   _CONNECTION_CLOSED_EXCEPTIONr  )ro   r  rL   rL   rM   r    s   

zClientResponse._notify_contentc                    r  rg  )r  r   r8  r   r[  ri  rj  r  rk  rL   rL   rM   wait_for_close  r  zClientResponse.wait_for_closec                    s   | j du r1z| j I dH | _ | jD ]}|| j| j| j I dH  qW n ty0   |    w | j	r8t
d| jo>| jj}|du sF|jsM|  I dH  | j S )zRead response payload.Nr  )r  r  r  r   send_response_chunk_receivedr^   r]   BaseExceptionr9  r  r"   r  r1  r  r  )ro   rq  r1  rL   rL   rM   r    s&   

zClientResponse.readc                 C   s   | j tjd }t|}|jd}|r3t	t
t t|jW  d    S 1 s.w   Y  |jdkrD|jdksB|jdkrDdS | jd u rMtd| | | jS )Nr   charsetapplicationjsonrdapr  z7Cannot compute fallback encoding of a not yet read body)r`   rk   r   rS  r  r   parse_mimetyperU   r!  r"  r#  rl   codecslookupr  rT   subtyper  RuntimeErrorr  )ro   ctypemimetypeencodingrL   rL   rM   get_encoding  s   

 

zClientResponse.get_encodingstrictr  errorsc                    s:   | j du r|  I dH  |du r|  }| j j||dS )z!Read response payload and decode.N)r  )r  r  r  r  )ro   r  r  rL   rL   rM   text  s   
zClientResponse.textr   )r  loadscontent_typer  r  c                   s   | j du r|  I dH  |r-| jtjd }t||s-t| j	| j
| jd| | jd| j  }|s6dS |du r>|  }|||S )zRead and decodes JSON response.Nr   z3Attempt to decode JSON with unexpected mimetype: %sr  )r  r  r`   rk   r   rS  r  r   r%   r   r  r  r   r  r  )ro   r  r  r  r  strippedrL   rL   rM   r    s&   



zClientResponse.jsonc                    s   d| _ | S r  )r  ru   rL   rL   rM   
__aenter__  s   zClientResponse.__aenter__exc_typeexc_valexc_tbc                    s"   d| _ |   |  I d H  d S )NF)r  r  r  )ro   r  r   r  rL   rL   rM   	__aexit__  s   zClientResponse.__aexit__rt   )rK   r_   )rK   r  )r  rI   rK   rE   rs  )Nr  )rK   rE   )YrW   rX   rY   r   r   r7   r[   r  r   r  rZ   r  r<   r  r   r  r   r  r   r  rB   r  r  r   r.  r   r   StackSummaryr   r  r  r  r  r   r  r   r,   rF   r   r   r  rr   r  r  r   r   r  r   r3   r]   r  ra   r   r`   r  r   rS   r  r   r   r  r  r  r  r  r  r  r   r  r9  r  r  r  r  r  r  r  r  r  r  r  r=   r>   r  r  r   r  r	   r  rL   rL   rL   rM   rE   3  s   
 	

'	
#
6









!
rE   )xr   r  r!  rL  r  r  r   r   r   hashlibr   r   r   http.cookiesr   r   r   typesr   r	   typingr
   r   r   r   r   r   r   r   r   r   r   r   attr	multidictr   r   r   r   yarlr   r   r   r   r   r   r    abcr!   client_exceptionsr"   r#   r$   r%   r&   r'   compression_utilsr)   formdatar*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   logr;   streamsr<   typedefsr=   r>   r?   r@   rA   rB   r   rC   ImportErrorr  __all__clientrH   	connectorrI   tracingrJ   compiler   r   rZ   rN   srS   r\   rF   rG   r   rT   r   r   r   	frozensetr   r   r   rD   r  rE   rL   rL   rL   rM   <module>   s    8 4 	


 
7
    9