%PDF- %PDF-
Mini Shell

Mini Shell

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

�

�ec����.�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlm Z ddl!m"Z"d
�Z#Gd�de"�Z$Gd�de�Z%Gd�de%�Z&Gd�de%�Z'y)z"
Abstraction for an SSH2 channel.
�N��wraps)�util)
�cMSG_CHANNEL_REQUEST�cMSG_CHANNEL_WINDOW_ADJUST�cMSG_CHANNEL_DATA�cMSG_CHANNEL_EXTENDED_DATA�DEBUG�ERROR�cMSG_CHANNEL_SUCCESS�cMSG_CHANNEL_FAILURE�cMSG_CHANNEL_EOF�cMSG_CHANNEL_CLOSE)�Message)�bytes_types)�SSHException)�BufferedFile)�BufferedPipe�PipeTimeout)�pipe)�ClosingContextManagerc�.��t���fd��}|S)z�
    Decorator for `.Channel` methods which performs an openness check.

    :raises:
        `.SSHException` -- If the wrapped method is called on an unopened
        `.Channel`.
    c���|js$|js|js|jst	d���|g|��i|��S)NzChannel is not open)�closed�eof_received�eof_sent�activer)�self�args�kwds�funcs   ��2/usr/lib/python3/dist-packages/paramiko/channel.py�_checkzopen_only.<locals>._check?sD���
�K�K�� � ��}�}��;�;��4�5�5��D�(�4�(�4�(�(�r)r!r#s` r"�	open_onlyr%6s"����4�[�)��)��Mr$c��eZdZdZd�Zd�Zd�Ze					dBd��Zed��Z	ed��Z
ed��ZedCd	��Zed
��Z
ed��Zd�Zd
�Zd�Ze					dDd��Zed��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-e.d,��Z/d-�Z0d.�Z1d/�Z2d0�Z3d1�Z4d2�Z5d3�Z6d4�Z7d5�Z8d6�Z9d7�Z:d8�Z;d9�Z<d:�Z=d;�Z>d<�Z?d=�Z@d>�ZAd?�ZBd@�ZCdA�ZDy)E�Channela
    A secure tunnel across an SSH `.Transport`.  A Channel is meant to behave
    like a socket, and has an API that should be indistinguishable from the
    Python socket API.

    Because SSH2 has a windowing kind of flow control, if you stop reading data
    from a Channel and its buffer fills up, the server will be unable to send
    you any more data until you read some of it.  (This won't affect other
    channels on the same transport -- all channels on a single transport are
    flow-controlled independently.)  Similarly, if the server isn't reading
    data you send, calls to `send` may block, unless you set a timeout.  This
    is exactly like a normal network socket, so it shouldn't be too surprising.

    Instances of this class may be used as context managers.
    c��||_d|_d|_d|_d|_d|_t
�|_t
�|_d|_	d|_
d|_tj�|_tj|j�|_d|_d|_d|_d|_d|_d|_tj.�|_t3|�|_t7j8d�|_d|_tj.�|_d|_ d|_!d|_"d|_#y)am
        Create a new channel.  The channel is not associated with any
        particular session or `.Transport` until the Transport attaches it.
        Normally you would only call this method from the constructor of a
        subclass of `.Channel`.

        :param int chanid:
            the ID of this channel, as passed by an existing `.Transport`.
        rNFzparamiko.transport���)$�chanid�
remote_chanid�	transportrrrr�	in_buffer�in_stderr_buffer�timeoutr�ultra_debug�	threading�Lock�lock�	Condition�
out_buffer_cv�in_window_size�out_window_size�in_max_packet_size�out_max_packet_size�in_window_threshold�in_window_sofar�Event�status_event�str�_namer�
get_logger�logger�_pipe�event�event_ready�combine_stderr�exit_status�origin_addr)rr*s  r"�__init__zChannel.__init__^s�������������������
�%���� ,���������� ����N�N�$��	�&�0�0����;������ ���"#���#$�� �#$�� � ���%�O�O�-�����[��
��o�o�&:�;�����
��_�_�&��
� ���#��������r$c�4�	|j�y#YyxYw�N)�close�rs r"�__del__zChannel.__del__�s��	��J�J�L��	��s��c��dj|j�}|jr|dz
}n�|jr|jr|dz
}|j
r|dz
}|dj|j�z
}t|j�dkDr'|djt|j��z
}|dt|j�zz
}|d	z
}|S)
zO
        Return a string representation of this object, for debugging.
        z<paramiko.Channel {}z	 (closed)z (EOF received)z (EOF sent)z (open) window={}rz
 in-buffer={}z -> �>)�formatr*rrrrr7�lenr-�reprr,)r�outs  r"�__repr__zChannel.__repr__�s���%�+�+�D�K�K�8���;�;��;��C�
�[�[�� � ��(�(���}�}��}�$���&�-�-�d�.B�.B�C�C�C��4�>�>�"�Q�&���-�-�c�$�.�.�.A�B�B���v��T�^�^�,�,�,���s�
���
r$c��t�}|jt�|j|j�|jd�|j
d�|j|�|j|�|j|�|j|�|j|�|jt��|j�|jj|�|j�y)ak
        Request a pseudo-terminal from the server.  This is usually used right
        after creating a client channel, to ask the server to provide some
        basic terminal semantics for a shell invoked with `invoke_shell`.
        It isn't necessary (or desirable) to call this method if you're going
        to execute a single command with `exec_command`.

        :param str term: the terminal type to emulate
            (for example, ``'vt100'``)
        :param int width: width (in characters) of the terminal screen
        :param int height: height (in characters) of the terminal screen
        :param int width_pixels: width (in pixels) of the terminal screen
        :param int height_pixels: height (in pixels) of the terminal screen

        :raises:
            `.SSHException` -- if the request was rejected or the channel was
            closed
        �pty-reqTN)r�add_byter�add_intr+�
