summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Labouisse <christophe@labouisse.org>2015-02-07 22:30:30 +0100
committerChristophe Labouisse <christophe@labouisse.org>2015-02-11 07:27:23 +0100
commit9bd71b2d4573a4431aa13ed1d764022263d2639c (patch)
treeedbce3f80cb6f8344e20e2cbfc6b4be592f23113
parent2bd21ad066606f7d1109f72fc4c5547e8dda5a2d (diff)
downloaddocker-py-9bd71b2d4573a4431aa13ed1d764022263d2639c.tar.gz
Add decoding to the events
Signed-off-by: Christophe Labouisse <christophe@labouisse.org>
-rw-r--r--docker/client.py7
-rw-r--r--docs/api.md8
2 files changed, 9 insertions, 6 deletions
diff --git a/docker/client.py b/docker/client.py
index 9ac43af..5ce83ba 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -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):
diff --git a/docs/api.md b/docs/api.md
index 421e5da..d9eebc0 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -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