Changeset 77
- Timestamp:
- 11/07/06 16:55:23 (2 years ago)
- Files:
-
- branches/experimental/jsolait/jsolait.js (modified) (4 diffs)
- branches/experimental/jsolait/jsolait.wsf (modified) (5 diffs)
- branches/experimental/jsolait/lib/asyncimprt.js (deleted)
- branches/experimental/jsolait/lib/codecs.js (modified) (2 diffs)
- branches/experimental/jsolait/lib/crypto.js (modified) (2 diffs)
- branches/experimental/jsolait/lib/dom.js (modified) (8 diffs)
- branches/experimental/jsolait/lib/forms.js (modified) (13 diffs)
- branches/experimental/jsolait/lib/itertools.js (modified) (24 diffs)
- branches/experimental/jsolait/lib/jsonrpc.js (modified) (38 diffs)
- branches/experimental/jsolait/lib/lang.js (modified) (78 diffs)
- branches/experimental/jsolait/lib/logging.js (modified) (14 diffs)
- branches/experimental/jsolait/lib/operators.js (modified) (11 diffs)
- branches/experimental/jsolait/lib/sets.js (modified) (22 diffs)
- branches/experimental/jsolait/lib/strings.js (modified) (9 diffs)
- branches/experimental/jsolait/lib/testing.js (modified) (20 diffs)
- branches/experimental/jsolait/lib/urllib.js (modified) (16 diffs)
- branches/experimental/jsolait/lib/xml.js (modified) (12 diffs)
- branches/experimental/jsolait/lib/xmlrpc.js (modified) (49 diffs)
- branches/experimental/test/test.html (modified) (1 diff)
- branches/experimental/test/test.js (modified) (1 diff)
- branches/experimental/test/test_codecs.js (modified) (2 diffs)
- branches/experimental/test/test_core.js (modified) (4 diffs)
- branches/experimental/test/test_crypto.js (modified) (2 diffs)
- branches/experimental/test/test_itertools.js (modified) (3 diffs)
- branches/experimental/test/test_jsonrpc.js (modified) (2 diffs)
- branches/experimental/test/test_sets.js (modified) (2 diffs)
- branches/experimental/test/test_strings.js (modified) (2 diffs)
- branches/experimental/test/test_testing.js (modified) (2 diffs)
- branches/experimental/test/test_urllib.js (modified) (2 diffs)
- branches/experimental/test/test_xmlrpc.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/experimental/jsolait/jsolait.js
r75 r77 518 518 }); 519 519 520 /** 521 Retrieves data given its URI. 522 @param uri The uri to load. 523 @param headers=[] The headers to use. 524 @return The content of the file. 525 **/ 526 mod.loadURI=function(uri, headers){ 527 headers = (headers !== undefined) ? headers : []; 520 521 mod.loadURI=function(uri, cb){ 522 var errorNotHandled=true; 528 523 try{ 529 524 var xmlhttp = mod.getHTTPRequestObject(); 530 xmlhttp.open("GET", uri, false); 531 for(var i=0;i< headers.length;i++){ 532 xmlhttp.setRequestHeader(headers[i][0], headers[i][1]); 533 } 525 }catch(e){ 526 cb(null, new mod.LoadURIFailed(uri, new mod.Exception(uri,e))); 527 return; 528 } 529 530 xmlhttp.onreadystatechange=function(){ 531 if (xmlhttp.readyState==4) { 532 //todo: the status checking needs testing 533 if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ 534 var s= str(xmlhttp.responseText); 535 xmlhttp = null; 536 cb(s); 537 }else{ 538 if(errorNotHandled){ 539 errorNotHandled=false; 540 cb(null, new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status))); 541 } 542 } 543 xmlhttp=null; 544 }else if (xmlhttp.readyState==2){ 545 //status property should be available (MS IXMLHTTPRequest documentation) 546 //in Mozilla it is not if the request failed(server not reachable) 547 //in IE it is not available at all ?! 548 try{//see if it is mozilla otherwise don't care. 549 var isNetscape = netscape; 550 try{//if status is not available the request failed. 551 var s=xmlhttp.status; 552 }catch(e){//call the callback because Mozilla will not get to readystate 4 553 if(errorNotHandled){ 554 xmlhttp = null; 555 errorNotHandled=false; 556 cb(null, new mod.LoadURIFailed(uri, new mod.Exception("url request failed ",e))); 557 } 558 } 559 }catch(e){ 560 } 561 } 562 }; 563 564 try{ 565 xmlhttp.open("GET", uri, true); 534 566 xmlhttp.send(""); 535 567 }catch(e){ 536 throw new mod.LoadURIFailed(uri, e); 537 } 538 //todo: the status checking needs testing 539 if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ 540 var s= str(xmlhttp.responseText); 541 return s; 542 }else{ 543 throw new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status)); 544 } 545 }; 546 568 if(errorNotHandled){ 569 errorNotHandled=false; 570 xmlhttp=null; 571 cb (null, new mod.LoadURIFailed(uri, e)); 572 } 573 } 574 }; 575 547 576 548 577 /** … … 599 628 600 629 /** 601 Loads a module given its name(someModule.someSubModule) .630 Loads a module given its name(someModule.someSubModule) asynchronously. 602 631 jsolait.getSearchURIsForModuleName() will be used to determine the possible locations for the source of the module. 603 632 604 633 @param name The name of the module to load. 605 @return The module object. 606 **/ 607 mod.loadModule = function(name){ 634 @param loadedCB A callback which gets called (callback(module, error) 635 when the module is loaded or an error occurs. 636 **/ 637 mod.loadModule=function(name, loadedCB){ 608 638 609 639 if(mod.modules[name]){ //module already loaded 610 return mod.modules[name];640 loadedCB(mod.modules[name]); 611 641 }else{ 612 642 var src,sourceURI; 613 643 var searchURIs = mod.getSearchURIsForModuleName(name); 644 614 645 var failedURIs=[]; 615 for(var i=0;i<searchURIs.length;i++){ 616 try{ 617 sourceURI = searchURIs[i]; 618 src = mod.loadURI(sourceURI); 619 break; 646 var currentURI=''; 647 var i=0 648 var handler=function(src, err){ 649 if(err){ 650 failedURIs.push(currentURI);//err.sourceURI); 651 if(searchURIs.length){ 652 mod.loadURI(currentURI=searchURIs.shift(), handler); 653 }else{ 654 loadedCB(null, new mod.LoadModuleFailed(name, failedURIs)); 655 } 656 }else{ 657 mod.createModuleFromSource(name, src, currentURI, function(m, err){ 658 loadedCB(m, err); 659 }); 660 } 661 } 662 mod.loadURI(currentURI=searchURIs.shift(), handler); 663 } 664 }; 665 666 mod.createModuleFromSource =function(name, source, sourceURI, createdCB){ 667 var newMod = new mod.ModuleClass(name, source, sourceURI); 668 669 var cmpSrc = mod.compileSource(source); 670 671 var deps= cmpSrc.imports; 672 var source= 'with(mod){\n%s\n}'.format(cmpSrc.src); 673 674 var locals={ 675 str:str, 676 repr:repr, 677 id:id, 678 bind:bind, 679 isinstance:isinstance, 680 issubclass:issubclass, 681 Class:Class 682 }; 683 684 mod.resolveDependencies(deps, locals, function(locals, err){ 685 if(err){ 686 createdCB(newMod, err); 687 }else{ 688 689 var argNames = ['mod','imprt', 'jsolait']; 690 var args = []; 691 692 args.push(newMod); 693 args.push(new Function("","")); 694 args.push(mod); 695 696 for(var key in locals){ 697 argNames.push(key); 698 args.push(locals[key]); 699 } 700 701 try{//to run the module source 702 var modFn = new Function(argNames.join(","), source); 703 modFn.apply(newMod, args); 620 704 }catch(e){ 621 failedURIs.push(e.sourceURI); 622 } 623 } 624 if(src == null){ 625 throw new mod.LoadModuleFailed(name, failedURIs); 705 createdCB(newMod, new mod.CreateModuleFailed(newMod, e)); 706 return; 707 } 708 709 applyNames(newMod); 710 mod.modules[name] = newMod; 711 createdCB(newMod); 712 } 713 }); 714 }; 715 716 mod.resolveDependencies=function(deps, attachTo, resolvedCB){ 717 var step = function(name){ 718 var n=name.replace(/\s/g,"").split(":"); 719 name = n[0]; 720 if(n.length>1){ 721 var items = n[1].split(","); 626 722 }else{ 627 try{//interpret the script 628 var m = mod.createModuleFromSource(name, src, sourceURI); 629 return m; 630 }catch(e){ 631 throw new mod.LoadModuleFailed(name, [sourceURI], e); 632 } 633 } 634 } 635 }; 636 637 mod.__imprt__ = function(name, attachTo){ 638 var n=name.replace(/\s/g,"").split(":"); 639 name = n[0]; 640 if(n.length>1){ 641 var items = n[1].split(","); 642 }else{ 643 var items=[]; 644 } 645 646 var m = mod.loadModule(name); 647 648 if(items.length > 0){ 649 if(items[0] == '*'){ 650 for(var key in m){ 651 if(key.slice(0,2) != "__" && attachTo[key] == undefined){ 652 attachTo[key] = m[key]; 653 } 654 } 655 }else{ 656 for(var i=0;i<items.length;i++){ 657 attachTo[items[i]] = m[items[i]]; 658 } 659 } 660 }else{ 661 var finalModuleName=name.split('.'); 662 finalModuleName=finalModuleName.pop(); 663 attachTo[finalModuleName] = m; 664 } 665 }; 666 667 var StringsOrCommentsOrImprt=/(\/\*([\n\r]|.)*?\*\/)|(\/\/.*)|('(\\'|.)*?')|("(\\"|.)*?")|\b(imprt\(.*?\))/g; 668 var ImprtStatement=/^imprt\(['"](.*?)['"]\)$/; 669 670 mod.getModuleDependenciesFromSource=function(source){ 671 672 var imprtStatements=[]; 673 var items=str(source).match(StringsOrCommentsOrImprt); 674 if(items){ 675 for(var i=0;i<items.length;i++){ 676 var item = items[i]; 677 var imprtStatement=item.match(ImprtStatement); 678 if(imprtStatement){ 679 imprtStatements.push(imprtStatement[1]); 680 } 681 } 682 } 683 return imprtStatements; 684 }; 723 var items=[]; 724 } 725 726 mod.loadModule(name, function(m, err){ 727 if(err){ 728 resolvedCB(attachTo, err); 729 }else{ 730 731 if(items.length > 0){ 732 if(items[0] == '*'){ 733 for(var key in m){ 734 if(key.slice(0,2) != "__" && attachTo[key] == undefined){ 735 attachTo[key] = m[key]; 736 } 737 } 738 }else{ 739 for(var i=0;i<items.length;i++){ 740 attachTo[items[i]] = m[items[i]]; 741 } 742 } 743 }else{ 744 var finalModuleName=name.split('.'); 745 finalModuleName=finalModuleName.pop(); 746 attachTo[finalModuleName] = m; 747 } 748 749 if(deps.length){ 750 step(deps.shift()); 751 }else{ 752 resolvedCB(attachTo); 753 } 754 } 755 }); 756 }; 757 758 if(deps.length){ 759 step(deps.shift()); 760 }else{ 761 resolvedCB(attachTo); 762 } 763 }; 764 685 765 686 766 mod.ModuleClass=Class(function(publ,priv,supr){ … … 739 819 }; 740 820 741 mod.createModuleFromSource=function(name, source, sourceURI){742 var newMod = new mod.ModuleClass(name, source, sourceURI);743 744 var deps=mod.getModuleDependenciesFromSource(source);745 746 var locals={747 str:str,748 repr:repr,749 id:id,750 bind:bind,751 isinstance:isinstance,752 issubclass:issubclass,753 Class:Class754 };755 756 for(var i=0;i<deps.length;i++){757 mod.__imprt__(deps[i], locals);758 }759 760 var argNames = ['mod', 'imprt', 'jsolait'];761 var args = [];762 763 args.push(newMod);764 args.push(new Function("",""));765 args.push(mod);766 767 for(var key in locals){768 argNames.push(key);769 args.push(locals[key]);770 }771 772 var modFn = new Function(argNames.join(","), source);773 774 try{//to run the module source775 modFn.apply(newMod, args);776 }catch(e){777 throw new mod.CreateModuleFailed(newMod, e);778 }779 780 applyNames(newMod);781 mod.modules[name] = newMod;782 return newMod;783 };784 821 785 822 mod.Module = function(name, modFn){ 786 return mod.createModule(name, str(modFn), ' ', modFn);823 return mod.createModule(name, str(modFn), 'unknown', modFn); 787 824 }; 788 825 … … 796 833 }; 797 834 835 mod.compileSource=function(src){ 836 var or=function(){ 837 var a=[]; 838 for(var i=0;i<arguments.length;i++){ 839 a.push(grp(arguments[i])); 840 } 841 return a.join('|'); 842 } 843 844 var grp=function(a){ 845 return '(' + a + ')'; 846 } 847 848 var wrd=function(w){ 849 w= w.replace(/\\/g,'\\\\'); 850 w= w.replace(/\(/g,'\\('); 851 w= w.replace(/\)/g,'\\)'); 852 w= w.replace(/\//g,'\\/'); 853 w= w.replace(/\*/g,'\\*'); 854 w= w.replace(/\./g,'\\.'); 855 w= w.replace(/\]/g,'\\]'); 856 w= w.replace(/\[/g,'\\['); 857 w= w.replace(/\{/g,'\\{'); 858 w= w.replace(/\}/g,'\\}'); 859 860 return '\\b' + w + '\\b'; 861 }; 862 863 864 var parens= function(a){ 865 return '\\('+a+'\\)'; 866 } 867 868 var re=function(s){ 869 return new RegExp(s,'g'); 870 }; 871 872 var string=function(d){ 873 return d + '(\\\\'+d+'|.' + d + ')*?' ; 874 }; 875 876 var identifier=function(){ 877 return '\\w+'; 878 }; 879 880 var anyWhiteSpaceStart= grp('(^|[\\n\\r])\\s*') ; 881 var someWhiteSpaceStart= grp('(^|[\\n\\r])\\s*') ; 882 var startOfLine= grp('^|[\\n\\r]'); 883 884 var blockComment='/\\*([\\n\\r]|.)*?\\*/'; 885 886 var comment='//' + '.*' ; 887 888 var methodDecl= grp([wrd('function'), wrd('def'),wrd('publ')].join('|')) ; 889 890 var moduleFunctionStatement = startOfLine + methodDecl +'\\s+' +grp(identifier()) + '\\s*' + grp(parens('.*?')); 891 892 var classMethodStatement = someWhiteSpaceStart + methodDecl +'\\s+' +grp(identifier()) + '\\s*' + grp(parens('.*?')); 893 894 var classMember= someWhiteSpaceStart + wrd('publ')+ '\\s+' +grp(identifier()); 895 896 var classStatement = anyWhiteSpaceStart + wrd('class')+'\\s+' +grp(identifier()) + '\\s+' + wrd('extends') +'\\s+' + grp('.+?') + '\\(\\{'; 897 var simpleClassStatement = anyWhiteSpaceStart + wrd('class')+'\\s+' +grp(identifier()) + '\\s*\\(\\{'; 898 899 var importStatement = anyWhiteSpaceStart + wrd('import')+'\\s+' + grp('.+?') + '[\\r\\n;]'; 900 901 var iterStatement= anyWhiteSpaceStart + wrd('iter') + '\\s+' +grp(identifier())+ '\\s+' + wrd('in') + '\\s+' + grp('.+?') + '\\{'; 902 903 var modLevelAssignment=startOfLine +grp(identifier())+'\\s*='; 904 905 var modGlobaling =wrd('mod') + '\\s+' + grp(identifier()) +'\\s*='; 906 907 var tupleAssingnment ='\\s\\[' + grp('.*?') + '\\]\\s*=' + grp('.+?') + ';'; 908 909 910 var allStatments=re(or(blockComment, comment, string("'"), string('"'), 911 classStatement, simpleClassStatement, classMethodStatement, moduleFunctionStatement, 912 classMember,importStatement,iterStatement,modLevelAssignment,modGlobaling,tupleAssingnment)); 913 914 915 var Replacer=Class(function(publ,priv,supr){ 916 publ.__init__=function(match, repl){ 917 this.match=re(match); 918 this.replacement=repl; 919 }; 920 921 publ.run = function(a){ 922 if(a.match(this.match)){ 923 return a.replace(this.match, this.replacement); 924 }else{ 925 return null; 926 } 927 }; 928 }); 929 930 931 var compile=function(src){ 932 var replacers=[ 933 new Replacer(moduleFunctionStatement, '$1var $3 = mod.$3=function$4' ), 934 new Replacer(classMethodStatement, '$1publ.$4=function$5' ) , 935 new Replacer(classStatement, '$1var $3 = mod.$3=Class("$3", $4, function(publ,priv,supr){' ), 936 new Replacer(simpleClassStatement, '$1var $3 = mod.$3=Class("$3", function(publ,priv,supr){' ), 937 new Replacer(classMember, '$1publ.$3' ), 938 new Replacer(modLevelAssignment, '$1var $2 = mod.$2 =' ), 939 new Replacer(modGlobaling, '$1 = mod.$1 =' ) 940 ]; 941 942 var importRE=re(importStatement); 943 var iterRE =re(iterStatement); 944 var tupleRE =re(tupleAssingnment); 945 946 var imports=[]; 947 948 src =src.replace(allStatments, function(a){ 949 var reslt=null; 950 951 952 for(var i=0;i<replacers.length;i++){ 953 rslt=replacers[i].run(a); 954 if(rslt!=null){ 955 return rslt; 956 }else{ 957 if(a.match(importRE)){ 958 imports.push(RegExp.$3); 959 return '/*' + a + '*/'; 960 }else if(a.match(iterRE)){ 961 imports.push('itertools:iter'); 962 963 return a.replace(iterRE, "$1for(var $3, _$3_iterator_= iter($4); ($3=_$3_iterator_.next())!== undefined;){"); 964 }else if(a.match(tupleRE)){ 965 var names= RegExp.$1; 966 var expr= RegExp.$2; 967 968 names = names.replace(/\s/g,'').split(','); 969 var s =' var ' + names.join(',')+', _' + names.join('_') + '=' + expr +';' 970 for(var i=0;i<names.length;i++){ 971 s+=names[i] + '= _' + names.join('_') + '['+i+'];'; 972 } 973 return s; 974 } 975 } 976 } 977 return a; 978 }); 979 980 return {imports: imports, src:src}; 981 }; 982 var src = compile(src); 983 //print(src.src) 984 return src; 985 }; 986 987 988 989 mod.run=function(modName, methodName, alertError){ 990 mod.loadModule(modName, function(m, err){ 991 if(err){ 992 if(alertError){ 993 alert(err); 994 } 995 throw err; 996 }else{ 997 try{ 998 m[methodName].call(m); 999 }catch(e){ 1000 if(alertError){ 1001 alert(e); 1002 } 1003 throw e 1004 } 1005 } 1006 }); 1007 1008 }; 798 1009 //---------------------------------------------------String Format ------------------------------------------------------- 799 1010 /** branches/experimental/jsolait/jsolait.wsf
r74 r77 32 32 33 33 <script language="JavaScript"> <![CDATA[ 34 34 jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js"; 35 36 35 37 jsolait.Module("jsolaitws", function(mod){ 38 36 39 mod.__version__ = "$Revision$" 37 40 mod.__sourceURI__ = 'file://' + WScript.scriptFullName; 38 jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js";39 41 40 42 var fs= new ActiveXObject("Scripting.FileSystemObject"); … … 82 84 return this.name +": " + this.message; 83 85 } 84 85 mod.run=function( ){86 87 mod.run=function(finishedCB){ 86 88 87 89 if (WScript.arguments.unnamed.length==0){ … … 93 95 //todo:check if file exists 94 96 } 95 97 96 98 //get the base of the file to execute 97 99 var fileBase= fs.getParentFolderName(fileName); … … 99 101 jsolait.moduleSearchURIs = [fileBase, "%(baseURI)s/lib"]; 100 102 101 102 //see if there are any jsolait config files in any of the parent folders103 var parentFolder= fileBase;104 while(parentFolder){105 try{106 var src = jsolait.loadURI(parentFolder+'/.jsolait');107 try{108 var f = new Function('__baseURI__',src);109 f(parentFolder);110 break;111 }catch(e){112 print('error in .jsolait', parentFolder);113 break;114 }115 }catch(e){116 }117 parentFolder=fs.getParentFolderName(parentFolder);118 }119 120 121 103 //change working dir to the file's location 122 104 //todo:is it OK to change cwd? … … 124 106 wshShell.currentDirectory = fileBase.slice('file://'.length); 125 107 } 126 108 127 109 if(fileName.toLowerCase() != jsolait.__sourceURI__.toLowerCase() && fileName.toLowerCase() != mod.__sourceURI__.toLowerCase()){ 128 var src = jsolait.loadURI(fileName); 129 var modl = jsolait.createModuleFromSource("__main__", src, fileName); 130 try{ 131 var tmain =typeof(modl.__main__); 132 }catch(e){ 133 var tmain=""; 134 } 135 if(tmain=='function'){ 136 //todo find arguments 137 if(WScript.arguments.named.exists("script-args")){ 138 var args = WScript.arguments.named.Item("script-args"); 139 switch(args.slice(0,1)){ 140 case "{": case "'": case "[": case '"': 141 break; 142 default: 143 args = jsolait.repr(args); 110 jsolait.moduleSourceURIs['__main__']=fileName; 111 112 jsolait.loadModule('__main__', function(modl, err){ 113 if(err){ 114 finishedCB(err); 115 }else{ 116 try{ 117 var tmain =typeof(modl.__main__); 118 }catch(e){ 119 var tmain=""; 144 120 } 145 f=new Function( "return " + args); 146 args = [f()]; 147 }else{ 148 var args =[]; 121 122 if(tmain=='function'){ 123 //todo find arguments 124 if(WScript.arguments.named.exists("script-args")){ 125 var args = WScript.arguments.named.Item("script-args"); 126 switch(args.slice(0,1)){ 127 case "{": case "'": case "[": case '"': 128 break; 129 default: 130 args = jsolait.repr(args); 131 } 132 f=new Function( "return " + args); 133 args = [f()]; 134 }else{ 135 var args =[]; 136 } 137 138 try{ 139 modl.__main__.apply(modl, args); 140 finishedCB(null); 141 }catch(e){ 142 finishedCB( new mod.Exception("runing %s __main__() failed\n".format(modl),e)); 143 } 144 } 149 145 } 150 151 try{ 152 modl.__main__.apply(modl, args); 153 }catch(e){ 154 throw new mod.Exception("runing %s __main__() failed\n".format(modl),e) 155 } 156 } 157 146 }); 158 147 } 159 148 }; 160 149 }); 161 150 162 try{ 163 jsolait.loadModule("jsolaitws").run(); 151 try{ 152 jsolait.loadModule("jsolaitws", function(jsolaitws,err){ 153 jsolaitws.run( function(err){ 154 if(err){ 155 WScript.Echo(''+err); 156 } 157 158 }); 159 }); 164 160 }catch(e){ 165 WScript.echo(""+e);161 166 162 } 167 163 branches/experimental/jsolait/lib/codecs.js
r73 r77 28 28 @lastchangeddate $Date$ 29 29 */ 30 mod.__version__ = "$Revision$";30 __version__ = "$Revision$"; 31 31 /** 32 32 Returns all all available encoders. 33 33 @return An array of encoder names. 34 34 **/ 35 mod.listEncoders=function(){35 def listEncoders(){ 36 36 var c=[]; 37 37 for(var attr in String.prototype){ … … 46 46 @return An array of decoder names. 47 47 **/ 48 mod.listDecoders=function(){48 def listDecoders(){ 49 49 var c=[]; 50 50 for(var attr in String.prototype){ branches/experimental/jsolait/lib/crypto.js
r73 r77 27 27 @lastchangeddate $Date$ 28 28 */ 29 mod.__version__="$Revision$";29 __version__="$Revision$"; 30 30 /** 31 31 Returns all all available encrypters. 32 32 @return An array of encrypters names. 33 33 **/ 34 mod.listEncrypters=function(){34 def listEncrypters(){ 35 35 var c=[]; 36 36 for(var attr in String.prototype){ … … 45 45 @return An array of decrypters names. 46 46 **/ 47 mod.listDecrypters=function(){47 def listDecrypters(){ 48 48 var c=[]; 49 49 for(var attr in String.prototype){ branches/experimental/jsolait/lib/dom.js
r73 r77 25 25 @lastchangeddate $Date$ 26 26 **/ 27 mod.__version__="$Revision$";27 __version__="$Revision$"; 28 28 29 imp rt("sets");29 import sets; 30 30 31 31 /** 32 32 Event class. 33 33 **/ 34 mod.Event=Class(function(publ, supr){35 publ .__init__=function(type, target){34 class Event({ 35 publ __init__(type, target){ 36 36 this.type = type; 37 37 this.target = target; 38 38 }; 39 39 ///The event type. 40 publ .type=null;40 publ type=null; 41 41 ///The target of the event 42 publ .target=null;42 publ target=null; 43 43 }); 44 44 … … 47 47 An EventTarget implementation. 48 48 **/ 49 mod.EventTarget =Class(function(publ, supr){50 publ .__init__=function(){49 class EventTarget({ 50 publ __init__(){ 51 51 this.eventListeners={}; 52 52 }; … … 55 55 @param evt The event to dispatch. 56 56 **/ 57 publ .dispatchEvent = function(evt){57 publ dispatchEvent(evt){ 58 58 if(this.eventListeners[evt.type]){ 59 59 var l = this.eventListeners[evt.type].items; … … 73 73 @param useCapture todo: Not used yet. 74 74 **/ 75 publ .addEventListener=function(evtType, listener, useCapture){75 publ addEventListener(evtType, listener, useCapture){ 76 76 if(this.eventListeners[evtType]===undefined){ 77 77 this.eventListeners[evtType] = new sets.Set(); … … 87 87 @param useCapture todo: Not used yet. 88 88 **/ 89 publ .removeEventListener=function(evtType, listener, useCapture){89 publ removeEventListener(evtType, listener, useCapture){ 90 90 if(this.eventListeners[evtType]){ 91 91 this.eventListeners[evtType].discard(listener); … … 98 98 It forwards all events to handler methods using the evt.type as the name for the method. 99 99 **/ 100 mod.EventListener=Class(function(publ){100 class EventListener({ 101 101 /** 102 102 Handles events dispatched by an EventTarget. … … 104 104 @param evt The event to handle. 105 105 **/ 106 publ .handleEvent=function(evt){106 publ handleEvent(evt){ 107 107 if(this['handleEvent_' +evt.type]){ 108 108 this['handleEvent_' + evt.type](evt); … … 114 114 A combination of an EventTarget and a EventListener. 115 115 **/ 116 mod.EventListenerTarget=Class(mod.EventTarget, mod.EventListener, function(publ, supr){116 class EventListenerTarget extends EventTarget, EventListener({ 117 117 }); branches/experimental/jsolait/lib/forms.js
r73 r77 28 28 **/ 29 29 30 mod.__version__="$Revision$"; 30 __version__="$Revision$"; 31 32 import urllib; 33 31 34 /** 32 35 A class that resembles the functionality of an HTML form. … … 34 37 by accessing the element as a named property of the form object(formObj.elemName ...). 35 38 **/ 36 mod.Form=Class(function(publ, supr){39 class Form({ 37 40 ///Contains the form elements. 38 publ .elements=[];41 publ elements=[]; 39 42 ///The URL to submit the form to. 40 publ .action="";43 publ action=""; 41 44 ///The method to use for subitting the form(GET/POST) 42 publ .method="GET";45 publ method="GET"; 43 46 44 47 /** … … 47 50 @param method="GET" The method to use for submitting(GET, POST). 48 51 **/ 49 publ .__init__=function(action, method){52 publ __init__(action, method){ 50 53 this.elements=[]; 51 54 this.action= (action==null)?"":action; … … 59 62 @return The Element set. 60 63 **/ 61 publ .set=function(name, value){64 publ set(name, value){ 62 65 var f = null; 63 66 for(var i=0;i<this.elements;i++){ … … 68 71 } 69 72 if(f == null){//add a new element 70 f = new mod.Element(name, value);73 f = new Element(name, value); 71 74 this.eleme