add_string�add_boolean�bytes�_event_pendingr,�_send_user_message�_wait_for_event)r�term�width�height�width_pixels�
height_pixels�ms       r"�get_ptyzChannel.get_pty�s���6
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���Y��	�
�
�d��	���T��	�	�	�%��	�	�	�&��	�	�	�,��	�	�	�-� �	���U�W���������)�)�!�,����r$c�2�t�}|jt�|j|j�|jd�|j
d�|j�|jj|�|j�y)a�
        Request an interactive shell session on this channel.  If the server
        allows it, the channel will then be directly connected to the stdin,
        stdout, and stderr of the shell.

        Normally you would call `get_pty` before this, in which case the
        shell will operate through the pty, and the channel will be connected
        to the stdin and stdout of the pty.

        When the shell exits, the channel will be closed and can't be reused.
        You must open a new channel if you wish to open another shell.

        :raises:
            `.SSHException` -- if the request was rejected or the channel was
            closed
        �shellTN�rrWrrXr+rYrZr\r,r]r^�rrds  r"�invoke_shellzChannel.invoke_shell�sl��$
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���W��	�
�
�d���������)�)�!�,����r$c�T�t�}|jt�|j|j�|jd�|j
d�|j|�|j�|jj|�|j�y)a'
        Execute a command on the server.  If the server allows it, the channel
        will then be directly connected to the stdin, stdout, and stderr of
        the command being executed.

        When the command finishes executing, the channel will be closed and
        can't be reused.  You must open a new channel if you wish to execute
        another command.

        :param str command: a shell command to execute.

        :raises:
            `.SSHException` -- if the request was rejected or the channel was
            closed
        �execTNrh)r�commandrds   r"�exec_commandzChannel.exec_command�sx��"
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���V��	�
�
�d��	���W���������)�)�!�,����r$c�T�t�}|jt�|j|j�|jd�|j
d�|j|�|j�|jj|�|j�y)a�
        Request a subsystem on the server (for example, ``sftp``).  If the
        server allows it, the channel will then be directly connected to the
        requested subsystem.

        When the subsystem finishes, the channel will be closed and can't be
        reused.

        :param str subsystem: name of the subsystem being requested.

        :raises:
            `.SSHException` -- if the request was rejected or the channel was
            closed
        �	subsystemTNrh)rrprds   r"�invoke_subsystemzChannel.invoke_subsystemsx�� 
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���[�!�	�
�
�d��	���Y���������)�)�!�,����r$c�z�t�}|jt�|j|j�|jd�|j
d�|j|�|j|�|j|�|j|�|jj|�y)aP
        Resize the pseudo-terminal.  This can be used to change the width and
        height of the terminal emulation created in a previous `get_pty` call.

        :param int width: new width (in characters) of the terminal screen
        :param int height: new height (in characters) of the terminal screen
        :param int width_pixels: new width (in pixels) of the terminal screen
        :param int height_pixels: new height (in pixels) of the terminal screen

        :raises:
            `.SSHException` -- if the request was rejected or the channel was
            closed
        �
window-changeFN�	rrWrrXr+rYrZr,r])rr`rarbrcrds      r"�
resize_ptyzChannel.resize_ptys���
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���_�%�	�
�
�e��	�	�	�%��	�	�	�&��	�	�	�,��	�	�	�-� ����)�)�!�,r$c��|j�D]\}}	|j||��y#t$r"}d}t|j|�|��d}~wwxYw)a�
        Updates this channel's remote shell environment.

        .. note::
            This operation is additive - i.e. the current environment is not
            reset before the given environment variables are set.

        .. warning::
            Servers may silently reject some environment variables; see the
            warning in `set_environment_variable` for details.

        :param dict environment:
            a dictionary containing the name and respective values to set
        :raises:
            `.SSHException` -- if any of the environment variables was rejected
            by the server or the channel was closed
        z(Failed to set environment variable "{}".N)�items�set_environment_variablerrP)r�environment�name�value�e�errs      r"�update_environmentzChannel.update_environment7sb��&'�,�,�.�	8�K�D�%�
8��-�-�d�E�:�	8�� �
8�@��"�3�:�:�d�#3�Q�7�7��
8�s�-�	A�A�Ac�6�t�}|jt�|j|j�|jd�|j
d�|j|�|j|�|jj|�y)a`
        Set the value of an environment variable.

        .. warning::
            The server may reject this request depending on its ``AcceptEnv``
            setting; such rejections will fail silently (which is common client
            practice for this particular request type). Make sure you
            understand your server's configuration before using!

        :param str name: name of the environment variable
        :param str value: value of the environment variable

        :raises:
            `.SSHException` -- if the request was rejected or the channel was
            closed
        �envFNrt)rrzr{rds    r"rxz Channel.set_environment_variableQsl��$
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���U��	�
�
�e��	���T��	���U�����)�)�!�,r$c�R�|jxs|jj�S)a�
        Return true if the remote process has exited and returned an exit
        status. You may use this to poll the process status if you don't
        want to block in `recv_exit_status`. Note that the server may not
        return an exit status in some cases (like bad servers).

        :return:
            ``True`` if `recv_exit_status` will return immediately, else
            ``False``.

        .. versionadded:: 1.7.3
        )rr=�is_setrLs r"�exit_status_readyzChannel.exit_status_readyls"���{�{�8�d�/�/�6�6�8�8r$c��|jj�|jj�sJ�|jS)a3
        Return the exit status from the process on the server.  This is
        mostly useful for retrieving the results of an `exec_command`.
        If the command hasn't finished yet, this method will wait until
        it does, or until the channel is closed.  If no exit status is
        provided by the server, -1 is returned.

        .. warning::
            In some situations, receiving remote output larger than the current
            `.Transport` or session's ``window_size`` (e.g. that set by the
            ``default_window_size`` kwarg for `.Transport.__init__`) will cause
            `.recv_exit_status` to hang indefinitely if it is called prior to a
            sufficiently large `.Channel.recv` (or if there are no threads
            calling `.Channel.recv` in the background).

            In these cases, ensuring that `.recv_exit_status` is called *after*
            `.Channel.recv` (or, again, using threads) can avoid the hang.

        :return: the exit code (as an `int`) of the process on the server.

        .. versionadded:: 1.2
        )r=�waitr�rFrLs r"�recv_exit_statuszChannel.recv_exit_status{s:��.	
