Patchwork [2,of,2] py3: select input or raw_input by pycompat

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 16, 2017, 5:22 a.m.
Message ID <2c44ad89954bf0a04392.1502860959@mimosa>
Download mbox | patch
Permalink /patch/23070/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 16, 2017, 5:22 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1502859264 -32400
#      Wed Aug 16 13:54:24 2017 +0900
# Node ID 2c44ad89954bf0a04392775e7444f1ba2fc0b2e9
# Parent  63c4583c7fa0f989f225488273614f3a0aa88002
py3: select input or raw_input by pycompat

This seems slightly cleaner.
Augie Fackler - Aug. 16, 2017, 6:29 p.m.
On Wed, Aug 16, 2017 at 02:22:39PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1502859264 -32400
> #      Wed Aug 16 13:54:24 2017 +0900
> # Node ID 2c44ad89954bf0a04392775e7444f1ba2fc0b2e9
> # Parent  63c4583c7fa0f989f225488273614f3a0aa88002
> py3: select input or raw_input by pycompat

queued, thanks

Very nice cleanups to my continued butchering in the name of python 3! Appreciated!

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -63,6 +63,7 @@  if ispy3:
         sysexecutable = os.fsencode(sysexecutable)
     stringio = io.BytesIO
     maplist = lambda *args: list(map(*args))
+    rawinput = input
 
     # TODO: .buffer might not exist if std streams were replaced; we'll need
     # a silly wrapper to make a bytes stream backed by a unicode one.
@@ -312,6 +313,7 @@  else:
     shlexsplit = shlex.split
     stringio = cStringIO.StringIO
     maplist = map
+    rawinput = raw_input
 
 class _pycompatstub(object):
     def __init__(self):
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -176,10 +176,7 @@  def bytesinput(fin, fout, *args, **kwarg
     sin, sout = sys.stdin, sys.stdout
     try:
         sys.stdin, sys.stdout = encoding.strio(fin), encoding.strio(fout)
-        if pycompat.ispy3:
-            return encoding.strtolocal(input(*args, **kwargs))
-        else:
-            return raw_input(*args, **kwargs)
+        return encoding.strtolocal(pycompat.rawinput(*args, **kwargs))
     finally:
         sys.stdin, sys.stdout = sin, sout