o
    û›hƒK  ã                   @   sž  d Z ddlZddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ dZdZd	Zd
ZdZdZdZdZdZeeeeeeeeeg	ZG dd„ dejd�ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZejdd„ ƒZde de de d e fd!d"„Z!d#efd$d%„Z"d#efd&d'„Z#d#efd(d)„Z$d#efd*d+„Z%d#efd,d-„Z&d#efd.d/„Z'd#efd0d1„Z(ee"ee#ee$ee$ee%ee&ee'ee(iZ)ejd2e fd3d4„ƒZ*e +d5¡Z,e +d6ej-¡Z.e/ƒ Z0e/ƒ Z1d7d8„ Z2d9d:„ Z3d;d<„ Z4ejd2e fd=d>„ƒZ5ejdTd@e6fdAdB„ƒZ7dUdCdD„Z8ejdEdF„ ƒZ9ejdGdH„ ƒZ:ejdIdJ„ ƒZ;dKZ<e +dL =e<¡ej-¡Z>dMZ?ejdNdO„ ƒZ@e +dP =e<¡ej-¡ZAdQZBejdRdS„ ƒZCdS )Va,  DEPRECATED: Input transformer classes to support IPython special syntax.

This module was deprecated in IPython 7.0, in favour of inputtransformer2.

This includes the machinery to recognise and transform ``%magic`` commands,
``!system`` commands, ``help?`` querying, prompt stripping, and so forth.
é    N)Ú
untokenizeÚ
TokenError)ÚStringIO)ÚLineInfo)Ú	tokenutilú!z!!ú?ú??ú%z%%ú,ú;ú/c                   @   s@   e Zd ZdZdd„ Zejdd„ ƒZejdd„ ƒZe	dd	„ ƒZ
d
S )ÚInputTransformerz6Abstract base class for line-based input transformers.c                 C   s   t jdtdd� d S )Nz`InputTransformer` has been deprecated since IPython 7.0 and emit a warnig since IPython 8.31, it will be removed in the futureé   ©Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarning©Úself© r   úSc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/inputtransformer.pyÚ__init__/   s
   
ûzInputTransformer.__init__c                 C   ó   dS )a1  Send a line of input to the transformer, returning the transformed
        input or None if the transformer is waiting for more input.

        Must be overridden by subclasses.

        Implementations may raise ``SyntaxError`` if the input is invalid. No
        other exceptions may be raised.
        Nr   ©r   Úliner   r   r   Úpush8   s   
zInputTransformer.pushc                 C   r   )z�Return, transformed any lines that the transformer has accumulated,
        and reset its internal state.

        Must be overridden by subclasses.
        Nr   r   r   r   r   ÚresetD   s   zInputTransformer.resetc                    s   t  ˆ¡‡ ‡fdd„ƒ}|S )z‡Can be used by subclasses as a decorator, to return a factory that
        will allow instantiation with the decorated object.
        c                     s   ˆ ˆfi | ¤ŽS ©Nr   )Úkwargs©ÚclsÚfuncr   r   Útransformer_factoryR   s   z2InputTransformer.wrap.<locals>.transformer_factory)Ú	functoolsÚwraps)r"   r#   r$   r   r!   r   ÚwrapM   s   zInputTransformer.wrapN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚabcÚabstractmethodr   r   Úclassmethodr'   r   r   r   r   r   ,   s    	

r   )Ú	metaclassc                       ó8   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Z‡  ZS )
ÚStatelessInputTransformerzDWrapper for a stateless input transformer implemented as a function.c                    s$   t ƒ  ¡  tjdtdd� || _d S )Nzˆ`StatelessInputTransformer` has been deprecated since IPython 7.0 and emit a warnig since IPython 8.31, it will be removed in the futurer   r   )Úsuperr   r   r   r   r#   ©r   r#   ©Ú	__class__r   r   r   Z   s   
û
z"StatelessInputTransformer.__init__c                 C   ó   d  | j¡S )Nz%StatelessInputTransformer(func={0!r}))Úformatr#   r   r   r   r   Ú__repr__e   ó   z"StatelessInputTransformer.__repr__c                 C   s
   |   |¡S )zQSend a line of input to the transformer, returning the
        transformed input.)r#   r   r   r   r   r   h   s   
