3 �Pfml�@s�ddlmZddlmZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlmZddlmZmZmZddlmZmZmZmZmZmZddl m!Z!ddl"m#Z#dd l$m%Z%dd l&m'Z'e%�r dd lm(Z)n dd lm)Z)d ddddddddddddddddddd d!d"d#d$gZ*e j+e,�Z-dzZ.d{Z/d|Z0d}Z1e0e.e1e/Z2e0e1Z3yddl4Z4e3e.7Z3Wn e5k �r�e-j6d1�YnXyddl7Z7e3e/7Z3Wn e5k �r�e-j6d2�YnXd3d4�Z8d5d!�Z9d6d�Z:e'd7d8d9�d~d;d ��Z;dd�Z=dd@d�Z>dAdB�Z?dCd�Z@dDd�ZAdEd�ZBdFd�ZCdGd�ZDejEfdHdI�ZFdJd�ZGdKd�ZHd�dMd�ZIdNd�ZJdOd�ZKdPdQ�ZLdRdS�ZMdTdU�ZNdVdW�ZOdXdY�ZPdZd[�ZQdLedLd:d:fd\d]�ZRd^d_�ZSd`da�ZTdbd�ZUdcdd�ZVd�ded�ZWdfd�ZXdgd�ZYd�did�ZZdjdk�Z[dldm�Z\Gdndo�doe]�Z^Gdpdq�dqe)�Z_ej`drds��Zadtd �ZbGdudv�dve]�Zcd�dwd$�Zddxdy�ZedS)��)�absolute_import)�dequeN)�InstallationError)�console_to_str� expanduser� stdlib_pkgs)� site_packages� user_site�running_under_virtualenv�virtualenv_no_global�write_delete_marker_file�distutils_scheme)� pkg_resources)�input)�PY2)�retry)�BytesIO)�StringIO�rmtree� display_path� backup_dir�ask�splitext� format_size�is_installable_dir� is_svn_page� file_contents�split_leading_dir�has_leading_dir�normalize_path�renames�get_terminal_size�get_prog� unzip_file� untar_file� unpack_file�call_subprocess�captured_stdout� ensure_dir�ARCHIVE_EXTENSIONS�SUPPORTED_EXTENSIONS�get_installed_version�.tar.bz2�.tbz�.tar.xz�.txz�.tlz�.tar.lz� .tar.lzma�.zip�.whl�.tar.gz�.tgz�.tarzbz2 module is not availablezlzma module is not availablec Os,yt|�Stk r&|||��YnXdS)N)� __import__� ImportError)Zpkg_or_module_stringZ ExceptionType�args�kwargs�r<�/usr/lib/python3.6/__init__.py�import_or_raiseIsr>cCsDytj|�Wn0tk r>}z|jtjkr.�WYdd}~XnXdS)z os.path.makedirs without EEXIST.N)�os�makedirs�OSError�errnoZEEXIST)�path�er<r<r=r(Ps  c CsDy$tjjtjd�dkr"dtjSWntttfk r>YnXdS)Nr� __main__.py�-cz %s -m pipZpip)rErF) r?rC�basename�sys�argv� executable�AttributeError� TypeError� IndexErrorr<r<r<r=r"Ys i� i�)Zstop_max_delayZ wait_fixedFcCstj||td�dS)N)� ignore_errors�onerror)�shutilr�rmtree_errorhandler)�dirrNr<r<r=rcscCs2tj|�jtj@r,tj|tj�||�dS�dS)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?�stat�st_mode�S_IREAD�chmod�S_IWRITE)�funcrC�exc_infor<r<r=rQis rQcCsttjjtjj|��}tjddkrB|jtj�d�}|jtj �d�}|j tj �tjj �rpd|t tj ��d�}|S)zTGives the display value for a given path, making it relative to cwd if possible.r��replace�.N)r?rC�normcase�abspathrH� version_info�decode�getfilesystemencoding�encode�getdefaultencoding� startswith�getcwd�sep�len)rCr<r<r=rxs�.bakcCs:d}|}x(tjj||�r0|d7}|t|�}q W||S)z\Figure out the name of a directory to back up the given dir to (adding .bak, .bak2, etc)�)r?rC�exists�str)rR�ext�n� extensionr<r<r=r�s cCs2x&tjjdd�j�D]}||kr|SqWt||�S)NZPIP_EXISTS_ACTION�)r?�environ�get�splitr)�message�options�actionr<r<r=�ask_path_exists�srvcCsZxTtjjd�rtd|��t|�}|j�j�}||krNtd|dj|�f�q|SqWdS)z@Ask the message interactively, with the given possible responsesZ PIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sz[^<]*Revision \d+:z#Powered by (?:]*?>)?Subversion)�re�search�I)Zhtmlr<r<r=r�s c Cs$t|d��}|j�jd�SQRXdS)N�rbzutf-8)�open�readr`)�filename�fpr<r<r=r�s ccs x|j|�}|sP|VqWdS)z7Yield pieces of data from a file-like object until EOF.N)r�)�file�size�chunkr<r<r=� read_chunks�s  r�cCsh|jd�jd�}d|krHd|kr4|jd�|jd�kss r�cCs8x2tjD](}tjj||jd�}tjj|�rdSqWdS)z$Is distribution an editable install?z .egg-linkTF)rHrCr?r{� project_namer)r�Z path_item�egg_linkr<r<r=�dist_is_editableHs   r�csl|r t�ndd��|r dd��ndd��|r6dd��ndd��|rHt�nd d �������fd d �tjD�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 stdlib_pkgs If ``editables`` is False, don't report editables. If ``editables_only`` is True , only report editables. If ``user_only`` is True , only report installations in the user site directory. cSsdS)NTr<)�dr<r<r=� local_testjsz/get_installed_distributions..local_testcSsdS)NTr<)r�r<r<r=� editable_testnsz2get_installed_distributions..editable_testcSs t|� S)N)r�)r�r<r<r=r�qscSst|�S)N)r�)r�r<r<r=�editables_only_testusz8get_installed_distributions..editables_only_testcSsdS)NTr<)r�r<r<r=r�xscSsdS)NTr<)r�r<r<r=� user_test~sz.get_installed_distributions..user_testcs:g|]2}�|�r|j�kr�|�r�|�r�|�r|�qSr<)�key)�.0r�)r�r�r��skipr�r<r=� �s  z/get_installed_distributions..)r�r�r� working_set)Z local_onlyr�Zinclude_editablesZeditables_onlyZ user_onlyr<)r�r�r�r�r�r=�get_installed_distributionsQs  r�cCs�g}t�r6t�r|jt�qN|jt�trN|jt�ntrD|jt�|jt�x0|D](}tjj||j�d}tjj |�rT|SqTWdS)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 �appendrr r?rCr{r�r)r�ZsitesZsiteZegglinkr<r<r=� egg_link_path�s       r�cCst|�}|r|S|jS)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�r�r<r<r=r��sr�c Cs�dd�}|d�p|d�p|d�}|sZy(tjtj�tj�}||�}tj|�Wn YnX|sztjjdd�tjjdd �f}t|d�t|d�fS) zlReturns a tuple (x, y) representing the width(x) and the height(x) in characters of the terminal window.c SsPy4ddl}ddl}ddl}|jd|j||jd��}Wn dS|dkrLdS|S)NrZhhZ1234)rr)�fcntl�termios�struct�unpackZioctlZ TIOCGWINSZ)�fdr�r�r��crr<r<r=� ioctl_GWINSZ�sz'get_terminal_size..ioctl_GWINSZrrirZZLINES�ZCOLUMNS�P)r?r��ctermid�O_RDONLY�closerprq�int)r�r�r�r<r<r=r!�scCstjd�}tj|�|S)zBGet the current umask which involves having to set it temporarily.r)r?�umask)�maskr<r<r=� current_umask�s  r�c Cst|�t|d�}z�tj|dd�}t|j��o0|}x�|j�D]�}|j}|j|�}|} |rdt |�d} t j j || �} t j j | �} | jd�s�| jd�r�t| �qd}n8|j�jt�rRd}n$|j�jd�rfd}ntjd|�d }tj||�}�z�t d d �|j �D��}�x�|j �D�]�}|j }|d kr�q�|r�t |�d }t jj||�}ytj|j|d�|�Wntjk �r YnX|j��r"t|�q�|j��rxy|j||�Wn8tk �rt}ztjd||j |�w�WYdd}~XnXq�y|j|�} Wn<ttfk �r�}ztjd||j |�w�WYdd}~XnXtt jj|��t|d��} tj| | �WdQRX| j�|j||�|jd@r�t j |dt!�dB�q�WWd|j�XdS)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.tgzzr:gzzr:bz2zr:xzz.tar�rz-Cannot determine compression type for file %szr:*cSsg|]}|jdkr|j�qS)�pax_global_header)r�)r��memberr<r<r=r�(szuntar_file..r�ri)r�z/In the tar file %s the member %s is invalid: %sNr�r�i�)"r(ryr��BZ2_EXTENSIONS� XZ_EXTENSIONS�logger�warning�tarfiler�rZ getmembersr�rr?rCr{Z data_filterr[ZLinkOutsideDestinationErrorr~ZissymZ_extract_memberrwZ extractfile�KeyErrorrKr�rPZ copyfileobjr��utimer�rVr�) r�r�r�Ztarr�r�r�rC�excr�Zdestfpr<r<r=r$ sh           cCs�tjj|�}|dks,|j�jt�s,tj|�rDt|||jd� d�n�|dkslt j |�sl|j�jt t t �rxt||�nX|r�|jd�r�tt|��r�ddlm}|d|j�j|�ntjd |||�td |��dS) Nzapplication/zipz.whl)r�zapplication/x-gzipz text/htmlr)� Subversionzsvn+zZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz%Cannot determine archive format of %s)r?rCr�ryr��ZIP_EXTENSIONSr�Z is_zipfiler#r�Z is_tarfile�TAR_EXTENSIONSr�r�r$rdrrZpip.vcs.subversionr�Zurlr�r��criticalr)r�r�Z content_type�linkr�r<r<r=r%`s,       �raisecCs,|r d}ntj}|dkrng}xF|D]>} d| ksFd| ksFd| ksFd| krVd| jdd�} |j| �q"Wdj|�}tjd|�tjj �} |r�| j |�ytj |tj d||| d�} Wn2t k r�} ztjd | |��WYdd} ~ XnX|dk �rNg} x\t| jj��}|�sP|j�}| j|d�tj�tjk�r:tj|�q�|dk r�|j�q�W| j�|dk �r~| j�rt|jd �n |jd �| j�r|d k�r�tj�tjk�r�| �r�tjd |�tjdj| �d�td|| j|f��n:|dk�r�tjd|| j|�n|dk�rntdt|���|�s(dj| �SdS)N� � �"�'z"%s"z\"zRunning command %s)�stderr�stdin�stdout�cwd�envz#Error %s while executing command %s�error�doner�z Complete output from command %s:roz) ----------------------------------------z,Command "%s" failed with error code %s in %s�warnz$Command "%s" had error code %s in %s�ignorezInvalid value: on_returncode=%s)� subprocess�PIPEr[r�r{r��debugr?rp�copy�update�PopenZSTDOUTrwr�rr��readline�rstripZgetEffectiveLevel� std_logging�DEBUGZspin�wait� returncodeZfinishr�rr�� ValueError�repr)�cmdZ show_stdoutr�Z on_returncodeZ command_descZ extra_environZspinnerr�Z cmd_parts�partr��procr�Z all_output�liner<r<r=r&�sz                  cCsxt|d��}|j�}WdQRXdtjd�dg}x4|D],}y|j|�}Wntk r\w4YnXPq4Wt|�tkstt�|S)aRReturn the contents of *filename*. Try to decode the file contents with utf-8, the preferred system encoding (e.g., cp1252 on some Windows machines), and latin1, in that order. Decoding a byte string with latin1 will never raise an error. In the worst case, the returned string will contain some garbage characters. r�Nzutf-8F�latin1) r�r��locale�getpreferredencodingr`�UnicodeDecodeError�typer}�AssertionError)r�r�r�Z encodings�encr<r<r=�read_text_file�s  rcCstj|�t|�dS)N)r?r@r )Z build_dirr<r<r=�_make_build_dir�s rc@s(eZdZdZdd�Zdd�Zdd�ZdS) �FakeFilezQWrap a list of lines in an object with readline() to make ConfigParser happy.cCsdd�|D�|_dS)Ncss|] }|VqdS)Nr<)r��lr<r<r=� sz$FakeFile.__init__..)�_gen)�self�linesr<r<r=�__init__szFakeFile.__init__cCsDy*y t|j�Stk r&|jj�SXWntk r>dSXdS)Nro)�nextr� NameError� StopIteration)rr<r<r=r�s zFakeFile.readlinecCs|jS)N)r)rr<r<r=�__iter__szFakeFile.__iter__N)�__name__� __module__� __qualname__�__doc__rr�rr<r<r<r=rs rc@s$eZdZedd��Zedd��ZdS)� StreamWrappercCs ||_|�S)N)� orig_stream)�clsr!r<r<r=� from_streamszStreamWrapper.from_streamcCs|jjS)N)r!�encoding)rr<r<r=r$szStreamWrapper.encodingN)rrr� classmethodr#�propertyr$r<r<r<r=r s r c cs@tt|�}tt|tj|��ztt|�VWdtt||�XdS)z�Return a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO. Taken from Lib/support/__init__.py in the CPython repo. N)�getattrrH�setattrr r#)Z stream_nameZ orig_stdoutr<r<r=�captured_output s  r)cCstd�S)z�Capture the output of sys.stdout: with captured_stdout() as stdout: print('hello') self.assertEqual(stdout.getvalue(), 'hello ') Taken from Lib/support/__init__.py in the CPython repo. r�)r)r<r<r<r=r'/s c@s eZdZdZdd�Zdd�ZdS)�cached_propertyz�A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property. Source: https://github.com/bottlepy/bottle/blob/0.11.5/bottle.py#L175 cCst|d�|_||_dS)Nr)r'rrX)rrXr<r<r=rCs zcached_property.__init__cCs(|dkr |S|j|�}|j|jj<|S)N)rX�__dict__r)r�objr"�valuer<r<r=�__get__Gszcached_property.__get__N)rrrrrr.r<r<r<r=r*;sr*cCs@tjj|�}|dkrtj�}n tj|�}|j|�}|r<|jSdS)zCGet the installed version of dist_name avoiding pkg_resources cacheN)rZ Requirement�parseZ WorkingSetr��version)Z dist_nameZ lookup_dirsZreqr�r�r<r<r=r+Os     cCst|dd�dS)zConsume an iterable at C speed.r)�maxlenN)r)�iteratorr<r<r=�consumecsr3)r,r-)r.r/r0r1r2)r3r4)r5r6r7)F)rh)T)T)TNr�NNN)N)fZ __future__r� collectionsr� contextlibrB�ior Zloggingr�r�r?r�rPrSr�rHr�r�Zpip.exceptionsrZ pip.compatrrrZ pip.locationsrr r r r r Z pip._vendorrZpip._vendor.six.movesrZpip._vendor.sixrZpip._vendor.retryingrrr�__all__Z getLoggerrr�r�r�r�r�r)r*�bz2r9r�Zlzmar>r(r"rrQrrrvrrrrr�DEFAULT_BUFFER_SIZEr�rrrrr r�r�r�r�r�r�r�r�r�r!r�r#r$r%r&rr�objectrr �contextmanagerr)r'r*r+r3r<r<r<r=�s�                            5% +S! _