
    G@d)                         d 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mZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZ  G d	 d
ee          ZdS )z#
External Kernel connection widget
    N)jupyter_runtime_dir)getopenfilename)Qt)	QCheckBoxQDialogQDialogButtonBoxQGridLayout	QGroupBoxQHBoxLayoutQLabel	QLineEditQPushButtonQRadioButtonQSpacerItemQVBoxLayout)SpyderConfigurationAccessor)_get_home_dirc                   X     e Zd ZdZdZd
 fd	Zd Zd Zd Zd Z	e
dd	            Z xZS )KernelConnectionDialogz?Dialog to connect to existing kernels (either local or remote).zexisting-kernelNc                    t          t          |                               |           |                     t	          d                     t          t	          d                    }|                    d           |                    t          j	                   |
                    d           t          t	          d                    }t                      | _        | j                            t	          d                     | j                            d           t          t	          d                    }|j                            | j                   t'                      }|                    |           |                    | j                   |                    |           t+          t	          d                    | _        t          t	          d	                    }t                      | _        t          t	          d
                    }t                      | _        | j                            d           t          t	          d                    }t                      | _        t+          t	          d                    }	t7                      | _        t          t	          d                    }
t7                      | _        t          t	          d                    }t                      | _        | j                            t          j                    | j        j!                            | j        j"                   | j        j!                            | j        j#                   t                      | _$        t          t	          d                    }|j                            | j%                   t'                      }|                    | j$                   |                    |           t          t	          d                    }t                      | _&        | j&                            t	          d                     | j&                            t          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#                   tO                      }|                    |dddd           |                    | j        dd           |                    |dd           |                    | j        dd           |                    |dddd           |                    | j        dddd           tO                      }|                    | j        dd           |                    |
dd           |                    | j        dd           |                    | j        dd           |                    |dd           |(                    |dd           |                    |dd           |                    | j&        dd           |	)                    |           tU                      }|(                    |           |+                    tY          dd                     |                    |	           | j        )                    |           | j        -                    d           | j        j!                            | j        j.                   t_          t^          j0        t^          j1        z  t          j2        |           | _3        | j3        j4                            | j5                   | j3        j4                            | j6                   | j3        j7                            | j8                   ts          |           | _:        | j:        ;                    t	          d                     t'                      }|                    | j:                   |                    | j3                   tU          |           }|                    |           |+                    tY          dd                     |(                    |           |+                    tY          dd                     |                    | j                   |(                    |           | j        <                                 | =                                 d S )NzConnect to an existing kernelah  <p>Please select the JSON connection file (<i>e.g.</i> <tt>kernel-1234.json</tt>) of the existing kernel, and enter the SSH information if connecting to a remote machine. To learn more about starting external kernels and connecting to them, see <a href="https://docs.spyder-ide.org/5/panes/ipythonconsole.html#using-external-kernels">our documentation</a>.</p>TzConnection file:zKernel connection file pathi^  Browsez!This is a remote kernel (via SSH)z	Hostname:zPort:K   z	Username:zAuthentication method:z	Password:zSSH keyfile:z
Passphase:Optionalr                  zSave connection settings   )>superr   __init__setWindowTitler   r   setWordWrapsetAlignmentr   AlignJustifysetOpenExternalLinksr   cfsetPlaceholderTextsetMinimumWidthr   clickedconnectselect_connection_filer   	addWidgetr
   rm_grouphnpnsetMaximumWidthunr   pw_radiokf_radiopwsetEchoModePasswordtoggled
setEnabledsetDisabledkfselect_ssh_keykfpr	   	addLayout	setLayoutr   addSpacerItemr   setCheckable
setCheckedr   OkCancel
Horizontalaccept_btnsacceptedsave_connection_settingsacceptrejectedrejectr   save_layoutsetTextsetFocusload_connection_settings)selfparent
main_labelcf_labelcf_open_btn	cf_layouthn_labelpn_labelun_label
auth_grouppw_labelkf_labelkf_open_btn	kf_layout	kfp_label
ssh_layoutauth_layout	rm_layoutbtns_layoutlayout	__class__s                       Slib/python3.11/site-packages/spyder/plugins/ipythonconsole/widgets/kernelconnect.pyr"   zKernelConnectionDialog.__init__!   s3   $d++44V<<<A=>>???A)* * + +
 	t$$$000''--- !.//00++""1%B#C#CDDD$$$!!H++..##D$?@@@MM	H%%%DG$$$K((( "!$G"H"HII !K..))++!G**%%++###!K..))++ q!9::;;
$!K..))$!N++,,++I.///%%dg&8999%%dg&9:::++!!H++..##D$7888MM	DG$$$K(((1\??++	;;##AjMM222Y/000%%dg&8999%%dh&9:::%%k&<===%%i&:;;;%%dg&9:::%%dh&:;;;%%k&=>>>%%i&;<<< !]]
Xq!Q222TWa+++Xq!,,,TWa+++Xq!Q222TWaAq111 "mmdmQ222h1---dgq!,,,dmQ222h1---iA...iA...dh1---[)))  MM	J'''Aq 1 1222J'''	***""4(((%%dm&>??? ,"2"99M4! ! 	!))$*GHHH!))$+666!))$+666 %T??  #=!>!>???!mmd.///d./// T""$$$[A..///###[B//000'''%%%%%'''''    c                 J   |                      di           }|                    dd          }|                    dd          }|                    dd          }|                    dd          }t          |                    dd	                    }|                    d
d          }|                    dd          }|dk    r| j                            |           |dk    r| j                            |           |dk    r| j                            |           |dk    r| j                            |           | j        	                    |           | j
                            |           | j        	                    |           | j        	                    |            	 ddl}	|	                    dd          }
