o
    )if?                     @  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
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-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= G dd dej>e?e?f Z@G dd dZAG dd dZBG dd dej>e?e?f ZCd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)is_known_encodingnormalize_header_keynormalize_header_valueobfuscate_sensitive_headersparse_content_type_charsetparse_header_linksc                   @  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 )WHeadersz9
    HTTP headers, as a case-insensitive multi-dict.
    NheadersHeaderTypes | Noneencoding
str | NonereturnNonec                   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                   4   g | ]\}}t |d  dt |d dt| fqS F)lowerr1   Tr)   r*   .0kvr1    F/var/www/html/corbot_env/lib/python3.10/site-packages/httpx/_models.py
<listcomp>H       z$Headers.__init__.<locals>.<listcomp>c                   r5   r6   r8   r9   r=   r>   r?   r@   Q   rA   )_list
isinstancer.   listr   items	_encoding)selfr/   r1   r>   r=   r?   __init__>   s   




	
	zHeaders.__init__strc              
   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-8z
iso-8859-1)rF   rawdecodeUnicodeDecodeError)rG   r1   keyvaluer>   r>   r?   r1   \   s   

	zHeaders.encodingrP   c                 C  
   || _ d S N)rF   rG   rP   r>   r>   r?   r1   u      
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 r>   r>   )r:   raw_key_rP   r>   r>   r?   r@   ~       zHeaders.raw.<locals>.<listcomp>rB   rG   r>   r>   r?   rL   y   s   zHeaders.rawtyping.KeysView[str]c                   s    fdd j D  S )Nc                   s    i | ]\}}}|  jd qS rR   rM   r1   r:   rX   rO   rP   r[   r>   r?   
<dictcomp>   s     z Headers.keys.<locals>.<dictcomp>)rB   keysr[   r>   r[   r?   r`      s   zHeaders.keystyping.ValuesView[str]c                 C  ^   i }| j D ]%\}}}|| j}|| j}||v r&||  d| 7  < q|||< q| S )N, )rB   rM   r1   valuesrG   values_dictrX   rO   rP   str_key	str_valuer>   r>   r?   rd      s   
zHeaders.valuestyping.ItemsView[str, str]c                 C  rb   )z
        Return `(key, value)` items of headers. Concatenate headers
        into a single comma separated value when a key occurs multiple times.
        rc   )rB   rM   r1   rE   re   r>   r>   r?   rE      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 r>   r]   r^   r[   r>   r?   r@      s    z'Headers.multi_items.<locals>.<listcomp>rZ   r[   r>   r[   r?   multi_items   s   
zHeaders.multi_itemsrO   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)rG   rO   rl   r>   r>   r?   get   s
   
zHeaders.getFsplit_commasbool	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 r>   )r7   rM   r1   )r:   rX   item_key
item_valueget_header_keyrG   r>   r?   r@      s
    
z$Headers.get_list.<locals>.<listcomp>c                 S  s   g | ]}|  qS r>   )strip)r:   itemr>   r>   r?   r@      s    ,)r7   encoder1   rB   extendsplit)rG   rO   rp   rd   split_valuesrP   r>   ru   r?   get_list   s   zHeaders.get_listc                 C  s:   t |}| D ]}|| v r| | q| j|j d S rR   )r.   r`   poprB   r{   )rG   r/   rO   r>   r>   r?   update   s   
zHeaders.updatec                 C  s   t | | jdS )Nr=   )r.   r1   r[   r>   r>   r?   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 r>   r]   )r:   rX   
header_keyheader_valuenormalized_keyrG   r>   r?   r@      s
    
z'Headers.__getitem__.<locals>.<listcomp>rc   )r7   rz   r1   rB   joinrn   )rG   rO   rE   r>   r   r?   __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.
        rK   c                   s"   g | ]\}\}}}| kr|qS r>   r>   r:   idxrX   rs   
lookup_keyr>   r?   r@      s
    z'Headers.__setitem__.<locals>.<listcomp>r   Nr   )rz   rF   r7   	enumeraterB   reversedappend)rG   rO   rP   set_key	set_valuefound_indexesr   r>   r   r?   __setitem__   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 r>   )r7   r   del_keyr>   r?   r@     s
    z'Headers.__delitem__.<locals>.<listcomp>N)r7   rz   r1   r   rB   rn   r   )rG   rO   pop_indexesr   r>   r   r?   __delitem__   s   

