diff options
author | cclauss <cclauss@me.com> | 2019-08-24 10:58:58 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-26 21:31:08 -0700 |
commit | 4662f67e3849d1e3d5127cc5ebc469d1febca57f (patch) | |
tree | b8f27ff6b2a429b8bf3f7a08b744afa703d12045 /tools/compress_json.py | |
parent | b2cce432f3ee91547e9a7c10560877d1d00229df (diff) | |
download | android-node-v8-4662f67e3849d1e3d5127cc5ebc469d1febca57f.tar.gz android-node-v8-4662f67e3849d1e3d5127cc5ebc469d1febca57f.tar.bz2 android-node-v8-4662f67e3849d1e3d5127cc5ebc469d1febca57f.zip |
tools: fix Python 3 issues in inspector_protocol
PR-URL: https://github.com/nodejs/node/pull/29296
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'tools/compress_json.py')
-rw-r--r-- | tools/compress_json.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/tools/compress_json.py b/tools/compress_json.py index e48a3f2c3c..dfe64063ae 100644 --- a/tools/compress_json.py +++ b/tools/compress_json.py @@ -7,14 +7,16 @@ import zlib try: xrange # Python 2 + PY2 = True except NameError: + PY2 = False xrange = range # Python 3 if __name__ == '__main__': - fp = open(sys.argv[1]) - obj = json.load(fp) - text = json.dumps(obj, separators=(',', ':')) + with open(sys.argv[1]) as fp: + obj = json.load(fp) + text = json.dumps(obj, separators=(',', ':')).encode('utf-8') data = zlib.compress(text, zlib.Z_BEST_COMPRESSION) # To make decompression a little easier, we prepend the compressed data @@ -24,8 +26,8 @@ if __name__ == '__main__': step = 20 slices = (data[i:i+step] for i in xrange(0, len(data), step)) - slices = [','.join(str(ord(c)) for c in s) for s in slices] + slices = [','.join(str(ord(c) if PY2 else c) for c in s) for s in slices] text = ',\n'.join(slices) - fp = open(sys.argv[2], 'w') - fp.write(text) + with open(sys.argv[2], 'w') as fp: + fp.write(text) |