|	                    dd          }|
r| j                            |
           |r| j                            |           dS dS # t"          $ r Y dS w xY w)z<Load the user's previously-saved kernel connection settings.settingsjson_file_path 	is_remoteFusernamehostnameport   is_ssh_keyfilessh_key_file_pathr   Nspyder_remote_kernelssh_key_passphrasessh_password)get_confgetstrr(   rN   r3   r0   r<   r/   rC   r1   r5   r4   keyringget_passwordr>   r6   	Exception)rQ   existing_kernelconnection_file_pathrl   rm   rn   ro   	is_ssh_kfssh_kfry   ssh_passphraseru   s               rf   rP   z/KernelConnectionDialog.load_connection_settings   s7   --
B77.223CRHH#''U;;	"&&z266"&&z266?&&vr2233#''(8%@@	 $$%8"==2%%GOO0111r>>GOOH%%%r>>GOOH%%%R<<GOOF###  +++  +++  Y///	NNN$112H2FH HN"//0F0>@ @L 1  000 .-----. . 	 	 	DD	s   (A(H 
H"!H"c                    | j                                         sdS t          | j                                                  }| j                                        | j                                        | j                                        | j                                        | j	                                        || j
                                        d}|                     d|           	 ddl}|r0|                    dd| j                                                   dS |                    dd| j                                                   dS # t           $ r Y dS w xY w)z'Save user's kernel connection settings.N)rj   rl   rm   rn   ro   rq   rr   ri   r   rs   rt   ru   )rM   	isCheckedboolr5   r(   textr/   r3   r0   r1   r<   set_confry   set_passwordr>   r6   r{   )rQ   
is_ssh_keyconnection_settingsry   s       rf   rI   z/KernelConnectionDialog.save_connection_settings   sZ    ))++ 	F$-113344
"gllnn0022GLLNN(!%
 
 	j"5666	NNN 5$$%;%9%)X]]__6 6 6 6 6 $$%;%3%)W\\^^5 5 5 5 5  	 	 	DD	s   -4E #.E 
E! E!c                     t          | t          d          t                      d          d         }| j                            |           d S )NzSelect kernel connection filez*.json;;*.*r   )r   r   r   r(   rN   )rQ   r(   s     rf   r-   z-KernelConnectionDialog.select_connection_file   sN    T1%D#E#E022MC CCDFrg   c                     t          | t          d          t                      d          d         }| j                            |           d S )NzSelect SSH keyfilez*.pem;;*r   )r   r   r   r<   rN   )rQ   r<   s     rf   r=   z%KernelConnectionDialog.select_ssh_key   sI    T1%9#:#:)^^Z9 99:<rg   c                    |st          |           }|                                }t          |j                                                  }|t
          j        k    }|rod }|j                                        r|j	                                        rz|j
                                        r|j
                                        nd}d                    |j	                                        |j                                        |          }nd }|j                                        r% ||j                                                  }d }	nb|j                                        rE ||j                                                  }	 ||j                                                  }nd }	d }|j                                        ||	||fS |j                                        }
t%          j        |
          t%          j        |
          }}|dk    r<|                    d          s't%          j        t/                      d|
z   dz             }
|
d d d |fS )Nc                     | r| nd S N )args    rf   falsy_to_nonezGKernelConnectionDialog.get_connection_parameters.<locals>.falsy_to_none   s    !+sst+rg   22z{0}@{1}:{2}rk   z.jsonzkernel-)r   exec_r   r/   r   r   Acceptedr0   r   r3   r1   formatr4   r6   r5   r<   r>   r(   ospdirnamebasenameendswithjoinr   )rR   dialogresultrl   rH   r   ro   rn   passwordkeyfilepath_dirfilenames                rf   get_connection_parametersz0KernelConnectionDialog.get_connection_parameters   s    	4+F33F224455	W-- 	6, , ,y~~  FINN$4$4  +19>>+;+;Evy~~'''(//	0@0@06	0@0@046 6  ((**  (=)9)9::**,,  '-	(8(899(=):):;;INN$$h8LL9>>##D [..T0B0B(Drzz("3"3G"<"<zx 3 5 5y~g7MNN$dH55rg   r   )NN)__name__
__module____qualname____doc__CONF_SECTIONr"   rP   rI   r-   r=   staticmethodr   __classcell__)re   s   @rf   r   r      s        II$LD( D( D( D( D( D(L$ $ $L  >  
  
  6  6  6 \ 6  6  6  6  6rg   r   )r   os.pathr   r   jupyter_core.pathsr   qtpy.compatr   qtpy.QtCorer   qtpy.QtWidgetsr   r   r   r	   r
   r   r   r   r   r   r   r   spyder.api.config.mixinsr   spyder.config.baser   r   r   r   rg   rf   <module>r      sU   
       3 2 2 2 2 2 ' ' ' ' ' '      ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) A @ @ @ @ @ . . . . . . . .{6 {6 {6 {6 {6W&A {6 {6 {6 {6 {6rg   