Skip to content

Commit 007b1fb

Browse files
committed
bam
1 parent cd677d0 commit 007b1fb

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎v3/pg_logger.py‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ def raw_input_wrapper(prompt=''):
227227
return input_str
228228
raise RawInputException(str(prompt)) # always convert prompt into a string
229229

230+
231+
# Python 2 input() does eval(raw_input())
232+
def python2_input_wrapper(prompt=''):
233+
if input_string_queue:
234+
input_str = input_string_queue.pop(0)
235+
236+
# write the prompt and user input to stdout, to emulate what happens
237+
# at the terminal
238+
sys.stdout.write(str(prompt)) # always convert prompt into a string
239+
sys.stdout.write(input_str + "\n") # newline to simulate the user hitting Enter
240+
return eval(input_str) # remember to eval!
241+
raise RawInputException(str(prompt)) # always convert prompt into a string
242+
230243
class MouseInputException(Exception):
231244
pass
232245

@@ -1210,9 +1223,12 @@ def _runscript(self, script_str, custom_globals=None):
12101223
else:
12111224
if k == 'raw_input':
12121225
user_builtins[k] = raw_input_wrapper
1213-
elif k == 'input' and is_python3:
1214-
# Python 3 input() is Python 2 raw_input()
1215-
user_builtins[k] = raw_input_wrapper
1226+
elif k == 'input':
1227+
if is_python3:
1228+
# Python 3 input() is Python 2 raw_input()
1229+
user_builtins[k] = raw_input_wrapper
1230+
else:
1231+
user_builtins[k] = python2_input_wrapper
12161232
else:
12171233
user_builtins[k] = v
12181234

0 commit comments

Comments
 (0)