
    
djo                        d dl Z d dlZd dlZd dlZd dl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 d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZ d dlmZmZ esd d	lmZm Z m!Z! nd d
l"m#Z#  ej$        e%          Z& e'ed          sdge_(        ej)        *                    d          dk    Z+ej)        *                    d          dk    Z,da-	 d dl.Z/n# e0$ r
 d dl/Z/e1fZ2Y nw xY wej3        dk    rer	 d dl4Z4d dl5Z5 e4j6        d          \  Z7Z8	  e9e8dd                   Z8e5j:        j;        <                    e8           e5j:        j;        =                    e8           n# e>e?f$ r Y nw xY wn# e@$ r Y nw xY wej3        dk    r"e,r d dlAZAdZB G d deAjC                  ZDeDeA_C        	 d dlEZEn# e@$ r Y nw xY wer$ejF        G                    d          r
d ZHeHe_I        ej)        *                    d          dk    r'	 d dlJZJdD ]ZK eJjL        eKd           n2# e@$ r Y n+w xY w	 ej)        M                    d           n# eN$ r Y nw xY w	 d dlOmPZP  G d dePjQ                  ZRg eR_S        eReP_Q        n# e@$ r Y nw xY w	 d dlTmUZU  G d  deUjQ                  ZRg eR_S        eReU_Q        n# e@$ r Y nw xY wd dlVZVd d!lVmWZW  G d" d#eW          ZXeXeV_Y        	  e	jZ        d$e[d%&           n# e@$ r Y nw xY w	 d dl\Z\d d'l\m]Z]m^Z^ d( Z_e_e\_`        n# e@$ r Y nw xY w	 d dlaZbd)ebjc        jd        _e         e	jZ        d$efd*d+,            e	jZ        d$efd-d+,           n# e@$ r Y nw xY w	  e	jZ        d$efd.d+,           n# e@$ r Y nw xY wes,	 d dlgZhehji        jj        Zkd/ Zlelehji        _j        n# e@$ r Y nw xY wdBd0Zmeme_n        ee_o         eej)        *                    d1d          2          Zpd3 Zqd4 Zrd5 ZsdCd7Zt	 	 dDd8ZudEd9Zv	 	 dFd:Zw	 	 	 dGd;Zxerewe/_w        newe/_y        	 	 dHd<Zzeze/_z        dId=Z{	 	 dJd>Z|e{e/_{        dId?Z}e}e/_}        dBd@Z~e~e/_~        dA Z e             dS )K    N)get_ipython)frontend_request)NamespaceManager)	SpyderPdbget_new_debugger)UserModuleReloader)PY2_printencodecompat_execFileNotFoundError)capture_last_Exprcanonic)TransformerManagerleading_indentleading_empty_lines)IPythonInputSplitterargv SPY_EXTERNAL_INTERPRETERTrueSPY_HIDE_CMDTntLANG   i   c                        e Zd Z fdZ xZS )SubprocessPopenc                 \    t           |d<    t          t          |           j        |i | d S )Ncreationflags)creation_flagsuperr   __init__selfargskwargs	__class__s      Hlib/python3.11/site-packages/spyder_kernels/customize/spydercustomize.pyr"   zSubprocessPopen.__init__k   s5    &3F?#1E/4((14B6BBBBB    __name__
__module____qualname__r"   __classcell__r'   s   @r(   r   r   j   sA        	C 	C 	C 	C 	C 	C 	C 	C 	Cr)   r   linuxc                      dS )Nutf-8 r3   r)   r(   _getfilesystemencoding_wrapperr4      s    wr)   QT_APIpyqt)QStringQVariantQDate	QDateTimeQTextStreamQTimeQUrl)	QtWidgetsc                        e Zd Z fdZ xZS )SpyderQApplicationc                      t          t          |           j        |i | t          j                            |            d S Nr!   r@   r"   _instance_listappendr#   s      r(   r"   zSpyderQApplication.__init__   E    4E$d++4dEfEEE -44T:::::r)   r*   r/   s   @r(   r@   r@      8        	; 	; 	; 	; 	; 	; 	; 	; 	;r)   r@   )QtGuic                        e Zd Z fdZ xZS )r@   c                      t          t          |           j        |i | t          j                            |            d S rB   rC   r#   s      r(   r"   zSpyderQApplication.__init__   rF   r)   r*   r/   s   @r(   r@   r@      rG   r)   )TestProgramc                       e Zd Zd ZdS )IPyTesProgramc                     t          j        t          j                  }|                    d|          |d<   d|d<   t          j        | g|R i | d S )N)stream
testRunnerFexit)unittestTextTestRunnersysstderrpoprK   r"   )r$   r%   r&   test_runners       r(   r"   zIPyTesProgram.__init__   s_    -SZ@@@%zz,DD|vT3D333F33333r)   N)r+   r,   r-   r"   r3   r)   r(   rM   rM      s#        4 4 4 4 4r)   rM   ignorezipykernel.ipkernel)actioncategorymodule)Screen
Terminatorc                      	 t                                                       dt          j        _        d S # t
          $ r Y d S w xY w)NT)r\   byeturtleTurtleScreen_RUNNINGr]   r3   r)   r(   
spyder_byerc      sK    	HHLLNNN+/F((( 	 	 	DD	s   15 
AAr2   zpandas.core.formatz .*invalid value encountered in.*)rY   rZ   r[   messagezpandas.formats.formatznumpy.core._methodsc                 `   	 t          |           }n8# t          $ r+ t          j        d         }d|_        t          |           }Y nw xY wt
          j        dk    rTd|v rPt
          j                            |d                   s+t          d
                    |d                              |d= |S )z{
            Patched get_preparation_data to work when all variables are
            removed before execution.
            __main__r   r   init_main_from_pathzHWarning: multiprocessing may need the main file to exist. Please save {})_old_preparation_dataAttributeErrorrT   modules__spec__osnamepathexistsr
   format)rm   dmain_modules      r(   _patched_preparation_datars   "  s    
0)$//! 0 0 0!k*5')$)$//	0 4$9Q$>$>GNN1-B+CDD %?%%+VA.C,D%E%EG G G +,Hs    2AAc                 *    t          j        d          S )N)P      )rl   terminal_size)fds    r(   _patched_get_terminal_sizery   A  s    H%%%r)   SPY_UMR_NAMELIST)namelistc                    t                      }|                    | ||f           t          j        |j                  }| t
          k    st          j        d           t          d           t          d           t          d           d|_	        |
                                 |j        j        }t          j        d           |                    ||           dS dS )zb
    For post mortem exception handling, print a banner and enable post
    mortem debugging.
    g?z(****************************************z!Entering post mortem debugging...TN)r   showtracebackpdbPdbcolorsSyntaxErrortimesleepr
   send_initial_notificationresettb_nexttb_frameinteraction)typevaluetbipython_shellpframes         r(   post_mortem_excepthookr   U  s    
  MMMub 1222$%%A;
3x2333x
 '+#				
#
3	eR     ! r)   c                      	 t          d                                          S # t          $ r5 t          d           t	                                          d           Y dS w xY w)zGet the current file name.TblockingzThis command failed to be executed because an error occurred while trying to get the current file name from Spyder's editor. The error was:

