
    Mh                         d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZmZ dd	lmZ ej        d
fdZe
 G d de	                      ZdS )zExtra magics for terminal use.    )errorN)TryNext
UsageError)Magicsmagics_class
line_magic)ClipboardEmpty)skip_doctest)SListstrip_email_quotes)	py3compatFc              #      K   |st          d| z             d}nd}	 	  ||          }|| k    rdS |V  n # t          $ r t          d           Y dS w xY w:)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<EOF>)printEOFError)sentinell_inputquietpromptls        W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/terminal/magics.pyget_pasted_linesr      s        Q 	 	 			AH}} 	 	 	'NNNFF		s   6 6 AAc                        e Zd Z fdZddZd ZddZedd            Ze	edd	                        Z
edd
            Zej        dk    red             Z xZS  xZS )TerminalMagicsc                 X    t          t          |                               |           d S )N)superr   __init__)selfshell	__class__s     r   r   zTerminalMagics.__init__)   s'    nd##,,U33333    Fc                 `   |rBt          |                                          | j        j        |<   t	          d|z             dS |                     |          }|| j        j        d<   d| j        _        	 | j                            ||           d| j        _        dS # d| j        _        w xY w)zM Execute a block, or store it in a variable, per the user's request.
        zBlock assigned to '%s'pasted_blockTFN)r   
splitlinesr    user_nsr   preclean_inputusing_paste_magicsrun_cell)r   blocknamestore_historybs        r   store_or_executezTerminalMagics.store_or_execute,   s      	6',U-=-=-?-?'@'@DJt$*T122222##E**A12DJ~.,0DJ)6
##A}55505
---
-5555s   6B B-c                     |                                 }|r@|d                                         s&|dd          }|r|d                                         &t          d                    |                    S )Nr      
)r%   stripr   join)r   r*   liness      r   r'   zTerminalMagics.preclean_input<   sv      "" 	E!HNN,, 	!""IE  	E!HNN,, 	!$))E"2"2333r"   r$   c                 X   | j         j                            |          }|t          d          t	          |t
                    st          d          t          d|                    dd          d         t          |          fz             | j         	                    |           dS )z, Rerun a previously pasted command.
        Nz"No previous pasted block availablez6Variable 'pasted_block' is not a string, can't executezRe-executing '%s...' (%d chars)r1   r0   r   )
r    r&   getr   
isinstancestrr   splitlenr)   )r   r+   r-   s      r   rerun_pastedzTerminalMagics.rerun_pastedB   s     J""4(( 9ABBB!S!! 	JHJ J J 	/!''$q//!2Dc!ff1MMNNN
Ar"   r   c                 |    | j                                          t          dddg| j         j                            dS )z%Toggle autoindent on/off (deprecated)zAutomatic indentation is:OFFONN)r    set_autoindentr   
autoindent)r   parameter_ss     r   r@   zTerminalMagics.autoindentQ   s=     	
!!###)5,tz7L*MNNNNNr"   c                    |                      |dd          \  }}d|v r|                                  dS d|v }|                    dd          }d	                    t	          ||
                    }|                     ||d           dS )u  Paste & 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)
        zrqs:stringmoderNqsz--r1   )r   Tr,   )parse_optionsr;   r6   r3   r   r.   )r   rA   optsr+   r   r   r*   s          r   cpastezTerminalMagics.cpasteW   s    l ''V('KK
d$;;F88C''		*85AAABBeT>>>>>r"   c                    |                      |dd          \  }}d|v r|                                  dS 	 | j        j                                        }nl# t
          $ rB}t          |d          }|rt          |d                    nt          d           Y d}~dS d}~wt          $ r}t          d	          |d}~ww xY wd
|vrt          j                            | j                            |                     |                    d          st          j                            d           t          j                            d           |                     ||d           dS )a  Paste & 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.
        rqrC   rD   rF   Nargsr   z&Could not get text from the clipboard.z!The clipboard appears to be emptyrG   r1   z## -- End pasted text --
TrI   )rJ   r;   r    hooksclipboard_getr   getattrr   r	   r   sysstdoutwrite
pycolorizeendswithr.   )r   rA   rK   r+   r*   clipboard_excmessagees           r   pastezTerminalMagics.paste   s   > ''T'II
d$;;F
	IJ$2244EE 	 	 	mV44G @gaj!!!!>???FFFFF 	I 	I 	I@AAqH	I d??JTZ22599:::>>$'' '
  &&&J9:::eT>>>>>s#   A 
B? 7BB?*B::B?win32c                 .    t          j        d           dS )zClear screen.
            clsN)ossystem)r   rH   s     r   r^   zTerminalMagics.cls   s     Ier"   )F)r$   )r   )__name__
__module____qualname__r   r.   r'   r;   r   r@   r
   rL   r[   rS   platformr^   __classcell__)r!   s   @r   r   r   '   s       4 4 4 4 46 6 6 6 4 4 4    O O O ZO
 =? =? =? Z \=?~ 5? 5? 5? Z5?p |w		 	 
	 	 	 	 	 r"   r   )__doc__loggingr   r_   rS   IPython.core.errorr   r   IPython.core.magicr   r   r   IPython.lib.clipboardr	   IPython.testing.skipdoctestr
   IPython.utils.textr   r   IPython.utilsr   inputr   r    r"   r   <module>rp      s   $ $       				 



 2 2 2 2 2 2 2 2 ? ? ? ? ? ? ? ? ? ? 0 0 0 0 0 0 4 4 4 4 4 4 8 8 8 8 8 8 8 8 # # # # # #'0e    * n n n n nV n n n n nr"   