o
    &=jœ®  ã                   @  sÐ  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	Z	d dl
Zd dlmZ d dlmZmZ ddl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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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; g d¢Z<ddhZ=d3dd„Z>d4d5dd„Z?d4d6dd„Z@d7d!d"„ZAd8d$d%„ZBd9d)d*„ZCG d+d,„ d,e	jDeEeEf ƒZFG d-d.„ d.ƒZGG d/d0„ d0ƒZHG d1d2„ d2e	jDeEeEf ƒZIdS ):é    )ÚannotationsN)ÚMapping)ÚCookieÚ	CookieJaré   )Ú
ByteStreamÚUnattachedStreamÚencode_requestÚencode_response)ÚSUPPORTED_DECODERSÚByteChunkerÚContentDecoderÚIdentityDecoderÚLineDecoderÚMultiDecoderÚTextChunkerÚTextDecoder)ÚCookieConflictÚHTTPStatusErrorÚRequestNotReadÚResponseNotReadÚStreamClosedÚStreamConsumedÚrequest_context)Ú(get_multipart_boundary_from_content_type)Úcodes)ÚAsyncByteStreamÚCookieTypesÚHeaderTypesÚQueryParamTypesÚRequestContentÚRequestDataÚRequestExtensionsÚRequestFilesÚResponseContentÚResponseExtensionsÚSyncByteStream)ÚURL)Úto_bytes_or_strÚto_str)ÚCookiesÚHeadersÚRequestÚResponseÚauthorizationzproxy-authorizationÚencodingÚstrÚreturnÚboolc                 C  s&   zt  | ¡ W dS  ty   Y dS w )z7
    Return `True` if `encoding` is a known codec.
    FTN)ÚcodecsÚlookupÚLookupError©r/   © r7   úWC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\httpx/_models.pyÚ_is_known_encoding8   s   þÿr9   Úkeyústr | bytesú
str | NoneÚbytesc                 C  s   t | tƒr| S |  |pd¡S )zE
    Coerce str/bytes into a strictly byte-wise HTTP header key.
    ÚasciiN)Ú
isinstancer=   Úencode)r:   r/   r7   r7   r8   Ú_normalize_header_keyC   s   rA   Úvaluec                 C  s8   t | tƒr| S t | tƒstdt| ƒ› �ƒ‚|  |pd¡S )zG
    Coerce str/bytes into a strictly byte-wise HTTP header value.
    z'Header value must be str or bytes, not r>   N)r?   r=   r0   Ú	TypeErrorÚtyper@   )rB   r/   r7   r7   r8   Ú_normalize_header_valueJ   s
   

rE   Úcontent_typec                 C  s   t j ¡ }| |d< |jd d�S )Núcontent-type)Úfailobj)ÚemailÚmessageÚMessageÚget_content_charset)rF   Úmsgr7   r7   r8   Ú_parse_content_type_charsetU   s   
rN   úlist[dict[str, str]]c           	   
   C  sÆ   g }d}|   |¡} | s|S t d| ¡D ]M}z
| dd¡\}}W n ty-   |d}}Y nw d|  d¡i}| d¡D ] }z	| d¡\}} W n
 tyO   Y  q[w |   |¡||  |¡< q:| |¡ q|S )
a7  
    Returns a list of parsed link headers, for more info see:
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
    The generic syntax of those is:
    Link: < uri-reference >; param1=value1; param2="value2"
    So for instance:
    Link; '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;'
    would return
        [
            {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
            {"url": "http://.../back.jpeg"},
        ]
    :param value: HTTP Link entity-header field
    :return: list of parsed link headers
    z '"z, *<ú;r   Ú Úurlz<> '"ú=N)ÚstripÚreÚsplitÚ
ValueErrorÚappend)	rB   ÚlinksÚreplace_charsÚvalrR   ÚparamsÚlinkÚparamr:   r7   r7   r8   Ú_parse_header_links]   s*   
ÿÿr_   Úitemsú4typing.Iterable[tuple[typing.AnyStr, typing.AnyStr]]ú4typing.Iterator[tuple[typing.AnyStr, typing.AnyStr]]c                 c  s:   � | D ]\}}t | ¡ ƒtv rtd|d�}||fV  qd S )Nz[secure])Zmatch_type_of)r)   ÚlowerÚSENSITIVE_HEADERSr(   )r`   ÚkÚvr7   r7   r8   Ú_obfuscate_sensitive_headers‚   s   €ýrg   c                   @  sò   e Zd ZdZ		dAdBd	d
„ZedCdd„ƒZejdDdd„ƒZedEdd„ƒZdFdd„Z	dGdd„Z
dHdd„ZdIdd„ZdJdKd"d#„ZdLdMd(d)„ZdJdNd*d+„ZdOd,d-„ZdPd.d/„ZdQd0d1„ZdRd2d3„ZdSd4d5„ZdTd7d8„ZdUd:d;„ZdVd=d>„ZdCd?d@„ZdS )Wr+   z9
    HTTP headers, as a case-insensitive multi-dict.
    NÚheadersúHeaderTypes | Noner/   r<   r1   ÚNonec                 C  s®   g | _ t|tƒrt|j ƒ| _ nCt|tƒr2| ¡ D ]9\}}t||ƒ}t||ƒ}| j  || 	¡ |f¡ q|d urR|D ]\}}t||ƒ}t||ƒ}| j  || 	¡ |f¡ q8|| _
d S ©N)Ú_listr?   r+   Úlistr   r`   rA   rE   rX   rc   Ú	_encoding)Úselfrh   r/   re   rf   Z	bytes_keyZbytes_valuer7   r7   r8   Ú__init__�   s   






zHeaders.__init__r0   c              
   C  sh   | j du r1dD ]&}| jD ]\}}z| |¡ | |¡ W q ty&   Y  qw || _  | j S d| _ | j S )zn
        Header encoding is mandated as ascii, but we allow fallbacks to utf-8
        or iso-8859-1.
        N)r>   úutf-8z
