Changeset 1391
- Timestamp:
- 06/24/08 05:41:41 (4 months ago)
- Files:
-
- mochikit/trunk/MochiKit/Base.js (modified) (4 diffs)
- mochikit/trunk/packed/MochiKit/MochiKit.js (modified) (196 diffs)
- mochikit/trunk/tests/test_Base.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mochikit/trunk/MochiKit/Base.js
r1390 r1391 836 836 } else if (o === null) { 837 837 return "null"; 838 } 839 var m = MochiKit.Base; 840 var reprString = m.reprString; 841 if (objtype == "string") { 842 return reprString(o); 838 } else if (objtype == "string") { 839 var res = ""; 840 for (var i = 0; i < o.length; i++) { 841 var c = o.charAt(i); 842 if (c == '\"') { 843 res += '\\"'; 844 } else if (c == '\\') { 845 res += '\\\\'; 846 } else if (c == '\b') { 847 res += '\\b'; 848 } else if (c == '\f') { 849 res += '\\f'; 850 } else if (c == '\n') { 851 res += '\\n'; 852 } else if (c == '\r') { 853 res += '\\r'; 854 } else if (c == '\t') { 855 res += '\\t'; 856 } else if (o.charCodeAt(i) <= 0x1F) { 857 var hex = o.charCodeAt(i).toString(16); 858 if (hex.length < 2) { 859 hex = '0' + hex; 860 } 861 res += '\\u00' + hex.toUpperCase(); 862 } else { 863 res += c; 864 } 865 } 866 return '"' + res + '"'; 843 867 } 844 868 // recurse … … 865 889 var val = me(o[i]); 866 890 if (typeof(val) != "string") { 867 val = "undefined"; 891 // skip non-serializable values 892 continue; 868 893 } 869 894 res.push(val); … … 872 897 } 873 898 // look in the registry 899 var m = MochiKit.Base; 874 900 try { 875 901 newObj = m.jsonRegistry.match(o); … … 898 924 useKey = '"' + k + '"'; 899 925 } else if (typeof(k) == "string") { 900 useKey = reprString(k);926 useKey = me(k); 901 927 } else { 902 928 // skip non-string or number keys mochikit/trunk/packed/MochiKit/MochiKit.js
r1390 r1391 650 650 if(o===null){ 651 651 return "null"; 652 } 653 } 654 var m=MochiKit.Base; 655 var _ea=m.reprString; 652 }else{ 656 653 if(_e8=="string"){ 657 return _ea(o); 654 var res=""; 655 for(var i=0;i<o.length;i++){ 656 var c=o.charAt(i); 657 if(c=="\""){ 658 res+="\\\""; 659 }else{ 660 if(c=="\\"){ 661 res+="\\\\"; 662 }else{ 663 if(c=="\b"){ 664 res+="\\b"; 665 }else{ 666 if(c=="\f"){ 667 res+="\\f"; 668 }else{ 669 if(c=="\n"){ 670 res+="\\n"; 671 }else{ 672 if(c=="\r"){ 673 res+="\\r"; 674 }else{ 675 if(c=="\t"){ 676 res+="\\t"; 677 }else{ 678 if(o.charCodeAt(i)<=31){ 679 var hex=o.charCodeAt(i).toString(16); 680 if(hex.length<2){ 681 hex="0"+hex; 682 } 683 res+="\\u00"+hex.toUpperCase(); 684 }else{ 685 res+=c; 686 } 687 } 688 } 689 } 690 } 691 } 692 } 693 } 694 } 695 return "\""+res+"\""; 696 } 697 } 658 698 } 659 699 var me=arguments.callee; 660 var _e c;700 var _ee; 661 701 if(typeof (o.__json__)=="function"){ 662 _e c=o.__json__();663 if(o!==_e c){664 return me(_e c);702 _ee=o.__json__(); 703 if(o!==_ee){ 704 return me(_ee); 665 705 } 666 706 } 667 707 if(typeof (o.json)=="function"){ 668 _e c=o.json();669 if(o!==_e c){670 return me(_e c);708 _ee=o.json(); 709 if(o!==_ee){ 710 return me(_ee); 671 711 } 672 712 } … … 676 716 var val=me(o[i]); 677 717 if(typeof (val)!="string"){ 678 val="undefined";718 continue; 679 719 } 680 720 res.push(val); … … 682 722 return "["+res.join(", ")+"]"; 683 723 } 724 var m=MochiKit.Base; 684 725 try{ 685 _e c=m.jsonRegistry.match(o);686 if(o!==_e c){687 return me(_e c);726 _ee=m.jsonRegistry.match(o); 727 if(o!==_ee){ 728 return me(_ee); 688 729 } 689 730 } … … 701 742 res=[]; 702 743 for(var k in o){ 703 var _f 1;744 var _f2; 704 745 if(typeof (k)=="number"){ 705 _f 1="\""+k+"\"";746 _f2="\""+k+"\""; 706 747 }else{ 707 748 if(typeof (k)=="string"){ 708 _f 1=_ea(k);749 _f2=me(k); 709 750 }else{ 710 751 continue; … … 715 756 continue; 716 757 } 717 res.push(_f 1+":"+val);758 res.push(_f2+":"+val); 718 759 } 719 760 return "{"+res.join(", ")+"}"; 720 761 },objEqual:function(a,b){ 721 762 return (MochiKit.Base.compare(a,b)===0); 722 },arrayEqual:function(_f 4,arr){723 if(_f 4.length!=arr.length){763 },arrayEqual:function(_f5,arr){ 764 if(_f5.length!=arr.length){ 724 765 return false; 725 766 } 726 return (MochiKit.Base.compare(_f 4,arr)===0);767 return (MochiKit.Base.compare(_f5,arr)===0); 727 768 },concat:function(){ 728 var _f 6=[];729 var _f 7=MochiKit.Base.extend;769 var _f7=[]; 770 var _f8=MochiKit.Base.extend; 730 771 for(var i=0;i<arguments.length;i++){ 731 _f 7(_f6,arguments[i]);732 } 733 return _f 6;772 _f8(_f7,arguments[i]); 773 } 774 return _f7; 734 775 },keyComparator:function(key){ 735 776 var m=MochiKit.Base; 736 var _f b=m.compare;777 var _fc=m.compare; 737 778 if(arguments.length==1){ 738 779 return function(a,b){ 739 return _f b(a[key],b[key]);740 }; 741 } 742 var _f e=m.extend(null,arguments);780 return _fc(a[key],b[key]); 781 }; 782 } 783 var _ff=m.extend(null,arguments); 743 784 return function(a,b){ 744 785 var rval=0; 745 for(var i=0;(rval===0)&&(i<_f e.length);i++){746 var key=_f e[i];747 rval=_f b(a[key],b[key]);786 for(var i=0;(rval===0)&&(i<_ff.length);i++){ 787 var key=_ff[i]; 788 rval=_fc(a[key],b[key]); 748 789 } 749 790 return rval; 750 791 }; 751 792 },reverseKeyComparator:function(key){ 752 var _10 5=MochiKit.Base.keyComparator.apply(this,arguments);793 var _106=MochiKit.Base.keyComparator.apply(this,arguments); 753 794 return function(a,b){ 754 return _10 5(b,a);795 return _106(b,a); 755 796 }; 756 797 },partial:function(func){ 757 798 var m=MochiKit.Base; 758 799 return m.bind.apply(this,m.extend([func,undefined],arguments,1)); 759 },listMinMax:function(_10 a,lst){800 },listMinMax:function(_10b,lst){ 760 801 if(lst.length===0){ 761 802 return null; 762 803 } 763 804 var cur=lst[0]; 764 var _10 d=MochiKit.Base.compare;805 var _10e=MochiKit.Base.compare; 765 806 for(var i=1;i<lst.length;i++){ 766 807 var o=lst[i]; 767 if(_10 d(o,cur)==_10a){808 if(_10e(o,cur)==_10b){ 768 809 cur=o; 769 810 } … … 774 815 },objMin:function(){ 775 816 return MochiKit.Base.listMinMax(-1,arguments); 776 },findIdentical:function(lst,_11 1,_112,end){817 },findIdentical:function(lst,_112,_113,end){ 777 818 if(typeof (end)=="undefined"||end===null){ 778 819 end=lst.length; 779 820 } 780 if(typeof (_11 2)=="undefined"||_112===null){781 _11 2=0;782 } 783 for(var i=_11 2;i<end;i++){784 if(lst[i]===_11 1){821 if(typeof (_113)=="undefined"||_113===null){ 822 _113=0; 823 } 824 for(var i=_113;i<end;i++){ 825 if(lst[i]===_112){ 785 826 return i; 786 827 } … … 791 832 var m=MochiKit.Base; 792 833 var args=m.extend(null,arguments); 793 var _11 8=args.length;834 var _119=args.length; 794 835 while(args.length){ 795 836 var o=args.shift(); 796 837 if(o&&typeof (o)=="object"&&typeof (o.length)=="number"){ 797 _11 8+=o.length-1;838 _119+=o.length-1; 798 839 for(var i=o.length-1;i>=0;i--){ 799 840 sum+=o[i]; … … 803 844 } 804 845 } 805 if(_11 8<=0){846 if(_119<=0){ 806 847 throw new TypeError("mean() requires at least one argument"); 807 848 } 808 return sum/_11 8;849 return sum/_119; 809 850 },median:function(){ 810 851 var data=MochiKit.Base.flattenArguments(arguments); … … 814 855 data.sort(compare); 815 856 if(data.length%2==0){ 816 var _11 c=data.length/2;817 return (data[_11 c]+data[_11c-1])/2;857 var _11d=data.length/2; 858 return (data[_11d]+data[_11d-1])/2; 818 859 }else{ 819 860 return data[(data.length-1)/2]; 820 861 } 821 },findValue:function(lst,_11 e,_11f,end){862 },findValue:function(lst,_11f,_120,end){ 822 863 if(typeof (end)=="undefined"||end===null){ 823 864 end=lst.length; 824 865 } 825 if(typeof (_1 1f)=="undefined"||_11f===null){826 _1 1f=0;866 if(typeof (_120)=="undefined"||_120===null){ 867 _120=0; 827 868 } 828 869 var cmp=MochiKit.Base.compare; 829 for(var i=_1 1f;i<end;i++){830 if(cmp(lst[i],_11 e)===0){870 for(var i=_120;i<end;i++){ 871 if(cmp(lst[i],_11f)===0){ 831 872 return i; 832 873 } 833 874 } 834 875 return -1; 835 },nodeWalk:function(node,_12 4){836 var _12 5=[node];837 var _12 6=MochiKit.Base.extend;838 while(_12 5.length){839 var res=_12 4(_125.shift());876 },nodeWalk:function(node,_125){ 877 var _126=[node]; 878 var _127=MochiKit.Base.extend; 879 while(_126.length){ 880 var res=_125(_126.shift()); 840 881 if(res){ 841 _12 6(_125,res);842 } 843 } 844 },nameFunctions:function(_12 8){845 var base=_12 8.NAME;882 _127(_126,res); 883 } 884 } 885 },nameFunctions:function(_129){ 886 var base=_129.NAME; 846 887 if(typeof (base)=="undefined"){ 847 888 base=""; … … 849 890 base=base+"."; 850 891 } 851 for(var name in _12 8){852 var o=_12 8[name];892 for(var name in _129){ 893 var o=_129[name]; 853 894 if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){ 854 895 try{ … … 859 900 } 860 901 } 861 },queryString:function(_12 c,_12d){862 if(typeof (MochiKit.DOM)!="undefined"&&arguments.length==1&&(typeof (_12 c)=="string"||(typeof (_12c.nodeType)!="undefined"&&_12c.nodeType>0))){863 var kv=MochiKit.DOM.formContents(_12 c);864 _12 c=kv[0];865 _12 d=kv[1];902 },queryString:function(_12d,_12e){ 903 if(typeof (MochiKit.DOM)!="undefined"&&arguments.length==1&&(typeof (_12d)=="string"||(typeof (_12d.nodeType)!="undefined"&&_12d.nodeType>0))){ 904 var kv=MochiKit.DOM.formContents(_12d); 905 _12d=kv[0]; 906 _12e=kv[1]; 866 907 }else{ 867 908 if(arguments.length==1){ 868 if(typeof (_12c.length)=="number"&&_12c.length==2){ 869 return arguments.callee(_12c[0],_12c[1]); 870 } 871 var o=_12c; 872 _12c=[]; 909 if(typeof (_12d.length)=="number"&&_12d.length==2){ 910 return arguments.callee(_12d[0],_12d[1]); 911 } 912 var o=_12d; 873 913 _12d=[]; 914 _12e=[]; 874 915 for(var k in o){ 875 916 var v=o[k]; … … 879 920 if(MochiKit.Base.isArrayLike(v)){ 880 921 for(var i=0;i<v.length;i++){ 881 _12 c.push(k);882 _12 d.push(v[i]);883 } 884 }else{ 885 _12 c.push(k);886 _12 d.push(v);922 _12d.push(k); 923 _12e.push(v[i]); 924 } 925 }else{ 926 _12d.push(k); 927 _12e.push(v); 887 928 } 888 929 } … … 891 932 } 892 933 var rval=[]; 893 var len=Math.min(_12 c.length,_12d.length);894 var _13 5=MochiKit.Base.urlEncode;934 var len=Math.min(_12d.length,_12e.length); 935 var _136=MochiKit.Base.urlEncode; 895 936 for(var i=0;i<len;i++){ 896 v=_12 d[i];937 v=_12e[i]; 897 938 if(typeof (v)!="undefined"&&v!==null){ 898 rval.push(_13 5(_12c[i])+"="+_135(v));939 rval.push(_136(_12d[i])+"="+_136(v)); 899 940 } 900 941 } 901 942 return rval.join("&"); 902 },parseQueryString:function(_13 6,_137){903 var qstr=(_13 6.charAt(0)=="?")?_136.substring(1):_136;904 var _13 9=qstr.replace(/\+/g,"%20").split(/\&\;|\&\#38\;|\&|\&/);943 },parseQueryString:function(_137,_138){ 944 var qstr=(_137.charAt(0)=="?")?_137.substring(1):_137; 945 var _13a=qstr.replace(/\+/g,"%20").split(/\&\;|\&\#38\;|\&|\&/); 905 946 var o={}; 906 var _13 b;947 var _13c; 907 948 if(typeof (decodeURIComponent)!="undefined"){ 908 _13 b=decodeURIComponent;909 }else{ 910 _13 b=unescape;911 } 912 if(_13 7){913 for(var i=0;i<_13 9.length;i++){914 var pair=_13 9[i].split("=");915 var name=_13 b(pair.shift());949 _13c=decodeURIComponent; 950 }else{ 951 _13c=unescape; 952 } 953 if(_138){ 954 for(var i=0;i<_13a.length;i++){ 955 var pair=_13a[i].split("="); 956 var name=_13c(pair.shift()); 916 957 if(!name){ 917 958 continue; … … 922 963 o[name]=arr; 923 964 } 924 arr.push(_13 b(pair.join("=")));925 } 926 }else{ 927 for(i=0;i<_13 9.length;i++){928 pair=_13 9[i].split("=");965 arr.push(_13c(pair.join("="))); 966 } 967 }else{ 968 for(i=0;i<_13a.length;i++){ 969 pair=_13a[i].split("="); 929 970 var name=pair.shift(); 930 971 if(!name){ 931 972 continue; 932 973 } 933 o[_13 b(name)]=_13b(pair.join("="));974 o[_13c(name)]=_13c(pair.join("=")); 934 975 } 935 976 } … … 939 980 this.pairs=[]; 940 981 }; 941 MochiKit.Base.AdapterRegistry.prototype={register:function(name,_14 1,wrap,_143){942 if(_14 3){943 this.pairs.unshift([name,_14 1,wrap]);944 }else{ 945 this.pairs.push([name,_14 1,wrap]);982 MochiKit.Base.AdapterRegistry.prototype={register:function(name,_142,wrap,_144){ 983 if(_144){ 984 this.pairs.unshift([name,_142,wrap]); 985 }else{ 986 this.pairs.push([name,_142,wrap]); 946 987 } 947 988 },match:function(){ … … 965 1006 MochiKit.Base.EXPORT=["flattenArray","noop","camelize","counter","clone","extend","update","updatetree","setdefault","keys","values","items","NamedError","operator","forwardCall","itemgetter","typeMatcher","isCallable","isUndefined","isUndefinedOrNull","isNull","isEmpty","isNotEmpty","isArrayLike","isDateLike","xmap","map","xfilter","filter","methodcaller","compose","bind","bindMethods","NotFound","AdapterRegistry","registerComparator","compare","registerRepr","repr","objEqual","arrayEqual","concat","keyComparator","reverseKeyComparator","partial","merge","listMinMax","listMax","listMin","objMax","objMin","nodeWalk","zip","urlEncode","queryString","serializeJSON","registerJSON","evalJSON","parseQueryString","findValue","findIdentical","flattenArguments","method","average","mean","median"]; 966 1007 MochiKit.Base.EXPORT_OK=["nameFunctions","comparatorRegistry","reprRegistry","jsonRegistry","compareDateLike","compareArrayLike","reprArrayLike","reprString","reprNumber"]; 967 MochiKit.Base._exportSymbols=function(_14 9,_14a){1008 MochiKit.Base._exportSymbols=function(_14a,_14b){ 968 1009 if(!MochiKit.__export__){ 969 1010 return; 970 1011 } 971 var all=_14 a.EXPORT_TAGS[":all"];1012 var all=_14b.EXPORT_TAGS[":all"]; 972 1013 for(var i=0;i<all.length;i++){ 973 _14 9[all[i]]=_14a[all[i]];1014 _14a[all[i]]=_14b[all[i]]; 974 1015 } 975 1016 }; … … 980 1021 m.find=m.findValue; 981 1022 if(typeof (encodeURIComponent)!="undefined"){ 982 m.urlEncode=function(_14e){983 return encodeURIComponent(_14e).replace(/\'/g,"%27");984 };985 }else{986 1023 m.urlEncode=function(_14f){ 987 return escape(_14f).replace(/\+/g,"%2B").replace(/\"/g,"%22").rval.replace(/\'/g,"%27"); 1024 return encodeURIComponent(_14f).replace(/\'/g,"%27"); 1025 }; 1026 }else{ 1027 m.urlEncode=function(_150){ 1028 return escape(_150).replace(/\+/g,"%2B").replace(/\"/g,"%22").rval.replace(/\'/g,"%27"); 988 1029 }; 989 1030 } … … 1036 1077 },toString:function(){ 1037 1078 return this.__repr__(); 1038 },registerIteratorFactory:function(name,_15 3,_154,_155){1039 MochiKit.Iter.iteratorRegistry.register(name,_15 3,_154,_155);1040 },iter:function(_15 6,_157){1079 },registerIteratorFactory:function(name,_154,_155,_156){ 1080 MochiKit.Iter.iteratorRegistry.register(name,_154,_155,_156); 1081 },iter:function(_157,_158){ 1041 1082 var self=MochiKit.Iter; 1042 1083 if(arguments.length==2){ 1043 1084 return self.takewhile(function(a){ 1044 return a!=_15 7;1045 },_15 6);1046 } 1047 if(typeof (_15 6.next)=="function"){1048 return _15 6;1049 }else{ 1050 if(typeof (_15 6.iter)=="function"){1051 return _15 6.iter();1085 return a!=_158; 1086 },_157); 1087 } 1088 if(typeof (_157.next)=="function"){ 1089 return _157; 1090 }else{ 1091 if(typeof (_157.iter)=="function"){ 1092 return _157.iter(); 1052 1093 } 1053 1094 } 1054 1095 try{ 1055 return self.iteratorRegistry.match(_15 6);1096 return self.iteratorRegistry.match(_157); 1056 1097 } 1057 1098 catch(e){ 1058 1099 var m=MochiKit.Base; 1059 1100 if(e==m.NotFound){ 1060 e=new TypeError(typeof (_15 6)+": "+m.repr(_156)+" is not iterable");1101 e=new TypeError(typeof (_157)+": "+m.repr(_157)+" is not iterable"); 1061 1102 } 1062 1103 throw e; … … 1074 1115 var m=MochiKit.Base; 1075 1116 var lst=[]; 1076 var _16 1=self.iter(p);1117 var _162=self.iter(p); 1077 1118 return {repr:function(){ 1078 1119 return "cycle(...)"; 1079 1120 },toString:m.forwardCall("repr"),next:function(){ 1080 1121 try{ 1081 var rval=_16 1.next();1122 var rval=_162.next(); 1082 1123 lst.push(rval); 1083 1124 return rval; … … 1119 1160 return elem; 1120 1161 }}; 1121 },next:function(_16 7){1122 return _16 7.next();1162 },next:function(_168){ 1163 return _168.next(); 1123 1164 },izip:function(p,q){ 1124 1165 var m=MochiKit.Base; 1125 1166 var self=MochiKit.Iter; 1126 1167 var next=self.next; 1127 var _16 d=m.map(self.iter,arguments);1168 var _16e=m.map(self.iter,arguments); 1128 1169 return {repr:function(){ 1129 1170 return "izip(...)"; 1130 1171 },toString:m.forwardCall("repr"),next:function(){ 1131 return m.map(next,_16 d);1172 return m.map(next,_16e); 1132 1173 }}; 1133 1174 },ifilter:function(pred,seq){ … … 1169 1210 var m=MochiKit.Base; 1170 1211 seq=self.iter(seq); 1171 var _17 9=0;1212 var _17a=0; 1172 1213 var stop=0; 1173 1214 var step=1; … … 1177 1218 }else{ 1178 1219 if(arguments.length==3){ 1179 _17 9=arguments[1];1220 _17a=arguments[1]; 1180 1221 stop=arguments[2]; 1181 1222 }else{ 1182 _17 9=arguments[1];1223 _17a=arguments[1]; 1183 1224 stop=arguments[2]; 1184 1225 step=arguments[3]; … … 1186 1227 } 1187 1228 return {repr:function(){ 1188 return "islice("+["...",_17 9,stop,step].join(", ")+")";1229 return "islice("+["...",_17a,stop,step].join(", ")+")"; 1189 1230 },toString:m.forwardCall("repr"),next:function(){ 1190 1231 var rval; 1191 while(i<_17 9){1232 while(i<_17a){ 1192 1233 rval=seq.next(); 1193 1234 i++; 1194 1235 } 1195 if(_17 9>=stop){1236 if(_17a>=stop){ 1196 1237 throw self.StopIteration; 1197 1238 } 1198 _17 9+=step;1239 _17a+=step; 1199 1240 return rval; 1200 1241 }}; … … 1202 1243 var m=MochiKit.Base; 1203 1244 var self=MochiKit.Iter; 1204 var _18 3=m.map(self.iter,m.extend(null,arguments,1));1245 var _184=m.map(self.iter,m.extend(null,arguments,1)); 1205 1246 var map=m.map; 1206 1247 var next=self.next; … … 1208 1249 return "imap(...)"; 1209 1250 },toString:m.forwardCall("repr"),next:function(){ 1210 return fun.apply(this,map(next,_18 3));1251 return fun.apply(this,map(next,_184)); 1211 1252 }}; 1212 1253 },applymap:function(fun,seq,self){ … … 1224 1265 return self.iter(arguments[0]); 1225 1266 } 1226 var _18 e=m.map(self.iter,arguments);1267 var _18f=m.map(self.iter,arguments); 1227 1268 return {repr:function(){ 1228 1269 return "chain(...)"; 1229 1270 },toString:m.forwardCall("repr"),next:function(){ 1230 while(_18 e.length>1){1271 while(_18f.length>1){ 1231 1272 try{ 1232 var _1 8f=_18e[0].next();1233 return _1 8f;1273 var _190=_18f[0].next(); 1274 return _190; 1234 1275 } 1235 1276 catch(e){ … … 1237 1278 throw e; 1238 1279 } 1239 _18 e.shift();1240 var _1 8f=_18e[0].next();1241 return _1 8f;1242 } 1243 } 1244 if(_18 e.length==1){1245 var arg=_18 e.shift();1280 _18f.shift(); 1281 var _190=_18f[0].next(); 1282 return _190; 1283 } 1284 } 1285 if(_18f.length==1){ 1286 var arg=_18f.shift(); 1246 1287 this.next=m.bind("next",arg); 1247 1288 return this.next(); … … 1280 1321 return rval; 1281 1322 }}; 1282 },_tee:function(_19 a,sync,_19c){1283 sync.pos[_19 a]=-1;1323 },_tee:function(_19b,sync,_19d){ 1324 sync.pos[_19b]=-1; 1284 1325 var m=MochiKit.Base; 1285 var _19 e=m.listMin;1326 var _19f=m.listMin; 1286 1327 return {repr:function(){ 1287 return "tee("+_19 a+", ...)";1328 return "tee("+_19b+", ...)"; 1288 1329 },toString:m.forwardCall("repr"),next:function(){ 1289 1330 var rval; 1290 var i=sync.pos[_19 a];1331 var i=sync.pos[_19b]; 1291 1332 if(i==sync.max){ 1292 rval=_19 c.next();1333 rval=_19d.next(); 1293 1334 sync.deque.push(rval); 1294 1335 sync.max+=1; 1295 sync.pos[_19 a]+=1;1336 sync.pos[_19b]+=1; 1296 1337 }else{ 1297 1338 rval=sync.deque[i-sync.min]; 1298 sync.pos[_19 a]+=1;1299 if(i==sync.min&&_19 e(sync.pos)!=sync.min){1339 sync.pos[_19b]+=1; 1340 if(i==sync.min&&_19f(sync.pos)!=sync.min){ 1300 1341 sync.min+=1; 1301 1342 sync.deque.shift(); … … 1304 1345 return rval; 1305 1346 }}; 1306 },tee:function(_1a 1,n){1347 },tee:function(_1a2,n){ 1307 1348 var rval=[]; 1308 1349 var sync={"pos":[],"deque":[],"max":-1,"min":-1}; … … 1311 1352 } 1312 1353 var self=MochiKit.Iter; 1313 _1a 1=self.iter(_1a1);1354 _1a2=self.iter(_1a2); 1314 1355 var _tee=self._tee; 1315 1356 for(var i=0;i<n;i++){ 1316 rval.push(_tee(i,sync,_1a 1));1357 rval.push(_tee(i,sync,_1a2)); 1317 1358 } 1318 1359 return rval; 1319 },list:function(_1a 8){1360 },list:function(_1a9){ 1320 1361 var rval; 1321 if(_1a 8instanceof Array){1322 return _1a 8.slice();1323 } 1324 if(typeof (_1a 8)=="function"&&!(_1a8 instanceof Function)&&typeof (_1a8.length)=="number"){1362 if(_1a9 instanceof Array){ 1363 return _1a9.slice(); 1364 } 1365 if(typeof (_1a9)=="function"&&!(_1a9 instanceof Function)&&typeof (_1a9.length)=="number"){ 1325 1366 rval=[]; 1326 for(var i=0;i<_1a 8.length;i++){1327 rval.push(_1a 8[i]);1367 for(var i=0;i<_1a9.length;i++){ 1368 rval.push(_1a9[i]); 1328 1369 } 1329 1370 return rval; 1330 1371 } 1331 1372 var self=MochiKit.Iter; 1332 _1a 8=self.iter(_1a8);1373 _1a9=self.iter(_1a9); 1333 1374 var rval=[]; 1334 var _1a c;1375 var _1ad; 1335 1376 try{ 1336 1377 while(true){ 1337 _1a c=_1a8.next();1338 rval.push(_1a c);1378 _1ad=_1a9.next(); 1379 rval.push(_1ad); 1339 1380 } 1340 1381 } … … 1346 1387 } 1347 1388 return undefined; 1348 },reduce:function(fn,_1a e,_1af){1389 },reduce:function(fn,_1af,_1b0){ 1349 1390 var i=0; 1350 var x=_1 af;1391 var x=_1b0; 1351 1392 var self=MochiKit.Iter; 1352 _1a e=self.iter(_1ae);1393 _1af=self.iter(_1af); 1353 1394 if(arguments.length<3){ 1354 1395 try{ 1355 x=_1a e.next();1396 x=_1af.next(); 1356 1397 } 1357 1398 catch(e){ … … 1365 1406 try{ 1366 1407 while(true){ 1367 x=fn(x,_1a e.next());1408 x=fn(x,_1af.next()); 1368 1409 } 1369 1410 } … … 1375 1416 return x; 1376 1417 },range:function(){ 1377 var _1b 3=0;1418 var _1b4=0; 1378 1419 var stop=0; 1379 1420 var step=1; … … 1382 1423 }else{ 1383 1424 if(arguments.length==2){ 1384 _1b 3=arguments[0];1425 _1b4=arguments[0]; 1385 1426 stop=arguments[1]; 1386 1427 }else{ 1387 1428 if(arguments.length==3){ 1388 _1b 3=arguments[0];1429 _1b4=arguments[0]; 1389 1430 stop=arguments[1]; 1390 1431 step=arguments[2]; … … 1398 1439 } 1399 1440 return {next:function(){ 1400 if((step>0&&_1b 3>=stop)||(step<0&&_1b3<=stop)){1441 if((step>0&&_1b4>=stop)||(step<0&&_1b4<=stop)){ 1401 1442 throw MochiKit.Iter.StopIteration; 1402 1443 } 1403 var rval=_1b 3;1404 _1b 3+=step;1444 var rval=_1b4; 1445 _1b4+=step; 1405 1446 return rval; 1406 1447 },repr:function(){ 1407 return "range("+[_1b 3,stop,step].join(", ")+")";1448 return "range("+[_1b4,stop,step].join(", ")+")"; 1408 1449 },toString:MochiKit.Base.forwardCall("repr")}; 1409 },sum:function(_1b 7,_1b8){1410 if(typeof (_1b 8)=="undefined"||_1b8===null){1411 _1b 8=0;1412 } 1413 var x=_1b 8;1450 },sum:function(_1b8,_1b9){ 1451 if(typeof (_1b9)=="undefined"||_1b9===null){ 1452 _1b9=0; 1453 } 1454 var x=_1b9; 1414 1455 var self=MochiKit.Iter; 1415 _1b 7=self.iter(_1b7);1456 _1b8=self.iter(_1b8); 1416 1457 try{ 1417 1458 while(true){ 1418 x+=_1b 7.next();1459 x+=_1b8.next(); 1419 1460 } 1420 1461 } … … 1425 1466 } 1426 1467 return x; 1427 },exhaust:function(_1b b){1468 },exhaust:function(_1bc){ 1428 1469 var self=MochiKit.Iter; 1429 _1b b=self.iter(_1bb);1470 _1bc=self.iter(_1bc); 1430 1471 try{ 1431 1472 while(true){ 1432 _1b b.next();1473 _1bc.next(); 1433 1474 } 1434 1475 } … … 1438 1479 } 1439 1480 } 1440 },forEach:function(_1b d,func,self){1481 },forEach:function(_1be,func,self){ 1441 1482 var m=MochiKit.Base; 1442 1483 if(arguments.length>2){ 1443 1484 func=m.bind(func,self); 1444 1485 } 1445 if(m.isArrayLike(_1b d)){1486 if(m.isArrayLike(_1be)){ 1446 1487 try{ 1447 for(var i=0;i<_1b d.length;i++){1448 func(_1b d[i]);1488 for(var i=0;i<_1be.length;i++){ 1489 func(_1be[i]); 1449 1490 } 1450 1491 } … … 1456 1497 }else{ 1457 1498 self=MochiKit.Iter; 1458 self.exhaust(self.imap(func,_1b d));1459 } 1460 },every:function(_1c 2,func){1499 self.exhaust(self.imap(func,_1be)); 1500 } 1501 },every:function(_1c3,func){ 1461 1502 var self=MochiKit.Iter; 1462 1503 try{ 1463 self.ifilterfalse(func,_1c 2).next();1504 self.ifilterfalse(func,_1c3).next(); 1464 1505 return false; 1465 1506 } … … 1470 1511 return true; 1471 1512 } 1472 },sorted:function(_1c 5,cmp){1473 var rval=MochiKit.Iter.list(_1c 5);1513 },sorted:function(_1c6,cmp){ 1514 var rval=MochiKit.Iter.list(_1c6); 1474 1515 if(arguments.length==1){ 1475 1516 cmp=MochiKit.Base.compare; … … 1477 1518 rval.sort(cmp); 1478 1519 return rval; 1479 },reversed:function(_1c 8){1480 var rval=MochiKit.Iter.list(_1c 8);1520 },reversed:function(_1c9){ 1521 var rval=MochiKit.Iter.list(_1c9); 1481 1522 rval.reverse(); 1482 1523 return rval; 1483 },some:function(_1c a,func){1524 },some:function(_1cb,func){ 1484 1525 var self=MochiKit.Iter; 1485 1526 try{ 1486 self.ifilter(func,_1c a).next();1527 self.ifilter(func,_1cb).next(); 1487 1528 return true; 1488 1529 } … … 1493 1534 return false; 1494 1535 } 1495 },iextend:function(lst,_1c e){1496 if(MochiKit.Base.isArrayLike(_1c e)){1497 for(var i=0;i<_1c e.length;i++){1498 lst.push(_1c e[i]);1536 },iextend:function(lst,_1cf){ 1537 if(MochiKit.Base.isArrayLike(_1cf)){ 1538 for(var i=0;i<_1cf.length;i++){ 1539 lst.push(_1cf[i]); 1499 1540 } 1500 1541 }else{ 1501 1542 var self=MochiKit.Iter; 1502 _1c e=self.iter(_1ce);1543 _1cf=self.iter(_1cf); 1503 1544 try{ 1504 1545 while(true){ 1505 lst.push(_1c e.next());1546 lst.push(_1cf.next()); 1506 1547 } 1507 1548 } … … 1513 1554 } 1514 1555 return lst; 1515 },groupby:function(_1d 1,_1d2){1556 },groupby:function(_1d2,_1d3){ 1516 1557 var m=MochiKit.Base; 1517 1558 var self=MochiKit.Iter; 1518 1559 if(arguments.length<2){ 1519 _1d 2=m.operator.identity;1520 } 1521 _1d 1=self.iter(_1d1);1560 _1d3=m.operator.identity; 1561 } 1562 _1d2=self.iter(_1d2); 1522 1563 var pk=undefined; 1523 1564 var k=undefined; 1524 1565 var v; 1525 1566 function fetch(){ 1526 v=_1d 1.next();1527 k=_1d 2(v);1567 v=_1d2.next(); 1568 k=_1d3(v); 1528 1569 } 1529 1570 function eat(){ … … 1532 1573 return ret; 1533 1574 } 1534 var _1d 9=true;1535 var _1d a=m.compare;1575 var _1da=true; 1576 var _1db=m.compare; 1536 1577 return {repr:function(){ 1537 1578 return "groupby(...)"; 1538 1579 },next:function(){ 1539 while(_1d a(k,pk)===0){1580 while(_1db(k,pk)===0){ 1540 1581 fetch(); 1541 if(_1d 9){1542 _1d 9=false;1582 if(_1da){ 1583 _1da=false; 1543 1584 break; 1544 1585 } … … 1549 1590 fetch(); 1550 1591 } 1551 if(_1d a(k,pk)!==0){1592 if(_1db(k,pk)!==0){ 1552 1593 throw self.StopIteration; 1553 1594 } … … 1555 1596 }}]; 1556 1597 }}; 1557 },groupby_as_array:function(_1d b,_1dc){1598 },groupby_as_array:function(_1dc,_1dd){ 1558 1599 var m=MochiKit.Base; 1559 1600 var self=MochiKit.Iter; 1560 1601 if(arguments.length<2){ 1561 _1d c=m.operator.identity;1562 } 1563 _1d b=self.iter(_1db);1564 var _1 df=[];1565 var _1e 0=true;1566 var _1e 1;1567 var _1e 2=m.compare;1602 _1dd=m.operator.identity; 1603 } 1604 _1dc=self.iter(_1dc); 1605 var _1e0=[]; 1606 var _1e1=true; 1607 var _1e2; 1608 var _1e3=m.compare; 1568 1609 while(true){ 1569 1610 try{ 1570 var _1e 3=_1db.next();1571 var key=_1d c(_1e3);1611 var _1e4=_1dc.next(); 1612 var key=_1dd(_1e4); 1572 1613 } 1573 1614 catch(e){ … … 1577 1618 throw e; 1578 1619 } 1579 if(_1e 0||_1e2(key,_1e1)!==0){1580 var _1e 5=[];1581 _1 df.push([key,_1e5]);1582 } 1583 _1e 5.push(_1e3);1584 _1e 0=false;1585 _1e 1=key;1586 } 1587 return _1 df;1588 },arrayLikeIter:function(_1e 6){1620 if(_1e1||_1e3(key,_1e2)!==0){ 1621 var _1e6=[]; 1622 _1e0.push([key,_1e6]); 1623 } 1624 _1e6.push(_1e4); 1625 _1e1=false; 1626 _1e2=key; 1627 } 1628 return _1e0; 1629 },arrayLikeIter:function(_1e7){ 1589 1630 var i=0; 1590 1631 return {repr:function(){ 1591 1632 return "arrayLikeIter(...)"; 1592 1633 },toString:MochiKit.Base.forwardCall("repr"),next:function(){ 1593 if(i>=_1e 6.length){1634 if(i>=_1e7.length){ 1594 1635 throw MochiKit.Iter.StopIteration; 1595 1636 } 1596 return _1e 6[i++];1637 return _1e7[i++]; 1597 1638 }}; 1598 },hasIterateNext:function(_1e 8){1599 return (_1e 8&&typeof (_1e8.iterateNext)=="function");1600 },iterateNextIter:function(_1e 9){1639 },hasIterateNext:function(_1e9){ 1640 return (_1e9&&typeof (_1e9.iterateNext)=="function"); 1641 },iterateNextIter:function(_1ea){ 1601 1642 return {repr:function(){ 1602 1643 return "iterateNextIter(...)"; 1603 1644 },toString:MochiKit.Base.forwardCall("repr"),next:function(){ 1604 var rval=_1e 9.iterateNext();1645 var rval=_1ea.iterateNext(); 1605 1646 if(rval===null||rval===undefined){ 1606 1647 throw MochiKit.Iter.StopIteration; … … 1640 1681 MochiKit.Logging.EXPORT=["LogLevel","LogMessage","Logger","alertListener","logger","log","logError","logDebug","logFatal","logWarning"]; 1641 1682 MochiKit.Logging.EXPORT_OK=["logLevelAtLeast","isLogMessage","compareLogMessage"]; 1642 MochiKit.Logging.LogMessage=function(num,_1e d,info){1683 MochiKit.Logging.LogMessage=function(num,_1ee,info){ 1643 1684 this.num=num; 1644 this.level=_1e d;1685 this.level=_1ee; 1645 1686 this.info=info; 1646 1687 this.timestamp=new Date(); … … 1650 1691 return "LogMessage("+m.map(m.repr,[this.num,this.level,this.info]).join(", ")+")"; 1651 1692 },toString:MochiKit.Base.forwardCall("repr")}; 1652 MochiKit.Base.update(MochiKit.Logging,{logLevelAtLeast:function(_1f 0){1693 MochiKit.Base.update(MochiKit.Logging,{logLevelAtLeast:function(_1f1){ 1653 1694 var self=MochiKit.Logging; 1654 if(typeof (_1f 0)=="string"){1655 _1f 0=self.LogLevel[_1f0];1695 if(typeof (_1f1)=="string"){ 1696 _1f1=self.LogLevel[_1f1]; 1656 1697 } 1657 1698 return function(msg){ 1658 var _1f 3=msg.level;1659 if(typeof (_1f 3)=="string"){1660 _1f 3=self.LogLevel[_1f3];1661 } 1662 return _1f 3>=_1f0;1699 var _1f4=msg.level; 1700 if(typeof (_1f4)=="string"){ 1701 _1f4=self.LogLevel[_1f4]; 1702 } 1703 return _1f4>=_1f1; 1663 1704 }; 1664 1705 },isLogMessage:function(){ 1665 var _1f 4=MochiKit.Logging.LogMessage;1706 var _1f5=MochiKit.Logging.LogMessage; 1666 1707 for(var i=0;i<arguments.length;i++){ 1667 if(!(arguments[i] instanceof _1f 4)){1708 if(!(arguments[i] instanceof _1f5)){ 1668 1709 return false; 1669 1710 } … … 1675 1716 alert("num: "+msg.num+"\nlevel: "+msg.level+"\ninfo: "+msg.info.join(" ")); 1676 1717 }}); 1677 MochiKit.Logging.Logger=function(_1f 9){1718 MochiKit.Logging.Logger=function(_1fa){ 1678 1719 this.counter=0; 1679 if(typeof (_1f 9)=="undefined"||_1f9===null){1680 _1f 9=-1;1681 } 1682 this.maxSize=_1f 9;1720 if(typeof (_1fa)=="undefined"||_1fa===null){ 1721 _1fa=-1; 1722 } 1723 this.maxSize=_1fa; 1683 1724 this._messages=[]; 1684 1725 this.listeners={}; … … 1715 1756 pair[1](msg); 1716 1757 } 1717 },addListener:function(_1f e,_1ff,_200){1718 if(typeof (_ 1ff)=="string"){1719 _ 1ff=MochiKit.Logging.logLevelAtLeast(_1ff);1720 } 1721 var _20 1=[_1ff,_200];1722 _20 1.ident=_1fe;1723 this.listeners[_1f e]=_201;1724 },removeListener:function(_20 2){1725 delete this.listeners[_20 2];1726 },baseLog:function(_20 3,_204){1727 var msg=new MochiKit.Logging.LogMessage(this.counter,_20 3,MochiKit.Base.extend(null,arguments,1));1758 },addListener:function(_1ff,_200,_201){ 1759 if(typeof (_200)=="string"){ 1760 _200=MochiKit.Logging.logLevelAtLeast(_200); 1761 } 1762 var _202=[_200,_201]; 1763 _202.ident=_1ff; 1764 this.listeners[_1ff]=_202; 1765 },removeListener:function(_203){ 1766 delete this.listeners[_203]; 1767 },baseLog:function(_204,_205){ 1768 var msg=new MochiKit.Logging.LogMessage(this.counter,_204,MochiKit.Base.extend(null,arguments,1)); 1728 1769 this._messages.push(msg); 1729 1770 this.dispatchListeners(msg); … … 1735 1776 this._messages.shift(); 1736 1777 } 1737 },getMessages:function(_20 6){1738 var _20 7=0;1739 if(!(typeof (_20 6)=="undefined"||_206===null)){1740 _20 7=Math.max(0,this._messages.length-_206);1741 } 1742 return this._messages.slice(_20 7);1743 },getMessageText:function(_20 8){1744 if(typeof (_20 8)=="undefined"||_208===null){1745 _20 8=30;1746 } 1747 var _20 9=this.getMessages(_208);1748 if(_20 9.length){1778 },getMessages:function(_207){ 1779 var _208=0; 1780 if(!(typeof (_207)=="undefined"||_207===null)){ 1781 _208=Math.max(0,this._messages.length-_207); 1782 } 1783 return this._messages.slice(_208); 1784 },getMessageText:function(_209){ 1785 if(typeof (_209)=="undefined"||_209===null){ 1786 _209=30; 1787 } 1788 var _20a=this.getMessages(_209); 1789 if(_20a.length){ 1749 1790 var lst=map(function(m){ 1750 1791 return "\n ["+m.num+"] "+m.level+": "+m.info.join(" "); 1751 },_20 9);1752 lst.unshift("LAST "+_20 9.length+" MESSAGES:");1792 },_20a);
