D6113: py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Sat Mar 9 20:30:46 EST 2019


yuja added a comment.


  > - 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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6113

To: Kwan, #hg-reviewers
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list