提交 c0ff6bb3 编写于 作者: C Cleber Rosa

Python 3 port: use input() instead of raw_input()

On Python 2, input() has a different behavior, including an evaluation
of the obtained string.  On Python 3, it just returns the stripped
string.

Let's hand off the difference handling to six.

PS: we won't use use six.moves.input() on the failtest_ugly.py file,
given that it's intended to be a bad example.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 8bd578dd
...@@ -20,6 +20,8 @@ import logging ...@@ -20,6 +20,8 @@ import logging
import os import os
import time import time
from six.moves import input
from . import path as utils_path from . import path as utils_path
log = logging.getLogger('avocado.test') log = logging.getLogger('avocado.test')
...@@ -99,7 +101,7 @@ def ask(question, auto=False): ...@@ -99,7 +101,7 @@ def ask(question, auto=False):
if auto: if auto:
log.info("%s (y/n) y" % question) log.info("%s (y/n) y" % question)
return "y" return "y"
return raw_input("%s (y/n) " % question) return input("%s (y/n) " % question)
def read_file(filename): def read_file(filename):
......
...@@ -6,7 +6,7 @@ import sys ...@@ -6,7 +6,7 @@ import sys
sys.stdout.write("Direct output to stdout\n") sys.stdout.write("Direct output to stdout\n")
sys.stderr.write("Direct output to stderr\n") sys.stderr.write("Direct output to stderr\n")
raw_input("I really want some input on each import") input("I really want some input on each import")
sys.stdin = 'This is my __COOL__ stdin' sys.stdin = 'This is my __COOL__ stdin'
sys.stdout = 'my stdout' sys.stdout = 'my stdout'
sys.stderr = 'my stderr' sys.stderr = 'my stderr'
......
...@@ -23,6 +23,8 @@ import sys ...@@ -23,6 +23,8 @@ import sys
import argparse import argparse
from six.moves import input
class Parser(argparse.ArgumentParser): class Parser(argparse.ArgumentParser):
...@@ -89,9 +91,9 @@ class App(object): ...@@ -89,9 +91,9 @@ class App(object):
result = None result = None
while True: while True:
result = raw_input("Result ([P]ass, [F]ail, [S]kip): ") result = input("Result ([P]ass, [F]ail, [S]kip): ")
if result in RESULT_MAP.keys(): if result in RESULT_MAP.keys():
notes = raw_input("Additional Notes: ") notes = input("Additional Notes: ")
break break
print("") print("")
...@@ -99,7 +101,7 @@ class App(object): ...@@ -99,7 +101,7 @@ class App(object):
"result": RESULT_MAP.get(result), "result": RESULT_MAP.get(result),
"notes": notes.strip()}) "notes": notes.strip()})
user = raw_input("Your identification [%s]: " % getpass.getuser()) user = input("Your identification [%s]: " % getpass.getuser())
if not user: if not user:
user = getpass.getuser() user = getpass.getuser()
self.user_identification = user self.user_identification = user
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册