o
    h                  	   @   sr  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
 d dlmZmZ d dlmZm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mZ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)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ej0rddl1m2Z2 ddl3m4Z4 ej5ej6e7e8e9e:f  Z;ej6de7f Z<ej6dej=e7e;f ej>ej?e7e;f  e7f Z@ej6dejAejBejBf ej>ej?ejBejBf  f ZCej6deejAe7e7f f ZDej6ej?ej6e7eEf ej6e7eEf f ejFdgdf df ZGej6e<dejAe<ej6e<df f f ZHej6eIe7eEejJeE f ZKej6eIe7eEejLeE f ZMejAe7ej6ejNejB ej?e7ejNejB f ej?e7ejNejB e7f f f ZOej6eEejJeE f ZPej6eEejLeE f ZQG dd dZRG dd dZSG dd dej=e7e7f ZTG dd dej
e7e7f ZUG dd dZVG dd deVZWG dd deVZXG dd  d ZYG d!d" d"eYZZG d#d$ d$eYZ[G d%d de
Z\dS )&    N)MutableMapping)Cookie	CookieJar)	parse_qsl	urlencode   )
USER_AGENT)ACCEPT_ENCODINGSUPPORTED_DECODERSDecoderIdentityDecoderMultiDecoderTextDecoder)CookieConflict	HTTPError
InvalidURLNotRedirectResponseResponseClosedResponseNotReadStreamConsumed)multipart_encode)
StatusCode)guess_json_utfis_known_encodingnormalize_header_keynormalize_header_valueobfuscate_sensitive_headersparse_header_linksstr_query_param)BaseMiddleware)AsyncDispatcherURLQueryParamsHeadersCookiesAsyncRequestr   r    c                	   @   s  e Zd Z		d7dedededdfddZedefd	d
Z	edefddZ
edefddZedefddZedefddZedefddZedefddZedefddZedefddZejdeje ddfddZedefddZedefdd Zedefd!d"Zedefd#d$Zed8d&d'Zd(ejdd fd)d*Zd+edd fd,d-Zdefd.d/Zd0ejdefd1d2Zdefd3d4Z defd5d6Z!dS )9r!   FNurlallow_relativeparamsreturnc                 C   s   t |trtj| | _n|j| _| jr| j | _|r,tt	|}| jj
|d| _|s<| js5td| js<tdd | _d S )N)queryzNo scheme included in URL.zNo host included in URL.)
isinstancestrrfc3986apiZiri_referenceencode_uri_referenceis_absolute_url	normalizer"   	copy_withschemer   host
_full_path)selfr&   r'   r(   query_string r9   T/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/httpx/models.py__init__d   s   

zURL.__init__c                 C      | j jpdS N )r0   r4   r7   r9   r9   r:   r4         z
URL.schemec                 C   r<   r=   )r0   	authorityr?   r9   r9   r:   rA      r@   zURL.authorityc                 C      | j jpd}|dd S )Nr>   :r   r0   userinfo	partitionr7   rE   r9   r9   r:   username      zURL.usernamec                 C   rB   )Nr>   rC      rD   rG   r9   r9   r:   password   rI   zURL.passwordc                 C   r<   r=   )r0   r5   r?   r9   r9   r:   r5      r@   zURL.hostc                 C   s(   | j j}|d u rddd| j S t|S )Ni  P   )httpshttp)r0   portr4   int)r7   rO   r9   r9   r:   rO      s   zURL.portc                 C   r<   )N/)r0   pathr?   r9   r9   r:   rR      r@   zURL.pathc                 C   r<   r=   )r0   r*   r?   r9   r9   r:   r*      r@   z	URL.queryc                 C   s.   | j d ur| j S | j}| jr|d| j 7 }|S )N?)r6   rR   r*   )r7   rR   r9   r9   r:   	full_path   s   
zURL.full_pathvaluec                 C   
   || _ d S N)r6   r7   rU   r9   r9   r:   rT         
c                 C   r<   r=   )r0   fragmentr?   r9   r9   r:   rZ      r@   zURL.fragmentc                 C   s
   | j dkS )NrM   )r4   r?   r9   r9   r:   is_ssl   rY   z
URL.is_sslc                 C   s   t | jo| jS )z
        Return `True` for absolute URLs such as 'http://example.com/path',
        and `False` for relative URLs such as '/path'.
        )boolr4   r5   r?   r9   r9   r:   r1      s   
