36 if not hasattr(sys,
'ps1'): sys.ps1 =
'>>> ' 37 if not hasattr(sys,
'ps2'): sys.ps2 =
'... ' 43 def __init__(self, ns_globals={}, ns_locals={}):
46 self.
completer = rlcompleter.Completer (ns_globals)
58 """ Checks line balance for brace, bracket, parentheses and string quote 60 This helper function checks for the balance of brace, bracket, 61 parentheses and string quote. Any unbalanced line means to wait until 62 some other lines are fed to the console. 66 s = list(filter(
lambda x: x
in '()[]{}"\'', s))
70 brackets = {
'(':
')',
'[':
']',
'{':
'}',
'"':
'"',
'\'':
'\''}
75 if stack
and brackets[stack[-1]] == s[0]:
80 if stack
and brackets[stack[-1]] == s[0]:
89 if s[0]
in '"\'' and stack
and brackets[stack[-1]] == s[0]:
93 return len(stack) == 0
96 def complete(self, line):
100 c = self.
completer.complete (split_line[-1], i)
102 possibilities.append(c)
104 c = self.
completer.complete (split_line[-1], i)
106 common_prefix = os.path.commonprefix (possibilities)
107 completed = line[:-len(split_line[-1])]+common_prefix
110 return completed, possibilities
113 def eval (self, console):
114 line = console.last_line()
120 console.prompt(
'prompt')
125 console.prompt(
'prompt')
129 if line[-1] ==
':' or line[-1] ==
'\\' or line[0]
in ' \11':
131 console.prompt(
'prompt')
136 console.prompt(
'prompt')
139 def execute (self, console):
149 buf = os.read(console.piperead, 256)
153 console.write (buf,
'output')
154 if len(buf) < 256:
break 160 if hasattr (sys,
'last_type')
and sys.last_type == SystemExit:
162 elif hasattr (sys,
'exc_type')
and sys.exc_type == SystemExit:
166 tb = sys.exc_info()[2]
169 traceback.print_exception(sys.exc_info()[0], sys.exc_info()[1], tb)
171 sys.stderr, console.stderr = console.stderr, sys.stderr
172 traceback.print_exc()
def __init__(self, ns_globals={}, ns_locals={})
def execute(self, console)
def is_balanced(self, line)