3

Q'ícM-ã@s¨ddlmZddlmZddlZddlZddlmZmZmZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZdd	lmZmZdd
lmZmZmZddlmZyddlmZWnek
rÜdZYnXe
jeƒZ d
d„Z!e!eeƒZ"Gdd„de#ƒZ$Gdd„de#ƒZ%Gdd„de#ƒZ&Gdd„de&e$e%e"ƒZ'Gdd„de&e$e%eeƒZ(e	j)dd„ƒZ*Gdd„de#ƒZ+Gdd„de#ƒZ,Gdd „d e#ƒZ-e	j)d!d"„ƒZ.dS)#é)Úabsolute_import)ÚdivisionN)ÚsignalÚSIGINTÚdefault_int_handler)ÚWINDOWS)Úformat_size)Úget_indentation)Úsix)ÚBarÚIncrementalBar)ÚWritelnMixinÚHIDE_CURSORÚSHOW_CURSOR)ÚSpinner)ÚcoloramacCs€t|jddƒ}|s|St|dtjƒƒt|dtjƒƒg}|tt|dgƒƒ7}ytjƒj|ƒj|ƒWntk
rv|SX|SdS)NÚencodingÚ
empty_fillÚfillÚphases)ÚgetattrÚfiler
Ú	text_typeÚlistÚjoinÚencodeÚUnicodeEncodeError)Ú	preferredÚfallbackrÚ
characters©r ú+/tmp/pip-build-l_bcah40/pip/pip/utils/ui.pyÚ_select_progress_classsr"cs4eZdZdZ‡fdd„Z‡fdd„Zdd„Z‡ZS)ÚInterruptibleMixinaÂ
    Helper to ensure that self.finish() gets called on keyboard interrupt.

    This allows downloads to be interrupted without leaving temporary state
    (like hidden cursors) behind.

    This class is similar to the progress library's existing SigIntMixin
    helper, but as of version 1.2, that helper has the following problems:

    1. It calls sys.exit().
    2. It discards the existing SIGINT handler completely.
    3. It leaves its own handler in place even after an uninterrupted finish,
       which will have unexpected delayed effects if the user triggers an
       unrelated keyboard interrupt some time after a progress-displaying
       download has already completed, for example.
    cs4tt|ƒj||Žtt|jƒ|_|jdkr0t|_dS)z=
        Save the original SIGINT handler for later.
        N)Úsuperr#Ú__init__rrÚ
handle_sigintÚoriginal_handlerr)ÚselfÚargsÚkwargs)Ú	__class__r r!r%Ns
zInterruptibleMixin.__init__cstt|ƒjƒtt|jƒdS)z½
        Restore the original SIGINT handler after finishing.

        This should happen regardless of whether the progress display finishes
        normally, or gets interrupted.
        N)r$r#Úfinishrrr')r()r+r r!r,^szInterruptibleMixin.finishcCs|jƒ|j||ƒdS)z²
        Call self.finish() before delegating to the original SIGINT handler.

        This handler should only be in place while the progress display is
        active.
        N)r,r')r(ÚsignumÚframer r r!r&hsz InterruptibleMixin.handle_sigint)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%r,r&Ú
__classcell__r r )r+r!r#<s
r#csJeZdZ‡fdd„Zedd„ƒZedd„ƒZedd„ƒZdd
d„Z‡Z	S)
ÚDownloadProgressMixincs,tt|ƒj||Ždtƒd|j|_dS)Nú é)r$r4r%r	Úmessage)r(r)r*)r+r r!r%uszDownloadProgressMixin.__init__cCs
t|jƒS)N)rÚindex)r(r r r!Ú
downloadedysz DownloadProgressMixin.downloadedcCs |jdkrdStd|jƒdS)Ngz...éz/s)Úavgr)r(r r r!Údownload_speed}s
z$DownloadProgressMixin.download_speedcCs|jrd|jSdS)Nzeta %sÚ)ÚetaÚeta_td)r(r r r!Ú
pretty_eta„s
z DownloadProgressMixin.pretty_etar:ccs*x|D]}|V|j|ƒqW|jƒdS)N)Únextr,)r(ÚitÚnÚxr r r!ÚiterŠs
zDownloadProgressMixin.iter)r:)
r/r0r1r%Úpropertyr9r<r@rEr3r r )r+r!r4ss
r4cseZdZ‡fdd„Z‡ZS)ÚWindowsMixincs\trˆjrdˆ_ttˆƒj||ŽtrXtrXtjˆjƒˆ_‡fdd„ˆj_‡fdd„ˆj_	dS)NFcsˆjjjƒS)N)rÚwrappedÚisattyr )r(r r!Ú<lambda>§sz'WindowsMixin.__init__.<locals>.<lambda>csˆjjjƒS)N)rrHÚflushr )r(r r!rJ«s)
rÚhide_cursorr$rGr%rÚAnsiToWin32rrIrK)r(r)r*)r+)r(r!r%“s
zWindowsMixin.__init__)r/r0r1r%r3r r )r+r!rG‘srGc@seZdZejZdZdZdS)ÚDownloadProgressBarz
%(percent)d%%z0%(downloaded)s %(download_speed)s %(pretty_eta)sN)r/r0r1ÚsysÚstdoutrr7Úsuffixr r r r!rN®srNc@s&eZdZejZdZdd„Zdd„ZdS)ÚDownloadProgressSpinnerz!%(downloaded)s %(download_speed)scCs"t|dƒstj|jƒ|_t|jƒS)NÚ_phaser)ÚhasattrÚ	itertoolsÚcyclerrSrA)r(r r r!Ú
next_phase¼s
z"DownloadProgressSpinner.next_phasecCsN|j|}|jƒ}|j|}dj||r*dnd||r6dnd|gƒ}|j|ƒdS)Nr=r5)r7rWrQrÚwriteln)r(r7ÚphaserQÚliner r r!ÚupdateÁs



