î
½1kd a  ã               @   sŽ  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 m Z m Z m Z d  d l m Z m Z m Z m Z m Z m Z d  d l m Z m Z m Z m Z d  d l m Z d  d l 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 d d g Z d  d „  Z  d! d" d „ Z! d# d$ „  Z" d% d „  Z# d& d' d	 „ Z$ d d d( d
 „ Z% d d) d* „ Z& d+ d, „  Z' d- d „  Z( Gd. d/ „  d/ e) ƒ Z* e* ƒ  Z+ [* e j, d0 e j- ƒ Z. d1 d „  Z/ d2 d „  Z0 d3 d „  Z1 d4 d „  Z2 d5 d „  Z3 d6 d „  Z4 d7 d „  Z5 d8 d „  Z6 d9 d „  Z7 d: d „  Z8 d; d „  Z9 d< d= „  Z: d> d? „  Z; d@ dA „  Z< dB dC „  Z= dD dE „  Z> dF d\ dF d! dK dL „ Z? dM dN „  Z@ dO dP „  ZA dQ d „  ZB dR dS „  ZC dF dT d „ ZD dU d „  ZE dV d „  ZF dW d „  ZG dX d „  ZH dF d d dF e jI d d dY d „ ZJ dZ d[ „  ZK d S)]é    N)ÚInstallationErrorÚ
BadCommandÚPipError)ÚWindowsErrorÚstring_typesÚ	raw_inputÚconsole_to_strÚ	user_siteÚPermissionError)Úsite_packagesÚrunning_under_virtualenvÚvirtualenv_no_globalÚdistutils_scheme)Úlogger)ÚversionÚrmtreeÚdisplay_pathÚ
backup_dirÚfind_commandÚaskÚInfÚnormalize_nameÚsplitextÚformat_sizeÚis_installable_dirÚis_svn_pageÚfile_contentsÚsplit_leading_dirÚhas_leading_dirÚmake_path_relativeÚnormalize_pathÚrenamesÚget_terminal_sizeÚget_progÚ
unzip_fileÚ
untar_fileÚcreate_download_cache_folderÚcache_downloadÚunpack_fileÚcall_subprocessc               C   sP   y. t  j j t j d ƒ d k r- d t j SWn t t t f k
 rK Yn Xd S)Nr   ú__main__.pyú-cz	%s -m pipÚpip)r*   r+   )	ÚosÚpathÚbasenameÚsysÚargvÚ
executableÚAttributeErrorÚ	TypeErrorÚ
IndexError© r6   r6   ú7/var/www/pythonscrapper/code/venv/build/pip/pip/util.pyr#   !   s    Fc             C   s   t  j |  d | d t ƒd  S)NÚignore_errorsÚonerror)Úshutilr   Úrmtree_errorhandler)Údirr8   r6   r6   r7   r   *   s    c             C   sÂ   | d d … \ } } | t  k r5 | j d d k pp | t k rT | j d d k pp | t k op | j d d k sy ‚  n  t j | ƒ j t j @t j k r¡ ‚  n  t j | t j	 ƒ |  | ƒ d S)zÑ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.Né   r   é   é   é   )
r   ÚargsÚOSErrorr
   r-   ÚstatÚst_modeÚS_IREADÚchmodÚS_IWRITE)Úfuncr.   Úexc_infoÚexctypeÚvaluer6   r6   r7   r;   /   s    "r;   c             C   sd   t  j j t  j j |  ƒ ƒ }  |  j t  j ƒ  t  j j ƒ r` d |  t t  j ƒ  ƒ d … }  n  |  S)zTGives the display value for a given path, making it relative to cwd
    if possible.Ú.N)r-   r.   ÚnormcaseÚabspathÚ
startswithÚgetcwdÚsepÚlen)r.   r6   r6   r7   r   B   s    #z.bakc             C   sK   d } | } x4 t  j j |  | ƒ rB | d 7} | t | ƒ } q W|  | S)z\Figure out the name of a directory to back up the given dir to
    (adding .bak, .bak2, etc)é   )r-   r.   ÚexistsÚstr)r<   ÚextÚnÚ	extensionr6   r6   r7   r   K   s    