zStatelessInputTransformer.pushc                 C   r   )z!No-op - exists for compatibility.Nr   r   r   r   r   r   m   s   zStatelessInputTransformer.reset©	r(   r)   r*   r+   r   r8   r   r   Ú__classcell__r   r   r4   r   r1   X   s    r1   c                       r0   )
ÚCoroutineInputTransformerz<Wrapper for an input transformer implemented as a coroutine.c                    s8   t ƒ  ¡  tjdtdd� |di |¤Ž| _t| jƒ d S )Núˆ`CoroutineInputTransformer` has been deprecated since IPython 7.0 and emit a warnig since IPython 8.31, it will be removed in the futurer   r   r   )r2   r   r   r   r   ÚcoroÚnext)r   r>   r    r4   r   r   r   s   s   
ûz"CoroutineInputTransformer.__init__c                 C   r6   )Nz%CoroutineInputTransformer(coro={0!r}))r7   r>   r   r   r   r   r8   €   r9   z"CoroutineInputTransformer.__repr__c                 C   s   | j  |¡S )z—Send a line of input to the transformer, returning the
        transformed input or None if the transformer is waiting for more
        input.
        ©r>   Úsendr   r   r   r   r   ƒ   s   zCoroutineInputTransformer.pushc                 C   s   | j  d¡S )zrReturn, transformed any lines that the transformer has
        accumulated, and reset its internal state.
        Nr@   r   r   r   r   r   Š   s   zCoroutineInputTransformer.resetr:   r   r   r4   r   r<   q   s    r<   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTokenInputTransformerzÆWrapper for a token-based input transformer.
    
    func should accept a list of tokens (5-tuples, see tokenize docs), and
    return an iterable which can be passed to tokenize.untokenize().
    c                 C   s(   t jdtdd� || _g | _|  ¡  d S )Nr=   r   r   )r   r   r   r#   ÚbufÚreset_tokenizerr3   r   r   r   r   –   s   ûzTokenInputTransformer.__init__c                 C   s   t | jƒ}t |j¡| _d S r   )ÚiterrC   r   Úgenerate_tokens_catch_errorsÚ__next__Ú	tokenizer)r   Úitr   r   r   rD   ¢   s   
z%TokenInputTransformer.reset_tokenizerc                 C   s¨   | j  |d ¡ tdd„ | j D ƒƒr|  ¡ S g }d}z&| jD ] }| |¡ |d }|tjks5|r7|tjkr7 n|tjkr>d}qW n t	yN   |  
¡  Y d S w |  |¡S )NÚ
c                 s   s   � | ]}|  ¡ V  qd S r   )Úisspace)Ú.0Úlr   r   r   Ú	<genexpr>¨   s   € z-TokenInputTransformer.push.<locals>.<genexpr>Fr   T)rC   ÚappendÚallr   rH   ÚtokenizeÚNEWLINEÚNLÚ
ERRORTOKENr   rD   Úoutput)r   r   ÚtokensZ
stop_at_NLZintokÚtr   r   r   r   ¦   s&   


€ý
zTokenInputTransformer.pushc                 C   s&   | j  ¡  |  ¡  t|  |¡ƒ d¡S )NrJ   )rC   ÚclearrD   r   r#   Úrstrip©r   rV   r   r   r   rU   ½   s   
zTokenInputTransformer.outputc                 C   s0   d  | j¡}| j ¡  |  ¡  |r| d¡S d S )NÚ rJ   )ÚjoinrC   rX   rD   rY   )r   rM   r   r   r   r   Â   s   

ÿzTokenInputTransformer.resetN)	r(   r)   r*   r+   r   rD   r   rU   r   r   r   r   r   rB   �   s    rB   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )Úassemble_python_linesc                    s   t ƒ  d ¡ d S r   )r2   r   r   r4   r   r   r   Ê   s   zassemble_python_lines.__init__c                 C   s   |   ¡ S r   )r   rZ   r   r   r   rU   Í   s   zassemble_python_lines.output)r(   r)   r*   r   rU   r;   r   r   r4   r   r]   É   s    r]   c                  c   st   � d} 	 | V } | r|   ¡ rqg }| dur4|  d¡r*t| ƒs*| | dd… ¡ dV } n| | ¡ n| dusd |¡} q)z4Join lines following explicit line continuations (\)r[   TNú\éÿÿÿÿ)rK   ÚendswithÚhas_commentrO   r\   )r   Úpartsr   r   r   Úassemble_logical_linesÐ   s    €
ú
	ñrc   ÚtargetÚescÚlspaceÚreturnc                 C   sR   |dkrdnd| v rdnd}d  || g¡}| d¡\}}}| t¡}d|||f S )zUPrepares a pinfo(2)/psearch call from a target name and the escape
    (i.e. ? or ??)r	   Zpinfo2Ú*ZpsearchZpinfoú ú&%sget_ipython().run_line_magic(%r, %r))r\   Ú	partitionÚlstripÚ	ESC_MAGIC)rd   re   rf   ÚmethodÚargÚt_magic_nameÚ_Út_magic_arg_sr   r   r   Ú_make_help_callæ   s   þ
