%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/pexpect/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/pexpect/__pycache__/pxssh.cpython-312.pyc

�

��e}_����dZddlmZmZmZmZddlZddlZddlZddl	Z	ddgZ
Gd�de�ZejdkDrddl
mZne	jd	�j Zd
�ZGd�de�Zy)a4This 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��eZdZdZy)rz!Raised for pxssh exceptions.
    N)�__name__�
__module__�__qualname__�__doc__���//usr/lib/python3/dist-packages/pexpect/pxssh.pyrr s��r)�r)�quotez[^\w@%+=:,./-]c�R�|syt|��|Sd|jdd�zdzS)z1Return a shell-escaped version of the string *s*.z''�'z'"'"')�_find_unsafe�replace)�ss rrr)s4������?�"��H��Q�Y�Y�s�I�.�.��4�4rc��eZdZdZddddddddiddddf
d�Zd	�Zd
�Zdd�Zddd
dddddddddiddddfd�Zd�Z	dd�Z
d�Zy)ra&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���tj|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)�selfrrrrr r!r"r#r1r$r%r0r&s              rr'zpxssh.__init__vs���
	���t�T�7�G�(8�'��C�}�4� (�|�h�	X�
��	�3����(�(���3���:���I���8��
�$���$8��!���rc�X�t|�t|�}}||kDr||}}||}}t|dz�}td|dz�D]c}||gdg|zz}}td|dz�D]C}||dz||dz
dz}
}	||dz
}||dz
||dz
k7r|dz}t|	|
|�||<�E�e||S)zBThis calculates the Levenshtein distance between a and b.
        �r)�len�range�min)r2�a�b�n�m�current�i�previous�j�add�delete�changes            r�levenshtein_distancezpxssh.levenshtein_distance�s����1�v�s�1�v�1���q�5��A�a�A��A�a�A���!��*���q��1���	6�A� '�!��a�S��U��g�H��1�Q�q�S�\�
6��&�q�k�!�m�W�Q�q�S�\�!�^�V��!�!�A�#����Q�q�S�6�Q�q��s�V�#�#�a�Z�F� ��f�f�5���
�
6�	6��q�z�rc�
�|dz}|dz}|dz}|j�}tj�}d}|}||kr6	||jd|��z
}tj�|z
}|}||kr�6|S#t$rY|SwxYw)aXThis facilitates using communication timeouts to perform
        synchronization as quickly as possible, while supporting high latency
        connections with a tunable worst case performance. Fast connections
        should be read almost immediately. Worst case performance for this
        method is timeout_multiplier * 3 seconds.
        g�?皙�����?g@gr4)�sizer)�string_type�time�read_nonblockingr)	r2�timeout_multiplier�first_char_timeout�inter_char_timeout�
total_timeout�prompt�begin�expiredrs	         r�try_read_promptzpxssh.try_read_prompt�s���0�#�5��0�#�5��+�S�0�
��!�!�#���	�	�����$���
�%�
��$�/�/�Q��/�H�H���)�)�+��-��,��	�
�%��
���
���
�
�s�/A5�5	B�Bc��|j�tjd�	|j|�|j�|j|�}|j�|j|�}|j�|j|�}|j||�}t
|�}|dk(ryt|�|zdkryy#t$rY��wxYw)a�This attempts to find the prompt. Basically, press enter and record
        the response; press enter again and record the response; if the two
        responses are similar then assume we are at the original prompt.
        This can be a slow function. Worst case with the default sync_multiplier
        can take 12 seconds. Low latency connections are more likely to fail
        with a low sync_multiplier. Best case sync time gets worse with a
        high sync multiplier (500 ms with default). rErFg�������?T)�sendlinerH�sleeprQrrCr5�float)r2�sync_multiplier�xr8r9�ld�len_as       r�sync_original_promptzpxssh.sync_original_prompt�s���	
