o
    í6Wjœ®  ã                   @  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.
    FT)ÚcodecsÚlookupÚLookupError©r/   © r7   ú\/home/esfera/Documents/content_generation/venv/lib/python3.10/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.
    Úascii)Ú
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>   )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  n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<> '"ú=)Ú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])Úmatch_type_of)r)   ÚlowerÚSENSITIVE_HEADERSr(   )r`   ÚkÚvr7   r7   r8   Ú_obfuscate_sensitive_headers‚   s   €ýrh   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 ƒ| _ nDt|tƒr3| ¡ D ]\}}t||ƒ}t||ƒ}| j  || 	¡ |f¡ qn |d urS|D ]\}}t||ƒ}t||ƒ}| j  || 	¡ |f¡ q9|| _
d S ©N)Ú_listr?   r+   Úlistr   r`   rA   rE   rX   rd   Ú	_encoding)Úselfri   r/   rf   rg   Ú	bytes_keyÚbytes_valuer7   r7   r8   Ú__init__�   s   



ý


zHeaders.__init__r0   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)r>   úutf-8z
iso-8859-1)ro   ÚrawÚdecodeÚUnicodeDecodeError)rp   r/   r:   rB   r7   r7   r8   r/   ¦   s   

ÿö	zHeaders.encodingrB   c                 C  ó
   || _ d S rl   )ro   ©rp   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   )Ú.0Úraw_keyÚ_rB   r7   r7   r8   Ú
<listcomp>È   ó    zHeaders.raw.<locals>.<listcomp>©rm   ©rp   r7   r7   r8   ru   Ã   s   zHeaders.rawútyping.KeysView[str]c                   s   ‡ fdd„ˆ j D ƒ ¡ S )Nc                   s    i | ]\}}}|  ˆ j¡d “qS rl   ©rv   r/   ©r}   r   r:   rB   rƒ   r7   r8   Ú
<dictcomp>Ë   s     z Headers.keys.<locals>.<dictcomp>)rm   Ú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ú, )rm   rv   r/   Úvalues©rp   Úvalues_dictr   r:   rB   Ústr_keyÚ	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‹   )rm   rv   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>r‚   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.
        )ÚKeyError)rp   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   )rd   rv   r/   )r}   r   Úitem_keyÚ
item_value©Úget_header_keyrp   r7   r8   r€     s
    
þz$Headers.get_list.<locals>.<listcomp>c                 S  s   g | ]}|  ¡ ‘qS r7   )rT   )r}   Úitemr7   r7   r8   r€     s    ú,)rd   r@   r/   rm   ÚextendrV   )rp   r:   r˜   rŒ   Úsplit_valuesrB   r7   rœ   r8   Úget_listü   s   þzHeaders.get_listc                 C  s:   t |ƒ}| ¡ D ]}|| v r|  |¡ q| j |j¡ d S rl   )r+   rˆ   Úpoprm   r    )rp   ri   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…   )r}   r   Ú
header_keyÚheader_value©Únormalized_keyrp   r7   r8   r€   %  s
    
þz'Headers.__getitem__.<locals>.<listcomp>r‹   )rd   r@   r/   rm   Újoinr–   )rp   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.
        rt   c                   s"   g | ]\}\}}}|ˆ kr|‘qS r7   r7   ©r}   Úidxr   rš   ©Ú
lookup_keyr7   r8   r€   9  s
    þz'Headers.__setitem__.<locals>.<listcomp>r   Nr   )r@   ro   rd   Ú	enumeraterm   ÚreversedrX   )rp   r:   rB   Úset_keyÚ	set_valueÚ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   )rd   r¬   ©Údel_keyr7   r8   r€   N  s
    þz'Headers.__delitem__.<locals>.<listcomp>N)rd   r@   r/   r°   rm   r–   r±   )rp   r:   Ú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   )r}   r   r:   r7   r7   r8   r€   \  s    z(Headers.__contains__.<locals>.<listcomp>)rd   r@   r/   rm   )rp   r:   r¦   r7   r7   r8   Ú__contains__Z  s   zHeaders.__contains__útyping.Iterator[typing.Any]c                 C  s   t |  ¡ ƒS rl   )Úiterrˆ   rƒ   r7   r7   r8   Ú__iter__^  ó   zHeaders.__iter__Úintc                 C  ó
   t | jƒS rl   )Úlenrm   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   rm   Úsorted)rp   rÄ   Úother_headersÚ	self_listÚ
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/   rn   rh   r“   ÚdictrÁ   )rp   Ú
class_nameÚencoding_strÚas_listÚas_dictÚno_duplicate_keysr7   r7   r8   Ú__repr__n  s   
zHeaders.__repr__©NN)ri   rj   r/   r<   r1   rk   ©r1   r0   ©rB   r0   r1   rk   )r1   r{   )r1   r„   )r1   r‰   )r1   r‘   )r1   r’   rl   )r:   r0   r”   r•   r1   r•   )F)r:   r0   r˜   r2   r1   r™   )ri   rj   r1   rk   )r1   r+   )r:   r0   r1   r0   ©r:   r0   rB   r0   r1   rk   )r:   r0   r1   rk   )r:   r•   r1   r2   )r1   r»   ©r1   r¿   )rÄ   r•   r1   r2   )rÎ   Ú
__module__Ú__qualname__Ú__doc__rs   Úpropertyr/   Úsetterru   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\   ri   ÚcookiesÚcontentÚdataÚfilesÚjsonÚstreamÚ
extensionsÚmethodr0   rR   ú	URL | strr\   úQueryParamTypes | Noneri   rj   rà   úCookieTypes | Nonerá   úRequestContent | Nonerâ   úRequestData | Nonerã   úRequestFiles | Nonerä   útyping.Any | Nonerå   ú'SyncByteStream | AsyncByteStream | Noneræ   úRequestExtensions | Noner1   rk   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+   ri   rÏ   ræ   r*   Úset_cookie_headerr—   r	   r   r@   r/   Ú_preparerå   r?   r   Úread)rp   rç   rR   r\   ri   rà   rá   râ   rã   rä   rå   ræ   rF   r7   r7   r8   rs     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`   rd   ri   Ú
setdefaultrR   ÚhostrX   Únetlocrç   r+   ru   )rp   rö   r:   rB   Úauto_headersÚhas_hostÚ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  ó    )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 rl   r7   ©r}   Ú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ç   )rp   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   ©r}   Ú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 rl   )r`   Úsetattrræ   r   rå   ©rp   r  r  rB   r7   r7   r8   Ú__setstate__ü  s   zRequest.__setstate__)rç   r0   rR   rè   r\   ré   ri   rj   rà   rê   rá   rë   râ   rì   rã   rí   rä   rî   rå   rï   ræ   rð   r1   rk   ©rö   r÷   r1   rk   ©r1   r=   r×   ©r1   r  ©r  r  r1   rk   )rÎ   rÛ   rÜ   rs   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-   Nrt   )
ri   rá   ÚtextÚhtmlrä   rå   Úrequestræ   ÚhistoryÚdefault_encodingÚstatus_coder¿   ri   rj   rá   úResponseContent | Noner&  r<   r'  rä   r•   rå   rï   r(  úRequest | Noneræ   úResponseExtensions | Noner)  úlist[Response] | Noner*  ú#str | typing.Callable[[bytes], str]r1   rk   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+   ri   Ú_requestÚnext_requestrÏ   ræ   rn   r)  Ú	is_closedÚis_stream_consumedr*  r
   rô   rå   r?   r   rõ   Ú_num_bytes_downloaded)rp   r+  ri   rá   r&  r'  rä   rå   r(  ræ   r)  r*  r7   r7   r8   rs     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`   rd   ri   rþ   )rp   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.)r  ÚRuntimeErrorr7  rƒ   r7   r7   r8   ÚelapsedB  s
   
