Patchwork [2,of,8] ui: inline util.bytesinput() into ui._readline()

login
register
mail settings
Submitter Yuya Nishihara
Date March 9, 2018, 12:35 p.m.
Message ID <0fc636a6f20d51e813b9.1520598935@mimosa>
Download mbox | patch
Permalink /patch/29162/
State Accepted
Headers show

Comments

Yuya Nishihara - March 9, 2018, 12:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520324051 21600
#      Tue Mar 06 02:14:11 2018 -0600
# Node ID 0fc636a6f20d51e813b9117961ad18f0eb5f83fb
# Parent  f7d9876d750e048b4c0e0ec0682928e86a8e8ecb
ui: inline util.bytesinput() into ui._readline()

Prepares for rework of Python 3 support, which is currently broken due to
read-ahead buffer of TextIOWrapper.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1278,7 +1278,13 @@  class ui(object):
         # prompt ' ' must exist; otherwise readline may delete entire line
         # - http://bugs.python.org/issue12833
         with self.timeblockedsection('stdio'):
-            line = util.bytesinput(self.fin, self.fout, r' ')
+            sin, sout = sys.stdin, sys.stdout
+            try:
+                sys.stdin = encoding.strio(self.fin)
+                sys.stdout = encoding.strio(self.fout)
+                line = encoding.strtolocal(pycompat.rawinput(r' '))
+            finally:
+                sys.stdin, sys.stdout = sin, sout
 
         # When stdin is in binary mode on Windows, it can cause
         # raw_input() to emit an extra trailing carriage return
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -212,14 +212,6 @@  def rapply(f, xs):
         return xs
     return _rapply(f, xs)
 
-def bytesinput(fin, fout, *args, **kwargs):
-    sin, sout = sys.stdin, sys.stdout
-    try:
-        sys.stdin, sys.stdout = encoding.strio(fin), encoding.strio(fout)
-        return encoding.strtolocal(pycompat.rawinput(*args, **kwargs))
-    finally:
-        sys.stdin, sys.stdout = sin, sout
-
 def bitsfrom(container):
     bits = 0
     for bit in container: