
    Je                     j   d Z ddlZddlZddlmZ ddlZddlmZ ddl	Z	ddl
mZmZmZ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mZ dd	lmZ dd
lmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddlm*Z* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;  ejx                  e=      Z> edd      Z? ej                  e?dddd      ZA ej                  e?ddd      ZB eC ej                  eBd             j                         ZE eC ej                  eBd!            j                         ZF eC ej                  eBd"            j                         ZG ed#      j                  e3e2      ZI	 e	j                    G d$ d%ee;e      ZLy# eK$ r e	j                  e	_J        Y &w xY w)&zR
Client widget for the IPython Console.

This is the widget used on all its tabs.
    N)Template)QUrlQTimerSignalSlotQThread)QMessageBoxQVBoxLayoutQWidget)_)SpyderWidgetMixin)get_home_dirget_module_source_pathrunning_under_pytest)ima)
sourcecode)get_image_path)InstallerIPythonKernelError)
get_coding)RemoteEnvDialog)QStylePalette)programs)add_actionsDialogManager)to_text_string)SPYDER_KERNELS_CONDASPYDER_KERNELS_MAX_VERSIONSPYDER_KERNELS_MIN_VERSIONSPYDER_KERNELS_PIPSPYDER_KERNELS_VERSION)ShellWidget)CollectionsEditor)SaveHistoryMixinspyderpluginshelputilsstaticcssipythonconsoleassets	templatesz
blank.htmlzloading.htmlzkernel_error.htmlz>= {0} and < {1}c                   4    e Zd ZdZ eee      Z e       Z ee      ZdZ	dj                  ej                  dz   ej                               ZddgZddddd	d
dd
dd	d
d
d	di ddddf fd	Zd Zd>dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Ze d        Z!d>dZ" e#       d        Z$d>dZ% fdZ&d Z' e#       d         Z(d! Z)d" Z*d# Z+d$ Z,d% Z-d& Z.d' Z/d>d(Z0d) Z1d* Z2d+ Z3 e#       d,        Z4d- Z5d?d.Z6d/ Z7d0 Z8 e#e      d1        Z9 e#       d2        Z: e#       d3        Z; e#       d4        Z< e#       d5        Z= e#       d6        Z> e#       d7        Z?d8 Z@ e#eA      d9        ZB e#eA      d:        ZCd?d;ZD e#eE      d<        ZFd= ZG xZHS )@ClientWidgetz
    Client widget for the IPython Console

    This widget is necessary to handle the interaction between the
    plugin and each shell widget.
    ipython_consolez{0}## ---({1})---   z# -*- coding: utf-8 -*-z+# *** Spyder Python Console History Log ***N FTc           
      
    t         t           |       t        j                   |       | _        | _        | _        | _        |
 _        | _	        | _
        | _        | _        | _        | _        | _        |	 _        | _        g  _        d _        d _        d  _        d  _        | _        |t0         _        n| _        t5        | |||||d       _         j                  j8                   _         j;                          _         j?                          _         d  _!         jE                          tG        jH                          _%        tM                _'        tQ                _)         jR                  jU                  dddd        jR                  jW                   j6                          j8                  % jR                  jW                   j8                          jY                   jR                          fd _-        t]                _/        | _0        | _1        | _2         j`                   jb                  / j6                  jf                  ji                   jj                         d _6        y )NTF)config	ipyclientadditional_optionsinterpreter_versionsis_external_kernelis_spyder_kernelhandlerslocal_kernelr   c                  <     j                   j                         S )N)client)	containerclose_clientselfs   N/usr/lib/python3/dist-packages/spyder/plugins/ipythonconsole/widgets/client.py<lambda>z'ClientWidget.__init__.<locals>.<lambda>   s    T^^%@%@%@%M     )7superr.   __init__r#   r=   id_connection_filehostnamemenu_actionsr7   
