a
    !f                     @   st  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-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; G dd dej<e=e=f Z>G dd dZ?G dd dZ@G dd dej<e=e=f ZAdS )    N)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d4eje eje ddddZe	edddZ
e
jedd	d
dZ
e	ejejeef  dddZeje dddZeje dddZejeef dddZejejeef  dddZd5eejejdddZd6eeeje dddZd7eje ddddZd ddd Zeed!d"d#Zeedd$d%d&Zedd!d'd(Zejed!d)d*Z ej!ej dd+d,Z"e#dd-d.Z$ejed/d0d1Z%edd2d3Z&dS )8Headersz9
    HTTP headers, as a case-insensitive multi-dict.
    N)headersencodingreturnc                    sj   |d u rg | _ nPt|tr(t|j | _ n8t|trL fdd| D | _ n fdd|D | _  | _d S )Nc                    s4   g | ],\}}t |d  dt |d dt| fqS F)lowerr/   Tr(   r)   .0kvr/    N/var/www/html/python-backend/venv/lib/python3.9/site-packages/httpx/_models.py
<listcomp>F   s
   z$Headers.__init__.<locals>.<listcomp>c                    s4   g | ],\}}t |d  dt |d dt| fqS r1   r3   r4   r8   r9   r:   r;   O   s
   )_list
isinstancer-   listr   items	_encoding)selfr.   r/   r9   r8   r:   __init__<   s    



	
	zHeaders.__init__r0   c              
   C   sl   | j du rfdD ]P}| jD ]:\}}z|| || W q tyP   Y  qY q0 q|| _  qfq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)r@   rawdecodeUnicodeDecodeError)rA   r/   keyvaluer9   r9   r:   r/   Z   s    

zHeaders.encodingrJ   r0   c                 C   s
   || _ d S N)r@   rA   rJ   r9   r9   r:   r/   s   s    c                 C   s   dd | j D S )zH
        Returns a list of the raw header items, as byte pairs.
        c                 S   s   g | ]\}}}||fqS r9   r9   )r5   Zraw_key_rJ   r9   r9   r:   r;   |       zHeaders.raw.<locals>.<listcomp>r<   rA   r9   r9   r:   rF   w   s    zHeaders.rawc                    s    fdd j D  S )Nc                    s    i | ]\}}}|  jd qS rL   rG   r/   r5   rN   rI   rJ   rQ   r9   r:   
<dictcomp>   rO   z Headers.keys.<locals>.<dictcomp>)r<   keysrQ   r9   rQ   r:   rU   ~   s    zHeaders.keysc                 C   s^   i }| j D ]J\}}}|| j}|| j}||v rL||  d| 7  < q
|||< q
| S )N, )r<   rG   r/   valuesrA   Zvalues_dictrN   rI   rJ   Zstr_keyZ	str_valuer9   r9   r:   rW      s    
zHeaders.valuesc                 C   s^   i }| j D ]J\}}}|| j}|| j}||v rL||  d| 7  < q
|||< q
| S )z
        Return `(key, value)` items of headers. Concatenate headers
        into a single comma separated value when a key occurs multiple times.
        rV   )r<   rG   r/   r?   rX   r9   r9   r:   r?      s    
zHeaders.itemsc                    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 r9   rR   rS   rQ   r9   r:   r;      s   z'Headers.multi_items.<locals>.<listcomp>rP   rQ   r9   rQ   r:   multi_items   s    
zHeaders.multi_items)rI   defaultr0   c                 C   s&   z
| | W S  t y    | Y S 0 dS )z
        Return a header value. If multiple occurrences of the header occur
        then concatenate them together with commas.
        N)KeyError)rA   rI   rZ   r9   r9   r:   get   s    
zHeaders.getF)rI   split_commasr0   c                    sZ   |  j  fddjD }|s.|S g }|D ]}|dd |dD  q6|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 r9   )r2   rG   r/   )r5   rN   item_keyZ
item_valueZget_header_keyrA   r9   r:   r;      s   z$Headers.get_list.<locals>.<listcomp>c                 S   s   g | ]}|  qS r9   )strip)r5   itemr9   r9   r:   r;      rO   ,)r2   encoder/   r<   extendsplit)rA   rI   r]   rW   Zsplit_valuesrJ   r9   r_   r:   get_list   s    zHeaders.get_list)r.   r0   c                 C   s:   t |}| D ]}|| v r| | q| j|j d S rL   )r-   rU   popr<   rd   )rA   r.   rI   r9   r9   r:   update   s
    zHeaders.updatec                 C   s   t | | jdS )Nr8   )r-   r/   rQ   r9   r9   r:   copy   s    zHeaders.copy)rI   r0   c                    s@   |  j  fddjD }|r4d|S t|dS )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 r9   rR   )r5   rN   
