o
    .j-                     @  s  U d dl mZ d dlZd dlZd dlmZ d dlmZ ddlm	Z	 ddl
mZmZ dd	lmZ ejr>d d
lmZ ddlmZ dZeg dZeg dZdZzzd dlZW n eyb   d dlZY nw W n	 eym   Y nw ed7 Zzd dlZW n	 ey   Y nw ed7 ZG dd deZej Z!de"d< h dZ#						dBdCd"d#Z$dDd'd(Z%dEd+d,Z&dEd-d.Z'dFd3d4Z(dGd5d6Z)G d7d8 d8ej*Z+	9dHdId@dAZ,dS )J    )annotationsN)	b64encode)Enum   )UnrewindableBodyError   )to_bytesiscoroutinefunction)BytesQueueBuffer)Final)_TYPE_BODY_POSITIONz@@@SKIP_HEADER@@@)accept-encodinghost
user-agent)zcontent-encodingzcontent-languagezcontent-locationzcontent-typezcontent-lengthdigestzlast-modifiedzgzip,deflatez,brz,zstdc                   @  s   e Zd ZdZdS )_TYPE_FAILEDTELLr   N)__name__
__module____qualname__token r   r   I/home/thesage/.local/lib/python3.10/site-packages/urllib3/util/request.pyr   5   s    r   zFinal[_TYPE_FAILEDTELL]_FAILEDTELL>   GETHEADTRACEDELETECONNECTOPTIONS
keep_alivebool | Noneaccept_encodingbool | list[str] | str | None
user_agent
str | None
basic_authproxy_basic_authdisable_cachereturndict[str, str]c                 C  s   i }|rt |tr
nt |trd|}nt}||d< |r!||d< | r'd|d< |r7dt|d  |d< |rGdt|d  |d	< |rMd
|d< |S )a  
    Shortcuts for generating request headers.

    :param keep_alive:
        If ``True``, adds 'connection: keep-alive' header.

    :param accept_encoding:
        Can be a boolean, list, or string.
        ``True`` translates to 'gzip,deflate'.  If either the ``brotli`` or
        ``brotlicffi`` package is installed 'gzip,deflate,br' is used instead.
        List will get joined by comma.
        String will be used as provided.

    :param user_agent:
        String representing the user-agent you want, such as
        "python-urllib3/0.6"

    :param basic_auth:
        Colon-separated username:password string for 'authorization: basic ...'
        auth header.

    :param proxy_basic_auth:
        Colon-separated username:password string for 'proxy-authorization: basic ...'
        auth header.

    :param disable_cache:
        If ``True``, adds 'cache-control: no-cache' header.

    Example:

    .. code-block:: python

        import urllib3

        print(urllib3.util.make_headers(keep_alive=True, user_agent="Batman/1.0"))
        # {'connection': 'keep-alive', 'user-agent': 'Batman/1.0'}
        print(urllib3.util.make_headers(accept_encoding=True))
        # {'accept-encoding': 'gzip,deflate'}
    ,r   r   z
keep-alive
connectionzBasic zlatin-1authorizationzproxy-authorizationzno-cachezcache-control)
isinstancestrlistjoinACCEPT_ENCODINGr   encodedecode)r   r!   r#   r%   r&   r'   headersr   r   r   make_headersD   s*   /

r5   body
typing.Anyboolc                 C  s   t t| ddd S )Ntellc                   S  s   d S )Nr   r   r   r   r   <lambda>   s    zis_async_file.<locals>.<lambda>)r	   getattr)r6   r   r   r   is_async_file   s   r<   pos_TYPE_BODY_POSITION | Nonec                 C  sR   |durt | | |S t| dddur'z|  }W |S  ty&   t}Y |S w |S )z
    If a position is provided, move file to that point.
    Otherwise, we'll attempt to record a position for future use.
    Nr9   )rewind_bodyr;   r9   OSErrorr   r6   r=   r   r   r   set_file_position   s   
	
