%PDF- %PDF-
Direktori : /lib/python3/dist-packages/pexpect/__pycache__/ |
Current File : //lib/python3/dist-packages/pexpect/__pycache__/pxssh.cpython-312.pyc |
� ��e}_ � �� � d Z ddlmZmZmZmZ ddlZddlZddlZddl Z ddgZ G d� de� Zej dkD rddl mZ n e j d � j Zd � Z G d� de� Zy)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 � � e Zd ZdZy)r z!Raised for pxssh exceptions. N)�__name__� __module__�__qualname__�__doc__� � �//usr/lib/python3/dist-packages/pexpect/pxssh.pyr r s � �r )� r )�quotez[^\w@%+=:,./-]c �R � | syt | � �| S d| j dd� z dz S )z1Return a shell-escaped version of the string *s*.z''�'z'"'"')�_find_unsafe�replace)�ss r r r ) s4 � �����?�"��H� �Q�Y�Y�s�I�.�.��4�4r c � � e Zd ZdZddddddddi ddddf d�Zd � Zd � Zdd�Zddd dddddddddi ddddfd�Zd� Z dd�Z d� Zy)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 �� � t j | d ||||||||| || �� d| _ d| _ | j | _ d| _ d| _ d| _ d| _ d| _ || _ | | _ y ) N)�timeout�maxread�searchwindowsize�logfile�cwd�env� ignore_sighup�echo�encoding�codec_errors�use_pollz<pxssh>z\[PEXPECT\][\$\#] zPS1='[PEXPECT]\$ 'zset prompt='[PEXPECT]\$ 'z(prompt restore; PS1='[PEXPECT]%(!.#.$) 'z -o 'PubkeyAuthentication=no'F)r �__init__�name� UNIQUE_PROMPT�PROMPT� PROMPT_SET_SH�PROMPT_SET_CSH�PROMPT_SET_ZSH�SSH_OPTS�force_password�debug_command_string�options)�selfr r r r r r! r"