GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
pycons.ishell.Shell Class Reference

Public Member Functions

 __init__ (self, argv=None, user_ns=None, user_global_ns=None, cin=None, cout=None, cerr=None, input_func=None)
 
 namespace (self)
 
 eval (self, console)
 
 complete (self, line)
 
 shell (self, cmd, verbose=0, debug=0, header='')
 

Data Fields

 term
 
 IP
 
 ip
 
 iter_more
 
 complete_sep
 
 prompt
 

Detailed Description

 

Definition at line 27 of file ishell.py.

Constructor & Destructor Documentation

◆ __init__()

pycons.ishell.Shell.__init__ (   self,
  argv = None,
  user_ns = None,
  user_global_ns = None,
  cin = None,
  cout = None,
  cerr = None,
  input_func = None 
)
 

Definition at line 30 of file ishell.py.

31 cin=None, cout=None,cerr=None, input_func=None):
32 """ """
33 if input_func:
34 IPython.iplib.raw_input_original = input_func
35 if cin:
36 IPython.Shell.Term.cin = cin
37 if cout:
38 IPython.Shell.Term.cout = cout
39 if cerr:
40 IPython.Shell.Term.cerr = cerr
41 if argv is None:
42 argv=[]
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,
48 user_ns=user_ns,
49 user_global_ns=user_global_ns,
50 embedded=True,
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)
55 # Get a hold of the public IPython API object and use it
56 self.ip = IPython.core.getipython.get_ipython()
57 self.ip.magic('colors LightBG')
58 sys.excepthook = excepthook
59 self.iter_more = 0
60 self.complete_sep = re.compile(r'[\s\{\}\[\]\‍(\‍)]')
61
62

Member Function Documentation

◆ complete()

pycons.ishell.Shell.complete (   self,
  line 
)

Definition at line 115 of file ishell.py.

115 def complete(self, line):
116 split_line = self.complete_sep.split(line)
117 possibilities = self.IP.complete(split_line[-1])
118 if possibilities:
119 common_prefix = os.path.commonprefix (possibilities)
120 completed = line[:-len(split_line[-1])]+common_prefix
121 else:
122 completed = line
123 return completed, possibilities
124

◆ eval()

pycons.ishell.Shell.eval (   self,
  console 
)

Definition at line 66 of file ishell.py.

66 def eval(self, console):
67 console.write ('\n')
68 orig_stdout = sys.stdout
69 sys.stdout = IPython.Shell.Term.cout
70 try:
71 line = self.IP.raw_input(None, self.iter_more)
72 if self.IP.autoindent:
73 self.IP.readline_startup_hook(None)
74 except KeyboardInterrupt:
75 self.IP.write('\nKeyboardInterrupt\n')
76 self.IP.resetbuffer()
77 self.IP.outputcache.prompt_count -= 1
78 if self.IP.autoindent:
79 self.IP.indent_current_nsp = 0
80 self.iter_more = 0
81 except:
82 self.IP.showtraceback()
83 else:
84 self.iter_more = self.IP.push(line)
85 if (self.IP.SyntaxTB.last_syntax_error and self.IP.rc.autoedit_syntax):
86 self.IP.edit_syntax_error()
87 if self.iter_more:
88 self.prompt = str(self.IP.outputcache.prompt2).strip()
89 if self.IP.autoindent:
90 self.IP.readline_startup_hook(self.IP.pre_readline)
91 else:
92 self.prompt = str(self.IP.outputcache.prompt1).strip()
93 sys.stdout = orig_stdout
94
95 # System output (if any)
96 while True:
97 try:
98 buf = os.read(console.piperead, 256)
99 except:
100 break
101 else:
102 console.write (buf)
103 if len(buf) < 256: break
104
105 # Command output
106 rv = console.cout.getvalue()
107 if rv:
108 rv = rv.strip('\n')
109 console.write (rv)
110 if rv:
111 console.write ('\n')
112 console.cout.truncate(0)
113 console.prompt()
114

◆ namespace()

pycons.ishell.Shell.namespace (   self)

Definition at line 63 of file ishell.py.

63 def namespace(self):
64 return self.IP.user_ns
65

◆ shell()

pycons.ishell.Shell.shell (   self,
  cmd,
  verbose = 0,
  debug = 0,
  header = '' 
)

Definition at line 125 of file ishell.py.

125 def shell(self, cmd,verbose=0,debug=0,header=''):
126 stat = 0
127 if verbose or debug: print(header+cmd)
128 if not debug:
129 input, output = os.popen4(cmd)
130 print(output.read())
131 output.close()
132 input.close()
133

Field Documentation

◆ complete_sep

pycons.ishell.Shell.complete_sep

Definition at line 60 of file ishell.py.

◆ IP

pycons.ishell.Shell.IP

Definition at line 47 of file ishell.py.

◆ ip

pycons.ishell.Shell.ip

Definition at line 56 of file ishell.py.

◆ iter_more

pycons.ishell.Shell.iter_more

Definition at line 59 of file ishell.py.

◆ prompt

pycons.ishell.Shell.prompt

Definition at line 88 of file ishell.py.

◆ term

pycons.ishell.Shell.term

Definition at line 44 of file ishell.py.


The documentation for this class was generated from the following file: