ó
'šMc           @   sU  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	 m
 Z
 d  d l m Z m Z m Z d  d l m Z m Z d  d l m Z d d d d	 d
 d d d d d d d d d d d d d d d d d d g Z e d „ Z d „  Z d „  Z d  d! „ Z d d d" „ Z d# „  Z d$ e f d% „  ƒ  YZ e ƒ  Z [ e j  d& e j! ƒ Z" d' „  Z# d( „  Z$ d) „  Z% d* „  Z& d+ „  Z' d, „  Z( d- „  Z) d. „  Z* d/ „  Z+ d0 „  Z, d1 „  Z- d2 „  Z. d3 „  Z/ e0 d@ d7 „ Z1 d8 „  Z2 d9 „  Z3 d: „  Z4 e0 d; „ Z5 d< „  Z6 d= „  Z7 d> „  Z8 d? „  Z9 d S(A   iÿÿÿÿN(   t   InstallationError(   t   WindowsErrort   string_typest	   raw_input(   t   site_packagest   running_under_virtualenv(   t   loggert   rmtreet   display_patht
   backup_dirt   find_commandt   askt   Inft   normalize_namet   splitextt   format_sizet   is_installable_dirt   is_svn_paget   file_contentst   split_leading_dirt   has_leading_dirt   make_path_relativet   normalize_patht   renamest   get_terminal_sizet
   unzip_filet
   untar_filet   create_download_cache_foldert   cache_downloadt   unpack_filec         C   s   t  j |  d | d t ƒd  S(   Nt   ignore_errorst   onerror(   t   shutilR   t   rmtree_errorhandler(   t   dirR   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR      s    c         C   s   | d  \ } } | t  k r/ | j d d k pK | t k oK | j d d k sT ‚  n  t j | ƒ j t j @t j k r| ‚  n  t j | t j ƒ |  | ƒ d S(   sÑ   On Windows, the files in .svn are read-only, so when rmtree() tries to
    remove them, an exception is thrown.  We catch that here, remove the
    read-only attribute, and hopefully continue without problems.i   i    i   i   N(	   R   t   argst   OSErrort   ost   statt   st_modet   S_IREADt   chmodt   S_IWRITE(   t   funct   patht   exc_infot   exctypet   value(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR!       s    "c         C   s^   t  j j t  j j |  ƒ ƒ }  |  j t  j ƒ  t  j j ƒ rZ d |  t t  j ƒ  ƒ }  n  |  S(   sT   Gives the display value for a given path, making it relative to cwd
    if possible.t   .(   R%   R,   t   normcaset   abspatht
   startswitht   getcwdt   sept   len(   R,   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   3   s    s   .bakc         C   sK   d } | } x4 t  j j |  | ƒ rB | d 7} | t | ƒ } q W|  | S(   s\   Figure out the name of a directory to back up the given dir to
    (adding .bak, .bak2, etc)i   (   R%   R,   t   existst   str(   R"   t   extt   nt	   extension(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR	   <   s    
c         C   s9  | d k r0 t j j d g  ƒ j t j ƒ } n  t | t ƒ rK | g } n  | d k ro t j j d d ƒ } n  g  | j ƒ  j t j ƒ D] } | ^ qˆ } t j	 j
 |  ƒ d j ƒ  | k rÈ d g } n  xj | D]b } t j	 j | |  ƒ } x. | D]& } | | } t j	 j | ƒ rñ | Sqñ Wt j	 j | ƒ rÏ | SqÏ Wd S(   s<   Searches the PATH for the given command and returns its patht   PATHt   PATHEXTs   .COM;.EXE;.BAT;.CMDi   t    N(   t   NoneR%   t   environt   gett   splitt   pathsept
   isinstanceR   t   lowerR,   R   t   joint   isfile(   t   cmdt   pathst   pathextR9   R,   t   cmd_patht   cmd_path_ext(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR
   G   s$    $+"
c         C   sx   xq t  j j d ƒ r( t d |  ƒ ‚ n  t |  ƒ } | j ƒ  j ƒ  } | | k rm d | d j | ƒ f GHq | Sq d S(   s@   Ask the message interactively, with the given possible responsest   PIP_NO_INPUTs7   No input was expected ($PIP_NO_INPUT set); question: %ss<   Your response (%r) was not one of the expected responses: %ss   , N(   R%   R@   RA   t	   ExceptionR   t   stripRE   RF   (   t   messaget   optionst   response(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   b   s    t   _Infc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   I am bigger than everything!c         C   s   |  | k r d Sd S(   Ni    i   (    (   t   selft   a(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   __cmp__r   s    c         C   s   d S(   NR   (    (   RT   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   __repr__w   s    (   t   __name__t
   __module__t   __doc__RV   RW   (    (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyRS   p   s   	s   [^a-z]c         C   s   t  j d |  j ƒ  ƒ S(   Nt   -(   t   _normalize_ret   subRE   (   t   name(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR      s    c         C   sX   |  d k r d |  d d S|  d	 k r4 d |  d S|  d k rL d |  d Sd |  Sd  S(
   Niè  s   %.1fMbg     @@i
   s   %iKbs   %.1fKbs   %ibytesi@B i'  (    (   t   bytes(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   …   s    c         C   sE   t  j j |  ƒ s t St  j j |  d ƒ } t  j j | ƒ rA t St S(   s@   Return True if `path` is a directory containing a setup.py file.s   setup.py(   R%   R,   t   isdirt   FalseRF   RG   t   True(   R,   t   setup_py(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR      s    c         C   s(   t  j d |  ƒ o' t  j d |  t  j ƒ S(   sJ   Returns true if the page appears to be the index page of an svn repositorys   <title>[^<]*Revision \d+:s#   Powered by (?:<a[^>]*?>)?Subversion(   t   ret   searcht   I(   t   html(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   š   s    c         C   s8   t  |  d ƒ } z | j ƒ  j d ƒ SWd  | j ƒ  Xd  S(   Nt   rbs   utf-8(   t   opent   readt   decodet   close(   t   filenamet   fp(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR       s    c         C   s    t  |  ƒ }  |  j d ƒ j d ƒ }  d |  k rv d |  k rZ |  j d ƒ |  j d ƒ k  sf d |  k rv |  j d d ƒ Sd |  k r’ |  j d d ƒ S|  d f Sd  S(   Nt   /s   \i   R>   (   R8   t   lstript   findRB   (   R,   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   ¨   s    6c         C   s\   d } xO |  D]G } t | ƒ \ } } | s/ t S| d k rD | } q | | k r t Sq Wt S(   sy   Returns true if all the paths have the same leading path name
    (i.e., everything is in one subdirectory in an archive)N(   R?   R   Ra   Rb   (   RI   t   common_prefixR,   t   prefixt   rest(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   ´   s    	c         C   s7  t  j j |  ƒ } t  j j |  ƒ }  t  j j t  j j |  ƒ ƒ }  t  j j t  j j | ƒ ƒ } |  j t  j j ƒ j t  j j ƒ } | j t  j j ƒ j t  j j ƒ } x> | rè | rè | d | d k rè | j	 d ƒ | j	 d ƒ q« Wd g t
 | ƒ | | g } | d g k r$d t  j j St  j j j | ƒ S(   s  
    Make a filename relative, where the filename path, and it is
    relative to rel_to

        >>> make_relative_path('/usr/share/something/a-file.pth',
        ...                    '/usr/share/another-place/src/Directory')
        '../../../something/a-file.pth'
        >>> make_relative_path('/usr/share/something/a-file.pth',
        ...                    '/home/user/src/Directory')
        '../../../usr/share/something/a-file.pth'
        >>> make_relative_path('/usr/share/a-file.pth', '/usr/share/')
        'a-file.pth'
    i    s   ..R>   R0   (   R%   R,   t   basenamet   dirnamet   normpathR2   RO   R5   RB   t   popR6   RF   (   R,   t   rel_tot   path_filenamet
   path_partst   rel_to_partst
   full_parts(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   Ã   s    $$#c         C   s   t  j j t  j j |  ƒ ƒ S(   sN   
    Convert a path to its canonical, case-normalized, absolute version.

    (   R%   R,   R1   t   realpath(   R,   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   à   s    c         C   sO   t  j |  ƒ \ } } | j ƒ  j d ƒ rE | d | } | d  } n  | | f S(   s,   Like os.path.splitext, but take off .tar toos   .tariüÿÿÿ(   t	   posixpathR   RE   t   endswith(   R,   t   baseR9   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   è   s
    c         C   s§   t  j j | ƒ \ } } | rG | rG t  j j | ƒ rG t  j | ƒ n  t j |  | ƒ t  j j |  ƒ \ } } | r£ | r£ y t  j | ƒ Wq£ t k
 rŸ q£ Xn  d S(   s7   Like os.renames(), but handles renaming across devices.N(	   R%   R,   RB   R7   t   makedirsR    t   movet
   removedirsR$   (   t   oldt   newt   headt   tail(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   ñ   s    c         C   s)   t  ƒ  s t St |  ƒ j t t j ƒ ƒ S(   s›   
    Return True if path is within sys.prefix, if we're running in a virtualenv.

    If we're not in a virtualenv, all paths are considered "local."

    (   R   Rb   R   R3   t   sysRs   (   R,   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   is_local  s    	c         C   s   t  t |  ƒ ƒ S(   s   
    Return True if given Distribution object is installed locally
    (i.e. within current virtualenv).

    Always True if we're not in a virtualenv.

    (   RŠ   t   dist_location(   t   dist(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   dist_is_local  s    t
   setuptoolst   pipt   pythonc         C   sM   |  r t  } n	 d „  } g  t j D]' } | | ƒ r" | j | k r" | ^ q" S(   sX  
    Return a list of installed Distribution objects.

    If ``local_only`` is True (default), only return installations
    local to the current virtualenv, if in a virtualenv.

    ``skip`` argument is an iterable of lower-case project names to
    ignore; defaults to ('setuptools', 'pip', 'python'). [FIXME also
    skip virtualenv?]

    c         S   s   t  S(   N(   Rb   (   t   d(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   <lambda>(  s    (   R   t   pkg_resourcest   working_sett   key(   t
   local_onlyt   skipt
   local_testR‘   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   get_installed_distributions  s    		c         C   s   t  j j t |  j ƒ d S(   sO  
    Return the path where we'd expect to find a .egg-link file for
    this distribution. (There doesn't seem to be any metadata in the
    Distribution object for a develop egg that points back to its
    .egg-link and easy-install.pth files).

    This won't find a globally-installed develop egg if we're in a
    virtualenv.

    s	   .egg-link(   R%   R,   RF   R   t   project_name(   RŒ   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   egg_link_path,  s    c         C   s)   t  |  ƒ } t j j | ƒ r" | S|  j S(   sÿ   
    Get the site-packages location of this distribution. Generally
    this is dist.location, except in the case of develop-installed
    packages, where dist.location is the source code location, and we
    want to know where the egg-link file is.

    (   R›   R%   R,   R7   t   location(   RŒ   t   egg_link(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR‹   :  s    c          C   sÉ   d „  }  |  d ƒ p* |  d ƒ p* |  d ƒ } | sx y8 t  j t  j ƒ  t  j ƒ } |  | ƒ } t  j | ƒ Wqx qx Xn  | s« t  j j d d ƒ t  j j d d ƒ f } n  t | d ƒ t | d ƒ f S(	   sl   Returns a tuple (x, y) representing the width(x) and the height(x)
    in characters of the terminal window.c         S   s{   yL d d  l  } d d  l } d d  l } | j d | j |  | j d ƒ ƒ } Wn d  SX| d k rg d  S| d k rw d  S| S(   Niÿÿÿÿt   hht   1234i    (   i    i    (   i    i    (   t   fcntlt   termiost   structt   unpackt   ioctlt
   TIOCGWINSZR?   (   t   fdR    R¡   R¢   t   cr(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   ioctl_GWINSZK  s    i    i   i   t   LINESi   t   COLUMNSiP   (   R%   Ri   t   ctermidt   O_RDONLYRl   R@   RA   t   int(   R¨   R§   R¦   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   H  s    	$-c         C   sm  t  j j | ƒ s" t  j | ƒ n  t |  d ƒ } z*t j | ƒ } t | j ƒ  ƒ oX | } xü | j ƒ  D]î } | j	 | ƒ } | } | rœ t
 | ƒ d } n  t  j j | | ƒ } t  j j | ƒ }	 t  j j |	 ƒ så t  j |	 ƒ n  | j d ƒ s| j d ƒ r(t  j j | ƒ sVt  j | ƒ qVqh t | d ƒ }
 z |
 j | ƒ Wd |
 j ƒ  Xqh WWd | j ƒ  Xd S(   sM   Unzip the file (zip file located at filename) to the destination
    locationRh   i   Ro   s   \t   wbN(   R%   R,   R7   R‚   Ri   t   zipfilet   ZipFileR   t   namelistRj   R   RF   Rv   R€   t   writeRl   (   Rm   Rœ   t   flattent   zipfpt   zipt   leadingR^   t   datat   fnR"   Rn   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   f  s.    c      	   C   s  t  j j | ƒ s" t  j | ƒ n  |  j ƒ  j d ƒ sL |  j ƒ  j d ƒ rU d } nh |  j ƒ  j d ƒ s |  j ƒ  j d ƒ rˆ d } n5 |  j ƒ  j d ƒ r¦ d } n t j d	 |  ƒ d
 } t j	 |  | ƒ } zžt
 g  | j ƒ  D] } | j d k râ | j ^ qâ ƒ } x`| j ƒ  D]R} | j } | d k r7qn  | rPt | ƒ d } n  t  j j | | ƒ } | j ƒ  r–t  j j | ƒ sht  j | ƒ qhqy | j | ƒ } WnG t t f k
 ròt j ƒ  d }	 t j d |  | j |	 f ƒ qn Xt  j j t  j j | ƒ ƒ s-t  j t  j j | ƒ ƒ n  t	 | d ƒ }
 z t j | |
 ƒ Wd |
 j ƒ  X| j ƒ  qWWd | j ƒ  Xd S(   sI   Untar the file (tar file located at filename) to the destination locations   .gzs   .tgzs   r:gzs   .bz2s   .tbzs   r:bz2s   .tart   rs-   Cannot determine compression type for file %ss   r:*t   pax_global_headeri   s/   In the tar file %s the member %s is invalid: %sR®   N(   R%   R,   R7   R‚   RE   R€   R   t   warnt   tarfileRi   R   t
   getmembersR^   R   RF   R`   t   extractfilet   KeyErrort   AttributeErrorR‰   R-   Rv   R    t   copyfileobjRl   (   Rm   Rœ   t   modet   tart   memberR¶   R¸   R,   Rn   t   et   destfp(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   †  sR    *	*		!	c         C   s@   t  j d 8_ t  j d |  ƒ t  j d 7_ t j |  ƒ d  S(   Ni   s&   Creating supposed download cache at %s(   R   t   indentt   notifyR%   R‚   (   t   folder(    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   »  s    c         C   sb   t  j d t |  ƒ ƒ t j | |  ƒ t |  d d ƒ } | j | ƒ | j ƒ  t j	 | ƒ d  S(   Ns   Storing download in cache at %ss   .content-typet   w(
   R   RÈ   R   R    t   copyfileRi   R²   Rl   R%   t   unlink(   t   target_filet   temp_locationt   content_typeRn   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   Â  s    
c         C   s"  | d k s9 |  j  d ƒ s9 |  j  d ƒ s9 t j |  ƒ rY t |  | d |  j  d ƒ ƒnÅ | d k s t j |  ƒ s t |  ƒ d j ƒ  d k r  t |  | ƒ n~ | rô | j	 d ƒ rô t
 t |  ƒ ƒ rô d d l m } | d | j ƒ j | ƒ n* t j d |  | | f ƒ t d | ƒ ‚ d  S(   Ns   application/zips   .zips	   .pybundleR³   s   application/x-gzipi   s   .tars   .tar.gzs   .tar.bz2s   .tgzs   .tbzs	   text/htmliÿÿÿÿ(   t
   Subversions   svn+sZ   Cannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formats%   Cannot determine archive format of %s(   s   .tars   .tar.gzs   .tar.bz2s   .tgzs   .tbz(   R€   R¯   t
   is_zipfileR   R¼   t
   is_tarfileR   RE   R   R3   R   R   t   pip.vcs.subversionRÐ   t   urlR£   R   t   fatalR    (   Rm   Rœ   RÏ   t   linkRÐ   (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyR   Ë  s      	(   RŽ   R   s   python(:   R‰   R    R%   R&   Rd   R   R“   R¯   R¼   t   pip.exceptionsR    t   pip.backwardcompatR   R   R   t   pip.locationsR   R   t   pip.logR   t   __all__Ra   R   R!   R   R	   R?   R
   R   t   objectRS   R   t   compileRf   R\   R   R   R   R   R   R   R   R   R   R   R   RŠ   R   Rb   R™   R›   R‹   R   R   R   R   R   R   (    (    (    s,   /usr/lib/python2.7/dist-packages/pip/util.pyt   <module>   sl   							
				
														 	5			