Ë
    7;h  ã                   ó¼   — 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y)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y|–— 	 Œ# t        $ r t        d«       Y yw xY w­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.Ú:Ú Nz<EOF>)ÚprintÚEOFError)ÚsentinelÚl_inputÚquietÚpromptÚls        úh/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/IPython/terminal/magics.pyÚget_pasted_linesr      sg   è ø€ ñ ÜÐQØñô 	à‰àˆØ
ð	Ù˜“ˆAØ�HŠ}Øà“ð øô ò 	Ü�'ŒNÙð	üs.   ‚Aš. §A¨. ¬A®AÁAÁ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                 ó,   •— t         t        | �  |«       y )N)Úsuperr   Ú__init__)ÚselfÚshellÚ	__class__s     €r   r   zTerminalMagics.__init__)   s   ø€ ÜŒn˜dÑ,¨UÕ3ó    c                 ó„  — |r?t        |j                  «       «      | j                  j                  |<   t	        d|z  «       y| j                  |«      }|| j                  j                  d<   d| j                  _        	 | j                  j                  ||«       d| j                  _        y# 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™   € ñ ä',¨U×-=Ñ-=Ó-?Ó'@ˆD�J‰J×Ñ˜tÑ$ÜÐ*¨TÑ1Õ2à×#Ñ# EÓ*ˆAØ12ˆD�J‰J×Ñ˜~Ñ.Ø,0ˆD�J‰JÔ)ð6Ø—
‘
×#Ñ# A }Ô5à05�—
‘
Õ-ø°�—
‘
Õ-ús   Á>B, Â,B?c                 ó¶   — |j                  «       }|r.|d   j                  «       s|dd  }|r|d   j                  «       sŒt        dj                  |«      «      S )Nr   é   Ú
)r%   Ústripr   Újoin)r   r*   Úliness      r   r'   zTerminalMagics.preclean_input<   sQ   € Ø× Ñ Ó"ˆÙ˜E !™HŸN™NÔ,Ø˜!˜"�IˆEñ ˜E !™HŸN™NÕ,ä! $§)¡)¨EÓ"2Ó3Ð3r"   c                 ó,  — | j                   j                  j                  |«      }|€t        d«      ‚t	        |t
        «      st        d«      ‚t        d|j                  dd«      d   t        |«      fz  «       | j                   j                  |«       y)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‰J×Ñ×"Ñ" 4Ó(ˆð ˆ9ÜÐAÓBÐBÜ˜!œSÔ!ÜØHóJð Jô 	Ð/°!·'±'¸$¸q³/À!Ñ2DÄcÈ!ÃfÐ1MÑMÔNØ�
‰
×Ñ˜AÕr"   c                 ó‚   — | j                   j                  «        t        dddg| j                   j                     «       y)z%Toggle autoindent on/off (deprecated)zAutomatic indentation is:ÚOFFÚONN)r    Úset_autoindentr   Ú
autoindent)r   Úparameter_ss     r   r@   zTerminalMagics.autoindentQ   s2   € ð 	�
‰
×!Ñ!Ô#ÜÐ)¨5°¨,°t·z±z×7LÑ7LÑ*MÕNr"   c                 óè   — | j                  |dd¬«      \  }}d|v r| j                  «        yd|v }|j                  dd«      }d	j                  t	        ||¬
«      «      }| j                  ||d¬«       y)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   sz   € ðl ×'Ñ'¨°VÀ(Ð'ÓK‰
ˆˆdØ�$‰;Ø×ÑÔØà˜�ˆà—8‘8˜C Ó'ˆØ—	‘	Ô*¨8¸5ÔAÓBˆØ×Ñ˜e T¸ÐÕ>r"   c                 ó�  — | j                  |dd¬«      \  }}d|v r| j                  «        y	 | j                  j                  j	                  «       }d
|vr‡t        j                  j                  | j                  j                  |«      «       |j                  d«      st        j                  j                  d«       t        j                  j                  d«       | j                  ||d¬«       y# t
        $ r2}t        |d«      }|rt        |d   «       nt        d«       Y d}~yd}~wt        $ r}t        d	«      |‚d}~ww xY w)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‰
ˆˆdØ�$‰;Ø×ÑÔØð
	IØ—J‘J×$Ñ$×2Ñ2Ó4ˆEð �d‰?Ü�J‰J×Ñ˜TŸZ™Z×2Ñ2°5Ó9Ô:Ø—>‘> $Ô'Ü—
‘
× Ñ  Ô&Ü�J‰J×ÑÐ9Ô:à×Ñ˜e T¸ÐÕ>øô# ò 	Ü˜m¨VÓ4ˆGÙÜ�g˜a‘jÕ!äÐ>Ô?ÜûÜò 	IÜÐ@ÓAÀqÐHûð	Iús#   ®$C2 Ã2	EÃ;(D(Ä(EÄ4E Å EÚwin32c                 ó.   — t        j                  d«       y)zClear screen.
            ÚclsN)ÚosÚsystem)r   rH   s     r   r^   zTerminalMagics.clsÒ   s   € ô �I‰I�eÕ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ó6ò 4óð òOó ðOð
 Øò=?ó ó ð=?ð~ ò5?ó ð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      sT   ðÙ $õ Û 	Û 
ç 2ß ?Ñ ?Ý 0Ý 4ß 8Ý #à'0§¡¸eó ð* ôn�Vó nó ñnr"   