# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1234767342 28800
# Node ID 70ff9c049ea2300bbe2ed53301cbea5fcfad64b3
# Parent b408cf8edb113c07d107d56e952c3c56d8f33a16
trac #5282 -- In %python mode in the notebook, tracebacks are not properly reported)
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/expect.py
a
|
b
|
|
899 | 899 | # END Synchronization code. |
900 | 900 | ########################################################################### |
901 | 901 | |
902 | | def eval(self, code, strip=True, synchronize=False, **kwds): |
| 902 | def eval(self, code, strip=True, synchronize=False, locals=None, **kwds): |
903 | 903 | """ |
904 | 904 | INPUT: |
905 | 905 | code -- text to evaluate |
906 | 906 | strip -- bool; whether to strip output prompts, etc. |
907 | 907 | (ignored in the base class). |
| 908 | locals -- None (ignored); this is used for compatibility with the |
| 909 | Sage notebook's generic system interface. |
908 | 910 | **kwds -- All other arguments are passed onto the _eval_line method. |
909 | 911 | An often useful example is reformat=False. |
910 | 912 | """ |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/gap.py
a
|
b
|
|
386 | 386 | def save_workspace(self): |
387 | 387 | self.eval('SaveWorkspace("%s");'%WORKSPACE) |
388 | 388 | |
389 | | def eval(self, x, newlines=False, strip=True): |
| 389 | def eval(self, x, newlines=False, strip=True, **kwds): |
390 | 390 | r""" |
391 | 391 | Send the code in the string s to the GAP interpreter and return |
392 | 392 | the output as a string. |
… |
… |
|
422 | 422 | if not input_line.endswith(';'): |
423 | 423 | input_line += ';' |
424 | 424 | |
425 | | result = Expect.eval(self, input_line) |
| 425 | result = Expect.eval(self, input_line, **kwds) |
426 | 426 | |
427 | 427 | if not newlines: |
428 | 428 | result = result.replace("\\\n","") |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/kash.py
a
|
b
|
|
455 | 455 | def _object_class(self): |
456 | 456 | return KashElement |
457 | 457 | |
458 | | def eval(self, x, newlines=False, strip=True): |
| 458 | def eval(self, x, newlines=False, strip=True, **kwds): |
459 | 459 | r""" |
460 | 460 | Send the code in the string s to the Kash interpreter and return |
461 | 461 | the output as a string. |
… |
… |
|
470 | 470 | x = x.rstrip() |
471 | 471 | if len(x) == 0 or x[len(x) - 1] != ';': |
472 | 472 | x += ';' |
473 | | s = Expect.eval(self, x) |
| 473 | s = Expect.eval(self, x, **kwds) |
474 | 474 | i = s.find('\r\n') |
475 | 475 | if i != -1: |
476 | 476 | s = s[i+2:] |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/lisp.py
a
|
b
|
|
103 | 103 | self.__seq = 0 |
104 | 104 | self.__in_seq = 1 |
105 | 105 | |
106 | | def eval(self, code, strip=True): |
| 106 | def eval(self, code, strip=True, **kwds): |
107 | 107 | """ |
108 | 108 | EXAMPLES: |
109 | 109 | sage: lisp.eval('(+ 2 2)') |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/macaulay2.py
a
|
b
|
|
193 | 193 | raise AttributeError |
194 | 194 | return Macaulay2Function(self, attrname) |
195 | 195 | |
196 | | def eval(self, code, strip=True): |
| 196 | def eval(self, code, strip=True, **kwds): |
197 | 197 | """ |
198 | 198 | Send the code x to the Macaulay2 interpreter and return the output |
199 | 199 | as a string suitable for input back into Macaulay2, if possible. |
… |
… |
|
208 | 208 | """ |
209 | 209 | code = code.strip() |
210 | 210 | # TODO: in some cases change toExternalString to toString?? |
211 | | ans = Expect.eval(self, code, strip=strip).strip('\n') |
| 211 | ans = Expect.eval(self, code, strip=strip, **kwds).strip('\n') |
212 | 212 | if strip: |
213 | 213 | ans = remove_output_labels(ans) |
214 | 214 | return AsciiArtString(ans) |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/magma.py
a
|
b
|
|
377 | 377 | """ |
378 | 378 | self.eval('ChangeDirectory("%s")'%dir, strip=False) |
379 | 379 | |
380 | | def eval(self, x, strip=True): |
| 380 | def eval(self, x, strip=True, **kwds): |
381 | 381 | """ |
382 | 382 | Evaluate the given block x of code in Magma and return the |
383 | 383 | output as a string. |
… |
… |
|
402 | 402 | x = str(x).rstrip() |
403 | 403 | if len(x) == 0 or x[len(x) - 1] != ';': |
404 | 404 | x += ';' |
405 | | ans = Expect.eval(self, x).replace('\\\n','') |
| 405 | ans = Expect.eval(self, x, **kwds).replace('\\\n','') |
406 | 406 | if 'Runtime error' in ans or 'User error' in ans: |
407 | 407 | raise RuntimeError, "Error evaluating Magma code.\nIN:%s\nOUT:%s"%(x, ans) |
408 | 408 | return ans |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/magma_free.py
a
|
b
|
|
54 | 54 | sage: magma_free("Factorization(9290348092384)") # optional - internet |
55 | 55 | [ <2, 5>, <290323377887, 1> ] |
56 | 56 | """ |
57 | | def eval(self, x): |
| 57 | def eval(self, x, **kwds): |
58 | 58 | return magma_free_eval(x) |
59 | 59 | def __call__(self, code, strip=True, columns=0): |
60 | 60 | return magma_free_eval(code, strip=strip, columns=columns) |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/mathematica.py
a
|
b
|
|
326 | 326 | ## 3) this cygwin batch file must be on the path for SAGE (placing |
327 | 327 | ## it in <SAGE_ROOT>/local/bin/ is an easy way to ensure this). |
328 | 328 | |
329 | | def eval(self, code, strip=True): |
330 | | s = Expect.eval(self, code) |
| 329 | def eval(self, code, strip=True, **kwds): |
| 330 | s = Expect.eval(self, code, **kwds) |
331 | 331 | if strip: |
332 | 332 | return AsciiArtString(clean_output(s)) |
333 | 333 | else: |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/mupad.py
a
|
b
|
|
227 | 227 | """ |
228 | 228 | mupad_console() |
229 | 229 | |
230 | | def eval(self, code, strip=True): |
| 230 | def eval(self, code, strip=True, **kwds): |
231 | 231 | """ |
232 | 232 | EXAMPLES: |
233 | 233 | sage: mupad.eval('2+2') # optional - mupad |
234 | 234 | 4 |
235 | 235 | |
236 | 236 | """ |
237 | | s = Expect.eval(self, code) |
| 237 | s = Expect.eval(self, code, **kwds) |
238 | 238 | return AsciiArtString(s) |
239 | 239 | |
240 | 240 | def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/psage.py
a
|
b
|
|
99 | 99 | os.system(cmd) |
100 | 100 | Sage.__del__(self) |
101 | 101 | |
102 | | def eval(self, x, strip=True): |
| 102 | def eval(self, x, strip=True, **kwds): |
103 | 103 | """ |
104 | 104 | x -- code |
105 | 105 | strip --ignored |
… |
… |
|
113 | 113 | self.expect().expect(self._prompt) |
114 | 114 | self.expect().expect(self._prompt) |
115 | 115 | try: |
116 | | return Sage.eval(self, x) |
| 116 | return Sage.eval(self, x, **kwds) |
117 | 117 | except: |
118 | 118 | return "<<currently executing code>>" |
119 | 119 | |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/reduce.py
a
|
b
|
|
84 | 84 | |
85 | 85 | self.__seq = 0 |
86 | 86 | |
87 | | def eval(self, code, strip=True): |
| 87 | def eval(self, code, strip=True, **kwds): |
88 | 88 | code += ';\n' |
89 | | return Expect.eval(self, code, strip)[1:] |
| 89 | return Expect.eval(self, code, strip, **kwds)[1:] |
90 | 90 | |
91 | 91 | def _repr_(self): |
92 | 92 | return 'Reduce Interpreter' |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/sage0.py
a
|
b
|
|
260 | 260 | """ |
261 | 261 | return sage.misc.preparser.preparse(x) |
262 | 262 | |
263 | | def eval(self, line, strip=True): |
| 263 | def eval(self, line, strip=True, **kwds): |
264 | 264 | """ |
265 | 265 | Send the code x to a second instance of the \sage interpreter and |
266 | 266 | return the output as a string. |
… |
… |
|
278 | 278 | """ |
279 | 279 | if self._preparse: |
280 | 280 | line = self.preparse(line) |
281 | | return Expect.eval(self, line).strip() |
| 281 | return Expect.eval(self, line, **kwds).strip() |
282 | 282 | |
283 | 283 | def set(self, var, value): |
284 | 284 | """ |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/scilab.py
a
|
b
|
|
261 | 261 | Expect._start(self) |
262 | 262 | self.eval("mode(0)") |
263 | 263 | |
264 | | def eval(self, command): |
| 264 | def eval(self, command, **kwds): |
265 | 265 | """ |
266 | 266 | Evaluates commands. |
267 | 267 | |
… |
… |
|
271 | 271 | sage: scilab.eval("d=44") # optional - scilab |
272 | 272 | 'd =\n \n 44.' |
273 | 273 | """ |
274 | | s = Expect.eval(self, command).replace("\x1b[?1l\x1b>","").strip() |
| 274 | s = Expect.eval(self, command, **kwds).replace("\x1b[?1l\x1b>","").strip() |
275 | 275 | return s |
276 | 276 | |
277 | 277 | def whos(self, name=None, typ=None): |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/singular.py
a
|
b
|
|
396 | 396 | return '< "%s";'%filename |
397 | 397 | |
398 | 398 | |
399 | | def eval(self, x, allow_semicolon=True, strip=True): |
| 399 | def eval(self, x, allow_semicolon=True, strip=True, **kwds): |
400 | 400 | r""" |
401 | 401 | Send the code x to the Singular interpreter and return the output |
402 | 402 | as a string. |
… |
… |
|
479 | 479 | if len(x) == 0 or x[len(x) - 1] != ';': |
480 | 480 | x += ';' |
481 | 481 | |
482 | | s = Expect.eval(self, x) |
| 482 | s = Expect.eval(self, x, **kwds) |
483 | 483 | |
484 | 484 | if s.find("error") != -1 or s.find("Segment fault") != -1: |
485 | 485 | raise RuntimeError, 'Singular error:\n%s'%s |
diff -r b408cf8edb11 -r 70ff9c049ea2 sage/server/support.py
a
|
b
|
|
312 | 312 | |
313 | 313 | |
314 | 314 | def syseval(system, cmd, dir=None): |
| 315 | """ |
| 316 | INPUT: |
| 317 | system -- an object with an eval method that takes as input |
| 318 | a cmd (a string), and two dictionaries: |
| 319 | sage_globals and locals. |
| 320 | dir -- an otional directory to change to before |
| 321 | calling system.eval. |
| 322 | |
| 323 | OUTPUT: |
| 324 | The output of system.eval is returned. |
| 325 | |
| 326 | EXAMPLES: |
| 327 | sage: from sage.misc.python import python |
| 328 | sage: sage.server.support.syseval(python, '2+4/3') |
| 329 | 3 |
| 330 | '' |
| 331 | sage: sage.server.support.syseval(python, 'import os; os.chdir(".")') |
| 332 | '' |
| 333 | sage: sage.server.support.syseval(python, 'import os; os.chdir(1,2,3)') |
| 334 | Traceback (most recent call last): |
| 335 | ... |
| 336 | TypeError: chdir() takes exactly 1 argument (3 given) |
| 337 | sage: sage.server.support.syseval(gap, "2+3") |
| 338 | '5' |
| 339 | """ |
315 | 340 | if dir: |
316 | 341 | if hasattr(system.__class__, 'chdir'): |
317 | 342 | system.chdir(dir) |
318 | | try: |
319 | | return system.eval(cmd, sage_globals, locals = sage_globals) |
320 | | except TypeError: |
321 | | return system.eval(cmd) |
322 | | |
| 343 | return system.eval(cmd, sage_globals, locals = sage_globals) |
323 | 344 | |
324 | 345 | ###################################################################### |
325 | 346 | # Cython |