diff -uNr sajax-0.9/Changes.txt sajax-0.10/Changes.txt --- sajax-0.9/Changes.txt Tue Mar 15 01:09:54 2005 +++ sajax-0.10/Changes.txt Mon Mar 21 19:35:36 2005 @@ -1,6 +1,20 @@ SAJAX CHANGELOG --------------- +Sajax version 0.10 (March 21, 2005) + +* [php] Support for POST instead of just GET. Set $sajax_request_type. + Based on code from Folletto Malefico, to whom I owe thanks. + POST mode should be used if you are sending long requests (more + than 512 bytes) or if you are modifying data with the request. +* [php] (untested) Support for GET/POST to pages other than $REQUEST_URI. + Set $sajax_remote_uri to the desired URL to get this behavior. +* [php] Small fixes to the Wall example, thanks to Leonardo Lorieri + and Jesse Sightler. +* [cf] Cold Fusion MX support (Thanks Eric Moritz) +* [asp] ASP support (Thanks Jared Nuzzolillo) +* [python] Improvements to the Python backend from Adam Collard + Sajax version 0.9 (March 15, 2005) * [php] Major changes to the PHP backend: diff -uNr sajax-0.9/Todo.txt sajax-0.10/Todo.txt --- sajax-0.9/Todo.txt Wed Mar 16 20:55:26 2005 +++ sajax-0.10/Todo.txt Mon Mar 21 18:49:01 2005 @@ -1,10 +1,13 @@ SAJAX TO DO LIST ---------------- +* Make the whole darn thing an object +* Encode array elements +* Fix Perl module (with the contributed code) +* Add J2EE module +THINGS THAT WERE TO DO AND ARE NOW TO DONE +------------------------------------------ * Added sajax_set_remote_url or something along those lines instead of $REQUEST_URI * Support POST -* Make the whole darn thing an object -* Encode array elements -* Fix Perl module (with the contributed code) -* Add CFML, ASP.Net, J2EE module +* Add CFML, ASP.Net diff -uNr sajax-0.9/asp/Readme.txt sajax-0.10/asp/Readme.txt --- sajax-0.9/asp/Readme.txt Wed Dec 31 19:00:00 1969 +++ sajax-0.10/asp/Readme.txt Mon Mar 21 18:36:14 2005 @@ -0,0 +1,4 @@ +SAJAX ASP(JScript) BACKEND +-------------------------- + +Contributed and copyighted by Jared Nuzzolillo (http://www.protoscript.net/). diff -uNr sajax-0.9/asp/example_multiply.asp sajax-0.10/asp/example_multiply.asp --- sajax-0.9/asp/example_multiply.asp Wed Dec 31 19:00:00 1969 +++ sajax-0.10/asp/example_multiply.asp Fri Mar 18 13:44:16 2005 @@ -0,0 +1,77 @@ +<%@ Language=JScript %> + + +<% + + function multiply(x, y) { + return x * y; + } + + function add(x, y, z) { + return x + y + z; + } + + sajax = new Sajax(); +// sajax.debug_mode = true; + sajax.export_function("multiply","add"); + sajax.handle_client_request(); + +%> + + + Multiplier + + + + + * + + = + + +
+ try adding some strings, eg: + + + + + + + + = + + + + diff -uNr sajax-0.9/asp/sajax.asp sajax-0.10/asp/sajax.asp --- sajax-0.9/asp/sajax.asp Wed Dec 31 19:00:00 1969 +++ sajax-0.10/asp/sajax.asp Fri Mar 18 13:43:12 2005 @@ -0,0 +1,186 @@ +<% + +function r(str) +{ + Response.write("
-"+str+"-
") +} + + function Sajax(debug_mode) + { + this.debug_mode = debug_mode||false; + this.export_list = []; + this.js_has_been_shown = false; + + this.handle_client_request = function() + { + func_name = Request.QueryString("rs"); + if(!func_name||String(func_name)=="undefined") return false + + //bust cache + Response.AddHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT") + //always modified + Response.AddHeader("Last-Modified", new Date().toGMTString().replace(/UTC/,"GMT")) + //HTTP/1.1 + Response.AddHeader("Cache-Control", "no-cache, must-revalidate") + //HTTP/1.0 + Response.AddHeader("Pragma", "no-cache") + + + + if(this.export_list[func_name]=="undefined") + { + result = "-"+func_name+" is not callable"; + //if(this.debug_mode) Response.write("-"+func_name+" is not callable"); + } + else + { + rsargs_raw = Request.QueryString("rsargs[]") + + rsargs = [] + for(rs_i=1;rs_i<=rsargs_raw.Count;rs_i++) + { + rsargs[rs_i-1]=rsargs_raw(rs_i) + } + + // if(this.debug_mode) Response.write("calling " + func_name + "(" + + // rsargs.join(",")+")") + + eval_str = this.export_list[func_name]+"("+rsargs+")" + + try + { + result = "+"+eval(eval_str); + } + catch(e) + { + result = "-"+e.message+" (x_"+eval_str+")"; + } + } + + Response.write(result+"[sajax_result________end]]") + //exit() + } + + this.show_common_js = function() + { + js_debug_mode = this.debug_mode + js_string_out = " // remote scripting library\n" + + " // (c) copyright 2005 modernmethod, inc\n" + + " var rs_debug_mode = "+js_debug_mode+";\n" + + " var rs_obj = false;\n" + + " var rs_callback = false;\n" + + " \n" + + " function rs_debug(text) {\n" + + " if (rs_debug_mode)\n" + + " alert('RSD: ' + text)\n" + + " }\n" + + " \n" + + " function rs_init_object() {\n" + + " rs_debug('rs_init_object() called..')\n" + + " \n" + + " var A;\n" + + " try {\n" + + " A=new ActiveXObject('Msxml2.XMLHTTP');\n" + + " } catch (e) {\n" + + " try {\n" + + " A=new ActiveXObject('Microsoft.XMLHTTP');\n" + + " } catch (oc) {\n" + + " A=null;\n" + + " }\n" + + " }\n" + + " if(!A && typeof XMLHttpRequest != 'undefined')\n" + + " A = new XMLHttpRequest();\n" + + " if (!A)\n" + + " rs_debug('Could not create connection object.');\n" + + " return A;\n" + + " }\n" + + Response.write(js_string_out) + } + + this.rs_esc=function(val) + { + + } + + this.export_function = function() + { + for(var i=0;i-1)) + { + uri += "?rs=" + escape(func_name) + } + else + { + uri += "&rs=" + escape(func_name) + } + + escapeduri = this.rs_esc(uri) + js_string_out = " // wrapper for "+func_name+"\n" + + " function x_"+func_name+"(){\n" + + " // count args; build URL\n" + + " var i, x, n;\n" + + " //var url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" + + " url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" + + " for (i = 0; i < a.length-1; i++)\n" + + " url = url + '&rsargs[]=' + escape(a[i]);\n" + + " x = rs_init_object();\n" + + " x.open('GET', url, true);\n" + + " x.onreadystatechange = function() {\n" + + " if (x.readyState != 4)\n" + + " return;\n" + + " rs_debug('received ' + x.responseText);\n" + + " \n" + + " var status;\n" + + " var data;\n" + + " status = x.responseText.charAt(0);\n" + + " data = x.responseText;\n" + + " var pos = data.indexOf('[sajax_result________end]]');\n " + + " if (status == '-'){\n" + + " if("+this.debug_mode+"){alert('Error: ' + data.substring(1,pos));}}\n" + + " else \n" + + " a[a.length-1](data.substring(1,pos));\n" + + " }\n" + + " x.send(null);\n" + + " rs_debug('x_"+func_name+" url = ' + url);\n" + + " rs_debug('x_"+func_name+" waiting..');\n" + + " }\n" + + Response.write(js_string_out) + } + } +%> \ No newline at end of file diff -uNr sajax-0.9/coldfusion/Readme.txt sajax-0.10/coldfusion/Readme.txt --- sajax-0.9/coldfusion/Readme.txt Wed Dec 31 19:00:00 1969 +++ sajax-0.10/coldfusion/Readme.txt Mon Mar 21 18:34:39 2005 @@ -0,0 +1,5 @@ +SAJAX COLDFUSION MX BACKEND +--------------------------- + +Contributed by Eric Moritz. + diff -uNr sajax-0.9/coldfusion/example_multiply.cfm sajax-0.10/coldfusion/example_multiply.cfm --- sajax-0.9/coldfusion/example_multiply.cfm Wed Dec 31 19:00:00 1969 +++ sajax-0.10/coldfusion/example_multiply.cfm Fri Mar 18 10:58:50 2005 @@ -0,0 +1,44 @@ + + + function multiply(x, y) { + return x * y; + } + + sajax_init(); + //sajax_debug_mode = 1;: + sajax_export("multiply"); + sajax_handle_client_request(); + + + + + + Multiplier + + + + + + * + + = + + + + diff -uNr sajax-0.9/coldfusion/sajax.cfm sajax-0.10/coldfusion/sajax.cfm --- sajax-0.9/coldfusion/sajax.cfm Wed Dec 31 19:00:00 1969 +++ sajax-0.10/coldfusion/sajax.cfm Fri Mar 18 10:59:50 2005 @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + uri = cgi.query_string; + if (find(uri,"?") gt 0) + uri = uri & "?rs=" & urlencodedformat(func_name); + else + uri = uri & "&rs=" & urlencodedformat(func_name); + uri = cgi.script_name & uri; + + + + // wrapper for #func_name# + + function x_#func_name#() { + // count args; build URL + + sajax_do_call("#func_name#", + "#sajax_esc(uri)#", + x_#func_name#.arguments); + } + + + + + // remote scripting library + // (c) copyright 2005 modernmethod, inc + var sajax_debug_mode = #iif(sajax_debug_mode,'"true"','"false"')#; + + function sajax_debug(text) { + if (sajax_debug_mode) + alert("RSD: " + text) + } + function sajax_init_object() { + sajax_debug("sajax_init_object() called..") + + var A; + try { + A=new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + A=new ActiveXObject("Microsoft.XMLHTTP"); + } catch (oc) { + A=null; + } + } + if(!A && typeof XMLHttpRequest != "undefined") + A = new XMLHttpRequest(); + if (!A) + sajax_debug("Could not create connection object."); + return A; + } + function sajax_do_call(func_name, url, args) { + var i, x, n,responseText; + url = url + "&rsargs="; + for (i = 0; i < args.length-1; i++) + url = url + escape(args[i]) + escape("#JSStringFormat(sajax_url_array_delim)#"); + url = url + "&rsrnd=" + new Date().getTime(); + x = sajax_init_object(); + x.open("GET", url, true); + x.onreadystatechange = function() { + if (x.readyState != 4) + return; + responseText = x.responseText.replace(/^\s+/,''); // remove leading space, cf loves to put extra whitespace. + sajax_debug("received " + responseText); + + var status; + var data; + status = responseText.charAt(0); + data = responseText.substring(1); + if (status == "-") + alert("Error: " + data); + else + args[args.length-1](data); + } + x.send(null); + sajax_debug(func_name + " url = " + url); + sajax_debug(func_name + " waiting.."); + delete x; + } + + + + + + var func_name=""; + var result=0; + + + + + + + if(not isdefined("url.rs")) + return; + + func_name = url['rs']; + if(not ListFindNoCase(sajax_export_list, func_name)) + writeoutput("-:#func_name# not callable"); + else { + writeoutput("+"); + if(not isdefined("url.rsargs")) + result = call_user_func(url['rs']); + else + result = call_user_func_array(url['rs'], get_url_array(url['rsargs'])); + if(isdefined("result")) + writeoutput(result); + } + if(sajax_test_mode eq 0) + exit(); + + +#output# + +-#cfcatch.type# + #cfcatch.message# + #cfcatch.detail# + + in #cfcatch.tagcontext[1].template# at #cfcatch.tagcontext[1].line# + + + + + + + + sajax_debug_mode = 0; +sajax_test_mode = 0; +sajax_export_list = ""; +sajax_url_array_delim = chr(31); +function call_user_func(user_func) { + return(call_user_func_array(user_func,arraynew(1))); +} +function sajax_export() { + var keys = structkeylist(arguments); + var size = listlen(keys); + var key = ""; + + for(i =1; i lte size;i=i+1) { + key = listgetat(keys,i); + sajax_export_list = listappend(sajax_export_list,arguments[key]); + } +} +function call_user_func_array(user_func, arg_array) { + var func_call = ""; + var func_args = ""; + var size = ArrayLen(arg_array); + + /* Loop though each of the args */ + for(i=1; i lte size; i = i + 1) { + func_args = func_args & "arg_array[#i#]"; + if(i lt size) + func_args = func_args & ","; + } + + return(evaluate("#user_func#(#func_args#)")); +} +function get_url_array(url_array) { + return(ListToArray(url_array,sajax_url_array_delim)); +} + +function set_url_array(array) { + return(ArrayToList(array,sajax_url_array_delim)); +} + +function sajax_init() { +} + + + + + function sajax_show_common_js() { + sajax_get_common_js(); + } + + // javascript escape a value + function sajax_esc(val) + { + return(jsstringformat(val)); + } + + + function sajax_show_one_stub(func_name) { + sajax_get_one_stub(func_name); + } + + sajax_js_has_been_shown = 0; + function sajax_get_javascript() + { + if (not sajax_js_has_been_shown) { + sajax_get_common_js(); + sajax_js_has_been_shown = 1; + } + + size = listlen(sajax_export_list); + for(i = 1; i lte size; i=i+1) { + func = listgetat(sajax_export_list,i); + sajax_get_one_stub(func); + } + } + + function sajax_show_javascript() + { + sajax_get_javascript(); + } + + SAJAX_INCLUDED = 1; + + + diff -uNr sajax-0.9/coldfusion/test_sajax.cfm sajax-0.10/coldfusion/test_sajax.cfm --- sajax-0.9/coldfusion/test_sajax.cfm Wed Dec 31 19:00:00 1969 +++ sajax-0.10/coldfusion/test_sajax.cfm Fri Mar 18 10:28:42 2005 @@ -0,0 +1,65 @@ + + + + function assert(v1,v2){ + writeoutput("#v1# = #v2#
"); + } + function test() { + return(42); + } + function test2(v) { + return(v); + } + function return_nothing() { + } + function make_error() { + a = 1 + "a"; // cause an error + } +
+ + + assert(call_user_func("test"),42); + foo = arraynew(1); + foo[1] = 42; + assert(call_user_func_array("test2",foo),foo[1]); + + + + foo = arraynew(1); + foo[1] = 1; + foo[2] = 2; + + a = set_url_array(foo); + a = get_url_array(a); + for(i = 1; i lte arraylen(foo);i=i+1) { + assert(foo[i],a[i]); + } + + + + sajax_export("test","test2","return_nothing","make_error"); + assert(sajax_export_list,"test,test2,return_nothing,make_error"); + + + + + sajax_test_mode = 1; + url.rs = "test"; + sajax_handle_client_request(); + + foo = arraynew(1); + foo[1] = 43; + + writeoutput("
"); + url.rs = "test2"; + url.rsargs = set_url_array(foo); + sajax_handle_client_request(); + + writeoutput("
"); + url.rs = "return_nothing"; + sajax_handle_client_request(); + + writeoutput("
"); + url.rs = "make_error"; + sajax_handle_client_request(); +
diff -uNr sajax-0.9/php/Sajax.php sajax-0.10/php/Sajax.php --- sajax-0.9/php/Sajax.php Tue Mar 15 01:03:43 2005 +++ sajax-0.10/php/Sajax.php Mon Mar 21 18:29:43 2005 @@ -1,34 +1,70 @@ @@ -43,6 +85,7 @@ // remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode = ; + var sajax_request_type = ""; function sajax_debug(text) { if (sajax_debug_mode) @@ -67,13 +110,33 @@ sajax_debug("Could not create connection object."); return A; } - function sajax_do_call(func_name, url, args) { + function sajax_do_call(func_name, args) { var i, x, n; - for (i = 0; i < args.length-1; i++) - url = url + "&rsargs[]=" + escape(args[i]); - url = url + "&rsrnd=" + new Date().getTime(); + var uri; + var post_data; + + uri = ""; + if (sajax_request_type == "GET") { + if (uri.indexOf("?") == -1) + uri = uri + "?rs=" + escape(func_name); + else + uri = uri + "&rs=" + escape(func_name); + for (i = 0; i < args.length-1; i++) + uri = uri + "&rsargs[]=" + escape(args[i]); + uri = uri + "&rsrnd=" + new Date().getTime(); + post_data = null; + } else { + post_data = "rs=" + escape(func_name); + for (i = 0; i < args.length-1; i++) + post_data = post_data + "&rsargs[]=" + escape(args[i]); + } + x = sajax_init_object(); - x.open("GET", url, true); + x.open(sajax_request_type, uri, true); + if (sajax_request_type == "POST") { + x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1"); + x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + } x.onreadystatechange = function() { if (x.readyState != 4) return; @@ -88,8 +151,8 @@ else args[args.length-1](data); } - x.send(null); - sajax_debug(func_name + " url = " + url); + x.send(post_data); + sajax_debug(func_name + " uri = " + uri + "/post = " + post_data); sajax_debug(func_name + " waiting.."); delete x; } @@ -111,24 +174,13 @@ } function sajax_get_one_stub($func_name) { - global $REQUEST_URI; - - $uri = $REQUEST_URI; - if (strpos($uri,"?") === false) - $uri .= "?rs=".urlencode($func_name); - else - $uri .= "&rs=".urlencode($func_name); - ob_start(); ?> // wrapper for function x_() { - // count args; build URL - sajax_do_call("", - "", x_.arguments); } @@ -172,6 +224,7 @@ { echo sajax_get_javascript(); } + $SAJAX_INCLUDED = 1; } diff -uNr sajax-0.9/php/Sajax.php.txt sajax-0.10/php/Sajax.php.txt --- sajax-0.9/php/Sajax.php.txt Tue Mar 15 01:03:43 2005 +++ sajax-0.10/php/Sajax.php.txt Mon Mar 21 18:29:43 2005 @@ -1,34 +1,70 @@ @@ -43,6 +85,7 @@ // remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode = ; + var sajax_request_type = ""; function sajax_debug(text) { if (sajax_debug_mode) @@ -67,13 +110,33 @@ sajax_debug("Could not create connection object."); return A; } - function sajax_do_call(func_name, url, args) { + function sajax_do_call(func_name, args) { var i, x, n; - for (i = 0; i < args.length-1; i++) - url = url + "&rsargs[]=" + escape(args[i]); - url = url + "&rsrnd=" + new Date().getTime(); + var uri; + var post_data; + + uri = ""; + if (sajax_request_type == "GET") { + if (uri.indexOf("?") == -1) + uri = uri + "?rs=" + escape(func_name); + else + uri = uri + "&rs=" + escape(func_name); + for (i = 0; i < args.length-1; i++) + uri = uri + "&rsargs[]=" + escape(args[i]); + uri = uri + "&rsrnd=" + new Date().getTime(); + post_data = null; + } else { + post_data = "rs=" + escape(func_name); + for (i = 0; i < args.length-1; i++) + post_data = post_data + "&rsargs[]=" + escape(args[i]); + } + x = sajax_init_object(); - x.open("GET", url, true); + x.open(sajax_request_type, uri, true); + if (sajax_request_type == "POST") { + x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1"); + x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + } x.onreadystatechange = function() { if (x.readyState != 4) return; @@ -88,8 +151,8 @@ else args[args.length-1](data); } - x.send(null); - sajax_debug(func_name + " url = " + url); + x.send(post_data); + sajax_debug(func_name + " uri = " + uri + "/post = " + post_data); sajax_debug(func_name + " waiting.."); delete x; } @@ -111,24 +174,13 @@ } function sajax_get_one_stub($func_name) { - global $REQUEST_URI; - - $uri = $REQUEST_URI; - if (strpos($uri,"?") === false) - $uri .= "?rs=".urlencode($func_name); - else - $uri .= "&rs=".urlencode($func_name); - ob_start(); ?> // wrapper for function x_() { - // count args; build URL - sajax_do_call("", - "", x_.arguments); } @@ -172,6 +224,7 @@ { echo sajax_get_javascript(); } + $SAJAX_INCLUDED = 1; } diff -uNr sajax-0.9/php/example_wall.php sajax-0.10/php/example_wall.php --- sajax-0.9/php/example_wall.php Tue Mar 15 00:57:44 2005 +++ sajax-0.10/php/example_wall.php Mon Mar 21 19:34:04 2005 @@ -26,16 +26,13 @@ } function refresh() { - $f = fopen("/tmp/wall.html", "r"); - $lines = array(); - while (!feof($f)) - $lines[] = fgets($f, 8192); + $lines = file("/tmp/wall.html"); // return the last 25 lines return join("\n", array_slice($lines, -25)); } + $sajax_request_type = "GET"; sajax_init(); - // $sajax_debug_mode = 1; sajax_export("add_line", "refresh"); sajax_handle_client_request(); @@ -85,6 +82,7 @@ +
Sajax - This example illustrates the simplest possible graffiti wall. @@ -99,6 +97,7 @@ onclick="add(); return false;">
Loading..
+
diff -uNr sajax-0.9/php/example_wall.php.txt sajax-0.10/php/example_wall.php.txt --- sajax-0.9/php/example_wall.php.txt Tue Mar 15 00:57:44 2005 +++ sajax-0.10/php/example_wall.php.txt Mon Mar 21 19:34:04 2005 @@ -26,16 +26,13 @@ } function refresh() { - $f = fopen("/tmp/wall.html", "r"); - $lines = array(); - while (!feof($f)) - $lines[] = fgets($f, 8192); + $lines = file("/tmp/wall.html"); // return the last 25 lines return join("\n", array_slice($lines, -25)); } + $sajax_request_type = "GET"; sajax_init(); - // $sajax_debug_mode = 1; sajax_export("add_line", "refresh"); sajax_handle_client_request(); @@ -85,6 +82,7 @@ +
Sajax - This example illustrates the simplest possible graffiti wall. @@ -99,6 +97,7 @@ onclick="add(); return false;">
Loading..
+
diff -uNr sajax-0.9/python/License.txt sajax-0.10/python/License.txt --- sajax-0.9/python/License.txt Wed Mar 9 18:57:17 2005 +++ sajax-0.10/python/License.txt Mon Mar 7 09:44:17 2005 @@ -1,4 +1 @@ -This work is licensed under the Creative Commons Attribution License. To -view a copy of this license, visit -http://creativecommons.org/licenses/by/2.0/ or send a letter to Creative -Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. +This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. diff -uNr sajax-0.9/python/multiply.py sajax-0.10/python/multiply.py --- sajax-0.9/python/multiply.py Wed Mar 9 18:57:17 2005 +++ sajax-0.10/python/multiply.py Fri Mar 18 03:44:50 2005 @@ -9,29 +9,27 @@ return 0 return float_x * float_y -sajax1.init() -sajax1.export(multiply) -sajax1.handle_client_request() +sajax1.sajax_init() +sajax1.sajax_export(multiply) +sajax1.sajax_handle_client_request() print """ - PyMuptiplier + PyMultiplier @@ -42,7 +40,7 @@ = + onclick="do_multiply(); return false;"> -""" % locals() \ No newline at end of file +""" % locals() diff -uNr sajax-0.9/python/sajax1.py sajax-0.10/python/sajax1.py --- sajax-0.9/python/sajax1.py Wed Mar 9 18:57:17 2005 +++ sajax-0.10/python/sajax1.py Sun Mar 20 16:13:33 2005 @@ -8,52 +8,52 @@ print "Content-type: text/html" -debug_mode = False -export_list = {} -js_has_been_shown = False +sajax_debug_mode = False +sajax_export_list = {} +sajax_js_has_been_shown = False form = cgi.FieldStorage() -def init(): +def sajax_init(): pass -def handle_client_request(): +def sajax_handle_client_request(): func_name = form.getfirst('rs') if func_name is None: return # Bust cache in the head print "Expires: Mon, 26 Jul 1997 05:00:00 GMT" - print "Last-Modified: %s GMT" % datetime.datetime.utcnow().strftime("%a, %d %m %H:%M:%S")# always modified + print "Last-Modified: %s GMT" % datetime.datetime.utcnow().strftime( + "%a, %d %m %H:%M:%S") + # always modified print "Cache-Control: no-cache, must-revalidate" # HTTP/1.1 print "Pragma: no-cache" # HTTP/1.0 print - if not func_name in export_list: + if not func_name in sajax_export_list: print "-:%s not callable" % func_name else: print "+:", rsargs = form.getlist('rsargs[]') - result = export_list[func_name](*rsargs) + result = sajax_export_list[func_name](*rsargs) print result sys.exit() -def show_common_js(): - js_debug_mode = str(debug_mode).lower() - print """\ - // remote scripting library +def sajax_get_common_js(): + sajax_debug_modeJS = str(sajax_debug_mode).lower() + return """\ + // remote scripting library // (c) copyright 2005 modernmethod, inc - var rs_debug_mode = %(js_debug_mode)s; - var rs_obj = false; - var rs_callback = false; + var sajax_debug_mode = %(sajax_debug_modeJS)s; - function rs_debug(text) { - if (rs_debug_mode) + function sajax_debug(text) { + if (sajax_debug_mode) alert("RSD: " + text) } - function rs_init_object() { - rs_debug("rs_init_object() called..") + function sajax_init_object() { + sajax_debug("sajax_init_object() called..") var A; try { @@ -68,63 +68,82 @@ if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) - rs_debug("Could not create connection object."); + sajax_debug("Could not create connection object."); return A; } + function sajax_do_call(func_name, url, args) { + var i, x, n; + for (i = 0; i < args.length-1; i++) + url = url + "&rsargs[]=" + escape(args[i]); + url = url + "&rsrnd=" + new Date().getTime(); + x = sajax_init_object(); + x.open("GET", url, true); + x.onreadystatechange = function() { + if (x.readyState != 4) + return; + sajax_debug("received " + x.responseText); + + var status; + var data; + status = x.responseText.charAt(0); + data = x.responseText.substring(2); + if (status == "-") + alert("Error: " + data); + else + args[args.length-1](data); + } + x.send(null); + sajax_debug(func_name + " url = " + url); + sajax_debug(func_name + " waiting.."); + delete x; + } """ % locals() - -def escape(val): +def sajax_show_common_js(): + print sajax_get_common_js() + +def sajax_esc(val): return val.replace('"', '\\\\"') -def show_one(func_name): - uri = os.environ['REQUEST_URI'] - if uri.find('?') == -1: - uri += "?rs=%s" % urllib.quote_plus(func_name) +def sajax_get_one_stub(func_name): + uri = os.environ['SCRIPT_NAME'] + if os.environ.has_key('QUERY_STRING'): + uri += "?" + os.environ['QUERY_STRING'] + "&rs=%s" % urllib.quote_plus(func_name) else: - uri += "&rs=%s" % urllib.quote_plus(func_name) - escapeduri = escape(uri) - print """ + uri += "?rs=%s" % urllib.quote_plus(func_name) + + escapeduri = sajax_esc(uri) + return """ // wrapper for %(func_name)s function x_%(func_name)s(){ // count args; build URL - var i, x, n; - var url = "%(escapeduri)s", a = x_%(func_name)s.arguments; - for (i = 0; i < a.length-1; i++) - url = url + "&rsargs[]=" + escape(a[i]); - x = rs_init_object(); - x.open("GET", url, true); - x.onreadystatechange = function() { - if (x.readyState != 4) - return; - rs_debug("received " + x.responseText); - - var status; - var data; - status = x.responseText.charAt(0); - data = x.responseText.substring(2); - if (status == "-") - alert("Error: " + callback_n); - else - a[a.length-1](data); - } - x.send(null); - rs_debug("x_%(func_name)s url = " + url); - rs_debug("x_%(func_name)s waiting.."); + + sajax_do_call("%(func_name)s", + "%(escapeduri)s", + x_%(func_name)s.arguments); } """ % locals() -def export(*args): +def sajax_show_one_stub(func_name): + print sajax_get_one_stub(func_name) + +def sajax_export(*args): decorated = [(f.func_name, f) for f in args] - export_list.update(dict(decorated)) + sajax_export_list.update(dict(decorated)) -def show_javascript(): - global js_has_been_shown - if not js_has_been_shown: - show_common_js() - js_has_been_shown = True +def sajax_get_javascript(): + global sajax_js_has_been_shown + + html = '' + if not sajax_js_has_been_shown: + html += sajax_get_common_js() + sajax_js_has_been_shown = True - for func_name in export_list.iterkeys(): - show_one(func_name) + for func_name in sajax_export_list.iterkeys(): + html += sajax_get_one_stub(func_name) + + return html +def sajax_show_javascript(): + print sajax_get_javascript() diff -uNr sajax-0.9/python/wall.py sajax-0.10/python/wall.py --- sajax-0.9/python/wall.py Wed Mar 9 18:57:17 2005 +++ sajax-0.10/python/wall.py Sun Mar 20 16:01:46 2005 @@ -6,6 +6,12 @@ import sajax1 +WALLFILE = '/tmp/wall.html' + +if not os.path.exists(WALLFILE): + fh = open(WALLFILE, 'w') + fh.close() + def colourify_ip(ip): colour = ''.join(['%02x' % int(part) for part in ip.split('.')[-3:]]) return colour @@ -23,9 +29,9 @@ f = open("/tmp/wall.html") return '\n'.join(list(f)[-25:]) -sajax1.init() -sajax1.export(refresh, add_line) -sajax1.handle_client_request() +sajax1.sajax_init() +sajax1.sajax_export(refresh, add_line) +sajax1.sajax_handle_client_request() print """ @@ -33,7 +39,7 @@ PyWall