Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 6460:3d2c17be1d35
Handle TypeError when loading possibly compressed response
Now 2.7, and all 3.x except 3.4 are passing. Handle TypeError raised
by python 3.4.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 24 Jul 2021 19:47:00 -0400 |
| parents | 0e86ea84e59d |
| children | 1fc765ef6379 |
comparison
equal
deleted
inserted
replaced
| 6459:0e86ea84e59d | 6460:3d2c17be1d35 |
|---|---|
| 532 print(f.content) | 532 print(f.content) |
| 533 print(type(f.content)) | 533 print(type(f.content)) |
| 534 | 534 |
| 535 try: | 535 try: |
| 536 json_dict = json.loads(f.content) | 536 json_dict = json.loads(f.content) |
| 537 except (ValueError): | 537 except (ValueError, TypeError): |
| 538 # Handle error from trying to load compressed data | 538 # Handle error from trying to load compressed data |
| 539 json_dict = json.loads(b2s(brotli.decompress(f.content))) | 539 json_dict = json.loads(b2s(brotli.decompress(f.content))) |
| 540 | 540 |
| 541 # etag wil not match, creation date different | 541 # etag wil not match, creation date different |
| 542 del(json_dict['data']['@etag']) | 542 del(json_dict['data']['@etag']) |
| 676 content = json.loads(content_str) | 676 content = json.loads(content_str) |
| 677 | 677 |
| 678 | 678 |
| 679 try: | 679 try: |
| 680 json_dict = json.loads(f.content) | 680 json_dict = json.loads(f.content) |
| 681 except (ValueError, UnicodeDecodeError): | 681 except (ValueError, UnicodeDecodeError, TypeError): |
| 682 # ValueError - raised by loads on compressed content python2 | 682 # ValueError - raised by loads on compressed content python2 |
| 683 # UnicodeDecodeError - raised by loads on compressed content | 683 # UnicodeDecodeError - raised by loads on compressed content |
| 684 # python3 | 684 # python3 |
| 685 json_dict = json.loads(b2s(zstd.decompress(f.content))) | 685 json_dict = json.loads(b2s(zstd.decompress(f.content))) |
| 686 | 686 |
