}BFjdZddlmZddlZddlZddlmZmZddlm Z m Z m Z ddl m Z ddlmZddlmZmZdd lmZejd fd Ze Gd d e ZdS)zExtra magics for terminal use.)errorN)TryNext UsageError)Magics magics_class line_magic)ClipboardEmpty) skip_doctest)SListstrip_email_quotes) py3compatFc#K|std|zd}nd} ||}||krdS|Vn #t$rtdYdSwxYw:)zH Yield pasted lines until the user enters the given sentinel value. zAPasting code; enter '%s' alone on the line to stop or use Ctrl-D.:TNz)printEOFError)sentinell_inputquietpromptls EC:\PYTHON\_runtimes\venv\Lib\site-packages\IPython/terminal/magics.pyget_pasted_linesrs  Q     AH}}    'NNN FF  s66AAceZdZfdZd dZdZddZeddZe edd Z edd Z e j d kred ZxZSxZS)TerminalMagicscXtt||dS)N)superr__init__)selfshell __class__s rrzTerminalMagics.__init__)s' nd##,,U33333Fc`|rBt||jj|<t d|zdS||}||jjd<d|j_ |j||d|j_dS#d|j_wxYw)zM Execute a block, or store it in a variable, per the user's request. zBlock assigned to '%s' pasted_blockTFN)r splitlinesr user_nsrpreclean_inputusing_paste_magicsrun_cell)rblockname store_historybs rstore_or_executezTerminalMagics.store_or_execute,s  6',U-=-=-?-?'@'@DJ t $ *T1 2 2 2 2 2##E**A12DJ ~ .,0DJ ) 6 ##A}55505 --- -5555s 6BB-c|}|r@|ds&|dd}|r|d&td|S)Nr )r%stripr join)rr*liness rr'zTerminalMagics.preclean_input<sv  "" E!HNN,, !""IE E!HNN,, !$))E"2"2333r"r$cX|jj|}|tdt |t stdt d|dddt|fz|j |dS)z, Rerun a previously pasted command. Nz"No previous pasted block availablez6Variable 'pasted_block' is not a string, can't executezRe-executing '%s...' (%d chars)r1r0r) r r&getr isinstancestrrsplitlenr))rr+r-s r rerun_pastedzTerminalMagics.rerun_pastedBs J  " "4 ( ( 9ABB B!S!! JHJJ J /!''$q//!2Dc!ff1MMNNN Ar"rc||jtdddg|jjdS)z%Toggle autoindent on/off (deprecated)zAutomatic indentation is:OFFONN)r set_autoindentr autoindent)r parameter_ss rr@zTerminalMagics.autoindentQs= !!### )5,tz7L*MNNNNNr"c||dd\}}d|vr|dSd|v}|dd}d t || }|||d dS) uPaste & execute a pre-formatted code block from clipboard. You must terminate the block with '--' (two minus-signs) or Ctrl-D alone on the line. You can also provide your own sentinel with '%paste -s %%' ('%%' is the new sentinel for this operation). The block is dedented prior to execution to enable execution of method definitions. '>' and '+' characters at the beginning of a line are ignored, to allow pasting directly from e-mails, diff files and doctests (the '...' continuation prompt is also stripped). The executed block is also assigned to variable named 'pasted_block' for later editing with '%edit pasted_block'. You can also pass a variable name as an argument, e.g. '%cpaste foo'. This assigns the pasted block to variable 'foo' as string, without dedenting or executing it (preceding >>> and + is still stripped) '%cpaste -r' re-executes the block previously entered by cpaste. '%cpaste -q' suppresses any additional output messages. Do not be alarmed by garbled output on Windows (it's a readline bug). Just press enter and type -- (and press enter again) and the block will be what was just pasted. Shell escapes are not supported (yet). See Also -------- paste : automatically pull code from clipboard. Examples -------- :: In [8]: %cpaste Pasting code; enter '--' alone on the line to stop. :>>> a = ["world!", "Hello"] :>>> print(" ".join(sorted(a))) :-- Hello world! :: In [8]: %cpaste Pasting code; enter '--' alone on the line to stop. :>>> %alias_magic t timeit :>>> %t -n1 pass :-- Created `%t` as an alias for `%timeit`. Created `%%t` as an alias for `%%timeit`. 354 ns ± 224 ns per loop (mean ± std. dev. of 7 runs, 1 loop each) zrqs:stringmoderNqsz--r1)rTr,) parse_optionsr;r6r3rr.)rrAoptsr+rrr*s rcpastezTerminalMagics.cpasteWsl'' V('KK d $;;       F88C'' *85AAABB eT>>>>>r"c||dd\}}d|vr|dS |jj}nl#t $rB}t |d}|rt|dntdYd}~dSd}~wt$r}td |d}~wwxYwd |vrtj |j ||d stj d tj d |||d dS)aPaste & execute a pre-formatted code block from clipboard. The text is pulled directly from the clipboard without user intervention and printed back on the screen before execution (unless the -q flag is given to force quiet mode). The block is dedented prior to execution to enable execution of method definitions. '>' and '+' characters at the beginning of a line are ignored, to allow pasting directly from e-mails, diff files and doctests (the '...' continuation prompt is also stripped). The executed block is also assigned to variable named 'pasted_block' for later editing with '%edit pasted_block'. You can also pass a variable name as an argument, e.g. '%paste foo'. This assigns the pasted block to variable 'foo' as string, without executing it (preceding >>> and + is still stripped). Options: -r: re-executes the block previously entered by cpaste. -q: quiet mode: do not echo the pasted text back to the terminal. IPython statements (magics, shell escapes) are not supported (yet). See Also -------- cpaste : manually paste code into terminal until you mark its end. rqrCrDrFNargsrz&Could not get text from the clipboard.z!The clipboard appears to be emptyrGr1z## -- End pasted text -- TrI)rJr;r hooks clipboard_getrgetattrrr rsysstdoutwrite pycolorizeendswithr.)rrArKr+r* clipboard_excmessagees rpastezTerminalMagics.pastes>'' T'II d $;;       F IJ$2244EE   mV44G @gaj!!!!>??? FFFFF I I I@AAq H I d?? J  TZ22599 : : :>>$'' '   &&& J  9 : : : eT>>>>>s#A B? 7B B?*B::B?win32c.tjddS)zClear screen. clsN)ossystem)rrHs rr^zTerminalMagics.clss Ie     r")F)r$)r)__name__ __module__ __qualname__rr.r'r;rr@r rLr[rSplatformr^ __classcell__)r!s@rrr's444446666 444    OOOZO =?=?=?Z\=?~5?5?5?Z5?p |w         r"r)__doc__loggingrr_rSIPython.core.errorrrIPython.core.magicrrrIPython.lib.clipboardr IPython.testing.skipdoctestr IPython.utils.textr r IPython.utilsr inputrrr"rrps$$  22222222??????????00000044444488888888######'0e*nnnnnVnnnnnr"