zURL.is_absolute_urlc                 C   s   | j  S rW   )r1   r?   r9   r9   r:   is_relative_url      zURL.is_relative_urlOriginc                 C   s   t | S rW   )r_   r?   r9   r9   r:   origin   r^   z
URL.originkwargsc                 K   s   t | jjdi | S )Nr9   )r!   r0   r3   unsplit)r7   ra   r9   r9   r:   r3      s   zURL.copy_withrelative_urlc                 C   s<   | j rt|S | jjdd}t|dd}t|j| S )zK
        Return an absolute URL, using given this URL as the base.
        N)rZ   T)r'   )r]   r!   r0   r3   Zresolve_withrb   )r7   rc   Zbase_urir9   r9   r:   join   s
   zURL.joinc                 C   s   t t| S rW   )hashr,   r?   r9   r9   r:   __hash__      zURL.__hash__otherc                 C   s   t |ttfot| t|kS rW   )r+   r!   r,   r7   rh   r9   r9   r:   __eq__   s   z
URL.__eq__c                 C   
   | j  S rW   )r0   rb   r?   r9   r9   r:   __str__      
zURL.__str__c                 C   sF   | j j}t| }| jjrt|j| j dd	 }| d|dS )Nz	:[secure])rE   ())
	__class____name__r,   r0   rE   r-   urlparser3   rH   rb   )r7   
class_nameZurl_strr9   r9   r:   __repr__   s   zURL.__repr__)FN)r)   r_   )"rq   
__module____qualname__URLTypesr\   QueryParamTypesr;   propertyr,   r4   rA   rH   rK   r5   rP   rO   rR   r*   rT   settertypingOptionalrZ   r[   r1   r]   r`   Anyr3   rd   rf   rj   rl   rt   r9   r9   r9   r:   r!   c   s`    
c                   @   sR   e Zd ZdZdeddfddZdejdefdd	Z	de
fd
dZdefddZdS )r_   zU
    The URL scheme and authority information, as a comparable, hashable object.
    r&   r)   Nc                 C   s6   t |ts	t|}|j| _|j| _|j| _|j| _d S rW   )r+   r!   r4   r[   r5   rO   )r7   r&   r9   r9   r:   r;      s   
zOrigin.__init__rh   c                 C   s0   t || jo| j|jko| j|jko| j|jkS rW   )r+   rp   r4   r5   rO   ri   r9   r9   r:   rj     s   


zOrigin.__eq__c                 C   s   t | j| j| jfS rW   )re   r4   r5   rO   r?   r9   r9   r:   rf        zOrigin.__hash__c                 C   s*   | j j}| d| jd| jd| j dS )Nz(scheme=z host=z port=ro   )rp   rq   r4   r5   rO   )r7   rs   r9   r9   r:   rt     s    zOrigin.__repr__)rq   ru   rv   __doc__rw   r;   r{   r}   r\   rj   rP   rf   r,   rt   r9   r9   r9   r:   r_      s    r_   c                   @   sT  e Zd ZdZdedejddfddZdejdeje	 fd	d
Z
dejfddZdejfddZdejfddZdejeje	e	f  fddZd+dejdejdejfddZd+deddfddZdejde	fddZde	de	ddfddZdejdefddZdejej fd d!Zdefd"d#Zd$ejdefd%d&Zde	fd'd(Zde	fd)d*ZdS ),r"   z0
    URL query parameters, as a multi-dict.
    argsra   r)   Nc                 O   s   t |dk s
J d|r|rJ d|r|d n|}t|tr$t|}nt|tr.| }nt|tr6|}n| }dd |D | _dd |D | _	d S )	NrJ   zToo many arguments.z'Cannot mix named and unnamed arguments.r   c                 S   s    g | ]\}}t |t|fqS r9   r,   r   .0kvr9   r9   r:   
<listcomp>)  s     z(QueryParams.__init__.<locals>.<listcomp>c                 S   s   i | ]\}}t |t|qS r9   r   r   r9   r9   r:   
<dictcomp>*  s    z(QueryParams.__init__.<locals>.<dictcomp>)
lenr+   r,   r   r"   multi_itemslistitems_list_dict)r7   r   ra   rU   r   r9   r9   r:   r;     s   




zQueryParams.__init__keyc                    s    fdd| j D S )Nc                    s   g | ]
\}}| kr|qS r9   r9   r   item_keyZ
item_valuer   r9   r:   r   -      z'QueryParams.getlist.<locals>.<listcomp>r   r7   r   r9   r   r:   getlist,  r~   zQueryParams.getlistc                 C   rk   rW   )r   keysr?   r9   r9   r:   r   /  rm   zQueryParams.keysc                 C   rk   rW   )r   valuesr?   r9   r9   r:   r   2  rm   zQueryParams.valuesc                 C   rk   rW   )r   r   r?   r9   r9   r:   r   5  rm   zQueryParams.itemsc                 C   
   t | jS rW   )r   r   r?   r9   r9   r:   r   8  rm   zQueryParams.multi_itemsdefaultc                 C   s   || j v r
| j | S |S rW   r   r7   r   r   r9   r9   r:   get;  s   

