a
    õ£Be“  ã                	   @  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g d¢ƒZdZz,zd dlZW n eyœ   d dlZY n0 W n ey²   Y n
0 ed7 Zzd dlZW n eyÚ   Y n
0 ed7 ZG dd„ deƒZejZded< ejeef Zh d£Z d.d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(d)d*d'd+œd,d-„Z&dS )/é    )ÚannotationsN)Ú	b64encode)ÚEnumé   )ÚUnrewindableBodyErroré   )Úto_bytes)ÚFinalz@@@SKIP_HEADER@@@)úaccept-encodingÚ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   úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/urllib3/util/request.pyr   '   s   r   zFinal[_TYPE_FAILEDTELL]Ú_FAILEDTELL>   ÚHEADÚGETÚTRACEÚDELETEZCONNECTÚOPTIONSz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< |rŽdt| d¡ƒ ¡ › �|d	< |ršd
|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_headers7   s2    /

þÿþÿr,   z
typing.Anyz_TYPE_BODY_POSITION | None)ÚbodyÚposr    c                 C  sL   |durt | |ƒ n4t| ddƒdurHz|  ¡ }W n tyF   t}Y n0 |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    
r3   ztyping.IO[typing.AnyStr]Ú_TYPE_BODY_POSITIONÚNone)r-   Úbody_posr    c              
   C  s†   t | ddƒ}|dur\t|tƒr\z||ƒ W q‚ tyX } ztdƒ|‚W Y d}~q‚d}~0 0 n&|tu rnt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 Ú.)r1   r$   Úintr2   r   r   Ú
ValueErrorÚtype)r-   r6   Ú	body_seekÚer   r   r   r0   š   s"    ÿþÿÿr0   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   r>   ¸   s   
r>   ztyping.Any | Noner%   r9   )r-   ÚmethodÚ	blocksizer    c                   sà   ˆdu r$d}|  ¡ tvrd}qÔd}n°tˆttfƒrJtˆƒf}t|d ƒ}nŠtˆdƒrtddœ‡ ‡fdd„}|ƒ }d}n`ztˆƒ}W nF t	yÆ   zt
ˆƒ}d}W n" t	yÀ   t	dˆ›�ƒd‚Y n0 Y n0 ˆ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
iso-8859-1)r$   ÚioÚ
TextIOBaserD   r)   )r)   Ú	datablock©rC   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 )r?   r@   )ÚupperÚ_METHODS_NOT_EXPECTING_BODYr$   r%   Úbytesr   ÚlenÚhasattrÚ
memoryviewÚ	TypeErrorÚiterÚnbytesr>   )r-   rB   rC   r?   r@   rI   Úmvr   rH   r   Úbody_to_chunks½   s:    

ÿÿýrT   )NNNNNN)'Ú
__future__r   rE   ÚtypingÚbase64r   Úenumr   Ú
exceptionsr   Úutilr   ÚTYPE_CHECKINGZtyping_extensionsr	   ÚSKIP_HEADERÚ	frozensetÚSKIPPABLE_HEADERSr(   Z
brotlicffiZ_unused_module_brotliÚImportErrorÚbrotliZ	zstandardZ_unused_module_zstdr   r   r   rA   ÚUnionr9   r4   rK   r,   r3   r0   Ú
NamedTupler>   rT   r   r   r   r   Ú<module>   sN         úO