Kaydet (Commit) fb6c9a82 authored tarafından Joffrey F's avatar Joffrey F

Use json_stream function in decoded _stream_helper

Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst 91a185d7
...@@ -18,16 +18,20 @@ from .service import ServiceApiMixin ...@@ -18,16 +18,20 @@ from .service import ServiceApiMixin
from .swarm import SwarmApiMixin from .swarm import SwarmApiMixin
from .volume import VolumeApiMixin from .volume import VolumeApiMixin
from .. import auth from .. import auth
from ..constants import (DEFAULT_TIMEOUT_SECONDS, DEFAULT_USER_AGENT, from ..constants import (
IS_WINDOWS_PLATFORM, DEFAULT_DOCKER_API_VERSION, DEFAULT_TIMEOUT_SECONDS, DEFAULT_USER_AGENT, IS_WINDOWS_PLATFORM,
STREAM_HEADER_SIZE_BYTES, DEFAULT_NUM_POOLS, DEFAULT_DOCKER_API_VERSION, STREAM_HEADER_SIZE_BYTES, DEFAULT_NUM_POOLS,
MINIMUM_DOCKER_API_VERSION) MINIMUM_DOCKER_API_VERSION
from ..errors import (DockerException, TLSParameterError, )
create_api_error_from_http_exception) from ..errors import (
DockerException, TLSParameterError,
create_api_error_from_http_exception
)
from ..tls import TLSConfig from ..tls import TLSConfig
from ..transport import SSLAdapter, UnixAdapter from ..transport import SSLAdapter, UnixAdapter
from ..utils import utils, check_resource, update_headers from ..utils import utils, check_resource, update_headers
from ..utils.socket import frames_iter from ..utils.socket import frames_iter
from ..utils.json_stream import json_stream
try: try:
from ..transport import NpipeAdapter from ..transport import NpipeAdapter
except ImportError: except ImportError:
...@@ -274,7 +278,12 @@ class APIClient( ...@@ -274,7 +278,12 @@ class APIClient(
def _stream_helper(self, response, decode=False): def _stream_helper(self, response, decode=False):
"""Generator for data coming from a chunked-encoded HTTP response.""" """Generator for data coming from a chunked-encoded HTTP response."""
if response.raw._fp.chunked: if response.raw._fp.chunked:
if decode:
for chunk in json_stream(self._stream_helper(response, False)):
yield chunk
else:
reader = response.raw reader = response.raw
while not reader.closed: while not reader.closed:
# this read call will block until we get a chunk # this read call will block until we get a chunk
...@@ -283,18 +292,6 @@ class APIClient( ...@@ -283,18 +292,6 @@ class APIClient(
break break
if reader._fp.chunk_left: if reader._fp.chunk_left:
data += reader.read(reader._fp.chunk_left) data += reader.read(reader._fp.chunk_left)
if decode:
if six.PY3:
data = data.decode('utf-8')
# remove the trailing newline
data = data.strip()
# split the data at any newlines
data_list = data.split("\r\n")
# load and yield each line seperately
for data in data_list:
data = json.loads(data)
yield data
else:
yield data yield data
else: else:
# Response isn't chunked, meaning we probably # Response isn't chunked, meaning we probably
......
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