On May 14, 2009, at 12:25 PM, RALPH THOMAS wrote:

> What I would like to do is have page(form) come up in a browser
> that would let the user enter a lets say an equation then Sage  
> would solve the equation and show the answer.  Or an integral then  
> Sage would calculate the value and display the solution.
>
> Is this doable with your script?

Yes, that is very doable. You might want to be careful about  
sanitizing the input if you're going to be exposing this to the web  
though, i.e. never pass the user's strings right into the code  
parameter.

> PHP, javascript, etc.

Just translate the script below into PHP. Imagine allow_url_fopen is  
on. Then one would have

$login_page = file_get_contents("http://localhost:$notebook_server: 
$notebook_port/simple/login?username=admin&password=$password' )
preg_match('.*"session": "([^"]*)"', $login_page, $matches)
$session = $matches[1]
...

- Robert

>
>
>
> Ralph
>
>
>
>
>
>
> > CC: rthomas...@msn.com
> > From: rober...@math.washington.edu
> > Subject: Re: twist.py
> > Date: Thu, 14 May 2009 11:15:47 -0700
> > To: sage-support@googlegroups.com
> >
> > On May 14, 2009, at 9:27 AM, RALPH THOMAS wrote:
> >
> > > Here is what I put into Sage
> > > -----------------------------------------------------------
> > > sage: from sage.server.misc import find_next_available_port
> > > sage: port = find_next_available_port(7777, verbose=False)
> > > sage: from sage.server.notebook.notebook_object import  
> test_notebook
> > > sage: passwd = str(randint(1,1<<128))
> > > sage: nb = test_notebook(passwd, secure=False,  
> address='localhost',
> > > port=port, verbose=True) #doctest: +ELLIPSIS
> > > sage: import urllib, re
> > > sage: def get_url(url): h = urllib.urlopen(url); data = h.read();
> > > h.close(); return data
> > > sage: sleep(1)
> > > sage: login_page = get_url('http://localhost:%s/simple/login?
> > > username=admin&password=%s' % (port, passwd))
> > > sage: print login_page # random session id
> > > sage: session = re.match(r'.*"session": "([^"]*)"', login_page,
> > > re.DOTALL).groups()[0]
> > > sage: sleep(0.5)
> > > sage: print get_url('http://localhost:%s/simple/compute?session=%
> > > s&code=2*2' % (port, session))
> > > sage: n = factorial(10)
> > > sage: print get_url('http://localhost:%s/simple/compute?session=%
> > > s&code=factor(%s)&timeout=0.1' % (port, session, n))
> > > sage: print get_url('http://localhost:%s/simple/status?session=%
> > > s&cell=2' % (port, session))
> > > sage: _ = get_url('http://localhost:%s/simple/interrupt?session= 
> %s'
> > > % (port, session))
> > > sage: code = "h = open('a.txt', 'w'); h.write('test'); h.close()"
> > > sage: print get_url('http://localhost:%s/simple/compute?session=%
> > > s&code=%s' % (port, session, urllib.quote(code)))
> > > sage: print get_url('http://localhost:%s/simple/file?session=%
> > > s&cell=3&file=a.txt' % (port, session))
> > > sage: _ = get_url('http://localhost:%s/simple/logout?session=%s' %
> > > (port, session))
> > > sage: nb.dispose()
> > >  
> ----------------------------------------------------------------------
> > > ---------------------
> > > And all the calculations are accomplished. (2*2, factorial,  
> text file)
> > > Now what do I do to get the Sage calculation into a html page?
> >
> > That depends on what you're trying to do, e.g. are you serving up
> > webpages using php? Another Python program? Something else?
> > Basically, you can "get" the same series of url's in any programming
> > language.
> >
> > - Robert
> >


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to