ÿzResponse.elapsedr9  c                 C  rx   rl   )r7  )rp   r9  r7   r7   r8   r9  O  rz   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.)r1  r8  rƒ   r7   r7   r8   r(  S  s
   
ÿzResponse.requestrB   c                 C  rx   rl   )r1  ry   r7   r7   r8   r(  ^  rz   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–   rv   )rp   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   Úget_reason_phraser+  rv   )rp   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.
        )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   rt   r6   )r  rá   r@  r   r/   rª   rv   Úflush)rp   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.
        ro   Nr  rt   )r  Úcharset_encodingr9   r?   r*  r0   r  ro   )rp   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   ro   ry   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)ri   r—   rN   )rp   rF   r7   r7   r8   rC  °  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   )Úchildren)r  ri   r¢   rT   rd   r   rX   r–   rÁ   rD  r   r   )rp   ÚdecodersrŒ   rB   Ú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.
        )r   Úis_informationalr+  rƒ   r7   r7   r8   rJ  Ô  ó   zResponse.is_informationalc                 C  rI  )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   Ú
is_successr+  rƒ   r7   r7   r8   rL  Û  rK  zResponse.is_successc                 C  rI  )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.
        )r   Úis_redirectr+  rƒ   r7   r7   r8   rM  â  s   
