// brython.js brython.info // version [3, 3, 0, 'alpha', 0] // implementation [3, 3, 2, 'dev', 0] // version compiled from commented, indented source files at // github.com/brython-dev/brython !function(r,n){"use strict";function t(r,n,t,e){for(t=void 0!==t?t:0,e=void 0!==e?e:r.length;e>t;){var c=e+t>>1;r[c]>n?e=c:t=c+1}return t}function e(r){if(35>r)return r;var n=t(K,r);return L[n]}function c(r){var n=t(M,r);return N[n]}function u(r){switch(r.charCodeAt(0)){case 9:case 10:case 11:case 12:case 13:case 28:case 29:case 30:case 31:case 32:case 133:case 160:case 5760:case 8192:case 8193:case 8194:case 8195:case 8196:case 8197:case 8198:case 8199:case 8200:case 8201:case 8202:case 8232:case 8233:case 8239:case 8287:case 12288:return!0}return!1}function a(r){var n;return r>=1114112?n=0:(n=e(r>>J),n=c((n<e;e++)t+=String.fromCharCode(I[r+e]);return t}function o(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&T)}function f(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&V)}function h(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&W)}function v(r){var n=r.charCodeAt(0),t=a(n);return t[H]&P?t[F]:-1}function s(r){return v(r)<0?0:1}function d(r){var n=r.charCodeAt(0),t=a(n);return t[H]&Q?t[G]:-1}function A(r){return d(r)<0?0:1}function l(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&Y)}function C(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&X)}function g(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&R)}function p(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&U)}function m(r){var n=r.charCodeAt(0),t=a(n);return t[H]&rn?i(65535&t[D],t[D]>>24):String.fromCharCode(n+t[D])}function S(r){var n=r.charCodeAt(0),t=a(n);return t[H]&rn?i(65535&t[E],t[E]>>24):String.fromCharCode(n+t[E])}function w(r){var n=r.charCodeAt(0),t=a(n);return t[H]&rn?i(65535&t[B],t[B]>>24):String.fromCharCode(n+t[B])}function b(r){var n=r.charCodeAt(0),t=a(n);if(t[H]&rn&&t[D]>>20&7){var e=(65535&t[D])+(t[D]>>24),c=t[D]>>20&7;return i(e,c)}return m(r)}function z(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&$)}function _(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&Z)}function j(r){var n=r.charCodeAt(0),t=a(n);return 0!=(t[H]&O)}function k(r){return j(r)||s(r)||A(r)||l(r)}function q(r,n){var t,e;for(t=n-1;t>=0&&(e=r.charAt(t),_(e));t--);var c=t>=0&&z(e);if(c){for(t=n+1;r.length>t&&(e=r.charAt(t),_(e));t++);c=t==r.length||!z(e)}return String.fromCharCode(c?962:963)}function x(r,n,t){return 931==r.charCodeAt(0)?q(n,t):m(r)}n.unicode=r;var y=[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,32],[0,0,0,0,0,48],[0,0,0,0,0,1056],[0,0,0,0,0,1024],[0,0,0,0,0,5120],[0,0,0,0,0,3590],[0,0,0,1,1,3590],[0,0,0,2,2,3590],[0,0,0,3,3,3590],[0,0,0,4,4,3590],[0,0,0,5,5,3590],[0,0,0,6,6,3590],[0,0,0,7,7,3590],[0,0,0,8,8,3590],[0,0,0,9,9,3590],[0,32,0,0,0,10113],[0,0,0,0,0,1536],[-32,0,-32,0,0,9993],[0,0,0,0,0,9993],[0,0,0,0,0,4096],[0,0,0,0,2,3076],[0,0,0,0,3,3076],[16777218,17825792,16777218,0,0,26377],[0,0,0,0,0,5632],[0,0,0,0,1,3076],[0,0,0,0,0,3072],[33554438,18874371,33554440,0,0,26377],[121,0,121,0,0,9993],[0,1,0,0,0,10113],[-1,0,-1,0,0,9993],[16777228,33554442,16777228,0,0,26497],[-232,0,-232,0,0,9993],[33554448,18874381,33554448,0,0,26377],[0,-121,0,0,0,10113],[16777236,17825810,16777236,0,0,26377],[195,0,195,0,0,9993],[0,210,0,0,0,10113],[0,206,0,0,0,10113],[0,205,0,0,0,10113],[0,79,0,0,0,10113],[0,202,0,0,0,10113],[0,203,0,0,0,10113],[0,207,0,0,0,10113],[97,0,97,0,0,9993],[0,211,0,0,0,10113],[0,209,0,0,0,10113],[163,0,163,0,0,9993],[0,213,0,0,0,10113],[130,0,130,0,0,9993],[0,214,0,0,0,10113],[0,218,0,0,0,10113],[0,217,0,0,0,10113],[0,219,0,0,0,10113],[0,0,0,0,0,1793],[56,0,56,0,0,9993],[0,2,1,0,0,10113],[-1,1,0,0,0,10049],[-2,0,-1,0,0,9993],[-79,0,-79,0,0,9993],[33554456,18874389,33554456,0,0,26377],[0,-97,0,0,0,10113],[0,-56,0,0,0,10113],[0,-130,0,0,0,10113],[0,10795,0,0,0,10113],[0,-163,0,0,0,10113],[0,10792,0,0,0,10113],[10815,0,10815,0,0,9993],[0,-195,0,0,0,10113],[0,69,0,0,0,10113],[0,71,0,0,0,10113],[10783,0,10783,0,0,9993],[10780,0,10780,0,0,9993],[10782,0,10782,0,0,9993],[-210,0,-210,0,0,9993],[-206,0,-206,0,0,9993],[-205,0,-205,0,0,9993],[-202,0,-202,0,0,9993],[-203,0,-203,0,0,9993],[42319,0,42319,0,0,9993],[42315,0,42315,0,0,9993],[-207,0,-207,0,0,9993],[42280,0,42280,0,0,9993],[42308,0,42308,0,0,9993],[-209,0,-209,0,0,9993],[-211,0,-211,0,0,9993],[10743,0,10743,0,0,9993],[42305,0,42305,0,0,9993],[10749,0,10749,0,0,9993],[-213,0,-213,0,0,9993],[-214,0,-214,0,0,9993],[10727,0,10727,0,0,9993],[-218,0,-218,0,0,9993],[42282,0,42282,0,0,9993],[-69,0,-69,0,0,9993],[-217,0,-217,0,0,9993],[-71,0,-71,0,0,9993],[-219,0,-219,0,0,9993],[42261,0,42261,0,0,9993],[42258,0,42258,0,0,9993],[0,0,0,0,0,14089],[0,0,0,0,0,5889],[16777244,17825818,16777244,0,0,30216],[0,0,0,0,0,13321],[0,116,0,0,0,10113],[0,38,0,0,0,10113],[0,37,0,0,0,10113],[0,64,0,0,0,10113],[0,63,0,0,0,10113],[50331681,19922973,50331681,0,0,26377],[-38,0,-38,0,0,9993],[-37,0,-37,0,0,9993],[50331688,19922980,50331688,0,0,26377],[16777261,17825835,16777261,0,0,26377],[-64,0,-64,0,0,9993],[-63,0,-63,0,0,9993],[0,8,0,0,0,10113],[16777264,17825838,16777264,0,0,26377],[16777267,17825841,16777267,0,0,26377],[0,0,0,0,0,10113],[16777270,17825844,16777270,0,0,26377],[16777273,17825847,16777273,0,0,26377],[-8,0,-8,0,0,9993],[16777276,17825850,16777276,0,0,26377],[16777279,17825853,16777279,0,0,26377],[7,0,7,0,0,9993],[-116,0,-116,0,0,9993],[0,-60,0,0,0,10113],[16777282,17825856,16777282,0,0,26377],[0,-7,0,0,0,10113],[0,80,0,0,0,10113],[-80,0,-80,0,0,9993],[0,15,0,0,0,10113],[-15,0,-15,0,0,9993],[0,48,0,0,0,10113],[-48,0,-48,0,0,9993],[33554502,18874435,33554504,0,0,26377],[0,0,0,0,0,1537],[0,7264,0,0,0,10113],[0,0,0,0,1,3588],[0,0,0,0,2,3588],[0,0,0,0,3,3588],[0,0,0,0,4,3588],[0,0,0,0,5,3588],[0,0,0,0,6,3588],[0,0,0,0,7,3588],[0,0,0,0,8,3588],[0,0,0,0,9,3588],[16777292,17825866,16777292,0,0,26497],[16777295,17825869,16777295,0,0,26497],[16777298,17825872,16777298,0,0,26497],[16777301,17825875,16777301,0,0,26497],[16777304,17825878,16777304,0,0,26497],[16777307,17825881,16777307,0,0,26497],[16777310,17825884,16777310,0,0,26497],[16777313,17825887,16777313,0,0,26497],[16777316,17825890,16777316,0,0,26497],[16777319,17825893,16777319,0,0,26497],[16777322,17825896,16777322,0,0,26497],[16777325,17825899,16777325,0,0,26497],[16777328,17825902,16777328,0,0,26497],[16777331,17825905,16777331,0,0,26497],[16777334,17825908,16777334,0,0,26497],[16777337,17825911,16777337,0,0,26497],[16777340,17825914,16777340,0,0,26497],[16777343,17825917,16777343,0,0,26497],[16777346,17825920,16777346,0,0,26497],[16777349,17825923,16777349,0,0,26497],[16777352,17825926,16777352,0,0,26497],[16777355,17825929,16777355,0,0,26497],[16777358,17825932,16777358,0,0,26497],[16777361,17825935,16777361,0,0,26497],[16777364,17825938,16777364,0,0,26497],[16777367,17825941,16777367,0,0,26497],[16777370,17825944,16777370,0,0,26497],[16777373,17825947,16777373,0,0,26497],[16777376,17825950,16777376,0,0,26497],[16777379,17825953,16777379,0,0,26497],[16777382,17825956,16777382,0,0,26497],[16777385,17825959,16777385,0,0,26497],[16777388,17825962,16777388,0,0,26497],[16777391,17825965,16777391,0,0,26497],[16777394,17825968,16777394,0,0,26497],[16777397,17825971,16777397,0,0,26497],[16777400,17825974,16777400,0,0,26497],[16777403,17825977,16777403,0,0,26497],[16777406,17825980,16777406,0,0,26497],[16777409,17825983,16777409,0,0,26497],[16777412,17825986,16777412,0,0,26497],[16777415,17825989,16777415,0,0,26497],[16777418,17825992,16777418,0,0,26497],[16777421,17825995,16777421,0,0,26497],[16777424,17825998,16777424,0,0,26497],[16777427,17826001,16777427,0,0,26497],[16777430,17826004,16777430,0,0,26497],[16777433,17826007,16777433,0,0,26497],[16777436,17826010,16777436,0,0,26497],[16777439,17826013,16777439,0,0,26497],[16777442,17826016,16777442,0,0,26497],[16777445,17826019,16777445,0,0,26497],[16777448,17826022,16777448,0,0,26497],[16777451,17826025,16777451,0,0,26497],[16777454,17826028,16777454,0,0,26497],[16777457,17826031,16777457,0,0,26497],[16777460,17826034,16777460,0,0,26497],[16777463,17826037,16777463,0,0,26497],[16777466,17826040,16777466,0,0,26497],[16777469,17826043,16777469,0,0,26497],[16777472,17826046,16777472,0,0,26497],[16777475,17826049,16777475,0,0,26497],[16777478,17826052,16777478,0,0,26497],[16777481,17826055,16777481,0,0,26497],[16777484,17826058,16777484,0,0,26497],[16777487,17826061,16777487,0,0,26497],[16777490,17826064,16777490,0,0,26497],[16777493,17826067,16777493,0,0,26497],[16777496,17826070,16777496,0,0,26497],[16777499,17826073,16777499,0,0,26497],[16777502,17826076,16777502,0,0,26497],[16777505,17826079,16777505,0,0,26497],[16777508,17826082,16777508,0,0,26497],[16777511,17826085,16777511,0,0,26497],[16777514,17826088,16777514,0,0,26497],[16777517,17826091,16777517,0,0,26497],[16777520,17826094,16777520,0,0,26497],[16777523,17826097,16777523,0,0,26497],[16777526,17826100,16777526,0,0,26497],[16777529,17826103,16777529,0,0,26497],[16777532,17826106,16777532,0,0,26497],[16777535,17826109,16777535,0,0,26497],[16777538,17826112,16777538,0,0,26497],[16777541,17826115,16777541,0,0,26497],[16777544,17826118,16777544,0,0,26497],[16777547,17826121,16777547,0,0,26497],[16777550,17826124,16777550,0,0,26377],[16777553,17826127,16777553,0,0,26377],[16777556,17826130,16777556,0,0,26377],[16777559,17826133,16777559,0,0,26377],[16777562,17826136,16777562,0,0,26377],[16777565,17826139,16777565,0,0,26377],[0,0,0,0,0,3840],[35332,0,35332,0,0,9993],[3814,0,3814,0,0,9993],[33554785,18874718,33554785,0,0,26377],[33554790,18874723,33554790,0,0,26377],[33554795,18874728,33554795,0,0,26377],[33554800,18874733,33554800,0,0,26377],[33554805,18874738,33554805,0,0,26377],[16777593,17826167,16777593,0,0,26377],[16777597,18874746,16777597,0,0,26497],[8,0,8,0,0,9993],[0,-8,0,0,0,10113],[33554817,18874750,33554817,0,0,26377],[50332039,19923331,50332039,0,0,26377],[50332046,19923338,50332046,0,0,26377],[50332053,19923345,50332053,0,0,26377],[74,0,74,0,0,9993],[86,0,86,0,0,9993],[100,0,100,0,0,9993],[128,0,128,0,0,9993],[112,0,112,0,0,9993],[126,0,126,0,0,9993],[33554843,18874776,16777629,0,0,26377],[33554849,18874782,16777635,0,0,26377],[33554855,18874788,16777641,0,0,26377],[33554861,18874794,16777647,0,0,26377],[33554867,18874800,16777653,0,0,26377],[33554873,18874806,16777659,0,0,26377],[33554879,18874812,16777665,0,0,26377],[33554885,18874818,16777671,0,0,26377],[33554891,18874824,16777677,0,0,26433],[33554897,18874830,16777683,0,0,26433],[33554903,18874836,16777689,0,0,26433],[33554909,18874842,16777695,0,0,26433],[33554915,18874848,16777701,0,0,26433],[33554921,18874854,16777707,0,0,26433],[33554927,18874860,16777713,0,0,26433],[33554933,18874866,16777719,0,0,26433],[33554939,18874872,16777725,0,0,26377],[33554945,18874878,16777731,0,0,26377],[33554951,18874884,16777737,0,0,26377],[33554957,18874890,16777743,0,0,26377],[33554963,18874896,16777749,0,0,26377],[33554969,18874902,16777755,0,0,26377],[33554975,18874908,16777761,0,0,26377],[33554981,18874914,16777767,0,0,26377],[33554987,18874920,16777773,0,0,26433],[33554993,18874926,16777779,0,0,26433],[33554999,18874932,16777785,0,0,26433],[33555005,18874938,16777791,0,0,26433],[33555011,18874944,16777797,0,0,26433],[33555017,18874950,16777803,0,0,26433],[33555023,18874956,16777809,0,0,26433],[33555029,18874962,16777815,0,0,26433],[33555035,18874968,16777821,0,0,26377],[33555041,18874974,16777827,0,0,26377],[33555047,18874980,16777833,0,0,26377],[33555053,18874986,16777839,0,0,26377],[33555059,18874992,16777845,0,0,26377],[33555065,18874998,16777851,0,0,26377],[33555071,18875004,16777857,0,0,26377],[33555077,18875010,16777863,0,0,26377],[33555083,18875016,16777869,0,0,26433],[33555089,18875022,16777875,0,0,26433],[33555095,18875028,16777881,0,0,26433],[33555101,18875034,16777887,0,0,26433],[33555107,18875040,16777893,0,0,26433],[33555113,18875046,16777899,0,0,26433],[33555119,18875052,16777905,0,0,26433],[33555125,18875058,16777911,0,0,26433],[33555131,18875064,33555133,0,0,26377],[33555138,18875071,16777924,0,0,26377],[33555144,18875077,33555146,0,0,26377],[33555151,18875084,33555151,0,0,26377],[50332373,19923665,50332376,0,0,26377],[0,-74,0,0,0,10113],[33555166,18875099,16777952,0,0,26433],[16777955,17826529,16777955,0,0,26377],[33555175,18875108,33555177,0,0,26377],[33555182,18875115,16777968,0,0,26377],[33555188,18875121,33555190,0,0,26377],[33555195,18875128,33555195,0,0,26377],[50332417,19923709,50332420,0,0,26377],[0,-86,0,0,0,10113],[33555210,18875143,16777996,0,0,26433],[50332433,19923725,50332433,0,0,26377],[50332440,19923732,50332440,0,0,26377],[33555230,18875163,33555230,0,0,26377],[50332452,19923744,50332452,0,0,26377],[0,-100,0,0,0,10113],[50332459,19923751,50332459,0,0,26377],[50332466,19923758,50332466,0,0,26377],[33555256,18875189,33555256,0,0,26377],[33555261,18875194,33555261,0,0,26377],[50332483,19923775,50332483,0,0,26377],[0,-112,0,0,0,10113],[33555273,18875206,33555275,0,0,26377],[33555280,18875213,16778066,0,0,26377],[33555286,18875219,33555288,0,0,26377],[33555293,18875226,33555293,0,0,26377],[50332515,19923807,50332518,0,0,26377],[0,-128,0,0,0,10113],[0,-126,0,0,0,10113],[33555308,18875241,16778094,0,0,26433],[0,0,0,0,0,3076],[0,0,0,0,4,3076],[0,0,0,0,5,3076],[0,0,0,0,6,3076],[0,0,0,0,7,3076],[0,0,0,0,8,3076],[0,0,0,0,9,3076],[0,0,0,0,0,1792],[0,-7517,0,0,0,10113],[0,-8383,0,0,0,10113],[0,-8262,0,0,0,10113],[0,28,0,0,0,10113],[-28,0,-28,0,0,9993],[0,16,0,0,0,12160],[-16,0,-16,0,0,12040],[0,26,0,0,0,9344],[-26,0,-26,0,0,9224],[0,-10743,0,0,0,10113],[0,-3814,0,0,0,10113],[0,-10727,0,0,0,10113],[-10795,0,-10795,0,0,9993],[-10792,0,-10792,0,0,9993],[0,-10780,0,0,0,10113],[0,-10749,0,0,0,10113],[0,-10783,0,0,0,10113],[0,-10782,0,0,0,10113],[0,-10815,0,0,0,10113],[-7264,0,-7264,0,0,9993],[0,0,0,0,0,5121],[0,0,0,0,0,3841],[0,-35332,0,0,0,10113],[0,-42280,0,0,0,10113],[0,-42308,0,0,0,10113],[0,-42319,0,0,0,10113],[0,-42315,0,0,0,10113],[0,-42305,0,0,0,10113],[0,-42258,0,0,0,10113],[0,-42282,0,0,0,10113],[0,-42261,0,0,0,10113],[0,928,0,0,0,10113],[-928,0,-928,0,0,9993],[16778097,17826671,16778097,0,0,26377],[16778100,17826674,16778100,0,0,26377],[16778103,17826677,16778103,0,0,26377],[16778106,17826680,16778106,0,0,26377],[16778109,17826683,16778109,0,0,26377],[16778112,17826686,16778112,0,0,26377],[16778115,17826689,16778115,0,0,26377],[16778118,17826692,16778118,0,0,26377],[16778121,17826695,16778121,0,0,26377],[16778124,17826698,16778124,0,0,26377],[16778127,17826701,16778127,0,0,26377],[16778130,17826704,16778130,0,0,26377],[16778133,17826707,16778133,0,0,26377],[16778136,17826710,16778136,0,0,26377],[16778139,17826713,16778139,0,0,26377],[16778142,17826716,16778142,0,0,26377],[16778145,17826719,16778145,0,0,26377],[16778148,17826722,16778148,0,0,26377],[16778151,17826725,16778151,0,0,26377],[16778154,17826728,16778154,0,0,26377],[16778157,17826731,16778157,0,0,26377],[16778160,17826734,16778160,0,0,26377],[16778163,17826737,16778163,0,0,26377],[16778166,17826740,16778166,0,0,26377],[16778169,17826743,16778169,0,0,26377],[16778172,17826746,16778172,0,0,26377],[16778175,17826749,16778175,0,0,26377],[16778178,17826752,16778178,0,0,26377],[16778181,17826755,16778181,0,0,26377],[16778184,17826758,16778184,0,0,26377],[16778187,17826761,16778187,0,0,26377],[16778190,17826764,16778190,0,0,26377],[16778193,17826767,16778193,0,0,26377],[16778196,17826770,16778196,0,0,26377],[16778199,17826773,16778199,0,0,26377],[16778202,17826776,16778202,0,0,26377],[16778205,17826779,16778205,0,0,26377],[16778208,17826782,16778208,0,0,26377],[16778211,17826785,16778211,0,0,26377],[16778214,17826788,16778214,0,0,26377],[16778217,17826791,16778217,0,0,26377],[16778220,17826794,16778220,0,0,26377],[16778223,17826797,16778223,0,0,26377],[16778226,17826800,16778226,0,0,26377],[16778229,17826803,16778229,0,0,26377],[16778232,17826806,16778232,0,0,26377],[16778235,17826809,16778235,0,0,26377],[16778238,17826812,16778238,0,0,26377],[16778241,17826815,16778241,0,0,26377],[16778244,17826818,16778244,0,0,26377],[16778247,17826821,16778247,0,0,26377],[16778250,17826824,16778250,0,0,26377],[16778253,17826827,16778253,0,0,26377],[16778256,17826830,16778256,0,0,26377],[16778259,17826833,16778259,0,0,26377],[16778262,17826836,16778262,0,0,26377],[16778265,17826839,16778265,0,0,26377],[16778268,17826842,16778268,0,0,26377],[16778271,17826845,16778271,0,0,26377],[16778274,17826848,16778274,0,0,26377],[16778277,17826851,16778277,0,0,26377],[16778280,17826854,16778280,0,0,26377],[16778283,17826857,16778283,0,0,26377],[16778286,17826860,16778286,0,0,26377],[16778289,17826863,16778289,0,0,26377],[16778292,17826866,16778292,0,0,26377],[16778295,17826869,16778295,0,0,26377],[16778298,17826872,16778298,0,0,26377],[16778301,17826875,16778301,0,0,26377],[16778304,17826878,16778304,0,0,26377],[16778307,17826881,16778307,0,0,26377],[16778310,17826884,16778310,0,0,26377],[16778313,17826887,16778313,0,0,26377],[16778316,17826890,16778316,0,0,26377],[16778319,17826893,16778319,0,0,26377],[16778322,17826896,16778322,0,0,26377],[16778325,17826899,16778325,0,0,26377],[16778328,17826902,16778328,0,0,26377],[16778331,17826905,16778331,0,0,26377],[16778334,17826908,16778334,0,0,26377],[33555554,18875487,33555556,0,0,26377],[33555561,18875494,33555563,0,0,26377],[33555568,18875501,33555570,0,0,26377],[50332792,19924084,50332795,0,0,26377],[50332802,19924094,50332805,0,0,26377],[33555595,18875528,33555597,0,0,26377],[33555602,18875535,33555604,0,0,26377],[33555609,18875542,33555611,0,0,26377],[33555616,18875549,33555618,0,0,26377],[33555623,18875556,33555625,0,0,26377],[33555630,18875563,33555632,0,0,26377],[33555637,18875570,33555639,0,0,26377],[0,0,0,0,0,1025],[0,0,0,0,0,5633],[0,40,0,0,0,10113],[-40,0,-40,0,0,9993],[0,0,0,0,0,9344]],B=0,D=1,E=2,F=3,G=4,H=5,I=[181,956,924,223,115,115,83,83,83,115,105,775,304,329,700,110,700,78,383,115,83,496,106,780,74,780,837,953,921,912,953,776,769,921,776,769,944,965,776,769,933,776,769,962,963,931,976,946,914,977,952,920,981,966,934,982,960,928,1008,954,922,1009,961,929,1013,949,917,1415,1381,1410,1333,1362,1333,1410,43888,5024,5024,43889,5025,5025,43890,5026,5026,43891,5027,5027,43892,5028,5028,43893,5029,5029,43894,5030,5030,43895,5031,5031,43896,5032,5032,43897,5033,5033,43898,5034,5034,43899,5035,5035,43900,5036,5036,43901,5037,5037,43902,5038,5038,43903,5039,5039,43904,5040,5040,43905,5041,5041,43906,5042,5042,43907,5043,5043,43908,5044,5044,43909,5045,5045,43910,5046,5046,43911,5047,5047,43912,5048,5048,43913,5049,5049,43914,5050,5050,43915,5051,5051,43916,5052,5052,43917,5053,5053,43918,5054,5054,43919,5055,5055,43920,5056,5056,43921,5057,5057,43922,5058,5058,43923,5059,5059,43924,5060,5060,43925,5061,5061,43926,5062,5062,43927,5063,5063,43928,5064,5064,43929,5065,5065,43930,5066,5066,43931,5067,5067,43932,5068,5068,43933,5069,5069,43934,5070,5070,43935,5071,5071,43936,5072,5072,43937,5073,5073,43938,5074,5074,43939,5075,5075,43940,5076,5076,43941,5077,5077,43942,5078,5078,43943,5079,5079,43944,5080,5080,43945,5081,5081,43946,5082,5082,43947,5083,5083,43948,5084,5084,43949,5085,5085,43950,5086,5086,43951,5087,5087,43952,5088,5088,43953,5089,5089,43954,5090,5090,43955,5091,5091,43956,5092,5092,43957,5093,5093,43958,5094,5094,43959,5095,5095,43960,5096,5096,43961,5097,5097,43962,5098,5098,43963,5099,5099,43964,5100,5100,43965,5101,5101,43966,5102,5102,43967,5103,5103,5112,5104,5104,5113,5105,5105,5114,5106,5106,5115,5107,5107,5116,5108,5108,5117,5109,5109,5112,5104,5104,5113,5105,5105,5114,5106,5106,5115,5107,5107,5116,5108,5108,5117,5109,5109,7830,104,817,72,817,7831,116,776,84,776,7832,119,778,87,778,7833,121,778,89,778,7834,97,702,65,702,7835,7777,7776,223,115,115,7838,8016,965,787,933,787,8018,965,787,768,933,787,768,8020,965,787,769,933,787,769,8022,965,787,834,933,787,834,8064,7936,953,7944,921,8072,8065,7937,953,7945,921,8073,8066,7938,953,7946,921,8074,8067,7939,953,7947,921,8075,8068,7940,953,7948,921,8076,8069,7941,953,7949,921,8077,8070,7942,953,7950,921,8078,8071,7943,953,7951,921,8079,8064,7936,953,7944,921,8072,8065,7937,953,7945,921,8073,8066,7938,953,7946,921,8074,8067,7939,953,7947,921,8075,8068,7940,953,7948,921,8076,8069,7941,953,7949,921,8077,8070,7942,953,7950,921,8078,8071,7943,953,7951,921,8079,8080,7968,953,7976,921,8088,8081,7969,953,7977,921,8089,8082,7970,953,7978,921,8090,8083,7971,953,7979,921,8091,8084,7972,953,7980,921,8092,8085,7973,953,7981,921,8093,8086,7974,953,7982,921,8094,8087,7975,953,7983,921,8095,8080,7968,953,7976,921,8088,8081,7969,953,7977,921,8089,8082,7970,953,7978,921,8090,8083,7971,953,7979,921,8091,8084,7972,953,7980,921,8092,8085,7973,953,7981,921,8093,8086,7974,953,7982,921,8094,8087,7975,953,7983,921,8095,8096,8032,953,8040,921,8104,8097,8033,953,8041,921,8105,8098,8034,953,8042,921,8106,8099,8035,953,8043,921,8107,8100,8036,953,8044,921,8108,8101,8037,953,8045,921,8109,8102,8038,953,8046,921,8110,8103,8039,953,8047,921,8111,8096,8032,953,8040,921,8104,8097,8033,953,8041,921,8105,8098,8034,953,8042,921,8106,8099,8035,953,8043,921,8107,8100,8036,953,8044,921,8108,8101,8037,953,8045,921,8109,8102,8038,953,8046,921,8110,8103,8039,953,8047,921,8111,8114,8048,953,8122,921,8122,837,8115,945,953,913,921,8124,8116,940,953,902,921,902,837,8118,945,834,913,834,8119,945,834,953,913,834,921,913,834,837,8115,945,953,913,921,8124,8126,953,921,8130,8052,953,8138,921,8138,837,8131,951,953,919,921,8140,8132,942,953,905,921,905,837,8134,951,834,919,834,8135,951,834,953,919,834,921,919,834,837,8131,951,953,919,921,8140,8146,953,776,768,921,776,768,8147,953,776,769,921,776,769,8150,953,834,921,834,8151,953,776,834,921,776,834,8162,965,776,768,933,776,768,8163,965,776,769,933,776,769,8164,961,787,929,787,8166,965,834,933,834,8167,965,776,834,933,776,834,8178,8060,953,8186,921,8186,837,8179,969,953,937,921,8188,8180,974,953,911,921,911,837,8182,969,834,937,834,8183,969,834,953,937,834,921,937,834,837,8179,969,953,937,921,8188,43888,5024,5024,43889,5025,5025,43890,5026,5026,43891,5027,5027,43892,5028,5028,43893,5029,5029,43894,5030,5030,43895,5031,5031,43896,5032,5032,43897,5033,5033,43898,5034,5034,43899,5035,5035,43900,5036,5036,43901,5037,5037,43902,5038,5038,43903,5039,5039,43904,5040,5040,43905,5041,5041,43906,5042,5042,43907,5043,5043,43908,5044,5044,43909,5045,5045,43910,5046,5046,43911,5047,5047,43912,5048,5048,43913,5049,5049,43914,5050,5050,43915,5051,5051,43916,5052,5052,43917,5053,5053,43918,5054,5054,43919,5055,5055,43920,5056,5056,43921,5057,5057,43922,5058,5058,43923,5059,5059,43924,5060,5060,43925,5061,5061,43926,5062,5062,43927,5063,5063,43928,5064,5064,43929,5065,5065,43930,5066,5066,43931,5067,5067,43932,5068,5068,43933,5069,5069,43934,5070,5070,43935,5071,5071,43936,5072,5072,43937,5073,5073,43938,5074,5074,43939,5075,5075,43940,5076,5076,43941,5077,5077,43942,5078,5078,43943,5079,5079,43944,5080,5080,43945,5081,5081,43946,5082,5082,43947,5083,5083,43948,5084,5084,43949,5085,5085,43950,5086,5086,43951,5087,5087,43952,5088,5088,43953,5089,5089,43954,5090,5090,43955,5091,5091,43956,5092,5092,43957,5093,5093,43958,5094,5094,43959,5095,5095,43960,5096,5096,43961,5097,5097,43962,5098,5098,43963,5099,5099,43964,5100,5100,43965,5101,5101,43966,5102,5102,43967,5103,5103,64256,102,102,70,70,70,102,64257,102,105,70,73,70,105,64258,102,108,70,76,70,108,64259,102,102,105,70,70,73,70,102,105,64260,102,102,108,70,70,76,70,102,108,64261,115,116,83,84,83,116,64262,115,116,83,84,83,116,64275,1396,1398,1348,1350,1348,1398,64276,1396,1381,1348,1333,1348,1381,64277,1396,1387,1348,1339,1348,1387,64278,1406,1398,1358,1350,1358,1398,64279,1396,1389,1348,1341,1348,1389],J=7,K=[36,37,38,39,40,41,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,71,72,73,74,78,79,80,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,104,105,106,112,113,118,119,155,156,157,158,159,162,163,166,167,168,173,174,177,178,188,189,190,191,197,198,199,207,208,222,223,231,232,236,237,257,258,264,265,281,282,283,300,301,302,319,320,321,329,330,332,333,334,335,336,337,338,339,340,341,342,343,344,431,432,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,526,527,528,529,530,531,532,533,534,535,536,537,538,540,541,544,545,546,547,548,549,550,551,553,554,555,556,557,558,559,561,562,565,566,576,583,584,585,586,587,608,616,617,648,652,653,720,724,725,726,727,728,734,735,736,864,865,888,889,890,928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,948,949,950,976,977,978,988,989,990,992,993,994,995,996,997,998,999,1e3,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1024,1025,1026,1027,1042,1043,1044,1045,1046,1047,1095,1096,1107,1108,1142,1143,1220,1221,1357,1358,1390,1391,1392,1393,1437,1438,1520,1521,1522,1524,1525,7168,7169,7170,7171,7172,7680,8191,8192,8703,8704],L=[34,35,36,37,38,39,34,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,64,68,69,64,70,71,72,73,74,75,76,77,64,78,79,80,81,82,83,84,64,85,86,34,87,34,88,34,89,90,91,92,34,93,34,94,95,34,96,34,97,34,98,99,100,34,101,102,34,103,34,104,34,105,34,101,34,104,34,106,34,107,108,34,109,110,34,111,112,34,113,34,114,115,116,117,118,119,120,121,122,123,124,125,34,126,127,128,129,130,131,132,133,134,34,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,145,34,152,145,153,154,155,156,157,158,159,160,161,162,145,163,145,164,165,166,167,168,169,170,145,171,145,172,173,174,175,145,176,145,177,145,34,178,179,34,180,145,34,181,145,34,182,145,34,183,184,185,186,145,187,188,145,189,145,190,191,145,64,192,193,194,195,145,196,145,197,198,199,200,201,202,203,204,64,205,206,145,34,207,145,208,209,145,210,211,212,213,214,145,64,215,64,216,217,64,218,219,220,221,222,223,224,145,225,226,227,34,87,228,34,229,230,34,231,34,232,34,233,34,234,34,235,34,236,34,237,34,238,145,34,231,34,239,145,240,145,241,242,145,127,243,127,243],M=[9,10,14,28,31,32,33,39,40,46,47,48,49,50,51,52,53,54,55,56,57,58,59,65,91,94,95,96,97,123,127,133,134,160,161,168,169,170,171,173,174,175,176,178,179,180,181,182,183,184,185,186,187,188,191,192,215,216,223,224,247,248,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,428,429,430,431,432,433,435,436,437,438,439,440,441,442,443,444,445,446,447,448,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,570,571,572,573,574,575,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,600,601,602,603,604,605,608,609,610,611,612,613,614,615,616,617,618,619,620,621,623,624,625,626,627,629,630,637,638,640,641,643,644,647,648,649,650,652,653,658,659,660,661,669,670,671,688,697,704,706,710,722,736,741,748,749,750,751,768,837,838,880,881,882,883,884,885,886,887,888,890,891,894,895,896,900,902,903,904,907,908,909,910,912,913,930,931,940,941,944,945,962,963,972,973,975,976,977,978,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999,1e3,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,1024,1040,1072,1104,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,1154,1155,1160,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,1183,1184,1185,1186,1187,1188,1189,1190,1191,1192,1193,1194,1195,1196,1197,1198,1199,1200,1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,1211,1212,1213,1214,1215,1216,1217,1218,1219,1220,1221,1222,1223,1224,1225,1226,1227,1228,1229,1230,1231,1232,1233,1234,1235,1236,1237,1238,1239,1240,1241,1242,1243,1244,1245,1246,1247,1248,1249,1250,1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,1261,1262,1263,1264,1265,1266,1267,1268,1269,1270,1271,1272,1273,1274,1275,1276,1277,1278,1279,1280,1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,1295,1296,1297,1298,1299,1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,1310,1311,1312,1313,1314,1315,1316,1317,1318,1319,1320,1321,1322,1323,1324,1325,1326,1327,1328,1329,1367,1369,1370,1376,1377,1415,1416,1417,1419,1421,1424,1425,1470,1471,1472,1473,1475,1476,1478,1479,1480,1488,1515,1520,1523,1524,1525,1536,1542,1552,1563,1564,1565,1566,1568,1600,1601,1611,1632,1633,1634,1635,1636,1637,1638,1639,1640,1641,1642,1646,1648,1649,1748,1749,1750,1757,1758,1759,1765,1767,1769,1770,1774,1776,1777,1778,1779,1780,1781,1782,1783,1784,1785,1786,1789,1791,1792,1806,1807,1808,1809,1810,1840,1867,1869,1958,1969,1970,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,2027,2036,2038,2042,2043,2048,2070,2074,2075,2084,2085,2088,2089,2094,2096,2111,2112,2137,2140,2142,2143,2208,2229,2275,2307,2308,2362,2363,2364,2365,2366,2369,2377,2381,2382,2384,2385,2392,2402,2404,2406,2407,2408,2409,2410,2411,2412,2413,2414,2415,2416,2417,2418,2433,2434,2436,2437,2445,2447,2449,2451,2473,2474,2481,2482,2483,2486,2490,2492,2493,2494,2497,2501,2503,2505,2507,2509,2510,2511,2519,2520,2524,2526,2527,2530,2532,2534,2535,2536,2537,2538,2539,2540,2541,2542,2543,2544,2546,2548,2554,2556,2561,2563,2564,2565,2571,2575,2577,2579,2601,2602,2609,2610,2612,2613,2615,2616,2618,2620,2621,2622,2625,2627,2631,2633,2635,2638,2641,2642,2649,2653,2654,2655,2662,2663,2664,2665,2666,2667,2668,2669,2670,2671,2672,2674,2677,2678,2689,2691,2692,2693,2702,2703,2706,2707,2729,2730,2737,2738,2740,2741,2746,2748,2749,2750,2753,2758,2759,2761,2762,2763,2765,2766,2768,2769,2784,2786,2788,2790,2791,2792,2793,2794,2795,2796,2797,2798,2799,2800,2802,2809,2810,2817,2818,2820,2821,2829,2831,2833,2835,2857,2858,2865,2866,2868,2869,2874,2876,2877,2878,2879,2880,2881,2885,2887,2889,2891,2893,2894,2902,2903,2904,2908,2910,2911,2914,2916,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,2936,2946,2947,2948,2949,2955,2958,2961,2962,2966,2969,2971,2972,2973,2974,2976,2979,2981,2984,2987,2990,3002,3006,3008,3009,3011,3014,3017,3018,3021,3022,3024,3025,3031,3032,3046,3047,3048,3049,3050,3051,3052,3053,3054,3055,3056,3059,3067,3072,3073,3076,3077,3085,3086,3089,3090,3113,3114,3130,3133,3134,3137,3141,3142,3145,3146,3150,3157,3159,3160,3163,3168,3170,3172,3174,3175,3176,3177,3178,3179,3180,3181,3182,3183,3184,3192,3199,3200,3201,3202,3204,3205,3213,3214,3217,3218,3241,3242,3252,3253,3258,3260,3261,3262,3263,3264,3269,3270,3271,3273,3274,3276,3278,3285,3287,3294,3295,3296,3298,3300,3302,3303,3304,3305,3306,3307,3308,3309,3310,3311,3312,3313,3315,3329,3330,3332,3333,3341,3342,3345,3346,3387,3389,3390,3393,3397,3398,3401,3402,3405,3406,3407,3415,3416,3423,3426,3428,3430,3431,3432,3433,3434,3435,3436,3437,3438,3439,3440,3446,3449,3450,3456,3458,3460,3461,3479,3482,3506,3507,3516,3517,3518,3520,3527,3530,3531,3535,3538,3541,3542,3543,3544,3552,3558,3559,3560,3561,3562,3563,3564,3565,3566,3567,3568,3570,3572,3573,3585,3633,3634,3635,3636,3643,3647,3648,3654,3655,3663,3664,3665,3666,3667,3668,3669,3670,3671,3672,3673,3674,3676,3713,3715,3716,3717,3719,3721,3722,3723,3725,3726,3732,3736,3737,3744,3745,3748,3749,3750,3751,3752,3754,3756,3757,3761,3762,3763,3764,3770,3771,3773,3774,3776,3781,3782,3783,3784,3790,3792,3793,3794,3795,3796,3797,3798,3799,3800,3801,3802,3804,3808,3840,3841,3864,3866,3872,3873,3874,3875,3876,3877,3878,3879,3880,3881,3882,3892,3893,3894,3895,3896,3897,3898,3902,3904,3912,3913,3949,3953,3967,3968,3973,3974,3976,3981,3992,3993,4029,4030,4038,4039,4045,4046,4059,4096,4139,4141,4145,4146,4152,4153,4155,4157,4159,4160,4161,4162,4163,4164,4165,4166,4167,4168,4169,4170,4176,4182,4184,4186,4190,4193,4194,4197,4199,4206,4209,4213,4226,4227,4229,4231,4237,4238,4239,4240,4241,4242,4243,4244,4245,4246,4247,4248,4249,4250,4253,4254,4256,4294,4295,4296,4301,4302,4304,4347,4348,4349,4553,4554,4558,4560,4567,4568,4569,4570,4574,4576,4617,4618,4622,4624,4657,4658,4662,4664,4671,4672,4673,4674,4678,4680,4695,4696,4753,4754,4758,4760,4827,4829,4832,4841,4842,4843,4844,4845,4846,4847,4848,4849,4850,4861,4864,4880,4890,4896,4897,4898,4899,4900,4901,4902,4903,4904,4905,4906,4907,4908,4909,4910,4911,4912,4913,4914,4915,4916,4917,4918,4919,4920,4921,4922,4923,4924,4925,4926,4927,4928,4929,4930,4931,4932,4933,4934,4935,4936,4937,4938,4939,4940,4941,4942,4943,4944,4945,4946,4947,4948,4949,4950,4951,4952,4953,4954,4955,4956,4957,4958,4959,4960,4961,4962,4963,4964,4965,4966,4967,4968,4969,4970,4971,4972,4973,4974,4975,4976,4977,4978,4979,4980,4981,4982,4984,4985,4986,4987,4988,4989,4990,4992,4993,5229,5231,5248,5249,5275,5277,5280,5355,5358,5361,5369,5376,5389,5390,5394,5397,5408,5426,5429,5431,5440,5458,5460,5472,5485,5486,5489,5490,5492,5504,5556,5558,5559,5566,5574,5575,5577,5588,5591,5592,5596,5597,5598,5600,5601,5602,5603,5604,5605,5606,5607,5608,5609,5610,5616,5626,5632,5643,5646,5647,5648,5649,5650,5651,5652,5653,5654,5655,5656,5657,5658,5664,5699,5700,5752,5760,5801,5802,5803,5808,5878,5888,5919,5920,5923,5927,5929,5932,5936,5938,5939,5945,5948,5952,5953,5956,5958,5959,5960,5961,5962,5963,5964,5965,5966,5967,5968,5998,6e3,6005,6016,6060,6064,6090,6096,6097,6098,6099,6100,6101,6102,6103,6104,6105,6106,6107,6110,6144,6167,6169,6171,6172,6174,6176,6229,6230,6231,6232,6239,6240,6241,6242,6243,6245,6253,6259,6269,6271,6272,6273,6274,6275,6276,6277,6278,6279,6280,6281,6282,6288,6289,6290,6291,6292,6293,6294,6295,6296,6297,6298,6304,6311,6312,6318,6320,6334,6335,6400,6404,6405,6452,6453,6454,6459,6460,6461,6466,6467,6469,6476,6480,6481,6482,6483,6484,6485,6486,6487,6488,6489,6490,6507,6516,6525,6528,6530,6531,6561,6562,6566,6568,6570,6571,6574,6576,6577,6578,6579,6580,6581,6582,6583,6584,6585,6586,6630,6631,6632,6634,6637,6638,6639,6642,6644,6652,6656,6692,6700,6708,6710,6712,6715,6720,6721,6722,6723,6724,6725,6726,6727,6728,6729,6730,6733,6736,6737,6738,6739,6740,6741,6742,6743,6744,6745,6746,6776,6782,6784,6848,6856,6864,6867,6868,6881,6882,6889,6893,6894,6898,6900,6901,6903,6904,6906,6912,6956,7019,7032,7033,7034,7037,7038,7067,7104,7158,7164,7168,7169,7170,7171,7172,7173,7174,7175,7176,7177,7178,7179,7180,7181,7182,7183,7184,7185,7186,7187,7188,7189,7190,7191,7192,7193,7194,7195,7196,7197,7198,7199,7200,7201,7202,7203,7204,7205,7206,7207,7208,7209,7210,7211,7212,7213,7214,7215,7216,7217,7218,7219,7220,7221,7222,7223,7224,7225,7226,7227,7228,7229,7230,7231,7232,7233,7234,7235,7236,7237,7238,7239,7240,7241,7242,7243,7244,7245,7246,7247,7248,7249,7250,7251,7252,7253,7254,7255,7256,7257,7258,7259,7260,7261,7262,7263,7264,7265,7266,7267,7268,7269,7270,7271,7272,7273,7274,7275,7276,7277,7278,7279,7280,7281,7282,7283,7284,7285,7286,7287,7288,7289,7290,7291,7292,7293,7294,7295,7296,7297,7298,7299,7300,7301,7302,7303,7304,7305,7306,7307,7308,7309,7310,7311,7312,7313,7314,7315,7316,7317,7318,7319,7320,7321,7322,7323,7324,7326,7327,7328,7329,7330,7331,7332,7333,7334,7335,7336,7337,7338,7339,7340,7341,7342,7343,7344,7345,7346,7347,7348,7349,7350,7351,7352,7353,7354,7355,7356,7357,7358,7359,7360,7361,7362,7363,7364,7365,7366,7367,7368,7369,7370,7371,7372,7373,7374,7375,7376,7377,7378,7379,7380,7381,7382,7383,7384,7385,7386,7387,7388,7389,7390,7391,7392,7393,7394,7395,7396,7397,7398,7399,7400,7401,7402,7403,7404,7405,7406,7407,7408,7409,7410,7411,7412,7413,7414,7415,7416,7417,7418,7419,7420,7421,7422,7423,7424,7432,7440,7446,7448,7454,7456,7464,7472,7480,7488,7494,7496,7502,7504,7505,7506,7507,7508,7509,7510,7511,7512,7513,7514,7515,7516,7517,7518,7519,7520,7528,7536,7538,7542,7544,7546,7548,7550,7552,7553,7554,7555,7556,7557,7558,7559,7560,7561,7562,7563,7564,7565,7566,7567,7568,7569,7570,7571,7572,7573,7574,7575,7576,7577,7578,7579,7580,7581,7582,7583,7584,7585,7586,7587,7588,7589,7590,7591,7592,7593,7594,7595,7596,7597,7598,7599,7600,7602,7603,7604,7605,7606,7607,7608,7610,7612,7613,7614,7615,7618,7619,7620,7621,7622,7623,7624,7628,7629,7632,7634,7635,7636,7638,7639,7640,7642,7644,7645,7648,7650,7651,7652,7653,7654,7655,7656,7658,7660,7661,7664,7666,7667,7668,7669,7670,7671,7672,7674,7676,7677,7679,7680,7691,7696,7704,7706,7716,7717,7719,7720,7722,7727,7728,7743,7745,7764,7765,7775,7776,7781,7782,7792,7793,7794,7796,7797,7798,7799,7800,7801,7802,7807,7808,7809,7810,7811,7812,7813,7814,7815,7816,7817,7818,7823,7824,7837,7840,7871,7888,7901,7905,7906,7909,7921,7936,7938,7939,7943,7944,7946,7947,7950,7952,7955,7956,7957,7958,7960,7961,7966,7972,7973,7974,7975,7976,7977,7978,7979,7980,7982,7983,7984,7986,7987,7988,7989,7993,7994,7996,7998,8e3,8005,8006,8010,8014,8015,8016,8032,8048,8064,8067,8068,8069,8073,8074,8076,8080,8443,8448,8487,8512,8523,8544,8545,8546,8547,8548,8549,8550,8551,8552,8553,8564,8565,8566,8567,8568,8569,8570,8571,8572,8573,8584,8585,8586,8587,8588,8589,8590,8591,8592,8593,8604,8630,8656,8682,8683,8693,8694,8695,8696,8697,8698,8699,8700,8701,8702,8703,8704,8822,8823,8824,8825,8826,8827,8828,8829,8830,8831,8832,8833,8834,8835,8836,8837,8838,8839,8840,8841,8842,8843,8844,8845,8846,8847,8848,8849,8850,8851,8852,9076,9078,9110,9112,9146,9149,9161,9162,9170,9196,9200,9216,9263,9264,9311,9312,9313,9314,9315,9316,9317,9318,9319,9320,9321,9322,9323,9324,9325,9326,9327,9328,9329,9330,9331,9332,9333,9334,9335,9340,9342,9344,9345,9346,9347,9348,9349,9350,9351,9352,9353,9354,9355,9356,9357,9358,9359,9360,9361,9362,9363,9364,9365,9366,9367,9368,9369,9370,9371,9372,9373,9374,9375,9376,9377,9378,9379,9380,9381,9382,9383,9384,9385,9386,9387,9388,9389,9390,9391,9392,9393,9394,9395,9396,9397,9398,9399,9400,9401,9402,9403,9404,9405,9406,9407,9408,9409,9410,9411,9412,9413,9414,9415,9416,9417,9418,9419,9420,9421,9422,9423,9424,9425,9426,9427,9428,9429,9430,9431,9432,9433,9434,9435,9436,9437,9438,9439,9440,9441,9442,9443,9444,9445,9451,9452,9453,9454,9455,9458,9459,9460,9465,9469,9470,9472,9510,9511,9512,9517,9518,9520,9576,9583,9584,9585,9599,9600,9623,9632,9639,9640,9647,9648,9655,9656,9663,9664,9671,9672,9679,9680,9687,9688,9695,9696,9728,9775,9776,9795,9856,9882,9883,9972,9984,10070,10096,10108,10112,10113,10117,10118,10119,10120,10145,10154,10158,10160,10161,10166,10168,10171,10172,10173,10176,10177,10263,10265,10267,10269,10271,10272,10273,10363,10364,10367,10368,10373,10414,10417,10511,10512,10514,10518,10528,10555,10560,10596,10608,10624,10655,10656,10666,10696,10704,10705,10720,10752,10762,10801,10816,10879,10880,10885,10886,11011,11012,11178,11179,11341,11342,11446,11456,11520,11521,11523,11524,11527,11528,11529,11530,11613,11614,11660,11661,11668,11669,11670,11671,11711,11713,11743,11744,11752,11753,11789,11790,11888,11889,11908,11909,11974,11975,12009,12010,12011,12012,12013,12014,12097,12098,12099,12102,12108,12109,12225,12229,12379,12380,12529,12530,12537,12538,12666,12667,12798,12800,12812,12815,12816,12817,13054,13055,13132,13133,13266,13267,13318,13319,13462,13463,13612,13613,13742,13743,13747,13748,13872,13873,13985,13986,14022,14023,14028,14029,14072,14073,14198,14199,14294,14336,14357,14358,14477,14480,14535,14544,14584,14590,14592,14604,14605,14608,14624,14625,14626,14627,14628,14629,14630,14631,14632,14633,14634,14636,14656,14657,14658,14659,14660,14661,14662,14663,14664,14665,14666,14667,14668,14669,14670,14671,14672,14673,14674,14675,14676,14677,14678,14679,14680,14681,14682,14683,14684,14685,14686,14687,14688,14689,14690,14691,14692,14693,14694,14695,14696,14697,14698,14699,14700,14701,14702,14703,14704,14707,14708,14718,14719,14720,14721,14722,14723,14724,14725,14726,14727,14728,14729,14730,14731,14732,14733,14734,14735,14736,14737,14738,14739,14740,14741,14742,14743,14744,14745,14746,14747,14748,14750,14752,14822,14832,14834,14840,14848,14871,14880,14882,14883,14884,14885,14886,14887,14888,14889,14890,14891,14892,14893,14894,14895,14896,14898,14899,14900,14901,14902,14903,14904,14905,14906,14907,14908,14909,14910,14911,14912,14913,14914,14915,14916,14917,14918,14919,14920,14921,14922,14923,14924,14925,14926,14927,14928,14929,14930,14931,14932,14933,14934,14935,14936,14937,14938,14939,14940,14941,14942,14943,14944,14945,14946,14947,14948,14949,14950,14951,14952,14953,14954,14955,14956,14957,14958,14959,14960,14961,14969,14970,14971,14972,14973,14974,14975,14976,14977,14978,14979,14980,14981,14982,14983,14984,14985,14987,14988,14989,14990,14991,14992,14993,14994,14995,14996,14998,14999,15e3,15001,15002,15003,15004,15005,15006,15007,15008,15009,15010,15011,15012,15013,15014,15015,15016,15017,15018,15019,15020,15021,15022,15024,15025,15026,15027,15028,15029,15030,15031,15032,15095,15096,15098,15099,15106,15107,15110,15111,15115,15116,15139,15141,15143,15144,15148,15152,15158,15162,15168,15220,15224,15232,15234,15284,15300,15301,15310,15312,15313,15314,15315,15316,15317,15318,15319,15320,15321,15322,15328,15346,15352,15355,15356,15357,15358,15360,15361,15362,15363,15364,15365,15366,15367,15368,15369,15370,15398,15406,15408,15431,15442,15444,15455,15456,15485,15488,15491,15492,15539,15540,15542,15546,15548,15549,15553,15566,15567,15568,15569,15570,15571,15572,15573,15574,15575,15576,15577,15578,15582,15584,15589,15590,15591,15600,15601,15602,15603,15604,15605,15606,15607,15608,15609,15610,15615,15616,15657,15663,15665,15667,15669,15671,15680,15683,15684,15692,15693,15694,15696,15697,15698,15699,15700,15701,15702,15703,15704,15705,15706,15708,15712,15728,15729,15735,15738,15739,15740,15741,15742,15792,15793,15794,15797,15799,15801,15806,15808,15809,15810,15811,15835,15837,15838,15840,15851,15852,15854,15856,15858,15859,15861,15862,15863,15873,15879,15881,15887,15889,15895,15904,15911,15912,15919,15920,15955,15956,15963,15964,15968,15974,15984,15985,15986,15987,15988,15989,15990,15991,15992,15993,15994,15995,15996,15997,15998,15999,16e3,16001,16002,16003,16004,16005,16006,16007,16008,16009,16010,16011,16012,16013,16014,16015,16016,16017,16018,16019,16020,16021,16022,16023,16024,16025,16026,16027,16028,16029,16030,16031,16032,16033,16034,16035,16036,16037,16038,16039,16040,16041,16042,16043,16044,16045,16046,16047,16048,16049,16050,16051,16052,16053,16054,16055,16056,16057,16058,16059,16060,16061,16062,16063,16064,16099,16101,16102,16104,16105,16107,16108,16109,16110,16112,16113,16114,16115,16116,16117,16118,16119,16120,16121,16122,16128,16164,16176,16199,16203,16252,16256,16384,16491,16492,16499,16500,16504,16505,16562,16563,16593,16594,16595,16596,16637,16638,16750,16752,16858,16896,16897,16898,16899,16900,16901,16902,16903,16915,16916,16917,16918,16919,16920,16925,16926,16927,16937,16938,16951,16952,16957,16958,16959,16960,16962,16963,16965,16966,17074,17090,17107,17246,17252,17342,17344,17360,17424,17426,17480,17520,17530,17532,17534,17536,17552,17555,17556,17562,17568,17584,17587,17589,17613,17616,17618,17619,17620,17621,17622,17639,17640,17644,17648,17649,17650,17651,17652,17653,17654,17655,17656,17657,17658,17659,17660,17661,17662,17663,17789,17791,17792,17793,17799,17800,17806,17807,17808,17809,17810,17811,17812,17813,17814,17815,17816,17817,17818,17819,17825,17851,17854,17855,17856,17857,17883,17894,17904,17905,17950,17952,17983,17986,17992,17994,18e3,18002,18008,18010,18013,18016,18019,18020,18023,18024,18031,18041,18044,18046,18048,18060,18061,18087,18088,18107,18108,18110,18111,18126,18128,18142,18176,18299,18304,18307,18311,18356,18359,18368,18421,18425,18442,18444,18445,18448,18460,18464,18465,18512,18557,18558,18688,18717,18720,18769,18784,18785,18812,18816,18848,18852,18864,18881,18882,18890,18891,18896,18934,18939,18944,18974,18975,18976,19012,19016,19024,19025,19030,19072,19112,19152,19230,19232,19233,19234,19235,19236,19237,19238,19239,19240,19241,19242,19328,19368,19376,19428,19439,19440,19456,19511,19520,19542,19552,19560,19584,19590,19592,19593,19594,19638,19639,19641,19644,19645,19647,19670,19671,19672,19680,19703,19705,19712,19743,19751,19760,19808,19827,19828,19830,19835,19840,19862,19868,19871,19872,19898,19903,19904,19968,20024,20028,20030,20032,20048,20050,20096,20097,20100,20101,20103,20108,20112,20116,20117,20120,20121,20148,20152,20155,20159,20160,20161,20162,20163,20164,20168,20176,20185,20192,20221,20223,20224,20253,20256,20288,20296,20297,20325,20327,20331,20336,20343,20352,20406,20409,20416,20438,20440,20448,20467,20472,20480,20498,20505,20509,20521,20528,20608,20681,20736,20787,20800,20851,20858,20864,20960,20961,20962,20963,20964,20965,20966,20967,20968,20969,20991,20992,20993,20994,20995,21048,21063,21070,21074,21075,21076,21077,21078,21079,21080,21081,21082,21083,21094,21095,21096,21097,21098,21099,21100,21101,21102,21103,21104,21119,21122,21123,21168,21171,21175,21177,21179,21181,21182,21186,21200,21225,21232,21233,21234,21235,21236,21237,21238,21239,21240,21241,21242,21248,21251,21287,21292,21293,21301,21302,21303,21304,21305,21306,21307,21308,21309,21310,21311,21312,21316,21328,21363,21364,21366,21367,21376,21378,21379,21427,21430,21439,21441,21445,21450,21453,21454,21456,21457,21458,21459,21460,21461,21462,21463,21464,21465,21466,21467,21468,21469,21472,21473,21493,21504,21522,21523,21548,21551,21554,21556,21557,21558,21560,21566,21632,21639,21640,21641,21642,21646,21647,21662,21663,21673,21674,21680,21727,21728,21731,21739,21744,21745,21746,21747,21748,21749,21750,21751,21752,21753,21754,21760,21762,21764,21765,21773,21775,21777,21779,21801,21802,21809,21810,21812,21813,21818,21820,21821,21822,21824,21825,21829,21831,21833,21835,21838,21840,21841,21847,21848,21853,21858,21860,21862,21869,21872,21877,21888,21936,21939,21945,21946,21947,21951,21953,21954,21956,21958,21959,21960,21968,21969,21970,21971,21972,21973,21974,21975,21976,21977,21978,22016,22063,22066,22070,22072,22076,22078,22079,22081,22104,22108,22110,22144,22192,22195,22203,22205,22206,22207,22209,22212,22213,22224,22225,22226,22227,22228,22229,22230,22231,22232,22233,22234,22272,22315,22316,22317,22318,22320,22326,22327,22328,22336,22337,22338,22339,22340,22341,22342,22343,22344,22345,22346,22400,22426,22429,22432,22434,22438,22439,22444,22448,22449,22450,22451,22452,22453,22454,22455,22456,22457,22458,22460,22464,22560,22592,22624,22625,22626,22627,22628,22629,22630,22631,22632,22633,22634,22643,22655,22656,22720,22777,22784,22810,22912,23023,23024,23029,23040,23108,23168,23215,23296,23367,23424,23481,23488,23519,23520,23521,23522,23523,23524,23525,23526,23527,23528,23529,23530,23534,23536,23632,23662,23664,23669,23670,23680,23728,23735,23744,23748,23750,23760,23761,23762,23763,23764,23765,23766,23767,23768,23769,23770,23771,23778,23779,23800,23805,23824,23936,24005,24016,24017,24063,24079,24083,24096,24192,24194,24320,24427,24432,24445,24448,24457,24464,24474,24476,24477,24479,24480,24484,24576,24694,24704,24743,24745,24805,24807,24810,24813,24819,24827,24835,24837,24844,24874,24878,24937,24960,25026,25029,25030,25088,25175,25184,25202,25216,25242,25268,25294,25301,25302,25320,25346,25372,25373,25374,25376,25378,25379,25381,25383,25385,25389,25390,25398,25402,25403,25404,25405,25412,25413,25424,25450,25476,25478,25479,25483,25485,25493,25494,25501,25502,25528,25530,25531,25535,25536,25541,25542,25543,25546,25553,25554,25580,25606,25632,25658,25684,25710,25736,25762,25788,25814,25840,25866,25894,25896,25921,25922,25947,25948,25954,25979,25980,26005,26006,26012,26037,26038,26063,26064,26070,26095,26096,26121,26122,26128,26153,26154,26179,26180,26186,26187,26188,26190,26191,26192,26193,26194,26195,26196,26197,26198,26199,26200,26201,26202,26203,26204,26205,26206,26207,26208,26209,26210,26211,26212,26213,26214,26215,26216,26217,26218,26219,26220,26221,26222,26223,26224,26225,26226,26227,26228,26229,26230,26231,26232,26233,26234,26235,26236,26237,26238,26239,26240,26295,26299,26349,26357,26358,26372,26373,26380,26395,26400,26401,26416,26496,26565,26567,26576,26583,26624,26628,26629,26656,26657,26659,26660,26661,26663,26664,26665,26675,26676,26680,26681,26682,26683,26684,26690,26691,26695,26696,26697,26698,26699,26700,26701,26704,26705,26707,26708,26709,26711,26712,26713,26714,26715,26716,26717,26718,26719,26720,26721,26723,26724,26725,26727,26731,26732,26739,26740,26744,26745,26749,26750,26751,26752,26762,26763,26780,26785,26788,26789,26794,26795,26812,26864,26866,26880,26924,26928,27028,27040,27055,27057,27072,27073,27088,27089,27126,27136,27138,27139,27140,27141,27142,27143,27144,27145,27146,27147,27149,27152,27183,27184,27210,27216,27242,27244,27248,27274,27291,27366,27395,27408,27451,27456,27465,27472,27474,27520,27643,27648,27770,27771,27812,27813,27985,28e3,28013,28016,28020,28032,28148,28160,28245,28288,28300,28304,28360,28368,28378,28384,28424,28432,28462,28560,28569,28672,28677,28736,28737,28800,28801,28802,28900,28901,29026,29027,29089,29090,29187,29188,29196,29197,29212,29213,29418,29419,29437,29438,29465,29466,29584,29585,29720,29721,29851,29852,30061,30062,30167,30208,30261,30272,30366,30368,30498,30592,30622,30721,30722,30752,30848,31088,31104,31230,31232],N=[1,2,3,1,3,2,4,5,6,5,6,5,7,8,9,10,11,12,13,14,15,16,6,5,17,5,6,18,6,19,5,1,3,1,2,5,6,5,20,5,21,5,6,5,22,23,6,24,5,25,6,26,20,5,27,5,17,5,17,28,19,5,19,29,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,32,33,30,31,30,31,30,31,20,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,34,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,35,30,31,30,31,30,31,36,37,38,30,31,30,31,39,30,31,40,30,31,20,41,42,43,30,31,40,44,45,46,47,30,31,48,20,46,49,50,51,30,31,30,31,30,31,52,30,31,52,20,30,31,52,30,31,53,30,31,30,31,54,30,31,20,55,30,31,20,56,55,57,58,59,57,58,59,57,58,59,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,60,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,61,57,58,59,30,31,62,63,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,64,20,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,20,65,30,31,66,67,68,30,31,69,70,71,30,31,30,31,30,31,30,31,30,31,72,73,74,75,76,20,77,20,78,20,79,80,20,77,81,20,82,20,83,84,20,85,86,20,87,88,20,86,20,89,90,20,91,20,92,20,93,20,93,20,94,93,95,96,97,20,98,20,55,20,99,100,20,101,102,101,6,102,6,101,6,102,6,102,6,25,103,25,30,31,30,31,102,6,30,31,0,104,50,5,105,0,6,106,25,107,0,108,0,109,110,17,0,17,111,112,113,19,114,19,115,116,117,118,119,120,121,122,123,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,124,125,126,127,128,129,5,30,31,130,30,31,20,64,131,17,19,132,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,5,25,6,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,133,30,31,30,31,30,31,30,31,30,31,30,31,30,31,134,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,0,135,0,102,5,0,136,137,0,5,0,5,0,25,5,25,5,25,5,25,5,25,0,55,0,55,5,6,0,21,5,25,5,21,0,5,55,102,55,25,7,8,9,10,11,12,13,14,15,16,5,55,25,55,5,55,25,21,5,25,102,25,5,25,55,7,8,9,10,11,12,13,14,15,16,55,5,55,5,0,21,55,25,55,25,0,55,25,55,0,7,8,9,10,11,12,13,14,15,16,55,25,102,5,102,0,55,25,102,25,102,25,102,25,0,5,0,55,25,0,5,0,55,0,25,18,55,25,18,25,55,18,25,18,25,18,55,25,55,25,5,7,8,9,10,11,12,13,14,15,16,5,102,55,25,18,0,55,0,55,0,55,0,55,0,55,0,55,0,25,55,18,25,0,18,0,18,25,55,0,18,0,55,0,55,25,0,7,8,9,10,11,12,13,14,15,16,55,5,27,5,0,25,18,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,25,0,18,25,0,25,0,25,0,25,0,55,0,55,0,7,8,9,10,11,12,13,14,15,16,25,55,25,0,25,18,0,55,0,55,0,55,0,55,0,55,0,55,0,25,55,18,25,0,25,18,0,18,25,0,55,0,55,25,0,7,8,9,10,11,12,13,14,15,16,5,0,55,0,25,18,0,55,0,55,0,55,0,55,0,55,0,55,0,25,55,18,25,18,25,0,18,0,18,25,0,25,18,0,55,0,55,25,0,7,8,9,10,11,12,13,14,15,16,5,55,27,0,25,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,18,25,18,0,18,0,18,25,0,55,0,18,0,7,8,9,10,11,12,13,14,15,16,27,5,0,25,18,0,55,0,55,0,55,0,55,0,55,25,18,0,25,0,25,0,25,0,55,0,55,25,0,7,8,9,10,11,12,13,14,15,16,0,27,5,0,25,18,0,55,0,55,0,55,0,55,0,55,0,25,55,18,25,18,0,25,18,0,18,25,0,18,0,55,0,55,25,0,7,8,9,10,11,12,13,14,15,16,0,55,0,25,18,0,55,0,55,0,55,0,55,18,25,0,18,0,18,25,55,0,18,0,55,25,0,7,8,9,10,11,12,13,14,15,16,27,0,5,55,0,18,0,55,0,55,0,55,0,55,0,55,0,25,0,18,25,0,25,0,18,0,7,8,9,10,11,12,13,14,15,16,0,18,5,0,55,25,55,138,25,0,5,55,102,25,5,7,8,9,10,11,12,13,14,15,16,5,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,25,55,138,25,0,25,55,0,55,0,102,0,25,0,7,8,9,10,11,12,13,14,15,16,0,55,0,55,5,25,5,7,8,9,10,11,12,13,14,15,16,27,5,25,5,25,5,25,5,18,55,0,55,0,25,18,25,5,25,55,25,0,25,0,5,25,5,0,5,0,55,18,25,18,25,18,25,18,25,55,7,8,9,10,11,12,13,14,15,16,5,55,18,25,55,25,55,18,55,18,55,25,55,25,18,25,18,25,55,18,7,8,9,10,11,12,13,14,15,16,18,25,5,139,0,139,0,139,0,55,5,102,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,25,5,140,141,142,143,144,145,146,147,148,27,0,55,5,0,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,0,235,236,237,238,239,240,0,5,55,5,55,2,55,5,0,55,5,241,55,0,55,0,55,25,0,55,25,5,0,55,25,0,55,0,55,0,25,0,55,25,18,25,18,25,18,25,5,102,5,55,25,0,7,8,9,10,11,12,13,14,15,16,0,27,0,5,25,21,0,7,8,9,10,11,12,13,14,15,16,0,55,102,55,0,55,25,55,0,55,0,55,0,25,18,25,18,0,18,25,18,25,0,5,0,5,7,8,9,10,11,12,13,14,15,16,55,0,55,0,55,0,55,0,7,8,9,10,11,12,13,14,15,16,140,0,5,55,25,18,25,0,5,55,18,25,18,25,0,25,18,25,18,25,18,25,0,25,7,8,9,10,11,12,13,14,15,16,0,7,8,9,10,11,12,13,14,15,16,0,5,102,5,0,25,6,0,25,18,55,25,18,25,18,25,18,25,18,55,0,7,8,9,10,11,12,13,14,15,16,5,25,5,0,25,18,55,18,25,18,25,18,25,55,7,8,9,10,11,12,13,14,15,16,55,25,18,25,18,25,18,25,18,0,5,55,18,25,18,25,0,5,7,8,9,10,11,12,13,14,15,16,0,55,7,8,9,10,11,12,13,14,15,16,55,102,5,0,5,0,25,5,25,18,25,55,25,55,18,25,55,0,25,0,20,101,20,101,242,20,243,20,101,25,0,25,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,244,245,246,247,248,249,20,250,20,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,251,252,251,0,252,0,251,252,251,252,251,0,252,0,253,251,254,251,255,251,256,251,0,252,0,252,0,252,0,252,251,252,257,258,259,260,261,262,0,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,251,311,312,313,0,314,315,252,316,317,6,318,6,319,320,321,0,322,323,324,325,6,251,326,327,0,328,329,252,330,0,6,251,331,332,333,126,334,335,252,336,130,6,0,337,338,339,0,340,341,342,343,344,6,0,2,21,5,6,5,6,5,6,3,21,2,5,18,5,18,5,2,21,0,21,345,101,0,346,347,348,349,350,351,5,101,345,26,22,23,346,347,348,349,350,351,5,0,101,0,5,0,25,6,25,6,25,0,5,120,5,120,5,20,120,20,120,20,5,120,5,352,120,5,120,5,353,5,120,5,354,355,120,352,20,120,356,120,20,55,20,5,20,120,5,120,20,5,357,5,27,358,359,241,30,31,241,27,5,0,5,0,5,0,5,0,26,22,23,346,347,348,349,350,351,27,26,22,23,346,347,348,349,350,351,27,26,22,23,346,347,348,349,350,351,27,5,360,361,345,27,26,22,23,346,347,348,349,350,351,27,345,5,26,22,23,346,347,348,349,350,351,27,26,22,23,346,347,348,349,350,351,27,26,22,23,346,347,348,349,350,351,27,5,0,5,0,5,0,5,0,5,0,5,0,135,0,136,0,30,31,362,363,364,365,366,30,31,30,31,30,31,367,368,369,370,20,30,31,20,30,31,20,101,371,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,20,5,30,31,30,31,25,30,31,0,5,27,5,372,0,372,0,372,0,55,0,102,5,0,25,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,25,5,373,5,0,5,0,5,0,5,0,5,0,2,5,102,55,241,5,241,25,18,5,102,5,241,102,55,5,0,55,0,25,6,102,55,5,55,5,102,55,0,55,0,55,0,5,27,5,55,0,5,0,55,5,0,27,5,27,5,27,5,27,5,27,5,0,55,374,55,374,55,374,55,374,55,0,5,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,0,55,102,55,0,5,0,55,102,5,55,102,5,55,7,8,9,10,11,12,13,14,15,16,55,0,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,55,25,6,5,25,5,102,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,101,25,55,241,25,5,0,6,102,6,30,31,30,31,30,31,30,31,30,31,30,31,30,31,20,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,101,20,30,31,30,31,375,30,31,30,31,30,31,30,31,30,31,102,6,30,31,376,20,55,30,31,30,31,20,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,30,31,377,378,379,380,0,381,382,383,384,30,31,30,31,0,55,101,20,55,25,55,25,55,25,55,18,25,18,5,0,27,5,0,55,5,0,18,55,18,25,0,5,7,8,9,10,11,12,13,14,15,16,0,25,55,5,55,5,55,0,7,8,9,10,11,12,13,14,15,16,55,25,5,55,25,18,0,5,55,0,25,18,55,25,18,25,18,25,18,5,0,102,7,8,9,10,11,12,13,14,15,16,0,5,55,25,102,55,7,8,9,10,11,12,13,14,15,16,55,0,55,25,18,25,18,25,0,55,25,55,25,18,0,7,8,9,10,11,12,13,14,15,16,0,5,55,102,55,5,55,18,25,18,55,25,55,25,55,25,55,25,55,25,55,0,55,102,5,55,18,25,18,5,55,102,18,25,0,55,0,55,0,55,0,55,0,55,0,20,385,20,6,101,20,0,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,55,18,25,18,25,18,5,18,25,0,7,8,9,10,11,12,13,14,15,16,0,55,0,55,0,55,0,1,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,0,55,0,466,467,468,469,470,471,472,0,473,474,475,476,477,0,55,25,55,5,55,0,55,0,55,0,55,0,55,0,55,6,0,55,478,55,5,0,55,0,55,0,55,478,5,0,25,5,6,5,0,25,5,18,5,18,5,6,0,5,6,5,0,5,0,478,55,478,55,478,0,478,55,478,55,478,55,478,55,478,55,0,21,0,5,6,5,6,5,7,8,9,10,11,12,13,14,15,16,6,5,17,5,6,18,6,19,5,55,102,55,479,55,0,55,0,55,0,55,0,55,0,5,6,5,0,5,0,21,5,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,5,0,27,0,5,241,27,5,27,5,0,5,0,5,0,5,25,0,55,0,55,0,25,27,0,55,27,0,55,241,55,241,0,55,25,0,55,0,5,55,0,55,5,241,0,480,481,55,0,7,8,9,10,11,12,13,14,15,16,0,55,0,55,0,5,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,5,27,55,5,27,55,0,27,0,55,0,55,0,27,55,27,0,5,55,0,5,0,55,0,27,55,27,0,27,55,25,0,25,0,25,55,0,55,0,55,0,25,0,25,26,22,23,346,27,0,5,0,55,27,5,55,27,0,55,5,55,25,0,27,5,0,55,0,5,55,0,27,55,0,27,55,0,5,0,27,0,55,0,108,0,115,0,27,0,26,22,23,346,347,348,349,350,351,27,0,18,25,18,55,25,5,0,26,22,23,346,347,348,349,350,351,27,7,8,9,10,11,12,13,14,15,16,0,25,18,55,18,25,18,25,5,21,5,0,55,0,7,8,9,10,11,12,13,14,15,16,0,25,55,25,18,25,0,7,8,9,10,11,12,13,14,15,16,5,0,55,25,5,55,0,25,18,55,18,25,18,55,5,25,5,0,7,8,9,10,11,12,13,14,15,16,55,5,55,5,0,27,0,55,0,55,18,25,18,25,18,25,5,0,55,0,55,0,55,0,55,0,55,5,0,55,25,18,25,0,7,8,9,10,11,12,13,14,15,16,0,25,18,0,55,0,55,0,55,0,55,0,55,0,55,0,25,55,18,25,18,0,18,0,18,0,55,0,18,0,55,18,0,25,0,25,0,55,18,25,18,25,18,25,18,25,55,5,55,0,7,8,9,10,11,12,13,14,15,16,0,55,18,25,0,18,25,18,25,5,55,25,0,55,18,25,18,25,18,25,5,55,0,7,8,9,10,11,12,13,14,15,16,0,55,25,18,25,18,25,18,25,0,7,8,9,10,11,12,13,14,15,16,0,55,0,25,18,25,18,25,0,7,8,9,10,11,12,13,14,15,16,27,5,0,17,19,7,8,9,10,11,12,13,14,15,16,27,0,55,0,55,0,55,0,241,0,5,0,55,0,55,0,55,0,55,0,55,0,7,8,9,10,11,12,13,14,15,16,0,5,0,55,0,25,5,0,55,25,5,102,5,0,7,8,9,10,11,12,13,14,15,16,0,27,0,55,0,55,0,55,0,55,18,0,25,102,0,55,0,55,0,55,0,55,0,55,0,5,25,5,21,0,5,0,5,0,5,18,25,5,18,21,25,5,25,5,25,5,0,5,25,5,0,5,0,27,0,120,20,120,20,0,20,120,20,120,0,120,0,120,0,120,0,120,0,120,20,0,20,0,20,0,20,120,20,120,0,120,0,120,0,120,0,20,120,0,120,0,120,0,120,0,120,0,20,120,20,120,20,120,20,120,20,120,20,120,20,0,120,5,20,5,20,120,5,20,5,20,120,5,20,5,20,120,5,20,5,20,120,5,20,5,20,120,20,0,7,8,9,10,11,12,13,14,15,16,7,8,9,10,11,12,13,14,15,16,7,8,9,10,11,12,13,14,15,16,7,8,9,10,11,12,13,14,15,16,7,8,9,10,11,12,13,14,15,16,25,5,25,5,25,5,25,5,0,25,0,25,0,55,0,27,25,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,55,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,345,26,22,23,346,347,348,349,350,351,27,0,5,0,482,5,482,5,0,482,5,0,5,0,5,0,5,0,5,0,5,6,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,374,55,0,55,0,55,0,55,0,55,0,21,0,21,25,0,1,0],O=1,P=2,Q=4,R=8,T=64,U=128,V=256,W=512,X=1024,Y=2048,Z=4096,$=8192,rn=16384; unicode=unicode||{},unicode.title=function(r){for(var n="",t=!1,e=0;r.length>e;e++){var c=r.charAt(e);n+=t?x(c,r,e):S(c),t=z(c)}return n},unicode.capitalize=function(r){var n="";n+=w(r.charAt(0));for(var t=1;r.length>t;t++)n+=x(r.charAt(t),r,t);return n},unicode.casefold=function(r){for(var n="",t=0;r.length>t;t++)n+=b(r.charAt(t));return n},unicode.islower=function(r){if(""==r)return!1;for(var n=!1,t=0;r.length>t;t++){var e=r.charAt(t);if(p(e)||o(e))return!1;n||(n=g(e))}return n},unicode.isupper=function(r){if(""==r)return!1;for(var n=!1,t=0;r.length>t;t++){var e=r.charAt(t);if(g(e)||o(e))return!1;n||(n=p(e))}return n},unicode.istitle=function(r){if(""==r)return!1;for(var n=!1,t=!1,e=0;r.length>e;e++){var c=r.charAt(e);if(p(c)||o(c)){if(t)return!1;t=!0,n=!0}else if(g(c)){if(!t)return!1;t=!0,n=!0}else t=!1}return n},unicode.isspace=function(r){if(""==r)return!1;for(var n=0;r.length>n;n++){var t=r.charAt(n);if(!u(t))return!1}return!0},unicode.isalpha=function(r){if(""==r)return!1;for(var n=0;r.length>n;n++){var t=r.charAt(n);if(!j(t))return!1}return!0},unicode.isalnum=function(r){if(""==r)return!1;for(var n=0;r.length>n;n++){var t=r.charAt(n);if(!k(t))return!1}return!0},unicode.isdecimal=function(r){if(""==r)return!1;for(var n=0;r.length>n;n++){var t=r.charAt(n);if(!s(t))return!1}return!0},unicode.isdigit=function(r){if(""==r)return!1;for(var n=0;r.length>n;n++){var t=r.charAt(n);if(!A(t))return!1}return!0},unicode.isnumeric=function(r){if(""==r)return!1;for(var n=0;r.length>n;n++){var t=r.charAt(n);if(!l(t))return!1}return!0},unicode.isidentifier=function(r){if(""==r)return!1;if("_"!=r.charAt(0)&&!f(r.charAt(0)))return!1;for(var n=1;r.length>n;n++)if(!h(r.charAt(n)))return!1;return!0},unicode.isprintable=function(r){for(var n=0;r.length>n;n++)if(!C(r.charAt(n)))return!1;return!0},unicode.lower=function(r){for(var n="",t=0;r.length>t;t++){var e=r.charAt(t);n+=x(e,r,t)}return n},unicode.swapcase=function(r){for(var n="",t=0;r.length>t;t++){var e=r.charAt(t);n+=p(e)?x(e,r,t):g(e)?w(e):e}return n},unicode.upper=function(r){for(var n="",t=0;r.length>t;t++){var e=r.charAt(t);n+=w(e)}return n}}({},function(){return this}()); var __BRYTHON__=__BRYTHON__ ||{} ;(function($B){ var scripts=document.getElementsByTagName('script') var this_url=scripts[scripts.length-1].src var elts=this_url.split('/') elts.pop() var $path=$B.brython_path=elts.join('/')+'/' var $href=$B.script_path=window.location.href var $href_elts=$href.split('/') $href_elts.pop() var $script_dir=$B.script_dir=$href_elts.join('/') $B.$py_module_path={} $B.$py_src={} $B.path=[$path+'Lib',$path+'libs',$script_dir,$path+'Lib/site-packages'] $B.bound={} $B.async_enabled=false if($B.async_enabled)$B.block={} $B.modules={} $B.imported={} $B.vars={} $B._globals={} $B.frames_stack=[] $B.builtins={__repr__:function(){return "'"},__str__:function(){return ""},} $B.builtins_block={id:'__builtins__',module:'__builtins__'} $B.modules['__builtins__']=$B.builtins_block $B.bound['__builtins__']={'__BRYTHON__':true,'$eval':true,'$open': true} $B.bound['__builtins__']['BaseException']=true $B.builtin_funcs={} $B.__getattr__=function(attr){return this[attr]} $B.__setattr__=function(attr,value){ if(['debug','stdout','stderr'].indexOf(attr)>-1){$B[attr]=value} else{throw $B.builtins.AttributeError('__BRYTHON__ object has no attribute '+attr)}} $B.language=window.navigator.userLanguage ||window.navigator.language $B.charset=document.characterSet ||document.inputEncoding ||"utf-8" $B.max_int=Math.pow(2,53)-1 $B.min_int=-$B.max_int $B.$py_next_hash=Math.pow(2,53)-1 $B.$py_UUID=0 $B.lambda_magic=Math.random().toString(36).substr(2,8) $B.callbacks={} var has_storage=typeof(Storage)!=="undefined" if(has_storage){$B.has_local_storage=false try{ if(localStorage){$B.local_storage=localStorage $B.has_local_storage=true}}catch(err){} $B.has_session_storage=false try{ if(sessionStorage){$B.session_storage=sessionStorage $B.has_session_storage=true}}catch(err){}}else{ $B.has_local_storage=false $B.has_session_storage=false} $B.globals=function(){ return $B.frames_stack[$B.frames_stack.length-1][3]} $B.regexIdentifier=/^(?:[\$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D])(?:[\$0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF])*$/})(__BRYTHON__) __BRYTHON__.implementation=[3,3,2,'dev',0] __BRYTHON__.__MAGIC__="3.3.2" __BRYTHON__.version_info=[3,3,0,'alpha',0] __BRYTHON__.compiled_date="2017-05-15 15:18:49.317950" __BRYTHON__.builtin_module_names=["posix","sys","errno","time","_ajax","_base64","_jsre","_multiprocessing","_posixsubprocess","_profile","_svg","_sys","builtins","dis","hashlib","json","long_int","math","modulefinder","random","_abcoll","_codecs","_collections","_csv","_functools","_imp","_io","_random","_socket","_sre","_string","_struct","_sysconfigdata","_testcapi","_thread","_warnings","_weakref"] ;(function($B){var js,$pos,res,$op var _b_=$B.builtins var keys=$B.keys=function(obj){var res=[],pos=0 for(var attr in obj){res[pos++]=attr} res.sort() return res} var clone=$B.clone=function(obj){var res={} for(var attr in obj){res[attr]=obj[attr]} return res} $B.last=function(table){return table[table.length-1]} $B.list2obj=function(list,value){var res={},i=list.length if(value===undefined){value=true} while(i-->0){res[list[i]]=value} return res} var $operators={"//=":"ifloordiv",">>=":"irshift","<<=":"ilshift","**=":"ipow","**":"pow","//":"floordiv","<<":"lshift",">>":"rshift","+=":"iadd","-=":"isub","*=":"imul","/=":"itruediv","%=":"imod","&=":"iand","|=":"ior","^=":"ixor","+":"add","-":"sub","*":"mul","/":"truediv","%":"mod","&":"and","|":"or","~":"invert","^":"xor","<":"lt",">":"gt","<=":"le",">=":"ge","==":"eq","!=":"ne","or":"or","and":"and","in":"in","not": "not","is":"is","not_in":"not_in","is_not":"is_not" } var $augmented_assigns=$B.augmented_assigns={"//=":"ifloordiv",">>=":"irshift","<<=":"ilshift","**=":"ipow","+=":"iadd","-=":"isub","*=":"imul","/=":"itruediv","%=":"imod","&=":"iand","|=":"ior","^=":"ixor"} var noassign=$B.list2obj(['True','False','None','__debug__']) var $op_order=[['or'],['and'],['not'],['in','not_in'],['<','<=','>','>=','!=','==','is','is_not'],['|'],['^'],['&'],['>>','<<'],['+'],['-'],['*','/','//','%'],['unary_neg','unary_inv','unary_pos'],['**'] ] var $op_weight={} var $weight=1 for(var $i=0;$i<$op_order.length;$i++){var _tmp=$op_order[$i] for(var $j=0;$j<_tmp.length;$j++){$op_weight[_tmp[$j]]=$weight} $weight++} var $loop_num=0 var chained_comp_num=0 function $_SyntaxError(C,msg,indent){ var ctx_node=C while(ctx_node.type!=='node'){ctx_node=ctx_node.parent} var tree_node=ctx_node.node,root=tree_node while(root.parent!==undefined){root=root.parent} var module=tree_node.module var line_num=tree_node.line_num if(root.line_info){line_num=root.line_info} if(indent!==undefined){line_num++} if(indent===undefined){if(Array.isArray(msg)){$B.$SyntaxError(module,msg[0],$pos)} if(msg==="Triple string end not found"){ $B.$SyntaxError(module,'invalid syntax : triple string end not found',$pos,line_num,root)} $B.$SyntaxError(module,'invalid syntax',$pos,line_num,root)}else{throw $B.$IndentationError(module,msg,$pos)}} function $Node(type){this.type=type this.children=[] this.yield_atoms=[] this.add=function(child){ this.children[this.children.length]=child child.parent=this child.module=this.module} this.insert=function(pos,child){ this.children.splice(pos,0,child) child.parent=this child.module=this.module} this.toString=function(){return ""} this.show=function(indent){ var res='' if(this.type==='module'){for(var i=0;i0)res +='{' res +='\n' for(var i=0;i0){res +=' '.repeat(indent) res+='}\n'} return res} this.to_js=function(indent){ if(this.js!==undefined)return this.js this.res=[] var pos=0 this.unbound=[] if(this.type==='module'){for(var i=0;i0)this.res[pos++]='{' this.res[pos++]='\n' for(var i=0;i0){this.res[pos++]=' '.repeat(indent) this.res[pos++]='}\n'}} this.js=this.res.join('') return this.js} this.transform=function(rank){ if(this.yield_atoms.length>0){ this.parent.children.splice(rank,1) var offset=0 for(var i=0;i0){assigned.push(left) var ctx=node.C ctx.tree=[] var nleft=new $RawJSCtx(ctx,'var $temp'+$loop_num) nleft.tree=ctx.tree nassign=new $AssignCtx(nleft) nassign.tree[1]=right for(var i=0;i1){left_items=left.tree}else if(left.tree[0].type==='list_or_tuple'||left.tree[0].type==='target_list'){left_items=left.tree[0].tree}else if(left.tree[0].type=='id'){ var name=left.tree[0].value if($B._globals && $B._globals[scope.id] && $B._globals[scope.id][name]){}else{left.tree[0].bound=true}} break case 'target_list': case 'list_or_tuple': left_items=left.tree} if(left_items===null){return} var right=this.tree[1] var right_items=null if(right.type==='list'||right.type==='tuple'|| (right.type==='expr' && right.tree.length>1)){right_items=right.tree} if(right_items!==null){ if(right_items.length>left_items.length){throw Error('ValueError : too many values to unpack (expected '+left_items.length+')')}else if(right_items.length=0;i--){node.parent.insert(rank,new_nodes[i])} $loop_num++}else{ var new_node=new $Node() new_node.line_num=node.line_num var rname='$right'+$loop_num var js='var '+rname+' = getattr' js +='(iter('+right.to_js()+'),"__next__");' new $NodeJSCtx(new_node,js) var new_nodes=[new_node],pos=1 var rlist_node=new $Node() var rlname='$rlist'+$loop_num js='var '+rlname+'=[], $pos=0;'+'while(1){try{'+rlname+ '[$pos++] = '+rname+'()}catch(err){break}};' new $NodeJSCtx(rlist_node,js) new_nodes[pos++]=rlist_node var packed=null for(var i=0;i1 ?'+ ' "s" : "")+" to unpack")}' new $NodeJSCtx(check_node,js) new_nodes[pos++]=check_node if(packed==null){var check_node=new $Node() var min_length=left_items.length js='if('+rlname+'.length>'+min_length+')'+ '{throw ValueError("too many values to unpack '+ '(expected '+left_items.length+')")}' new $NodeJSCtx(check_node,js) new_nodes[pos++]=check_node} for(var i=0;i=0;i--){node.parent.insert(rank,new_nodes[i])} $loop_num++}} this.to_js=function(){this.js_processed=true if(this.parent.type==='call'){ return '{$nat:"kw",name:'+this.tree[0].to_js()+',value:'+this.tree[1].to_js()+'}'} var left=this.tree[0] if(left.type==='expr')left=left.tree[0] var right=this.tree[1] if(left.type=='attribute' ||left.type=='sub'){ var right_js=right.to_js() var res='',rvar='',$var='$temp'+$loop_num if(right.type=='expr' && right.tree[0]!==undefined && right.tree[0].type=='call' && ('eval'==right.tree[0].func.value || 'exec'==right.tree[0].func.value)){res +='var '+$var+'='+right_js+';\n' rvar=$var}else if(right.type=='expr' && right.tree[0]!==undefined && right.tree[0].type=='sub'){res +='var '+$var+'='+right_js+';\n' rvar=$var}else{rvar=right_js} if(left.type==='attribute'){ $loop_num++ left.func='setattr' res +=left.to_js() left.func='getattr' res=res.substr(0,res.length-1) return res + ','+rvar+');None;'} if(left.type==='sub'){ var seq=left.value.to_js(),temp='$temp'+$loop_num,type if(left.value.type=='id'){type=$get_node(this).locals[left.value.value]} $loop_num++ var res='var '+temp+'='+seq+'\n' if(type!=='list'){res +='if(Array.isArray('+temp+') && !'+temp+'.__class__){'} if(left.tree.length==1){res +='$B.set_list_key('+temp+','+ (left.tree[0].to_js()+''||'null')+','+ right.to_js()+')'}else if(left.tree.length==2){res +='$B.set_list_slice('+temp+','+ (left.tree[0].to_js()+''||'null')+','+ (left.tree[1].to_js()+''||'null')+','+ right.to_js()+')'}else if(left.tree.length==3){res +='$B.set_list_slice_step('+temp+','+ (left.tree[0].to_js()+''||'null')+','+ (left.tree[1].to_js()+''||'null')+','+ (left.tree[2].to_js()+''||'null')+','+ right.to_js()+')'} if(type=='list'){return res} res +='\n}else{' if(left.tree.length==1){res +='$B.$setitem('+left.value.to_js() res +=','+left.tree[0].to_js()+','+right_js+')};None;'}else{left.func='setitem' res +=left.to_js() res=res.substr(0,res.length-1) left.func='getitem' res +=','+right_js+')};None;'} return res}} return left.to_js()+'='+right.to_js()}} function $AttrCtx(C){ this.type='attribute' this.value=C.tree[0] this.parent=C C.tree.pop() C.tree[C.tree.length]=this this.tree=[] this.func='getattr' this.toString=function(){return '(attr) '+this.value+'.'+this.name} this.to_js=function(){this.js_processed=true return this.func+'('+this.value.to_js()+',"'+this.name+'")'}} function $AugmentedAssignCtx(C,op){ this.type='augm_assign' this.parent=C.parent C.parent.tree.pop() C.parent.tree[C.parent.tree.length]=this this.op=op this.tree=[C] var scope=this.scope=$get_scope(this) if(C.type=='expr' && C.tree[0].type=='id'){var name=C.tree[0].value if(noassign[name]===true){$_SyntaxError(C,["can't assign to keyword"])}else if((scope.ntype=='def'||scope.ntype=='generator')&& $B.bound[scope.id][name]===undefined){if(scope.globals===undefined ||scope.globals.indexOf(name)==-1){ C.tree[0].unbound=true}}} $get_node(this).bound_before=$B.keys($B.bound[scope.id]) this.module=scope.module this.toString=function(){return '(augm assign) '+this.tree} this.transform=function(node,rank){var func='__'+$operators[op]+'__' var offset=0,parent=node.parent var line_num=node.line_num,lnum_set=false parent.children.splice(rank,1) var left_is_id=(this.tree[0].type=='expr' && this.tree[0].tree[0].type=='id') if(left_is_id){ this.tree[0].tree[0].augm_assign=true if($B.debug>0){var check_node=$NodeJS('if('+this.tree[0].to_js()+ '===undefined){throw NameError("name \''+ this.tree[0].tree[0].value+'\' is not defined")}') node.parent.insert(rank,check_node) offset++} var left_id=this.tree[0].tree[0].value,was_bound=$B.bound[this.scope.id][left_id]!==undefined,left_id_unbound=this.tree[0].tree[0].unbound} var right_is_int=(this.tree[1].type=='expr' && this.tree[1].tree[0].type=='int') var right=right_is_int ? this.tree[1].tree[0].to_js(): '$temp' if(!right_is_int){ var new_node=new $Node() new_node.line_num=line_num lnum_set=true new $NodeJSCtx(new_node,'var $temp,$left;') parent.insert(rank,new_node) offset++ var new_node=new $Node() new_node.id=this.scope.id var new_ctx=new $NodeCtx(new_node) var new_expr=new $ExprCtx(new_ctx,'js',false) var _id=new $RawJSCtx(new_expr,'$temp') var assign=new $AssignCtx(new_expr) assign.tree[1]=this.tree[1] _id.parent=assign parent.insert(rank+offset,new_node) offset++} var prefix='',in_class=false switch(op){case '+=': case '-=': case '*=': case '/=': if(left_is_id){var scope=this.scope,global_ns='$local_'+scope.module.replace(/\./g,'_') switch(scope.ntype){case 'module': prefix=global_ns break case 'def': case 'generator': if(scope.globals && scope.globals.indexOf(C.tree[0].value)>-1){prefix=global_ns}else{prefix='$locals'} break; case 'class': var new_node=new $Node() if(!lnum_set){new_node.line_num=line_num;lnum_set=true} new $NodeJSCtx(new_node,'var $left='+C.to_js()) parent.insert(rank+offset,new_node) in_class=true offset++}}} var left=C.tree[0].to_js() prefix=prefix && !C.tree[0].unknown_binding && !left_id_unbound var op1=op.charAt(0) if(prefix){var left1=in_class ? '$left' : left var new_node=new $Node() if(!lnum_set){new_node.line_num=line_num;lnum_set=true} js=right_is_int ? 'if(' : 'if(typeof $temp.valueOf()=="number" && ' js +=left1+'.constructor===Number' js +='&& '+left+op1+right+'>$B.min_int && '+left+op1+right+ '< $B.max_int){' js +=right_is_int ? '(' : '(typeof $temp=="number" && ' js +='typeof '+left1+'=="number") ? ' js +=left+op+right js +=' : ('+left1+'.constructor===Number ? ' js +=left+'=float('+left+op1 js +=right_is_int ? right : right+'.valueOf()' js +=') : '+left + op js +=right_is_int ? right : right+'.valueOf()' js +=')}' new $NodeJSCtx(new_node,js) parent.insert(rank+offset,new_node) offset++} var aaops={'+=':'add','-=':'sub','*=':'mul'} if(C.tree[0].type=='sub' && ('+='==op ||'-='==op ||'*='==op)&& C.tree[0].tree.length==1){var js1='$B.augm_item_'+aaops[op]+'(' js1 +=C.tree[0].value.to_js() js1 +=','+C.tree[0].tree[0].to_js()+',' js1 +=right+');None;' var new_node=new $Node() if(!lnum_set){new_node.line_num=line_num;lnum_set=true} new $NodeJSCtx(new_node,js1) parent.insert(rank+offset,new_node) offset++ return} var new_node=new $Node() if(!lnum_set){new_node.line_num=line_num;lnum_set=true} var js='' if(prefix){js +='else '} js +='if(!hasattr('+C.to_js()+',"'+func+'"))' new $NodeJSCtx(new_node,js) parent.insert(rank+offset,new_node) offset ++ var aa1=new $Node() aa1.id=this.scope.id var ctx1=new $NodeCtx(aa1) var expr1=new $ExprCtx(ctx1,'clone',false) if(left_id_unbound){new $RawJSCtx(expr1,'$locals["'+left_id+'"]')}else{expr1.tree=C.tree for(var i=0;i0){if(this.tree[this.tree.length-1].tree.length==0){ this.tree.pop()}} var func_js=this.func.to_js() if(this.func!==undefined){switch(this.func.value){case 'classmethod': return 'classmethod('+$to_js(this.tree)+')' case '$$super': if(this.tree.length==0){ var scope=$get_scope(this) if(scope.ntype=='def' ||scope.ntype=='generator'){var def_scope=$get_scope(scope.C.tree[0]) if(def_scope.ntype=='class'){new $IdCtx(this,def_scope.C.tree[0].name)}}} if(this.tree.length==1){ var scope=$get_scope(this) if(scope.ntype=='def' ||scope.ntype=='generator'){var args=scope.C.tree[0].args if(args.length>0){new $IdCtx(this,args[0])}}} break default: if(this.func.type=='unary'){ switch(this.func.op){case '+': return 'getattr('+$to_js(this.tree)+',"__pos__")()' case '-': return 'getattr('+$to_js(this.tree)+',"__neg__")()' case '~': return 'getattr('+$to_js(this.tree)+',"__invert__")()'}}} var _block=false if($B.async_enabled){var scope=$get_scope(this.func) if($B.block[scope.id]===undefined){} else if($B.block[scope.id][this.func.value])_block=true} var positional=[],kw_args=[],star_args=false,dstar_args=[] for(var i=0;i-1){if(this.func.type=='id'){if(this.func.is_builtin){ if($B.builtin_funcs[this.func.value]!==undefined){return func_js+args_str}}else{var bound_obj=this.func.found if(bound_obj &&(bound_obj.type=='class' || bound_obj.type=='def')){return func_js+args_str}} var res='getattr('+func_js+',"__call__")'+args_str}else{var res='getattr('+func_js+',"__call__")'+args_str} return res} return 'getattr('+func_js+',"__call__")'+args_str}}} function $ClassCtx(C){ this.type='class' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.expect='id' this.toString=function(){return '(class) '+this.name+' '+this.tree+' args '+this.args} var scope=this.scope=$get_scope(this) this.parent.node.parent_block=scope this.parent.node.bound={} this.set_name=function(name){this.random=$B.UUID() this.name=name this.id=C.node.module+'_'+name+'_'+this.random $B.bound[this.id]={} if($B.async_enabled)$B.block[this.id]={} $B.modules[this.id]=this.parent.node this.parent.node.id=this.id var parent_block=scope while(parent_block.C && parent_block.C.tree[0].type=='class'){parent_block=parent_block.parent} while(parent_block.C && 'def' !=parent_block.C.tree[0].type && 'generator' !=parent_block.C.tree[0].type){parent_block=parent_block.parent} this.parent.node.parent_block=parent_block this.level=this.scope.level $B.bound[this.scope.id][name]=this if(scope.is_function){if(scope.C.tree[0].locals.indexOf(name)==-1){scope.C.tree[0].locals.push(name)}}} this.transform=function(node,rank){ this.doc_string=$get_docstring(node) var instance_decl=new $Node() var local_ns='$locals_'+this.id.replace(/\./g,'_') var js=';var '+local_ns+'={}' js +=', $locals = '+local_ns+';' new $NodeJSCtx(instance_decl,js) node.insert(0,instance_decl) var ret_obj=new $Node() new $NodeJSCtx(ret_obj,'return '+local_ns+';') node.insert(node.children.length,ret_obj) var run_func=new $Node() new $NodeJSCtx(run_func,')();') node.parent.insert(rank+1,run_func) var scope=$get_scope(this) var name_ref=';$locals_'+scope.id.replace(/\./g,'_') name_ref +='["'+this.name+'"]' var js=[name_ref +'=$B.$class_constructor("'+this.name],pos=1 js[pos++]='",$'+this.name+'_'+this.random if(this.args!==undefined){ var arg_tree=this.args.tree,args=[],kw=[] for(var i=0;i0){res.push('{'+this.tree[1].to_js()+'}')}} return res.join('')}} function $ContinueCtx(C){ this.type='continue' this.parent=C $get_node(this).is_continue=true C.tree[C.tree.length]=this set_loop_C.apply(this,[C,'continue']) this.toString=function(){return '(continue)'} this.to_js=function(){this.js_processed=true return 'continue'}} function $DebuggerCtx(C){ this.type='continue' this.parent=C C.tree[C.tree.length]=this this.toString=function(){return '(debugger)'} this.to_js=function(){this.js_processed=true return 'debugger'}} function $DecoratorCtx(C){ this.type='decorator' this.parent=C C.tree[C.tree.length]=this this.tree=[] this.toString=function(){return '(decorator) '+this.tree} this.transform=function(node,rank){var func_rank=rank+1,children=node.parent.children var decorators=[this.tree] while(1){if(func_rank>=children.length){$_SyntaxError(C,['decorator expects function'])} else if(children[func_rank].C.type=='node_js'){func_rank++} else if(children[func_rank].C.tree[0].type==='decorator'){decorators.push(children[func_rank].C.tree[0].tree) children.splice(func_rank,1)}else{break}} this.dec_ids=[] var pos=0 for(var i=0;i0){defaults[dpos++]='"'+arg.name+'"' defs1[dpos1++]=arg.name+':'+$to_js(arg.tree) this.__defaults__.push($to_js(arg.tree))}}else if(arg.type=='func_star_arg'){if(arg.op=='*'){this.star_arg=arg.name} else if(arg.op=='**'){this.kw_arg=arg.name}} if(arg.annotation){annotations.push(arg.name+': '+arg.annotation.to_js())}} var flags=67 if(this.star_arg){flags |=4} if(this.kw_arg){flags |=8} if(this.type=='generator'){flags |=32} var positional_str=[],positional_obj=[],pos=0 for(var i=0,_len=this.positional_list.length;i<_len;i++){positional_str[pos]='"'+this.positional_list[i]+'"' positional_obj[pos++]=this.positional_list[i]+':null'} positional_str=positional_str.join(',') positional_obj='{'+positional_obj.join(',')+'}' var dobj=[],pos=0 for(var i=0;i 1){if(this.scope.ntype=='class'){fname=this.scope.C.tree[0].name+'.'+this.name} else fname=this.name if(pnode && pnode.id){fmod=pnode.id.slice(0,pnode.id.indexOf('_'))} else fmod=''; js=";var _parent_line_info={}; if($B.frames_stack[$B.frames_stack.length-1]){"+ " _parent_line_info=$B.frames_stack[$B.frames_stack.length-1][1].$line_info;"+ "} else _parent_line_info="+global_ns+".$line_info;"+ ";$B.$profile.call('"+fmod+"','"+fname+"',"+ node.line_num+",_parent_line_info)"+js;} enter_frame_node.enter_frame=true new $NodeJSCtx(enter_frame_node,js) nodes.push(enter_frame_node) this.env=[] var make_args_nodes=[] var js=this.type=='def' ? local_ns+' = $locals' : 'var $ns' js +=' = $B.args("'+this.name+'", '+ this.argcount+', {'+this.slots.join(', ')+'}, '+ '['+slot_list.join(', ')+'], arguments, ' if(defs1.length){js +='$defaults, '} else{js +='{}, '} js +=this.other_args+', '+this.other_kw+');' var new_node=new $Node() new $NodeJSCtx(new_node,js) make_args_nodes.push(new_node) if(this.type=='generator'){ js='for(var $var in $ns){$locals[$var]=$ns[$var]};' make_args_nodes.push($NodeJS(js))} var only_positional=false if(this.other_args===null && this.other_kw===null && this.after_star.length==0 && defaults.length==0){ only_positional=true if($B.debug>0 ||this.positional_list.length>0){ nodes.push($NodeJS('var $len = arguments.length;')) var new_node=new $Node() var js='if($len>0 && arguments[$len-1].$nat!==undefined)' new $NodeJSCtx(new_node,js) nodes.push(new_node) new_node.add(make_args_nodes[0]) if(make_args_nodes.length>1){new_node.add(make_args_nodes[1])} var else_node=new $Node() new $NodeJSCtx(else_node,'else') nodes.push(else_node)} var pos_len=this.positional_list.length if($B.debug>0){ js='if($len!='+pos_len+'){$B.wrong_nb_args("'+this.name+ '", $len, '+pos_len if(positional_str.length>0){js +=', ['+positional_str+']'} js +=')}' else_node.add($NodeJS(js))} if(this.positional_list.length>0){if(this.type=='generator'){for(var i=0;i0){js +=', ['+positional_str+']'} js +=')}' else_node.add($NodeJS(js)) else_node.add($NodeJS(local_ns+'=$locals={'+pargs.join(', ')+'}'))}}}else{nodes.push(make_args_nodes[0]) if(make_args_nodes.length>1){nodes.push(make_args_nodes[1])}} nodes.push($NodeJS('$B.frames_stack[$B.frames_stack.length-1][1] = $locals;')) nodes.push($NodeJS('$B.js_this = this;')) for(var i=nodes.length-1;i>=0;i--){node.children.splice(0,0,nodes[i])} var def_func_node=new $Node() this.params='' if(only_positional){this.params=Object.keys(this.varnames).join(', ') new $NodeJSCtx(def_func_node,'')}else{new $NodeJSCtx(def_func_node,'')} def_func_node.is_def_func=true def_func_node.module=this.module var last_instr=node.children[node.children.length-1].C.tree[0] if(last_instr.type!=='return' && this.type!='generator'){ node.add($NodeJS('$B.leave_frame($local_name);return None'))} node.add(def_func_node) var offset=1 var indent=node.indent node.parent.insert(rank+offset++,$NodeJS(name+'.$infos = {')) js=' __name__:"' if(this.scope.ntype=='class'){js+=this.scope.C.tree[0].name+'.'} js +=this.name+'",' node.parent.insert(rank+offset++,$NodeJS(js)) var def_names=[] for(var i=0;i0){lnum='($locals.$line_info="'+$get_node(this).line_num+','+ this.scope.id+'") && '} return 'else if('+lnum+'$B.is_exc('+this.error_name+',['+res.join(',')+']))'}} function $ExprCtx(C,name,with_commas){ this.type='expr' this.name=name this.with_commas=with_commas this.expect=',' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){return '(expr '+with_commas+') '+this.tree} this.to_js=function(arg){this.js_processed=true if(this.type==='list')return '['+$to_js(this.tree)+']' if(this.tree.length===1)return this.tree[0].to_js(arg) return 'tuple('+$to_js(this.tree)+')'}} function $ExprNot(C){ this.type='expr_not' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){return '(expr_not)'}} function $FloatCtx(C,value){ this.type='float' this.value=value this.toString=function(){return 'float '+this.value} this.parent=C this.tree=[] C.tree[C.tree.length]=this this.to_js=function(){this.js_processed=true if(/^\d+$/.exec(this.value)|| /^\d+\.\d*$/.exec(this.value)){return '(new Number('+this.value+'))'} return 'float('+this.value+')'}} function $ForExpr(C){ this.type='for' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.loop_num=$loop_num this.module=$get_scope(this).module $loop_num++ this.toString=function(){return '(for) '+this.tree} this.transform=function(node,rank){var scope=$get_scope(this),target=this.tree[0],target_is_1_tuple=target.tree.length==1 && target.expect=='id',iterable=this.tree[1],num=this.loop_num,local_ns='$locals_'+scope.id.replace(/\./g,'_'),h='\n'+' '.repeat(node.indent+4) var $range=false if(target.tree.length==1 && target.expct !='id' && iterable.type=='expr' && iterable.tree[0].type=='expr' && iterable.tree[0].tree[0].type=='call'){var call=iterable.tree[0].tree[0] if(call.func.type=='id'){var func_name=call.func.value if(func_name=='range' && call.tree.length<3){$range=call}}} var new_nodes=[],pos=0 var children=node.children var offset=1 if($range && scope.ntype!='generator'){if(this.has_break){ new_node=new $Node() new $NodeJSCtx(new_node,local_ns+'["$no_break'+num+'"]=true') new_nodes[pos++]=new_node} var range_is_builtin=false if(!scope.blurred){var _scope=$get_scope(this),found=[],fpos=0 while(1){if($B.bound[_scope.id]['range']){found[fpos++]=_scope.id} if(_scope.parent_block){_scope=_scope.parent_block} else{break}} range_is_builtin=found.length==1 && found[0]=="__builtins__" if(found==['__builtins__']){range_is_builtin=true}} var test_range_node=new $Node() if(range_is_builtin){new $NodeJSCtx(test_range_node,'if(1)')}else{new $NodeJSCtx(test_range_node,'if('+call.func.to_js()+'===$B.builtins.range)')} new_nodes[pos++]=test_range_node var idt=target.to_js() if($range.tree.length==1){var start=0,stop=$range.tree[0].to_js()}else{var start=$range.tree[0].to_js(),stop=$range.tree[1].to_js()} var js='var $stop_'+num +'=$B.int_or_bool('+ stop+');'+h+idt+'='+start+';'+h+ ' var $next'+num+'= '+idt+','+h+ ' $safe'+num+'= typeof $next'+num+'=="number" && typeof '+ '$stop_'+num+'=="number";'+h+'while(true)' var for_node=new $Node() new $NodeJSCtx(for_node,js) for_node.add($NodeJS('if($safe'+num+' && $next'+num+'>= $stop_'+ num+'){break}')) for_node.add($NodeJS('else if(!$safe'+num+ ' && $B.ge($next'+num+', $stop_'+num+ ')){break}')) for_node.add($NodeJS(idt+' = $next'+num)) for_node.add($NodeJS('if($safe'+num+'){$next'+num+'+=1'+'}')) for_node.add($NodeJS('else{$next'+num+'=$B.add($next'+num+',1)}')) for(var i=0;i=0;i--){node.parent.insert(rank+k,new_nodes[k].children[i])} node.parent.children[rank].line_num=node.line_num node.children=[] return 0} var else_node=new $Node() new $NodeJSCtx(else_node,'else') new_nodes[pos++]=else_node for(var i=new_nodes.length-1;i>=0;i--){node.parent.insert(rank+1,new_nodes[i])} this.test_range=true new_nodes=[],pos=0} var new_node=new $Node() new_node.line_num=$get_node(this).line_num var js='$locals["$next'+num+'"]' js +='=getattr(iter('+iterable.to_js()+'),"__next__");\n' new $NodeJSCtx(new_node,js) new_nodes[pos++]=new_node if(this.has_break){ new_node=new $Node() new $NodeJSCtx(new_node,local_ns+'["$no_break'+num+'"]=true;') new_nodes[pos++]=new_node} var while_node=new $Node() if(this.has_break){js='while('+local_ns+'["$no_break'+num+'"])'} else{js='while(1)'} new $NodeJSCtx(while_node,js) while_node.C.loop_num=num while_node.C.type='for' while_node.line_num=node.line_num if(scope.ntype=='generator'){ while_node.loop_start=num} new_nodes[pos++]=while_node node.parent.children.splice(rank,1) if(this.test_range){for(var i=new_nodes.length-1;i>=0;i--){else_node.insert(0,new_nodes[i])}}else{for(var i=new_nodes.length-1;i>=0;i--){node.parent.insert(rank,new_nodes[i]) offset +=new_nodes.length}} var try_node=new $Node() new $NodeJSCtx(try_node,'try') while_node.add(try_node) var iter_node=new $Node() iter_node.parent=$get_node(this).parent iter_node.id=this.module var C=new $NodeCtx(iter_node) var target_expr=new $ExprCtx(C,'left',true) if(target_is_1_tuple){ var t=new $ListOrTupleCtx(target_expr) t.real='tuple' t.tree=target.tree}else{target_expr.tree=target.tree} var assign=new $AssignCtx(target_expr) assign.tree[1]=new $JSCode('$locals["$next'+num+'"]()') try_node.add(iter_node) var catch_node=new $Node() var js='catch($err){if($B.is_exc($err,[StopIteration]))'+ '{$B.clear_exc();break;}' js +='else{throw($err)}}' new $NodeJSCtx(catch_node,js) while_node.add(catch_node) for(var i=0;i0){if(_mod.charAt(0)=='.'){if(package===undefined){if($B.imported[mod]!==undefined){package=$B.imported[mod].__package__}}else{package=$B.imported[package]} if(package===undefined){return 'throw SystemError("Parent module \'\' not loaded,'+ ' cannot perform relative import")'}else if(package=='None'){console.log('package is None !')}else{packages.push(package)} _mod=_mod.substr(1)}else{break}} if(_mod){packages.push(_mod)} this.module=packages.join('.') var mod_name=this.module.replace(/\$/g,'') if(this.blocking){res[pos++]='$B.$import("'; res[pos++]=mod_name+'",["'; res[pos++]=this.names.join('","')+'"], {'; var sep=''; for(var attr in this.aliases){res[pos++]=sep + '"'+attr+'": "'+this.aliases[attr]+'"'; sep=',';} res[pos++]='}, {}, true);'; if(this.names[0]=='*'){res[pos++]='\n'+head+'for(var $attr in $B.imported["'+mod_name+ '"]){if($attr.charAt(0)!=="_"){'+ '$locals[$attr]=$B.imported["'+mod_name+'"][$attr]}};'}else{for(var i=0;i-1){found.push(scope)} else if(scope.C && scope.C.tree[0].type=='def' && scope.C.tree[0].env.indexOf(val)>-1){found.push(scope)}}else{if($B.bound[scope.id][val]){ if(!this.bound && this_node.locals[val]===undefined){ if(!scope.is_comp && (!scope.parent_block || !scope.parent_block.is_comp)){ found.push(scope)}}else{found.push(scope)}}}}else{ if($B.bound[scope.id]===undefined){console.log('no bound',scope.id)} if($B.bound[scope.id][val]){found.push(scope)}} if(scope.parent_block){scope=scope.parent_block} else{break}} this.found=found if(this.nonlocal && found[0]===innermost){found.shift()} if(found.length>0){ if(!this.bound && found[0].C && found[0]===innermost && val.charAt(0)!='$'){var locs=$get_node(this).locals ||{},nonlocs=innermost.nonlocals if(locs[val]===undefined && ((innermost.type!='def' ||innermost.type!='generator')&& innermost.C.tree[0].args.indexOf(val)==-1)&& (nonlocs===undefined ||nonlocs[val]===undefined)){this.result='$B.$local_search("'+val+'")' return this.result}} if(found.length>1 && found[0].C){if(found[0].C.tree[0].type=='class' && !this.bound){var ns0='$locals_'+found[0].id.replace(/\./g,'_'),ns1='$locals_'+found[1].id.replace(/\./g,'_'),res if(bound_before){if(bound_before.indexOf(val)>-1){this.found=$B.bound[found[0].id][val] res=ns0}else{this.found=$B.bound[found[1].id][val] res=ns1} this.result=res+'["'+val+'"]' return this.result}else{this.found=false var res=ns0 + '["'+val+'"]!==undefined ? ' res +=ns0 + '["'+val+'"] : ' this.result=res + ns1 + '["'+val+'"]' return this.result}}} var scope=found[0] this.found=$B.bound[scope.id][val] var scope_ns='$locals_'+scope.id.replace(/\./g,'_') if(scope.C===undefined){ if(scope.id=='__builtins__'){if(gs.blurred){ val='('+global_ns+'["'+val+'"] || '+val+')'}else{ if(val!=='__builtins__'){val='$B.builtins.'+val} this.is_builtin=true}}else if(scope.id==scope.module){ if(this.bound ||this.augm_assign){ val=scope_ns+'["'+val+'"]'}else{if(scope===innermost && this.env[val]===undefined){var locs=this_node.locals ||{} if(locs[val]===undefined){ if(found.length>1 && found[1].id=='__builtins__'){this.is_builtin=true this.result='$B.builtins.'+val+$to_js(this.tree,'') return this.result}} this.result='$B.$search("'+val+'")' return this.result}else{if(scope.level<=2){ val=scope_ns+'["'+val+'"]'}else{ val='$B.$check_def("'+val+'",'+scope_ns+'["'+val+'"])'}}}}else{val=scope_ns+'["'+val+'"]'}}else if(scope===innermost){if($B._globals[scope.id]&& $B._globals[scope.id][val]){val=global_ns+'["'+val+'"]'}else if(!this.bound && !this.augm_assign){ var bind_level if(this_node.locals && this_node.locals[val]){bind_level=this_node.locals[val].level} if(bind_level!==undefined && bind_level<=this.level){val='$locals["'+val+'"]'}else{val='$B.$check_def_local("'+val+'",$locals["'+val+'"])'}}else{val='$locals["'+val+'"]'}}else if(!this.bound && !this.augm_assign){ if(scope.ntype=='generator'){ var up=0, sc=innermost while(sc!==scope){up++;sc=sc.parent_block} var scope_name="$B.frames_stack[$B.frames_stack.length-1-"+up+"][1]" val='$B.$check_def_free("'+val+'",'+scope_name+'["'+val+'"])'}else{val='$B.$check_def_free("'+val+'",'+scope_ns+'["'+val+'"])'}}else{val=scope_ns+'["'+val+'"]'} this.result=val+$to_js(this.tree,'') return this.result}else{ this.unknown_binding=true this.result='$B.$global_search("'+val+'")' return this.result}}} function $ImaginaryCtx(C,value){ this.type='imaginary' this.value=value this.toString=function(){return 'imaginary '+this.value} this.parent=C this.tree=[] C.tree[C.tree.length]=this this.to_js=function(){this.js_processed=true return 'complex(0,'+this.value+')'}} function $ImportCtx(C){ this.type='import' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.expect='id' this.toString=function(){return 'import '+this.tree} this.bind_names=function(){ var scope=$get_scope(this) for(var i=0;i1){bound=parts[0]}}else{bound=this.tree[i].alias} $B.bound[scope.id][bound]={level: scope.level}}} this.to_js=function(){this.js_processed=true var scope=$get_scope(this),res=[],pos=0 for(var i=0;i1){bound=parts[0]}}else{bound=this.tree[i].alias} $B.bound[scope.id][bound]=true}} this.transform=function(node,rank){ for(var i=1;i$B.min_int && v<$B.max_int){return v} else{return '$B.LongInt("'+value[1]+'", '+value[0]+')'}}} function $JSCode(js){this.js=js this.toString=function(){return this.js} this.to_js=function(){this.js_processed=true return this.js}} function $KwArgCtx(C){ this.type='kwarg' this.parent=C.parent this.tree=[C.tree[0]] C.parent.tree.pop() C.parent.tree.push(this) var value=this.tree[0].value var ctx=C.parent.parent if(ctx.kwargs===undefined){ctx.kwargs=[value]} else if(ctx.kwargs.indexOf(value)===-1){ctx.kwargs.push(value)} else{$_SyntaxError(C,['keyword argument repeated'])} this.toString=function(){return 'kwarg '+this.tree[0]+'='+this.tree[1]} this.to_js=function(){this.js_processed=true var key=this.tree[0].value if(key.substr(0,2)=='$$'){key=key.substr(2)} var res='{$nat:"kw",name:"'+key+'",' return res + 'value:'+$to_js(this.tree.slice(1,this.tree.length))+'}'}} function $LambdaCtx(C){ this.type='lambda' this.parent=C C.tree[C.tree.length]=this this.tree=[] this.args_start=$pos+6 this.vars=[] this.locals=[] this.toString=function(){return '(lambda) '+this.args_start+' '+this.body_start} this.to_js=function(){this.js_processed=true var node=$get_node(this),module=$get_module(this),src=$B.$py_src[module.id],args=src.substring(this.args_start,this.body_start),body=src.substring(this.body_start+1,this.body_end) body=body.replace(/\\\n/g,' ') body=body.replace(/\n/g,' ') var scope=$get_scope(this) var rand=$B.UUID(),func_name='lambda_'+$B.lambda_magic+'_'+rand,py='def '+func_name+'('+args+'):\n' py +=' return '+body var lambda_name='lambda'+rand,module_name=module.id.replace(/\./g,'_'),scope_id=scope.id.replace(/\./g,'_') var js=$B.py2js(py,module_name,lambda_name,scope_id,node.line_num).to_js() js='(function(){\n'+js+'\nreturn $locals.'+func_name+'\n})()' $B.clear_ns(lambda_name) delete $B.$py_src[lambda_name] return js}} function $ListOrTupleCtx(C,real){ this.type='list_or_tuple' this.start=$pos this.real=real this.expect='id' this.closed=false this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){switch(this.real){case 'list': return '(list) ['+this.tree+']' case 'list_comp': case 'gen_expr': return '('+this.real+') ['+this.intervals+'-'+this.tree+']' default: return '(tuple) ('+this.tree+')'}} this.is_comp=function(){switch(this.real){case 'list_comp': case 'gen_expr': case 'dict_or_set_comp': return true} return false} this.get_src=function(){ var scope=$get_scope(this) var ident=scope.id while($B.$py_src[ident]===undefined && $B.modules[ident].parent_block){ident=$B.modules[ident].parent_block.id} if($B.$py_src[ident]===undefined){ return $B.$py_src[scope.module]} return $B.$py_src[ident]} this.ids=function(){ var _ids={} for(var i=0;i1){var new_node=new $Node() var ctx=new $NodeCtx(new_node) ctx.tree=[this.tree[1]] new_node.indent=node.indent+4 this.tree.pop() node.add(new_node)} if(node.children.length==0){this.js=$to_js(this.tree)+';'}else{this.js=$to_js(this.tree)} return this.js}} function $NodeJS(js){var node=new $Node() new $NodeJSCtx(node,js) return node} function $NodeJSCtx(node,js){ this.node=node node.C=this this.type='node_js' this.tree=[js] this.toString=function(){return 'js '+js} this.to_js=function(){this.js_processed=true return js}} function $NonlocalCtx(C){ this.type='global' this.parent=C this.tree=[] this.names={} C.tree[C.tree.length]=this this.expect='id' this.scope=$get_scope(this) this.scope.nonlocals=this.scope.nonlocals ||{} if(this.scope.C===undefined){$_SyntaxError(C,["nonlocal declaration not allowed at module level"])} this.toString=function(){return 'global '+this.tree} this.add=function(name){if($B.bound[this.scope.id][name]=='arg'){$_SyntaxError(C,["name '"+name+"' is parameter and nonlocal"])} this.names[name]=[false,$pos] this.scope.nonlocals[name]=true} this.transform=function(node,rank){var pscope=this.scope.parent_block if(pscope.C===undefined){$_SyntaxError(C,["no binding for nonlocal '"+ $B.last(Object.keys(this.names))+"' found"])}else{while(pscope!==undefined && pscope.C!==undefined){for(var name in this.names){if($B.bound[pscope.id][name]!==undefined){this.names[name]=[true]}} pscope=pscope.parent_block} for(var name in this.names){if(!this.names[name][0]){console.log('nonlocal error, C '+C) $pos=this.names[name][1] $_SyntaxError(C,["no binding for nonlocal '"+name+"' found"])}}}} this.to_js=function(){this.js_processed=true return ''}} function $NotCtx(C){ this.type='not' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){return 'not ('+this.tree+')'} this.to_js=function(){this.js_processed=true return '!bool('+$to_js(this.tree)+')'}} function $OpCtx(C,op){ this.type='op' this.op=op this.parent=C.parent this.tree=[C] this.scope=$get_scope(this) if(C.type=="expr"){if(['int','float','str'].indexOf(C.tree[0].type)>-1){this.left_type=C.tree[0].type}else if(C.tree[0].type=="id"){var binding=$B.bound[this.scope.id][C.tree[0].value] if(binding){this.left_type=binding.type}}} C.parent.tree.pop() C.parent.tree.push(this) this.toString=function(){return '(op '+this.op+') ['+this.tree+']'} this.to_js=function(){this.js_processed=true var comps={'==':'eq','!=':'ne','>=':'ge','<=':'le','<':'lt','>':'gt'} if(comps[this.op]!==undefined){var method=comps[this.op] if(this.tree[0].type=='expr' && this.tree[1].type=='expr'){var t0=this.tree[0].tree[0],t1=this.tree[1].tree[0] switch(t1.type){case 'int': switch(t0.type){case 'int': if(t0.value>$B.min_int && t0.value<$B.max_int && t1.value>$B.min_int && t1.value<$B.max_int){return t0.to_js()+this.op+t1.to_js()}else{return 'getattr('+this.tree[0].to_js()+',"__'+ method+'__")('+this.tree[1].to_js()+')'} case 'str': return '$B.$TypeError("unorderable types: int() < str()")' case 'id': var res='typeof '+t0.to_js()+'=="number" ? ' res +=t0.to_js()+this.op+t1.to_js()+' : ' res +='getattr('+this.tree[0].to_js() res +=',"__'+method+'__")('+this.tree[1].to_js()+')' return res} break; case 'str': switch(t0.type){case 'str': return t0.to_js()+this.op+t1.to_js() case 'int': return '$B.$TypeError("unorderable types: str() < int()")' case 'id': var res='typeof '+t0.to_js()+'=="string" ? ' res +=t0.to_js()+this.op+t1.to_js()+' : ' res +='getattr('+this.tree[0].to_js() res +=',"__'+method+'__")('+this.tree[1].to_js()+')' return res} break; case 'id': if(t0.type=='id'){var res='typeof '+t0.to_js()+'!="object" && ' res +='typeof '+t0.to_js()+'==typeof '+t1.to_js() res +=' ? '+t0.to_js()+this.op+t1.to_js()+' : ' res +='getattr('+this.tree[0].to_js() res +=',"__'+method+'__")('+this.tree[1].to_js()+')' return res} break;}}} switch(this.op){case 'and': var op0=this.tree[0].to_js(),op1=this.tree[1].to_js() if(this.wrap!==undefined){ return '(function(){var '+this.wrap.name+'='+this.wrap.js+ ';return $B.$test_expr($B.$test_item('+ op0+') && $B.$test_item('+op1+'))})()'}else{return '$B.$test_expr($B.$test_item('+op0+')&&'+ '$B.$test_item('+op1+'))'} case 'or': var res='$B.$test_expr($B.$test_item('+this.tree[0].to_js()+')||' return res + '$B.$test_item('+this.tree[1].to_js()+'))' case 'in': return '$B.$is_member('+$to_js(this.tree)+')' case 'not_in': return '!$B.$is_member('+$to_js(this.tree)+')' case 'unary_neg': case 'unary_pos': case 'unary_inv': var op,method if(this.op=='unary_neg'){op='-';method='__neg__'} else if(this.op=='unary_pos'){op='+';method='__pos__'} else{op='~';method='__invert__'} if(this.tree[1].type=="expr"){var x=this.tree[1].tree[0] switch(x.type){case 'int': var v=parseInt(x.value[1],x.value[0]) if(v>$B.min_int && v<$B.max_int){return op+v} return 'getattr('+x.to_js()+', "'+method+'")()' case 'float': return 'float('+op+x.value+')' case 'imaginary': return 'complex(0,'+op+x.value+')'}} return 'getattr('+this.tree[1].to_js()+',"'+method+'")()' case 'is': return this.tree[0].to_js()+ '===' + this.tree[1].to_js() case 'is_not': return this.tree[0].to_js()+ '!==' + this.tree[1].to_js() case '*': case '+': case '-': var op=this.op,vars=[],has_float_lit=false,scope=$get_scope(this) function is_simple(elt){if(elt.type=='expr' && elt.tree[0].type=='int'){return true} else if(elt.type=='expr' && elt.tree[0].type=='float'){has_float_lit=true return true}else if(elt.type=='expr' && elt.tree[0].type=='list_or_tuple' && elt.tree[0].real=='tuple' && elt.tree[0].tree.length==1 && elt.tree[0].tree[0].type=='expr'){return is_simple(elt.tree[0].tree[0].tree[0])}else if(elt.type=='expr' && elt.tree[0].type=='id'){var _var=elt.tree[0].to_js() if(vars.indexOf(_var)==-1){vars.push(_var)} return true}else if(elt.type=='op' &&['*','+','-'].indexOf(elt.op)>-1){for(var i=0;i-1){t=v.type}else if(v.type=='id' && ns[v.value]){t=ns[v.value].type} return t} var e0=this.tree[0],e1=this.tree[1] if(is_simple(this)){var v0=this.tree[0].tree[0] var v1=this.tree[1].tree[0] if(vars.length==0 && !has_float_lit){ return this.simple_js()}else if(vars.length==0){ return 'new Number('+this.simple_js()+')'}else{ var ns=$B.bound[scope.id],t0=get_type(ns,v0),t1=get_type(ns,v1) if((t0=='float' && t1=='float')|| (this.op=='+' && t0=='str' && t1=='str')){this.result_type=t0 return v0.to_js()+this.op+v1.to_js()}else if(['int','float'].indexOf(t0)>-1 && ['int','float'].indexOf(t1)>-1){if(t0=='int' && t1=='int'){this.result_type='int'} else{this.result_type='float'} switch(this.op){case '+': return '$B.add('+v0.to_js()+','+v1.to_js()+')' case '-': return '$B.sub('+v0.to_js()+','+v1.to_js()+')' case '*': return '$B.mul('+v0.to_js()+','+v1.to_js()+')'}} var tests=[],tests1=[],pos=0 for(var i=0;i0 && child.tree[0].type=='packed'){$_SyntaxError(C,["two starred expressions in assignment"])}}} this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){return '(packed) '+this.tree} this.to_js=function(){this.js_processed=true return $to_js(this.tree)}} function $PassCtx(C){ this.type='pass' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){return '(pass)'} this.to_js=function(){this.js_processed=true return 'void(0)'}} function $RaiseCtx(C){ this.type='raise' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){return ' (raise) '+this.tree} this.to_js=function(){this.js_processed=true var res='' if(this.tree.length===0){return '$B.$raise()'} var exc=this.tree[0],exc_js=exc.to_js() return '$B.$raise('+exc_js+')'}} function $RawJSCtx(C,js){this.type="raw_js" C.tree[C.tree.length]=this this.parent=C this.toString=function(){return '(js) '+js} this.to_js=function(){this.js_processed=true return js}} function $ReturnCtx(C){ this.type='return' this.parent=C this.tree=[] C.tree[C.tree.length]=this var node=$get_node(this) while(node.parent){if(node.parent.C){var elt=node.parent.C.tree[0] if(elt.type=='for'){elt.has_return=true break}else if(elt.type=='try'){elt.has_return=true}else if(elt.type=='single_kw' && elt.token=='finally'){elt.has_return=true}} node=node.parent} this.toString=function(){return 'return '+this.tree} this.to_js=function(){this.js_processed=true if(this.tree.length==1 && this.tree[0].type=='abstract_expr'){ this.tree.pop() new $IdCtx(new $ExprCtx(this,'rvalue',false),'None')} var scope=$get_scope(this) if(scope.ntype=='generator'){return 'return [$B.generator_return(' + $to_js(this.tree)+')]'} return 'var $res = '+$to_js(this.tree)+';'+ '$B.leave_frame($local_name);return $res'}} function $SingleKwCtx(C,token){ this.type='single_kw' this.token=token this.parent=C this.tree=[] C.tree[C.tree.length]=this if(token=="else"){var node=C.node var pnode=node.parent for(var rank=0;rank0){var elt=pctx.tree[0] if(elt.type=='for' || elt.type=='asyncfor' || (elt.type=='condition' && elt.token=='while')){elt.has_break=true elt.else_node=$get_node(this) this.loop_num=elt.loop_num}}} this.toString=function(){return this.token} this.transform=function(node,rank){ if(this.token=='finally'){var scope=$get_scope(this) if(scope.ntype!='generator'){var scope_id=scope.id.replace(/\./g,'_'),js='var $exit;if($B.frames_stack.length<$stack_length)'+ '{$exit=true;$B.frames_stack.push($top_frame)}' node.insert(0,$NodeJS(js)) node.add($NodeJS('if($exit){$B.leave_frame("'+scope_id+'")}'))}}} this.to_js=function(){this.js_processed=true if(this.token=='finally')return this.token if(this.loop_num!==undefined){var scope=$get_scope(this) var res='if($locals_'+scope.id.replace(/\./g,'_') return res +'["$no_break'+this.loop_num+'"])'} return this.token}} function $StarArgCtx(C){ this.type='star_arg' this.parent=C this.tree=[] C.tree[C.tree.length]=this this.toString=function(){return '(star arg) '+this.tree} this.to_js=function(){this.js_processed=true return '{$nat:"ptuple",arg:'+$to_js(this.tree)+'}'}} function $StringCtx(C,value){ this.type='str' this.parent=C this.tree=[value] this.raw=false C.tree[C.tree.length]=this this.toString=function(){return 'string '+(this.tree||'')} this.to_js=function(){this.js_processed=true var res='',type=null for(var i=0;i0 && ctx.tree[0].alias!==null && ctx.tree[0].alias!==undefined){ var new_node=new $Node() var alias=ctx.tree[0].alias var js='$locals["'+alias+'"]' js +='=$B.exception($err'+$loop_num+')' new $NodeJSCtx(new_node,js) node.parent.children[pos].insert(0,new_node)} catch_node.insert(catch_node.children.length,node.parent.children[pos]) if(ctx.tree.length===0){if(has_default){$_SyntaxError(C,'more than one except: line')} has_default=true} node.parent.children.splice(pos,1)}else if(ctx.type==='single_kw' && ctx.token==='finally'){has_finally=true var finally_node=node.parent.children[pos] pos++}else if(ctx.type==='single_kw' && ctx.token==='else'){if(has_else){$_SyntaxError(C,"more than one 'else'")} if(has_finally){$_SyntaxError(C,"'else' after 'finally'")} has_else=true var else_body=node.parent.children[pos] node.parent.children.splice(pos,1)}else{break}} if(!has_default){ var new_node=new $Node(),ctx=new $NodeCtx(new_node) catch_node.insert(catch_node.children.length,new_node) new $SingleKwCtx(ctx,'else') new_node.add($NodeJS('throw $err'+$loop_num))} if(has_else){var else_node=new $Node() else_node.module=scope.module new $NodeJSCtx(else_node,'if(!$failed'+$loop_num+')') for(var i=0;i1){ var suite=node.children,item=this.tree.pop(),new_node=new $Node(),ctx=new $NodeCtx(new_node),with_ctx=new $WithCtx(ctx) item.parent=with_ctx with_ctx.tree=[item] for(var i=0;i1){var nw=new $Node() var ctx=new $NodeCtx(nw) nw.parent=node nw.module=node.module nw.indent=node.indent+4 var wc=new $WithCtx(ctx) wc.tree=this.tree.slice(1) for(var i=0;i=0;i--){ids[i].alias=alias[i].value this.tree.splice(0,0,ids[i])}} var block=node.children node.children=[] var try_node=new $Node() try_node.is_try=true new $NodeJSCtx(try_node,'try') node.add(try_node) if(this.tree[0].alias){var alias=this.tree[0].alias.tree[0].tree[0].value var js='$locals'+'["'+alias+'"] = $value'+num var value_node=new $Node() new $NodeJSCtx(value_node,js) try_node.add(value_node)} for(var i=0;i0){var firstchild=node.children[0] if(firstchild.C.tree && firstchild.C.tree[0].type=='expr'){if(firstchild.C.tree[0].tree[0].type=='str') doc_string=firstchild.C.tree[0].tree[0].to_js()}} return doc_string} function $get_scope(C){ var ctx_node=C.parent while(ctx_node.type!=='node'){ctx_node=ctx_node.parent} var tree_node=ctx_node.node,scope=null,level=1 while(tree_node.parent && tree_node.parent.type!=='module'){var ntype=tree_node.parent.C.tree[0].type switch(ntype){case 'def': case 'class': case 'generator': var scope=tree_node.parent scope.ntype=ntype scope.is_function=ntype!='class' scope.level=level return scope} tree_node=tree_node.parent level++} var scope=tree_node.parent ||tree_node scope.ntype="module" scope.level=level return scope} function $get_level(ctx){var nd=$get_node(ctx),level=0 while(nd.parent!==undefined){level++ nd=nd.parent} return level} function $get_module(C){ var ctx_node=C.parent while(ctx_node.type!=='node'){ctx_node=ctx_node.parent} var tree_node=ctx_node.node var scope=null while(tree_node.parent.type!=='module'){tree_node=tree_node.parent} var scope=tree_node.parent scope.ntype="module" return scope} function $get_node(C){var ctx=C while(ctx.parent){ctx=ctx.parent} return ctx.node} function $get_blocks(name,scope){var res=[] while(true){if($B.bound[scope.id][name]!==undefined){res.push(scope.id)} if(scope.parent_block){if(scope.parent_block.id=='__builtins__'){if(scope.blurred){return false}}}else{break} scope=scope.parent_block} return res} function $to_js_map(tree_element){if(tree_element.to_js !==undefined)return tree_element.to_js() throw Error('no to_js() for '+tree_element)} function $to_js(tree,sep){if(sep===undefined){sep=','} return tree.map($to_js_map).join(sep)} function $arbo(ctx){while(ctx.parent!=undefined){ctx=ctx.parent} return ctx} function $transition(C,token){ switch(C.type){case 'abstract_expr': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lambda': case 'yield': C.parent.tree.pop() var commas=C.with_commas C=C.parent} switch(token){case 'id': return new $IdCtx(new $ExprCtx(C,'id',commas),arguments[2]) case 'str': return new $StringCtx(new $ExprCtx(C,'str',commas),arguments[2]) case 'bytes': return new $StringCtx(new $ExprCtx(C,'bytes',commas),arguments[2]) case 'int': return new $IntCtx(new $ExprCtx(C,'int',commas),arguments[2]) case 'float': return new $FloatCtx(new $ExprCtx(C,'float',commas),arguments[2]) case 'imaginary': return new $ImaginaryCtx(new $ExprCtx(C,'imaginary',commas),arguments[2]) case '(': return new $ListOrTupleCtx(new $ExprCtx(C,'tuple',commas),'tuple') case '[': return new $ListOrTupleCtx(new $ExprCtx(C,'list',commas),'list') case '{': return new $DictOrSetCtx(new $ExprCtx(C,'dict_or_set',commas)) case '.': return new $EllipsisCtx(new $ExprCtx(C,'ellipsis',commas)) case 'not': if(C.type==='op'&&C.op==='is'){ C.op='is_not' return C} return new $NotCtx(new $ExprCtx(C,'not',commas)) case 'lambda': return new $LambdaCtx(new $ExprCtx(C,'lambda',commas)) case 'op': var tg=arguments[2] switch(tg){case '*': C.parent.tree.pop() var commas=C.with_commas C=C.parent return new $PackedCtx(new $ExprCtx(C,'expr',commas)) case '-': case '~': case '+': C.parent.tree.pop() var left=new $UnaryCtx(C.parent,tg) if(tg=='-'){var op_expr=new $OpCtx(left,'unary_neg')} else if(tg=='+'){var op_expr=new $OpCtx(left,'unary_pos')} else{var op_expr=new $OpCtx(left,'unary_inv')} return new $AbstractExprCtx(op_expr,false) case 'not': C.parent.tree.pop() var commas=C.with_commas C=C.parent return new $NotCtx(new $ExprCtx(C,'not',commas))} $_SyntaxError(C,'token '+token+' after '+C) case '=': $_SyntaxError(C,token) case 'yield': return new $AbstractExprCtx(new $YieldCtx(C),true) case ':': return $transition(C.parent,token,arguments[2]) case ')': case ',': switch(C.parent.type){case 'list_or_tuple': case 'call_arg': case 'op': case 'yield': break default: $_SyntaxError(C,token)}} return $transition(C.parent,token,arguments[2]) case 'annotation': return $transition(C.parent,token) case 'assert': if(token==='eol')return $transition(C.parent,token) $_SyntaxError(C,token) case 'assign': if(token==='eol'){if(C.tree[1].type=='abstract_expr'){$_SyntaxError(C,'token '+token+' after '+C)} C.guess_type() return $transition(C.parent,'eol')} $_SyntaxError(C,'token '+token+' after '+C) case 'attribute': if(token==='id'){var name=arguments[2] if(noassign[name]===true){$_SyntaxError(C,["cannot assign to "+name])} C.name=name return C.parent} $_SyntaxError(C,token) case 'augm_assign': if(token==='eol'){if(C.tree[1].type=='abstract_expr'){$_SyntaxError(C,'token '+token+' after '+C)} return $transition(C.parent,'eol')} $_SyntaxError(C,'token '+token+' after '+C) case 'break': if(token==='eol')return $transition(C.parent,'eol') $_SyntaxError(C,token) case 'call': switch(token){case ',': if(C.expect=='id'){$_SyntaxError(C,token)} return C case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lambda': if(C.has_dstar)$_SyntaxError(C,token) C.expect=',' return $transition(new $CallArgCtx(C),token,arguments[2]) case ')': C.end=$pos return C.parent case 'op': C.expect=',' switch(arguments[2]){case '-': case '~': case '+': C.expect=',' return $transition(new $CallArgCtx(C),token,arguments[2]) case '*': C.has_star=true; return new $StarArgCtx(C) case '**': C.has_dstar=true return new $DoubleStarArgCtx(C)} $_SyntaxError(C,token)} return $transition(C.parent,token,arguments[2]) case 'call_arg': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lambda': if(C.expect==='id'){C.expect=',' var expr=new $AbstractExprCtx(C,false) return $transition(expr,token,arguments[2])} break case '=': if(C.expect===','){return new $ExprCtx(new $KwArgCtx(C),'kw_value',false)} break case 'for': var lst=new $ListOrTupleCtx(C,'gen_expr') lst.vars=C.vars lst.locals=C.locals lst.intervals=[C.start] C.tree.pop() lst.expression=C.tree C.tree=[lst] lst.tree=[] var comp=new $ComprehensionCtx(lst) return new $TargetListCtx(new $CompForCtx(comp)) case 'op': if(C.expect==='id'){var op=arguments[2] C.expect=',' switch(op){case '+': case '-': case '~': return $transition(new $AbstractExprCtx(C,false),token,op) case '*': return new $StarArgCtx(C) case '**': return new $DoubleStarArgCtx(C)}} $_SyntaxError(C,'token '+token+' after '+C) case ')': if(C.parent.kwargs && $B.last(C.parent.tree).tree[0]&& ['kwarg','star_arg','double_star_arg'].indexOf($B.last(C.parent.tree).tree[0].type)==-1){$_SyntaxError(C,['non-keyword arg after keyword arg'])} if(C.tree.length>0){var son=C.tree[C.tree.length-1] if(son.type==='list_or_tuple'&&son.real==='gen_expr'){son.intervals.push($pos)}} return $transition(C.parent,token) case ':': if(C.expect===',' && C.parent.parent.type==='lambda'){return $transition(C.parent.parent,token)} break case ',': if(C.expect===','){if(C.parent.kwargs && ['kwarg','star_arg','double_star_arg'].indexOf($B.last(C.parent.tree).tree[0].type)==-1){console.log('err2') $_SyntaxError(C,['non-keyword arg after keyword arg'])} return $transition(C.parent,token,arguments[2])} console.log('C '+C+'token '+token+' expect '+C.expect)} $_SyntaxError(C,'token '+token+' after '+C) case 'class': switch(token){case 'id': if(C.expect==='id'){C.set_name(arguments[2]) C.expect='(:' return C} break case '(': return new $CallCtx(C) case ':': return $BodyCtx(C)} $_SyntaxError(C,'token '+token+' after '+C) case 'comp_if': return $transition(C.parent,token,arguments[2]) case 'comp_for': if(token==='in' && C.expect==='in'){C.expect=null return new $AbstractExprCtx(new $CompIterableCtx(C),true)} if(C.expect===null){ return $transition(C.parent,token,arguments[2])} $_SyntaxError(C,'token '+token+' after '+C) case 'comp_iterable': return $transition(C.parent,token,arguments[2]) case 'comprehension': switch(token){case 'if': return new $AbstractExprCtx(new $CompIfCtx(C),false) case 'for': return new $TargetListCtx(new $CompForCtx(C))} return $transition(C.parent,token,arguments[2]) case 'condition': if(token===':')return $BodyCtx(C) $_SyntaxError(C,'token '+token+' after '+C) case 'continue': if(token=='eol')return C.parent $_SyntaxError(C,'token '+token+' after '+C) case 'ctx_manager_alias': switch(token){case ',': case ':': return $transition(C.parent,token,arguments[2])} $_SyntaxError(C,'token '+token+' after '+C) case 'decorator': if(token==='id' && C.tree.length===0){return $transition(new $AbstractExprCtx(C,false),token,arguments[2])} if(token==='eol'){return $transition(C.parent,token)} $_SyntaxError(C,'token '+token+' after '+C) case 'def': switch(token){case 'id': if(C.name){$_SyntaxError(C,'token '+token+' after '+C)} C.set_name(arguments[2]) return C case '(': if(C.name===null){$_SyntaxError(C,'token '+token+' after '+C)} C.has_args=true; return new $FuncArgs(C) case 'annotation': return new $AbstractExprCtx(new $AnnotationCtx(C),true) case ':': if(C.has_args)return $BodyCtx(C)} $_SyntaxError(C,'token '+token+' after '+C) case 'del': if(token==='eol')return $transition(C.parent,token) $_SyntaxError(C,'token '+token+' after '+C) case 'dict_or_set': if(C.closed){switch(token){case '[': return new $SubCtx(C.parent) case '(': return new $CallArgCtx(new $CallCtx(C))} return $transition(C.parent,token,arguments[2])}else{if(C.expect===','){switch(token){case '}': switch(C.real){case 'dict_or_set': if(C.tree.length !==1)break C.real='set' case 'set': case 'set_comp': case 'dict_comp': C.items=C.tree C.tree=[] C.closed=true return C case 'dict': if(C.tree.length%2===0){C.items=C.tree C.tree=[] C.closed=true return C}} $_SyntaxError(C,'token '+token+' after '+C) case ',': if(C.real==='dict_or_set'){C.real='set'} if(C.real==='dict' && C.tree.length%2){$_SyntaxError(C,'token '+token+' after '+C)} C.expect='id' return C case ':': if(C.real==='dict_or_set'){C.real='dict'} if(C.real==='dict'){C.expect=',' return new $AbstractExprCtx(C,false)}else{$_SyntaxError(C,'token '+token+' after '+C)} case 'for': if(C.real==='dict_or_set'){C.real='set_comp'} else{C.real='dict_comp'} var lst=new $ListOrTupleCtx(C,'dict_or_set_comp') lst.intervals=[C.start+1] lst.vars=C.vars C.tree.pop() lst.expression=C.tree C.tree=[lst] lst.tree=[] var comp=new $ComprehensionCtx(lst) return new $TargetListCtx(new $CompForCtx(comp))} $_SyntaxError(C,'token '+token+' after '+C)}else if(C.expect==='id'){switch(token){case '}': if(C.tree.length==0){ C.items=[] C.real='dict'}else{ C.items=C.tree} C.tree=[] C.closed=true return C case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lambda': C.expect=',' var expr=new $AbstractExprCtx(C,false) return $transition(expr,token,arguments[2]) case 'op': switch(arguments[2]){case '+': return C case '-': case '~': C.expect=',' var left=new $UnaryCtx(C,arguments[2]) if(arguments[2]=='-'){var op_expr=new $OpCtx(left,'unary_neg')} else if(arguments[2]=='+'){var op_expr=new $OpCtx(left,'unary_pos')} else{var op_expr=new $OpCtx(left,'unary_inv')} return new $AbstractExprCtx(op_expr,false)} $_SyntaxError(C,'token '+token+' after '+C)} $_SyntaxError(C,'token '+token+' after '+C)} return $transition(C.parent,token,arguments[2])} case 'double_star_arg': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lambda': return $transition(new $AbstractExprCtx(C,false),token,arguments[2]) case ',': case ')': return $transition(C.parent,token) case ':': if(C.parent.parent.type==='lambda'){return $transition(C.parent.parent,token)}} $_SyntaxError(C,'token '+token+' after '+C) case 'ellipsis': if(token=='.'){C.nbdots++;return C} else{if(C.nbdots!=3){$pos--;$_SyntaxError(C,'token '+token+' after '+C)}else{return $transition(C.parent,token,arguments[2])}} case 'except': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case 'not': case 'lamdba': if(C.expect==='id'){C.expect='as' return $transition(new $AbstractExprCtx(C,false),token,arguments[2])} case 'as': if(C.expect==='as' && C.has_alias===undefined){C.expect='alias' C.has_alias=true return C} case 'id': if(C.expect==='alias'){C.expect=':' C.set_alias(arguments[2]) return C} break case ':': var _ce=C.expect if(_ce=='id' ||_ce=='as' ||_ce==':'){return $BodyCtx(C)} break case '(': if(C.expect==='id' && C.tree.length===0){C.parenth=true return C} break case ')': if(C.expect==',' ||C.expect=='as'){C.expect='as' return C} case ',': if(C.parenth!==undefined && C.has_alias===undefined && (C.expect=='as' ||C.expect==',')){C.expect='id' return C}} $_SyntaxError(C,'token '+token+' after '+C.expect) case 'expr': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case 'lamdba': $_SyntaxError(C,'token '+token+' after '+C) break case '[': case '(': case '{': case '.': case 'not': if(C.expect==='expr'){C.expect=',' return $transition(new $AbstractExprCtx(C,false),token,arguments[2])}} switch(token){case 'not': if(C.expect===',')return new $ExprNot(C) break case 'in': if(C.parent.type=='target_list'){ return $transition(C.parent,token)} if(C.expect===',')return $transition(C,'op','in') break case ',': if(C.expect===','){if(C.with_commas){ C.parent.tree.pop() var tuple=new $ListOrTupleCtx(C.parent,'tuple') tuple.implicit=true tuple.has_comma=true tuple.tree=[C] C.parent=tuple return tuple}} return $transition(C.parent,token) case '.': return new $AttrCtx(C) case '[': return new $AbstractExprCtx(new $SubCtx(C),true) case '(': return new $CallCtx(C) case 'op': var op_parent=C.parent,op=arguments[2] if(op_parent.type=='ternary' && op_parent.in_else){var new_op=new $OpCtx(C,op) return new $AbstractExprCtx(new_op,false)} var op1=C.parent,repl=null while(1){if(op1.type==='expr'){op1=op1.parent} else if(op1.type==='op' &&$op_weight[op1.op]>=$op_weight[op] && !(op1.op=='**' && op=='**') ){repl=op1;op1=op1.parent}else if(op1.type=="not" && $op_weight['not']>$op_weight[op]){repl=op1;op1=op1.parent}else{break}} if(repl===null){while(1){if(C.parent!==op1){C=C.parent op_parent=C.parent}else{break}} C.parent.tree.pop() var expr=new $ExprCtx(op_parent,'operand',C.with_commas) expr.expect=',' C.parent=expr var new_op=new $OpCtx(C,op) return new $AbstractExprCtx(new_op,false)}else{ if(op==='and' ||op==='or'){while(repl.parent.type==='not'|| (repl.parent.type==='expr'&&repl.parent.parent.type==='not')){ repl=repl.parent op_parent=repl.parent}}} if(repl.type==='op'){var _flag=false switch(repl.op){case '<': case '<=': case '==': case '!=': case 'is': case '>=': case '>': _flag=true} if(_flag){switch(op){case '<': case '<=': case '==': case '!=': case 'is': case '>=': case '>': var c2=repl.tree[1], c2js=c2.to_js() var c2_clone=new Object() for(var attr in c2){c2_clone[attr]=c2[attr]} var vname="$c"+chained_comp_num c2.to_js=function(){return vname} c2_clone.to_js=function(){return vname} chained_comp_num++ while(repl.parent && repl.parent.type=='op'){if($op_weight[repl.parent.op]<$op_weight[repl.op]){repl=repl.parent}else{break}} repl.parent.tree.pop() var and_expr=new $OpCtx(repl,'and') and_expr.wrap={'name': vname,'js': c2js} c2_clone.parent=and_expr and_expr.tree.push('xxx') var new_op=new $OpCtx(c2_clone,op) return new $AbstractExprCtx(new_op,false)}}} repl.parent.tree.pop() var expr=new $ExprCtx(repl.parent,'operand',false) expr.tree=[op1] repl.parent=expr var new_op=new $OpCtx(repl,op) return new $AbstractExprCtx(new_op,false) case 'augm_assign': if(C.expect===','){return new $AbstractExprCtx(new $AugmentedAssignCtx(C,arguments[2]),true)} break case '=': if(C.expect===','){if(C.parent.type==="call_arg"){return new $AbstractExprCtx(new $KwArgCtx(C),true)}else if(C.parent.type=="annotation"){return $transition(C.parent.parent,token,arguments[2])} while(C.parent!==undefined){C=C.parent if(C.type=='condition'){$_SyntaxError(C,'token '+token+' after '+C)}} C=C.tree[0] return new $AbstractExprCtx(new $AssignCtx(C),true)} break case 'if': var in_comp=false,ctx=C.parent while(true){if(ctx.type=='comp_iterable'){in_comp=true;break} else if(ctx.parent!==undefined){ctx=ctx.parent} else{break}} if(in_comp){break} var ctx=C while(ctx.parent && ctx.parent.type=='op'){ctx=ctx.parent if(ctx.type=='expr' && ctx.parent && ctx.parent.type=='op'){ctx=ctx.parent}} return new $AbstractExprCtx(new $TernaryCtx(ctx),false)} return $transition(C.parent,token) case 'expr_not': if(token=='in'){ C.parent.tree.pop() return new $AbstractExprCtx(new $OpCtx(C.parent,'not_in'),false)} $_SyntaxError(C,'token '+token+' after '+C) case 'for': switch(token){case 'in': return new $AbstractExprCtx(new $ExprCtx(C,'target list',true),false) case ':': return $BodyCtx(C)} $_SyntaxError(C,'token '+token+' after '+C) case 'from': switch(token){case 'id': if(C.expect=='id'){C.add_name(arguments[2]) C.expect=',' return C} if(C.expect==='alias'){C.aliases[C.names[C.names.length-1]]=arguments[2] C.expect=',' return C} case '.': if(C.expect=='module'){if(token=='id'){C.module +=arguments[2]} else{C.module +='.'} return C} case 'import': C.blocking=token=='import' if(C.expect=='module'){C.expect='id' return C} case 'op': if(arguments[2]=='*' && C.expect=='id' && C.names.length==0){if($get_scope(C).ntype!=='module'){$_SyntaxError(C,["import * only allowed at module level"])} C.add_name('*') C.expect='eol' return C} case ',': if(C.expect==','){C.expect='id' return C} case 'eol': switch(C.expect){case ',': case 'eol': C.bind_names() return $transition(C.parent,token) case 'id': $_SyntaxError(C,['trailing comma not allowed without surrounding parentheses']) default: $_SyntaxError(C,['invalid syntax'])} case 'as': if(C.expect==',' ||C.expect=='eol'){C.expect='alias' return C} case '(': if(C.expect=='id'){C.expect='id' return C} case ')': if(C.expect==',' ||C.expect=='id'){C.expect='eol' return C}} $_SyntaxError(C,'token '+token+' after '+C) case 'func_arg_id': switch(token){case '=': if(C.expect==='='){C.parent.has_default=true var def_ctx=C.parent.parent if(C.parent.has_star_arg){def_ctx.default_list.push(def_ctx.after_star.pop())}else{def_ctx.default_list.push(def_ctx.positional_list.pop())} return new $AbstractExprCtx(C,false)} break case ',': case ')': if(C.parent.has_default && C.tree.length==0 && C.parent.has_star_arg===undefined){console.log('parent '+C.parent,C.parent) $pos -=C.name.length $_SyntaxError(C,['non-default argument follows default argument'])}else{return $transition(C.parent,token)} case ':': return new $AbstractExprCtx(new $AnnotationCtx(C),false)} $_SyntaxError(C,'token '+token+' after '+C) case 'func_args': switch(token){case 'id': if(C.expect==='id'){C.expect=',' if(C.names.indexOf(arguments[2])>-1){$_SyntaxError(C,['duplicate argument '+arguments[2]+' in function definition'])}} return new $FuncArgIdCtx(C,arguments[2]) case ',': if(C.has_kw_arg)$_SyntaxError(C,'duplicate kw arg') if(C.expect===','){C.expect='id' return C} $_SyntaxError(C,'token '+token+' after '+C) case ')': return C.parent case 'op': var op=arguments[2] C.expect=',' if(op=='*'){if(C.has_star_arg){$_SyntaxError(C,'duplicate star arg')} return new $FuncStarArgCtx(C,'*')} if(op=='**')return new $FuncStarArgCtx(C,'**') $_SyntaxError(C,'token '+op+' after '+C)} $_SyntaxError(C,'token '+token+' after '+C) case 'func_star_arg': switch(token){case 'id': if(C.name===undefined){if(C.parent.names.indexOf(arguments[2])>-1){$_SyntaxError(C,['duplicate argument '+arguments[2]+' in function definition'])}} C.set_name(arguments[2]) C.parent.names.push(arguments[2]) return C case ',': case ')': if(C.name===undefined){ C.set_name('$dummy') C.parent.names.push('$dummy')} return $transition(C.parent,token) case ':': if(C.name===undefined){$_SyntaxError(C,'annotation on an unnamed parameter')} return new $AbstractExprCtx(new $AnnotationCtx(C),false)} $_SyntaxError(C,'token '+token+' after '+C) case 'global': switch(token){case 'id': if(C.expect==='id'){new $IdCtx(C,arguments[2]) C.add(arguments[2]) C.expect=',' return C} break case ',': if(C.expect===','){C.expect='id' return C} break case 'eol': if(C.expect===','){return $transition(C.parent,token)} break} $_SyntaxError(C,'token '+token+' after '+C) case 'id': switch(token){case '=': if(C.parent.type==='expr' && C.parent.parent !==undefined && C.parent.parent.type==='call_arg'){return new $AbstractExprCtx(new $KwArgCtx(C.parent),false)} return $transition(C.parent,token,arguments[2]) case 'op': return $transition(C.parent,token,arguments[2]) case 'id': case 'str': case 'int': case 'float': case 'imaginary': $_SyntaxError(C,'token '+token+' after '+C)} return $transition(C.parent,token,arguments[2]) case 'import': switch(token){case 'id': if(C.expect==='id'){new $ImportedModuleCtx(C,arguments[2]) C.expect=',' return C} if(C.expect==='qual'){C.expect=',' C.tree[C.tree.length-1].name +='.'+arguments[2] C.tree[C.tree.length-1].alias +='.'+arguments[2] return C} if(C.expect==='alias'){C.expect=',' C.tree[C.tree.length-1].alias=arguments[2] return C} break case '.': if(C.expect===','){C.expect='qual' return C} break case ',': if(C.expect===','){C.expect='id' return C} break case 'as': if(C.expect===','){C.expect='alias' return C} break case 'eol': if(C.expect===','){C.bind_names() return $transition(C.parent,token)} break} $_SyntaxError(C,'token '+token+' after '+C) case 'imaginary': case 'int': case 'float': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case 'not': case 'lamdba': $_SyntaxError(C,'token '+token+' after '+C)} return $transition(C.parent,token,arguments[2]) case 'kwarg': if(token===',')return new $CallArgCtx(C.parent.parent) return $transition(C.parent,token) case 'lambda': if(token===':' && C.args===undefined){C.args=C.tree C.tree=[] C.body_start=$pos return new $AbstractExprCtx(C,false)} if(C.args!==undefined){ C.body_end=$pos return $transition(C.parent,token)} if(C.args===undefined){return $transition(new $CallCtx(C),token,arguments[2])} $_SyntaxError(C,'token '+token+' after '+C) case 'list_or_tuple': if(C.closed){if(token==='[')return new $SubCtx(C.parent) if(token==='(')return new $CallCtx(C) return $transition(C.parent,token,arguments[2])}else{if(C.expect===','){switch(C.real){case 'tuple': case 'gen_expr': if(token===')'){C.closed=true if(C.real==='gen_expr'){C.intervals.push($pos)} return C.parent} break case 'list': case 'list_comp': if(token===']'){C.closed=true if(C.real==='list_comp'){C.intervals.push($pos)} return C} break case 'dict_or_set_comp': if(token==='}'){C.intervals.push($pos) return $transition(C.parent,token)} break} switch(token){case ',': if(C.real==='tuple'){C.has_comma=true} C.expect='id' return C case 'for': if(C.real==='list'){C.real='list_comp'} else{C.real='gen_expr'} C.intervals=[C.start+1] C.expression=C.tree C.tree=[] var comp=new $ComprehensionCtx(C) return new $TargetListCtx(new $CompForCtx(comp))} return $transition(C.parent,token,arguments[2])}else if(C.expect==='id'){switch(C.real){case 'tuple': if(token===')'){C.closed=true return C.parent} if(token=='eol' && C.implicit===true){C.closed=true return $transition(C.parent,token)} break case 'gen_expr': if(token===')'){C.closed=true return $transition(C.parent,token)} break case 'list': if(token===']'){C.closed=true return C} break} switch(token){case '=': if(C.real=='tuple' && C.implicit===true){C.closed=true C.parent.tree.pop() var expr=new $ExprCtx(C.parent,'tuple',false) expr.tree=[C] C.parent=expr return $transition(C.parent,token)} break case ')': break case ']': if(C.real=='tuple' && C.implicit===true){ return $transition(C.parent,token,arguments[2])}else{break} case ',': $_SyntaxError(C,'unexpected comma inside list') default: C.expect=',' var expr=new $AbstractExprCtx(C,false) return $transition(expr,token,arguments[2])}}else{return $transition(C.parent,token,arguments[2])}} case 'list_comp': switch(token){case ']': return C.parent case 'in': return new $ExprCtx(C,'iterable',true) case 'if': return new $ExprCtx(C,'condition',true)} $_SyntaxError(C,'token '+token+' after '+C) case 'node': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case 'not': case 'lamdba': case '.': var expr=new $AbstractExprCtx(C,true) return $transition(expr,token,arguments[2]) case 'op': switch(arguments[2]){case '*': case '+': case '-': case '~': var expr=new $AbstractExprCtx(C,true) return $transition(expr,token,arguments[2])} break case 'class': return new $ClassCtx(C) case 'continue': return new $ContinueCtx(C) case '__debugger__': return new $DebuggerCtx(C) case 'break': return new $BreakCtx(C) case 'def': return new $DefCtx(C) case 'for': return new $TargetListCtx(new $ForExpr(C)) case 'if': case 'while': return new $AbstractExprCtx(new $ConditionCtx(C,token),false) case 'elif': var previous=$previous(C) if(['condition'].indexOf(previous.type)==-1 || previous.token=='while'){$_SyntaxError(C,'elif after '+previous.type)} return new $AbstractExprCtx(new $ConditionCtx(C,token),false) case 'else': var previous=$previous(C) if(['condition','except','for'].indexOf(previous.type)==-1){$_SyntaxError(C,'else after '+previous.type)} return new $SingleKwCtx(C,token) case 'finally': var previous=$previous(C) if(['try','except'].indexOf(previous.type)==-1 && (previous.type!='single_kw' ||previous.token!='else')){$_SyntaxError(C,'finally after '+previous.type)} return new $SingleKwCtx(C,token) case 'try': return new $TryCtx(C) case 'except': var previous=$previous(C) if(['try','except'].indexOf(previous.type)==-1){$_SyntaxError(C,'except after '+previous.type)} return new $ExceptCtx(C) case 'assert': return new $AbstractExprCtx(new $AssertCtx(C),'assert',true) case 'from': return new $FromCtx(C) case 'import': return new $ImportCtx(C) case 'IMPRT': return new $IMPRTCtx(C) case 'global': return new $GlobalCtx(C) case 'nonlocal': return new $NonlocalCtx(C) case 'lambda': return new $LambdaCtx(C) case 'pass': return new $PassCtx(C) case 'raise': return new $AbstractExprCtx(new $RaiseCtx(C),true) case 'return': return new $AbstractExprCtx(new $ReturnCtx(C),true) case 'with': return new $AbstractExprCtx(new $WithCtx(C),false) case 'yield': return new $AbstractExprCtx(new $YieldCtx(C),true) case 'del': return new $AbstractExprCtx(new $DelCtx(C),true) case '@': return new $DecoratorCtx(C) case 'eol': if(C.tree.length===0){ C.node.parent.children.pop() return C.node.parent.C} return C} $_SyntaxError(C,'token '+token+' after '+C) case 'not': switch(token){case 'in': C.parent.parent.tree.pop() return new $ExprCtx(new $OpCtx(C.parent,'not_in'),'op',false) case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lamdba': var expr=new $AbstractExprCtx(C,false) return $transition(expr,token,arguments[2]) case 'op': var a=arguments[2] if('+'==a ||'-'==a ||'~'==a){var expr=new $AbstractExprCtx(C,false) return $transition(expr,token,arguments[2])}} return $transition(C.parent,token) case 'op': if(C.op===undefined){$_SyntaxError(C,['C op undefined '+C])} if(C.op.substr(0,5)=='unary' && token !='eol'){if(C.parent.type=='assign' ||C.parent.type=='return'){ C.parent.tree.pop() var t=new $ListOrTupleCtx(C.parent,'tuple') t.tree.push(C) C.parent=t return t}} switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lamdba': return $transition(new $AbstractExprCtx(C,false),token,arguments[2]) case 'op': switch(arguments[2]){case '+': case '-': case '~': return new $UnaryCtx(C,arguments[2])} default: if(C.tree[C.tree.length-1].type=='abstract_expr'){$_SyntaxError(C,'token '+token+' after '+C)}} var t0=C.tree[0],t1=C.tree[1] if(t0.tree && t1.tree){t0=t0.tree[0] t1=t1.tree[0]} return $transition(C.parent,token) case 'packed': if(token==='id'){new $IdCtx(C,arguments[2]) C.parent.expect=',' return C.parent} $_SyntaxError(C,'token '+token+' after '+C) case 'pass': if(token==='eol')return C.parent $_SyntaxError(C,'token '+token+' after '+C) case 'raise': switch(token){case 'id': if(C.tree.length===0){return new $IdCtx(new $ExprCtx(C,'exc',false),arguments[2])} break case 'from': if(C.tree.length>0){return new $AbstractExprCtx(C,false)} break case 'eol': return $transition(C.parent,token)} $_SyntaxError(C,'token '+token+' after '+C) case 'return': return $transition(C.parent,token) case 'single_kw': if(token===':')return $BodyCtx(C) $_SyntaxError(C,'token '+token+' after '+C) case 'star_arg': switch(token){case 'id': if(C.parent.type=="target_list"){C.tree.push(arguments[2]) C.parent.expect=',' console.log('return parent',C.parent) return C.parent} return $transition(new $AbstractExprCtx(C,false),token,arguments[2]) case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case 'not': case 'lamdba': return $transition(new $AbstractExprCtx(C,false),token,arguments[2]) case ',': return $transition(C.parent,token) case ')': return $transition(C.parent,token) case ':': if(C.parent.parent.type==='lambda'){return $transition(C.parent.parent,token)}} $_SyntaxError(C,'token '+token+' after '+C) case 'str': switch(token){case '[': return new $AbstractExprCtx(new $SubCtx(C.parent),false) case '(': C.parent.tree[0]=C return new $CallCtx(C.parent) case 'str': C.tree.push(arguments[2]) return C} return $transition(C.parent,token,arguments[2]) case 'sub': switch(token){case 'id': case 'imaginary': case 'int': case 'float': case 'str': case 'bytes': case '[': case '(': case '{': case '.': case 'not': case 'lamdba': var expr=new $AbstractExprCtx(C,false) return $transition(expr,token,arguments[2]) case ']': return C.parent case ':': if(C.tree.length==0){new $AbstractExprCtx(C,false)} return new $AbstractExprCtx(C,false)} $_SyntaxError(C,'token '+token+' after '+C) case 'target_list': switch(token){case 'id': if(C.expect==='id'){C.expect=',' return new $IdCtx(new $ExprCtx(C,'target',false),arguments[2])} case 'op': if(C.expect=='id' && arguments[2]=='*'){ return new $PackedCtx(C)} case '(': case '[': if(C.expect==='id'){C.expect=',' return new $TargetListCtx(C)} case ')': case ']': if(C.expect===',')return C.parent case ',': if(C.expect==','){C.expect='id' return C}} if(C.expect===','){return $transition(C.parent,token,arguments[2])}else if(token=='in'){ return $transition(C.parent,token,arguments[2])} $_SyntaxError(C,'token '+token+' after '+C) case 'ternary': if(token==='else'){C.in_else=true return new $AbstractExprCtx(C,false)} return $transition(C.parent,token,arguments[2]) case 'try': if(token===':')return $BodyCtx(C) $_SyntaxError(C,'token '+token+' after '+C) case 'unary': switch(token){case 'int': case 'float': case 'imaginary': console.log(token,arguments[2],'after',C) var expr=C.parent C.parent.parent.tree.pop() var value=arguments[2] if(C.op==='-'){value="-"+value} else if(C.op==='~'){value=~value} return $transition(C.parent.parent,token,value) case 'id': C.parent.parent.tree.pop() var expr=new $ExprCtx(C.parent.parent,'call',false) var expr1=new $ExprCtx(expr,'id',false) new $IdCtx(expr1,arguments[2]) var repl=new $AttrCtx(expr) if(C.op==='+'){repl.name='__pos__'} else if(C.op==='-'){repl.name='__neg__'} else{repl.name='__invert__'} return expr1 case 'op': if('+'==arguments[2]||'-'==arguments[2]){var op=arguments[2] if(C.op===op){C.op='+'}else{C.op='-'} return C}} return $transition(C.parent,token,arguments[2]) case 'with': switch(token){case 'id': if(C.expect==='id'){C.expect='as' return $transition(new $AbstractExprCtx(C,false),token,arguments[2])} if(C.expect==='alias'){if(C.parenth!==undefined){C.expect=','} else{C.expect=':'} C.set_alias(arguments[2]) return C} break case 'as': return new $AbstractExprCtx(new $AliasCtx(C)) case ':': switch(C.expect){case 'id': case 'as': case ':': return $BodyCtx(C)} break case '(': if(C.expect==='id' && C.tree.length===0){C.parenth=true return C}else if(C.expect=='alias'){C.expect=':' return new $TargetListCtx(C,false)} break case ')': if(C.expect==',' ||C.expect=='as'){C.expect=':' return C} break case ',': if(C.parenth!==undefined && C.has_alias===undefined && (C.expect==',' ||C.expect=='as')){C.expect='id' return C}else if(C.expect=='as'){C.expect='id' return C}else if(C.expect==':'){C.expect='id' return C} break} $_SyntaxError(C,'token '+token+' after '+C.expect) case 'yield': if(token=='from'){ if(C.tree[0].type!='abstract_expr'){ $_SyntaxError(C,"'from' must follow 'yield'")} C.from=true C.tree=[] return new $AbstractExprCtx(C,true)} return $transition(C.parent,token)}} $B.forbidden=['case','catch','constructor','Date','delete','default','enum','eval','extends','Error','history','function','location','Math','new','null','Number','RegExp','super','this','throw','var','toString'] var s_escaped='abfnrtvxuU"'+"'"+'\\',is_escaped={} for(var i=0;i0)indent+=8-indent%8}else{break}} var _s=src.charAt(pos) if(_s=='\n'){pos++;lnum++;indent=null;continue} else if(_s==='#'){ var offset=src.substr(pos).search(/\n/) if(offset===-1){break} pos+=offset+1;lnum++;indent=null;continue} new_node.indent=indent new_node.line_num=lnum new_node.module=module if(indent>current.indent){ if(C!==null){if($indented.indexOf(C.tree[0].type)==-1){$pos=pos $_SyntaxError(C,'unexpected indent',pos)}} current.add(new_node)}else if(indent<=current.indent && $indented.indexOf(C.tree[0].type)>-1 && C.tree.length<2){$pos=pos $_SyntaxError(C,'expected an indented block',pos)}else{ while(indent!==current.indent){current=current.parent if(current===undefined ||indent>current.indent){$pos=pos $_SyntaxError(C,'unexpected indent',pos)}} current.parent.add(new_node)} current=new_node C=new $NodeCtx(new_node) continue} if(car=="#"){var end=src.substr(pos+1).search('\n') if(end==-1){end=src.length-1} pos +=end+1;continue} if(car=='"' ||car=="'"){var raw=C.type=='str' && C.raw,bytes=false ,end=null; if(string_modifier){switch(string_modifier){case 'r': raw=true break case 'u': break case 'b': bytes=true break case 'rb': case 'br': bytes=true;raw=true break} string_modifier=false} if(src.substr(pos,3)==car+car+car){_type="triple_string";end=pos+3} else{_type="string";end=pos+1} var escaped=false var zone=car var found=false while(end-1){$pos=pos-name.length if(unsupported.indexOf(name)>-1){$_SyntaxError(C,"Unsupported Python keyword '"+name+"'")} C=$transition(C,name)}else if($operators[name]!==undefined && $B.forbidden.indexOf(name)==-1){ if(name=='is'){ var re=/^\s+not\s+/ var res=re.exec(src.substr(pos)) if(res!==null){pos +=res[0].length $pos=pos-name.length C=$transition(C,'op','is_not')}else{$pos=pos-name.length C=$transition(C,'op',name)}}else if(name=='not'){ var re=/^\s+in\s+/ var res=re.exec(src.substr(pos)) if(res!==null){pos +=res[0].length $pos=pos-name.length C=$transition(C,'op','not_in')}else{$pos=pos-name.length C=$transition(C,name)}}else{$pos=pos-name.length C=$transition(C,'op',name)}}else if((src.charAt(pos)=='"'||src.charAt(pos)=="'") &&['r','b','u','rb','br'].indexOf(name.toLowerCase())!==-1){string_modifier=name.toLowerCase() name="" continue}else{ if($B.forbidden.indexOf(name)>-1){name='$$'+name} $pos=pos-name.length C=$transition(C,'id',name)} name="" continue}} switch(car){case ' ': case '\t': pos++ break case '.': if(pos-1){j++} C=$transition(C,'float','0'+src.substr(pos,j-pos)) pos=j break} $pos=pos C=$transition(C,'.') pos++ break case '0': var res=hex_pattern.exec(src.substr(pos)) if(res){C=$transition(C,'int',[16,res[1]]) pos +=res[0].length break} var res=octal_pattern.exec(src.substr(pos)) if(res){C=$transition(C,'int',[8,res[1]]) pos +=res[0].length break} var res=binary_pattern.exec(src.substr(pos)) if(res){C=$transition(C,'int',[2,res[1]]) pos +=res[0].length break} if(src.charAt(pos+1).search(/\d/)>-1){ if(parseInt(src.substr(pos))===0){res=int_pattern.exec(src.substr(pos)) $pos=pos C=$transition(C,'int',[10,res[0]]) pos +=res[0].length break}else{$_SyntaxError(C,('invalid literal starting with 0'))}} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': var res=float_pattern1.exec(src.substr(pos)) if(res){$pos=pos if(res[2]!==undefined){C=$transition(C,'imaginary',res[0].substr(0,res[0].length-1))}else{C=$transition(C,'float',res[0])}}else{res=float_pattern2.exec(src.substr(pos)) if(res){$pos=pos if(res[2]!==undefined){C=$transition(C,'imaginary',res[0].substr(0,res[0].length-1))}else{C=$transition(C,'float',res[0])}}else{res=int_pattern.exec(src.substr(pos)) $pos=pos if(res[1]!==undefined){C=$transition(C,'imaginary',res[0].substr(0,res[0].length-1))}else{C=$transition(C,'int',[10,res[0]])}}} pos +=res[0].length break case '\n': lnum++ if(br_stack.length>0){ pos++;}else{ if(current.C.tree.length>0){$pos=pos C=$transition(C,'eol') indent=null new_node=new $Node()}else{new_node.line_num=lnum} pos++} break case '(': case '[': case '{': br_stack +=car br_pos[br_stack.length-1]=[C,pos] $pos=pos C=$transition(C,car) pos++ break case ')': case ']': case '}': if(br_stack==""){$_SyntaxError(C,"Unexpected closing bracket")}else if(br_close[car]!=br_stack.charAt(br_stack.length-1)){$_SyntaxError(C,"Unbalanced bracket")}else{ br_stack=br_stack.substr(0,br_stack.length-1) $pos=pos C=$transition(C,car) pos++} break case '=': if(src.charAt(pos+1)!="="){$pos=pos C=$transition(C,'=') pos++;}else{ $pos=pos C=$transition(C,'op','==') pos+=2} break case ',': case ':': $pos=pos C=$transition(C,car) pos++ break case ';': $transition(C,'eol') if(current.C.tree.length===0){ $pos=pos $_SyntaxError(C,'invalid syntax')} var pos1=pos+1 var ends_line=false while(pos1': case '<': case '-': case '+': case '*': case '/': case '^': case '=': case '|': case '~': case '!': if(car=='-' && src.charAt(pos+1)=='>'){C=$transition(C,'annotation') pos +=2 continue} var op_match="" for(var op_sign in $operators){if(op_sign==src.substr(pos,op_sign.length) && op_sign.length>op_match.length){op_match=op_sign}} $pos=pos if(op_match.length>0){if(op_match in $augmented_assigns){C=$transition(C,'augm_assign',op_match)}else{C=$transition(C,'op',op_match)} pos +=op_match.length}else{$_SyntaxError(C,'invalid character: '+car)} break case '\\': if(src.charAt(pos+1)=='\n'){lnum++ pos+=2 break} case '@': $pos=pos C=$transition(C,car) pos++ break default: $pos=pos;$_SyntaxError(C,'unknown token ['+car+']')}} if(br_stack.length!=0){var br_err=br_pos[0] $pos=br_err[1] $_SyntaxError(br_err[0],["Unbalanced bracket "+br_stack.charAt(br_stack.length-1)])} if(C!==null && $indented.indexOf(C.tree[0].type)>-1){$pos=pos-1 $_SyntaxError(C,'expected an indented block',pos)} return root} $B.py2js=function(src,module,locals_id,parent_block_id,line_info){ var t0=new Date().getTime(),is_comp=false if(typeof src=='object'){is_comp=src.is_comp src=src.src} src=src.replace(/\r\n/gm,'\n') if(src.charAt(src.length-1)!="\n"){src+='\n'} var locals_is_module=Array.isArray(locals_id) if(locals_is_module){locals_id=locals_id[0]} var internal=locals_id.charAt(0)=='$' var local_ns='$locals_'+locals_id.replace(/\./g,'_') var global_ns='$locals_'+module.replace(/\./g,'_') $B.bound[module]=$B.bound[module]||{} $B.bound[module]['__doc__']=true $B.bound[module]['__name__']=true $B.bound[module]['__file__']=true $B.$py_src[locals_id]=$B.$py_src[locals_id]||src var root=$tokenize({src:src,is_comp:is_comp},module,locals_id,parent_block_id,line_info) root.is_comp=is_comp root.transform() var js=['var $B = __BRYTHON__;\n'],pos=1 js[pos++]='eval(__BRYTHON__.InjectBuiltins());\n\n' js[pos]='var ' if(locals_is_module){js[pos]+=local_ns+'=$locals_'+module+', '}else if(!internal){js[pos]+=local_ns+'=$B.imported["'+locals_id+'"] || {}, '} js[pos]+='$locals='+local_ns+';' var offset=0 root.insert(0,$NodeJS(js.join(''))) offset++ var ds_node=new $Node() new $NodeJSCtx(ds_node,local_ns+'["__doc__"]='+(root.doc_string||'None')+';') root.insert(offset++,ds_node) var name_node=new $Node() new $NodeJSCtx(name_node,local_ns+'["__name__"]='+local_ns+'["__name__"] || "'+locals_id+'";') root.insert(offset++,name_node) var file_node=new $Node() new $NodeJSCtx(file_node,local_ns+'["__file__"]="'+$B.$py_module_path[module]+'";None;\n') root.insert(offset++,file_node) if(line_info !==undefined){var line_node=new $Node() new $NodeJSCtx(line_node,local_ns+'.$line="'+line_info+'";None;\n') root.insert(offset++,line_node)} var enter_frame_pos=offset,js='var $top_frame = ["'+locals_id.replace(/\./g,'_')+'", '+ local_ns+', "'+module.replace(/\./g,'_')+'", '+global_ns+ ', "a"]; $B.frames_stack.push($top_frame); var $stack_length = '+ '$B.frames_stack.length;' root.insert(offset++,$NodeJS(js)) var try_node=new $NodeJS('try'),children=root.children.slice(enter_frame_pos+1,root.children.length) root.insert(enter_frame_pos+1,try_node) if(children.length==0){children=[$NodeJS('')]} for(var i=0;i0){$add_profile(root,null,module)} if($B.debug>0){$add_line_num(root,null,module)} var t1=new Date().getTime() if($B.debug>=2){if(module==locals_id){console.log('module '+module+' translated in '+(t1 - t0)+' ms')}} $B.compile_time +=t1-t0 return root} function load_scripts(scripts,run_script,onerror){ if(run_script===undefined){run_script=$B._run_script;} function callback(ev,script){var ok=false,skip=false; if(ev !==null){var req=ev.target if(req.readyState==4){if(req.status==200){ok=true; var script={name:req.module_name,url:req.responseURL,src:req.responseText};}} else{ skip=true;}} else{ ok=true;} if(skip){return;} if(ok){try{ run_script(script)} catch(e){if(onerror===undefined){throw e;} else{onerror(e);}} if(scripts.length>0){load_scripts(scripts)}}else{try{ throw Error("cannot load script "+ req.module_name+' at '+req.responseURL+ ': error '+req.status)} catch(e){if(onerror===undefined){throw e;} else{onerror(e);}}}} var noajax=true while(scripts.length>0 && noajax){var script=scripts.shift() if(script['src']===undefined){ noajax=false; var req=new XMLHttpRequest() req.onreadystatechange=callback req.module_name=script.name req.open('GET',script.url,true) req.send()}else{ callback(null,script) load_scripts(scripts)}}} $B._load_scripts=load_scripts; function run_script(script){ $B.$py_module_path[script.name]=script.url var root,js try{ root=$B.py2js(script.src,script.name,script.name,'__builtins__') js=root.to_js() if($B.debug>1){console.log(js)} eval(js)}catch($err){if($B.debug>1){console.log($err) for(var attr in $err){console.log(attr+' : ',$err[attr])}} if($err.$py_error===undefined){console.log('Javascript error',$err) $err=_b_.RuntimeError($err+'')} var name=$err.__name__ var $trace=_b_.getattr($err,'info')+'\n'+name+': ' if(name=='SyntaxError' ||name=='IndentationError'){$trace +=$err.args[0]}else{$trace +=$err.args} try{_b_.getattr($B.stderr,'write')($trace)}catch(print_exc_err){console.log($trace)} throw $err}finally{root=null js=null $B.clear_ns(script.name)}} $B._run_script=run_script; function brython(options){ if($B.meta_path===undefined){$B.meta_path=[]} $B.$options={} if(options===undefined)options={'debug':0} if(typeof options==='number')options={'debug':options} if(options.debug===undefined){options.debug=0 } $B.debug=options.debug _b_.__debug__=$B.debug>0 $B.compile_time=0 if(options.profile===undefined){options.profile=0} $B.profile=options.profile if(options.static_stdlib_import===undefined){options.static_stdlib_import=true} $B.static_stdlib_import=options.static_stdlib_import if(options.open !==undefined){_b_.open=options.open; console.log("DeprecationWarning: \'open\' option of \'brython\' "+ "function will be deprecated in future versions of Brython.");} $B.$options=options var meta_path=[] var path_hooks=[] if($B.use_VFS){meta_path.push($B.$meta_path[0]) path_hooks.push($B.$path_hooks[0])} if(options.static_stdlib_import!==false){ meta_path.push($B.$meta_path[1]) if($B.path.length>3){$B.path.shift() $B.path.shift()}} meta_path.push($B.$meta_path[2]) $B.meta_path=meta_path path_hooks.push($B.$path_hooks[1]) $B.path_hooks=path_hooks if(options.ipy_id!==undefined){var $elts=[]; for(var $i=0;$i1)console.log(js) eval(js) $B.clear_ns(module_name) root=null js=null}catch($err){root=null js=null console.log($err) if($B.debug>1){console.log($err) for(var attr in $err){console.log(attr+' : ',$err[attr])}} if($err.$py_error===undefined){console.log('Javascript error',$err) $err=_b_.RuntimeError($err+'')} var $trace=_b_.getattr($err,'info')+'\n'+$err.__name__+ ': ' +$err.args try{_b_.getattr($B.stderr,'write')($trace)}catch(print_exc_err){console.log($trace)} throw $err}}else{ var defined_ids={} for(var i=0;i<$elts.length;i++){var elt=$elts[i] if(elt.id){if(defined_ids[elt.id]){throw Error("Brython error : Found 2 scripts with the same id '"+ elt.id+"'")}else{defined_ids[elt.id]=true}}} var scripts=[] for(var $i=0;$i<$elts.length;$i++){var $elt=$elts[$i] if($elt.type=="text/python"||$elt.type==="text/python3"){if($elt.id){module_name=$elt.id} else{if(first_script){module_name='__main__';first_script=false} else{module_name='__main__'+$B.UUID()} while(defined_ids[module_name]!==undefined){module_name='__main__'+$B.UUID()}} $B.scripts.push(module_name) var $src=null if($elt.src){ scripts.push({name:module_name,url:$elt.src})}else{ var $src=($elt.innerHTML ||$elt.textContent) $src=$src.replace(/^\n/,'') $B.$py_module_path[module_name]=$href scripts.push({name: module_name,src: $src,url: $href})}}}} if(options.ipy_id===undefined){$B._load_scripts(scripts)}} $B.$operators=$operators $B.$Node=$Node $B.$NodeJSCtx=$NodeJSCtx $B.brython=brython})(__BRYTHON__) var brython=__BRYTHON__.brython __BRYTHON__.$__new__=function(factory){return function(cls){ var res=factory.apply(null,[]) res.__class__=cls.$dict var init_func=null try{init_func=__BRYTHON__.builtins.getattr(res,'__init__')} catch(err){} if(init_func!==null){var args=[],pos=0 for(var i=1,_len_i=arguments.length;i < _len_i;i++){args[pos++]=arguments[i]} init_func.apply(null,args) res.__initialized__=true} return res}} __BRYTHON__.builtins.object=(function($B){var _b_=$B.builtins var $ObjectDict={ __name__:'object',$native:true} var reverse_func={'__lt__':'__gt__','__gt__':'__lt__','__le__': '__ge__','__ge__': '__le__'} var $ObjectNI=function(name,op){return function(self,other){var klass=$B.get_class(other),other_comp=_b_.getattr(klass,reverse_func[name]) if(other_comp.__func__===$ObjectDict[reverse_func[name]]){throw _b_.TypeError('unorderable types: object() '+op+ ' '+ _b_.str($B.get_class(other).__name__)+'()')}else{return other_comp(other,self)}}} var opnames=['add','sub','mul','truediv','floordiv','mod','pow','lshift','rshift','and','xor','or'] var opsigns=['+','-','*','/','//','%','**','<<','>>','&','^','|'] $ObjectDict.__delattr__=function(self,attr){_b_.getattr(self,attr) delete self[attr]; return _b_.None} $ObjectDict.__dir__=function(self){var objects=[self],pos=1,klass=self.__class__ ||$B.get_class(self) objects[pos++]=klass var mro=klass.__mro__ for(var i=0,_len_i=mro.length;i < _len_i;i++){objects[pos++]=mro[i]} var res=[],pos=0 for(var i=0,_len_i=objects.length;i < _len_i;i++){for(var attr in objects[i]){ if(attr.charAt(0)=='$' && attr.charAt(1)!='$'){ continue} if(!isNaN(parseInt(attr.charAt(0)))){ continue} if(attr=='__mro__'){continue} res[pos++]=attr}} res=_b_.list(_b_.set(res)) _b_.list.$dict.sort(res) return res} $ObjectDict.__eq__=function(self,other){ var _class=$B.get_class(self) if(_class.$native ||_class.__name__=='function'){var _class1=$B.get_class(other) if(!_class1.$native && _class1.__name__ !='function'){return _b_.getattr(other,'__eq__')(self)}} return self===other} $ObjectDict.__format__=function(){var $=$B.args('__format__',2,{self:null,spec:null},['self','spec'],arguments,{},null,null) if($.spec!==''){throw _b_.TypeError("non-empty format string passed to object.__format__")} return _b_.getattr($.self,'__repr__')()} $ObjectDict.__ge__=$ObjectNI('__ge__','>=') $ObjectDict.__getattribute__=function(obj,attr){var klass=obj.__class__ ||$B.get_class(obj) if(attr==='__class__'){return klass.$factory} var res=obj[attr] if(res===undefined){ function check(obj,kl,attr){if(kl.$methods){var method=kl.$methods[attr] if(method!==undefined){return method(obj)}} var v=kl[attr] if(v!==undefined){return v}else if(attr=='__str__' && kl['__repr__']!==undefined){ return kl['__repr__']}} res=check(obj,klass,attr) if(res===undefined){var mro=klass.__mro__ for(var i=0,_len_i=mro.length;i < _len_i;i++){res=check(obj,mro[i],attr) if(res!==undefined){break}}}}else{if(res.__set__===undefined){ return res}} if(res!==undefined){if(res.__class__===_b_.property.$dict){return res.__get__(res,obj,klass)} var get=res.__get__ if(get===undefined && res.__class__){var get=res.__class__.__get__ for(var i=0;i -1){var rop='__r'+opnames[rank]+'__' var func=function(){try{ if($B.get_class(arguments[0])===klass){throw Error('')} return _b_.getattr(arguments[0],rop)(obj)}catch(err){var msg="unsupported operand types for "+ opsigns[rank]+": '"+ klass.__name__+"' and '"+ $B.get_class(arguments[0]).__name__+"'" throw _b_.TypeError(msg)}} func.$infos={__name__ : klass.__name__+'.'+attr} return func}}}} $ObjectDict.__gt__=$ObjectNI('__gt__','>') $ObjectDict.__hash__=function(self){var hash=self.__hashvalue__ if(hash!==undefined){return hash} return self.__hashvalue__=$B.$py_next_hash--;} $ObjectDict.__init__=function(){return _b_.None} $ObjectDict.__le__=$ObjectNI('__le__','<=') $ObjectDict.__lt__=$ObjectNI('__lt__','<') $ObjectDict.__mro__=[] $ObjectDict.__new__=function(cls){if(cls===undefined){throw _b_.TypeError('object.__new__(): not enough arguments')} return{__class__ : cls.$dict}} $ObjectDict.__ne__=function(self,other){return !_b_.getattr(self,'__eq__')(other)} $ObjectDict.__repr__=function(self){if(self===object)return "" if(self.__class__===$B.$factory)return "" if(self.__class__===$B.$type && self.__name__=='classXXX')return "" if(self.__class__.__module__!==undefined){return "<"+self.__class__.__module__+"."+self.__class__.__name__+" object>"}else{return "<"+self.__class__.__name__+" object>"}} $ObjectDict.__setattr__=function(self,attr,val){if(val===undefined){ throw _b_.TypeError("can't set attributes of built-in/extension type 'object'")}else if(self.__class__===$ObjectDict){ if($ObjectDict[attr]===undefined){throw _b_.AttributeError("'object' object has no attribute '"+attr+"'")}else{throw _b_.AttributeError("'object' object attribute '"+attr+"' is read-only")}} self[attr]=val return _b_.None} $ObjectDict.__setattr__.__str__=function(){return 'method object.setattr'} $ObjectDict.__str__=$ObjectDict.__repr__ $ObjectDict.__subclasshook__=function(){return _b_.NotImplemented} function object(){return{__class__:$ObjectDict}} object.$dict=$ObjectDict $ObjectDict.$factory=object object.__repr__=object.__str__=function(){return ""} $B.make_class=function(class_obj){ function A(){var res={__class__:A.$dict} if(class_obj.init){class_obj.init.apply(null,[res].concat(Array.prototype.slice.call(arguments)))} return res} A.__class__=$B.$factory A.$dict={__class__: $B.type,__name__: class_obj.name} A.$dict.__mro__=[object.$dict] return A} return object})(__BRYTHON__) ;(function($B){var _b_=$B.builtins $B.$class_constructor=function(class_name,class_obj,parents,parents_names,kwargs){var cl_dict=_b_.dict(),bases=null for(var attr in class_obj){cl_dict.$string_dict[attr]=class_obj[attr]} if(parents!==undefined){for(var i=0;i0)non_empty[pos++]=seqs[i]} if(non_empty.length==0)break for(var i=0;i-1){not_head[pos++]=s}} if(not_head.length>0){candidate=null} else{break}} if(candidate===null){throw _b_.TypeError("inconsistent hierarchy, no C3 MRO is possible")} mro[mpos++]=candidate for(var i=0;i"} return '' }}(attr) break; case 'classmethod': args=[klass.$factory] __self__=klass __repr__=__str__=function(){var x='' return x} break; case 'staticmethod': args=[] __repr__=__str__=function(attr){return function(){return ''}}(attr) break;} var method=(function(initial_args,attr){return function(){ var local_args=initial_args.slice(),pos=local_args.length for(var i=0;i < arguments.length;i++){local_args[pos++]=arguments[i]} return res.apply(null,local_args)}})(args,attr) method.__class__=$B.$FunctionDict method.__eq__=function(other){return other.__func__===__func__} for(var attr in res){method[attr]=res[attr]} method.__func__=__func__ method.__repr__=__repr__ method.__self__=__self__ method.__str__=__str__ method.__code__={'__class__': $B.CodeDict} method.__doc__=res.__doc__ ||'' method.im_class=klass return method}}} function $instance_creator(klass){ if(klass.$instanciable!==undefined){return function(){throw _b_.TypeError("Can't instantiate abstract "+ "class interface with abstract methods")}} var new_func=klass.__new__ for(var i=0;i"}} member_descriptor.$dict.__mro__=[_b_.object.$dict] function $MethodFactory(){} $MethodFactory.__class__=$B.$factory $B.$MethodDict={__class__:$B.$type,__name__:'method',$factory:$MethodFactory} $B.$MethodDict.__eq__=function(self,other){return self.$infos !==undefined && other.$infos !==undefined && self.$infos.__func__===other.$infos.__func__ && self.$infos.__self__===other.$infos.__self__} $B.$MethodDict.__ne__=function(self,other){return !$B.$MethodDict.__eq__(self,other)} $B.$MethodDict.__getattribute__=function(self,attr){ var infos=self.$infos.__func__.$infos if(infos && infos[attr]){if(attr=='__code__'){var res={__class__:$B.$CodeDict} for(var attr in infos.__code__){res[attr]=infos.__code__[attr]} return res}else{return infos[attr]}}else{return _b_.object.$dict.__getattribute__(self,attr)}} $B.$MethodDict.__mro__=[_b_.object.$dict] $B.$MethodDict.__repr__=$B.$MethodDict.__str__=function(self){var res=''} $MethodFactory.$dict=$B.$MethodDict $B.$InstanceMethodDict={__class__:$B.$type,__name__:'instancemethod',__mro__:[_b_.object.$dict],$factory:$MethodFactory}})(__BRYTHON__) ;(function($B){var _b_=$B.builtins $B.args=function($fname,argcount,slots,var_names,$args,$dobj,extra_pos_args,extra_kw_args){ var has_kw_args=false,nb_pos=$args.length if(nb_pos>0 && $args[nb_pos-1].$nat){has_kw_args=true nb_pos-- var kw_args=$args[nb_pos].kw} if(extra_pos_args){slots[extra_pos_args]=[]; slots[extra_pos_args].__class__=_b_.tuple.$dict} if(extra_kw_args){ slots[extra_kw_args]={__class__:_b_.dict.$dict,$numeric_dict :{},$object_dict :{},$string_dict :{},$str_hash:{},length: 0}} if(nb_pos>argcount){ if(extra_pos_args===null){ msg=$fname+"() takes "+argcount+' positional argument'+ (argcount> 1 ? '' : 's')+ ' but more were given' throw _b_.TypeError(msg)}else{ for(var i=argcount;i0){if(missing.length==1){throw _b_.TypeError($fname+" missing 1 positional argument: "+missing[0])}else{var msg=$fname+" missing "+missing.length+" positional arguments: " msg +=missing.join(' and ') throw _b_.TypeError(msg)}} return slots} $B.wrong_nb_args=function(name,received,expected,positional){if(received1 ? 's' : '')+': '+ positional.slice(received))}else{throw _b_.TypeError(name+'() takes '+expected+' positional argument'+ (expected>1 ? 's' : '')+ ' but more were given')}} $B.get_class=function(obj,from){ if(obj===null){return $B.$NoneDict} var klass=obj.__class__ if(klass===undefined){switch(typeof obj){case 'number': if(obj % 1===0){ obj.__class__=_b_.int.$dict return _b_.int.$dict} obj.__class__=_b_.float.$dict return _b_.float.$dict case 'string': obj.__class__=_b_.str.$dict return _b_.str.$dict case 'boolean': obj.__class__=$B.$BoolDict return $B.$BoolDict case 'function': obj.__class__=$B.$FunctionDict return $B.$FunctionDict case 'object': if(Array.isArray(obj)){if(Object.getPrototypeOf(obj)===Array.prototype){obj.__class__=_b_.list.$dict return _b_.list.$dict}}else if(obj.constructor===Number)return _b_.float.$dict break}} return klass} $B.$mkdict=function(glob,loc){var res={} for(var arg in glob)res[arg]=glob[arg] for(var arg in loc)res[arg]=loc[arg] return res} $B.$list_comp=function(items){ var ix=$B.UUID() var py="x"+ix+"=[]\n",indent=0 for(var i=1,len=items.length;i < len;i++){py +=' '.repeat(indent) var item=items[i] item=item.replace(/\s*$/,'').replace(/\s+/g,' ') py +=item+':\n' indent +=4} py +=' '.repeat(indent) py +='x'+ix+'.append('+items[0]+')\n' return[py,ix]} $B.$dict_comp=function(module_name,parent_block_id,items,line_num){ var ix=$B.UUID(),res='res'+ix,py=res+"={}\n", indent=0 for(var i=1,len=items.length;i=0;i--){res=$B.frames_stack[i][1][name] if(res!==undefined){return res} res=$B.frames_stack[i][3][name] if(res!==undefined){return res}} throw _b_.NameError("free variable '"+name+ "' referenced before assignment in enclosing scope")} $B.$JS2Py=function(src){if(typeof src==='number'){if(src%1===0)return src return _b_.float(src)} if(src===null||src===undefined)return _b_.None var klass=$B.get_class(src) if(klass!==undefined){if(klass===_b_.list.$dict){for(var i=0,_len_i=src.length;i< _len_i;i++)src[i]=$B.$JS2Py(src[i])}else if(klass===$B.JSObject.$dict){src=src.js}else{return src}} if(typeof src=="object"){if($B.$isNode(src))return $B.DOMNode(src) if($B.$isEvent(src))return $B.$DOMEvent(src) if($B.$isNodeList(src))return $B.DOMNode(src) if(Array.isArray(src)&&Object.getPrototypeOf(src)===Array.prototype){var res=[],pos=0 for(var i=0,_len_i=src.length;i<_len_i;i++)res[pos++]=$B.$JS2Py(src[i]) return res}} return $B.JSObject(src)} $B.list_key=function(obj,key){key=$B.$GetInt(key) if(key<0){key +=obj.length} var res=obj[key] if(res===undefined){throw _b_.IndexError("list index out of range")} return res} $B.list_slice=function(obj,start,stop){if(start===null){start=0} else{start=$B.$GetInt(start) if(start<0){start=Math.max(0,start+obj.length)}} if(stop===null){return obj.slice(start)} stop=$B.$GetInt(stop) if(stop<0){stop=Math.max(0,stop+obj.length)} return obj.slice(start,stop)} $B.list_slice_step=function(obj,start,stop,step){if(step===null||step==1){return $B.list_slice(obj,start,stop)} if(step==0){throw _b_.ValueError("slice step cannot be zero")} step=$B.$GetInt(step) if(start===null){start=step >=0 ? 0 : obj.length-1} else{start=$B.$GetInt(start) if(start<0){start=Math.min(0,start+obj.length)}} if(stop===null){stop=step >=0 ? obj.length : -1} else{stop=$B.$GetInt(stop) if(stop<0){stop=Math.max(0,stop+obj.length)}} var res=[] if(step>0){for(var i=start;istop;i+=step){res.push(obj[i])}} return res} function index_error(obj){var type=typeof obj=='string' ? 'string' : 'list' throw _b_.IndexError(type+" index out of range")} $B.$getitem=function(obj,item){if(typeof item=='number'){if(Array.isArray(obj)||typeof obj=='string'){item=item >=0 ? item : obj.length+item if(obj[item]!==undefined){return obj[item]} else{index_error(obj)}}} try{item=$B.$GetInt(item)}catch(err){} if((Array.isArray(obj)||typeof obj=='string') && typeof item=='number'){item=item >=0 ? item : obj.length+item if(obj[item]!==undefined){return obj[item]} else{index_error(obj)}} return _b_.getattr(obj,'__getitem__')(item)} $B.set_list_key=function(obj,key,value){try{key=$B.$GetInt(key)} catch(err){if(_b_.isinstance(key,_b_.slice)){var s=_b_.slice.$dict.$conv_for_seq(key,obj.length) return $B.set_list_slice_step(obj,s.start,s.stop,s.step,value)}} if(key<0){key+=obj.length} if(obj[key]===undefined){console.log(obj,key) throw _b_.IndexError('list assignment index out of range')} obj[key]=value} $B.set_list_slice=function(obj,start,stop,value){if(start===null){start=0} else{start=$B.$GetInt(start) if(start<0){start=Math.max(0,start+obj.length)}} if(stop===null){stop=obj.length} stop=$B.$GetInt(stop) if(stop<0){stop=Math.max(0,stop+obj.length)} var res=_b_.list(value) obj.splice.apply(obj,[start,stop-start].concat(res))} $B.set_list_slice_step=function(obj,start,stop,step,value){if(step===null||step==1){return $B.set_list_slice(obj,start,stop,value)} if(step==0){throw _b_.ValueError("slice step cannot be zero")} step=$B.$GetInt(step) if(start===null){start=step>0 ? 0 : obj.length-1} else{start=$B.$GetInt(start) if(start<0){start=Math.min(0,start+obj.length)}} if(stop===null){stop=step>0 ? obj.length : -1} else{stop=$B.$GetInt(stop) if(stop<0){stop=Math.max(0,stop+obj.length)}} var repl=_b_.list(value),j=0,test,nb=0 if(step>0){test=function(i){return istop}} for(var i=start;test(i);i+=step){nb++} if(nb!=repl.length){throw _b_.ValueError('attempt to assign sequence of size '+ repl.length+' to extended slice of size '+nb)} for(var i=start;test(i);i+=step){obj[i]=repl[j] j++}} $B.$setitem=function(obj,item,value){if(Array.isArray(obj)&& typeof item=='number' && !_b_.isinstance(obj,_b_.tuple)){if(item<0){item+=obj.length} if(obj[item]===undefined){throw _b_.IndexError("list assignment index out of range")} obj[item]=value return}else if(obj.__class__===_b_.dict.$dict){obj.__class__.__setitem__(obj,item,value) return} _b_.getattr(obj,'__setitem__')(item,value)} $B.augm_item_add=function(obj,item,incr){if(Array.isArray(obj)&& typeof item=="number" && obj[item]!==undefined){if(Array.isArray(obj[item])&& Array.isArray(incr)){obj[item]=obj[item].concat(incr) return}else if(typeof obj[item]=='string' && typeof incr=='string'){obj[item]+=incr return}} var ga=_b_.getattr try{var augm_func=ga(ga(obj,'__getitem__')(item),'__iadd__')}catch(err){ga(obj,'__setitem__')(item,ga(ga(obj,'__getitem__')(item),'__add__')(incr)) return} augm_func(incr)} var augm_item_src=''+$B.augm_item_add var augm_ops=[['-=','sub'],['*=','mul']] for(var i=0,_len_i=augm_ops.length;i < _len_i;i++){var augm_code=augm_item_src.replace(/add/g,augm_ops[i][1]) augm_code=augm_code.replace(/\+=/g,augm_ops[i][0]) eval('$B.augm_item_'+augm_ops[i][1]+'='+augm_code)} $B.extend=function(fname,arg){ for(var i=2;i"},counter:-1} res.__str__=res.toString=res.__repr__ return res} $B.$iterator_class=function(name){var res={__class__:$B.$type,__name__:name,} res.__mro__=[_b_.object.$dict] function as_array(s){var _a=[],pos=0 var _it=_b_.iter(s) while(1){try{ _a[pos++]=_b_.next(_it)}catch(err){if(err.__name__=='StopIteration'){break}}} return _a} function as_list(s){return _b_.list(as_array(s))} function as_set(s){return _b_.set(as_array(s))} res.__eq__=function(self,other){if(_b_.isinstance(other,[_b_.tuple,_b_.set,_b_.list])){return _b_.getattr(as_list(self),'__eq__')(other)} if(_b_.hasattr(other,'__iter__')){return _b_.getattr(as_list(self),'__eq__')(as_list(other))} _b_.NotImplementedError("__eq__ not implemented yet for list and " + _b_.type(other))} var _ops=['eq','ne'] var _f=res.__eq__+'' for(var i=0;i < _ops.length;i++){var _op='__'+_ops[i]+'__' eval('res.'+_op+'='+_f.replace(new RegExp('__eq__','g'),_op))} res.__or__=function(self,other){if(_b_.isinstance(other,[_b_.tuple,_b_.set,_b_.list])){return _b_.getattr(as_set(self),'__or__')(other)} if(_b_.hasattr(other,'__iter__')){return _b_.getattr(as_set(self),'__or__')(as_set(other))} _b_.NotImplementedError("__or__ not implemented yet for set and " + _b_.type(other))} var _ops=['sub','and','xor','gt','ge','lt','le'] var _f=res.__or__+'' for(var i=0;i < _ops.length;i++){var _op='__'+_ops[i]+'__' eval('res.'+_op+'='+_f.replace(new RegExp('__or__','g'),_op))} res.$factory={__class__:$B.$factory,$dict:res} return res} $B.$CodeDict={__class__:$B.$type,__name__:'code'} $B.$CodeDict.__mro__=[_b_.object.$dict] function _code(){} _code.__class__=$B.$factory _code.$dict=$B.$CodeDict $B.$CodeDict.$factory=_code function $err(op,klass,other){var msg="unsupported operand type(s) for "+op msg +=": '"+klass.__name__+"' and '"+$B.get_class(other).__name__+"'" throw _b_.TypeError(msg)} var ropnames=['add','sub','mul','truediv','floordiv','mod','pow','lshift','rshift','and','xor','or'] var ropsigns=['+','-','*','/','//','%','**','<<','>>','&','^','|'] $B.make_rmethods=function(klass){for(var j=0,_len_j=ropnames.length;j < _len_j;j++){if(klass['__'+ropnames[j]+'__']===undefined){ klass['__'+ropnames[j]+'__']=(function(name,sign){return function(self,other){try{return _b_.getattr(other,'__r'+name+'__')(self)} catch(err){$err(sign,klass,other)}}})(ropnames[j],ropsigns[j])}}} $B.set_func_names=function(klass){var name=klass.__name__ for(var attr in klass){if(typeof klass[attr]=='function'){klass[attr].$infos={__name__ : name+'.'+attr}}}} $B.UUID=function(){return $B.$py_UUID++} $B.InjectBuiltins=function(){var _str=["var _b_=$B.builtins"],pos=1 for(var $b in $B.builtins)_str[pos++]='var ' + $b +'=_b_["'+$b+'"]' return _str.join(';')} $B.$GetInt=function(value){ if(typeof value=="number"||value.constructor===Number){return value} else if(typeof value==="boolean"){return value ? 1 : 0} else if(_b_.isinstance(value,_b_.int)){return value} else if(_b_.isinstance(value,_b_.float)){return value.valueOf()} if(value.__class__!==$B.$factory){try{var v=_b_.getattr(value,'__int__')();return v}catch(e){} try{var v=_b_.getattr(value,'__index__')();return v}catch(e){}} throw _b_.TypeError("'"+$B.get_class(value).__name__+ "' object cannot be interpreted as an integer")} $B.PyNumber_Index=function(item){switch(typeof item){case "boolean": return item ? 1 : 0 case "number": return item case "object": if(item.__class__===$B.LongInt.$dict){return item} var method=_b_.getattr(item,'__index__',null) if(method!==null){method=typeof method=='function' ? method : _b_.getattr(method,'__call__') return $B.int_or_bool(method)} default: throw _b_.TypeError("'"+$B.get_class(item).__name__+ "' object cannot be interpreted as an integer")}} $B.int_or_bool=function(v){switch(typeof v){case "boolean": return v ? 1 : 0 case "number": return v case "object": if(v.__class__===$B.LongInt.$dict){return v} else{throw _b_.TypeError("'"+$B.get_class(v).__name__+ "' object cannot be interpreted as an integer")} default: throw _b_.TypeError("'"+$B.get_class(v).__name__+ "' object cannot be interpreted as an integer")}} $B.int_value=function(v){ try{return $B.int_or_bool(v)} catch(err){if(_b_.isinstance(v,_b_.complex)&& v.imag==0){return $B.int_or_bool(v.real)}else if(isinstance(v,_b_.float)&& v==Math.floor(v)){return Math.floor(v)}else{throw _b_.TypeError("'"+$B.get_class(v).__name__+ "' object cannot be interpreted as an integer")}}} $B.enter_frame=function(frame){ $B.frames_stack.push(frame)} $B.leave_frame=function(arg){ if($B.profile > 0)$B.$profile.return(); if($B.frames_stack.length==0){console.log('empty stack');return} $B.frames_stack.pop()} $B.memory=function(){var info=[] for(var attr in __BRYTHON__){var obj=__BRYTHON__[attr] if(obj===null){continue} if(Array.isArray(obj)){info.push([obj.length,attr])} else if(typeof obj=='object'){info.push([Object.keys(obj).length,attr])}} info.sort(function(x,y){return x[0]-y[0]}) for(var i=0,len=info.length;i 1 && active){var ctime=new Date(); var h=_fhash(module,fname,line) if(!(h in call_times)){call_times[h]=[];} if(call_stack.length > 0){in_func=call_stack[call_stack.length-1]; func_stack=call_times[in_func] inner_most_call=func_stack[func_stack.length-1]; inner_most_call[_CUMULATED]+=(ctime-inner_most_call[_LAST_RESUMED]) caller=caller+":"+in_func;} call_times[h].push([ctime,caller,0,ctime]) call_stack.push(h)}},'return':function(){if($B.profile > 1 && active){var h=call_stack.pop() if(h in call_times){var t_end=new Date(); var data=call_times[h].pop(); t_start=data[_START] caller=data[_CALLER] t_duration=t_end-t_start; t_in_func=data[_CUMULATED]+(t_end-data[_LAST_RESUMED]); if(!(h in profile.call_times)){profile.call_times[h]=0; profile.call_times_proper[h]=0; profile.call_counts[h]=0; profile.call_counts_norec[h]=0; profile.callers[h]={};} profile.call_times[h]+=t_duration; profile.call_times_proper[h]+=t_in_func; profile.call_counts[h]+=1; if(!(caller in profile.callers[h])){profile.callers[h][caller]=[0,0,0,0]} if(! _is_recursive(h)){profile.call_counts_norec[h]+=1; profile.callers[h][caller][3]++;} profile.callers[h][caller][0]+=t_duration; profile.callers[h][caller][1]+=t_in_func; profile.callers[h][caller][2]++; if(call_stack.length > 0){ in_func=call_stack[call_stack.length-1]; func_stack=call_times[in_func]; inner_most_call=func_stack[func_stack.length-1]; inner_most_call[_LAST_RESUMED]=new Date();}}}},'count':function(module,line){if(active){var h=_hash(module,line); if(!(h in profile.line_counts)){profile.line_counts[h]=0;} profile.line_counts[h]++;}},'pause':function(){if(active){elapsed=(new Date())-profile_start cumulated +=elapsed active=false paused=true}},'start':function(){if($B.profile > 0){if(! paused )$B.$profile.clear(); else{paused=false;} active=true profile_start=new Date()}},'elapsed': function(){if(active)return cumulated +(new Date())-profile_start else return cumulated;},'stop':function(){if(active ||paused){profile.profile_duration=((new Date())-profile_start)+cumulated active=false paused=false}},'clear':function(){cumulated=0; profile.line_counts={}; profile.call_times={}; profile.call_times_proper={}; profile.call_counts={}; profile.call_counts_norec={}; profile.callers={}; active=false; paused=false;},'status':function(){if($B.profile <=0)return "Disabled"; if(active)return "Collecting data: active"; else if(paused)return "Collecting data: paused"; else return "Stopped";},} return $profile;})($B.$profile_data) var min_int=Math.pow(-2,53),max_int=Math.pow(2,53)-1 $B.is_safe_int=function(){for(var i=0;imax_int){return false}} return true} $B.add=function(x,y){var z=(typeof x!='number' ||typeof y!='number')? new Number(x+y): x+y if(x>min_int && xmin_int && ymin_int && zmin_int && xmin_int && ymin_int && zmin_int && xmin_int && ymin_int && xmin_int && ymin_int && zmin_int && xmin_int && ymin_int && zmin_int && xmin_int && ymin_int && z=y} else if(typeof x=='number' && typeof y!='number'){return !y.pos} else if(typeof x !='number' && typeof y=='number'){return x.pos===true} else{return $B.LongInt.$dict.__ge__(x,y)}} $B.gt=function(x,y){if(typeof x=='number' && typeof y=='number'){return x>y} else if(typeof x=='number' && typeof y!='number'){return !y.pos} else if(typeof x !='number' && typeof y=='number'){return x.pos===true} else{return $B.LongInt.$dict.__gt__(x,y)}} $B.is_none=function(o){return o===undefined ||o==_b_.None;} $B.imports=function(){ var w=window.open('','','width="50%",height=400,resizeable,scrollbars'); w.document.write("Currently imported modules. Copy and paste in file "+ ".bundle-include in your application folder, then run "+ "python -m brython --modules to generate a new version "+ "of brython_modules.js

") w.document.write("") w.document.close();} $B.compiled_imports=function(){ if(!$B.use_VFS){console.log('only works with VFS') return} var res={} for(var attr in $B.imported){var info=$B.VFS[attr] if(info!==undefined){var lang=info[0],src=info[1] if(lang=='.js'){res[attr]=['.js',src]}else{res[attr]=['.js',$B.py2js(src,attr,attr,'__builtins__').to_js()] if(info[2]!==undefined){res[attr].push(info[2])}}}} var w=window.open('','','width="80%",height=400,resizeable,scrollbars') w.document.write("Currently imported modules. Copy and paste in file "+ "brython_modules.js in your application folder

"+ "") w.document.close();}})(__BRYTHON__) if(!Array.indexOf){Array.prototype.indexOf=function(obj){for(var i=0,_len_i=this.length;i < _len_i;i++)if(this[i]==obj)return i return -1}} if(!String.prototype.repeat){String.prototype.repeat=function(count){if(count < 1)return ''; var result='',pattern=this.valueOf() while(count > 1){if(count & 1)result +=pattern count >>=1,pattern +=pattern} return result + pattern;}} ;(function($B){eval($B.InjectBuiltins()) _b_.__debug__=false var $ObjectDict=_b_.object.$dict,odga=$ObjectDict.__getattribute__ $B.$comps={'>':'gt','>=':'ge','<':'lt','<=':'le'} $B.$inv_comps={'>': 'lt','>=': 'le','<': 'gt','<=': 'gt'} function abs(obj){if(isinstance(obj,_b_.int))return _b_.int(Math.abs(obj)); if(isinstance(obj,_b_.float))return _b_.float(Math.abs(obj)); if(hasattr(obj,'__abs__')){return getattr(obj,'__abs__')()}; throw _b_.TypeError("Bad operand type for abs(): '"+$B.get_class(obj)+"'")} function all(obj){var iterable=iter(obj) while(1){try{var elt=next(iterable) if(!bool(elt))return false}catch(err){return true}}} function any(obj){var iterable=iter(obj) while(1){try{var elt=next(iterable) if(bool(elt))return true}catch(err){return false}}} function ascii(obj){var res=repr(obj),res1='',cp for(var i=0;i=0)return prefix + value.toString(base); return '-' + prefix +(-value).toString(base);} function bin(obj){if(isinstance(obj,_b_.int)){return $builtin_base_convert_helper(obj,2)} return getattr(obj,'__index__')()} function bool(obj){ if(obj===null ||obj===undefined )return false switch(typeof obj){case 'boolean': return obj case 'number': case 'string': if(obj)return true return false default: try{return getattr(obj,'__bool__')()} catch(err){try{return getattr(obj,'__len__')()>0} catch(err){return true}}}} function callable(obj){return hasattr(obj,'__call__')} function chr(i){if(i < 0 ||i > 1114111)_b_.ValueError('Outside valid range') return String.fromCharCode(i)} function classmethod(func){func.$type='classmethod' return func} classmethod.__class__=$B.$factory classmethod.$dict={__class__:$B.$type,__name__:'classmethod',$factory: classmethod} classmethod.$dict.__mro__=[$ObjectDict] $B.$CodeObjectDict={__class__:$B.$type,__name__:'code',__repr__:function(self){return ''},} $B.$CodeObjectDict.__str__=$B.$CodeObjectDict.__repr__ $B.$CodeObjectDict.__mro__=[$ObjectDict] function compile(source,filename,mode){var $=$B.args('compile',6,{source:null,filename:null,mode:null,flags:null,dont_inherit:null,optimize:null},['source','filename','mode','flags','dont_inherit','optimize'],arguments,{flags:0,dont_inherit:false,optimize:-1},null,null) var module_name='$exec_' + $B.UUID() $B.clear_ns(module_name) $.__class__=$B.$CodeObjectDict $.co_flags=$.flags return $} compile.__class__=$B.factory $B.$CodeObjectDict.$factory=compile compile.$dict=$B.$CodeObjectDict var __debug__=$B.debug>0 function delattr(obj,attr){ var klass=$B.get_class(obj) var res=obj[attr] if(res===undefined){res=klass[attr] if(res===undefined){var mro=klass.__mro__ for(var i=0;i"},__str__:function(){return ""},counter:_start-1} for(var attr in res){if(typeof res[attr]==='function' && attr!=="__class__"){res[attr].__str__=(function(x){return function(){return ""}})(attr)}} return res} enumerate.__class__=$B.$factory enumerate.$dict=$EnumerateDict $EnumerateDict.$factory=enumerate function $eval(src,_globals,_locals){var current_frame=$B.frames_stack[$B.frames_stack.length-1] if(current_frame!==undefined){var current_locals_id=current_frame[0].replace(/\./,'_'),current_globals_id=current_frame[2].replace(/\./,'_')} var is_exec=arguments[3]=='exec',leave=false if(src.__class__===$B.$CodeObjectDict){src=src.source} var globals_id='$exec_'+$B.UUID(),locals_id,parent_block_id if(_locals===_globals ||_locals===undefined){locals_id=globals_id}else{locals_id='$exec_'+$B.UUID()} eval('var $locals_'+globals_id+' = {}\nvar $locals_'+locals_id+' = {}') if(_globals===undefined){var gobj=current_frame[3],ex='' parent_block_id=current_globals_id ex +='var $locals_'+current_globals_id+'=gobj;' eval(ex)}else{$B.bound[globals_id]={} var items=_b_.dict.$dict.items(_globals),item while(1){try{var item=next(items) eval('$locals_'+globals_id+'["'+item[0]+'"] = item[1]') $B.bound[globals_id][item[0]]=true}catch(err){break}} parent_block_id='__builtins__'} if(_locals===undefined){if(_globals!==undefined){eval('var $locals_'+locals_id+' = $locals_'+globals_id)}else{var lobj=current_frame[1],ex='' for(var attr in current_frame[1]){ex +='$locals_'+locals_id+'["'+attr+ '"] = current_frame[1]["'+attr+'"];'} eval(ex)}}else{var items=_b_.dict.$dict.items(_locals),item while(1){try{var item=next(items) eval('$locals_'+locals_id+'["'+item[0]+'"] = item[1]')}catch(err){break}}} var root=$B.py2js(src,globals_id,locals_id,parent_block_id),leave_frame=true,js,gns,lns try{ if(!is_exec){ var try_node=root.children[root.children.length-2],instr=try_node.children[try_node.children.length-2] var type=instr.C.tree[0].type switch(type){case 'expr': case 'list_or_tuple': case 'op': case 'ternary': var children=try_node.children root.children.splice(root.children.length-2,2) for(var i=0;i',1,1,src)}} js=root.to_js() var res=eval(js) gns=eval('$locals_'+globals_id) if(_locals!==undefined){lns=eval('$locals_'+locals_id) var setitem=getattr(_locals,'__setitem__') for(var attr in lns){if(attr.charAt(0)=='$'){continue} setitem(attr,lns[attr])}}else{for(var attr in lns){current_frame[1][attr]=lns[attr]}} if(_globals!==undefined){ var setitem=getattr(_globals,'__setitem__') for(var attr in gns){if(attr.charAt(0)=='$'){continue} setitem(attr,gns[attr])}}else{for(var attr in gns){current_frame[3][attr]=gns[attr]}} if(res===undefined)return _b_.None return res}catch(err){if(err.$py_error===undefined){throw $B.exception(err)} throw err}finally{root=null js=null gns=null lns=null $B.clear_ns(globals_id) $B.clear_ns(locals_id) if(!is_exec && leave_frame){ $B.frames_stack.pop()}}} $eval.$is_func=true function exec(src,globals,locals){return $eval(src,globals,locals,'exec')||_b_.None} exec.$is_func=true var $FilterDict={__class__:$B.$type,__name__:'filter'} $FilterDict.__iter__=function(self){return self} $FilterDict.__repr__=$FilterDict.__str__=function(){return ""},$FilterDict.__mro__=[$ObjectDict] function filter(){if(arguments.length!=2){throw _b_.TypeError( "filter expected 2 arguments, got "+arguments.length)} var func=arguments[0],iterable=iter(arguments[1]) if(func===_b_.None)func=bool var __next__=function(){while(true){var _item=next(iterable) if(func(_item)){return _item}}} return{ __class__: $FilterDict,__next__: __next__}} function format(value,format_spec){if(hasattr(value,'__format__'))return getattr(value,'__format__')(format_spec) throw _b_.NotImplementedError("__format__ is not implemented for object '" + _b_.str(value)+ "'")} function attr_error(attr,cname){var msg="bad operand type for unary #: '"+cname+"'" switch(attr){case '__neg__': throw _b_.TypeError(msg.replace('#','-')) case '__pos__': throw _b_.TypeError(msg.replace('#','+')) case '__invert__': throw _b_.TypeError(msg.replace('#','~')) case '__call__': throw _b_.TypeError("'"+cname+"'"+' object is not callable') default: throw _b_.AttributeError("'"+cname+"' object has no attribute '"+attr+"'")}} $B.show_getattr=function(){var items=[] for(var attr in $B.counter){items.push([$B.counter[attr],attr])} items.sort(function(x,y){return x[0]>y[0]? 1 : x[0]==y[0]? 0 : -1}) items.reverse() for(var i=0;i<10;i++){console.log(items[i])}} function getattr(obj,attr,_default){ var klass=obj.__class__ if(klass===undefined){ if(typeof obj=='string'){klass=_b_.str.$dict} else if(typeof obj=='number'){klass=obj % 1==0 ? _b_.int.$dict : _b_.float.$dict}else if(obj instanceof Number){klass=_b_.float.$dict}else{klass=$B.get_class(obj)}} if(klass===undefined){ if(obj[attr]!==undefined){if(typeof obj[attr]=="function"){return function(){ return obj[attr].apply(obj,arguments)}}else{return $B.$JS2Py(obj[attr])}} if(_default!==undefined)return _default throw _b_.AttributeError('object has no attribute '+attr)} switch(attr){case '__call__': if(typeof obj=='function'){return obj}else if(klass===$B.JSObject.$dict && typeof obj.js=='function'){return function(){ var args=[] for(var i=0;i'} return method} return klass[attr]} var is_class=klass.is_class,mro,attr_func if(is_class){attr_func=$B.$type.__getattribute__ if(obj.$dict===undefined){console.log('obj '+obj+' $dict undefined')} obj=obj.$dict}else{attr_func=klass.__getattribute__ if(attr_func===undefined){var mro=klass.__mro__ for(var i=0,len=mro.length;i-1){return true}} var hook=getattr(classinfo,'__subclasscheck__',null) if(hook!==null){return hook(klass)} return false} var iterator_class=$B.make_class({name:'iterator',init:function(self,getitem,len){self.getitem=getitem self.len=len self.counter=-1}}) iterator_class.$dict.__next__=function(self){self.counter++ if(self.len!==null && self.counter==self.len){throw _b_.StopIteration('')} try{return self.getitem(self.counter)} catch(err){throw _b_.StopIteration('')}} function iter(obj){try{var _iter=getattr(obj,'__iter__')} catch(err){var gi=getattr(obj,'__getitem__',null),ln=getattr(obj,'__len__',null) if(gi!==null){if(ln!==null){var len=getattr(ln,'__call__')() return iterator_class(gi,len)}else{return iterator_class(gi,null)}} throw _b_.TypeError("'"+$B.get_class(obj).__name__+"' object is not iterable")} var res=_iter() try{getattr(res,'__next__')} catch(err){if(isinstance(err,_b_.AttributeError)){throw _b_.TypeError( "iter() returned non-iterator of type '"+ $B.get_class(res).__name__+"'")}} return res} function len(obj){try{return getattr(obj,'__len__')()} catch(err){throw _b_.TypeError("object of type '"+$B.get_class(obj).__name__+ "' has no len()")}} function locals(){ var locals_obj=$B.last($B.frames_stack)[1] return $B.obj_dict(locals_obj)} var $MapDict={__class__:$B.$type,__name__:'map'} $MapDict.__mro__=[$ObjectDict] $MapDict.__iter__=function(self){return self} function map(){var func=getattr(arguments[0],'__call__') var iter_args=[],pos=0 for(var i=1;i"},__str__:function(){return ""},__next__: __next__} return obj} function $extreme(args,op){ var $op_name='min' if(op==='__gt__')$op_name="max" if(args.length==0){throw _b_.TypeError($op_name+" expected 1 arguments, got 0")} var last_arg=args[args.length-1],nb_args=args.length,has_default=false,func=false if(last_arg.$nat=='kw'){nb_args-- last_arg=last_arg.kw for(var attr in last_arg){switch(attr){case 'key': func=last_arg[attr] break case '$$default': var default_value=last_arg[attr] has_default=true break default: throw _b_.TypeError("'"+attr+"' is an invalid keyword argument for this function")}}} if(!func){func=function(x){return x}} if(nb_args==0){throw _b_.TypeError($op_name+" expected 1 arguments, got 0")}else if(nb_args==1){ var $iter=iter(args[0]),res=null while(true){try{var x=next($iter) if(res===null ||bool(getattr(func(x),op)(func(res)))){res=x}}catch(err){if(err.__name__=="StopIteration"){if(res===null){if(has_default){return default_value} else{throw _b_.ValueError($op_name+"() arg is an empty sequence")}}else{return res}} throw err}}}else{if(has_default){throw _b_.TypeError("Cannot specify a default for "+$op_name+"() with multiple positional arguments")} var res=null for(var i=0;i'}} p.__get__=function(self,obj,objtype){if(obj===undefined)return self if(self.fget===undefined)throw _b_.AttributeError("unreadable attribute") return getattr(self.fget,'__call__')(obj)} if(fset!==undefined){p.__set__=function(self,obj,value){if(self.fset===undefined)throw _b_.AttributeError("can't set attribute") getattr(self.fset,'__call__')(obj,value)}} p.__delete__=fdel; p.getter=function(fget){return property(fget,p.fset,p.fdel,p.__doc__)} p.setter=function(fset){return property(p.fget,fset,p.fdel,p.__doc__)} p.deleter=function(fdel){return property(p.fget,p.fset,fdel,p.__doc__)} return p} property.__class__=$B.$factory property.$dict=$PropertyDict $PropertyDict.$factory=property function repr(obj){if(obj.__class__===$B.$factory){ var func=$B.$type.__getattribute__(obj.$dict.__class__,'__repr__') return func(obj)} var func=getattr(obj,'__repr__') if(func!==undefined){return func()} throw _b_.AttributeError("object has no attribute __repr__")} var $ReversedDict={__class__:$B.$type,__name__:'reversed'} $ReversedDict.__mro__=[$ObjectDict] $ReversedDict.__iter__=function(self){return self} $ReversedDict.__next__=function(self){self.$counter-- if(self.$counter<0)throw _b_.StopIteration('') return self.getter(self.$counter)} function reversed(seq){ try{return getattr(seq,'__reversed__')()} catch(err){if(err.__name__!='AttributeError'){throw err}} try{var res={__class__:$ReversedDict,$counter : getattr(seq,'__len__')(),getter:getattr(seq,'__getitem__')} return res}catch(err){throw _b_.TypeError("argument to reversed() must be a sequence")}} reversed.__class__=$B.$factory reversed.$dict=$ReversedDict $ReversedDict.$factory=reversed function round(arg,n){if(!isinstance(arg,[_b_.int,_b_.float])){if(!hasattr(arg,'__round__')) throw _b_.TypeError("type "+arg.__class__+" doesn't define __round__ method") if(n===undefined)return getattr(arg,'__round__')() else return getattr(arg,'__round__')(n)} if(isinstance(arg,_b_.float)&&(arg.value===Infinity ||arg.value===-Infinity)){throw _b_.OverflowError("cannot convert float infinity to integer")} if(n===undefined){var floor=Math.floor(arg) var diff=Math.abs(arg-floor) if(diff==0.5){if(floor % 2){return Math.round(arg)}else{return Math.floor(arg)}}else{return _b_.int(Math.round(arg))}} if(!isinstance(n,_b_.int)){throw _b_.TypeError( "'"+n.__class__+"' object cannot be interpreted as an integer")} var mult=Math.pow(10,n) if(isinstance(arg,_b_.float)){return _b_.float(_b_.int.$dict.__truediv__(Number(Math.round(arg.valueOf()*mult)),mult))}else{ return _b_.int(_b_.int.$dict.__truediv__(Number(Math.round(arg.valueOf()*mult)),mult))}} function setattr(obj,attr,value){if(!(typeof attr=='string')){throw _b_.TypeError("setattr(): attribute name must be string")} switch(attr){case 'alert': case 'case': case 'catch': case 'constructor': case 'Date': case 'delete': case 'default': case 'document': case 'Error': case 'history': case 'function': case 'location': case 'Math': case 'new': case 'Number': case 'RegExp': case 'this': case 'throw': case 'var': case 'super': case 'window': attr='$$'+attr break case '__class__': obj.__class__=value.$dict; return None} if(obj.__class__===$B.$factory){ if(obj.$dict.$methods && typeof value=='function' && value.__class__!==$B.$factory && value.__class__!==$B.$MethodDict ){ obj.$dict.$methods[attr]=$B.make_method(attr,obj.$dict,value,value) return None}else{obj.$dict[attr]=value;return None}} var res=obj[attr],klass=obj.__class__ ||$B.get_class(obj) if(res===undefined && klass){res=klass[attr] if(res===undefined){var mro=klass.__mro__,_len=mro.length for(var i=0;i<_len;i++){res=mro[i][attr] if(res!==undefined)break}}} if(res!==undefined){ if(res.__set__!==undefined){res.__set__(res,obj,value);return None} var rcls=res.__class__,__set1__ if(rcls!==undefined){var __set1__=rcls.__set__ if(__set1__===undefined){var mro=rcls.__mro__ for(var i=0,_len=mro.length;i<_len;i++){__set1__=mro[i].__set__ if(__set1__){break}}}} if(__set1__!==undefined){var __set__=getattr(res,'__set__',null) if(__set__ &&(typeof __set__=='function')){__set__.apply(res,[obj,value]);return None}}} if(klass && klass.$slots && klass.$slots[attr]===undefined){throw _b_.AttributeError("'"+klass.__name__+"' object has no attribute'"+ attr+"'")} var _setattr=false if(klass!==undefined){_setattr=klass.__setattr__ if(_setattr===undefined){var mro=klass.__mro__ for(var i=0,_len=mro.length;i<_len;i++){_setattr=mro[i].__setattr__ if(_setattr){break}}}} if(!_setattr){obj[attr]=value}else{_setattr(obj,attr,value)} return None} function sorted(){var $=$B.args('sorted',1,{iterable:null},['iterable'],arguments,{},null,'kw') var _list=_b_.list(iter($.iterable)),args=[_list] for(var i=1;i-1){for(var j=start;j'} return res+'>'} function $$super(_type1,_type2){return{__class__:$SuperDict,__thisclass__:_type1,__self_class__:(_type2 ||None)}} $$super.$dict=$SuperDict $$super.__class__=$B.$factory $SuperDict.$factory=$$super $$super.$is_func=true var $Reader={__class__:$B.$type,__name__:'reader'} $Reader.__enter__=function(self){return self} $Reader.__exit__=function(self){return false} $Reader.__iter__=function(self){return iter(self.$lines)} $Reader.__len__=function(self){return self.lines.length} $Reader.__mro__=[$ObjectDict] $Reader.close=function(self){self.closed=true} $Reader.read=function(self,nb){if(self.closed===true)throw _b_.ValueError('I/O operation on closed file') if(nb===undefined)return self.$content self.$counter+=nb if(self.$bin){var res=self.$content.source.slice(self.$counter-nb,self.$counter) return _b_.bytes(res)} return self.$content.substr(self.$counter-nb,nb)} $Reader.readable=function(self){return true} $Reader.readline=function(self,limit){ self.$lc=self.$lc===undefined ? -1 : self.$lc if(self.closed===true)throw _b_.ValueError('I/O operation on closed file') if(self.$lc==self.$lines.length-1){return self.$bin ? _b_.bytes(): ''} self.$lc++ var res=self.$lines[self.$lc] self.$counter +=(self.$bin ? res.source.length : res.length) return res} $Reader.readlines=function(self,hint){if(self.closed===true)throw _b_.ValueError('I/O operation on closed file') self.$lc=self.$lc===undefined ? -1 : self.$lc return self.$lines.slice(self.$lc+1)} $Reader.seek=function(self,offset,whence){if(self.closed===True)throw _b_.ValueError('I/O operation on closed file') if(whence===undefined)whence=0 if(whence===0){self.$counter=offset} else if(whence===1){self.$counter +=offset} else if(whence===2){self.$counter=self.$content.length+offset}} $Reader.seekable=function(self){return true} $Reader.tell=function(self){return self.$counter} $Reader.writable=function(self){return false} var $BufferedReader={__class__:$B.$type,__name__:'_io.BufferedReader'} $BufferedReader.__mro__=[$Reader,$ObjectDict] var $TextIOWrapper={__class__:$B.$type,__name__:'_io.TextIOWrapper'} $TextIOWrapper.__mro__=[$Reader,$ObjectDict] function $url_open(){ var $ns=$B.args('open',3,{file:null,mode:null,encoding:null},['file','mode','encoding'],arguments,{mode:'r',encoding:'utf-8'},'args','kw'),$res for(var attr in $ns){eval('var '+attr+'=$ns["'+attr+'"]')} if(args.length>0)var mode=args[0] if(args.length>1)var encoding=args[1] var is_binary=mode.search('b')>-1 if(isinstance(file,$B.JSObject))return new $OpenFile(file.js,mode,encoding) if(isinstance(file,_b_.str)){ if(window.XMLHttpRequest){ var req=new XMLHttpRequest();}else{ var req=new ActiveXObject("Microsoft.XMLHTTP");} req.onreadystatechange=function(){try{ var status=this.status if(status===404){$res=_b_.IOError('File '+file+' not found')}else if(status!==200){$res=_b_.IOError('Could not open file '+file+' : status '+status)}else{$res=this.responseText if(is_binary){$res=_b_.str.$dict.encode($res,'utf-8')}}}catch(err){$res=_b_.IOError('Could not open file '+file+' : error '+err)}} var fake_qs='?foo='+$B.UUID() req.open('GET',file+fake_qs,false) if(is_binary){req.overrideMimeType('text/plain; charset=utf-8');} req.send() if($res.constructor===Error)throw $res if(is_binary){var lf=_b_.bytes('\n','ascii'),lines=_b_.bytes.$dict.split($res,lf) for(var i=0;i"}})($func)}} var $NoneDict={__class__:$B.$type,__name__:'NoneType'} $NoneDict.__mro__=[$ObjectDict] $NoneDict.__setattr__=function(self,attr){return no_set_attr($NoneDict,attr)} var None={__bool__ : function(){return False},__class__ : $NoneDict,__hash__ : function(){return 0},__repr__ : function(){return 'None'},__str__ : function(){return 'None'},toString : function(){return 'None'}} $NoneDict.$factory=function(){return None} $NoneDict.$factory.__class__=$B.$factory $NoneDict.$factory.$dict=$NoneDict for(var $op in $B.$comps){ var key=$B.$comps[$op] switch(key){case 'ge': case 'gt': case 'le': case 'lt': $NoneDict['__'+key+'__']=(function(op){return function(other){throw _b_.TypeError("unorderable types: NoneType() "+op+" "+ $B.get_class(other).__name__+"()")}})($op)}} for(var $func in None){if(typeof None[$func]==='function'){None[$func].__str__=(function(f){return function(){return ""}})($func)}} var $FunctionCodeDict={__class__:$B.$type,__name__:'function code'} $FunctionCodeDict.__mro__=[$ObjectDict] $FunctionCodeDict.$factory={__class__:$B.$factory,$dict:$FunctionCodeDict} var $FunctionGlobalsDict={__class:$B.$type,__name__:'function globals'} $FunctionGlobalsDict.__mro__=[$ObjectDict] $FunctionGlobalsDict.$factory={__class__:$B.$factory,$dict:$FunctionGlobalsDict} var $FunctionDict=$B.$FunctionDict={__class__:$B.$type,__code__:{__class__:$FunctionCodeDict,__name__:'function code'},__globals__:{__class__:$FunctionGlobalsDict,__name__:'function globals'},__name__:'function'} $FunctionDict.__getattribute__=function(self,attr){ if(self.$infos && self.$infos[attr]!==undefined){if(attr=='__code__'){var res={__class__:$B.$CodeDict} for(var attr in self.$infos.__code__){res[attr]=self.$infos.__code__[attr]} return res}else if(attr=='__annotations__'){ return $B.obj_dict(self.$infos[attr])}else{return self.$infos[attr]}}else{return _b_.object.$dict.__getattribute__(self,attr)}} $FunctionDict.__repr__=$FunctionDict.__str__=function(self){return ''} $FunctionDict.__mro__=[$ObjectDict] $FunctionDict.__setattr__=function(self,attr,value){if(self.$infos[attr]!==undefined){self.$infos[attr]=value} else{self[attr]=value}} var $Function=function(){} $Function.__class__=$B.$factory $FunctionDict.$factory=$Function $Function.$dict=$FunctionDict _b_.__BRYTHON__=__BRYTHON__ var builtin_funcs=['abs','all','any','ascii','bin','bool','bytearray','bytes','callable','chr','classmethod','compile','complex','delattr','dict','dir','divmod','enumerate','eval','exec','exit','filter','float','format','frozenset','getattr','globals','hasattr','hash','help','hex','id','input','int','isinstance','issubclass','iter','len','list','locals','map','max','memoryview','min','next','object','oct','open','ord','pow','print','property','quit','range','repr','reversed','round','set','setattr','slice','sorted','staticmethod','str','sum','$$super','tuple','type','vars','zip'] for(var i=0;i'}})(orig_name)} _b_[name].__module__='builtins' _b_[name].__name__=name _b_[name].__defaults__=_b_[name].__defaults__ ||[] _b_[name].__kwdefaults__=_b_[name].__kwdefaults__ ||{} _b_[name].__annotations__=_b_[name].__annotations__ ||{}} _b_[name].__doc__=_b_[name].__doc__ ||''} catch(err){}} _b_['$$eval']=$eval _b_['open']=$url_open _b_['print']=$print _b_['$$super']=$$super})(__BRYTHON__) ;(function($B){eval($B.InjectBuiltins()) $B.$raise=function(arg){ if(arg===undefined){var es=$B.current_exception if(es!==undefined)throw es throw _b_.RuntimeError('No active exception to reraise')}else if(isinstance(arg,BaseException)){throw arg}else if(arg.__class__===$B.$factory && issubclass(arg,BaseException)){throw arg()}else{throw _b_.TypeError("exceptions must derive from BaseException")}} $B.$syntax_err_line=function(exc,module,pos,line_num){ var pos2line={} var lnum=1 var src=$B.$py_src[module] if(src===undefined){console.log('no src for',module)} var line_pos={1:0} for(var i=0,_len_i=src.length;i < _len_i;i++){pos2line[i]=lnum if(src.charAt(i)=='\n'){line_pos[++lnum]=i}} if(line_num===undefined){line_num=pos2line[pos]} exc.$line_info=line_num+','+module var lines=src.split('\n') var line=lines[line_num-1] var lpos=pos-line_pos[line_num] var len=line.length line=line.replace(/^\s*/,'') lpos-=len-line.length exc.args=_b_.tuple([$B.$getitem(exc.args,0),module,line_num,lpos,line])} $B.$SyntaxError=function(module,msg,pos,line_num,root){if(root!==undefined && root.line_info!==undefined){ line_num=root.line_info} var exc=_b_.SyntaxError(msg) $B.$syntax_err_line(exc,module,pos,line_num) throw exc} $B.$IndentationError=function(module,msg,pos){var exc=_b_.IndentationError(msg) $B.$syntax_err_line(exc,module,pos) throw exc} var $TracebackDict={__class__:$B.$type,__name__:'traceback'} $TracebackDict.__getattribute__=function(self,attr){if(self.stack.length==0){alert('no stack',attr)} var last_frame=$B.last(self.stack) if(last_frame==undefined){alert('last frame undef '); console.log(self.stack,Object.keys(self.stack))} var line_info=last_frame[1].$line_info switch(attr){case 'tb_frame': return frame(self.stack) case 'tb_lineno': if(line_info===undefined){return -1} else{return parseInt(line_info.split(',')[0])} case 'tb_lasti': if(line_info===undefined){return ''} else{var info=line_info.split(',') var src=$B.$py_src[info[1]] if(src!==undefined){return src.split('\n')[parseInt(info[0]-1)].trim()}else{return ''}} case 'tb_next': if(self.stack.length==1){return None} else{return traceback(self.stack.slice(0,self.stack.length-1))} default: return $TracebackDict[attr]}} $TracebackDict.__mro__=[_b_.object.$dict] $TracebackDict.__str__=function(self){return ''} function traceback(stack){return{__class__ : $TracebackDict,stack : stack}} traceback.__class__=$B.$factory traceback.$dict=$TracebackDict $TracebackDict.$factory=traceback var $FrameDict={__class__:$B.$type,__name__:'frame'} $FrameDict.__getattr__=function(self,attr){ if(attr=='f_back'){if(self.$pos>0){return frame(self.$stack,self.$pos-1)}}} $FrameDict.__mro__=[_b_.object.$dict] function to_dict(obj){var res=_b_.dict() var setitem=_b_.dict.$dict.__setitem__ for(var attr in obj){if(attr.charAt(0)=='$'){continue} setitem(res,attr,obj[attr])} return res} function frame(stack,pos){var fs=stack var res={__class__:$FrameDict,f_builtins :{}, $stack: stack,} if(pos===undefined){pos=fs.length-1} res.$pos=pos if(fs.length){var _frame=fs[pos] var locals_id=_frame[0] try{res.f_locals=$B.obj_dict(_frame[1])}catch(err){console.log('err '+err) throw err} res.f_globals=$B.obj_dict(_frame[3]) if(_frame[1].$line_info===undefined){res.f_lineno=-1} else{res.f_lineno=parseInt(_frame[1].$line_info.split(',')[0])} res.f_code={__class__:$B.$CodeDict,co_code:None, co_name: locals_id, co_filename: _frame[3].__name__ } if(res.f_code.co_filename===undefined){console.log(_frame[0],_frame[1],_frame[2],_frame[3]); alert('no cofilename')}} return res} frame.__class__=$B.$factory frame.$dict=$FrameDict $FrameDict.$factory=frame $B._frame=frame var $BaseExceptionDict={__class__:$B.$type,__bases__ :[_b_.object],__module__:'builtins',__name__:'BaseException',args:[]} $BaseExceptionDict.__init__=function(self){var args=arguments[1]===undefined ?[]:[arguments[1]] self.args=_b_.tuple(args)} $BaseExceptionDict.__repr__=function(self){return self.__class__.__name__+repr(self.args)} $BaseExceptionDict.__str__=function(self){return _b_.str(self.args[0])} $BaseExceptionDict.__mro__=[_b_.object.$dict] $BaseExceptionDict.__new__=function(cls){var err=_b_.BaseException() err.__name__=cls.$dict.__name__ err.__class__=cls.$dict return err} $BaseExceptionDict.__getattr__=function(self,attr){if(attr=='info'){var name=self.__class__.__name__ if(name=='SyntaxError' ||name=='IndentationError'){return 'File "'+self.args[1]+'", line '+self.args[2]+'\n '+ self.args[4]} var info='Traceback (most recent call last):' if(self.$js_exc!==undefined){for(var attr in self.$js_exc){if(attr==='message')continue try{info +='\n '+attr+' : '+self.$js_exc[attr]} catch(_err){}} info+='\n'} for(var i=0;i'} info +='\n module '+module+' line '+line_info[0] var line=lines[parseInt(line_info[0])-1] if(line)line=line.replace(/^[ ]+/g,'') if(line===undefined){console.log('line undef...',line_info,$B.$py_src[line_info[1]])} info +='\n '+line} return info}else if(attr=='traceback'){ return traceback(self.$stack)}else{throw AttributeError(self.__class__.__name__+ "has no attribute '"+attr+"'")}} $BaseExceptionDict.with_traceback=function(self,tb){self.traceback=tb return self} $B.set_func_names($BaseExceptionDict) var BaseException=function(){var err=Error() err.__name__='BaseException' err.args=_b_.tuple(Array.prototype.slice.call(arguments)) err.__class__=$BaseExceptionDict err.$py_error=true err.$stack=$B.frames_stack.slice() $B.current_exception=err eval('//placeholder//'); return err} BaseException.__class__=$B.$factory BaseException.$dict=$BaseExceptionDict $BaseExceptionDict.$factory=BaseException _b_.BaseException=BaseException $B.exception=function(js_exc){ if(!js_exc.$py_error){ if(js_exc.info===undefined){var _frame=$B.last($B.frames_stack) if(_frame===undefined){_frame=$B.pmframe} if(_frame && _frame[1].$line_info!==undefined){var line_info=_frame[1].$line_info.split(',') var mod_name=line_info[1] var module=$B.modules[mod_name] if(module){if(module.caller!==undefined){ var mod_name=line_info[1]} var lib_module=mod_name var line_num=parseInt(line_info[0]) if($B.$py_src[mod_name]===undefined){console.log('pas de py_src pour '+mod_name) console.log(js_exc)} var lines=$B.$py_src[mod_name].split('\n'),msg=js_exc.message.toString() msg +="\n module '"+lib_module+"' line "+line_num msg +='\n'+lines[line_num-1] js_exc.msg=msg js_exc.info_in_msg=true}}else{console.log('error ',js_exc)}} var exc=Error() exc.__name__='Internal Javascript error: '+(js_exc.__name__ ||js_exc.name) exc.__class__=_b_.Exception.$dict exc.$js_exc=js_exc if(js_exc.name=='ReferenceError'){exc.__name__='NameError' exc.__class__=_b_.NameError.$dict js_exc.message=js_exc.message.replace('$$','')}else if(js_exc.name=="InternalError"){exc.__name__='RuntimeError' exc.__class__=_b_.RuntimeError.$dict} var $message=js_exc.msg ||'<'+js_exc+'>' exc.args=_b_.tuple([$message]) exc.info='' exc.$py_error=true exc.$stack=$B.frames_stack.slice()}else{var exc=js_exc} $B.current_exception=exc return exc} $B.is_exc=function(exc,exc_list){ if(exc.__class__===undefined)exc=$B.exception(exc) var exc_class=exc.__class__.$factory for(var i=0;ilen){return r.stop} return $B.add(r.start,$B.mul(r.step,i))} $RangeDict.__getitem__=function(self,rank){if(_b_.isinstance(rank,_b_.slice)){var norm=_b_.slice.$dict.$conv_for_seq(rank,$RangeDict.__len__(self)),substep=$B.mul(self.step,norm.step),substart=compute_item(self,norm.start),substop=compute_item(self,norm.stop) return range(substart,substop,substep)} if(typeof rank !="number"){rank=$B.$GetInt(rank)} if($B.gt(0,rank)){rank=$B.add(rank,$RangeDict.__len__(self))} var res=$B.add(self.start,$B.mul(rank,self.step)) if(($B.gt(self.step,0)&&($B.ge(res,self.stop)||$B.gt(self.start,res)))|| ($B.gt(0,self.step)&&($B.ge(self.stop,res)||$B.gt(res,self.start)))){throw _b_.IndexError('range object index out of range')} return res } $RangeDict.__hash__=function(self){var len=$RangeDict.__len__(self) if(len==0){return _b_.hash(_b_.tuple([0,None,None]))} if(len==1){return _b_.hash(_b_.tuple([1,self.start,None]))} return _b_.hash(_b_.tuple([len,self.start,self.step]))} var $RangeIterator=function(obj){return{__class__:$RangeIterator.$dict,obj: obj}} $RangeIterator.__class__=$B.$factory $RangeIterator.$dict={__class__: $B.$type,__name__: 'range_iterator',$factory: $RangeIterator,__iter__: function(self){return self},__next__: function(self){return _b_.next(self.obj)}} $RangeIterator.$dict.__mro__=[_b_.object.$dict] $RangeDict.__iter__=function(self){var res={__class__ : $RangeDict,start:self.start,stop:self.stop,step:self.step} if(self.$safe){res.$counter=self.start-self.step}else{res.$counter=$B.sub(self.start,self.step)} return $RangeIterator(res)} $RangeDict.__len__=function(self){var len if($B.gt(self.step,0)){if($B.ge(self.start,self.stop)){return 0} var n=$B.sub(self.stop,$B.add(1,self.start)),q=$B.floordiv(n,self.step) len=$B.add(1,q)}else{if($B.ge(self.stop,self.start)){return 0} var n=$B.sub(self.start,$B.add(1,self.stop)),q=$B.floordiv(n,$B.mul(-1,self.step)) len=$B.add(1,q)} if($B.maxsize===undefined){$B.maxsize=$B.LongInt.$dict.__pow__($B.LongInt(2),63) $B.maxsize=$B.LongInt.$dict.__sub__($B.maxsize,1)} return len} $RangeDict.__next__=function(self){if(self.$safe){self.$counter +=self.step if((self.step>0 && self.$counter >=self.stop) ||(self.step<0 && self.$counter <=self.stop)){throw _b_.StopIteration('')}}else{self.$counter=$B.add(self.$counter,self.step) if(($B.gt(self.step,0)&& $B.ge(self.$counter,self.stop)) ||($B.gt(0,self.step)&& $B.ge(self.stop,self.$counter))){throw _b_.StopIteration('')}} return self.$counter} $RangeDict.__mro__=[_b_.object.$dict] $RangeDict.__reversed__=function(self){var n=$B.sub($RangeDict.__len__(self),1) return range($B.add(self.start,$B.mul(n,self.step)),$B.sub(self.start,self.step),$B.mul(-1,self.step))} $RangeDict.__repr__=$RangeDict.__str__=function(self){var res='range('+_b_.str(self.start)+', '+_b_.str(self.stop) if(self.step!=1)res +=', '+_b_.str(self.step) return res+')'} $RangeDict.__setattr__=function(self,attr,value){throw _b_.AttributeError('readonly attribute')} $RangeDict.start=function(self){return self.start} $RangeDict.step=function(self){return self.step},$RangeDict.stop=function(self){return self.stop} $RangeDict.count=function(self,ob){if(_b_.isinstance(ob,[_b_.int,_b_.float,_b_.bool])){return _b_.int($RangeDict.__contains__(self,ob))}else{var comp=_b_.getattr(ob,'__eq__'),it=$RangeDict.__iter__(self) _next=$RangeIterator.$dict.__next__,nb=0 while(true){try{if(comp(_next(it))){nb++}}catch(err){if(_b_.isinstance(err,_b_.StopIteration)){return nb} throw err}}}} $RangeDict.index=function(self,other){var $=$B.args('index',2,{self:null,other:null},['self','other'],arguments,{},null,null),self=$.self,other=$.other try{other=$B.int_or_bool(other)}catch(err){var comp=_b_.getattr(other,'__eq__'),it=$RangeDict.__iter__(self),_next=$RangeIterator.$dict.__next__,nb=0 while(true){try{if(comp(_next(it))){return nb} nb++}catch(err){if(_b_.isinstance(err,_b_.StopIteration)){throw _b_.ValueError(_b_.str(other)+' not in range')} throw err}}} var sub=$B.sub(other,self.start),fl=$B.floordiv(sub,self.step),res=$B.mul(self.step,fl) if($B.eq(res,sub)){if(($B.gt(self.stop,self.start)&& $B.ge(other,self.start) && $B.gt(self.stop,other))|| ($B.ge(self.start,self.stop)&& $B.ge(self.start,other) && $B.gt(other,self.stop))){return fl}else{throw _b_.ValueError(_b_.str(other)+' not in range')}}else{throw _b_.ValueError(_b_.str(other)+' not in range')}} function range(){var $=$B.args('range',3,{start:null,stop:null,step:null},['start','stop','step'],arguments,{stop:null,step:null},null,null),start=$.start,stop=$.stop,step=$.step,safe if(stop===null && step===null){stop=$B.PyNumber_Index(start) safe=typeof stop==="number" return{__class__:$RangeDict,start: 0,stop: stop,step: 1,$is_range: true,$safe: safe}} if(step===null){step=1} start=$B.PyNumber_Index(start) stop=$B.PyNumber_Index(stop) step=$B.PyNumber_Index(step) if(step==0){throw _b_.ValueError("range() arg 3 must not be zero")} safe=(typeof start=='number' && typeof stop=='number' && typeof step=='number') return{__class__: $RangeDict,start: start,stop: stop,step: step,$is_range: true,$safe: safe}} range.__class__=$B.$factory range.$dict=$RangeDict $RangeDict.$factory=range range.$is_func=true var $SliceDict={__class__:$B.$type,__name__:'slice',$native:true,descriptors:{start:true,step:true,stop:true}} $SliceDict.__mro__=[_b_.object.$dict] $SliceDict.__repr__=$SliceDict.__str__=function(self){return 'slice('+_b_.str(self.start)+','+ _b_.str(self.stop)+','+_b_.str(self.step)+')'} $SliceDict.__setattr__=function(self,attr,value){throw _b_.AttributeError('readonly attribute')} $SliceDict.$conv=function(self,len){ return{start: self.start===_b_.None ? 0 : self.start,stop: self.stop===_b_.None ? len : self.stop,step: self.step===_b_.None ? 1 : self.step}} $SliceDict.$conv_for_seq=function(self,len){ var step=self.step===None ? 1 : $B.PyNumber_Index(self.step),step_is_neg=$B.gt(0,step),len_1=$B.sub(len,1) if(step==0){throw Error('ValueError : slice step cannot be zero');} var start if(self.start===None){start=step_is_neg ? len_1 : 0;}else{ start=$B.PyNumber_Index(self.start); if($B.gt(0,start))start=$B.add(start,len); if($B.gt(0,start))start=step<0 ? -1 : 0 if($B.ge(start,len))start=step<0 ? len_1 : len;} if(self.stop===None){stop=step_is_neg ? -1 : len;}else{ stop=$B.PyNumber_Index(self.stop); if($B.gt(0,stop))stop +=len if($B.gt(0,stop))stop=step<0 ? -1 : 0 if($B.ge(stop,len))stop=step_is_neg ? len_1 : len;} return{start: start,stop: stop,step: step}} $SliceDict.start=function(self){return self.start} $SliceDict.step=function(self){return self.step} $SliceDict.stop=function(self){return self.stop} $SliceDict.indices=function(self,length){var len=$B.$GetInt(length) if(len < 0)_b_.ValueError('length should not be negative') if(self.step > 0){var _len=_b_.min(len,self.stop) return _b_.tuple([self.start,_len,self.step])}else if(self.step==_b_.None){var _len=_b_.min(len,self.stop) var _start=self.start if(_start==_b_.None)_start=0 return _b_.tuple([_start,_len,1])} _b_.NotImplementedError("Error! negative step indices not implemented yet")} function slice(){var $=$B.args('slice',3,{start:null,stop:null,step:null},['start','stop','step'],arguments,{stop:null,step:null},null,null),start,stop,step if($.stop===null && $.step===null){start=_b_.None stop=$.start step=_b_.None}else{start=$.start stop=$.stop step=$.step===null ? _b_.None : $.step} var res={__class__ : $SliceDict,start:start,stop:stop,step:step} return res} slice.__class__=$B.$factory slice.$dict=$SliceDict $SliceDict.$factory=slice slice.$is_func=true _b_.range=range _b_.slice=slice})(__BRYTHON__) ;(function($B){var _b_=$B.builtins var $ObjectDict=_b_.object.$dict var isinstance=_b_.isinstance,getattr=_b_.getattr,None=_b_.None var from_unicode={},to_unicode={} var $BytearrayDict={__class__:$B.$type,__name__:'bytearray'} var mutable_methods=['__delitem__','clear','copy','count','index','pop','remove','reverse','sort'] for(var i=0,_len_i=mutable_methods.length;i < _len_i;i++){var method=mutable_methods[i] $BytearrayDict[method]=(function(m){return function(self){var args=[self.source],pos=1 for(var i=1,_len_i=arguments.length;i < _len_i;i++)args[pos++]=arguments[i] return _b_.list.$dict[m].apply(null,args)}})(method)} var $bytearray_iterator=$B.$iterator_class('bytearray_iterator') $BytearrayDict.__iter__=function(self){return $B.$iterator(self.source,$bytearray_iterator)} $BytearrayDict.__mro__=[$ObjectDict] $BytearrayDict.__repr__=$BytearrayDict.__str__=function(self){return 'bytearray('+$BytesDict.__repr__(self)+")"} $BytearrayDict.__setitem__=function(self,arg,value){if(isinstance(arg,_b_.int)){if(!isinstance(value,_b_.int)){throw _b_.TypeError('an integer is required')}else if(value>255){throw _b_.ValueError("byte must be in range(0, 256)")} var pos=arg if(arg<0)pos=self.source.length+pos if(pos>=0 && pos=0;i--){if(!isinstance($temp[i],_b_.int)){throw _b_.TypeError('an integer is required')}else if($temp[i]>255){throw ValueError("byte must be in range(0, 256)")} self.source.splice(start,0,$temp[i])}}else{throw _b_.TypeError("can only assign an iterable")}}else{ throw _b_.TypeError('list indices must be integer, not '+$B.get_class(arg).__name__)}} $BytearrayDict.append=function(self,b){if(arguments.length!=2){throw _b_.TypeError( "append takes exactly one argument ("+(arguments.length-1)+" given)")} if(!isinstance(b,_b_.int))throw _b_.TypeError("an integer is required") if(b>255)throw ValueError("byte must be in range(0, 256)") self.source[self.source.length]=b} $BytearrayDict.insert=function(self,pos,b){if(arguments.length!=3){throw _b_.TypeError( "insert takes exactly 2 arguments ("+(arguments.length-1)+" given)")} if(!isinstance(b,_b_.int))throw _b_.TypeError("an integer is required") if(b>255)throw ValueError("byte must be in range(0, 256)") _b_.list.$dict.insert(self.source,pos,b)} function bytearray(source,encoding,errors){var obj={__class__:$BytearrayDict} $BytearrayDict.__init__(obj,source,encoding,errors) return obj} bytearray.__class__=$B.$factory bytearray.$dict=$BytearrayDict $BytearrayDict.$factory=bytearray bytearray.__code__={} bytearray.__code__.co_argcount=1 bytearray.__code__.co_consts=[] bytearray.__code__.co_varnames=['i'] var $BytesDict={__class__ : $B.$type,__name__ : 'bytes'} $BytesDict.__add__=function(self,other){if(!isinstance(other,bytes)){throw _b_.TypeError("can't concat bytes to " + _b_.str(other))} self.source=self.source.concat(other.source) return self} var $bytes_iterator=$B.$iterator_class('bytes_iterator') $BytesDict.__iter__=function(self){return $B.$iterator(self.source,$bytes_iterator)} $BytesDict.__eq__=function(self,other){return getattr(self.source,'__eq__')(other.source)} $BytesDict.__ge__=function(self,other){return _b_.list.$dict.__ge__(self.source,other.source)} $BytesDict.__getitem__=function(self,arg){var i if(isinstance(arg,_b_.int)){var pos=arg if(arg<0)pos=self.source.length+pos if(pos>=0 && pos0){var start=arg.start===None ? 0 : arg.start var stop=arg.stop===None ? getattr(self.source,'__len__')(): arg.stop}else{var start=arg.start===None ? getattr(self.source,'__len__')()-1 : arg.start var stop=arg.stop===None ? 0 : arg.stop} if(start<0)start=self.source.length+start if(stop<0)stop=self.source.length+stop var res=[],i=null,pos=0 if(step>0){if(stop<=start)return '' for(i=start;i=start)return '' for(i=start;i>=stop;i+=step)res[pos++]=self.source[i]} return bytes(res)}else if(isinstance(arg,bool)){return self.source.__getitem__(_b_.int(arg))}} $BytesDict.__gt__=function(self,other){return _b_.list.$dict.__gt__(self.source,other.source)} $BytesDict.__hash__=function(self){if(self===undefined){return $BytesDict.__hashvalue__ ||$B.$py_next_hash-- } var hash=1; for(var i=0,_len_i=self.length;i < _len_i;i++){hash=(101*hash + self.source[i])& 0xFFFFFFFF} return hash} $BytesDict.__init__=function(self,source,encoding,errors){var int_list=[],pos=0 if(source===undefined){}else if(isinstance(source,_b_.int)){var i=source while(i--)int_list[pos++]=0}else{if(isinstance(source,_b_.str)){if(encoding===undefined) throw _b_.TypeError("string argument without an encoding") int_list=encode(source,encoding)}else{ int_list=_b_.list(source)}} self.source=int_list self.encoding=encoding self.errors=errors} $BytesDict.__le__=function(self,other){return _b_.list.$dict.__le__(self.source,other.source)} $BytesDict.__len__=function(self){return self.source.length} $BytesDict.__lt__=function(self,other){return _b_.list.$dict.__lt__(self.source,other.source)} $BytesDict.__mro__=[$ObjectDict] $BytesDict.__mul__=function(){var $=$B.args('__mul__',2,{self:null,other:null},['self','other'],arguments,{},null,null),other=$B.PyNumber_Index($.other),res=bytes() for(var i=0;i=128){var hx=s.toString(16) hx=(hx.length==1 ? '0' : '')+ hx res +='\\x'+hx}else{res +=String.fromCharCode(s)}} return res+"'"} $BytesDict.__reduce_ex__=function(self){return $BytesDict.__repr__(self)} $BytesDict.decode=function(self,encoding,errors){if(encoding===undefined)encoding='utf-8' if(errors===undefined)errors='strict' switch(errors){case 'strict': case 'ignore': case 'replace': case 'surrogateescape': case 'xmlcharrefreplace': case 'backslashreplace': return decode(self.source,encoding,errors) default:}} $BytesDict.join=function(){var $ns=$B.args('join',2,{self:null,iterable:null},['self','iterable'],arguments,{}),self=$ns['self'],iterable=$ns['iterable'] var next_func=_b_.getattr(_b_.iter(iterable),'__next__'),res=bytes(),empty=true while(true){try{var item=next_func() if(empty){empty=false} else{res=$BytesDict.__add__(res,self)} res=$BytesDict.__add__(res,item)}catch(err){if(isinstance(err,_b_.StopIteration)){break} throw err}} return res} $BytesDict.maketrans=function(from,to){var _t=[] for(var i=0;i < 256;i++)_t[i]=i for(var i=0,_len_i=from.source.length;i < _len_i;i++){var _ndx=from.source[i] _t[_ndx]=to.source[i]} return bytes(_t)} $BytesDict.split=function(){var $=$B.args('split',2,{self:null,sep:null},['self','sep'],arguments,{},null,null),res=[],start=0,stop=0 var seps=$.sep.source,len=seps.length,src=$.self.source,blen=src.length while(stopstart)){res.push(bytes(src.slice(start,stop)))} return res} function _strip(self,cars,lr){if(cars===undefined){cars=[],pos=0 var ws='\r\n \t' for(var i=0,_len_i=ws.length;i < _len_i;i++)cars[pos++]=ws.charCodeAt(i)}else if(isinstance(cars,bytes)){cars=cars.source}else{throw _b_.TypeError("Type str doesn't support the buffer API")} if(lr=='l'){for(var i=0,_len_i=self.source.length;i < _len_i;i++){if(cars.indexOf(self.source[i])==-1)break} return bytes(self.source.slice(i))} for(var i=self.source.length-1;i>=0;i--){if(cars.indexOf(self.source[i])==-1)break} return bytes(self.source.slice(0,i+1))} $BytesDict.lstrip=function(self,cars){return _strip(self,cars,'l')} $BytesDict.rstrip=function(self,cars){return _strip(self,cars,'r')} $BytesDict.startswith=function(){var $=$B.args('startswith',2,{self: null,start: null},['self','start'],arguments,{},null,null) if(_b_.isinstance($.start,bytes)){var res=true for(var i=0;i<$.start.source.length && res;i++){res=$.self.source[i]==$.start.source[i]} return res}else if(_b_.isinstance($.start,_b_.tuple)){var items=[] for(var i=0;i<$.start.length;i++){if(_b_.isinstance($.start[i],bytes)){items=items.concat($.start[i].source)}else{throw _b_.TypeError("startswith first arg must be bytes or "+ "a tuple of bytes, not "+$B.get_class($.start).__name__)}} var start=bytes(items) return $BytesDict.startswith($.self,start)}else{throw _b_.TypeError("startswith first arg must be bytes or a tuple of bytes, not "+ $B.get_class($.start).__name__)}} $BytesDict.strip=function(self,cars){var res=$BytesDict.lstrip(self,cars) return $BytesDict.rstrip(res,cars)} $BytesDict.translate=function(self,table,_delete){if(_delete===undefined){_delete=[]} else if(isinstance(_delete,bytes)){_delete=_delete.source} else{throw _b_.TypeError("Type "+$B.get_class(_delete).__name+" doesn't support the buffer API")} var res=[],pos=0 if(isinstance(table,bytes)&& table.source.length==256){for(var i=0,_len_i=self.source.length;i < _len_i;i++){if(_delete.indexOf(self.source[i])>-1)continue res[pos++]=table.source[self.source[i]]}} return bytes(res)} $BytesDict.upper=function(self){var _res=[],pos=0 for(var i=0,_len_i=self.source.length;i < _len_i;i++)_res[pos++]=self.source[i].toUpperCase() return bytes(_res)} function $UnicodeEncodeError(encoding,code_point,position){throw _b_.UnicodeEncodeError("'"+encoding+ "' codec can't encode character "+_b_.hex(code_point)+ " in position "+position)} function $UnicodeDecodeError(encoding,position){throw _b_.UnicodeDecodeError("'"+encoding+ "' codec can't decode bytes in position "+position)} function _hex(int){return int.toString(16)} function _int(hex){return parseInt(hex,16)} function normalise(encoding){var enc=encoding.toLowerCase() if(enc.substr(0,7)=='windows'){enc='cp'+enc.substr(7)} enc=enc.replace('-','') enc=enc.replace('-','_') return enc} function load_decoder(enc){ if(to_unicode[enc]===undefined){load_encoder(enc) to_unicode[enc]={} for(var attr in from_unicode[enc]){to_unicode[enc][from_unicode[enc][attr]]=attr}}} function load_encoder(enc){ if(from_unicode[enc]===undefined){var mod=_b_.__import__('encodings.'+enc),table=mod[enc].decoding_table from_unicode[enc]={} for(var i=0;i-1){ return pyobj.elt}else if([_b_.list.$dict,_b_.tuple.$dict].indexOf(klass)>-1){ var res=[] for(var i=0,_len_i=pyobj.length;i < _len_i;i++){res.push(pyobj2jsobj(pyobj[i]))} return res}else if(klass===_b_.dict.$dict){ var jsobj={} var items=_b_.list(_b_.dict.$dict.items(pyobj)) for(var j=0,_len_j=items.length;j < _len_j;j++){if(typeof items[j][1]=='function'){ items[j][1].bind(jsobj)} jsobj[items[j][0]]=pyobj2jsobj(items[j][1])} return jsobj}else if(klass===$B.builtins.float.$dict){ return pyobj.valueOf()}else if(klass===$B.$FunctionDict){ return function(){try{var args=[] for(var i=0;i 0 ? err.args[0]: '' ) throw err}}}else{ return pyobj}} var $JSObjectDict={__class__:$B.$type,__name__:'JSObject',toString:function(){return '(JSObject)'}} $JSObjectDict.__bool__=function(self){return(new Boolean(self.js)).valueOf()} $JSObjectDict.__delattr__=function(self,attr){_b_.getattr(self,attr) delete self.js[attr] return _b_.None} $JSObjectDict.__dir__=function(self){return Object.keys(self.js)} $JSObjectDict.__getattribute__=function(self,attr){if(attr.substr(0,2)=='$$')attr=attr.substr(2) if(self.js===null)return $ObjectDict.__getattribute__(None,attr) if(attr==='__class__')return $JSObjectDict if(self.__class__===$JSObjectDict && attr=="$bind" && self.js[attr]===undefined && self.js['addEventListener']!==undefined){attr='addEventListener'} var js_attr=self.js[attr] if(self.js_func && self.js_func[attr]!==undefined){js_attr=self.js_func[attr]} if(js_attr !==undefined){if(typeof js_attr=='function'){ var res=function(){ var args=[] for(var i=0,_len_i=arguments.length;i < _len_i;i++){if(arguments[i].$nat!=undefined){ throw TypeError("A Javascript function can't "+ "take keyword arguments")}else{args.push(pyobj2jsobj(arguments[i]))}} if(attr==='replace' && self.js===location){location.replace(args[0]) return} var new_this=self.js; if(self.js_func){ new_this=self.js_func;} if(this !==null && this !==undefined && this !==window){new_this=this} var result=js_attr.apply(new_this,args) if(result===undefined){result=this} return $B.$JS2Py(result)} res.__repr__=function(){return ''} res.__str__=function(){return ''} res.prototype=js_attr.prototype return{__class__:$JSObjectDict,js:res,js_func:js_attr}}else{if(Array.isArray(js_attr)){return js_attr} return $B.$JS2Py(js_attr)}}else if(self.js===window && attr==='$$location'){ return $Location()} var res=self.__class__[attr] if(res===undefined){ var mro=self.__class__.__mro__ for(var i=0,_len_i=mro.length;i < _len_i;i++){var v=mro[i][attr] if(v!==undefined){res=v break}}} if(res!==undefined){if(typeof res==='function'){ return function(){var args=[self] for(var i=0,_len_i=arguments.length;i < _len_i;i++){arg=arguments[i] if(arg &&(arg.__class__===$JSObjectDict ||arg.__class__===$JSConstructorDict)){args.push(arg.js)}else{args.push(arg)}} return res.apply(self,args)}} return $B.$JS2Py(res)}else{ throw _b_.AttributeError("no attribute "+attr+' for '+self.js)}} $JSObjectDict.__getitem__=function(self,rank){if(typeof self.js.length=='number'){if((typeof rank=="number" ||typeof rank=="boolean")&& typeof self.js.item=='function'){var rank_to_int=_b_.int(rank) if(rank_to_int<0){rank_to_int+=self.js.length} var res=JSObject(self.js.item(rank_to_int)) if(res===undefined){throw _b_.KeyError(rank)} return res}else if(typeof rank=="string" && typeof self.js.getNamedItem=='function'){var res=JSObject(self.js.getNamedItem(rank)) if(res===undefined){throw _b_.keyError(rank)} return res}} try{return getattr(self.js,'__getitem__')(rank)} catch(err){if(self.js[rank]!==undefined){return JSObject(self.js[rank])} throw _b_.KeyError(rank)}} var $JSObject_iterator=$B.$iterator_class('JS object iterator') $JSObjectDict.__iter__=function(self){var items=[] if(window.Symbol && self.js[Symbol.iterator]!==undefined){ if(self.js.length!==undefined && self.js.item!==undefined){for(var i=0;i"} return ""} $JSObjectDict.__setattr__=function(self,attr,value){if(isinstance(value,JSObject)){self.js[attr]=value.js} else{self.js[attr]=value if(typeof value=='function'){self.js[attr]=function(){var args=[] for(var i=0,len=arguments.length;i 0){err.toString=function(){return info+'\n'+err.__class__.__name__+ ': '+_b_.repr(err.args[0])}}else{ err.toString=function(){return info+'\n'+err.__class__.__name__}} console.log(err+'') throw err}}}}} $JSObjectDict.__setitem__=$JSObjectDict.__setattr__ $JSObjectDict.__str__=$JSObjectDict.__repr__ var no_dict={'string':true,'function':true,'number':true,'boolean':true} $JSObjectDict.bind=function(self,evt,func){self.js.addEventListener(evt,func) return _b_.None} $JSObjectDict.to_dict=function(self){ var res=_b_.dict() for(var key in self.js){var value=self.js[key] if(typeof value=='object' && !Array.isArray(value)){_b_.dict.$dict.__setitem__(res,key,$JSObjectDict.to_dict(JSObject(value)))}else{_b_.dict.$dict.__setitem__(res,key,value)}} return res} function JSObject(obj){if(obj===null){return _b_.None} if(typeof obj=='function'){return{__class__:$JSObjectDict,js:obj,js_func:obj}} var klass=$B.get_class(obj) if(klass===_b_.float.$dict)return _b_.float(obj) if(klass!==undefined)return obj return{__class__:$JSObjectDict,js:obj}} JSObject.__class__=$B.$factory JSObject.$dict=$JSObjectDict $JSObjectDict.$factory=JSObject $B.JSObject=JSObject $B.JSConstructor=JSConstructor})(__BRYTHON__) ;(function($B){$B.stdlib={} var pylist=['VFS_import','__future__','_abcoll','_codecs','_collections','_csv','_dummy_thread','_functools','_imp','_io','_markupbase','_random','_socket','_sre','_string','_strptime','_struct','_sysconfigdata','_testcapi','_thread','_threading_local','_warnings','_weakref','_weakrefset','abc','antigravity','argparse','atexit','base64','bdb','binascii','bisect','calendar','cmd','code','codecs','codeop','colorsys','configparser','Clib','copy','copyreg','csv','datetime','decimal','difflib','doctest','errno','external_import','fnmatch','formatter','fractions','functools','gc','genericpath','getopt','gettext','glob','heapq','imp','inspect','io','itertools','keyword','linecache','locale','marshal','numbers','opcode','operator','optparse','os','pdb','pickle','platform','posix','posixpath','pprint','profile','pwd','pydoc','queue','re','reprlib','select','shutil','signal','site','site-packages.__future__','site-packages.docs','site-packages.header','site-packages.highlight','site-packages.test_sp','site-packages.turtle','socket','sre_compile','sre_constants','sre_parse','stat','string','struct','subprocess','sys','sysconfig','tarfile','tempfile','test.namespace_pkgs.module_and_namespace_package.a_test','textwrap','this','threading','time','timeit','token','tokenize','traceback','types','uuid','warnings','weakref','webbrowser','zipfile','zlib'] for(var i=0;i'} $B.$ModuleDict.__mro__=[_b_.object.$dict] $B.$ModuleDict.__setattr__=function(self,attr,value){if(self.__name__=='__builtins__'){ $B.builtins[attr]=value}else{self[attr]=value}} function module(name,doc,package){return{__class__:$B.$ModuleDict,__name__:name,__doc__:doc||_b_.None,__package__:package||_b_.None}} module.__class__=$B.$factory module.$dict=$B.$ModuleDict $B.$ModuleDict.$factory=module var loader=function(){} var Loader={__class__:$B.$type,__name__ : 'Loader'} Loader.__mro__=[_b_.object.$dict] Loader.$factory=loader loader.$dict=Loader loader.__class__=$B.$factory function parent_package(mod_name){var parts=mod_name.split('.'); parts.pop(); return parts.join('.');} function $importer(){ var $xmlhttp=new XMLHttpRequest(); var fake_qs; switch($B.$options.cache){case 'version': fake_qs="?v="+$B.version_info[2] break; case 'browser': fake_qs='' break; default: fake_qs="?v="+(new Date().getTime())} var timer=setTimeout(function(){$xmlhttp.abort() throw _b_.ImportError("No module named '"+module+"'")},5000) return[$xmlhttp,fake_qs,timer]} function $download_module(module,url,package,blocking){var imp=$importer(),$xmlhttp=imp[0],fake_qs=imp[1],timer=imp[2],res=null,mod_name=module.__name__,no_block=Array.isArray(blocking)||blocking===false,res,t0=new Date() $B.download_time=$B.download_time ||0 if(no_block){console.log('download non blocking',mod_name) $xmlhttp.open('GET',url+fake_qs,true)}else{$xmlhttp.open('GET',url+fake_qs,false)} if($B.$CORS){$xmlhttp.onload=function(){if($xmlhttp.status==200 ||$xmlhttp.status==0){res=$xmlhttp.responseText}else{ res=_b_.FileNotFoundError("No module named '"+mod_name+"'")}} $xmlhttp.onerror=function(){res=_b_.FileNotFoundError("No module named '"+mod_name+"'")}}else{ $xmlhttp.onreadystatechange=function(){if(this.readyState==4){window.clearTimeout(timer) if(this.status==200 ||$xmlhttp.status==0){res=this.responseText module.$last_modified=this.getResponseHeader('Last-Modified') if(no_block){var ext=url.substr(url.length-2) if(ext=='py'){try{import_py1(module,mod_name,url,package,res)} catch(err){console.log(err);throw err}}else if(ext=='js'){try{run_js(res,url,module)} catch(err){console.log(err);throw err}} console.log('non blocking ok',mod_name) blocking[1]() return}}else{ console.log('Error '+this.status+ ' means that Python module '+mod_name+ ' was not found at url '+url) res=_b_.FileNotFoundError("No module named '"+mod_name+"'")}}}} if('overrideMimeType' in $xmlhttp){$xmlhttp.overrideMimeType("text/plain")} $xmlhttp.send() if(!no_block){ if(res==null)throw _b_.FileNotFoundError("No module named '"+mod_name+"' (res is null)") if(res.constructor===Error){throw res} $B.download_time +=(new Date())-t0 return res}} $B.$download_module=$download_module function import_js(module,path,blocking){try{var module_contents=$download_module(module,path,undefined,blocking) if(Array.isArray(blocking)){return}}catch(err){return null} run_js(module_contents,path,module) return true} function run_js(module_contents,path,module){ try{eval(module_contents); if($B.$options.store){module.$js=module_contents}}catch(err){console.log(err) throw err} try{$module} catch(err){console.log('no $module') throw _b_.ImportError("name '$module' is not defined in module")} if(module !==undefined){ for(var attr in $module){module[attr]=$module[attr];} $module=module;} else{ $module.__class__=$B.$ModuleDict $module.__name__=module.name $module.__repr__=$module.__str__=function(){if($B.builtin_module_names.indexOf(module.name)> -1){return ""} return ""} $module.toString=function(){return ""} if(module.name !='builtins'){ $module.__file__=path}} $B.imported[module.__name__]=$module return true} function show_ns(){var kk=Object.keys(window) for(var i=0,_len_i=kk.length;i < _len_i;i++){console.log(kk[i]) if(kk[i].charAt(0)=='$'){console.log(eval(kk[i]))}} console.log('---')} function import_py1(module,mod_name,path,package,module_contents){console.log('importpy1',mod_name) $B.imported[mod_name]={__class__: $B.$ModuleDict,$is_package: module.$is_package,$last_modified: module.$last_modified} if(path.substr(path.length-12)=='/__init__.py'){ $B.imported[mod_name].__package__=mod_name $B.imported[mod_name].__path__=path $B.imported[mod_name].$is_package=module.$is_package=true}else if(package){$B.imported[mod_name].__package__=package}else{var mod_elts=mod_name.split('.') mod_elts.pop() $B.imported[mod_name].__package__=mod_elts.join('.')} $B.imported[mod_name].__file__=path return run_py(module_contents,path,module)} function import_py(module,path,package,blocking){ var mod_name=module.__name__,module_contents=$download_module(module,path,package,blocking) if(Array.isArray(blocking)){return} $B.imported[mod_name].$is_package=module.$is_package $B.imported[mod_name].$last_modified=module.$last_modified if(path.substr(path.length-12)=='/__init__.py'){ $B.imported[mod_name].__package__=mod_name $B.imported[mod_name].__path__=path $B.imported[mod_name].$is_package=module.$is_package=true}else if(package){$B.imported[mod_name].__package__=package}else{var mod_elts=mod_name.split('.') mod_elts.pop() $B.imported[mod_name].__package__=mod_elts.join('.')} $B.imported[mod_name].__file__=path return run_py(module_contents,path,module)} function run_py(module_contents,path,module,compiled){var root,js if(!compiled){var $Node=$B.$Node,$NodeJSCtx=$B.$NodeJSCtx $B.$py_module_path[module.__name__]=path root=$B.py2js(module_contents,module.__name__,module.__name__,'__builtins__') var body=root.children root.children=[] var mod_node=new $Node('expression') new $NodeJSCtx(mod_node,'var $module=(function()') root.insert(0,mod_node) for(var i=0,_len_i=body.length;i < _len_i;i++){mod_node.add(body[i])} var ret_node=new $Node('expression') new $NodeJSCtx(ret_node,'return $locals_'+module.__name__.replace(/\./g,'_')) mod_node.add(ret_node) var ex_node=new $Node('expression') new $NodeJSCtx(ex_node,')(__BRYTHON__)') root.add(ex_node)} try{js=(compiled)? module_contents : root.to_js() if($B.$options.debug==10){console.log('code for module '+module.__name__) console.log(js)} eval(js)}catch(err){console.log(err+' for module '+module.__name__) root=null js=null throw err}finally{$B.clear_ns(module.__name__)} try{ var mod=eval('$module') for(var attr in mod){module[attr]=mod[attr];} module.__initializing__=false $B.imported[module.__name__]=module return true}catch(err){console.log(''+err+' '+' for module '+module.name) for(var attr in err)console.log(attr+' '+err[attr]) if($B.debug>0){console.log('line info '+__BRYTHON__.line_info)} throw err}finally{root=null js=null}} $B.run_py=run_py function new_spec(fields){ fields.__class__=$B.$ModuleDict return fields;} function finder_VFS(){return{__class__:finder_VFS.$dict}} finder_VFS.__class__=$B.$factory finder_VFS.$dict={$factory: finder_VFS,__class__: $B.$type,__name__: 'VFSFinder',create_module : function(cls,spec){ return _b_.None;},exec_module : function(cls,module){var stored=module.__spec__.loader_state.stored; delete module.__spec__['loader_state']; var ext=stored[0],module_contents=stored[1]; module.$is_package=stored[2]||false; var path=$B.brython_path+'Lib/'+module.__name__ if(module.$is_package){path +='/__init__.py'} module.__file__=path if(ext=='.js'){run_js(module_contents,module.__path__,module)} else{ run_py(module_contents,module.__path__,module,ext=='.pyc.js')} if($B.debug>1){console.log('import '+module.__name__+' from VFS')}},find_module: function(cls,name,path){return{__class__:Loader,load_module:function(name,path){var spec=cls.$dict.find_spec(cls,name,path) var mod=module(name) $B.imported[name]=mod mod.__spec__=spec cls.$dict.exec_module(cls,mod)}}},find_spec : function(cls,fullname,path,prev_module){if(!$B.use_VFS){return _b_.None;} var stored=$B.VFS[fullname]; if(stored===undefined){return _b_.None;} var is_package=stored[2],is_builtin=$B.builtin_module_names.indexOf(fullname)> -1; return new_spec({name : fullname,loader: cls, origin : is_builtin? 'built-in' : 'brython_stdlib', submodule_search_locations: is_package?[]: _b_.None,loader_state:{stored: stored}, cached: _b_.None,parent: is_package? fullname : parent_package(fullname),has_location: _b_.False});}} finder_VFS.$dict.__mro__=[_b_.object.$dict] finder_VFS.$dict.create_module.$type='classmethod' finder_VFS.$dict.exec_module.$type='classmethod' finder_VFS.$dict.find_module.$type='classmethod' finder_VFS.$dict.find_spec.$type='classmethod' function finder_stdlib_static(){return{__class__:finder_stdlib_static.$dict}} finder_stdlib_static.__class__=$B.$factory finder_stdlib_static.$dict={$factory : finder_stdlib_static,__class__ : $B.$type,__name__ : 'StdlibStatic',create_module : function(cls,spec){ return _b_.None;},exec_module : function(cls,module,blocking){var metadata=module.__spec__.loader_state; module.$is_package=metadata.is_package; if(metadata.ext=='py'){import_py(module,metadata.path,module.__package__,blocking);} else{ import_js(module,metadata.path,blocking);} delete module.__spec__['loader_state'];},find_module: function(cls,name,path){var spec=cls.$dict.find_spec(cls,name,path) if(spec===_b_.None){return _b_.None} return{__class__:Loader,load_module:function(name,path){var mod=module(name) $B.imported[name]=mod mod.__spec__=spec mod.__package__=spec.parent cls.$dict.exec_module(cls,mod,spec.blocking)}}},find_spec: function(cls,fullname,path,prev_module){if($B.stdlib && $B.$options.static_stdlib_import){var address=$B.stdlib[fullname]; if(address===undefined){var elts=fullname.split('.') if(elts.length>1){elts.pop() var package=$B.stdlib[elts.join('.')] if(package && package[1]){address=['py']}}} if(address !==undefined){var ext=address[0],is_pkg=address[1]!==undefined,path=$B.brython_path +((ext=='py')? 'Lib/' : 'libs/')+ fullname.replace(/\./g,'/'),metadata={ext: ext,is_package: is_pkg,path: path +(is_pkg? '/__init__.py' : ((ext=='py')? '.py' : '.js')),address: address} var res=new_spec( {name : fullname,loader: cls, origin : metadata.path,submodule_search_locations: is_pkg?[path]: _b_.None,loader_state: metadata, cached: _b_.None,parent: is_pkg? fullname : parent_package(fullname),has_location: _b_.True}); return res}} return _b_.None;}} finder_stdlib_static.$dict.__mro__=[_b_.object.$dict] finder_stdlib_static.$dict.create_module.$type='classmethod' finder_stdlib_static.$dict.exec_module.$type='classmethod' finder_stdlib_static.$dict.find_module.$type='classmethod' finder_stdlib_static.$dict.find_spec.$type='classmethod' function finder_path(){return{__class__:finder_path.$dict}} finder_path.__class__=$B.$factory finder_path.$dict={$factory: finder_path,__class__: $B.$type,__name__: 'ImporterPath',create_module : function(cls,spec){ return _b_.None;},exec_module : function(cls,module){var _spec=_b_.getattr(module,'__spec__'),code=_spec.loader_state.code; module.$is_package=_spec.loader_state.is_package,delete _spec.loader_state['code']; var src_type=_spec.loader_state.type if(src_type=='py' ||src_type=='pyc.js'){run_py(code,_spec.origin,module,src_type=='pyc.js');} else if(_spec.loader_state.type=='js'){run_js(code,_spec.origin,module)}},find_module: function(cls,name,path){return finder_path.$dict.find_spec(cls,name,path)},find_spec : function(cls,fullname,path,prev_module,blocking){if($B.is_none(path)){ path=$B.path} for(var i=0,li=path.length;i'},self.path)} catch(e){self.vfs=undefined; throw new _b_.ImportError(e.$message ||e.message);} eval(code); try{ self.vfs=$vfs;} catch(e){throw new _b_.ImportError('Expecting $vfs var in VFS file');} $B.path_importer_cache[self.path + '/']=self;},find_spec: function(self,fullname,module){if(self.vfs===undefined){try{vfs_hook.$dict.load_vfs(self)} catch(e){console.log("Could not load VFS while importing '" + fullname + "'"); return _b_.None;}} var stored=self.vfs[fullname]; if(stored===undefined){return _b_.None;} var is_package=stored[2]; return new_spec({name : fullname,loader: finder_VFS, origin : self.path + '#' + fullname, submodule_search_locations: is_package?[self.path]: _b_.None,loader_state:{stored: stored}, cached: _b_.None,parent: is_package? fullname : parent_package(fullname),has_location: _b_.True});},invalidate_caches: function(self){self.vfs=undefined;}} vfs_hook.$dict.__mro__=[_b_.object.$dict] function url_hook(path_entry,hint){return{__class__: url_hook.$dict,path_entry:path_entry,hint:hint }} url_hook.__class__=$B.$factory url_hook.$dict={$factory: url_hook,__class__: $B.$type,__name__ : 'UrlPathFinder',__repr__: function(self){return ''},find_spec : function(self,fullname,module,blocking){var loader_data={},notfound=true,hint=self.hint,base_path=self.path_entry + fullname.match(/[^.]+$/g)[0],modpaths=[]; var tryall=hint===undefined; if(tryall ||hint=='js'){ modpaths=[[base_path + '.js','js',false]];} if(tryall ||hint=='pyc.js'){ modpaths=modpaths.concat([[base_path + '.pyc.js','pyc.js',false],[base_path + '/__init__.pyc.js','pyc.js',true]]);} if(tryall ||hint=='py'){ modpaths=modpaths.concat([[base_path + '.py','py',false],[base_path + '/__init__.py','py',true]]);} for(var j=0;notfound && j < modpaths.length;++j){try{var file_info=modpaths[j],module={__name__:fullname,$is_package: false} loader_data.code=$download_module(module,file_info[0],undefined,blocking); notfound=false; loader_data.type=file_info[1]; loader_data.is_package=file_info[2]; if(hint===undefined){self.hint=file_info[1]; $B.path_importer_cache[self.path_entry]=self;} if(loader_data.is_package){ $B.path_importer_cache[base_path + '/']= url_hook(base_path + '/',self.hint);} loader_data.path=file_info[0];}catch(err){}} if(!notfound){return new_spec({name : fullname,loader: finder_path,origin : loader_data.path, submodule_search_locations: loader_data.is_package?[base_path]: _b_.None,loader_state: loader_data, cached: _b_.None,parent: loader_data.is_package? fullname : parent_package(fullname),has_location: _b_.True});} return _b_.None;},invalidate_caches : function(self){}} url_hook.$dict.__mro__=[_b_.object.$dict] $B.path_importer_cache={}; var _sys_paths=[[$B.script_dir + '/','py'],[$B.brython_path + 'Lib/','py'],[$B.brython_path + 'Lib/site-packages/','py'],[$B.brython_path + 'libs/','js']]; for(i=0;i < _sys_paths.length;++i){var _path=_sys_paths[i],_type=_path[1]; _path=_path[0]; $B.path_importer_cache[_path]=url_hook(_path,_type);} delete _path; delete _type; delete _sys_paths; $B.$__import__=function(mod_name,globals,locals,fromlist,level,blocking){ var modobj=$B.imported[mod_name],parsed_name=mod_name.split('.'); if(modobj==_b_.None){ throw _b_.ImportError(mod_name)} if(modobj===undefined){ if($B.is_none(fromlist)){fromlist=[];} for(var i=0,modsep='',_mod_name='',len=parsed_name.length - 1,__path__=_b_.None;i <=len;++i){var _parent_name=_mod_name; _mod_name +=modsep + parsed_name[i]; modsep='.'; var modobj=$B.imported[_mod_name]; if(modobj==_b_.None){ throw _b_.ImportError(_mod_name)} else if(modobj===undefined){try{$B.import_hooks(_mod_name,__path__,undefined,blocking)} catch(err){delete $B.imported[_mod_name] throw err} if($B.is_none($B.imported[_mod_name])){throw _b_.ImportError(_mod_name)} else{ if(_parent_name){_b_.setattr($B.imported[_parent_name],parsed_name[i],$B.imported[_mod_name]);}}} if(i < len){try{ __path__=_b_.getattr($B.imported[_mod_name],'__path__')}catch(e){ if(i==len-1 && $B.imported[_mod_name][parsed_name[len]]&& $B.imported[_mod_name][parsed_name[len]].__class__===$B.$ModuleDict){return $B.imported[_mod_name][parsed_name[len]]} throw _b_.ImportError(_mod_name)}}}} else if(Array.isArray(blocking)){var frames=$B.frames_stack for(var i=0;i"} $B.imported['_importlib']=$B.modules['_importlib']=_importlib_module})(__BRYTHON__) ;(function($B){eval($B.InjectBuiltins()) var $ObjectDict=_b_.object.$dict function $err(op,other){var msg="unsupported operand type(s) for "+op msg +=": 'float' and '"+$B.get_class(other).__name__+"'" throw _b_.TypeError(msg)} var $FloatDict={__class__:$B.$type,__dir__:$ObjectDict.__dir__,__name__:'float',$native:true} $FloatDict.as_integer_ratio=function(self){if(self.valueOf()==Number.POSITIVE_INFINITY || self.valueOf()==Number.NEGATIVE_INFINITY){throw _b_.OverflowError("Cannot pass infinity to float.as_integer_ratio.")} if(!Number.isFinite(self.valueOf())){throw _b_.ValueError("Cannot pass NaN to float.as_integer_ratio.")} var tmp=_b_.$frexp(self.valueOf()) var fp=tmp[0] var exponent=tmp[1] for(var i=0;i < 300;i++){if(fp==Math.floor(fp)){break}else{ fp *=2 exponent--}} numerator=float(fp) py_exponent=abs(exponent) denominator=1 py_exponent=_b_.getattr(int(denominator),"__lshift__")(py_exponent) if(exponent > 0){numerator=numerator * py_exponent}else{ denominator=py_exponent} return _b_.tuple([_b_.int(numerator),_b_.int(denominator)])} $FloatDict.__bool__=function(self){return _b_.bool(self.valueOf())} $FloatDict.__class__=$B.$type $FloatDict.__eq__=function(self,other){if(isNaN(self)&& isNaN(other)){return false} if(isinstance(other,_b_.int))return self==other if(isinstance(other,float)){ return self.valueOf()==other.valueOf()} if(isinstance(other,_b_.complex)){if(other.imag !=0)return false return self==other.real} if(_b_.hasattr(other,'__eq__')){return _b_.getattr(other,'__eq__')(self.value)} return self.value===other} $FloatDict.__floordiv__=function(self,other){if(isinstance(other,[_b_.int,float])){if(other.valueOf()==0)throw ZeroDivisionError('division by zero') return float(Math.floor(self/other))} if(hasattr(other,'__rfloordiv__')){return getattr(other,'__rfloordiv__')(self)} $err('//',other)} $FloatDict.fromhex=function(arg){ if(!isinstance(arg,_b_.str)){throw _b_.ValueError('argument must be a string')} var value=arg.trim() switch(value.toLowerCase()){case '+inf': case 'inf': case '+infinity': case 'infinity': return $FloatClass(Infinity) case '-inf': case '-infinity': return $FloatClass(-Infinity) case '+nan': case 'nan': return $FloatClass(Number.NaN) case '-nan': return $FloatClass(-Number.NaN) case '': throw _b_.ValueError('count not convert string to float')} var _m=/^(\d*\.?\d*)$/.exec(value) if(_m !==null)return $FloatClass(parseFloat(_m[1])) var _m=/^(\+|-)?(0x)?([0-9A-F]+\.?)?(\.[0-9A-F]+)?(p(\+|-)?\d+)?$/i.exec(value) if(_m==null)throw _b_.ValueError('invalid hexadecimal floating-point string') var _sign=_m[1] var _int=parseInt(_m[3]||'0',16) var _fraction=_m[4]||'.0' var _exponent=_m[5]||'p0' if(_sign=='-'){_sign=-1}else{_sign=1} var _sum=_int for(var i=1,_len_i=_fraction.length;i < _len_i;i++){_sum+=parseInt(_fraction.charAt(i),16)/Math.pow(16,i)} return new Number(_sign * _sum * Math.pow(2,parseInt(_exponent.substring(1))))} $FloatDict.__getformat__=function(arg){if(arg=='double' ||arg=='float')return 'IEEE, little-endian' throw _b_.ValueError("__getformat__() argument 1 must be 'double' or 'float'")} function preformat(self,fmt){if(fmt.empty){return _b_.str(self)} if(fmt.type && 'eEfFgGn%'.indexOf(fmt.type)==-1){throw _b_.ValueError("Unknown format code '"+fmt.type+ "' for object of type 'float'")} if(isNaN(self)){if(fmt.type=='f'||fmt.type=='g'){return 'nan'} else{return 'NAN'}} if(self==Number.POSITIVE_INFINITY){if(fmt.type=='f'||fmt.type=='g'){return 'inf'} else{return 'INF'}} if(fmt.precision===undefined && fmt.type !==undefined){fmt.precision=6} if(fmt.type=='%'){self *=100} if(fmt.type=='e'){var res=self.toExponential(fmt.precision),exp=parseInt(res.substr(res.search('e')+1)) if(Math.abs(exp)<10){res=res.substr(0,res.length-1)+'0'+ res.charAt(res.length-1)} return res } if(fmt.precision!==undefined){ var prec=fmt.precision if(prec==0){return Math.round(self)+''} var res=self.toFixed(prec),pt_pos=res.indexOf('.') if(fmt.type!==undefined && (fmt.type=='%' ||fmt.type.toLowerCase()=='f')){if(pt_pos==-1){res +='.'+'0'.repeat(fmt.precision)} else{var missing=fmt.precision-res.length+pt_pos+1 if(missing>0)res +='0'.repeat(missing)}}else{var res1=self.toExponential(fmt.precision-1),exp=parseInt(res1.substr(res1.search('e')+1)) if(exp<-4 ||exp>=fmt.precision-1){res=res1 if(Math.abs(exp)<10){res=res.substr(0,res.length-1)+'0'+ res.charAt(res.length-1)}}}}else{var res=_b_.str(self)} if(fmt.type===undefined||'gGn'.indexOf(fmt.type)!=-1){ while(res.charAt(res.length-1)=='0'){res=res.substr(0,res.length-1)} if(res.charAt(res.length-1)=='.'){if(fmt.type===undefined){res +='0'} else{res=res.substr(0,res.length-1)}}} if(fmt.sign!==undefined){if((fmt.sign==' ' ||fmt.sign=='+')&& self>0){res=fmt.sign+res}} if(fmt.type=='%'){res+='%'} return res} $FloatDict.__format__=function(self,format_spec){var fmt=new $B.parse_format_spec(format_spec) fmt.align=fmt.align ||'>' var raw=preformat(self,fmt).split('.'),_int=raw[0] if(fmt.comma){var len=_int.length,nb=Math.ceil(_int.length/3),chunks=[] for(var i=0;i0?float(x):float(-x)} _b_.$frexp=function(x){var x1=x if(isinstance(x,float))x1=x.valueOf() if(isNaN(x1)||_b_.$isinf(x1)){return[x1,-1]} if(x1==0)return[0,0] var sign=1,ex=0,man=x1 if(man < 0.){sign=-sign man=-man} while(man < 0.5){man *=2.0 ex--} while(man >=1.0){man *=0.5 ex++} man *=sign return[man ,ex]} _b_.$ldexp=function(x,i){if(_b_.$isninf(x))return float('-inf') if(_b_.$isinf(x))return float('inf') var y=x if(isinstance(x,float))y=x.valueOf() if(y==0)return y var j=i if(isinstance(i,float))j=i.valueOf() return y * Math.pow(2,j)} $FloatDict.hex=function(self){ var DBL_MANT_DIG=53 var TOHEX_NBITS=DBL_MANT_DIG + 3 -(DBL_MANT_DIG+2)%4; switch(self.valueOf()){case Infinity: case -Infinity: case Number.NaN: case -Number.NaN: return self case -0: return '-0x0.0p0' case 0: return '0x0.0p0'} var _a=_b_.$frexp(_b_.$fabs(self.valueOf())) var _m=_a[0],_e=_a[1] var _shift=1 - Math.max(-1021 - _e,0) _m=_b_.$ldexp(_m,_shift) _e -=_shift var _int2hex='0123456789ABCDEF'.split('') var _s=_int2hex[Math.floor(_m)] _s+='.' _m -=Math.floor(_m) for(var i=0;i <(TOHEX_NBITS-1)/4;i++){_m*=16.0 _s+=_int2hex[Math.floor(_m)] _m-=Math.floor(_m)} var _esign='+' if(_e < 0){_esign='-' _e=-_e} if(self.value < 0)return "-0x" + _s + 'p' + _esign + _e; return "0x" + _s + 'p' + _esign + _e;} $FloatDict.__init__=function(self,value){self=new Number(value)} $FloatDict.__int__=function(self){return parseInt(self)} $FloatDict.is_integer=function(self){return _b_.int(self)==self} $FloatDict.__mod__=function(self,other){ if(other==0){throw ZeroDivisionError('float modulo')} if(isinstance(other,_b_.int))return new Number((self%other+other)%other) if(isinstance(other,float)){ var q=Math.floor(self/other),r=self-other*q return new Number(r)} if(isinstance(other,_b_.bool)){var bool_value=0; if(other.valueOf())bool_value=1; return new Number((self%bool_value+bool_value)%bool_value)} if(hasattr(other,'__rmod__'))return getattr(other,'__rmod__')(self) $err('%',other)} $FloatDict.__mro__=[$ObjectDict] $FloatDict.__mul__=function(self,other){if(isinstance(other,_b_.int)){if(other.__class__==$B.LongInt.$dict){return new Number(self*parseFloat(other.value))} return new Number(self*other)} if(isinstance(other,float))return new Number(self*other) if(isinstance(other,_b_.bool)){var bool_value=0; if(other.valueOf())bool_value=1; return new Number(self*bool_value)} if(isinstance(other,_b_.complex)){return _b_.complex(float(self*other.real),float(self*other.imag))} if(hasattr(other,'__rmul__'))return getattr(other,'__rmul__')(self) $err('*',other)} $FloatDict.__ne__=function(self,other){return !$FloatDict.__eq__(self,other)} $FloatDict.__neg__=function(self,other){return float(-self)} $FloatDict.__pos__=function(self){return self} $FloatDict.__pow__=function(self,other){var other_int=isinstance(other,_b_.int) if(other_int ||isinstance(other,float)){if(self==1){return self} if(other==0){return new Number(1)} if(self==-1 && (!isFinite(other)||other.__class__===$B.LongInt.$dict ||!$B.is_safe_int(other)) && !isNaN(other)){return new Number(1)} else if(self==0 && isFinite(other)&& other<0){throw _b_.ZeroDivisionError("0.0 cannot be raised to a negative power")}else if(self==Number.NEGATIVE_INFINITY && !isNaN(other)){if(other<0 && other%2==1){return new Number(-0.0)}else if(other<0){return new Number(0)} else if(other>0 && other%2==1){return Number.NEGATIVE_INFINITY}else{return Number.POSITIVE_INFINITY}}else if(self==Number.POSITIVE_INFINITY && !isNaN(other)){return other>0 ? self : new Number(0)} if(other==Number.NEGATIVE_INFINITY && !isNaN(self)){return Math.abs(self)<1 ? Number.POSITIVE_INFINITY : new Number(0)}else if(other==Number.POSITIVE_INFINITY && !isNaN(self)){return Math.abs(self)<1 ? new Number(0): Number.POSITIVE_INFINITY} if(self<0 && !_b_.getattr(other,'__eq__')(_b_.int(other))){ return _b_.complex.$dict.__pow__(_b_.complex(self,0),other)} return float(Math.pow(self,other))}else if(isinstance(other,_b_.complex)){var preal=Math.pow(self,other.real),ln=Math.log(self) return _b_.complex(preal*Math.cos(ln),preal*Math.sin(ln))} if(hasattr(other,'__rpow__'))return getattr(other,'__rpow__')(self) $err("** or pow()",other)} $FloatDict.__repr__=$FloatDict.__str__=function(self){if(self===float)return "" if(self.valueOf()==Infinity)return 'inf' if(self.valueOf()==-Infinity)return '-inf' if(isNaN(self.valueOf()))return 'nan' var res=self.valueOf()+'' if(res.indexOf('.')==-1)res+='.0' return _b_.str(res)} $FloatDict.__setattr__=function(self,attr,value){if(self.constructor===Number){if($FloatDict[attr]===undefined){throw _b_.AttributeError("'float' object has no attribute '"+attr+"'")}else{throw _b_.AttributeError("'float' object attribute '"+attr+"' is read-only")}} self[attr]=value return $N} $FloatDict.__truediv__=function(self,other){if(isinstance(other,[_b_.int,float])){if(other.valueOf()==0)throw ZeroDivisionError('division by zero') return float(self/other)} if(isinstance(other,_b_.complex)){var cmod=other.real*other.real+other.imag*other.imag if(cmod==0)throw ZeroDivisionError('division by zero') return _b_.complex(float(self*other.real/cmod),float(-self*other.imag/cmod))} if(hasattr(other,'__rtruediv__'))return getattr(other,'__rtruediv__')(self) $err('/',other)} var $op_func=function(self,other){if(isinstance(other,_b_.int)){if(typeof other=='boolean'){return other ? self-1 : self}else if(other.__class__===$B.LongInt.$dict){return float(self-parseInt(other.value))}else{return float(self-other)}} if(isinstance(other,float))return float(self-other) if(isinstance(other,_b_.bool)){var bool_value=0; if(other.valueOf())bool_value=1; return float(self-bool_value)} if(isinstance(other,_b_.complex)){return _b_.complex(self - other.real,-other.imag)} if(hasattr(other,'__rsub__'))return getattr(other,'__rsub__')(self) $err('-',other)} $op_func +='' var $ops={'+':'add','-':'sub'} for(var $op in $ops){var $opf=$op_func.replace(/-/gm,$op) $opf=$opf.replace(/__rsub__/gm,'__r'+$ops[$op]+'__') eval('$FloatDict.__'+$ops[$op]+'__ = '+$opf)} var $comp_func=function(self,other){if(isinstance(other,_b_.int)){if(other.__class__===$B.LongInt.$dict){return self > parseInt(other.value)} return self > other.valueOf()} if(isinstance(other,float))return self > other if(isinstance(other,_b_.bool)){return self.valueOf()> _b_.bool.$dict.__hash__(other)} if(hasattr(other,'__int__')||hasattr(other,'__index__')){return $IntDict.__gt__(self,$B.$GetInt(other))} var inv_op=getattr(other,'__le__',null) if(inv_op !==null){return inv_op(self)} var inv_op=getattr(other,'__le__',null) if(inv_op !==null){return inv_op(self)} throw _b_.TypeError( 'unorderable types: float() > '+$B.get_class(other).__name__+"()")} $comp_func +='' for(var $op in $B.$comps){eval("$FloatDict.__"+$B.$comps[$op]+'__ = '+ $comp_func.replace(/>/gm,$op). replace(/__gt__/gm,'__'+$B.$comps[$op]+'__'). replace(/__le__/,'__'+$B.$inv_comps[$op]+'__'))} $B.make_rmethods($FloatDict) var $notimplemented=function(self,other){throw _b_.TypeError( "unsupported operand types for OPERATOR: 'float' and '"+ $B.get_class(other).__name__+"'")} $notimplemented +='' for(var $op in $B.$operators){ if($B.augmented_assigns[$op]===undefined){var $opfunc='__'+$B.$operators[$op]+'__' if($FloatDict[$opfunc]===undefined){eval('$FloatDict.'+$opfunc+"="+$notimplemented.replace(/OPERATOR/gm,$op))}}} function $FloatClass(value){return new Number(value)} function to_digits(s){ var arabic_digits='\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669',res='' for(var i=0;i-1){res +=x} else{res +=s[i]}} return res} var float=function(value){switch(value){case undefined: return $FloatClass(0.0) case Number.MAX_VALUE: return $FloatClass(Infinity) case -Number.MAX_VALUE: return $FloatClass(-Infinity)} if(typeof value=="number")return new Number(value) if(isinstance(value,float)){return value} if(isinstance(value,_b_.bytes)){var s=getattr(value,'decode')('latin-1') return float(getattr(value,'decode')('latin-1'))} if(hasattr(value,'__float__')){return $FloatClass(getattr(value,'__float__')())} if(typeof value=='string'){value=value.trim() switch(value.toLowerCase()){case '+inf': case 'inf': case '+infinity': case 'infinity': return Number.POSITIVE_INFINITY case '-inf': case '-infinity': return Number.NEGATIVE_INFINITY case '+nan': case 'nan': return Number.NaN case '-nan': return -Number.NaN case '': throw _b_.ValueError('count not convert string to float') default: value=to_digits(value) if(isFinite(value))return $FloatClass(eval(value)) else{ _b_.str.$dict.encode(value,'latin-1') throw _b_.ValueError("Could not convert to float(): '"+_b_.str(value)+"'")}}} throw _b_.TypeError("float() argument must be a string or a number, not '"+ $B.get_class(value).__name__+"'")} float.__class__=$B.$factory float.$dict=$FloatDict $FloatDict.$factory=float $FloatDict.__new__=$B.$__new__(float) $B.$FloatClass=$FloatClass _b_.float=float})(__BRYTHON__) ;(function($B){eval($B.InjectBuiltins()) var $ObjectDict=_b_.object.$dict,$N=_b_.None function $err(op,other){var msg="unsupported operand type(s) for "+op msg +=": 'int' and '"+$B.get_class(other).__name__+"'" throw _b_.TypeError(msg)} var $IntDict={__class__:$B.$type,__name__:'int',__dir__:$ObjectDict.__dir__,toString:function(){return '$IntDict'},$native:true,descriptors:{'numerator':true,'denominator':true,'imag':true,'real':true}} $IntDict.from_bytes=function(){var $=$B.args("from_bytes",3,{bytes:null,byteorder:null,signed:null},['bytes','byteorder','signed'],arguments,{signed:False},null,null) var x=$.bytes,byteorder=$.byteorder,signed=$.signed var _bytes,_len if(isinstance(x,[_b_.list,_b_.tuple])){_bytes=x _len=len(x)}else if(isinstance(x,[_b_.bytes,_b_.bytearray])){_bytes=x.source _len=x.source.length}else{ _b_.TypeError("Error! " + _b_.type(x)+ " is not supported in int.from_bytes. fix me!")} switch(byteorder){case 'big': var num=_bytes[_len - 1]; var _mult=256 for(var i=(_len - 2);i >=0;i--){ num=$B.add($B.mul(_mult,_bytes[i]),num) _mult=$B.mul(_mult,256)} if(!signed)return num if(_bytes[0]< 128)return num return $B.sub(num,_mult) case 'little': var num=_bytes[0] if(num >=128)num=num - 256 var _mult=256 for(var i=1;i < _len;i++){num=$B.add($B.mul(_mult,_bytes[i]),num) _mult=$B.mul(_mult,256)} if(!signed)return num if(_bytes[_len - 1]< 128)return num return $B.sub(num,_mult)} throw _b_.ValueError("byteorder must be either 'little' or 'big'");} $IntDict.to_bytes=function(length,byteorder,star){ throw _b_.NotImplementedError("int.to_bytes is not implemented yet")} $IntDict.__abs__=function(self){return abs(self)} $IntDict.__bool__=function(self){return new Boolean(self.valueOf())} $IntDict.__ceil__=function(self){return Math.ceil(self)} $IntDict.__class__=$B.$type $IntDict.__divmod__=function(self,other){return divmod(self,other)} $IntDict.__eq__=function(self,other){ if(other===undefined)return self===int if(isinstance(other,int))return self.valueOf()==other.valueOf() if(isinstance(other,_b_.float))return self.valueOf()==other.valueOf() if(isinstance(other,_b_.complex)){if(other.imag !=0)return False return self.valueOf()==other.real} if(hasattr(other,'__eq__'))return getattr(other,'__eq__')(self) return self.valueOf()===other} function preformat(self,fmt){if(fmt.empty){return _b_.str(self)} if(fmt.type && 'bcdoxXn'.indexOf(fmt.type)==-1){throw _b_.ValueError("Unknown format code '"+fmt.type+ "' for object of type 'int'")} switch(fmt.type){case undefined: case 'd': return self.toString() case 'b': return(fmt.alternate ? '0b' : '')+ self.toString(2) case 'c': return _b_.chr(self) case 'o': return(fmt.alternate ? '0o' : '')+ self.toString(8) case 'x': return(fmt.alternate ? '0x' : '')+ self.toString(16) case 'X': return(fmt.alternate ? '0X' : '')+ self.toString(16).toUpperCase() case 'n': return self } return res} $IntDict.__format__=function(self,format_spec){var fmt=new $B.parse_format_spec(format_spec) if(fmt.type && 'eEfFgG%'.indexOf(fmt.type)!=-1){ return _b_.float.$dict.__format__(self,format_spec)} fmt.align=fmt.align ||'>' var res=preformat(self,fmt) if(fmt.comma){var sign=res[0]=='-' ? '-' : '',rest=res.substr(sign.length),len=rest.length,nb=Math.ceil(rest.length/3),chunks=[] for(var i=0;i$B.min_int && res<$B.max_int){return res} else{return int($B.LongInt.$dict.__mul__($B.LongInt(self),$B.LongInt(other)))}} if(isinstance(other,_b_.float)){return new Number(self*other)} if(isinstance(other,_b_.bool)){if(other.valueOf())return self return int(0)} if(isinstance(other,_b_.complex)){return _b_.complex($IntDict.__mul__(self,other.real),$IntDict.__mul__(self,other.imag))} if(isinstance(other,[_b_.list,_b_.tuple])){var res=[] var $temp=other.slice(0,other.length) for(var i=0;i$B.min_int && res<$B.max_int){return res} else{return int($B.LongInt.$dict.__pow__($B.LongInt(self),$B.LongInt(other)))}} if(isinstance(other,_b_.float)){if(self>=0){return new Number(Math.pow(self,other.valueOf()))} else{ return _b_.complex.$dict.__pow__(_b_.complex(self,0),other)}}else if(isinstance(other,_b_.complex)){var preal=Math.pow(self,other.real),ln=Math.log(self) return _b_.complex(preal*Math.cos(ln),preal*Math.sin(ln))} if(hasattr(other,'__rpow__'))return getattr(other,'__rpow__')(self) $err("**",other)} $IntDict.__repr__=function(self){if(self===int)return "" return self.toString()} $IntDict.__rshift__=function(self,other){if(isinstance(other,int)){return int($B.LongInt.$dict.__rshift__($B.LongInt(self),$B.LongInt(other)))} var rrshift=getattr(other,'__rrshift__',null) if(rrshift!==null){return rrshift(self)} $err('>>',other)} $IntDict.__setattr__=function(self,attr,value){if(typeof self=="number"){if($IntDict[attr]===undefined){throw _b_.AttributeError("'int' object has no attribute '"+attr+"'")}else{throw _b_.AttributeError("'int' object attribute '"+attr+"' is read-only")}} self[attr]=value return $N} $IntDict.__str__=$IntDict.__repr__ $IntDict.__truediv__=function(self,other){if(isinstance(other,int)){if(other==0)throw ZeroDivisionError('division by zero') if(other.__class__==$B.LongInt.$dict){return new Number(self/parseInt(other.value))} return new Number(self/other)} if(isinstance(other,_b_.float)){if(!other.valueOf())throw ZeroDivisionError('division by zero') return new Number(self/other)} if(isinstance(other,_b_.complex)){var cmod=other.real*other.real+other.imag*other.imag if(cmod==0)throw ZeroDivisionError('division by zero') return _b_.complex(self*other.real/cmod,-self*other.imag/cmod)} if(hasattr(other,'__rtruediv__'))return getattr(other,'__rtruediv__')(self) $err("/",other)} $IntDict.bit_length=function(self){s=bin(self) s=getattr(s,'lstrip')('-0b') return s.length } $IntDict.numerator=function(self){return self} $IntDict.denominator=function(self){return int(1)} $IntDict.imag=function(self){return int(0)} $IntDict.real=function(self){return self} $B.max_int32=(1<<30)* 2 - 1 $B.min_int32=- $B.max_int32 var $op_func=function(self,other){if(isinstance(other,int)){if(other.__class__===$B.LongInt.$dict){return $B.LongInt.$dict.__sub__($B.LongInt(self),$B.LongInt(other))} if(self > $B.max_int32 ||self < $B.min_int32 || other > $B.max_int32 ||other < $B.min_int32){return $B.LongInt.$dict.__sub__($B.LongInt(self),$B.LongInt(other))} return self-other} if(isinstance(other,_b_.bool))return self-other if(hasattr(other,'__rsub__'))return getattr(other,'__rsub__')(self) $err("-",other)} $op_func +='' var $ops={'&':'and','|':'or','^':'xor'} for(var $op in $ops){var opf=$op_func.replace(/-/gm,$op) opf=opf.replace(new RegExp('sub','gm'),$ops[$op]) eval('$IntDict.__'+$ops[$op]+'__ = '+opf)} var $op_func=function(self,other){if(isinstance(other,int)){if(typeof other=='number'){var res=self.valueOf()-other.valueOf() if(res>=$B.min_int && res<=$B.max_int){return res} else{return $B.LongInt.$dict.__sub__($B.LongInt(self),$B.LongInt(other))}}else if(typeof other=="boolean"){return other ? self-1 : self}else{return $B.LongInt.$dict.__sub__($B.LongInt(self),$B.LongInt(other))}} if(isinstance(other,_b_.float)){return new Number(self-other)} if(isinstance(other,_b_.complex)){return _b_.complex(self-other.real,-other.imag)} if(isinstance(other,_b_.bool)){var bool_value=0; if(other.valueOf())bool_value=1; return self-bool_value} if(isinstance(other,_b_.complex)){return _b_.complex(self.valueOf()- other.real,other.imag)} if(hasattr(other,'__rsub__'))return getattr(other,'__rsub__')(self) throw $err('-',other)} $op_func +='' var $ops={'+':'add','-':'sub'} for(var $op in $ops){var opf=$op_func.replace(/-/gm,$op) opf=opf.replace(new RegExp('sub','gm'),$ops[$op]) eval('$IntDict.__'+$ops[$op]+'__ = '+opf)} var $comp_func=function(self,other){if(other.__class__===$B.LongInt.$dict){return $B.LongInt.$dict.__lt__(other,$B.LongInt(self))} if(isinstance(other,int))return self.valueOf()> other.valueOf() if(isinstance(other,_b_.float))return self.valueOf()> other.valueOf() if(isinstance(other,_b_.bool)){return self.valueOf()> _b_.bool.$dict.__hash__(other)} if(hasattr(other,'__int__')||hasattr(other,'__index__')){return $IntDict.__gt__(self,$B.$GetInt(other))} var inv_op=getattr(other,'__lt__',null) if(inv_op !==null){return inv_op(self)} throw _b_.TypeError( "unorderable types: int() > "+$B.get_class(other).__name__+"()")} $comp_func +='' for(var $op in $B.$comps){eval("$IntDict.__"+$B.$comps[$op]+'__ = '+ $comp_func.replace(/>/gm,$op). replace(/__gt__/gm,'__'+$B.$comps[$op]+'__'). replace(/__lt__/,'__'+$B.$inv_comps[$op]+'__'))} $B.make_rmethods($IntDict) var $valid_digits=function(base){var digits='' if(base===0)return '0' if(base < 10){for(var i=0;i < base;i++)digits+=String.fromCharCode(i+48) return digits} var digits='0123456789' for(var i=10;i < base;i++)digits+=String.fromCharCode(i+55) return digits} var int=function(value,base){ if(value===undefined){return 0} if(typeof value=='number' && (base===undefined ||base==10)){return parseInt(value)} if(base!==undefined){if(!isinstance(value,[_b_.str,_b_.bytes,_b_.bytearray])){throw TypeError("int() can't convert non-string with explicit base")}} if(isinstance(value,_b_.complex)){throw TypeError("can't convert complex to int")} var $ns=$B.args('int',2,{x:null,base:null},['x','base'],arguments,{'base':10},'null','null') var value=$ns['x'] var base=$ns['base'] if(isinstance(value,_b_.float)&& base===10){if(value<$B.min_int ||value>$B.max_int){return $B.LongInt.$dict.$from_float(value)} else{return value>0 ? Math.floor(value): Math.ceil(value)}} if(!(base >=2 && base <=36)){ if(base !=0)throw _b_.ValueError("invalid base")} if(typeof value=='number'){if(base==10){if(value < $B.min_int ||value > $B.max_int)return $B.LongInt(value) return value}else if(value.toString().search('e')>-1){ throw _b_.OverflowError("can't convert to base "+base)}else{var res=parseInt(value,base) if(res < $B.min_int ||res > $B.max_int)return $B.LongInt(value,base) return res}} if(value===true)return Number(1) if(value===false)return Number(0) if(value.__class__===$B.LongInt.$dict){var z=parseInt(value.value) if(z>$B.min_int && z<$B.max_int){return z} else{return value}} base=$B.$GetInt(base) if(isinstance(value,_b_.str))value=value.valueOf() if(typeof value=="string"){var _value=value.trim() if(_value.length==2 && base==0 &&(_value=='0b' ||_value=='0o' ||_value=='0x')){throw _b_.ValueError('invalid value')} if(_value.length >2){var _pre=_value.substr(0,2).toUpperCase() if(base==0){if(_pre=='0B')base=2 if(_pre=='0O')base=8 if(_pre=='0X')base=16} if(_pre=='0B' ||_pre=='0O' ||_pre=='0X'){_value=_value.substr(2)}} var _digits=$valid_digits(base) var _re=new RegExp('^[+-]?['+_digits+']+$','i') if(!_re.test(_value)){throw _b_.ValueError( "invalid literal for int() with base "+base +": '"+_b_.str(value)+"'")} if(base <=10 && !isFinite(value)){throw _b_.ValueError( "invalid literal for int() with base "+base +": '"+_b_.str(value)+"'")} var res=parseInt(_value,base) if(res < $B.min_int ||res > $B.max_int)return $B.LongInt(_value,base) return res} if(isinstance(value,[_b_.bytes,_b_.bytearray])){var _digits=$valid_digits(base) for(var i=0;i=0;i--){iself-- if(iself<0){sv=0}else{sv=parseInt(v1.charAt(iself))} x=(carry+sv+parseInt(v2.charAt(i))).toString() if(x.length==2){res=x.charAt(1)+res;carry=parseInt(x.charAt(0))} else{res=x+res;carry=0}} while(iself>0){iself-- x=(carry+parseInt(v1.charAt(iself))).toString() if(x.length==2){res=x.charAt(1)+res;carry=parseInt(x.charAt(0))} else{res=x+res;carry=0}} if(carry){res=carry+res} return{__class__:$LongIntDict,value:res,pos:true}} function check_shift(shift){ if(!isinstance(shift,LongInt)){throw TypeError("shift must be int, not '"+ $B.get_class(shift).__name__+"'")} if(!shift.pos){throw ValueError("negative shift count")}} function clone(obj){ var obj1={} for(var attr in obj){obj1[attr]=obj[attr]} return obj1} function comp_pos(v1,v2){ if(v1.length>v2.length){return 1} else if(v1.lengthv2){return 1} else if(v1=0;i--){i1-- sv=parseInt(v1.charAt(i1)) x=(sv-carry-parseInt(v2.charAt(i))) if(x<0){res=(10+x)+res;carry=1} else{res=x+res;carry=0}} while(i1>0){i1-- x=(parseInt(v1.charAt(i1))-carry) if(x<0){res=(10+x)+res;carry=1} else{res=x+res;carry=0}} while(res.charAt(0)=='0' && res.length>1){res=res.substr(1)} return{__class__:$LongIntDict,value:res,pos:true}} $LongIntDict.$from_float=function(value){var s=Math.abs(value).toString(),v=s if(s.search('e')>-1){var t=/-?(\d)(\.\d+)?e([+-])(\d*)/.exec(s),n1=t[1],n2=t[2],pos=t[3],exp=t[4] if(pos=='+'){if(n2===undefined){v=n1+'0'.repeat(exp-1)}else{v=n1+n2+'0'.repeat(exp-1-n2.length)}}} return{__class__:$LongIntDict,value: v,pos: value >=0}} $LongIntDict.__abs__=function(self){return{__class__:$LongIntDict,value: self.value,pos:true}} $LongIntDict.__add__=function(self,other){if(isinstance(other,_b_.float)){return _b_.float(parseInt(self.value)+other.value)} if(typeof other=='number')other=LongInt(_b_.str(other)) var res if(self.pos&&other.pos){ return add_pos(self.value,other.value)}else if(!self.pos&&!other.pos){ res=add_pos(self.value,other.value) res.pos=false return intOrLong(res)}else if(self.pos && !other.pos){ switch(comp_pos(self.value,other.value)){case 1: res=sub_pos(self.value,other.value) break case 0: res={__class__:$LongIntDict,value:0,pos:true} break case -1: res=sub_pos(other.value,self.value) res.pos=false break} return intOrLong(res)}else{ switch(comp_pos(self.value,other.value)){case 1: res=sub_pos(self.value,other.value) res.pos=false break case 0: res={__class__:$LongIntDict,value:0,pos:true} break case -1: res=sub_pos(other.value,self.value) break} return intOrLong(res)}} $LongIntDict.__and__=function(self,other){if(typeof other=='number')other=LongInt(_b_.str(other)) var v1=$LongIntDict.__index__(self) var v2=$LongIntDict.__index__(other) if(v1.lengthother.value.length){return self.pos} else if(self.value.length=other.value : self.value <=other.value}} $LongIntDict.__gt__=function(self,other){return !$LongIntDict.__le__(self,other)} $LongIntDict.__index__=function(self){ var res='',temp=self.value,d while(true){d=divmod_pos(temp,'2') res=d[1].value + res temp=d[0].value if(temp=='0'){break}} return intOrLong(res)} $LongIntDict.__invert__=function(self){return $LongIntDict.__sub__(LongInt('-1'),self)} $LongIntDict.__le__=function(self,other){if(typeof other=='number')other=LongInt(_b_.str(other)) if(self.pos !==other.pos){return !self.pos} if(self.value.length>other.value.length){return !self.pos} else if(self.value.length=other.value}} $LongIntDict.__lt__=function(self,other){return !$LongIntDict.__ge__(self,other)} $LongIntDict.__lshift__=function(self,shift){var is_long=shift.__class__==$LongIntDict if(is_long){var shift_value=parseInt(shift.value) if(shift_value<0){throw _b_.ValueError('negative shift count')} if(shift_value < $B.max_int){shift_safe=true;shift=shift_value}} if(shift_safe){if(shift_value==0){return self}}else{shift=LongInt(shift) if(shift.value=='0'){return self}} var res=self.value while(true){var x,carry=0,res1='' for(var i=res.length-1;i>=0;i--){x=(carry+parseInt(res.charAt(i))*2).toString() if(x.length==2){res1=x.charAt(1)+res1;carry=parseInt(x.charAt(0))} else{res1=x+res1;carry=0}} if(carry){res1=carry+res1} res=res1 if(shift_safe){shift-- if(shift==0){break}}else{shift=sub_pos(shift.value,'1') if(shift.value=='0'){break}}} return intOrLong({__class__:$LongIntDict,value:res,pos:self.pos})} $LongIntDict.__mod__=function(self,other){return intOrLong($LongIntDict.__divmod__(self,other)[1])} $LongIntDict.__mro__=[_b_.int.$dict,_b_.object.$dict] $LongIntDict.__mul__=function(self,other){switch(self){case Number.NEGATIVE_INFINITY: case Number.POSITIVE_INFINITY: var eq=_b_.getattr(other,'__eq__') if(eq(0)){return NaN} else if(_b_.getattr(other,'__gt__')(0)){return self} else{return -self}} if(isinstance(other,_b_.float)){return _b_.float(parseInt(self.value)*other)} if(typeof other=='number')other=LongInt(_b_.str(other)) var res=mul_pos(self.value,other.value) if(self.pos==other.pos){return intOrLong(res)} res.pos=false return intOrLong(res)} $LongIntDict.__neg__=function(obj){return{__class__:$LongIntDict,value:obj.value,pos:!obj.pos}} $LongIntDict.__or__=function(self,other){other=LongInt(other) var v1=$LongIntDict.__index__(self) var v2=$LongIntDict.__index__(other) if(v1.length0){var dm=divmod_pos(v,base.toString()) res=parseInt(dm[1].value).toString(base)+res v=dm[0].value if(v==0){break}} return res} function digits(base){ var is_digits={} for(var i=0;i10){ for(var i=0;iMIN_SAFE_INTEGER && v2){throw _b_.TypeError("LongInt takes at most 2 arguments ("+ arguments.length+" given)")} if(base===undefined){base=10} else if(!isinstance(base,int)){throw TypeError("'"+$B.get_class(base).__name__+"' object cannot be interpreted as an integer")} if(base<0 ||base==1 ||base>36){throw ValueError("LongInt() base must be >= 2 and <= 36")} if(isinstance(value,_b_.float)){if(value===Number.POSITIVE_INFINITY ||value===Number.NEGATIVE_INFINITY){return value} if(value>=0){value=new Number(Math.round(value.value))} else{value=new Number(Math.ceil(value.value))}}else if(isinstance(value,_b_.bool)){if(value.valueOf())return int(1) return int(0)} if(typeof value=='number'){if(isSafeInteger(value)){value=value.toString()} else if(value.constructor==Number){console.log('big number',value);value=value.toString()} else{console.log('wrong value',value);throw ValueError("argument of long_int is not a safe integer")}}else if(value.__class__===$LongIntDict){return value} else if(isinstance(value,_b_.bool)){value=_b_.bool.$dict.__int__(value)+''} else if(typeof value!='string'){throw ValueError("argument of long_int must be a string, not "+ $B.get_class(value).__name__)} var has_prefix=false,pos=true,start=0 while(value.charAt(0)==' ' && value.length){value=value.substr(1)} while(value.charAt(value.length-1)==' ' && value.length){value=value.substr(0,value.length-1)} if(value.charAt(0)=='+'){has_prefix=true} else if(value.charAt(0)=='-'){has_prefix=true;pos=false} if(has_prefix){ if(value.length==1){ throw ValueError('LongInt argument is not a valid number: "'+value+'"')}else{value=value.substr(1)}} while(start=0)return '('+self.real+'+'+self.imag+'j)' return '('+self.real+'-'+(-self.imag)+'j)'} $ComplexDict.__sqrt__=function(self){if(self.imag==0)return complex(Math.sqrt(self.real)) var r=self.real,i=self.imag,_a=Math.sqrt((r + sqrt)/2),_b=Number.sign(i)* Math.sqrt((-r + sqrt)/2) return complex(_a,_b)} $ComplexDict.__truediv__=function(self,other){if(isinstance(other,complex)){if(other.real==0 && other.imag==0){throw ZeroDivisionError('division by zero')} var _num=self.real*other.real + self.imag*other.imag var _div=other.real*other.real + other.imag*other.imag var _num2=self.imag*other.real - self.real*other.imag return complex(_num/_div,_num2/_div)} if(isinstance(other,_b_.int)){if(!other.valueOf())throw ZeroDivisionError('division by zero') return $ComplexDict.__truediv__(self,complex(other.valueOf()))} if(isinstance(other,_b_.float)){if(!other.value)throw ZeroDivisionError('division by zero') return $ComplexDict.__truediv__(self,complex(other.value))} $UnsupportedOpType("//","complex",other.__class__)} var $op_func=function(self,other){throw _b_.TypeError("TypeError: unsupported operand type(s) for -: 'complex' and '" + $B.get_class(other).__name__+"'")} $op_func +='' var $ops={'&':'and','|':'ior','<<':'lshift','>>':'rshift','^':'xor'} for(var $op in $ops){eval('$ComplexDict.__'+$ops[$op]+'__ = '+$op_func.replace(/-/gm,$op))} $ComplexDict.__ior__=$ComplexDict.__or__ var $op_func=function(self,other){if(isinstance(other,complex))return complex(self.real-other.real,self.imag-other.imag) if(isinstance(other,_b_.int))return complex($B.sub(self.real,other.valueOf()),self.imag) if(isinstance(other,_b_.float))return complex(self.real - other.value,self.imag) if(isinstance(other,_b_.bool)){var bool_value=0; if(other.valueOf())bool_value=1; return complex(self.real - bool_value,self.imag)} throw _b_.TypeError("unsupported operand type(s) for -: "+self.__repr__()+ " and '"+$B.get_class(other).__name__+"'")} $ComplexDict.__sub__=$op_func $op_func +='' $op_func=$op_func.replace(/-/gm,'+').replace(/sub/gm,'add') eval('$ComplexDict.__add__ = '+$op_func) var $comp_func=function(self,other){throw _b_.TypeError("TypeError: unorderable types: complex() > " + $B.get_class(other).__name__ + "()")} $comp_func +='' for(var $op in $B.$comps){eval("$ComplexDict.__"+$B.$comps[$op]+'__ = '+$comp_func.replace(/>/gm,$op))} $B.make_rmethods($ComplexDict) $ComplexDict.real=function(self){return new Number(self.real)} $ComplexDict.imag=function(self){return new Number(self.imag)} var complex_re=/^(\d*\.?\d*)([\+\-]?)(\d*\.?\d*)(j?)$/ var complex=function(real,imag){if(typeof real=='string'){if(imag!==undefined){throw _b_.TypeError("complex() can't take second arg if first is a string")} var parts=complex_re.exec(real) if(parts===null){throw _b_.ValueError("complex() arg is a malformed string")}else if(parts[1]=='.' ||parts[3]=='.'){throw _b_.ValueError("complex() arg is a malformed string")}else if(parts[4]=='j'){if(parts[2]==''){real=0;imag=parseFloat(parts[1])}else{real=parseFloat(parts[1]) imag=parts[3]=='' ? 1 : parseFloat(parts[3]) imag=parts[2]=='-' ? -imag : imag}}else{real=parseFloat(parts[1]) imag=0}} var res={__class__:$ComplexDict,real:real ||0,imag:imag ||0} res.__repr__=res.__str__=function(){if(real==0)return imag + 'j' return '('+real+'+'+imag+'j)'} return res} complex.$dict=$ComplexDict complex.__class__=$B.$factory $ComplexDict.$factory=complex $B.set_func_names($ComplexDict) _b_.complex=complex})(__BRYTHON__) ;(function($B){eval($B.InjectBuiltins()) var $ObjectDict=_b_.object.$dict,$N=_b_.None function $list(){ var args=[],pos=0 for(var i=0,_len_i=arguments.length;i < _len_i;i++){args[pos++]=arguments[i]} return new $ListDict(args)} var $ListDict={__class__:$B.$type,__name__:'list',$native:true,__dir__:$ObjectDict.__dir__} $ListDict.__add__=function(self,other){if($B.get_class(self)!==$B.get_class(other)){throw TypeError('can only concatenate list (not "'+ $B.get_class(other).__name__+'") to list')} var res=self.valueOf().concat(other.valueOf()) if(isinstance(self,tuple))res=tuple(res) return res} $ListDict.__contains__=function(self,item){var $=$B.args('__contains__',2,{self:null,item:null},['self','item'],arguments,{},null,null),self=$.self,item=$.item var _eq=getattr(item,'__eq__') var i=self.length while(i--){if(_eq(self[i]))return true} return false} $ListDict.__delitem__=function(self,arg){if(isinstance(arg,_b_.int)){var pos=arg if(arg<0)pos=self.length+pos if(pos>=0 && pos0 ? 0 : self.length} var stop=arg.stop if(stop===None){stop=step >0 ? self.length : 0} if(start<0)start=self.length+start if(stop<0)stop=self.length+stop var res=[],i=null,pos=0 if(step>0){if(stop>start){for(var i=start;istop;i+=step){if(self[i]!==undefined){res[pos++]=i}} res.reverse()}} var i=res.length while(i--){ self.splice(res[i],1)} return $N} if(hasattr(arg,'__int__')||hasattr(arg,'__index__')){$ListDict.__delitem__(self,_b_.int(arg)) return $N} throw _b_.TypeError('list indices must be integer, not '+_b_.str(arg.__class__))} $ListDict.__eq__=function(self,other){if(isinstance(other,$B.get_class(self).$factory)){if(other.length==self.length){var i=self.length while(i--){if(!getattr(self[i],'__eq__')(other[i]))return false} return true}} return false} $ListDict.__getitem__=function(self,arg){var $=$B.args('__getitem__',2,{self:null,key:null},['self','key'],arguments,{},null,null),self=$.self,key=$.key var klass=$B.get_class(self).$factory if(isinstance(key,_b_.int)){var items=self.valueOf() var pos=key if(key<0)pos=items.length+pos if(pos>=0 && pos 0){if(stop <=start)return res; for(var i=start;i start)return res; for(var i=start;i>stop;i+=step){res[pos++]=items[i]} return klass(res);}} if(hasattr(key,'__int__')||hasattr(key,'__index__')){return $ListDict.__getitem__(self,_b_.int(key))} throw _b_.TypeError('list indices must be integer, not '+ $B.get_class(key).__name__)} $ListDict.__ge__=function(self,other){if(!isinstance(other,[list,_b_.tuple])){throw _b_.TypeError("unorderable types: list() >= "+ $B.get_class(other).__name__+'()')} var i=0 while(i=other.length)return true if(getattr(self[i],'__eq__')(other[i])){i++} else return(getattr(self[i],"__ge__")(other[i]))} return other.length==self.length} $ListDict.__gt__=function(self,other){if(!isinstance(other,[list,_b_.tuple])){throw _b_.TypeError("unorderable types: list() > "+ $B.get_class(other).__name__+'()')} var i=0 while(i=other.length)return true if(getattr(self[i],'__eq__')(other[i])){i++} else return(getattr(self[i],'__gt__')(other[i]))} return false} $ListDict.__hash__=None $ListDict.__iadd__=function(){var $=$B.args('__iadd__',2,{self:null,x:null},['self','x'],arguments,{},null,null) var x=list(iter($.x)) for(var i=0;i < x.length;i++){$.self.push(x[i])} return $.self} $ListDict.__imul__=function(){var $=$B.args('__imul__',2,{self:null,x:null},['self','x'],arguments,{},null,null) var x=$B.$GetInt($.x),len=$.self.length,pos=len if(x==0){$ListDict.clear($.self);return $.self} for(var i=1;i < x;i++){for(j=0;j" var _r=[] for(var i=0;i=0 && posbegin){var pivot=begin+Math.floor(Math.random()*(end-begin)) pivot=$partition(arg,array,begin,end,pivot); $qsort(arg,array,begin,pivot); $qsort(arg,array,pivot+1,end);}} function $elts_class(self){ if(self.length==0){return null} var cl=$B.get_class(self[0]),i=self.length while(i--){ if($B.get_class(self[i])!==cl)return false} return cl} $ListDict.sort=function(self){var $=$B.args('sort',1,{self:null},['self'],arguments,{},null,'kw') var func=null var reverse=false var kw_args=$.kw,keys=_b_.list(_b_.dict.$dict.keys(kw_args)) for(var i=0;i0){var args=[arguments[0].$t] var pos=1 for(var i=1,_len_i=arguments.length;i < _len_i;i++){args[pos++]=arguments[i]}} return $ListDict[attr].apply(null,args)}})($attr)}} $ListSubclassDict.__mro__=[$ObjectDict] $B.$ListSubclassFactory={__class__:$B.$factory,$dict:$ListSubclassDict} function $tuple(arg){return arg} var $TupleDict={__class__:$B.$type,__name__:'tuple',$native:true} $TupleDict.__iter__=function(self){return $B.$iterator(self,$tuple_iterator)} var $tuple_iterator=$B.$iterator_class('tuple_iterator') function tuple(){var obj=list.apply(null,arguments) obj.__class__=$TupleDict return obj} tuple.__class__=$B.$factory tuple.$dict=$TupleDict tuple.$is_func=true $TupleDict.$factory=tuple $TupleDict.__new__=$B.$__new__(tuple) tuple.__module__='builtins' for(var attr in $ListDict){switch(attr){case '__delitem__': case '__iadd__': case '__imul__': case '__setitem__': case 'append': case 'extend': case 'insert': case 'remove': case 'pop': case 'reverse': case 'sort': break default: if($TupleDict[attr]===undefined){if(typeof $ListDict[attr]=='function'){$TupleDict[attr]=(function(x){return function(){return $ListDict[x].apply(null,arguments)}})(attr)}else{$TupleDict[attr]=$ListDict[attr]}}}} $TupleDict.__delitem__=function(){throw _b_.TypeError("'tuple' object doesn't support item deletion")} $TupleDict.__setitem__=function(){throw _b_.TypeError("'tuple' object does not support item assignment")} $TupleDict.__eq__=function(self,other){ if(other===undefined)return self===tuple return $ListDict.__eq__(self,other)} function c_mul(a,b){s=((parseInt(a)* b)& 0xFFFFFFFF).toString(16) return parseInt(s.substr(0,s.length-1),16)} $TupleDict.__hash__=function(self){ var x=0x3456789 for(var i=0,_len_i=self.length;i < _len_i;i++){var y=_b_.hash(self[i]); x=c_mul(1000003,x)^ y & 0xFFFFFFFF;} return x} $TupleDict.__mro__=[$ObjectDict] $TupleDict.__name__='tuple' $B.set_func_names($TupleDict) _b_.list=list _b_.tuple=tuple _b_.object.$dict.__bases__=tuple()})(__BRYTHON__) ;(function($B){ eval($B.InjectBuiltins()) DEFAULT_MIN_MERGE=32; DEFAULT_MIN_GALLOPING=7; DEFAULT_TMP_STORAGE_LENGTH=256; POWERS_OF_TEN=[1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9] function log10(x){if(x < 1e5){if(x < 1e2){return x < 1e1 ? 0 : 1;} if(x < 1e4){return x < 1e3 ? 2 : 3;} return 4;} if(x < 1e7){return x < 1e6 ? 5 : 6;} if(x < 1e9){return x < 1e8 ? 7 : 8;} return 9;} function alphabeticalCompare(a,b){if(a===b){return 0;} if(~~a===a && ~~b===b){if(a===0 ||b===0){return a < b ? -1 : 1;} if(a < 0 ||b < 0){if(b >=0){return -1;} if(a >=0){return 1;} a=-a; b=-b;} al=log10(a); bl=log10(b); var t=0; if(al < bl){a *=POWERS_OF_TEN[bl - al - 1]; b /=10; t=-1;}else if(al > bl){b *=POWERS_OF_TEN[al - bl - 1]; a /=10; t=1;} if(a===b){return t;} return a < b ? -1 : 1;} var aStr=String(a); var bStr=String(b); if(aStr===bStr){return 0;} return aStr < bStr ? -1 : 1;} function minRunLength(n){var r=0; while(n >=DEFAULT_MIN_MERGE){r |=(n & 1); n >>=1;} return n + r;} function makeAscendingRun(array,lo,hi,compare){var runHi=lo + 1; if(runHi===hi){return 1;} if(compare(array[runHi++],array[lo])< 0){while(runHi < hi && compare(array[runHi],array[runHi - 1])< 0){runHi++;} reverseRun(array,lo,runHi);}else{ while(runHi < hi && compare(array[runHi],array[runHi - 1])>=0){runHi++;}} return runHi - lo;} function reverseRun(array,lo,hi){hi--; while(lo < hi){var t=array[lo]; array[lo++]=array[hi]; array[hi--]=t;}} function binaryInsertionSort(array,lo,hi,start,compare){if(start===lo){start++;} for(;start < hi;start++){var pivot=array[start]; var left=lo; var right=start; while(left < right){var mid=(left + right)>>> 1; if(compare(pivot,array[mid])< 0){right=mid;}else{ left=mid + 1;}} var n=start - left; switch(n){case 3: array[left + 3]=array[left + 2]; case 2: array[left + 2]=array[left + 1]; case 1: array[left + 1]=array[left]; break; default: while(n > 0){array[left + n]=array[left + n - 1]; n--;}} array[left]=pivot;}} function gallopLeft(value,array,start,length,hint,compare){var lastOffset=0; var maxOffset=0; var offset=1; if(compare(value,array[start + hint])> 0){maxOffset=length - hint; while(offset < maxOffset && compare(value,array[start + hint + offset])> 0){lastOffset=offset; offset=(offset << 1)+ 1; if(offset <=0){offset=maxOffset;}} if(offset > maxOffset){offset=maxOffset;} lastOffset +=hint; offset +=hint;}else{ maxOffset=hint + 1; while(offset < maxOffset && compare(value,array[start + hint - offset])<=0){lastOffset=offset; offset=(offset << 1)+ 1; if(offset <=0){offset=maxOffset;}} if(offset > maxOffset){offset=maxOffset;} var tmp=lastOffset; lastOffset=hint - offset; offset=hint - tmp;} lastOffset++; while(lastOffset < offset){var m=lastOffset +((offset - lastOffset)>>> 1); if(compare(value,array[start + m])> 0){lastOffset=m + 1;}else{ offset=m;}} return offset;} function gallopRight(value,array,start,length,hint,compare){var lastOffset=0; var maxOffset=0; var offset=1; if(compare(value,array[start + hint])< 0){maxOffset=hint + 1; while(offset < maxOffset && compare(value,array[start + hint - offset])< 0){lastOffset=offset; offset=(offset << 1)+ 1; if(offset <=0){offset=maxOffset;}} if(offset > maxOffset){offset=maxOffset;} var tmp=lastOffset; lastOffset=hint - offset; offset=hint - tmp;}else{ maxOffset=length - hint; while(offset < maxOffset && compare(value,array[start + hint + offset])>=0){lastOffset=offset; offset=(offset << 1)+ 1; if(offset <=0){offset=maxOffset;}} if(offset > maxOffset){offset=maxOffset;} lastOffset +=hint; offset +=hint;} lastOffset++; while(lastOffset < offset){var m=lastOffset +((offset - lastOffset)>>> 1); if(compare(value,array[start + m])< 0){offset=m;}else{ lastOffset=m + 1;}} return offset;} TimSort=function(array,compare){self={array:array,compare:compare,minGallop:DEFAULT_MIN_GALLOPING,length : array.length,tmpStorageLength:DEFAULT_TMP_STORAGE_LENGTH,stackLength:0,runStart:null,runLength:null,stackSize:0, pushRun: function(runStart,runLength){this.runStart[this.stackSize]=runStart; this.runLength[this.stackSize]=runLength; this.stackSize +=1;}, mergeRuns: function(){while(this.stackSize > 1){var n=this.stackSize - 2; if((n >=1 && this.runLength[n - 1]<=this.runLength[n]+ this.runLength[n + 1])|| (n >=2 && this.runLength[n - 2]<=this.runLength[n]+ this.runLength[n - 1])){if(this.runLength[n - 1]< this.runLength[n + 1]){n--;}}else if(this.runLength[n]> this.runLength[n + 1]){break;} this.mergeAt(n);}}, forceMergeRuns: function(){while(this.stackSize > 1){var n=this.stackSize - 2; if(n > 0 && this.runLength[n - 1]< this.runLength[n + 1]){n--;} this.mergeAt(n);}}, mergeAt: function(i){var compare=this.compare; var array=this.array; var start1=this.runStart[i]; var length1=this.runLength[i]; var start2=this.runStart[i + 1]; var length2=this.runLength[i + 1]; this.runLength[i]=length1 + length2; if(i===this.stackSize - 3){this.runStart[i + 1]=this.runStart[i + 2]; this.runLength[i + 1]=this.runLength[i + 2];} this.stackSize--; var k=gallopRight(array[start2],array,start1,length1,0,compare); start1 +=k; length1 -=k; if(length1===0){return;} length2=gallopLeft(array[start1 + length1 - 1],array,start2,length2,length2 - 1,compare); if(length2===0){return;} if(length1 <=length2){this.mergeLow(start1,length1,start2,length2);}else{ this.mergeHigh(start1,length1,start2,length2);}}, mergeLow: function(start1,length1,start2,length2){var compare=this.compare; var array=this.array; var tmp=this.tmp; var i=0; for(i=0;i < length1;i++){tmp[i]=array[start1 + i];} var cursor1=0; var cursor2=start2; var dest=start1; array[dest++]=array[cursor2++]; if(--length2===0){for(i=0;i < length1;i++){array[dest + i]=tmp[cursor1 + i];} return;} if(length1===1){for(i=0;i < length2;i++){array[dest + i]=array[cursor2 + i];} array[dest + length2]=tmp[cursor1]; return;} var minGallop=this.minGallop; while(true){var count1=0; var count2=0; var exit=false; do{ if(compare(array[cursor2],tmp[cursor1])< 0){array[dest++]=array[cursor2++]; count2++; count1=0; if(--length2===0){exit=true; break;}}else{ array[dest++]=tmp[cursor1++]; count1++; count2=0; if(--length1===1){exit=true; break;}}}while((count1 |count2)< minGallop); if(exit){break;} do{ count1=gallopRight(array[cursor2],tmp,cursor1,length1,0,compare); if(count1 !==0){for(i=0;i < count1;i++){array[dest + i]=tmp[cursor1 + i];} dest +=count1; cursor1 +=count1; length1 -=count1; if(length1 <=1){exit=true; break;}} array[dest++]=array[cursor2++]; if(--length2===0){exit=true; break;} count2=gallopLeft(tmp[cursor1],array,cursor2,length2,0,compare); if(count2 !==0){for(i=0;i < count2;i++){array[dest + i]=array[cursor2 + i];} dest +=count2; cursor2 +=count2; length2 -=count2; if(length2===0){exit=true; break;}} array[dest++]=tmp[cursor1++]; if(--length1===1){exit=true; break;} minGallop--;}while(count1 >=DEFAULT_MIN_GALLOPING ||count2 >=DEFAULT_MIN_GALLOPING); if(exit){break;} if(minGallop < 0){minGallop=0;} minGallop +=2;} this.minGallop=minGallop; if(minGallop < 1){this.minGallop=1;} if(length1===1){for(i=0;i < length2;i++){array[dest + i]=array[cursor2 + i];} array[dest + length2]=tmp[cursor1];}else if(length1===0){throw new Error('mergeLow preconditions were not respected');}else{ for(i=0;i < length1;i++){array[dest + i]=tmp[cursor1 + i];}}}, mergeHigh: function(start1,length1,start2,length2){var compare=this.compare; var array=this.array; var tmp=this.tmp; var i=0; for(i=0;i < length2;i++){tmp[i]=array[start2 + i];} var cursor1=start1 + length1 - 1; var cursor2=length2 - 1; var dest=start2 + length2 - 1; var customCursor=0; var customDest=0; array[dest--]=array[cursor1--]; if(--length1===0){customCursor=dest -(length2 - 1); for(i=0;i < length2;i++){array[customCursor + i]=tmp[i];} return;} if(length2===1){dest -=length1; cursor1 -=length1; customDest=dest + 1; customCursor=cursor1 + 1; for(i=length1 - 1;i >=0;i--){array[customDest + i]=array[customCursor + i];} array[dest]=tmp[cursor2]; return;} var minGallop=this.minGallop; while(true){var count1=0; var count2=0; var exit=false; do{ if(compare(tmp[cursor2],array[cursor1])< 0){array[dest--]=array[cursor1--]; count1++; count2=0; if(--length1===0){exit=true; break;}}else{ array[dest--]=tmp[cursor2--]; count2++; count1=0; if(--length2===1){exit=true; break;}}}while((count1 |count2)< minGallop); if(exit){break;} do{ count1=length1 - gallopRight(tmp[cursor2],array,start1,length1,length1 - 1,compare); if(count1 !==0){dest -=count1; cursor1 -=count1; length1 -=count1; customDest=dest + 1; customCursor=cursor1 + 1; for(i=count1 - 1;i >=0;i--){array[customDest + i]=array[customCursor + i];} if(length1===0){exit=true; break;}} array[dest--]=tmp[cursor2--]; if(--length2===1){exit=true; break;} count2=length2 - gallopLeft(array[cursor1],tmp,0,length2,length2 - 1,compare); if(count2 !==0){dest -=count2; cursor2 -=count2; length2 -=count2; customDest=dest + 1; customCursor=cursor2 + 1; for(i=0;i < count2;i++){array[customDest + i]=tmp[customCursor + i];} if(length2 <=1){exit=true; break;}} array[dest--]=array[cursor1--]; if(--length1===0){exit=true; break;} minGallop--;}while(count1 >=DEFAULT_MIN_GALLOPING ||count2 >=DEFAULT_MIN_GALLOPING); if(exit){break;} if(minGallop < 0){minGallop=0;} minGallop +=2;} this.minGallop=minGallop; if(minGallop < 1){this.minGallop=1;} if(length2===1){dest -=length1; cursor1 -=length1; customDest=dest + 1; customCursor=cursor1 + 1; for(i=length1 - 1;i >=0;i--){array[customDest + i]=array[customCursor + i];} array[dest]=tmp[cursor2];}else if(length2===0){throw new Error('mergeHigh preconditions were not respected');}else{ customCursor=dest -(length2 - 1); for(i=0;i < length2;i++){array[customCursor + i]=tmp[i];}}}} if(self.length < 2 * DEFAULT_TMP_STORAGE_LENGTH){self.tmpStorageLength=self.length >>> 1;} self.tmp=new Array(self.tmpStorageLength); self.stackLength= (self.length < 120 ? 5 : self.length < 1542 ? 10 : self.length < 119151 ? 19 : 40); self.runStart=new Array(self.stackLength); self.runLength=new Array(self.stackLength); return self;} function tim_sort(array,compare,lo,hi){if(!Array.isArray(array)){throw new TypeError('Can only sort arrays');} if(!compare){compare=alphabeticalCompare;}else if(typeof compare !=='function'){hi=lo; lo=compare; compare=alphabeticalCompare;} if(!lo){lo=0;} if(!hi){hi=array.length;} var remaining=hi - lo; if(remaining < 2){return;} var runLength=0; if(remaining < DEFAULT_MIN_MERGE){runLength=makeAscendingRun(array,lo,hi,compare); binaryInsertionSort(array,lo,hi,lo + runLength,compare); return;} var ts=new TimSort(array,compare); var minRun=minRunLength(remaining); do{ runLength=makeAscendingRun(array,lo,hi,compare); if(runLength < minRun){var force=remaining; if(force > minRun){force=minRun;} binaryInsertionSort(array,lo,lo + force,lo + runLength,compare); runLength=force;} ts.pushRun(lo,runLength); ts.mergeRuns(); remaining -=runLength; lo +=runLength;}while(remaining !==0); ts.forceMergeRuns();} $B.$TimSort=tim_sort; $B.$AlphabeticalCompare=alphabeticalCompare;})(__BRYTHON__) ;(function($B){eval($B.InjectBuiltins()) if(!String.prototype.trim){ String.prototype.trim=function(){var c; for(var i=0;i < this.length;i++){c=this.charCodeAt(i); if(c==32 ||c==10 ||c==13 ||c==9 ||c==12 ||c==11 ||c==160 ||c==5760 ||c==6158 ||c==8192 ||c==8193 ||c==8194 ||c==8195 ||c==8196 ||c==8197 ||c==8198 ||c==8199 ||c==8200 ||c==8201 ||c==8202 ||c==8232 ||c==8233 ||c==8239 ||c==8287 ||c==12288 ||c==65279) continue;else break;} for(var j=this.length - 1;j >=i;j--){c=this.charCodeAt(j); if(c==32 ||c==10 ||c==13 ||c==9 ||c==12 ||c==11 ||c==160 ||c==5760 ||c==6158 ||c==8192 ||c==8193 ||c==8194 ||c==8195 ||c==8196 ||c==8197 ||c==8198 ||c==8199 ||c==8200 ||c==8201 ||c==8202 ||c==8232 ||c==8233 ||c==8239 ||c==8287 ||c==12288 ||c==65279) continue;else break;} return this.substring(i,j + 1);}} if(!String.prototype.trimLeft){ String.prototype.trimLeft=function(){var c; for(var i=0;i < this.length;i++){c=this.charCodeAt(i); if(c==32 ||c==10 ||c==13 ||c==9 ||c==12 ||c==11 ||c==160 ||c==5760 ||c==6158 ||c==8192 ||c==8193 ||c==8194 ||c==8195 ||c==8196 ||c==8197 ||c==8198 ||c==8199 ||c==8200 ||c==8201 ||c==8202 ||c==8232 ||c==8233 ||c==8239 ||c==8287 ||c==12288 ||c==65279) continue;else break;} return this.substring(i);};} if(!String.prototype.trimRight){String.prototype.trimRight=function(){ var c; for(var j=this.length - 1;j >=0;j--){c=this.charCodeAt(j); if(c==32 ||c==10 ||c==13 ||c==9 ||c==12 ||c==11 ||c==160 ||c==5760 ||c==6158 ||c==8192 ||c==8193 ||c==8194 ||c==8195 ||c==8196 ||c==8197 ||c==8198 ||c==8199 ||c==8200 ||c==8201 ||c==8202 ||c==8232 ||c==8233 ||c==8239 ||c==8287 ||c==12288 ||c==65279) continue;else break;} return this.substring(0,j + 1);};} var $ObjectDict=object.$dict var $StringDict={__class__:$B.$type,__dir__:$ObjectDict.__dir__,__name__:'str',$native:true} function normalize_start_end($){if($.start===null||$.start===_b_.None){$.start=0} else if($.start<0){$.start +=$.self.length;$.start=Math.max(0,$.start)} if($.end===null||$.end===_b_.None){$.end=$.self.length} else if($.end<0){$.end +=$.self.length;$.end=Math.max(0,$.end)} if(!isinstance($.start,_b_.int)||!isinstance($.end,_b_.int)){throw _b_.TypeError( "slice indices must be integers or None or have an __index__ method")}} function reverse(s){ return s.split('').reverse().join('')} function check_str(obj){if(!_b_.isinstance(obj,str)){throw _b_.TypeError("can't convert '"+ $B.get_class(obj).__name__+"' object to str implicitely")}} $StringDict.__add__=function(self,other){if(!(typeof other==="string")){try{return getattr(other,'__radd__')(self)} catch(err){throw _b_.TypeError( "Can't convert "+$B.get_class(other).__name__+" to str implicitely")}} return self+other} $StringDict.__contains__=function(self,item){if(!(typeof item==="string")){throw _b_.TypeError( "'in ' requires string as left operand, not "+item.__class__)} var nbcar=item.length if(nbcar==0)return true if(self.length==0)return nbcar==0 for(var i=0,_len_i=self.length;i < _len_i;i++){if(self.substr(i,nbcar)==item)return true} return false} $StringDict.__delitem__=function(){throw _b_.TypeError("'str' object doesn't support item deletion")} $StringDict.__dir__=$ObjectDict.__dir__ $StringDict.__eq__=function(self,other){if(other===undefined){ return self===str} if(_b_.isinstance(other,_b_.str)){return other.valueOf()==self.valueOf()} return other===self.valueOf()} function preformat(self,fmt){if(fmt.empty){return _b_.str(self)} if(fmt.type && fmt.type!='s'){throw _b_.ValueError("Unknown format code '"+fmt.type+ "' for object of type 'str'")} return self} $StringDict.__format__=function(self,format_spec){var fmt=new $B.parse_format_spec(format_spec) fmt.align=fmt.align ||'<' return $B.format_width(preformat(self,fmt),fmt)} $StringDict.__getitem__=function(self,arg){if(isinstance(arg,_b_.int)){var pos=arg if(arg<0)pos+=self.length if(pos>=0 && pos0){if(stop<=start)return '' for(var i=start;i=start)return '' for(var i=start;i>stop;i+=step)res +=self.charAt(i)} return res} if(isinstance(arg,bool))return self.__getitem__(_b_.int(arg)) throw _b_.TypeError('string indices must be integers')} $StringDict.__hash__=function(self){if(self===undefined){return $StringDict.__hashvalue__ ||$B.$py_next_hash-- } var hash=1; for(var i=0,_len_i=self.length;i < _len_i;i++){hash=(101*hash + self.charCodeAt(i))& 0xFFFFFFFF} return hash} $StringDict.__init__=function(self,arg){self.valueOf=function(){return arg} self.toString=function(){return arg} return _b_.None} var $str_iterator=$B.$iterator_class('str_iterator') $StringDict.__iter__=function(self){var items=self.split('') return $B.$iterator(items,$str_iterator)} $StringDict.__len__=function(self){return self.length} var kwarg_key=new RegExp('([^\\)]*)\\)') var NotANumber=function(){this.name='NotANumber'} var number_check=function(s){if(!isinstance(s,[_b_.int,_b_.float])){throw new NotANumber()}} var get_char_array=function(size,char){if(size <=0) return '' return new Array(size + 1).join(char)} var format_padding=function(s,flags,minus_one){var padding=flags.padding if(!padding){ return s} s=s.toString() padding=parseInt(padding,10) if(minus_one){ padding -=1} if(!flags.left){return get_char_array(padding - s.length,flags.pad_char)+ s}else{ return s + get_char_array(padding - s.length,flags.pad_char)}} var format_int_precision=function(val,flags){var precision=flags.precision if(!precision){return val.toString()} precision=parseInt(precision,10) var s if(val.__class__===$B.LongInt.$dict){s=$B.LongInt.$dict.to_base(val,10)}else{ s=val.toString()} if(s[0]==='-'){return '-' + get_char_array(precision - s.length + 1,'0')+ s.slice(1)} return get_char_array(precision - s.length,'0')+ s} var format_float_precision=function(val,upper,flags,modifier){var precision=flags.precision if(isFinite(val)){return modifier(val,precision,flags,upper)} if(val===Infinity){val='inf'}else if(val===-Infinity){val='-inf'}else{ val='nan'} if(upper){return val.toUpperCase()} return val} var format_sign=function(val,flags){if(flags.sign){if(val >=0){return "+"}}else if(flags.space){if(val >=0){return " "}} return ""} var str_format=function(val,flags){ flags.pad_char=" " return format_padding(str(val),flags)} var num_format=function(val,flags){number_check(val) if(val.__class__===$B.LongInt.$dict){val=$B.LongInt.$dict.to_base(val,10)}else{ val=parseInt(val)} var s=format_int_precision(val,flags) if(flags.pad_char==='0'){if(val < 0){s=s.substring(1) return '-' + format_padding(s,flags,true)} var sign=format_sign(val,flags) if(sign !==''){return sign + format_padding(s,flags,true)}} return format_padding(format_sign(val,flags)+ s,flags)} var repr_format=function(val,flags){flags.pad_char=" " return format_padding(repr(val),flags)} var ascii_format=function(val,flags){flags.pad_char=" " return format_padding(ascii(val),flags)} var _float_helper=function(val,flags){number_check(val) if(!flags.precision){if(!flags.decimal_point){flags.precision=6}else{ flags.precision=0}}else{ flags.precision=parseInt(flags.precision,10) validate_precision(flags.precision)} return parseFloat(val)} var trailing_zeros=/(.*?)(0+)([eE].*)/ var leading_zeros=/\.(0*)/ var trailing_dot=/\.$/ var validate_precision=function(precision){ if(precision > 20){precision=20 }} var floating_point_format=function(val,upper,flags){val=_float_helper(val,flags) var v=val.toString() var v_len=v.length var dot_idx=v.indexOf('.') if(dot_idx < 0){dot_idx=v_len} if(val < 1 && val > -1){var zeros=leading_zeros.exec(v) var numzeros if(zeros){numzeros=zeros[1].length}else{ numzeros=0} if(numzeros >=4){val=format_sign(val,flags)+ format_float_precision(val,upper,flags,_floating_g_exp_helper) if(!flags.alternate){var trl=trailing_zeros.exec(val) if(trl){val=trl[1].replace(trailing_dot,'')+ trl[3]}}else{ if(flags.precision <=1){val=val[0]+ '.' + val.substring(1)}} return format_padding(val,flags)} flags.precision=(flags.precision ||0)+ numzeros return format_padding(format_sign(val,flags)+ format_float_precision(val,upper,flags,function(val,precision){return val.toFixed(min(precision,v_len - dot_idx)+ numzeros)}),flags)} if(dot_idx > flags.precision){val=format_sign(val,flags)+ format_float_precision(val,upper,flags,_floating_g_exp_helper) if(!flags.alternate){var trl=trailing_zeros.exec(val) if(trl){val=trl[1].replace(trailing_dot,'')+ trl[3]}}else{ if(flags.precision <=1){val=val[0]+ '.' + val.substring(1)}} return format_padding(val,flags)} return format_padding(format_sign(val,flags)+ format_float_precision(val,upper,flags,function(val,precision){if(!flags.decimal_point){precision=min(v_len - 1,6)}else if(precision > v_len){if(!flags.alternate){precision=v_len}} if(precision < dot_idx){precision=dot_idx} return val.toFixed(precision - dot_idx)}),flags)} var _floating_g_exp_helper=function(val,precision,flags,upper){if(precision){--precision} val=val.toExponential(precision) var e_idx=val.lastIndexOf('e') if(e_idx > val.length - 4){val=val.substring(0,e_idx + 2)+ '0' + val.substring(e_idx + 2)} if(upper){return val.toUpperCase()} return val} var floating_point_decimal_format=function(val,upper,flags){val=_float_helper(val,flags) return format_padding(format_sign(val,flags)+ format_float_precision(val,upper,flags,function(val,precision,flags){val=val.toFixed(precision) if(precision===0 && flags.alternate){val +='.'} return val}),flags)} var _floating_exp_helper=function(val,precision,flags,upper){val=val.toExponential(precision) var e_idx=val.lastIndexOf('e') if(e_idx > val.length - 4){val=val.substring(0,e_idx + 2)+ '0' + val.substring(e_idx + 2)} if(upper){return val.toUpperCase()} return val} var floating_point_exponential_format=function(val,upper,flags){val=_float_helper(val,flags) return format_padding(format_sign(val,flags)+ format_float_precision(val,upper,flags,_floating_exp_helper),flags)} var signed_hex_format=function(val,upper,flags){var ret number_check(val) if(val.__class__===$B.LongInt.$dict){ret=$B.LongInt.$dict.to_base(val,16)}else{ ret=parseInt(val) ret=ret.toString(16)} ret=format_int_precision(ret,flags) if(upper){ret=ret.toUpperCase()} if(flags.pad_char==='0'){if(val < 0){ret=ret.substring(1) ret='-' + format_padding(ret,flags,true)} var sign=format_sign(val,flags) if(sign !==''){ret=sign + format_padding(ret,flags,true)}} if(flags.alternate){if(ret.charAt(0)==='-'){if(upper){ret="-0X" + ret.slice(1)}else{ ret="-0x" + ret.slice(1)}}else{ if(upper){ret="0X" + ret}else{ ret="0x" + ret}}} return format_padding(format_sign(val,flags)+ ret,flags)} var octal_format=function(val,flags){number_check(val) var ret if(val.__class__===$B.LongInt.$dict){ret=$B.LongInt.$dict.to_base(8)}else{ ret=parseInt(val) ret=ret.toString(8)} ret=format_int_precision(ret,flags) if(flags.pad_char==='0'){if(val < 0){ret=ret.substring(1) ret='-' + format_padding(ret,flags,true)} var sign=format_sign(val,flags) if(sign !==''){ret=sign + format_padding(ret,flags,true)}} if(flags.alternate){if(ret.charAt(0)==='-'){ret="-0o" + ret.slice(1)}else{ ret="0o" + ret}} return format_padding(ret,flags)} var single_char_format=function(val,flags){if(isinstance(val,str)&& val.length==1)return val try{ val=_b_.int(val)}catch(err){throw _b_.TypeError('%c requires int or char')} return format_padding(chr(val),flags)} var num_flag=function(c,flags){if(c==='0' && !flags.padding && !flags.decimal_point && !flags.left){flags.pad_char='0' return} if(!flags.decimal_point){flags.padding=(flags.padding ||"")+ c}else{ flags.precision=(flags.precision ||"")+ c}} var decimal_point_flag=function(val,flags){if(flags.decimal_point){ throw new UnsupportedChar()} flags.decimal_point=true} var neg_flag=function(val,flags){flags.pad_char=' ' flags.left=true} var space_flag=function(val,flags){flags.space=true} var sign_flag=function(val,flags){flags.sign=true} var alternate_flag=function(val,flags){flags.alternate=true} var char_mapping={'s': str_format,'d': num_format,'i': num_format,'u': num_format,'o': octal_format,'r': repr_format,'a': ascii_format,'g': function(val,flags){return floating_point_format(val,false,flags)},'G': function(val,flags){return floating_point_format(val,true,flags)},'f': function(val,flags){return floating_point_decimal_format(val,false,flags)},'F': function(val,flags){return floating_point_decimal_format(val,true,flags)},'e': function(val,flags){return floating_point_exponential_format(val,false,flags)},'E': function(val,flags){return floating_point_exponential_format(val,true,flags)},'x': function(val,flags){return signed_hex_format(val,false,flags)},'X': function(val,flags){return signed_hex_format(val,true,flags)},'c': single_char_format,'0': function(val,flags){return num_flag('0',flags)},'1': function(val,flags){return num_flag('1',flags)},'2': function(val,flags){return num_flag('2',flags)},'3': function(val,flags){return num_flag('3',flags)},'4': function(val,flags){return num_flag('4',flags)},'5': function(val,flags){return num_flag('5',flags)},'6': function(val,flags){return num_flag('6',flags)},'7': function(val,flags){return num_flag('7',flags)},'8': function(val,flags){return num_flag('8',flags)},'9': function(val,flags){return num_flag('9',flags)},'-': neg_flag,' ': space_flag,'+': sign_flag,'.': decimal_point_flag,'#': alternate_flag} var UnsupportedChar=function(){this.name="UnsupportedChar"} $StringDict.__mod__=function(self,args){var length=self.length,pos=0 |0,argpos=null,getitem if(_b_.isinstance(args,_b_.tuple)){argpos=0 |0}else{getitem=_b_.getattr(args,'__getitem__',null)} var ret='' var $get_kwarg_string=function(s){ ++pos var rslt=kwarg_key.exec(s.substring(newpos)) if(!rslt){throw _b_.ValueError("incomplete format key")} var key=rslt[1] newpos +=rslt[0].length try{ var self=getitem(key)}catch(err){if(err.name==="KeyError"){throw err} throw _b_.TypeError("format requires a mapping")} return get_string_value(s,self)} var $get_arg_string=function(s){ var self if(argpos===null){ self=args}else{ self=args[argpos++] if(self===undefined){throw _b_.TypeError("not enough arguments for format string")}} return get_string_value(s,self)} var get_string_value=function(s,self){ var flags={'pad_char': ' '} do{ var func=char_mapping[s[newpos]] try{ if(func===undefined){throw new UnsupportedChar()}else{ var ret=func(self,flags) if(ret !==undefined){return ret} ++newpos}}catch(err){if(err.name==="UnsupportedChar"){invalid_char=s[newpos] if(invalid_char===undefined){throw _b_.ValueError("incomplete format")} throw _b_.ValueError("unsupported format character '" + invalid_char + "' (0x" + invalid_char.charCodeAt(0).toString(16)+ ") at index " + newpos)}else if(err.name==="NotANumber"){var try_char=s[newpos] var cls=self.__class__ if(!cls){if(typeof(self)==='string'){cls='str'}else{ cls=typeof(self)}}else{ cls=cls.__name__} throw _b_.TypeError("%" + try_char + " format: a number is required, not " + cls)}else{ throw err}}}while(true)} var nbph=0 do{ var newpos=self.indexOf('%',pos) if(newpos < 0){ret +=self.substring(pos) break} ret +=self.substring(pos,newpos) ++newpos if(newpos < length){if(self[newpos]==='%'){ret +='%'}else{ nbph++ if(self[newpos]==='('){++newpos ret +=$get_kwarg_string(self)}else{ ret +=$get_arg_string(self)}}}else{ throw _b_.ValueError("incomplete format")} pos=newpos + 1}while(pos < length) if(argpos!==null){if(args.length>argpos){throw _b_.TypeError('not enough arguments for format string')}else if(args.length" return self.toString()} $StringDict.toString=function(){return 'string!'} var $comp_func=function(self,other){if(typeof other !=="string"){throw _b_.TypeError( "unorderable types: 'str' > "+$B.get_class(other).__name__+"()")} return self > other} $comp_func +='' var $comps={'>':'gt','>=':'ge','<':'lt','<=':'le'} for(var $op in $comps){eval("$StringDict.__"+$comps[$op]+'__ = '+$comp_func.replace(/>/gm,$op))} $B.make_rmethods($StringDict) var $notimplemented=function(self,other){throw NotImplementedError("OPERATOR not implemented for class str")} $StringDict.title=unicode.title; $StringDict.capitalize=unicode.capitalize; $StringDict.casefold=unicode.casefold; $StringDict.islower=unicode.islower; $StringDict.isupper=unicode.isupper; $StringDict.istitle=unicode.istitle; $StringDict.isspace=unicode.isspace; $StringDict.isalpha=unicode.isalpha; $StringDict.isalnum=unicode.isalnum; $StringDict.isdecimal=unicode.isdecimal; $StringDict.isdigit=unicode.isdigit; $StringDict.isnumeric=unicode.isnumeric; $StringDict.isidentifier=unicode.isidentifier; $StringDict.isprintable=unicode.isprintable; $StringDict.lower=unicode.lower; $StringDict.swapcase=unicode.swapcase; $StringDict.upper=unicode.upper; $StringDict.center=function(self,width,fillchar){var $=$B.args("center",3,{self:null,width:null,fillchar:null},['self','width','fillchar'],arguments,{fillchar:' '},null,null) if($.width<=self.length)return self var pad=parseInt(($.width-self.length)/2) var res=$.fillchar.repeat(pad) res +=self + res if(res.length<$.width){res +=$.fillchar} return res} $StringDict.count=function(){var $=$B.args('count',4,{self:null,sub:null,start:null,stop:null},['self','sub','start','stop'],arguments,{start:null,stop:null},null,null) if(!(typeof $.sub==="string")){throw _b_.TypeError( "Can't convert '"+$B.get_class($.sub).__name__+"' object to str implicitly")} var substr=$.self if($.start!==null){var _slice if($.stop!==null){_slice=_b_.slice($.start,$.stop)} else{_slice=_b_.slice($.start,$.self.length)} substr=$StringDict.__getitem__.apply(null,[$.self].concat(_slice))}else{if($.self.length+$.sub.length==0){return 1}} if($.sub.length==0){if($.start==$.self.length){return 1} else if(substr.length==0){return 0} return substr.length+1} var n=0,pos=0 while(pos=0){n++;pos+=$.sub.length}else break;} return n} $StringDict.encode=function(self,encoding){if(encoding===undefined)encoding='utf-8' if(encoding=='rot13' ||encoding=='rot_13'){ var res='' for(var i=0,_len=self.length;i<_len ;i++){var char=self.charAt(i) if(('a'<=char && char<='m')||('A'<=char && char<='M')){res +=String.fromCharCode(String.charCodeAt(char)+13)}else if(('m' 0){res +=' ';col++} break case '\r': case '\n': res +=car col=0 break default: res +=car col++ break} pos++} return res} $StringDict.find=function(){ var $=$B.args("$StringDict.find",4,{self:null,sub:null,start:null,end:null},['self','sub','start','end'],arguments,{start:0,end:null},null,null) check_str($.sub) normalize_start_end($) if(!isinstance($.start,_b_.int)||!isinstance($.end,_b_.int)){throw _b_.TypeError( "slice indices must be integers or None or have an __index__ method")} var s=$.self.substring($.start,$.end) if($.sub.length==0 && $.start==$.self.length){return $.self.length} if(s.length+$.sub.length==0){return -1} var last_search=s.length-$.sub.length for(var i=0;i<=last_search;i++){if(s.substr(i,$.sub.length)==$.sub){return $.start+i}} return -1} function parse_format(fmt_string){ var elts=fmt_string.split(':'),name,conv,spec,name_ext=[] if(elts.length==1){ name=fmt_string}else{ name=elts[0] spec=elts.splice(1).join(':')} var elts=name.split('!') if(elts.length>1){name=elts[0] conv=elts[1] if(conv.length!==1 ||'ras'.search(conv)==-1){throw _b_.ValueError('wrong conversion flag '+conv)}} if(name!==undefined){ function name_repl(match){name_ext.push(match) return ''} var name_ext_re=/\.[_a-zA-Z][_a-zA-Z0-9]*|\[[_a-zA-Z][_a-zA-Z0-9]*\]|\[[0-9]+\]/g name=name.replace(name_ext_re,name_repl)} return{name: name,name_ext: name_ext,conv: conv,spec: spec||''}} $StringDict.format=function(self){var $=$B.args('format',1,{self:null},['self'],arguments,{},'args','kw') var pos=0,_len=self.length,car,text='',parts=[],rank=0 while(pos<_len){car=self.charAt(pos) if(car=='{' && self.charAt(pos+1)=='{'){ text +='{' pos+=2}else if(car=='}' && self.charAt(pos+1)=='}'){ text +='}' pos+=2}else if(car=='{'){ parts.push(text) var end=pos+1,nb=1 while(end<_len){if(self.charAt(end)=='{'){nb++;end++} else if(self.charAt(end)=='}'){nb--;end++ if(nb==0){ var fmt_string=self.substring(pos+1,end-1) var fmt_obj=parse_format(fmt_string) if(!fmt_obj.name){fmt_obj.name=rank+'' rank++} if(fmt_obj.spec!==undefined){ function replace_nested(name,key){if(/\d+/.exec(key)){ return _b_.tuple.$dict.__getitem__($.args,parseInt(key))}else{ return _b_.dict.$dict.__getitem__($.kw,key)}} fmt_obj.spec=fmt_obj.spec.replace(/\{(.+?)\}/g,replace_nested)} parts.push(fmt_obj) text='' break}}else{end++}} if(nb>0){throw ValueError("wrong format "+self)} pos=end}else{text +=car;pos++}} if(text){parts.push(text)} var res='',fmt for(var i=0;i-1){ var pos=parseInt(fmt.name),value=_b_.tuple.$dict.__getitem__($.args,pos)}else{ var value=_b_.dict.$dict.__getitem__($.kw,fmt.name)} for(var j=0;j-1){key=parseInt(key)} value=_b_.getattr(value,'__getitem__')(key)}} if(fmt.conv=='a'){value=_b_.ascii(value)} else if(fmt.conv=='r'){value=_b_.repr(value)} else if(fmt.conv=='s'){value=_b_.str(value)} res +=_b_.getattr(value,'__format__')(fmt.spec)} return res} $StringDict.format_map=function(self){throw NotImplementedError("function format_map not implemented yet");} $StringDict.index=function(self){ var res=$StringDict.find.apply(null,arguments) if(res===-1)throw _b_.ValueError("substring not found") return res} $StringDict.join=function(){var $=$B.args('join',2,{self:null,iterable:null},['self','iterable'],arguments,{},null,null) var iterable=_b_.iter($.iterable) var res=[],count=0 while(1){try{var obj2=_b_.next(iterable) if(!isinstance(obj2,str)){throw _b_.TypeError( "sequence item "+count+": expected str instance, "+$B.get_class(obj2).__name__+" found")} res.push(obj2)}catch(err){if(_b_.isinstance(err,_b_.StopIteration)){break} else{throw err}}} return res.join($.self)} $StringDict.ljust=function(self){var $=$B.args('ljust',3,{self:null,width:null,fillchar:null},['self','width','fillchar'],arguments,{fillchar:' '},null,null) if($.width <=self.length)return self return self + $.fillchar.repeat($.width - self.length)} $StringDict.lstrip=function(self,x){var $=$B.args('lstrip',2,{self:null,chars:null},['self','chars'],arguments,{chars:_b_.None},null,null) if($.chars===_b_.None){return $.self.trimLeft()} for(var i=0;i < $.self.length;i++){if($.chars.indexOf($.self.charAt(i))===-1){return $.self.substring(i);}} return '';} $StringDict.maketrans=function(){var $=$B.args('maketrans',3,{x:null,y:null,z:null},['x','y','z'],arguments,{y:null,z:null},null,null) var _t=_b_.dict() for(var i=0;i < 256;i++)_t.$numeric_dict[i]=i if($.y===null && $.z===null){ if(!_b_.isinstance($.x,_b_.dict)){throw _b_.TypeError('maketrans only argument must be a dict')} var items=_b_.list(_b_.dict.$dict.items($.x)) for(var i=0,len=items.length;i-1 && elts.length>=count){var rest=elts.slice(count).join('') return _new+elts.slice(0,count).join(_new)+rest}else{return _new+elts.join(_new)+_new}}else{var elts=$StringDict.split(self,old,count)} var res=self,pos=-1 if(old.length==0){var res=_new for(var i=0;i 0){pos=res.indexOf(old,pos); if(pos < 0) break; res=res.substr(0,pos)+ _new + res.substr(pos + old.length); pos=pos + _new.length; count--;} return res;} $StringDict.rfind=function(self){ var $=$B.args("rfind",4,{self:null,sub:null,start:null,end:null},['self','sub','start','end'],arguments,{start:0,end:null},null,null) normalize_start_end($) check_str($.sub) if($.sub.length==0){if($.start>$.self.length){return -1} else{return $.self.length}} var sublen=$.sub.length for(var i=$.end-sublen;i>=$.start;i--){if($.self.substr(i,sublen)==$.sub){return i}} return -1} $StringDict.rindex=function(){ var res=$StringDict.rfind.apply(null,arguments) if(res==-1){throw _b_.ValueError("substring not found")} return res} $StringDict.rjust=function(self){var $=$B.args("rjust",3,{self:null,width:null,fillchar:null},['self','width','fillchar'],arguments,{fillchar:' '},null,null) if($.width <=self.length)return self return $.fillchar.repeat($.width - self.length)+ self} $StringDict.rpartition=function(self,sep){var $=$B.args('rpartition',2,{self:null,sep:null},['self','sep'],arguments,{},null,null) check_str($.sep) var self=reverse($.self),sep=reverse($.sep) var items=$StringDict.partition(self,sep).reverse() for(var i=0;i=0;j--){if($.chars.indexOf($.self.charAt(j))===-1){return $.self.substring(0,j+1);}} return '';} $StringDict.split=function(){var pos=0 var $=$B.args("split",3,{self:null,sep:null,maxsplit:null},['self','sep','maxsplit'],arguments,{sep:_b_.None,maxsplit:-1},null,null) var sep=$.sep,maxsplit=$.maxsplit,self=$.self if(maxsplit.__class__===$B.LongInt.$dict){maxsplit=parseInt(maxsplit.value)} if(sep=='')throw _b_.ValueError('empty separator') if(sep===_b_.None){var res=[] while(pos-1){pos++} if(pos===self.length-1){return[self]} var name='' while(1){if(self.charAt(pos).search(/\s/)===-1){if(name===''){name=self.charAt(pos)} else{name+=self.charAt(pos)}}else{if(name!==''){res.push(name) if(maxsplit!==-1&&res.length===maxsplit+1){res.pop() res.push(name+self.substr(pos)) return res} name=''}} pos++ if(pos>self.length-1){if(name){res.push(name)} break}} return res}else{var res=[],s='',seplen=sep.length if(maxsplit==0){return[self]} while(pos-1 && res.length>=maxsplit){res.push(self.substr(pos)) return res} s=''}else{s +=self.charAt(pos) pos++}} res.push(s) return res}} $StringDict.splitlines=function(self){var $=$B.args('splitlines',2,{self:null,keepends:null},['self','keepends'],arguments,{keepends:false},null,null) if(!_b_.isinstance($.keepends,[_b_.bool,_b_.int])){throw _b_.TypeError('integer argument expected, got '+ $B.get_class($.keepends).__name)} var keepends=_b_.int($.keepends) if(keepends){var res=[],start=pos,pos=0,self=$.self while(pos=i;j--){if($.chars.indexOf($.self.charAt(j))===-1){break;}} return $.self.substring(i,j+1);} $StringDict.translate=function(self,table){var res=[],pos=0 if(isinstance(table,_b_.dict)){for(var i=0,_len_i=self.length;i < _len_i;i++){var repl=_b_.dict.$dict.get(table,self.charCodeAt(i),-1) if(repl==-1){res[pos++]=self.charAt(i)} else if(repl!==None){res[pos++]=_b_.chr(repl)}}} return res.join('')} $StringDict.zfill=function(self,width){var $=$B.args('zfill',2,{self:null,width:null},['self','width'],arguments,{},null,null) if($.width <=self.length){return self} switch(self.charAt(0)){case '+': case '-': return self.charAt(0)+'0'.repeat($.width-self.length)+self.substr(1) default: return '0'.repeat(width - self.length)+self}} function str(arg){if(arg===undefined)return '' switch(typeof arg){case 'string': return arg case 'number': if(isFinite(arg)){return arg.toString()}} try{if(arg.__class__===$B.$factory){ var func=$B.$type.__getattribute__(arg.$dict.__class__,'__str__') if(func.__func__===_b_.object.$dict.__str__){return func(arg)} return func()}else if(arg.__class__===$B.$type){ var func=$B.$type.__getattribute__(arg.__class__,'__str__') if(func.__func__===_b_.object.$dict.__str__){return func(arg)} return func()} var f=getattr(arg,'__str__') return f()} catch(err){ try{ var f=getattr(arg,'__repr__') return getattr(f,'__call__')()}catch(err){if($B.debug>1){console.log(err)} console.log('Warning - no method __str__ or __repr__, default to toString',arg) return arg.toString()}}} str.__class__=$B.$factory str.$dict=$StringDict $StringDict.$factory=str $StringDict.__new__=function(cls){if(cls===undefined){throw _b_.TypeError('str.__new__(): not enough arguments')} return{__class__:cls.$dict}} $B.set_func_names($StringDict) var $StringSubclassDict={__class__:$B.$type,__name__:'str'} for(var $attr in $StringDict){if(typeof $StringDict[$attr]=='function'){$StringSubclassDict[$attr]=(function(attr){return function(){var args=[],pos=0 if(arguments.length>0){var args=[arguments[0].valueOf()],pos=1 for(var i=1,_len_i=arguments.length;i < _len_i;i++){args[pos++]=arguments[i]}} return $StringDict[attr].apply(null,args)}})($attr)}} $StringSubclassDict.__mro__=[$ObjectDict] $B.$StringSubclassFactory={__class__:$B.$factory,$dict:$StringSubclassDict} _b_.str=str $B.parse_format_spec=function(spec){if(spec==''){this.empty=true} else{var pos=0,aligns='<>=^',digits='0123456789',types='bcdeEfFgGnosxX%',align_pos=aligns.indexOf(spec.charAt(0)) if(align_pos!=-1){if(spec.charAt(1)&& aligns.indexOf(spec.charAt(1))!=-1){ this.fill=spec.charAt(0) this.align=spec.charAt(1) pos=2}else{ this.align=aligns[align_pos]; this.fill=' '; pos++}}else{align_pos=aligns.indexOf(spec.charAt(1)) if(spec.charAt(1)&& align_pos!=-1){ this.align=aligns[align_pos] this.fill=spec.charAt(0) pos=2}} var car=spec.charAt(pos) if(car=='+'||car=='-'||car==' '){this.sign=car; pos++; car=spec.charAt(pos);} if(car=='#'){this.alternate=true;pos++;car=spec.charAt(pos)} if(car=='0'){ this.fill='0' this.align='=' pos++;car=spec.charAt(pos)} while(car && digits.indexOf(car)>-1){if(this.width===undefined){this.width=car} else{this.width+=car} pos++;car=spec.charAt(pos)} if(this.width!==undefined){this.width=parseInt(this.width)} if(car==','){this.comma=true;pos++;car=spec.charAt(pos)} if(car=='.'){if(digits.indexOf(spec.charAt(pos+1))==-1){throw _b_.ValueError("Missing precision in format spec")} this.precision=spec.charAt(pos+1) pos+=2;car=spec.charAt(pos) while(car && digits.indexOf(car)>-1){this.precision+=car;pos++;car=spec.charAt(pos)} this.precision=parseInt(this.precision)} if(car && types.indexOf(car)>-1){this.type=car;pos++;car=spec.charAt(pos)} if(pos!==spec.length){ throw _b_.ValueError("Invalid format specifier")}} this.toString=function(){return(this.fill===undefined ? '' : _b_.str(this.fill))+ (this.align||'')+ (this.sign||'')+ (this.alternate ? '#' : '')+ (this.sign_aware ? '0' : '')+ (this.width ||'')+ (this.comma ? ',' : '')+ (this.precision ? '.'+this.precision : '')+ (this.type ||'')}} $B.format_width=function(s,fmt){if(fmt.width && s.length': return fill.repeat(missing)+s case '=': if('+-'.indexOf(s.charAt(0))>-1){return s.charAt(0)+fill.repeat(missing)+s.substr(1)}else{return fill.repeat(missing)+s } case '^': var left=parseInt(missing/2) return fill.repeat(left)+s+fill.repeat(missing-left)}} return s}})(__BRYTHON__) ;(function($B){eval($B.InjectBuiltins()) var $ObjectDict=_b_.object.$dict,str_hash=_b_.str.$dict.__hash__,$N=_b_.None function $DictClass($keys,$values){this.iter=null this.__class__=$DictDict $DictDict.clear(this) var setitem=$DictDict.__setitem__ var i=$keys.length while(i--)setitem($keys[i],$values[i])} var $DictDict={__class__:$B.$type,__name__ : 'dict',$native:true,__dir__:$ObjectDict.__dir__} var $key_iterator=function(d){this.d=d this.current=0 this.iter=new $item_generator(d)} $key_iterator.prototype.length=function(){return this.iter.length } $key_iterator.prototype.next=function(){return this.iter.next()[0]} var $value_iterator=function(d){this.d=d this.current=0 this.iter=new $item_generator(d)} $value_iterator.prototype.length=function(){return this.iter.length } $value_iterator.prototype.next=function(){return this.iter.next()[1]} var $item_generator=function(d){this.i=0 if(d.$jsobj){this.items=[] for(var attr in d.$jsobj){if(attr.charAt(0)!='$'){this.items.push([attr,d.$jsobj[attr]])}} this.length=this.items.length; return} var items=[] var pos=0 for(var k in d.$numeric_dict){items[pos++]=[parseFloat(k),d.$numeric_dict[k]]} for(var k in d.$string_dict){items[pos++]=[k,d.$string_dict[k]]} for(var k in d.$object_dict){items[pos++]=d.$object_dict[k]} this.items=items this.length=items.length} $item_generator.prototype.next=function(){if(this.i < this.items.length){return this.items[this.i++]} throw _b_.StopIteration("StopIteration")} $item_generator.prototype.as_list=function(){return this.items} var $item_iterator=function(d){this.d=d this.current=0 this.iter=new $item_generator(d)} $item_iterator.prototype.length=function(){return this.iter.items.length } $item_iterator.prototype.next=function(){return _b_.tuple(this.iter.next())} var $copy_dict=function(left,right){var _l=new $item_generator(right).as_list() var si=$DictDict.__setitem__ var i=_l.length while(i--)si(left,_l[i][0],_l[i][1])} var $iterator_wrapper=function(items,klass){var res={__class__:klass,__iter__:function(){items.iter.i=0;return res},__len__:function(){return items.length()},__next__:function(){return items.next()},__repr__:function(){var s=[] for(var i=0,len=items.length();i 0} $DictDict.__contains__=function(){var $=$B.args('__contains__',2,{self:null,item:null},['self','item'],arguments,{},null,null),self=$.self,item=$.item if(self.$jsobj)return self.$jsobj[item]!==undefined switch(typeof item){case 'string': return self.$string_dict[item]!==undefined case 'number': return self.$numeric_dict[item]!==undefined} var _key=hash(item) if(self.$str_hash[_key]!==undefined && _b_.getattr(item,'__eq__')(self.$str_hash[_key])){return true} if(self.$numeric_dict[_key]!==undefined && _b_.getattr(item,'__eq__')(_key)){return true} if(self.$object_dict[_key]!==undefined){ var _eq=getattr(item,'__eq__') if(_eq(self.$object_dict[_key][0])){return true}} return false} $DictDict.__delitem__=function(){var $=$B.args('__eq__',2,{self:null,arg:null},['self','arg'],arguments,{},null,null),self=$.self,arg=$.arg if(self.$jsobj){if(self.$jsobj[arg]===undefined){throw KeyError(arg)} delete self.$jsobj[arg] return $N} switch(typeof arg){case 'string': if(self.$string_dict[arg]===undefined)throw KeyError(_b_.str(arg)) delete self.$string_dict[arg] delete self.$str_hash[str_hash(arg)] return $N case 'number': if(self.$numeric_dict[arg]===undefined)throw KeyError(_b_.str(arg)) delete self.$numeric_dict[arg] return $N} var _key=hash(arg) if(self.$object_dict[_key]!==undefined){delete self.$object_dict[_key]} if(self.$jsobj)delete self.$jsobj[arg] return $N} $DictDict.__eq__=function(){var $=$B.args('__eq__',2,{self:null,other:null},['self','other'],arguments,{},null,null),self=$.self,other=$.other if(!isinstance(other,dict))return false if($DictDict.__len__(self)!=$DictDict.__len__(other)){return false} if((self.$numeric_dict.length!=other.$numeric_dict.length)|| (self.$string_dict.length!=other.$string_dict.length)|| (self.$object_dict.length!=other.$object_dict.length)){return false} for(var k in self.$numeric_dict){if(!_b_.getattr(other.$numeric_dict[k],'__eq__')(self.$numeric_dict[k])){return false}} for(var k in self.$string_dict){if(!_b_.getattr(other.$string_dict[k],'__eq__')(self.$string_dict[k])){return false}} for(var k in self.$object_dict){console.log('key in object dict',k) if(!_b_.getattr(other.$object_dict[k][1],'__eq__')(self.$object_dict[k][1])){return false}} return true} $DictDict.__getitem__=function(){var $=$B.args('__getitem__',2,{self:null,arg:null},['self','arg'],arguments,{},null,null),self=$.self,arg=$.arg if(self.$jsobj){if(self.$jsobj[arg]===undefined){return None} return self.$jsobj[arg]} switch(typeof arg){case 'string': if(self.$string_dict[arg]!==undefined)return self.$string_dict[arg] break case 'number': if(self.$numeric_dict[arg]!==undefined)return self.$numeric_dict[arg]} var _key=_b_.hash(arg),_eq=_b_.getattr(arg,'__eq__') var sk=self.$str_hash[_key] if(sk!==undefined && _eq(sk)){return self.$string_dict[sk]} if(self.$numeric_dict[_key]!==undefined && _eq(_key)){return self.$numeric_dict[_key]} var obj_ref=self.$object_dict[_key] if(obj_ref!==undefined){ _eq(self.$object_dict[_key][0]) return self.$object_dict[_key][1]} if(self.__class__!==$DictDict){try{var missing_method=getattr(self.__class__.$factory,'__missing__') return missing_method(self,arg)}catch(err){}} throw KeyError(_b_.str(arg))} $DictDict.__hash__=None $DictDict.__init__=function(self){var args=[],pos=0 for(var i=1;i0)si(self,obj[i-1][0],obj[i-1][1]) return $N}else if(isinstance(obj,dict)){$copy_dict(self,obj) return $N} if(obj.__class__===$B.JSObject.$dict){ var si=$DictDict.__setitem__ for(var attr in obj.js)si(self,attr,obj.js[attr]) self.$jsobj=obj.js return $N}} var $ns=$B.args('dict',0,{},[],args,{},'args','kw') var args=$ns['args'] var kw=$ns['kw'] if(args.length>0){if(isinstance(args[0],dict)){$B.$copy_dict(self,args[0]) return $N} if(Array.isArray(args[0])){var src=args[0] var i=src.length -1 var si=$DictDict.__setitem__ while(i-->0)si(self,src[i-1][0],src[i-1][1])}else{var iterable=iter(args[0]) while(1){try{var elt=next(iterable) var key=getattr(elt,'__getitem__')(0) var value=getattr(elt,'__getitem__')(1) $DictDict.__setitem__(self,key,value)}catch(err){if(err.__name__==='StopIteration'){break} throw err}}}} if($DictDict.__len__(kw)> 0)$copy_dict(self,kw) return $N} var $dict_iterator=$B.$iterator_class('dict iterator') $DictDict.__iter__=function(self){return $DictDict.keys(self)} $DictDict.__len__=function(self){var _count=0 if(self.$jsobj){for(var attr in self.$jsobj){if(attr.charAt(0)!='$'){_count++}} return _count} for(var k in self.$numeric_dict)_count++ for(var k in self.$string_dict)_count++ for(var k in self.$object_dict)_count+=self.$object_dict[k].length return _count} $DictDict.__mro__=[$ObjectDict] $DictDict.__ne__=function(self,other){return !$DictDict.__eq__(self,other)} $DictDict.__next__=function(self){if(self.$iter==null){self.$iter=new $item_generator(self)} try{ return self.$iter.next()}catch(err){if(err.__name__ !=="StopIteration"){throw err }}} $DictDict.__repr__=function(self){if(self===undefined)return "" if(self.$jsobj){ var res=[] for(var attr in self.$jsobj){if(attr.charAt(0)=='$' ||attr=='__class__'){continue} else{try{res.push("'"+attr+"': "+_b_.repr(self.$jsobj[attr]))}catch(err){}}} return '{'+res.join(', ')+'}'} var res=[],pos=0,items=new $item_generator(self).as_list() for(var i=0;i < items.length;i++){var itm=items[i] if(itm[1]===self){res[pos++]=repr(itm[0])+': {...}'} else{res[pos++]=repr(itm[0])+': '+repr(itm[1])}} return '{'+ res.join(', ')+'}'} $DictDict.__setitem__=function(self,key,value){var $=$B.args('__setitem__',3,{self:null,key:null,value:null},['self','key','value'],arguments,{},null,null),self=$.self,key=$.key,value=$.value if(self.$jsobj){self.$jsobj[key]=value;return} switch(typeof key){case 'string': self.$string_dict[key]=value self.$str_hash[str_hash(key)]=key return $N case 'number': self.$numeric_dict[key]=value return $N} var _key=hash(key) var _eq=getattr(key,'__eq__') if(self.$numeric_dict[_key]!==undefined && _eq(_key)){self.$numeric_dict[_key]=value return $N} var sk=self.$str_hash[_key] if(sk!==undefined && _eq(sk)){self.$string_dict[sk]=value return $N} var obj_ref=self.$object_dict[_key] if(obj_ref!==undefined){ _eq(self.$object_dict[_key][0])} self.$object_dict[_key]=[key,value] return $N} $DictDict.__str__=$DictDict.__repr__ $B.make_rmethods($DictDict) $DictDict.clear=function(){ var $=$B.args('clear',1,{self:null},['self'],arguments,{},null,null),self=$.self self.$numeric_dict={} self.$string_dict={} self.$str_hash={} self.$object_dict={} if(self.$jsobj)self.$jsobj={} return $N} $DictDict.copy=function(self){ var $=$B.args('copy',1,{self:null},['self'],arguments,{},null,null),self=$.self,res=_b_.dict() $copy_dict(res,self) return res} $DictDict.fromkeys=function(){var $=$B.args('fromkeys',3,{cls:null,keys:null,value:null},['cls','keys','value'],arguments,{value:_b_.None},null,null),keys=$.keys,value=$.value var klass=$.cls,res=klass(),keys_iter=_b_.iter(keys) while(1){try{var key=_b_.next(keys_iter) if(klass===dict){$DictDict.__setitem__(res,key,value)} else{_b_.getattr(res,"__setitem__")(key,value)}}catch(err){if($B.is_exc(err,[_b_.StopIteration])){return res} throw err}}} $DictDict.fromkeys.$type='classmethod' $DictDict.get=function(){var $=$B.args('get',3,{self:null,key:null,_default:null},['self','key','_default'],arguments,{_default:$N},null,null) try{return $DictDict.__getitem__($.self,$.key)} catch(err){if(_b_.isinstance(err,_b_.KeyError)){return $._default} else{throw err}}} var $dict_itemsDict=$B.$iterator_class('dict_items') $DictDict.items=function(self){if(arguments.length > 1){var _len=arguments.length - 1 var _msg="items() takes no arguments ("+_len+" given)" throw _b_.TypeError(_msg)} return $iterator_wrapper(new $item_iterator(self),$dict_itemsDict)} var $dict_keysDict=$B.$iterator_class('dict_keys') $DictDict.keys=function(self){if(arguments.length > 1){var _len=arguments.length - 1 var _msg="keys() takes no arguments ("+_len+" given)" throw _b_.TypeError(_msg)} return $iterator_wrapper(new $key_iterator(self),$dict_keysDict)} $DictDict.pop=function(){var $=$B.args('pop',3,{self:null,key: null,_default:null},['self','key','_default'],arguments,{_default:$N},null,null),self=$.self,key=$.key,_default=$._default try{var res=$DictDict.__getitem__(self,key) $DictDict.__delitem__(self,key) return res}catch(err){if(err.__name__==='KeyError'){if(_default!==undefined)return _default throw err} throw err}} $DictDict.popitem=function(self){try{var itm=new $item_iterator(self).next() $DictDict.__delitem__(self,itm[0]) return _b_.tuple(itm)}catch(err){if(err.__name__=="StopIteration"){throw KeyError("'popitem(): dictionary is empty'")}}} $DictDict.setdefault=function(){var $=$B.args('setdefault',3,{self:null,key: null,_default:null},['self','key','_default'],arguments,{_default:$N},null,null),self=$.self,key=$.key,_default=$._default try{return $DictDict.__getitem__(self,key)} catch(err){if(_default===undefined)_default=None $DictDict.__setitem__(self,key,_default) return _default}} $DictDict.update=function(self){var $=$B.args('update',1,{'self':null},['self'],arguments,{},'args','kw'),self=$.self,args=$.args,kw=$.kw if(args.length>0){var o=args[0] if(isinstance(o,dict)){$copy_dict(self,o)}else if(hasattr(o,'__getitem__')&& hasattr(o,'keys')){var _keys=_b_.list(getattr(o,'keys')()) var si=$DictDict.__setitem__ var i=_keys.length while(i--){ var _value=getattr(o,'__getitem__')(_keys[i]) si(self,_keys[i],_value)}}} $copy_dict(self,kw) return $N} var $dict_valuesDict=$B.$iterator_class('dict_values') $DictDict.values=function(self){if(arguments.length > 1){var _len=arguments.length - 1 var _msg="values() takes no arguments ("+_len+" given)" throw _b_.TypeError(_msg)} return $iterator_wrapper(new $value_iterator(self),$dict_valuesDict)} function dict(args,second){var res={__class__:$DictDict,$numeric_dict :{},$object_dict :{},$string_dict :{},$str_hash:{},length: 0} if(args===undefined){return res} if(second===undefined){if(Array.isArray(args)){ var i=-1,stop=args.length-1 var si=$DictDict.__setitem__ while(i++=0;i--){if(isNaN(self.$items[i])){return true}} return false}else{return self.$items.indexOf(item)>-1}} if(self.$str &&(typeof item=='string')){return self.$items.indexOf(item)>-1} if(! _b_.isinstance(item,set)){_b_.hash(item)} for(var i=0,_len_i=self.$items.length;i < _len_i;i++){if(_b_.getattr(self.$items[i],'__eq__')(item))return true} return false} $SetDict.__eq__=function(self,other){ if(other===undefined)return self===set if(_b_.isinstance(other,_b_.set)){if(other.$items.length==self.$items.length){for(var i=0,_len_i=self.$items.length;i < _len_i;i++){if($SetDict.__contains__(self,other.$items[i])===false)return false} return true} return false} if(_b_.isinstance(other,[_b_.list])){if(_b_.len(other)!=self.$items.length)return false for(var i=0,_len_i=_b_.len(other);i < _len_i;i++){var _value=_b_.getattr(other,'__getitem__')(i) if($SetDict.__contains__(self,_value)===false)return false} return true} if(_b_.hasattr(other,'__iter__')){ if(_b_.len(other)!=self.$items.length)return false var _it=_b_.iter(other) while(1){try{ var e=_b_.next(_it) if(!$SetDict.__contains__(self,e))return false}catch(err){if(err.__name__=="StopIteration"){break} throw err}} return true} return false} $SetDict.__format__=function(self,format_string){return $SetDict.__str__(self)} $SetDict.__ge__=function(self,other){if(_b_.isinstance(other,[set,frozenset])){return !$SetDict.__lt__(self,other)}else{return _b_.object.$dict.__ge__(self,other)}} $SetDict.__gt__=function(self,other){if(_b_.isinstance(other,[set,frozenset])){return !$SetDict.__le__(self,other)}else{return _b_.object.$dict.__gt__(self,other)}} $SetDict.__init__=function(self){var $=$B.args('__init__',2,{self:null,iterable:null},['self','iterable'],arguments,{iterable:[]},null,null),self=$.self,iterable=$.iterable if(_b_.isinstance(iterable,[set,frozenset])){self.$items=iterable.$items.slice() return $N} var it=_b_.iter(iterable),obj={$items:[],$str:true,$num:true} while(1){try{var item=_b_.next(it) $SetDict.add(obj,item)}catch(err){if(_b_.isinstance(err,_b_.StopIteration)){break} throw err}} self.$items=obj.$items return $N} var $set_iterator=$B.$iterator_class('set iterator') $SetDict.__iter__=function(self){var it=$B.$iterator(self.$items,$set_iterator),len=self.$items.length,nxt=it.__next__ it.__next__=function(){if(it.__len__()!=len){throw _b_.RuntimeError("size changed during iteration")} return nxt()} return it} $SetDict.__le__=function(self,other){if(_b_.isinstance(other,[set,frozenset])){var cfunc=_b_.getattr(other,'__contains__') for(var i=0,_len_i=self.$items.length;i < _len_i;i++){if(!cfunc(self.$items[i]))return false} return true}else{return _b_.object.$dict.__le__(self,other)}} $SetDict.__len__=function(self){return self.$items.length} $SetDict.__lt__=function(self,other){if(_b_.isinstance(other,[set,frozenset])){return($SetDict.__le__(self,other)&& $SetDict.__len__(self)<_b_.getattr(other,'__len__')())}else{return _b_.object.$dict['__lt__'](self,other)}} $SetDict.__mro__=[_b_.object.$dict] $SetDict.__ne__=function(self,other){return !$SetDict.__eq__(self,other)} $SetDict.__or__=function(self,other,accept_iter){ var res=clone(self) var func=_b_.getattr(_b_.iter(other),'__next__') while(1){try{$SetDict.add(res,func())} catch(err){if(_b_.isinstance(err,_b_.StopIteration)){break} throw err}} res.__class__=self.__class__ return res} $SetDict.__str__=$SetDict.__repr__=function(self){var frozen=self.$real==='frozen' self.$cycle=self.$cycle===undefined ? 0 : self.$cycle+1 if(self.$items.length===0){if(frozen)return 'frozenset()' return 'set()'} var klass_name=$B.get_class(self).__name__,head=klass_name+'({',tail='})' if(head=='set('){head='{';tail='}'} var res=[] if(self.$cycle){self.$cycle-- return klass_name+'(...)'} for(var i=0,_len_i=self.$items.length;i < _len_i;i++){var r=_b_.repr(self.$items[i]) if(r===self||r===self.$items[i]){res.push('{...}')} else{res.push(r)}} res=res.join(', ') self.$cycle-- return head+res+tail} $SetDict.__sub__=function(self,other,accept_iter){ $test(accept_iter,other,'-') var res=create_type(self) var cfunc=_b_.getattr(other,'__contains__') for(var i=0,_len_i=self.$items.length;i < _len_i;i++){if(!cfunc(self.$items[i])){res.$items.push(self.$items[i])}} return res} $SetDict.__xor__=function(self,other,accept_iter){ $test(accept_iter,other,'^') var res=create_type(self) var cfunc=_b_.getattr(other,'__contains__') for(var i=0,_len_i=self.$items.length;i < _len_i;i++){if(!cfunc(self.$items[i])){$SetDict.add(res,self.$items[i])}} for(var i=0,_len_i=other.$items.length;i < _len_i;i++){if(!$SetDict.__contains__(self,other.$items[i])){$SetDict.add(res,other.$items[i])}} return res} function $test(accept_iter,other,op){if(accept_iter===undefined && !_b_.isinstance(other,[set,frozenset])){throw _b_.TypeError("unsupported operand type(s) for "+op+ ": 'set' and '"+$B.get_class(other).__name__+"'")}} $B.make_rmethods($SetDict) $SetDict.add=function(){var $=$B.args('add',2,{self:null,item:null},['self','item'],arguments,{},null,null),self=$.self,item=$.item _b_.hash(item) if(self.$str && !(typeof item=='string')){self.$str=false} if(self.$num && !(typeof item=='number')){self.$num=false} if(self.$num||self.$str){var ix=self.$items.indexOf(item) if(ix==-1){self.$items.push(item)} else{ if(item!==self.$items[ix]){self.$items.push(item)}} return $N} var cfunc=_b_.getattr(item,'__eq__') for(var i=0,_len_i=self.$items.length;i < _len_i;i++){if(cfunc(self.$items[i]))return} self.$items.push(item) return $N} $SetDict.clear=function(){var $=$B.args('clear',1,{self:null},['self'],arguments,{},null,null) $.self.$items=[]; return $N} $SetDict.copy=function(){var $=$B.args('copy',1,{self:null},['self'],arguments,{},null,null) if(_b_.isinstance($.self,frozenset)){return $.self} var res=set() for(var i=0,_len_i=$.self.$items.length;i < _len_i;i++){res.$items[i]=$.self.$items[i]} return res} $SetDict.difference_update=function(self){var $=$B.args('difference_update',1,{self:null},['self'],arguments,{},'args',null) for(var i=0;i<$.args.length;i++){var s=set($.args[i]),_next=_b_.getattr(_b_.iter(s),'__next__'),item while(true){try{item=_next() var _type=typeof item if(_type=='string' ||_type=="number"){var _index=self.$items.indexOf(item) if(_index > -1){self.$items.splice(_index,1)}}else{ for(var j=0;j < self.$items.length;j++){if(_b_.getattr(self.$items[j],'__eq__')(item)){self.$items.splice(j,1)}}}}catch(err){if(_b_.isinstance(err,_b_.StopIteration)){break} throw err}}} return $N} $SetDict.discard=function(){var $=$B.args('discard',2,{self:null,item:null},['self','item'],arguments,{},null,null) try{$SetDict.remove($.self,$.item)} catch(err){if(!_b_.isinstance(err,[_b_.KeyError,_b_.LookupError])){throw err}} return $N} $SetDict.intersection_update=function(){ var $=$B.args('intersection_update',1,{self:null},['self'],arguments,{},'args',null),self=$.self for(var i=0;i<$.args.length;i++){var remove=[],s=set($.args[i]) for(var j=0;j -1){remove.push(_index)}else{add.push(item)}}else{ var found=false for(var j=0;!found && j < self.$items.length;j++){if(_b_.getattr(self.$items[j],'__eq__')(item)){remove.push(j) found=true}} if(!found){add.push(item)}}}catch(err){if(_b_.isinstance(err,_b_.StopIteration)){break} throw err}} remove.sort(function(x,y){return x-y}).reverse() for(var i=0;i 0)) )}catch(err){return false}} var $DOMEventAttrs_W3C=['NONE','CAPTURING_PHASE','AT_TARGET','BUBBLING_PHASE','type','target','currentTarget','eventPhase','bubbles','cancelable','timeStamp','stopPropagation','preventDefault','initEvent'] var $DOMEventAttrs_IE=['altKey','altLeft','button','cancelBubble','clientX','clientY','contentOverflow','ctrlKey','ctrlLeft','data','dataFld','dataTransfer','fromElement','keyCode','nextPage','offsetX','offsetY','origin','propertyName','reason','recordset','repeat','screenX','screenY','shiftKey','shiftLeft','source','srcElement','srcFilter','srcUrn','toElement','type','url','wheelDelta','x','y'] $B.$isEvent=function(obj){var flag=true for(var i=0;i<$DOMEventAttrs_W3C.length;i++){if(obj[$DOMEventAttrs_W3C[i]]===undefined){flag=false;break}} if(flag)return true for(var i=0;i<$DOMEventAttrs_IE.length;i++){if(obj[$DOMEventAttrs_IE[i]]===undefined)return false} return true} var $NodeTypes={1:"ELEMENT",2:"ATTRIBUTE",3:"TEXT",4:"CDATA_SECTION",5:"ENTITY_REFERENCE",6:"ENTITY",7:"PROCESSING_INSTRUCTION",8:"COMMENT",9:"DOCUMENT",10:"DOCUMENT_TYPE",11:"DOCUMENT_FRAGMENT",12:"NOTATION"} var $DOMEventDict={__class__:$B.$type,__name__:'DOMEvent'} $DOMEventDict.__mro__=[$ObjectDict] $DOMEventDict.__getattribute__=function(self,attr){switch(attr){case 'x': return $mouseCoords(self).x case 'y': return $mouseCoords(self).y case 'data': if(self.dataTransfer!==undefined)return $Clipboard(self.dataTransfer) return self['data'] case 'target': if(self.target===undefined)return DOMNode(self.target) return DOMNode(self.target) case 'char': return String.fromCharCode(self.which)} var res=self[attr] if(res!==undefined){if(typeof res=='function'){var func=function(){return res.apply(self,arguments)} func.$infos={__name__:res.toString().substr(9,res.toString().search('{'))} return func} return $B.$JS2Py(res)} throw _b_.AttributeError("object DOMEvent has no attribute '"+attr+"'")} function $DOMEvent(ev){ev.__class__=$DOMEventDict if(ev.preventDefault===undefined){ev.preventDefault=function(){ev.returnValue=false}} if(ev.stopPropagation===undefined){ev.stopPropagation=function(){ev.cancelBubble=true}} ev.__repr__=function(){return ''} ev.toString=ev.__str__=ev.__repr__ return ev} $B.$DOMEvent=$DOMEvent $B.DOMEvent=function(evt_name){ return $DOMEvent(new Event(evt_name))} $B.DOMEvent.__class__=$B.$factory $B.DOMEvent.$dict=$DOMEventDict $DOMEventDict.$factory=$B.DOMEvent var $ClipboardDict={__class__:$B.$type,__name__:'Clipboard'} $ClipboardDict.__getitem__=function(self,name){return self.data.getData(name)} $ClipboardDict.__mro__=[$ObjectDict] $ClipboardDict.__setitem__=function(self,name,value){self.data.setData(name,value)} function $Clipboard(data){ return{ data : data,__class__ : $ClipboardDict,}} function $EventsList(elt,evt,arg){ this.elt=elt this.evt=evt if(isintance(arg,list)){this.callbacks=arg} else{this.callbacks=[arg]} this.remove=function(callback){var found=false for(var i=0;i"} dom.FileReader.__class__=$B.$type dom.FileReader.__str__=function(){return ""} function $Options(parent){return{ __class__:$OptionsDict,parent:parent}} var $OptionsDict={__class__:$B.$type,__name__:'Options'} $OptionsDict.__delitem__=function(self,arg){self.parent.options.remove(arg.elt)} $OptionsDict.__getitem__=function(self,key){return DOMNode(self.parent.options[key])} $OptionsDict.__len__=function(self){return self.parent.options.length} $OptionsDict.__mro__=[$ObjectDict] $OptionsDict.__setattr__=function(self,attr,value){self.parent.options[attr]=value} $OptionsDict.__setitem__=function(self,attr,value){self.parent.options[attr]=$B.$JS2Py(value)} $OptionsDict.__str__=function(self){return ""} $OptionsDict.append=function(self,element){self.parent.options.add(element.elt)} $OptionsDict.insert=function(self,index,element){if(index===undefined){self.parent.options.add(element.elt)} else{self.parent.options.add(element.elt,index)}} $OptionsDict.item=function(self,index){return self.parent.options.item(index)} $OptionsDict.namedItem=function(self,name){return self.parent.options.namedItem(name)} $OptionsDict.remove=function(self,arg){self.parent.options.remove(arg.elt)} var $StyleDict={__class__:$B.$type,__name__:'CSSProperty'} $StyleDict.__mro__=[$ObjectDict] $StyleDict.__getattr__=function(self,attr){return $ObjectDict.__getattribute__(self.js,attr)} $StyleDict.__setattr__=function(self,attr,value){if(attr.toLowerCase()==='float'){self.js.cssFloat=value self.js.styleFloat=value}else{switch(attr){case 'top': case 'left': case 'height': case 'width': case 'borderWidth': if(isinstance(value,_b_.int))value=value+'px'} self.js[attr]=value}} function $Style(style){ return{__class__:$StyleDict,js:style}} $Style.__class__=$B.$factory $Style.$dict=$StyleDict $StyleDict.$factory=$Style var DOMNode=$B.DOMNode=function(elt){if(elt.__class__===DOMNodeDict){return elt} if(typeof elt=="number" ||typeof elt=="boolean" || typeof elt=="string"){return elt} var res={} res.$dict={} res.elt=elt if(elt['$brython_id']===undefined||elt.nodeType===9){ elt.$brython_id='DOM-'+$B.UUID()} res.__class__=DOMNodeDict return res} DOMNodeDict={__class__ : $B.$type,__name__ : 'DOMNode'} DOMNode.__class__=$B.$factory DOMNode.$dict=DOMNodeDict DOMNodeDict.$factory=DOMNode DOMNodeDict.__mro__=[_b_.object.$dict] DOMNodeDict.__add__=function(self,other){ var res=$TagSum() res.children=[self],pos=1 if(isinstance(other,$TagSum)){res.children=res.children.concat(other.children)}else if(isinstance(other,[_b_.str,_b_.int,_b_.float,_b_.list,_b_.dict,_b_.set,_b_.tuple])){res.children[pos++]=DOMNode(document.createTextNode(_b_.str(other)))}else if(isinstance(other,DOMNode)){res.children[pos++]=other}else{ try{res.children=res.children.concat(_b_.list(other))} catch(err){throw _b_.TypeError("can't add '"+ $B.get_class(other).__name__+"' object to DOMNode instance")}} return res} DOMNodeDict.__bool__=function(self){return true} DOMNodeDict.__class__=$B.$type DOMNodeDict.__contains__=function(self,key){ if(self.elt.nodeType==9 && typeof key=="string"){return document.getElementById(key)!==null} key=key.elt !==undefined ? key.elt : key if(self.elt.length!==undefined && typeof self.elt.item=="function"){for(var i=0,len=self.elt.length;i0){var res=$TagSum() var pos=res.children.length for(var i=0;i"} var res=""} DOMNodeDict.__setattr__=function(self,attr,value){if(attr.substr(0,2)=='on'){ if(!_b_.bool(value)){ DOMNodeDict.unbind(self,attr.substr(2))}else{ DOMNodeDict.bind(self,attr.substr(2),value)}}else{if(DOMNodeDict['set_'+attr]!==undefined){return DOMNodeDict['set_'+attr](self,value)} var attr1=attr.replace('_','-').toLowerCase() if(self.elt instanceof SVGElement && self.elt.getAttributeNS(null,attr1)!==null){self.elt.setAttributeNS(null,attr1,value) return} if(self.elt[attr1]!==undefined){self.elt[attr1]=value;return} if(typeof self.elt.getAttribute=='function' && typeof self.elt.setAttribute=='function'){var res=self.elt.getAttribute(attr1) if(res!==undefined&&res!==null&&res!=''){if(value===false){self.elt.removeAttribute(attr1)}else{self.elt.setAttribute(attr1,value)} return}} self.elt[attr]=value}} DOMNodeDict.__setitem__=function(self,key,value){self.elt.childNodes[key]=value} DOMNodeDict.abs_left={__get__: function(self){return $getPosition(self.elt).left},__set__: function(){throw _b_.AttributeError("'DOMNode' objectattribute 'abs_left' is read-only")}} DOMNodeDict.abs_top={__get__: function(self){return $getPosition(self.elt).top},__set__: function(){throw _b_.AttributeError("'DOMNode' objectattribute 'abs_top' is read-only")}} DOMNodeDict.bind=function(self,event){ var _id if(self.elt.nodeType===9){_id=0} else{_id=self.elt.$brython_id} var _d=_b_.dict.$dict if(!_d.__contains__($B.events,_id)){_d.__setitem__($B.events,_id,dict())} var item=_d.__getitem__($B.events,_id) if(!_d.__contains__(item,event)){_d.__setitem__(item,event,[])} var evlist=_d.__getitem__(item,event) var pos=evlist.length for(var i=2;i=0;i--){elt.removeChild(elt.childNodes[i])}} DOMNodeDict.Class=function(self){if(self.elt.className !==undefined)return self.elt.className return None} DOMNodeDict.class_name=function(self){return DOMNodeDict.Class(self)} DOMNodeDict.clone=function(self){res=DOMNode(self.elt.cloneNode(true)) res.elt.$brython_id='DOM-' + $B.UUID() var _d=_b_.dict.$dict if(_d.__contains__($B.events,self.elt.$brython_id)){var events=_d.__getitem__($B.events,self.elt.$brython_id) var items=_b_.list(_d.items(events)) for(var i=0;i=0;i--)res.splice(to_delete[i],1)} return res} DOMNodeDict.getContext=function(self){ if(!('getContext' in self.elt)){throw _b_.AttributeError("object has no attribute 'getContext'")} var obj=self.elt return function(ctx){return JSObject(obj.getContext(ctx))}} DOMNodeDict.getSelectionRange=function(self){ if(self.elt['getSelectionRange']!==undefined){return self.elt.getSelectionRange.apply(null,arguments)}} DOMNodeDict.height={'__get__': function(self){ if(self.elt.tagName=='CANVAS'){return self.elt.height} if(self.elt.style===undefined){return _b_.None} var res=parseInt(self.elt.style.height) if(isNaN(res)){return self.elt.offsetHeight} return res},'__set__': function(obj,self,value){if(self.elt.tagName=='CANVAS'){self.elt.height=value} self.elt.style.height=value+'px'}} DOMNodeDict.html=function(self){var res=self.elt.innerHTML if(res===undefined){if(self.elt.nodeType==9){res=self.elt.body.innerHTML} else{res=_b_.None}} return res} DOMNodeDict.id=function(self){if(self.elt.id !==undefined)return self.elt.id return None} DOMNodeDict.inside=function(self,other){ other=other.elt var elt=self.elt while(true){if(other===elt){return true} elt=elt.parentElement if(!elt){return false}}} DOMNodeDict.left={'__get__': function(self){if(self.elt.style===undefined){return _b_.None} var res=parseInt(self.elt.style.left) if(isNaN(res)){throw _b_.AttributeError("node has no attribute 'left'")} return res},'__set__': function(obj,self,value){self.elt.style.left=value+'px'}} DOMNodeDict.options=function(self){ return new $OptionsClass(self.elt)} DOMNodeDict.parent=function(self){if(self.elt.parentElement)return DOMNode(self.elt.parentElement) return None} DOMNodeDict.remove=function(self,child){ console.log('WARNING - since version 3.1.2, method remove() is the '+ 'DOM Node method of the same name.') if(typeof self.elt.remove=="function"){self.elt.remove(child) return None}else{throw _b_.AttributeError(_b_.str(self)+" has no attribute 'remove'")}} DOMNodeDict.reset=function(self){ return function(){self.elt.reset()}} DOMNodeDict.style=function(self){ self.elt.style.float=self.elt.style.cssFloat ||self.style.styleFloat return $B.JSObject(self.elt.style)} DOMNodeDict.top={'__get__': function(self){if(self.elt.style===undefined){return _b_.None} var res=parseInt(self.elt.style.top) if(isNaN(res)){throw _b_.AttributeError("node has no attribute 'top'")} return res},'__set__': function(obj,self,value){self.elt.style.top=value+'px'}} DOMNodeDict.setSelectionRange=function(self){ if(this['setSelectionRange']!==undefined){return(function(obj){return function(){return obj.setSelectionRange.apply(obj,arguments)}})(this)}else if(this['createTextRange']!==undefined){return(function(obj){return function(start_pos,end_pos){if(end_pos==undefined){end_pos=start_pos} var range=obj.createTextRange(); range.collapse(true); range.moveEnd('character',start_pos); range.moveStart('character',end_pos); range.select();}})(this)}} DOMNodeDict.set_class_name=function(self,arg){self.elt.setAttribute('class',arg)} DOMNodeDict.set_html=function(self,value){var elt=self.elt if(elt.nodeType==9){elt=elt.body} elt.innerHTML=str(value)} DOMNodeDict.set_style=function(self,style){ if(!_b_.isinstance(style,_b_.dict)){throw TypeError('style must be dict, not '+$B.get_class(style).__name__)} var items=_b_.list(_b_.dict.$dict.items(style)) for(var i=0;i-1} $QueryDict.__getitem__=function(self,key){ var result=self._values[key] if(result===undefined)throw KeyError(key) if(result.length==1)return result[0] return result} var $QueryDict_iterator=$B.$iterator_class('query string iterator') $QueryDict.__iter__=function(self){return $B.$iterator(self._keys,$QueryDict_iterator)} $QueryDict.__mro__=[$ObjectDict] $QueryDict.getfirst=function(self,key,_default){ var result=self._values[key] if(result===undefined){if(_default===undefined)return None return _default} return result[0]} $QueryDict.getlist=function(self,key){ var result=self._values[key] if(result===undefined)return[] return result} $QueryDict.getvalue=function(self,key,_default){try{return $QueryDict.__getitem__(self,key)} catch(err){if(_default===undefined)return None return _default}} $QueryDict.keys=function(self){return self._keys} DOMNodeDict.query=function(self){var res={__class__:$QueryDict,_keys :[],_values :{}} var qs=location.search.substr(1).split('&') for(var i=0;i-1){res._values[key].push(value)} else{res._keys.push(key) res._values[key]=[value]}} return res} var $TagSumDict={__class__ : $B.$type,__name__:'TagSum'} $TagSumDict.appendChild=function(self,child){self.children.push(child)} $TagSumDict.__add__=function(self,other){if($B.get_class(other)===$TagSumDict){self.children=self.children.concat(other.children)}else if(isinstance(other,[_b_.str,_b_.int,_b_.float,_b_.dict,_b_.set,_b_.list])){self.children=self.children.concat(DOMNode(document.createTextNode(other)))}else{self.children.push(other)} return self} $TagSumDict.__mro__=[$ObjectDict] $TagSumDict.__radd__=function(self,other){var res=$TagSum() res.children=self.children.concat(DOMNode(document.createTextNode(other))) return res} $TagSumDict.__repr__=function(self){var res=' ' for(var i=0;i'}} $B.GeneratorBreak={} $B.$GeneratorSendError={} var $GeneratorReturn={} $B.generator_return=function(value){return{__class__:$GeneratorReturn,value:value}} function in_loop(node){ while(node){if(node.loop_start!==undefined)return node node=node.parent} return false} function in_try(node){ var tries=[],pnode=node.parent,pos=0 while(pnode){if(pnode.is_try){tries[pos++]=pnode} pnode=pnode.parent} return tries} var $BRGeneratorDict={__class__:$B.$type,__name__:'generator'} $B.gen_counter=0 $B.$BRgenerator=function(func_name,blocks,def_id,def_node){ var def_ctx=def_node.C.tree[0] var module=def_node.module, iter_id=def_id var func_root=new $B.genNode(def_ctx.to_js()) func_root.module=module func_root.yields=[] func_root.loop_ends={} func_root.def_id=def_id func_root.iter_id=iter_id for(var i=0,_len_i=def_node.children.length;i < _len_i;i++){var nd=make_node(func_root,def_node.children[i]) if(nd===undefined){continue} func_root.addChild(nd)} var obj={__class__ : $BRGeneratorDict,blocks: blocks,def_ctx:def_ctx,def_id:def_id,func_name:func_name,func_root:func_root,module:module,gi_running:false,iter_id:iter_id,id:iter_id,num:0} var src=func_root.src(), raw_src=src.substr(src.search('function')) raw_src +='return '+def_ctx.name+def_ctx.num+'}' var funcs=[raw_src] obj.parent_block=def_node.parent_block for(var i=0;i"} $B.imported[name]=$B.modules[name]=module_obj} for(var attr in modules){load(attr,modules[attr])} modules['browser'].html=modules['browser.html'] var _b_=$B.builtins _b_.__builtins__=$B.$ModuleDict.$factory('__builtins__','Python builtins') for(var attr in $B.builtins){_b_.__builtins__[attr]=_b_[attr]} _b_.__builtins__.__setattr__=function(attr,value){_b_[attr]=value} $B.bound.__builtins__.__builtins__=_b_.__builtins__})(__BRYTHON__) ;(function($B){var _b_=$B.builtins function import_hooks(mod_name,_path,module,blocking){ if($B.is_none(module)){module=undefined;} var _meta_path=$B.meta_path; var spec=undefined; for(var i=0,_len_i=_meta_path.length;i < _len_i && $B.is_none(spec);i++){var _finder=_meta_path[i],find_spec=_b_.getattr(_finder,'find_spec',null) if(find_spec !==null){spec=_b_.getattr(find_spec,'__call__')(mod_name,_path,undefined,blocking); spec.blocking=blocking}} if($B.is_none(spec)){ throw _b_.ImportError('No module named '+mod_name);} var _loader=_b_.getattr(spec,'loader',_b_.None),_sys_modules=$B.imported,_spec_name=_b_.getattr(spec,'name'); if($B.is_none(module)){ if(!$B.is_none(_loader)){var create_module=_b_.getattr(_loader,'create_module',_b_.None); if(!$B.is_none(create_module)){module=_b_.getattr(create_module,'__call__')(spec);}} if(module===undefined){throw _b_.ImportError(mod_name)} if($B.is_none(module)){ module=$B.$ModuleDict.$factory(mod_name); var mod_desc=_b_.getattr(spec,'origin'); if(_b_.getattr(spec,'has_location')){mod_desc="from '" + mod_desc + "'";} else{ mod_desc='(' + mod_desc + ')';} module.toString=module.__repr__=module.__str__= function(){return ""}}} module.__name__=_spec_name; module.__loader__=_loader; module.__package__=_b_.getattr(spec,'parent',''); module.__spec__=spec; var locs=_b_.getattr(spec,'submodule_search_locations'); if(module.$is_package=!$B.is_none(locs)){module.__path__=locs;} if(_b_.getattr(spec,'has_location')){module.__file__=_b_.getattr(spec,'origin') $B.$py_module_path[module.__name__]=module.__file__;} var cached=_b_.getattr(spec,'cached'); if(!$B.is_none(cached)){module.__cached__=cached;} if($B.is_none(_loader)){if(!$B.is_none(locs)){$B.modules[_spec_name]=_sys_modules[_spec_name]=module;} else{ throw _b_.ImportError(mod_name);}} else{ var exec_module=_b_.getattr(_loader,'exec_module',_b_.None); if($B.is_none(exec_module)){ module=_b_.getattr(_b_.getattr(_loader,'load_module'),'__call__')(_spec_name);} else{ $B.modules[_spec_name]=_sys_modules[_spec_name]=module; try{_b_.getattr(exec_module,'__call__')(module,blocking)} catch(e){delete $B.modules[_spec_name]; delete _sys_modules[_spec_name]; throw e;}}} return _sys_modules[_spec_name];} $B.import_hooks=import_hooks})(__BRYTHON__)