Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/rads/__pycache__/ssh.cpython-39.pyc
Ðазад
a � h_ � @ sd d Z ddlZddlmZ ddlZddlmZ G dd� dejj�Z G dd� d�Z G d d � d ej�ZdS )z Convenience classes for paramiko� N)�List)�Channelc @ s e Zd ZdZdS )�SSHErrorzRaised by ``SSHConn`` on errorsN)�__name__� __module__�__qualname__�__doc__� r r �7/opt/imh-python/lib/python3.9/site-packages/rads/ssh.pyr s r c @ s e Zd ZdZed�dd�ZdS )� CmdResultzuReturn type for ``SSHConn.run()`` Attributes: stdout (str) stderr (str) rcode (int) )�cmdc C s� |� � �� }|�dd� |�|� |�dd�}|�dd�}|�� | _|�� | _| j� d�rj| jdd � | _t | jddd �| _t | jddd �| _|�� | _|� � d S ) N�shellZxterm�rb���s stdin: is not a tty � zutf-8�surrogateescape)�errors)� get_transport�open_session�set_environment_variable�exec_command�makefile�makefile_stderr�read�stdout�stderr� startswith�str�recv_exit_statusZrcode�close)�self�connr �chanr r r r r �__init__ s zCmdResult.__init__N)r r r r r r# r r r r r s r c s� e Zd ZdZed�� fdd�Zdd� Zdd� Zee e d �d d�Z ee e d �dd �Zee e d �dd�Zdd� Z eed�dd�Z� ZS )�SSHConnas Context manager that handles SSH connections **Arguments are the same as paramiko.SSHClient.connect, but with one extra argument, "sftp"** Args: sftp (bool): whether to enable SFTP and listdir features on connect Raises: SSHError: on failure to connect Attributes: sftp: A paramiko.SFTPClient object, or None )�sftpc s. t � �� | �t�� � || _|| _d| _dS )zmArgs for the context manager are read from here. If you don't need sftp functionality, set sftp=FalseN)�superr# �set_missing_host_key_policy�paramiko� AutoAddPolicy�_kwargs� _use_sftpr% )r r% �kwargs�� __class__r r r# 7 s zSSHConn.__init__c C sZ z&| j f i | j�� | jr$| �� | _W n. tyT } zt|�|�W Y d}~n d}~0 0 | S )z:Connects to SSH using the context manager 'with' statementN)�connectr* r+ � open_sftpr% � Exceptionr )r �excr r r � __enter__@ s zSSHConn.__enter__c C s | j r| j�� | �� dS )zADisconnects from SSH on un-indent, even if an exception is raisedN)r+ r% r )r �exc_typeZexc_val� tracebackr r r �__exit__J s zSSHConn.__exit__)�path�returnc C s | j |dd�S )z�List contents of a remote dir similar to os.listdir() Args: path: remote path to browse Raises: SSHError N��_type)�_listdir�r r7 r r r �listdirP s zSSHConn.listdirc C s | j |tjd�S )z�listdir() but only return directories Args: path: remote path to browse Raises: SSHError r9 )r; �stat�S_ISDIRr<