
    lc                         d Z ddlZddlZddlZddlZddlZ ej        e	          Z
i ZdZ	 dZdZd Zd Zd Zd	 Zd
dddedfdZdS )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)sshscpsftp   )zssh://username@host/path/filezssh://username@host//path/filezscp://username@host/path/filezsftp://username@host/path/filec                 D    | ot           j                            |           S )N)urllibparseunquote)texts    .lib/python3.11/site-packages/smart_open/ssh.py_unquoter   4   s    .FL((...    c           
      <   t           j                            |           }|j        t          v sJ t          |j        t          |j                  t          |j                  |j	        t          |j        pt                    t          |j                            S )N)schemeuri_pathuserhostportpassword)r   r	   urlsplitr   SCHEMESdictr   pathusernamehostnameintr   DEFAULT_PORTr   )uri_as_string	split_uris     r   	parse_urir    8   s    %%m44Iw&&&&).))i())/<00),--   r   c                     t           j                            t          |           t	          |           }|                    d          }|                    d           t          ||fd|i|S )Nr   r   transport_params)
smart_openutilscheck_kwargsopenr    pop)urimoder"   
parsed_urir   s        r   open_urir+   E   sh    !!$(89993J~~j))HNN8$PP1APZPPPr   c                 "   	 dd l }n## t          $ r t          j        d            w xY w| |f}t                              |          }||j                                        x}t          |<   |                                 |	                    |
                                           |                    di                                           }d|vr|                    d|           |                    d|            |j        | |fi | |S )Nr   zaparamiko missing, opening SSH/SCP/SFTP paths will be disabled. `pip install paramiko` to suppressconnect_kwargskey_filenamer   r   )paramikoImportErrorwarningswarn_SSHgetclient	SSHClientload_system_host_keysset_missing_host_key_policyAutoAddPolicycopy
setdefaultconnect)	r   r   r   r   r"   r/   keyr   kwargss	            r   _connectr?   M   s:      1	
 	
 	
 	 X
C
((3--C
 
."/33555d3i!!###''(>(>(@(@AAA!%%&6;;@@BB ' 	4j(333*h///Hd--f---Js     'rc                    |st          d          |st          j                    }|si }t          |||||          }|                                                                }|                    | |          }	| |	_        |	S )ax  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.
    transport_params: dict, optional
        Any additional settings to be passed to paramiko.SSHClient.connect

    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
    z'you must specify the host to connect to)
ValueErrorgetpassgetuserr?   get_transportopen_sftp_clientr&   name)
r   r)   r   r   r   r   r"   connsftp_clientfobjs
             r   r&   r&   g   s    F  DBCCC !   D$h0@AAD$$&&7799KD$''DDIKr   )__doc__rC   loggingurllib.parser   r1   smart_open.utilsr#   	getLogger__name__loggerr3   r   r   URI_EXAMPLESr   r    r+   r?   r&    r   r   <module>rT      s                		8	$	$
 

  / / /
 
 
Q Q Q  4 d<bf . . . . . .r   