8000 Remove more instance of raw_input · simahawk/github3.py@451b7c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 451b7c1

Browse files
committed
Remove more instance of raw_input
1 parent 3d4ac72 commit 451b7c1

File tree

3 files changed

+7
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,10 @@ For example:
1515
1616
import github3
1717
18-
try:
19-
# Python 2
20-
prompt = raw_input
21-
except NameError:
22-
# Python 3
23-
prompt = input
24-
2518
def my_two_factor_function():
26-
code = ''
27-
while not code:
28-
# The user could accidentally press Enter before being ready,
29-
# let's protect them from doing that.
30-
code = prompt('Enter 2FA code: ')
31-
return code
19+
# The user could accidentally press Enter before being ready,
20+
# let's protect them from doing that.
21+
return input('Enter 2FA code: ').strip() or my_two_factor_function()
3222
3323
g = github3.login('sigmavirus24', 'my_password',
3424
two_factor_callback=my_two_factor_function)
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@
3030
"collapsed": false,
3131
"input": [
3232
"def callback_handler():\n",
33-
" prompt_str = 'Please enter your 2FA token now: '\n",
34-
" try:\n",
35-
" token = raw_input(prompt_str)\n",
36-
" except NameError:\n",
37-
" token = input(prompt_str)\n",
38-
" return token"
33+
" return input('Please enter your 2FA token now: ').strip() or callback_handler()"
3934
],
4035
"language": "python",
4136
"metadata": {},
4237
"outputs": [],
43-
"prompt_number": 1
38+
token "prompt_number": 1
4439
},
4540
{
4641
"cell_type": "markdown",
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,10 @@
1010
except ImportError:
1111
pass
1212

13-
if hasattr(__builtins__, 'raw_input'):
14-
prompt = raw_input
15-
else:
16-
prompt = input
17-
1813

1914
def prompt_user(prompt_str):
20-
val = ''
21-
while not val:
22-
val = prompt(prompt_str)
23-
return val
15+
return input(prompt_str).strip() or prompt_user(prompt_str)
16+
2417

2518
if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help', '-?'):
2619
print("Usage: {0} [-h|-?|--help]".format(sys.argv[0]))