o
    Rh                     @  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Z>G dd dej?e@e@f ZAG dd dZBG dd dZCG dd dej?e@e@f ZDd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_links)CookiesHeadersRequestResponsec                   @  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 | 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)lowerr4   Tr)   r*   .0kvr4    O/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/httpx/_models.py
<listcomp>J       z$Headers.__init__.<locals>.<listcomp>c                   r8   r9   r;   r<   r@   rA   rB   rC   S   rD   )_list
isinstancer/   listr   items	_encoding)selfr2   r4   rA   r@   rB   __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)rI   rawdecodeUnicodeDecodeError)rJ   r4   keyvaluerA   rA   rB   r4   ^   s   

	zHeaders.encodingrS   c                 C  
   || _ d S N)rI   rJ   rS   rA   rA   rB   r4   w      
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 rA   rA   )r=   raw_key_rS   rA   rA   rB   rC          zHeaders.raw.<locals>.<listcomp>rE   rJ   rA   rA   rB   rO   {   s   zHeaders.rawtyping.KeysView[str]c                   s    fdd j D  S )Nc                   s    i | ]\}}}|  jd qS rU   rP   r4   r=   r[   rR   rS   r^   rA   rB   
<dictcomp>   s     z Headers.keys.<locals>.<dictcomp>)rE   keysr^   rA   r^   rB   rc      s   zHeaders.keystyping.ValuesView[str]c                 C  ^   i }| j D ]%\}}}|| j}|| j}||v r&||  d| 7  < q|||< q| S )N, )rE   rP   r4   valuesrJ   values_dictr[   rR   rS   str_key	str_valuerA   rA   rB   rg      s   
zHeaders.valuestyping.ItemsView[str, str]c                 C  re   )z
        Return `(key, value)` items of headers. Concatenate headers
        into a single comma separated value when a key occurs multiple times.
        rf   )rE   rP   r4   rH   rh   rA   rA   rB   rH      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 rA   r`   ra   r^   rA   rB   rC      s    z'Headers.multi_items.<locals>.<listcomp>r]   r^   rA   r^   rB   multi_items   s   
zHeaders.multi_itemsrR   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)rJ   rR   ro   rA   rA   rB   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 rA   )r:   rP   r4   )r=   r[   item_key
item_valueget_header_keyrJ   rA   rB   rC      s
    
z$Headers.get_list.<locals>.<listcomp>c                 S  s   g | ]}|  qS rA   )strip)r=   itemrA   rA   rB   rC      s    ,)r:   encoder4   rE   extendsplit)rJ   rR   rs   rg   split_valuesrS   rA   rx   rB   get_list   s   zHeaders.get_listc                 C  s:   t |}| D ]}|| v r| | q| j|j d S rU   )r/   rc   poprE   r~   )rJ   r2   rR   rA   rA   rB   update   s   
zHeaders.updatec                 C  s   t | | jdS )Nr@   )r/   r4   r^   rA   rA   rB   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 rA   r`   )r=   r[   
header_keyheader_valuenormalized_keyrJ   rA   rB   rC      s
    
z'Headers.__getitem__.<locals>.<listcomp>rf   )r:   r}   r4   rE   joinrq   )rJ   rR   rH   rA   r   rB   __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.
        rN   c                   s"   g | ]\}\}}}| kr|qS rA   rA   r=   idxr[   rv   
lookup_keyrA   rB   rC      s
    z'Headers.__setitem__.<locals>.<listcomp>r   Nr   )r}   rI   r:   	enumeraterE   reversedappend)rJ   rR   rS   set_key	set_valuefound_indexesr   rA   r   rB   __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 rA   )r:   r   del_keyrA   rB   rC     s
    z'Headers.__delitem__.<locals>.<listcomp>N)r:   r}   r4   r   rE   rq   r   )rJ   rR   pop_indexesr   rA   r   rB   __delitem__   s   

zHeaders.__delitem__c                 C  s$   |  | j}|dd | jD v S )Nc                 S  s   g | ]\}}}|qS rA   rA   )r=   r[   rR   rA   rA   rB   rC     s    z(Headers.__contains__.<locals>.<listcomp>)r:   r}   r4   rE   )rJ   rR   r   rA   rA   rB   __contains__  s   zHeaders.__contains__typing.Iterator[typing.Any]c                 C  s   t |  S rU   )iterrc   r^   rA   rA   rB   __iter__     zHeaders.__iter__intc                 C  
   t | jS rU   )lenrE   r^   rA   rA   rB   __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 rA   rA   ra   rA   rA   rB   rC   "  r\   z"Headers.__eq__.<locals>.<listcomp>c                 S  r   rA   rA   ra   rA   rA   rB   rC   #  r\   )r/   