iso-8859-1)rn   ÚrawÚdecodeÚUnicodeDecodeError)ro   r/   r:   rB   r7   r7   r8   r/   ¦   s   

ÿÿzHeaders.encodingrB   c                 C  ó
   || _ d S rk   )rn   ©ro   rB   r7   r7   r8   r/   ¿   ó   
úlist[tuple[bytes, bytes]]c                 C  ó   dd„ | j D ƒS )zH
        Returns a list of the raw header items, as byte pairs.
        c                 S  s   g | ]	\}}}||f‘qS r7   r7   )Ú.0Zraw_keyÚ_rB   r7   r7   r8   Ú
<listcomp>È   ó    zHeaders.raw.<locals>.<listcomp>N©rl   ©ro   r7   r7   r8   rr   Ã   s   zHeaders.rawútyping.KeysView[str]c                   s   ‡ fdd„ˆ j D ƒ ¡ S )Nc                   s    i | ]\}}}|  ˆ j¡d “qS rk   ©rs   r/   ©rz   r{   r:   rB   r   r7   r8   Ú
<dictcomp>Ë   s     z Headers.keys.<locals>.<dictcomp>)rl   Úkeysr   r7   r   r8   r„   Ê   s   zHeaders.keysútyping.ValuesView[str]c                 C  ó^   i }| j D ]%\}}}| | j¡}| | j¡}||v r&||  d|› �7  < q|||< q| ¡ S )Nú, )rl   rs   r/   Úvalues©ro   Zvalues_dictr{   r:   rB   Zstr_keyZ	str_valuer7   r7   r8   rˆ   Í   s   
zHeaders.valuesútyping.ItemsView[str, str]c                 C  r†   )z›
        Return `(key, value)` items of headers. Concatenate headers
        into a single comma separated value when a key occurs multiple times.
        r‡   N)rl   rs   r/   r`   r‰   r7   r7   r8   r`   Ø   s   
zHeaders.itemsúlist[tuple[str, str]]c                   s   ‡ fdd„ˆ j D ƒS )z¹
        Return a list of `(key, value)` pairs of headers. Allow multiple
        occurrences of the same key without concatenating into a single
        comma separated value.
        c                   s*   g | ]\}}}|  ˆ j¡|  ˆ j¡f‘qS r7   r�   r‚   r   r7   r8   r|   í   s    ÿÿz'Headers.multi_items.<locals>.<listcomp>Nr~   r   r7   r   r8   Úmulti_itemsç   s   
þzHeaders.multi_itemsr:   Údefaultú
typing.Anyc                 C  s"   z| | W S  t y   | Y S w )zˆ
        Return a header value. If multiple occurrences of the header occur
        then concatenate them together with commas.
        N)ÚKeyError)ro   r:   r�   r7   r7   r8   Úgetò   s
   
ÿzHeaders.getFÚsplit_commasr2   ú	list[str]c                   sZ   |  ¡  ˆj¡‰ ‡ ‡fdd„ˆjD ƒ}|s|S g }|D ]}| dd„ | d¡D ƒ¡ q|S )zÆ
        Return a list of all header values for a given key.
        If `split_commas=True` is passed, then any comma separated header
        values are split into multiple return strings.
        c                   s*   g | ]\}}}|  ¡ ˆ kr| ˆj¡‘qS r7   )rc   rs   r/   )rz   r{   Úitem_keyZ
item_value©Zget_header_keyro   r7   r8   r|     s    
ý
ÿz$Headers.get_list.<locals>.<listcomp>c                 S  s   g | ]}|  ¡ ‘qS r7   )rT   )rz   Úitemr7   r7   r8   r|     s    ú,N)rc   r@   r/   rl   ÚextendrV   )ro   r:   r‘   rˆ   Zsplit_valuesrB   r7   r”   r8   Úget_listü   s   þzHeaders.get_listc                 C  s:   t |ƒ}| ¡ D ]}|| v r|  |¡ q| j |j¡ d S rk   )r+   r„   Úpoprl   r—   )ro   rh   r:   r7   r7   r8   Úupdate  s   
€zHeaders.updatec                 C  s   t | | jd�S )Nr6   )r+   r/   r   r7   r7   r8   Úcopy  s   zHeaders.copyc                   s<   |  ¡  ˆj¡‰ ‡ ‡fdd„ˆjD ƒ}|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
        c                   s&   g | ]\}}}|ˆ kr|  ˆj¡‘qS r7   r�   )rz   r{   Ú
header_keyÚheader_value©Znormalized_keyro   r7   r8   r|   %  s    ý
ÿz'Headers.__getitem__.<locals>.<listcomp>r‡   N)rc   r@   r/   rl   Újoinr�   )ro   r:   r`   r7   rž   r8   Ú__getitem__  s   þ
zHeaders.__getitem__c                   s”   |  | jpd¡}|  | jpd¡}| ¡ ‰ ‡ fdd„t| jƒD ƒ}t|dd… ƒD ]}| j|= q(|r?|d }|ˆ |f| j|< dS | j |ˆ |f¡ dS )zs
        Set the header `key` to `value`, removing any duplicate entries.
        Retains insertion order.
        rq   c                   s"   g | ]\}\}}}|ˆ kr|‘qS r7   r7   ©rz   Úidxr{   r“   ©Z
lookup_keyr7   r8   r|   9  s    ýÿz'Headers.__setitem__.<locals>.<listcomp>r   Nr   )r@   rn   rc   Ú	enumeraterl   ÚreversedrX   )ro   r:   rB   Zset_keyÚ	set_valueZfound_indexesr¢   r7   r£   r8   Ú__setitem__0  s   
þ
zHeaders.__setitem__c                   sN   |  ¡  | j¡‰ ‡ fdd„t| jƒD ƒ}|st|ƒ‚t|ƒD ]}| j|= qdS )z*
        Remove the header `key`.
        c                   s&   g | ]\}\}}}|  ¡ ˆ kr|‘qS r7   )rc   r¡   ©Zdel_keyr7   r8   r|   N  s    
