ui: convert to/from Unicode on Python 3 in ui.editor()
authorAugie Fackler <augie@google.com>
Sun, 19 Mar 2017 01:38:10 -0400
changeset 31532 713e984bec91
parent 31531 326bca5477d0
child 31533 28f00d07e2ee
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.
mercurial/ui.py
--- a/mercurial/ui.py	Sun Mar 19 01:12:03 2017 -0400
+++ b/mercurial/ui.py	Sun Mar 19 01:38:10 2017 -0400
@@ -1196,7 +1196,7 @@
                                       dir=rdir)
         try:
             f = os.fdopen(fd, pycompat.sysstr("w"))
-            f.write(text)
+            f.write(encoding.strfromlocal(text))
             f.close()
 
             environ = {'HGUSER': user}
@@ -1219,7 +1219,7 @@
                         blockedtag='editor')
 
             f = open(name)
-            t = f.read()
+            t = encoding.strtolocal(f.read())
             f.close()
         finally:
             os.unlink(name)