diff options
Diffstat (limited to 'bitbake/lib/bb/asyncrpc/connection.py')
-rw-r--r-- | bitbake/lib/bb/asyncrpc/connection.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bitbake/lib/bb/asyncrpc/connection.py b/bitbake/lib/bb/asyncrpc/connection.py index a10628f75a..7f0cf6ba96 100644 --- a/bitbake/lib/bb/asyncrpc/connection.py +++ b/bitbake/lib/bb/asyncrpc/connection.py | |||
@@ -7,6 +7,7 @@ | |||
7 | import asyncio | 7 | import asyncio |
8 | import itertools | 8 | import itertools |
9 | import json | 9 | import json |
10 | from datetime import datetime | ||
10 | from .exceptions import ClientError, ConnectionClosedError | 11 | from .exceptions import ClientError, ConnectionClosedError |
11 | 12 | ||
12 | 13 | ||
@@ -30,6 +31,12 @@ def chunkify(msg, max_chunk): | |||
30 | yield "\n" | 31 | yield "\n" |
31 | 32 | ||
32 | 33 | ||
34 | def json_serialize(obj): | ||
35 | if isinstance(obj, datetime): | ||
36 | return obj.isoformat() | ||
37 | raise TypeError("Type %s not serializeable" % type(obj)) | ||
38 | |||
39 | |||
33 | class StreamConnection(object): | 40 | class StreamConnection(object): |
34 | def __init__(self, reader, writer, timeout, max_chunk=DEFAULT_MAX_CHUNK): | 41 | def __init__(self, reader, writer, timeout, max_chunk=DEFAULT_MAX_CHUNK): |
35 | self.reader = reader | 42 | self.reader = reader |
@@ -42,7 +49,7 @@ class StreamConnection(object): | |||
42 | return self.writer.get_extra_info("peername") | 49 | return self.writer.get_extra_info("peername") |
43 | 50 | ||
44 | async def send_message(self, msg): | 51 | async def send_message(self, msg): |
45 | for c in chunkify(json.dumps(msg), self.max_chunk): | 52 | for c in chunkify(json.dumps(msg, default=json_serialize), self.max_chunk): |
46 | self.writer.write(c.encode("utf-8")) | 53 | self.writer.write(c.encode("utf-8")) |
47 | await self.writer.drain() | 54 | await self.writer.drain() |
48 | 55 | ||
@@ -105,7 +112,7 @@ class WebsocketConnection(object): | |||
105 | return ":".join(str(s) for s in self.socket.remote_address) | 112 | return ":".join(str(s) for s in self.socket.remote_address) |
106 | 113 | ||
107 | async def send_message(self, msg): | 114 | async def send_message(self, msg): |
108 | await self.send(json.dumps(msg)) | 115 | await self.send(json.dumps(msg, default=json_serialize)) |
109 | 116 | ||
110 | async def recv_message(self): | 117 | async def recv_message(self): |
111 | m = await self.recv() | 118 | m = await self.recv() |