rB   c                   s`   |durt | |I dH  |S t| dddur.z
|  I dH }W |S  ty-   t}Y |S w |S )z\
    Asynchronous variant for set_file_position when using anyio.AsyncFile for example.
    Nr9   )arewind_bodyr;   r9   r@   r   rA   r   r   r   aset_file_position   s   	rD   typing.IO[typing.AnyStr]body_posr   Nonec              
   C  st   t | dd}|dur(t|tr(z|| W dS  ty' } ztd|d}~ww |tu r0tdtdt| d)z
    Attempt to rewind body to a certain position.
    Primarily used for request redirects and retries.

    :param body:
        File-like object that supports seek.

    :param int pos:
        Position to seek to in file.
    seekNAAn error occurred when rewinding request body for redirect/retry.RUnable to record file position for rewinding request body during a redirect/retry.1body_pos must be of type integer, instead it was .r;   r-   intr@   r   r   
ValueErrortyper6   rF   	body_seeker   r   r   r?      s&   r?   c              
     s|   t | dd}|dur,t|tr,z
||I dH  W dS  ty+ } ztd|d}~ww |tu r4tdtdt| d)z+
    Async counterpart of rewind_body.
    rH   NrI   rJ   rK   rL   rM   rQ   r   r   r   rC      s(   rC   c                   @  s&   e Zd ZU ded< ded< ded< dS )ChunksAndContentLengthz;typing.Iterable[bytes] | typing.AsyncIterable[bytes] | Nonechunksz
int | Nonecontent_lengthr8   	is_stringN)r   r   r   __annotations__r   r   r   r   rT      s   
 rT   Ftyping.Any | Nonemethodr.   	blocksizerN   forcec           
        sH  du rd}|  tvrd}nd}t||ddS d fdd}d fd
d}tttfrLt}t|}|rHt| krHt	|| }nM|f}nIt
dr\t
ds\| }d}n9t
drg| }d}n.zt}	W n! ty   zt}d}W n ty   tddw Y nw f}|	j}t||tttjtjfdS )aR  Takes the HTTP request method, body, and blocksize and
    transforms them into an iterable of chunks to pass to
    socket.sendall() and an optional 'Content-Length' header.

    A 'Content-Length' of 'None' indicates the length of the body
    can't be determined so should use 'Transfer-Encoding: chunked'
    for framing instead.
    Nr   F)rU   rV   rW   r(   typing.Iterable[bytes]c                  3  s8    t tj} 	  }|sd S | r|d}|V  q)NTutf-8)r-   io
TextIOBasereadr2   )r2   	datablockr[   r6   r   r   chunk_readable  s   

z&body_to_chunks.<locals>.chunk_readabletyping.AsyncIterable[bytes]c                   s   d ur
t dsJ d } t dr4	  I d H }|s d S | d u r)t|t} | r0|dn|V  qt }2 z!3 d H W }| d u rHt|t} || rQ|dn| | V  q96 |rh| V  |s^d S d S )N	__aiter__ra   Tr^   )hasattrra   r-   r.   r2   r
   putget)r2   blockqueuerc   r   r   chunk_areadable&  s,   


z'body_to_chunks.<locals>.chunk_areadablera   rf   zO'body' must be a bytes-like object, file-like object, or iterable. Instead was )r(   r]   )r(   re   )upper_METHODS_NOT_EXPECTING_BODYrT   r-   r.   bytesr   lenr_   BytesIOrg   
memoryview	TypeErroriternbytesStringIOTextIOWrapper)
r6   rZ   r[   r\   rU   rV   rd   rl   	convertedmvr   rc   r   body_to_chunks   sn   !

rz   )NNNNNN)r   r    r!   r"   r#   r$   r%   r$   r&   r$   r'   r    r(   r)   )r6   r7   r(   r8   )r6   r7   r=   r>   r(   r>   )r6   rE   rF   r   r(   rG   )r6   r7   rF   r   r(   rG   )F)
r6   rY   rZ   r.   r[   rN   r\   r8   r(   rT   )-
__future__r   r_   typingbase64r   enumr   
exceptionsr   utilr   r	   responser
   TYPE_CHECKINGtyping_extensionsr   _typingr   SKIP_HEADER	frozensetSKIPPABLE_HEADERSNOT_FORWARDABLE_HEADERSr1   
brotlicffi_unused_module_brotliImportErrorbrotli	zstandard_unused_module_zstdr   r   r   rX   rn   r5   r<   rB   rD   r?   rC   
NamedTuplerT   rz   r   r   r   r   <module>   sh    
O




