a
    lct;                     @   s   d 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m	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZ G dd deZeZe	G dd deZG dd dZG dd deZdddddZ dS )z
An embedded IPython shell.
    N)ultratb
compilerop)magic_arguments)Magicsmagics_class
line_magic)DummyModInteractiveShell)TerminalInteractiveShell)load_default_config)BoolCBoolUnicode)
ask_yes_no)Setc                   @   s   e Zd ZdS )KillEmbeddedN)__name__
__module____qualname__ r   r   R/var/www/html/django/DPS/env/lib/python3.9/site-packages/IPython/terminal/embed.pyr          r   c                
   @   sf   e Zd Zee ejdddddejdddddejd	d
ddddddZedddZdS )EmbeddedMagicsz-iz
--instance
store_truez&Kill instance instead of call location)actionhelpz-xz--exitzAlso exit the current sessionz-yz--yeszDo not ask confirmation c                 C   s   t | j|}t| |jrJ|js.tdd}nd}|rt| j  td n*|js\tdd}nd}|rtd| j_	td |j
r| j  dS )	a#  %kill_embedded : deactivate for good the current embedded IPython

        This function (after asking for confirmation) sets an internal flag so
        that an embedded IPython will never activate again for the given call
        location. This is useful to permanently disable a shell that is being
        called inside a loop: once you've figured out what you needed from it,
        you may then kill it and the program will then continue to run without
        the interactive shell interfering again.

        Kill Instance Option:

            If for some reasons you need to kill the location where the instance
            is created and not called, for example if you create a single
            instance in one place and debug in many locations, you can use the
            ``--instance`` option to kill this specific instance. Like for the
            ``call location`` killing an "instance" should work even if it is
            recreated within a loop.

        .. note::

            This was the default behavior before IPython 5.2

        z<Are you sure you want to kill this embedded instance? [y/N] nTzIThis embedded IPython instance will not reactivate anymore once you exit.zAAre you sure you want to kill this embedded call_location? [y/N] FzOThis embedded IPython  call location will not reactivate anymore once you exit.N)r   Zparse_argstringkill_embeddedprintinstanceyesr   shell_disable_init_locationembedded_activeexitask_exit)selfparameter_sargskillr   r   r   r   "   s*    !

zEmbeddedMagics.kill_embeddedc                 C   s   d| j _| j   dS )a]  %exit_raise Make the current embedded kernel exit and raise and exception.

        This function sets an internal flag so that an embedded IPython will
        raise a `IPython.terminal.embed.KillEmbedded` Exception on exit, and then exit the current I. This is
        useful to permanently exit a loop that create IPython embed instance.
        TN)r"   should_raiser&   )r'   r(   r   r   r   
exit_raisea   s    	zEmbeddedMagics.exit_raiseN)r   )r   )r   r   r   r   r   argumentr   r,   r   r   r   r   r      s   


7r   c                   @   s   e Zd Zdd Zdd ZdS )	_Sentinelc                 C   s   t |tsJ || _d S N)
isinstancestrrepr)r'   r2   r   r   r   __init__o   s    z_Sentinel.__init__c                 C   s   t S r/   )r2   r'   r   r   r   __repr__s   s    z_Sentinel.__repr__N)r   r   r   r3   r5   r   r   r   r   r.   n   s   r.   c                       s   e Zd ZU edZedZedZedZ	edZ
e ZedddjddZe Zee ed< dd	 Zed
d Zejdd Z fddZdd Z fddZdddZdddZ  ZS )InteractiveShellEmbedFr   Tz$Automatically set the terminal title)r   )config_inactive_locationsc                 C   s   t j| j dS )z.Disable the current Instance creation locationN)r6   r8   add_init_location_idr4   r   r   r   r#      s    z,InteractiveShellEmbed._disable_init_locationc                 C   s   | j tjvo| jtjvS r/   )_call_location_idr6   r8   r:   r4   r   r   r   r$      s    
z%InteractiveShellEmbed.embedded_activec                 C   s4   |r"t j| j t j| j nt j| j d S r/   )r6   r8   discardr;   r:   r9   )r'   valuer   r   r   r$      s    c                    st   d|vsJ d| dd }|s<td}d|jj|jf }|| _tt| j	f i | t
j| j| j| jdt_d S )NZuser_global_nszXKey word argument `user_global_ns` has been replaced by `user_module` since IPython 4.0.r:      %s:%s)color_schememodecall_pdb)popsys	_getframef_codeco_filenamef_linenor:   superr6   r3   r   FormattedTBcolorsZxmodepdb
excepthook)r'   kwclidframe	__class__r   r   r3      s    
zInteractiveShellEmbed.__init__c                 C   s   dS )zZ
        Explicitly overwrite :mod:`IPython.core.interactiveshell` to do nothing.
        Nr   r4   r   r   r   init_sys_modules   s    z&InteractiveShellEmbed.init_sys_modulesc                    s   t t|   | t d S r/   )rI   r6   init_magicsZregister_magicsr   r4   rQ   r   r   rT      s    z!InteractiveShellEmbed.init_magicsNr>   c           
      K   s   d| _ |dd}|s2td}	d|	jj|	jf }|| _| jsBdS d| _	|sZ|dkr^| j
