Exemplo n.º 1
0
 def recv_raw(self, numb):
     data = ''
     try:
         if self.tty:
             data = docker_socket.read(self.sock, numb)
         else:
             data = self._internal_recv(numb)
     except Exception as e:
         raise EOFError
     return data
Exemplo n.º 2
0
def _read_payload(socket, payload_size):
    remaining = payload_size
    while remaining > 0:

        data = read(socket, remaining)
        if data is None:
            continue

        if len(data) == 0:
            break

        remaining -= len(data)
        yield data
Exemplo n.º 3
0
    def _internal_recv(self, n):
        if len(self._buf) == 0:
            (stream, size) = docker_socket.next_frame_header(self.sock)
            while size > 0:
                result = docker_socket.read(self.sock, size)
                if result is None:
                    continue
                data_length = len(result)
                if data_length == 0:
                    raise EOFError
                size -= data_length
                self._buf += result

        end = min(len(self._buf), n)
        ret = self._buf[:end]
        self._buf = self._buf[end:]
        return ret
Exemplo n.º 4
0
def _read_payload(socket, payload_size):
    """
    From the given socket, reads and yields payload of the given size. With sockets, we don't receive all data at
    once. Therefore this method will yield each time we read some data from the socket until the payload_size has
    reached or socket has no more data.

    Parameters
    ----------
    socket
        Socket to read from

    payload_size : int
        Size of the payload to read. Exactly these many bytes are read from the socket before stopping the yield.

    Yields
    -------
    int
        Type of the stream (1 => stdout, 2 => stderr)
    str
        Data in the stream
    """

    remaining = payload_size
    while remaining > 0:

        # Try and read as much as possible
        data = read(socket, remaining)
        if data is None:
            # ``read`` will terminate with an empty string. This is just a transient state where we didn't get any data
            continue

        if len(data) == 0:  # pylint: disable=C1801
            # Empty string. Socket does not have any more data. We are done here even if we haven't read full payload
            break

        remaining -= len(data)
        yield data
Exemplo n.º 5
0
def _read_payload(socket, payload_size):
    """
    From the given socket, reads and yields payload of the given size. With sockets, we don't receive all data at
    once. Therefore this method will yield each time we read some data from the socket until the payload_size has
    reached or socket has no more data.

    Parameters
    ----------
    socket
        Socket to read from

    payload_size : int
        Size of the payload to read. Exactly these many bytes are read from the socket before stopping the yield.

    Yields
    -------
    int
        Type of the stream (1 => stdout, 2 => stderr)
    str
        Data in the stream
    """

    remaining = payload_size
    while remaining > 0:

        # Try and read as much as possible
        data = read(socket, remaining)
        if data is None:
            # ``read`` will terminate with an empty string. This is just a transient state where we didn't get any data
            continue

        if len(data) == 0:  # pylint: disable=C1801
            # Empty string. Socket does not have any more data. We are done here even if we haven't read full payload
            break

        remaining -= len(data)
        yield data