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/lib/python3/dist-packages/dockerpty/__pycache__/io.cpython-310.pyc
o

~vU"+�@sxddlZddlZddlZddlZddlZddlZd
dd�Zddd�ZGdd�de�Z	Gd	d
�d
e�Z
Gdd�de�ZdS)�NTcCsJt�|tj�}|r|tj@}n|tjB}t�|tj|�t|tj@�S)zl
    Set the given file-descriptor blocking or non-blocking.

    Returns the original blocking status.
    )�fcntl�F_GETFL�os�
O_NONBLOCK�F_SETFL�bool)�fd�blocking�old_flag�new_flag�r�./usr/lib/python3/dist-packages/dockerpty/io.py�set_blockings
rc
Cspg}z
t�||||�dd�WStjy7}ztjr|jn|d}|tjkr1ggfWYd}~S|�d}~ww)z�
    Select the streams from `read_streams` that are ready for reading, and
    streams from `write_streams` ready for writing.

    Uses `select.select()` internally but only returns two lists of ready streams.
    r�N)�builtin_select�select�error�six�PY3�errno�EINTR)�read_streams�
write_streams�timeout�exception_streams�e�norrr
r,s"��
��rc@sleZdZdZ	ejejejgZdd�Z	dd�Z
dd�Zdd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�ZdS)�Streamz�
    Generic Stream class.

    This is a file-like abstraction on top of os.read() and os.write(), which
    add consistency to the reading of sockets and files alike.
    cCs||_d|_d|_d|_dS)z}
        Initialize the Stream for the file descriptor `fd`.

        The `fd` object must have a `fileno()` method.
        �FN)r�buffer�close_requested�closed)�selfrrrr
�__init__Ws
zStream.__init__cC�
|j��S)z=
        Return the fileno() of the file descriptor.
        )r�fileno�r"rrr
r%b�
z
Stream.filenocCs(t|jd�r|j�|�dSt|j|�S)N�setblockingT)�hasattrrr(r�r"�valuerrr
riszStream.set_blocking�c
Csh	zt|jd�r|j�|�WSt�|j��|�WSty2}z|jtj	vr(|�WYd}~nd}~wwq)zU
        Return `n` bytes of data from the Stream, or None at end of stream.
        T�recvN)
r)rr-r�readr%�EnvironmentErrorrr�ERRNO_RECOVERABLE)r"�nrrrr
r.ps����zStream.readcCs&|sdS|j|7_|��t|�S)z�
        Write `data` to the Stream. Not all data may be written right away.
        Use select to find when the stream is writeable, and call do_write()
        to flush the internal buffer.
        N)r�do_write�len�r"�datarrr
�writes
zStream.writec
Cs�	z3d}t|jd�r|j�|j�}n
t�|j��|j�}|j|d�|_|jr2t|j�dkr2|�	�|WSt
yN}z|jtj
vrD|�WYd}~nd}~wwq)zZ
        Flushes as much pending data from the internal write buffer as possible.
        Tr�sendN)r)rr7rrr6r%r r3�closer/rrr0)r"�writtenrrrr
r2�s"����zStream.do_writecCst|j�dkS)zL
        Returns True if the stream has data waiting to be written.
        r)r3rr&rrr
�needs_write�szStream.needs_writecCsVd|_|js't|j�dkr)d|_t|jd�r|j��dSt�|j���dSdSdS)NTrr8)	r r!r3rr)rr8rr%r&rrr
r8�s�zStream.closecC�djt|�j|jd�S)Nz{cls}({fd}))�clsr)�format�type�__name__rr&rrr
�__repr__�szStream.__repr__N�r,)r?�
__module__�__qualname__�__doc__rr�EDEADLK�EWOULDBLOCKr0r#r%rr.r6r2r:r8r@rrrr
rFs �
rc@sdeZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zddd�Zdd�Z
dS)�Demuxera8
    Wraps a multiplexed Stream to read in data demultiplexed.

    Docker multiplexes streams together when there is no PTY attached, by
    sending an 8-byte header, followed by a chunk of data.

    The first 4 bytes of the header denote the stream from which the data came
    (i.e. 0x01 = stdout, 0x02 = stderr). Only the first byte of these initial 4
    bytes is used.

    The next 4 bytes indicate the length of the following chunk of data as an
    integer in big endian format. This much data must be consumed before the
    next 8-byte header is read.
    cCs||_d|_dS)zA
        Initialize a new Demuxer reading from `stream`.
        rN)�stream�remain)r"rHrrr
