ó
û_¾Tc           @   sp  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
 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 d# „ Z 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, d0 „  Z- d1 „  Z. d2 „  Z/ d3 „  Z0 d4 „  Z1 d5 „  Z2 e3 dB d9 „ Z4 d: „  Z5 d; „  Z6 d< „  Z7 e3 d= „ Z8 d> „  Z9 d? „  Z: d@ „  Z; dA „  Z< d S(C   iÿÿÿÿN(   t   InstallationErrort
   BadCommand(   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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR
   <   s    
c         C   s=  | d k r0 t j j d d ƒ j t j ƒ } n  t | t ƒ rK | g } n  | d k rc t ƒ  } 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Ã Wt d |  ƒ ‚ d S(   s<   Searches the PATH for the given command and returns its patht   PATHt    i   s   Cannot find command %rN(   t   NoneR&   t   environt   gett   splitt   pathsept
   isinstanceR   t   get_pathextt   lowerR-   R   t   joint   isfileR   (   t   cmdt   pathst   pathextR:   R-   t   cmd_patht   cmd_path_ext(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR   G   s$    $+"
c         C   sF   |  d k r- t j j d d d d g ƒ }  n  t j j d |  ƒ } | S(   s9   Returns the path extensions from environment or a defaults   .COMs   .EXEs   .BATs   .CMDt   PATHEXTN(   R?   R&   RC   RG   R@   RA   (   t   default_pathextRK   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyRE   b   s    !c         C   s=   x- t  j j d d ƒ D] } | | k r | Sq Wt |  | ƒ S(   Nt   PIP_EXISTS_ACTIONR>   (   R&   R@   RA   R   (   t   messaget   optionst   action(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyt   ask_path_existsj   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   stripRF   RG   (   RQ   RR   t   response(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR   q   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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyt   __cmp__   s    c         C   s   d S(   NR   (    (   RZ   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyt   __repr__†   s    (   t   __name__t
   __module__t   __doc__R\   R]   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyRY      s   	s   [^a-z]c         C   s   t  j d |  j ƒ  ƒ S(   Nt   -(   t   _normalize_ret   subRF   (   t   name(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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   FalseRG   RH   t   True(   R-   t   setup_py(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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>   (   R9   t   lstript   findRB   (   R-   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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   Rg   Rh   (   RJ   t   common_prefixR-   t   prefixt   rest(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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>   R1   (   R&   R-   t   basenamet   dirnamet   normpathR3   RW   R6   RB   t   popR7   RG   (   R-   t   rel_tot   path_filenamet
   path_partst   rel_to_partst
   full_parts(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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-   R2   t   realpath(   R-   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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   RF   t   endswith(   R-   t   baseR:   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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   R8   t   makedirsR!   t   movet
   removedirsR%   (   t   oldt   newt   headt   tail(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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   Rh   R   R4   t   sysRy   (   R-   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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(   Rh   (   t   d(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyt   <lambda>7  s    (   R“   t   pkg_resourcest   working_sett   key(   t
   local_onlyt   skipt
   local_testR—   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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-   RG   R   t   project_name(   R’   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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-   R8   t   location(   R’   t   egg_link(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR‘   I  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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyt   ioctl_GWINSZZ  s    i    i   i   t   LINESi   t   COLUMNSiP   (   R&   Ro   t   ctermidt   O_RDONLYRr   R@   RA   t   int(   R®   R­   R¬   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR   W  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
    locationRn   i   Ru   s   \t   wbN(   R&   R-   R8   Rˆ   Ro   t   zipfilet   ZipFileR   t   namelistRp   R   RG   R|   R†   t   writeRr   (   Rs   R¢   t   flattent   zipfpt   zipt   leadingRd   t   datat   fnR#   Rt   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR   u  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]¯} | j } | d k r7qn  | rPt | ƒ d } n  t  j j | | ƒ } | j ƒ  r–t  j j | ƒ sÅt  j | ƒ qÅq| j ƒ  róy | j | | ƒ WqÅt j ƒ  d } t j d |  | j | f ƒ qqÅXqy | j | ƒ }	 WnG t t f k
 rO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-   R8   Rˆ   RF   R†   R   t   warnt   tarfileRo   R   t
   getmembersRd   R   RG   Rf   t   issymt   _extract_memberR   R.   t   extractfilet   KeyErrort   AttributeErrorR|   R!   t   copyfileobjRr   (   Rs   R¢   t   modet   tart   memberR¼   R¾   R-   t   eRt   t   destfp(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR   •  sd    *	*		!	
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`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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   copyfileRo   R¸   Rr   R&   t   unlink(   t   target_filet   temp_locationt   content_typeRt   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/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   RF   R   R4   R   R   t   pip.vcs.subversionRØ   t   urlR©   R   t   fatalR    (   Rs   R¢   R×   t   linkRØ   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyR   å  s      	(   s
   setuptoolss   pips   python(=   R   R!   R&   R'   Rj   R…   R™   Rµ   RÂ   t   pip.exceptionsR    R   t   pip.backwardcompatR   R   R   t   pip.locationsR   R   t   pip.logR   t   __all__Rg   R   R"   R	   R
   R?   R   RE   RT   R   t   objectRY   R   t   compileRl   Rb   R   R   R   R   R   R   R   R   R   R   R   R   R“   Rh   RŸ   R¡   R‘   R   R   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/util.pyt   <module>   sp   								
				
														 	@			