o �J�h���@s�ddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddlmZmZddlmZmZmZmZddlmZmZmZmZmZmZmZmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&dd l'm(Z(dd l)m*Z*dd l+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6dd l7m8Z8dd l9m:Z:m;Z;gd�Z<ddhZ=d3dd�Z>d4d5dd�Z?d4d6dd�Z@d7d!d"�ZAd8d$d%�ZBd9d)d*�ZCGd+d,�d,e jDeEeEf�ZFGd-d.�d.�ZGGd/d0�d0�ZHGd1d2�d2e jDeEeEf�ZIdS):�)� annotationsN)�Mapping)�Cookie� CookieJar�)� ByteStream�UnattachedStream�encode_request�encode_response)�SUPPORTED_DECODERS� ByteChunker�ContentDecoder�IdentityDecoder� LineDecoder� MultiDecoder� TextChunker� TextDecoder)�CookieConflict�HTTPStatusError�RequestNotRead�ResponseNotRead� StreamClosed�StreamConsumed�request_context)�(get_multipart_boundary_from_content_type)�codes) �AsyncByteStream� CookieTypes� HeaderTypes�QueryParamTypes�RequestContent� RequestData�RequestExtensions� RequestFiles�ResponseContent�ResponseExtensions�SyncByteStream)�URL)�to_bytes_or_str�to_str)�Cookies�Headers�Request�ResponseZ authorizationzproxy-authorization�encoding�str�return�boolcCs&zt�|�WdStyYdSw)z7 Return `True` if `encoding` is a known codec. FT)�codecs�lookup� LookupError�r.�r6�KC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\httpx\_models.py�_is_known_encoding8s   ��r8�key� str | bytes� str | None�bytescCst|t�r|S|�|p d�S)zE Coerce str/bytes into a strictly byte-wise HTTP header key. �ascii)� isinstancer<�encode)r9r.r6r6r7�_normalize_header_keyCsr@�valuecCs8t|t�r|St|t�stdt|�����|�|pd�S)zG Coerce str/bytes into a strictly byte-wise HTTP header value. z'Header value must be str or bytes, not r=)r>r<r/� TypeError�typer?)rAr.r6r6r7�_normalize_header_valueJs  rD� content_typecCstj��}||d<|jdd�S)N� content-type)�failobj)�email�message�Message�get_content_charset)rE�msgr6r6r7�_parse_content_type_charsetUs  rM�list[dict[str, str]]c Cs�g}d}|�|�}|s |St�d|�D]M}z |�dd�\}}Wnty-|d}}Ynwd|�d�i}|�d�D] }z |�d�\}}Wn tyOYn w|�|�||�|�<q:|�|�q|S) a7 Returns a list of parsed link headers, for more info see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link The generic syntax of those is: Link: < uri-reference >; param1=value1; param2="value2" So for instance: Link; '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;' would return [ {"url": "http:/.../front.jpeg", "type": "image/jpeg"}, {"url": "http://.../back.jpeg"}, ] :param value: HTTP Link entity-header field :return: list of parsed link headers z '"z, *<�;r��urlz<> '"�=)�strip�re�split� ValueError�append) rA�linksZ replace_chars�valrQ�params�link�paramr9r6r6r7�_parse_header_links]s*  � � r]�items�4typing.Iterable[tuple[typing.AnyStr, typing.AnyStr]]�4typing.Iterator[tuple[typing.AnyStr, typing.AnyStr]]ccs:�|D]\}}t|���tvrtd|d�}||fVqdS)Nz[secure])Z match_type_of)r)�lower�SENSITIVE_HEADERSr()r^�k�vr6r6r7�_obfuscate_sensitive_headers�s �   �rec@s�eZdZdZ  dAdBd d �ZedCd d ��ZejdDdd ��ZedEdd��ZdFdd�Z dGdd�Z dHdd�Z dIdd�Z dJdKd"d#�Z dLdMd(d)�ZdJdNd*d+�ZdOd,d-�ZdPd.d/�ZdQd0d1�ZdRd2d3�ZdSd4d5�ZdTd7d8�ZdUd:d;�ZdVd=d>�ZdCd?d@�ZdS)Wr+z9 HTTP headers, as a case-insensitive multi-dict. N�headers�HeaderTypes | Noner.r;r0�NonecCs�g|_t|t�rt|j�|_nDt|t�r3|��D]\}}t||�}t||�}|j�||� �|f�qn |durS|D]\}}t||�}t||�}|j�||� �|f�q9||_ dS�N) �_listr>r+�listrr^r@rDrWra� _encoding)�selfrfr.rcrdZ bytes_keyZ bytes_valuer6r6r7�__init__�s    �    zHeaders.__init__r/c Csj|jdur2dD]'}|jD]\}}z |�|�|�|�Wq ty&Ynw||_|jSqd|_|jS)zn Header encoding is mandated as ascii, but we allow fallbacks to utf-8 or iso-8859-1. N)r=�utf-8z iso-8859-1)rl�raw�decode�UnicodeDecodeError)rmr.r9rAr6r6r7r.�s   �� zHeaders.encodingrAcC� ||_dSri)rl�rmrAr6r6r7r.�� �list[tuple[bytes, bytes]]cC�dd�|jD�S)zH Returns a list of the raw header items, as byte pairs. cSsg|] \}}}||f�qSr6r6)�.0Zraw_key�_rAr6r6r7� <listcomp>��zHeaders.raw.<locals>.<listcomp>�rj�rmr6r6r7rp�sz Headers.raw�typing.KeysView[str]cs�fdd��jD���S)Ncs i|] \}}}|��j�d�qSri�rqr.�rxryr9rAr}r6r7� <dictcomp>�s z Headers.keys.<locals>.<dictcomp>)rj�keysr}r6r}r7r��sz Headers.keys�typing.ValuesView[str]cC�^i}|jD]%\}}}|�|j�}|�|j�}||vr&||d|��7<q|||<q|��S)N�, )rjrqr.�values�rmZ values_dictryr9rAZstr_keyZ str_valuer6r6r7r��s   zHeaders.values�typing.ItemsView[str, str]cCr�)z� Return `(key, value)` items of headers. Concatenate headers into a single comma separated value when a key occurs multiple times. r�)rjrqr.r^r�r6r6r7r^�s   z Headers.items�list[tuple[str, str]]cs�fdd��jD�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. cs*g|]\}}}|��j�|��j�f�qSr6rr�r}r6r7rz�s��z'Headers.multi_items.<locals>.<listcomp>r|r}r6r}r7� multi_items�s �zHeaders.multi_itemsr9�default� typing.AnycCs"z||WSty|YSw)z� Return a header value. If multiple occurrences of the header occur then concatenate them together with commas. )�KeyError)rmr9r�r6r6r7�get�s   �z Headers.getF� split_commasr1� list[str]csZ|����j����fdd��jD�}|s|Sg}|D]}|�dd�|�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. cs*g|]\}}}|���kr|��j��qSr6)rarqr.)rxry�item_keyZ item_value�Zget_header_keyrmr6r7rzs   �z$Headers.get_list.<locals>.<listcomp>cSsg|]}|���qSr6)rS)rx�itemr6r6r7rzs�,)rar?r.rj�extendrU)rmr9r�r�Z split_valuesrAr6r�r7�get_list�s �zHeaders.get_listcCs:t|�}|��D] }||vr|�|�q|j�|j�dSri)r+r��poprjr�)rmrfr9r6r6r7�updates   �zHeaders.updatecCst||jd�S)Nr5)r+r.r}r6r6r7�copysz Headers.copycs<|����j����fdd��jD�}|rd�|�St|��)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 cs&g|]\}}}|�kr|��j��qSr6r)rxry� header_key� header_value�Znormalized_keyrmr6r7rz%s  �z'Headers.__getitem__.<locals>.<listcomp>r�)rar?r.rj�joinr�)rmr9r^r6r�r7� __getitem__s � zHeaders.__getitem__cs�|�|jpd�}|�|jpd�}|����fdd�t|j�D�}t|dd��D]}|j|=q(|r?|d}|�|f|j|<dS|j�|�|f�dS)zs Set the header `key` to `value`, removing any duplicate entries. Retains insertion order. rocs"g|] \}\}}}|�kr|�qSr6r6�rx�idxryr��Z lookup_keyr6r7rz9s  �z'Headers.__setitem__.<locals>.<listcomp>rNr)r?rlra� enumeraterj�reversedrW)rmr9rAZset_keyZ set_valueZ found_indexesr�r6r�r7� __setitem__0s � zHeaders.__setitem__csN|���|j���fdd�t|j�D�}|st|��t|�D]}|j|=qdS)z* Remove the header `key`. cs&g|]\}\}}}|���kr|�qSr6)rar��Zdel_keyr6r7rzNs   �z'Headers.__delitem__.<locals>.<listcomp>N)rar?r.r�rjr�r�)rmr9Z pop_indexesr�r6r�r7� __delitem__Hs �  �zHeaders.__delitem__cCs$|���|j�}|dd�|jD�vS)NcSsg|]\}}}|�qSr6r6)rxryr9r6r6r7rz\sz(Headers.__contains__.<locals>.<listcomp>)rar?r.rj)rmr9r�r6r6r7� __contains__ZszHeaders.__contains__�typing.Iterator[typing.Any]cCs t|���Sri)�iterr�r}r6r6r7�__iter__^� zHeaders.__iter__�intcC� t|j�Sri)�lenrjr}r6r6r7�__len__a� zHeaders.__len__�othercCsRzt|�}Wn tyYdSwdd�|jD�}dd�|jD�}t|�t|�kS)NFcS�g|] \}}}||f�qSr6r6r�r6r6r7rzjr{z"Headers.__eq__.<locals>.<listcomp>cSr�r6r6r�r6r6r7rzkr{)r+rVrj�sorted)rmr�Z other_headersZ self_listZ other_listr6r6r7�__eq__ds  �zHeaders.__eq__cCsv|jj}d}|jdkrd|j��}tt|����}t|�}t|�t|�k}|r1|�d|�|�d�S|�d|�|�d�S)NrPr=z , encoding=�(�))� __class__�__name__r.rkrer��dictr�)rm� class_nameZ encoding_strZas_list�as_dictZno_duplicate_keysr6r6r7�__repr__ns  zHeaders.__repr__�NN)rfrgr.r;r0rh�r0r/�rAr/r0rh)r0rv)r0r~)r0r�)r0r�)r0r�ri)r9r/r�r�r0r�)F)r9r/r�r1r0r�)rfrgr0rh)r0r+)r9r/r0r/�r9r/rAr/r0rh)r9r/r0rh)r9r�r0r1)r0r��r0r�)r�r�r0r1)r�� __module__� __qualname__�__doc__rn�propertyr.�setterrpr�r�r^r�r�r�r�r�r�r�r�r�r�r�r�r�r6r6r6r7r+�s6 �                r+c @sveZdZdddddddddd� d0dd�Zd1dd �Zed2d"d#��Zd2d$d%�Zd2d&d'�Zd3d(d)�Z d4d+d,�Z d5d.d/�Z dS)6r,N) rZrf�cookies�content�data�files�json�stream� extensions�methodr/rQ� URL | strrZ�QueryParamTypes | Nonerfrgr��CookieTypes | Noner��RequestContent | Noner��RequestData | Noner��RequestFiles | Noner��typing.Any | Noner��'SyncByteStream | AsyncByteStream | Noner��RequestExtensions | Noner0rhc Cs�|��|_|dur t|�nt||d�|_t|�|_| durint| �|_|r-t|�� |�| durc|j� d�} t |||| t | rF| � |jj�ndd�d�\}} |�|�| |_t| t�ra|��dSdS| |_dS)N)rZrF)rE)r�r�r�r��boundary)�upperr�r'rQr+rfr�r�r*�set_cookie_headerr�r rr?r.�_preparer�r>r�read) rmr�rQrZrfr�r�r�r�r�r�r�rEr6r6r7rns2   �� �   � zRequest.__init__�default_headers�dict[str, str]cCs�|��D]\}}|��dkrd|jvrq|j�||�qg}d|jv}d|jvp,d|jv}|s<|jjr<|�d|jjf�|sH|jdvrH|�d�t ||jj �|_dS)N�transfer-encodingzContent-Length�HostzTransfer-EncodingsHost)�POST�PUT�PATCH)sContent-Length�0) r^rarf� setdefaultrQ�hostrW�netlocr�r+rp)rmr�r9rAZ auto_headersZhas_hostZhas_content_lengthr6r6r7r��s �  zRequest._preparer<cC�t|d�st��|jS�N�_content)�hasattrrr�r}r6r6r7r��� zRequest.contentcCsHt|d�s!t|jtj�sJ�d�|j�|_t|jt�s!t|j�|_|jS)�6 Read and return the request content. r��)r�r>r��typing�Iterabler�r�rr}r6r6r7r��s   z Request.readc�sZ�t|d�s*t|jtj�sJ�d�dd�|j2�IdH�|_t|jt�s*t|j�|_|jS)r�r�r�c���g|z3dHW}|�q6Srir6�rx�partr6r6r7rz���z!Request.aread.<locals>.<listcomp>N)r�r>r�r�� AsyncIterabler�r�rr}r6r6r7�aread�s�   z Request.areadcCs,|jj}t|j�}d|�d|j�d|�d�S)N�<r�r�z)>)r�r�r/rQr�)rmr�rQr6r6r7r��s zRequest.__repr__�dict[str, typing.Any]cC�dd�|j��D�S)NcS�i|] \}}|dvr||�qS))r�r�r6�rx�namerAr6r6r7r��� �z(Request.__getstate__.<locals>.<dictcomp>��__dict__r^r}r6r6r7� __getstate__���zRequest.__getstate__�statecCs0|��D] \}}t|||�qi|_t�|_dSri)r^�setattrr�rr��rmrr�rAr6r6r7� __setstate__�s zRequest.__setstate__)r�r/rQr�rZr�rfrgr�r�r�r�r�r�r�r�r�r�r�r�r�r�r0rh�r�r�r0rh�r0r<r��r0r��rr�r0rh) r�r�r�rnr�r�r�r�r�r�rrr6r6r6r7r,~s&� :     r,c @s8eZdZddddddddddd� d�dd�Zd�dd �Zed�d"d#��Zejd�d%d#��Zed�d'd(��Zejd�d*d(��Zed�d,d-��Z ed�d.d/��Z ed�d1d2��Z ed�d4d5��Z ed�d6d7��Z ed�d8d9��Zejd�d:d9��Zed�d;d<��Zd�d>d?�Zed�dAdB��Zed�dCdD��Zed�dEdF��Zed�dGdH��Zed�dIdJ��Zed�dKdL��Zed�dMdN��Zd�dOdP�Zd�dRdS�Zed�dUdV��Zed�dXdY��Zed�dZd[��Zd�d\d]�Zd�d_d`�Zd�dbdc�Zd�ddde�Z d�d�didj�Z!d�d�dldm�Z"d�dndo�Z#d�d�dpdq�Z$d�drds�Z%d�dtdu�Z& d�d�dwdx�Z' d�d�dzd{�Z(d�d|d}�Z) d�d�d~d�Z*d�d�d��Z+dS)�r-Nro) rfr��text�htmlr�r��requestr��history�default_encoding� status_coder�rfrgr��ResponseContent | Noner r;r r�r�r�r�r �Request | Noner��ResponseExtensions | Noner �list[Response] | Noner�#str | typing.Callable[[bytes], str]r0rhc Cs�||_t|�|_||_d|_| durint| �|_| durgnt| �|_d|_ d|_ | |_ |durLt ||||�\}}|� |�||_t|t�rK|��n||_d|_dS)NFr)rr+rf�_request� next_requestr�r�rkr � is_closed�is_stream_consumedrr r�r�r>rr��_num_bytes_downloaded) rmrrfr�r r r�r�r r�r rr6r6r7rns$   � zResponse.__init__r�r�cCs<|��D]\}}|��dkrd|jvrq|j�||�qdS)Nr�zcontent-length)r^rarfr�)rmr�r9rAr6r6r7r�;s �zResponse._prepare�datetime.timedeltacCst|d�s td��|jS)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�� RuntimeErrorrr}r6r6r7�elapsedBs �zResponse.elapsedrcCrsri)r)rmrr6r6r7rOrur,cCs|jdur td��|jS)zR Returns the request instance associated to the current response. Nz7The request instance has not been set on this response.)rrr}r6r6r7r Ss �zResponse.requestrAcCrsri)rrtr6r6r7r ^rur/cCs2z|jd}Wn tyYdSw|jddd�S)N� http_versionzHTTP/1.1r=�ignore��errors)r�r�rq)rmrr6r6r7rbs  �zResponse.http_versioncCs<z|jd}Wntyt�|j�YSw|jddd�S)N� reason_phraser=rr )r�r�rZget_reason_phraserrq)rmr"r6r6r7r"ks  �zResponse.reason_phraser'cCs|jjS)zA Returns the URL for which the request was made. )r rQr}r6r6r7rQtsz Response.urlr<cCr�r�)r�rr�r}r6r6r7r�{r�zResponse.contentcCsRt|d�s&|j}|sd|_|jSt|jpdd�}d�|�|j�|��g�|_|jS)N�_textrPror5)r�r�r#rr.r�rq�flush)rmr��decoderr6r6r7r �s �z Response.textcCsZt|d�s*|j}|dust|�s%t|jt�r|j}n t|d�r%|�|j�}|p(d|_|jS)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. rlNr�ro)r��charset_encodingr8r>rr/r�rl)rmr.r6r6r7r.�s     zResponse.encodingcCst|d�r td��||_dS)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�rVrlrtr6r6r7r.�s � cCs |j�d�}|dur dSt|�S)zO Return the encoding, as specified by the Content-Type header. z Content-TypeN)rfr�rM)rmrEr6r6r7r&�s zResponse.charset_encodingr c Cs�t|d�sPg}|jjddd�}|D]}|����}z t|}|�|��Wqty.Yqwt|�dkr=|d|_ |j St|�dkrLt |d�|_ |j St �|_ |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. �_decoderzcontent-encodingT)r�rr)�children) r�rfr�rSrar rWr�r�r'rr)rmZdecodersr�rAZ decoder_clsr6r6r7�_get_content_decoder�s&   �   � �zResponse._get_content_decoderr1cC� t�|j�S)zU A property which is `True` for 1xx status codes, `False` otherwise. )r�is_informationalrr}r6r6r7r+�� zResponse.is_informationalcCr*)zU A property which is `True` for 2xx status codes, `False` otherwise. )r� is_successrr}r6r6r7r-�r,zResponse.is_successcCr*)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_redirectrr}r6r6r7r.�s zResponse.is_redirectcCr*)zU A property which is `True` for 4xx status codes, `False` otherwise. )r�is_client_errorrr}r6r6r7r/�r,zResponse.is_client_errorcCr*)zU A property which is `True` for 5xx status codes, `False` otherwise. )r�is_server_errorrr}r6r6r7r0�r,zResponse.is_server_errorcCr*)z] A property which is `True` for 4xx and 5xx status codes, `False` otherwise. )r�is_errorrr}r6r6r7r1�r,zResponse.is_errorcCs(|jtjtjtjtjtjfvod|jvS)zs Returns True for 3xx responses with a properly formed URL redirection, `False` otherwise. �Location)rr�MOVED_PERMANENTLY�FOUND� SEE_OTHER�TEMPORARY_REDIRECT�PERMANENT_REDIRECTrfr}r6r6r7�has_redirect_locations�� �zResponse.has_redirect_locationcCsp|j}|dur td��|jr|S|jrd}nd}|jd}dddd 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}�dzInformational responsezRedirect responsez Client errorz Server error)r���zInvalid status code)� error_type)r �response)rrr-r8rr��formatr)rmr rIZ status_classZ error_typesr=r6r6r7�raise_for_statuss*��� � zResponse.raise_for_status�kwargscKstj|jfi|��Sri)�jsonlib�loadsr�)rmrAr6r6r7r�?sz Response.jsonr*cCs$t|d�st�|_|j�|�|jS)N�_cookies)r�r*rD�extract_cookiesr}r6r6r7r�Bs  zResponse.cookies� dict[str | None, dict[str, str]]cCs*|j�d�}|dur iSdd�t|�D�S)zI Returns the parsed header links of the response, if any r[NcSs"i|] }|�d�p |�d�|�qS)�relrQ)r�)rxr[r6r6r7r�Rs��z"Response.links.<locals>.<dictcomp>)rfr�r])rm�headerr6r6r7rXIs �zResponse.linkscCs|jSri)rr}r6r6r7�num_bytes_downloadedWszResponse.num_bytes_downloadedcCsd|j�d|j�d�S)Nz <Response [� �]>)rr"r}r6r6r7r�[szResponse.__repr__r�cCr�)NcSr�))r�r�rr'r6r�r6r6r7r�_r�z)Response.__getstate__.<locals>.<dictcomp>r�r}r6r6r7r^rzResponse.__getstate__rcCs6|��D] \}}t|||�qd|_i|_t�|_dS)NT)r^rrr�rr�rr6r6r7res  zResponse.__setstate__cCs t|d�s d�|���|_|jS)�7 Read and return the response content. r�r�)r�r�� iter_bytesr�r}r6r6r7r�ls z Response.read� chunk_size� int | None�typing.Iterator[bytes]ccs��t|d�r,|durt|j�n|}tdt|j�t|d��D] }|j|||�VqdS|��}t|d�}t|jd��9|� �D]}|� |�}|� |�D]}|VqLq@|� �}|� |�D]}|Vq\|� �D]}|VqfWd�dS1swwYdS�z� A byte-iterator over the decoded response content. This allows us to handle gzip, deflate, brotli, and zstd encoded responses. r�Nrr�rN�r ) r�r�r��range�maxr)r rr�iter_rawrqr$�rmrN�ir%�chunkerZ raw_bytes�decoded�chunkr6r6r7rMts*� �   � �"�zResponse.iter_bytes�typing.Iterator[str]ccs��t|jpdd�}t|d�}t|jd��9|��D]}|�|�}|�|�D]}|Vq%q|��}|�|�D]}|Vq5|��D]}|Vq?Wd�dS1sPwYdS�z� A str-iterator over the decoded response content that handles both gzip, deflate, etc but also detects the content's string encoding. ror5rRrSN)rr.rrrrMrqr$�rmrNr%rYZ byte_contentZ text_contentr[r6r6r7� iter_text�s �   � �"�zResponse.iter_textccsr�t�}t|jd��%|��D] }|�|�D]}|Vqq|��D]}|Vq!Wd�dS1s2wYdS�NrS)rrrr_rqr$�rmr%r �liner6r6r7� iter_lines�s� � �"�zResponse.iter_linesccs��|jrt��|jr t��t|jt�std��d|_d|_t |d�}t |j d��"|jD]}|jt |�7_|� |�D]}|Vq<q,Wd�n1sMwY|��D]}|VqV|��dS)�@ A byte-iterator over the raw response content. z5Attempted to call a sync iterator on an async stream.TrrRrSN)rrrrr>r�r&rrr rrr�rqr$�close�rmrNrYZraw_stream_bytesr[r6r6r7rV�s*�   ���  zResponse.iter_rawcCs`t|jt�s td��|js.d|_t|jd��|j��Wd�dS1s'wYdSdS)�� 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.TrSN)r>r�r&rrrrrer}r6r6r7re�s  "��zResponse.closec�s2�t|d�sd�dd�|��2�IdH�|_|jS)rLr�r�c�r�rir6r�r6r6r7rz�r�z"Response.aread.<locals>.<listcomp>N)r�r�� aiter_bytesr�r}r6r6r7r��s�  zResponse.aread�typing.AsyncIterator[bytes]cCs�t|d�r,|durt|j�n|}tdt|j�t|d��D] }|j|||�VqdS|��}t|d�}t|jd��>|� �2z3dHW}|� |�}|� |�D]}|VqPq@6|� �}|� |�D]}|Vqa|� �D]}|VqkWd�dS1s|wYdSrQ) r�r�r�rTrUr)r rr� aiter_rawrqr$rWr6r6r7rh�s,� �  �� �"�zResponse.aiter_bytes�typing.AsyncIterator[str]cCs��t|jpdd�}t|d�}t|jd��>|��2z3dHW}|�|�}|�|�D]}|Vq)q6|��}|�|�D]}|Vq:|��D]}|VqDWd�dS1sUwYdSr])rr.rrrrhrqr$r^r6r6r7� aiter_text�s"�  �� �"�zResponse.aiter_textcCs|�t�}t|jd��*|��2z3dHW}|�|�D]}|Vqq6|��D]}|Vq&Wd�dS1s7wYdSr`)rrrrlrqr$rar6r6r7� aiter_liness��� �"�zResponse.aiter_linescCs��|jrt��|jr t��t|jt�std��d|_d|_t |d�}t |j d��'|j2z3dHW}|jt |�7_|� |�D]}|Vq@q,6Wd�n1sRwY|��D]}|Vq[|��IdHdS)rdz6Attempted to call an async iterator on an sync stream.TrrRrSN)rrrrr>r�rrrr rrr�rqr$�acloserfr6r6r7rj s*�  ��� zResponse.aiter_rawc�sh�t|jt�s td��|js2d|_t|jd��|j��IdHWd�dS1s+wYdSdS)rgz3Attempted to call an async close on an sync stream.TrSN)r>r�rrrrrrnr}r6r6r7rn)s� "��zResponse.aclose)rr�rfrgr�rr r;r r;r�r�r�r�r rr�rr rrrr0rhr)r0r)rrr0rh)r0r,)rAr,r0rhr�)r0r'r)r0r;r�)r0r �r0r1)r0r-)rAr�r0r�)r0r*)r0rFr�rr ri)rNrOr0rP)rNrOr0r\�r0r\)r0rh)rNrOr0ri)rNrOr0rk)r0rk),r�r�r�rnr�r�rr�r rr"rQr�r r.r&r)r+r-r.r/r0r1r8r@r�r�rXrIr�rrr�rMr_rcrVrer�rhrlrmrjrnr6r6r6r7r-s�� 7                      %             � �  �r-c@s�eZdZdZd9d:dd�Zd;d d �Zd<dd�Zd=d>dd�Z   d?d@dd�Z  dAdBdd�Z dAdCd d!�Z d9d:d"d#�Z dDd$d%�Z dEd&d'�Z dFd(d)�ZdGd+d,�ZdHd.d/�ZdId1d2�ZdJd3d4�ZGd5d6�d6ejj�ZGd7d8�d8�ZdS)Kr*z- HTTP Cookies, as a mutable mapping. Nr�r�r0rhcCs�|dus t|t�r%t�|_t|t�r!|��D] \}}|�||�qdSdSt|t�r=t�|_|D] \}}|�||�q0dSt|t�rTt�|_|jD]}|j�|�qIdS||_dSri) r>r�r�jarr^�setrkr*� set_cookie)rmr�r9rA�cookier6r6r7rn<s$ �  �  � zCookies.__init__r>r-cCs(|�|�}|�|j�}|j�||�dS)zO Loads any cookies based on the response `Set-Cookie` headers. N)�_CookieCompatResponse�_CookieCompatRequestr rqrE)rmr>Zurllib_response�urllib_requestr6r6r7rEMs  zCookies.extract_cookiesr r,cCs|�|�}|j�|�dS)zM Sets an appropriate 'Cookie:' HTTP header on the `Request`. N)rvrq�add_cookie_header)rmr rwr6r6r7r�Vs zCookies.set_cookie_headerrP�/r�r/rA�domain�pathcCs�idd�d|�d|�dd�dd�d |�d t|��d |�d ��d |�dt|��dd�dd�dd�dd�dd�dddi�dd�}tdi|��}|j�|�dS)zU Set a cookie value by name. May optionally include domain and path. �versionrr�rA�portNZport_specifiedFrzZdomain_specifiedZdomain_initial_dot�.r{Zpath_specifiedZsecureZexpires�discardT�commentZ comment_url�restZHttpOnlyZrfc2109r6)r1� startswithrrqrs)rmr�rArzr{rArtr6r6r7rr]sJ������� � � � � � �����z Cookies.setr�r;cCsnd}|jD])}|j|kr.|dus|j|kr.|dus|j|kr.|dur+d|��}t|��|j}q|dur5|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=)rqr�rzr{rrA)rmr�r�rzr{rArtrIr6r6r7r�ws   �z Cookies.getcs\�dur�dur|j�����S���fdd�|jD�}|D] }|j�|j|j|j�qdS)z� Delete a cookie by name. May optionally include domain and path in order to specify exactly which cookie to delete. Ncs>g|]}|j�kr�dus|j�kr�dus|j�kr|�qSri)r�rzr{�rxrt�rzr�r{r6r7rz�s �z"Cookies.delete.<locals>.<listcomp>)rq�clearrzr{r�)rmr�rzr{�removertr6r�r7�delete�s ��zCookies.deletecCsDg}|dur |�|�|dur|dusJ�|�|�|jj|�dS)z� Delete all cookies. Optionally include a domain and path in order to only delete a subset of all the cookies. N)rWrqr�)rmrzr{�argsr6r6r7r��s   z Cookies.clearcCs$t|�}|jD]}|j�|�qdSri)r*rqrs)rmr�rtr6r6r7r��s �zCookies.updatecCs |�||�Sri)rr�rmr�rAr6r6r7r��r�zCookies.__setitem__cCs|�|�}|dur t|��|Sri)r�r�r�r6r6r7r��s zCookies.__getitem__cCs |�|�Sri)r�)rmr�r6r6r7r��r�zCookies.__delitem__r�cCr�ri)r�rqr}r6r6r7r��r�zCookies.__len__r\cCrw)Ncss�|]}|jVqdSri)r�r�r6r6r7� <genexpr>�s�z#Cookies.__iter__.<locals>.<genexpr>�rqr}r6r6r7r��szCookies.__iter__r1cCs|jD]}dSdS)NTFr�)rmryr6r6r7�__bool__�s zCookies.__bool__cCs"d�dd�|jD��}d|�d�S)Nr�c Ss*g|]}d|j�d|j�d|j�d��qS)z<Cookie rRz for z />)r�rArzr�r6r6r7rz�s��z$Cookies.__repr__.<locals>.<listcomp>z <Cookies[rK)r�rq)rmZ cookies_reprr6r6r7r��s �� zCookies.__repr__cs0eZdZdZd �fdd� Zd�fd d � Z�ZS)zCookies._CookieCompatRequest�� Wraps a `Request` instance up in a compatibility interface suitable for use with `CookieJar` operations. r r,r0rhcs*t�jt|j�t|j�|jd�||_dS)N)rQrfr�)�superrnr/rQr�rfr�r )rmr �r�r6r7rn�s � z%Cookies._CookieCompatRequest.__init__r9r/rAcst��||�||jj|<dSri)r��add_unredirected_headerr rf)rmr9rAr�r6r7r��sz4Cookies._CookieCompatRequest.add_unredirected_header�r r,r0rhr�)r�r�r�r�rnr�� __classcell__r6r6r�r7rv�srvc@s$eZdZdZd dd�Zd d d �Zd S)zCookies._CookieCompatResponser�r>r-r0rhcCrsri)r>)rmr>r6r6r7rn�r�z&Cookies._CookieCompatResponse.__init__�email.message.MessagecCs,tj��}|jj��D]\}}|||<q |Sri)rHrIrJr>rfr�)rm�infor9rAr6r6r7r��s  z"Cookies._CookieCompatResponse.infoN�r>r-r0rh)r0r�)r�r�r�r�rnr�r6r6r6r7ru�s ruri)r�r�r0rhr�r�)rPry) r�r/rAr/rzr/r{r/r0rh)NNN) r�r/r�r;rzr;r{r;r0r;r�)r�r/rzr;r{r;r0rh)rzr;r{r;r0rh)r�r/rAr/r0rh)r�r/r0r/)r�r/r0rhr�rpror�)r�r�r�r�rnrEr�rrr�r�r�r�r�r�r�r�r�r�r��urllibr r,rvrur6r6r6r7r*7s0    � �         r*)r.r/r0r1ri)r9r:r.r;r0r<)rAr:r.r;r0r<)rEr/r0r;)rAr/r0rN)r^r_r0r`)J� __future__rr2�datetime� email.messagerHr�rBrTr��urllib.requestr��collections.abcr�http.cookiejarrrr�rrr r � _decodersr r r rrrrr� _exceptionsrrrrrrrZ _multipartr� _status_codesr�_typesrrrrr r!r"r#r$r%r&�_urlsr'�_utilsr(r)�__all__rbr8r@rDrMr]re�MutableMappingr/r+r,r-r*r6r6r6r7�<module>sH  ($ 4     % t8
Memory