header_keyheader_valueZnormalized_keyrA   r9   r:   r;      s   z'Headers.__getitem__.<locals>.<listcomp>rV   N)r2   rc   r/   r<   joinr[   )rA   rI   r?   r9   rl   r:   __getitem__   s    
zHeaders.__getitem__rI   rJ   r0   c                    s   | | jpd}| | jpd}|   fddt| jD }t|dd D ]}| j|= qP|r||d }| |f| j|< n| j| |f dS )zs
        Set the header `key` to `value`, removing any duplicate entries.
        Retains insertion order.
        rE   c                    s"   g | ]\}\}}}| kr|qS r9   r9   r5   idxrN   r^   Z
lookup_keyr9   r:   r;      s   z'Headers.__setitem__.<locals>.<listcomp>r   Nr   )rc   r@   r2   	enumerater<   reversedappend)rA   rI   rJ   Zset_key	set_valueZfound_indexesrq   r9   rr   r:   __setitem__   s    

zHeaders.__setitem__c                    sN   |  | j  fddt| jD }|s4t|t|D ]}| j|= q<dS )z*
        Remove the header `key`.
        c                    s&   g | ]\}\}}}|   kr|qS r9   )r2   rp   Zdel_keyr9   r:   r;     s   z'Headers.__delitem__.<locals>.<listcomp>N)r2   rc   r/   rs   r<   r[   rt   )rA   rI   Zpop_indexesrq   r9   rx   r:   __delitem__   s    
zHeaders.__delitem__c                 C   s$   |  | j}|dd | jD v S )Nc                 S   s   g | ]\}}}|qS r9   r9   )r5   rN   rI   r9   r9   r:   r;     rO   z(Headers.__contains__.<locals>.<listcomp>)r2   rc   r/   r<   )rA   rI   rj   r9   r9   r:   __contains__  s    zHeaders.__contains__c                 C   s   t |  S rL   )iterrU   rQ   r9   r9   r:   __iter__  s    zHeaders.__iter__c                 C   s
   t | jS rL   )lenr<   rQ   r9   r9   r:   __len__  s    zHeaders.__len__)otherr0   c                 C   sR   zt |}W n ty    Y dS 0 dd | jD }dd |jD }t|t|kS )NFc                 S   s   g | ]\}}}||fqS r9   r9   rS   r9   r9   r:   r;     rO   z"Headers.__eq__.<locals>.<listcomp>c                 S   s   g | ]\}}}||fqS r9   r9   rS   r9   r9   r:   r;     rO   )r-   
ValueErrorr<   sorted)rA   r   Zother_headersZ	self_listZ
other_listr9   r9   r:   __eq__  s    zHeaders.__eq__c                 C   sv   | j j}d}| jdkr"d| j}tt|  }t|}t|t|k}|rb| d|| dS | d|| dS )N rD   z, encoding=())	__class____name__r/   r>   r*   rY   dictr}   )rA   
class_nameZencoding_stras_listas_dictZno_duplicate_keysr9   r9   r:   __repr__"  s    
zHeaders.__repr__)NN)N)F)N)'r   
__module____qualname____doc__typingOptionalr   strrB   propertyr/   setterListTuplebytesrF   KeysViewrU   
ValuesViewrW   	ItemsViewr?   rY   Anyr\   boolrf   rh   ri   rn   rw   ry   rz   Iteratorr|   intr~   r   r   r9   r9   r9   r:   r-   7   s<      

r-   c                   @   s$  e Zd Zdddddddddd	ejeef ejdef eje eje	 eje
 eje eje eje ejej ejeedf eje ddddZejeef dddd	Zeed