ýrs   Ú	line_infoc                 C   s   | j  ¡  t¡}d| j|f S )zTranslate lines escaped with: !z%sget_ipython().system(%r))r   rl   Ú	ESC_SHELLÚpre©rt   Úcmdr   r   r   Ú
_tr_systemø   s   ry   c                 C   s    | j  ¡ dd… }d| j|f S )z Translate lines escaped with: !!r   Nz%sget_ipython().getoutput(%r))r   rl   rv   rw   r   r   r   Ú_tr_system2þ   s   rz   c                 C   s$   | j dd… s	dS t| j| j| jƒS )z"Translate lines escaped with: ?/??é   Nzget_ipython().show_usage())r   rs   Úifunre   rv   ©rt   r   r   r   Ú_tr_help  s   r~   c                 C   sV   d}| j  t¡r| j S d | j| jg¡ ¡ }| d¡\}}}| t	¡}|| j
||f S )zTranslate lines escaped with: %rj   ri   )r   Ú
startswithÚ
ESC_MAGIC2r\   r|   Úthe_restÚstriprk   rl   rm   rv   )rt   Útplrx   rp   rq   rr   r   r   r   Ú	_tr_magic  s   
r„   c                 C   ó   d| j | jd | j ¡ ¡f S )zTranslate lines escaped with: ,ú
%s%s("%s")z", "©rv   r|   r\   r�   Úsplitr}   r   r   r   Ú	_tr_quote  ó   
ÿr‰   c                 C   s   d| j | j| jf S )zTranslate lines escaped with: ;r†   )rv   r|   r�   r}   r   r   r   Ú
_tr_quote2  s   
ÿr‹   c                 C   r…   )zTranslate lines escaped with: /z%s%s(%s)z, r‡   r}   r   r   r   Ú	_tr_paren%  rŠ   rŒ   r   c                 C   s4   | r|   ¡ r| S t| ƒ}|jtvr| S t|j |ƒS )zHTransform escaped commands - %magic, !system, ?help + various autocalls.)rK   r   re   Útr)r   Zlineinfr   r   r   Úescaped_commands3  s   
rŽ   z\s*a  (%{0,2}
                              (?!\d)[\w*]+            # Variable name
                              (\.(?!\d)[\w*]+)*       # .etc.etc
                              )
                              (\?\??)$                # ? or ??
                              c              
   C   sŽ   t | ƒj}tƒ }zt |¡D ]	}| |d ¡ qW |S  tyF } z d|jd v r/| t¡ n| t	¡ W Y d}~|S W Y d}~|S d}~ww )z5Helper for has_comment and ends_in_comment_or_string.r   zmulti-line stringN)
r   ÚreadlineÚsetr   rF   Úaddr   ÚargsÚ_MULTILINE_STRINGÚ_MULTILINE_STRUCTURE)r   r�   ÚtoktypesrW   Úer   r   r   Ú_line_tokensL  s    
ÿú
ý€úr—   c                 C   s   t jt| ƒv S )a=  Indicate whether an input line has (i.e. ends in, or is) a comment.

    This uses tokenize, so it can distinguish comments from # inside strings.

    Parameters
    ----------
    src : string
        A single line input string.

    Returns
    -------
    comment : bool
        True if source has a comment.
    )rQ   ÚCOMMENTr—   )Úsrcr   r   r   ra   [  s   ra   c                 C   s   t | ƒ}tj|v pt|v S )a  Indicates whether or not an input line ends in a comment or within
    a multiline string.

    Parameters
    ----------
    src : string
        A single line input string.

    Returns
    -------
    comment : bool
        True if source ends in a comment or multiline string.
    )r—   rQ   r˜   r“   )r™   r•   r   r   r   Úends_in_comment_or_stringl  s   rš   c                 C   s^   t  | ¡}|du st| ƒr| S | d¡}| d¡}t | ¡}|dus$J ‚| d¡}t|||ƒS )z$Translate lines with ?/?? at the endNr{   é   r   )Ú_help_end_reÚsearchrš   ÚgroupÚ_initial_space_reÚmatchrs   )r   Úmrd   re   r    rf   r   r   r   Úhelp_end~  s   




r¢   FÚend_on_blank_linec                 c   sÖ   � d}t  d¡}d}	 |V }|s|V }|r| t¡s&|dur%|V }|dusq
| |¡r,q
|}g }dV }|durS| ¡ dks?| sS| |¡ dV }|durS| ¡ dks?| r?| d¡\}}}| t¡}|||d 	|¡f }q)z�Captures & transforms cell magics.

    After a cell magic is started, this stores up any lines it gets until it is
    reset (sent None).
    z(get_ipython().run_cell_magic(%r, %r, %r)z%%\w+\?r[   TNri   rJ   )
ÚreÚcompiler   r€   r    r‚   rO   rk   rl   r\   )r£   rƒ   Zcellmagic_help_rer   ÚfirstÚbodyZ
magic_namerq   r   r   r   Ú	cellmagic�  s:   €
ÿ
ÿ