zHeaders.__delitem__c                 C  s$   |  | j}|dd | jD v S )Nc                 S  s   g | ]\}}}|qS r>   r>   )r:   rX   rO   r>   r>   r?   r@     s    z(Headers.__contains__.<locals>.<listcomp>)r7   rz   r1   rB   )rG   rO   r   r>   r>   r?   __contains__  s   zHeaders.__contains__typing.Iterator[typing.Any]c                 C  s   t |  S rR   )iterr`   r[   r>   r>   r?   __iter__     zHeaders.__iter__intc                 C  
   t | jS rR   )lenrB   r[   r>   r>   r?   __len__     
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 r>   r>   r^   r>   r>   r?   r@      rY   z"Headers.__eq__.<locals>.<listcomp>c                 S  r   r>   r>   r^   r>   r>   r?   r@   !  rY   )r.   
ValueErrorrB   sorted)rG   r   other_headers	self_list
other_listr>   r>   r?   __eq__  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 )N rJ   z, encoding=())	__class____name__r1   rD   r+   rk   dictr   )rG   
class_nameencoding_stras_listas_dictno_duplicate_keysr>   r>   r?   __repr__$  s   
zHeaders.__repr__NN)r/   r0   r1   r2   r3   r4   r3   rI   rP   rI   r3   r4   )r3   rU   )r3   r\   )r3   ra   )r3   ri   )r3   rj   rR   )rO   rI   rl   rm   r3   rm   )F)rO   rI   rp   rq   r3   rr   )r/   r0   r3   r4   )r3   r.   )rO   rI   r3   rI   rO   rI   rP   rI   r3   r4   )rO   rI   r3   r4   )rO   rm   r3   rq   )r3   r   r3   r   )r   rm   r3   rq   )r   
__module____qualname____doc__rH   propertyr1   setterrL   r`   rd   rE   rk   ro   r~   r   r   r   r   r   r   r   r   r   r   r>   r>   r>   r?   r.   9   s6    













r.   c                
   @  sv   e Zd Zdddddddddd	d1ddZd2dd Zed3d"d#Zd3d$d%Zd3d&d'Zd4d)d*Z	d5d,d-Z
d6d/d0ZdS )7RequestN)	paramsr/   cookiescontentdatafilesjsonstream
extensionsmethodstr | bytesurl	URL | strr   QueryParamTypes | Noner/   r0   r   CookieTypes | Noner   RequestContent | Noner   RequestData | Noner   RequestFiles | Noner   typing.Any | Noner   'SyncByteStream | AsyncByteStream | Noner   RequestExtensions | Noner3   r4   c       	      	   C  s   t |tr|d n| | _t|| _|d ur"| jj|d| _t|| _	|d u r-i n|| _
|r9t||  |
d u ro| j	d}t||||	t|rR|| j	jnd dd\}}
| | |
| _t |
trm|   d S d S |
| _d S )NrJ   )r   zcontent-type)content_type)r   r   r   r   boundary)rC   bytesrM   upperr   r'   r   copy_merge_paramsr.   r/   r   Cookiesset_cookie_headerro   r	   r   rz   r1   _preparer   r   read)rG   r   r   r   r/   r   r   r   r   r   r   r   r   r>   r>   r?   rH   5  s<   





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)rE   r7   r/   
setdefaultr   hostr   netlocr   r.   rL   )rG   r   rO   rP   auto_headershas_hosthas_content_lengthr>   r>   r?   r   u  s   

zRequest._preparer   c                 C     t | dst | jS N_content)hasattrr   r   r[   r>   r>   r?   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   rC   r   typingIterabler   r   r   r[   r>   r>   r?   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 rR   r>   r:   partr>   r>   r?   r@         z!Request.aread.<locals>.<listcomp>N)r   rC   r   r   AsyncIterabler   r   r   r[   r>   r>   r?   aread  s   
zRequest.areadrI   c                 C  s,   | j j}t| j}d| d| jd|dS )N<r   rc   z)>)r   r   rI   r   r   )rG   r   r   r>   r>   r?   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   r>   r:   namerP   r>   r>   r?   r_     
    z(Request.__getstate__.<locals>.<dictcomp>__dict__rE   r[   r>   r>   r?   __getstate__     zRequest.__getstate__statec                 C  s0   |  D ]
\}}t| || qi | _t | _d S rR   )rE   setattrr   r   r   rG   r  r   rP   r>   r>   r?   __setstate__  s   zRequest.__setstate__)r   r   r   r   r   r   r/   r0   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r4   r   r   r3   r4   r3   r   r   r3   r   r  r   r3   r4   )r   r   r   rH   r   r   r   r   r   r   r  r  r>   r>   r>   r?   r   4  s&    
@



