Tuesday, April 12, 2005

Python CGI Scripting

I want the ability to call a python CGI script and run a specific
function from within the script. The os.environ variable has a key
called 'REQUEST_URI'. This contains the URI with which the script was
called. Here is some code I worked out:
import os, string

print 'Content-Type: text/html'
print

def test_func():
print 'Running test function'

str_list = os.environ['REQUEST_URI']
func_call = string.split(str_list, '/')

if (len(func_call) > 3):
if (func_call[3] == 'test'):
test_func()
else:
print 'Unknown method called'
else:
print 'Called without an argument'

So now if your script resides in cgi-bin folder, and you call
http://somehost.somewhere.com/cgi-bin/test.py/test, the test_func()
call should go through.

Now I have to figure out if there is a way to tie the python script with XMLHttpRequest. Why do I want to that?
The user requests a page from the server, which is built and delivered to the browser. This page includes an HTML form element for capturing data from the user. Once the user posts their input back to the server, the next page can be built and served based on the input, and so the process continues. This is largely dictated by the nature of HTTP and differs from the traditional desktop application model of an interface which is inherently connected to the application layer.
...
A solution to these problem presents itself in the form of the XMLHttpRequest object. This object, first implemented by Microsoft as an ActiveX object but now also available as a native object within both Mozilla and Apple's Safari browser, enables JavaScript to make HTTP requests to a remote server without the need to reload the page. In essence, HTTP requests can be made and responses received, completely in the background and without the user experiencing any visual interruptions.

This is a tremendous boon, as it takes the developer a long way towards achieving the goals of both a responsive user interface and keeping all the important logic in the application layer. By using JavaScript to ferry input back to the server in real time, the logic can be performed on the server and the response returned for near-instant feedback.

from XML.com: Very Dynamic Web Interfaces

Mozilla and hypocrisy

Right, but what about the experiences that Mozilla chooses to default for users like switching to  Yahoo and making that the default upon ...