ó
>ò†[c           @  sÌ   d  d l  m Z d  d l Z d  d l Z d  d l m Z m Z d  d l Z d  d l Z d  d l	 m
 Z
 m Z e j d ƒ Z d d „ Z d e f d „  ƒ  YZ d d d	 „ Z d
 e j j f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   BytesIOt   StringIO(   t   choose_boundaryt   iter_fieldsu   binstar.requests_extc           sœ  g  ‰  ‡  f d †  } ‡  f d †  } | d k r< t ƒ  } n  x;t |  ƒ D]-\ } } | d | ƒ t | t ƒ rt | ƒ d k r– | \ } } } nC | \ } } d d l m }	 |	 | ƒ \ } }
 | d k rÙ d } n  | d | | f ƒ | d	 | f ƒ n | } | d
 | ƒ | d ƒ t | t j	 ƒ rCt j
 | ƒ } n  t | t j
 ƒ rb| | ƒ n
 | | ƒ | d ƒ qI W| d | ƒ d | } ˆ  | f S(   u>  
    Encode a dictionary of ``fields`` using the multipart/form-data MIME format.

    :param fields:
        Dictionary of fields or list of (key, value) or (key, value, MIME type)
        field tuples.  The key is treated as the field name, and the value as
        the body of the form-data bytes. If the value is a tuple of two
        elements, then the first element is treated as the filename of the
        form-data section and a suitable MIME type is guessed based on the
        filename. If the value is a tuple of three elements, then the third
        element is treated as an explicit MIME type of the form-data section.

        Field names and filenames must be unicode.

    :param boundary:
        If not specified, then a random boundary will be generated using
        :func:`mimetools.choose_boundary`.
    c           sS   t  |  t j ƒ r! t |  ƒ }  n! t  |  t j ƒ rB t |  ƒ }  n  ˆ  j |  ƒ d  S(   N(   t
   isinstancet   sixt   binary_typeR   t	   text_typeR   t   append(   t   item(   t   body(    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyt
   body_write%   s
    c           s   ˆ  j  t |  j d ƒ ƒ ƒ S(   Nu   utf-8(   R	   R   t   encode(   R
   (   R   (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyt   <lambda>,   s    u   --%s
i   iÿÿÿÿ(   t
   guess_typeu   application/octet-streamu:   Content-Disposition: form-data; name="%s"; filename="%s"
u   Content-Type: %s

u+   Content-Disposition: form-data; name="%s"
s   
u   --%s--
u    multipart/form-data; boundary=%sN(   t   NoneR   R   R   t   tuplet   lent	   mimetypesR   R   t   integer_typesR   (   t   fieldst   boundaryR   t   body_write_encodet	   fieldnamet   valuet   filenamet   datat   content_typeR   t   _(    (   R   sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyt    encode_multipart_formdata_stream   s@    	


t   MultiPartIOc           B  s5   e  Z d d  „ Z d d „ Z d „  Z d d „ Z RS(   c         C  s(   | |  _  g  |  _ d |  _ | |  _ d  S(   Ni    (   t   to_readt	   have_readt   _totalt   callback(   t   selfR   R#   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyt   __init__Y   s    			iÿÿÿÿc         C  s®   |  j  r% |  j  |  j ƒ  |  j ƒ n  | d k rK d j d „  |  j Dƒ ƒ S|  j sX d SxO |  j r© |  j d j | ƒ } | r„ | S|  j j d ƒ } |  j j | ƒ q[ Wd S(   Niÿÿÿÿt    c         s  s   |  ] } | j  ƒ  Vq d  S(   N(   t   read(   t   .0t   fd(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pys	   <genexpr>d   s    i    (	   R#   t   tellR"   t   joinR    R'   t   popR!   R	   (   R$   t   nR   R)   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyR'   _   s    		c         C  s@   t  d „  |  j Dƒ ƒ } |  j r< | |  j d j ƒ  7} n  | S(   Nc         s  s   |  ] } | j  ƒ  Vq d  S(   N(   R*   (   R(   R)   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pys	   <genexpr>u   s    i    (   t   sumR!   R    R*   (   R$   t   cursor(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyR*   t   s    	i    c         C  sÐ   | d k s t  ‚ | d k rl |  j |  j |  _ g  |  _ g  |  j D] } | j | | ƒ ^ qD d |  _ n` | d k rÌ |  j |  j |  _ g  |  _ g  |  j D] } | j | | ƒ ^ qž |  j ƒ  |  _ n  d  S(   Ni    i   (   t   AssertionErrorR!   R    t   seekR/   R*   R"   (   R$   t   post   modeR)   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyR1   z   s    	&	&N(   t   __name__t
   __module__R   R%   R'   R*   R1   (    (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyR   X   s   	c         C  su   d d l  m } | r4 | t |  ƒ t | ƒ ƒ } n |  } t | ƒ \ } } t | d | ƒ}  i | d 6} |  | f S(   Niÿÿÿÿ(   t   chainR#   u   Content-Type(   t	   itertoolsR6   R   R   R   (   R   t   filesR#   R6   R   R   R   t   headers(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyt   stream_multipart‰   s    t   NullAuthc           B  s   e  Z d  Z d „  Z RS(   u§  force requests to ignore the ``.netrc``

    Some sites do not support regular authentication, but we still
    want to store credentials in the ``.netrc`` file and submit them
    as form elements. Without this, requests would otherwise use the
    .netrc which leads, on some sites, to a 401 error.

    https://github.com/kennethreitz/requests/issues/2773

    Use with::

        requests.get(url, auth=NullAuth())
    c         C  s   | S(   N(    (   R$   t   r(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyt   __call__¤   s    (   R4   R5   t   __doc__R=   (    (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyR;   –   s   (   t
   __future__R    t   codecst   loggingt   ioR   R   R   t   requestst"   requests.packages.urllib3.filepostR   R   t	   getLoggert   loggerR   R   t   objectR   R:   t   autht   AuthBaseR;   (    (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/requests_ext.pyt   <module>   s   H1