given_nameshow_elapsed_timereset_warningask_before_restartask_before_closinginitial_cwdcontext_menu_actionsoptions_buttonhistoryallow_renameis_error_shown
error_textrestart_thread
give_focusCSS_PATHcss_pathr!   shellwidget
infowidget_create_blank_page
blank_page_create_loading_pageloading_page	info_page_before_prompt_is_readytime	monotonict0r   timerr
   layoutsetContentsMargins	addWidget	setLayoutexit_callbackr   dialog_manager
stderr_obj
stdout_obj	fault_objexecutedconnectpoll_std_file_changestart_successful)r@   parentrF   history_filenameconfig_optionsr5   r6   rG   rH   rP   rI   r7   r8   rJ   rW   rQ   rK   rL   rM   rN   rY   r9   rl   rm   rn   rO   	__class__s   `                         rA   rE   zClientWidget.__init__a   s5   * 	lD*62!!$(89  . ("4$!2*"4"4& %9!, #"$$DM$DM '!1!51-	
 ..33113 557 $$& .."D\
 "m&&q!Q2d../??&KK!!$//2t{{# N ,o %$"??&$//*E%%--d.G.GH %rC   c                     | j                   P| j                   j                         r5| j                   j                          | j                   j                          yyy)z Close threads to avoid segfault.N)rV   	isRunningquitwaitr?   s    rA   __del__zClientWidget.__del__   sN    +''113$$&$$& 4 ,rC   c                     |r| j                          | j                  j                  j                  | j                         | j                  j
                  j                  | j                         y)z)Configuration before kernel is connected.N)_show_loading_pagerZ   sig_prompt_readyrp   _when_prompt_is_readysig_remote_execute)r@   show_loading_pages     rA   ra   z$ClientWidget._before_prompt_is_ready   sY    ##%))11&&	( 	++33&&	(rC   c                    d| _         | j                          | j                          | j                          | j	                          | j
                  j                  j                  | j                         | j
                  j                  j                  | j                         	 | j                          | j                  r%| j
                  j                  j                          yy# t        $ r Y =w xY w)z(Configuration after the prompt is shown.TN)rr   _hide_loading_page_show_mpl_backend_errors_check_special_console_error_set_initial_cwd_in_kernelrZ   r~   
disconnectr   r   _connect_control_signalsRuntimeErrorrW   _controlsetFocusr?   s    rA   r   z"ClientWidget._when_prompt_is_ready   s     $! 	%%' 	))+ 	'')))44&&	(++66&&	(	))+ ??%%..0   		s   'C) )	C54C5c                     t        t              }t        d      }t        j                  dk(  r|j                  dd      }t        d      }|j                  | j                  ||      }|S )5Create html page to show while the kernel is startingloading_spritesnt\/zConnecting to kernel...)rY   loading_imgmessage)	r   LOADINGr   osnamereplacer   
substituterY   )r@   loading_templater   r   pages        rA   r^   z!ClientWidget._create_loading_page   sh    #G,$%6777d?%--dC8K-.**DMM7B3: + < rC   c                 \    t        t              }|j                  | j                        }|S )r   )rY   )r   BLANKr   rY   )r@   r   r   s      rA   r\   zClientWidget._create_blank_page  s(    #E?**DMM*BrC   c                     | j                   V| j                  j                          | j                   j                          | j                  | _        | j                          yy)z+Show animation while the kernel is loading.N)r[   rZ   hideshowr_   r`   set_info_pager?   s    rA   r}   zClientWidget._show_loading_page  sL    ??&!!#OO  "!..DN 	 'rC   c                     | j                   ;| j                   j                          | j                  | _        | j	                          | j
                  j                          y)z1Hide animation shown while the kernel is loading.N)r[   r   r]   r`   r   rZ   r   r?   s    rA   r   zClientWidget._hide_loading_page  sE    ??&OO  "!__DN rC   c                     t        | j                  d      }	 |j                         }|s	 |j                          yt	        |      }t        ||      }||j                          S # |j                          w xY w)z#Read the stderr file of the kernel.rb )openstderr_filereadcloser   r   )r@   fstderr_textencodings       rA   _read_stderrzClientWidget._read_stderr  sg     !!4(	&&(K
  GGI	 "+.H(h?KGGIAGGIs   A% A% %A7c                     | j                   j                  r)| j                   j                         j                          yy)zT
        Show possible errors when setting the selected Matplotlib backend.
        N)rZ   r8   call_kernelshow_mpl_backend_errorsr?   s    rA   r   z%ClientWidget._show_mpl_backend_errors0  s3     ,,((*BBD -rC   c                 l    | j                   j                  | j                        j                          y)z<Check if the dependecies for special consoles are available.)callbackN)rZ   r   _show_special_console_erroris_special_kernel_validr?   s    rA   r   z)ClientWidget._check_special_console_error7  s-    $$55 	% 	%%'rC   c                 b    |-t        d      j                  |      }| j                  |       y y )NzYour Python environment or installation doesn't have the <tt>{missing_dependency}</tt> module installed or it occurred a problem importing it. Due to that, it is not possible for Spyder to create this special console for you.)missing_dependency)r   formatshow_kernel_error)r@   r   error_messages      rA   r   z(ClientWidget._show_special_console_error=  s>    ) f(:f;  ""=1 *rC   c                     | j                         sy| j                  ry| j                  j                         }|sy|j	                         D ]  }|s| j                  |      r y y)z
        Abort kernel restart if there are errors while starting it.

        We also ignore errors about comms, which are irrelevant.
        TF)has_spyder_kernelsrr   rl   get_contents
splitlinesis_benign_error)r@   stderrlines      rA   _abort_kernel_restartz"ClientWidget._abort_kernel_restartI  si     &&(  --/ %%' 	DD006	 rC   c                 F   | j                   j                  }| j                   j                  }|j                  j	                  | j
                  j                         |j                  j	                  | j
                  j                         |j                  j	                  | j
                  j                         |j                  j	                  | j
                  j                         |j                  j	                  | j
                  j                  j                         y)z#Connect signals of control widgets.N)rZ   r   _page_controlsig_focus_changedrp   r=   sig_visibility_changedrefresh_containersig_show_find_widget_requestedfind_widgetr   )r@   controlpage_controls      rA   r   z%ClientWidget._connect_control_signals_  s    ""++''55!!))NN,,	.&&..NN,,	.&&..NN,,	.++33NN,,	.33;;NN&&++	-rC   c                    t         j                  d       t               }| j                  j	                         }d}| j
                  d   dk(  rR| j                  dd      rt               }||}n| j                  d	d      r| j                  d
t               d      }n| j                  | j                  }n| j                  dd      rt               }|b|}n_| j                  dd      r| j                  j                         }d}n/| j                  dd      r| j                  dt               d      }t        j                  |      r| j                  j                  ||       yy)z"Set the initial cwd in the kernel.z/Setting initial working directory in the kernelTint_id1z%startup/use_project_or_home_directory
workingdirsectionNzstartup/use_fixed_directoryzstartup/fixed_directory)defaultr   z%console/use_project_or_home_directoryzconsole/use_cwdFzconsole/use_fixed_directoryzconsole/fixed_directory)emit_cwd_change)loggerdebugr   r=   get_active_project_pathrF   get_confrO   get_working_directoryospisdirrZ   set_cwd)r@   cwd_pathproject_pathr   s       rA   r   z'ClientWidget._set_initial_cwd_in_kernelo  sq   FG>~~==? 88H$}}7$   (>++H-$    ==-(N( )  +++7$   (>++H0,G>>??A"'-$    ==-(N( )  99X$$X$O rC   c                     | j                   3t        j                  | j                         }|j                  d      d   S y)zGet kernel id.Nz.jsonr   )rG   r   basenamesplit)r@   	json_files     rA   	kernel_idzClientWidget.kernel_id  s=     +T%9%9:I??7+A.. ,rC   c                 z   	 | j                   j                  j                  | j                         |rt| j                  | j                  j                          | j                  | j                  j                          | j                  | j                  j                          yyy# t        t
        f$ r Y w xY w)z.Remove stderr_file associated with the client.N)
rZ   ro   r   rq   	TypeErrorr   rl   removerm   rn   r@   is_last_clients     rA   remove_std_fileszClientWidget.remove_std_files  s    	%%001J1JK *&&(*&&(~~)%%' *  <( 		s   /B( (B:9B:c                    | j                   j                  }| j                  | j                  j                         }|r| j	                  |      ry| j                   j                         r@| j                  d|z  k7  r.| j                  j                         }| j                  d|z         |r,|dz   | j                   j                  z   | j                   _	        n | j                   j                  d|z   d       | j                  l| j                  j                         }|rO|r,|dz   | j                   j                  z   | j                   _	        y| j                   j                  d|z   d       yyy)z0Check if the stderr or stdout file just changed.Nz<tt>%s</tt>
Tbefore_prompt)rZ   	_startingrl   poll_file_changer   isHiddenrU   r   r   banner_append_plain_textrm   )r@   startingr   full_stderrstdouts        rA   rq   z!ClientWidget.poll_std_file_change  sR    ##--??&__557F''/##,,.-&*@@&*oo&B&B&D..}{/JK(8(8(?(?? $$+ $$77vT 8 ; ??&__557F(8(8(?(?? $$+ $$77vT 8 ;  'rC   c                 0   || _         | j                  j                         j                          | j                  j	                          | j                  j
                  j                  | j                         | j                  j
                  j                  | j                  j                         | j                  j                  j                  | j                         | j                  j                  j                  | j                  j                         | j                  j
                  j                  | j                         | j                  j                  j                  | j                         | j                  j                  j                  | j                         | j                  j                  j                  | j                          | j                  j
                  j                  | j                  j"                         | j                  j$                  j                  | j&                         | j                  j(                  j                  | j*                         | j                  j                  j                  | j                  j,                         | j/                  | j                  j0                  d       | j2                  >| j                  j                         j5                  | j2                  j6                         yy)z0Configure shellwidget after kernel is connected.FresetN)rW   rZ   r   _send_comm_configset_exit_callback	executingrp   add_to_historyset_backend_for_mayaviro   update_historyrefresh_namespacebrowsersig_execution_state_changedsig_kernel_restarted_messagekernel_restarted_messagesig_kernel_restarted_finalise_restartchange_mpl_backendsig_show_syspathshow_syspathsig_show_envshow_env
update_cwdset_color_schemesyntax_stylern   enable_faulthandlerfilename)r@   rW   s     rA   configure_shellwidgetz"ClientWidget.configure_shellwidget  sS   $ 	$$&88: 	**, 	""**4+>+>? 	""**33	5 	!!))$*=*=> 	!!))55	7 	""**,,	. 	!!)),,	. 	55==))	+--55""	$ 	""**//	1 	))11$2C2CD%%--dmm< 	!!))$*:*:*E*EF 	d..;;5I>>%((*>>'') &rC   c                 `    | j                   j                         ryt        t        |   |      S )zAdd command to historyN)rZ   is_debuggingrD   r.   r   )r@   commandrv   s     rA   r   zClientWidget.add_to_history  s*    ((*\47@@rC   c                 f    | j                   j                  xs | j                   j                         S N)rZ   
_executingis_waiting_pdb_inputr?   s    rA   is_client_executingz ClientWidget.is_client_executing  s-      ++ 8  557	9rC   c                     | j                   j                         s| j                          y| j                   j                  d       y)z;Method to handle what to do when the stop button is pressedexitN)rZ   r  interrupt_kernelpdb_execute_commandr?   s    rA   stop_button_click_handlerz&ClientWidget.stop_button_click_handler  s6     446!!#008rC   c                 B   || _         | j                  |      ryt        |       t        j                  |      }|r|j                  |d      }|j                  dd      }t        d      }t        t              }|j                  | j                  ||      | _        | j                  D| j                          | j                  j                          | j                  j!                          d| _        | j                  j%                          | j'                  d	       y)
z0Show kernel initialization errors in infowidget.Nz<br>-z&#8209z*An error ocurred while starting the kernel)rY   r   errorTF)r   )rU   r   r   r   get_eol_charsr   r   r   KERNEL_ERRORr   rY   r`   r[   r   rZ   r   r   rT   shutdownr   )r@   r  eolr   kernel_error_templates        rA   r   zClientWidget.show_kernel_error$  s    &#E* &&u-MM#v.E c8, @A ( 6.99]] :  ??& !!#OO  " # 	!!#U3rC   c                 J    g d}t        |D cg c]  }||v  c}      S c c}w )z3Decide if an error is benign in order to filter it.)
z"KeyboardInterrupt caught in kernelz:QSocketNotifier: Multiple socket notifiers for same socketz9Tcl_AsyncDelete async handler deleted by the wrong threadz"error in background error handler:z    while executingz"::tcl::Bgerrorz:WARNING: Insecure writes have been enabled via environmentzNo such commz^Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.z'The following argument was not expected)any)r@   r  benign_errorserrs       rA   r   zClientWidget.is_benign_errorK  s(    
. M:SC5L:;;:s    c                    | j                   P| j                  t        d      }n| j                  }| j                  d   dz   | j                  d   z   }|dz   |z   }|S | j                   dv r6| j                  d   dz   | j                  d   z   }| j                   dz   |z   }|S | j                   dz   | j                  d   z   }|S )zReturn client nameConsoler   r   str_id )PylabSymPyCython)rJ   rH   r   rF   )r@   r   	client_ids      rA   get_namezClientWidget.get_namef  s    ??"}}$|}}*T1DHHX4FFI$;*D  __ <<*T1DHHX4FFI??T)I5D  ??T)DHHX,>>DrC   c                     | j                   j                  }|r|j                         r|S | j                   j                  S )z4Return the text widget (or similar) to give focus to)rZ   r   	isVisibler   )r@   r   s     rA   get_controlzClientWidget.get_controlx  s;     ''55L224##,,,rC   c                 .    | j                   j                  S )z&Get kernel associated with this client)rZ   kernel_managerr?   s    rA   
get_kernelzClientWidget.get_kernel  s    ...rC   c                 2    t        || j                         |S )z*Add actions to IPython widget context menu)r   rP   )r@   menus     rA   add_actions_to_context_menuz(ClientWidget.add_actions_to_context_menu  s    D$334rC   c                 p    | j                   j                  j                  |       || j                   _        y)zSet IPython widget's fontN)rZ   r   setFontfont)r@   r:  s     rA   set_fontzClientWidget.set_font  s*    !!))$/ $rC   c                 \    	 | j                   j                  ||       y# t        $ r Y yw xY w)zSet IPython color scheme.N)rZ   r  AttributeError)r@   color_schemer   s      rA   r  zClientWidget.set_color_scheme  s/    	--lEB 		s    	++c                 2   	 | j                          	 | j                  j                  j	                  | j
                         | j                  |       | j                          | j                  d       y# t        $ r Y nw xY w# t        t        f$ r Y Sw xY w)zClose the client.N)