����� �� � �'�'�)�)�)����r$c��t�}|jt�|j|j�|jd�|j
d�|j|�|jj|�y)aS
        Send the exit status of an executed command to the client.  (This
        really only makes sense in server mode.)  Many clients expect to
        get some sort of status code back from an executed command after
        it completes.

        :param int status: the exit code of the process

        .. versionadded:: 1.2
        �exit-statusFNrt)r�statusrds   r"�send_exit_statuszChannel.send_exit_status�s`��
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���]�#�	�
�
�e��	�	�	�&�����)�)�!�,r$Nc�N�|�d}|�(tjtjd��}t	�}|jt�|j|j�|jd�|jd�|j|�|j|�|j|�|j|�|j�|jj|�|j�|jj|�|S)aM
        Request an x11 session on this channel.  If the server allows it,
        further x11 requests can be made from the server to the client,
        when an x11 application is run in a shell session.

        From :rfc:`4254`::

            It is RECOMMENDED that the 'x11 authentication cookie' that is
            sent be a fake, random cookie, and that the cookie be checked and
            replaced by the real cookie when a connection request is received.

        If you omit the auth_cookie, a new secure random 128-bit value will be
        generated, used, and returned.  You will need to use this value to
        verify incoming x11 requests and replace them with the actual local
        x11 cookie (which requires some knowledge of the x11 protocol).

        If a handler is passed in, the handler is called from another thread
        whenever a new x11 connection arrives.  The default handler queues up
        incoming x11 connections, which may be retrieved using
        `.Transport.accept`.  The handler's calling signature is::

            handler(channel: Channel, (address: str, port: int))

        :param int screen_number: the x11 screen number (0, 10, etc.)
        :param str auth_protocol:
            the name of the X11 authentication method used; if none is given,
            ``"MIT-MAGIC-COOKIE-1"`` is used
        :param str auth_cookie:
            hexadecimal string containing the x11 auth cookie; if none is
            given, a secure random 128-bit value is generated
        :param bool single_connection:
            if True, only a single x11 connection will be forwarded (by
            default, any number of x11 connections can arrive over this
            session)
        :param handler:
            an optional callable handler to use for incoming X11 connections
        :return: the auth_cookie used
        zMIT-MAGIC-COOKIE-1��x11-reqT)�binascii�hexlify�os�urandomrrWrrXr+rYrZr\r,r]r^�_set_x11_handler)r�
screen_number�
auth_protocol�auth_cookie�single_connection�handlerrds       r"�request_x11zChannel.request_x11�s���^� �0�M���"�*�*�2�:�:�b�>�:�K��I��	�
�
�'�(�	�	�	�$�$�$�%�	���Y��	�
�
�d��	�
�
�'�(�	���]�#�	���[�!�	�	�	�-� ��������)�)�!�,��������'�'��0��r$c�(�t�}|jt�|j|j�|jd�|j
d�|jj|�|jj|�y)a�
        Request for a forward SSH Agent on this channel.
        This is only valid for an ssh-agent from OpenSSH !!!

        :param handler:
            a required callable handler to use for incoming SSH Agent
            connections

        :return: True if we are ok, else False
            (at that time we always return ok)

        :raises: SSHException in case of channel problem.
        �auth-agent-req@openssh.comFT)
rrWrrXr+rYrZr,r]�_set_forward_agent_handler)rr�rds   r"�request_forward_agentzChannel.request_forward_agent�sj��
�I��	�
�
�'�(�	�	�	�$�$�$�%�	���1�2�	�
�
�e�����)�)�!�,����1�1�'�:�r$c��|jS)zG
        Return the `.Transport` associated with this channel.
        )r,rLs r"�
get_transportzChannel.get_transports���~�~�r$c��||_y)z�
        Set a name for this channel.  Currently it's only used to set the name
        of the channel in logfile entries.  The name can be fetched with the
        `get_name` method.

        :param str name: new channel name
        N�r?)rrzs  r"�set_namezChannel.set_names����
r$c��|jS)zU
        Get the name of this channel that was previously set by `set_name`.
        r�rLs r"�get_namezChannel.get_names���z�z�r$c��|jS)a3
        Return the `int` ID # for this channel.

        The channel ID is unique across a `.Transport` and usually a small
        number.  It's also the number passed to
        `.ServerInterface.check_channel_request` when determining whether to
        accept a channel request in server mode.
        )r*rLs r"�get_idzChannel.get_ids���{�{�r$c�b�t�}|jj�	|j}||_|r|s|jj�}|jj
