
hyb\c           @   s]  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 y d  d l Z Wn e k
 r d Z n Xd  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/ m0 Z0 m1 Z1 e
 j2 e3  Z4 e j5 d  Z6 e j5 d  Z7 e j5 d	  Z8 e j5 d
  Z9 e j5 d  Z: e j5 d  Z; e j5 d  Z< e j5 d  Z= d   Z> d   Z? d   Z@ d   ZA d   ZB d d d  ZC d   ZD d   ZE d   ZF e jG d    ZH e jG d    ZI e jG d d   ZJ d eK f d     YZL d   ZM d eK f d      YZN d!   ZO d" eK f d#     YZP e j5 d$ e jQ  ZR d%   ZS d d&  ZT d'   ZU d(   ZV d)   ZW d*   ZX d+   ZY e j5 d, e jZ  Z[ e j5 d-  Z\ d d.  Z] e j5 d/  Z^ d0   Z_ d1   Z` d2   Za d3 Zb d4   Zc d5   Zd d6 eK f d7     YZe d8 eK f d9     YZf d: eK f d;     YZg dq Zh d ei dC  Zj dD   Zk dr Zl dK eK f dL     YZm e j5 dM  Zn e j5 dN  Zo e j5 dO  Zp dP   Z dQ   Zq e r.d dR l mr Zs mt Zt mu Zu dS e% jv f dT     YZv dU es f dV     YZr dW er e( f dX     YZw n  e jx dY  Zy ey ds k rd[ e% jz f d\     YZz e rd] e% j{ f d^     YZ{ qn  d_ e& j| f d`     YZ| e rda e& j} f db     YZ} n  dc e& j~ f dd     YZ~ de   Z df eK f dg     YZ dh e f di     YZ dj e f dk     YZ dl e) f dm     YZ dn eK f do     YZ dp   Z d S(t   iN(   t   deque(   t   iglobi   (   t   DistlibException(   t   string_typest	   text_typet   shutilt	   raw_inputt   StringIOt   cache_from_sourcet   urlopent   urljoint   httplibt	   xmlrpclibt	   splittypet   HTTPHandlert   BaseConfiguratort   valid_identt	   Containert   configparsert   URLErrort   ZipFilet   fsdecodet   unquotet   urlparses   ^([\w\.-]+)\s*s   ^([\w\.*+-]+)\s*s   ^(<=?|>=?|={2,3}|[~!]=)\s*s*   ^((<=?)|(>=?)|={2,3}|[~!]=|in|not\s+in)\s*s   ^or\b\s*s	   ^and\b\s*s   (\S+)\s*s(   ([\s\w\.{}()*+#:;,/?!~`@$%^&=|<>\[\]-]+)c            sC   d       f d     f d     f d       |   S(   se  
    Parse a marker string and return a dictionary containing a marker expression.

    The dictionary will contain keys "op", "lhs" and "rhs" for non-terminals in
    the expression grammar, or strings. A string contained in quotes is to be
    interpreted as a literal string, and a string not contained in quotes is a
    variable (such as os_name).
    c         S   s  t  j |   } | r8 | j   d } |  | j   }  nH|  sM t d   n3|  d } | d k rv t d |    n  d j | d  } |  d }  | g } x |  r4|  d | k r Pq |  d | k r | j |  |  d }  q t j |   } | s
