σ
ΌS]c           @@  sv   d  d l  m Z d  d l Z d  d l Z d e f d     YZ e   Z d d  Z d   Z	 d e f d	     YZ
 d S(
   i    (   t   absolute_importNt   Sixc           B@  s'   e  Z d  d l Z e j d  d k Z RS(   i    Ni   (   t   __name__t
   __module__t   syst   version_infot   PY3(    (    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyR      s   s   application/octet-streamc         C@  s!   |  r t  j |   d p | 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(   t   filenamet   default(    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   guess_content_type'   s    	c         @  s   t    f d   d D  sX d |    f } y | j d  Wn t k
 rP qX X| Sn  t j ss   j d    n  t j j   d    d |    f     S(   s   
    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(   N(    (   t   .0t   ch(   t   value(    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pys	   <genexpr>B   s    s   "\
s   %s="%s"t   asciis   utf-8s   %s*=%s(   t   anyt   encodet   UnicodeEncodeErrort   sixR   t   emailt   utilst   encode_rfc2231(   t   nameR   t   result(    (   R   sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   format_header_param5   s    	t   RequestFieldc           B@  sY   e  Z d  Z d d d  Z e d    Z d   Z d   Z d   Z	 d d d d  Z
 RS(   sK  
    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.
    c         C@  s@   | |  _  | |  _ | |  _ i  |  _ | r< t |  |  _ n  d  S(   N(   t   _namet	   _filenamet   datat   headerst   dict(   t   selfR   R   R	   R   (    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   __init___   s    				c         C@  s   t  | t  rN t |  d k r3 | \ } } } q` | \ } } t |  } n d } d } | } |  | | d | } | j d |  | 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.
        i   R	   t   content_typeN(   t
   isinstancet   tuplet   lenR   t   Nonet   make_multipart(   t   clst	   fieldnameR   R	   R   R"   t   request_param(    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   from_tuplesg   s    c         C@  s   t  | |  S(   s  
        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   (    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   _render_part   s    	c         C@  sp   g  } | } t  | t  r* | j   } n  x6 | D]. \ } } | r1 | j |  j | |   q1 q1 Wd j |  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) typles or a :class:`dict` of (k, v) to format
            as `k1="v1"; k2="v2"; ...`.
        s   ; (   R#   R   t   itemst   appendR,   t   join(   R    t   header_partst   partst   iterableR   R   (    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   _render_parts   s     c         C@  sΕ   g  } d d d g } xD | D]< } |  j  j | t  r | j d | |  j  | f  q q WxL |  j  j   D]; \ } } | | k rl | r§ | j d | | f  q§ ql ql W| j d  d j |  S(   s=   
        Renders the headers for this request field.
        s   Content-Dispositions   Content-Types   Content-Locations   %s: %ss   
(   R   t   gett   FalseR.   R-   R/   (   R    t   linest	   sort_keyst   sort_keyt   header_namet   header_value(    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   render_headersͺ   s    %!c      	   C@  st   | p	 d |  j  d <|  j  d c d j d |  j d |  j f d |  j f f  g  7<| |  j  d <| |  j  d <d	 S(
   s|  
        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.

        s	   form-datas   Content-Dispositions   ; t    R   R	   s   Content-Types   Content-LocationN(   R   R/   R3   R   R   (   R    t   content_dispositionR"   t   content_location(    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyR'   ½   s
    0N(   R   R   t   __doc__R&   R!   t   classmethodR+   R,   R3   R;   R'   (    (    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyR   Q   s   "			(   t
   __future__R    t   email.utilsR   R   t   objectR   R   R   R   R   (    (    (    sD   lib/python2.7/site-packages/anaconda_project/internal/test/fields.pyt   <module>   s   		