�t|�dkDr|j|�|S#|jj
�wxYw)a
        Set whether stderr should be combined into stdout on this channel.
        The default is ``False``, but in some cases it may be convenient to
        have both streams combined.

        If this is ``False``, and `exec_command` is called (or ``invoke_shell``
        with no pty), output to stderr will not show up through the `recv`
        and `recv_ready` calls.  You will have to use `recv_stderr` and
        `recv_stderr_ready` to get stderr output.

        If this is ``True``, data will never show up via `recv_stderr` or
        `recv_stderr_ready`.

        :param bool combine:
            ``True`` if stderr output should be combined into stdout on this
            channel.
        :return: the previous setting (a `bool`).

        .. versionadded:: 1.1
        r)	r[r3�acquirerEr.�empty�releaserQ�_feed)r�combine�data�olds    r"�set_combine_stderrzChannel.set_combine_stderr's���*�w���	�	����	 ��%�%�C�")�D���s��,�,�2�2�4���I�I�����t�9�q�=��J�J�t���
��
�I�I����s�1B�B.c��||_y)a�
        Set a timeout on blocking read/write operations.  The ``timeout``
        argument can be a nonnegative float expressing seconds, or ``None``.
        If a float is given, subsequent channel read/write operations will
        raise a timeout exception if the timeout period value has elapsed
        before the operation has completed.  Setting a timeout of ``None``
        disables timeouts on socket operations.

        ``chan.settimeout(0.0)`` is equivalent to ``chan.setblocking(0)``;
        ``chan.settimeout(None)`` is equivalent to ``chan.setblocking(1)``.

        :param float timeout:
            seconds to wait for a pending read/write operation before raising
            ``socket.timeout``, or ``None`` for no timeout.
        N�r/)rr/s  r"�
settimeoutzChannel.settimeoutLs�� ��r$c��|jS)z�
        Returns the timeout in seconds (as a float) associated with socket
        operations, or ``None`` if no timeout is set.  This reflects the last
        call to `setblocking` or `settimeout`.
        r�rLs r"�
gettimeoutzChannel.gettimeout^s���|�|�r$c�N�|r|jd�y|jd�y)aZ
        Set blocking or non-blocking mode of the channel: if ``blocking`` is 0,
        the channel is set to non-blocking mode; otherwise it's set to blocking
        mode. Initially all channels are in blocking mode.

        In non-blocking mode, if a `recv` call doesn't find any data, or if a
        `send` call can't immediately dispose of the data, an error exception
        is raised. In blocking mode, the calls block until they can proceed. An
        EOF condition is considered "immediate data" for `recv`, so if the
        channel is closed in the read direction, it will never block.

        ``chan.setblocking(0)`` is equivalent to ``chan.settimeout(0)``;
        ``chan.setblocking(1)`` is equivalent to ``chan.settimeout(None)``.

        :param int blocking:
            0 to set non-blocking mode; non-0 to set blocking mode.
        N�)r�)r�blockings  r"�setblockingzChannel.setblockingfs��$��O�O�D�!��O�O�C� r$c�6�|jj�S)a
        Return the address of the remote side of this Channel, if possible.

        This simply wraps `.Transport.getpeername`, used to provide enough of a
        socket-like interface to allow asyncore to work. (asyncore likes to
        call ``'getpeername'``.)
        )r,�getpeernamerLs r"r�zChannel.getpeername}s���~�~�)�)�+�+r$c���|jj�	|j�!|jj�d|_|jr|j
r	|jj
�y|j�}|jj
�|D] }|��|jj|��"y#|jj
�wxYw)a+
        Close the channel.  All future read/write operations on the channel
        will fail.  The remote end will receive no more data (after queued data
        is flushed).  Channels are automatically closed when their `.Transport`
        is closed or when they are garbage collected.
        N)
r3r�rBrKrrr��_close_internalr,r])r�msgsrds   r"rKz
Channel.close�s���	
�	�	����
	 �
�z�z�%��
�
� � �"�!��
��;�;�$�+�+��
�I�I�����'�'�)�D��I�I�����	5�A��}����1�1�!�4�	5��
�I�I����s�AC
�=C
�
C)c�6�|jj�S)av
        Returns true if data is buffered and ready to be read from this
        channel.  A ``False`` result does not mean that the channel has closed;
        it means you may need to wait before more data arrives.

        :return:
            ``True`` if a `recv` call on this channel would immediately return
            at least one byte; ``False`` otherwise.
        )r-�
read_readyrLs r"�
recv_readyzChannel.recv_ready�s���~�~�(�(�*�*r$c��	|jj||j�}|jt
|��}|dkDrft�}|jt�|j|j�|j|�|jj|�|S#t$rt	j��wxYw)a�
        Receive data from the channel.  The return value is a string
        representing the data received.  The maximum amount of data to be
        received at once is specified by ``nbytes``.  If a string of
        length zero is returned, the channel stream has closed.

        :param int nbytes: maximum number of bytes to read.
        :return: received data, as a ``str``/``bytes``.

        :raises socket.timeout:
            if no data is ready before the timeout set by `settimeout`.
        r)r-�readr/r�socket�_check_add_windowrQrrWrrXr+r,r]�r�nbytesrS�ackrds     r"�recvzChannel.recv�s���	#��.�.�%�%�f�d�l�l�;�C��$�$�S��X�.����7��	�A�
�J�J�1�2�
�I�I�d�(�(�)�
�I�I�c�N��N�N�-�-�a�0��
���	#��.�.�"�"�	#���&B/�/C
c�6�|jj�S)a�
        Returns true if data is buffered and ready to be read from this
        channel's stderr stream.  Only channels using `exec_command` or
        `invoke_shell` without a pty will ever have data on the stderr
        stream.

        :return:
            ``True`` if a `recv_stderr` call on this channel would immediately
            return at least one byte; ``False`` otherwise.

        .. versionadded:: 1.1
        )r.r�rLs r"�recv_stderr_readyzChannel.recv_stderr_ready�s���$�$�/�/�1�1r$c��	|jj||j�}|jt
