
9Vc           @   ss  d  d l  Z  d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l Z Wn e k
 rd  d l Z n Xd  d l Z d d l m Z d d l m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ e
 j0 e1  Z2 d Z3 e j4 e3  Z5 d Z6 d	 e6 d
 Z7 e6 d Z8 d Z9 d e9 d e8 d e3 d e9 d e8 d Z: d Z; d e: d e; d e: d Z< e7 d e3 e7 d Z= d e= d Z> d e6 d e> d e< d Z? e j4 e?  Z@ d e9 d e8 d
 ZA e j4 eA  ZB d   ZC d    ZD d!   ZE d"   ZF d d d#  ZH d$   ZI d%   ZJ d&   ZK e jL d'    ZM e jL d(    ZN e jL d) d*   ZO d+ eP f d,     YZQ d-   ZR d. eP f d/     YZS d0   ZT d1 eP f d2     YZU e j4 d3 e jV  ZW d4   ZX d d5  ZY d6   ZZ d7   Z[ d8   Z\ d9   Z] d:   Z^ e j4 d; e j_  Z` e j4 d<  Za d d=  Zb e j4 d>  Zc d?   Zd d@   Ze dA   Zf dB   Zg dC   Zh dD eP f dE     YZi dF eP f dG     YZj dH eP f dI     YZk d} Zl d em dQ  Zn dR   Zo d~ Zp dY eP f dZ     YZq e j4 d[  Zr e j4 d\  Zs e j4 d]  Zt d^   Z d_   Zu d` e" jv f da     YZv db e' f dc     YZ& dd e& e% f de     YZw e jx df  Zy ey d k rdh e" jz f di     YZz dj e" j{ f dk     YZ{ n  dl e# j| f dm     YZ| dn e# j} f do     YZ} dp e# j~ f dq     YZ~ dr   Z ds eP f dt     YZ du e f dv     YZ dw e f dx     YZ dy e( f dz     YZ d{ eP f d|     YZ d S(   iN(   t   deque(   t   iglobi   (   t   DistlibException(   t   string_typest	   text_typet   shutilt	   raw_inputt   StringIOt   cache_from_sourcet   urlopent   httplibt	   xmlrpclibt	   splittypet   HTTPHandlert   HTTPSHandlert   BaseConfiguratort   valid_identt	   Containert   configparsert   URLErrort   match_hostnamet   CertificateErrort   ZipFiles   \s*,\s*s
   (\w|[.-])+s   (\*|:(\*|\w+):|t   )s   \*?s   ([<>=!~]=)|[<>]t   (s   )?\s*(s   )(s   )\s*(s   ))*s   (from\s+(?P<diref>.*))s   \(\s*(?P<c1>t   |s   )\s*\)|(?P<c2>s   \s*)s   )*s   \[\s*(?P<ex>s   )?\s*\]s   (?P<dn>s	   \s*)?(\s*s   )?$s   (?P<op>s   )\s*(?P<vn>c         C   sk  d   } d  } t j |   } | rg| j   } | d } | d pK | d } | d sa d  } n d  } | d j   } | s d  } d } | d }	 n{ | d d k r d	 | } n  t j |  }
 g  |
 D] } | |  ^ q } d
 | d j g  | D] } d | ^ q  f }	 | d s$d  } n t j	 | d  } t
 d | d | d | d |	 d |  d |  } n  | S(   Nc         S   s   |  j    } | d | d f S(   Nt   opt   vn(   t	   groupdict(   t   mt   d(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_constraintT   s    t   dnt   c1t   c2t   direft    i    s   <>!=s   ~=s   %s (%s)s   , s   %s %st   ext   namet   constraintst   extrast   requirementt   sourcet   url(   t   Nonet   REQUIREMENT_REt   matchR   t   stript   RELOP_IDENT_REt   finditert   joint   COMMA_REt   splitR   (   t   sR   t   resultR   R   R&   t   consR+   t   constrt   rst   iteratort   conR(   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   parse_requirementR   s4    	

	0
	c         C   s   d   } i  } x | D] \ } } } t  j j |  |  } x t |  D] } t  j j | |  }	 x t |	  D]v }
 | |  |
  } | d k r | j | d  qo | | |
  } | j t  j j d  j d  } | d | | | <qo WqG Wq W| S(   s%   Find destinations for resources filesc         S   s\   |  j  t j j d  }  | j  t j j d  } | j |   sE t  | t |   j d  S(   Nt   /(   t   replacet   ost   patht   sept
   startswitht   AssertionErrort   lent   lstrip(   t   baseR@   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_rel_pathz   s    R=   N(	   R?   R@   R2   R   R,   t   popR>   RA   t   rstrip(   t   resources_roott   rulesRG   t   destinationsRF   t   suffixt   destt   prefixt   abs_baset   abs_globt   abs_patht   resource_filet   rel_patht   rel_dest(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_resources_destsw   s    	!c          C   s:   t  t d  r t }  n t j t t d t j  k }  |  S(   Nt   real_prefixt   base_prefix(   t   hasattrt   syst   TrueRO   t   getattr(   R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   in_venv   s    	c           C   s   t  j j t j  S(   N(   R?   R@   t   normcaseRZ   t
   executable(    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_executable   s    
c         C   s   |  } xw t  r t |  } |  } | r7 | r7 | } n  | r	 | d j   } | | k r] Pn  | r| d | | |  f } q| q	 q	 W| S(   Ni    s	   %c: %s
%s(   R[   R   t   lower(   t   promptt   allowed_charst   error_promptt   defaultt   pR5   t   c(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   proceed   s    		c         C   sV   t  | t  r | j   } n  i  } x+ | D]# } | |  k r+ |  | | | <q+ q+ W| S(   N(   t
   isinstanceR   R4   (   R   t   keysR6   t   key(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   extract_by_key   s    c         C   s  t  j d d k r+ t j d  |   }  n  |  j   } t |  }  y t j |   } | d d d } xo | j   D]a \ } } xR | j   D]D \ } } d | | f } t	 |  } | d  k	 s t  | | | <q Wqt W| SWn! t k
 r|  j d d  n Xt j   }	 t |	 d  r-|	 j |   n |	 j |   i  } xz |	 j   D]l }
 i  | |
 <} xU |	 j |
  D]D \ } } d | | f } t	 |  } | d  k	 st  | | | <qqWqMW| S(	   Ni    i   s   utf-8t
   extensionss   python.exportst   exportss   %s = %st	   read_file(   RZ   t   version_infot   codecst	   getreadert   readR   t   jsont   loadt   itemst   get_export_entryR,   RC   t	   Exceptiont   seekR   t   ConfigParserRY   Ro   t   readfpt   sections(   t   streamt   dataR6   t   groupt   entriest   kt   vR5   t   entryt   cpRk   R&   t   value(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   read_exports   s:    c         C   s   t  j d d k r+ t j d  |  } n  t j   } x |  j   D] \ } } | j |  x | j   D]u } | j	 d  k r | j } n d | j | j	 f } | j r d | d j | j  f } n  | j | | j |  qj WqD W| j |  d  S(   Ni    i   s   utf-8s   %s:%ss   %s [%s]s   , (   RZ   Rp   Rq   t	   getwriterR   Rz   Rv   t   add_sectiont   valuesRM   R,   RO   t   flagsR2   t   setR&   t   write(   Rn   R}   R   R   R   R   R5   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   write_exports   s    	c          c   s*   t  j   }  z	 |  VWd  t j |   Xd  S(   N(   t   tempfilet   mkdtempR   t   rmtree(   t   td(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   tempdir   s    	c         c   s7   t  j   } z t  j |   d  VWd  t  j |  Xd  S(   N(   R?   t   getcwdt   chdir(   R   t   cwd(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s
    	i   c         c   s7   t  j   } z t  j |   d  VWd  t  j |  Xd  S(   N(   t   sockett   getdefaulttimeoutt   setdefaulttimeout(   t   secondst   cto(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   socket_timeout  s
    	t   cached_propertyc           B   s   e  Z d    Z d d  Z RS(   c         C   s   | |  _  d  S(   N(   t   func(   t   selfR   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   __init__  s    c         C   s<   | d  k r |  S|  j |  } t j | |  j j |  | S(   N(   R,   R   t   objectt   __setattr__t   __name__(   R   t   objt   clsR   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   __get__  s
    N(   R   t
   __module__R   R,   R   (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s   	c         C   s   t  j d k r |  S|  s |  S|  d d k r@ t d |    n  |  d d k rc t d |    n  |  j d  } x# t  j | k r | j t  j  qu W| s t  j St  j j |   S(   s  Return 'pathname' as a name that will work on the native filesystem.

    The path is split on '/' and put back together again using the current
    directory separator.  Needed because filenames in the setup script are
    always supplied in Unix style, and have to be converted to the local
    convention before we can actually use them in the filesystem.  Raises
    ValueError on non-Unix-ish systems if 'pathname' either starts or
    ends with a slash.
    R=   i    s   path '%s' cannot be absoluteis   path '%s' cannot end with '/'(   R?   RA   t
   ValueErrorR4   t   curdirt   removeR@   R2   (   t   pathnamet   paths(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   convert_path#  s    
t   FileOperatorc           B   s   e  Z e d   Z d   Z d   Z d   Z e d  Z d d  Z
 d   Z d   Z d   Z d	   Z d
   Z e e d d  Z d   Z d   Z d   Z d   Z RS(   c         C   s#   | |  _  t   |  _ |  j   d  S(   N(   t   dry_runR   t   ensuredt   _init_record(   R   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   ?  s    	c         C   s%   t  |  _ t   |  _ t   |  _ d  S(   N(   t   Falset   recordR   t   files_writtent   dirs_created(   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   D  s    	c         C   s    |  j  r |  j j |  n  d  S(   N(   R   R   t   add(   R   R@   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   record_as_writtenI  s    	c         C   si   t  j j |  s1 t d t  j j |    n  t  j j |  sG t St  j |  j t  j |  j k S(   s  Tell if the target is newer than the source.

        Returns true if 'source' exists and is more recently modified than
        'target', or if 'source' exists and 'target' doesn't.

        Returns false if both exist and 'target' is the same age or younger
        than 'source'. Raise PackagingFileError if 'source' does not exist.

        Note that this test is not very accurate: files created in the same
        second will have the same "age".
        s   file '%r' does not exist(   R?   R@   t   existsR   t   abspathR[   t   statt   st_mtime(   R   R*   t   target(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   newerM  s    c         C   s   |  j  t j j |   t j d | |  |  j s d } | r t j j |  r` d | } q t j j	 |  r t j j
 |  r d | } q n  | r t | d   n  t j | |  n  |  j |  d S(   s8   Copy a file respecting dry-run and force flags.
        s   Copying %s to %ss   %s is a symlinks   %s is a non-regular files    which would be overwrittenN(   t
   ensure_dirR?   R@   t   dirnamet   loggert   infoR   R,   t   islinkR   t   isfileR   R   t   copyfileR   (   R   t   infilet   outfilet   checkt   msg(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt	   copy_filea  s    	%c         C   s   t  j j |  s t  |  j t  j j |   t j d | |  |  j s | d  k rl t
 | d  } n t j
 | d d | } z t j | |  Wd  | j   Xn  |  j |  d  S(   Ns   Copying stream %s to %st   wbt   wt   encoding(   R?   R@   t   isdirRC   R   R   R   R   R   R,   t   openRq   R   t   copyfileobjt   closeR   (   R   t   instreamR   R   t	   outstream(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   copy_streamr  s    	c         C   s[   |  j  t j j |   |  j sJ t | d   } | j |  Wd  QXn  |  j |  d  S(   NR   (   R   R?   R@   R   R   R   R   R   (   R   R@   R~   t   f(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   write_binary_file  s
    	c         C   sd   |  j  t j j |   |  j sS t | d   } | j | j |   Wd  QXn  |  j |  d  S(   NR   (	   R   R?   R@   R   R   R   R   t   encodeR   (   R   R@   R~   R   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   write_text_file  s
    	c         C   s   t  j d k s- t  j d k r t  j d k r xj | D]_ } |  j rV t j d |  q4 t  j |  j | B| @} t j d | |  t  j | |  q4 Wn  d  S(   Nt   posixt   javas   changing mode of %ss   changing mode of %s to %o(	   R?   R&   t   _nameR   R   R   R   t   st_modet   chmod(   R   t   bitst   maskt   filesR   t   mode(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   set_mode  s    -	c         C   s   |  j  d d |  S(   Nim  i  (   R   (   R5   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   <lambda>  s    c         C   s   t  j j |  } | |  j k r t  j j |  r |  j j |  t  j j |  \ } } |  j |  t j	 d |  |  j
 s t  j |  n  |  j r |  j j |  q n  d  S(   Ns   Creating %s(   R?   R@   R   R   R   R   R4   R   R   R   R   t   mkdirR   R   (   R   R@   R   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    "		c         C   s   t  | |  } t j d | |  |  j s | sD |  j | |  r{ | sS d  } q{ | j |  sh t  | t |  } n  t	 j
 | | | t  n  |  j |  | S(   Ns   Byte-compiling %s to %s(   R   R   R   R   R   R,   RB   RC   RD   t
   py_compilet   compileR[   R   (   R   R@   t   optimizet   forceRO   t   dpatht   diagpath(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   byte_compile  s    		c         C   s  t  j j |  rt  j j |  r t  j j |  r t j d |  |  j s` t j	 |  n  |  j
 r| |  j k r |  j j |  q qqt  j j |  r d } n d } t j d | |  |  j s t  j |  n  |  j
 r| |  j k r|  j j |  qqn  d  S(   Ns   Removing directory tree at %st   linkt   files   Removing %s %s(   R?   R@   R   R   R   R   t   debugR   R   R   R   R   R   R   (   R   R@   R5   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   ensure_removed  s"    %					c         C   sj   t  } x] | se t j j |  r: t j | t j  } Pn  t j j |  } | | k r\ Pn  | } q	 W| S(   N(   R   R?   R@   R   t   accesst   W_OKR   (   R   R@   R6   t   parent(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   is_writable  s    	
c         C   s/   |  j  s t  |  j |  j f } |  j   | S(   sV   
        Commit recorded changes, turn off recording, return
        changes.
        (   R   RC   R   R   R   (   R   R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   commit  s    
c         C   s   |  j  s x9 t |  j  D]( } t j j |  r t j |  q q Wt |  j d t	 } xq | D]f } t j
 |  } | r | d g k s t  t j j | | d  } t j |  n  t j |  qa Wn  |  j   d  S(   Nt   reverset   __pycache__i    (   R   t   listR   R?   R@   R   R   t   sortedR   R[   t   listdirRC   R2   t   rmdirR   (   R   R   t   dirsR   t   flistt   sd(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   rollback  s    	N(   R   R   R   R   R   R   R   R[   R   R,   R   R   R   R   t   set_executable_modeR   R   R   R   R   R   (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   >  s    											
c         C   s   |  t  j k r t  j |  } n t |   } | d  k r@ | } nG | j d  } t | | j d   } x | D] } t | |  } qn W| S(   Nt   .i    (   RZ   t   modulest
   __import__R,   R4   R\   RH   (   t   module_namet   dotted_patht   modR6   t   partsRf   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   resolve  s    	t   ExportEntryc           B   s;   e  Z d    Z e d    Z d   Z d   Z e j Z RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R&   RO   RM   R   (   R   R&   RO   RM   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    			c         C   s   t  |  j |  j  S(   N(   R  RO   RM   (   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   
  s    c         C   s    d |  j  |  j |  j |  j f S(   Ns   <ExportEntry %s = %s:%s %s>(   R&   RO   RM   R   (   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   __repr__  s    c         C   sd   t  | t  s t } nH |  j | j k o] |  j | j k o] |  j | j k o] |  j | j k } | S(   N(   Ri   R  R   R&   RO   RM   R   (   R   t   otherR6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   __eq__  s    	(	   R   R   R   R   R   R  R	  R   t   __hash__(    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR    s
   			
s   (?P<name>(\w|[-.])+)
                      \s*=\s*(?P<callable>(\w+)([:\.]\w+)*)
                      \s*(\[\s*(?P<flags>\w+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])?
                      c         C   sS  t  j |   } | sI d  } d |  k s3 d |  k rOt d |    qOn| j   } | d } | d } | j d  } | d k r | d  } } n4 | d k r t d |    n  | j d  \ } } | d	 }	 |	 d  k rd |  k s d |  k r	t d |    n  g  }	 n( g  |	 j d
  D] }
 |
 j   ^ q"}	 t | | | |	  } | S(   Nt   [t   ]s   Invalid specification %rR&   t   callablet   :i    i   R   t   ,(	   t   ENTRY_REt   searchR,   R   R   t   countR4   R/   R  (   t   specificationR   R6   R   R&   R@   t   colonsRO   RM   R   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyRw   %  s2    


	(c         C   s  |  d
 k r d }  n  t j d k rH d t j k rH t j j d  } n t j j d  } t j j |  r t j | t j	  } | s t
 j d |  q nG y t j |  t } Wn- t k
 r t
 j d | d t t } n X| s	t j   } t
 j d	 |  n  t j j | |   S(   s  
    Return the default base location for distlib caches. If the directory does
    not exist, it is created. Use the suffix provided for the base directory,
    and default to '.distlib' if it isn't provided.

    On Windows, if LOCALAPPDATA is defined in the environment, then it is
    assumed to be a directory, and will be the parent directory of the result.
    On POSIX, and on Windows if LOCALAPPDATA is not defined, the user's home
    directory - using os.expanduser('~') - will be the parent directory of
    the result.

    The result is just the directory '.distlib' in the parent directory as
    determined above, or with the name specified with ``suffix``.
    s   .distlibt   ntt   LOCALAPPDATAs   $localappdatat   ~s(   Directory exists but is not writable: %ss   Unable to create %st   exc_infos#   Default location unusable, using %sN(   R,   R?   R&   t   environR@   t
   expandvarst
   expanduserR   R   R   R   t   warningt   makedirsR[   t   OSErrorR   R   R   R2   (   RM   R6   t   usable(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_cache_baseD  s&    	

c         C   s`   t  j j t  j j |    \ } } | r? | j d d  } n  | j t  j d  } | | d S(   s  
    Convert an absolute path to a directory name for use in a cache.

    The algorithm used is:

    #. On Windows, any ``':'`` in the drive is replaced with ``'---'``.
    #. Any occurrence of ``os.sep`` is replaced with ``'--'``.
    #. ``'.cache'`` is appended.
    R  s   ---s   --s   .cache(   R?   R@   t
   splitdriveR   R>   RA   (   R@   R   Rf   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   path_to_cache_dirm  s
    
$c         C   s   |  j  d  s |  d S|  S(   NR=   (   t   endswith(   R5   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   ensure_slash~  s    c         C   sk   d  } } d |  k r^ |  j d d  \ } }  d | k rC | } q^ | j d d  \ } } n  | | |  f S(   Nt   @i   R  (   R,   R4   (   t   netloct   usernamet   passwordRO   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   parse_credentials  s    
	c          C   s    t  j d  }  t  j |   |  S(   Ni   (   R?   t   umask(   R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_process_umask  s    c         C   sX   t  } d  } x3 t |   D]% \ } } t | t  s t } Pq q W| d  k	 sT t  | S(   N(   R[   R,   t	   enumerateRi   R   R   RC   (   t   seqR6   t   iR5   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   is_string_sequence  s    s3   ([a-z0-9_]+([.-][a-z_][a-z0-9_]*)*)-([a-z0-9_.+-]+)s   -py(\d\.?\d?)c         C   s  d } d } t j |   } | rC | j d  } |  | j    }  n  | r t |   t |  d k r t j t j |  d |   } | r | j	   } |  |  |  | d | f } q n  | d k r t
 j |   } | r | j d  | j d  | f } q n  | S(   sw   
    Extract name, version, python version from a filename (no extension)

    Return name, version, pyver or None
    i   s   \bi   N(   R,   t   PYTHON_VERSIONR  R   t   startRD   t   reR.   t   escapet   endt   PROJECT_NAME_AND_VERSION(   t   filenamet   project_nameR6   t   pyverR   t   n(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   split_filename  s     "!'s-   (?P<name>[\w .-]+)\s*\(\s*(?P<ver>[^\s)]+)\)$c         C   sR   t  j |   } | s( t d |    n  | j   } | d j   j   | d f S(   s   
    A utility method used to get name and version from a string.

    From e.g. a Provides-Dist value.

    :param p: A value in a form 'foo (1.0)'
    :return: The name and version as a tuple.
    s$   Ill-formed name/version string: '%s'R&   t   ver(   t   NAME_VERSION_RER.   R   R   R/   Ra   (   Rf   R   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   parse_name_and_version  s
    	c         C   s	  t    } t  |  p g   }  t  | p' g   } d |  k rS |  j d  | | O} n  x |  D] } | d k r| | j |  qZ | j d  r | d } | | k r t j d |  n  | | k r| j |  qqZ | | k r t j d |  n  | j |  qZ W| S(   Nt   *t   -i   s   undeclared extra: %s(   R   R   R   RB   R   R  (   t	   requestedt	   availableR6   t   rt   unwanted(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt
   get_extras  s&    	
c         C   s   i  } ye t  |   } | j   } | j d  d k rF t j d  n$ t j d  |  } t j |  } Wn& t	 k
 r } t j
 d |  |  n X| S(   Ns   Content-Types   application/jsons$   Unexpected response for JSON requests   utf-8s&   Failed to get external data for %s: %s(   R	   R   t   getR   R   Rq   Rr   Rt   Ru   Rx   t	   exception(   R+   R6   t   respt   headerst   readert   e(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   _get_external_data  s    c         C   s*   d |  d j    |  f } t |  } | S(   Ns9   https://www.red-dove.com/pypi/projects/%s/%s/project.jsoni    (   t   upperRK  (   R&   R+   R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_project_data  s    c         C   s'   d |  d j    |  | f } t |  S(   Ns<   https://www.red-dove.com/pypi/projects/%s/%s/package-%s.jsoni    (   RL  RK  (   R&   t   versionR+   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_package_data   s    t   Cachec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   
    A class implementing a cache for resources that need to live in the file system
    e.g. shared libraries. This class was moved from resources to here because it
    could be used by other modules, e.g. the wheel module.
    c         C   sv   t  j j |  s" t  j |  n  t  j |  j d @d k rQ t j d |  n  t  j j t  j j	 |   |  _
 d S(   su   
        Initialise an instance.

        :param base: The base directory where the cache should be located.
        i?   i    s   Directory '%s' is not privateN(   R?   R@   R   R  R   R   R   R  R   t   normpathRF   (   R   RF   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s
    c         C   s
   t  |  S(   sN   
        Converts a resource prefix to a directory name in the cache.
        (   R"  (   R   RO   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   prefix_to_dir  s    c         C   s   g  } x t  j |  j  D] } t  j j |  j |  } yZ t  j j |  s^ t  j j |  rn t  j |  n" t  j j |  r t	 j
 |  n  Wq t k
 r | j |  q Xq W| S(   s"   
        Clear the cache.
        (   R?   R   RF   R@   R2   R   R   R   R   R   R   Rx   t   append(   R   t   not_removedt   fn(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   clear!  s    $(   R   R   t   __doc__R   RR  RV  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyRP    s   		t
   EventMixinc           B   s>   e  Z d  Z d   Z e d  Z d   Z d   Z d   Z RS(   s1   
    A very simple publish/subscribe system.
    c         C   s   i  |  _  d  S(   N(   t   _subscribers(   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   6  s    c         C   s\   |  j  } | | k r+ t | g  | | <n- | | } | rK | j |  n | j |  d S(   s`  
        Add a subscriber for an event.

        :param event: The name of an event.
        :param subscriber: The subscriber to be added (and called when the
                           event is published).
        :param append: Whether to append or prepend the subscriber to an
                       existing subscriber list for the event.
        N(   RY  R    RS  t
   appendleft(   R   t   eventt
   subscriberRS  t   subst   sq(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   9  s    
	
c         C   s=   |  j  } | | k r( t d |   n  | | j |  d S(   s   
        Remove a subscriber for an event.

        :param event: The name of an event.
        :param subscriber: The subscriber to be removed.
        s   No subscribers: %rN(   RY  R   R   (   R   R[  R\  R]  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   M  s    	c         C   s   t  |  j j | d   S(   s   
        Return an iterator for the subscribers for an event.
        :param event: The event to return subscribers for.
        (    (   t   iterRY  RE  (   R   R[  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   get_subscribersY  s    c         O   s   g  } xa |  j  |  D]P } y | | | |  } Wn$ t k
 rX t j d  d } n X| j |  q Wt j d | | | |  | S(   s^  
        Publish a event and return a list of values returned by its
        subscribers.

        :param event: The event to publish.
        :param args: The positional arguments to pass to the event's
                     subscribers.
        :param kwargs: The keyword arguments to pass to the event's
                       subscribers.
        s"   Exception during event publications/   publish %s: args = %s, kwargs = %s, result = %sN(   R`  Rx   R   RF  R,   RS  R   (   R   R[  t   argst   kwargsR6   R\  R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   publish`  s    
	(	   R   R   RW  R   R[   R   R   R`  Rc  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyRX  2  s   			t	   Sequencerc           B   sh   e  Z d    Z d   Z e d  Z d   Z d   Z d   Z d   Z	 e
 d    Z e
 d    Z RS(	   c         C   s"   i  |  _  i  |  _ t   |  _ d  S(   N(   t   _predst   _succsR   t   _nodes(   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   {  s    		c         C   s   |  j  j |  d  S(   N(   Rg  R   (   R   t   node(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   add_node  s    c         C   s  | |  j  k r" |  j  j |  n  | r	x3 t |  j j | d   D] } |  j | |  qD Wx3 t |  j j | d   D] } |  j | |  qz Wx6 t |  j j    D] \ } } | s |  j | =q q Wx9 t |  j j    D] \ } } | s |  j | =q q Wn  d  S(   N(    (    (   Rg  R   R   Re  RE  Rf  R   Rv   (   R   Rh  t   edgesRf   R5   R   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   remove_node  s    """"c         C   sT   | | k s t   |  j j | t    j |  |  j j | t    j |  d  S(   N(   RC   Re  t
   setdefaultR   R   Rf  (   R   t   predt   succ(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    c         C   s   | | k s t   y |  j | } |  j | } Wn! t k
 rS t d |   n Xy | j |  | j |  Wn' t k
 r t d | | f   n Xd  S(   Ns   %r not a successor of anythings   %r not a successor of %r(   RC   Re  Rf  t   KeyErrorR   R   (   R   Rm  Rn  t   predst   succs(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    c         C   s+   | |  j  k p* | |  j k p* | |  j k S(   N(   Re  Rf  Rg  (   R   t   step(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   is_step  s    c         C   s   |  j  |  s" t d |   n  g  } g  } t   } | j |  x | r | j d  } | | k r | | k r | j |  | j |  q qG | j |  | j |  |  j j | d  } | j	 |  qG Wt
 |  S(   Ns   Unknown: %ri    (    (   Rs  R   R   RS  RH   R   R   Re  RE  t   extendt   reversed(   R   t   finalR6   t   todot   seenRr  Rp  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt	   get_steps  s"    		c            sy   d g  g   i   i   g   |  j            f d    x'   D] } |  k rR  |  qR qR W S(   Ni    c            s@   d  |  < d  |  < d c d 7< j  |   y   |  } Wn t k
 r` g  } n Xxl | D]d } |  k r  |  t  |   |   |  <qh |  k rh t  |   |   |  <qh qh W |   |  k r<g  } x3 t r j   } | j  |  | |  k r Pq q Wt |  }  j  |  n  d  S(   Ni    i   (   RS  Rx   t   minR[   RH   t   tuple(   Rh  t
   successorst	   successort   connected_componentt	   component(   t   grapht   indext   index_countert   lowlinksR6   t   stackt   strongconnect(    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR    s.    

"	 (   Rf  (   R   Rh  (    (   R  R  R  R  R6   R  R  s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   strong_connections  s    		!"c         C   s   d g } xF |  j  D]; } |  j  | } x% | D] } | j d | | f  q- Wq Wx" |  j D] } | j d |  q\ W| j d  d j |  S(   Ns   digraph G {s     %s -> %s;s     %s;t   }s   
(   Re  RS  Rg  R2   (   R   R6   Rn  Rp  Rm  Rh  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   dot  s    	(   R   R   R   Ri  R   Rk  R   R   Rs  Ry  t   propertyR  R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyRd  z  s   						3s   .tar.gzs   .tar.bz2s   .tars   .zips   .tgzs   .tbzs   .whlc   
         s     f d   } t  j j      t     d  } | d  k r |  j d  rZ d } q |  j d  rx d } d } q |  j d  r d } d } q |  j d  r d } d } q t d |    n  z| d k rt |  d  } | rZ| j   } x | D] } | |  q WqZnB t	 j
 |  |  } | rZ| j   } x | D] } | |  qCWn  | d k rt j d d k  rxA | j   D]0 }	 t |	 j t  s|	 j j d  |	 _ qqWn  | j    Wd  | r| j   n  Xd  S(   Nc            s|   t  |  t  s! |  j d  }  n  t j j t j j   |    } | j    se |  t j k rx t	 d |   n  d  S(   Ns   utf-8s   path outside destination: %r(
   Ri   R   t   decodeR?   R@   R   R2   RB   RA   R   (   R@   Rf   (   t   dest_dirt   plen(    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt
   check_path
  s
    !#s   .zips   .whlt   zips   .tar.gzs   .tgzt   tgzs   r:gzs   .tar.bz2s   .tbzt   tbzs   r:bz2s   .tart   tarRB  s   Unknown format for %ri    i   s   utf-8(   s   .zips   .whl(   s   .tar.gzs   .tgz(   s   .tar.bz2s   .tbz(   R?   R@   R   RD   R,   R#  R   R   t   namelistt   tarfileR   t   getnamesRZ   Rp   t
   getmembersRi   R&   R   R  t
   extractallR   (
   t   archive_filenameR  t   formatR   R  t   archiveR   t   namesR&   t   tarinfo(    (   R  R  s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt	   unarchive  sH    				c      	   C   s   t  j   } t |   } t | d   } xu t j |   D]d \ } } } xR | D]J } t j j | |  } | | }	 t j j |	 |  }
 | j | |
  qP Wq: WWd QX| S(   s*   zip a directory tree into a BytesIO objectR   N(	   t   iot   BytesIORD   R   R?   t   walkR@   R2   R   (   t	   directoryR6   t   dlent   zft   rootR   R   R&   t   fullt   relRN   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   zip_dir>  s    
R$   t   Kt   Mt   Gt   Tt   Pt   Progressc           B   s   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z e d    Z	 e d	    Z
 d
   Z e d    Z e d    Z RS(   t   UNKNOWNi    id   c         C   sV   | d  k s | | k s t  | |  _ |  _ | |  _ d  |  _ d |  _ t |  _ d  S(   Ni    (	   R,   RC   Rz  t   curt   maxt   startedt   elapsedR   t   done(   R   t   minvalt   maxval(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   U  s    			c         C   s}   |  j  | k s t  |  j d  k s9 | |  j k s9 t  | |  _ t j   } |  j d  k ri | |  _ n | |  j |  _ d  S(   N(   Rz  RC   R  R,   R  t   timeR  R  (   R   t   curvalt   now(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   update]  s    $	c         C   s*   | d k s t   |  j |  j |  d  S(   Ni    (   RC   R  R  (   R   t   incr(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt	   incrementg  s    c         C   s   |  j  |  j  |  S(   N(   R  Rz  (   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR1  k  s    c         C   s/   |  j  d  k	 r" |  j |  j   n  t |  _ d  S(   N(   R  R,   R  R[   R  (   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   stopo  s    c         C   s   |  j  d  k r |  j S|  j  S(   N(   R  R,   t   unknown(   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   maximumt  s    c         C   sZ   |  j  r d } nD |  j d  k r* d } n, d |  j |  j |  j |  j } d | } | S(   Ns   100 %s    ?? %g      Y@s   %3d %%(   R  R  R,   R  Rz  (   R   R6   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt
   percentagex  s    			"
c         C   sU   | d k r |  j  d  k s- |  j |  j k r6 d } n t j d t j |   } | S(   Ni    s   ??:??:??s   %H:%M:%S(   R  R,   R  Rz  R  t   strftimet   gmtime(   R   t   durationR6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   format_duration  s    -	c         C   s   |  j  r d } |  j } n d } |  j d  k r9 d } ne |  j d k sZ |  j |  j k rc d } n; t |  j |  j  } | |  j |  j :} | d |  j } d | |  j |  f S(   Nt   Dones   ETA ii    i   s   %s: %s(   R  R  R  R,   R  Rz  t   floatR  (   R   RO   t   t(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   ETA  s    		!	c         C   sh   |  j  d k r d } n |  j |  j |  j  } x( t D]  } | d k  rL Pn  | d :} q6 Wd | | f S(   Ni    g        i  g     @@s   %d %sB/s(   R  R  Rz  t   UNITS(   R   R6   t   unit(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   speed  s    	(   R   R   R  R   R  R  R1  R  R  R  R  R  R  R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  R  s   	
					s   \{([^}]*)\}s   [^/\\,{]\*\*|\*\*[^/\\,}]s   ^[^{]*\}|\{[^}]*$c         C   sZ   t  j |   r( d } t | |    n  t j |   rP d } t | |    n  t |   S(   sA   Extended globbing function that supports ** and {opt1,opt2,opt3}.s7   invalid glob %r: recursive glob "**" must be used alones2   invalid glob %r: mismatching set marker '{' or '}'(   t   _CHECK_RECURSIVE_GLOBR  R   t   _CHECK_MISMATCH_SETt   _iglob(   t	   path_globR   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    c         c   s  t  j |  d  } t |  d k r t |  d k sB t |   | \ } } } x3| j d  D]4 } x+ t d j | | | f   D] } | Vq Wqa Wn d |  k r x t |   D] } | Vq Wn |  j d d  \ } } | d k r d } n  | d k r	d } n | j d  } | j d	  } x] t j	 |  D]L \ } } }	 t j
 j |  } x( t t j
 j | |   D] }
 |
 VqtWq7Wd  S(
   Ni   i   R  R$   s   **R   R>  R=   s   \(   t	   RICH_GLOBR4   RD   RC   R  R2   t	   std_iglobRE   R?   R  R@   RQ  (   R  t   rich_path_globRO   R   RM   t   itemR@   t   radicalt   dirR   RU  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR    s*    %		"t   HTTPSConnectionc           B   s   e  Z d Z e Z d    Z RS(   c      
   C   s  t  j |  j |  j f |  j  } t |  d t  rI | |  _ |  j   n  t	 t
 d  s |  j rm t
 j } n	 t
 j } t
 j | |  j |  j d | d t
 j d |  j |  _ n t
 j t
 j  } | j t
 j O_ |  j r | j |  j |  j  n  i  } |  j rHt
 j | _ | j d |  j  t t
 d t  rH|  j | d <qHn  | j | |  |  _ |  j r|  j ry0 t |  j j   |  j  t j d	 |  j  Wqt k
 r|  j j t  j  |  j j      qXn  d  S(
   Nt   _tunnel_hostt
   SSLContextt	   cert_reqst   ssl_versiont   ca_certst   cafilet   HAS_SNIt   server_hostnames   Host verified: %s(!   R   t   create_connectiont   hostt   portt   timeoutR\   R   t   sockt   _tunnelRY   t   sslR  t   CERT_REQUIREDt	   CERT_NONEt   wrap_sockett   key_filet	   cert_filet   PROTOCOL_SSLv23R  t   optionst   OP_NO_SSLv2t   load_cert_chaint   verify_modet   load_verify_locationst   check_domainR   t   getpeercertR   R   R   t   shutdownt	   SHUT_RDWRR   (   R   R  R  t   contextRb  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   connect  s>    !						N(   R   R   R,   R  R[   R  R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR    s   R   c           B   s&   e  Z e d   Z d   Z d   Z RS(   c         C   s#   t  j |   | |  _ | |  _ d  S(   N(   t   BaseHTTPSHandlerR   R  R  (   R   R  R  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    	c         O   s7   t  | |   } |  j r3 |  j | _ |  j | _ n  | S(   s  
        This is called to create a connection instance. Normally you'd
        pass a connection class to do_open, but it doesn't actually check for
        a class, and just expects a callable. As long as we behave just as a
        constructor would have, we should be OK. If it ever changes so that
        we *must* pass a class, we'll create an UnsafeHTTPSConnection class
        which just sets check_domain to False in the class definition, and
        choose which one to pass to do_open.
        (   R  R  R  (   R   Ra  Rb  R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   _conn_maker  s
    
	c         C   s_   y |  j  |  j |  SWnA t k
 rZ } d t | j  k rT t d | j   q[   n Xd  S(   Ns   certificate verify faileds*   Unable to verify server certificate for %s(   t   do_openR  R   t   strt   reasonR   R  (   R   t   reqRJ  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt
   https_open   s    (   R   R   R[   R   R  R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   
  s   	t   HTTPSOnlyHandlerc           B   s   e  Z d    Z RS(   c         C   s   t  d |   d  S(   NsA   Unexpected HTTP request on what should be a secure connection: %s(   R   (   R   R  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt	   http_open4  s    (   R   R   R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  3  s   i   i   t   HTTPc           B   s   e  Z d  d d  Z RS(   R$   c         K   s5   | d k r d  } n  |  j |  j | | |   d  S(   Ni    (   R,   t   _setupt   _connection_class(   R   R  R  Rb  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   @  s    	N(   R   R   R,   R   (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  ?  s   t   HTTPSc           B   s   e  Z d  d d  Z RS(   R$   c         K   s5   | d k r d  } n  |  j |  j | | |   d  S(   Ni    (   R,   R  R   (   R   R  R  Rb  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   G  s    	N(   R   R   R,   R   (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  F  s   t	   Transportc           B   s   e  Z d  d  Z d   Z RS(   i    c         C   s    | |  _  t j j |  |  d  S(   N(   R  R   R  R   (   R   R  t   use_datetime(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   N  s    	c         C   s   |  j  |  \ } } } t d k r< t | d |  j } nN |  j sY | |  j d k r} | |  _ | t j |  f |  _ n  |  j d } | S(   Ni   i   R  i    i   (   i   i   (   t   get_host_infot	   _ver_infoR  R  t   _connectiont   _extra_headersR
   t   HTTPConnection(   R   R  t   ht   eht   x509R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   make_connectionR  s    	(   R   R   R   R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  M  s   t   SafeTransportc           B   s   e  Z d  d  Z d   Z RS(   i    c         C   s    | |  _  t j j |  |  d  S(   N(   R  R   R  R   (   R   R  R  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   ^  s    	c         C   s   |  j  |  \ } } } | s' i  } n  |  j | d <t d k rU t | d  |  } nT |  j sr | |  j d k r | |  _ | t j | d  |  f |  _ n  |  j d } | S(   NR  i   i   i    i   (   i   i   (	   R  R  R  R  R,   R  R  R
   R  (   R   R  R	  R
  Rb  R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  b  s    		(   R   R   R   R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  ]  s   t   ServerProxyc           B   s   e  Z d    Z RS(   c   	      K   s   | j  d d   |  _ } | d  k	 r t |  \ } } | j d d  } | d k r^ t } n t } | | d | | d <} | |  _ n  t j	 j
 |  | |  d  S(   NR  R  i    t   httpst	   transport(   RH   R,   R  R   RE  R  R  R  R   R  R   (	   R   t   uriRb  R  t   schemet   _R  t   tclsR  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR   s  s    	(   R   R   R   (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR  r  s   c         K   s:   t  j d d k  r  | d 7} n
 d | d <t |  | |  S(   Ni    i   t   bR$   t   newline(   RZ   Rp   R   (   RU  R   Rb  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt	   _csv_open  s    
t   CSVBasec           B   sG   e  Z i e d   d 6e d  d 6e d  d 6Z d   Z d   Z RS(   R  t	   delimitert   "t	   quotechars   
t   lineterminatorc         C   s   |  S(   N(    (   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt	   __enter__  s    c         G   s   |  j  j   d  S(   N(   R}   R   (   R   R  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   __exit__  s    (   R   R   R  t   defaultsR  R  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR    s   	t	   CSVReaderc           B   s)   e  Z d    Z d   Z d   Z e Z RS(   c         K   s   d | k rM | d } t  j d d k rA t j d  |  } n  | |  _ n t | d d  |  _ t j |  j |  j  |  _ d  S(   NR}   i    i   s   utf-8R@   RB  (	   RZ   Rp   Rq   Rr   R}   R  t   csvRI  R  (   R   Rb  R}   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    
c         C   s   |  S(   N(    (   R   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   __iter__  s    c         C   sk   t  |  j  } t j d d k  rg xB t |  D]1 \ } } t | t  s/ | j d  | | <q/ q/ Wn  | S(   Ni    i   s   utf-8(   t   nextRI  RZ   Rp   R,  Ri   R   R  (   R   R6   R.  R  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR#    s    (   R   R   R   R"  R#  t   __next__(    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s   			t	   CSVWriterc           B   s   e  Z d    Z d   Z RS(   c         K   s1   t  | d  |  _ t j |  j |  j  |  _ d  S(   NR   (   R  R}   R!  t   writerR  (   R   RU  Rb  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    c         C   su   t  j d d k  ra g  } x< | D]4 } t | t  rG | j d  } n  | j |  q  W| } n  |  j j |  d  S(   Ni    i   s   utf-8(   RZ   Rp   Ri   R   R   RS  R&  t   writerow(   R   t   rowRB  R  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR'    s    	(   R   R   R   R'  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR%    s   	t   Configuratorc           B   sH   e  Z e e j  Z d  e d <d d  Z d   Z d   Z d   Z	 RS(   t   inc_convertt   incc         C   s/   t  t |   j |  | p% t j   |  _ d  S(   N(   t   superR)  R   R?   R   RF   (   R   t   configRF   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    c            s!     f d     | j  d  } t |  s?  j |  } n  | j  d d   } | j  d d  } | r t g  | D] }   |  ^ qs  } n  g  | D]( } t |  r |   | |  f ^ q } t |  } | | |   }	 | rx3 | j   D]" \ }
 } t |	 |
   |   q Wn  |	 S(   Nc            s   t  |  t t f  rC t |   g  |  D] }   |  ^ q%  } nj t  |  t  r d |  k rp  j |   } q i  } x4 |  D] }   |  |  | | <q} Wn  j |   } | S(   Ns   ()(   Ri   R   R{  t   typet   dictt   configure_customt   convert(   t   oR.  R6   R   (   R1  R   (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR1    s    .s   ()R   s   [](    (	   RH   R  R  R,   R{  R   R/  Rv   t   setattr(   R   R-  Rg   t   propsRa  R2  R   Rv   Rb  R6   R9  R   (    (   R1  R   s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR0    s    (5c         C   sI   |  j  | } t | t  rE d | k rE |  j |  |  j  | <} n  | S(   Ns   ()(   R-  Ri   R/  R0  (   R   Rk   R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   __getitem__  s    c         C   sa   t  j j |  s- t  j j |  j |  } n  t j | d d d  } t j |  } Wd QX| S(   s*   Default converter for the inc:// protocol.RB  R   s   utf-8N(	   R?   R@   t   isabsR2   RF   Rq   R   Rt   Ru   (   R   R   R   R6   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR*    s
    N(
   R   R   R/  R   t   value_convertersR,   R   R0  R5  R*  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR)    s   
		t   SubprocessMixinc           B   s)   e  Z e d d   Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   verboset   progress(   R   R9  R:  (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR     s    	c         C   s   |  j  } |  j } x{ t r | j   } | s1 Pn  | d k	 rM | | |  q | sf t j j d  n t j j | j d   t j j	   q W| j
   d S(   s   
        Read lines from a subprocess' output stream and either pass to a progress
        callable (if specified) or write progress information to sys.stderr.
        R   s   utf-8N(   R:  R9  R[   t   readlineR,   RZ   t   stderrR   R  t   flushR   (   R   R}   R  R:  R9  R5   (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyRI    s    			c         K   s   t  j | d t  j d t  j | } t j d |  j d | j d f  } | j   t j d |  j d | j d f  } | j   | j	   | j
   | j
   |  j d  k	 r |  j d d  n |  j r t j j d  n  | S(   Nt   stdoutR<  R   Ra  s   done.t   mains   done.
(   t
   subprocesst   Popent   PIPEt	   threadingt   ThreadRI  R>  R1  R<  t   waitR2   R:  R,   R9  RZ   R   (   R   t   cmdRb  Rf   t   t1t   t2(    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   run_command  s    $
$



	N(   R   R   R   R,   R   RI  RI  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyR8    s   	(   s   .tar.gzs   .tar.bz2s   .tars   .zips   .tgzs   .tbzs   .whl(   R$   R  R  R  R  R  (   i   i   (   Rq   t   collectionsR    t
   contextlibR!  t   globR   R  R  Rt   t   loggingR?   R   R2  R   R   R  R@  RZ   R  R   RC  t   ImportErrort   dummy_threadingR  R$   R   t   compatR   R   R   R   R   R	   R
   R   R   R   R   R  R   R   R   R   R   R   R   R   t	   getLoggerR   R   t   COMMAR   R3   t   IDENTt   EXTRA_IDENTt   VERSPECt   RELOPt   BARE_CONSTRAINTSt
   DIRECT_REFt   CONSTRAINTSt
   EXTRA_LISTt   EXTRASt   REQUIREMENTR-   t   RELOP_IDENTR0   R<   RV   R]   R`   R,   Rh   Rl   R   R   t   contextmanagerR   R   R   R   R   R   R   R  R  t   VERBOSER  Rw   R   R"  R$  R)  R+  R/  t   IR5  R0  R:  R<  R=  RD  RK  RM  RO  RP  RX  Rd  t   ARCHIVE_EXTENSIONSR[   R  R  R  R  R  R  R  R  R  R  Rp   R  R  R  R  R  R  R  R  R   R%  R)  R8  (    (    (    s5   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/distlib/util.pyt   <module>   s   
.	%		
				$	
				)					
						,H 6	]		!*)		: