2 if sys.version_info[0] < 3:
3 import __builtin__
as builtins
15 except AttributeError:
21 if 'libedit' in readline.__doc__:
22 readline.parse_and_bind(
'bind ^I rl_complete')
24 readline.parse_and_bind(
'tab: complete')
26 g_builtin_override_called =
False
38 global g_builtin_override_called
39 g_builtin_override_called =
True
44 '''Redefine builtin functions 'quit()' and 'exit()' to print a message and raise an EOFError exception.'''
51 global g_builtin_override_called
52 g_builtin_override_called =
False
59 g_run_one_line_str =
None
67 hw = struct.unpack(
'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
'1234'))
74 sys.stdout.write(prompt)
76 line = sys.stdin.readline()
88 fd = sys.stdin.fileno()
93 old = termios.tcgetattr(fd)
94 if old[3] & termios.ECHO:
96 new = termios.tcgetattr(fd)
97 new[3] = new[3] & ~termios.ECHO
99 termios.tcsetattr(fd, termios.TCSADRAIN, new)
102 banner=
"Python Interactive Interpreter. To exit, type 'quit()', 'exit()'.",
103 readfunc=readfunc_stdio,
106 termios.tcsetattr(fd, termios.TCSADRAIN, old)
112 banner=
"Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.",
113 readfunc=readfunc_stdio,
118 banner=
"Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.",
120 except SystemExit
as e:
121 global g_builtin_override_called
122 if not g_builtin_override_called:
123 print(
'Script exited with %s' % (e))
127 global g_run_one_line_str
130 repl = code.InteractiveConsole(local_dict)
132 repl.runsource(input_string)
133 elif g_run_one_line_str:
134 repl.runsource(g_run_one_line_str)
136 except SystemExit
as e:
137 global g_builtin_override_called
138 if not g_builtin_override_called:
139 print(
'Script exited with %s' % (e))