�
�
���
�
�3��	�� � ��1�	
�
�
��� � ��1���
�
��� � ��1���
�
��� � ��1��
�
&�
&�q��
+���A����A�:����9�U�?�S� ����%�	��	�s�C�	C�C��ansiz[#$]�
r4z((?i)(?:password:)|(?:passphrase for key)�sshc��	�d||
ddtg}g}|j|�|jdtg�dj|jj�D��cgc]\}}d|�d|�d���c}}�}|
r|d	z}|s|d
z}|jr|dz|jz}|�4|r*tjj|�std
��|dz|z}|�|dt|�zz}|	�?|	dk(r|dz}n4|r*tjj|	�std��|d|	zz}|ik7rhtit|��rSdddd�}|D]H}||}||vs�
||}|D]2}|dk(rtt|��}|dz|zdzt|�z}�4�J|�
|dz|z}�n|�t!d��t#|d�5}|j%�D�cgc]}|j'���}}ddd�d|z} d}!d}"d}#D]�}$|"s(t)j*| |$t(j,�rd}"�-|"rd|$j/�vr�B|"rd |$j/�vrd}#n.|"s�]t)j*|!|$t(j,�s��d}#n|r~$~|"st!d!|z��|#st!d"|z��|d|�d|��z
}|j0r|S|rt3j4||�n|j7|�|j9||�#�}%|%d$k(r"|j7d%�|j9|�}%|%d&k(r"|j7|�|j9|�}%|%d'k(r"|j7|�|j9|�}%|%d(k(r|j;�td)��|%d$k(r|j;�td*��|%d+k(rn�|%d&k(r|j;�td,��|%d-k(r|j;�td.��|%d'k(r|j;�td/��|%d0k(rn;|%d1k(r|j;�td2��|j;�td3��|r,|j=|�s|j;�td4��|rF|j?�s6|j;�td5|j@�d6|jB�d7���ycc}}wcc}w#1swY���xYw)8aThis logs the user into the given server.

        It uses 'original_prompt' to try to find the prompt right after login.
        When it finds the prompt it immediately tries to reset the prompt to
        something more easily matched. The default 'original_prompt' is very
        optimistic and is easily fooled. It's more reliable to try to match the original
        prompt as exactly as possible to prevent false matches by server
        strings such as the "Message Of The Day". On many systems you can
        disable the MOTD on the remote server by creating a zero-length file
        called :file:`~/.hushlogin` on the remote server. If a prompt cannot be found
        then this will not necessarily cause the login to fail. In the case of
        a timeout when looking for the prompt we assume that the original
        prompt was so weird that we could not match it, so we use a few tricks
        to guess when we have reached the prompt. Then we hope for the best and
        blindly try to reset the prompt to something more unique. If that fails
        then login() raises an :class:`ExceptionPxssh` exception.

        In some situations it is not possible or desirable to reset the
        original prompt. In this case, pass ``auto_prompt_reset=False`` to
        inhibit setting the prompt to the UNIQUE_PROMPT. Remember that pxssh
        uses a unique prompt in the :meth:`prompt` method. If the original prompt is
        not reset then this will disable the :meth:`prompt` method unless you
        manually set the :attr:`PROMPT` attribute.

        Set ``password_regex`` if there is a MOTD message with `password` in it.
        Changing this is like playing in traffic, don't (p)expect it to match straight
        away.

        If you require to connect to another SSH server from the your original SSH
        connection set ``spawn_local_ssh`` to `False` and this will use your current
        session to do so. Setting this option to `False` and not having an active session
        will trigger an error.

        Set ``ssh_key`` to a file path to an SSH private key to use that SSH key
        for the session authentication.
        Set ``ssh_key`` to `True` to force passing the current SSH authentication socket
        to the desired ``hostname``.

        Set ``ssh_config`` to a file path string of an SSH client config file to pass that
        file to the client to handle itself. You may set any options you wish in here, however
        doing so will require you to post extra information that you may not want to if you
        run into issues.

        Alter the ``cmd`` to change the ssh client used, or to prepend it with network
        namespaces. For example ```cmd="ip netns exec vlan2 ssh"``` to execute the ssh in
        network namespace named ```vlan```.
        z0(?i)are you sure you want to continue connectingz(?i)permission deniedz(?i)terminal typez$(?i)connection closed by remote hostr[z -o '�=rz -qz) -o'NoHostAuthenticationForLocalhost=yes'� Nz+SSH config does not exist or is not a file.z -F z -p %sTz -Az0private ssh key does not exist or is not a file.z -i %s�L�R�D)�local�remote�dynamicFz -z -l z0login() needs either a username or an ssh_config�rtz^Host\s+%s\s*$z^User\s+\w+\s*$�hostname�hostz+login() ssh_config has no Host entry for %sz+login() ssh_config has no user entry for %s�rr�yes���z&Could not establish connection to hostz-Weird error. Got "are you sure" prompt twice.r4zpassword refusedrzpermission deniedz.Weird error. Got "terminal type" prompt twice.��zconnection closedzunexpected login responsez*could not synchronize with original promptz&could not set shell prompt (received: z, expected: z).)"r�extendr�joinr1�itemsr/r.�os�path�isfiler�str�
isinstance�typer�	TypeError�open�	readlines�strip�re�match�
IGNORECASE�lowerr0r�_spawnrS�expect�closerZ�set_unique_prompt�beforer*)&r2�server�username�password�
terminal_type�original_prompt�
login_timeout�port�auto_prompt_reset�ssh_key�quietrV�check_local_ip�password_regex�ssh_tunnels�spawn_local_sshrZ�
ssh_config�cmd�session_regex_array�session_init_regex_array�o�v�ssh_options�tunnel_types�tunnel_type�cmd_type�tunnels�tunnel�f�l�lines�server_regex�
user_regex�config_has_server�server_has_username�liner=s&                                      r�loginzpxssh.logins��n R�Sb�dr�uL�Na�cj�k��#%� � �'�'�(;�<� �'�'�)O�QT�(U�V��g�g�D�L�L�DV�DV�DX�Y�&�1�a��1�5�Y�Z���%��-�K��%�(S�S�K����%��+�d�m�m�;�K��!��r�w�w�~�~�j�'A�$�%R�S�S�%��.��;�K���%��#�d�)�(<�<�K�����}�)�E�1��"�2�7�7�>�>�'�+B�(�)[�\�\�)�H��,@�@����?�z�"�T�+�->�?�����L�
 ,�
