13 |
13 |
14 class EricJsonWriter: |
14 class EricJsonWriter: |
15 """ |
15 """ |
16 Class implementing a JSON based writer class. |
16 Class implementing a JSON based writer class. |
17 """ |
17 """ |
|
18 |
18 def __init__(self, host, port): |
19 def __init__(self, host, port): |
19 """ |
20 """ |
20 Constructor |
21 Constructor |
21 |
22 |
22 @param host IP address the reader is listening on |
23 @param host IP address the reader is listening on |
23 @type str |
24 @type str |
24 @param port port the reader is listening on |
25 @param port port the reader is listening on |
25 @type int |
26 @type int |
26 """ |
27 """ |
27 self.__connection = socket.create_connection((host, port)) |
28 self.__connection = socket.create_connection((host, port)) |
28 |
29 |
29 def write(self, data): |
30 def write(self, data): |
30 """ |
31 """ |
31 Public method to send JSON serializable data. |
32 Public method to send JSON serializable data. |
32 |
33 |
33 @param data JSON serializable object to be sent |
34 @param data JSON serializable object to be sent |
34 @type object |
35 @type object |
35 """ |
36 """ |
36 dataStr = json.dumps(data) + '\n' |
37 dataStr = json.dumps(data) + "\n" |
37 self.__connection.sendall(dataStr.encode('utf8', 'backslashreplace')) |
38 self.__connection.sendall(dataStr.encode("utf8", "backslashreplace")) |
38 |
39 |
39 def close(self): |
40 def close(self): |
40 """ |
41 """ |
41 Public method to close the stream. |
42 Public method to close the stream. |
42 """ |
43 """ |
43 self.__connection.close() |
44 self.__connection.close() |