ddZed
ddZed
ddZed
ddZejeejf d
ddZejeejf ddddZdS )RequestN)	paramsr.   cookiescontentdatafilesjsonstream
extensionsr&   )methodurlr   r.   r   r   r   r   r   r   r   r0   c       	      	   C   s   t |tr|d n| | _t|| _|d urD| jj|d| _t|| _	|d u rZi n|| _
|rrt||  |
d u r| j	d}t||||	t|r|| j	jnd dd\}}
| | |
| _t |
tr|   n|
| _d S )NrD   )r   zcontent-type)content_type)r   r   r   r   boundary)r=   r   rG   upperr   r&   r   Zcopy_merge_paramsr-   r.   r   Cookiesset_cookie_headerr\   r   r   rc   r/   _preparer   r   read)rA   r   r   r   r.   r   r   r   r   r   r   r   r   r9   r9   r:   rB   3  s:    





zRequest.__init__default_headersr0   c                 C   s   |  D ].\}}| dkr(d| jv r(q| j|| qg }d| jv }d| jv pXd| jv }|sx| jjrx|d| jjf |s| jdv r|d t	|| jj
 | _d S )Ntransfer-encodingzContent-LengthHostzTransfer-Encodings   Host)POSTPUTPATCH)s   Content-Length   0)r?   r2   r.   
setdefaultr   hostru   netlocr   r-   rF   )rA   r   rI   rJ   Zauto_headersZhas_hostZhas_content_lengthr9   r9   r:   r   r  s    

zRequest._preparerC   c                 C   s   t | dst | jS N_content)hasattrr   r   rQ   r9   r9   r:   r     s    
zRequest.contentc                 C   sH   t | dsBt| jtjsJ d| j| _t| jtsBt| j| _| jS )6
        Read and return the request content.
        r   rO   )r   r=   r   r   Iterablerm   r   r   rQ   r9   r9   r:   r     s    
zRequest.readc                    sX   t | dsRt| jtjsJ ddd | j2 I dH | _t| jtsRt| j| _| jS )r   r   rO   c                    s   g | z3 d H W }|q6 S rL   r9   r5   partr9   r9   r:   r;     rO   z!Request.aread.<locals>.<listcomp>N)r   r=   r   r   AsyncIterablerm   r   r   rQ   r9   r9   r:   aread  s    
zRequest.areadc                 C   s,   | j j}t| j}d| d| jd|dS )N<r   rV   z)>)r   r   r   r   r   )rA   r   r   r9   r9   r:   r     s    
zRequest.__repr__c                 C   s   dd | j  D S )Nc                 S   s   i | ]\}}|d vr||qS ))r   r   r9   r5   namerJ   r9   r9   r:   rT     s   z(Request.__getstate__.<locals>.<dictcomp>__dict__r?   rQ   r9   r9   r:   __getstate__  s    zRequest.__getstate__stater0   c                 C   s0   |  D ]\}}t| || qi | _t | _d S rL   )r?   setattrr   r   r   rA   r   r   rJ   r9   r9   r:   __setstate__  s    zRequest.__setstate__)r   r   r   r   Unionr   r   r   r   r   r   r   r    r"   r   r%   r   r!   rB   Dictr   r   r   r   r   r   r   r   r9   r9   r9   r:   r   2  s>   
?r   c                   @   s   e Zd Zddddddddddd
eeje eje eje eje ej	ej
eedf eje eje ejejd   ej
eejegef f ddddZejeef dddd	Zeejd
ddZejejddddZeed
ddZejeddddZeed
ddZeed
ddZeed
ddZeed
ddZeed
ddZ eeje d
ddZ!e!jeddddZ!eeje d
d d!Z"e#d
d"d#Z$ee%d
d$d%Z&ee%d
d&d'Z'ee%d
d(d)Z(ee%d
d*d+Z)ee%d
d,d-Z*ee%d
d.d/Z+ee%d
d0d1Z,d d
d2d3Z-ej	ej	d4d5d6Z.ed7d
d8d9Z/eejeje ejeef f d
d:d;Z0eed
d<d=Z1ed
d>d?Z2ejeej	f d
d@dAZ3ejeej	f ddBdCdDZ4ed
dEdFZ5d^eje ej6e dGdHdIZ7d_eje ej6e dGdJdKZ8ej6e d
dLdMZ9d`eje ej6e dGdNdOZ:dd
dPdQZ;ed
dRdSZ<daeje ej=e dGdTdUZ>dbeje ej=e dGdVdWZ?ej=e d
dXdYZ@dceje ej=e dGdZd[ZAdd
d\d]ZBdS )dResponseNrE   )
r.   r   texthtmlr   r   requestr   historydefault_encoding)status_coder.   r   r   r   r   r   r   r   r   r   r0   c       
         C   s   || _ t|| _|| _d | _|	d u r(i n|	| _|
d u r:g nt|
| _d| _d| _	|| _
|d u rt||||\}}| | || _t|tr|   n|| _d| _d S )NFr   )r   r-   r.   _requestZnext_requestr   r>   r   	is_closedis_stream_consumedr   r	   r   r   r=   r   r   _num_bytes_downloaded)rA   r   r.   r   r   r   r   r   r   r   r   r   r9   r9   r:   rB     s"    



zResponse.__init__r   c                 C   s<   |  D ].\}}| dkr(d| jv r(q| j|| qd S )Nr   zcontent-length)r?   r2   r.   r   )rA   r   rI   rJ   r9   r9   r:   r     s    zResponse._preparerC   c                 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   rQ   r9   r9   r:   elapsed  s
    
zResponse.elapsed)r   r0   c                 C   s
   || _ d S rL   )r   )rA   r   r9   r9   r:   r     s    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   rQ   r9   r9   r:   r     s
    
zResponse.requestrK   c                 C   s
   || _ d S rL   )r   rM   r9   r9   r:   r     s    c                 C   s6   z| j d }W n ty"   Y dS 0 |jdddS d S )Nhttp_versionzHTTP/1.1rD   ignoreerrors)r   r[   rG   )rA   r   r9   r9   r:   r     s
    zResponse.http_versionc                 C   s@   z| j d }W n ty,   t| j Y S 0 |jdddS d S )Nreason_phraserD   r   r   )r   r[   r   Zget_reason_phraser   rG   )rA   r   r9   r9   r:   r   $  s
    zResponse.reason_phrasec                 C   s   | j jS )zA
        Returns the URL for which the request was made.
        )r   r   rQ   r9   r9   r:   r   -  s    zResponse.urlc                 C   s   t | dst | jS r   )r   r   r   rQ   r9   r9   r:   r   4  s    
zResponse.contentc                 C   sN   t | dsH| j}|sd| _n,t| jp&dd}d|| j| g| _| jS )N_textr   rE   r8   )r   r   r   r   r/   rm   rG   flush)rA   r   decoderr9   r9   r:   r   :  s    
zResponse.textc                 C   sZ   t | dsT| j}|du s t|sJt| jtr4| j}nt | drJ| | j}|pPd| _| 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.
        r@   Nr   rE   )r   charset_encodingr'   r=   r   r   r   r@   )rA   r/   r9   r9   r:   r/   E  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   r@   rM   r9   r9   r:   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)r.   r\   r+   )rA   r   r9   r9   r:   r   i  s    zResponse.charset_encodingc              	   C   s   t | dsg }| jjddd}|D ]@}|  }zt| }||  W q" ty`   Y q"Y q"0 q"t|dkr||d | _	n"t|dkrt
