Ticket #5282: trac_5282.patch

File trac_5282.patch, 11.6 KB (added by was, 13 years ago)
  • sage/interfaces/expect.py

    # 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  
    899899    # END Synchronization code.
    900900    ###########################################################################
    901901
    902     def eval(self, code, strip=True, synchronize=False, **kwds):
     902    def eval(self, code, strip=True, synchronize=False, locals=None, **kwds):
    903903        """
    904904        INPUT:
    905905            code -- text to evaluate
    906906            strip -- bool; whether to strip output prompts, etc.
    907907                     (ignored in the base class).
     908            locals -- None (ignored); this is used for compatibility with the
     909                      Sage notebook's generic system interface.
    908910            **kwds -- All other arguments are passed onto the _eval_line method.
    909911                     An often useful example is reformat=False.
    910912        """
  • sage/interfaces/gap.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/gap.py
    a b  
    386386    def save_workspace(self):
    387387        self.eval('SaveWorkspace("%s");'%WORKSPACE)
    388388
    389     def eval(self, x, newlines=False, strip=True):
     389    def eval(self, x, newlines=False, strip=True, **kwds):
    390390        r"""
    391391        Send the code in the string s to the GAP interpreter and return
    392392        the output as a string.
     
    422422        if not input_line.endswith(';'):
    423423            input_line += ';'
    424424               
    425         result = Expect.eval(self, input_line)
     425        result = Expect.eval(self, input_line, **kwds)
    426426       
    427427        if not newlines:
    428428            result = result.replace("\\\n","")
  • sage/interfaces/kash.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/kash.py
    a b  
    455455    def _object_class(self):
    456456        return KashElement
    457457
    458     def eval(self, x, newlines=False, strip=True):
     458    def eval(self, x, newlines=False, strip=True, **kwds):
    459459        r"""
    460460        Send the code in the string s to the Kash interpreter and return
    461461        the output as a string.
     
    470470        x = x.rstrip()
    471471        if len(x) == 0 or x[len(x) - 1] != ';':
    472472            x += ';'
    473         s = Expect.eval(self, x)
     473        s = Expect.eval(self, x, **kwds)
    474474        i = s.find('\r\n')
    475475        if i != -1:
    476476            s = s[i+2:]
  • sage/interfaces/lisp.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/lisp.py
    a b  
    103103        self.__seq = 0
    104104        self.__in_seq = 1
    105105
    106     def eval(self, code, strip=True):
     106    def eval(self, code, strip=True, **kwds):
    107107        """
    108108        EXAMPLES:
    109109            sage: lisp.eval('(+ 2 2)')
  • sage/interfaces/macaulay2.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/macaulay2.py
    a b  
    193193            raise AttributeError
    194194        return Macaulay2Function(self, attrname)
    195195
    196     def eval(self, code, strip=True):
     196    def eval(self, code, strip=True, **kwds):
    197197        """
    198198        Send the code x to the Macaulay2 interpreter and return the output
    199199        as a string suitable for input back into Macaulay2, if possible.
     
    208208        """
    209209        code = code.strip()
    210210        # 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')
    212212        if strip:
    213213            ans = remove_output_labels(ans)
    214214        return AsciiArtString(ans)
  • sage/interfaces/magma.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/magma.py
    a b  
    377377        """
    378378        self.eval('ChangeDirectory("%s")'%dir, strip=False)
    379379
    380     def eval(self, x, strip=True):
     380    def eval(self, x, strip=True, **kwds):
    381381        """
    382382        Evaluate the given block x of code in Magma and return the
    383383        output as a string.
     
    402402        x = str(x).rstrip()
    403403        if len(x) == 0 or x[len(x) - 1] != ';':
    404404            x += ';'
    405         ans = Expect.eval(self, x).replace('\\\n','')
     405        ans = Expect.eval(self, x, **kwds).replace('\\\n','')
    406406        if 'Runtime error' in ans or 'User error' in ans:
    407407            raise RuntimeError, "Error evaluating Magma code.\nIN:%s\nOUT:%s"%(x, ans)
    408408        return ans
  • sage/interfaces/magma_free.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/magma_free.py
    a b  
    5454        sage: magma_free("Factorization(9290348092384)")  # optional - internet
    5555        [ <2, 5>, <290323377887, 1> ]
    5656    """
    57     def eval(self, x):
     57    def eval(self, x, **kwds):
    5858        return magma_free_eval(x)
    5959    def __call__(self, code, strip=True, columns=0):
    6060        return magma_free_eval(code, strip=strip, columns=columns)
  • sage/interfaces/mathematica.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/mathematica.py
    a b  
    326326##         3) this cygwin batch file must be on the path for SAGE (placing
    327327##            it in <SAGE_ROOT>/local/bin/ is an easy way to ensure this).
    328328
    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)
    331331        if strip:
    332332            return AsciiArtString(clean_output(s))
    333333        else:
  • sage/interfaces/mupad.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/mupad.py
    a b  
    227227        """
    228228        mupad_console()
    229229
    230     def eval(self, code, strip=True):
     230    def eval(self, code, strip=True, **kwds):
    231231        """
    232232        EXAMPLES:
    233233            sage: mupad.eval('2+2')   # optional - mupad
    234234                                                   4
    235235
    236236        """
    237         s = Expect.eval(self, code)
     237        s = Expect.eval(self, code, **kwds)
    238238        return AsciiArtString(s)
    239239
    240240    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True,
  • sage/interfaces/psage.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/psage.py
    a b  
    9999            os.system(cmd)
    100100        Sage.__del__(self)
    101101       
    102     def eval(self, x, strip=True):
     102    def eval(self, x, strip=True, **kwds):
    103103        """
    104104            x -- code
    105105            strip --ignored
     
    113113            self.expect().expect(self._prompt)
    114114            self.expect().expect(self._prompt)
    115115        try:
    116             return Sage.eval(self, x)
     116            return Sage.eval(self, x, **kwds)
    117117        except:
    118118            return "<<currently executing code>>"
    119119           
  • sage/interfaces/reduce.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/reduce.py
    a b  
    8484       
    8585        self.__seq = 0
    8686
    87     def eval(self, code, strip=True):
     87    def eval(self, code, strip=True, **kwds):
    8888        code += ';\n'
    89         return Expect.eval(self, code, strip)[1:]
     89        return Expect.eval(self, code, strip, **kwds)[1:]
    9090
    9191    def _repr_(self):
    9292        return 'Reduce Interpreter'
  • sage/interfaces/sage0.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/sage0.py
    a b  
    260260        """
    261261        return sage.misc.preparser.preparse(x)
    262262
    263     def eval(self, line, strip=True):
     263    def eval(self, line, strip=True, **kwds):
    264264        """
    265265        Send the code x to a second instance of the \sage interpreter and
    266266        return the output as a string.
     
    278278        """
    279279        if self._preparse:
    280280            line = self.preparse(line)
    281         return Expect.eval(self, line).strip()
     281        return Expect.eval(self, line, **kwds).strip()
    282282
    283283    def set(self, var, value):
    284284        """
  • sage/interfaces/scilab.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/scilab.py
    a b  
    261261        Expect._start(self)
    262262        self.eval("mode(0)")
    263263
    264     def eval(self, command):
     264    def eval(self, command, **kwds):
    265265        """
    266266        Evaluates commands.
    267267
     
    271271            sage: scilab.eval("d=44")                   # optional - scilab
    272272            'd  =\n \n    44.'
    273273        """
    274         s = Expect.eval(self, command).replace("\x1b[?1l\x1b>","").strip()
     274        s = Expect.eval(self, command, **kwds).replace("\x1b[?1l\x1b>","").strip()
    275275        return s
    276276
    277277    def whos(self, name=None, typ=None):
  • sage/interfaces/singular.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/interfaces/singular.py
    a b  
    396396        return '< "%s";'%filename
    397397
    398398
    399     def eval(self, x, allow_semicolon=True, strip=True):
     399    def eval(self, x, allow_semicolon=True, strip=True, **kwds):
    400400        r"""
    401401        Send the code x to the Singular interpreter and return the output
    402402        as a string.
     
    479479        if len(x) == 0 or x[len(x) - 1] != ';':
    480480            x += ';'
    481481
    482         s = Expect.eval(self, x)
     482        s = Expect.eval(self, x, **kwds)
    483483
    484484        if s.find("error") != -1 or s.find("Segment fault") != -1:
    485485            raise RuntimeError, 'Singular error:\n%s'%s
  • sage/server/support.py

    diff -r b408cf8edb11 -r 70ff9c049ea2 sage/server/support.py
    a b  
    312312
    313313
    314314def 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    """
    315340    if dir:
    316341        if hasattr(system.__class__, 'chdir'):
    317342            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)
    323344
    324345######################################################################
    325346# Cython