σ ‘fH^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((surllib3/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(surllib3/fields.pys )ss"\ u%s="%s"tasciis%s*=%s( t isinstanceRt binary_typetdecodetanytencodetUnicodeEncodeErrortUnicodeDecodeErrortPY2temailtutilstencode_rfc2231(tnameR tresult((R surllib3/fields.pytformat_header_param_rfc2231s   u%22u"u\\u\cC@s7i|]-}|dkrdj|ƒtj|ƒ“qS(iu%{:02X}(i(tformatRtunichr(Rtcc((surllib3/fields.pys Js ic@s_‡fd†}tjdjgˆjƒD]}tj|ƒ^q(ƒƒ}|j||ƒ}|S(Nc@sˆ|jdƒS(Ni(tgroup(tmatch(tneedles_and_replacements(surllib3/fields.pytreplacerRst|(tretcompiletjointkeystescapetsub(R RRtneedletpatternR((Rsurllib3/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 ((surllib3/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((surllib3/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((surllib3/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 ((surllib3/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 ((surllib3/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((surllib3/fields.pytrender_headersεs % ! c C@st|p d|jd<|jdcdjd|jd|jfd|jffƒgƒ7<||jd<||jdRDRLR9(((surllib3/fields.pyR,}s #  i (t __future__Rt email.utilsRRR!tpackagesRRRR*tupdatetrangeR)R+tformat_header_paramtobjectR,(((surllib3/fields.pyts"     )