forked from LBRYCommunity/lbry-sdk
rework data parser
This commit is contained in:
parent
b36cf3e36c
commit
40da5b6cb6
1 changed files with 12 additions and 18 deletions
|
@ -146,32 +146,26 @@ def _parse_blob_response(response_msg: bytes) -> typing.Tuple[typing.Optional[ty
|
||||||
# <blob bytes>
|
# <blob bytes>
|
||||||
# <json><blob bytes>
|
# <json><blob bytes>
|
||||||
|
|
||||||
extra_data = b''
|
|
||||||
response = None
|
|
||||||
curr_pos = 0
|
curr_pos = 0
|
||||||
while True:
|
while True:
|
||||||
next_close_paren = response_msg.find(b'}', curr_pos)
|
next_close_paren = response_msg.find(b'}', curr_pos)
|
||||||
if next_close_paren == -1:
|
if next_close_paren == -1:
|
||||||
break
|
return None, response_msg
|
||||||
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])
|
||||||
if not isinstance(response, dict):
|
except ValueError:
|
||||||
raise ValueError()
|
continue
|
||||||
for key in response.keys():
|
possible_response_keys = {
|
||||||
if key not in [
|
|
||||||
BlobPaymentAddressResponse.key,
|
BlobPaymentAddressResponse.key,
|
||||||
BlobAvailabilityResponse.key,
|
BlobAvailabilityResponse.key,
|
||||||
BlobPriceResponse.key,
|
BlobPriceResponse.key,
|
||||||
BlobDownloadResponse.key]:
|
BlobDownloadResponse.key
|
||||||
raise ValueError()
|
}
|
||||||
extra_data = response_msg[curr_pos:]
|
if isinstance(response, dict) and response.keys():
|
||||||
break
|
if set(response.keys()).issubset(possible_response_keys):
|
||||||
except ValueError:
|
return response, response_msg[curr_pos:]
|
||||||
response = None
|
return None, response_msg
|
||||||
if response is None:
|
|
||||||
extra_data = response_msg
|
|
||||||
return response, extra_data
|
|
||||||
|
|
||||||
|
|
||||||
class BlobRequest:
|
class BlobRequest:
|
||||||
|
|
Loading…
Reference in a new issue