8000 Merge pull request #991 from cclauss/raw_input · staticdev/github4.py@700aafc · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Commit 700aafc

Browse files
authored
Merge pull request sigmavirus24#991 from cclauss/raw_input
Remove more instances of raw_input()
2 parents 3d4ac72 + c3ead36 commit 700aafc

File tree

3 files changed

+6
-28
lines changed

3 files changed

+6
-28
lines changed

docs/source/examples/two_factor_auth.rst

Lines changed: 3 additions & 13 deletions
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)

example-notebooks/two_factor_authentication.ipynb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@
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": {},

report_issue.py

Lines changed: 2 additions & 9 deletions
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]))

0 commit comments

Comments
 (0)
0