|d| _	n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   r.   rf   r`   r2   r
   ru   r[   r}   r   r   r   )rA   ZdecodersrW   rJ   Zdecoder_clsr9   r9   r:   _get_content_decodert  s     
zResponse._get_content_decoderc                 C   s   t | jS )zU
        A property which is `True` for 1xx status codes, `False` otherwise.
        )r   is_informationalr   rQ   r9   r9   r:   r     s    zResponse.is_informationalc                 C   s   t | jS )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   
is_successr   rQ   r9   r9   r:   r     s    zResponse.is_successc                 C   s   t | jS )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   rQ   r9   r9   r:   r     s    
zResponse.is_redirectc                 C   s   t | jS )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        )r   is_client_errorr   rQ   r9   r9   r:   r     s    zResponse.is_client_errorc                 C   s   t | jS )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        )r   is_server_errorr   rQ   r9   r9   r:   r     s    zResponse.is_server_errorc                 C   s   t | jS )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        )r   is_errorr   rQ   r9   r9   r:   r     s    zResponse.is_errorc                 C   s(   | j tjtjtjtjtjfv o&d| jv S )zs
        Returns True for 3xx responses with a properly formed URL redirection,
        `False` otherwise.
        ZLocation)r   r   MOVED_PERMANENTLYFOUND	SEE_OTHERTEMPORARY_REDIRECTPERMANENT_REDIRECTr.   rQ   r9   r9   r:   has_redirect_location  s    zResponse.has_redirect_locationc                 C   st   | 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dS )z>
        Raise the `HTTPStatusError` if one occurred.
        NzYCannot call `raise_for_status` as the request instance has not been set on this response.z{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
Redirect location: '{0.headers[location]}'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}z{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}d   zInformational responsezRedirect responsezClient errorzServer error)r            zInvalid status code)
error_type)r   response)r   r   r   r   r   r\   formatr   )rA   r   messageZstatus_classZerror_typesr   r9   r9   r:   raise_for_status  s*    
zResponse.raise_for_status)kwargsr0   c                 K   s   t j| jfi |S rL   )jsonlibloadsr   )rA   r  r9   r9   r:   r     s    zResponse.jsonr   c                 C   s$   t | dst | _| j|  | jS )N_cookies)r   r   r  extract_cookiesrQ   r9   r9   r:   r     s    
zResponse.cookiesc                 C   sF   | j d}i }|rBt|}|D ] }|dp6|d}|||< q |S )zI
        Returns the parsed header links of the response, if any
        linkrelr   )r.   r\   r,   )rA   headerZldictlinksr  rI   r9   r9   r:   r	    s    
zResponse.linksc                 C   s   | j S rL   )r   rQ   r9   r9   r:   num_bytes_downloaded  s    zResponse.num_bytes_downloadedc                 C   s   d| j  d| j dS )Nz<Response [ ]>)r   r   rQ   r9   r9   r:   r     s    zResponse.__repr__c                 C   s   dd | j  D S )Nc                 S   s   i | ]\}}|d vr||qS ))r   r   r   r   r9   r   r9   r9   r:   rT     s   z)Response.__getstate__.<locals>.<dictcomp>r   rQ   r9   r9   r:   r     s    zResponse.__getstate__r   c                 C   s6   |  D ]\}}t| || qd| _i | _t | _d S )NT)r?   r   r   r   r   r   r   r9   r9   r:   r     s
    zResponse.__setstate__c                 C   s    t | dsd|  | _| jS )7
        Read and return the response content.
        r   rO   )r   rm   
iter_bytesr   rQ   r9   r9   r:   r   %  s    
zResponse.read)
chunk_sizer0   c                 c   s   t | drT|du rt| jn|}tdt| jt|dD ]}| j|||  V  q8n|  }t|d}t| jdp | 	 D ]$}|
|}|
|D ]
}|V  qq|| }|
|D ]
}|V  q| D ]
}|V  qW d   n1 s0    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   r  r   )r   r}   r   rangemaxr   r   r   r   iter_rawrG   r   rA   r  ir   chunkerZ	raw_bytesdecodedchunkr9   r9   r:   r  -  s     



zResponse.iter_bytesc                 c   s   t | jp
dd}t|d}t| jdp |  D ]$}||}||D ]
}|V  qHq0| }||D ]
}|V  qh| D ]
}|V  q|W d   n1 s0    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.
        rE   r8   r  r  N)r   r/   r   r   r   r  rG   r   rA   r  r   r  Zbyte_contentZtext_contentr  r9   r9   r:   	iter_textF  s    


zResponse.iter_textc                 c   sn   t  }t| jdH |  D ]}||D ]
}|V  q*q| D ]
}|V  q@W d    n1 s`0    Y  d S Nr  )r   r   r   r  rG   r   rA   r   r   liner9   r9   r:   
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D | jD ],}|  jt|7  _||D ]
}|V  qvqVW d   n1 s0    Y  | D ]
}|V  q|   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   r=   r   r%   r   r   r   r   r   r}   rG   r   closerA   r  r  Zraw_stream_bytesr  r9   r9   r:   r  d  s"    

(zResponse.iter_rawc                 C   sZ   t | jtstd| jsVd| _t| jd | j  W d   n1 sL0    Y  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)r=   r   r%   r   r   r   r   r#  rQ   r9   r9   r:   r#    s    zResponse.closec                    s0   t | ds*ddd |  2 I dH | _| jS )r  r   rO   c                    s   g | z3 d H W }|q6 S rL   r9   r   r9   r9   r:   r;     rO   z"Response.aread.<locals>.<listcomp>N)r   rm   aiter_bytesr   rQ   r9   r9   r:   r     s    
 zResponse.areadc                 C  s   t | drT|du rt| jn|}tdt| jt|dD ]}| j|||  V  q8n|  }t|d}t| jdz | 	 2 z,3 dH W }|