|��}|dkDrft�}|jt�|j|j�|j|�|jj|�|S#t$rt	j��wxYw)a�
        Receive data from the channel's stderr stream.  Only channels using
        `exec_command` or `invoke_shell` without a pty will ever have data
        on the stderr stream.  The return value is a string representing the
        data received.  The maximum amount of data to be received at once is
        specified by ``nbytes``.  If a string of length zero is returned, the
        channel stream has closed.

        :param int nbytes: maximum number of bytes to read.
        :return: received data as a `str`

        :raises socket.timeout: if no data is ready before the timeout set by
            `settimeout`.

        .. versionadded:: 1.1
        r)r.r�r/rr�r�rQrrWrrXr+r,r]r�s     r"�recv_stderrzChannel.recv_stderr�s���"	#��'�'�,�,�V�T�\�\�B�C��$�$�S��X�.����7��	�A�
�J�J�1�2�
�I�I�d�(�(�)�
�I�I�c�N��N�N�-�-�a�0��
���	#��.�.�"�"�	#�r�c�0�|jj�	|js|jr	|jj	�y|j
dkD|jj	�S#|jj	�wxYw)a#
        Returns true if data can be written to this channel without blocking.
        This means the channel is either closed (so any write attempt would
        return immediately) or there is at least one byte of space in the
        outbound buffer. If there is at least one byte of space in the
        outbound buffer, a `send` call will succeed immediately and return
        the number of bytes actually written.

        :return:
            ``True`` if a `send` call on this channel would immediately succeed
            or fail
        Tr)r3r�rrr�r7rLs r"�
send_readyzChannel.send_ready�sl��	
�	�	����	 ��{�{�d�m�m��
�I�I�����'�'�!�+��I�I�����D�I�I����s�A9�A9�9Bc��t�}|jt�|j|j�|j||�S)a
        Send data to the channel.  Returns the number of bytes sent, or 0 if
        the channel stream is closed.  Applications are responsible for
        checking that all data has been sent: if only some of the data was
        transmitted, the application needs to attempt delivery of the remaining
        data.

        :param str s: data to send
        :return: number of bytes actually sent, as an `int`

        :raises socket.timeout: if no data could be sent before the timeout set
            by `settimeout`.
        )rrWrrXr+�_send�r�srds   r"�sendzChannel.sends;��
�I��	�
�
�$�%�	�	�	�$�$�$�%��z�z�!�Q��r$c��t�}|jt�|j|j�|jd�|j||�S)a�
        Send data to the channel on the "stderr" stream.  This is normally
        only used by servers to send output from shell commands -- clients
        won't use this.  Returns the number of bytes sent, or 0 if the channel
        stream is closed.  Applications are responsible for checking that all
        data has been sent: if only some of the data was transmitted, the
        application needs to attempt delivery of the remaining data.

        :param str s: data to send.
        :return: number of bytes actually sent, as an `int`.

        :raises socket.timeout:
            if no data could be sent before the timeout set by `settimeout`.

        .. versionadded:: 1.1
        �)rrWr	rXr+r�r�s   r"�send_stderrzChannel.send_stderr#sF��$
�I��	�
�
�-�.�	�	�	�$�$�$�%�	�	�	�!���z�z�!�Q��r$c�:�|r|j|�}||d}|r�y)a�
        Send data to the channel, without allowing partial results.  Unlike
        `send`, this method continues to send data from the given string until
        either all data has been sent or an error occurs.  Nothing is returned.

        :param str s: data to send.

        :raises socket.timeout:
            if sending stalled for longer than the timeout set by `settimeout`.
        :raises socket.error:
            if an error occurred before the entire string was sent.

        .. note::
            If the channel is closed while only part of the data has been
            sent, there is no way to determine how much data (if any) was sent.
            This is irritating, but identically follows Python's API.
        N)r��rr��sents   r"�sendallzChannel.sendall;s)��$��9�9�Q�<�D��$�%��A��r$c�:�|r|j|�}||d}|r�y)aE
        Send data to the channel's "stderr" stream, without allowing partial
        results.  Unlike `send_stderr`, this method continues to send data
        from the given string until all data has been sent or an error occurs.
        Nothing is returned.

        :param str s: data to send to the client as "stderr" output.

        :raises socket.timeout:
            if sending stalled for longer than the timeout set by `settimeout`.
        :raises socket.error:
            if an error occurred before the entire string was sent.

        .. versionadded:: 1.1
        N)r�r�s   r"�sendall_stderrzChannel.sendall_stderrRs,�� ��#�#�A�&�D��$�%��A��r$c�,�t|gt|�z�S)a(
        Return a file-like object associated with this channel.  The optional
        ``mode`` and ``bufsize`` arguments are interpreted the same way as by
        the built-in ``file()`` function in Python.

        :return: `.ChannelFile` object which can be used for Python file I/O.
        )�ChannelFile�list�r�paramss  r"�makefilezChannel.makefilegs���d�V�d�6�l�2�4�4r$c�,�t|gt|�z�S)a}
        Return a file-like object associated with this channel's stderr
        stream.   Only channels using `exec_command` or `invoke_shell`
        without a pty will ever have data on the stderr stream.

        The optional ``mode`` and ``bufsize`` arguments are interpreted the
        same way as by the built-in ``file()`` function in Python.  For a
        client, it only makes sense to open this file for reading.  For a
        server, it only makes sense to open this file for writing.

        :returns:
            `.ChannelStderrFile` object which can be used for Python file I/O.

        .. versionadded:: 1.1
        )�ChannelStderrFiler�r�s  r"�makefile_stderrzChannel.makefile_stderrqs�� !�D�6�D��L�#8�:�:r$c�,�t|gt|�z�S)a
        Return a file-like object associated with this channel's stdin
        stream.

        The optional ``mode`` and ``bufsize`` arguments are interpreted the
        same way as by the built-in ``file()`` function in Python.  For a
        client, it only makes sense to open this file for writing.  For a
        server, it only makes sense to open this file for reading.

        :returns:
            `.ChannelStdinFile` object which can be used for Python file I/O.

        .. versionadded:: 2.6
        )�ChannelStdinFiler�r�s  r"�makefile_stdinzChannel.makefile_stdin�s�� �4�&�4��<�"7�9�9r$c�@�|jj�	|j�4|jj�|jj	�Stj�|_tj|j�\}}|jj|�|jj|�|jj�|jj	�S#|jj	�wxYw)a�
        Returns an OS-level file descriptor which can be used for polling, but
        but not for reading or writing.  This is primarily to allow Python's
        ``select`` module to work.

        The first time ``fileno`` is called on a channel, a pipe is created to
        simulate real OS-level file descriptor (FD) behavior.  Because of this,
        two OS-level FDs are created, which will use up FDs faster than normal.
        (You won't notice this effect unless you have hundreds of channels
        open at the same time.)

        :return: an OS-level file descriptor (`int`)

        .. warning::
            This method causes channel reads to be slightly less efficient.
        )r3r�rB�filenor�r�	make_pipe�make_or_piper-�	set_eventr.)r�p1�p2s   r"r�zChannel.fileno�s���"	
