max_precision){throw _b_.OverflowError.$factory("precision too large")}var s;if(val.__class__===$B.long_int){s=$B.long_int.to_base(val,10)}else{s=val.toString()}if(precision-s.length>max_repeat){throw _b_.OverflowError.$factory("precision too large")}if(s[0]==="-"){return"-"+"0".repeat(Math.max(0,precision-s.length+1))+s.slice(1)}return"0".repeat(Math.max(0,precision-s.length))+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||isNaN(val)||val===Number.POSITIVE_INFINITY){return"+"}}else if(flags.space){if(val>=0||isNaN(val)){return" "}}return""};var str_format=function(val,flags){flags.pad_char=" ";return format_padding(str.$factory(val),flags)};var num_format=function(val,flags){number_check(val,flags);if($B.$isinstance(val,_b_.float)){val=parseInt(val.value)}else if(!$B.$isinstance(val,_b_.int)){val=parseInt(val)}else if($B.$isinstance(val,_b_.bool)){val=val?1:0}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(_b_.repr(val),flags)};var ascii_format=function(val,flags,type){flags.pad_char=" ";var ascii;if(type=="bytes"){var repr=_b_.repr(val);ascii=_b_.str.encode(repr,"ascii","backslashreplace");ascii=_b_.bytes.decode(ascii,"ascii")}else{ascii=_b_.ascii(val)}return format_padding(ascii,flags)};var _float_helper=function(val,flags){number_check(val,flags);if(flags.precision===undefined){if(!flags.decimal_point){flags.precision=6}else{flags.precision=0}}else{flags.precision=parseInt(flags.precision,10);validate_precision(flags.precision)}return $B.$isinstance(val,_b_.int)?val:val.value};var validate_precision=function(precision){if(precision>20){precision=20}};function handle_special_values(value,upper){var special;if(isNaN(value)){special=upper?"NAN":"nan"}else if(value==Number.POSITIVE_INFINITY){special=upper?"INF":"inf"}else if(value==Number.NEGATIVE_INFINITY){special=upper?"-INF":"-inf"}return special}var floating_point_format=function(val,upper,flags){val=_float_helper(val,flags);var special=handle_special_values(val,upper);if(special){return format_padding(format_sign(val,flags)+special,flags)}var p=flags.precision;if(p==0){p=1}var exp_format=val.toExponential(p-1),e_index=exp_format.indexOf("e"),exp=parseInt(exp_format.substr(e_index+1)),res;function remove_zeros(v){if(flags.alternate){return v}if(v.indexOf(".")>-1){while(v.endsWith("0")){v=v.substr(0,v.length-1)}if(v.endsWith(".")){v=v.substr(0,v.length-1)}}return v}if(-4<=exp&&exp-1){return BigInt(v).toString()}const mul=Math.pow(10,d);var is_neg=v<0;if(is_neg){v=-v}var res_floor=(Math.floor(v*mul)/mul).toFixed(d),res_ceil=(Math.ceil(v*mul)/mul).toFixed(d),res;if(v-res_floor==res_ceil-v){var last=res_floor[res_floor.length-1];res=last.match(/[02468]/)?res_floor:res_ceil}else{res=v-res_floor1){mant+="."+parts[0].substr(1)+(parts[1]||"")}else if(parts[1]){mant+="."+parts[1]}}mant=parseFloat(mant);mant=roundDownToFixed(parseFloat(mant),precision);if(parseFloat(mant)==10){parts=mant.split(".");parts[0]="1";mant=parts.join(".");exp=parseInt(exp)+(exp_sign=="+"?1:-1);if(exp==0){exp_sign="+"}}if(flags.alternate&&mant.indexOf(".")==-1){mant+="."}if(exp.toString().length==1){exp="0"+exp}return`${is_neg?"-":""}${mant}${upper?"E":"e"}${exp_sign}${exp}`};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)};$B.formatters={floating_point_format:floating_point_format,floating_point_decimal_format:floating_point_decimal_format,floating_point_exponential_format:floating_point_exponential_format};var signed_hex_format=function(val,upper,flags){var ret;if(!$B.$isinstance(val,_b_.int)){throw _b_.TypeError.$factory(`%X format: an integer is required, not ${$B.class_name(val)}`)}else if($B.$isinstance(val,_b_.bool)){val=val?1:0}if(val.__class__===$B.long_int){ret=val.value.toString(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,flags);var ret;if(val.__class__===$B.long_int){ret=$B.long_int.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)};function series_of_bytes(val,flags){if(val.__class__&&val.__class__.$buffer_protocol){var it=_b_.iter(val),ints=[];while(true){try{ints.push(_b_.next(it))}catch(err){if(err.__class__===_b_.StopIteration){var b=_b_.bytes.$factory(ints);return format_padding(_b_.bytes.decode(b,"ascii"),flags)}throw err}}}else{try{var bytes_obj=$B.$getattr(val,"__bytes__")();return format_padding(_b_.bytes.decode(bytes_obj),flags)}catch(err){if(err.__class__===_b_.AttributeError){throw _b_.TypeError.$factory("%b does not accept '"+$B.class_name(val)+"'")}throw err}}}var single_char_format=function(val,flags,type){if(type=="bytes"){if($B.$isinstance(val,_b_.int)){if(val.__class__===$B.long_int||val<0||val>255){throw _b_.OverflowError.$factory("%c arg not in range(256)")}}else if($B.$isinstance(val,[_b_.bytes,_b_.bytearray])){if(val.source.length>1){throw _b_.TypeError.$factory("%c requires an integer in range(256) or a single byte")}val=val.source[0]}}else{if($B.$isinstance(val,_b_.str)){if(_b_.str.__len__(val)==1){return val}throw _b_.TypeError.$factory("%c requires int or char")}else if(!$B.$isinstance(val,_b_.int)){throw _b_.TypeError.$factory("%c requires int or char")}if(val.__class__===$B.long_int&&(val.value<0||val.value>=1114112)||(val<0||val>=1114112)){throw _b_.OverflowError.$factory("%c arg not in range(0x110000)")}}return format_padding(_b_.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={b:series_of_bytes,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"};const conversion_flags="#0- +",length_modifiers="hlL",conversion_types="diouxXeEfFgGcrsa";function parse_mod_format(s,type,pos){var flags={pad_char:" "},len=s.length,start_pos=pos,mo;pos++;while(pos-1){flags.conversion_flag=char;if(char=="#"){flags.alternate=true}else if(char=="-"){flags.left=true}else if(char=="+"){flags.sign="+"}else if(char=="0"){flags.pad_char="0"}else if(char==" "){flags.space=true}pos++}else if(char=="*"){flags.padding="*";pos++}else if(mo=/^\d+/.exec(s.substr(pos))){flags.padding=mo[0];pos+=mo[0].length}else if(char=="."){pos++;if(s[pos]=="*"){flags.precision="*";pos++}else if(mo=/^\d+/.exec(s.substr(pos))){flags.precision=mo[0];pos+=mo[0].length}else{flags.precision="0"}}else if(length_modifiers.indexOf(char)>-1){flags.length_modifier=char;pos++}else if(conversion_types.indexOf(char)>-1||char=="b"&&type=="bytes"){if(type=="bytes"){if(char=="s"){char="b"}else if(char=="r"){char="a"}}flags.conversion_type=char;flags.end=pos;flags.string=s.substring(start_pos,pos+1);if(flags.left&&flags.pad_char=="0"){flags.pad_char=" "}return flags}else{throw _b_.ValueError.$factory(`invalid character in format: ${char}`)}}throw _b_.ValueError.$factory("invalid format")}function is_mapping(obj){return _b_.hasattr(obj,"keys")&&_b_.hasattr(obj,"__getitem__")}$B.printf_format=function(s,type,args){var argpos=null,getitem;if($B.$isinstance(args,_b_.tuple)){argpos=0}else{getitem=$B.$getattr(args,"__getitem__",_b_.None)}var ret="",nbph=0,pos=0,len=s.length;while(pos1){if(!$B.$isinstance(args,_b_.tuple)&&!is_mapping(args)){throw _b_.TypeError.$factory("not enough arguments for format string")}}var fmt=parse_mod_format(s,type,pos);pos=fmt.end+1;if(fmt.padding=="*"){if(args[argpos]===undefined){throw _b_.ValueError.$factory("no value for field width *")}fmt.padding=args[argpos];argpos++}if(fmt.precision=="*"){if(args[argpos]===undefined){throw _b_.ValueError.$factory("no value for precision *")}fmt.precision=args[argpos];argpos++}var func=char_mapping[fmt.conversion_type],value;if(fmt.mapping_key!==undefined){value=getitem(fmt.mapping_key)}else{if(argpos===null){value=args}else{value=args[argpos];if(value===undefined){throw _b_.TypeError.$factory("not enough arguments for format string")}argpos++}}ret+=func(value,fmt,type)}}if(argpos!==null){if(args.length>argpos){throw _b_.TypeError.$factory("not enough arguments for format string")}else if(args.length=127&&cp<160){cp=cp.toString(16);if(cp.length<2){cp="0"+cp}repl+="\\x"+cp}else if(cp>=768&&cp<=879){repl+=""+chars[i]+" "}else if(cp.toString(16)=="feff"){repl+="\\ufeff"}else{repl+=chars[i]}}var res=repl;if(res.search('"')==-1&&res.search("'")==-1){return"'"+res+"'"}else if(_self.search('"')==-1){return'"'+res+'"'}var qesc=new RegExp("'","g");res="'"+res.replace(qesc,"\\'")+"'";return res};str.__rmod__=function(){var $=$B.args("__rmod__",2,{self:null,other:null},["self","other"],arguments,{},null,null);if(!$B.$isinstance($.other,str)){return _b_.NotImplemented}return str.__mod__($.other,$.self)};str.__rmul__=function(_self,other){_self=to_string(_self);if($B.$isinstance(other,_b_.int)){other=_b_.int.numerator(other);var res="";while(other>0){res+=_self;other--}return res}return _b_.NotImplemented};str.__setattr__=function(_self,attr,value){if(typeof _self==="string"){if(str.hasOwnProperty(attr)){throw _b_.AttributeError.$factory("'str' object attribute '"+attr+"' is read-only")}else{throw _b_.AttributeError.$factory("'str' object has no attribute '"+attr+"'")}}_b_.dict.$setitem(_self.__dict__,attr,value);return _b_.None};str.__setitem__=function(){throw _b_.TypeError.$factory("'str' object does not support item assignment")};var combining=[];for(var cp=768;cp<=879;cp++){combining.push(String.fromCharCode(cp))}var combining_re=new RegExp("("+combining.join("|")+")","g");str.__str__=function(_self){_self=to_string(_self);var repl="",chars=to_chars(_self);if(chars.length==_self.length){return _self.replace(combining_re,"$1")}for(var i=0;i=768&&cp<=879){repl+=""+chars[i]}else{repl+=chars[i]}}return repl};var body=`var _b_ = __BRYTHON__.builtins\nif(typeof other !== typeof _self){\n return _b_.NotImplemented}else if(typeof _self == "string"){\n return _self > other}else{\n return _self.$brython_value > other.$brython_value}`;var comps={">":"gt",">=":"ge","<":"lt","<=":"le"};for(var op in comps){str[`__${comps[op]}__`]=Function("_self","other",body.replace(/>/gm,op))}str.capitalize=function(){var $=$B.args("capitalize",1,{self:self},["self"],arguments,{},null,null),_self=to_string($.self);if(_self.length==0){return""}return _self.charAt(0).toUpperCase()+_self.substr(1).toLowerCase()};str.casefold=function(){var $=$B.args("casefold",1,{self:self},["self"],arguments,{},null,null),res="",char,cf,_self=to_string($.self),chars=to_chars(_self);for(var i=0,len=chars.length;i=0){n++;pos+=sub.length}else{break}}return n};str.encode=function(){var $=$B.args("encode",3,{self:null,encoding:null,errors:null},["self","encoding","errors"],arguments,{encoding:"utf-8",errors:"strict"},null,null),_self=to_string($.self);if($.encoding=="rot13"||$.encoding=="rot_13"){var res="";for(var i=0,len=_self.length;i0){res+=" ";col++}break;case"\r":case"\n":res+=car;col=0;break;default:res+=car;col++;break}pos++}return res};str.find=function(){var $=$B.args("str.find",4,{self:null,sub:null,start:null,end:null},["self","sub","start","end"],arguments,{start:0,end:null},null,null),_self,sub;check_str($.sub);normalize_start_end($);[_self,sub]=to_string([$.self,$.sub]);var len=str.__len__(_self),sub_len=str.__len__(sub);if(sub_len==0&&$.start==len){return len}if(len+sub_len==0){return-1}var js_start=pypos2jspos(_self,$.start),js_end=pypos2jspos(_self,$.end),ix=_self.slice(js_start,js_end).indexOf(sub);if(ix==-1){return-1}return jspos2pypos(_self,js_start+ix)};$B.parse_format=function(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(":")}elts=name.split("!");if(elts.length>1){name=elts[0];conv=elts[1]}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||"",string:fmt_string}};$B.split_format=function(s){var pos=0,_len=s.length,car,text="",parts=[],rank=0;while(pos<_len){car=s.charAt(pos);if(car=="{"&&s.charAt(pos+1)=="{"){text+="{";pos+=2}else if(car=="}"&&s.charAt(pos+1)=="}"){text+="}";pos+=2}else if(car=="{"){parts.push(text);var end=pos+1,nb=1;while(end<_len){if(s.charAt(end)=="{"){nb++;end++}else if(s.charAt(end)=="}"){nb--;end++;if(nb==0){var fmt_string=s.substring(pos+1,end-1);var fmt_obj=$B.parse_format(fmt_string);fmt_obj.raw_name=fmt_obj.name;fmt_obj.raw_spec=fmt_obj.spec;if(!fmt_obj.name){fmt_obj.name=rank+"";rank++}if(fmt_obj.spec!==undefined){function replace_nested(name,key){if(key==""){return"{"+rank+++"}"}return"{"+key+"}"}fmt_obj.spec=fmt_obj.spec.replace(/\{(.*?)\}/g,replace_nested)}parts.push(fmt_obj);text="";break}}else{end++}}if(nb>0){throw _b_.ValueError.$factory("wrong format "+s)}pos=end}else{text+=car;pos++}}if(text){parts.push(text)}return parts};str.format=function(){var last_arg=$B.last(arguments),$,mapping,getitem;if(last_arg.$nat=="mapping"){mapping=last_arg.mapping;getitem=$B.$getattr(mapping,"__getitem__");var args=[];for(let i=0,len=arguments.length-1;i-1){let pos=parseInt(fmt.name);value=_b_.tuple.__getitem__($.$args,pos)}else{value=getitem(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.$factory(value)}if(value.$is_class||value.$factory){res+=value.__class__.__format__(value,fmt.spec)}else{res+=$B.$getattr(value,"__format__")(fmt.spec)}}return res};str.format_map=function(){var $=$B.args("format_map",2,{self:null,mapping:null},["self","mapping"],arguments,{},null,null),_self=to_string($.self);return str.format(_self,{$nat:"mapping",mapping:$.mapping})};str.index=function(){var res=str.find.apply(null,arguments);if(res===-1){throw _b_.ValueError.$factory("substring not found")}return res};str.isascii=function(){var $=$B.args("isascii",1,{self:null},["self"],arguments,{},null,null),_self=to_string($.self);for(var i=0,len=_self.length;i127){return false}}return true};var unicode_categories_contain_character=function(categories,cp){for(var cat of categories){console.log(cat,cp);if($B.in_unicode_category(cat,cp)){return true}}return false};var alpha_categories=["Ll","Lu","Lm","Lt","Lo"];var alnum_categories=["Ll","Lu","Lm","Lt","Lo","Nd"];str.isalnum=function(){var $=$B.args("isalnum",1,{self:null},["self"],arguments,{},null,null);var _self=to_string($.self);if(_self.length==0){return false}for(var char of _self){if(!unicode_categories_contain_character(alnum_categories,_b_.ord(char))){return false}}return true};str.isalpha=function(){var $=$B.args("isalpha",1,{self:null},["self"],arguments,{},null,null);var _self=to_string($.self);if(_self.length==0){return false}for(var char of _self){if(!unicode_categories_contain_character(alpha_categories,_b_.ord(char))){return false}}return true};str.isdecimal=function(){var $=$B.args("isdecimal",1,{self:null},["self"],arguments,{},null,null),cp,_self=to_string($.self);for(var char of _self){cp=_b_.ord(char);if(!$B.in_unicode_category("Nd",cp)){return false}}return _self.length>0};str.isdigit=function(){var $=$B.args("isdigit",1,{self:null},["self"],arguments,{},null,null),cp,_self=to_string($.self);for(var char of _self){if(/\p{Nd}/u.test(char)){continue}cp=_b_.ord(char);if(!$B.in_unicode_category("No_digits",cp)){return false}}return _self.length>0};str.isidentifier=function(){var $=$B.args("isidentifier",1,{self:null},["self"],arguments,{},null,null),_self=to_string($.self);if(_self.length==0){return false}var chars=to_chars(_self);if(!$B.is_XID_Start(_b_.ord(chars[0]))){return false}else{for(var char of chars){var cp=_b_.ord(char);if(!$B.is_XID_Continue(cp)){return false}}}return true};str.islower=function(){var $=$B.args("islower",1,{self:null},["self"],arguments,{},null,null),has_cased=false,cp,_self=to_string($.self);for(var char of _self){cp=_b_.ord(char);if($B.in_unicode_category("Ll",cp)){has_cased=true;continue}else if($B.in_unicode_category("Lu",cp)||$B.in_unicode_category("Lt",cp)){return false}}return has_cased};const numeric_re=/\p{Nd}|\p{Nl}|\p{No}/u;str.isnumeric=function(){var $=$B.args("isnumeric",1,{self:null},["self"],arguments,{},null,null),_self=to_string($.self);for(var char of _self){if(!numeric_re.test(char)&&!$B.in_unicode_category("Lo_numeric",_b_.ord(char))){return false}}return _self.length>0};var unprintable_re=/\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}|\p{Zl}|\p{Zp}|\p{Zs}/u;str.isprintable=function(){var $=$B.args("isprintable",1,{self:null},["self"],arguments,{},null,null),_self=to_string($.self);for(var char of _self){if(char==" "){continue}if(unprintable_re.test(char)){return false}}return true};str.isspace=function(){var $=$B.args("isspace",1,{self:null},["self"],arguments,{},null,null),cp,_self=to_string($.self);for(var char of _self){cp=_b_.ord(char);if(!$B.in_unicode_category("Zs",cp)&&$B.unicode_bidi_whitespace.indexOf(cp)==-1){return false}}return _self.length>0};str.istitle=function(){var $=$B.args("istitle",1,{self:null},["self"],arguments,{},null,null),_self=to_string($.self);return _self.length>0&&str.title(_self)==_self};str.isupper=function(){var $=$B.args("islower",1,{self:null},["self"],arguments,{},null,null),is_upper=false,cp,_self=to_string($.self);for(var char of _self){cp=_b_.ord(char);if($B.in_unicode_category("Lu",cp)){is_upper=true;continue}else if($B.in_unicode_category("Ll",cp)||$B.in_unicode_category("Lt",cp)){return false}}return is_upper};str.join=function(){var $=$B.args("join",2,{self:null,iterable:null},["self","iterable"],arguments,{},null,null),_self=to_string($.self);var iterable=_b_.iter($.iterable),res=[],count=0;while(1){try{var obj2=_b_.next(iterable);if(!$B.$isinstance(obj2,str)){throw _b_.TypeError.$factory("sequence item "+count+": expected str instance, "+$B.class_name(obj2)+" found")}res.push(obj2)}catch(err){if($B.$isinstance(err,_b_.StopIteration)){break}else{throw err}}}return res.join(_self)};str.ljust=function(){var $=$B.args("ljust",3,{self:null,width:null,fillchar:null},["self","width","fillchar"],arguments,{fillchar:" "},null,null),_self=to_string($.self),len=str.__len__(_self);if($.width<=len){return _self}return _self+$.fillchar.repeat($.width-len)};str.lower=function(){var $=$B.args("lower",1,{self:null},["self"],arguments,{},null,null),_self=to_string($.self);return _self.toLowerCase()};str.lstrip=function(){var $=$B.args("lstrip",2,{self:null,chars:null},["self","chars"],arguments,{chars:_b_.None},null,null),_self=$.self,chars=$.chars;if(chars===_b_.None){return _self.trimStart()}[_self,chars]=to_string([_self,chars]);while(_self.length>0){var flag=false;for(var char of chars){if(_self.startsWith(char)){_self=_self.substr(char.length);flag=true;break}}if(!flag){return $.self.surrogates?$B.String(_self):_self}}return""};str.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.empty_dict();if($.y===null&&$.z===null){if(!$B.$isinstance($.x,_b_.dict)){throw _b_.TypeError.$factory("maketrans only argument must be a dict")}var items=_b_.list.$factory(_b_.dict.items($.x));for(let i=0,len=items.length;i0&&str.endswith(_self,suffix)){return _self.substr(0,_self.length-suffix.length)}return _self.substr(0)};str.replace=function(){var $=$B.args("replace",4,{self:null,old:null,new:null,count:null},["self","old","new","count"],arguments,{count:-1},null,null),count=$.count,_self=$.self,old=$.old,_new=$.new;check_str(old,"replace() argument 1 ");check_str(_new,"replace() argument 2 ");if(!$B.$isinstance(count,[_b_.int,_b_.float])){throw _b_.TypeError.$factory("'"+$B.class_name(count)+"' object cannot be interpreted as an integer")}else if($B.$isinstance(count,_b_.float)){throw _b_.TypeError.$factory("integer argument expected, got float")}if(count==0){return _self}if(count.__class__==$B.long_int){count=parseInt(count.value)}[old,_new]=to_string([old,_new]);var elts;if(old==""){if(_new==""){return _self}if(_self==""){return _new}elts=_self.split("");if(count>-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{elts=str.split(_self,old,count)}var res=_self,pos=-1;if(old.length==0){res=_new;for(var i=0;i0){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};str.rfind=function(){var $=$B.args("rfind",4,{self:null,sub:null,start:null,end:null},["self","sub","start","end"],arguments,{start:0,end:null},null,null),_self,sub;normalize_start_end($);check_str($.sub);[_self,sub]=to_string([$.self,$.sub]);var len=str.__len__(_self),sub_len=str.__len__(sub);if(sub_len==0){if($.js_start>len){return-1}else{return str.__len__(_self)}}var js_start=pypos2jspos(_self,$.start),js_end=pypos2jspos(_self,$.end),ix=_self.substring(js_start,js_end).lastIndexOf(sub);if(ix==-1){return-1}return jspos2pypos(_self,js_start+ix)-$.start};str.rindex=function(){var res=str.rfind.apply(null,arguments);if(res==-1){throw _b_.ValueError.$factory("substring not found")}return res};str.rjust=function(){var $=$B.args("rjust",3,{self:null,width:null,fillchar:null},["self","width","fillchar"],arguments,{fillchar:" "},null,null),_self=to_string($.self);var len=str.__len__(_self);if($.width<=len){return _self}return $B.String($.fillchar.repeat($.width-len)+_self)};str.rpartition=function(self,sep){var $=$B.args("rpartition",2,{self:null,sep:null},["self","sep"],arguments,{},null,null),_self;check_str($.sep);[_self,sep]=[$.self,$.sep];_self=reverse(_self),sep=reverse(sep);var items=str.partition(_self,sep).reverse();for(var i=0;i0){var flag=false;for(var char of chars){if(_self.endsWith(char)){_self=_self.substr(0,_self.length-char.length);flag=true;break}}if(!flag){return _self.surrogates?$B.String(_self):_self}}return""};str.split=function(){var $=$B.args("split",3,{self:null,sep:null,maxsplit:null},["self","sep","maxsplit"],arguments,{sep:_b_.None,maxsplit:-1},null,null),maxsplit=$.maxsplit,sep=$.sep,pos=0,_self=to_string($.self);if(maxsplit.__class__===$B.long_int){maxsplit=parseInt(maxsplit.value)}if(sep==""){throw _b_.ValueError.$factory("empty separator")}if(sep===_b_.None){let res=[];while(pos<_self.length&&_self.charAt(pos).search(/\s/)>-1){pos++}if(pos===_self.length-1){return[_self]}let 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.map($B.String)}else{sep=to_string(sep);let res=[],s="",seplen=sep.length;if(maxsplit==0){return[$.self]}while(pos<_self.length){if(_self.substr(pos,seplen)==sep){res.push(s);pos+=seplen;if(maxsplit>-1&&res.length>=maxsplit){res.push(_self.substr(pos));return res.map($B.String)}s=""}else{s+=_self.charAt(pos);pos++}}res.push(s);return res.map($B.String)}};str.splitlines=function(){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.$factory($.keepends),res=[],start=0,pos=0,_self=to_string($.self);if(!_self.length){return res}while(pos<_self.length){if(_self.substr(pos,2)=="\r\n"){res.push(_self.slice(start,keepends?pos+2:pos));start=pos=pos+2}else if(_self[pos]=="\r"||_self[pos]=="\n"){res.push(_self.slice(start,keepends?pos+1:pos));start=pos=pos+1}else{pos++}}if(start<_self.length){res.push(_self.slice(start))}return res.map($B.String)};str.startswith=function(){var $=$B.args("startswith",4,{self:null,prefix:null,start:null,end:null},["self","prefix","start","end"],arguments,{start:0,end:null},null,null),_self;normalize_start_end($);var prefixes=$.prefix;if(!$B.$isinstance(prefixes,_b_.tuple)){prefixes=[prefixes]}_self=to_string($.self);prefixes=to_string(prefixes);var s=_self.substring($.start,$.end);for(var prefix of prefixes){if(!$B.$isinstance(prefix,str)){throw _b_.TypeError.$factory("endswith first arg must be str "+"or a tuple of str, not int")}if(s.substr(0,prefix.length)==prefix){return true}}return false};str.strip=function(){var $=$B.args("strip",2,{self:null,chars:null},["self","chars"],arguments,{chars:_b_.None},null,null);if($.chars===_b_.None){return $.self.trim()}return str.rstrip(str.lstrip($.self,$.chars),$.chars)};str.swapcase=function(self){var $=$B.args("swapcase",1,{self:self},["self"],arguments,{},null,null),res="",cp,_self=to_string($.self);for(var char of _self){cp=_b_.ord(char);if($B.in_unicode_category("Ll",cp)){res+=char.toUpperCase()}else if($B.in_unicode_category("Lu",cp)){res+=char.toLowerCase()}else{res+=char}}return res};str.title=function(self){var $=$B.args("title",1,{self:self},["self"],arguments,{},null,null),state,cp,res="",_self=to_string($.self);for(var char of _self){cp=_b_.ord(char);if($B.in_unicode_category("Ll",cp)){if(!state){res+=char.toUpperCase();state="word"}else{res+=char}}else if($B.in_unicode_category("Lu",cp)||$B.in_unicode_category("Lt",cp)){res+=state?char.toLowerCase():char;state="word"}else{state=null;res+=char}}return res};str.translate=function(){var $=$B.args("translate",2,{self:null,table:null},["self","table"],arguments,{},null,null),table=$.table,res=[],getitem=$B.$getattr(table,"__getitem__"),cp,_self=to_string($.self);for(var char of _self){cp=_b_.ord(char);try{var repl=getitem(cp);if(repl!==_b_.None){if(typeof repl=="string"){res.push(repl)}else if(typeof repl=="number"){res.push(String.fromCharCode(repl))}}}catch(err){res.push(char)}}return res.join("")};str.upper=function(){var $=$B.args("upper",1,{self:null},["self"],arguments,{},null,null),_self=to_string($.self);return _self.toUpperCase()};str.zfill=function(){var $=$B.args("zfill",2,{self:null,width:null},["self","width"],arguments,{},null,null),_self=to_string($.self);var len=str.__len__(_self);if($.width<=len){return _self}switch(_self.charAt(0)){case"+":case"-":return _self.charAt(0)+"0".repeat($.width-len)+_self.substr(1);default:return"0".repeat($.width-len)+_self}};str.$factory=function(arg,encoding){if(arguments.length==0){return""}if(arg===undefined){return $B.UndefinedType.__str__()}else if(arg===null){return""}if(encoding!==undefined){var $=$B.args("str",3,{arg:null,encoding:null,errors:null},["arg","encoding","errors"],arguments,{encoding:"utf-8",errors:"strict"},null,null);encoding=$.encoding}if(typeof arg=="string"||arg instanceof String){return arg.toString()}else if(typeof arg=="number"&&Number.isInteger(arg)){return arg.toString()}try{if(arg.__class__&&arg.__class__===_b_.bytes&&encoding!==undefined){return _b_.bytes.decode(arg,$.encoding,$.errors)}var klass=arg.__class__||$B.get_class(arg);if(klass===undefined){return $B.JSObj.__str__($B.jsobj2pyobj(arg))}var method=$B.$getattr(klass,"__str__",null);if(method===null){method=$B.$getattr(klass,"__repr__")}}catch(err){console.log("no __str__ for",arg);console.log("err ",err);if($B.get_option("debug")>1){console.log(err)}console.log("Warning - no method __str__ or __repr__, "+"default to toString",arg);throw err}var res=$B.$call(method)(arg);if(typeof res=="string"||$B.$isinstance(res,str)){return res}throw _b_.TypeError.$factory("__str__ returned non-string "+`(type ${$B.class_name(res)})`)};$B.set_func_names(str,"builtins");_b_.str=str;$B.parse_format_spec=function(spec,obj){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=="z"){this.z=true;pos++;car=spec.charAt(pos)}if(car=="#"){this.alternate=true;pos++;car=spec.charAt(pos)}if(car=="0"){this.fill="0";if(align_pos==-1){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(this.width===undefined&&car=="{"){var end_param_pos=spec.substr(pos).search("}");this.width=spec.substring(pos,end_param_pos);pos+=end_param_pos+1}if(car==","||car=="_"){this.comma=true;this.grouping_option=car;pos++;car=spec.charAt(pos);if(car==","||car=="_"){if(car==this.grouping_option){throw _b_.ValueError.$factory(`Cannot specify '${car}' with '${car}'.`)}else{throw _b_.ValueError.$factory("Cannot specify both ',' and '_'.")}}}if(car=="."){if(digits.indexOf(spec.charAt(pos+1))==-1){throw _b_.ValueError.$factory("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){var err_msg=`Invalid format specifier '${spec}'`;if(obj){err_msg+=` for object of type '${$B.class_name(obj)}'`}throw _b_.ValueError.$factory(err_msg)}}this.toString=function(){return(this.fill===undefined?"":_b_.str.$factory(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};function fstring_expression(start){this.type="expression";this.start=start;this.expression="";this.conversion=null;this.fmt=null}function fstring_error(msg,pos){var error=Error(msg);error.position=pos;throw error}$B.parse_fstring=function(string){var elts=[],pos=0,current="",ctype=null,nb_braces=0,expr_start,car;while(pos-1){if(current.expression.length==0){throw Error("f-string: empty expression not allowed")}if("ars".indexOf(string.charAt(i+1))==-1){throw Error("f-string: invalid conversion character:"+" expected 's', 'r', or 'a'")}else{current.conversion=string.charAt(i+1);i+=2}}else if(car=="("||car=="["){nb_paren++;current.expression+=car;i++}else if(car==")"||car=="]"){nb_paren--;current.expression+=car;i++}else if(car=='"'){if(string.substr(i,3)=='"""'){let end=string.indexOf('"""',i+3);if(end==-1){fstring_error("f-string: unterminated string",pos)}else{var trs=string.substring(i,end+3);trs=trs.replace("\n","\\n\\");current.expression+=trs;i=end+3}}else{let end=string.indexOf('"',i+1);if(end==-1){fstring_error("f-string: unterminated string",pos)}else{current.expression+=string.substring(i,end+1);i=end+1}}}else if(nb_paren==0&&car==":"){current.fmt=true;var cb=0,fmt_complete=false;for(var j=i+1;j-1?"\\":"")+last_char;if(ce.length==0||nb_paren>0||string.charAt(i+1)=="="||"=!<>:".search(last_char_re)>-1){current.expression+=car;i+=1}else{var tail=car;while(string.charAt(i+1).match(/\s/)){tail+=string.charAt(i+1);i++}elts.push(current.expression+tail);while(ce.match(/\s$/)){ce=ce.substr(0,ce.length-1)}current.expression=ce;ctype="debug";i++}}else{current.expression+=car;i++}}if(nb_braces>0){fstring_error("f-string: expected '}'",pos)}}}if(current.length>0){elts.push(current)}for(var elt of elts){if(typeof elt=="object"){if(elt.fmt_pos!==undefined&&elt.expression.charAt(elt.fmt_pos)!=":"){throw Error()}}}return elts};$B.codepoint2jsstring=function(i){if(i>=65536&&i<=1114111){var code=i-65536;return String.fromCodePoint(55296|code>>10)+String.fromCodePoint(56320|code&1023)}else{return String.fromCodePoint(i)}};$B.jsstring2codepoint=function(c){if(c.length==1){return c.charCodeAt(0)}var code=65536;code+=(c.charCodeAt(0)&1023)<<10;code+=c.charCodeAt(1)&1023;return code}})(__BRYTHON__);(function($B){var _b_=$B.builtins;function $err(op,other){var msg="unsupported operand type(s) for "+op+" : 'int' and '"+$B.class_name(other)+"'";throw _b_.TypeError.$factory(msg)}function int_value(obj){if(typeof obj=="boolean"){return obj?1:0}return obj.$brython_value!==undefined?obj.$brython_value:obj}function bigint_value(obj){if(typeof obj=="boolean"){return obj?1n:0n}else if(typeof obj=="number"){return BigInt(obj)}else if(obj.__class__===$B.long_int){return obj.value}else if($B.$isinstance(obj,_b_.int)){return bigint_value(obj.$brython_value)}}var int={__class__:_b_.type,__dir__:_b_.object.__dir__,__mro__:[_b_.object],__qualname__:"int",$is_class:true,$native:true,$descriptors:{numerator:true,denominator:true,imag:true,real:true},$is_int_subclass:true};var int_or_long=int.$int_or_long=function(bigint){var res=Number(bigint);return Number.isSafeInteger(res)?res:$B.fast_long_int(bigint)};int.$to_js_number=function(obj){if(typeof obj=="number"){return obj}else if(obj.__class__===$B.long_int){return Number(obj.value)}else if($B.$isinstance(obj,_b_.int)){return int.$to_js_value(obj.$brython_value)}return null};int.$to_bigint=bigint_value;int.$int_value=int_value;int.as_integer_ratio=function(){var $=$B.args("as_integer_ratio",1,{self:null},["self"],arguments,{},null,null);return $B.fast_tuple([$.self,1])};int.from_bytes=function(){var $=$B.args("from_bytes",3,{bytes:null,byteorder:null,signed:null},["bytes","byteorder","signed"],arguments,{byteorder:"big",signed:false},null,null);var x=$.bytes,byteorder=$.byteorder,signed=$.signed,_bytes,_len;if($B.$isinstance(x,[_b_.bytes,_b_.bytearray])){_bytes=x.source;_len=x.source.length}else{_bytes=_b_.list.$factory(x);_len=_bytes.length;for(let i=0;i<_len;i++){_b_.bytes.$factory([_bytes[i]])}}if(byteorder=="big"){_bytes.reverse()}else if(byteorder!="little"){throw _b_.ValueError.$factory("byteorder must be either 'little' or 'big'")}var num=_bytes[0];if(signed&&num>=128){num=num-256}num=BigInt(num);var _mult=256n;for(let i=1;i<_len;i++){num+=_mult*BigInt(_bytes[i]);_mult*=256n}if(!signed){return int_or_long(num)}if(_bytes[_len-1]<128){return int_or_long(num)}return int_or_long(num-_mult)};int.to_bytes=function(){var $=$B.args("to_bytes",3,{self:null,len:null,byteorder:null,signed:null},["self","len","byteorder","signed"],arguments,{len:1,byteorder:"big",signed:false},null,null),self=$.self,len=$.len,byteorder=$.byteorder,signed=$.signed;if(!$B.$isinstance(len,_b_.int)){throw _b_.TypeError.$factory("integer argument expected, got "+$B.class_name(len))}if(["little","big"].indexOf(byteorder)==-1){throw _b_.ValueError.$factory("byteorder must be either 'little' or 'big'")}if($B.$isinstance(self,$B.long_int)){return $B.long_int.to_bytes(self,len,byteorder,signed)}if(self<0){if(!signed){throw _b_.OverflowError.$factory("can't convert negative int to unsigned")}self=Math.pow(256,len)+self}var res=[],value=self;while(value>0){var quotient=Math.floor(value/256),rest=value-256*quotient;res.push(rest);if(res.length>len){throw _b_.OverflowError.$factory("int too big to convert")}value=quotient}while(res.length=0){res=fmt.sign+res}}return res}int.__format__=function(self,format_spec){var fmt=new $B.parse_format_spec(format_spec,self);if(fmt.type&&"eEfFgG%".indexOf(fmt.type)!=-1){return _b_.float.__format__($B.fast_float(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;iint_value(self);int.__init__=()=>_b_.None;int.__int__=self=>self;int.__invert__=function(self){if(Math.abs(self)<2**31){return~self}return $B.rich_op("__sub__",$B.rich_op("__mul__",self,-1),1)};int.__mod__=function(self,other){if($B.$isinstance(other,_b_.tuple)&&other.length==1){other=other[0]}if(other.__class__===$B.long_int){self=BigInt(self);other=other.value;if(other==0){throw _b_.ZeroDivisionError.$factory("integer division or modulo by zero")}return int_or_long((self%other+other)%other)}if($B.$isinstance(other,int)){other=int_value(other);if(other===false){other=0}else if(other===true){other=1}if(other==0){throw _b_.ZeroDivisionError.$factory("integer division or modulo by zero")}return(self%other+other)%other}return _b_.NotImplemented};int.__mul__=Function("self","other",op_model.replace(/\+/g,"*").replace(/add/g,"mul"));int.__ne__=function(self,other){var res=int.__eq__(self,other);return res===_b_.NotImplemented?res:!res};int.__neg__=function(self){var self_as_int=int_value(self);if(self_as_int.__class__===$B.long_int){return $B.long_int.__neg__(self_as_int)}return-self};int.__new__=function(cls,value,base){if(cls===undefined){throw _b_.TypeError.$factory("int.__new__(): not enough arguments")}else if(!$B.$isinstance(cls,_b_.type)){throw _b_.TypeError.$factory("int.__new__(X): X is not a type object")}if(cls===int){return int.$factory(value,base)}if(cls===bool){throw _b_.TypeError.$factory("int.__new__(bool) is not safe, use bool.__new__()")}return{__class__:cls,__dict__:$B.empty_dict(),$brython_value:int.$factory(value,base),toString:function(){return value}}};int.__pos__=function(self){return self};function extended_euclidean(a,b){var d,u,v;if(b==0){return[a,1n,0n]}else{[d,u,v]=extended_euclidean(b,a%b);return[d,v,u-a/b*v]}}int.__pow__=function(self,other,z){if(!$B.$isinstance(other,int)){return _b_.NotImplemented}if(typeof other=="boolean"){other=other?1:0}if(typeof other=="number"||$B.$isinstance(other,int)){if(z!==undefined&&z!==_b_.None){self=bigint_value(self);other=bigint_value(other);z=bigint_value(z);if(z==1){return 0}var result=1n,exponent=other,base=self%z;if(base<0){base+=z}if(exponent<0){var gcd,inv,_;[gcd,inv,_]=extended_euclidean(self,z);if(gcd!=1){throw _b_.ValueError.$factory("not relative primes: "+self+" and "+z)}return int.__pow__(int_or_long(inv),int_or_long(-exponent),int_or_long(z))}while(exponent>0){if(exponent%2n==1n){result=result*base%z}exponent=exponent>>1n;base=base*base%z}return int_or_long(result)}else{if(typeof other=="number"){if(other>=0){return int_or_long(BigInt(self)**BigInt(other))}else{return $B.fast_float(Math.pow(self,other))}}else if(other.__class__===$B.long_int){if(other.value>=0){return int_or_long(BigInt(self)**other.value)}else{return $B.fast_float(Math.pow(self,other))}}else if($B.$isinstance(other,_b_.int)){return int_or_long(int.__pow__(self,other.$brython_value))}return _b_.NotImplemented}}if($B.$isinstance(other,_b_.float)){other=_b_.float.numerator(other);if(self>=0){return $B.fast_float(Math.pow(self,other))}else{return _b_.complex.__pow__($B.make_complex(self,0),other)}}else if($B.$isinstance(other,_b_.complex)){var preal=Math.pow(self,other.$real),ln=Math.log(self);return $B.make_complex(preal*Math.cos(ln),preal*Math.sin(ln))}var rpow=$B.$getattr(other,"__rpow__",_b_.None);if(rpow!==_b_.None){return rpow(self)}$err("**",other)};int.__repr__=function(self){$B.builtins_repr_check(int,arguments);var value=int_value(self),x=value.__class__===$B.long_int?value.value:value;if($B.int_max_str_digits!=0&&x>=10n**BigInt($B.int_max_str_digits)){throw _b_.ValueError.$factory(`Exceeds the limit `+`(${$B.int_max_str_digits}) for integer string conversion`)}return x.toString()};int.__setattr__=function(self,attr,value){if(typeof self=="number"||typeof self=="boolean"){var cl_name=$B.class_name(self);if(_b_.dir(self).indexOf(attr)>-1){throw _b_.AttributeError.$factory("attribute '"+attr+`' of '${cl_name}' objects is not writable`)}else{throw _b_.AttributeError.$factory(`'${cl_name}' object`+` has no attribute '${attr}'`)}}_b_.dict.$setitem(self.__dict__,attr,value);return _b_.None};int.__sub__=Function("self","other",op_model.replace(/\+/g,"-").replace(/__add__/g,"__sub__"));int.__truediv__=function(self,other){if($B.$isinstance(other,int)){other=int_value(other);if(other==0){throw _b_.ZeroDivisionError.$factory("division by zero")}if(other.__class__===$B.long_int){return $B.fast_float(self/parseInt(other.value))}return $B.fast_float(self/other)}return _b_.NotImplemented};int.bit_count=function(self){var s=_b_.bin(_b_.abs(self)),nb=0;for(var x of s){if(x=="1"){nb++}}return nb};int.bit_length=function(self){var s=_b_.bin(self);s=$B.$getattr(s,"lstrip")("-0b");return s.length};int.numerator=self=>int_value(self);int.denominator=()=>1;int.imag=()=>0;int.real=self=>self;for(var attr of["numerator","denominator","imag","real"]){int[attr].setter=function(x){return function(self){throw _b_.AttributeError.$factory(`attribute '${x}' of `+`'${$B.class_name(self)}' objects is not writable`)}}(attr)}var model=`var _b_ = __BRYTHON__.builtins\nif(typeof other == "number"){\n // transform into BigInt: JS converts numbers to 32 bits\n return _b_.int.$int_or_long(BigInt(self) & BigInt(other))}else if(typeof other == "boolean"){\n return self & (other ? 1 : 0)}else if(other.__class__ === $B.long_int){\n return _b_.int.$int_or_long(BigInt(self) & other.value)}else if($B.$isinstance(other, _b_.int)){\n // int subclass\n return _b_.int.__and__(self, other.$brython_value)}\nreturn _b_.NotImplemented`;int.__and__=Function("self","other",model);int.__lshift__=Function("self","other",model.replace(/&/g,"<<").replace(/__and__/g,"__lshift__"));int.__rshift__=Function("self","other",model.replace(/&/g,">>").replace(/__and__/g,"__rshift__"));int.__or__=Function("self","other",model.replace(/&/g,"|").replace(/__and__/g,"__or__"));int.__xor__=Function("self","other",model.replace(/&/g,"^").replace(/__and__/g,"__xor__"));int.__ge__=function(self,other){self=int_value(self);if(typeof other=="number"){return self>=other}else if(other!==null&&other.__class__===$B.long_int){return self>=other.value}else if(typeof other=="boolean"){return self>=other?1:0}else if($B.$isinstance(other,_b_.int)){return self>=other.$brython_value}return _b_.NotImplemented};int.__gt__=function(self,other){var res=int.__le__(self,other);return res===_b_.NotImplemented?res:!res};int.__le__=function(self,other){self=int_value(self);if(typeof other=="number"){return self<=other}else if(other!==null&&other.__class__===$B.long_int){return self<=other.value}else if(typeof other=="boolean"){return self<=other?1:0}else if($B.$isinstance(other,_b_.int)){return self<=other.$brython_value}return _b_.NotImplemented};int.__lt__=function(self,other){var res=int.__ge__(self,other);return res===_b_.NotImplemented?res:!res};var r_opnames=["add","sub","mul","truediv","floordiv","mod","pow","lshift","rshift","and","xor","or","divmod"];for(var r_opname of r_opnames){if(int["__r"+r_opname+"__"]===undefined&&int["__"+r_opname+"__"]){int["__r"+r_opname+"__"]=function(name){return function(self,other){if($B.$isinstance(other,int)){other=int_value(other);return int["__"+name+"__"](other,self)}return _b_.NotImplemented}}(r_opname)}}var $valid_digits=function(base){var digits="";if(base===0){return"0"}if(base<10){for(let i=0;i=2&&base<=36)){if(base!=0){throw _b_.ValueError.$factory("invalid base")}}function invalid(base){throw _b_.ValueError.$factory("invalid literal for int() with base "+base+": "+_b_.repr(initial_value))}if(typeof value!="string"){value=_b_.str.$to_string(value)}var _value=value.trim(),sign="";if(_value.startsWith("+")||_value.startsWith("-")){sign=_value[0];_value=_value.substr(1)}if(_value.length==2&&base==0&&(_value=="0b"||_value=="0o"||_value=="0x")){throw _b_.ValueError.$factory("invalid value")}if(_value.endsWith("_")){invalid(base)}if(value.indexOf("__")>-1){invalid(base)}if(_value.length>2){let _pre=_value.substr(0,2).toUpperCase();if(base==0){if(_pre=="0B"){base=2}else if(_pre=="0O"){base=8}else if(_pre=="0X"){base=16}else if(_value.startsWith("0")){_value=_value.replace(/_/g,"");if(_value.match(/^0+$/)){return 0}invalid(base)}}else if(_pre=="0X"&&base!=16){invalid(base)}else if(_pre=="0O"&&base!=8){invalid(base)}if(_pre=="0B"&&base==2||_pre=="0O"||_pre=="0X"){_value=_value.substr(2);if(_value.startsWith("_")){_value=_value.substr(1)}}}if(base==0){base=10}var _digits=$valid_digits(base),_re=new RegExp("^[+-]?["+_digits+"]"+"["+_digits+"_]*$","i"),match=_re.exec(_value),res;if(match===null){res=0;var digit;for(var char of _value){if(/\p{Nd}/u.test(char)){let cp=char.codePointAt(0);for(let start of $B.digits_starts){if(cp-start<10){digit=cp-start;break}}}else{if(base>10&&_digits.indexOf(char.toUpperCase())>-1){digit=char.toUpperCase().charCodeAt(0)-55}else{invalid(base)}}if(digit$B.int_max_str_digits){throw _b_.ValueError.$factory("Exceeds the limit "+`(${$B.int_max_str_digits}) for integer string conversion: `+`value has ${value.length} digits; use `+"sys.set_int_max_str_digits() to increase the limit.")}if(base==10){res=BigInt(_value)}else{base=BigInt(base);res=0n;let coef=1n,char;for(let i=_value.length-1;i>=0;i--){char=_value[i].toUpperCase();res+=coef*BigInt(_digits.indexOf(char));coef*=base}}}if(sign=="-"){res=-res}return int_or_long(res)};$B.set_func_names(int,"builtins");_b_.int=int;$B.$bool=function(obj,bool_class){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:if(obj.$is_class){return true}var klass=$B.get_class(obj),missing={},bool_method=bool_class?$B.$getattr(klass,"__bool__",missing):$B.$getattr(obj,"__bool__",missing);var test=false;if(test){console.log("bool(obj)",obj,"bool_class",bool_class,"klass",klass,"apply bool method",bool_method);console.log("$B.$call(bool_method)",bool_method+"")}if(bool_method===missing){var len_method=$B.$getattr(klass,"__len__",missing);if(len_method===missing){return true}return _b_.len(obj)>0}else{var res=bool_class?$B.$call(bool_method)(obj):$B.$call(bool_method)();if(res!==true&&res!==false){throw _b_.TypeError.$factory("__bool__ should return "+"bool, returned "+$B.class_name(res))}if(test){console.log("bool method returns",res)}return res}}};var bool={__bases__:[int],__class__:_b_.type,__mro__:[int,_b_.object],__qualname__:"bool",$is_class:true,$not_basetype:true,$native:true,$descriptors:{numerator:true,denominator:true,imag:true,real:true}};bool.__and__=function(self,other){if($B.$isinstance(other,bool)){return self&&other}else if($B.$isinstance(other,int)){return int.__and__(bool.__index__(self),int.__index__(other))}return _b_.NotImplemented};bool.__float__=function(self){return self?$B.fast_float(1):$B.fast_float(0)};bool.__hash__=bool.__index__=bool.__int__=function(self){if(self.valueOf())return 1;return 0};bool.__neg__=function(self){return-$B.int_or_bool(self)};bool.__or__=function(self,other){if($B.$isinstance(other,bool)){return self||other}else if($B.$isinstance(other,int)){return int.__or__(bool.__index__(self),int.__index__(other))}return _b_.NotImplemented};bool.__pos__=$B.int_or_bool;bool.__repr__=function(self){$B.builtins_repr_check(bool,arguments);return self?"True":"False"};bool.__xor__=function(self,other){if($B.$isinstance(other,bool)){return self^other?true:false}else if($B.$isinstance(other,int)){return int.__xor__(bool.__index__(self),int.__index__(other))}return _b_.NotImplemented};bool.__invert__=function(self){$B.warn(_b_.DeprecationWarning,`Bitwise inversion '~' on bool is deprecated.This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool.Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.`);return int.__invert__(self)};bool.$factory=function(){var $=$B.args("bool",1,{x:null},["x"],arguments,{x:false},null,null,1);return $B.$bool($.x,true)};bool.__new__=function(cls,value){if(cls===undefined){throw _b_.TypeError.$factory("bool.__new__(): not enough arguments")}else if(!$B.$isinstance(cls,_b_.type)){throw _b_.TypeError.$factory(`bool.__new__(X): X is not a type object (${$B.class_name(cls)})`)}else if(!_b_.issubclass(cls,bool)){let class_name=$B.class_name(cls);throw _b_.TypeError.$factory(`bool.__new__(${class_name}): ${class_name} is not a subtype of bool`)}if(arguments.length>2){throw _b_.TypeError.$factory(`bool expected at most 1 argument, got ${arguments.length-1}`)}return bool.$factory(value)};bool.from_bytes=function(){var $=$B.args("from_bytes",3,{bytes:null,byteorder:null,signed:null},["bytes","byteorder","signed"],arguments,{byteorder:"big",signed:false},null,null);let int_result=int.from_bytes($.bytes,$.byteorder,$.signed);return bool.$factory(int_result)};bool.numerator=int.numerator;bool.denominator=int.denominator;bool.real=self=>self?1:0;bool.imag=int.imag;for(var attr of["real"]){bool[attr].setter=function(x){return function(self){throw _b_.AttributeError.$factory(`attribute '${x}' of `+`'${$B.class_name(self)}' objects is not writable`)}}(attr)}_b_.bool=bool;$B.set_func_names(bool,"builtins")})(__BRYTHON__);(function($B){var _b_=$B.builtins;var long_int={__class__:_b_.type,__mro__:[_b_.int,_b_.object],__qualname__:"int",$infos:{__module__:"builtins",__name__:"int"},$is_class:true,$native:true,$descriptors:{numerator:true,denominator:true,imag:true,real:true}};var int_or_long=_b_.int.$int_or_long;function preformat(self,fmt){if(fmt.empty){return _b_.str.$factory(self)}if(fmt.type&&"bcdoxXn".indexOf(fmt.type)==-1){throw _b_.ValueError.$factory("Unknown format code '"+fmt.type+"' for object of type 'int'")}var res;switch(fmt.type){case undefined:case"d":res=self.toString();break;case"b":res=(fmt.alternate?"0b":"")+BigInt(self.value).toString(2);break;case"c":res=_b_.chr(self);break;case"o":res=(fmt.alternate?"0o":"")+BigInt(self.value).toString(8);break;case"x":res=(fmt.alternate?"0x":"")+BigInt(self.value).toString(16);break;case"X":res=(fmt.alternate?"0X":"")+BigInt(self.value).toString(16).toUpperCase();break;case"n":return self}if(fmt.sign!==undefined){if((fmt.sign==" "||fmt.sign=="+")&&self>=0){res=fmt.sign+res}}return res}long_int.$to_js_number=function(self){return Number(self.value)};long_int.__format__=function(self,format_spec){var fmt=new $B.parse_format_spec(format_spec,self);if(fmt.type&&"eEfFgG%".indexOf(fmt.type)!=-1){return _b_.float.__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;i0?self.value:-self.value)};long_int.__add__=function(self,other){if(typeof other=="number"){return int_or_long(self.value+BigInt(other))}else if(other.__class__===$B.long_int){return int_or_long(self.value+other.value)}else if(typeof other=="boolean"){return int_or_long(self.value+(other?1n:0n))}else if($B.$isinstance(other,_b_.int)){return long_int.__add__(self,other.$brython_value)}return _b_.NotImplemented};long_int.__divmod__=function(self,other){var a=self.value,b=_b_.int.$to_bigint(other),quotient;if(a>=0&&b>0||a<=0&&b<0){quotient=a/b}else{quotient=a/b-1n}var rest=a-quotient*b;return $B.fast_tuple([int_or_long(quotient),int_or_long(rest)])};long_int.__eq__=function(self,other){if(other.__class__===$B.long_int){return self.value==other.value}else if(typeof other=="number"||typeof other=="boolean"){return false}else if($B.$isinstance(other,_b_.int)){return long_int.__eq__(self,other.$brython_value)}return _b_.NotImplemented};long_int.__float__=function(self){if(!isFinite(Number(self.value))){throw _b_.OverflowError.$factory("int too large to convert to float")}return $B.fast_float(Number(self.value))};long_int.__floordiv__=function(self,other){if(typeof other=="number"){return int_or_long(self.value/BigInt(other))}else if(other.__class__===$B.long_int){return int_or_long(self.value/other.value)}else if(typeof other=="boolean"){return int_or_long(self.value/(other?1n:0n))}else if($B.$isinstance(other,_b_.int)){return int_or_long(self.value/other.$brython_value)}return _b_.NotImplemented};long_int.__ge__=function(self,other){if(typeof other=="number"){return self.value>=other}else if(other.__class__===$B.long_int){return self.value>=other.value}else if(typeof other=="boolean"){return self.value>=(other?1:0)}else if($B.$isinstance(other,_b_.int)){return self.value>=other.$brython_value}return _b_.NotImplemented};long_int.__gt__=function(self,other){var res=long_int.__le__(self,other);return res===_b_.NotImplemented?res:!res};long_int.__hash__=function(self){var modulus=2305843009213693951n,sign=self.value>=0?1n:-1n,self_pos=self.value*sign;var _hash=sign*(self_pos%modulus);return self.__hashvalue__=int_or_long(_hash)};long_int.__index__=function(self){return self};long_int.__invert__=function(self){return int_or_long(-1n-self.value)};long_int.__le__=function(self,other){if(typeof other=="number"){return self.value<=other}else if(other.__class__===$B.long_int){return self.value<=other.value}else if(typeof other=="boolean"){return self.value<=(other?1:0)}else if($B.$isinstance(other,_b_.int)){return self.value<=other.$brython_value}return _b_.NotImplemented};long_int.__lt__=function(self,other){var res=long_int.__ge__(self,other);return res===_b_.NotImplemented?res:!res};long_int.__lshift__=function(self,other){if(typeof other=="number"){return int_or_long(self.value<>BigInt(other))}else if(other.__class__===$B.long_int){return int_or_long(self.value>>other.value)}else if(typeof other=="boolean"){return int_or_long(self.value>>(other?1n:0n))}else if($B.$isinstance(other,_b_.int)){return long_int.__rshift__(self,other.$brython_value)}return _b_.NotImplemented};long_int.__repr__=function(self){$B.builtins_repr_check($B.long_int,arguments);if($B.int_max_str_digits!=0&&self.value>=10n**BigInt($B.int_max_str_digits)){throw _b_.ValueError.$factory(`Exceeds the limit `+`(${$B.int_max_str_digits}) for integer string conversion`)}return self.value.toString()};long_int.__sub__=function(self,other){if(typeof other=="number"){return int_or_long(self.value-BigInt(other))}else if(typeof other=="boolean"){return int_or_long(self.value-(other?1n:0n))}else if(other.__class__===$B.long_int){return int_or_long(self.value-other.value)}else if($B.$isinstance(other,_b_.int)){return long_int.__sub__(self,other.$brython_value)}return _b_.NotImplemented};long_int.__truediv__=function(self,other){if(typeof other=="number"){return $B.fast_float(Number(self.value)/other)}else if(typeof other=="boolean"){return $B.fast_float(Number(self.value)*(other?1:0))}else if(other.__class__===$B.long_int){return $B.fast_float(Number(self.value)/Number(other.value))}else if($B.$isinstance(other,_b_.int)){return long_int.__truediv__(self,other.$brython_value)}return _b_.NotImplemented};long_int.bit_count=function(self){var s=self.value.toString(2),nb=0;for(var x of s){if(x=="1"){nb++}}return nb};long_int.bit_length=function(self){return self.value.toString(2).length};function _infos(self){var nbits=$B.long_int.bit_length(self),pow2=2n**BigInt(nbits-1),rest=BigInt(self.value)-pow2,relative_rest=new Number(rest/pow2);return{nbits:nbits,pow2:pow2,rest:rest,relative_rest:relative_rest}}long_int.$log2=function(x){if(x.value<0){throw _b_.ValueError.$factory("math domain error")}var infos=_infos(x);return _b_.float.$factory(infos.nbits-1+Math.log(1+infos.relative_rest/Math.LN2))};long_int.$log10=function(x){if(x.value<0){throw _b_.ValueError.$factory("math domain error")}var x_string=x.value.toString(),exp=x_string.length-1,mant=parseFloat(x_string[0]+"."+x_string.substr(1));return _b_.float.$factory(exp+Math.log10(mant))};long_int.numerator=self=>self;long_int.denominator=()=>1;long_int.imag=()=>0;long_int.real=self=>self;var body=`var $B = __BRYTHON__,\n _b_ = $B.builtins\nif(typeof other == "number"){\n return _b_.int.$int_or_long(self.value & BigInt(other))}else if(typeof other == "boolean"){\n return _b_.int.$int_or_long(self.value & (other ? 1n : 0n))}else if(other.__class__ === $B.long_int){\n return _b_.int.$int_or_long(self.value & other.value)}else if($B.$isinstance(other, _b_.int)){\n // int subclass\n return $B.long_int.__and__(self, other.$brython_value)}\nreturn _b_.NotImplemented`;long_int.__and__=Function("self","other",body);long_int.__or__=Function("self","other",body.replace(/&/g,"|").replace(/__and__/g,"__or__"));long_int.__xor__=Function("self","other",body.replace(/&/g,"^").replace(/__and__/g,"__xor__"));long_int.to_bytes=function(self,len,byteorder,signed){var res=[],v=self.value;if(!$B.$bool(signed)&&v<0){throw _b_.OverflowError.$factory("can't convert negative int to unsigned")}while(v>0){var quot=v/256n,rest=v-quot*256n;v=quot;res.push(Number(rest));if(res.length>len){throw _b_.OverflowError.$factory("int too big to convert")}}while(res.length10){for(let i=0;i0}};long_int.$factory=function(value,base){var is_digits=digits(base);for(let i=0;i=0;i--){char=value[i].toUpperCase();res+=coef*BigInt(is_digits[char]);coef*=base}}return{__class__:$B.long_int,value:res}};function extended_euclidean_algorithm(a,b){var s=0,old_s=1,t=1,old_t=0,r=b,old_r=a,quotient,tmp;while($B.rich_comp("__ne__",r,0)){quotient=$B.rich_op("__floordiv__",old_r,r);tmp=$B.rich_op("__sub__",old_r,$B.rich_op("__mul__",quotient,r));old_r=r;r=tmp;tmp=$B.rich_op("__sub__",old_s,$B.rich_op("__mul__",quotient,s));old_s=s;s=tmp;tmp=$B.rich_op("__sub__",old_t,$B.rich_op("__mul__",quotient,t));old_t=t;t=tmp}return[old_r,old_s,old_t]}function inverse_of(n,p){var gcd,x,y;[gcd,x,y]=extended_euclidean_algorithm(n,p);if($B.rich_comp("__ne__",gcd,1)){throw Error(`${n} has no multiplicative inverse '\n 'modulo ${p}`)}else{return $B.rich_op("__mod__",x,p)}}$B.inverse_of=inverse_of;$B.set_func_names(long_int,"builtins");$B.long_int=long_int;$B.fast_long_int=function(value){if(typeof value!=="bigint"){console.log("expected bigint, got",value);throw Error("not a big int")}return{__class__:$B.long_int,value:value}}})(__BRYTHON__);(function($B){var _b_=$B.builtins;function float_value(obj){return obj.__class__===float?obj:fast_float(obj.value)}var float={__class__:_b_.type,__dir__:_b_.object.__dir__,__qualname__:"float",$is_class:true,$native:true,$descriptors:{numerator:true,denominator:true,imag:true,real:true}};float.$float_value=float_value;float.$to_js_number=function(self){if(self.__class__===float){return self.value}else{return float.$to_js_number(self.value)}};float.numerator=self=>self;float.denominator=()=>1;float.imag=()=>0;float.real=self=>self;float.__float__=function(self){return self};$B.shift1_cache={};float.as_integer_ratio=function(self){if(isinf(self)){throw _b_.OverflowError.$factory("Cannot pass infinity to "+"float.as_integer_ratio.")}if(isnan(self)){throw _b_.ValueError.$factory("Cannot pass NaN to "+"float.as_integer_ratio.")}var tmp=frexp(self),fp=tmp[0],exponent=tmp[1];for(var i=0;i<300;i++){if(fp==Math.floor(fp)){break}else{fp*=2;exponent--}}var numerator=_b_.int.$factory(fp),py_exponent=_b_.abs(exponent),denominator=1,x;if($B.shift1_cache[py_exponent]!==undefined){x=$B.shift1_cache[py_exponent]}else{x=$B.$getattr(1,"__lshift__")(py_exponent);$B.shift1_cache[py_exponent]=x}py_exponent=x;if(exponent>0){numerator=$B.rich_op("__mul__",numerator,py_exponent)}else{denominator=py_exponent}return $B.fast_tuple([_b_.int.$factory(numerator),_b_.int.$factory(denominator)])};function check_self_is_float(x,method){if(x.__class__===_b_.float||$B.$isinstance(x,_b_.float)){return true}throw _b_.TypeError.$factory(`descriptor '${method}' requires a `+`'float' object but received a '${$B.class_name(x)}'`)}float.__abs__=function(self){check_self_is_float(self,"__abs__");return fast_float(Math.abs(self.value))};float.__bool__=function(self){check_self_is_float(self,"__bool__");return _b_.bool.$factory(self.value)};float.__ceil__=function(self){check_self_is_float(self,"__ceil__");if(isnan(self)){throw _b_.ValueError.$factory("cannot convert float NaN to integer")}else if(isinf(self)){throw _b_.OverflowError.$factory("cannot convert float infinity to integer")}return Math.ceil(self.value)};float.__divmod__=function(self,other){check_self_is_float(self,"__divmod__");if(!$B.$isinstance(other,[_b_.int,float])){return _b_.NotImplemented}return $B.fast_tuple([float.__floordiv__(self,other),float.__mod__(self,other)])};float.__eq__=function(self,other){check_self_is_float(self,"__eq__");if(isNaN(self.value)&&($B.$isinstance(other,float)&&isNaN(other.value))){return false}if($B.$isinstance(other,_b_.int)){return self.value==other}if($B.$isinstance(other,float)){return self.value==other.value}if($B.$isinstance(other,_b_.complex)){if(!$B.rich_comp("__eq__",0,other.$imag)){return false}return float.__eq__(self,other.$real)}return _b_.NotImplemented};float.__floor__=function(self){check_self_is_float(self,"__floor__");if(isnan(self)){throw _b_.ValueError.$factory("cannot convert float NaN to integer")}else if(isinf(self)){throw _b_.OverflowError.$factory("cannot convert float infinity to integer")}return Math.floor(self.value)};float.__floordiv__=function(self,other){check_self_is_float(self,"__floordiv__");if($B.$isinstance(other,float)){if(other.value==0){throw _b_.ZeroDivisionError.$factory("division by zero")}return fast_float(Math.floor(self.value/other.value))}if($B.$isinstance(other,_b_.int)){if(other.valueOf()==0){throw _b_.ZeroDivisionError.$factory("division by zero")}return fast_float(Math.floor(self.value/other))}return _b_.NotImplemented};const DBL_MANT_DIG=53,LONG_MAX=$B.MAX_VALUE,DBL_MAX_EXP=2**10,LONG_MIN=$B.MIN_VALUE,DBL_MIN_EXP=-1021;float.fromhex=function(klass,s){function hex_from_char(char){return parseInt(char,16)}function finished(){while(s[pos]&&s[pos].match(/\s/)){pos++}if(pos!=s.length){throw parse_error()}if(negate){x=float.__neg__(x)}return klass===_b_.float?x:$B.$call(klass)(x)}function overflow_error(){throw _b_.OverflowError.$factory("hexadecimal value too large to represent as a float")}function parse_error(){throw _b_.ValueError.$factory("invalid hexadecimal floating-point string")}function insane_length_error(){throw _b_.ValueError.$factory("hexadecimal string too long to convert")}s=s.trim();if(s.match(/^\+?inf(inity)?$/i)){return INF}else if(s.match(/^-inf(inity)?$/i)){return NINF}else if(s.match(/^[+-]?nan$/i)){return NAN}var pos=0,negate,ldexp=_b_.float.$funcs.ldexp;if(s[pos]=="-"){pos++;negate=1}else if(s[pos]=="+"){pos++}if(s.substr(pos,2).toLowerCase()=="0x"){pos+=2}var coeff_start=pos,coeff_end;while(hex_from_char(s[pos])>=0){pos++}var save_pos=pos;if(s[pos]=="."){pos++;while(hex_from_char(s[pos])>=0){pos++}coeff_end=pos-1}else{coeff_end=pos}var ndigits=coeff_end-coeff_start,fdigits=coeff_end-save_pos;if(ndigits==0){throw parse_error()}if(ndigits>Math.min(DBL_MIN_EXP-DBL_MANT_DIG-LONG_MIN/2,LONG_MAX/2+1-DBL_MAX_EXP)/4){throw insane_length_error()}var exp;if(s[pos]=="p"||s[pos]=="P"){pos++;var exp_start=pos;if(s[pos]=="-"||s[pos]=="+"){pos++}if(!("0"<=s[pos]&&s[pos]<="9")){throw parse_error()}pos++;while("0"<=s[pos]&&s[pos]<="9"){pos++}exp=parseInt(s.substr(exp_start))}else{exp=0}function HEX_DIGIT(j){if(!Number.isInteger(j)){throw Error("j pas entier")}return hex_from_char(s[j0&&HEX_DIGIT(ndigits-1)==0){ndigits--}if(ndigits==0||expLONG_MAX/2){console.log("overflow, exp",exp);throw overflow_error()}exp=exp-4*fdigits;var top_exp=exp+4*(ndigits-1);for(let digit=BigInt(HEX_DIGIT(ndigits-1));digit!=0;digit/=2n){top_exp++}if(top_expDBL_MAX_EXP){throw overflow_error()}var lsb=Math.max(top_exp,DBL_MIN_EXP)-DBL_MANT_DIG;var x=0;if(exp>=lsb){for(let i=ndigits-1;i>=0;i--){x=16*x+HEX_DIGIT(i)}x=ldexp($B.fast_float(x),exp);return finished()}var half_eps=1<<(lsb-exp-1)%4,key_digit=parseInt((lsb-exp-1)/4);for(let i=ndigits-1;i>key_digit;i--){x=16*x+HEX_DIGIT(i)}let digit=HEX_DIGIT(key_digit);x=16*x+(digit&16-2*half_eps);if((digit&half_eps)!=0){var round_up=0;if((digit&3*half_eps-1)!=0||half_eps==8&&key_digit+1=0;i--){if(HEX_DIGIT(i)!=0){round_up=1;break}}}if(round_up){x+=2*half_eps;if(top_exp==DBL_MAX_EXP&&x==ldexp(2*half_eps,DBL_MANT_DIG).value){throw overflow_error()}}}x=ldexp(x,exp+4*key_digit);return finished()};float.__getformat__=function(arg){if(arg=="double"||arg=="float"){return"IEEE, little-endian"}if(typeof arg!=="string"){throw _b_.TypeError.$factory(" __getformat__() argument must be str, not "+$B.class_name(arg))}throw _b_.ValueError.$factory("__getformat__() argument 1 must be "+"'double' or 'float'")};var format_sign=function(val,flags){switch(flags.sign){case"+":return val>=0||isNaN(val)?"+":"";case"-":return"";case" ":return val>=0||isNaN(val)?" ":""}if(flags.space){if(val>=0){return" "}}return""};function preformat(self,fmt){var value=self.value;if(fmt.empty){return _b_.str.$factory(self)}if(fmt.type&&"eEfFgGn%".indexOf(fmt.type)==-1){throw _b_.ValueError.$factory("Unknown format code '"+fmt.type+"' for object of type 'float'")}var special;if(isNaN(value)){special="efg".indexOf(fmt.type)>-1?"nan":"NAN"}else if(value==Number.POSITIVE_INFINITY){special="efg".indexOf(fmt.type)>-1?"inf":"INF"}else if(value==Number.NEGATIVE_INFINITY){special="efg".indexOf(fmt.type)>-1?"-inf":"-INF"}if(special){return format_sign(value,fmt)+special}if(fmt.precision===undefined&&fmt.type!==undefined){fmt.precision=6}if(fmt.type=="%"){value*=100}if(fmt.type=="e"){let res=value.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}var res;if(fmt.precision!==undefined){let prec=fmt.precision;if(prec==0){return Math.round(value)+""}res=$B.roundDownToFixed(value,prec);let 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 if(fmt.type&&fmt.type.toLowerCase()=="g"){let exp_fmt=preformat(self,{type:"e"}).split("e"),exp=parseInt(exp_fmt[1]);if(-4<=exp&&exp0){while(signif.endsWith("0")){signif=signif.substr(0,signif.length-1)}}if(signif.endsWith(".")){signif=signif.substr(0,signif.length-1)}parts[0]=signif}res=parts.join("e");if(fmt.type=="G"){res=res.toUpperCase()}return res}else if(fmt.type===undefined){fmt.type="g";res=preformat(self,fmt);if(res.indexOf(".")==-1){let exp=res.length-1;exp=exp<10?"0"+exp:exp;let is_neg=res.startsWith("-"),point_pos=is_neg?2:1,mant=res.substr(0,point_pos)+"."+res.substr(point_pos);return`${mant}e+${exp}`}fmt.type=undefined}else{let res1=value.toExponential(fmt.precision-1),exp=parseInt(res1.substr(res1.search("e")+1));if(exp<-4||exp>=fmt.precision-1){var elts=res1.split("e");while(elts[0].endsWith("0")){elts[0]=elts[0].substr(0,elts[0].length-1)}res=elts.join("e")}}}else{res=_b_.str.$factory(self)}if(fmt.type===undefined||"gGn".indexOf(fmt.type)!=-1){if(res.search("e")==-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=="+")&&value>0){res=fmt.sign+res}}if(fmt.type=="%"){res+="%"}return res}float.__format__=function(self,format_spec){check_self_is_float(self,"__format__");var fmt=new $B.parse_format_spec(format_spec,self);return float.$format(self,fmt)};float.$format=function(self,fmt){fmt.align=fmt.align||">";var pf=preformat(self,fmt);if(fmt.z&&Object.is(parseFloat(pf),-0)){pf=pf.substr(1)}var raw=pf.split("."),_int=raw[0];if(fmt.comma){var len=_int.length,nb=Math.ceil(_int.length/3),chunks=[];for(var i=0;i0?float.$factory(x):float.$factory(-x)}function frexp(x){var x1=x;if($B.$isinstance(x,float)){if(isnan(x)||isinf(x)){return[x,0]}x1=float_value(x).value}else if($B.$isinstance(x,$B.long_int)){var exp=x.value.toString(2).length,power=2n**BigInt(exp);return[$B.fast_float(Number(x.value)/Number(power)),exp]}if(x1==0){return[0,0]}var sign=1,ex=0,man=x1;if(man<0){sign=-sign;man=-man}while(man<.5){man*=2;ex--}while(man>=1){man*=.5;ex++}man*=sign;return[man,ex]}function ldexp(mantissa,exponent){if(isninf(mantissa)){return NINF}else if(isinf(mantissa)){return INF}if($B.$isinstance(mantissa,_b_.float)){mantissa=mantissa.value}if(mantissa==0){return ZERO}else if(isNaN(mantissa)){return NAN}if($B.$isinstance(exponent,$B.long_int)){if(exponent.value<0){return ZERO}else{throw _b_.OverflowError.$factory("overflow")}}else if(!isFinite(mantissa*Math.pow(2,exponent))){throw _b_.OverflowError.$factory("overflow")}var steps=Math.min(3,Math.ceil(Math.abs(exponent)/1023));var result=mantissa;for(var i=0;i=0){if(Number.isInteger(other)&&other%2==1){return self}return fast_float(0)}else if(self.value==Number.NEGATIVE_INFINITY&&!isNaN(other)){if(other%2==-1){return fast_float(-0)}else if(other<0){return fast_float(0)}else if(other%2==1){return fast_float(Number.NEGATIVE_INFINITY)}else{return fast_float(Number.POSITIVE_INFINITY)}}else if(self.value==Number.POSITIVE_INFINITY&&!isNaN(other)){return other>0?self:fast_float(0)}if(other==Number.NEGATIVE_INFINITY&&!isNaN(self.value)){return Math.abs(self.value)<1?fast_float(Number.POSITIVE_INFINITY):fast_float(0)}else if(other==Number.POSITIVE_INFINITY&&!isNaN(self.value)){return Math.abs(self.value)<1?fast_float(0):fast_float(Number.POSITIVE_INFINITY)}if(self.value<0&&!Number.isInteger(other)){return _b_.complex.__pow__($B.make_complex(self.value,0),fast_float(other))}return fast_float(Math.pow(self.value,other))}return _b_.NotImplemented};float.__repr__=function(self){$B.builtins_repr_check(float,arguments);self=self.value;if(self==Infinity){return"inf"}else if(self==-Infinity){return"-inf"}else if(isNaN(self)){return"nan"}else if(self===0){if(1/self===-Infinity){return"-0.0"}return"0.0"}var res=self+"";if(res.search(/[.eE]/)==-1){res+=".0"}var split_e=res.split(/e/i);if(split_e.length==2){let mant=split_e[0],exp=split_e[1];if(exp.startsWith("-")){let exp_str=parseInt(exp.substr(1))+"";if(exp_str.length<2){exp_str="0"+exp_str}return mant+"e-"+exp_str}}var x,y;[x,y]=res.split(".");var sign="";if(x[0]=="-"){x=x.substr(1);sign="-"}if(x.length>16){let exp=x.length-1,int_part=x[0],dec_part=x.substr(1)+y;while(dec_part.endsWith("0")){dec_part=dec_part.substr(0,dec_part.length-1)}let mant=int_part;if(dec_part.length>0){mant+="."+dec_part}return sign+mant+"e+"+exp}else if(x=="0"){let exp=0;while(exp3){let rest=y.substr(exp);exp=(exp+1).toString();while(rest.endsWith("0")){rest=rest.substr(0,res.length-1)}let mant=rest[0];if(rest.length>1){mant+="."+rest.substr(1)}if(exp.length==1){exp="0"+exp}return sign+mant+"e-"+exp}}return _b_.str.$factory(res)};float.__round__=function(){var $=$B.args("__round__",2,{self:null,ndigits:null},["self","ndigits"],arguments,{ndigits:_b_.None},null,null);return float.$round($.self,$.ndigits)};float.$round=function(x,ndigits){function overflow(){throw _b_.OverflowError.$factory("cannot convert float infinity to integer")}var no_digits=ndigits===_b_.None;if(isnan(x)){if(ndigits===_b_.None){throw _b_.ValueError.$factory("cannot convert float NaN to integer")}return NAN}else if(isninf(x)){return ndigits===_b_.None?overflow():NINF}else if(isinf(x)){return ndigits===_b_.None?overflow():INF}x=float_value(x);ndigits=ndigits===_b_.None?0:ndigits;if(ndigits==0){var res=Math.round(x.value);if(Math.abs(x.value-res)==.5){if(res%2){return res-1}}if(no_digits){return res}return $B.fast_float(res)}if(ndigits.__class__===$B.long_int){ndigits=Number(ndigits.value)}var pow1,pow2,y,z;if(ndigits>=0){if(ndigits>22){pow1=10**(ndigits-22);pow2=1e22}else{pow1=10**ndigits;pow2=1}y=x.value*pow1*pow2;if(!isFinite(y)){return x}}else{pow1=10**-ndigits;pow2=1;if(isFinite(pow1)){y=x.value/pow1}else{return ZERO}}z=Math.round(y);if(fabs(y-z).value==.5){z=2*Math.round(y/2)}if(ndigits>=0){z=z/pow2/pow1}else{z*=pow1}if(!isFinite(z)){throw _b_.OverflowError.$factory("overflow occurred during round")}return fast_float(z)};float.__setattr__=function(self,attr,value){if(self.__class__===float){if(float[attr]===undefined){throw _b_.AttributeError.$factory("'float' object has no attribute '"+attr+"'")}else{throw _b_.AttributeError.$factory("'float' object attribute '"+attr+"' is read-only")}}self[attr]=value;return _b_.None};float.__truediv__=function(self,other){if($B.$isinstance(other,_b_.int)){if(other.valueOf()==0){throw _b_.ZeroDivisionError.$factory("division by zero")}else if($B.$isinstance(other,$B.long_int)){return float.$factory(self.value/Number(other.value))}return float.$factory(self.value/other)}else if($B.$isinstance(other,float)){if(other.value==0){throw _b_.ZeroDivisionError.$factory("division by zero")}return float.$factory(self.value/other.value)}return _b_.NotImplemented};var op_func_body=`var $B = __BRYTHON__,\n _b_ = __BRYTHON__.builtins\n if($B.$isinstance(other, _b_.int)){\n if(typeof other == "boolean"){\n return other ? $B.fast_float(self.value - 1) : self\n }else if(other.__class__ === $B.long_int){\n return _b_.float.$factory(self.value - parseInt(other.value))\n }else{\n return $B.fast_float(self.value - other)\n }\n }\n if($B.$isinstance(other, _b_.float)){\n return $B.fast_float(self.value - other.value)\n }\n return _b_.NotImplemented`;var ops={"+":"add","-":"sub"};for(let op in ops){let body=op_func_body.replace(/-/gm,op);float[`__${ops[op]}__`]=Function("self","other",body)}var comp_func_body=`\nvar $B = __BRYTHON__,\n _b_ = $B.builtins\nif($B.$isinstance(other, _b_.int)){\n if(other.__class__ === $B.long_int){\n return self.value > parseInt(other.value)\n }\n return self.value > other.valueOf()}\nif($B.$isinstance(other, _b_.float)){\n return self.value > other.value}\nif($B.$isinstance(other, _b_.bool)) {\n return self.value > _b_.bool.__hash__(other)}\nif(_b_.hasattr(other, "__int__") || _b_.hasattr(other, "__index__")) {\n return _b_.int.__gt__(self.value, $B.$GetInt(other))}\n// See if other has the opposite operator, eg <= for >\nvar inv_op = $B.$getattr(other, "__le__", _b_.None)\nif(inv_op !== _b_.None){\n return inv_op(self)}\nthrow _b_.TypeError.$factory(\n "unorderable types: float() > " + $B.class_name(other) + "()")\n`;for(let op in $B.$comps){let body=comp_func_body.replace(/>/gm,op).replace(/__gt__/gm,`__${$B.$comps[op]}__`).replace(/__le__/,`__${$B.$inv_comps[op]}__`);float[`__${$B.$comps[op]}__`]=Function("self","other",body)}var r_opnames=["add","sub","mul","truediv","floordiv","mod","pow","lshift","rshift","and","xor","or","divmod"];for(var r_opname of r_opnames){if(float["__r"+r_opname+"__"]===undefined&&float["__"+r_opname+"__"]){float["__r"+r_opname+"__"]=function(name){return function(self,other){var other_as_num=_b_.int.$to_js_number(other);if(other_as_num!==null){var other_as_float=$B.fast_float(other_as_num);return float["__"+name+"__"](other_as_float,self)}return _b_.NotImplemented}}(r_opname)}}function $FloatClass(value){return new Number(value)}function to_digits(s){var arabic_digits="٠١٢٣٤٥٦٧٨٩",res="";for(var i=0;i-1){res+=x}else{res+=s[i]}}return res}const fast_float=$B.fast_float=function(value){return{__class__:_b_.float,value:value}};float.$factory=function(value){if(value===undefined){return fast_float(0)}$B.check_nb_args_no_kw("float",1,arguments);switch(value){case true:return fast_float(1);case false:return fast_float(0)}var original_value=value;if(typeof value=="number"){return fast_float(value)}if(value.__class__===float){return value}if($B.$isinstance(value,_b_.memoryview)){value=_b_.memoryview.tobytes(value)}if($B.$isinstance(value,_b_.bytes)){try{value=$B.$getattr(value,"decode")("utf-8")}catch(err){throw _b_.ValueError.$factory("could not convert string to float: "+_b_.repr(original_value))}}if(typeof value=="string"){if(value.trim().length==0){throw _b_.ValueError.$factory(`could not convert string to float: ${_b_.repr(value)}`)}value=value.trim();switch(value.toLowerCase()){case"+inf":case"inf":case"+infinity":case"infinity":return fast_float(Number.POSITIVE_INFINITY);case"-inf":case"-infinity":return fast_float(Number.NEGATIVE_INFINITY);case"+nan":case"nan":return fast_float(Number.NaN);case"-nan":return fast_float(-Number.NaN);default:var parts=value.split("e");if(parts[1]){if(parts[1].startsWith("+")||parts[1].startsWith("-")){parts[1]=parts[1].substr(1)}}parts=parts[0].split(".").concat(parts.splice(1));for(var part of parts){if(part.startsWith("_")||part.endsWith("_")){throw _b_.ValueError.$factory("invalid float literal "+value)}}if(value.indexOf("__")>-1){throw _b_.ValueError.$factory("invalid float literal "+value)}value=value.charAt(0)+value.substr(1).replace(/_/g,"");value=to_digits(value);if(isFinite(value)){return fast_float(parseFloat(value))}else{throw _b_.TypeError.$factory("could not convert string to float: "+_b_.repr(original_value))}}}let klass=$B.get_class(value),float_method=$B.$getattr(klass,"__float__",null);if(float_method===null){var index_method=$B.$getattr(klass,"__index__",null);if(index_method===null){throw _b_.TypeError.$factory("float() argument must be a string or a "+"real number, not '"+$B.class_name(value)+"'")}let index=$B.$call(index_method)(value),index_klass=$B.get_class(index);if(index_klass===_b_.int){return fast_float(index)}else if(index_klass===$B.long_int){return $B.long_int.__float__(index)}else if(index_klass.__mro__.indexOf(_b_.int)>-1){let msg=`${$B.class_name(value)}.__index__ returned `+`non-int (type ${$B.class_name(index)}). The `+"ability to return an instance of a strict subclass"+" of int is deprecated, and may be removed in a "+"future version of Python.";$B.warn(_b_.DeprecationWarning,msg);return fast_float(index)}throw _b_.TypeError.$factory("__index__ returned non-int"+` (type ${$B.class_name(index)})`)}let res=$B.$call(float_method)(value);klass=$B.get_class(res);if(klass!==_b_.float){if(klass.__mro__.indexOf(_b_.float)>-1){let msg=`${$B.class_name(value)}.__float__ returned `+`non-float (type ${$B.class_name(res)}). The `+"ability to return an instance of a strict subclass"+" of float is deprecated, and may be removed in a "+"future version of Python.";$B.warn(_b_.DeprecationWarning,msg);return float.$factory(res.value)}throw _b_.TypeError.$factory("__float__ returned non-float"+` (type ${$B.class_name(res)})`)}return res};$B.$FloatClass=$FloatClass;$B.set_func_names(float,"builtins");float.fromhex=_b_.classmethod.$factory(float.fromhex);_b_.float=float;$B.MAX_VALUE=fast_float(Number.MAX_VALUE);$B.MIN_VALUE=fast_float(22250738585072014e-324);const NINF=fast_float(Number.NEGATIVE_INFINITY),INF=fast_float(Number.POSITIVE_INFINITY),NAN=fast_float(Number.NaN),ZERO=fast_float(0)})(__BRYTHON__);(function($B){var _b_=$B.builtins;function $UnsupportedOpType(op,class1,class2){throw _b_.TypeError.$factory("unsupported operand type(s) for "+op+": '"+class1+"' and '"+class2+"'")}var complex={__class__:_b_.type,__dir__:_b_.object.__dir__,__qualname__:"complex",$is_class:true,$native:true,$descriptors:{real:true,imag:true}};complex.__abs__=function(self){var _rf=isFinite(self.$real.value),_if=isFinite(self.$imag.value);if(_rf&&isNaN(self.$imag.value)||_if&&isNaN(self.$real.value)||isNaN(self.$imag.value)&&isNaN(self.$real.value)){return $B.fast_float(NaN)}if(!_rf||!_if){return $B.fast_float(Infinity)}var mag=Math.sqrt(Math.pow(self.$real.value,2)+Math.pow(self.$imag.value,2));if(!isFinite(mag)&&_rf&&_if){throw _b_.OverflowError.$factory("absolute value too large")}return $B.fast_float(mag)};complex.__add__=function(self,other){if($B.$isinstance(other,complex)){return make_complex(self.$real.value+other.$real.value,self.$imag.value+other.$imag.value)}if($B.$isinstance(other,_b_.int)){other=_b_.int.numerator(other);return make_complex($B.rich_op("__add__",self.$real,other).value,self.$imag.value)}if($B.$isinstance(other,_b_.float)){return make_complex(self.$real.value+other.value,self.$imag.value)}return _b_.NotImplemented};complex.__bool__=function(self){return!$B.rich_comp("__eq__",self.$real,0)||!$B.rich_comp("__eq__",self.$imag,0)};complex.__complex__=function(self){if(self.__class__===complex){return self}return $B.make_complex(self.$real,self.$imag)};complex.__eq__=function(self,other){if($B.$isinstance(other,complex)){return self.$real.value==other.$real.value&&self.$imag.value==other.$imag.value}if($B.$isinstance(other,_b_.int)){if(self.$imag.value!=0){return false}return self.$real.value==other.valueOf()}if($B.$isinstance(other,_b_.float)){if(!$B.rich_comp("__eq__",0,self.$imag)){return false}return self.$real.value==other.value}return _b_.NotImplemented};const max_precision=2**31-4;complex.__format__=function(self,format_spec){if(format_spec.length==0){return _b_.str.$factory(self)}var fmt=new $B.parse_format_spec(format_spec,self),type=fmt.conversion_type;var skip_re,add_parens;if(type===undefined||"eEfFgGn".indexOf(type)>-1){if(fmt.precision>max_precision){throw _b_.ValueError.$factory("precision too big")}if(fmt.fill_char=="0"){throw _b_.ValueError.$factory("Zero padding is not allowed in complex format specifier")}if(fmt.align=="="){throw _b_.ValueError.$factory("'=' alignment flag is not allowed in complex format "+"specifier")}var re=self.$real.value,precision=parseInt(fmt.precision,10);if(type===undefined){type="r";if(re==0&&Object.is(re,0)){skip_re=1}else{add_parens=1}}else if(type=="n"){type="g"}if(precision<0){precision=6}else if(type=="r"){type="g"}var format=$B.clone(fmt);format.conversion_type=type;format.precision=precision;var res="";if(!skip_re){res+=_b_.float.$format(self.$real,format);if(self.$imag.value>=0){res+="+"}}var formatted_im=_b_.float.$format(self.$imag,format);var pos=-1,last_num;for(var char of formatted_im){pos++;if(char.match(/\d/)){last_num=pos}}formatted_im=formatted_im.substr(0,last_num+1)+"j"+formatted_im.substr(last_num+1);res+=formatted_im;if(add_parens){res="("+res+")"}return res}throw _b_.ValueError.$factory(`invalid type for complex: ${type}`)};complex.$getnewargs=function(self){return $B.fast_tuple([self.$real,self.$imag])};complex.__getnewargs__=function(){return complex.$getnewargs($B.single_arg("__getnewargs__","self",arguments))};complex.__hash__=function(self){return $B.$hash(self.$real)+$B.$hash(self.$imag)*1000003};complex.__init__=function(){return _b_.None};complex.__invert__=function(self){return~self};complex.__mro__=[_b_.object];complex.__mul__=function(self,other){if($B.$isinstance(other,complex)){return make_complex(self.$real.value*other.$real.value-self.$imag.value*other.$imag.value,self.$imag.value*other.$real.value+self.$real.value*other.$imag.value)}else if($B.$isinstance(other,_b_.int)){return make_complex(self.$real.value*other.valueOf(),self.$imag.value*other.valueOf())}else if($B.$isinstance(other,_b_.float)){return make_complex(self.$real.value*other.value,self.$imag.value*other.value)}else if($B.$isinstance(other,_b_.bool)){if(other.valueOf()){return self}return make_complex(0,0)}$UnsupportedOpType("*",complex,other)};complex.__ne__=function(self,other){var res=complex.__eq__(self,other);return res===_b_.NotImplemented?res:!res};complex.__neg__=function(self){return make_complex(-self.$real.value,-self.$imag.value)};complex.__new__=function(cls){if(cls===undefined){throw _b_.TypeError.$factory("complex.__new__(): not enough arguments")}var res,missing={},$=$B.args("complex",3,{cls:null,real:null,imag:null},["cls","real","imag"],arguments,{real:0,imag:missing},null,null);cls=$.cls;var first=$.real,second=$.imag;if(typeof first=="string"){if(second!==missing){throw _b_.TypeError.$factory("complex() can't take second arg "+"if first is a string")}else{var arg=first;first=first.trim();if(first.startsWith("(")&&first.endsWith(")")){first=first.substr(1);first=first.substr(0,first.length-1)}var complex_re=/^\s*([+-]*[0-9_]*\.?[0-9_]*(e[+-]*[0-9_]*)?)([+-]?)([0-9_]*\.?[0-9_]*(e[+-]*[0-9_]*)?)(j?)\s*$/i;var parts=complex_re.exec(first);function to_num(s){var res=parseFloat(s.charAt(0)+s.substr(1).replace(/_/g,""));if(isNaN(res)){throw _b_.ValueError.$factory("could not convert string "+"to complex: '"+arg+"'")}return res}if(parts===null){throw _b_.ValueError.$factory("complex() arg is a malformed string")}if(parts[_real]&&parts[_imag].startsWith(".")&&parts[_sign]==""){throw _b_.ValueError.$factory("complex() arg is a malformed string")}else if(parts[_real]=="."||parts[_imag]=="."||parts[_real]==".e"||parts[_imag]==".e"||parts[_real]=="e"||parts[_imag]=="e"){throw _b_.ValueError.$factory("complex() arg is a malformed string")}else if(parts[_j]!=""){if(parts[_sign]==""){first=0;if(parts[_real]=="+"||parts[_real]==""){second=1}else if(parts[_real]=="-"){second=-1}else{second=to_num(parts[_real])}}else{first=to_num(parts[_real]);second=parts[_imag]==""?1:to_num(parts[_imag]);second=parts[_sign]=="-"?-second:second}}else{if(parts[_sign]&&parts[_imag]==""){throw _b_.ValueError.$factory("complex() arg is a malformed string")}first=to_num(parts[_real]);second=0}res=make_complex(first,second);res.__class__=cls;res.__dict__=$B.empty_dict();return res}}if(first.__class__===complex&&cls===complex&&second===missing){return first}var arg1=_convert(first),r,i;if(arg1===null){throw _b_.TypeError.$factory("complex() first argument must be a "+`string or a number, not '${$B.class_name(first)}'`)}if(typeof second=="string"){throw _b_.TypeError.$factory("complex() second arg can't be a string")}var arg2=_convert(second===missing?0:second);if(arg2===null){throw _b_.TypeError.$factory("complex() second argument must be a "+`number, not '${$B.class_name(second)}'`)}if(arg1.method=="__complex__"){if(arg2.method=="__complex__"){r=$B.rich_op("__sub__",arg1.result.$real,arg2.result.$imag);i=$B.rich_op("__add__",arg1.result.$imag,arg2.result.$real)}else{r=arg1.result.$real;i=$B.rich_op("__add__",arg1.result.$imag,arg2.result)}}else{if(arg2.method=="__complex__"){r=$B.rich_op("__sub__",arg1.result,arg2.result.$imag);i=arg2.result.$real}else{r=arg1.result;i=arg2.result}}res=make_complex(r,i);res.__class__=cls;res.__dict__=$B.empty_dict();return res};complex.__pos__=function(self){return self};function complex2expo(cx){var norm=Math.sqrt(cx.$real.value*cx.$real.value+cx.$imag.value*cx.$imag.value),sin=cx.$imag.value/norm,cos=cx.$real.value/norm,angle;if(cos==0){angle=sin==1?Math.PI/2:3*Math.PI/2}else if(sin==0){angle=cos==1?0:Math.PI}else{angle=Math.atan(sin/cos)}return{norm:norm,angle:angle}}function c_powi(x,n){if(n>0){return c_powu(x,n)}else{return c_quot(c_1,c_powu(x,-n))}}function c_powu(x,n){var mask=1,r=c_1,p=x;while(mask>0&&n>=mask){if(n&mask){r=c_prod(r,p)}mask<<=1;p=c_prod(p,p)}return r}function c_prod(a,b){return make_complex(a.$real.value*b.$real.value-a.$imag.value*b.$imag.value,a.$real.value*b.$imag.value+a.$imag.value*b.$real.value)}function c_quot(a,b){var abs_breal=Math.abs(b.$real.value),abs_bimag=Math.abs(b.$imag.value);if($B.rich_comp("__ge__",abs_breal,abs_bimag)){if(abs_breal==0){throw _b_.ZeroDivisionError.$factory()}else{let ratio=b.$imag.value/b.$real.value,denom=b.$real.value+b.$imag.value*ratio;return make_complex((a.$real.value+a.$imag.value*ratio)/denom,(a.$imag.value-a.$real.value*ratio)/denom)}}else if(abs_bimag>=abs_breal){let ratio=b.$real.value/b.$imag.value,denom=b.$real.value*ratio+b.$imag.value;if(b.$imag.value==0){throw _b_.ZeroDivisionError.$factory()}return make_complex((a.$real.value*ratio+a.$imag.value)/denom,(a.$imag.value*ratio-a.$real.value)/denom)}else{return $B.make_complex("nan","nan")}}complex.__pow__=function(self,other,mod){if(mod!==undefined&&mod!==_b_.None){throw _b_.ValueError.$factory("complex modulo")}if($B.rich_comp("__eq__",other,1)){var funcs=_b_.float.$funcs;if(funcs.isinf(self.$real)||funcs.isninf(self.$real)||funcs.isinf(self.$imag)||funcs.isninf(self.$imag)){throw _b_.OverflowError.$factory("complex exponentiation")}return self}var small_int=null;if($B.$isinstance(other,_b_.int)&&_b_.abs(other)<100){small_int=other}else if($B.$isinstance(other,_b_.float)&&Number.isInteger(other.value)&&Math.abs(other.value<100)){small_int=other.value}else if($B.$isinstance(other,complex)&&other.$imag.value==0&&Number.isInteger(other.$real.value)&&Math.abs(other.$real.value)<100){small_int=other.$real.value}if(small_int!==null){return c_powi(self,small_int)}if($B.$isinstance(other,_b_.float)){other=_b_.float.$to_js_number(other)}if(self.$real.value==0&&self.$imag.value==0){if($B.$isinstance(other,complex)&&(other.$imag.value!=0||other.$real.value<0)){throw _b_.ZeroDivisionError.$factory("0.0 to a negative or complex power")}return $B.make_complex(0,0)}var exp=complex2expo(self),angle=exp.angle,res=Math.pow(exp.norm,other);if($B.$isinstance(other,_b_.int)){return make_complex(res*Math.cos(angle*other),res*Math.sin(angle*other))}else if($B.$isinstance(other,_b_.float)){return make_complex(res*Math.cos(angle*other.value),res*Math.sin(angle*other.value))}else if($B.$isinstance(other,complex)){var x=other.$real.value,y=other.$imag.value;var pw=Math.pow(exp.norm,x)*Math.pow(Math.E,-y*angle),theta=y*Math.log(exp.norm)-x*angle;if(pw==Number.POSITIVE_INFINITY||pw===Number.NEGATIVE_INFINITY){throw _b_.OverflowError.$factory("complex exponentiation")}return make_complex(pw*Math.cos(theta),pw*Math.sin(theta))}else{throw _b_.TypeError.$factory("unsupported operand type(s) "+"for ** or pow(): 'complex' and '"+$B.class_name(other)+"'")}};complex.__radd__=function(self,other){if($B.$isinstance(other,_b_.bool)){other=other?1:0}if($B.$isinstance(other,_b_.int)){return make_complex(other+self.$real.value,self.$imag.value)}else if($B.$isinstance(other,_b_.float)){return make_complex(other.value+self.$real.value,self.$imag.value)}return _b_.NotImplemented};complex.__repr__=function(self){$B.builtins_repr_check(complex,arguments);var real=Number.isInteger(self.$real.value)?self.$real.value+"":_b_.str.$factory(self.$real),imag=Number.isInteger(self.$imag.value)?self.$imag.value+"":_b_.str.$factory(self.$imag);if(imag.endsWith(".0")){imag=imag.substr(0,imag.length-2)}if(Object.is(self.$imag.value,-0)){imag="-0"}var sign=imag.startsWith("-")?"":"+";if(self.$real.value==0){if(Object.is(self.$real.value,-0)){return"(-0"+sign+imag+"j)"}else{return imag+"j"}}if(self.$imag.value>0||isNaN(self.$imag.value)){return"("+real+"+"+imag+"j)"}if(self.$imag.value==0){if(1/self.$imag.value<0){return"("+real+"-0j)"}return"("+real+"+0j)"}return"("+real+sign+imag+"j)"};complex.__rmul__=function(self,other){if($B.$isinstance(other,_b_.bool)){other=other?1:0}if($B.$isinstance(other,_b_.int)){return make_complex(other*self.$real.value,other*self.$imag.value)}else if($B.$isinstance(other,_b_.float)){return make_complex(other.value*self.$real.value,other.value*self.$imag.value)}return _b_.NotImplemented};complex.__sub__=function(self,other){if($B.$isinstance(other,complex)){return make_complex(self.$real.value-other.$real.value,self.$imag.value-other.$imag.value)}if($B.$isinstance(other,_b_.int)){other=_b_.int.numerator(other);return make_complex(self.$real.value-other.valueOf(),self.$imag.value)}if($B.$isinstance(other,_b_.float)){return make_complex(self.$real.value-other.value,self.$imag.value)}return _b_.NotImplemented};complex.__truediv__=function(self,other){if($B.$isinstance(other,complex)){if(other.$real.value==0&&other.$imag.value==0){throw _b_.ZeroDivisionError.$factory("division by zero")}var _num=self.$real.value*other.$real.value+self.$imag.value*other.$imag.value,_div=other.$real.value*other.$real.value+other.$imag.value*other.$imag.value;var _num2=self.$imag.value*other.$real.value-self.$real.value*other.$imag.value;return make_complex(_num/_div,_num2/_div)}if($B.$isinstance(other,_b_.int)){if(!other.valueOf()){throw _b_.ZeroDivisionError.$factory("division by zero")}return complex.__truediv__(self,complex.$factory(other.valueOf()))}if($B.$isinstance(other,_b_.float)){if(!other.value){throw _b_.ZeroDivisionError.$factory("division by zero")}return complex.__truediv__(self,complex.$factory(other.value))}$UnsupportedOpType("//","complex",other.__class__)};complex.conjugate=function(self){return make_complex(self.$real.value,-self.$imag.value)};complex.__ior__=complex.__or__;var r_opnames=["add","sub","mul","truediv","floordiv","mod","pow","lshift","rshift","and","xor","or"];for(var r_opname of r_opnames){if(complex["__r"+r_opname+"__"]===undefined&&complex["__"+r_opname+"__"]){complex["__r"+r_opname+"__"]=function(name){return function(self,other){if($B.$isinstance(other,_b_.int)){other=make_complex(other,0);return complex["__"+name+"__"](other,self)}else if($B.$isinstance(other,_b_.float)){other=make_complex(other.value,0);return complex["__"+name+"__"](other,self)}else if($B.$isinstance(other,complex)){return complex["__"+name+"__"](other,self)}return _b_.NotImplemented}}(r_opname)}}var comp_func_body=`\n var _b_ = __BRYTHON__.builtins\n if(other === undefined || other == _b_.None){\n return _b_.NotImplemented\n }\n throw _b_.TypeError.$factory("no ordering relation " +\n "is defined for complex numbers")`;for(var $op in $B.$comps){complex["__"+$B.$comps[$op]+"__"]=Function("self","other",comp_func_body.replace(/>/gm,$op))}complex.real=function(self){return self.$real};complex.real.setter=function(){throw _b_.AttributeError.$factory("readonly attribute")};complex.imag=function(self){return self.$imag};complex.imag.setter=function(){throw _b_.AttributeError.$factory("readonly attribute")};var _real=1,_real_mantissa=2,_sign=3,_imag=4,_imag_mantissa=5,_j=6;var expected_class={__complex__:complex,__float__:_b_.float,__index__:_b_.int};function _convert(obj){var klass=obj.__class__||$B.get_class(obj);for(var method_name in expected_class){var missing={},method=$B.$getattr(klass,method_name,missing);if(method!==missing){var res=method(obj);if(!$B.$isinstance(res,expected_class[method_name])){throw _b_.TypeError.$factory(method_name+"returned non-"+expected_class[method_name].__name__+"(type "+$B.get_class(res)+")")}if(method_name=="__index__"&&$B.rich_comp("__gt__",res,__BRYTHON__.MAX_VALUE)){throw _b_.OverflowError.$factory("int too large to convert to float")}if(method_name=="__complex__"&&res.__class__!==complex){$B.warn(_b_.DeprecationWarning,"__complex__ returned "+`non-complex (type ${$B.class_name(res)}). `+"The ability to return an instance of a strict subclass "+"of complex is deprecated, and may be removed in a future "+"version of Python.")}return{result:res,method:method_name}}}return null}var make_complex=$B.make_complex=function(real,imag){return{__class__:complex,$real:_b_.float.$factory(real),$imag:_b_.float.$factory(imag)}};var c_1=make_complex(1,0);complex.$factory=function(){return complex.__new__(complex,...arguments)};$B.set_func_names(complex,"builtins");_b_.complex=complex})(__BRYTHON__);(function($B){var _b_=$B.builtins;var set_ops=["eq","le","lt","ge","gt","sub","rsub","and","rand","or","ror","xor","rxor"];function is_sublist(t1,t2){for(var i=0,ilen=t1.length;i-1){continue}else if(!_b_.hasattr(v.__class__,"__hash__")){return false}}return true};dict.$iter_items=function*(d){if(d.$all_str){for(let key in d.$strings){if(key!="$dict_strings"){yield{key:key,value:d.$strings[key]}}}}if(d.$jsobj){for(let key in d.$jsobj){if(!d.$exclude||!d.$exclude(key)){yield{key:key,value:d.$jsobj[key]}}}}else{var version=d.$version;for(var i=0,len=d._keys.length;i0};dict.__class_getitem__=function(cls,item){if(!Array.isArray(item)){item=[item]}return $B.GenericAlias.$factory(cls,item)};dict.$lookup_by_key=function(d,key,hash){hash=hash===undefined?_b_.hash(key):hash;var indices=d.table[hash],index;if(indices!==undefined){for(var i=0,len=indices.length;ix!==undefined)))}return res};dict.$setitem_string=function(self,key,value){if(self.$all_str){self.$strings[key]=value;return _b_.None}else{var h=_b_.hash(key),indices=self.table[h];if(indices!==undefined){self._values[indices[0]]=value;return _b_.None}}var index=self._keys.length;self.$strings[key]=index;self._keys.push(key);self._values.push(value);self.$version++;return _b_.None};dict.$getitem=function(self,key,ignore_missing){if(self.$all_str){if(typeof key=="string"){if(self.$strings.hasOwnProperty(key)){return self.$strings[key]}}else{var hash_method=$B.$getattr($B.get_class(key),"__hash__");if(hash_method!==_b_.object.__hash__){convert_all_str(self);let lookup=dict.$lookup_by_key(self,key);if(lookup.found){return lookup.value}}}}else if(self.$jsobj){if(self.$exclude&&self.$exclude(key)){throw _b_.KeyError.$factory(key)}if(self.$jsobj.hasOwnProperty(key)){return self.$jsobj[key]}if(!self.table){throw _b_.KeyError.$factory(key)}}else{let lookup=dict.$lookup_by_key(self,key);if(lookup.found){return lookup.value}}if(!ignore_missing){if(self.__class__!==dict&&!ignore_missing){try{var missing_method=$B.$getattr(self.__class__,"__missing__",_b_.None)}catch(err){console.log(err)}if(missing_method!==_b_.None){return missing_method(self,key)}}}throw _b_.KeyError.$factory(key)};dict.__hash__=_b_.None;function init_from_list(self,args){var i=0;for(var item of args){if(item.length!=2){throw _b_.ValueError.$factory("dictionary "+`update sequence element #${i} has length ${item.length}; 2 is required`)}dict.$setitem(self,item[0],item[1]);i++}}dict.$set_string_no_duplicate=function(d,keys,string,value){if(typeof string!=="string"){throw _b_.TypeError.$factory("keywords must be strings")}if(keys.has(string)){throw _b_.TypeError.$factory("dict() got multiple values for keyword "+`argument '${string}'`)}d.$strings[string]=value;keys.add(string)};function add_mapping(d,obj){for(var entry of _b_.dict.$iter_items(obj)){dict.$setitem(d,entry.key,entry.value,entry.hash)}}function add_iterable(d,js_iterable){var i=0;for(var entry of js_iterable){var items=Array.from($B.make_js_iterator(entry));if(items.length!==2){throw _b_.ValueError.$factory("dictionary "+`update sequence element #${i} has length ${items.length}; 2 is required`)}dict.$setitem(d,items[0],items[1]);i++}}dict.__init__=function(self,first,second){if(first===undefined){return _b_.None}if(second===undefined){if(!first.$kw&&$B.$isinstance(first,$B.JSObj)){for(let key in first){dict.$setitem(self,key,first[key])}return _b_.None}else if(first.$kw){var keys=new Set;for(let item of first.$kw){if($B.$isinstance(item,dict)){for(let subitem of dict.$iter_items(item)){dict.$set_string_no_duplicate(self,keys,subitem.key,subitem.value)}}else{for(let key in item){dict.$set_string_no_duplicate(self,keys,key,item[key])}}}return _b_.None}else if(first[Symbol.iterator]){init_from_list(self,first);return _b_.None}else if(first.__class__===$B.generator){init_from_list(self,first.js_gen);return _b_.None}}var $=$B.args("dict",1,{self:null},["self"],arguments,{},"first","second");var args=$.first;if(args.length>1){if($B._experimental_dict){console.log("try dict(*args)");for(var arg of args){if(_b_.isinstance(arg,_b_.dict)){add_mapping(self,arg)}else{try{var js_iterable=$B.make_js_iterator(arg)}catch(err){console.log(arg);console.log(err);throw _b_.TypeError.$factory("expected mapping or "+`iterable, got ${$B.class_name(arg)}`)}add_iterable(self,js_iterable)}}}else{throw _b_.TypeError.$factory("dict expected at most 1 argument"+`, got ${args.length}`)}}else if(args.length==1){args=args[0];if(args.__class__===dict){for(let entry of dict.$iter_items(args)){dict.$setitem(self,entry.key,entry.value,entry.hash)}}else{var keys=$B.$getattr(args,"keys",null);if(keys!==null){var gi=$B.$getattr(args,"__getitem__",null);if(gi!==null){gi=$B.$call(gi);let kiter=_b_.iter($B.$call(keys)());while(true){try{let key=_b_.next(kiter),value=gi(key);dict.__setitem__(self,key,value)}catch(err){if(err.__class__===_b_.StopIteration){break}throw err}}}}else{if(!Array.isArray(args)){args=_b_.list.$factory(args)}init_from_list(self,args)}}}for(let item of _b_.dict.$iter_items($.second)){dict.$setitem(self,item.key,item.value)}return _b_.None};dict.__iter__=function(self){return _b_.iter(dict.keys(self))};dict.__ior__=function(self,other){dict.update(self,other);return self};dict.__len__=function(self){var _count=0;if(self.$all_str){return Object.keys(self.$strings).length}if(self.$jsobj){for(var attr in self.$jsobj){if(attr.charAt(0)!="$"&&(!self.$exclude||!self.$exclude(attr))){_count++}}return _count}for(var d of self._keys){if(d!==undefined){_count++}}return _count};dict.__ne__=function(self,other){var res=dict.__eq__(self,other);return res===_b_.NotImplemented?res:!res};dict.__new__=function(cls){if(cls===undefined){throw _b_.TypeError.$factory("int.__new__(): not enough arguments")}var instance=$B.empty_dict();instance.__class__=cls;if(cls!==dict){instance.__dict__=$B.empty_dict()}return instance};dict.__or__=function(self,other){if(!$B.$isinstance(other,dict)){return _b_.NotImplemented}var res=dict.copy(self);dict.update(res,other);return res};dict.__repr__=function(self){$B.builtins_repr_check(dict,arguments);if(self.$jsobj){return dict.__repr__(jsobj2dict(self.$jsobj,self.$exclude))}if($B.repr.enter(self)){return"{...}"}let res=[];for(let entry of dict.$iter_items(self)){res.push(_b_.repr(entry.key)+": "+_b_.repr(entry.value))}$B.repr.leave(self);return"{"+res.join(", ")+"}"};dict.$iter_items_reversed=function*(d){var version=d.$version;if(d.$all_str){for(var item of Object.entries(d.$strings).reverse()){yield $B.fast_tuple(item);if(d.$version!==version){throw _b_.RuntimeError.$factory("changed in iteration")}}}else{for(var i=d._keys.length-1;i>=0;i--){var key=d._keys[i];if(key!==undefined){yield $B.fast_tuple([key,d._values[i]]);if(d.$version!==version){throw _b_.RuntimeError.$factory("changed in iteration")}}}}if(d.$version!==version){throw _b_.RuntimeError.$factory("changed in iteration")}};dict.$iter_keys_reversed=function*(d){for(var entry of dict.$iter_items_reversed(d)){yield entry[0]}};dict.$iter_values_reversed=function*(d){for(var entry of dict.$iter_items_reversed(d)){yield entry[1]}};function make_reverse_iterator(name,iter_func){var klass=$B.make_class(name,(function(d){return{__class__:klass,d:d,iter:iter_func(d),make_iter:function(){return iter_func(d)}}}));klass.__iter__=function(self){self[Symbol.iterator]=self.make_iter;return self};klass.__next__=function(self){var res=self.iter.next();if(res.done){throw _b_.StopIteration.$factory("")}return res.value};klass.__reduce_ex__=function(self){return $B.fast_tuple([_b_.iter,$B.fast_tuple([Array.from(self.make_iter())])])};$B.set_func_names(klass,"builtins");return klass}const dict_reversekeyiterator=make_reverse_iterator("dict_reversekeyiterator",dict.$iter_keys_reversed);dict.__reversed__=function(self){return dict_reversekeyiterator.$factory(self)};dict.__ror__=function(self,other){if(!$B.$isinstance(other,dict)){return _b_.NotImplemented}var res=dict.copy(other);dict.update(res,self);return res};dict.__setitem__=function(){var $=$B.args("__setitem__",3,{self:null,key:null,value:null},["self","key","value"],arguments,{},null,null);return dict.$setitem($.self,$.key,$.value)};function convert_all_str(d){d.$all_str=false;for(var key in d.$strings){dict.$setitem(d,key,d.$strings[key])}}dict.$setitem=function(self,key,value,$hash,from_setdefault){if(self[$B.JSOBJ]){self[$B.JSOBJ][key]=$B.pyobj2jsobj(value)}if(self.$all_str){if(typeof key=="string"){var int=parseInt(key);if(isNaN(int)||int>=0){self.$strings[key]=value;return _b_.None}else{convert_all_str(self)}}else{convert_all_str(self)}}if(self.$jsobj){if(self.$from_js){value=$B.pyobj2jsobj(value)}if(self.$jsobj.__class__===_b_.type){self.$jsobj[key]=value;if(key=="__init__"||key=="__new__"){self.$jsobj.$factory=$B.$instance_creator(self.$jsobj)}}else{self.$jsobj[key]=value}return _b_.None}if(key instanceof String){key=key.valueOf()}var hash=$hash!==undefined?$hash:$B.$hash(key);var index;if(self.table[hash]===undefined){index=self._keys.length;self.table[hash]=[index]}else{if(!from_setdefault){var lookup=dict.$lookup_by_key(self,key,hash);if(lookup.found){self._values[lookup.index]=value;return _b_.None}}index=self._keys.length;if(self.table[hash]===undefined){self.table[hash]=[index]}else{self.table[hash].push(index)}}self._keys.push(key);self._values.push(value);self._hashes.push(hash);self.$version++;return _b_.None};$B.make_rmethods(dict);dict.clear=function(){var $=$B.args("clear",1,{self:null},["self"],arguments,{},null,null),self=$.self;self.table=Object.create(null);self._keys=[];self._values=[];self.$all_str=true;self.$strings=new $B.str_dict;if(self.$jsobj){for(var attr in self.$jsobj){if(attr.charAt(0)!=="$"&&attr!=="__class__"){delete self.$jsobj[attr]}}}self.$version++;return _b_.None};dict.copy=function(){var $=$B.args("copy",1,{self:null},["self"],arguments,{},null,null),self=$.self,res=$B.empty_dict();if(self.__class__===_b_.dict){$copy_dict(res,self);return res}var it=$B.make_js_iterator(self);for(var k of it){console.log("iteration yields key",k)}return res};dict.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 cls=$.cls,res=$B.$call(cls)(),klass=$B.get_class(res),keys_iter=$B.$iter(keys),setitem=klass===dict?dict.$setitem:$B.$getattr(klass,"__setitem__");while(1){try{var key=_b_.next(keys_iter);setitem(res,key,value)}catch(err){if($B.is_exc(err,[_b_.StopIteration])){return res}throw err}}};dict.get=function(){var $=$B.args("get",3,{self:null,key:null,_default:null},["self","key","_default"],arguments,{_default:_b_.None},null,null);try{return dict.$getitem($.self,$.key,true)}catch(err){if($B.$isinstance(err,_b_.KeyError)){return $._default}else{throw err}}};var dict_items=$B.make_class("dict_items",(function(d){return{__class__:dict_items,dict:d,make_iter:function*(){for(var entry of dict.$iter_items(d)){yield $B.fast_tuple([entry.key,entry.value])}}}}));dict_items.__iter__=function(self){return dict_itemiterator.$factory(self.make_iter)};dict_items.__len__=function(self){return dict.__len__(self.dict)};dict_items.__reduce__=function(self){var items=Array.from(self.make_iter());return $B.fast_tuple([_b_.iter,$B.fast_tuple([items])])};dict_items.__repr__=function(self){var items=Array.from(self.make_iter());items=items.map($B.fast_tuple);return"dict_items("+_b_.repr(items)+")"};const dict_reverseitemiterator=make_reverse_iterator("dict_reverseitemiterator",dict.$iter_items_reversed);dict_items.__reversed__=function(self){return dict_reverseitemiterator.$factory(self.dict)};make_view_comparison_methods(dict_items);$B.set_func_names(dict_items,"builtins");var dict_itemiterator=$B.make_class("dict_itemiterator",(function(make_iter){return{__class__:dict_itemiterator,iter:make_iter(),make_iter:make_iter}}));dict_itemiterator.__iter__=function(self){self[Symbol.iterator]=function(){return self.iter};return self};dict_itemiterator.__next__=function(self){var res=self.iter.next();if(res.done){throw _b_.StopIteration.$factory("")}return $B.fast_tuple(res.value)};dict_itemiterator.__reduce_ex__=function(self){return $B.fast_tuple([_b_.iter,$B.fast_tuple([Array.from(self.make_iter())])])};$B.set_func_names(dict_itemiterator,"builtins");dict.items=function(self){$B.args("items",1,{self:null},["self"],arguments,{},null,null);return dict_items.$factory(self)};var dict_keys=$B.make_class("dict_keys",(function(d){return{__class__:dict_keys,dict:d,make_iter:function(){return dict.$iter_keys_check(d)}}}));dict_keys.__iter__=function(self){return dict_keyiterator.$factory(self.make_iter)};dict_keys.__len__=function(self){return dict.__len__(self.dict)};dict_keys.__reduce__=function(self){var items=Array.from(self.make_iter());return $B.fast_tuple([_b_.iter,$B.fast_tuple([items])])};dict_keys.__repr__=function(self){var items=Array.from(self.make_iter());return"dict_keys("+_b_.repr(items)+")"};dict_keys.__reversed__=function(self){return dict_reversekeyiterator.$factory(self.dict)};make_view_comparison_methods(dict_keys);$B.set_func_names(dict_keys,"builtins");var dict_keyiterator=$B.make_class("dict_keyiterator",(function(make_iter){return{__class__:dict_keyiterator,iter:make_iter(),make_iter:make_iter}}));dict_keyiterator.__iter__=function(self){self[Symbol.iterator]=function(){return self.iter};return self};dict_keyiterator.__next__=function(self){var res=self.iter.next();if(res.done){throw _b_.StopIteration.$factory("")}return res.value};dict_keyiterator.__reduce_ex__=function(self){return $B.fast_tuple([_b_.iter,$B.fast_tuple([Array.from(self.make_iter())])])};$B.set_func_names(dict_keyiterator,"builtins");dict.keys=function(self){$B.args("keys",1,{self:null},["self"],arguments,{},null,null);return dict_keys.$factory(self)};dict.pop=function(){var missing={},$=$B.args("pop",3,{self:null,key:null,_default:null},["self","key","_default"],arguments,{_default:missing},null,null),self=$.self,key=$.key,_default=$._default;try{var res=dict.__getitem__(self,key);dict.__delitem__(self,key);return res}catch(err){if(err.__class__===_b_.KeyError){if(_default!==missing){return _default}throw err}throw err}};dict.popitem=function(self){$B.check_nb_args_no_kw("popitem",1,arguments);if(dict.__len__(self)==0){throw _b_.KeyError.$factory("'popitem(): dictionary is empty'")}if(self.$all_str){for(var key in self.$strings){}let res=$B.fast_tuple([key,self.$strings[key]]);delete self.$strings[key];self.$version++;return res}var index=self._keys.length-1;while(index>=0){if(self._keys[index]!==undefined){let res=$B.fast_tuple([self._keys[index],self._values[index]]);delete self._keys[index];delete self._values[index];self.$version++;return res}index--}};dict.setdefault=function(){var $=$B.args("setdefault",3,{self:null,key:null,_default:null},["self","key","_default"],arguments,{_default:_b_.None},null,null),self=$.self,key=$.key,_default=$._default;_default=_default===undefined?_b_.None:_default;if(self.$all_str){if(!self.$strings.hasOwnProperty(key)){self.$strings[key]=_default}return self.$strings[key]}if(self.$jsobj){if(!self.$jsobj.hasOwnProperty(key)){self.$jsobj[key]=_default}return self.$jsobj[key]}var lookup=dict.$lookup_by_key(self,key);if(lookup.found){return lookup.value}var hash=lookup.hash;dict.$setitem(self,key,_default,hash,true);return _default};dict.update=function(){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($B.$isinstance(o,dict)){if(o.$jsobj){o=jsobj2dict(o.$jsobj)}$copy_dict(self,o)}else if(_b_.hasattr(o,"keys")){var _keys=_b_.list.$factory($B.$call($B.$getattr(o,"keys"))());for(let i=0,len=_keys.length;i-1){continue}if(typeof dict[attr]=="function"){mappingproxy[attr]=function(key){return function(){return dict[key].apply(null,arguments)}}(attr)}else{mappingproxy[attr]=dict[attr]}}$B.set_func_names(mappingproxy,"builtins");function jsobj2dict(x,exclude){exclude=exclude||function(){return false};var d=$B.empty_dict();for(var attr in x){if(attr.charAt(0)!="$"&&!exclude(attr)){if(x[attr]===null){dict.$setitem(d,attr,_b_.None)}else if(x[attr]===undefined){continue}else if(x[attr].$jsobj===x){dict.$setitem(d,attr,d)}else{dict.$setitem(d,attr,$B.jsobj2pyobj(x[attr]))}}}return d}$B.obj_dict=function(obj,exclude){var klass=obj.__class__||$B.get_class(obj);if(klass!==undefined&&klass.$native){throw $B.attr_error("__dict__",obj)}var res={__class__:dict,$jsobj:obj,$exclude:exclude||function(){return false}};return res}})(__BRYTHON__);(function($B){var _b_=$B.builtins,isinstance=$B.$isinstance;function check_not_tuple(self,attr){if(self.__class__===tuple){throw $B.attr_error(attr,self)}}var list={__class__:_b_.type,__qualname__:"list",__mro__:[_b_.object],$is_class:true,$native:true,$match_sequence_pattern:true,__dir__:_b_.object.__dir__};list.__add__=function(self,other){if($B.get_class(self)!==$B.get_class(other)){var this_name=$B.class_name(self);var radd=$B.$getattr(other,"__radd__",null);if(radd===null){throw _b_.TypeError.$factory("can only concatenate "+this_name+' (not "'+$B.class_name(other)+'") to '+this_name)}return _b_.NotImplemented}var res=self.slice(),is_js=other.$is_js_array;for(const item of other){res.push(is_js?$B.$pyobj2jsobj(item):item)}if(isinstance(self,tuple)){res=tuple.$factory(res)}return res};list.__bool__=function(self){return list.__len__(self)>0};list.__class_getitem__=function(cls,item){if(!Array.isArray(item)){item=[item]}return $B.GenericAlias.$factory(cls,item)};list.__contains__=function(){var $=$B.args("__contains__",2,{self:null,item:null},["self","item"],arguments,{},null,null),self=$.self,item=$.item;for(var _item of self){if($B.is_or_equals(_item,item)){return true}}return false};list.__delitem__=function(self,arg){if(isinstance(arg,_b_.int)){let pos=arg;if(arg<0){pos=self.length+pos}if(pos>=0&&pos0?0:self.length}var stop=arg.stop;if(stop===_b_.None){stop=step>0?self.length:0}if(start<0){start=self.length+start}if(stop<0){stop=self.length+stop}let res=[],pos=0;if(step>0){if(stop>start){for(let i=start;istop;i+=step){if(self[i]!==undefined){res[pos++]=i}}res.reverse()}}let i=res.length;while(i--){self.splice(res[i],1)}return _b_.None}if(_b_.hasattr(arg,"__int__")||_b_.hasattr(arg,"__index__")){list.__delitem__(self,_b_.int.$factory(arg));return _b_.None}throw _b_.TypeError.$factory($B.class_name(self)+" indices must be integer, not "+$B.class_name(arg))};list.__eq__=function(self,other){if(other[$B.PYOBJ]){other=other[$B.PYOBJ]}var klass=isinstance(self,list)?list:tuple;if(isinstance(other,klass)){if(other.length==self.length){var i=self.length;while(i--){if(!$B.is_or_equals(self[i],other[i])){return false}}return true}return false}return _b_.NotImplemented};list.__getitem__=function(self,key){$B.check_nb_args_no_kw("__getitem__",2,arguments);return list.$getitem(self,key)};list.$getitem=function(self,key){var klass=self.__class__||$B.get_class(self);var factory=function(list_res){list_res.__class__=klass;return list_res};var int_key;try{int_key=$B.PyNumber_Index(key)}catch(err){}if(int_key!==undefined){let items=self.valueOf(),pos=int_key;if(int_key<0){pos=items.length+pos}if(pos>=0&&pos0){if(stop<=start){return factory(res)}for(let i=start;istart){return factory(res)}for(let i=start;i>stop;i+=step){res[pos++]=items[i]}return factory(res)}}throw _b_.TypeError.$factory($B.class_name(self)+" indices must be integer, not "+$B.class_name(key))};list.__ge__=function(self,other){if(!isinstance(other,list)){return _b_.NotImplemented}var res=list.__le__(other,self);if(res===_b_.NotImplemented){return res}return res};list.__gt__=function(self,other){if(!isinstance(other,list)){return _b_.NotImplemented}var res=list.__lt__(other,self);if(res===_b_.NotImplemented){return res}return res};list.__hash__=_b_.None;list.__iadd__=function(){var $=$B.args("__iadd__",2,{self:null,x:null},["self","x"],arguments,{},null,null);var x=list.$factory($B.$iter($.x));for(var i=0;i1){throw _b_.TypeError.$factory("expected at most 1 argument, got "+args.length)}if(_b_.dict.__len__(kw)>0){throw _b_.TypeError.$factory("list() takes no keyword arguments")}while(self.length>0){self.pop()}var arg=args[0];if(arg===undefined){return _b_.None}var pos=0;for(var item of $B.make_js_iterator(arg)){self[pos++]=item}return _b_.None};var list_iterator=$B.make_iterator_class("list_iterator");list_iterator.__reduce__=list_iterator.__reduce_ex__=function(self){return $B.fast_tuple([_b_.iter,$B.fast_tuple([list.$factory(self)]),0])};list.__iter__=function(self){return list_iterator.$factory(self)};list.__le__=function(self,other){if(!isinstance(other,[list,_b_.tuple])){return _b_.NotImplemented}var i=0;while(i$B.max_array_size/other){throw _b_.OverflowError.$factory(`cannot fit `+`'${$B.class_name(other)}' into an index-sized integer`)}var res=[],$temp=self.slice(),len=$temp.length;for(var i=0;i=0&&pos0){if(args.length==1){for(var item of $B.make_js_iterator(args[0])){self.push(item)}}else{throw _b_.TypeError.$factory("tuple expected at most 1 "+`argument, got ${args.length}`)}}if(cls===tuple&&_b_.dict.__len__(kw)>0){throw _b_.TypeError.$factory("tuple() takes no keyword arguments")}return self};tuple.__repr__=function(self){$B.builtins_repr_check(tuple,arguments);return list_repr(self)};$B.set_func_names(tuple,"builtins");_b_.list=list;_b_.tuple=tuple;_b_.object.__bases__=tuple.$factory();_b_.type.__bases__=$B.fast_tuple([_b_.object])})(__BRYTHON__);(function($B){var _b_=$B.builtins;function to_simple(value){switch(typeof value){case"string":case"number":return value;case"boolean":return value?"true":"false";case"object":if(value===_b_.None){return"null"}else if(value instanceof Number){return value.valueOf()}else if(value instanceof String){return value.valueOf()}break;default:throw _b_.TypeError.$factory("keys must be str, int, "+"float, bool or None, not "+$B.class_name(value))}}$B.pyobj2structuredclone=function(obj,strict){strict=strict===undefined?true:strict;if(typeof obj=="boolean"||typeof obj=="number"||typeof obj=="string"||obj instanceof String){return obj}else if(obj.__class__===_b_.float){return obj.value}else if(obj===_b_.None){return null}else if(Array.isArray(obj)||obj.__class__===_b_.list||obj.__class__===_b_.tuple){let res=new Array(obj.length);for(var i=0,len=obj.length;i`}var js_repr=Object.prototype.toString.call(_self);return``};$B.JSObj.bind=function(_self,evt,func){var js_func=function(ev){try{return func(jsobj2pyobj(ev))}catch(err){if(err.__class__!==undefined){$B.handle_error(err)}else{try{$B.$getattr($B.get_stderr(),"write")(err)}catch(err1){console.log(err)}}}};Object.defineProperty(_self,"$brython_events",{value:_self.$brython_events||{},writable:true});if(_self.$brython_events){_self.$brython_events[evt]=_self.$brython_events[evt]||[];_self.$brython_events[evt].push([func,js_func])}_self.addEventListener(evt,js_func);return _b_.None};$B.JSObj.bindings=function(_self){var res=$B.empty_dict();if(_self.$brython_events){for(var key in _self.$brython_events){_b_.dict.$setitem(res,key,$B.fast_tuple(_self.$brython_events[key].map((x=>x[0]))))}}return res};$B.JSObj.unbind=function(_self,evt,func){if(!_self.$brython_events){return _b_.None}if(!_self.$brython_events[evt]){return _b_.None}var events=_self.$brython_events[evt];if(func===undefined){for(var item of events){_self.removeEventListener(evt,item[1])}delete _self.$brython_events[evt]}else{for(var i=0,len=events.length;i-1){return function(){var args=new Array(arguments.length);args[0]=arguments[0];for(var i=1,len=arguments.length;i-1){return function(){var pylist=$B.$list(arguments[0].map(jsobj2pyobj));return jsobj2pyobj(_b_.list[attr].call(null,pylist,...Array.from(arguments).slice(1)))}}return function(){var js_array=arguments[0],t=jsobj2pyobj(js_array),args=[t];return _b_.list[attr].apply(null,args)}};$B.set_func_names(js_list_meta,"builtins");$B.SizedJSObj=$B.make_class("SizedJavascriptObject");$B.SizedJSObj.__bases__=[$B.JSObj];$B.SizedJSObj.__mro__=[$B.JSObj,_b_.object];$B.SizedJSObj.__len__=function(_self){return _self.length};$B.set_func_names($B.SizedJSObj,"builtins");$B.IterableJSObj=$B.make_class("IterableJavascriptObject");$B.IterableJSObj.__bases__=[$B.JSObj];$B.IterableJSObj.__mro__=[$B.JSObj,_b_.object];$B.IterableJSObj.__contains__=function(self,key){if(self.contains!==undefined&&typeof self.contains=="function"){return self.contains(key)}else{for(var item of $B.IterableJSObj.__iter__(self).it){if($B.is_or_equals(item,key)){return true}}return false}};$B.IterableJSObj.__iter__=function(_self){return{__class__:$B.IterableJSObj,it:_self[Symbol.iterator]()}};$B.IterableJSObj.__len__=function(_self){return _self.length};$B.IterableJSObj.__next__=function(_self){var value=_self.it.next();if(!value.done){return jsobj2pyobj(value.value)}throw _b_.StopIteration.$factory("")};$B.set_func_names($B.IterableJSObj,"builtins");var js_array=$B.js_array=$B.make_class("Array");js_array.__class__=js_list_meta;js_array.__mro__=[$B.JSObj,_b_.object];js_array.__getattribute__=function(_self,attr){if(_b_.list[attr]===undefined){var proto=Object.getPrototypeOf(_self),res=proto[attr];if(res!==undefined){return jsobj2pyobj(res,_self)}if(_self.hasOwnProperty(attr)){return jsobj2pyobj(_self[attr])}throw $B.attr_error(attr,_self)}return function(){var args=pyobj2jsobj(Array.from(arguments));return _b_.list[attr].call(null,_self,...args)}};js_array.__getitem__=function(_self,i){i=$B.PyNumber_Index(i);return jsobj2pyobj(_self[i])};var js_array_iterator=$B.make_class("JSArray_iterator",(function(obj){return{__class__:js_array_iterator,it:obj[Symbol.iterator]()}}));js_array_iterator.__next__=function(_self){var v=_self.it.next();if(v.done){throw _b_.StopIteration.$factory("")}return jsobj2pyobj(v.value)};$B.set_func_names(js_array_iterator,"builtins");js_array.__iter__=function(_self){return js_array_iterator.$factory(_self)};js_array.__repr__=function(_self){if($B.repr.enter(_self)){return"[...]"}var _r=new Array(_self.length),res;for(var i=0;i<_self.length;++i){_r[i]=_b_.str.$factory(_self[i])}res="["+_r.join(", ")+"]";$B.repr.leave(_self);return res};$B.set_func_names(js_array,"javascript");$B.get_jsobj_class=function(obj){if(typeof obj=="function"){return $B.JSObj}var proto=Object.getPrototypeOf(obj);if(proto===null){return $B.JSObj}if(proto[Symbol.iterator]!==undefined){return $B.IterableJSObj}else if(Object.getOwnPropertyNames(proto).indexOf("length")>-1){return $B.SizedJSObj}return $B.JSObj};$B.JSMeta=$B.make_class("JSMeta");$B.JSMeta.__call__=function(cls){var extra_args=new Array(arguments.length-1),klass=arguments[0];for(var i=1,len=arguments.length;i`};$B.generator.close=function(self){var save_frame_obj=$B.frame_obj;if(self.$frame){$B.frame_obj=$B.push_frame(self.$frame)}try{$B.generator.throw(self,_b_.GeneratorExit.$factory())}catch(err){if(!$B.is_exc(err,[_b_.GeneratorExit,_b_.StopIteration])){$B.frame_obj=save_frame_obj;throw _b_.RuntimeError.$factory("generator ignored GeneratorExit")}}$B.frame_obj=save_frame_obj};$B.generator.send=function(self,value){var gen=self.js_gen;gen.$has_run=true;if(gen.$finished){throw _b_.StopIteration.$factory(value)}if(gen.gi_running===true){throw _b_.ValueError.$factory("generator already executing")}gen.gi_running=true;var save_frame_obj=$B.frame_obj;if(self.$frame){$B.frame_obj=$B.push_frame(self.$frame)}try{var res=gen.next(value)}catch(err){gen.$finished=true;$B.frame_obj=save_frame_obj;throw err}if($B.frame_obj!==null&&$B.frame_obj.frame===self.$frame){$B.leave_frame()}$B.frame_obj=save_frame_obj;if(res.value&&res.value.__class__===$GeneratorReturn){gen.$finished=true;throw _b_.StopIteration.$factory(res.value.value)}gen.gi_running=false;if(res.done){throw _b_.StopIteration.$factory(res.value)}return res.value};$B.generator.throw=function(){var $=$B.args("throw",4,{self:null,type:null,value:null,traceback:null},["self","type","value","traceback"],arguments,{value:_b_.None,traceback:_b_.None},null,null),self=$.self,type=$.type,value=$.value,traceback=$.traceback;var gen=self.js_gen,exc=type;if(exc.$is_class){if(!_b_.issubclass(type,_b_.BaseException)){throw _b_.TypeError.$factory("exception value must be an "+"instance of BaseException")}else if(value===undefined||value===_b_.None){exc=$B.$call(exc)()}else if($B.$isinstance(value,type)){exc=value}}else{if(value===_b_.None){value=exc}else{exc=$B.$call(exc)(value)}}if(traceback!==_b_.None){exc.$traceback=traceback}var save_frame_obj=$B.frame_obj;if(self.$frame){$B.frame_obj=$B.push_frame(self.$frame)}var res=gen.throw(exc);$B.frame_obj=save_frame_obj;if(res.done){throw _b_.StopIteration.$factory(res.value)}return res.value};$B.set_func_names($B.generator,"builtins");$B.async_generator=$B.make_class("async_generator",(function(func){var f=function(){var gen=func.apply(null,arguments);var res=Object.create(null);res.__class__=$B.async_generator;res.js_gen=gen;return res};return f}));$B.async_generator.__aiter__=function(self){return self};$B.async_generator.__anext__=function(self){return $B.async_generator.asend(self,_b_.None)};$B.async_generator.aclose=function(self){self.js_gen.$finished=true;return _b_.None};$B.async_generator.asend=async function(self,value){var gen=self.js_gen;if(gen.$finished){throw _b_.StopAsyncIteration.$factory(value)}if(gen.ag_running===true){throw _b_.ValueError.$factory("generator already executing")}gen.ag_running=true;var save_frame_obj=$B.frame_obj;if(self.$frame){$B.frame_obj=$B.push_frame(self.$frame)}try{var res=await gen.next(value)}catch(err){gen.$finished=true;$B.frame_obj=save_frame_obj;throw err}if($B.frame_obj!==null&&$B.frame_obj.frame===self.$frame){$B.leave_frame()}$B.frame_obj=save_frame_obj;if(res.done){throw _b_.StopAsyncIteration.$factory(value)}if(res.value.__class__===$GeneratorReturn){gen.$finished=true;throw _b_.StopAsyncIteration.$factory(res.value.value)}gen.ag_running=false;return res.value};$B.async_generator.athrow=async function(self,type,value,traceback){var gen=self.js_gen,exc=type;if(exc.$is_class){if(!_b_.issubclass(type,_b_.BaseException)){throw _b_.TypeError.$factory("exception value must be an "+"instance of BaseException")}else if(value===undefined){value=$B.$call(exc)()}}else{if(value===undefined){value=exc}else{exc=$B.$call(exc)(value)}}if(traceback!==undefined){exc.$traceback=traceback}var save_frame_obj=$B.frame_obj;if(self.$frame){$B.frame_obj=$B.push_frame(self.$frame)}await gen.throw(value);$B.frame_obj=save_frame_obj};$B.set_func_names($B.async_generator,"builtins")})(__BRYTHON__);(function($B){var _b_=$B.builtins,object=_b_.object,_window=globalThis;function convertDomValue(v){if(v===null||v===undefined){return _b_.None}return $B.jsobj2pyobj(v)}var py_immutable_to_js=$B.py_immutable_to_js=function(pyobj){if($B.$isinstance(pyobj,_b_.float)){return pyobj.value}else if($B.$isinstance(pyobj,$B.long_int)){return $B.long_int.$to_js_number(pyobj)}return pyobj};function js_immutable_to_py(jsobj){if(typeof jsobj=="number"){if(Number.isSafeInteger(jsobj)){return jsobj}else if(Number.isInteger(jsobj)){return $B.fast_long_int(BigInt(jsobj+""))}else{return $B.fast_float(jsobj)}}return jsobj}function $getPosition(e){var left=0,top=0,width=e.width||e.offsetWidth,height=e.height||e.offsetHeight;while(e.offsetParent){left+=e.offsetLeft;top+=e.offsetTop;e=e.offsetParent}left+=e.offsetLeft||0;top+=e.offsetTop||0;if(e.parentElement){var parent_pos=$getPosition(e.parentElement);left+=parent_pos.left;top+=parent_pos.top}return{left:left,top:top,width:width,height:height}}var $mouseCoords=$B.$mouseCoords=function(ev){if(ev.type.startsWith("touch")){let res={};res.x=_b_.int.$factory(ev.touches[0].screenX);res.y=_b_.int.$factory(ev.touches[0].screenY);res.__getattr__=function(attr){return this[attr]};res.__class__="MouseCoords";return res}var posx=0,posy=0;if(!ev){ev=_window.event}if(ev.pageX||ev.pageY){posx=ev.pageX;posy=ev.pageY}else if(ev.clientX||ev.clientY){posx=ev.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;posy=ev.clientY+document.body.scrollTop+document.documentElement.scrollTop}let res={};res.x=_b_.int.$factory(posx);res.y=_b_.int.$factory(posy);res.__getattr__=function(attr){return this[attr]};res.__class__="MouseCoords";return res};$B.$isNode=function(o){return typeof Node==="object"?o instanceof Node:o&&typeof o==="object"&&typeof o.nodeType==="number"&&typeof o.nodeName==="string"};$B.$isNodeList=function(nodes){try{var result=Object.prototype.toString.call(nodes);var re=new RegExp("^\\[object (HTMLCollection|NodeList)\\]$");return typeof nodes==="object"&&re.exec(result)!==null&&nodes.length!==undefined&&(nodes.length==0||typeof nodes[0]==="object"&&nodes[0].nodeType>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(let attr of $DOMEventAttrs_W3C){if(obj[attr]===undefined){flag=false;break}}if(flag){return true}for(let attr of $DOMEventAttrs_IE){if(obj[attr]===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 Attributes=$B.make_class("Attributes",(function(elt){return{__class__:Attributes,elt:elt}}));Attributes.__contains__=function(){var $=$B.args("__getitem__",2,{self:null,key:null},["self","key"],arguments,{},null,null);if($.self.elt instanceof SVGElement){return $.self.elt.hasAttributeNS(null,$.key)}else if(typeof $.self.elt.hasAttribute=="function"){return $.self.elt.hasAttribute($.key)}return false};Attributes.__delitem__=function(){var $=$B.args("__getitem__",2,{self:null,key:null},["self","key"],arguments,{},null,null);if(!Attributes.__contains__($.self,$.key)){throw _b_.KeyError.$factory($.key)}if($.self.elt instanceof SVGElement){$.self.elt.removeAttributeNS(null,$.key);return _b_.None}else if(typeof $.self.elt.hasAttribute=="function"){$.self.elt.removeAttribute($.key);return _b_.None}};Attributes.__getitem__=function(){var $=$B.args("__getitem__",2,{self:null,key:null},["self","key"],arguments,{},null,null);if($.self.elt instanceof SVGElement&&$.self.elt.hasAttributeNS(null,$.key)){return $.self.elt.getAttributeNS(null,$.key)}else if(typeof $.self.elt.hasAttribute=="function"&&$.self.elt.hasAttribute($.key)){return $.self.elt.getAttribute($.key)}throw _b_.KeyError.$factory($.key)};Attributes.__iter__=function(self){self.$counter=0;var attrs=self.elt.attributes,items=[];for(var i=0;i");var DOMEvent=$B.DOMEvent=$B.make_class("DOMEvent",(function(evt_name){return DOMEvent.__new__(DOMEvent,evt_name)}));DOMEvent.__new__=function(cls,evt_name){var ev=new Event(evt_name);ev.__class__=DOMEvent;if(ev.preventDefault===undefined){ev.preventDefault=function(){ev.returnValue=false}}if(ev.stopPropagation===undefined){ev.stopPropagation=function(){ev.cancelBubble=true}}return ev};DOMEvent.__setattr__=function(self,attr,value){self[attr]=value};function dom2svg(svg_elt,coords){var pt=svg_elt.createSVGPoint();pt.x=coords.x;pt.y=coords.y;return pt.matrixTransform(svg_elt.getScreenCTM().inverse())}DOMEvent.__getattribute__=function(ev,attr){switch(attr){case"__repr__":case"__str__":return function(){return""};case"x":return $mouseCoords(ev).x;case"y":return $mouseCoords(ev).y;case"data":if(ev.dataTransfer!==null&&ev.dataTransfer!==undefined){return Clipboard.$factory(ev.dataTransfer)}else if(typeof Worker!=="undefined"&&ev.target instanceof Worker){return $B.structuredclone2pyobj(ev.data)}else if(typeof DedicatedWorkerGlobalScope!=="undefined"&&ev.target instanceof DedicatedWorkerGlobalScope){return $B.structuredclone2pyobj(ev.data)}return convertDomValue(ev.data);case"target":if(ev.target!==undefined){return DOMNode.$factory(ev.target)}break;case"char":return String.fromCharCode(ev.which);case"svgX":if(ev.target instanceof SVGSVGElement){return Math.floor(dom2svg(ev.target,$mouseCoords(ev)).x)}throw _b_.AttributeError.$factory("event target is not an SVG "+"element");case"svgY":if(ev.target instanceof SVGSVGElement){return Math.floor(dom2svg(ev.target,$mouseCoords(self)).y)}throw _b_.AttributeError.$factory("event target is not an SVG "+"element")}var res=ev[attr];if(res!==undefined){if(typeof res=="function"){var func=function(){var args=[];for(var i=0;i");var dom={File:function(){},FileReader:function(){}};dom.File.__class__=_b_.type;dom.File.__str__=function(){return""};dom.FileReader.__class__=_b_.type;dom.FileReader.__str__=function(){return""};var DOMNode=$B.make_class("DOMNode",(function(elt){return elt}));DOMNode.__add__=function(self,other){var res=TagSum.$factory();res.children=[self];var pos=1;if($B.$isinstance(other,TagSum)){res.children=res.children.concat(other.children)}else if($B.$isinstance(other,[_b_.str,_b_.int,_b_.float,_b_.list,_b_.dict,_b_.set,_b_.tuple])){res.children[pos++]=DOMNode.$factory(document.createTextNode(_b_.str.$factory(other)))}else if($B.$isinstance(other,DOMNode)){res.children[pos++]=other}else{try{res.children=res.children.concat(_b_.list.$factory(other))}catch(err){throw _b_.TypeError.$factory("can't add '"+$B.class_name(other)+"' object to DOMNode instance")}}return res};DOMNode.__bool__=function(){return true};DOMNode.__contains__=function(self,key){if(self.nodeType==9&&typeof key=="string"){return document.getElementById(key)!==null}if(self.length!==undefined&&typeof self.item=="function"){for(var i=0,len=self.length;i-1){return function(selector){if(selector===undefined){self.select();return _b_.None}return DOMNode.select(self,selector)}}if(attr=="query"&&self.nodeType==9){let res={__class__:Query,_keys:[],_values:{}};let qs=location.search.substr(1).split("&");if(location.search!=""){for(let i=0;i-1){res._values[key].push(value)}else{res._keys.push(key);res._values[key]=[value]}}}return res}var klass=$B.get_class(self);var property=self[attr];if(property!==undefined&&self.__class__&&klass.__module__!="browser.html"&&klass.__module__!="browser.svg"&&!klass.$webcomponent){var from_class=$B.$getattr(klass,attr,null);if(from_class!==null){property=from_class;if(typeof from_class==="function"){return property.bind(self,self)}}else{var bases=self.__class__.__bases__;var show_message=true;for(var base of bases){if(base.__module__=="browser.html"){show_message=false;break}}if(show_message){from_class=$B.$getattr(self.__class__,attr,_b_.None);if(from_class!==_b_.None){var frame=$B.frame_obj.frame,line=frame.$lineno;console.info("Warning: line "+line+", "+self.tagName+" element has instance attribute '"+attr+"' set."+" Attribute of class "+$B.class_name(self)+" is ignored.")}}}}if(property===undefined){if(self.tagName){var ce=customElements.get(self.tagName.toLowerCase());if(ce!==undefined&&ce.$cls!==undefined){var save_class=self.__class__;self.__class__=ce.$cls;try{let res=_b_.object.__getattribute__(self,attr);self.__class__=save_class;return res}catch(err){self.__class__=save_class;if(!$B.is_exc(err,[_b_.AttributeError])){throw err}}}}else{return object.__getattribute__(self,attr)}}var res=property;if(res!==undefined){if(res===null){return res}if(typeof res==="function"){if(self.__class__&&self.__class__.$webcomponent){var method=$B.$getattr(self.__class__,attr,null);if(method!==null){return res.bind(self)}}if(res.$is_func){return res}var func=function(f,elt){return function(){var args=[];for(var i=0;i0){var res=TagSum.$factory();var pos=res.children.length;for(var i=0;i"}var res=""};DOMNode.__setattr__=function(self,attr,value){switch(attr){case"left":case"top":case"width":case"height":if($B.$isinstance(value,[_b_.int,_b_.float])&&self.nodeType==1){self.style[attr]=value+"px";return _b_.None}else{throw _b_.ValueError.$factory(attr+" value should be"+" an integer or float, not "+$B.class_name(value))}}if(DOMNode["set_"+attr]!==undefined){return DOMNode["set_"+attr](self,value)}function warn(msg){console.log(msg);var frame=$B.frame_obj.frame;if(!frame){return}if($B.get_option("debug")>0){var file=frame.__file__,lineno=frame.$lineno;console.log("module",frame[2],"line",lineno);if($B.file_cache.hasOwnProperty(file)){var src=$B.file_cache[file];console.log(src.split("\n")[lineno-1])}}else{console.log("module",frame[2])}}var proto=Object.getPrototypeOf(self),nb=0;while(!!proto&&proto!==Object.prototype&&nb++<10){var descriptors=Object.getOwnPropertyDescriptors(proto);if(!!descriptors&&typeof descriptors.hasOwnProperty=="function"){if(descriptors.hasOwnProperty(attr)){if(!descriptors[attr].writable&&descriptors[attr].set===undefined){warn("Warning: property '"+attr+"' is not writable. Use element.attrs['"+attr+"'] instead.")}break}}else{break}proto=Object.getPrototypeOf(proto)}if(self.style&&self.style[attr]!==undefined&&attr!="src"){warn("Warning: '"+attr+"' is a property of element.style")}self[attr]=py_immutable_to_js(value);return _b_.None};DOMNode.__setitem__=function(self,key,value){if(typeof key=="number"){self.childNodes[key]=value}else if(typeof key=="string"){if(self.attributes){if(self instanceof SVGElement){self.setAttributeNS(null,key,value)}else if(typeof self.setAttribute=="function"){self.setAttribute(key,value)}}}};DOMNode.abs_left={__get__:function(self){return $getPosition(self).left},__set__:function(){throw _b_.AttributeError.$factory("'DOMNode' objectattribute "+"'abs_left' is read-only")}};DOMNode.abs_top={__get__:function(self){return $getPosition(self).top},__set__:function(){throw _b_.AttributeError.$factory("'DOMNode' objectattribute "+"'abs_top' is read-only")}};DOMNode.attach=DOMNode.__le__;DOMNode.bind=function(){var $=$B.args("bind",4,{self:null,event:null,func:null,options:null},["self","event","func","options"],arguments,{func:_b_.None,options:_b_.None},null,null),self=$.self,event=$.event,func=$.func,options=$.options;if(func===_b_.None){return function(f){return DOMNode.bind(self,event,f)}}var callback=function(f){return function(ev){try{return $B.$call(f)($DOMEvent(ev))}catch(err){if(err.__class__!==undefined){$B.handle_error(err)}else{try{$B.$getattr($B.get_stderr(),"write")(err)}catch(err1){console.log(err)}}}}}(func);callback.$infos=func.$infos;callback.$attrs=func.$attrs||{};callback.$func=func;if(typeof options=="boolean"){self.addEventListener(event,callback,options)}else if(options.__class__===_b_.dict){self.addEventListener(event,callback,_b_.dict.$to_obj(options))}else if(options===_b_.None){self.addEventListener(event,callback,false)}self.$events=self.$events||{};self.$events[event]=self.$events[event]||[];self.$events[event].push([func,callback]);return self};DOMNode.children=function(self){var res=[];if(self.nodeType==9){self=self.body}for(var child of self.children){res.push(DOMNode.$factory(child))}return res};DOMNode.child_nodes=function(self){var res=[];if(self.nodeType==9){self=self.body}for(var child of self.childNodes){res.push(DOMNode.$factory(child))}return res};DOMNode.clear=function(){var $=$B.args("clear",1,{self:null},["self"],arguments,{},null,null),self=$.self;if(self.nodeType==9){self=self.body}while(self.firstChild){self.removeChild(self.firstChild)}};DOMNode.Class=function(self){if(self.className!==undefined){return self.className}return _b_.None};DOMNode.class_name=function(self){return DOMNode.Class(self)};DOMNode.clone=function(self){var res=DOMNode.$factory(self.cloneNode(true));var events=self.$events||{};for(var event in events){var evt_list=events[event];evt_list.forEach((function(evt){var func=evt[0];DOMNode.bind(res,event,func)}))}return res};DOMNode.closest=function(){var $=$B.args("closest",2,{self:null,selector:null},["self","selector"],arguments,{},null,null),self=$.self,selector=$.selector;var res=self.closest(selector);if(res===null){throw _b_.KeyError.$factory("no parent with selector "+selector)}return DOMNode.$factory(res)};DOMNode.bindings=function(self){var res=$B.empty_dict();for(var key in self.$events){_b_.dict.$setitem(res,key,self.$events[key].map((x=>x[1])))}return res};DOMNode.events=function(self,event){self.$events=self.$events||{};var evt_list=self.$events[event]=self.$events[event]||[],callbacks=[];evt_list.forEach((function(evt){callbacks.push(evt[1])}));return callbacks};function make_list(node_list){var res=[];for(var i=0;i-1};Query.__getitem__=function(self,key){var result=self._values[key];if(result===undefined){throw _b_.KeyError.$factory(key)}else if(result.length==1){return result[0]}return result};var Query_iterator=$B.make_iterator_class("query string iterator");Query.__iter__=function(self){return Query_iterator.$factory(self._keys)};Query.__setitem__=function(self,key,value){self._values[key]=[value];return _b_.None};Query.__str__=Query.__repr__=function(self){var elts=[];for(var key in self._values){for(const val of self._values[key]){elts.push(encodeURIComponent(key)+"="+encodeURIComponent(val))}}if(elts.length==0){return""}else{return"?"+elts.join("&")}};Query.getfirst=function(self,key,_default){var result=self._values[key];if(result===undefined){if(_default===undefined){return _b_.None}return _default}return result[0]};Query.getlist=function(self,key){var result=self._values[key];if(result===undefined){return[]}return result};Query.getvalue=function(self,key,_default){try{return Query.__getitem__(self,key)}catch(err){if(_default===undefined){return _b_.None}return _default}};Query.keys=function(self){return self._keys};$B.set_func_names(Query,"");var TagSum=$B.make_class("TagSum",(function(){return{__class__:TagSum,children:[],toString:function(){return"(TagSum)"}}}));TagSum.appendChild=function(self,child){self.children.push(child)};TagSum.__add__=function(self,other){if($B.get_class(other)===TagSum){self.children=self.children.concat(other.children)}else if($B.$isinstance(other,[_b_.str,_b_.int,_b_.float,_b_.dict,_b_.set,_b_.list])){self.children=self.children.concat(DOMNode.$factory(document.createTextNode(other)))}else{self.children.push(other)}return self};TagSum.__radd__=function(self,other){var res=TagSum.$factory();res.children=self.children.slice();res.children.splice(0,0,DOMNode.$factory(document.createTextNode(other)));return res};TagSum.__repr__=function(self){var res="