File: //lib/python3/dist-packages/pexpect/__pycache__/pxssh.cpython-310.pyc
o
    ��!^�^  �                   @   s�   d Z ddlmZmZmZmZ ddlZddlZddlZddl	Z	ddgZ
G dd� de�Zejdkr6ddl
mZ n
e	�d	�jZd
d� ZG dd� de�ZdS )
a4  This class extends pexpect.spawn to specialize setting up SSH connections.
This adds methods for login, logout, and expecting the shell prompt.
PEXPECT LICENSE
    This license is approved by the OSI and FSF as GPL-compatible.
        http://opensource.org/licenses/isc-license.txt
    Copyright (c) 2012, Noah Spurrier <noah@noah.org>
    PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
    PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
    COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
�    )�ExceptionPexpect�TIMEOUT�EOF�spawnN�ExceptionPxssh�pxsshc                   @   s   e Zd ZdZdS )r   z!Raised for pxssh exceptions.
    N)�__name__�
__module__�__qualname__�__doc__� r   r   �//usr/lib/python3/dist-packages/pexpect/pxssh.pyr       s    )�   r   )�quotez[^\w@%+=:,./-]c                 C   s,   | sdS t | �du r| S d| �dd� d S )z1Return a shell-escaped version of the string *s*.z''N�'z'"'"')�_find_unsafe�replace)�sr   r   r
   r   )   s
   r   c                   @   s�   e Zd ZdZddddddddi ddddf
dd	�Zd
d� Zdd
� Zd!dd�Zddddddddddddi ddddfdd�Zdd� Z	d"dd�Z
dd � ZdS )#r   a&  This class extends pexpect.spawn to specialize setting up SSH
    connections. This adds methods for login, logout, and expecting the shell
    prompt. It does various tricky things to handle many situations in the SSH
    login process. For example, if the session is your first login, then pxssh
    automatically accepts the remote certificate; or if you have public key
    authentication setup then pxssh won't wait for the password prompt.
    pxssh uses the shell prompt to synchronize output from the remote host. In
    order to make this more robust it sets the shell prompt to something more
    unique than just $ or #. This should work on most Borne/Bash or Csh style
    shells.
    Example that runs a few commands on a remote server and prints the result::
        from pexpect import pxssh
        import getpass
        try:
            s = pxssh.pxssh()
            hostname = raw_input('hostname: ')
            username = raw_input('username: ')
            password = getpass.getpass('password: ')
            s.login(hostname, username, password)
            s.sendline('uptime')   # run a command
            s.prompt()             # match the prompt
            print(s.before)        # print everything before the prompt.
            s.sendline('ls -l')
            s.prompt()
            print(s.before)
            s.sendline('df')
            s.prompt()
            print(s.before)
            s.logout()
        except pxssh.ExceptionPxssh as e:
            print("pxssh failed on login.")
            print(e)
    Example showing how to specify SSH options::
        from pexpect import pxssh
        s = pxssh.pxssh(options={
                            "StrictHostKeyChecking": "no",
                            "UserKnownHostsFile": "/dev/null"})
        ...
    Note that if you have ssh-agent running while doing development with pxssh
    then this can lead to a lot of confusion. Many X display managers (xdm,
    gdm, kdm, etc.) will automatically start a GUI agent. You may see a GUI
    dialog box popup asking for a password during development. You should turn
    off any key agents during testing. The 'force_password' attribute will turn
    off public key authentication. This will only work if the remote SSH server
    is configured to allow password logins. Example of using 'force_password'
    attribute::
            s = pxssh.pxssh()
            s.force_password = True
            hostname = raw_input('hostname: ')
            username = raw_input('username: ')
            password = getpass.getpass('password: ')
            s.login (hostname, username, password)
    `debug_command_string` is only for the test suite to confirm that the string
    generated for SSH is correct, using this will not allow you to do
    anything other than get a string back from `pxssh.pxssh.login()`.
    �   i�  NT�strictFc                 C   s`   t j| d |||||||||
||
d�
 d| _d| _| j| _d| _d| _d| _d| _|| _	|	| _
d S )N)�timeout�maxread�searchwindowsize�logfile�cwd�env�
ignore_sighup�echo�encoding�codec_errors�use_pollz<pxssh>z\[PEXPECT\][\$\#] zPS1='[PEXPECT]\$ 'zset prompt='[PEXPECT]\$ 'z5-o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'F)r   �__init__�name�
UNIQUE_PROMPT�PROMPT�
PROMPT_SET_SH�PROMPT_SET_CSH�SSH_OPTS�force_password�debug_command_string�options)�selfr   r   r   r   r   r   r   r   r*   r   r   r)   r    r   r   r
   r!   v   s   �
zpxssh.__init__c                 C   s�   t |�t |�}}||kr||}}||}}t|d �}td|d �D ]D}||gdg|  }}td|d �D ]/}|| d ||d  d }	}
||d  }||d  ||d  kr_|d }t|	|
|�||<