r#�s
zDemuxer.__init__cCr$)zn
        Returns the fileno() of the underlying Stream.

        This is useful for select() to work.
        )rHr%r&rrr
r%��
zDemuxer.filenocC�|j�|�S�N)rHrr*rrr
r��zDemuxer.set_blockingr,cCs^|�|�}|dkrdSt��}t|�|kr-|j�|t|��}|s#|S||}t|�|ks|S)a
        Read up to `n` bytes of data from the Stream, after demuxing.

        Less than `n` bytes of data may be returned depending on the available
        payload, but the number of bytes returned will never exceed `n`.

        Because demuxing involves scanning 8-byte headers, the actual amount of
        data read from the underlying stream may be greater than `n`.
        rN)�_next_packet_sizer�binary_typer3rHr.)r"r1�sizer5�nxtrrr
r.�s
�zDemuxer.readcCrK)z6
        Delegates the the underlying Stream.
        )rHr6r4rrr
r6�sz
Demuxer.writecC�t|jd�r|j��SdS)�1
        Delegates to underlying Stream.
        r:F)r)rHr:r&rrr
r:�
zDemuxer.needs_writecCrR)rSr2F)r)rHr2r&rrr
r2
rTzDemuxer.do_writecCr$)rS)rHr8r&rrr
r8r'z
Demuxer.closercCs�d}|jdkrt||j�}|j|8_|St��}t|�dkr8|j�dt|��}|s.dS||}t|�dks |dur>dSt|�dkrVt�d|�\}}t||�}|||_|S)Nr�z>BxxxL)	rI�minrrOr3rHr.�struct�unpack)r"r1rPr5rQ�__�actualrrr
rNs&
��

zDemuxer._next_packet_sizecCr;)Nz{cls}({stream}))r<rH)r=r>r?rHr&rrr
r@3s�zDemuxer.__repr__NrA�r)r?rBrCrDr#r%rr.r6r:r2r8rNr@rrrr
rG�s	



rGc@sHeZdZdZ		ddd�Zdd�Zdd�Zdd
d�Zdd
�Zdd�Z	dS)�Pumpa�
    Stream pump class.

    A Pump wraps two Streams, reading from one and and writing its data into
    the other, much like a pipe but manually managed.

    This abstraction is used to facilitate piping data between the file
    descriptors associated with the tty and those associated with a container's
    allocated pty.

    Pumps are selectable based on the 'read' end of the pipe.
    TcCs"||_||_d|_||_||_dS)z�
        Initialize a Pump with a Stream to read from and another to write to.

        `wait_for_output` is a flag that says that we need to wait for EOF
        on the from_stream in order to consider this pump as "done".
        FN)�from_stream�	to_stream�eof�wait_for_output�propagate_close)r"r]r^r`rarrr
r#Fs

z
Pump.__init__cCr$)z�
        Returns the `fileno()` of the reader end of the Pump.

        This is useful to allow Pumps to function with `select()`.
        )r]r%r&rrr
r%XrJzPump.filenocCrKrL)r]rr*rrr
rarMzPump.set_blockingr,c
Cs�z%|j�|�}|dust|�dkrd|_|jr|j��WdS|j�|�WSty@}z|j	t	j
kr5|�WYd}~dSd}~ww)z�
        Flush `n` bytes of data from the reader Stream to the writer Stream.

        Returns the number of bytes that were actually flushed. A return value
        of zero is not an error.

        If EOF has been reached, `None` is returned.
        NrT)r]r.r3r_rar^r8r6�OSErrorr�EPIPE)r"r1r.rrrr
�flushds

���z
Pump.flushcCs&|js|jot|jd�o|j��S)z�
        Returns True if the read stream is done (either it's returned EOF or
        the pump doesn't have wait_for_output set), and the write
        side does not have pending bytes to send.
        r:)r`r_r)r^r:r&rrr
�is_done|s�zPump.is_donecCsdjt|�j|j|jd�S)Nz){cls}(from={from_stream}, to={to_stream}))r<r]r^)r=r>r?r]r^r&rrr
r@�s
�z
Pump.__repr__N)TTrA)
r?rBrCrDr#r%rrdrer@rrrr
r\8s
�	

r\)Tr[)rrrrWrrrr�objectrrGr\rrrr
�<module>s

v|