mirror of https://github.com/docker/docker-py.git
Add decoding to the events
Signed-off-by: Christophe Labouisse <christophe@labouisse.org>
This commit is contained in:
parent
2bd21ad066
commit
9bd71b2d45
|
@ -292,7 +292,7 @@ class Client(requests.Session):
|
||||||
|
|
||||||
return sock
|
return sock
|
||||||
|
|
||||||
def _stream_helper(self, response):
|
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:
|
||||||
reader = response.raw
|
reader = response.raw
|
||||||
|
@ -303,6 +303,8 @@ class Client(requests.Session):
|
||||||
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:
|
||||||
|
data = json.loads(data)
|
||||||
yield data
|
yield data
|
||||||
else:
|
else:
|
||||||
# Response isn't chunked, meaning we probably
|
# Response isn't chunked, meaning we probably
|
||||||
|
@ -584,7 +586,8 @@ class Client(requests.Session):
|
||||||
}
|
}
|
||||||
|
|
||||||
return self._stream_helper(self.get(self._url('/events'),
|
return self._stream_helper(self.get(self._url('/events'),
|
||||||
params=params, stream=True))
|
params=params, stream=True),
|
||||||
|
decode=True)
|
||||||
|
|
||||||
def execute(self, container, cmd, detach=False, stdout=True, stderr=True,
|
def execute(self, container, cmd, detach=False, stdout=True, stderr=True,
|
||||||
stream=False, tty=False):
|
stream=False, tty=False):
|
||||||
|
|
|
@ -245,10 +245,10 @@ function return a blocking generator you can iterate over to retrieve events as
|
||||||
**Returns** (generator):
|
**Returns** (generator):
|
||||||
|
|
||||||
```python
|
```python
|
||||||
{"status":"die",
|
{u'status': u'start',
|
||||||
"id":"container-id",
|
u'from': u'image/with:tag',
|
||||||
"from":"image/with:tag",
|
u'id': u'container-id',
|
||||||
"time":unix-timestamp}
|
u'time': 1423339459}
|
||||||
```
|
```
|
||||||
|
|
||||||
## execute
|
## execute
|
||||||
|
|
Loading…
Reference in New Issue