c             C   s7  | d k r0 t  j j d d ƒ j t  j ƒ } n  t | t ƒ rK | g } n  | d k rc t ƒ  } n  d d „  | j ƒ  j t  j ƒ Dƒ } 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)z<Searches the PATH for the given command and returns its pathNÚPATHÚ c             S   s"   g  |  ] } t  | ƒ r | ‘ q Sr6   )rR   )Ú.0rV   r6   r6   r7   ú
<listcomp>_   s   	 z find_command.<locals>.<listcomp>rS   zCannot find command %r)r-   ÚenvironÚgetÚsplitÚpathsepÚ
isinstancer   Úget_pathextÚlowerr.   r   ÚjoinÚisfiler   )ÚcmdÚpathsÚpathextr.   Úcmd_pathrV   Úcmd_path_extr6   r6   r7   r   V   s$    $%"
c             C   sF   |  d k r- t  j j d d d d g ƒ }  n  t  j j d |  ƒ } | S)z9Returns the path extensions from environment or a defaultNz.COMz.EXEz.BATz.CMDÚPATHEXT)r-   r`   rd   r]   r^   )Údefault_pathextrh   r6   r6   r7   rb   q   s    !rb   c             C   sC   x3 t  j j d d ƒ j ƒ  D] } | | k r | Sq Wt |  | ƒ S)NÚPIP_EXISTS_ACTIONrZ   )r-   r]   r^   r_   r   )ÚmessageÚoptionsÚactionr6   r6   r7   Úask_path_existsy   s    "rq   c             C   s~   xw t  j j d ƒ r( t d |  ƒ ‚ n  t |  ƒ } | j ƒ  j ƒ  } | | k rr t d | d j | ƒ f ƒ q | Sq Wd S)z@Ask the message interactively, with the given possible responsesÚPIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sz<Your response (%r) was not one of the expected responses: %sz, N)	r-   r]   r^   Ú	Exceptionr   Ústriprc   Úprintrd   )rn   ro   Úresponser6   r6   r7   r   €   s    c               @   sj   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z d d „  Z	 d d „  Z
 d S)Ú_InfzI am bigger than everything!c             C   s   |  | k r d Sd Sd  S)NTFr6   )ÚselfÚotherr6   r6   r7   Ú__eq__‘   s    z_Inf.__eq__c             C   s   |  j  | ƒ S)N)rz   )rx   ry   r6   r6   r7   Ú__ne__—   s    z_Inf.__ne__c             C   s   d S)NFr6   )rx   ry   r6   r6   r7   Ú__lt__š   s    z_Inf.__lt__c             C   s   d S)NFr6   )rx   ry   r6   r6   r7   Ú__le__�   s    z_Inf.__le__c             C   s   d S)NTr6   )rx   ry   r6   r6   r7   Ú__gt__    s    z_Inf.__gt__c             C   s   d S)NTr6   )rx   ry   r6   r6   r7   Ú__ge__£   s    z_Inf.__ge__c             C   s   d S)Nr   r6   )rx   r6   r6   r7   Ú__repr__¦   s    z_Inf.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rz   r{   r|   r}   r~   r   r€   r6   r6   r6   r7   rw   Ž   s   rw   z[^a-z]c             C   s   t  j d |  j ƒ  ƒ S)Nú-)Ú_normalize_reÚsubrc   )Únamer6   r6   r7   r   ±   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è  z%.1fMBg     @�@é
   z%ikBz%.1fkBz%ibytesi@B i'  r6   )Úbytesr6   r6   r7   r   µ   s    c             C   sE   t  j j |  ƒ s d St  j j |  d ƒ } t  j j | ƒ rA d Sd S)z@Return True if `path` is a directory containing a setup.py file.Fzsetup.pyT)r-   r.   Úisdirrd   re   )r.   Úsetup_pyr6   r6   r7   r   À   s    c             C   s(   t  j d |  ƒ o' t  j d |  t  j ƒ S)zJReturns true if the page appears to be the index page of an svn repositoryz<title>[^<]*Revision \d+:z#Powered by (?:<a[^>]*?>)?Subversion)ÚreÚsearchÚI)Úhtmlr6   r6   r7   r   Ê   s    c          
   C   s8   t  |  d ƒ } z | j ƒ  j d ƒ SWd  | j ƒ  Xd  S)NÚrbzutf-8)ÚopenÚreadÚdecodeÚclose)ÚfilenameÚfpr6   r6   r7   r   Ð   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)Nú/ú\rS   rZ   )rU   ÚlstripÚfindr_   )r.   r6   r6   r7   r   Ø   s    6c             C   s\   d } xO |  D]G } t  | ƒ \ } } | s/ d S| d k rD | } q | | k r d Sq Wd S)zyReturns true if all the paths have the same leading path name
    (i.e., everything is in one subdirectory in an archive)NFT)r   )rg   Úcommon_prefixr.   ÚprefixÚrestr6   r6   r7   r   ä   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)a  
    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'
    r   z..rZ   rL   )r-   r.   r/   ÚdirnameÚnormpathrN   rt   rQ   r_   ÚpoprR   rd   )r.   Úrel_toÚpath_filenameÚ
path_partsÚrel_to_partsÚ
full_partsr6   r6   r7   r   ó   s    $$#c             C   s(   t  j j t  j j t  j j |  ƒ ƒ ƒ S)zN
    Convert a path to its canonical, case-normalized, absolute version.

    )r-   r.   rM   ÚrealpathÚ
expanduser)r.   r6   r6   r7   r      s    c             C   s[   t  j |  ƒ \ } } | j ƒ  j d ƒ rQ | d d … | } | d d … } n  | | f S)z,Like os.path.splitext, but take off .tar tooz.taré   Néüÿÿÿrª   )Ú	posixpathr   rc   Úendswith)r.   ÚbaserV   r6   r6   r7   r     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  Yq¤ Xn  d S)z7Like os.renames(), but handles renaming across devices.N)	r-   r.   r_   rT   Úmakedirsr:   ÚmoveÚ
removedirsrB   )ÚoldÚnewÚheadÚtailr6   r6   r7   r!   !  s    c             C   s‹   t  |  ƒ }  t  t j ƒ } t ƒ  r: |  j t  t j ƒ ƒ S|  j | ƒ rƒ x3 t d ƒ j ƒ  D] } |  j t  | ƒ ƒ r\ d Sq\ Wd Sd Sd S)aB  
    Return True if this is a path pip is allowed to modify.

    If we're in a virtualenv, sys.prefix points to the virtualenv's
    prefix; only sys.prefix is considered local.

    If we're not in a virtualenv, in general we can modify anything.
    However, if the OS vendor has configured distutils to install
    somewhere other than sys.prefix (which could be a subdirectory of
    sys.prefix, e.g. /usr/local), we consider sys.prefix itself nonlocal
    and the domain of the OS vendor. (In other words, everything _other
    than_ sys.prefix is considered local.)

    rZ   TFN)r    r0   r�   r   rO   r   Úvalues)r.   r�   Ú
local_pathr6   r6   r7   Úis_local2  s    	r·   c             C   s   t  t |  ƒ ƒ S)zh
    Return True if given Distribution object is installed somewhere pip
    is allowed to modify.

    )r·   Údist_location)Údistr6   r6   r7   Údist_is_localQ  s    rº   c             C   s-   t  r% t t |  ƒ ƒ j t t  ƒ ƒ Sd Sd S)zF
    Return True if given Distribution is installed in user site.
    FN)r	   r    r¸   rO   )r¹   r6   r6   r7   Údist_in_usersiteZ  s    r»   c             C   s   t  t |  ƒ ƒ j t  t ƒ ƒ S)za
    Return True if given Distribution is installed in distutils.sysconfig.get_python_lib().
    )r    r¸   rO   r   )r¹   r6   r6   r7   Údist_in_site_packagesc  s    r¼   c             C   s)   d d l  m } | j |  g  ƒ } | j S)z$Is distribution an editable install?r   )ÚFrozenRequirement)r,   r½   Ú	from_distÚeditable)r¹   r½   Úreqr6   r6   r7   Údist_is_editablej  s    rÁ   TÚ
setuptoolsr,   ÚpythonÚ
distributec                s€   |  r t  ‰ n d d „  ‰ | r0 d d „  ‰  n d d „  ‰  | rQ d d „  ‰ n d d „  ‰ ‡  ‡ ‡ ‡ f d d †  t j Dƒ S)	aÌ  
    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?]

    If ``editables`` is False, don't report editables.

    If ``editables_only`` is True , only report editables.

    c             S   s   d S)NTr6   )Údr6   r6   r7   Ú<lambda>‡  s    z-get_installed_distributions.<locals>.<lambda>c             S   s   d S)NTr6   )rÅ   r6   r6   r7   rÆ   Š  s    c             S   s   t  |  ƒ S)N)rÁ   )rÅ   r6   r6   r7   rÆ   Œ  s    c             S   s
   t  |  ƒ S)N)rÁ   )rÅ   r6   r6   r7   rÆ   �  s    c             S   s   d S)NTr6   )rÅ   r6   r6   r7   rÆ   ‘  s    c                sI   g  |  ]? } ˆ | ƒ r | j  ˆ k r ˆ  | ƒ r ˆ | ƒ r | ‘ q Sr6   )Úkey)r[   rÅ   )Úeditable_testÚeditables_only_testÚ
local_testÚskipr6   r7   r\   “  s
   	 z/get_installed_distributions.<locals>.<listcomp>)rº   Úpkg_resourcesÚworking_set)Ú
local_onlyrË   Úinclude_editablesÚeditables_onlyr6   )rÈ   rÉ   rÊ   rË   r7   Úget_installed_distributionsq  s    	rÑ   c             C   s¸   g  } t  ƒ  rN t ƒ  r( | j t ƒ qq | j t ƒ t rq | j t ƒ qq n# t rd | j t ƒ n  | j t ƒ x@ | D]8 } t j j | |  j ƒ d } t j j	 | ƒ rx | Sqx Wd S)a  
    Return the path for the .egg-link file if it exists, otherwise, None.

    There's 3 scenarios:
    1) not in a virtualenv
       try to find in site.USER_SITE, then site_packages
    2) in a no-global virtualenv
       try to find in site_packages
    3) in a yes-global virtualenv
       try to find in site_packages, then site.USER_SITE  (don't look in global location)

    For #1 and #3, there could be odd cases, where there's an egg-link in 2 locations.
    This method will just return the first one found.
    z	.egg-linkN)
r   r   Úappendr   r	   r-   r.   rd   Úproject_namere   )r¹   ÚsitesÚsiteÚegglinkr6   r6   r7   Úegg_link_path›  s    		r×   c             C   s   t  |  ƒ } | r | S|  j S)zÿ
    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×   Úlocation)r¹   Úegg_linkr6   r6   r7   r¸   ½  s    r¸   c           
   C   sÍ   d d „  }  |  d ƒ p- |  d ƒ p- |  d ƒ } | s| y8 t  j t  j ƒ  t  j ƒ } |  | ƒ } t  j | ƒ Wq| Yq| Xn  | s¯ t  j j d d ƒ t  j j d d	 ƒ f } n  t | d ƒ t | d ƒ f S)
zlReturns 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  SYn X| d k rk d  S| d k r{ d  S| S)Nr   ÚhhÚ1234)r   r   )r   r   )ÚfcntlÚtermiosÚstructÚunpackÚioctlÚ
TIOCGWINSZ)ÚfdrÜ   rÝ   rÞ   Úcrr6   r6   r7   Úioctl_GWINSZÎ  s    	z'get_terminal_size.<locals>.ioctl_GWINSZr   rS   r=   ÚLINESé   ÚCOLUMNSéP   )r-   r’   ÚctermidÚO_RDONLYr•   r]   r^   Úint)rä   rã   râ   r6   r6   r7   r"   Ë  s    $-c              C   s    t  j d ƒ }  t  j |  ƒ |  S)zBGet the current umask which involves having to set it temporarily.r   )r-   Úumask)Úmaskr6   r6   r7   Úcurrent_umaské  s    rî   c             C   sÀ  t  j j | ƒ s" t  j | ƒ n  t |  d ƒ } z}t j | ƒ } t | j ƒ  ƒ oX | } xO| j	 ƒ  D]A} | j
 } | j | ƒ } | }	 | r¥ t | ƒ d }	 n  t  j j | |	 ƒ }	 t  j j |	 ƒ }
 t  j j |
 ƒ sî t  j |
 ƒ n  |	 j d ƒ s|	 j d ƒ r1t  j j |	 ƒ s©t  j |	 ƒ q©qh t |	 d ƒ } z | j | ƒ Wd | j ƒ  | j d ?} | r¨t j | ƒ r¨| d @r¨t  j |	 d	 t ƒ  d Bƒ n  Xqh WWd | j ƒ  Xd S)
aŸ  
    Unzip the file (with path `filename`) to the destination `location`.  All
    files are written based on system defaults and umask (i.e. permissions are
    not preserved), except that regular file members with any execute
    permissions (user, group, or world) have "chmod +x" applied after being
    written. Note that for windows, any execute changes using os.chmod are
    no-ops per the python docs.
    r‘   rS   r˜   r™   ÚwbNé   éI   iÿ  )r-   r.   rT   r®   r’   ÚzipfileÚZipFiler   ÚnamelistÚinfolistr–   r“   r   rd   rŸ   r¬   Úwriter•   Úexternal_attrrC   ÚS_ISREGrF   rî   )r–   rØ   ÚflattenÚzipfpÚzipÚleadingÚinforˆ   ÚdataÚfnr<   r—   Úmoder6   r6   r7   r$   ð  s6    		
'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
 d d „  | j ƒ  Dƒ ƒ } xê| j ƒ  D]Ü} | j } | d k rqþ n  | r8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 ƒ wþ YqÚXqþ y | j | ƒ }	 WnH t t f k
 r9t j ƒ  d } t j d |  | j | f ƒ wþ Yn Xt  j j t  j j | ƒ ƒ stt  j t  j j | ƒ ƒ n  t	 | d ƒ }
 z t j |	 |
 ƒ Wd |
 j ƒ  X|	 j ƒ  | j d @rþ t  j | d t ƒ  d Bƒ qþ qþ WWd | j ƒ  Xd S)aŸ  
    Untar the file (with path `filename`) to the destination `location`.
    All files are written based on system defaults and umask (i.e. permissions
    are not preserved), except that regular file members with any execute
    permissions (user, group, or world) have "chmod +x" applied after being
    written.  Note that for windows, any execute changes using os.chmod are
    no-ops per the python docs.
    z.gzz.tgzzr:gzz.bz2z.tbzzr:bz2z.tarÚrz-Cannot determine compression type for file %szr:*c             S   s(   g  |  ] } | j  d  k r | j  ‘ q S)Úpax_global_header)rˆ   )r[   Úmemberr6   r6   r7   r\   5  s   	 zuntar_file.<locals>.<listcomp>r  rS   z/In the tar file %s the member %s is invalid: %srï   Nrñ   iÿ  )r-   r.   rT   r®   rc   r¬   r   ÚwarnÚtarfiler’   r   Ú
getmembersrˆ   r   rd   r‹   ÚissymÚ_extract_memberr0   rI   ÚextractfileÚKeyErrorr3   rŸ   r:   Úcopyfileobjr•   r   rF   rî   )r–   rØ   r   Útarrü   r  rÿ   r.   Úer—   Údestfpr6   r6   r7   r%     sf    	*	*			
&c             C   s@   t  j d 8_ t  j d |  ƒ t  j d 7_ t j |  ƒ d  S)Nr=   z&Creating supposed download cache at %s)r   ÚindentÚnotifyr-   r®   )Úfolderr6   r6   r7   r&   i  s    c             C   sU   t  j d t |  ƒ ƒ t j | |  ƒ t |  d d ƒ } | j | ƒ | j ƒ  d  S)NzStoring download in cache at %sz.content-typeÚw)r   r  r   r:   Úcopyfiler’   rö   r•   )Útarget_fileÚtemp_locationÚcontent_typer—   r6   r6   r7   r'   p  s
    c             C   sC  t  j j |  ƒ }  | d k sZ |  j d ƒ sZ |  j d ƒ sZ |  j d ƒ sZ t j |  ƒ rz 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)Nzapplication/zipz.zipú	.pybundleú.whlrù   zapplication/x-gziprS   ú.tarú.tar.gzú.tar.bz2ú.tgzú.tbzz	text/htmlr   )Ú
Subversionzsvn+zZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz%Cannot determine archive format of %s)r  r  )r  r  r  r  r  )r-   r.   r§   r¬   rò   Ú
is_zipfiler$   r  Ú
is_tarfiler   rc   r%   rO   r   r   Úpip.vcs.subversionr  Úurlrß   r   Úfatalr   )r–   rØ   r  Úlinkr  r6   r6   r7   r(   x  s$     	c             C   sã  | d  k r‹ g  } xd |  D]\ }	 d |	 k sO d |	 k sO d |	 k sO d |	 k rh d |	 j  d d ƒ }	 n  | j |	 ƒ q Wd j | ƒ } n  | rš d  }
 n	 t j }
 t j | d | ƒ t j j	 ƒ  } | rÜ | j
 | ƒ n  y4 t j |  d t j d	 d  d
 |
 d | d | ƒ} Wn< t k
 rNt j ƒ  d } t j d | | f ƒ ‚  Yn Xg  } |
 d  k	 r| j }
 xÍ t |
 j ƒ  ƒ } | s‰Pn  | j ƒ  } | j | d ƒ | r| | ƒ } t | t ƒ rÖ| \ } } n  t j | | ƒ t j | ƒ st j ƒ  qqmt j | ƒ qmWn! | j ƒ  \ } } | p4d g } | j ƒ  | j rÆ| r¦| r‡t j d | ƒ t j d j | ƒ d ƒ n  t d | | j | f ƒ ‚ qÆt j d | | j | f ƒ n  |
 d  k	 rßd j | ƒ Sd  S)Nú Ú
ú"ú'z"%s"z\"zRunning command %sÚstderrÚstdinÚstdoutÚcwdÚenvrS   z#Error %s while executing command %srZ   z Complete output from command %s:z)
----------------------------------------z*Command %s failed with error code %s in %sz"Command %s had error code %s in %s) ÚreplacerÒ   rd   Ú
subprocessÚPIPEr   Úlogr-   r]   ÚcopyÚupdateÚPopenÚSTDOUTrs   r0   rI   r#  r+  r   ÚreadlineÚrstripra   ÚtupleÚstdout_level_matchesÚshow_progressrý   ÚcommunicateÚwaitÚ
returncoder  r   r  )rf   Úshow_stdoutÚfilter_stdoutr,  Úraise_on_returncodeÚcommand_levelÚcommand_descÚextra_environÚ	cmd_partsÚpartr+  r-  Úprocr  Ú
all_outputÚlineÚlevelÚreturned_stdoutÚreturned_stderrr6   r6   r7   r)   ‘  sp    0			
	c             C   sE   t  j |  ƒ } | d k r d St  j | ƒ } t d d „  | Dƒ ƒ S)zØ
    Attempt to determine if this is a pre-release using PEP386/PEP426 rules.

    Will return True if it is a pre-release and False if not. Versions are
    assumed to be a pre-release if they cannot be parsed.
    NTc             S   s)   g  |  ] } t  d  d „  | Dƒ ƒ ‘ q S)c          	   S   s1   g  |  ]' } | t  d  d d d d g ƒ k ‘ q S)ÚaÚbÚcÚrcÚdev)Úset)r[   Úyr6   r6   r7   r\   â  s   	 z,is_prerelease.<locals>.<listcomp>.<listcomp>)Úany)r[   Úxr6   r6   r7   r\   â  s   	 z!is_prerelease.<locals>.<listcomp>)r   Ú_suggest_normalized_versionÚ_normalized_keyrS  )ÚversÚ
normalizedÚparsedr6   r6   r7   Úis_prereleaseÔ  s
    rZ  )z
setuptoolszpipzpythonz
distribute)Lr0   r:   r-   rC   r�   r«   rò   r  r/  ÚtextwrapÚpip.exceptionsr   r   r   Zpip.backwardcompatr   r   r   r   r	   r
   Úpip.locationsr   r   r   r   Úpip.logr   rÌ   Údistlibr   Ú__all__r#   r   r;   r   r   r   rb   rq   r   Úobjectrw   r   Úcompiler�   r†   r   r   r   r   r   r   r   r   r    r   r!   r·   rº   r»   r¼   rÁ   rÑ   r×   r¸   r"   rî   r$   r%   r&   r'   r(   ÚDEBUGr)   rZ  r6   r6   r6   r7   Ú<module>   s’   ."							
			'"-L	?