r   c                   @  s8  e Zd Zddddddddddd
dddZddd Zedd"d#Zejdd%d#Zedd'd(Zejdd*d(Zedd,d-Z	edd.d/Z
edd1d2Zedd4d5Zedd6d7Zedd8d9Zejdd:d9Zedd;d<Zdd>d?ZeddAdBZeddCdDZeddEdFZeddGdHZeddIdJZeddKdLZeddMdNZddOdPZddRdSZeddUdVZeddXdYZeddZd[Zdd\d]Zdd_d`ZddbdcZddddeZ dddidjZ!dddldmZ"ddndoZ#dddpdqZ$ddrdsZ%ddtduZ&	dddwdxZ'	dddzd{Z(dd|d}Z)	ddd~dZ*dddZ+dS )ResponseNrK   )
r/   r   texthtmlr   r   requestr   historydefault_encodingstatus_coder   r/   r0   r   ResponseContent | Noner  r2   r  r   rm   r   r   r  Request | Noner   ResponseExtensions | Noner  list[Response] | Noner  #str | typing.Callable[[bytes], str]r3   r4   c       
         C  s   || _ t|| _|| _d | _|	d u ri n|	| _|
d u rg nt|
| _d| _d| _	|| _
|d u rJt||||\}}| | || _t|trI|   n|| _d| _d S )NFr   )r  r.   r/   _requestnext_requestr   rD   r  	is_closedis_stream_consumedr  r
   r   r   rC   r   r   _num_bytes_downloaded)rG   r  r/   r   r  r  r   r   r  r   r  r  r>   r>   r?   rH     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)rE   r7   r/   r   )rG   r   rO   rP   r>   r>   r?   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   RuntimeErrorr  r[   r>   r>   r?   elapsed  s
   
zResponse.elapsedr!  c                 C  rQ   rR   )r  )rG   r!  r>   r>   r?   r!    rT   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[   r>   r>   r?   r    s
   
zResponse.requestrP   c                 C  rQ   rR   )r  rS   r>   r>   r?   r    rT   rI   c                 C  s2   z| j d }W n
 ty   Y dS w |jdddS )Nhttp_versionzHTTP/1.1rJ   ignoreerrors)r   rn   rM   )rG   r"  r>   r>   r?   r"    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_phraserJ   r#  r$  )r   rn   r   get_reason_phraser  rM   )rG   r&  r>   r>   r?   r&  '  s   zResponse.reason_phraser'   c                 C  s   | j jS )zA
        Returns the URL for which the request was made.
        )r  r   r[   r>   r>   r?   r   0  s   zResponse.urlr   c                 C  r   r   )r   r   r   r[   r>   r>   r?   r   7  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_textr   rK   r=   )r   r   r(  r   r1   r   rM   flush)rG   r   decoderr>   r>   r?   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.
        rF   Nr   rK   )r   charset_encodingr(   rC   r  rI   r   rF   )rG   r1   r>   r>   r?   r1   H  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   r   rF   rS   r>   r>   r?   r1   ^  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)r/   ro   r,   )rG   r   r>   r>   r?   r+  l  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)rp   r   r   )children)r   r/   r~   rw   r7   r   r   rn   r   r,  r   r   )rG   decodersrd   rP   decoder_clsr>   r>   r?   _get_content_decoderw  s&   

zResponse._get_content_decoderrq   c                 C     t | jS )zU
        A property which is `True` for 1xx status codes, `False` otherwise.
        )r   is_informationalr  r[   r>   r>   r?   r2       zResponse.is_informationalc                 C  r1  )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   
is_successr  r[   r>   r>   r?   r4    r3  zResponse.is_successc                 C  r1  )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[   r>   r>   r?   r5    s   
zResponse.is_redirectc                 C  r1  )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        )r   is_client_errorr  r[   r>   r>   r?   r6    r3  zResponse.is_client_errorc                 C  r1  )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        )r   is_server_errorr  r[   r>   r>   r?   r7    r3  zResponse.is_server_errorc                 C  r1  )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        )r   is_errorr  r[   r>   r>   r?   r8    r3  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_REDIRECTr/   r[   r>   r>   r?   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   r4  r?  r  ro   formatr   )rG   r  messagestatus_classerror_typesrD  r>   r>   r?   raise_for_status  s*   
zResponse.raise_for_statuskwargsc                 K  s   t j| jfi |S rR   )jsonlibloadsr   )rG   rK  r>   r>   r?   r     s   zResponse.jsonr   c                 C  s$   t | dst | _| j|  | jS )N_cookies)r   r   rN  extract_cookiesr[   r>   r>   r?   r     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
        linkNc                 S  s"   i | ]}| d p| d|qS )relr   )ro   )r:   rQ  r>   r>   r?   r_     s    z"Response.links.<locals>.<dictcomp>)r/   ro   r-   )rG   headerr>   r>   r?   links  s   zResponse.linksc                 C  s   | j S rR   )r  r[   r>   r>   r?   num_bytes_downloaded  s   zResponse.num_bytes_downloadedc                 C  s   d| j  d| j dS )Nz<Response [ ]>)r  r&  r[   r>   r>   r?   r     s   zResponse.__repr__r   c                 C  r   )Nc                 S  r   ))r   r   r  r,  r>   r   r>   r>   r?   r_     r   z)Response.__getstate__.<locals>.<dictcomp>r  r[   r>   r>   r?   r    r  zResponse.__getstate__r  c                 C  s6   |  D ]
\}}t| || qd| _i | _t | _d S )NT)rE   r  r  r   r   r   r  r>   r>   r?   r  !  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[   r>   r>   r?   r   (  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, and brotli encoded responses.
        r   Nr   r   rZ  r  )r   r   r   rangemaxr0  r   r   r  iter_rawrM   r)  rG   rZ  ir*  chunker	raw_bytesdecodedchunkr>   r>   r?   rY  0  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.
        rK   r=   r^  r_  N)r   r1   r   r   r  rY  rM   r)  rG   rZ  r*  re  byte_contenttext_contentrh  r>   r>   r?   	iter_textG  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 Nr_  )r   r   r  rn  rM   r)  rG   r*  r  liner>   r>   r?   
iter_linesZ  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   r^  r_  N)r  r   r  r   rC   r   r&   r   r  r   r   r  r   rM   r)  closerG   rZ  re  raw_stream_bytesrh  r>   r>   r?   rb  c  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.Tr_  N)rC   r   r&   r   r  r   r  rt  r[   r>   r>   r?   rt  }  s   "zResponse.closec                   s2   t | dsddd |  2 I dH | _| jS )rX  r   r   c                   r   rR   r>   r   r>   r>   r?   r@     r   z"Response.aread.<locals>.<listcomp>N)r   r   aiter_bytesr   r[   r>   r>   r?   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 r]  )r   r   r   r`  ra  r0  r   r   r  	aiter_rawrM   r)  rc  r>   r>   r?   rx    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 rj  )r   r1   r   r   r  rx  rM   r)  rk  r>   r>   r?   
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 ro  )r   r   r  r|  rM   r)  rp  r>   r>   r?   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 )rs  z6Attempted to call an async iterator on an sync stream.Tr   r^  r_  N)r  r   r  r   rC   r   r   r   r  r   r   r  r   rM   r)  acloseru  r>   r>   r?   rz    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 )rw  z3Attempted to call an async close on an sync stream.Tr_  N)rC   r   r   r   r  r   r  r~  r[   r>   r>   r?   r~    s   "zResponse.aclose)r  r   r/   r0   r   r  r  r2   r  r2   r   rm   r   r   r  r  r   r  r  r  r  r  r3   r4   r	  )r3   r  )r!  r  r3   r4   )r3   r   )rP   r   r3   r4   r   )r3   r'   r
  )r3   r2   r   )r3   r   r3   rq   )r3   r  )rK  rm   r3   rm   )r3   r   )r3   rP  r   r  r  rR   )rZ  r[  r3   r\  )rZ  r[  r3   ri  r3   ri  )r3   r4   )rZ  r[  r3   ry  )rZ  r[  r3   r{  )r3   r{  ),r   r   r   rH   r   r   r!  r   r  r"  r&  r   r   r  r1   r+  r0  r2  r4  r5  r6  r7  r8  r?  rJ  r   r   rT  rU  r   r  r  r   rY  rn  rr  rb  rt  r   rx  r|  r}  rz  r~  r>   r>   r>   r?   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   r3   r4   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 rR   )	rC   r   r   jarrE   setrD   r   
set_cookie)rG   r   rO   rP   cookier>   r>   r?   rH     s$   