ýÿz'Headers.__delitem__.<locals>.<listcomp>N)rc   r@   r/   r¤   rl   r�   r¥   )ro   r:   Zpop_indexesr¢   r7   r¨   r8   Ú__delitem__H  s   
þ
ÿzHeaders.__delitem__c                 C  s$   |  ¡  | j¡}|dd„ | jD ƒv S )Nc                 S  s   g | ]\}}}|‘qS r7   r7   )rz   r{   r:   r7   r7   r8   r|   \  s    z(Headers.__contains__.<locals>.<listcomp>)rc   r@   r/   rl   )ro   r:   rœ   r7   r7   r8   Ú__contains__Z  s   zHeaders.__contains__útyping.Iterator[typing.Any]c                 C  s   t |  ¡ ƒS rk   )Úiterr„   r   r7   r7   r8   Ú__iter__^  ó   zHeaders.__iter__Úintc                 C  ó
   t | jƒS rk   )Úlenrl   r   r7   r7   r8   Ú__len__a  ó   
zHeaders.__len__Úotherc                 C  sR   zt |ƒ}W n
 ty   Y dS w dd„ | jD ƒ}dd„ |jD ƒ}t|ƒt|ƒkS )NFc                 S  ó   g | ]	\}}}||f‘qS r7   r7   r‚   r7   r7   r8   r|   j  r}   z"Headers.__eq__.<locals>.<listcomp>c                 S  rµ   r7   r7   r‚   r7   r7   r8   r|   k  r}   )r+   rW   rl   Úsorted)ro   r´   Zother_headersZ	self_listZ
other_listr7   r7   r8   Ú__eq__d  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 )NrQ   r>   z, encoding=ú(ú))Ú	__class__Ú__name__r/   rm   rg   rŒ   Údictr±   )ro   Ú
class_nameZencoding_strZas_listZas_dictZno_duplicate_keysr7   r7   r8   Ú__repr__n  s   
zHeaders.__repr__©NN)rh   ri   r/   r<   r1   rj   ©r1   r0   ©rB   r0   r1   rj   )r1   rx   )r1   r€   )r1   r…   )r1   rŠ   )r1   r‹   rk   )r:   r0   r�   rŽ   r1   rŽ   )F)r:   r0   r‘   r2   r1   r’   )rh   ri   r1   rj   )r1   r+   )r:   r0   r1   r0   ©r:   r0   rB   r0   r1   rj   )r:   r0   r1   rj   )r:   rŽ   r1   r2   )r1   r«   ©r1   r¯   )r´   rŽ   r1   r2   )r»   Ú
__module__Ú__qualname__Ú__doc__rp   Úpropertyr/   Úsetterrr   r„   rˆ   r`   rŒ   r�   r˜   rš   r›   r    r§   r©   rª   r­   r²   r·   r¾   r7   r7   r7   r8   r+   ‹   s6    ý













r+   c                
   @  sv   e Zd Zddddddddddœ	d0dd„Zd1dd „Zed2d"d#„ƒZd2d$d%„Zd2d&d'„Zd3d(d)„Z	d4d+d,„Z
d5d.d/„ZdS )6r,   N)	r\   rh   ÚcookiesÚcontentÚdataÚfilesÚjsonÚstreamÚ
extensionsÚmethodr0   rR   ú	URL | strr\   úQueryParamTypes | Nonerh   ri   rÉ   úCookieTypes | NonerÊ   úRequestContent | NonerË   úRequestData | NonerÌ   úRequestFiles | NonerÍ   útyping.Any | NonerÎ   ú'SyncByteStream | AsyncByteStream | NonerÏ   úRequestExtensions | Noner1   rj   c       	      	   C  sÐ   |  ¡ | _|d u rt|ƒnt||d�| _t|ƒ| _|d u ri nt|ƒ| _|r-t|ƒ 	| ¡ |
d u rc| j 
d¡}t||||	t|rF| | jj¡nd d�d�\}}
|  |¡ |
| _t|
tƒra|  ¡  d S d S |
| _d S )N)r\   rG   )rF   )rÊ   rË   rÌ   rÍ   Úboundary)ÚupperrÐ   r'   rR   r+   rh   r¼   rÏ   r*   Úset_cookie_headerr�   r	   r   r@   r/   Ú_preparerÎ   r?   r   Úread)ro   rÐ   rR   r\   rh   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÏ   rF   r7   r7   r8   rp     s2   

ÿý
û

ÿ
zRequest.__init__Údefault_headersúdict[str, str]c                 C  s¦   |  ¡ D ]\}}| ¡ dkrd| jv rq| j ||¡ qg }d| jv }d| jv p,d| jv }|s<| jjr<| d| jjf¡ |sH| jdv rH| d¡ t	|| jj
 ƒ| _d S )Nútransfer-encodingzContent-LengthÚHostzTransfer-Encodings   Host)ÚPOSTÚPUTÚPATCH)s   Content-Lengthó   0)r`   rc   rh   Ú
setdefaultrR   ÚhostrX   ÚnetlocrÐ   r+   rr   )ro   rß   r:   rB   Zauto_headersZhas_hostZhas_content_lengthr7   r7   r8   rÝ   ¹  s   
ÿ
zRequest._preparer=   c                 C  ó   t | dƒstƒ ‚| jS ©NÚ_content)Úhasattrr   rì   r   r7   r7   r8   rÊ   Î  ó   
zRequest.contentc                 C  sH   t | dƒs!t| jtjƒsJ ‚d | j¡| _t| jtƒs!t| jƒ| _| jS )ú6
        Read and return the request content.
        rì   ó    N)rí   r?   rÎ   ÚtypingÚIterablerŸ   rì   r   r   r7   r7   r8   rÞ   Ô  s   