�	�	����
	 ��z�z�%��z�z�(�(�*�
�I�I����
���)�D�J��&�&�t�z�z�2�F�B���N�N�$�$�R�(��!�!�+�+�B�/��:�:�$�$�&��I�I�����D�I�I����s�%D�B
D�Dc�@�|dk(s|dk(rd|_|dk(s|dk(rd|jj�	|j�}|jj	�|�|j
j
|�yyy#|jj	�wxYw)a�
        Shut down one or both halves of the connection.  If ``how`` is 0,
        further receives are disallowed.  If ``how`` is 1, further sends
        are disallowed.  If ``how`` is 2, further sends and receives are
        disallowed.  This closes the stream in one or both directions.

        :param int how:
            0 (stop receiving), 1 (stop sending), or 2 (stop receiving and
              sending).
        r�r�N)rr3r��	_send_eofr�r,r])r�howrds   r"�shutdownzChannel.shutdown�s���
�1�H�#��(� !�D���1�H�#��(��I�I����
$��N�N�$���	�	�!�!�#��}����1�1�!�4��
#��
�	�	�!�!�#�s�B�Bc�&�|jd�y)a|
        Shutdown the receiving side of this socket, closing the stream in
        the incoming direction.  After this call, future reads on this
        channel will fail instantly.  This is a convenience method, equivalent
        to ``shutdown(0)``, for people who don't make it a habit to
        memorize unix constants from the 1970s.

        .. versionadded:: 1.2
        rN�r�rLs r"�
shutdown_readzChannel.shutdown_read����	
�
�
�a�r$c�&�|jd�y)a{
        Shutdown the sending side of this socket, closing the stream in
        the outgoing direction.  After this call, future writes on this
        channel will fail instantly.  This is a convenience method, equivalent
        to ``shutdown(1)``, for people who don't make it a habit to
        memorize unix constants from the 1970s.

        .. versionadded:: 1.2
        r�Nr�rLs r"�shutdown_writezChannel.shutdown_write�r�r$c��|jSrJ)rrLs r"�_closedzChannel._closed�s���{�{�r$c�v�||_tj|jj��|_yrJ)r,rr@�get_log_channelrA)rr,s  r"�_set_transportzChannel._set_transport�s&��"����o�o�d�n�n�&D�&D�&F�G��r$c��||_||_|dz|_d|_|j	t
dj
|��y)N�
rzMax packet in: {} bytes)r6r8r:r;�_logr
rP)r�window_size�max_packet_sizes   r"�_set_windowzChannel._set_window�sC��)���"1���$/�"�#4�� � ����	�	�%�2�9�9�/�J�Kr$c���||_||_|jj|�|_d|_|j
tdj|j��y)Nr�zMax packet out: {} bytes)	r+r7r,�_sanitize_packet_sizer9rrr
rP)rr*rrs    r"�_set_remote_channelzChannel._set_remote_channel�sX��#���*���#'�>�>�#G�#G��$
�� �����	�	��-�4�4�T�5M�5M�N�	
r$c��|jtdj|j��d|_|j
j
�y)NzSesch channel {} request okT)rr
rPr*rDrC�setris  r"�_request_successzChannel._request_successs9���	�	�%�6�=�=�d�k�k�J�K�����
�
����r$c��|jj�	|j�}|jj�|D] }|��|jj|��"y#|jj�wxYwrJ)r3r�r�r�r,r]�rrdr�s   r"�_request_failedzChannel._request_failedso���	�	����	 ��'�'�)�D��I�I�����	5�A��}����1�1�!�4�	5��
�I�I����s�A,�,Bc��t|t�r|}n|j�}|jj	|�yrJ)�
isinstancer�
get_binaryr-�feed)rrdr�s   r"r�z
Channel._feeds.���a��%��A�����A������A�r$c��|j�}|j�}|dk7r&|jtdj	|��y|j
r|j
|�y|jj|�y)Nr�z)unknown extended_data type {}; discarding)	�get_intrrrrPrEr�r.r)rrd�coder�s    r"�_feed_extendedzChannel._feed_extendedsi���y�y�{��
�L�L�N���1�9��I�I��B�I�I�$�O�
�
�����J�J�q�M��!�!�&�&�q�)r$c��|j�}|jj�	|jr%|j	t
dj
|��|xj|z
c_|jj�|jj�y#|jj�wxYw)Nzwindow up {})rr3r�r0rr
rPr7r5�
notify_allr�)rrdr�s   r"�_window_adjustzChannel._window_adjust&s���������	�	����	 �����	�	�%��!6�!6�v�!>�?�� � �F�*� ����)�)�+��I�I�����D�I�I����s�A B'�'Cc	�\�|j�}|j�}|jj}d}|dk(r3|j	�|_|jj�d}�nL|dk(rd}�nC|dk(r|j�}|j	�}|j	�}|j	�}	|j	�}
|j�}|�d}�n�|j|||||	|
|�}�n�|dk(r|�d}�n�|j|�}�n�|dk(r;|j�}|j�}
|�d}�nv|j|||
�}�na|dk(r*|j�}|�d}�nF|j||�}�n2|d	k(r*|j�}|�d}�n|j||�}�n|d
k(r[|j	�}|j	�}|j	�}	|j	�}
|�d}n�|j||||	|
�}n�|dk(r[|j�}|j�}|j�}|j	�}|�d}nY|j!|||||�}nC|dk(r|�d}n9|j#|�}n'|j%t&d
j)|��d}|rnt+�}|r|j-t.�n|j-t0�|j3|j4�|jj7|�yy)NFr�Tzxon-xoffrVrgr�rlrprsr�r�zUnhandled channel request "{}")�get_text�get_booleanr,�
server_objectrrFr=r
�
get_string�check_channel_pty_request�check_channel_shell_request�check_channel_env_request�check_channel_exec_request�check_channel_subsystem_request�#check_channel_window_change_requestr�check_channel_x11_request�#check_channel_forward_agent_requestrr
rPrrWrr
rXr+r])rrd�key�
want_reply�server�okr_r`ra�
pixelwidth�pixelheight�modesrzr{�cmdr��
auth_protor�r�s                   r"�_handle_requestzChannel._handle_request1s����j�j�l���]�]�_�
����-�-��
���-�� �y�y�{�D�����!�!�#��B�
�J�
��B�
�I�
��<�<�>�D��I�I�K�E��Y�Y�[�F�����J��)�)�+�K��L�L�N�E��~����5�5��$��v�z�;�����G�^��~����7�7��=��
�E�\��<�<�>�D��L�L�N�E��~����5�5�d�D�%�H��
�F�]��,�,�.�C��~����6�6�t�S�A��
�K�
��:�:�<�D��~����;�;�D�$�G��
�O�
#��I�I�K�E��Y�Y�[�F�����J��)�)�+�K��~����?�?��%���[����I�
� !�
�
�������J��,�,�.�K��I�I�K�M��~����5�5��%���!����0�
0��~����?�?��E���I�I�e�=�D�D�S�I�J��B���	�A���
�
�/�0��
�
�/�0�
�I�I�d�(�(�)��N�N�-�-�a�0�r$c���|jj�	|jsad|_|jj	�|j
j	�|j�|jj�|jj�|jtdj|j��y#|jj�wxYw)NTzEOF received ({}))
r3r�rr-rKr.rB�set_foreverr�rr
rPr?ris  r"�_handle_eofzChannel._handle_eof�s����	�	����	 ��$�$�$(��!����$�$�&��%�%�+�+�-��:�:�)��J�J�*�*�,��I�I�����	�	�%�,�3�3�D�J�J�?�@��
�I�I����s�A-C�C/c�`�|jj�	|j�}|jj	|j
�|jj
�|D] }|��|jj|��"y#|jj
�wxYwrJ)r3r�r�r,�_unlink_channelr*r�r]r
s   r"�
_handle_closezChannel._handle_close�s����	�	����	 ��'�'�)�D��N�N�*�*�4�;�;�7��I�I�����	5�A��}����1�1�!�4�	5��
�I�I����s�5B�B-c���t|�}|jj�	|jrt	j
d��|j
|�}|dk(r	|jj�y|j|d|�|jj�|jj|�|S#|jj�wxYw)NzSocket is closedr)rQr3r�rr��error�_wait_for_send_windowr�rYr,r])rr�rd�sizes    r"r�z
Channel._send�s����1�v���	�	����	 ��{�{��l�l�#5�6�6��-�-�d�3�D��q�y��
�I�I����
�L�L��5�D��"��I�I����	
���)�)�!�,����	
�I�I����s�7C�:C�C!c�f�|jj|d|jzdz|zg|���y)Nz[chan z] )rA�logr?)r�level�msgrs    r"rzChannel._log�s.���������x�$�*�*�4�t�;�c�A�I�D�Ir$c�F�|jj�d|_y)NF)rC�clearrDrLs r"r\zChannel._event_pending�s���
�
���� ��r$c���|jj�|jj�sJ�|jry|jj�}|�t
d�}|�)NzChannel closed.)rCr�r�rDr,�
get_exceptionr)rr|s  r"r^zChannel._wait_for_event�sY���
�
�����z�z� � �"�"�"������N�N�(�(�*���9��.�/�A��r$c�d�d|_|jj�|jj�|jj�|jj�|jj�|j�|jj�yy)NT)rr-rKr.r5rrCr
r=rBr2rLs r"�_set_closedzChannel._set_closed�s|��������������#�#�%����%�%�'��
�
�����������:�:�!��J�J�"�"�$�"r$c��|jryt�}|jt�|j	|j
�d|_|j
tdj|j��|S)NTz
EOF sent ({}))
rrrWrrXr+rr
rPr?ris  r"r�zChannel._send_eof�s[���=�=���I��	�
�
�#�$�	�	�	�$�$�$�%���
��	�	�%��/�/��
�
�;�<��r$c���|jr|jry|j�}t�}|j	t
�|j
|j�|j�||fS)N)NN)	rrr�rrWrrXr+rD)r�m1�m2s   r"r�zChannel._close_internal�s[���{�{�d�k�k��
�^�^�
��
�Y��
���&�'�
�
�
�4�%�%�&������2�v�
r$c�0�|jry|jj�	|j�|jj|j�|jj�y#|jj�wxYwrJ)rr3r�rDr,r5r*r�rLs r"�_unlinkzChannel._unlink�sf���;�;���	�	����	 ������N�N�*�*�4�;�;�7��I�I�����D�I�I����s�5A9�9Bc��|jj�	|js|js|js	|jj�y|jr%|jtdj|��|xj|z
c_
|j|jkr	|jj�y|jr/|jtdj|j��|j}d|_
||jj�S#|jj�wxYw)Nrzaddwindow {}zaddwindow send {})r3r�rrrr�r0rr
rPr;r:)r�nrSs   r"r�zChannel._check_add_window�s���	�	����	 ��{�{�d�/�/�t�{�{��
�I�I��������	�	�%��!6�!6�q�!9�:�� � �A�%� ��#�#�t�'?�'?�?��
�I�I��������	�	��.�5�5�d�6J�6J�K���&�&�C�#$�D� ���I�I�����D�I�I����s�$E�AE�AE�Ec�6�|js|jry|jdk(r�|jdk(rt	j��|j}|jdk(r�|js|jrytj
�}|jj|�|�3|tj
�|z
z}|dkrt	j��|jdk(r��|js|jry|j|kr|j}|jdz
|kr|jdz
}|xj|zc_|jr/|jtdj|j��|S)aD
        (You are already holding the lock.)
        Wait for the send window to open up, and allocate up to ``size`` bytes
        for transmission.  If no space opens up before the timeout, a timeout
        exception is raised.  Returns the number of bytes available to send
        (may be less than requested).
        rr��@zwindow down to {})