zCookies.__init__rE  r  c                 C  s(   |  |}| |j}| j|| dS )zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)_CookieCompatResponse_CookieCompatRequestr  r  rO  )rG   rE  urllib_responseurllib_requestr>   r>   r?   rO  	  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)rG   r  r  r>   r>   r?   r     s   
zCookies.set_cookie_headerr   /r   rI   rP   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   rP   portNport_specifiedFr  domain_specifieddomain_initial_dot.r  path_specifiedsecureexpiresdiscardTcommentcomment_urlrestHttpOnlyrfc2109r>   )rq   
startswithr   r  r  )rG   r   rP   r  r  rK  r  r>   r>   r?   r    sJ   
	
zCookies.setrl   r2   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   rP   )rG   r   rl   r  r  rP   r  rG  r>   r>   r?   ro   3  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 rR   )r   r  r  r:   r  r  r   r  r>   r?   r@   Y  s    
z"Cookies.delete.<locals>.<listcomp>)r  clearr  r  r   )rG   r   r  r  remover  r>   r  r?   deleteL  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   r  r  )rG   r  r  argsr>   r>   r?   r  d  s   

zCookies.clearc                 C  s$   t |}|jD ]}| j| qd S rR   )r   r  r  )rG   r   r  r>   r>   r?   r   q  s   
zCookies.updatec                 C  s   |  ||S rR   )r  rG   r   rP   r>   r>   r?   r   v  r   zCookies.__setitem__c                 C  s   |  |}|d u rt||S rR   )ro   rn   r  r>   r>   r?   r   y  s   
zCookies.__getitem__c                 C  s
   |  |S rR   )r  )rG   r   r>   r>   r?   r     r   zCookies.__delitem__r   c                 C  r   rR   )r   r  r[   r>   r>   r?   r     r   zCookies.__len__ri  c                 C  rV   )Nc                 s  s    | ]}|j V  qd S rR   )r   r  r>   r>   r?   	<genexpr>  s    z#Cookies.__iter__.<locals>.<genexpr>r  r[   r>   r>   r?   r     s   zCookies.__iter__rq   c                 C  s   | j D ]} dS dS )NTFr  )rG   rX   r>   r>   r?   __bool__  s   
