[PATCH 3 of 5 py3] ui: convert to/from Unicode on Python 3 in ui.editor()

Yuya Nishihara yuya at tcha.org
Tue Mar 21 09:44:59 EDT 2017


On Mon, 20 Mar 2017 21:56:49 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1489901890 14400
> #      Sun Mar 19 01:38:10 2017 -0400
> # Node ID 70ec92cd06b503cdba456f069c0f65bd71987a6e
> # Parent  4136d2f283afab8b143a5392144652c079dedbaf
> ui: convert to/from Unicode on Python 3 in ui.editor()
> 
> I considered making this I/O be done in terms of bytes, but that would
> cause an observable regression for Windows users, as non-binary-mode
> open does EOL conversion there. There are probably new encoding
> dragons lurking here, so we may want to switch to using binary mode
> and doing EOL conversion ourselves.

This is lossy conversion we should avoid, but I've taken this as it will
never break things on Python 2.

Another workaround is to abuse latin-1 unicode as a fat bytes on Python 3:

  f = fdopen(fd, 'w', encoding='latin-1')
  f.write(text.decode('latin-1'))

  f = open(name, 'r', encoding='latin-1')
  f.read().encode('latin-1')


More information about the Mercurial-devel mailing list