U
    
"gÜ  ã                   @   s†   d dl mZ d dlmZ d dlmZmZ ddlmZ dZ	zd dl
ZW n ek
rX   Y n
X e	d7 Z	eƒ Zdd	d
„Zdd„ Zdd„ ZdS )é    )Úabsolute_import)Ú	b64encode)ÚbÚinteger_typesé   )ÚUnrewindableBodyErrorzgzip,deflateNz,brc                 C   sš   i }|r6t |tƒrnt |tƒr*d |¡}nt}||d< |rB||d< | rNd|d< |rldtt|ƒƒ d¡ |d< |rŠdt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'.
        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::

        >>> make_headers(keep_alive=True, user_agent="Batman/1.0")
        {'connection': 'keep-alive', 'user-agent': 'Batman/1.0'}
        >>> make_headers(accept_encoding=True)
        {'accept-encoding': 'gzip,deflate'}
    ú,zaccept-encodingz
user-agentz
keep-aliveZ
connectionzBasic zutf-8Zauthorizationzproxy-authorizationzno-cachezcache-control)Ú
isinstanceÚstrÚlistÚjoinÚACCEPT_ENCODINGr   r   Údecode)Z
keep_aliveZaccept_encodingZ
user_agentZ
basic_authZproxy_basic_authZdisable_cacheZheaders© r   ú6/usr/lib/python3/dist-packages/urllib3/util/request.pyÚmake_headers   s.    *

ÿþ
r   c              	   C   sR   |dk	rt | |ƒ n:t| ddƒdk	rNz|  ¡ }W n ttfk
rL   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   ÚIOErrorÚOSErrorÚ_FAILEDTELL)ÚbodyÚposr   r   r   Úset_file_positionZ   s    
r   c              	   C   st   t | ddƒ}|dk	rNt|tƒrNz||ƒ W qp ttfk
rJ   tdƒ‚Y qpX n"|tkr`tdƒ‚ntdt|ƒ ƒ‚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.z4body_pos must be of type integer, instead it was %s.)	r   r	   r   r   r   r   r   Ú
ValueErrorÚtype)r   Zbody_posZ	body_seekr   r   r   r   l   s    ÿÿ
ÿr   )NNNNNN)Z
__future__r   Úbase64r   Zsixr   r   Ú
exceptionsr   r   ZbrotliZ_unused_module_brotliÚImportErrorÚobjectr   r   r   r   r   r   r   r   Ú<module>   s&         ú
H