X��'��4���+�-�)�+�6�G�")�X��*�E�1�%*�3�v�;�%7�F�&1�D�&8�8�&C�c�&I�C�PV�K�&W��X�	
X���%��.��9�K�
�
��N�O�O��j�$�'�
;�1�,-�K�K�M�:�q�����:��:�
;�-�v�5�L�+�J� %��"'���

��(�R�X�X�l�D�"�-�-�-X�(,�%�&�:�����+E��&�6�T�Z�Z�\�+A�*/�'��&�2�8�8�J��b�m�m�+T�*.�'��

����$�� M�PV� V�W�W�(�� M�PV� V�W�W��;��/�/���$�$��K���L�L��s�#��M�M�#��
�K�K�0�-�K�H��
�a�4�
�M�M�%� ����/�0�A��a�4��M�M�(�#����/�0�A��a�4��M�M�-�(����/�0�A��a�4��J�J�L� �!I�J�J�
�a�4��J�J�L� �!P�Q�Q�
��T��
��T�

�J�J�L� �!3�4�4�
��T��J�J�L� �!4�5�5�
��T��J�J�L� �!Q�R�R�
��T�
�
��T��J�J�L� �!4�5�5��J�J�L� �!<�=�=���,�,�_�=��
�
��$�%Q�R�R���)�)�+��
�
��$�)-���d�k�k�&D�E�E���{Z��f;�
;�
;�s$�S
�S#�S�,S#�S#�#S-c���|jd�|jtdg�}|dk(r&|jd�|jt�|j�y)zuSends exit to the remote shell.

        If there are stopped jobs then this automatically sends exit twice.
        �exitz(?i)there are stopped jobsr4N)rSr�rr�)r2�indexs  r�logoutzpxssh.logout�sL��
	
�
�
�f�����S�">�?�@���!�8��M�M�&�!��K�K����
�
�rc�x�|dk(r|j}|j|jtg|��}|dk(ryy)a�Match the next shell prompt.

        This is little more than a short-cut to the :meth:`~pexpect.spawn.expect`
        method. Note that if you called :meth:`login` with
        ``auto_prompt_reset=False``, then before calling :meth:`prompt` you must
        set the :attr:`PROMPT` attribute to a regex that it will use for
        matching the prompt.

        Calling :meth:`prompt` will erase the contents of the :attr:`before`
        attribute even if no prompt is ever matched. If timeout is not given or
        it is set to -1 then self.timeout is used.

        :return: True if the shell prompt was matched, False if the timeout was
                 reached.
        ���rkr4FT)rr�r*r)r2rr=s   rrNzpxssh.prompt�s<��"�b�=��l�l�G��K�K����g�.��K�@���a�4��rc��|jd�|j|j�|jt|jgd��}|dk(r�|j|j
�|jt|jgd��}|dk(rD|j|j�|jt|jgd��}|dk(ryy)a}This sets the remote prompt to something more unique than ``#`` or ``$``.
        This makes it easier for the :meth:`prompt` method to match the shell prompt
        unambiguously. This method is called automatically by the :meth:`login`
        method, but you may want to call it manually if you somehow reset the
        shell prompt. For example, if you 'su' to a different user then you
        will need to manually reset the prompt. This sends shell commands to
        the remote host to set the prompt, so this assumes the remote host is
        ready to receive commands.

        Alternatively, you may use your own prompt pattern. In this case you
        should call :meth:`login` with ``auto_prompt_reset=False``; then set the
        :attr:`PROMPT` attribute to a regular expression. After that, the
        :meth:`prompt` method will try to match your prompt pattern.
        zunset PROMPT_COMMANDr]rkrFT)rSr+r�rr*r,r-)r2r=s  rr�zpxssh.set_unique_prompt�s��� 	
�
�
�,�-��
�
�d�(�(�)��K�K�'�4�;�;�/��K�<����6��M�M�$�-�-�.����W�d�k�k�2�B��?�A��A�v��
�
�d�1�1�2��K�K��$�+�+� 6��K�C����6� �r)g�?)r�)r
rrr
r'rCrQrZr�r�rNr�rrrrr4s���?�B!#�D�4� �d��D�t���H�).��,�\�&�@$�R'+�R�v� '�r��"&��D� !�$�J���%)�d��
Y�v
��0r)r
�pexpectrrrrrHru�sysr�__all__r�version_info�shlexr�compile�searchrrrrr�<module>r�sr���,:�9��	�
�	��W�
%���%�����f����2�:�:�/�0�7�7�L�	5�f�U�fr

Zerion Mini Shell 1.0