CoCalc Shared Fileswww / calc / calc / democalc.pyOpen in CoCalc with one click!
Author: William A. Stein
1
#!/usr/bin/python
2
# calc.py
3
# Original Author: William Stein, 2003
4
# Modified: Tom Boothby, 2006
5
# Released under GPL, etc.
6
# If the input is valid render the page.
7
8
import os, cgi, string, time, sys, sage
9
10
def fix_backslashes(s):
11
s = s.replace("\r","")
12
s = s.replace("\\\n","")
13
# Remove remaining backslashes, because in PARI one could type
14
# "sys\\[spaces]\r\ntem" and get around the above. By
15
# adding the following, this possibility is removed.
16
# (However, this breaks the "\" operator in PARI, which means
17
# divide and take the remainder.)
18
s = s.replace("\\","")
19
return s
20
21
form = cgi.FieldStorage()
22
23
if form.has_key("input") and form["input"].value.find("IsUninstall") != -1:
24
print "What is this nonsense?"
25
sys.exit(1)
26
27
if form.has_key("input"):
28
input = form["input"].value
29
input = fix_backslashes(input)
30
31
print "Content-Type: text/html" # HTML is following
32
print # blank line, end of headers
33
34
print "<pre>"
35
print sage.sage(input)
36
print "</pre>"
37