rrr7r/r��timer5r�r9r0rr
rP)rr:r/�thens    r"r9zChannel._wait_for_send_windowsO���;�;�$�-�-�����1�$��|�|�s�"��n�n�&�&��l�l�G��&�&�!�+��;�;�$�-�-���y�y�{���"�"�'�'��0��&��t�y�y�{�T�1�1�G��#�~�$�n�n�.�.��&�&�!�+��;�;�$�-�-�����$�&��'�'�D��#�#�b�(�4�/��+�+�b�0�D�����$������I�I�e�0�7�7��8L�8L�M�N��r$)�vt100�P�rr)rRrSrr)rNNFN)E�__name__�
__module__�__qualname__�__doc__rHrMrTr%rerjrnrqrur~rxr�r�r�r�r�r�r�r�r�r�r�r�r�r�rKr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��propertyr�r�rrrrr�rrr0r3r6r�rr\r^rDr�r�rJr�r9�r$r"r'r'Ms��� * �X��&������
'��'�R����4����4����2�-��-�2�8��8�2�-��-�4
9� �6-�*������
@��@�D����.���	�!�J�$�!�.,�5�4
+��:
2��B �* �( �0�.�*5�;�$:�" �<5�.
�
�����H�L�	
��5��*�	 �Z1�xA�	5��(J�!��
%�	��
 � �(%r$r'c�*�eZdZdZdd�Zd�Zd�Zd�Zy)r�a�
    A file-like wrapper around `.Channel`.  A ChannelFile is created by calling
    `Channel.makefile`.

    .. warning::
        To correctly emulate the file object created from a socket's `makefile
        <python:socket.socket.makefile>` method, a `.Channel` and its
        `.ChannelFile` should be able to be closed or garbage-collected
        independently. Currently, closing the `ChannelFile` does nothing but
        flush the buffer.
    c�`�||_tj|�|j||�yrJ)�channelrrH�	_set_mode)rr\�mode�bufsizes    r"rHzChannelFile.__init__Es%��������d�#����t�W�%r$c�8�dt|j�zdzS)zP
        Returns a string representation of this object, for debugging.
        z<paramiko.ChannelFile from rO)rRr\rLs r"rTzChannelFile.__repr__Js��-�t�D�L�L�/A�A�C�G�Gr$c�8�|jj|�SrJ)r\r��rr:s  r"�_readzChannelFile._readPs���|�|� � ��&�&r$c�N�|jj|�t|�SrJ)r\r�rQ�rr�s  r"�_writezChannelFile._writeSs�������T�"��4�y�r$N)�rr))rTrUrVrWrHrTrcrfrYr$r"r�r�8s��
�&�
H�'�r$r�c��eZdZdZd�Zd�Zy)r�zg
    A file-like wrapper around `.Channel` stderr.

    See `Channel.makefile_stderr` for details.
    c�8�|jj|�SrJ)r\r�rbs  r"rczChannelStderrFile._read_s���|�|�'�'��-�-r$c�N�|jj|�t|�SrJ)r\r�rQres  r"rfzChannelStderrFile._writebs�����#�#�D�)��4�y�r$N)rTrUrVrWrcrfrYr$r"r�r�Xs���.�r$r�c�"��eZdZdZ�fd�Z�xZS)r�ze
    A file-like wrapper around `.Channel` stdin.

    See `Channel.makefile_stdin` for details.
    c�^��tt|��|jj	�yrJ)�superr�rKr\r�)r�	__class__s �r"rKzChannelStdinFile.closens!���
���+�-����#�#�%r$)rTrUrVrWrK�
__classcell__)rns@r"r�r�gs����&�&r$r�)(rWr�r�r�rOr1�	functoolsr�paramikor�paramiko.commonrrrr	r
rrr
rr�paramiko.messager�paramiko.py3compatr�paramiko.ssh_exceptionr�
paramiko.filer�paramiko.buffered_piperrr�
paramiko.utilrr%r'r�r�r�rYr$r"�<module>rys���&��	�
��������%�*�/�&�<��/��.h�#�h�V'�,��@���	&�{�	&r$

Zerion Mini Shell 1.0