Ticket #3685: sage-3685.patch
| File sage-3685.patch, 10.0 kB (added by was, 4 months ago) |
|---|
-
a/sage/all.py
old new 1 1 """ 2 2 all.py -- much of sage is imported into this module, so you don't 3 3 have to import everything individually. 4 5 TESTS: 6 7 Check that IPython is *not* imported by default when sage.all is imported. 8 sage: os.system('sage -startuptime|grep IPython') 9 256 4 10 """ 5 11 6 12 from __future__ import with_statement … … 236 242 from sage.libs.all import symmetrica 237 243 symmetrica.end() 238 244 239 def _quit_sage_(self):240 import sage.misc.preparser_ipython241 if sage.misc.preparser_ipython.interface != None:242 sage.misc.preparser_ipython.switch_interface('sage')243 self.exit_now = False244 return245 246 from IPython.genutils import ask_yes_no247 if self.rc.confirm_exit:248 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):249 self.exit_now = True250 else:251 self.exit_now = True252 if self.exit_now:253 quit_sage()254 self.exit_now = True255 256 return self.exit_now257 258 from IPython.iplib import InteractiveShell259 InteractiveShell.exit = _quit_sage_260 261 245 from sage.ext.interactive_constructors_c import inject_on, inject_off 262 246 263 247 #from catalogue.all import new -
a/sage/interfaces/gap.py
old new 148 148 import expect 149 149 from expect import Expect, ExpectElement, FunctionElement, ExpectFunction 150 150 from sage.misc.misc import SAGE_ROOT, DOT_SAGE, is_64_bit 151 from IPython.genutils import page152 151 import re 153 152 import os 154 153 import pexpect … … 334 333 self._get_tmpfile() 335 334 F = open(self._local_tmpfile(),"r") 336 335 if pager: 336 from IPython.genutils import page 337 337 page(F.read(), start = int(sline)-1) 338 338 else: 339 339 return F.read() -
a/sage/misc/all.py
old new 60 60 61 61 from defaults import set_default_variable_name 62 62 63 # the order of the following two imports matters! 63 64 from preparser import preparse, implicit_multiplication 64 65 65 from interpreter import preparser66 from interpreter2 import preparser 66 67 67 68 from sage_eval import sage_eval, sageobj 68 69 -
a/sage/misc/interpreter.py
old new 419 419 return sage.server.support.EMBEDDED_MODE 420 420 421 421 ipython_prefilter = InteractiveShell.prefilter 422 do_preparse=True423 def preparser(on=True):424 """425 Turn on or off the SAGE preparser.426 427 NOTE: This only works on the command line. To turn off preparsing428 in the notebook, switch to python mode.429 430 INPUT:431 on -- bool (default: True) if True turn on preparsing; if False, turn it off.432 433 EXAMPLES:434 sage: 2/3435 2/3436 sage: preparser(False)437 sage: 2/3438 0439 sage: preparser(True)440 sage: 2^3441 8442 """443 global do_preparse444 if on:445 do_preparse = True446 InteractiveShell.prefilter = sage_prefilter447 else:448 do_preparse = False449 InteractiveShell.prefilter = ipython_prefilter450 451 422 452 423 import sagedoc 453 424 import IPython.OInspect 454 425 IPython.OInspect.getdoc = sagedoc.my_getdoc 455 426 IPython.OInspect.getsource = sagedoc.my_getsource 456 457 427 458 428 import __builtin__ 459 429 _prompt = 'sage' … … 468 438 469 439 __builtin__.sage_prompt = sage_prompt 470 440 441 from interpreter2 import preparser 471 442 443 def _quit_sage_(self): 444 import sage.misc.preparser_ipython 445 if sage.misc.preparser_ipython.interface != None: 446 sage.misc.preparser_ipython.switch_interface('sage') 447 self.exit_now = False 448 return 449 450 from IPython.genutils import ask_yes_no 451 if self.rc.confirm_exit: 452 if ask_yes_no('Do you really want to exit ([y]/n)?','y'): 453 self.exit_now = True 454 else: 455 self.exit_now = True 456 457 if self.exit_now: 458 from sage.all import quit_sage 459 quit_sage() 460 self.exit_now = True 461 462 return self.exit_now 463 464 from IPython.iplib import InteractiveShell 465 InteractiveShell.exit = _quit_sage_ 466 -
/dev/null
old new 1 do_preparse=True 2 def preparser(on=True): 3 """ 4 Turn on or off the Sage preparser. 5 6 NOTE: This only works on the command line. To turn off preparsing 7 in the notebook, switch to python mode. 8 9 INPUT: 10 on -- bool (default: True) if True turn on preparsing; if False, turn it off. 11 12 EXAMPLES: 13 sage: 2/3 14 2/3 15 sage: preparser(False) 16 sage: 2/3 # not tested -- impossible to test from doctest system since uses IPython 17 0 18 sage: preparser(True) 19 sage: 2^3 20 8 21 """ 22 global do_preparse 23 import interpreter 24 if on: 25 do_preparse = True 26 interpreter.InteractiveShell.prefilter = interpreter.sage_prefilter 27 else: 28 do_preparse = False 29 interpreter.InteractiveShell.prefilter = interpreter.ipython_prefilter -
a/sage/misc/log.py
old new 54 54 import os 55 55 import time 56 56 57 import interpreter58 57 import latex 59 58 import misc 60 59 … … 64 63 65 64 offset = 0 66 65 loggers = [] 66 67 def prompt(): 68 import interpreter 69 return interpreter._prompt 67 70 68 71 def update(): 69 72 for X in loggers: … … 240 243 if n >= len(self._input): 241 244 return 242 245 return """<font color=darkblue> %s %s:</font> %s"""%( 243 n, interpreter._prompt, self._input[n])246 n, prompt(), self._input[n]) 244 247 245 248 def _get_output(self, n): 246 249 x = self._output[n] … … 354 357 self._in_verbatim = True 355 358 I = self._input[n] 356 359 #print('input: %s' % I) 357 s += "%s %s: %s"%(n, interpreter._prompt, I)360 s += "%s %s: %s"%(n, prompt(), I) 358 361 s += '\\end{verbatim}' 359 362 if followed_by_output: 360 363 self._in_verbatim = False … … 445 448 if n >= len(self._input): 446 449 return 447 450 else: 448 return "%s %s: %s"%(n, interpreter._prompt, self._input[n])451 return "%s %s: %s"%(n, prompt(), self._input[n]) 449 452 450 453 def _get_output(self, n): 451 454 return '\n ' + str(self._output[n]) + '\n\n' -
a/sage/misc/preparser.py
old new 1050 1050 if s[-1] in ["'", '"']: 1051 1051 s = s[:-1] 1052 1052 return s 1053 1054 -
a/sage/misc/sage_timeit.py
old new 9 9 -- William Stein, based on code copied from Fernand Perez's Ipython 10 10 """ 11 11 12 import timeit as timeit_, time, math, preparser , interpreter12 import timeit as timeit_, time, math, preparser 13 13 14 14 def sage_timeit(stmt, globals, preparse=None, 15 15 number = 0, repeat = 3, precision = 3): … … 42 42 repeat=int(repeat) 43 43 precision=int(precision) 44 44 if preparse is None: 45 preparse = interpreter.do_preparse 45 import interpreter2 46 preparse = interpreter2.do_preparse 46 47 if preparse: 47 48 stmt = preparser.preparse(stmt) 48 49 if stmt == "": -
a/sage/server/notebook/cell.py
old new 53 53 class. 54 54 55 55 EXAMPLES: 56 This function just raises a NotImplementedError, since it most be defined 57 in derived class. 56 57 This function just raises a NotImplementedError, since it most 58 be defined in derived class. 59 58 60 sage: C = sage.server.notebook.cell.Cell_generic() 59 61 sage: C.delete_output() 60 62 Traceback (most recent call last): -
a/sage/server/notebook/worksheet.py
old new 33 33 import crypt 34 34 import bz2 35 35 import re 36 import sage.misc.interpreter2 36 37 37 38 # A library that we ship with sage 38 39 import pexpect … … 43 44 from sage.structure.sage_object import load, save 44 45 from sage.interfaces.sage0 import Sage 45 46 from sage.misc.preparser import preparse_file 46 import sage.misc.interpreter47 47 from sage.misc.misc import alarm, cancel_alarm, verbose, DOT_SAGE, walltime 48 48 import sage.server.support as support 49 49 … … 3094 3094 return support.get_rightmost_identifier(s) 3095 3095 3096 3096 def preparse(self, s): 3097 if sage.misc.interpreter .do_preparse:3097 if sage.misc.interpreter2.do_preparse: 3098 3098 s = preparse_file(s, magic=False, do_time=True, 3099 3099 ignore_prompts=False) 3100 3100 return s