ValueErrorrE   sorted)rJ   r   other_headers	self_list
other_listrA   rA   rB   __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 rM   z, encoding=())	__class____name__r4   rG   r+   rn   dictr   )rJ   
class_nameencoding_stras_listas_dictno_duplicate_keysrA   rA   rB   __repr__&  s   
zHeaders.__repr__NN)r2   r3   r4   r5   r6   r7   r6   rL   rS   rL   r6   r7   )r6   rX   )r6   r_   )r6   rd   )r6   rl   )r6   rm   rU   )rR   rL   ro   rp   r6   rp   )F)rR   rL   rs   rt   r6   ru   )r2   r3   r6   r7   )r6   r/   )rR   rL   r6   rL   rR   rL   rS   rL   r6   r7   )rR   rL   r6   r7   )rR   rp   r6   rt   )r6   r   r6   r   )r   rp   r6   rt   )r   
__module____qualname____doc__rK   propertyr4   setterrO   rc   rg   rH   rn   rr   r   r   r   r   r   r   r   r   r   r   r   rA   rA   rA   rB   r/   ;   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 )7r0   N)	paramsr2   cookiescontentdatafilesjsonstream
extensionsmethodstr | bytesurl	URL | strr   QueryParamTypes | Noner2   r3   r   CookieTypes | Noner   RequestContent | Noner   RequestData | Noner   RequestFiles | Noner   typing.Any | Noner   'SyncByteStream | AsyncByteStream | Noner   RequestExtensions | Noner6   r7   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 )NrM   )r   zcontent-type)content_type)r   r   r   r   boundary)rF   bytesrP   upperr   r'   r   copy_merge_paramsr/   r2   r   r.   set_cookie_headerrr   r	   r   r}   r4   _preparer   r   read)rJ   r   r   r   r2   r   r   r   r   r   r   r   r   rA   rA   rB   rK   7  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)rH   r:   r2   
setdefaultr   hostr   netlocr   r/   rO   )rJ   r   rR   rS   auto_headershas_hosthas_content_lengthrA   rA   rB   r   w  s   

zRequest._preparer   c                 C     t | dst | jS N_content)hasattrr   r   r^   rA   rA   rB   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   rF   r   typingIterabler   r   r   r^   rA   rA   rB   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 rU   rA   r=   partrA   rA   rB   rC         z!Request.aread.<locals>.<listcomp>N)r   rF   r   r   AsyncIterabler   r   r   r^   rA   rA   rB   aread  s   
zRequest.areadrL   c                 C  s,   | j j}t| j}d| d| jd|dS )N<r   rf   z)>)r   r   rL   r   r   )rJ   r   r   rA   rA   rB   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   rA   r=   namerS   rA   rA   rB   rb     
    z(Request.__getstate__.<locals>.<dictcomp>__dict__rH   r^   rA   rA   rB   __getstate__     zRequest.__getstate__statec                 C  s0   |  D ]
\}}t| || qi | _t | _d S rU   )rH   setattrr   r   r   rJ   r  r   rS   rA   rA   rB   __setstate__  s   zRequest.__setstate__)r   r   r   r   r   r   r2   r3   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r7   r   r   r6   r7   r6   r   r   r6   r   r  r   r6   r7   )r   r   r   rK   r   r   r   r   r   r   r  r	  rA   rA   rA   rB   r0   6  s&    
@



r0   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 )r1   NrN   )
r2   r   texthtmlr   r   requestr   historydefault_encodingstatus_coder   r2   r3   r   ResponseContent | Noner  r5   r  r   rp   r   r   r  Request | Noner   ResponseExtensions | Noner  list[Response] | Noner  #str | typing.Callable[[bytes], str]r6   r7   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/   r2   _requestnext_requestr   rG   r  	is_closedis_stream_consumedr  r
   r   r   rF   r   r   _num_bytes_downloaded)rJ   r  r2   r   r  r  r   r   r  r   r  r  rA   rA   rB   rK     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)rH   r:   r2   r   )rJ   r   rR   rS   rA   rA   rB   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^   rA   rA   rB   elapsed   s
   
zResponse.elapsedr!  c                 C  rT   rU   )r  )rJ   r!  rA   rA   rB   r!    rW   r0   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^   rA   rA   rB   r    s
   
