ó
zÛ^c           @   sg  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% 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, d0 „  Z- d1 „  Z. d2 „  Z/ d3 „  Z0 d4 „  Z1 e2 dA d8 „ Z3 d9 „  Z4 d: „  Z5 d; „  Z6 e2 d< „ Z7 d= „  Z8 d> „  Z9 d? „  Z: d@ „  Z; d S(B   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   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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-   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyRE   b   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   (   t   messaget   optionst   response(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyR   i   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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyt   __cmp__y   s    c         C   s   d S(   NR   (    (   RW   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyt   __repr__~   s    (   t   __name__t
   __module__t   __doc__RY   RZ   (    (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyRV   w   s   	s   [^a-z]c         C   s   t  j d |  j ƒ  ƒ S(   Nt   -(   t   _normalize_ret   subRF   (   t   name(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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-   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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   Rd   Re   (   RJ   t   common_prefixR-   t   prefixt   rest(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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   RR   R6   RB   t   popR7   RG   (   R-   t   rel_tot   path_filenamet
   path_partst   rel_to_partst
   full_parts(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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-   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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:   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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   Re   R   R4   t   sysRv   (   R-   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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(   Re   (   t   d(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyt   <lambda>/  s    (   R   t   pkg_resourcest   working_sett   key(   t
   local_onlyt   skipt
   local_testR”   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyt   egg_link_path3  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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyRŽ   A  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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyt   ioctl_GWINSZR  s    i    i   i   t   LINESi   t   COLUMNSiP   (   R&   Rl   t   ctermidt   O_RDONLYRo   R@   RA   t   int(   R«   Rª   R©   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyR   O  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
    locationRk   i   Rr   s   \t   wbN(   R&   R-   R8   R…   Rl   t   zipfilet   ZipFileR   t   namelistRm   R   RG   Ry   Rƒ   t   writeRo   (   Rp   RŸ   t   flattent   zipfpt   zipt   leadingRa   t   datat   fnR#   Rq   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyR   m  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-   R8   R…   RF   Rƒ   R   t   warnt   tarfileRl   R   t
   getmembersRa   R   RG   Rc   t   extractfilet   KeyErrort   AttributeErrorRŒ   R.   Ry   R!   t   copyfileobjRo   (   Rp   RŸ   t   modet   tart   memberR¹   R»   R-   Rq   t   et   destfp(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/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(    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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   copyfileRl   Rµ   Ro   R&   t   unlink(   t   target_filet   temp_locationt   content_typeRq   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-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    (   Rp   RŸ   RÒ   t   linkRÓ   (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyR   Ò  s      	(   s
   setuptoolss   pips   python(<   RŒ   R!   R&   R'   Rg   R‚   R–   R²   R¿   t   pip.exceptionsR    R   t   pip.backwardcompatR   R   R   t   pip.locationsR   R   t   pip.logR   t   __all__Rd   R   R"   R	   R
   R?   R   RE   R   t   objectRV   R   t   compileRi   R_   R   R   R   R   R   R   R   R   R   R   R   R   R   Re   Rœ   Rž   RŽ   R   R   R   R   R   R   (    (    (    sU   /opt/eff.org/certbot/venv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.pyt   <module>   sn   							
				
														 	5			