zRequest.readc                 Ã  sZ   �t | dƒs*t| jtjƒsJ ‚d dd„ | j2 ƒI dH ¡| _t| jtƒs*t| jƒ| _| jS )rï   rì   rð   c                 Ó  ó   �g | z3 d H W }|‘q6 S rk   r7   ©rz   Úpartr7   r7   r8   r|   è  ó   € z!Request.aread.<locals>.<listcomp>N)rí   r?   rÎ   rñ   ÚAsyncIterablerŸ   rì   r   r   r7   r7   r8   Úareadâ  s   €
zRequest.areadc                 C  s,   | j j}t| jƒ}d|› d| j›d|›d�S )Nú<r¸   r‡   z)>)rº   r»   r0   rR   rÐ   )ro   r½   rR   r7   r7   r8   r¾   ð  s   
zRequest.__repr__údict[str, typing.Any]c                 C  ó   dd„ | j  ¡ D ƒS )Nc                 S  ó   i | ]\}}|d vr||“qS ))rÏ   rÎ   r7   ©rz   ÚnamerB   r7   r7   r8   rƒ   ö  ó    ýÿz(Request.__getstate__.<locals>.<dictcomp>©Ú__dict__r`   r   r7   r7   r8   Ú__getstate__õ  ó   þzRequest.__getstate__Ústatec                 C  s0   |  ¡ D ]
\}}t| ||ƒ qi | _tƒ | _d S rk   )r`   ÚsetattrrÏ   r   rÎ   ©ro   r  rþ   rB   r7   r7   r8   Ú__setstate__ü  s   zRequest.__setstate__)rÐ   r0   rR   rÑ   r\   rÒ   rh   ri   rÉ   rÓ   rÊ   rÔ   rË   rÕ   rÌ   rÖ   rÍ   r×   rÎ   rØ   rÏ   rÙ   r1   rj   ©rß   rà   r1   rj   ©r1   r=   rÀ   ©r1   rú   ©r  rú   r1   rj   )r»   rÄ   rÅ   rp   rÝ   rÇ   rÊ   rÞ   rø   r¾   r  r  r7   r7   r7   r8   r,   ~  s&    ó
:



r,   c                   @  s8  e Zd Zdddddddddddœ
d‚dd„Zdƒdd „Zed„d"d#„ƒZejd…d%d#„ƒZed†d'd(„ƒZejd‡d*d(„ƒZedˆd,d-„ƒZ	edˆd.d/„ƒZ
ed‰d1d2„ƒZedŠd4d5„ƒZedˆd6d7„ƒZed‹d8d9„ƒZejdŒd:d9„ƒZed‹d;d<„ƒZd�d>d?„ZedŽdAdB„ƒZedŽdCdD„ƒZedŽdEdF„ƒZedŽdGdH„ƒZedŽdIdJ„ƒZedŽdKdL„ƒZedŽdMdN„ƒZd�dOdP„Zd�dRdS„Zed‘dUdV„ƒZed’dXdY„ƒZed“dZd[„ƒZdˆd\d]„Zd”d_d`„Zd•dbdc„ZdŠddde„Z d–d—didj„Z!d–d˜dldm„Z"d™dndo„Z#d–d—dpdq„Z$dšdrds„Z%dŠdtdu„Z&	d–d›dwdx„Z'	d–dœdzd{„Z(d�d|d}„Z)	d–d›d~d„Z*dšd€d�„Z+dS )žr-   Nrq   )
rh   rÊ   ÚtextÚhtmlrÍ   rÎ   ÚrequestrÏ   ÚhistoryÚdefault_encodingÚstatus_coder¯   rh   ri   rÊ   úResponseContent | Noner  r<   r  rÍ   rŽ   rÎ   rØ   r  úRequest | NonerÏ   úResponseExtensions | Noner  úlist[Response] | Noner  ú#str | typing.Callable[[bytes], str]r1   rj   c       
         C  s¨   || _ t|ƒ| _|| _d | _|	d u ri nt|	ƒ| _|
d u rg nt|
ƒ| _d| _	d| _
|| _|d u rLt||||ƒ\}}|  |¡ || _t|tƒrK|  ¡  n|| _d| _d S )NFr   )r  r+   rh   Ú_requestZnext_requestr¼   rÏ   rm   r  Ú	is_closedÚis_stream_consumedr  r
   rÝ   rÎ   r?   r   rÞ   Ú_num_bytes_downloaded)ro   r  rh   rÊ   r  r  rÍ   rÎ   r  rÏ   r  r  r7   r7   r8   rp     s$   


€
zResponse.__init__rß   rà   c                 C  s<   |  ¡ D ]\}}| ¡ dkrd| jv rq| j ||¡ qd S )Nrá   zcontent-length)r`   rc   rh   rç   )ro   rß   r:   rB   r7   r7   r8   rÝ   ;  s
   üzResponse._prepareúdatetime.timedeltac                 C  s   t | dƒs	tdƒ‚| jS )ze
        Returns the time taken for the complete request/response
        cycle to complete.
        Ú_elapsedzK'.elapsed' may only be accessed after the response has been read or closed.N)rí   ÚRuntimeErrorr  r   r7   r7   r8   ÚelapsedB  s
   
ÿzResponse.elapsedr  c                 C  ru   rk   )r  )ro   r  r7   r7   r8   r  O  rw   r,   c                 C  s   | j du r	tdƒ‚| j S )zR
        Returns the request instance associated to the current response.
        Nz7The request instance has not been set on this response.)r  r  r   r7   r7   r8   r  S  s
   