r  r   re   timeoutr   	show_timer   r  r   	setParentr   s     rA   r>   zClientWidget.close_client  s    	**,
	JJ))$..9 	n%

t  		 i( 		s"   A5 /B 5	B BBBc                    | j                   j                          | j                  r| j                  j                         rX| j                  j                  j                          | j                  j                          | j                  j                          |xr | j                   xr | j                   }| j                  j                  |       | j                  |       y)z)Shutdown connection and kernel if needed.N)rk   	close_allrV   rx   finishedr   ry   rz   r7   rT   rZ   r  r   )r@   r   shutdown_kernels      rA   r  zClientWidget.shutdown  s    %%'+''113((335$$&$$& (4#:#:: (''' 	 	!!/2o.rC   c                 X    	 | j                   j                          y# t        $ r Y yw xY w)z7Interrupt the associanted Spyder kernel if it's runningN)rZ   request_interrupt_kernelr   r?   s    rA   r  zClientWidget.interrupt_kernel  s+    	557 		s    	))c                 P     j                   }t               sZ j                  rNt        d      }t        j
                  t        j                  z  }t	        j                   t        d      ||      }nd}|t        j
                  k(  st               s j                  s	|j                  rω j                  4 j                  j                         r j                  j                           j                         r|j                  j                          y j                          |j                  j                          |j                  j!                          d|j                  _         j%                  d        j&                  r j&                  j)                         rX j&                  j*                  j-                           j&                  j/                           j&                  j1                          t3        d       _         j4                   j&                  _        d j&                  _         j&                  j*                  j;                   fd        j&                  j=                          y|j?                  t        d      d	        jA                          yy)