zDownloadProgressSpinner.updateN)	r/r0r1rOrPrrQrWr[r r r r!rR¶srRccsRtrdVnB|jƒs$tjƒtjkr,dVn"|jtƒz
dVWd|jtƒXdS)N)	rrIÚloggerÚgetEffectiveLevelÚloggingÚINFOÚwriterr)rr r r!Ú
hidden_cursorØs

rac@s$eZdZdd„Zdd„Zdd„ZdS)ÚRateLimitercCs||_d|_dS)Nr)Ú_min_update_interval_secondsÚ_last_update)r(Úmin_update_interval_secondsr r r!r%ìszRateLimiter.__init__cCstjƒ}||j}||jkS)N)Útimerdrc)r(ÚnowÚdeltar r r!Úreadyðs
zRateLimiter.readycCstjƒ|_dS)N)rfrd)r(r r r!ÚresetõszRateLimiter.resetN)r/r0r1r%rirjr r r r!rbësrbc@s.eZdZddd„Zdd„Zdd	„Zd
d„ZdS)
ÚInteractiveSpinnerNú-\|/çÀ?cCs\||_|dkrtj}||_t|ƒ|_d|_tj|ƒ|_	|jj
dtƒ|jdƒd|_dS)NFr5z ... r)
Ú_messagerOrPÚ_filerbÚ
_rate_limiterÚ	_finishedrUrVÚ_spin_cycler`r	Ú_width)r(r7rÚ
spin_charsrer r r!r%ús
zInteractiveSpinner.__init__cCs^|jst‚d|j}|jj|d|j|ƒ|jj|ƒt|ƒ|_|jjƒ|jjƒdS)Núr5)	rqÚAssertionErrorrsror`ÚlenrKrprj)r(ÚstatusÚbackupr r r!Ú_write	s


zInteractiveSpinner._writecCs,|jr
dS|jjƒsdS|jt|jƒƒdS)N)rqrprirzrArr)r(r r r!Úspins

zInteractiveSpinner.spincCs4|jr
dS|j|ƒ|jjdƒ|jjƒd|_dS)NÚ
T)rqrzror`rK)r(Úfinal_statusr r r!r,s

zInteractiveSpinner.finish)Nrlrm)r/r0r1r%rzr{r,r r r r!rkùs


rkc@s.eZdZddd„Zdd„Zdd„Zdd	„Zd
S)ÚNonInteractiveSpinneré<cCs$||_d|_t|ƒ|_|jdƒdS)NFÚstarted)rnrqrbrpÚ_update)r(r7rer r r!r%*s
zNonInteractiveSpinner.__init__cCs*|jst‚|jjƒtjd|j|ƒdS)Nz%s: %s)rqrvrprjr\Úinforn)r(rxr r r!r0s
zNonInteractiveSpinner._updatecCs&|jr
dS|jjƒsdS|jdƒdS)Nzstill running...)rqrprir)r(r r r!r{5s

zNonInteractiveSpinner.spincCs$|jr
dS|jd|fƒd|_dS)Nzfinished with status '%s'T)rqr)r(r}r r r!r,<szNonInteractiveSpinner.finishN)r)r/r0r1r%rr{r,r r r r!r~)s
r~ccs˜tjjƒr"tjƒtjkr"t|ƒ}nt|ƒ}y t	tjƒ|VWdQRXWn>t
k
rj|jdƒ‚Yn*tk
rˆ|jdƒ‚YnX|jdƒdS)NÚcanceledÚerrorÚdone)
rOrPrIr\r]r^r_rkr~raÚKeyboardInterruptr,Ú	Exception)r7Úspinnerr r r!Úopen_spinnerCs


r‰)/Ú
__future__rrrUrOrrrrfÚ
contextlibr^Ú
pip.compatrÚ	pip.utilsrÚpip.utils.loggingr	Úpip._vendorr
Úpip._vendor.progress.barrrZpip._vendor.progress.helpersr
rrÚpip._vendor.progress.spinnerrrr‡Ú	getLoggerr/r\r"Ú_BaseBarÚobjectr#r4rGrNrRÚcontextmanagerrarbrkr~r‰r r r r!Ú<module>sB


7
!0