Ë
    æš¾j%,  ã                  ó
  — U d Z ddlm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mZmZ 	 ddlZddlZerddlmZ ddlmZ  ej.                  e«      Zi Zd	ed
<   dZ	 dZdZ e e	d«      jA                  «       «      gZ!d!d„Z"d"d„Z#de$fde#fde#fde#fde#fde#fdœZ%ded<    G d„ de«      Z&d#d„Z'd$d„Z(	 	 	 	 	 	 	 	 	 	 	 	 d%d„Z)	 	 	 	 d&	 	 	 	 	 	 	 	 	 	 	 d'd„Z*	 	 	 	 	 	 	 	 d(	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)d „Z+y# e$ r dZY ŒÒw xY w)*aº  Implements I/O streams over SSH; GSSAPI auth (``gss_*`` options) needs ``paramiko[gssapi]``.

Example:
    >>> 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'
é    )ÚannotationsN)ÚPath)ÚTYPE_CHECKINGÚAnyÚ	TypedDictT)ÚCallable)ÚTransportParamsz)dict[tuple[str, str], paramiko.SSHClient]Ú_SSH)Ú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                óH   — | xr t         j                  j                  | «      S ©N)ÚurllibÚparseÚunquote)Útexts    úX/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/smart_open/ssh.pyÚ_unquoter   C   s   € ØÒ.”F—L‘L×(Ñ(¨Ó.Ð.ó    c                ó<   — | dk(  ry| dk(  ryd| › d�}t        |«      ‚)NÚnoFÚyesTzExpected 'yes' / 'no', got ú.)Ú
ValueError)ÚstringÚmsgs     r   Ú	_str2boolr   G   s.   € Ø�‚~ØØ�‚ØØ'¨ x¨qÐ
1€CÜ
�S‹/Ðr   ÚconnecttimeoutÚcompressionÚgssapiauthenticationÚgssapikeyexchangeÚgssapidelegatecredentialsÚgssapitrustdns)ÚtimeoutÚcompressÚgss_authÚgss_kexÚgss_deleg_credsÚgss_trust_dnszdict[str, tuple[str, Callable]]Ú_PARAMIKO_CONFIG_MAPc                  óJ   — e Zd ZU ded<   ded<   ded<   ded<   ded<   ded	<   y
)Ú_SSHUriÚstrÚschemeú
str | NoneÚuri_pathÚuserÚhostú
int | NoneÚportÚpasswordN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r   r   r.   r.   d   s%   … ØƒKØÓØ
ÓØ
ÓØ
ÓØÔr   r.   c                óV  — t         j                  j                  | «      }|j                  t        v sJ ‚|j                  t        |j                  «      t        |j                  «      |j                  |j                  rt        |j                  «      ndt        |j                  «      dœS )zJParse an ``ssh://``/``scp://``/``sftp://`` URI into connection components.N)r0   r2   r3   r4   r6   r7   )r   r   Úurlsplitr0   ÚSCHEMESr   ÚpathÚusernameÚhostnamer6   Úintr7   )Úuri_as_stringÚ	split_uris     r   Ú	parse_urirF   m   s‚   € ä—‘×%Ñ% mÓ4€IØ×ÑœwÑ&Ð&Ð&à×"Ñ"Ü˜YŸ^™^Ó,Ü˜×+Ñ+Ó,Ø×"Ñ"Ø'0§~¢~”�I—N‘NÔ#¸4Ü˜Y×/Ñ/Ó0ñð r   c                óÜ   — t         j                  j                  t        |«      }t	        t        | «      «      }|j                  d«      }|j                  d«       i |¥|¥}t        ||fi |¤ŽS )zCOpen an SSH/SCP/SFTP URI using the given mode and transport params.r2   r0   )Ú
smart_openÚutilsÚcheck_kwargsÚopenÚdictrF   Úpop)ÚuriÚmodeÚtransport_paramsÚkwargsÚ
parsed_urir2   Úfinal_paramss          r   Úopen_urirT   {   sd   € ä×Ñ×*Ñ*¬4Ð1AÓB€FÜ!%¤i°£nÓ!5€JØ�~‰~˜jÓ)€HØ‡N�N�8ÔØ+�jÐ+ FÐ+€LÜ�˜$Ñ/ ,Ñ/Ð/r   c                óD  — t        j                  «       }|j                  «        |j                  t        j                  «       «       |xs i j                  «       }d|vr|j                  d|«       |j                  d|«        |j                  | |�|nt        fi |¤Ž |S )NÚkey_filenamer7   rA   )	ÚparamikoÚ	SSHClientÚload_system_host_keysÚset_missing_host_key_policyÚAutoAddPolicyÚcopyÚ
setdefaultÚconnectÚDEFAULT_PORT)rB   rA   r6   r7   Úconnect_kwargsr   rQ   s          r   Ú_connect_sshra   …   s‘   € ô ×
Ñ
Ó
€CØ×ÑÔØ×#Ñ#¤H×$:Ñ$:Ó$<Ô=ØÒ" ×(Ñ(Ó*€FØ˜VÑ#Ø×Ñ˜* hÔ/Ø
×Ñ�j (Ô+Ø€C‡K�K� $Ð"2™$¼ÑOÈÒOØ€Jr   c                ó¢  — t        d„ | ||||fD «       «      s| ||||fS | sd}t        |«      ‚|xs i j                  «       }t        D �cg c]  }t	        |«      j                  «       sŒ|‘Œ  }}d}	|D �]  }
	 t        j                  j                  |
«      }| |j                  «       vrŒ7|j                  | «      }|€|j                  dd «      }|	s|d   }	|€5t        j                  t        t        «      5  t!        |d   «      }d d d «       |j                  d«      €"|j                  dg «      }t#        |«      r||d<   t$        j'                  «       D ]-  \  }\  }}|j                  |«      �Œ||v sŒ  |||   «      ||<   Œ/ �Œ |€t(        }|st+        j,                  «       }|	r|	} | ||||fS c c}w # t        $ r Y �ŒNw xY w# 1 sw Y   ŒÁxY w)	Nc              3  ó$   K  — | ]  }|d u –— Œ
 y ­wr   r<   )Ú.0Úargs     r   ú	<genexpr>z&_maybe_fetch_config.<locals>.<genexpr>Ÿ   s   è ø€ ÒW˜sˆs�dŒ{ÑWùs   ‚z'you must specify the host to connect toÚ r3   rB   r6   rV   Úidentityfile)Úanyr   r\   Ú_SSH_CONFIG_FILESr   ÚexistsrW   Ú	SSHConfigÚ	from_pathÚPermissionErrorÚget_hostnamesÚlookupÚgetÚ
contextlibÚsuppressÚKeyErrorrC   Úlenr,   Úitemsr_   ÚgetpassÚgetuser)r4   rA   r7   r6   r`   r   Úconnect_paramsÚfÚconfig_filesÚactual_hostnameÚconfig_filenameÚcfgrh   Ú
param_nameÚsshcfg_nameÚfrom_strs                   r   Ú_maybe_fetch_configr‚   —   sû  € ô ÑW t¨X°xÀÀ~Ð&VÔWÔWØ�X˜x¨¨~Ð=Ð=áØ7ˆÜ˜‹oÐð" %Ò*¨×0Ñ0Ó2€NÜ0ÖE˜!´D¸³G·N±NÕ4D’AÐE€LÐEð
 €Oà'ó !Hˆð	Ü×$Ñ$×.Ñ.¨Ó?ˆCð �s×(Ñ(Ó*Ñ*Øà�j‰j˜ÓˆØÐØ—w‘w˜v tÓ,ˆHáØ! *™oˆOàˆ<ä×$Ñ$¤X¬zÓ:ñ (Ü˜3˜v™;Ó'�÷(ð ×Ñ˜nÓ-Ð5ØŸ7™7 >°2Ó6ˆLÜ�<Ô Ø1=�˜~Ñ.ä3G×3MÑ3MÓ3Oò 	HÑ/ˆJÑ/˜ hØ×!Ñ! *Ó-Ñ5¸+ÈÒ:LÙ-5°c¸+Ñ6FÓ-G�˜zÒ*ò	Hð?!HðP €|ÜˆáÜ—?‘?Ó$ˆáØˆà�˜8 T¨>Ð9Ð9ùòq Føô ò 	Úð	ú÷(ð (ús*   Á
F0Á)F0Á8F5Ã6GÆ5	GÇGÇG	c	           	     óÂ  — t        |||||«      \  }}}}}|€J ‚|€J ‚| €J ‚||f}	d}
d}t        |«      D ]z  }	 t        |	   }|j                  «       }|€J ‚|j                  s(|j                  «        t        |||||«      x}t        |	<   	 |j                  «       }|€J ‚|j                  «       }
 n |
€J ‚|
j                  | ||¬«      }| |_        |� |j                  di |¤Ž |S # t        $ r t        |||||«      x}t        |	<   Y Œ€w xY w# t        j                  $ r=}|j                  xr |j                  d   dk(  }||dz
  k(  s|s‚ t        |	= Y d}~�Œ$d}~ww xY w)aw  Open a file on a remote machine over SSH.

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

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

    Returns:
        A file-like object.

    Raises:
        paramiko.SSHException: If the SSH session is no longer active and
            cannot be re-established within the retry limit.

    Note:
        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.
    Né   r   zSSH session not activeé   )rO   Úbufsizer<   )r‚   Úranger
   Úget_transportÚactiveÚclosera   rt   Úopen_sftp_clientrW   ÚSSHExceptionÚargsrK   ÚnameÚprefetch)r@   rO   r4   r3   r7   r6   r`   Úprefetch_kwargsÚbuffer_sizeÚkeyÚsftp_clientÚattemptsÚattemptr   Ú	transportÚexÚconnection_timed_outÚfobjs                     r   rK   rK   ñ   s¿  € ôT 2EØˆd�H˜d Nó2Ñ.€Dˆ$�˜$ ð ÐÐÐØÐÐÐØÐÐÐà�ˆ,€Cà.2€KØ€HÜ˜“?ò ˆð
	WÜ�s‘)ˆCð ×)Ñ)Ó+ˆIØÐ(Ð(Ð(Ø×#Ò#Ø—	‘	”Ü".¨t°T¸4ÀÈ>Ó"ZÐZ�”d˜3‘ið	Ø×)Ñ)Ó+ˆIØÐ(Ð(Ð(Ø#×4Ñ4Ó6ˆKÙð#ð: Ð"Ð"Ð"Ø×Ñ˜D t°[ÐÓA€DØ€D„IØÐ"Øˆ�‰Ñ(˜Ò(Ø€Køô1 ò 	WÜ*¨4°°t¸XÀ~ÓVÐVˆC”$�s“)ð	Wûô ×$Ñ$ò 		Ø#%§7¡7Ò#U¨r¯w©w°q©zÐ=UÑ/UÐ Ø˜( Q™,Ò&Ñ.BØô �S–	ûð		ús*   ¹AC'Â$DÃ'!DÄ
DÄEÄ!2EÅE)r   r1   Úreturnr1   )r   r/   rš   Úbool)rD   r/   rš   r.   )rN   r/   rO   r/   rP   r	   rš   úparamiko.SFTPFile)rB   r/   rA   r1   r6   r5   r7   r1   r`   údict[str, Any] | Nonerš   zparamiko.SSHClient)NNNN)r4   r1   rA   r1   r7   r1   r6   r5   r`   r�   rš   zLtuple[str | None, str | None, str | None, int | None, dict[str, Any] | None])ÚrNNNNNNéÿÿÿÿ)r@   r1   rO   r/   r4   r1   r3   r1   r7   r1   r6   r5   r`   r�   r�   r�   r‘   rC   rš   rœ   ),Ú__doc__Ú
__future__r   rr   rw   ÚloggingÚurllib.parser   Úpathlibr   Útypingr   r   r   rW   ÚImportErrorÚMISSING_DEPSÚsmart_open.utilsrH   Úcollections.abcr   Úsmart_open._typingr	   Ú	getLoggerr8   Úloggerr
   r;   r?   r_   ÚURI_EXAMPLESr/   Ú
expanduserrj   r   r   Úfloatr,   r.   rF   rT   ra   r‚   rK   r<   r   r   ú<module>r°      s  ðòõ #ã Û Û Û Ý ß 0Ñ 0ðÛó áÝ(å2à	ˆ×	Ñ	˜8Ó	$€ð
 35€Ð/Ó 4à
 €Ø à€ð€ñ ™˜oÓ.×9Ñ9Ó;Ó<Ð=Ð ó/óð( ! %Ð(Ø 	Ð*Ø'¨Ð3Ø# YÐ/Ø3°YÐ?Ø&¨	Ð2ñ9Ð Ð5ó ôˆiô óó0ðØðàðð ðð ð	ð
 *ðð óð(  ØØØ,0ðW:Ø
ðW:àðW:ð ðW:ð ð	W:ð
 *ðW:ð RóW:ðx ØØØØØ,0Ø-1ØðWØ
ðWà
ðWð ðWð ð	Wð
 ðWð ðWð *ðWð +ðWð ðWð ôWøðc ò Ø‚Lðús   «C8 Ã8DÄD