
    Je                     h    d Z ddlZddlZddlmZ ej
                  dk(  sddlZddlmZ d Z		 	 ddZ
y)	z,Utilities to connect to kernels through ssh.    N)QMessageBoxnt)_c                 .    t        j                  |        y )N)pexpectrun)cmds    I/usr/lib/python3/dist-packages/spyder/plugins/ipythonconsole/utils/ssh.py_stop_tunnelr      s    KK    c                 D   d}|r|d|z   z  }d|v r|j                  d      \  }}	|d|	z  z  }|d|}
t        j                  |
d      \  }}|st        ||j	                  d      d	z   |j	                  d
             }d|||||fz  }
t        j                  |
d      \  }}|s-t        j                  t        |
j                  ddd             |S d||||||fz  }
t        j                  j                         }|j                  dd       d}t        j                  |
|      }d}	 	 |j                  |ddgd      }|dk(  r|j                  d      d   }t        d      |z  }t!        j"                  | t        d      |t         j$                  t         j&                  z  t         j&                        }|t         j$                  k(  r|j)                  d       |j)                  d       t+        t        d             |dk(  r||j)                  |       |s|t+        t        d!            |j)                  |       d}# t        j,                  $ r Y 3t        j.                  $ r2 |j0                  rt+        t        d"      |
z        |j2                  cY S w xY w)#z
    We decided to replace pyzmq's openssh_tunnel method to work around
    issue https://github.com/zeromq/pyzmq/issues/589 which was solved
    in pyzmq https://github.com/zeromq/pyzmq/pull/615
    zssh z-i :z -p %sz
 -O check T)withexitstatusz(pid=   )z&%s -O forward -L 127.0.0.1:%i:%s:%i %sz
-O forwardz	-O cancel   z/%s -f -S none -L 127.0.0.1:%i:%s:%i %s sleep %iSSH_ASKPASSNz,Are you sure you want to continue connecting)envFz[Pp]assword:z[Pp]assphraseg?)timeoutr   @zfThe authenticity of host <b>%s</b> can't be established. Are you sure you want to continue connecting?Warningyesnoz1The authenticity of the host can't be establishedz Could not connect to remote hostzTunnel '%s' failed to start)splitr   r   intfindatexitregisterr   replaceosenvironcopypopspawnexpectr   r   questionYesNosendlineRuntimeErrorTIMEOUTEOF
exitstatuspid)selflportrportserverremoteipkeyfilepasswordr   sshportr	   outputr.   r/   r   
ssh_newkeytunnelfailedihostr'   replys                         r
   openssh_tunnelr@      s    Cuw
f}||C(x$!6
*C";;s4@VZ&W-a/C0@AB6%:1 1&{{3tDOOL#++l6A67+9 : J
;"%uhvw?P PC **//
CGGM4 ?J]]3C(FF
(	^_=  A Av||C(, + ,.23 $,,T1Y<-8__{~~-M-8^^= KOO+OOE*OOD)&LMO OAv(.) )"1%G#HII OOH%FS .  	{{ 	"  "1%B#Cc#IJJzz!		"s    *B0I =I JAJJ)z	127.0.0.1NNg?)__doc__r   r!   qtpy.QtWidgetsr   namer   spyder.config.baser   r   r@    r   r
   <module>rF      s8    3  	 &	ww$   9D8;Nr   