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! _