exception_onlyN)r   current_filename	Exceptionr
   r   r}   r3   r)   r(   get_current_file_namer   t  sz    ...??AAA    - 	. 	. 	. 	##4#888tts   !$ ;A#"A#c                     t           r|                     d          }n|                     d          }|sdS t          |          D ]\  }}|r|                                s|c S  t	          |          S )z(Count the number of leading empty cells.Tkeependsr   )r	   
splitlines	enumerateisspacelen)celllinesilines       r(   count_leading_empty_linesr     s    
 /%%.. qU##  4 	 	HHHu::r)   Fc                    t          |           }|rkt          r| S |                     d          s| dz  } |                     d          }t	          t          |                    }d                    |          } nMt          r#t                      }|                    |           S t                      }|                    |           } d|z  | z   S )z&Transform IPython code to Python code.
Tr   r   )
r   r	   endswithr   r   r   joinr   transform_cellr   )codeindent_onlynumber_empty_linesr   tms        r(   r   r     s    2488 + 	K}}T"" 	DLD..2599::wwu~~ 	+%''B$$T***#%%B$$T**D$$t++r)   c                    d}t           rt          |          }t          |           } |t          }t                      }t          j                            |          d         dk    }		 |	s	 t          j        t          | d                    }
n# t          $ rm}	 t          j        t          |                     }
t          rt          d           dan(# t          $ r t           r|t          d           Y nw xY wY d}~n)d}~ww xY wt          j        t          |                     }
|                                 d	d         d
k    rd}|rt          |
d          \  }
} |t!          |
|d          ||           |r|                    dd          }||d}S n# t$          $ r'}|j        r|                    d           Y d}~nd}~wt*          $ r}t-          |t.          j                  r|j        rd|_        nV|r>t-          |t4                    r)t7          j                    \  }}}t;          |||           n|                    d           Y d}~nd}~ww xY wd}dS # d}w xY w)z'Execute code and display any exception.TN   z.ipy)r   z
WARNING: This is not valid Python code. If you want to use IPython magics, flexible indentation, and prompt removal, we recommend that you save this file with the .ipy extension.
Fzraise e from None;_spyder_outexec__pdb_exit__r   )	tb_offset)r	   r   r   r   rl   rn   splitextastparser   r   SHOW_INVALID_SYNTAX_MSGr
   r   rstripr   compilerV   