t d |    n  | j | j   d  |  | j   }  q Wd j |  } t d |   | j |  d j |  } |  d j	   }  | |  f S(	   Ni    s   unexpected end of inputs   '"s   invalid expression: %st    i   s   error in string literal: %ss   unterminated string: %s(
   t
   IDENTIFIERt   matcht   groupst   endt   SyntaxErrort   replacet   appendt   STRING_CHUNKt   joint   lstrip(   t	   remainingt   mt   resultt   qt   oqt   partst   s(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt
   marker_varA   s:    

		c            s   |  rh |  d d k rh   |  d j     \ } }  |  d d k rU t d |    n  |  d j    }  n  |   \ } }  xp |  r t j |   } | s Pn  | j   d } |  | j   }   |   \ } }  i | d 6| d 6| d 6} q} W| } | |  f S(	   Ni    t   (i   t   )s   unterminated parenthesis: %st   opt   lhst   rhs(   R"   R   t	   MARKER_OPR   R   R   (   R#   R%   R.   R$   R-   R/   (   t   markerR*   (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   marker_expre   s     	c            s     |   \ } }  x` |  rt t  j |   } | s4 Pn  |  | j   }    |   \ } }  i d d 6| d 6| d 6} q W| |  f S(   Nt   andR-   R.   R/   (   t   ANDR   R   (   R#   R.   R$   R/   (   R2   (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt
   marker_andx   s    	c            s     |   \ } }  x` |  rt t  j |   } | s4 Pn  |  | j   }    |   \ } }  i d d 6| d 6| d 6} q W| |  f S(   Nt   orR-   R.   R/   (   t   ORR   R   (   R#   R.   R$   R/   (   R5   (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR1      s    	(    (   t   marker_string(    (   R1   R5   R2   R*   s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   parse_marker8   s
    		$c         C   s?  |  j    } | s" | j d  r& d St j |  } | sN t d |   n  | j   d } | | j   } d } } } } | r| d d k r| j d d  } | d k  r t d |   n  | d | !}	 | | d j	   } g  } x |	 rt j |	  } | st d |	   n  | j
 | j   d  |	 | j   }	 |	 sPPn  |	 d d	 k rst d
 |	   n  |	 d j	   }	 q W| sd } qn  | r^| d d k rA| d j	   } t j |  } | st d |   n  | j   d } t |  }
 |
 j o|
 j s(t d |   n  | | j   j	   } q^d   } | d d k ro| |  \ } } q^| j d d  } | d k  rt d |   n  | d | !}	 | | d j	   } t j |	  r| |	  \ } } q^t j |	  } | st d |	   n  | j   d } |	 | j   j	   }	 |	 rLt d |	   n  d | f g } n  | r| d d k rt d |   n  | d j	   } t |  \ } } n  | r| d d k rt d |   n  | s| } n0 d | d j g  | D] } d | ^ q f } t d | d | d | d | d | d |  S(    s   
    Parse a requirement passed in as a string. Return a Container
    whose attributes contain the various parts of the requirement.
    t   #s   name expected: %si    t   [t   ]i   s   unterminated extra: %ss   malformed extra: %st   ,s   comma expected in extras: %st   @s   invalid URI: %ss   Invalid URL: %sc         S   s  t  j |   } d } | rg  } x t r | j   d } |  | j   }  t j |   } | sr t d |    n  | j   d } | j | | f  |  | j   }  |  s |  d d k r Pn  |  d j	   }  t  j |   } | s$ t d |    q$ q$ W| sd } qn  | |  f S(   s|   
                Return a list of operator, version tuples if any are
                specified, else None.
                i    s   invalid version: %sR=   i   s   invalid constraint: %sN(
   t
   COMPARE_OPR   t   Nonet   TrueR   R   t   VERSION_IDENTIFIERR   R   R"   (   t   ver_remainingR$   t   versionsR-   t   v(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   get_versions   s,    	R+   R,   s   unterminated parenthesis: %ss   invalid constraint: %ss   ~=t   ;s   invalid requirement: %ss   unexpected trailing data: %ss   %s %ss   , t   namet   extrast   constraintsR1   t   urlt   requirementN(   t   stript
   startswithR@   R   R   R   R   R   t   findR"   R   t	   NON_SPACER   t   schemet   netlocR?   RB   R9   R!   R   (   t   reqR#   R$   t   distnameRI   t	   mark_exprRD   t   urit   iR)   t   tRF   t   _RE   t   rst   con(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   parse_requirement   s    			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   /(   R   t   ost   patht   sepRN   t   AssertionErrort   lenR"   (   t   rootR_   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   get_rel_path  s    R]   N(	   R^   R_   R!   R   R@   t   popR   R`   t   rstrip(   t   resources_roott   rulesRd   t   destinationst   baset   suffixt   destt   prefixt   abs_baset   abs_globt   abs_patht   resource_filet   rel_patht   rel_dest(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   get_resources_dests
  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   sysRA   Rm   t   getattr(   R%   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   in_venv$  s    	c          C   s7   t  j j t j  }  t |  t  s3 t |   }  n  |  S(   N(   R^   R_   t   normcaseRx   t
   executablet
   isinstanceR   R   (   R%   (    (    s7   /tmp/pip-install-3P1oDe/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(   RA   R   t   lower(   t   promptt   allowed_charst   error_promptt   defaultt   pR)   t   c(    (    s7   /tmp/pip-install-3P1oDe/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(   R}   R   t   split(   t   dt   keysR%   t   key(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   extract_by_keyN  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 Xd   }
 t j   } y |
 | |   WnF t j k
 rp|  j   t j |  } t |  }  |
 | |   n Xi  } xz | j   D]l } i  | | <} xU | j |  D]D \ } } d | | f } t	 |  }	 |	 d  k	 st  |	 | | <qWqW| S(	   Ni    i   s   utf-8t
   extensionss   python.exportst   exportss   %s = %sc         S   s0   t  |  d  r |  j |  n |  j |  d  S(   Nt	   read_file(   Rw   R   t   readfp(   t   cpt   stream(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   read_streamk  s    (   Rx   t   version_infot   codecst	   getreadert   readR   t   jsont   loadt   itemst   get_export_entryR@   Ra   t	   Exceptiont   seekR   t   ConfigParsert   MissingSectionHeaderErrort   closet   textwrapt   dedentt   sections(   R   t   datat   jdataR%   t   groupt   entriest   kRE   R)   t   entryR   R   R   RH   t   value(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   read_exportsW  sD    	
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   , (   Rx   R   R   t	   getwriterR   R   R   t   add_sectiont   valuesRk   R@   Rm   t   flagsR!   t   setRH   t   write(   R   R   R   R   RE   R   R)   (    (    s7   /tmp/pip-install-3P1oDe/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(    (    s7   /tmp/pip-install-3P1oDe/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(    (    s7   /tmp/pip-install-3P1oDe/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(    (    s7   /tmp/pip-install-3P1oDe/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   (    (    s7   /tmp/pip-install-3P1oDe/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   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   __get__  s
    N(   R   t
   __module__R   R@   R   (    (    (    s7   /tmp/pip-install-3P1oDe/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^   R`   t
   ValueErrorR   t   curdirt   removeR_   R!   (   t   pathnamet   paths(    (    s7   /tmp/pip-install-3P1oDe/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 e 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   (    (    s7   /tmp/pip-install-3P1oDe/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   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s    	c         C   s    |  j  r |  j j |  n  d  S(   N(   R   R   t   add(   R   R_   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   record_as_written  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   abspathRA   t   statt   st_mtime(   R   t   sourcet   target(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   newer  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(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt	   copy_file  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   isdirRa   R   R   R   R   R   R@   t   openR   R   t   copyfileobjR   R   (   R   t   instreamR   R   t	   outstream(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   copy_stream  s    	c         C   s}   |  j  t j j |   |  j sl t j j |  rD t j |  n  t | d   } | j |  Wd  QXn  |  j	 |  d  S(   NR   (
   R   R^   R_   R   R   R   R   R   R   R   (   R   R_   R   t   f(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   write_binary_file!  s    	c         C   s   |  j  | | j |   d  S(   N(   R   t   encode(   R   R_   R   R   (    (    s7   /tmp/pip-install-3P1oDe/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^   RH   t   _nameR   R   R   R   t   st_modet   chmod(   R   t   bitst   maskt   filesR   t   mode(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   set_mode-  s    -	c         C   s   |  j  d d |  S(   Nim  i  (   R  (   R)   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   <lambda>9  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   R   R   R   R   R   t   mkdirR   R   (   R   R_   R   R   (    (    s7   /tmp/pip-install-3P1oDe/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  i  } | r t	 t
 d  r t
 j j | d <n  t
 j | | | t |  n  |  j |  | S(   Ns   Byte-compiling %s to %st   PycInvalidationModet   invalidation_mode(   R   R   R   R   R   R@   RN   Ra   Rb   Rw   t
   py_compileR  t   CHECKED_HASHt   compileRA   R   (	   R   R_   t   optimizet   forceRm   t   hashed_invalidationt   dpatht   diagpatht   compile_kwargs(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   byte_compileG  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_   R)   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   ensure_removedX  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_   R%   t   parent(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   is_writablem  s    	
c         C   s/   |  j  s t  |  j |  j f } |  j   | S(   sV   
        Commit recorded changes, turn off recording, return
        changes.
        (   R   Ra   R   R   R   (   R   R%   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   commity  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   RA   t   listdirRa   R!   t   rmdirR   (   R   R   t   dirsR   t   flistt   sd(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   rollback  s    	N(   R   R   R   R   R   R   R   RA   R   R@   R   R   R   R  t   set_executable_modeR   R  R  R  R  R%  (    (    (    s7   /tmp/pip-install-3P1oDe/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    (   Rx   t   modulest
   __import__R@   R   Ry   Re   (   t   module_namet   dotted_patht   modR%   R(   R   (    (    s7   /tmp/pip-install-3P1oDe/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(   RH   Rm   Rk   R   (   R   RH   Rm   Rk   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s    			c         C   s   t  |  j |  j  S(   N(   R-  Rm   Rk   (   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s    c         C   s    d |  j  |  j |  j |  j f S(   Ns   <ExportEntry %s = %s:%s %s>(   RH   Rm   Rk   R   (   R   (    (    s7   /tmp/pip-install-3P1oDe/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(   R}   R.  R   RH   Rm   Rk   R   (   R   t   otherR%   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   __eq__  s    	(	   R   R   R   R   R   R/  R1  R   t   __hash__(    (    (    s7   /tmp/pip-install-3P1oDe/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(   NR;   R<   s   Invalid specification '%s'RH   t   callablet   :i    i   R   R=   (	   t   ENTRY_REt   searchR@   R   t	   groupdictt   countR   RM   R.  (   t   specificationR$   R%   R   RH   R_   t   colonsRm   Rk   R   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     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^   RH   t   environR_   t
   expandvarst
   expanduserR   R  R  R   t   warningt   makedirsRA   t   OSErrorR   R   R   R!   (   Rk   R%   t   usable(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   get_cache_base  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.
    R4  s   ---s   --s   .cache(   R^   R_   t
   splitdriveR   R   R`   (   R_   R   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   path_to_cache_dir  s
    
$c         C   s   |  j  d  s |  d S|  S(   NR]   (   t   endswith(   R)   (    (    s7   /tmp/pip-install-3P1oDe/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(   NR>   i   R4  (   R@   R   (   RR   t   usernamet   passwordRm   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   parse_credentials$  s    
	c          C   s    t  j d  }  t  j |   |  S(   Ni   (   R^   t   umask(   R%   (    (    s7   /tmp/pip-install-3P1oDe/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(   RA   R@   t	   enumerateR}   R   R   Ra   (   t   seqR%   RW   R)   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   is_string_sequence4  s    s3   ([a-z0-9_]+([.-][a-z_][a-z0-9_]*)*)-([a-z0-9_.+-]+)s   -py(\d\.?\d?)c         C   s  d } d } t |   j d d  }  t j |   } | r[ | 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
    t    t   -i   s   \bi   N(   R@   R   R   t   PYTHON_VERSIONR6  R   t   startRb   t   reR   t   escapeR   t   PROJECT_NAME_AND_VERSION(   t   filenamet   project_nameR%   t   pyverR$   t   n(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   split_filenameC  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'RH   t   ver(   t   NAME_VERSION_RER   R   R7  RM   R   (   R   R$   R   (    (    s7   /tmp/pip-install-3P1oDe/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   *RT  i   s   undeclared extra: %s(   R   R   R   RN   R   RB  (   t	   requestedt	   availableR%   t   rt   unwanted(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt
   get_extrasn  s&    	
c         C   s   i  } yq t  |   } | j   } | j d  } | j d  sR 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 request: %ss   utf-8s&   Failed to get external data for %s: %s(   R	   R   t   getRN   R   R  R   R   R   R   R   t	   exception(   RK   R%   t   respt   headerst   ctt   readert   e(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   _get_external_data  s    s'   https://www.red-dove.com/pypi/projects/c         C   s9   d |  d j    |  f } t t |  } t |  } | S(   Ns   %s/%s/project.jsoni    (   t   upperR
   t   _external_data_base_urlRo  (   RH   RK   R%   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   get_project_data  s    c         C   s6   d |  d j    |  | f } t t |  } t |  S(   Ns   %s/%s/package-%s.jsoni    (   Rp  R
   Rq  Ro  (   RH   t   versionRK   (    (    s7   /tmp/pip-install-3P1oDe/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   RC  R   R   R   RB  R   t   normpathRj   (   R   Rj   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s
    c         C   s
   t  |  S(   sN   
        Converts a resource prefix to a directory name in the cache.
        (   RH  (   R   Rm   (    (    s7   /tmp/pip-install-3P1oDe/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   Rj   R_   R!   R   R   R   R   R   R   R   R   (   R   t   not_removedt   fn(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   clear  s    $(   R   R   t   __doc__R   Rw  Rz  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRu    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   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     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(   R}  R    R   t
   appendleft(   R   t   eventt
   subscriberR   t   subst   sq(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     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(   R}  R   R   (   R   R  R  R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     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   iterR}  Rh  (   R   R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   get_subscribers  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  R   R   Ri  R@   R   R  (   R   R  t   argst   kwargsR%   R  R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   publish  s    
	(	   R   R   R{  R   RA   R   R   R  R  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR|    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   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s    		c         C   s   |  j  j |  d  S(   N(   R  R   (   R   t   node(    (    s7   /tmp/pip-install-3P1oDe/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(    (    (   R  R   R   R  Rh  R  R  R   (   R   R  t   edgesR   R)   R   RE   (    (    s7   /tmp/pip-install-3P1oDe/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(   Ra   R  t
   setdefaultR   R   R  (   R   t   predt   succ(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR   6  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(   Ra   R  R  t   KeyErrorR   R   (   R   R  R  t   predst   succs(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR   ;  s    c         C   s+   | |  j  k p* | |  j k p* | |  j k S(   N(   R  R  R  (   R   t   step(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   is_stepH  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    (    (   R  R   R   R   Re   R   R   R  Rh  t   extendt   reversed(   R   t   finalR%   t   todot   seenR  R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt	   get_stepsL  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   (   R   R   t   minRA   Re   t   tuple(   R  t
   successorst	   successort   connected_componentt	   component(   t   grapht   indext   index_countert   lowlinksR%   t   stackt   strongconnect(    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR  p  s.    

"	 (   R  (   R   R  (    (   R  R  R  R  R%   R  R  s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   strong_connectionse  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   
(   R  R   R  R!   (   R   R%   R  R  R  R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   dot  s    	(   R   R   R   R  R   R  R   R   R  R  t   propertyR  R  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR    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(
   R}   R   t   decodeR^   R_   R   R!   RN   R`   R   (   R_   R   (   t   dest_dirt   plen(    s7   /tmp/pip-install-3P1oDe/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   tarRe  s   Unknown format for %ri    i   s   utf-8(   s   .zips   .whl(   s   .tar.gzs   .tgz(   s   .tar.bz2s   .tbz(   R^   R_   R   Rb   R@   RI  R   R   t   namelistt   tarfileR   t   getnamesRx   R   t
   getmembersR}   RH   R   R  t
   extractallR   (
   t   archive_filenameR  t   formatR   R  t   archiveR  t   namesRH   t   tarinfo(    (   R  R  s7   /tmp/pip-install-3P1oDe/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   BytesIORb   R   R^   t   walkR_   R!   R   (   t	   directoryR%   t   dlent   zfRc   R"  R  RH   t   fullt   relRl   (    (    s7   /tmp/pip-install-3P1oDe/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@   Ra   R  t   curt   maxt   startedt   elapsedR   t   done(   R   t   minvalt   maxval(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     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(   R  Ra   R  R@   R  t   timeR  R  (   R   t   curvalt   now(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   update   s    $	c         C   s*   | d k s t   |  j |  j |  d  S(   Ni    (   Ra   R  R  (   R   t   incr(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt	   increment
  s    c         C   s   |  j  |  j  |  S(   N(   R  R  (   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRV    s    c         C   s/   |  j  d  k	 r" |  j |  j   n  t |  _ d  S(   N(   R  R@   R  RA   R  (   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   stop  s    c         C   s   |  j  d  k r |  j S|  j  S(   N(   R  R@   t   unknown(   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   maximum  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  R  (   R   R%   RE   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt
   percentage  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  R  R  t   strftimet   gmtime(   R   t   durationR%   (    (    s7   /tmp/pip-install-3P1oDe/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  R  t   floatR  (   R   Rm   RX   (    (    s7   /tmp/pip-install-3P1oDe/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  R  t   UNITS(   R   R%   t   unit(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   speedB  s    	(   R   R   R  R   R  R  RV  R  R  R  R  R  R  R  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR    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_GLOBR6  R   t   _CHECK_MISMATCH_SETt   _iglob(   t	   path_globR   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR   W  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'  Rb  R]   s   \(   t	   RICH_GLOBR   Rb   Ra   R  R!   t	   std_iglobR"   R^   R  R_   Rv  (   R  t   rich_path_globRm   R   Rk   t   itemR_   t   radicalt   dirR  Ry  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR  b  s*    %		"(   t   HTTPSHandlert   match_hostnamet   CertificateErrort   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   timeoutRy   R   t   sockt   _tunnelRw   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   contextR  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   connect  s>    !						N(   R   R   R@   R  RA   R  R  (    (    (    s7   /tmp/pip-install-3P1oDe/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  (    (    s7   /tmp/pip-install-3P1oDe/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   R  R  R%   (    (    s7   /tmp/pip-install-3P1oDe/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   RS   Rn  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt
   https_open  s    (   R   R   RA   R   R  R  (    (    (    s7   /tmp/pip-install-3P1oDe/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   RS   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt	   http_open  s    (   R   R   R!  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     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  R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s    	N(   R   R   R@   R   (    (    (    s7   /tmp/pip-install-3P1oDe/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  R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s    	N(   R   R   R@   R   (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR%    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(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     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   x509R%   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   make_connection  s    	(   R   R   R   R0  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR&    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   R1  R   (   R   R  R'  (    (    s7   /tmp/pip-install-3P1oDe/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.  R  R%   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR0  
  s    		(   R   R   R   R0  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR1    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(   Re   R@   R  R   Rh  R1  R&  R4  R   R2  R   (	   R   RV   R  R  RQ   RY   R'  t   tclsRX   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR     s    	(   R   R   R   (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR2    s   c         K   sD   t  j d d k  r  | d 7} n d | d <d | d <t |  | |  S(   Ni    i   t   bR   t   newlines   utf-8R   (   Rx   R   R   (   Ry  R  R  (    (    s7   /tmp/pip-install-3P1oDe/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   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt	   __enter__A  s    c         G   s   |  j  j   d  S(   N(   R   R   (   R   R>  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   __exit__D  s    (   R   R   R  t   defaultsR>  R?  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR9  :  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_   Re  (	   Rx   R   R   R   R   R8  t   csvRm  R@  (   R   R  R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR   I  s    
c         C   s   |  S(   N(    (   R   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   __iter__T  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   nextRm  Rx   R   RP  R}   R   R  (   R   R%   RW   R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRD  W  s    (   R   R   R   RC  RD  t   __next__(    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRA  H  s   			t	   CSVWriterc           B   s   e  Z d    Z d   Z RS(   c         K   s1   t  | d  |  _ t j |  j |  j  |  _ d  S(   NR   (   R8  R   RB  t   writerR@  (   R   Ry  R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR   b  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(   Rx   R   R}   R   R   R   RG  t   writerow(   R   t   rowRe  R  (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRH  f  s    	(   R   R   R   RH  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRF  a  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   superRJ  R   R^   R   Rj   (   R   t   configRj   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyR   y  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   ()(   R}   R  R  t   typet   dictt   configure_customt   convert(   t   oRW   R%   R   (   RR  R   (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRR  ~  s    .s   ()R'  s   [](    (	   Re   R3  R-  R@   R  R   RP  R   t   setattr(   R   RN  R   t   propsR  RS  R   R   R  R%   R]  RE   (    (   RR  R   s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRQ  }  s    (5c         C   sI   |  j  | } t | t  rE d | k rE |  j |  |  j  | <} n  | S(   Ns   ()(   RN  R}   RP  RQ  (   R   R   R%   (    (    s7   /tmp/pip-install-3P1oDe/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.Re  R   s   utf-8N(	   R^   R_   t   isabsR!   Rj   R   R   R   R   (   R   R   R   R%   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRK    s
    N(
   R   R   RP  R   t   value_convertersR@   R   RQ  RV  RK  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRJ  t  s   
		t   SubprocessMixinc           B   s/   e  Z d  Z e d d  Z d   Z d   Z RS(   sC   
    Mixin for running subprocesses and capturing their output
    c         C   s   | |  _  | |  _ d  S(   N(   t   verboset   progress(   R   RZ  R[  (    (    s7   /tmp/pip-install-3P1oDe/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[  RZ  RA   t   readlineR@   Rx   t   stderrR   R  t   flushR   (   R   R   R  R[  RZ  R)   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRm    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   R  s   done.t   mains   done.
(   t
   subprocesst   Popent   PIPEt	   threadingt   ThreadRm  R_  RV  R]  t   waitR!   R[  R@   RZ  Rx   R   (   R   t   cmdR  R   t   t1t   t2(    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   run_command  s    $
$



	N(   R   R   R{  R   R@   R   Rm  Rj  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyRY    s   	c         C   s   t  j d d |   j   S(   s,   Normalize a python package name a la PEP 503s   [-_.]+RT  (   RW  t   subR   (   RH   (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   normalize_name  s    (   s   .tar.gzs   .tar.bz2s   .tars   .zips   .tgzs   .tbzs   .whl(   R   R  R  R  R  R  (   i   i   (   R   t   collectionsR    t
   contextlibRB  t   globR   R  R  R   t   loggingR^   R	  RW  R   R  t   ImportErrorR@   Ra  Rx   R  R   R   Rd  t   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   R   t	   getLoggerR   R   R  R   RB   R?   R0   R7   R4   RP   R    R9   R\   Rt   Rz   R~   R   R   R   R   t   contextmanagerR   R   R   R   R   R   R   R-  R.  t   VERBOSER5  R   RF  RH  RJ  RM  RO  RR  t   IRY  RU  R^  R`  Ra  Rg  Ro  Rq  Rr  Rt  Ru  R|  R  t   ARCHIVE_EXTENSIONSRA   R  R  R  R  R  R  R  R  R  R  R  R  R  R   R   R)  R"  R%  R&  R1  R2  R8  R9  RA  RF  RJ  RY  Rl  (    (    (    s7   /tmp/pip-install-3P1oDe/pip/pip/_vendor/distlib/util.pyt   <module>   s   
	Y	y		
				/	
				)					
						,H 6	]		*)		7.