zQueryParams.getr(   c                 C   s*   |sd S t |}|D ]}|| | |< q
d S rW   )r"   )r7   r(   paramr9   r9   r:   update@  s   zQueryParams.updatec                 C   s
   | j | S rW   r   r   r9   r9   r:   __getitem__H  rm   zQueryParams.__getitem__rU   c                 C   s   || j |< g }t| jD ]\}\}}||kr|| qt|dd  D ]}| j|= q$|r:|d }||f| j|< d S | j||f d S )Nr   r   )r   	enumerater   appendreversed)r7   r   rU   found_indexesidxr   _r9   r9   r:   __setitem__K  s   


zQueryParams.__setitem__c                 C   s
   || j v S rW   r   r   r9   r9   r:   __contains__\  rm   zQueryParams.__contains__c                 C      t |  S rW   iterr   r?   r9   r9   r:   __iter___  rg   zQueryParams.__iter__c                 C   r   rW   )r   r   r?   r9   r9   r:   __len__b  rm   zQueryParams.__len__rh   c                 C   s$   t || jsdS t| jt|jkS NF)r+   rp   sortedr   ri   r9   r9   r:   rj   e  s   zQueryParams.__eq__c                 C   r   rW   )r   r   r?   r9   r9   r:   rl   j  rm   zQueryParams.__str__c                 C   s    | j j}t| }| d|dS )Nrn   ro   )rp   rq   r,   )r7   rs   r8   r9   r9   r:   rt   m  s   zQueryParams.__repr__rW   ) rq   ru   rv   r   rx   r{   r}   r;   Listr,   r   KeysViewr   
ValuesViewr   	ItemsViewr   Tupler   r   r   r   r   r\   r   Iteratorr   rP   r   rj   rl   rt   r9   r9   r9   r:   r"     s$    c                   @   s  e Zd ZdZd1dededdfddZedefdd	Zej	d
eddfdd	Zede
je
jeef  fddZde
je fddZde
je fddZde
je
jeef  fddZd2dede
jde
jfddZd3dedede
je fddZd2deddfddZd4ddZdedefd d!Zded
eddfd"d#Zdeddfd$d%Zde
jdefd&d'Zde
je
j fd(d)Zdefd*d+Zd,e
jdefd-d.Z defd/d0Z!dS )5r#   z9
    HTTP headers, as a case-insensitive multi-dict.
    Nheadersencodingr)   c                    sj   |d u rg | _ n(t|trt|j| _ nt|tr& fdd| D | _ n
 fdd|D | _  | _d S )Nc                    $   g | ]\}}t | t| fqS r9   r   r   r   r   r9   r:   r   ~      z$Headers.__init__.<locals>.<listcomp>c                    r   r9   r   r   r   r9   r:   r     r   )r   r+   r#   r   rawdictr   	_encoding)r7   r   r   r9   r   r:   r;   x  s   





zHeaders.__init__c              
   C   sj   | j du r2dD ]'}| jD ]\}}z|| || W q ty&   Y  nw || _  | j S qd| _ | j S )zn
        Header encoding is mandated as ascii, but we allow fallbacks to utf-8
        or iso-8859-1.
        N)asciiutf-8
iso-8859-1)r   r   decodeUnicodeDecodeError)r7   r   r   rU   r9   r9   r:   r     s   

	zHeaders.encodingrU   c                 C   rV   rW   r   rX   r9   r9   r:   r     rY   c                 C   s   | j S )zi
        Returns a list of the raw header items, as byte pairs.
        May be mutated in-place.
        r   r?   r9   r9   r:   r     s   zHeaders.rawc                        fdd j D S )Nc                    s   g | ]
\}}|  jqS r9   r   r   r   r   rU   r?   r9   r:   r     r   z Headers.keys.<locals>.<listcomp>r   r?   r9   r?   r:   r     r~   zHeaders.keysc                    r   )Nc                    s   g | ]
\}}|  jqS r9   r   r   r?   r9   r:   r     r   z"Headers.values.<locals>.<listcomp>r   r?   r9   r?   r:   r     r~   zHeaders.valuesc                    r   )Nc                    s(   g | ]\}}|  j|  jfqS r9   r   r   r?   r9   r:   r     s    z!Headers.items.<locals>.<listcomp>r   r?   r9   r?   r:   r     s   
zHeaders.itemsr   r   c                 C   s"   z| | W S  t y   | Y S w rW   )KeyErrorr   r9   r9   r:   r     s
   
zHeaders.getFsplit_commasc                    sZ   |  j  fddjD }|s|S g }|D ]}|dd |dD  q|S )z0
        Return multiple header values.
        c                    s$   g | ]\}}| kr| jqS r9   r   r   get_header_keyr7   r9   r:   r     s
    
