Mercurial > hg
comparison tests/get-with-headers.py @ 43380:579672b347d2 stable
py3: define and use json.loads polyfill
Python 3.5's json.loads() requires a str. Only Python 3.6+
supports passing a bytes or bytearray.
This commit implements a json.loads() polyfill on Python 3.5
so that we can use bytes. The added function to detect encodings
comes verbatim from Python 3.7.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 02 Nov 2019 12:09:35 -0700 |
parents | 2372284d9457 |
children | c102b704edb5 |
comparison
equal
deleted
inserted
replaced
43379:bb509f39d387 | 43380:579672b347d2 |
---|---|
96 # Pretty print JSON. This also has the beneficial side-effect | 96 # Pretty print JSON. This also has the beneficial side-effect |
97 # of verifying emitted JSON is well-formed. | 97 # of verifying emitted JSON is well-formed. |
98 if formatjson: | 98 if formatjson: |
99 # json.dumps() will print trailing newlines. Eliminate them | 99 # json.dumps() will print trailing newlines. Eliminate them |
100 # to make tests easier to write. | 100 # to make tests easier to write. |
101 data = json.loads(data) | 101 data = pycompat.json_loads(data) |
102 lines = json.dumps(data, sort_keys=True, indent=2).splitlines() | 102 lines = json.dumps(data, sort_keys=True, indent=2).splitlines() |
103 for line in lines: | 103 for line in lines: |
104 bodyfh.write(pycompat.sysbytes(line.rstrip())) | 104 bodyfh.write(pycompat.sysbytes(line.rstrip())) |
105 bodyfh.write(b'\n') | 105 bodyfh.write(b'\n') |
106 else: | 106 else: |