zResponse.is_redirectc                 C  rI  )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        )r   Úis_client_errorr+  rƒ   r7   r7   r8   rN  î  rK  zResponse.is_client_errorc                 C  rI  )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        )r   Úis_server_errorr+  rƒ   r7   r7   r8   rO  õ  rK  zResponse.is_server_errorc                 C  rI  )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        )r   Úis_errorr+  rƒ   r7   r7   r8   rP  ü  rK  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.
        ÚLocation)r+  r   ÚMOVED_PERMANENTLYÚFOUNDÚ	SEE_OTHERÚTEMPORARY_REDIRECTÚPERMANENT_REDIRECTri   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)r1  r8  rL  rW  r+  r—   Úformatr   )rp   r(  rJ   Ústatus_classÚerror_typesr\  r7   r7   r8   Úraise_for_status  s*   ÿÿÿ
üzResponse.raise_for_statusÚkwargsc                 K  s   t j| jfi |¤ŽS rl   )ÚjsonlibÚloadsrá   )rp   rb  r7   r7   r8   rä   ?  s   zResponse.jsonr*   c                 C  s$   t | dƒstƒ | _| j | ¡ | jS )NÚ_cookies)r  r*   re  Ú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—   )r}   r]   r7   r7   r8   r‡   R  s    ÿÿz"Response.links.<locals>.<dictcomp>)ri   r—   r_   )rp   Úheaderr7   r7   r8   rY   I  s   þzResponse.linksc                 C  s   | j S rl   )r5  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å   r3  rD  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  r3  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
  )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   ©ro  ©r(  )r  rÁ   r  ÚrangeÚmaxrH  r   r   r1  Úiter_rawrv   rA  ©rp   ro  ÚirB  ÚchunkerÚ	raw_bytesÚdecodedÚchunkr7   r7   r8   rn  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.
        rt   r6   rs  rt  N)r   r/   r   r   r1  rn  rv   rA  ©rp   ro  rB  rz  Úbyte_contentÚ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 ©Nrt  )r   r   r1  rƒ  rv   rA  ©rp   rB  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   rs  rt  N)r4  r   r3  r   r?   rå   r&   r8  r5  r   r   r1  rÁ   rv   rA  Úclose©rp   ro  rz  Úraw_stream_bytesr}  r7   r7   r8   rw  §  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.Trt  N)r?   rå   r&   r8  r3  r   r1  r‰  rƒ   r7   r7   r8   r‰  Á  s   "ÿþzResponse.closec                 Ã  s2   �t | dƒsd dd„ |  ¡ 2 ƒI dH ¡| _| jS )rm  r  r
  c                 Ó  r  rl   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 rr  )r  rÁ   r  ru  rv  rH  r   r   r1  Ú	aiter_rawrv   rA  rx  r7   r7   r8   r�  Ö  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   r1  r�  rv   rA  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   r1  r‘  rv   rA  r…  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 )rˆ  z6Attempted to call an async iterator on an sync stream.Tr   rs  rt  N)r4  r   r3  r   r?   rå   r   r8  r5  r   r   r1  rÁ   rv   rA  ÚacloserŠ  r7   r7   r8   r�    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 )rŒ  z3Attempted to call an async close on an sync stream.Trt  N)r?   rå   r   r8  r3  r   r1  r“  rƒ   r7   r7   r8   r“  )  s   €"ÿþzResponse.aclose)r+  r¿   ri   rj   rá   r,  r&  r<   r'  r<   rä   r•   rå   rï   r(  r-  ræ   r.  r)  r/  r*  r0  r1   rk   r"  )r1   r6  )r9  r6  r1   rk   )r1   r,   )rB   r,   r1   rk   r×   )r1   r'   r#  )r1   r<   rØ   )r1   r   ©r1   r2   )r1   r-   )rb  r•   r1   r•   )r1   r*   )r1   rg  rÚ   r$  r%  rl   )ro  rp  r1   rq  )ro  rp  r1   r~  ©r1   r~  )r1   rk   )ro  rp  r1   rŽ  )ro  rp  r1   r�  )r1   r�  ),rÎ   rÛ   rÜ   rs   rô   rÞ   r9  rß   r(  r:  r>  rR   rá   r&  r/   rC  rH  rJ  rL  rM  rN  rO  rP  rW  ra  rä   rà   rY   rj  rÕ   r  r!  rõ   rn  rƒ  r‡  rw  r‰  r  r�  r‘  r’  r�  r“  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   rk   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 rl   )	r?   rÏ   r   Újarr`   Úsetrn   r*   Ú
set_cookie)rp   rà   r:   rB   Úcookier7   r7   r8   rs   <  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(  r–  rf  )rp   r]  Úurllib_responseÚurllib_requestr7   r7   r8   rf  M  s   
zCookies.extract_cookiesr(  r,   c                 C  s   |   |¡}| j |¡ dS )zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)r›  r–  Úadd_cookie_header)rp   r(  r�  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_specifiedFr   Údomain_specifiedÚdomain_initial_dotÚ.r¡  Úpath_specifiedÚsecureÚexpiresÚdiscardTÚcommentÚcomment_urlÚrestÚHttpOnlyÚrfc2109r7   )r2   Ú
startswithr   r–  r˜  )rp   r  rB   r   r¡  rb  r™  r7   r7   r8   r—  ]  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=)r–  r  r   r¡  r   rB   )rp   r  r”   r   r¡  rB   r™  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 rl   )r  r   r¡  ©r}   r™  ©r   r  r¡  r7   r8   r€   �  s    
üz"Cookies.delete.<locals>.<listcomp>)r–  Úclearr   r¡  r  )rp   r  r   r¡  Úremover™  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   r–  r´  )rp   r   r¡  Úargsr7   r7   r8   r´  ¨  s   

zCookies.clearc                 C  s$   t |ƒ}|jD ]}| j |¡ qd S rl   )r*   r–  r˜  )rp   rà   r™  r7   r7   r8   r¤   µ  s   
ÿzCookies.updatec                 C  s   |   ||¡S rl   )r—  ©rp   r  rB   r7   r7   r8   rµ   º  r¾   zCookies.__setitem__c                 C  s   |   |¡}|d u rt|ƒ‚|S rl   )r—   r–   r¸  r7   r7   r8   r«   ½  s   
zCookies.__getitem__c                 C  s
   |   |¡S rl   )r¶  )rp   r  r7   r7   r8   r¹   Ã  rÃ   zCookies.__delitem__r¿   c                 C  rÀ   rl   )rÁ   r–  rƒ   r7   r7   r8   rÂ   Æ  rÃ   zCookies.__len__r~  c                 C  r|   )Nc                 s  s   � | ]}|j V  qd S rl   )r  r²  r7   r7   r8   Ú	<genexpr>Ê  s   € z#Cookies.__iter__.<locals>.<genexpr>©r–  rƒ   r7   r7   r8   r½   É  s   zCookies.__iter__r2   c                 C  s   | j D ]} dS dS )NTFrº  )rp   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   r   r²  r7   r7   r8   r€   Ó  s    ÿÿz$Cookies.__repr__.<locals>.<listcomp>z	<Cookies[rl  )rª   r–  )rp   Ú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   rk   c                   s*   t ƒ jt|jƒt|jƒ|jd� || _d S )N)rR   ri   rç   )Úsuperrs   r0   rR   rÏ   ri   rç   r(  )rp   r(  ©rÍ   r7   r8   rs   á  s   ý
z%Cookies._CookieCompatRequest.__init__r:   r0   rB   c                   s   t ƒ  ||¡ || jj|< d S rl   )r¾  Úadd_unredirected_headerr(  ri   )rp   r:   rB   r¿  r7   r8   rÀ  é  s   z4Cookies._CookieCompatRequest.add_unredirected_header©r(  r,   r1   rk   rÙ   )rÎ   rÛ   rÜ   rÝ   rs   rÀ  Ú__classcell__r7   r7   r¿  r8   r›  Û  s    r›  c                   @  s$   e Zd ZdZddd„Zdd	d
„ZdS )zCookies._CookieCompatResponser½  r]  r-   r1   rk   c                 C  rx   rl   )r]  )rp   r]  r7   r7   r8   rs   ó  rÃ   z&Cookies._CookieCompatResponse.__init__úemail.message.Messagec                 C  s,   t j ¡ }| jj ¡ D ]\}}|||< q|S rl   )rI   rJ   rK   r]  ri   r“   )rp   Úinfor:   rB   r7   r7   r8   rÄ  ö  s   

z"Cookies._CookieCompatResponse.infoN©r]  r-   r1   rk   )r1   rÃ  )rÎ   rÛ   rÜ   rÝ   rs   rÄ  r7   r7   r7   r8   rš  í  s    
rš  rl   )rà   rê   r1   rk   rÅ  rÁ  )rQ   rŸ  )
r  r0   rB   r0   r   r0   r¡  r0   r1   rk   )NNN)
r  r0   r”   r<   r   r<   r¡  r<   r1   r<   rÖ   )r  r0   r   r<   r¡  r<   r1   rk   )r   r<   r¡  r<   r1   rk   )r  r0   rB   r0   r1   rk   )r  r0   r1   r0   )r  r0   r1   rk   rÚ   r•  r”  r×   )rÎ   rÛ   rÜ   rÝ   rs   rf  ró   r—  r—   r¶  r´  r¤   rµ   r«   r¹   rÂ   r½   r»  rÕ   Úurllibr(  r,   r›  rš  r7   r7   r7   r8   r*   7  s0    

	ûü







r*   )r/   r0   r1   r2   rl   )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ä   rc  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   Ú
_multipartr   Ú_status_codesr   Ú_typesr   r   r   r   r    r!   r"   r#   r$   r%   r&   Ú_urlsr'   Ú_utilsr(   r)   Ú__all__re   r9   rA   rE   rN   r_   rh   ÚMutableMappingr0   r+   r,   r-   r*   r7   r7   r7   r8   Ú<module>   sH    ($
	4



%	 t     8