z
        Restart the associated kernel.

        Took this code from the qtconsole project
        Licensed under the BSD license
        z,Are you sure you want to restart the kernel?zRestart kernel?NF)r   c                  &     j                  d      S )NT)r  r?   s   rA   rB   z-ClientWidget.restart_kernel.<locals>.<lambda>  s    D2248 rC   z.Cannot restart a kernel not started by Spyder
Tr   )!rZ   r   rM   r   r	   YesNoquestionr3  r[   r0  r   r   spyder_kernel_commr   r}   stop_restarterautorestartra   rV   rx   rE  r   ry   rz   r   _restart_thread_mainrunr  rp   startr   r   )r@   swr   buttonsresults   `    rA   restart_kernelzClientWidget.restart_kernel  s    #%$*A*AFGG!oo6G ))$2C0D*17<F Fkoo%$&++  ??.002,,.--/))//1'') %%++- !!00205!!- ,,u,E ''3 //99;''00;;='',,.'',,.&-dm#*.*C*C##',0##)##,,448:##))+ %%GH"& &  '')Q ,rC   c                     	 | j                   j                  j                  | j                  j                  | j
                  j                         y# t        $ r}|| j                  _        Y d}~yd}~ww xY w)zRestart the kernel in a thread.)r   r   N)	rZ   r3  rW  rl   handlerm   r   rV   r  )r@   es     rA   rQ  z!ClientWidget._restart_thread_main  sc    	*++::---- ; /  	*()D%%	*s   AA 	A6A11A6c                 r   | j                   }| j                         r|j                  j                          y| j                  rK| j                  j
                  5|j                  t        d      | j                  j
                  z  d       ni| j                  M| j                  j                         }|r1| j                  |      }| j                   j                  d|z   d       d|_        |j                  j                          	 |j                  j                  |j                         |j                   r+d|j                   _        |j                   j%                          | j'                  |j(                  |       |j+                  t        d      d       |j-                          | j                  =| j                   j/                         j1                  | j                  j2                         | j5                          d| _        | j6                  j9                          y# t        $ r Y yw xY w)	z&Finishes the restarting of the kernel.NzError restarting kernel: %s
Tr   r   Fr   z<br>Restarting kernel...<br>)rZ   r   rN  r   rV   r  r   r   rn   r   filter_fault_pdb_in_loopr   	open_commkernel_clientr=  r3  rP  start_restarterr  r	  _append_htmlinsert_horizontal_rulerr   r
  r  r   r   emit)r@   r   rT  faults       rA   r  zClientWidget._finalise_restart
  s   %%'!!'')4#6#6#<#<#H!!12T5H5H5N5NN" " 
 ~~)335 --e4E$$77uD 8 : $BO!!((*%%//0@0@A   04!!-!!113
 !!"//!?OOA<=*.  0&&(~~)  ,,.BBNN++- 	!"((--/5 "  s   
%H* *	H65H6c                    | j                  dd      sm| j                  dd      }t        j                  d|t              }t	        d      j                  |t        t        t              }|s| j                  |       yy	y	)
z
        Check if the kernel has the right Spyder-kernels version and show a
        message in case that's not the true.
        r   main_interpreterr   
executablespyder_kernels)interpreterversiona  The Python environment or installation whose interpreter is located at<pre>    <tt>{0}</tt></pre>doesn't have the <tt>spyder-kernels</tt> module or the right version of it installed ({1}). Without this module is not possible for Spyder to create a console for you.<br><br>You can install it by activating your environment first (if necessary) and then running in a system terminal:<pre>    <tt>{2}</tt></pre>or<pre>    <tt>{3}</tt></pre>FT)
r   r   is_module_installedr    r   r   SPYDER_KERNELS_VERSION_MSGr   r   r   )r@   pyexecr   msgs       rA   r   zClientWidget.has_spyder_kernels@  s    
 }}Y0B}C]]<9K]LF!)!=!= "."0
 " !&.(&	# 0 &&&s+rC   c           	      |   d}d}d}t        j                  ||      D ]  }t        |j                  d      d      }  d}g }d}t        j                  ||      D ]L  }|j                  d      j	                         D 	cg c]  }	t        |	d       }}	|j                         d   }N d}
t        t        j                  ||            D ]  \  }}|dk(  r|
|||j                         d    z  }
t        |j                  d	      d      }||k7  r4||v rJd
|j                  d      v r^|
d|j                  d      z   dz   z  }
y	 d}t        t        j                  ||j                  d                  }|j                         d   }|
d|j                  d      d| z   dz   z  }
 |
S c c}	w # t        $ r d}Y 3w xY w)z$Get a fault from a previous session.zn(Current thread|Thread) (0x[\da-f]+) \(most recent call first\):(?:.|\r\n|\r|\n)+?(?=Current thread|Thread|\Z)z&Main thread id:(?:
||
)(0x[0-9a-f]+)r         )basez;System threads ids:(?:
||
)(0x[0-9a-f]+(?: 0x[0-9a-f]+)+)r   r0   zwurlitzer.pyr   zP.*(?:/IPython/core/interactiveshell\.py|\\IPython\\core\\interactiveshell\.py).*Nz
Main thread:
)	refinditerintgroupr   span	enumeratenextStopIteration)r@   rd  thread_regexmain_remain_idmatch	system_re
ignore_ids	start_idxitextidx	thread_idpatternmatch_internalend_idxs                   rA   r\  zClientWidget.filter_faultl  s   > 	 ?[[%0 	3E%++a.r2G	3D	
	[[E2 	(E38;;q>3G3G3IJa#ab/JJJ

QI	( #BKKe$DE 	MJCaxi

Q88EKKN4IG#
*!U[[^3u{{1~-44# KG%)"++gu{{1~*N%ON,113A6G *U[[^HW-EELL'	M( / K( % #"G#s   >F(AF--F;:F;c                 ~    | j                   | j                          y| j                  j                  d|z  d       y)z$Show kernel restarted/died messages.Nz<br>%s<hr><br>Fr   )rl   rq   rZ   ra  )r@   rn  s     rA   r   z%ClientWidget.kernel_restarted_message  s@     ??& %%'))*:S*@8= * ?rC   c                 L    | j                   j                  j                          y)z0Enter and show the array builder on inline mode.N)rZ   r   enter_array_inliner?   s    rA   r  zClientWidget.enter_array_inline  s     	!!446rC   c                 L    | j                   j                  j                          y)z*Enter and show the array builder on table.N)rZ   r   enter_array_tabler?   s    rA   r  zClientWidget.enter_array_table  s     	!!335rC   c                 L    | j                   j                  j                          y)z2Show how to inspect an object with our Help pluginN)rZ   r   inspect_current_objectr?   s    rA   inspect_objectzClientWidget.inspect_object  s     	!!88:rC   c                 8    | j                   j                          y)zClear a console lineN)rZ   _keyboard_quitr?   s    rA   
clear_linezClientWidget.clear_line  s     	'')rC   c                 8    | j                   j                          y)zClear the whole consoleN)rZ   clear_consoler?   s    rA   r  zClientWidget.clear_console  s     	&&(rC   c                 R    | j                   j                  | j                  d       y)z>Resets the namespace by removing all names defined by the userT)warningr   N)rZ   reset_namespacerL   r?   s    rA   r  zClientWidget.reset_namespace  s(     	((1C1C15 	) 	7rC   c                 :    | j                   j                  | _        y r  )rZ   _historyrR   r?   s    rA   r   zClientWidget.update_history  s    ''00rC   c                     |Ot        |       }|j                  |ddt        j                  d             | j                  j                  |       yy)zShow sys.path contents.Nzsys.path contentsTsyspath)titlereadonlyicon)r"   setupr   r  rk   r   )r@   r  editors      rA   r  zClientWidget.show_syspath  sO     &t,FLL(;d!hhy1  3$$V,rC   c                 P    | j                   j                  t        ||              y)zShow environment variables.)rs   N)rk   r   r   )r@   envs     rA   r  zClientWidget.show_env  s     	  T!BCrC   c           	         t        j                         | j                  z
  }|dk  rt        j                         | _        d}|dkD  rd}nd}|rt        j                  }nt        j
                  }d|dt        j                  |t        j                  |            d}| j                  r| j                  j                  |       y	| j                  j                  d       y	)
zText to show in time_label.r   iQ z%d %H:%M:%Sz%H:%M:%Sz<span style='color: z'><b>z</b></span>r   N)rb   rc   rd   r   COLOR_TEXT_3COLOR_ACCENT_4strftimegmtimerK   sig_time_labelrc  )r@   endelapsed_timefmtcolorr  s         rA   rA  zClientWidget.show_time  s     ~~'$''1!nn&DGL)#CC!..E!00E % $c4;;|3L MO !!$$T*$$R(rC   c                     || _         y)z%Slot to show/hide elapsed time label.N)rK   )r@   states     rA   set_show_elapsed_timez"ClientWidget.set_show_elapsed_time  s     "'rC   c                     | j                   Q| j                  D| j                   j                  | j                  t        j                  | j
                               yyy)zSet current info_page.N)r[   r`   setHtmlr   fromLocalFilerY   r?   s    rA   r   zClientWidget.set_info_page  sI    ??&4>>+EOO##""4==1 ,F&rC   )T)F)I__name__