z#Headers.getlist.<locals>.<listcomp>c                 S   s   g | ]}|  qS r9   )strip)r   itemr9   r9   r:   r     s    ,)lowerr/   r   r   extendsplit)r7   r   r   r   Zsplit_valuesrU   r9   r   r:   r     s   zHeaders.getlistc                 C   s"   t |}|D ]}|| | |< qd S rW   )r#   )r7   r   headerr9   r9   r:   r     s   zHeaders.updatec                 C   s   t |  | jdS )Nr   )r#   r   r   r?   r9   r9   r:   copy  s   zHeaders.copyc                 C   sT   |  | j}g }| jD ]\}}||kr||| j q|r&d|S t|)z
        Return a single header value.

        If there are multiple headers with the same key, then we concatenate
        them with commas. See: https://tools.ietf.org/html/rfc7230#section-3.2.2
        , )r   r/   r   r   r   r   rd   r   )r7   r   Znormalized_keyr   
header_keyheader_valuer9   r9   r:   r     s   
zHeaders.__getitem__c           	      C   s   |  | j}|| j}g }t| jD ]\}\}}||kr$|| qt|dd D ]}| j|= q-|rC|d }||f| j|< dS | j||f dS )zs
        Set the header `key` to `value`, removing any duplicate entries.
        Retains insertion order.
        r   Nr   )r   r/   r   r   r   r   r   )	r7   r   rU   Zset_key	set_valuer   r   r   r   r9   r9   r:   r     s   

zHeaders.__setitem__c                 C   sd   |  | j}g }t| jD ]\}\}}||kr|| q|s%t|t|D ]}| j|= q)dS )z*
        Remove the header `key`.
        N)r   r/   r   r   r   r   r   r   )r7   r   Zdel_keyZpop_indexesr   r   r   r9   r9   r:   __delitem__  s   

zHeaders.__delitem__c                 C   s2   |  | j}| jD ]\}}||kr dS qdS NTF)r   r/   r   r   )r7   r   r   r   r   r9   r9   r:   r     s   zHeaders.__contains__c                 C   r   rW   r   r?   r9   r9   r:   r     rg   zHeaders.__iter__c                 C   r   rW   )r   r   r?   r9   r9   r:   r     rm   zHeaders.__len__rh   c                 C   s"   t |tsdS t| jt|jkS r   )r+   r#   r   r   ri   r9   r9   r:   rj   "  s   
zHeaders.__eq__c                 C   sv   | j j}d}| jdkrd| j}tt|  }t|}t|t|k}|r1| d|| dS | d|| dS )Nr>   r   z, encoding=rn   ro   )rp   rq   r   r   r   r   r   r   )r7   rs   Zencoding_strZas_listas_dictZno_duplicate_keysr9   r9   r:   rt   '  s   
zHeaders.__repr__NNrW   )F)r)   r#   )"rq   ru   rv   r   HeaderTypesr,   r;   ry   r   rz   r{   r   r   bytesr   r   r   r   r}   r   r\   r   r   r   r   r   r   r   r   r   rP   r   rj   rt   r9   r9   r9   r:   r#   s  s0     
c                   @   s   e Zd Zdddddedejeef dedede	f
dd	Z
	dd
ededejdejeef fddZdddZedddZdefddZdS )BaseRequestN)r(   r   cookiesmethodr&   r(   r   r   c                C   sD   |  | _t||d| _t|| _|r t|| _| j|  d S d S )N)r(   )	upperr   r!   r&   r#   r   r$   _cookiesset_cookie_header)r7   r   r&   r(   r   r   r9   r9   r:   r;   8  s   
	

