Add decoding to the events

Signed-off-by: Christophe Labouisse <christophe@labouisse.org>
This commit is contained in:
Christophe Labouisse 2015-02-07 22:30:30 +01:00
parent 2bd21ad066
commit 9bd71b2d45
2 changed files with 9 additions and 6 deletions

View File

@ -292,7 +292,7 @@ class Client(requests.Session):
return sock
def _stream_helper(self, response):
def _stream_helper(self, response, decode=False):
"""Generator for data coming from a chunked-encoded HTTP response."""
if response.raw._fp.chunked:
reader = response.raw
@ -303,6 +303,8 @@ class Client(requests.Session):
break
if reader._fp.chunk_left:
data += reader.read(reader._fp.chunk_left)
if decode:
data = json.loads(data)
yield data
else:
# Response isn't chunked, meaning we probably
@ -584,7 +586,8 @@ class Client(requests.Session):
}
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,
stream=False, tty=False):

View File

@ -245,10 +245,10 @@ function return a blocking generator you can iterate over to retrieve events as
**Returns** (generator):
```python
{"status":"die",
"id":"container-id",
"from":"image/with:tag",
"time":unix-timestamp}
{u'status': u'start',
u'from': u'image/with:tag',
u'id': u'container-id',
u'time': 1423339459}
```
## execute