SystemExitr   r}   BaseException
isinstancebdbBdbQuitpdb_sessionr   rT   exc_infor   )r   filename
ns_globals	ns_localspost_mortemexec_funcapture_last_expression__tracebackhide__r   
is_ipythonast_codeeoutstatuserror
error_typer   s                    r(   	exec_coder     s      (##d||MMM!!(++A.&8J;+ 	789^Dd%K%K%KLL 8 8 88"y)=)=>>H / 801 1 1 38/ # 2 2 2 2 01111128( y!5!566H;;==$$&+#" 	)0A-1) 1)-H- 	8V44j)LLL" 	..55C$ +!  = = =; 	=''t'<<< 
5 
5 
5uck** 		5!-		5 )-M%% 	5Zy99 	5$'LNN!Jr":ub9999 ''!'444
5 +N****s   )F ,#B F 
D!C<D"C:7D9C::D=F DBF I& 
I'G	I& 	IA?II& II& &I*c                    	 t          d                              | |          S # t          $ rW 	 t          | d          5 }|                                cddd           cY S # 1 swxY w Y   n# t
          $ r Y nw xY w|r Y dS w xY w)zRetrieve the content of a file.Tr   save_allrN)r   get_file_coder   openreadr   )r   r   raise_exceptionfs       r(   r   r     s   ...<<x = ) ) 	) 
 
 
	h$$  vvxx                                       	 	 	D	 	tt
s\   $' 
BA1A%A1"B%A)	)A1,A)	-A10B1
A>;B=A>>BBc           	      .    t          | |||||d          S )a  
    Run filename
    args: command line arguments (string)
    wdir: working directory
    namespace: namespace for execution
    post_mortem: boolean, whether to enter post-mortem mode on error
    current_namespace: if true, run the file in the current namespace
    r   stack_depth)
_exec_file)r   r%   wdir	namespacer   current_namespaces         r(   runfiler     s,     $i&A7 7 7 7r)   c	           
         d}	t                      }
| t                      } | d S 	 |                     d          } n# t          t          t
          f$ r Y nw xY wt          rt          |           } t          j	        rt          
                                 |$t          |t                    st	          d          	 t          | d          }nB# t          $ r5 t          d           t                                          d           Y d S w xY w||} nt#          |           } t%          | ||||dz             5 \  }}| gt&          _        |6t+          j        |          D ]!}t&          j                            |           "d	t&          j        v r1	 t&          j        d
         t&          j        d<   n# t          $ r Y nw xY w|t          r.	 |                    d          }n# t          t          f$ r Y nw xY wt2          j                            |          rbt3          j        |           dt&          j        v r?	 dd l}t2          j                            |          |j        _         n3# t          $ r Y n'w xY wn"t          d!                    |                     	 t          j"        rXtG          j$        | d          5 }|
%                    dd|&                                           d d d            n# 1 swxY w Y   ntO          || ||||d           dgt&          _        n# dgt&          _        w xY w	 d d d            d S # 1 swxY w Y   d S )NTr2   z"expected a character buffer object)r   zThis command failed to be executed because an error occurred while trying to get the file code from Spyder's editor. The error was:

r   r   )	file_coder   multiprocessingrf   __mp_main__zmultiprocessing.processr   z$Working directory {} doesn't exist.
)encodingcythonr   Fr   r   r   )(r   r   decodeUnicodeError	TypeErrorri   r	   r   __umr__enabledrunr   
basestringr   r   r
   r}   r   r   rT   r   shlexsplitrE   rj   rl   rn   isdirchdirmultiprocessing.processabspathprocessORIGINAL_DIRrp   
has_cythonior   run_cell_magicr   r   )r   r%   r   r   r   r   r   r   canonic_filenamer   r   r   r   r   argr   r   s                    r(   r   r     sI    MMM(**F??7++)^4    	  $(## 
4 < <<===	!(DAAA		   *	+ 	+ 	+ 	##4#888 ##8$$	(I/@$-;?
 
 
 -6
I:{4(( % %$$$$++-0[-DM**     ;;w//DD$i0   D w}}T"" M,;;6666?Aw @" @"/<<$    < >EEdKKLLL
	! 9WX888 IA!002qvvxxHHHI I I I I I I I I I I I I I I )Xz9&1H279 9 9 9 tCHHtCHOOOOH[- - - - - - - - - - - - - - - - - -s   < AA;C ;DD:AMF21M2
F?<M>F??MG"!M"G63M5G66AM;-I)(M)
I63M5I66&M"L%?*K5)L%5K9	9L%<K9	=L%M%L44MM	M	c           	         d}| t                      } | dS t                      }|                                rMd                    t	          |                     d|d|d|dz   }|j                            || d           dS t          | d          }t          | |	                    |           ||||j
        d	           dS )
z
    Debug filename
    args: command line arguments (string)
    wdir: working directory
    post_mortem: boolean, included for compatiblity with runfile
    TNz
runfile({}z, args=z, wdir=z, current_namespace=)r   )r   r   r%   r   r   r   r   )r   r   is_debuggingrp   reprr   enter_recursive_debuggerr   r   r   r   )	r   r%   r   r   r   r   shellr   debuggers	            r(   	debugfiler  w  s	    (**FMME 
 X///ddd---// 	 	22(D	
 	
 	
 	
 	
 $Hd33%--h77/\	
 	
 	
 	
 	
 	
r)   c                 ,    d}t          | ||d          S )a  
    Run a code cell from an editor as a file.

    Parameters
    ----------
    cellname : str or int
        Cell name or index.
    filename : str
        Needed to allow for proper traceback links.
    post_mortem: bool
        Automatically enter post mortem on exception.
    Tr   r   )
_exec_cell)cellnamer   r   r   s       r(   runcellr    s!     h+1EEEEr)   c           
         d}|t                      }|dS 	 |                    d          }n# t          t          t          f$ r Y nw xY wt                      }	 t          d                              | |          }nB# t          $ r5 t          d           t                      
                    d           Y dS w xY w|r|                                dk    rt          d           dS |j                            d	           t          |d
          }	||}nt          |          }t!          |d|	|dz             5 \  }
}t#          |||
|||d          cddd           S # 1 swxY w Y   dS )z9
    Execute a code cell with a given exec function.
    TNr2   r   zThis command failed to be executed because an error occurred while trying to get the cell code from Spyder's editor. The error was:

r   r   z(Nothing to execute, this cell is empty.
post_executeFr   r   )r   r   r   r   )r   r   r   r   ri   r   r   run_cellr   r
   r}   stripeventstriggerr   r   r   r   )r  r   r   r   r   r   r   r   	cell_coder   r   r   s               r(   r  r    s    (**F??7++)^4    	  MMM	$  #8Hh77 		    - 	. 	. 	. 	##4#888  	))R//:;;;   000h777I ## 8$$	(d$-;?
 
 
 76
IHj)%08157 7 77 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s3   . AA$A? ?;B>=B>E''E+.E+c                    d}|t                      }|dS t                      }|                                rcd                    t	          |                     d                    t	          |                    z   }|j                            ||d           dS t          |d          }t          | ||	                    |          |j
        d           dS )zDebug a cell.TNzruncell({}, z{})Fr   )r  r   r   r   r   )r   r   r   rp   r   r   r  r   r  r   r   )r  r   r   r   r  r   r  s          r(   	debugcellr    s     (**FMME 
 !!$x..11LLh(() 	 	22(E	
 	
 	
 	
 	
 $He44%--h77\	
 	
 	
 	
 	
 	
r)   c                     | t                      } | t          d          	 t          d                              |           }|S # t          $ r# t          j                    \  }}} ||          w xY w)z
    Get the number of cells in a file.

    Parameters
    ----------
    filename : str
        The file to get the cells from. If None, the currently opened file.
    Nz'Could not get cell count from frontend.Tr   )r   RuntimeErrorr   
cell_countr   rT   r   )r   r  etyper   r   s        r(   r  r    s     (**HIII%t444??II
   <>>ubeElls   $A -A5c                     t           j                            d          } | r_t          j                            |                     t           j                             t           j                            d| i           d S d S )NSPY_PYTHONPATH