zBaseRequest.__init__datafilesjsonr)   c                 C   s|   |d urt |d}d}||fS |d ur#t|pi |\}}||fS |d ur6t|ddd}d}||fS d}d}||fS )Nr   zapplication/jsonT)doseqz!application/x-www-form-urlencoded    r>   )jsonlibdumpsr/   r   r   )r7   r   r   r   contentcontent_typer9   r9   r:   encode_dataH  s   	zBaseRequest.encode_datac                 C   s   t | dd }t | dd}g }d| jv }d| jv }d| jv }d| jv p&d| jv }d	| jv }d
| jv }	|s?|d| jjdf |sK|dtdf |sR|d |sm|r\|d n|rmtt| }
|d|
f |sx|dt	 f |	s|d t
|D ]
}| jjd| qd S )Nr   is_streamingFr5   z
user-agentacceptzcontent-lengthztransfer-encodingzaccept-encoding
connections   hostr   s
   user-agent)s   accepts   */*)s   transfer-encodings   chunkeds   content-lengths   accept-encoding)s
   connections
   keep-aliver   )getattrr   r   r&   rA   r/   r   r,   r   r	   r   r   insert)r7   r   r   Zauto_headersZhas_hostZhas_user_agentZ
has_acceptZhas_content_lengthZhas_accept_encodingZhas_connectioncontent_lengthr   r9   r9   r:   prepareX  s:   






zBaseRequest.preparer$   c                 C   s   t | ds	t | _| jS Nr   )hasattrr$   r   r?   r9   r9   r:   r   {  s   
zBaseRequest.cookiesc                 C   s,   | j j}t| j}d| d| jd|dS )N<rn   r   z)>)rp   rq   r,   r&   r   )r7   rs   r&   r9   r9   r:   rt     s   
zBaseRequest.__repr__NNNr)   Nr)   r$   )rq   ru   rv   r,   r{   Unionr!   rx   r   CookieTypesr;   r   RequestFilesr}   r   r   r   r   ry   r   rt   r9   r9   r9   r:   r   7  s:    


#r   c                       |   e Zd Zddddddddedejeef dedede	de
d	ed
ejf fddZdefddZdeje fddZ  ZS )r%   Nr(   r   r   r   r   r   r   r&   r(   r   r   r   r   r   c                      t  j|||||d |d u st|tr+| |||\}	}
d| _|	| _|
r*|
| jd< n't|tt	frEt|tr<|
dn|}d| _|| _nt|dsLJ d| _|| _|   d S )Nr   r&   r(   r   r   FContent-Typer   	__aiter__T)superr;   r+   r   r   r   r   r   r,   r   r/   r   content_aiterr   r7   r   r&   r(   r   r   r   r   r   r   r   rp   r9   r:   r;     s$   

zAsyncRequest.__init__r)   c                    2   t | dsddd |  2 I dH | _| jS )7
        Read and return the response content.
        r   r   c                       g | z3 d H W }|q6 S rW   r9   r   partr9   r9   r:   r         z%AsyncRequest.read.<locals>.<listcomp>Nr   rd   streamr   r?   r9   r9   r:   read     
 zAsyncRequest.readc                 C  s>   | j r| j2 z	3 d H W }|V  q6 d S | jr| jV  d S d S rW   )r   r  r   r7   r  r9   r9   r:   r    s   zAsyncRequest.stream)rq   ru   rv   r,   r{   r   r!   rx   r   r   AsyncRequestDatar   r}   r;   r   r  AsyncIteratorr  __classcell__r9   r9   r  r:   r%     s4    	
 c                       r   )RequestNr   r   r&   r(   r   r   r   r   r   c                   r   )Nr   Fr  r   r   T)r  r;   r+   r   r   r   r   r   r,   r   r/   r   content_iterr   r  r  r9   r:   r;     s$   

zRequest.__init__r)   c                 C   *   t | dsddd |  D | _| jS )Nr   r   c                 S      g | ]}|qS r9   r9   r
  r9   r9   r:   r         z Request.read.<locals>.<listcomp>r  r?   r9   r9   r:   r    s   
zRequest.readc                 c   s4    | j r| jD ]}|V  qd S | jr| jV  d S d S rW   )r   r  r   r  r9   r9   r:   r    s   
zRequest.stream)rq   ru   rv   r,   r{   r   r!   rx   r   r   RequestDatar   r}   r;   r   r  r   r  r  r9   r9   r  r:   r    s4    	
!r  c                   @   s|  e Zd Zdddddddededededejde	j
fd	d
ZedefddZedeje fddZedefddZedefddZedefddZejdeddfddZedeje fddZedeje fddZedefddZedefddZd,d d!Zd"ejdejee f fd#d$Z!ed-d&d'Z"edej#eje ej#eef f fd(d)Z$defd*d+Z%dS ).BaseResponseN)http_versionr   requeston_closeelapsedstatus_coder  r   r  r  r  c                C   sD   || _ || _t|| _|| _|| _|d u rtdn|| _d | _	d S )Nr   )
r   r  r#   r   r  r  datetime	timedeltar  	call_next)r7   r   r  r   r  r  r  r9   r9   r:   r;     s   


zBaseResponse.__init__r)   c                 C   s   t | jS rW   )r   Zget_reason_phraser   r?   r9   r9   r:   reason_phrase  r@   zBaseResponse.reason_phrasec                 C   s   | j du rdS | j jS )z
        Returns the URL for which the request was made.

        Requires that `request` was provided when instantiating the response.
        N)r  r&   r?   r9   r9   r:   r&     s   zBaseResponse.urlc                 C   sL   t | ds#t | dr | j}| j|}|| j 7 }|| _| jS t | jS )N_content_raw_content)r   r&  decoderr   flushr%  r   )r7   raw_contentr   r9   r9   r:   r     s   

zBaseResponse.contentc                 C   s<   t | ds| j}|sd| _| jS | j}|j|dd| _| jS )N_textr>   replace)errors)r   r   r*  r   r   )r7   r   r   r9   r9   r:   text  s   
zBaseResponse.textc                 C   sF   t | ds | j}|d u st|s| j}|d u st|sd}|| _| jS )Nr   r   )r   charset_encodingr   apparent_encodingr   )r7   r   r9   r9   r:   r     s   
zBaseResponse.encodingrU   c                 C   rV   rW   r   rX   r9   r9   r:   r   *  rY   c                 C   s\   | j d}|du rdS t|}|d |d }}d|v r%|d dS |dr,dS dS )	zO
        Return the encoding, as specified by the Content-Type header.
        r  Nr   charsetz'"ztext/r   )r   r   cgiZparse_headerr   
startswith)r7   r   parsed
media_typer(   r9   r9   r:   r.  .  s   

zBaseResponse.charset_encodingc                 C   s   t | jd S )zF
        Return the encoding, as it appears to autodetection.
        r   )chardetdetectr   r?   r9   r9   r:   r/  D  s   zBaseResponse.apparent_encodingc              	   C   s   t | dsOg }| jjddd}|D ]}|  }zt| }||  W q ty.   Y qw t|dkr=|d | _	| j	S t|dkrKt
|| _	| j	S t | _	| j	S )z
        Returns a decoder instance which can be used to decode the raw byte
        content, depending on the Content-Encoding used in the response.
        _decoderzcontent-encodingT)r   r   r   )r   r   r   r   r   r
   r   r   r   r8  r   r   )r7   decodersr   rU   Zdecoder_clsr9   r9   r:   r'  K  s&   


zBaseResponse.decoderc                 C   s   t | jo
d| jv S )Nlocation)r   is_redirectr   r   r?   r9   r9   r:   r;  e  s   zBaseResponse.is_redirectc                 C   sT   d}t | jr|j| dd}nt | jr|j| dd}nd}|r(t|| ddS )z8
        Raise the `HttpError` if one occurred.
        z{0.status_code} {error_type}: {0.reason_phrase} for url: {0.url}
For more information check: https://httpstatuses.com/{0.status_code}zClient Error)Z
error_typezServer Errorr>   responseN)r   Zis_client_errorr   formatZis_server_errorr   )r7   messager9   r9   r:   raise_for_statusi  s   zBaseResponse.raise_for_statusra   c                 K   st   | j d u r0| jr0t| jdkr0t| j}|d ur0ztj| j|fi |W S  ty/   Y nw tj| jfi |S )N   )	r.  r   r   r   r   loadsr   r   r-  )r7   ra   r   r9   r9   r:   r   {  s   
zBaseResponse.jsonr$   c                 C   s2   t | ds| jd usJ t | _| j|  | jS r   )r   r  r$   r   extract_cookiesr?   r9   r9   r:   r     s
   
zBaseResponse.cookiesc                 C   sF   | j d}i }|r!t|}|D ]}|dp|d}|||< q|S )zI
        Returns the parsed header links of the response, if any
        linkrelr&   )r   r   r   )r7   r   ZldictlinksrD  r   r9   r9   r:   rF    s   
zBaseResponse.linksc                 C   s   d| j  d| j dS )Nz<Response [ z]>)r   r$  r?   r9   r9   r:   rt     s   zBaseResponse.__repr__r   r   )&rq   ru   rv   rP   r,   r   r   r{   Callabler!  r"  r;   ry   r$  r|   r!   r&   r   r   r-  r   rz   r.  r/  r   r'  r\   r;  r@  r}   r   r   r   r   r   DictrF  rt   r9   r9   r9   r:   r    s\    




*r  c                       s   e Zd Zdddddddddededededejde	d	ej
d
 dejf fddZdefddZdeje fddZdeje fddZdeje fddZdddZdddZ  ZS )AsyncResponseNr  r   r   r  r  historyr  r   r  r   r   r  r  rL  r  r  c          	         p   t  j||||||d |d u rg nt|| _|d u s t|tr-d| _d| _|p)d| _d S d| _d| _|| _	d S N)r   r  r   r  r  r  Tr   F
r  r;   r   rL  r+   r   	is_closedis_stream_consumedr&  _raw_stream	r7   r   r  r   r   r  r  rL  r  r  r9   r:   r;         	
zAsyncResponse.__init__r)   c                    r  )r  r%  r   c                    r	  rW   r9   r
  r9   r9   r:   r     r  z&AsyncResponse.read.<locals>.<listcomp>Nr   rd   r  r%  r?   r9   r9   r:   r    r  zAsyncResponse.readc                 C  sN   t | dr| jV  dS |  2 z3 dH W }| j|V  q6 | j V  dS z
        A byte-iterator over the decoded response content.
        This allows us to handle gzip, deflate, and brotli encoded responses.
        r%  Nr   r%  r   r'  r   r(  r7   chunkr9   r9   r:   r    s   
zAsyncResponse.streamc                 C  s@   t | jd}|  2 z3 dH W }||V  q6 | V  dS z
        A str-iterator over the decoded response content
        that handles both gzip, deflate, etc but also detects the content's
        string encoding.
        r   Nr   r.  r  r   r(  r7   r'  rY  r9   r9   r:   stream_text  s   zAsyncResponse.stream_textc                 C  sd   t | dr| jV  dS | jrt | jrt d| _| j2 z	3 dH W }|V  q6 |  I dH  dS z@
        A byte-iterator over the raw response content.
        r&  TNr   r&  rQ  r   rP  r   rR  closer  r9   r9   r:   r     s   
zAsyncResponse.rawc                    s*   | j st | jdusJ |  I dH S )zA
        Get the next response from a redirect response.
        N)r;  r   r#  r?   r9   r9   r:   next  s
   zAsyncResponse.nextc                    s2   | j sd| _ | jdur|  I dH  dS dS dS z
        Close the response and release the connection.
        Automatically called if the response body is read to completion.
        TNrP  r  r?   r9   r9   r:   r`    s   
zAsyncResponse.close)r)   rJ  r   )rq   ru   rv   rP   r,   r   AsyncResponseContentr{   rH  r%   r   r!  r"  r;   r   r  r  r  r]  r   ra  r`  r  r9   r9   r  r:   rJ    s>    	
 
	rJ  c                       s   e Zd Zdddddddddededededejde	d	ej
d
 dejf fddZdefddZdeje fddZdeje fddZdeje fddZdddZ  ZS )ResponseNrK  r   r  r   r   r  r  rL  r  r  c          	         rM  rN  rO  rS  r  r9   r:   r;     rT  zResponse.__init__r)   c                 C   r  )r  r%  r   c                 S   r  r9   r9   r
  r9   r9   r:   r   *  r  z!Response.read.<locals>.<listcomp>rU  r?   r9   r9   r:   r  %  s   
zResponse.readc                 c   sD    t | dr| jV  dS |  D ]	}| j|V  q| j V  dS rV  rW  rX  r9   r9   r:   r  -  s   
zResponse.streamc                 c   s6    t | jd}|  D ]}||V  q| V  dS rZ  r[  r\  r9   r9   r:   r]  9  s
   zResponse.stream_textc                 c   sT    t | dr| jV  dS | jrt | jrt d| _| jD ]}|V  q|   dS r^  r_  r  r9   r9   r:   r   D  s   

zResponse.rawc                 C   s*   | j sd| _ | jdur|   dS dS dS rb  rc  r?   r9   r9   r:   r`  U  s   
zResponse.closer   )rq   ru   rv   rP   r,   r   ResponseContentr{   rH  r  r   r!  r"  r;   r   r  r   r  r]  r   r`  r  r9   r9   r  r:   re    s<    	
 re  c                   @   sd  e Zd ZdZd.deddfddZdeddfdd	Zd
eddfddZ	d/de
de
de
de
ddf
ddZ	d0de
de
de
de
deje
 f
ddZd1de
de
de
ddfddZd1de
de
ddfddZd.deddfddZde
de
ddfddZde
de
fd d!Zde
ddfd"d#Zdefd$d%Zdeje
 fd&d'Zdefd(d)ZG d*d+ d+ejjZG d,d- d-ZdS )2r$   z-
    HTTP Cookies, as a mutable mapping.
    Nr   r)   c                 C   s   |d u s	t |tr%t | _t |tr!| D ]\}}| || qd S d S t |tr<t | _|jD ]}| j| q1d S || _d S rW   )r+   r   r   jarr   setr$   
set_cookie)r7   r   r   rU   cookier9   r9   r:   r;   e  s   



zCookies.__init__r=  c                 C   s6   |j dusJ | |}| |j }| j|| dS )zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)r  _CookieCompatResponse_CookieCompatRequestrg  rC  )r7   r=  Zurlib_responseurllib_requestr9   r9   r:   rC  r  s   
zCookies.extract_cookiesr  c                 C   s   |  |}| j| dS )zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)rl  rg  add_cookie_header)r7   r  rm  r9   r9   r:   r   |  s   
zCookies.set_cookie_headerr>   rQ   namerU   domainrR   c                 C   s   i ddd|d|ddddd	|d
t |d|dd|dt |dddddddddddddidd}tdi |}| j| dS )zU
        Set a cookie value by name. May optionally include domain and path.
        versionr   ro  rU   rO   Nport_specifiedFrp  domain_specifieddomain_initial_dot.rR   path_specifiedsecureexpiresdiscardTcommentcomment_urlrestHttpOnlyrfc2109r9   )r\   r3  r   rg  ri  )r7   ro  rU   rp  rR   ra   rj  r9   r9   r:   rh    sJ   
	
zCookies.setr   c                 C   sn   d}| j D ])}|j|kr.|du s|j|kr.|du s|j|kr.|dur+d| }t||j}q|du r5|S |S )z
        Get a cookie by name. May optionally include domain and path
        in order to specify exactly which cookie to retrieve.
        Nz!Multiple cookies exist with name=)rg  ro  rp  rR   r   rU   )r7   ro  r   rp  rR   rU   rj  r?  r9   r9   r:   r     s   


zCookies.getc                 C   s   |dur|dur| j |||S g }| j D ]}|j|kr3|du s%|j|kr3|du s.|j|kr3|| q|D ]}| j |j|j|j q6dS )z
        Delete a cookie by name. May optionally include domain and path
        in order to specify exactly which cookie to delete.
        N)rg  clearro  rp  rR   r   )r7   ro  rp  rR   removerj  r9   r9   r:   delete  s   


zCookies.deletec                 C   sD   g }|dur| | |dur|dusJ | | | jj|  dS )z
        Delete all cookies. Optionally include a domain and path in
        order to only delete a subset of all the cookies.
        N)r   rg  r  )r7   rp  rR   r   r9   r9   r:   r    s   

zCookies.clearc                 C   s$   t |}|jD ]}| j| qd S rW   )r$   rg  ri  )r7   r   rj  r9   r9   r:   r     s   
zCookies.updatec                 C   s   |  ||S rW   )rh  r7   ro  rU   r9   r9   r:   r     rg   zCookies.__setitem__c                 C   s   |  |}|d u rt||S rW   )r   r   r  r9   r9   r:   r     s   
zCookies.__getitem__c                 C   s
   |  |S rW   )r  )r7   ro  r9   r9   r:   r     rm   zCookies.__delitem__c                 C   r   rW   )r   rg  r?   r9   r9   r:   r     rm   zCookies.__len__c                 C   s   dd | j D S )Nc                 s   s    | ]}|j V  qd S rW   )ro  )r   rj  r9   r9   r:   	<genexpr>  s    z#Cookies.__iter__.<locals>.<genexpr>rg  r?   r9   r9   r:   r     s   zCookies.__iter__c                 C   s   | j D ]} dS dS r   r  )r7   r   r9   r9   r:   __bool__  s   
zCookies.__bool__c                       sD   e Zd ZdZdeddf fddZdededdf fd	d
Z  ZS )zCookies._CookieCompatRequest
        Wraps a `Request` instance up in a compatibility interface suitable
        for use with `CookieJar` operations.
        r  r)   Nc                    s*   t  jt|jt|j|jd || _d S )N)r&   r   r   )r  r;   r,   r&   r   r   r   r  )r7   r  r  r9   r:   r;     s   
z%Cookies._CookieCompatRequest.__init__r   rU   c                    s   t  || || jj|< d S rW   )r  add_unredirected_headerr  r   )r7   r   rU   r  r9   r:   r    s   z4Cookies._CookieCompatRequest.add_unredirected_header)	rq   ru   rv   r   r   r;   r,   r  r  r9   r9   r  r:   rl    s    "rl  c                   @   s0   e Zd ZdZdefddZdejjfddZ	dS )	zCookies._CookieCompatResponser  r=  c                 C   rV   rW   r<  )r7   r=  r9   r9   r:   r;     rm   z&Cookies._CookieCompatResponse.__init__r)   c                 C   s,   t j }| jj D ]\}}|||< q|S rW   )emailr?  Messager=  r   r   )r7   infor   rU   r9   r9   r:   r    s   

z"Cookies._CookieCompatResponse.infoN)
rq   ru   rv   r   r  r;   r  r?  r  r  r9   r9   r9   r:   rk    s    rk  rW   )r>   rQ   r   r   ) rq   ru   rv   r   r   r;   r  rC  r   r   r,   rh  r{   r|   r   r  r  r   r   r   r   rP   r   r   r   r\   r  urllibr  r  rl  rk  r9   r9   r9   r:   r$   `  s:    
 
)]r2  r!  email.messager  r   r   r{   urllib.requestr  collections.abcr   http.cookiejarr   r   urllib.parser   r   r6  r-   configr   r9  r	   r
   r   r   r   r   
exceptionsr   r   r   r   r   r   r   	multipartr   status_codesr   utilsr   r   r   r   r   r   r   TYPE_CHECKINGZmiddleware.baser   Zdispatch.baser    r|   r   r,   rP   floatr\   ZPrimitiveDatarw   Mappingr   r   rx   rI  AnyStrr   r   r   rH  Z	AuthTypesZProxiesTypesr   r  r  r   r  IOr   rd  rf  r!   r_   r"   r#   r   r%   r  r  rJ  re  r$   r9   r9   r9   r:   <module>   s     $	$
 
 ^ EP1/ 9e\