ÿzResponse.requestrB   c                 C  ru   rk   )r  rv   r7   r7   r8   r  ^  rw   r0   c                 C  s2   z| j d }W n
 ty   Y dS w |jddd�S )NÚhttp_versionzHTTP/1.1r>   Úignore©Úerrors)rÏ   r�   rs   )ro   r  r7   r7   r8   r  b  s   ÿzResponse.http_versionc                 C  s<   z| j d }W n ty   t | j¡ Y S w |jddd�S )NÚreason_phraser>   r   r!  )rÏ   r�   r   Zget_reason_phraser  rs   )ro   r#  r7   r7   r8   r#  k  s   ÿzResponse.reason_phraser'   c                 C  s   | j jS )zA
        Returns the URL for which the request was made.
        N)r  rR   r   r7   r7   r8   rR   t  s   zResponse.urlr=   c                 C  rê   rë   )rí   r   rì   r   r7   r7   r8   rÊ   {  rî   zResponse.contentc                 C  sR   t | dƒs&| j}|sd| _| jS t| jpdd�}d | | j¡| ¡ g¡| _| jS )NÚ_textrQ   rq   r6   )rí   rÊ   r$  r   r/   rŸ   rs   Úflush)ro   rÊ   Údecoderr7   r7   r8   r  �  s   
þzResponse.textc                 C  sZ   t | dƒs*| j}|du st|ƒs%t| jtƒr| j}nt | dƒr%|  | j¡}|p(d| _| jS )aï  
        Return an encoding to use for decoding the byte content into text.
        The priority for determining this is given by...

        * `.encoding = <>` has been set explicitly.
        * The encoding as specified by the charset parameter in the Content-Type header.
        * The encoding as determined by `default_encoding`, which may either be
          a string like "utf-8" indicating the encoding to use, or may be a callable
          which enables charset autodetection.
        rn   Nrì   rq   )rí   Úcharset_encodingr9   r?   r  r0   rì   rn   )ro   r/   r7   r7   r8   r/   Œ  s   


zResponse.encodingc                 C  s   t | dƒr	tdƒ‚|| _dS )zÆ
        Set the encoding to use for decoding the byte content into text.

        If the `text` attribute has been accessed, attempting to set the
        encoding will throw a ValueError.
        r$  z?Setting encoding after `text` has been accessed is not allowed.N)rí   rW   rn   rv   r7   r7   r8   r/   ¢  s
   
ÿ
c                 C  s    | j  d¡}|du rdS t|ƒS )zO
        Return the encoding, as specified by the Content-Type header.
        zContent-TypeN)rh   r�   rN   )ro   rF   r7   r7   r8   r'  °  s   zResponse.charset_encodingr   c              	   C  s¦   t | dƒsPg }| 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rLt
|d�| _	| 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   )ÚchildrenN)rí   rh   r˜   rT   rc   r   rX   r�   r±   r(  r   r   )ro   Zdecodersrˆ   rB   Zdecoder_clsr7   r7   r8   Ú_get_content_decoder»  s&   
ÿ
ûþzResponse._get_content_decoderr2   c                 C  ó   t  | j¡S )zU
        A property which is `True` for 1xx status codes, `False` otherwise.
        N)r   Úis_informationalr  r   r7   r7   r8   r,  Ô  ó   zResponse.is_informationalc                 C  r+  )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        N)r   Ú
is_successr  r   r7   r7   r8   r.  Û  r-  zResponse.is_successc                 C  r+  )a  
        A property which is `True` for 3xx status codes, `False` otherwise.

        Note that not all responses with a 3xx status code indicate a URL redirect.

        Use `response.has_redirect_location` to determine responses with a properly
        formed URL redirection.
        N)r   Úis_redirectr  r   r7   r7   r8   r/  â  s   
zResponse.is_redirectc                 C  r+  )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        N)r   Úis_client_errorr  r   r7   r7   r8   r0  î  r-  zResponse.is_client_errorc                 C  r+  )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        N)r   Úis_server_errorr  r   r7   r7   r8   r1  õ  r-  zResponse.is_server_errorc                 C  r+  )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        N)r   Úis_errorr  r   r7   r7   r8   r2  ü  r-  zResponse.is_errorc                 C  s(   | j tjtjtjtjtjfv od| jv S )zs
        Returns True for 3xx responses with a properly formed URL redirection,
        `False` otherwise.
        ZLocationN)r  r   ÚMOVED_PERMANENTLYÚFOUNDÚ	SEE_OTHERÚTEMPORARY_REDIRECTÚPERMANENT_REDIRECTrh   r   r7   r7   r8   Úhas_redirect_location  s   öÿòzResponse.has_redirect_locationc                 C  sp   | j }|du rtdƒ‚| jr| S | jrd}nd}| jd }dddd	d
œ}| |d¡}|j| |d�}t||| d�‚)z>
        Raise the `HTTPStatusError` if one occurred.
        NzYCannot call `raise_for_status` as the request instance has not been set on this response.zÒ{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
Redirect location: '{0.headers[location]}'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}z§{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}éd   zInformational responsezRedirect responsezClient errorzServer error)r   é   é   é   zInvalid status code)Ú
error_type)r  Úresponse)r  r  r.  r8  r  r�   Úformatr   )ro   r  rJ   Zstatus_classZerror_typesr=  r7   r7   r8   Úraise_for_status  s*   ÿÿÿ
üzResponse.raise_for_statusÚkwargsc                 K  s   t j| jfi |¤ŽS rk   )ÚjsonlibÚloadsrÊ   )ro   rA  r7   r7   r8   rÍ   ?  s   zResponse.jsonr*   c                 C  s$   t | dƒstƒ | _| j | ¡ | jS )NÚ_cookies)rí   r*   rD  Úextract_cookiesr   r7   r7   r8   rÉ   B  s   
zResponse.cookiesú dict[str | None, dict[str, str]]c                 C  s*   | j  d¡}|du ri S dd„ t|ƒD ƒS )zI
        Returns the parsed header links of the response, if any
        r]   Nc                 S  s"   i | ]}|  d ¡p|  d¡|“qS )ÚrelrR   )r�   )rz   r]   r7   r7   r8   rƒ   R  s    ÿÿz"Response.links.<locals>.<dictcomp>)rh   r�   r_   )ro   Úheaderr7   r7   r8   rY   I  s   þzResponse.linksc                 C  s   | j S rk   )r  r   r7   r7   r8   Únum_bytes_downloadedW  s   zResponse.num_bytes_downloadedc                 C  s   d| j › d| j› d�S )Nz<Response [ú ú]>)r  r#  r   r7   r7   r8   r¾   [  s   zResponse.__repr__rú   c                 C  rû   )Nc                 S  rü   ))rÏ   rÎ   r  r(  r7   rý   r7   r7   r8   rƒ   _  rÿ   z)Response.__getstate__.<locals>.<dictcomp>r   r   r7   r7   r8   r  ^  r  zResponse.__getstate__r  c                 C  s6   |  ¡ D ]
\}}t| ||ƒ qd| _i | _tƒ | _d S )NT)r`   r  r  rÏ   r   rÎ   r  r7   r7   r8   r  e  s
   zResponse.__setstate__c                 C  s    t | dƒsd |  ¡ ¡| _| jS )ú7
        Read and return the response content.
        rì   rð   N)rí   rŸ   Ú
iter_bytesrì   r   r7   r7   r8   rÞ   l  s   
zResponse.readÚ
chunk_sizeú
int | Noneútyping.Iterator[bytes]c                 c  sü   � t | dƒr,|du rt| jƒn|}tdt| jƒt|dƒƒD ]}| j||| … V  qdS |  ¡ }t|d�}t| jd��9 |  	¡ D ]}| 
|¡}| 
|¡D ]}|V  qLq@| ¡ }| 
|¡D ]}|V  q\| ¡ D ]}|V  qfW d  ƒ dS 1 sww   Y  dS ©z˜
        A byte-iterator over the decoded response content.
        This allows us to handle gzip, deflate, brotli, and zstd encoded responses.
        rì   Nr   r   ©rN  ©r  )rí   r±   rì   ÚrangeÚmaxr*  r   r   r  Úiter_rawrs   r%  ©ro   rN  Úir&  ÚchunkerZ	raw_bytesÚdecodedÚchunkr7   r7   r8   rM  t  s*   €
ÿ

ÿÿ"øzResponse.iter_bytesútyping.Iterator[str]c                 c  s®   � t | jpdd�}t|d�}t| jd��9 |  ¡ D ]}| |¡}| |¡D ]}|V  q%q| ¡ }| |¡D ]}|V  q5| ¡ D ]}|V  q?W d  ƒ dS 1 sPw   Y  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.
        rq   r6   rR  rS  N)r   r/   r   r   r  rM  rs   r%  ©ro   rN  r&  rY  Zbyte_contentZtext_contentr[  r7   r7   r8   Ú	iter_text‹  s    €

ÿÿ"øzResponse.iter_textc                 c  sr   � t ƒ }t| jd��% |  ¡ D ]}| |¡D ]}|V  qq| ¡ D ]}|V  q!W d   ƒ d S 1 s2w   Y  d S ©NrS  )r   r   r  r_  rs   r%  ©ro   r&  r  Úliner7   r7   r8   Ú
iter_linesž  s   €ÿÿ"üzResponse.iter_linesc                 c  sÄ   � | j rtƒ ‚| jrtƒ ‚t| jtƒstdƒ‚d| _ d| _t	|d�}t
| jd��" | jD ]}|  jt|ƒ7  _| |¡D ]}|V  q<q,W d  ƒ n1 sMw   Y  | ¡ D ]}|V  qV|  ¡  dS )ú@
        A byte-iterator over the raw response content.
        z5Attempted to call a sync iterator on an async stream.Tr   rR  rS  N)r  r   r  r   r?   rÎ   r&   r  r  r   r   r  r±   rs   r%  Úclose©ro   rN  rY  Zraw_stream_bytesr[  r7   r7   r8   rV  §  s*   €

ÿþÿzResponse.iter_rawc                 C  s`   t | jtƒs
tdƒ‚| js.d| _t| jd�� | j ¡  W d  ƒ dS 1 s'w   Y  dS dS )ú‰
        Close the response and release the connection.
        Automatically called if the response body is read to completion.
        z3Attempted to call an sync close on an async stream.TrS  N)r?   rÎ   r&   r  r  r   r  re  r   r7   r7   r8   re  Á  s   "ÿþzResponse.closec                 Ã  s2   �t | dƒsd dd„ |  ¡ 2 ƒI dH ¡| _| jS )rL  rì   rð   c                 Ó  ró   rk   r7   rô   r7   r7   r8   r|   Ó  rö   z"Response.aread.<locals>.<listcomp>N)rí   rŸ   Úaiter_bytesrì   r   r7   r7   r8   rø   Î  s   €
 zResponse.areadútyping.AsyncIterator[bytes]c                 C s  �t | dƒr,|du rt| jƒn|}tdt| jƒt|dƒƒD ]}| j||| … V  qdS |  ¡ }t|d�}t| jd��> |  	¡ 2 z3 dH W }| 
|¡}| 
|¡D ]}|V  qPq@6 | ¡ }| 
|¡D ]}|V  qa| ¡ D ]}|V  qkW d  ƒ dS 1 s|w   Y  dS rQ  )rí   r±   rì   rT  rU  r*  r   r   r  Ú	aiter_rawrs   r%  rW  r7   r7   r8   rh  Ö  s,   €
ÿ

ÿþÿ"øzResponse.aiter_bytesútyping.AsyncIterator[str]c                 C s¸   �t | jpdd�}t|d�}t| jd��> |  ¡ 2 z3 dH W }| |¡}| |¡D ]}|V  q)q6 | ¡ }| |¡D ]}|V  q:| ¡ D ]}|V  qDW d  ƒ dS 1 sUw   Y  dS r]  )r   r/   r   r   r  rh  rs   r%  r^  r7   r7   r8   Ú
aiter_textï  s"   €

ÿþÿ"øzResponse.aiter_textc                 C s|   �t ƒ }t| jd��* |  ¡ 2 z3 d H W }| |¡D ]}|V  qq6 | ¡ D ]}|V  q&W d   ƒ d S 1 s7w   Y  d S r`  )r   r   r  rl  rs   r%  ra  r7   r7   r8   Úaiter_lines  s   €ÿÿÿ"üzResponse.aiter_linesc                 C sÔ   �| j rtƒ ‚| jrtƒ ‚t| jtƒstdƒ‚d| _ d| _t	|d�}t
| jd��' | j2 z3 dH W }|  jt|ƒ7  _| |¡D ]}|V  q@q,6 W d  ƒ n1 sRw   Y  | ¡ D ]}|V  q[|  ¡ I dH  dS )rd  z6Attempted to call an async iterator on an sync stream.Tr   rR  rS  N)r  r   r  r   r?   rÎ   r   r  r  r   r   r  r±   rs   r%  Úacloserf  r7   r7   r8   rj    s*   €
ÿþÿzResponse.aiter_rawc                 Ã  sh   �t | jtƒstdƒ‚| js2d| _t| jd�� | j ¡ I dH  W d  ƒ dS 1 s+w   Y  dS dS )rg  z3Attempted to call an async close on an sync stream.TrS  N)r?   rÎ   r   r  r  r   r  rn  r   r7   r7   r8   rn  )  s   €"ÿþzResponse.aclose)r  r¯   rh   ri   rÊ   r  r  r<   r  r<   rÍ   rŽ   rÎ   rØ   r  r  rÏ   r  r  r  r  r  r1   rj   r  )r1   r  )r  r  r1   rj   )r1   r,   )rB   r,   r1   rj   rÀ   )r1   r'   r	  )r1   r<   rÁ   )r1   r   ©r1   r2   )r1   r-   )rA  rŽ   r1   rŽ   )r1   r*   )r1   rF  rÃ   r
  r  rk   )rN  rO  r1   rP  )rN  rO  r1   r\  ©r1   r\  )r1   rj   )rN  rO  r1   ri  )rN  rO  r1   rk  )r1   rk  ),r»   rÄ   rÅ   rp   rÝ   rÇ   r  rÈ   r  r  r#  rR   rÊ   r  r/   r'  r*  r,  r.  r/  r0  r1  r2  r8  r@  rÍ   rÉ   rY   rI  r¾   r  r  rÞ   rM  r_  rc  rV  re  rø   rh  rl  rm  rj  rn  r7   r7   r7   r8   r-     sœ    ó
7





%




	

	ÿÿ

ÿr-   c                   @  sÞ   e Zd ZdZd9d:dd„Zd;dd„Zd<dd„Zd=d>dd„Z			d?d@dd„Z		dAdBdd„Z	dAdCd d!„Z
d9d:d"d#„ZdDd$d%„ZdEd&d'„ZdFd(d)„ZdGd+d,„ZdHd.d/„ZdId1d2„ZdJd3d4„ZG d5d6„ d6ejjƒZG d7d8„ d8ƒZdS )Kr*   z-
    HTTP Cookies, as a mutable mapping.
    NrÉ   rÓ   r1   rj   c                 C  s²   |d u s	t |tƒr%tƒ | _t |tƒr!| ¡ D ]\}}|  ||¡ qd S d S t |tƒr=tƒ | _|D ]