zCookies.__bool__c                 C  s"   d dd | jD }d| dS )Nrc   c              	   S  s*   g | ]}d |j  d|j d|j dqS )z<Cookie =z for z />)r   rP   r  r  r>   r>   r?   r@     s    z$Cookies.__repr__.<locals>.<listcomp>z	<Cookies[rW  )r   r  )rG   cookies_reprr>   r>   r?   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   r3   r4   c                   s*   t  jt|jt|j|jd || _d S )N)r   r/   r   )superrH   rI   r   r   r/   r   r  )rG   r  r   r>   r?   rH     s   
z%Cookies._CookieCompatRequest.__init__rO   rI   rP   c                   s   t  || || jj|< d S rR   )r  add_unredirected_headerr  r/   )rG   rO   rP   r  r>   r?   r    s   z4Cookies._CookieCompatRequest.add_unredirected_headerr  r   r3   r4   r   )r   r   r   r   rH   r  __classcell__r>   r>   r  r?   r    s    r  c                   @  s$   e Zd ZdZdddZdd	d
ZdS )zCookies._CookieCompatResponser  rE  r  r3   r4   c                 C  rQ   rR   )rE  )rG   rE  r>   r>   r?   rH     r   z&Cookies._CookieCompatResponse.__init__email.message.Messagec                 C  s,   t j }| jj D ]\}}|||< q|S rR   )emailrG  MessagerE  r/   rk   )rG   inforO   rP   r>   r>   r?   r    s   

z"Cookies._CookieCompatResponse.infoNrE  r  r3   r4   )r3   r  )r   r   r   r   rH   r  r>   r>   r>   r?   r    s    
r  rR   )r   r   r3   r4   r  r  )r   r  )
r   rI   rP   rI   r  rI   r  rI   r3   r4   )NNN)
r   rI   rl   r2   r  r2   r  r2   r3   r2   r   )r   rI   r  r2   r  r2   r3   r4   )r  r2   r  r2   r3   r4   )r   rI   rP   rI   r3   r4   )r   rI   r3   rI   )r   rI   r3   r4   r   r  r  r   )r   r   r   r   rH   rO  r   r  ro   r  r  r   r   r   r   r   r   r  r   urllibr  r   r  r  r>   r>   r>   r?   r     s0    

	







r   )D
__future__r   datetimeemail.messager  r   rL  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)   r*   r+   r,   r-   MutableMappingrI   r.   r   r  r   r>   r>   r>   r?   <module>   s4    ($
	4 
 |     8