U
    ah                  	   @  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 ejr`d d	lmZ d
ZedddgZdZz.zd dlZW n ek
r   d dlZY nX W n ek
r   Y n
X ed7 Zzd dlZW n ek
r   Y n
X ed7 ZG dd deZejZded< ejeef ZddddddhZd5ddddddddd d!Z d"d#d#d$d%d&Z!d'd(d)d*d+d,Z"G d-d. d.ej#Z$d/d0d1d.d2d3d4Z%dS )6    )annotationsN)	b64encode)Enum   )UnrewindableBodyError   )to_bytes)Finalz@@@SKIP_HEADER@@@accept-encodingZhost
user-agentzgzip,deflatez,brz,zstdc                   @  s   e Zd ZdZdS )_TYPE_FAILEDTELLr   N)__name__
__module____qualname__token r   r   :./venv/lib/python3.8/site-packages/urllib3/util/request.pyr   '   s   r   zFinal[_TYPE_FAILEDTELL]_FAILEDTELLZGETZHEADZDELETEZTRACEZOPTIONSZCONNECTzbool | Nonezbool | list[str] | str | Nonez
str | Nonezdict[str, str])
keep_aliveaccept_encoding
user_agent
basic_authproxy_basic_authdisable_cachereturnc                 C  s   i }|r6t |trnt |tr*d|}nt}||d< |rB||d< | rNd|d< |rndt|d  |d< |rdt|d  |d	< |rd
|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-aliveZ
connectionzBasic zlatin-1Zauthorizationzproxy-authorizationzno-cachezcache-control)
isinstancestrlistjoinACCEPT_ENCODINGr   encodedecode)r   r   r   r   r   r   Zheadersr   r   r   make_headers7   s2    /

r#   z
typing.Anyz_TYPE_BODY_POSITION | None)bodyposr   c                 C  sN   |dk	rt | | n6t| dddk	rJz|  }W n tk
rH   t}Y nX |S )z
    If a position is provided, move file to that point.
    Otherwise, we'll attempt to record a position for future use.
    Ntell)rewind_bodygetattrr&   OSErrorr   )r$   r%   r   r   r   set_file_position   s    
r*   ztyping.IO[typing.AnyStr]_TYPE_BODY_POSITIONNone)r$   body_posr   c              
   C  s   t | dd}|dk	rZt|trZz|| W q tk
rV } ztd|W 5 d}~X Y qX n&|tkrltdntdt| ddS )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.
    seekNzAAn error occurred when rewinding request body for redirect/retry.zRUnable to record file position for rewinding request body during a redirect/retry.z1body_pos must be of type integer, instead it was .)r(   r   intr)   r   r   
ValueErrortype)r$   r-   Z	body_seeker   r   r   r'      s"    r'   c                   @  s   e Zd ZU ded< ded< dS )ChunksAndContentLengthztyping.Iterable[bytes] | Nonechunksz
int | Nonecontent_lengthN)r   r   r   __annotations__r   r   r   r   r4      s   
r4   ztyping.Any | Noner   r0   )r$   method	blocksizer   c                   s   dkr$d}|  tkrd}qd}ntttfrJtf}t|d }ntdrtdd fdd}| }d}ndzt}W nJ t	k
r   zt
}d}W n$ t	k
r   t	ddY nX Y nX f}|j}t||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   readztyping.Iterable[bytes])r   c                  3  s6   t tj}  }|sq2| r*|d}|V  qd S )Nzutf-8)r   io
TextIOBaser:   r!   )r!   Z	datablockr9   r$   r   r   chunk_readable   s    

z&body_to_chunks.<locals>.chunk_readablezO'body' must be a bytes-like object, file-like object, or iterable. Instead was )r5   r6   )upper_METHODS_NOT_EXPECTING_BODYr   r   bytesr   lenhasattr
memoryview	TypeErroriternbytesr4   )r$   r8   r9   r5   r6   r>   mvr   r=   r   body_to_chunks   s6    

rI   )NNNNNN)&Z
__future__r   r;   typingbase64r   enumr   
exceptionsr   utilr   ZTYPE_CHECKINGr	   ZSKIP_HEADER	frozensetZSKIPPABLE_HEADERSr    Z
brotlicffiZ_unused_module_brotliImportErrorZbrotliZ	zstandardZ_unused_module_zstdr   r   r   r7   ZUnionr0   r+   r@   r#   r*   r'   Z
NamedTupler4   rI   r   r   r   r   <module>   sP          O