\}}|  ||¡ q0d S t |tƒrTtƒ | _|jD ]}| j |¡ qId S || _d S rk   )	r?   r¼   r   Újarr`   Úsetrm   r*   Ú
set_cookie)ro   rÉ   r:   rB   Úcookier7   r7   r8   rp   <  s$   
þ
ÿ

ÿ
zCookies.__init__r>  r-   c                 C  s(   |   |¡}|  |j¡}| j ||¡ dS )zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)Ú_CookieCompatResponseÚ_CookieCompatRequestr  rq  rE  )ro   r>  Zurllib_responseÚurllib_requestr7   r7   r8   rE  M  s   
zCookies.extract_cookiesr  r,   c                 C  s   |   |¡}| j |¡ dS )zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)rv  rq  Úadd_cookie_header)ro   r  rw  r7   r7   r8   rÜ   V  s   
zCookies.set_cookie_headerrQ   ú/rþ   r0   rB   ÚdomainÚpathc                 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   rþ   rB   ÚportNÚport_specifiedFrz  Údomain_specifiedÚdomain_initial_dotÚ.r{  Úpath_specifiedÚsecureÚexpiresÚdiscardTÚcommentÚcomment_urlÚrestÚHttpOnlyÚrfc2109r7   )r2   Ú
startswithr   rq  rs  )ro   rþ   rB   rz  r{  rA  rt  r7   r7   r8   rr  ]  sJ   ÿþýüûúù
ø	÷
öõôóòñðïzCookies.setr�   r<   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=)rq  rþ   rz  r{  r   rB   )ro   rþ   r�   rz  r{  rB   rt  rJ   r7   r7   r8   r�   w  s   


€zCookies.getc                   s\   ˆ durˆdur| j  ˆ ˆˆ¡S ‡ ‡‡fdd„| j D ƒ}|D ]}| j  |j|j|j¡ qdS )z�
        Delete a cookie by name. May optionally include domain and path
        in order to specify exactly which cookie to delete.
        Nc                   s>   g | ]}|j ˆkrˆ d u s|jˆ krˆd u s|jˆkr|‘qS rk   )rþ   rz  r{  ©rz   rt  ©rz  rþ   r{  r7   r8   r|   �  s    ýüüûûÿz"Cookies.delete.<locals>.<listcomp>)rq  Úclearrz  r{  rþ   )ro   rþ   rz  r{  Úremovert  r7   r�  r8   Ú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)rX   rq  rŽ  )ro   rz  r{  Úargsr7   r7   r8   rŽ  ¨  s   

zCookies.clearc                 C  s$   t |ƒ}|jD ]}| j |¡ qd S rk   )r*   rq  rs  )ro   rÉ   rt  r7   r7   r8   rš   µ  s   
ÿzCookies.updatec                 C  s   |   ||¡S rk   )rr  ©ro   rþ   rB   r7   r7   r8   r§   º  r®   zCookies.__setitem__c                 C  s   |   |¡}|d u rt|ƒ‚|S rk   )r�   r�   r’  r7   r7   r8   r    ½  s   
zCookies.__getitem__c                 C  s
   |   |¡S rk   )r�  )ro   rþ   r7   r7   r8   r©   Ã  r³   zCookies.__delitem__r¯   c                 C  r°   rk   )r±   rq  r   r7   r7   r8   r²   Æ  r³   zCookies.__len__r\  c                 C  ry   )Nc                 s  s   � | ]}|j V  qd S rk   )rþ   rŒ  r7   r7   r8   Ú	<genexpr>Ê  s   € z#Cookies.__iter__.<locals>.<genexpr>©rq  r   r7   r7   r8   r­   É  s   zCookies.__iter__r2   c                 C  s   | j D ]} dS dS )NTFr”  )ro   r{   r7   r7   r8   Ú__bool__Ì  s   
zCookies.__bool__c                 C  s"   d  dd„ | jD ƒ¡}d|› d�S )Nr‡   c              	   S  s*   g | ]}d |j › d|j› d|j› d�‘qS )z<Cookie rS   z for z />)rþ   rB   rz  rŒ  r7   r7   r8   r|   Ó  s    ÿÿz$Cookies.__repr__.<locals>.<listcomp>z	<Cookies[rK  )rŸ   rq  )ro   Zcookies_reprr7   r7   r8   r¾   Ñ  s   þÿzCookies.__repr__c                      s0   e Zd ZdZd‡ fdd„Zd‡ 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,   r1   rj   c                   s*   t ƒ jt|jƒt|jƒ|jd� || _d S )N)rR   rh   rÐ   )Úsuperrp   r0   rR   r¼   rh   rÐ   r  )ro   r  ©rº   r7   r8   rp   á  s   ý
z%Cookies._CookieCompatRequest.__init__r:   r0   rB   c                   s   t ƒ  ||¡ || jj|< d S rk   )r—  Úadd_unredirected_headerr  rh   )ro   r:   rB   r˜  r7   r8   r™  é  s   z4Cookies._CookieCompatRequest.add_unredirected_header©r  r,   r1   rj   rÂ   )r»   rÄ   rÅ   rÆ   rp   r™  Ú__classcell__r7   r7   r˜  r8   rv  Û  s    rv  c                   @  s$   e Zd ZdZddd„Zdd	d
„ZdS )zCookies._CookieCompatResponser–  r>  r-   r1   rj   c                 C  ru   rk   )r>  )ro   r>  r7   r7   r8   rp   ó  r³   z&Cookies._CookieCompatResponse.__init__úemail.message.Messagec                 C  s,   t j ¡ }| jj ¡ D ]\}}|||< q|S rk   )rI   rJ   rK   r>  rh   rŒ   )ro   Úinfor:   rB   r7   r7   r8   r�  ö  s   

z"Cookies._CookieCompatResponse.infoN©r>  r-   r1   rj   )r1   rœ  )r»   rÄ   rÅ   rÆ   rp   r�  r7   r7   r7   r8   ru  í  s    
ru  rk   )rÉ   rÓ   r1   rj   rž  rš  )rQ   ry  )
rþ   r0   rB   r0   rz  r0   r{  r0   r1   rj   )NNN)
rþ   r0   r�   r<   rz  r<   r{  r<   r1   r<   r¿   )rþ   r0   rz  r<   r{  r<   r1   rj   )rz  r<   r{  r<   r1   rj   )rþ   r0   rB   r0   r1   rj   )rþ   r0   r1   r0   )rþ   r0   r1   rj   rÃ   rp  ro  rÀ   )r»   rÄ   rÅ   rÆ   rp   rE  rÜ   rr  r�   r�  rŽ  rš   r§   r    r©   r²   r­   r•  r¾   Úurllibr  r,   rv  ru  r7   r7   r7   r8   r*   7  s0    

	ûü







r*   )r/   r0   r1   r2   rk   )r:   r;   r/   r<   r1   r=   )rB   r;   r/   r<   r1   r=   )rF   r0   r1   r<   )rB   r0   r1   rO   )r`   ra   r1   rb   )JÚ
__future__r   r3   ÚdatetimeÚemail.messagerI   rÍ   rB  rU   rñ   Úurllib.requestrŸ  Úcollections.abcr   Úhttp.cookiejarr   r   rì   r   r   r	   r
   Ú	_decodersr   r   r   r   r   r   r   r   Ú_exceptionsr   r   r   r   r   r   r   Z
_multipartr   Z_status_codesr   Ú_typesr   r   r   r   r    r!   r"   r#   r$   r%   r&   Z_urlsr'   Ú_utilsr(   r)   Ú__all__rd   r9   rA   rE   rN   r_   rg   ÚMutableMappingr0   r+   r,   r-   r*   r7   r7   r7   r8   Ú<module>   sH    ($
	4



%	 t     8