|}|
|D ]
}|V  qq|6 | }|
|D ]
}|V  q| D ]
}|V  qW d   n1 s0    Y  dS r  )r   r}   r   r  r  r   r   r   r   	aiter_rawrG   r   r  r9   r9   r:   r&    s     


zResponse.aiter_bytesc                 C  s   t | jp
dd}t|d}t| jdz |  2 z,3 dH W }||}||D ]
}|V  qPq06 | }||D ]
}|V  qr| D ]
}|V  qW d   n1 s0    Y  dS r  )r   r/   r   r   r   r&  rG   r   r  r9   r9   r:   
aiter_text  s    

zResponse.aiter_textc                 C  sx   t  }t| jdR |  2 z"3 d H W }||D ]
}|V  q2q6 | D ]
}|V  qJW d    n1 sj0    Y  d S r  )r   r   r   r(  rG   r   r  r9   r9   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N | j2 z43 dH W }|  jt|7  _||D ]
}|V  q~qV6 W d   n1 s0    Y  | D ]
}|V  q|  I dH  dS )r"  z6Attempted to call an async iterator on an sync stream.Tr   r  r  N)r   r   r   r   r=   r   r   r   r   r   r   r   r}   rG   r   acloser$  r9   r9   r:   r'    s"    
*zResponse.aiter_rawc                    s`   t | jtstd| js\d| _t| jd  | j I dH  W d   n1 sR0    Y  dS )r%  z3Attempted to call an async close on an sync stream.Tr  N)r=   r   r   r   r   r   r   r*  rQ   r9   r9   r:   r*    s    zResponse.aclose)N)N)N)N)N)N)Cr   r   r   r   r   r   r   r#   r   r   r   r%   r   r   r$   r   Callabler   rB   r   r   r   datetime	timedeltar   r   r   r   r   r&   r   r   r   r/   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r
  r   r   r   r   r   r  r  r!  r  r#  r   AsyncIteratorr&  r(  r)  r'  r*  r9   r9   r9   r:   r     s   7


%*	  
 	  
 r   c                   @   s|  e Zd ZdZd1eje ddddZeddddZ	e
dd	d
dZd2eeeeddddZd3eeje eje eje eje dddZd4eeje eje ddddZd5eje eje ddddZd6eje ddddZeeddddZeedd d!Zeddd"d#Zed$d%d&Zeje d$d'd(Zed$d)d*Zed$d+d,ZG d-d. d.ejj
ZG d/d0 d0ZdS )7r   z-
    HTTP Cookies, as a mutable mapping.
    N)r   r0   c                 C   s   |d u st |trDt | _t |tr| D ]\}}| || q,n`t |trrt | _|D ]\}}| || qZn2t |trt | _|jD ]}| j| qn|| _d S rL   )	r=   r   r   jarr?   setr>   r   
set_cookie)rA   r   rI   rJ   cookier9   r9   r:   rB     s    



zCookies.__init__r   r0   c                 C   s(   |  |}| |j}| j|| dS )zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)_CookieCompatResponse_CookieCompatRequestr   r/  r  )rA   r   Zurllib_responseurllib_requestr9   r9   r:   r    s    
zCookies.extract_cookiesr   r0   c                 C   s   |  |}| j| dS )zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)r5  r/  add_cookie_header)rA   r   r6  r9   r9   r:   r     s    
zCookies.set_cookie_headerr   /)r   rJ   domainpathr0   c                 C   sX   d||dd|t ||d|t |dddddddidd}tf i |}| j| dS )zU
        Set a cookie value by name. May optionally include domain and path.
        r   NF.THttpOnly)versionr   rJ   portport_specifiedr:  domain_specifieddomain_initial_dotr;  path_specifiedsecureexpiresdiscardcommentcomment_urlrestrfc2109)r   
startswithr   r/  r1  )rA   r   rJ   r:  r;  r  r2  r9   r9   r:   r0    s(    zCookies.set)r   rZ   r:  r;  r0   c                 C   sn   d}| j D ]R}|j|kr
|du s*|j|kr
|du s<|j|kr
|durVd| }t||j}q
|du rj|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   rJ   )rA   r   rZ   r:  r;  rJ   r2  r   r9   r9   r:   r\   6  s    