r^dS |r| j| _| jd | d | _nd	| _| jr|   | j||||d
 | j| _| jdurt| j | jrtddS )a  Activate the interactive interpreter.

        __call__(self,header='',local_ns=None,module=None,dummy=None) -> Start
        the interpreter shell with the given local and global namespaces, and
        optionally print a header string at startup.

        The shell can be globally activated/deactivated using the
        dummy_mode attribute. This allows you to turn off a shell used
        for debugging globally.

        However, *each* time you call the shell you can override the current
        state of dummy_mode with the optional keyword parameter 'dummy'. For
        example, if you set dummy mode on with IPShell.dummy_mode = True, you
        can still have a specific call work by making it as IPShell(dummy=False).
        Tr;   Nr>   r?   Fr   
r   )stack_depthcompile_flagsz2Embedded IPython raising error, as user requested.)Zkeep_runningrC   rD   rE   rF   rG   rH   r;   r$   Zexit_now
dummy_modeZbanner2Zold_banner2display_bannerZshow_bannermainloopexit_msgr   r+   r   )
r'   headerlocal_nsmoduledummyrV   rW   rN   rO   rP   r   r   r   __call__   s2    


zInteractiveShellEmbed.__call__r   c              
      s  |du s|du s|du r j rt|j}|du r8|j}|du r|j}ztj|d  }W n4 ty   t	d|
dd  t }||_Y n0 |du r|jjtj@ } j} j} jj}	|dur| _|dur fdd| D }
|
 _   |dur| j_    j@  j    W d   n1 s:0    Y  W d   n1 sZ0    Y  |dur| fdd j D  | _| _|	 j_dS )a  Embeds IPython into a running python program.

        Parameters
        ----------
        local_ns, module
            Working local namespace (a dict) and module (a module or similar
            object). If given as None, they are automatically taken from the scope
            where the shell was called, so that program variables become visible.
        stack_depth : int
            How many levels in the stack to go to looking for namespaces (when
            local_ns or module is None). This allows an intermediate caller to
            make sure that this function gets the namespace from the intended
            level in the stack. By default (0) it will get its locals and globals
            from the immediate caller.
        compile_flags
            A bit field identifying the __future__ features
            that are enabled, as passed to the builtin :func:`compile` function.
            If given as None, they are automatically taken from the scope where
            the shell was called.

        Nr   zFailed to get module %szunknown modulec                    s$   i | ]\}}| j  vr||qS r   Zuser_ns_hiddenkeys.0kvr4   r   r   
<dictcomp>D  r   z2InteractiveShellEmbed.mainloop.<locals>.<dictcomp>c                    s$   i | ]\}}| j  vr||qS r   ra   rc   r4   r   r   rg   U  r   )Zdefault_user_namespacesrD   rE   f_backf_locals	f_globalsmodulesKeyErrorwarningswarngetr   __dict__rF   co_flagsr   Z	PyCF_MASKZuser_moduleZuser_nscompileflagsitemsZinit_user_nsZset_completer_frameZbuiltin_trapdisplay_trapinteractupdate)r'   r]   r^   rV   rW   
call_frame	global_nsZorig_user_moduleZorig_user_nsZorig_compile_flagsZreentrant_local_nsr   r4   r   rZ     sN    

H
zInteractiveShellEmbed.mainloop)r   NNNr>   N)NNr   N)r   r   r   r   rX   r   r[   r   Zembeddedr+   rY   tagZ
term_titlesetr8   r   r1   __annotations__r#   propertyr$   setterr3   rS   rT   r`   rZ   __classcell__r   r   rQ   r   r6   w   s@   



      
I    r6   r   )r\   rW   c                 K   s<  | d}|du r(t }|j|_||d< | dd}|rV|d d|d|dkdi d}d}ztj}tj}W n ty   Y n0 t	j
}|durt|}|  td}	tjf d	d
|	jj|	jf i|}
|
| d|d
|	jj|	jf d t  |dur"t|}|  | D ]}||_
q|dur8|t_|t_dS )a  Call this to embed IPython at the current point in your program.

    The first invocation of this will create an :class:`InteractiveShellEmbed`
    instance and then call it.  Consecutive calls just call the already
    created instance.

    If you don't want the kernel to initialize the namespace
    from the scope of the surrounding function,
    and/or you want to load full IPython configuration,
    you probably want `IPython.start_ipython()` instead.

    Here is a simple example::

        from IPython import embed
        a = 10
        b = 20
        embed(header='First time')
        c = 30
        d = 40
        embed()

    Full customization can be done by passing a :class:`Config` in as the
    config argument.
    r7   Nusingsyncr
   NoColor)Zloop_runnerrK   Z	autoawaitr>   r:   r?      )r\   rV   rW   r;   )ro   r   r
   r6   rw   rD   ps1ps2AttributeErrorr	   	_instancetypeclear_instancerE   r    rF   rG   rH   	_walk_mro)r\   rW   kwargsr7   r   r   r   Zsaved_shell_instanceclsrP   r"   subclassr   r   r   embed^  sJ    







r   )!__doc__rD   rm   IPython.corer   r   r   ZIPython.core.magicr   r   r   IPython.core.interactiveshellr   r	   !IPython.terminal.interactiveshellr
   IPython.terminal.ipappr   	traitletsr   r   r   ZIPython.utils.ior   typingr   	Exceptionr   ZKillEmbededr   r.   r6   r   r   r   r   r   <module>   s&   N	 h