HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/cwd/usr/lib/python3/dist-packages/dockerpty/__pycache__/pty.cpython-310.pyc
o

���V�+�@s�ddlZddlZddlZddlmZddlmZddlmZGdd�de	�Z
Gdd�de	�ZGdd�de�Zdd
d�Z
Gdd
�d
e�ZGdd�de	�ZdS)�N)�SSLErrorc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�WINCHHandlerz?
    WINCH Signal handler to keep the PTY correctly sized.
    cCs||_d|_dS)z�
        Initialize a new WINCH handler for the given PTY.

        Initializing a handler has no immediate side-effects. The `start()`
        method must be invoked for the signals to be trapped.
        N)�pty�original_handler)�selfr�r�//usr/lib/python3/dist-packages/dockerpty/pty.py�__init__s
zWINCHHandler.__init__cCs|��|S)z5
        Invoked on entering a `with` block.
        )�start�rrrr�	__enter__*szWINCHHandler.__enter__cGs|��dS)z4
        Invoked on exiting a `with` block.
        N)�stop)r�_rrr�__exit__2szWINCHHandler.__exit__cs �fdd�}t�tj|��_dS)z�
        Start trapping WINCH signals and resizing the PTY.

        This method saves the previous WINCH handler so it can be restored on
        `stop()`.
        cs|tjkr�j��dSdS�N)�signal�SIGWINCHr�resize)�signum�framerrr�handleAs
�z"WINCHHandler.start.<locals>.handleN)rrr)rrrrrr
9szWINCHHandler.startcCs"|jdurt�tj|j�dSdS)zU
        Stop trapping WINCH signals and restore the previous WINCH handler.
        N)rrrrrrrr
Gs
�zWINCHHandler.stopN)	�__name__�
__module__�__qualname__�__doc__r	rrr
r
rrrrrsrc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�	OperationcK�t��)z3
        are we dealing with a tty or not?
        ��NotImplementedError�r�kwargsrrr�israwR�zOperation.israwcKr)�!
        start execution
        rrrrrr
Xr"zOperation.startcKr)z0
        if we have terminal, resize it
        r�r�height�widthr rrrr^r"zOperation.resizecCr)zReturn sockets for streams.rrrrr�socketsdszOperation.socketsN)rrrr!r
rr'rrrrrPs
rc@sDeZdZdZddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�RunOperationz6
    class for handling `docker run`-like command
    TNcCs^|durt�dt�d}||_||_d|_||_|ptj|_|p"tj	|_	|p(tj
|_
||_dS)�Y
        Initialize the PTY using the docker.Client instance and container dict.
        Nz�The default behaviour of dockerpty is changing. Please add logs=1 to your dockerpty.start call to maintain existing behaviour. See https://github.com/d11wtq/dockerpty/issues/51 for details.�)�warnings�warn�DeprecationWarning�client�	container�raw�interactive�sys�stdout�stderr�stdin�logs)rr.r/r1r3r4r5r6rrrr	ns
zRunOperation.__init__cKs�|p|��\}}}g}|r|jr|�tjt�|j�|dd��|r0|�tj|t�|j�dd��|rA|�tj|t�|j�dd��|�	�ddsT|j
j|jfi|��|S)z�
        Present the PTY of the container inside the current process.

        This will take over the current process' TTY until the container's PTY
        is closed.
        F��wait_for_output��propagate_close�State�Running)
r'r1�append�io�Pump�Streamr5r3r4�_container_infor.r
r/)rr'r �	pty_stdin�
pty_stdout�
pty_stderr�pumpsrrrr
�s
zRunOperation.startcKs0|jdur|��}|j��o|dd|_|jS)z�
        Returns True if the PTY should operate in raw mode.

        If the container was not started with tty=True, this will return False.
        N�Config�Tty)r0rAr3�isatty)rr �inforrrr!�s
zRunOperation.israwcs ������fdd�}t|d�S)z�
        Returns a tuple of sockets connected to the pty (stdin,stdout,stderr).

        If any of the sockets are not attached in the container, `None` is
        returned in the tuple.
        c	s\�dd�|���r,�j��j|dddd�ji�}t�|�}�ddr'|St�|�SdS)NrFz	Attach{0}r*�streamr6rG)	�format�
capitalizer.�
attach_socketr/r6r>r@�Demuxer)�key�socketrJ�rIrrrrM�s�

z+RunOperation.sockets.<locals>.attach_socket)r5r3r4)rA�map)rrMrrQrr'�s
zRunOperation.socketscK�|jj|j||d�dS)z-
        resize pty within container
        �r%r&N)r.rr/r$rrrr��zRunOperation.resizecCs|j�|j�S)zA
        Thin wrapper around client.inspect_container().
        )r.�inspect_containerr/rrrrrA�szRunOperation._container_info)TNNNNr)
