� ��^c@@s�ddlmZddlZddlZddlZddlmZdd�Zd�Z idd 6d d 6d d 6Z e j d �e dd�D��d�Z d�ZeZdefd��YZdS(i(tabsolute_importNi(tsixsapplication/octet-streamcC@s!|rtj|�dp|S|S(s� 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`. i(t mimetypest guess_type(tfilenametdefault((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pytguess_content_type s c@s�t�tj�r$�jd��nt�fd�dD��s�d|�f}y|jd�Wnttfk rzq�X|Sntjr��jd��nt j j �d��d|�f�tjr��jd��n�S(s� Helper function to format and quote a single header parameter using the strategy defined in RFC 2231. Particularly useful for header parameters which might contain non-ASCII values, like file names. This follows 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 ``bytes`` or `str``. :ret: An RFC-2231-formatted unicode string. sutf-8c3@s|]}|�kVqdS(N((t.0tch(tvalue(s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pys )ss"\ u%s="%s"tasciis%s*=%s( t isinstanceRt binary_typetdecodetanytencodetUnicodeEncodeErrortUnicodeDecodeErrortPY2temailtutilstencode_rfc2231(tnameR tresult((R s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pytformat_header_param_rfc2231s   u%22u"u\\u\cC@s7i|]-}|dkrdj|�tj|��qS(iu%{:02X}(i(tformatRtunichr(Rtcc((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pys Js ic@s_�fd�}tjdjg�j�D]}tj|�^q(��}|j||�}|S(Nc@s�|jd�S(Ni(tgroup(tmatch(tneedles_and_replacements(s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pytreplacerRst|(tretcompiletjointkeystescapetsub(R RRtneedletpatternR((Rs//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pyt_replace_multipleQs 4cC@sAt|tj�r$|jd�}nt|t�}d||fS(s� Helper function to format and quote a single header parameter using the HTML5 strategy. Particularly useful for header parameters which might contain non-ASCII values, like file names. This follows the `HTML5 Working Draft Section 4.10.22.7`_ and matches the behavior of curl and modern browsers. .. _HTML5 Working Draft Section 4.10.22.7: https://w3c.github.io/html/sec-forms.html#multipart-form-data :param name: The name of the parameter, a string expected to be ASCII only. :param value: The value of the parameter, provided as ``bytes`` or `str``. :ret: A unicode string, stripped of troublesome characters. sutf-8u%s="%s"(R RR R R)t_HTML5_REPLACEMENTS(RR ((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pytformat_header_param_html5^st RequestFieldcB@s_eZdZdded�Zeed��Zd�Zd�Z d�Z dddd�Z RS(s A data container for request body parameters. :param name: The name of this request field. Must be unicode. :param data: The data/value body. :param filename: An optional filename of the request field. Must be unicode. :param headers: An optional dict-like object of headers to initially use for the field. :param header_formatter: An optional callable that is used to encode and format the headers. By default, this is :func:`format_header_param_html5`. cC@sI||_||_||_i|_|r<t|�|_n||_dS(N(t_namet _filenametdatatheaderstdicttheader_formatter(tselfRR/RR0R2((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pyt__init__�s    cC@s�t|t�rNt|�dkr3|\}}}q`|\}}t|�}nd}d}|}|||d|d|�}|jd|�|S(s� 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. iRR2t content_typeN(R ttupletlenRtNonetmake_multipart(tclst fieldnameR R2RR/R5t request_param((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pyt from_tuples�s cC@s|j||�S(sI Overridable helper function to format a single header parameter. By default, this calls ``self.header_formatter``. :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. (R2(R3RR ((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pyt _render_part�s cC@svg}|}t|t�r*|j�}nx<|D]4\}}|dk r1|j|j||��q1q1Wdj|�S(sO 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) tuples or a :class:`dict` of (k, v) to format as `k1="v1"; k2="v2"; ...`. u; N(R R1titemsR8tappendR>R#(R3t header_partstpartstiterableRR ((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pyt _render_parts�s   cC@s�g}dddg}xD|D]<}|jj|t�r|jd||j|f�qqWxL|jj�D];\}}||krl|r�|jd||f�q�qlqlW|jd�dj|�S(s= Renders the headers for this request field. sContent-Dispositions Content-TypesContent-Locationu%s: %su (R0tgettFalseR@R?R#(R3tlinest sort_keystsort_keyt header_namet header_value((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pytrender_headers�s % ! c C@st|p d|jd<|jdcdjd|jd|jfd|jff�g�7<||jd<||jdRDRLR9(((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pyR,}s #  i (t __future__Rt email.utilsRRR!tpackagesRRRR*tupdatetrangeR)R+tformat_header_paramtobjectR,(((s//tmp/pip-build-1THPZW/urllib3/urllib3/fields.pyts"     )