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/root/usr/lib/python3/dist-packages/docker/utils/__pycache__/socket.cpython-310.pyc
o

�2.a�@s�ddlZddlZddlZddlZddlZzddlmZWn
ey)e	d�ZYnwdZ
dZGdd�de�Z
ddd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zddd�Zdd�ZdS)�N�)�NpipeSocket�c@seZdZdS)�SocketErrorN)�__name__�
__module__�__qualname__�r	r	�5/usr/lib/python3/dist-packages/docker/utils/socket.pyrsr�c
Cs�tjtjtjf}t|t�st�|ggg�z"t|d�r!|�|�WSt|t	t
d��r/|�|�WSt�|�
�|�WStyP}z
|j|vrE�WYd}~dSd}~ww)z+
    Reads at most n bytes from socket
    �recv�SocketION)�errno�EINTR�EDEADLK�EWOULDBLOCK�
isinstancer�select�hasattrr�getattr�pysocket�read�os�fileno�OSError)�socket�n�recoverable_errors�er	r	r
rs


���rcCsHt�}t|�|kr"t||t|��}|std��||7}t|�|ks	|S)z]
    Reads exactly n bytes from socket
    Raises SocketError if there isn't enough data
    zUnexpected EOF)�bytes�lenrr)rr�data�	next_datar	r	r
�read_exactly*s�r#cCs<zt|d�}Wn
tyYdSwt�d|�\}}||fS)z�
    Returns the stream and size of the next frame of data waiting to be read
    from socket, according to the protocol defined here:

    https://docs.docker.com/engine/api/v1.24/#attach-to-a-container
    �)���r%z>BxxxL)r#r�struct�unpack)rr!�stream�actualr	r	r
�next_frame_header8s�r*cCs|rdd�t|�D�St|�S)z�
    Return a generator of frames read from socket. A frame is a tuple where
    the first item is the stream number and the second item is a chunk of data.

    If the tty setting is enabled, the streams are multiplexed into the stdout
    stream.
    css�|]}t|fVqdS)N)�STDOUT)�.0�framer	r	r
�	<genexpr>Qs�zframes_iter.<locals>.<genexpr>)�frames_iter_tty�frames_iter_no_tty)r�ttyr	r	r
�frames_iterHsr2ccsh�	t|�\}}|dkrdS|dkr3t||�}|durqt|�}|dkr&dS||8}||fV|dksq)zc
    Returns a generator of data read from the socket when the tty setting is
    not enabled.
    TrN)r*rr )rr(r�result�data_lengthr	r	r
r0Vs �

��r0ccs$�	t|�}t|�dkrdS|Vq)z^
    Return a generator of data read from the socket when the tty setting is
    enabled.
    TrN)rr )rr3r	r	r
r/ks��r/FcCs�|dur
t��|�Sddg}|D]=}|dksJ�|ddur6|ddur+|d|d<q|d|d7<q|ddurC|d|d<q|d|d7<qt|�S)a�
    Iterate through frames read from the socket and return the result.

    Args:

        demux (bool):
            If False, stdout and stderr are multiplexed, and the result is the
            concatenation of all the frames. If True, the streams are
            demultiplexed, and the result is a 2-tuple where each item is the
            concatenation of frames belonging to the same stream.
    FN)NNrr)r�join�tuple)�frames�demux�outr-r	r	r
�consume_socket_outputxsr:cCs.|tkr|dfS|tkrd|fSt|�d���)z[
    Utility to demultiplex stdout and stderr when reading frames from the
    socket.
    Nz is not a valid stream)r+�STDERR�
ValueError)�	stream_idr!r	r	r
�
demux_adaptor�s
r>)r)F)rrrrrr&�	transportr�ImportError�typer+r;�	Exceptionrrr#r*r2r0r/r:r>r	r	r	r
�<module>s*�


%