예제 #1
0
    def _eval_line(self,
                   line,
                   allow_use_file=True,
                   wait_for_prompt=True,
                   restart_if_needed=False):
        """
        EXAMPLES::

            sage: giac._eval_line('2+2')
            '4'

            sage: A = matrix([range(280)])
            sage: GA = giac(A)

        TESTS::

            sage: h1 = 'int(sin(x)^2, x)'
            sage: h2 = 'int(cos(x)^2, x)'
            sage: giac_result = giac(h1) + giac(h2)
            sage: bool(giac_result.sage() == x)
            True

        """
        with gc_disabled():
            z = Expect._eval_line(self,
                                  line,
                                  allow_use_file=allow_use_file,
                                  wait_for_prompt=wait_for_prompt)
            if z.lower().find("error") != -1:
                raise RuntimeError(
                    "An error occurred running a Giac command:\nINPUT:\n%s\nOUTPUT:\n%s"
                    % (line, z))
        lines = (line for line in z.splitlines()
                 if not line.startswith('Evaluation time:'))
        return "\n".join(lines)
예제 #2
0
    def _eval_line(self, line, reformat=True, allow_use_file=False,
                   wait_for_prompt=True, restart_if_needed=False):
        """
        EXAMPLES::

            sage: print octave._eval_line('2+2')  #optional - octave
              ans =  4
        """
        if not wait_for_prompt:
            return Expect._eval_line(self, line)
        if line == '':
            return ''
        if self._expect is None:
            self._start()
        if allow_use_file and len(line)>3000:
            return self._eval_line_using_file(line)
        try:
            E = self._expect
            verbose("in = '%s'"%line,level=3)
            E.sendline(line)
            E.expect(self._prompt)
            out = E.before
            verbose("out = '%s'"%out,level=3)
        except EOF:
            if self._quit_string() in line:
                return ''
        except KeyboardInterrupt:
            self._keyboard_interrupt()
        if reformat:
            if '>>> ' in out and 'syntax error' in out:
                raise SyntaxError(out)
        out = "\n".join(out.splitlines()[1:])
        return out
예제 #3
0
파일: mathematica.py 프로젝트: yjjcc/sage
 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')
예제 #4
0
파일: giac.py 프로젝트: thalespaiva/sagelib
    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True):
        """
        EXAMPLES::

            sage: giac._eval_line('2+2')  # optional - giac
            '4'
        """
        with gc_disabled():
            z = Expect._eval_line(self, line, allow_use_file=allow_use_file,
                    wait_for_prompt=wait_for_prompt)
            if z.lower().find("error") != -1:
                raise RuntimeError, "An error occurred running a Giac command:\nINPUT:\n%s\nOUTPUT:\n%s"%(line, z)
        return z
예제 #5
0
파일: giac.py 프로젝트: BlairArchibald/sage
    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
        """
        EXAMPLES::

            sage: giac._eval_line('2+2')  # optional - giac
            '4'

            sage: A=matrix([range(280)])  # optional - giac
            sage: GA=giac(A)              # optional - giac
        """
        with gc_disabled():
            z = Expect._eval_line(self, line, allow_use_file=allow_use_file,
                    wait_for_prompt=wait_for_prompt)
            if z.lower().find("error") != -1:
                raise RuntimeError("An error occurred running a Giac command:\nINPUT:\n%s\nOUTPUT:\n%s"%(line, z))
        return z
예제 #6
0
파일: giac.py 프로젝트: yjjcc/sage
    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
        """
        EXAMPLES::

            sage: giac._eval_line('2+2')
            '4'

            sage: A=matrix([range(280)])
            sage: GA=giac(A)
        """
        with gc_disabled():
            z = Expect._eval_line(self, line, allow_use_file=allow_use_file,
                    wait_for_prompt=wait_for_prompt)
            if z.lower().find("error") != -1:
                raise RuntimeError("An error occurred running a Giac command:\nINPUT:\n%s\nOUTPUT:\n%s"%(line, z))
        return z
예제 #7
0
파일: giac.py 프로젝트: timgates42/sage
    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
        """
        EXAMPLES::

            sage: giac._eval_line('2+2')
            '4'

            sage: A = matrix([range(280)])
            sage: GA = giac(A)

        TESTS::

            sage: h='int(1/x*((-2*x^(1/3)+1)^(1/4))^3,x)'
            sage: giac(h)
            12*(...)
        """
        with gc_disabled():
            z = Expect._eval_line(self, line, allow_use_file=allow_use_file,
                    wait_for_prompt=wait_for_prompt)
            if z.lower().find("error") != -1:
                raise RuntimeError("An error occurred running a Giac command:\nINPUT:\n%s\nOUTPUT:\n%s"%(line, z))
        lines = (line for line in z.splitlines()
                 if not line.startswith('Evaluation time:'))
        return "\n".join(lines)
예제 #8
0
파일: mathematica.py 프로젝트: Babyll/sage
 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')