Skip to content

Commit 9bd71b2

Browse files
committed
Add decoding to the events
Signed-off-by: Christophe Labouisse <[email protected]>
1 parent 2bd21ad commit 9bd71b2

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

docker/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _get_raw_response_socket(self, response):
292292

293293
return sock
294294

295-
def _stream_helper(self, response):
295+
def _stream_helper(self, response, decode=False):
296296
"""Generator for data coming from a chunked-encoded HTTP response."""
297297
if response.raw._fp.chunked:
298298
reader = response.raw
@@ -303,6 +303,8 @@ def _stream_helper(self, response):
303303
break
304304
if reader._fp.chunk_left:
305305
data += reader.read(reader._fp.chunk_left)
306+
if decode:
307+
data = json.loads(data)
306308
yield data
307309
else:
308310
# Response isn't chunked, meaning we probably
@@ -584,7 +586,8 @@ def events(self, since=None, until=None, filters=None):
584586
}
585587

586588
return self._stream_helper(self.get(self._url('/events'),
587-
params=params, stream=True))
589+
params=params, stream=True),
590+
decode=True)
588591

589592
def execute(self, container, cmd, detach=False, stdout=True, stderr=True,
590593
stream=False, tty=False):

docs/api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ function return a blocking generator you can iterate over to retrieve events as
245245
**Returns** (generator):
246246

247247
```python
248-
{"status":"die",
249-
"id":"container-id",
250-
"from":"image/with:tag",
251-
"time":unix-timestamp}
248+
{u'status': u'start',
249+
u'from': u'image/with:tag',
250+
u'id': u'container-id',
251+
u'time': 1423339459}
252252
```
253253

254254
## execute

0 commit comments

Comments
 (0)