""" Evaluates a given set of MAGMA commands using http://magma.maths.usyd.edu.au/calc/ the free online MAGMA calculator. AUTHOR: Martin Albrecht """ import urllib def magma_remote_eval(cmd): """ Evaluates cmd using http://magma.maths.usyd.edu.au/calc/ . No state is preserved remotely so all definitions must be in one command. Also the remote execution is terminated after 20 seconds. EXAMPLES: sage: s = 'R := PolynomialRing(GF(2^8));\n f := x^2 + x; f' sage: magma_remote_eval(s) 'x^2 + x' TODO: It could be possible to provide a full backend for SAGE's Magma class using this approach. Is this a copyright problem? """ start_string = "" url = "http://magma.maths.usyd.edu.au/calc/?input=%s"%urllib.quote(cmd) fp = urllib.urlopen(url) answer = fp.read() i = answer.index(start_string) j = answer.rindex(end_string) answer = answer[i+len(start_string):j] answer = answer.splitlines() return "\n".join(answer[3:-2]) # strip MAGMA version string etc.