depot_tools: Use gclient_utils.AskForData instead of raw_input.
gclient_utils.AskForData will use raw_input on Python 2 and input on Python 3.
Bug: 1063976
Change-Id: I93c059c4e4454d01787716b5a0a2641ad5253f53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2116370
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Anthony Polito <apolito@google.com>
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/gclient_utils.py b/gclient_utils.py
index 4d9e986..540f2b7 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -158,6 +158,17 @@
return output
+def AskForData(message):
+ # Use this so that it can be mocked in tests on Python 2 and 3.
+ try:
+ if sys.version_info.major == 2:
+ return raw_input(message)
+ return input(message)
+ except KeyboardInterrupt:
+ # Hide the exception.
+ sys.exit(1)
+
+
def FileRead(filename, mode='rbU'):
# Always decodes output to a Unicode string.
# On Python 3 newlines are converted to '\n' by default and 'U' is deprecated.