Ticket #10187: trac_10187_general_display_prefix_workaround.patch

File trac_10187_general_display_prefix_workaround.patch, 4.2 KB (added by vbraun, 9 years ago)

Updated patch

  • sage/interfaces/maxima.py

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1288385467 -3600
    # Node ID b2c29b301c0714b2a2afcaae076520099ef52de4
    # Parent  0484986477877e8144cd830e8320d19a53f0b5c6
    Trac #10187: workaround for missing general-display-prefix in maxima
    
    The symptom is a "Error: TIMED OUT! PROCESS KILLED!" because expect interface waits forever for maxima to print its next prompt.
    
    This patch uses maxima's prompt-prefix instead.
    
    diff -r 048498647787 -r b2c29b301c07 sage/interfaces/maxima.py
    a b  
    544544        self._prompt_wait = [self._prompt] + [re.compile(x) for x in self._ask] + \
    545545                            ['Break [0-9]+'] #note that you might need to change _expect_expr if you
    546546                                             #change this
    547         self._error_re = re.compile('(Principal Value|debugmode|Incorrect syntax|Maxima encountered a Lisp error)')
     547        self._error_re = re.compile('(Principal Value|debugmode|incorrect syntax|Maxima encountered a Lisp error)')
    548548        self._display2d = False
    549549
    550550
     551
    551552    def _function_class(self):
    552553        """
    553554        EXAMPLES::
     
    728729       
    729730            sage: maxima._eval_line('1+1;')
    730731            '2'
    731             sage: maxima.eval('sage0: x == x;')
     732            sage: maxima._eval_line('sage0: x == x;')
    732733            Traceback (most recent call last):
    733734            ...
    734             TypeError: error evaluating "sage0: x == x;":...
     735            TypeError: Error executing code in Maxima...
     736
     737
    735738        """
    736739        if len(line) == 0:
    737740            return ''
     
    750753        else:
    751754            self._sendline(line)
    752755
     756        line_echo = self._expect.readline()
    753757        if not wait_for_prompt:
    754758            return
     759        assert line_echo.strip() == line.strip()
    755760
    756         self._expect_expr(self._display_prompt)
    757         pre_out = self._before()
    758         self._expect_expr()
    759         out = self._before()
     761        # This broke in maxima-5.22.1 as discussed in http://trac.sagemath.org/sage_trac/ticket/10187
     762        #self._expect_expr(self._display_prompt)
     763        #pre_out = self._before()
     764        #self._expect_expr()
     765        #out = self._before()
     766        #
     767        # if error_check:
     768        #     self._error_check(line, pre_out)
     769        #     self._error_check(line, out)
     770        #
     771        # if not reformat:
     772        #     return out
     773        #
     774        # r = self._output_prompt_re
     775        # m = r.search(out)
     776        # if m is None:
     777        #     o = out[:-2]
     778        # else:
     779        #     o = out[m.end()+1:-2]
     780        # o = ''.join([x.strip() for x in o.split()])
     781        # return o
     782        #
     783        # i = o.rfind('(%o')
     784        # return o[:i]
    760785
     786        self._expect_expr(self._display_prompt)   
     787        out = self._before()        # input echo + output prompt + output
    761788        if error_check:
    762             self._error_check(line, pre_out)
    763789            self._error_check(line, out)
    764        
     790
    765791        if not reformat:
    766792            return out
    767        
     793
     794        self._expect_expr()
     795        assert len(self._before())==0, 'Maxima expect interface is confused!'
     796
    768797        r = self._output_prompt_re
    769798        m = r.search(out)
    770799        if m is None:
     
    774803        o = ''.join([x.strip() for x in o.split()])
    775804        return o
    776805
    777         i = o.rfind('(%o')
    778         return o[:i]
    779 
    780 
     806       
    781807    def _synchronize(self):
    782808        """
    783809        Synchronize pexpect interface.
     
    882908            p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
    883909                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    884910            res = p.stdout.read()
    885             # we are now getting three lines of commented verbosity
     911            # we are now getting five lines of commented verbosity
    886912            # every time Maxima starts, so we need to get rid of them
    887             for _ in range(3):
     913            for _ in range(5):
    888914                res = res[res.find('\n')+1:]
    889915            return AsciiArtString(res)
    890916        else:
     
    12401266        EXAMPLES::
    12411267       
    12421268            sage: maxima.version()
    1243             '5.20.1'
     1269            '5.22.1'
    12441270        """
    12451271        return maxima_version()
    12461272