
    h$                     d   % S r SSKrSSKrSSKrSSKrSSKJrJrJ	r	   SSK
r
SSKr\R                  " \5      r0 rSr SrSr\R,                  R/                  S5      /rS	 rS
 rS\4S\4S\4S\4S\4S\4S.r\\\	\\4   4   \S'   S rS r S r!SS jr"        SS jr#g! \ a    Sr Nf = f)aq  Implements I/O streams over SSH.

Examples
--------

>>> with open('/proc/version_signature', host='1.2.3.4') as conn:
...     print(conn.read())
b'Ubuntu 4.4.0-1061.70-aws 4.4.131'

Similarly, from a command line::

    $ python -c "from smart_open import ssh;print(ssh.open('/proc/version_signature', host='1.2.3.4').read())"
    b'Ubuntu 4.4.0-1061.70-aws 4.4.131'

    N)DictCallableTupleT)sshscpsftp   )zssh://username@host/path/filezssh://username@host//path/filezscp://username@host/path/filezsftp://username@host/path/filez~/.ssh/configc                 R    U =(       a    [         R                  R                  U 5      $ N)urllibparseunquote)texts    H/home/james-whalen/.local/lib/python3.13/site-packages/smart_open/ssh.py_unquoter   D   s    .FLL((..    c                 <    U S:X  a  gU S:X  a  g[        SU  S35      e)NnoFyesTzExpected 'yes' / 'no', got .)
ValueError)strings    r   	_str2boolr   H   s+    ~
26(!<
==r   connecttimeoutcompressiongssapiauthenticationgssapikeyexchangegssapidelegatecredentialsgssapitrustdns)timeoutcompressgss_authgss_kexgss_deleg_credsgss_trust_dns_PARAMIKO_CONFIG_MAPc           
      n   [         R                  R                  U 5      nUR                  [        ;   d   e[        UR                  [        UR                  5      [        UR                  5      UR                  UR                  (       a  [        UR                  5      OS [        UR                  5      S9$ )N)schemeuri_pathuserhostportpassword)r   r   urlsplitr(   SCHEMESdictr   pathusernamehostnamer,   intr-   )uri_as_string	split_uris     r   	parse_urir7   d   s    %%m4Iw&&&)..)i(()$-NNS ),,- r   c                     [         R                  R                  [        U5      n[	        U 5      nUR                  S5      nUR                  S5        0 UEUEn[        XQ40 UD6$ )Nr)   r(   )
smart_openutilscheck_kwargsopenr7   pop)urimodetransport_paramskwargs
parsed_urir)   final_paramss          r   open_urirD   q   s]    **41ABF3J~~j)HNN8+j+F+L/,//r   c                 D   [         R                  " 5       nUR                  5         UR                  [         R                  " 5       5        U=(       d    0 R                  5       nSU;  a  UR                  SU5        UR                  SU5        UR                  " X40 UD6  U$ )Nkey_filenamer-   r2   )paramiko	SSHClientload_system_host_keysset_missing_host_key_policyAutoAddPolicycopy
setdefaultconnect)r3   r2   r,   r-   connect_kwargsr   rA   s          r   _connect_sshrP   z   s    



