D6113: py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Yuya Nishihara
yuya at tcha.org
Sat Mar 9 20:28:11 EST 2019
> - params = json.loads(ui.fin.read())
> - result = callconduit(repo, name, params)
> - s = json.dumps(result, sort_keys=True, indent=2, separators=(b',', b': '))
> - ui.write(b'%s\n' % s)
> + # json.(load|dump)s only returns/accepts unicode strings
> + params = pycompat.rapply(lambda x:
> + encoding.unitolocal(x) if isinstance(x, pycompat.unicode) else x,
> + json.loads(ui.fin.read())
> + )
Perhaps, the input data has to be converted to unicode. IIRC old Python 3
versions don't accept bytes.
> + result = pycompat.rapply(lambda x:
> + encoding.unifromlocal(x) if isinstance(x, bytes) else x,
> + callconduit(repo, name, params)
> + )
> + s = json.dumps(result, sort_keys=True, indent=2, separators=(u',', u': '))
> + ui.write(b'%s\n' % encoding.unitolocal(s))
Maybe we can use `templatefilters.json()` to dump internal (i.e. no unicode)
dict.
More information about the Mercurial-devel
mailing list