ý
år¨   c                 c   sÐ   � |du r| }d}	 |V }|du rq	|j d|dd�\}}|r1|s1| |¡r1|dur0|V }|dus)q	|V }|du r9q	| j d|dd�\}}|V }|sJ|r\|dur[| jd|dd�V }|dusNn|durg|V }|dus`q
)a&  Remove matching input prompts from a block of input.

    Parameters
    ----------
    prompt_re : regular expression
        A regular expression matching any input prompt (including continuation)
    initial_re : regular expression, optional
        A regular expression matching only the initial prompt, but not continuation.
        If no initial expression is given, prompt_re will be used everywhere.
        Used mainly for plain Python prompts, where the continuation prompt
        ``...`` is a valid Python expression in Python 3, so shouldn't be stripped.

    Notes
    -----
    If `initial_re` and `prompt_re differ`,
    only `initial_re` will be tested against the first line.
    If any prompt is found on the first two lines,
    prompts will be stripped from the rest of the block.
    Nr[   Tr{   )Úcount)Úsubnr    Úsub)Ú	prompt_reÚ
initial_reÚ
turnoff_rer   ÚoutZn1Zn2r   r   r   Ú_strip_promptsµ  s:   €
ÿÿ€ÿßr°   c                  C   s*   t  d¡} t  d¡}t  d¡}t| ||ƒS )z:Strip the >>>/... prompts of the Python interactive shell.z^(>>>|\.\.\.)( |$)z	^>>>( |$)z^[%!]©r¤   r¥   r°   )r¬   r­   r®   r   r   r   Úclassic_promptð  s   


r²   c                  C   s    t  d¡} t  d¡}t| |d�S )z%Strip IPython's In [1]:/...: prompts.z^(In \[\d+\]: |\s*\.{3,}: ?)z^%%)r®   r±   )r¬   r®   r   r   r   Ú
ipy_promptú  s   

r³   c                  c   s„   � t  d¡} d}	 |V }|du rq|  |¡}|r6| d¡}|dur5| |¡r.|t|ƒd… }|V }|dus!n|durA|V }|dus:q	)z©Remove leading indentation.

    If the first line starts with a spaces or tabs, the same whitespace will be
    removed from each following line until it is reset.
    z^[ \t]+r[   TNr   )r¤   r¥   r    rž   r   Úlen)Zspace_rer   r¡   Úspacer   r   r   Úleading_indent  s(   €



ý€ÿñr¶   zÎ(?P<lhs>(\s*)
    ([\w\.]+)                # Initial identifier
    (\s*,\s*
        \*?[\w\.]+)*         # Further identifiers for unpacking
    \s*?,?                   # Trailing comma
    )
    \s*=\s*
z{}!\s*(?P<cmd>.*)z %s = get_ipython().getoutput(%r)c                 C   s&   t  | ¡}|du r| S t| dd¡ S )z<Transform assignment from system commands (e.g. files = !ls)NÚlhsrx   )Úassign_system_rer    Úassign_system_templaterž   )r   r¡   r   r   r   Úassign_from_system,  s   
rº   z{}%\s*(?P<cmd>.*)z)%s = get_ipython().run_line_magic(%r, %r)c                 C   sN   t  | ¡}|du r| S | dd¡\}}| d¡\}}}| t¡}t|||f S )z;Transform assignment from magic commands (e.g. a = %who_ls)Nr·   rx   ri   )Úassign_magic_rer    rž   rk   rl   rm   Úassign_magic_template)r   r¡   Zm_lhsZm_cmdrp   rq   rr   r   r   r   Úassign_from_magic7  s   

r½   )F)NN)Dr+   r,   r%   r¤   rQ   r   r   r   Úior   ZIPython.core.splitinputr   ZIPython.utilsr   ru   Z
ESC_SH_CAPZESC_HELPZ	ESC_HELP2rm   r€   Z	ESC_QUOTEZ
ESC_QUOTE2Z	ESC_PARENZESC_SEQUENCESÚABCMetar   r1   r<   rB   r]   r'   rc   Ústrrs   ry   rz   r~   r„   r‰   r‹   rŒ   r�   rŽ   r¥   rŸ   ÚVERBOSErœ   Úobjectr“   r”   r—   ra   rš   r¢   Úboolr¨   r°   r²   r³   r¶   Z_assign_patr7   r¸   r¹   rº   r»   r¼   r½   r   r   r   r   Ú<module>   sž    þ,9
	ù	

ú	
';
	
	
ÿ