PYTHONPATH)	rl   environgetrT   rn   extendr   pathsepupdate)pypaths    r(   set_spyder_pythonpathr  ,  sk    Z^^,--F 2RZ00111

<0111112 2r)   rB   )F)NFNF)TF)NNNNFF)	NNNNFFr   NN)NNNFF)NF)NFr   NN)r   r   r   loggingrl   r~   r   rT   r   warningsIPython.core.getipythonr   !spyder_kernels.comms.frontendcommr   *spyder_kernels.customize.namespace_managerr   "spyder_kernels.customize.spyderpdbr   r   spyder_kernels.customize.umrr   spyder_kernels.py3compatr	   r
   r   r   r   spyder_kernels.customize.utilsr   r   IPython.core.inputtransformer2r   r   r   IPython.core.inputsplitterr   	getLoggerr+   loggerhasattrr   r  r  IS_EXT_INTERPRETERHIDE_CMD_WINDOWSr   __builtin__builtinsImportErrorstrr   rm   localectypesgetdefaultlocale_t_cpintwindllkernel32SetConsoleCPSetConsoleOutputCP
ValueErrorr   r   
subprocessr    Popenr   sitecustomizeplatform
startswithr4   getfilesystemencodingsipqtypesetapirV   KeyErrorPyQt5r>   QApplicationr@   rD   PyQt4rH   rR   rK   rM   mainfilterwarningsDeprecationWarningr`   r\   r]   rc   r_   pandaspdoptionsdisplayr   RuntimeWarningmultiprocessing.spawnr   spawnget_preparation_datarh   rs   ry   get_terminal_sizer   r   r   r   r   r   r   r   r   r   spyder_runfiler  r  r  r  r  r  r3   r)   r(   <module>rY     s	   


 



 				  				 



  



   / / / / / / > > > > > > G G G G G G J J J J J J J J ; ; ; ; ; ;9 9 9 9 9 9 9 9 9 9 9 9 9 9 E E E E E E E E
 @A A A A A A A A A A A @????? 
	8	$	$ wsF tCH Z^^$>??6I :>>.11V;  """""   OOOJJJ 7d??s?)&)&11C	#c!""g,,CM"//444M"55c::::I& 	 	 	D	     7d??'?MC C C C C** C C C
 'J	 	 	 	D	  ?3<""7++ ?   !?C :>>(v%%


6 	! 	!ECJua    	!    

x       	; ; ; ; ;Y3 ; ; ; )+%/I 	 	 	D		; ; ; ; ;U/ ; ; ; )+%+E 	 	 	D	             4 4 4 4 4K 4 4 4 	H86H#79 9 9 9 9 	 	 	D		MMM))))))))   FJJ 	 	 	D		 #*BJ H8n#7$FH H H H H8n#:$FH H H H H  	 	 	D			
 H8n#8$FH H H H H  	 	 	D	  $$$$ / 5 J	 	 	, 6O22   & & & & 2  
 
bjnn5G&N&N
O
O
O! ! !>	 	 	  , , , ,, GL5:L+ L+ L+ L+^   & <@167 7 7 7 ?CGH/3V V V Vx  &H%H @E %%
 %
 %
 %
P  F F F F$ HI/327 27 27 27j  
 
 
 
<     , ! 2 2 2       s   C C)(C):E6 AE( 'E6 (E2/E6 1E22E6 6E>=E>/F4 4F<;F<H H'&H'+I II'I: :JJ'J. .J65J6K- -K54K59L LL=M M"!M"&M; ;NN	N) )N10N1