C##H$:$:$<="((*FV#*h/
j(+KK)&)Jr   c                    [        S XX#U4 5       5      (       d  XX#U4$ U (       d  [        S5      eU=(       d    0 R                  5       n[         Vs/ s H+  n[        R
                  R                  U5      (       d  M)  UPM-     nnSnU H  n	 [        R                  R                  U	5      n
X
R                  5       ;  a  M8  U
R                  U 5      n
Uc  U
R                  SS 5      nU(       d  U
S   nUc   [        U
S   5      nUR                  S5      c&  U
R                  S/ 5      n[!        U5      (       a  XS'   ["        R%                  5        H/  u  nu  pUR                  U5      b  M  X;   d  M#  U" X   5      X\'   M1     M     Uc  [&        nU(       d  [(        R*                  " 5       nU(       a  Un XX#U4$ s  snf ! [         a     GME  f = f! [        [        4 a     Nf = f)	Nc              3   (   #    U  H  oS L v   M
     g 7fr    ).0args     r   	<genexpr>&_maybe_fetch_config.<locals>.<genexpr>   s     W&Vsd{&Vs   z'you must specify the host to connect to r*   r3   r,   rF   identityfile)anyr   rL   _SSH_CONFIG_FILESosr1   existsrG   	SSHConfig	from_pathPermissionErrorget_hostnameslookupgetr4   KeyErrorlenr&   itemsDEFAULT_PORTgetpassgetuser)r+   r2   r-   r,   rO   connect_paramsfconfig_filesactual_hostnameconfig_filenamecfgrY   
param_namesshcfg_namefrom_strs                  r   _maybe_fetch_configrs      s   Wtx~&VWWWx~==BCC" %*002N0F0!BGGNN14EA0LF
 O'	$$..?C ((**jjwwvt,H!*oO<3v;' n-577>26L<  1=~.3G3M3M3O/J/!!*-5+:L-5c6F-G* 4PG (X |??$8>99y G  		  j)  	s0   (F=?F=G9G
GGG'&G'c	           	         [        X#XEU5      u  p#pEnX#4n	Sn
[        U
5       Hs  n [        U	   nUR                  5       R                  (       d&  UR                  5         [        X#XTU5      =n[        U	'    UR                  5       nUR                  5       n  O   WR                  XUS9nU Ul        Ub  UR                  " S0 UD6  U$ ! [         a    [        X#XTU5      =n[        U	'    Nuf = f! [        R                   aH  nUR                  =(       a    UR                  S   S:H  nXS-
  :X  d  U(       d  e [        U		  SnAGM"  SnAff = f)a  Open a file on a remote machine over SSH.

Expects authentication to be already set up via existing keys on the local machine.

Parameters
----------
path: str
    The path to the file to open on the remote machine.
mode: str, optional
    The mode to use for opening the file.
host: str, optional
    The hostname of the remote machine. May not be None.
user: str, optional
    The username to use to login to the remote machine.
    If None, defaults to the name of the current user.
password: str, optional
    The password to use to login to the remote machine.
port: int, optional
    The port to connect to.
connect_kwargs: dict, optional
    Any additional settings to be passed to paramiko.SSHClient.connect.
prefetch_kwargs: dict, optional
    Any additional settings to be passed to paramiko.SFTPFile.prefetch.
    The presence of this dict (even if empty) triggers prefetching.
buffer_size: int, optional
    Passed to the bufsize argument of paramiko.SFTPClient.open.

Returns
-------
A file-like object.

Important
---------
If you specify a previously unseen host, then its host key will be added to
the local ~/.ssh/known_hosts *automatically*.

If ``username`` or ``password`` are specified in *both* the uri and
``transport_params``, ``transport_params`` will take precedence
   r   zSSH session not active   N)r?   bufsizerS   )rs   range_SSHget_transportactivecloserP   rd   open_sftp_clientrG   SSHExceptionargsr<   nameprefetch)r1   r?   r+   r*   r-   r,   rO   prefetch_kwargsbuffer_sizekeyattemptsattemptr   	transportsftp_clientexconnection_timed_outfobjs                     r   r<   r<      sP   d 2EHN2.D ,CH?	Ws)C $$&--		".t4>"ZZd3i	))+I#446K #4 D[ADDI"((K-  	W*4t~VVC$s)	W $$ 		#%77#Urwwqz=U/U Q,&.B S			s*   AC5 C- C*)C*-E	<EE	)NNNN)rNNNNNN)$__doc__rh   r\   loggingurllib.parser   typingr   r   r   rG   ImportErrorMISSING_DEPSsmart_open.utilsr9   	getLogger__name__loggerry   r/   rg   URI_EXAMPLESr1   
expanduserr[   r   r   floatr&   str__annotations__r7   rD   rP   rs   r<   rS   r   r   <module>r      s     	    			8	$
 

   WW''89 />& !%(	*'3#Y/3Y?&	29 d3c8m 445 
0	T:r 
			Wo  Ls   B$ $B/.B/