70 @rtype tuple of (str, dict) |
70 @rtype tuple of (str, dict) |
71 """ |
71 """ |
72 # step 1: receive the data |
72 # step 1: receive the data |
73 # The JSON RPC string is prefixed by a 9 character long length field. |
73 # The JSON RPC string is prefixed by a 9 character long length field. |
74 length = self.__connection.recv(9) |
74 length = self.__connection.recv(9) |
|
75 if len(length) < 9: |
|
76 # invalid length string received |
|
77 return None, None |
|
78 |
75 length = int(length) |
79 length = int(length) |
76 data = b'' |
80 data = b'' |
77 while len(data) < length: |
81 while len(data) < length: |
78 newData = self.__connection.recv(length - len(data)) |
82 newData = self.__connection.recv(length - len(data)) |
79 if not newData: |
83 if not newData: |
80 return None, None |
84 return None, None |
|
85 |
81 data += newData |
86 data += newData |
82 |
87 |
83 # step 2: decode and convert the data |
88 # step 2: decode and convert the data |
84 line = data.decode( |
89 line = data.decode( |
85 'utf8', 'backslashreplace') |
90 'utf8', 'backslashreplace') |