zCookies.get)r   r:  r;  r0   c                    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 | ]6}|j kr d u s$|j krd u s6|jkr|qS rL   )r   r:  r;  r5   r2  r:  r   r;  r9   r:   r;   \  s
   
z"Cookies.delete.<locals>.<listcomp>)r/  clearr:  r;  r   )rA   r   r:  r;  remover2  r9   rM  r:   deleteO  s    
zCookies.delete)r:  r;  r0   c                 C   sD   g }|dur| | |dur4|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)ru   r/  rN  )rA   r:  r;  argsr9   r9   r:   rN  g  s    

zCookies.clearc                 C   s$   t |}|jD ]}| j| qd S rL   )r   r/  r1  )rA   r   r2  r9   r9   r:   rh   v  s    
zCookies.update)r   rJ   r0   c                 C   s   |  ||S rL   )r0  rA   r   rJ   r9   r9   r:   rw   {  s    zCookies.__setitem__)r   r0   c                 C   s   |  |}|d u rt||S rL   )r\   r[   rR  r9   r9   r:   rn   ~  s    
zCookies.__getitem__c                 C   s
   |  |S rL   )rP  )rA   r   r9   r9   r:   ry     s    zCookies.__delitem__rC   c                 C   s
   t | jS rL   )r}   r/  rQ   r9   r9   r:   r~     s    zCookies.__len__c                 C   s   dd | j D S )Nc                 s   s   | ]}|j V  qd S rL   )r   rL  r9   r9   r:   	<genexpr>  rO   z#Cookies.__iter__.<locals>.<genexpr>r/  rQ   r9   r9   r:   r|     s    zCookies.__iter__c                 C   s   | j D ]} dS dS )NTFrT  )rA   rN   r9   r9   r:   __bool__  s    
zCookies.__bool__c                 C   s"   d dd | jD }d| dS )NrV   c              	   S   s*   g | ]"}d |j  d|j d|j dqS )z<Cookie =z for z />)r   rJ   r:  rL  r9   r9   r:   r;     s   z$Cookies.__repr__.<locals>.<listcomp>z	<Cookies[r  )rm   r/  )rA   Zcookies_reprr9   r9   r:   r     s    zCookies.__repr__c                       s>   e Zd ZdZedd fddZeed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.
        Nr7  c                    s*   t  jt|jt|j|jd || _d S )N)r   r.   r   )superrB   r   r   r   r.   r   r   )rA   r   r   r9   r:   rB     s    z%Cookies._CookieCompatRequest.__init__ro   c                    s   t  || || jj|< d S rL   )rX  add_unredirected_headerr   r.   )rA   rI   rJ   rY  r9   r:   rZ    s    z4Cookies._CookieCompatRequest.add_unredirected_header)	r   r   r   r   r   rB   r   rZ  __classcell__r9   r9   rY  r:   r5    s   r5  c                   @   s2   e Zd ZdZeddddZejjdddZ	dS )	zCookies._CookieCompatResponserW  Nr3  c                 C   s
   || _ d S rL   )r   )rA   r   r9   r9   r:   rB     s    z&Cookies._CookieCompatResponse.__init__rC   c                 C   s,   t j }| jj D ]\}}|||< q|S rL   )emailr   Messager   r.   rY   )rA   inforI   rJ   r9   r9   r:   r^    s    

z"Cookies._CookieCompatResponse.info)
r   r   r   r   r   rB   r\  r   r]  r^  r9   r9   r9   r:   r4    s   r4  )N)r   r9  )NNN)NN)NN)N) r   r   r   r   r   r   r   rB   r   r  r   r   r   r0  r\   rP  rN  rh   rw   rn   ry   r   r~   r   r|   r   rU  r   urllibr   r5  r4  r9   r9   r9   r:   r     sL   	      
r   )Br,  email.messager\  r   r  r   urllib.requestr_  collections.abcr   http.cookiejarr   r   r   r   r   r   r	   	_decodersr
   r   r   r   r   r   r   r   _exceptionsr   r   r   r   r   r   r   Z
_multipartr   Z_status_codesr   _typesr   r   r   r   r   r    r!   r"   r#   r$   r%   Z_urlsr&   _utilsr'   r(   r)   r*   r+   r,   MutableMappingr   r-   r   r   r   r9   r9   r9   r:   <module>   s0   (
$	4 
 |     >