D6113: py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Kwan (Ian Moody)
phabricator at mercurial-scm.org
Sat Mar 9 03:01:58 UTC 2019
Kwan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D6113
AFFECTED FILES
hgext/phabricator.py
CHANGE DETAILS
diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -239,10 +239,17 @@
Call parameters are read from stdin as a JSON blob. Result will be written
to stdout as a JSON blob.
"""
- 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())
+ )
+ 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))
def getrepophid(repo):
"""given callsign, return repository PHID or None"""
To: Kwan, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list