Kaydet (Commit) 267021e4 authored tarafından Aanand Prasad's avatar Aanand Prasad

Rename read methods for clarity

read_socket() is now just read(), because its behaviour is consistent
with `os.read` et al.
Signed-off-by: 's avatarAanand Prasad <aanand.prasad@gmail.com>
üst 69832627
......@@ -10,7 +10,7 @@ class SocketError(Exception):
pass
def read_socket(socket, n=4096):
def read(socket, n=4096):
"""
Reads at most n bytes from socket
"""
......@@ -28,13 +28,14 @@ def read_socket(socket, n=4096):
raise
def read_data(socket, n):
def read_exactly(socket, n):
"""
Reads exactly n bytes from socket
Raises SocketError if there isn't enough data
"""
data = six.binary_type()
while len(data) < n:
next_data = read_socket(socket, n - len(data))
next_data = read(socket, n - len(data))
if not next_data:
raise SocketError("Unexpected EOF")
data += next_data
......@@ -49,7 +50,7 @@ def next_frame_size(socket):
https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/attach-to-a-container
"""
try:
data = read_data(socket, 8)
data = read_exactly(socket, 8)
except SocketError:
return 0
......@@ -63,5 +64,5 @@ def frames_iter(socket):
"""
n = next_frame_size(socket)
while n > 0:
yield read_socket(socket, n)
yield read(socket, n)
n = next_frame_size(socket)
......@@ -4,7 +4,7 @@ import tempfile
import docker
from docker.utils.socket import next_frame_size
from docker.utils.socket import read_data
from docker.utils.socket import read_exactly
import pytest
import six
......@@ -1029,7 +1029,7 @@ class AttachContainerTest(helpers.BaseTestCase):
next_size = next_frame_size(pty_stdout)
self.assertEqual(next_size, len(line))
data = read_data(pty_stdout, next_size)
data = read_exactly(pty_stdout, next_size)
self.assertEqual(data.decode('utf-8'), line)
......
import pytest
from docker.utils.socket import next_frame_size
from docker.utils.socket import read_data
from docker.utils.socket import read_exactly
from .. import helpers
......@@ -112,7 +112,7 @@ class ExecTest(helpers.BaseTestCase):
next_size = next_frame_size(socket)
self.assertEqual(next_size, len(line))
data = read_data(socket, next_size)
data = read_exactly(socket, next_size)
self.assertEqual(data.decode('utf-8'), line)
def test_exec_inspect(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment