raise exception when curr_pos > 100 and json fails to decode
This commit is contained in:
parent
b65570fb16
commit
3fb4831804
1 changed files with 4 additions and 5 deletions
|
@ -45,23 +45,22 @@ class ReflectorServer(Protocol):
|
||||||
extra_data = None
|
extra_data = None
|
||||||
response = None
|
response = None
|
||||||
curr_pos = 0
|
curr_pos = 0
|
||||||
size_of_message = len(response_msg)
|
|
||||||
while 1:
|
while 1:
|
||||||
next_close_paren = response_msg.find('}', curr_pos)
|
next_close_paren = response_msg.find('}', curr_pos)
|
||||||
if next_close_paren != -1:
|
if next_close_paren != -1:
|
||||||
curr_pos = next_close_paren + 1
|
curr_pos = next_close_paren + 1
|
||||||
try:
|
try:
|
||||||
response = json.loads(response_msg[:curr_pos])
|
response = json.loads(response_msg[:curr_pos])
|
||||||
failed_to_decode = False
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
failed_to_decode = True
|
if curr_pos > 100:
|
||||||
|
raise Exception("error decoding response")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
extra_data = response_msg[curr_pos:]
|
extra_data = response_msg[curr_pos:]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if size_of_message > 100 and failed_to_decode:
|
|
||||||
raise Exception("error decoding response")
|
|
||||||
return response, extra_data
|
return response, extra_data
|
||||||
|
|
||||||
def handle_request(self, request_dict):
|
def handle_request(self, request_dict):
|
||||||
|
|
Loading…
Reference in a new issue