rrrrr	r
r!r'rrArrrrr(is


r(TcCs|j||||d�}|S)N)�ttyr5)�exec_create)r.r/�commandr1�exec_idrrrrX�srXc@sLeZdZdZddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)�
ExecOperationz7
    class for handling `docker exec`-like command
    TNcCsF||_||_d|_||_|ptj|_|ptj|_|ptj|_d|_dSr)	rZr.r0r1r2r3r4r5�_info)rr.rZr1r3r4r5rrrr	�s
zExecOperation.__init__cKsV|p|��}g}|jr|�tjt�|j�|dd��|�tj|t�|j�dd��|S)r#Fr7r9)r'r1r=r>r?r@r5r3)rr'r rJrErrrr
�szExecOperation.startcKs$|jdur|j��o
|��|_|jS)z�
        Returns True if the PTY should operate in raw mode.

        If the exec was not started with tty=True, this will return False.
        N)r0r3rH�is_process_ttyrrrrr!�s
zExecOperation.israwcCs6|jj|jd|jd�}t�|�}|��r|St�|�S)zL
        Return a single socket which is processing all I/O to exec
        T)rPrW)r.�
exec_startrZr1r>r@r]rN)rrPrJrrrr's


zExecOperation.socketscKrS)z1
        resize pty of an execed process
        rTN)r.�exec_resizerZr$rrrrrUzExecOperation.resizecCs|��ddS)z9
        does execed process have allocated tty?
        �
ProcessConfigrW)�
_exec_inforrrrr]szExecOperation.is_process_ttycCs |jdur
|j�|j�|_|jS)z<
        Caching wrapper around client.exec_inspect
        N)r\r.�exec_inspectrZrrrrras
zExecOperation._exec_info)TNNNr)rrrrr	r
r!r'rr]rarrrrr[�s


r[c@s<eZdZdZdd�Zdd�Zd
dd�Zd
d	d
�Zdd�ZdS)�PseudoTerminala!
    Wraps the pseudo-TTY (PTY) allocated to a docker container.

    The PTY is managed via the current process' TTY until it is closed.

    Example:

        import docker
        from dockerpty import PseudoTerminal

        client = docker.Client()
        container = client.create_container(
            image='busybox:latest',
            stdin_open=True,
            tty=True,
            command='/bin/sh',
        )

        # hijacks the current tty until the pty is closed
        PseudoTerminal(client, container).start()

    Care is taken to ensure all file descriptors are restored on exit. For
    example, you can attach to a running container from within a Python REPL
    and when the container exits, the user will be returned to the Python REPL
    without adverse effects.
    cCs||_||_dS)r)N)r.�	operation)rr.rdrrrr	<s
zPseudoTerminal.__init__cCs
|j��Sr)rdr'rrrrr'Ds
zPseudoTerminal.socketsNcCs�|jj|d�}dd�|D�}z0t|��
|�|�Wd�n1s#wYW|r;t||�D]\}}t�||�q0dSdS|rQt||�D]\}}t�||�qFww)N)r'cSsg|]}|�d��qS)F)�set_blocking��.0�prrr�
<listcomp>J�z(PseudoTerminal.start.<locals>.<listcomp>)rdr
r�_hijack_tty�zipr>re)rr'rE�flags�pump�flagrrrr
Gs"
�����zPseudoTerminal.startcCs`|j��sdS|pt�|jj�}|dur.|\}}z|jj||d�WdSty-YdSwdS)z�
        Resize the container's PTY.

        If `size` is not None, it must be a tuple of (height,width), otherwise
        it will be determined by the size of the current TTY.
        NrT)rdr!rW�sizer3r�IOError)rrp�rows�colsrrrrTs
��zPseudoTerminal.resizec	Cs�tj|jj|j��d��`|��	dd�|D�}dd�|D�}tj||dd�\}}z|D]}|��q-|D]}|�	�q6t
dd�|D��rHWnWntyb}z
d	|jvrX|�WYd}~nd}~wwqWd�dS1sowYdS)
N)r0TcSsg|]}|js|�qSr)�eofrfrrrrilrjz.PseudoTerminal._hijack_tty.<locals>.<listcomp>cSsg|]
}|j��r|j�qSr)�	to_stream�needs_writerfrrrrims�<)�timeoutcSsg|]}|���qSr)�is_donerfrrrriwszThe operation did not complete)
rW�Terminalrdr5r!rr>�select�do_write�flush�allr�strerror)	rrE�
read_pumps�
write_streams�
read_ready�write_ready�write_streamrn�errrrkhs.

�
����
"�zPseudoTerminal._hijack_ttyr)	rrrrr	r'r
rrkrrrrrc s


rc)T)r2rr+�sslr�dockerpty.ior>�
dockerpty.ttyrW�objectrrr(rXr[rcrrrr�<module>s6
fL