comparison tests/get-with-headers.py @ 40154:fe11fc7e541f

py3: encode JSON str to bytes json.dumps() will emit UTF-8 str on Python 2 and 3. Use sysbytes to force the .encode('utf-8') on Python 3 and no-op on Python 2. Differential Revision: https://phab.mercurial-scm.org/D4965
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 11 Oct 2018 21:18:58 +0200
parents cfd0c1df5e33
children 2372284d9457
comparison
equal deleted inserted replaced
40153:0ae20d2141ed 40154:fe11fc7e541f
9 import json 9 import json
10 import os 10 import os
11 import sys 11 import sys
12 12
13 from mercurial import ( 13 from mercurial import (
14 pycompat,
14 util, 15 util,
15 ) 16 )
16 17
17 httplib = util.httplib 18 httplib = util.httplib
18 19
88 # json.dumps() will print trailing newlines. Eliminate them 89 # json.dumps() will print trailing newlines. Eliminate them
89 # to make tests easier to write. 90 # to make tests easier to write.
90 data = json.loads(data) 91 data = json.loads(data)
91 lines = json.dumps(data, sort_keys=True, indent=2).splitlines() 92 lines = json.dumps(data, sort_keys=True, indent=2).splitlines()
92 for line in lines: 93 for line in lines:
93 bodyfh.write(line.rstrip()) 94 bodyfh.write(pycompat.sysbytes(line.rstrip()))
94 bodyfh.write(b'\n') 95 bodyfh.write(b'\n')
95 else: 96 else:
96 bodyfh.write(data) 97 bodyfh.write(data)
97 98
98 if args.bodyfile: 99 if args.bodyfile: