Xj{dZddlmZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl ZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ejFdZ$GddejJZ& d.dZ'e jPdk(rdZ)dZ*ndZ)dZ*GddejVe$Z,GddejZZ. d/ d0d Z/ej`d/d1d!Z1ej` d/ d2d"Z2ej` d/ d2d#Z3ej` d/ d3d$Z4Gd%d&Z5d4d5d'Z6d6d(Z7e jpd)k(rddl9Z9ej`d7d*Z:d8d+Z;yddl , 2.F|  ~ @AAvv0%-@H&*8n   "  %)YY[0 T]$# %)" &*tyy) &*rc4d|_|j|S)NT)rJrender_progressrNs r __enter__zProgressBar.__enter__s   rc$|jyN) render_finish)rNexc_type exc_valuetbs r__exit__zProgressBar.__exit__s rcp|js td|j|jS)N.You need to use progress bars in a with block.)rJ RuntimeErrorrR generatorrSs r__iter__zProgressBar.__iter__s.||OP P ~~rc*tt|SrV)nextr@rSs r__next__zProgressBar.__next__s DJrc|js |jsy|jjt|jj yrV)r/rLr5write AFTER_BARflushrSs rrWzProgressBar.render_finishs0 ;;dmm   " rc|jryt|jt|jxsdxsdz dS)N?r)rHminrBfloatrArSs rpctzProgressBar.pcts5 ==488uT[[%5A6;!>DHH A"fG "HA"fG "HAFE "HA1u<CCf D 1WRL'">>rclt|j}|j|d|jz }|S)N/)strrBrA)rNrBs r format_poszProgressBar.format_poss3$((m ;; " Qt{{m$ $C rc@t|jdzddddS)Ndz 4%r)r~rlrSs r format_pctzProgressBar.format_pcts&dhhn%b)+AB//rcF|jRt|j|jz}|j|z}||j |j|z zz }|S|j r|j|jz}|St|j |jxsdz}|jdk7rU|j|ttj|j|jzdz dz|jz<dj|}|S)Nrrg@g?r() rAr~rlr9r+r,rHlistrqmathcosrBjoin)rN bar_lengthbarcharss r format_barzProgressBar.format_bars ;; "TXX 23J..:-C 4??djj:&=> >C ]]..4::-C DJJO!<=E&&!+ NN $((T-D-D"DEKcQ**% ''%.C rc|j}g}|j| |j }|jr|j|j |r|j|j |j r7|jr+|js|j|j|j.|j|j}||j||j|j|j|jj!|dzj#S)N)r4rinfo)r1rAr2appendrrr0rGrHrr3rKr-r4rr.rrstrip)rNr1 info_bits item_infos rformat_progress_linez ProgressBar.format_progress_lines((  ;; "|';#}},L ==   T__. /    T__. / ==T^^DMM   T__. /    *++D,=,=>I$  +   ( **95  &( rcX|jry|jsW|j|jk7r=|j|_t |j|j |j yg}|jrddl}|j}d|_ t|j}td|jj|z }||krF|j:|j!t"|j!d|jz||_||_ |j}|j |j}|j!t"|j}t|}|j|j|kr||_|j!||j!d||z zdj%|}||jk7rE||_t ||j |j d|j j'yy)N)r5r6r r(F)r5r6nl)r/rLrMr4rr5r6r:shutilr9rrmaxget_terminal_sizecolumnsrIr BEFORE_BARrrg) rNbufr old_widthclutter_length new_width clear_widthlineline_lens rrRzProgressBar.render_progresss ;; }}$**,"&**TZZdiitzzB  >>  IDJ%d&?&?&ABNAv779AANRSI9$)C :& 3/0!*"DJjj >> %..K :((*D> >> !T^^h%>%DN 4 3+012wws| 4?? ""DO DIITZZE B IIOO  #rc|xj|z c_|j |j|jk\rd|_tj|jz dkrytj|_|jr/tj|j z |jz }n!tj|j z }|j dd|gz|_|jdu|_y)NTrii)rBrArHrDrFrErCrG)rNn_stepssteps r make_stepzProgressBar.make_step.s G ;; "txx4;;'> DM IIK$-- '3 .   88IIK$**,8D99;+D88BC=D6)D0rc|||_|xj|z c_|j|jk\r3|j|j|j d|_yy)aUpdate the progress bar by advancing a specified number of steps, and optionally set the ``current_item`` for this new position. :param n_steps: Number of steps to advance. :param current_item: Optional item to set as ``current_item`` for the updated position. .. versionchanged:: 8.0 Added the ``current_item`` optional parameter. .. versionchanged:: 8.0 Only render when the number of steps meets the ``update_min_steps`` threshold. Nr)rKr8r7rrR)rNrrKs rupdatezProgressBar.updateDsb  # ,D  !!W,!  $ $(=(= = NN444 5  "()D % >rc.d|_d|_d|_y)NFT)rGrKrHrSs rfinishzProgressBar.finish^s  rc#XK|js td|js|jEd{y|jD]=}||_|j dk(r|j ||jd?|j|j y7rw)zReturn a generator which yields the items added to the bar during construction, and updates the progress bar *after* the yielded block returns. r]Nrr) rJr^rLr@rKr8rRrr)rNrvs rr_zProgressBar.generatorcs||OP P}}yy ii $&! ,,1((* A  KKM  " !s3B*B(A3B*)N#rz%(bar)sz FTNFNNNNr)"rOzcabc.Iterable[V] | NonerAz int | Noner+rr,rr-rr.rr/boolr0rr1 bool | Noner2rr3z)t.Callable[[V | None], str | None] | Noner4 str | Noner5zt.TextIO | Noner6rr7r~r9r~returnNone)rzProgressBar[V])rXztype[BaseException] | NonerYzBaseException | NonerZzTracebackType | Nonerr)rzcabc.Iterator[V])rr)rr)rrkrr)rr~rrrV)rr~rKzV | Nonerr)rrrrPrTr[r`rcrWpropertyrlrqrsrrrrrrRrrrr_rrrr&r&9s"%$(DH $! !#E+)E+E+ E+  E+  E+E+E+E+"E+E+BE+E+E+E+ !E+"#E+$ %E+N ,( !      CC 44  * 0&6,\1,*4 #rr&c,eZdZdfd Zdfd ZxZS)MaybeStripAnsic 4t||fi|||_yrV)superrPr6)rNr r6kwargs __class__s rrPzMaybeStripAnsi.__init__s *6* rcP|js t|}t| |SrV)r6r rre)rNtextrs rrezMaybeStripAnsi.writes#zzd#Dw}T""r)r z t.IO[bytes]r6rrzt.Any)rrrr~)rrrrPre __classcell__)rs@rrrs##rrc t}| t}ttjr t|s t ||St jtjjdd}|rtr t||St||Stjjddvr t ||Ststjjdr tdg|Stdg|S)z2Decide what method to use for paging through text.PAGERr(TERM)dumbemacsos2moreless)r rr sysstdin _nullpagershlexsplitosenvirongetr_tempfilepager _pipepagerplatform startswith)r6stdoutpager_cmd_partss r_pager_contextmanagerrs" #F~ #)) F6N&%(( kk"**..""=>O !/59 9/511 zz~~f!22&%(( cll%%e,vh.. vh &&rc#Kt|5\}}}d}t|rt|j||}|} t j tj | |j||j dddy#||jwwxYw# |j||jww#||jwwxYwxYw#1swYyxYww)zContext manager. Yields a writable file-like object which can be used as an output pager. .. versionadded:: 8.4.0 :param color: controls if the pager supports ANSI colors or not. The default is autodetection. )r6N)r6encoding) rr!rrr=r>TextIOrgdetach)r6r rwrappers rget_pager_filers U +%/H%*. f %$V]]%(SGF %&&6* * % &NN$1%%.&NN$' % &NN$'7&NN$'/%%s] C4,C(&B'#B3C( C4B$$C('C%)C 9C% C" "C%%C((C1-C4c#K|s0txs t}t||5}|dddyddl}|d}|dd}|j |}|s0txs t}t||5}|dddyt |j }|j} ddl} ttj} |L| dk(rGtjjdddj|} | sd| d<d }n d | vsd | vrd }|d }| jt|g|zd | j | d d } t#j$t"j&| j(}t+|} |||f |j3 | j5y#1swYyxYw#1swYyxYw#t,$rYGt.$r}| j1|d}~wwxYw#t,$rYcwxYw#t6$rYnwxYwv# |j3n#t,$rYnwxYw | j5w#t6$rYnwxYw"xYww)aPage through text by feeding it to another program. Invokes the pager via :class:`subprocess.Popen` with an ``argv`` list produced by :func:`shlex.split`. The command is resolved to an absolute path with :func:`shutil.which` as recommended by the :mod:`subprocess` docs for Windows compatibility. Invoking a pager through this might support colors: if piping to ``less`` and the user hasn't decided on colors, ``LESS=-R`` is set automatically. NrrrLESSr(r-RTrRFreplace)shellrenverrorsr)r rrrwhichrabsolutename subprocessdictrrrrPopenrPIPEr=r>BinaryIOrr BrokenPipeError Exception terminateclosewaitKeyboardInterrupt) cmd_partsr6rrrcmd cmd_params cmd_filepathcmd_pathcmd_namerr less_flagscrres rrrsx &'58:  & "H  A,C12J<<$L &'58:  & "H  L!**,H}}H rzz C }V+ vr23CHHZ4H3IJ CKE J #"3E } X*$oo    A FF1::qww 'E 'H#Xu$$  KKM o  L        %    KKM    %  s%IF-A I8F9=DIG G2IH,I-F62I9G>I G/HG/G**G//H2 G>;I=G>>I H  I H  IIH$#I$ H0-I/H00I5II IIIIIc#@K|s0txs t}t||5}|dddyddl}ddl}|d}|j |}|s0txs t}t||5}|dddyt |j}ddl} ttj} |d}| jdd} tjtj| | |f| j!| j#|j%t'|| j(gt+j,| j(y#1swYyxYw#1swYyxYw#t+j,| j(wxYww)a Page through text by invoking a program on a temporary file. Used as the primary pager strategy on Windows (where piping to ``more`` adds spurious ``\r\n``), and as a fallback on other platforms. The command is resolved to an absolute path with :func:`shutil.which`. NrFwb)modedelete)r rrrrrrrtempfiler rrNamedTemporaryFiler=r>rrgrcallrrrunlink) rr6rrrrrrrr rfs rrrCsQ &'58:  & "H  A,C<<$L &'58:  & "H  L!**,H ,H } ##e#&C99C>cyrVrrNrs reditz Editor.edits=@rcyrVrr&s rr'z Editor.edits47rcddl}|d}njt|ttfr|}nQ|r|j ds|dz }t r"|j ddjd}n|jd}|jd|j\}} tj|d 5}|j|dddtj|tjj|tjj!|d z ftjj!|}|j#|f|j$r9tjj!||k(r tj&|yt)|d 5}|j+}dddt|ttfrtj&|Sj-dj ddtj&|S#1swY]xYw#1swYyxYw#tj&|wxYw) Nrrr$z z utf-8-sigzutf-8zeditor-)prefixsuffixrrb)r  isinstancebytes bytearrayendswithrrencodemkstemprrfdopenreutimepathgetatimegetmtimer$rr openreaddecode) rNrr datafdrr  timestamprs rr'z Editor.edits <&)D ui0 1DDMM$/ ||D&188E{{7+##9T^^#LD 2t$    HHTBGG,,T2BGG4D4DT4JQ4NO P((.I OOTG $  RWW%5%5d%;y%H IIdOdD! QVVX $ 23 IIdO99[)11&$? IIdO3  "   IIdOsIH1+H=B._unquote_files&( >>) $#ab'"C rdarwinr9z-Wrz /dev/nullw)stderrexplorerz/select,cygstartz-w.zxdg-open)zhttp://zhttps://r)rErrr)rrrrr9rrrrr r!r startfiler r6dirnamer webbrowser) rErlocaterrFrnullrrPs ropen_urlrSs ||xx  KK   KK  M#&'K% ##D#6;;= JJL $C C0D !t,,  S!  $C 45D>1 26$  OOC  sU) F0F3G2GAG F03 F?>F? G G GG 3HHcx|dk(r t|dk(rts t|dk(rtr tyy)N)rrEOFError)chs r_translate_ch_to_excrZJs; V|!! V|Cj V|j|rwin32c#Kdyw)Nr*rrrr raw_terminalr]Xs sc8|rCallablermsvcrtgetwchegetwchrZ)rfuncrs rgetcharrf\ss> 66!**RW-v~~>D66!**RW-v}}=D V ! ! $&LBR  rc#Kttjstd}|j }n tjj }d} t j |} tj||t j|t j|tjj||jyy#t j|t j|tjj||jwwxYw#t j$rYywxYww)Nz/dev/tty)r rrr9filenotermios tcgetattrttysetraw tcsetattr TCSADRAINrrgrerror)r r= old_settingss rr]r]s cii Z AB!!#BA ",,R0L  2!!"g&7&7F   "=GGI!!!"g&7&7F   "=GGI!}}   sDAED:/CAD:EAD77D::E EEEcJt5}tj|djt t j d}|r8tt jrt jj|t||cdddS#1swYyxYw)N r) r]rr:r;r rrr rrerZ)rr=rYs rrfrfso ^ rR''(9#))(DiPBszz*   $  $   s BBB")r zt.BinaryIO | t.TextIOrz%t.TypeGuard[_BufferedTextPagerStream]rV)r6rrz9t.ContextManager[tuple[t.BinaryIO | t.TextIO, str, bool]])r6rrz!t.Generator[t.TextIO, None, None])rz list[str]r6rrz3t.Iterator[tuple[t.BinaryIO | t.TextIO, str, bool]])r zt.TextIOr6rrz&t.Iterator[tuple[t.TextIO, str, bool]])FF)rErrrrQrrr~)rYrrr)rzcabc.Iterator[int])rrrr)>__doc__ __future__rcollections.abcabccabc contextlibiorrrrrDtypingr=rrrpathlibrtypesr_compatr r r r r rr exceptionsrutilsrrTypeVarrProtocolrr!rrrfGenericr& TextIOWrapperrrcontextmanagerrrrrrrSrZrrbr]rfrirkrrrrs #  )&& AIIcNqzz7 !7*777d?JIJII#!))A,I#X #R%%#' '>'> "%"%J /3jj!,j8jjZ /355!,5855p +/0 0(0+00&qqhCL<<7,^4r