Format: application/x-python-code
⬇ Download File (12.2 KB)
   1  o
   2  
   3  ��h�>�@s�dZddlZddlZddlmZmZddlmZddlmZm	Z	m
   4  Z
   5  ddlmZm
   6  Z
   7  ddlmZddlmZdd	lmZmZmZdd
   8  lmZddlmZGdd
   9  �d
  10  e�ZeZe	Gdd�de��ZGdd�d�ZGdd�de�Zddd�dd�Z dS)z
  11  An embedded IPython shell.
  12  �N)�ultratb�
  13  compilerop)�magic_arguments)�Magics�magics_class�
  14  line_magic)�DummyMod�InteractiveShell)�TerminalInteractiveShell)�load_default_config)�Bool�CBool�Unicode)�
  15  ask_yes_no)�Setc@seZdZdS)�KillEmbeddedN)�__name__�
  16  __module__�__qualname__�rr�Lc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/terminal/embed.pyrsrc
  17  @sfeZdZee��ejddddd�ejddddd�ejd	d
  18  ddd�dd
  19  d������Zeddd��ZdS)�EmbeddedMagicsz-iz
  20  --instance�
  21  store_truez&Kill instance instead of call location)�action�helpz-xz--exitzAlso exit the current sessionz-yz--yeszDo not ask confirmation�cCs�t�|j|�}t|�|jr%|jstdd�}nd}|r$|j��td�n|js.tdd�}nd}|r:d|j_	td�|j
  22  rD|j��dSdS)	a#%kill_embedded : deactivate for good the current embedded IPython
  23  
  24          This function (after asking for confirmation) sets an internal flag so
  25          that an embedded IPython will never activate again for the given call
  26          location. This is useful to permanently disable a shell that is being
  27          called inside a loop: once you've figured out what you needed from it,
  28          you may then kill it and the program will then continue to run without
  29          the interactive shell interfering again.
  30  
  31          Kill Instance Option:
  32  
  33              If for some reasons you need to kill the location where the instance
  34              is created and not called, for example if you create a single
  35              instance in one place and debug in many locations, you can use the
  36              ``--instance`` option to kill this specific instance. Like for the
  37              ``call location`` killing an "instance" should work even if it is
  38              recreated within a loop.
  39  
  40          .. note::
  41  
  42              This was the default behavior before IPython 5.2
  43  
  44          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)rZparse_argstring�
  45  kill_embedded�print�instance�yesr�shell�_disable_init_location�embedded_active�exit�ask_exit)�self�parameter_s�args�killrrrr"s.!�
  46  ���zEmbeddedMagics.kill_embeddedcCsd|j_|j��dS)a]%exit_raise Make the current embedded kernel exit and raise and exception.
  47  
  48          This function sets an internal flag so that an embedded IPython will
  49          raise a `IPython.terminal.embed.KillEmbedded` Exception on exit, and then exit the current I. This is
  50          useful to permanently exit a loop that create IPython embed instance.
  51          TN)r!�should_raiser%)r&r'rrr�
  52  exit_raiseas	zEmbeddedMagics.exit_raiseN)r)rrrrrZargumentrr+rrrrrs
  53  �
  54  �
  55  �7rc@seZdZdd�Zdd�ZdS)�	_SentinelcCst|t�sJ�||_dS�N)�
  56  isinstance�str�repr)r&r0rrr�__init__os
  57  z_Sentinel.__init__cCstSr-)r0�r&rrr�__repr__ssz_Sentinel.__repr__N)rrrr1r3rrrrr,nsr,cs�eZdZUed�Zed�Zed�Zed�Z	ed�Z
  58  e�Zeddd�jdd�Ze
  59  �Zeeed<dd	�Zed
  60  d��Zejdd��Z�fd
  61  d�Zdd�Z�fdd�Z						ddd�Z				ddd�Z�ZS)�InteractiveShellEmbedFrTz$Automatically set the terminal title)r)�config�_inactive_locationscCstj�|j�dS)z.Disable the current Instance creation locationN)r4r6�add�_init_location_idr2rrrr"�sz,InteractiveShellEmbed._disable_init_locationcCs|jtjvo|jtjvSr-)�_call_location_idr4r6r8r2rrrr#�s
  62  �z%InteractiveShellEmbed.embedded_activecCs6|rtj�|j�tj�|j�dStj�|j�dSr-)r4r6�discardr9r8r7)r&�valuerrrr#�s���cs�d|vsJd��t|�}|jdur|��D]}||_q||_|�dd�}|s4t�d�}d|jj|jf}||_	t
  63  t|�jdi|��t
  64  j|j|j|jd�t_dS)NZuser_global_nszXKey word argument `user_global_ns` has been replaced by `user_module` since IPython 4.0.r8��%s:%s)Zcolor_scheme�modeZcall_pdbr)�type�	_instance�	_walk_mro�pop�sys�	_getframe�f_code�co_filename�f_linenor8�superr4r1rZFormattedTB�colorsZxmode�pdb�
  65  excepthook)r&�kw�cls�subclass�clid�frame��	__class__rrr1�s$
  66  �
  67  
  68  �zInteractiveShellEmbed.__init__cCsdS)zZ
  69          Explicitly overwrite :mod:`IPython.core.interactiveshell` to do nothing.
  70          Nrr2rrr�init_sys_modules�sz&InteractiveShellEmbed.init_sys_modulescstt|���|�t�dSr-)rHr4�init_magicsZregister_magicsrr2rQrrrT�sz!InteractiveShellEmbed.init_magicsNr<c
  71  Ks�d|_|�dd�}|st�d�}	d|	jj|	jf}||_|js!dSd|_	|s-|dkr/|j
  72  r/dS|r@|j|_|jd|d|_nd	|_|j
  73  rJ|��|j||||d
  74  �|j|_|jdurat|j�|jrhtd��dS)a�Activate the interactive interpreter.
  75  
  76          __call__(self,header='',local_ns=None,module=None,dummy=None) -> Start
  77          the interpreter shell with the given local and global namespaces, and
  78          optionally print a header string at startup.
  79  
  80          The shell can be globally activated/deactivated using the
  81          dummy_mode attribute. This allows you to turn off a shell used
  82          for debugging globally.
  83  
  84          However, *each* time you call the shell you can override the current
  85          state of dummy_mode with the optional keyword parameter 'dummy'. For
  86          example, if you set dummy mode on with IPShell.dummy_mode = True, you
  87          can still have a specific call work by making it as IPShell(dummy=False).
  88          Tr9Nr<r=Fr�
  89  r)�stack_depth�
  90  compile_flagsz2Embedded IPython raising error, as user requested.)Zkeep_runningrBrCrDrErFrGr9r#Zexit_now�
  91  dummy_modeZbanner2Zold_banner2�display_bannerZshow_banner�mainloop�exit_msgrr*r)
  92  r&�header�local_ns�module�dummyrVrWrLrOrPrrr�__call__�s4
  93  �
  94  
  95  �zInteractiveShellEmbed.__call__rc
  96  s�|dus|dus|durR�jrRt�|�j}|dur|j}|durG|j}z	tj|d}WntyFt�	d|�
  97  dd��t�}||_Ynw|durR|j
  98  jtj@}�j}�j}�jj}	|durc|�_|dury�fdd�|��D�}
  99  |
 100  �_���|dur�|�j_����j��j����Wd�n1s�wYWd�n1s�wY|dur�|��fdd��j��D��|�_|�_|	�j_dS)a�Embeds IPython into a running python program.
 101  
 102          Parameters
 103          ----------
 104          local_ns, module
 105              Working local namespace (a dict) and module (a module or similar
 106              object). If given as None, they are automatically taken from the scope
 107              where the shell was called, so that program variables become visible.
 108          stack_depth : int
 109              How many levels in the stack to go to looking for namespaces (when
 110              local_ns or module is None). This allows an intermediate caller to
 111              make sure that this function gets the namespace from the intended
 112              level in the stack. By default (0) it will get its locals and globals
 113              from the immediate caller.
 114          compile_flags
 115              A bit field identifying the __future__ features
 116              that are enabled, as passed to the builtin :func:`compile` function.
 117              If given as None, they are automatically taken from the scope where
 118              the shell was called.
 119  
 120          NrzFailed to get module %szunknown modulec�$i|]\}}|�j��vr||�qSr�Zuser_ns_hidden�keys��.0�k�vr2rr�
 121  <dictcomp>J�$z2InteractiveShellEmbed.mainloop.<locals>.<dictcomp>crarrbrdr2rrrh[ri)Zdefault_user_namespacesrCrD�f_back�f_locals�	f_globals�modules�KeyError�warnings�warn�getr�__dict__rE�co_flagsrZ	PyCF_MASKZuser_moduleZuser_ns�compile�flags�itemsZinit_user_nsZset_completer_frameZbuiltin_trapZdisplay_trapZinteract�update)r&r]r^rVrWZ
 122  call_frame�	global_nsZorig_user_moduleZorig_user_nsZorig_compile_flagsZreentrant_local_nsrr2rrZsV�
 123  �
 124  ��
 125  ��zInteractiveShellEmbed.mainloop)rNNNr<N)NNrN)rrrrrXrr[r
 126  Zembeddedr*rY�tagZ
 127  term_title�setr6rr/�__annotations__r"�propertyr#�setterr1rSrTr`rZ�
 128  __classcell__rrrQrr4wsB
 129  ��
 130  
 131  
 132  
 133  �I�r4r)r\rWcKs:|�d�}|durt�}|j|_||d<|�dd�}|r+|d�d|d|dkd�i�d}d}ztj}tj}Wn	ty@Ynwt	j
 134  }|durPt|�}|��t�
 135  d�}	tjd
 136  d	d
 137  |	jj|	jfi|��}
 138  |
 139  |d|d
 140  |	jj|	jfd�t��|dur�t|�}|��|��D]}||_
 141  q�|dur�|t_|t_dSdS)aCall this to embed IPython at the current point in your program.
 142  
 143      The first invocation of this will create a :class:`terminal.embed.InteractiveShellEmbed`
 144      instance and then call it.  Consecutive calls just call the already
 145      created instance.
 146  
 147      If you don't want the kernel to initialize the namespace
 148      from the scope of the surrounding function,
 149      and/or you want to load full IPython configuration,
 150      you probably want `IPython.start_ipython()` instead.
 151  
 152      Here is a simple example::
 153  
 154          from IPython import embed
 155          a = 10
 156          b = 20
 157          embed(header='First time')
 158          c = 30
 159          d = 40
 160          embed()
 161  
 162      Parameters
 163      ----------
 164  
 165      header : str
 166          Optional header string to print at startup.
 167      compile_flags
 168          Passed to the `compile_flags` parameter of :py:meth:`terminal.embed.InteractiveShellEmbed.mainloop()`,
 169          which is called when the :class:`terminal.embed.InteractiveShellEmbed` instance is called.
 170      **kwargs : various, optional
 171          Any other kwargs will be passed to the :class:`terminal.embed.InteractiveShellEmbed` constructor.
 172          Full customization can be done by passing a traitlets :class:`Config` in as the
 173          `config` argument (see :ref:`configure_start_ipython` and :ref:`terminal_options`).
 174      r5N�usingZsyncr
 175  ZNoColor)Zloop_runnerrIZ	autoawaitr<r8r=�)r\rVrWr9r)rqrr
 176  r4rwrC�ps1�ps2�AttributeErrorr	r@r?Zclear_instancerDrrErFrGrA)r\rW�kwargsr5rr�r�Zsaved_shell_instancerMrPr!rNrrr�embeddsN
 177  #
 178  �
 179  
 180  
 181  ���
 182  �r�)!�__doc__rCroZIPython.corerrrZIPython.core.magicrrrZIPython.core.interactiveshellrr	Z!IPython.terminal.interactiveshellr
 183  ZIPython.terminal.ipapprZ	traitletsrr
 184  rZIPython.utils.ior�typingr�	ExceptionrZKillEmbededrr,r4r�rrrr�<module>s(N	n