__module____qualname____doc__r   strsig_append_to_history_requestedr   r  CONF_SECTIONr   r   lineseprb   ctime	SEPARATORINITHISTORYrE   r{   ra   r   r^   r\   r}   r   r   r   r   r   r   r   r   propertyr   r   r   rq   r  r   r  r  r   r   r.  r1  r4  r7  r;  r  r>   r  r  rW  rQ  r  r   r\  r   r  r  r  r  r  r  r   objectr  r  rA  boolr  r   __classcell__)rv   s   @rA   r.   r.   P   s    '-S#&6#"((C[N$L#**2::a<FI,@DK "&&("$)"&   $#(#$($)  !)a&F'(1@
! 0E(
2,- 2Pj / /( 
V; ;<7)rA9 
V9 9%4N<6$-/%
&/ 
V;* ;*z*40l*X*X 
#Y? ? 
V7 7 
V6 6 
V; ; 
V* * 
V) ) 
V7 7
1 
&\  
&\D D)0 
$Z' 'rC   r.   )Mr  loggingr   os.pathpathr   rs  stringr   rb   qtpy.QtCorer   r   r   r   r   qtpy.QtWidgetsr	   r
   r   spyder.api.translationsr   spyder.api.widgets.mixinsr   spyder.config.baser   r   r   spyder.utils.icon_managerr   spyder.utilsr   spyder.utils.image_path_managerr   spyder.utils.installersr   spyder.utils.encodingr   spyder.utils.environr   spyder.utils.paletter   r   spyder.utils.qthelpersr   r   spyder.py3compatr   spyder.plugins.ipythonconsoler   r   r   r   r    %spyder.plugins.ipythonconsole.widgetsr!    spyder.widgets.collectionseditorr"   spyder.widgets.mixinsr#   	getLoggerr  r   PLUGINS_PATHjoinrX   TEMPLATES_PATHr   r   r   r   r  r   rl  rc   r=  r.   r1   rC   rA   <module>r     s    	  	   < ; > > & 7@ @ ) # : ? , 0 . ! = +L L > > 2 
		8	$ &h	:388L&'8UC"Hk; 	XSXXnl3499;
xsxx7
8
=
=
?HCHH^-@ABGGI"$>@ NNl7,.? l  YYDNs   ?F F21F2