def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False): """ EXAMPLES:: sage: gp._eval_line('2+2') '4' TESTS: We verify that trac 11617 is fixed:: sage: gp._eval_line('a='+str(range(2*10^5)))[:70] '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,' """ line = line.strip() if len(line) == 0: return '' a = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) if a.find("the PARI stack overflows") != -1: verbose("automatically doubling the PARI stack and re-executing current input line") b = self.eval("allocatemem()") if b.find("Warning: not enough memory") != -1: raise RuntimeError(a) return self._eval_line(line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) else: return a
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True): """ EXAMPLES:: sage: maple._eval_line('2+2') # optional - maple '4' """ line += ';' with gc_disabled(): z = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt).replace('\\\n','').strip() if z.lower().find("error") != -1: # The following was very tricky to figure out. # When an error occurs using Maple, unfortunately, # Maple also dumps one into the line where the # error occurred with that line copied in. This # totally messes up the pexpect interface. However, # I think the following few lines successfully # "clear things out", i.e., delete the text from # the edit buffer and get a clean prompt. e = self.expect() e.sendline('%s__sage__;'%(chr(8)*len(line))) e.expect('__sage__;') e.expect(self._prompt) raise RuntimeError, "An error occurred running a Maple command:\nINPUT:\n%s\nOUTPUT:\n%s"%(line, z) return z
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False): """ EXAMPLES:: sage: maple._eval_line('2+2') # optional - maple '4' """ line += ';' with gc_disabled(): z = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt).replace('\\\n','').strip() if z.lower().find("error") != -1: raise RuntimeError("An error occurred running a Maple command:\nINPUT:\n%s\nOUTPUT:\n%s" % (line, z)) return z
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False): """ EXAMPLES: sage: lie._eval_line('2+2') # optional - lie ' 4' sage: lie._eval_line('diagram(2)') # optional - lie Traceback (most recent call last): ... RuntimeError: An error occurred running a LiE command: Argument types do not match in call. Types are: diagram(bin). Valid argument types are for instance: diagram(grp). """ out = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) # Check to see if an error has occurred err = max(out.find("\n(in"), out.find("not defined"), out.find("Argument types")) if err != -1: raise RuntimeError, "An error occurred running a LiE command:\n%s" % (out.replace("\r\n", "\n")) return out
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True): """ EXAMPLES:: sage: gp._eval_line('2+2') '4' """ line = line.strip() if len(line) == 0: return '' a = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) if a.find("the PARI stack overflows") != -1: verbose("automatically doubling the PARI stack and re-executing current input line") b = self.eval("allocatemem()") if b.find("Warning: not enough memory") != -1: raise RuntimeError, a return self._eval_line(line) else: return a
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False): """ EXAMPLES:: sage: gp._eval_line('2+2') '4' TESTS: We verify that trac 11617 is fixed:: sage: gp._eval_line('a='+str(range(2*10^5)))[:70] '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,' """ line = line.strip() if len(line) == 0: return '' a = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) if a.find("the PARI stack overflows") != -1: verbose( "automatically doubling the PARI stack and re-executing current input line" ) b = self.eval("allocatemem()") if b.find("Warning: not enough memory") != -1: raise RuntimeError(a) return self._eval_line(line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) else: return a
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True): """ EXAMPLES:: sage: gp._eval_line('2+2') '4' """ line = line.strip() if len(line) == 0: return '' a = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) if a.find("the PARI stack overflows") != -1: verbose( "automatically doubling the PARI stack and re-executing current input line" ) b = self.eval("allocatemem()") if b.find("Warning: not enough memory") != -1: raise RuntimeError, a return self._eval_line(line) else: return a
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False): s = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) return str(s).strip('\n')
def _eval_line(self, line, reformat=True, allow_use_file=False, wait_for_prompt=True): """ EXAMPLES:: sage: print axiom._eval_line('2+2') #optional - axiom 4 Type: PositiveInteger """ if not wait_for_prompt: return Expect._eval_line(self, line) line = line.rstrip().rstrip(';') if line == '': return '' if len(line) > 3000: raise NotImplementedError, "evaluation of long input lines (>3000 characters) in Axiom not yet implemented." if self._expect is None: self._start() if allow_use_file and self.__eval_using_file_cutoff and \ len(line) > self.__eval_using_file_cutoff: return self._eval_line_using_file(line) try: E = self._expect # debug self._synchronize(cmd='1+%s\n') verbose("in = '%s'"%line,level=3) E.sendline(line) self._expect.expect(self._prompt) out = self._expect.before # debug verbose("out = '%s'"%out,level=3) except EOF: if self._quit_string() in line: return '' except KeyboardInterrupt: self._keyboard_interrupt() if '>> Error detected within library code:' in out or \ 'Cannot find a definition or applicable library operation named' in out: raise RuntimeError, out if not reformat: return out if 'error' in out: return out #out = out.lstrip() i = out.find('\n') out = out[i+1:] outs = out.split("\n") i = 0 outline = '' for line in outs: line = line.rstrip() # print "'%s'"%line if line[:4] == ' (': i = line.find('(') i += line[i:].find(')') if line[i+1:] == "": i = 0 outs = outs[1:] break; out = "\n".join(line[i+1:] for line in outs[1:]) return out
def _eval_line(self, line, allow_use_file=False, wait_for_prompt=True, restart_if_needed=False): return Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt)
def _eval_line(self, line, allow_use_file=False, wait_for_prompt=True): return Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt)
def _eval_line(self, line, reformat=True, allow_use_file=False, wait_for_prompt=True): """ EXAMPLES:: sage: print axiom._eval_line('2+2') #optional - axiom 4 Type: PositiveInteger """ if not wait_for_prompt: return Expect._eval_line(self, line) line = line.rstrip().rstrip(';') if line == '': return '' if len(line) > 3000: raise NotImplementedError, "evaluation of long input lines (>3000 characters) in Axiom not yet implemented." if self._expect is None: self._start() if allow_use_file and self.__eval_using_file_cutoff and \ len(line) > self.__eval_using_file_cutoff: return self._eval_line_using_file(line) try: E = self._expect # debug self._synchronize(cmd='1+%s\n') verbose("in = '%s'" % line, level=3) E.sendline(line) self._expect.expect(self._prompt) out = self._expect.before # debug verbose("out = '%s'" % out, level=3) except EOF: if self._quit_string() in line: return '' except KeyboardInterrupt: self._keyboard_interrupt() if '>> Error detected within library code:' in out or \ 'Cannot find a definition or applicable library operation named' in out: raise RuntimeError, out if not reformat: return out if 'error' in out: return out #out = out.lstrip() i = out.find('\n') out = out[i + 1:] outs = out.split("\n") i = 0 outline = '' for line in outs: line = line.rstrip() # print "'%s'"%line if line[:4] == ' (': i = line.find('(') i += line[i:].find(')') if line[i + 1:] == "": i = 0 outs = outs[1:] break out = "\n".join(line[i + 1:] for line in outs[1:]) return out
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True): s = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt) return str(s).strip('\n')