B
    @)H[é  ã               @   sN   d dl mZ d dlZd dlZddlmZ ddd„Zdd	„ ZG d
d„ de	ƒZ
dS )é    )Úabsolute_importNé   )Úsixúapplication/octet-streamc             C   s   | rt  | ¡d p|S |S )zæ
    Guess the "Content-Type" of a file.

    :param filename:
        The filename to guess the "Content-Type" of using :mod:`mimetypes`.
    :param default:
        If no "Content-Type" can be guessed, default to `default`.
    r   )Ú	mimetypesÚ
guess_type)ÚfilenameÚdefault© r
   ú[C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_vendor\urllib3\fields.pyÚguess_content_type   s    	r   c          	      sˆ   t ‡ fdd„dD ƒƒsNd| ˆ f }y| d¡ W n ttfk
rH   Y nX |S tjsjtˆ tjƒrjˆ  d¡‰ tj	 
ˆ d¡‰ d| ˆ f ‰ ˆ S )a   
    Helper function to format and quote a single header parameter.

    Particularly useful for header parameters which might contain
    non-ASCII values, like file names. This follows RFC 2231, as
    suggested by RFC 2388 Section 4.4.

    :param name:
        The name of the parameter, a string expected to be ASCII only.
    :param value:
        The value of the parameter, provided as a unicode string.
    c             3   s   | ]}|ˆ kV  qd S )Nr
   )Ú.0Úch)Úvaluer
   r   ú	<genexpr>#   s    z&format_header_param.<locals>.<genexpr>z"\
z%s="%s"Úasciizutf-8z%s*=%s)ÚanyÚencodeÚUnicodeEncodeErrorÚUnicodeDecodeErrorr   ÚPY3Ú
isinstanceÚ	text_typeÚemailÚutilsÚencode_rfc2231)Únamer   Úresultr
   )r   r   Úformat_header_param   s    
r   c               @   sH   e Zd ZdZddd„Zedd„ ƒZdd„ Zd	d
„ Zdd„ Z	ddd„Z
dS )ÚRequestFieldaK  
    A data container for request body parameters.

    :param name:
        The name of this request field.
    :param data:
        The data/value body.
    :param filename:
        An optional filename of the request field.
    :param headers:
        An optional dict-like object of headers to initially use for the field.
    Nc             C   s*   || _ || _|| _i | _|r&t|ƒ| _d S )N)Ú_nameÚ	_filenameÚdataÚheadersÚdict)Úselfr   r"   r   r#   r
   r
   r   Ú__init__?   s    zRequestField.__init__c             C   s^   t |tƒr4t|ƒdkr"|\}}}q@|\}}t|ƒ}nd}d}|}| |||d�}|j|d� |S )a³  
        A :class:`~urllib3.fields.RequestField` factory from old-style tuple parameters.

        Supports constructing :class:`~urllib3.fields.RequestField` from
        parameter of key/value strings AND key/filetuple. A filetuple is a
        (filename, data, MIME type) tuple where the MIME type is optional.
        For example::

            'foo': 'bar',
            'fakefile': ('foofile.txt', 'contents of foofile'),
            'realfile': ('barfile.txt', open('realfile').read()),
            'typedfile': ('bazfile.bin', open('bazfile').read(), 'image/jpeg'),
            'nonamefile': 'contents of nonamefile field',

        Field names and filenames must be unicode.
        é   N)r   )Úcontent_type)r   ÚtupleÚlenr   Úmake_multipart)ÚclsÚ	fieldnamer   r   r"   r(   Úrequest_paramr
   r
   r   Úfrom_tuplesG   s    

zRequestField.from_tuplesc             C   s
   t ||ƒS )a  
        Overridable helper function to format a single header parameter.

        :param name:
            The name of the parameter, a string expected to be ASCII only.
        :param value:
            The value of the parameter, provided as a unicode string.
        )r   )r%   r   r   r
   r
   r   Ú_render_parti   s    	zRequestField._render_partc             C   sP   g }|}t |tƒr| ¡ }x*|D ]"\}}|dk	r | |  ||¡¡ q W d |¡S )aO  
        Helper function to format and quote a single header.

        Useful for single headers that are composed of multiple items. E.g.,
        'Content-Disposition' fields.

        :param header_parts:
            A sequence of (k, v) typles or a :class:`dict` of (k, v) to format
            as `k1="v1"; k2="v2"; ...`.
        Nz; )r   r$   ÚitemsÚappendr0   Újoin)r%   Úheader_partsÚpartsÚiterabler   r   r
   r
   r   Ú_render_partst   s    
zRequestField._render_partsc             C   sŒ   g }dddg}x2|D ]*}| j  |d¡r| d|| j | f ¡ qW x4| j  ¡ D ]&\}}||krN|rN| d||f ¡ qNW | d¡ d |¡S )z=
        Renders the headers for this request field.
        zContent-DispositionzContent-TypezContent-LocationFz%s: %sz
)r#   Úgetr2   r1   r3   )r%   ÚlinesÚ	sort_keysÚsort_keyÚheader_nameÚheader_valuer
   r
   r   Úrender_headersŠ   s    


zRequestField.render_headersc             C   sX   |pd| j d< | j d  d d|  d| jfd| jff¡g¡7  < || j d< || j d< d	S )
a|  
        Makes this request field into a multipart request field.

        This method overrides "Content-Disposition", "Content-Type" and
        "Content-Location" headers to the request parameter.

        :param content_type:
            The 'Content-Type' of the request body.
        :param content_location:
            The 'Content-Location' of the request body.

        z	form-datazContent-Dispositionz; Ú r   r   zContent-TypezContent-LocationN)r#   r3   r7   r    r!   )r%   Úcontent_dispositionr(   Úcontent_locationr
   r
   r   r+   �   s    
zRequestField.make_multipart)NN)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   Úclassmethodr/   r0   r7   r>   r+   r
   r
   r
   r   r   2   s   
" r   )r   )Ú
__future__r   Úemail.utilsr   r   Úpackagesr   r   r   Úobjectr   r
   r
   r
   r   Ú<module>   s   