zResponse.requestrS   c                 C  rT   rU   )r  rV   rA   rA   rB   r    rW   rL   c                 C  s2   z| j d }W n
 ty   Y dS w |jdddS )Nhttp_versionzHTTP/1.1rM   ignoreerrors)r   rq   rP   )rJ   r"  rA   rA   rB   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_phraserM   r#  r$  )r   rq   r   get_reason_phraser  rP   )rJ   r&  rA   rA   rB   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^   rA   rA   rB   r   2  s   zResponse.urlr   c                 C  r   r   )r   r   r   r^   rA   rA   rB   r   9  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   rN   r@   )r   r   r(  r   r4   r   rP   flush)rJ   r   decoderrA   rA   rB   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.
        rI   Nr   rN   )r   charset_encodingr(   rF   r  rL   r   rI   )rJ   r4   rA   rA   rB   r4   J  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   rI   rV   rA   rA   rB   r4   `  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)r2   rr   r,   )rJ   r   rA   rA   rB   r+  n  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)rs   r   r   )children)r   r2   r   rz   r:   r   r   rq   r   r,  r   r   )rJ   decodersrg   rS   decoder_clsrA   rA   rB   _get_content_decodery  s&   

zResponse._get_content_decoderrt   c                 C     t | jS )zU
        A property which is `True` for 1xx status codes, `False` otherwise.
        )r   is_informationalr  r^   rA   rA   rB   r2       zResponse.is_informationalc                 C  r1  )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   
is_successr  r^   rA   rA   rB   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^   rA   rA   rB   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^   rA   rA   rB   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^   rA   rA   rB   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^   rA   rA   rB   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_REDIRECTr2   r^   rA   rA   rB   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  rr   formatr   )rJ   r  messagestatus_classerror_typesrD  rA   rA   rB   raise_for_status  s*   
zResponse.raise_for_statuskwargsc                 K  s   t j| jfi |S rU   )jsonlibloadsr   )rJ   rK  rA   rA   rB   r     s   zResponse.jsonr.   c                 C  s$   t | dst | _| j|  | jS )N_cookies)r   r.   rN  extract_cookiesr^   rA   rA   rB   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   )rr   )r=   rQ  rA   rA   rB   rb     s    z"Response.links.<locals>.<dictcomp>)r2   rr   r-   )rJ   headerrA   rA   rB   links  s   zResponse.linksc                 C  s   | j S rU   )r  r^   rA   rA   rB   num_bytes_downloaded  s   zResponse.num_bytes_downloadedc                 C  s   d| j  d| j dS )Nz<Response [ ]>)r  r&  r^   rA   rA   rB   r     s   zResponse.__repr__r   c                 C  r   )Nc                 S  r   ))r   r   r  r,  rA   r   rA   rA   rB   rb     r  z)Response.__getstate__.<locals>.<dictcomp>r  r^   rA   rA   rB   r    r  zResponse.__getstate__r  c                 C  s6   |  D ]
\}}t| || qd| _i | _t | _d S )NT)rH   r  r  r   r   r   r  rA   rA   rB   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^   rA   rA   rB   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, brotli, and zstd encoded responses.
        r   Nr   r   rZ  r  )r   r   r   rangemaxr0  r   r   r  iter_rawrP   r)  rJ   rZ  ir*  chunker	raw_bytesdecodedchunkrA   rA   rB   rY  2  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.
        rN   r@   r^  r_  N)r   r4   r   r   r  rY  rP   r)  rJ   rZ  r*  re  byte_contenttext_contentrh  rA   rA   rB   	iter_textI  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  rP   r)  rJ   r*  r  linerA   rA   rB   
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   r^  r_  N)r  r   r  r   rF   r   r&   r   r  r   r   r  r   rP   r)  closerJ   rZ  re  raw_stream_bytesrh  rA   rA   rB   rb  e  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)rF   r   r&   r   r  r   r  rt  r^   rA   rA   rB   rt    s   "zResponse.closec                   s2   t | dsddd |  2 I dH | _| jS )rX  r   r   c                   r   rU   rA   r   rA   rA   rB   rC     r   z"Response.aread.<locals>.<listcomp>N)r   r   aiter_bytesr   r^   rA   rA   rB   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_rawrP   r)  rc  rA   rA   rB   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   r4   r   r   r  rx  rP   r)  rk  rA   rA   rB   
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|  rP   r)  rp  rA   rA   rB   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   rF   r   r   r   r  r   r   r  r   rP   r)  acloseru  rA   rA   rB   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)rF   r   r   r   r  r   r  r~  r^   rA   rA   rB   r~    s   "zResponse.aclose)r  r   r2   r3   r   r  r  r5   r  r5   r   rp   r   r   r  r  r   r  r  r  r  r  r6   r7   r
  )r6   r  )r!  r  r6   r7   )r6   r0   )rS   r0   r6   r7   r   )r6   r'   r  )r6   r5   r   )r6   r   r6   rt   )r6   r1   )rK  rp   r6   rp   )r6   r.   )r6   rP  r   r  r  rU   )rZ  r[  r6   r\  )rZ  r[  r6   ri  r6   ri  )r6   r7   )rZ  r[  r6   ry  )rZ  r[  r6   r{  )r6   r{  ),r   r   r   rK   r   r   r!  r   r  r"  r&  r   r   r  r4   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~  rA   rA   rA   rB   r1     s    
7





%




	

	

r1   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   r6   r7   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 rU   )	rF   r   r   jarrH   setrG   r.   
set_cookie)rJ   r   rR   rS   cookierA   rA   rB   rK     s$   




zCookies.__init__rE  r1   c                 C  s(   |  |}| |j}| j|| dS )zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)_CookieCompatResponse_CookieCompatRequestr  r  rO  )rJ   rE  urllib_responseurllib_requestrA   rA   rB   rO    s   
zCookies.extract_cookiesr  r0   c                 C  s   |  |}| j| dS )zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)r  r  add_cookie_header)rJ   r  r  rA   rA   rB   r     s   
zCookies.set_cookie_headerr   /r   rL   rS   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   rS   portNport_specifiedFr  domain_specifieddomain_initial_dot.r  path_specifiedsecureexpiresdiscardTcommentcomment_urlrestHttpOnlyrfc2109rA   )rt   
startswithr   r  r  )rJ   r   rS   r  r  rK  r  rA   rA   rB   r    sJ   
	
zCookies.setro   r5   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   rS   )rJ   r   ro   r  r  rS   r  rG  rA   rA   rB   rr   5  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 rU   )r   r  r  r=   r  r  r   r  rA   rB   rC   [  s    
z"Cookies.delete.<locals>.<listcomp>)r  clearr  r  r   )rJ   r   r  r  remover  rA   r  rB   deleteN  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  )rJ   r  r  argsrA   rA   rB   r  f  s   

zCookies.clearc                 C  s$   t |}|jD ]}| j| qd S rU   )r.   r  r  )rJ   r   r  rA   rA   rB   r   s  s   
zCookies.updatec                 C  s   |  ||S rU   )r  rJ   r   rS   rA   rA   rB   r   x  r   zCookies.__setitem__c                 C  s   |  |}|d u rt||S rU   )rr   rq   r  rA   rA   rB   r   {  s   
zCookies.__getitem__c                 C  s
   |  |S rU   )r  )rJ   r   rA   rA   rB   r     r   zCookies.__delitem__r   c                 C  r   rU   )r   r  r^   rA   rA   rB   r     r   zCookies.__len__ri  c                 C  rY   )Nc                 s  s    | ]}|j V  qd S rU   )r   r  rA   rA   rB   	<genexpr>  s    z#Cookies.__iter__.<locals>.<genexpr>r  r^   rA   rA   rB   r     s   zCookies.__iter__rt   c                 C  s   | j D ]} dS dS )NTFr  )rJ   r[   rA   rA   rB   __bool__  s   
zCookies.__bool__c                 C  s"   d dd | jD }d| dS )Nrf   c              	   S  s*   g | ]}d |j  d|j d|j dqS )z<Cookie =z for z />)r   rS   r  r  rA   rA   rB   rC     s    z$Cookies.__repr__.<locals>.<listcomp>z	<Cookies[rW  )r   r  )rJ   cookies_reprrA   rA   rB   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  r0   r6   r7   c                   s*   t  jt|jt|j|jd || _d S )N)r   r2   r   )superrK   rL   r   r   r2   r   r  )rJ   r  r   rA   rB   rK     s   
z%Cookies._CookieCompatRequest.__init__rR   rL   rS   c                   s   t  || || jj|< d S rU   )r  add_unredirected_headerr  r2   )rJ   rR   rS   r  rA   rB   r    s   z4Cookies._CookieCompatRequest.add_unredirected_headerr  r0   r6   r7   r   )r   r   r   r   rK   r  __classcell__rA   rA   r  rB   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  r1   r6   r7   c                 C  rT   rU   )rE  )rJ   rE  rA   rA   rB   rK     r   z&Cookies._CookieCompatResponse.__init__email.message.Messagec                 C  s,   t j }| jj D ]\}}|||< q|S rU   )emailrG  MessagerE  r2   rn   )rJ   inforR   rS   rA   rA   rB   r    s   

z"Cookies._CookieCompatResponse.infoNrE  r1   r6   r7   )r6   r  )r   r   r   r   rK   r  rA   rA   rA   rB   r    s    
r  rU   )r   r   r6   r7   r  r  )r   r  )
r   rL   rS   rL   r  rL   r  rL   r6   r7   )NNN)
r   rL   ro   r5   r  r5   r  r5   r6   r5   r   )r   rL   r  r5   r  r5   r6   r7   )r  r5   r  r5   r6   r7   )r   rL   rS   rL   r6   r7   )r   rL   r6   rL   )r   rL   r6   r7   r   r  r  r   )r   r   r   r   rK   rO  r   r  rr   r  r  r   r   r   r   r   r   r  r   urllibr  r0   r  r  rA   rA   rA   rB   r.     s0    

	







r.   )E
__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-   __all__MutableMappingrL   r/   r0   r1   r.   rA   rA   rA   rB   <module>   s6    ($
	4 	 |     8