19 from io
import StringIO
22 except Exception
as e:
23 raise Exception(
"Error importing IPython (%s)" % str(e))
30 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
31 cin=None, cout=None,cerr=None, input_func=None):
34 IPython.iplib.raw_input_original = input_func
36 IPython.Shell.Term.cin = cin
38 IPython.Shell.Term.cout = cout
40 IPython.Shell.Term.cerr = cerr
43 IPython.iplib.raw_input =
lambda x:
None 44 self.
term = IPython.genutils.IOTerm(cin=cin, cout=cout, cerr=cerr)
45 os.environ[
'TERM'] =
'dumb' 46 excepthook = sys.excepthook
47 self.
IP = IPython.Shell.make_IPython(argv,
49 user_global_ns=user_global_ns,
51 shell_class=IPython.Shell.InteractiveShell)
52 self.
IP.system =
lambda cmd: self.
shell(self.
IP.var_expand(cmd),
53 header=
'IPython system call: ',
54 verbose=self.
IP.rc.system_verbose)
56 self.
ip = IPython.core.getipython.get_ipython()
57 self.
ip.magic(
'colors LightBG')
58 sys.excepthook = excepthook
64 return self.
IP.user_ns
66 def eval(self, console):
68 orig_stdout = sys.stdout
69 sys.stdout = IPython.Shell.Term.cout
72 if self.
IP.autoindent:
73 self.
IP.readline_startup_hook(
None)
74 except KeyboardInterrupt:
75 self.
IP.write(
'\nKeyboardInterrupt\n')
77 self.
IP.outputcache.prompt_count -= 1
78 if self.
IP.autoindent:
79 self.
IP.indent_current_nsp = 0
82 self.
IP.showtraceback()
85 if (self.
IP.SyntaxTB.last_syntax_error
and self.
IP.rc.autoedit_syntax):
86 self.
IP.edit_syntax_error()
88 self.
prompt = str(self.
IP.outputcache.prompt2).strip()
89 if self.
IP.autoindent:
90 self.
IP.readline_startup_hook(self.
IP.pre_readline)
92 self.
prompt = str(self.
IP.outputcache.prompt1).strip()
93 sys.stdout = orig_stdout
98 buf = os.read(console.piperead, 256)
103 if len(buf) < 256:
break 106 rv = console.cout.getvalue()
112 console.cout.truncate(0)
115 def complete(self, line):
117 possibilities = self.
IP.complete(split_line[-1])
119 common_prefix = os.path.commonprefix (possibilities)
120 completed = line[:-len(split_line[-1])]+common_prefix
123 return completed, possibilities
125 def shell(self, cmd,verbose=0,debug=0,header=''):
127 if verbose
or debug: print(header+cmd)
129 input, output = os.popen4(cmd)
def shell(self, cmd, verbose=0, debug=0, header='')
def __init__(self, argv=None, user_ns=None, user_global_ns=None, cin=None, cout=None, cerr=None, input_func=None)