-
Notifications
You must be signed in to change notification settings - Fork 10
/
alerts3.js
2231 lines (2229 loc) · 74.2 KB
/
alerts3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
// Transcrypt'ed from Python, 2018-02-18 20:37:22
function alerts3 () {
var __symbols__ = ['__py3.6__', '__esv5__'];
var __all__ = {};
var __world__ = __all__;
var __nest__ = function (headObject, tailNames, value) {
var current = headObject;
if (tailNames != '') {
var tailChain = tailNames.split ('.');
var firstNewIndex = tailChain.length;
for (var index = 0; index < tailChain.length; index++) {
if (!current.hasOwnProperty (tailChain [index])) {
firstNewIndex = index;
break;
}
current = current [tailChain [index]];
}
for (var index = firstNewIndex; index < tailChain.length; index++) {
current [tailChain [index]] = {};
current = current [tailChain [index]];
}
}
for (var attrib in value) {
current [attrib] = value [attrib];
}
};
__all__.__nest__ = __nest__;
var __init__ = function (module) {
if (!module.__inited__) {
module.__all__.__init__ (module.__all__);
module.__inited__ = true;
}
return module.__all__;
};
__all__.__init__ = __init__;
var __get__ = function (self, func, quotedFuncName) {
if (self) {
if (self.hasOwnProperty ('__class__') || typeof self == 'string' || self instanceof String) {
if (quotedFuncName) {
Object.defineProperty (self, quotedFuncName, {
value: function () {
var args = [] .slice.apply (arguments);
return func.apply (null, [self] .concat (args));
},
writable: true,
enumerable: true,
configurable: true
});
}
return function () {
var args = [] .slice.apply (arguments);
return func.apply (null, [self] .concat (args));
};
}
else {
return func;
}
}
else {
return func;
}
}
__all__.__get__ = __get__;
var __getcm__ = function (self, func, quotedFuncName) {
if (self.hasOwnProperty ('__class__')) {
return function () {
var args = [] .slice.apply (arguments);
return func.apply (null, [self.__class__] .concat (args));
};
}
else {
return function () {
var args = [] .slice.apply (arguments);
return func.apply (null, [self] .concat (args));
};
}
}
__all__.__getcm__ = __getcm__;
var __getsm__ = function (self, func, quotedFuncName) {
return func;
}
__all__.__getsm__ = __getsm__;
var py_metatype = {
__name__: 'type',
__bases__: [],
__new__: function (meta, name, bases, attribs) {
var cls = function () {
var args = [] .slice.apply (arguments);
return cls.__new__ (args);
};
for (var index = bases.length - 1; index >= 0; index--) {
var base = bases [index];
for (var attrib in base) {
var descrip = Object.getOwnPropertyDescriptor (base, attrib);
Object.defineProperty (cls, attrib, descrip);
}
}
cls.__metaclass__ = meta;
cls.__name__ = name.startsWith ('py_') ? name.slice (3) : name;
cls.__bases__ = bases;
for (var attrib in attribs) {
var descrip = Object.getOwnPropertyDescriptor (attribs, attrib);
Object.defineProperty (cls, attrib, descrip);
}
return cls;
}
};
py_metatype.__metaclass__ = py_metatype;
__all__.py_metatype = py_metatype;
var object = {
__init__: function (self) {},
__metaclass__: py_metatype,
__name__: 'object',
__bases__: [],
__new__: function (args) {
var instance = Object.create (this, {__class__: {value: this, enumerable: true}});
this.__init__.apply (null, [instance] .concat (args));
return instance;
}
};
__all__.object = object;
var __class__ = function (name, bases, attribs, meta) {
if (meta === undefined) {
meta = bases [0] .__metaclass__;
}
return meta.__new__ (meta, name, bases, attribs);
}
__all__.__class__ = __class__;
var __pragma__ = function () {};
__all__.__pragma__ = __pragma__;
__nest__ (
__all__,
'org.transcrypt.__base__', {
__all__: {
__inited__: false,
__init__: function (__all__) {
var __name__ = 'org.transcrypt.__base__';
var __Envir__ = __class__ ('__Envir__', [object], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self) {
self.interpreter_name = 'python';
self.transpiler_name = 'transcrypt';
self.transpiler_version = '3.6.94';
self.target_subdir = '__javascript__';
});}
});
var __envir__ = __Envir__ ();
__pragma__ ('<all>')
__all__.__Envir__ = __Envir__;
__all__.__envir__ = __envir__;
__all__.__name__ = __name__;
__pragma__ ('</all>')
}
}
}
);
__nest__ (
__all__,
'org.transcrypt.__standard__', {
__all__: {
__inited__: false,
__init__: function (__all__) {
var __name__ = 'org.transcrypt.__standard__';
var Exception = __class__ ('Exception', [object], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self) {
var kwargs = dict ();
if (arguments.length) {
var __ilastarg0__ = arguments.length - 1;
if (arguments [__ilastarg0__] && arguments [__ilastarg0__].hasOwnProperty ("__kwargtrans__")) {
var __allkwargs0__ = arguments [__ilastarg0__--];
for (var __attrib0__ in __allkwargs0__) {
switch (__attrib0__) {
case 'self': var self = __allkwargs0__ [__attrib0__]; break;
default: kwargs [__attrib0__] = __allkwargs0__ [__attrib0__];
}
}
delete kwargs.__kwargtrans__;
}
var args = tuple ([].slice.apply (arguments).slice (1, __ilastarg0__ + 1));
}
else {
var args = tuple ();
}
self.__args__ = args;
try {
self.stack = kwargs.error.stack;
}
catch (__except0__) {
self.stack = 'No stack trace available';
}
});},
get __repr__ () {return __get__ (this, function (self) {
if (len (self.__args__)) {
return '{}{}'.format (self.__class__.__name__, repr (tuple (self.__args__)));
}
else {
return '{}()'.format (self.__class__.__name__);
}
});},
get __str__ () {return __get__ (this, function (self) {
if (len (self.__args__) > 1) {
return str (tuple (self.__args__));
}
else if (len (self.__args__)) {
return str (self.__args__ [0]);
}
else {
return '';
}
});}
});
var IterableError = __class__ ('IterableError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, error) {
Exception.__init__ (self, "Can't iterate over non-iterable", __kwargtrans__ ({error: error}));
});}
});
var StopIteration = __class__ ('StopIteration', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, error) {
Exception.__init__ (self, 'Iterator exhausted', __kwargtrans__ ({error: error}));
});}
});
var ValueError = __class__ ('ValueError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, message, error) {
Exception.__init__ (self, message, __kwargtrans__ ({error: error}));
});}
});
var KeyError = __class__ ('KeyError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, message, error) {
Exception.__init__ (self, message, __kwargtrans__ ({error: error}));
});}
});
var AssertionError = __class__ ('AssertionError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, message, error) {
if (message) {
Exception.__init__ (self, message, __kwargtrans__ ({error: error}));
}
else {
Exception.__init__ (self, __kwargtrans__ ({error: error}));
}
});}
});
var NotImplementedError = __class__ ('NotImplementedError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, message, error) {
Exception.__init__ (self, message, __kwargtrans__ ({error: error}));
});}
});
var IndexError = __class__ ('IndexError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, message, error) {
Exception.__init__ (self, message, __kwargtrans__ ({error: error}));
});}
});
var AttributeError = __class__ ('AttributeError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, message, error) {
Exception.__init__ (self, message, __kwargtrans__ ({error: error}));
});}
});
var py_TypeError = __class__ ('py_TypeError', [Exception], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, message, error) {
Exception.__init__ (self, message, __kwargtrans__ ({error: error}));
});}
});
var Warning = __class__ ('Warning', [Exception], {
__module__: __name__,
});
var UserWarning = __class__ ('UserWarning', [Warning], {
__module__: __name__,
});
var DeprecationWarning = __class__ ('DeprecationWarning', [Warning], {
__module__: __name__,
});
var RuntimeWarning = __class__ ('RuntimeWarning', [Warning], {
__module__: __name__,
});
var __sort__ = function (iterable, key, reverse) {
if (typeof key == 'undefined' || (key != null && key .hasOwnProperty ("__kwargtrans__"))) {;
var key = null;
};
if (typeof reverse == 'undefined' || (reverse != null && reverse .hasOwnProperty ("__kwargtrans__"))) {;
var reverse = false;
};
if (arguments.length) {
var __ilastarg0__ = arguments.length - 1;
if (arguments [__ilastarg0__] && arguments [__ilastarg0__].hasOwnProperty ("__kwargtrans__")) {
var __allkwargs0__ = arguments [__ilastarg0__--];
for (var __attrib0__ in __allkwargs0__) {
switch (__attrib0__) {
case 'iterable': var iterable = __allkwargs0__ [__attrib0__]; break;
case 'key': var key = __allkwargs0__ [__attrib0__]; break;
case 'reverse': var reverse = __allkwargs0__ [__attrib0__]; break;
}
}
}
}
else {
}
if (key) {
iterable.sort ((function __lambda__ (a, b) {
if (arguments.length) {
var __ilastarg0__ = arguments.length - 1;
if (arguments [__ilastarg0__] && arguments [__ilastarg0__].hasOwnProperty ("__kwargtrans__")) {
var __allkwargs0__ = arguments [__ilastarg0__--];
for (var __attrib0__ in __allkwargs0__) {
switch (__attrib0__) {
case 'a': var a = __allkwargs0__ [__attrib0__]; break;
case 'b': var b = __allkwargs0__ [__attrib0__]; break;
}
}
}
}
else {
}
return (key (a) > key (b) ? 1 : -(1));
}));
}
else {
iterable.sort ();
}
if (reverse) {
iterable.reverse ();
}
};
var sorted = function (iterable, key, reverse) {
if (typeof key == 'undefined' || (key != null && key .hasOwnProperty ("__kwargtrans__"))) {;
var key = null;
};
if (typeof reverse == 'undefined' || (reverse != null && reverse .hasOwnProperty ("__kwargtrans__"))) {;
var reverse = false;
};
if (arguments.length) {
var __ilastarg0__ = arguments.length - 1;
if (arguments [__ilastarg0__] && arguments [__ilastarg0__].hasOwnProperty ("__kwargtrans__")) {
var __allkwargs0__ = arguments [__ilastarg0__--];
for (var __attrib0__ in __allkwargs0__) {
switch (__attrib0__) {
case 'iterable': var iterable = __allkwargs0__ [__attrib0__]; break;
case 'key': var key = __allkwargs0__ [__attrib0__]; break;
case 'reverse': var reverse = __allkwargs0__ [__attrib0__]; break;
}
}
}
}
else {
}
if (py_typeof (iterable) == dict) {
var result = copy (iterable.py_keys ());
}
else {
var result = copy (iterable);
}
__sort__ (result, key, reverse);
return result;
};
var map = function (func, iterable) {
return (function () {
var __accu0__ = [];
var __iterable0__ = iterable;
for (var __index0__ = 0; __index0__ < len (__iterable0__); __index0__++) {
var item = __iterable0__ [__index0__];
__accu0__.append (func (item));
}
return __accu0__;
}) ();
};
var filter = function (func, iterable) {
if (func == null) {
var func = bool;
}
return (function () {
var __accu0__ = [];
var __iterable0__ = iterable;
for (var __index0__ = 0; __index0__ < len (__iterable0__); __index0__++) {
var item = __iterable0__ [__index0__];
if (func (item)) {
__accu0__.append (item);
}
}
return __accu0__;
}) ();
};
var __Terminal__ = __class__ ('__Terminal__', [object], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self) {
self.buffer = '';
try {
self.element = document.getElementById ('__terminal__');
}
catch (__except0__) {
self.element = null;
}
if (self.element) {
self.element.style.overflowX = 'auto';
self.element.style.boxSizing = 'border-box';
self.element.style.padding = '5px';
self.element.innerHTML = '_';
}
});},
get print () {return __get__ (this, function (self) {
var sep = ' ';
var end = '\n';
if (arguments.length) {
var __ilastarg0__ = arguments.length - 1;
if (arguments [__ilastarg0__] && arguments [__ilastarg0__].hasOwnProperty ("__kwargtrans__")) {
var __allkwargs0__ = arguments [__ilastarg0__--];
for (var __attrib0__ in __allkwargs0__) {
switch (__attrib0__) {
case 'self': var self = __allkwargs0__ [__attrib0__]; break;
case 'sep': var sep = __allkwargs0__ [__attrib0__]; break;
case 'end': var end = __allkwargs0__ [__attrib0__]; break;
}
}
}
var args = tuple ([].slice.apply (arguments).slice (1, __ilastarg0__ + 1));
}
else {
var args = tuple ();
}
self.buffer = '{}{}{}'.format (self.buffer, sep.join ((function () {
var __accu0__ = [];
var __iterable0__ = args;
for (var __index0__ = 0; __index0__ < len (__iterable0__); __index0__++) {
var arg = __iterable0__ [__index0__];
__accu0__.append (str (arg));
}
return __accu0__;
}) ()), end).__getslice__ (-(4096), null, 1);
if (self.element) {
self.element.innerHTML = self.buffer.py_replace ('\n', '<br>').py_replace (' ', ' ');
self.element.scrollTop = self.element.scrollHeight;
}
else {
console.log (sep.join ((function () {
var __accu0__ = [];
var __iterable0__ = args;
for (var __index0__ = 0; __index0__ < len (__iterable0__); __index0__++) {
var arg = __iterable0__ [__index0__];
__accu0__.append (str (arg));
}
return __accu0__;
}) ()));
}
});},
get input () {return __get__ (this, function (self, question) {
if (arguments.length) {
var __ilastarg0__ = arguments.length - 1;
if (arguments [__ilastarg0__] && arguments [__ilastarg0__].hasOwnProperty ("__kwargtrans__")) {
var __allkwargs0__ = arguments [__ilastarg0__--];
for (var __attrib0__ in __allkwargs0__) {
switch (__attrib0__) {
case 'self': var self = __allkwargs0__ [__attrib0__]; break;
case 'question': var question = __allkwargs0__ [__attrib0__]; break;
}
}
}
}
else {
}
self.print ('{}'.format (question), __kwargtrans__ ({end: ''}));
var answer = window.prompt ('\n'.join (self.buffer.py_split ('\n').__getslice__ (-(16), null, 1)));
self.print (answer);
return answer;
});}
});
var __terminal__ = __Terminal__ ();
__pragma__ ('<all>')
__all__.AssertionError = AssertionError;
__all__.AttributeError = AttributeError;
__all__.DeprecationWarning = DeprecationWarning;
__all__.Exception = Exception;
__all__.IndexError = IndexError;
__all__.IterableError = IterableError;
__all__.KeyError = KeyError;
__all__.NotImplementedError = NotImplementedError;
__all__.RuntimeWarning = RuntimeWarning;
__all__.StopIteration = StopIteration;
__all__.py_TypeError = py_TypeError;
__all__.UserWarning = UserWarning;
__all__.ValueError = ValueError;
__all__.Warning = Warning;
__all__.__Terminal__ = __Terminal__;
__all__.__name__ = __name__;
__all__.__sort__ = __sort__;
__all__.__terminal__ = __terminal__;
__all__.filter = filter;
__all__.map = map;
__all__.sorted = sorted;
__pragma__ ('</all>')
}
}
}
);
var __call__ = function (/* <callee>, <this>, <params>* */) {
var args = [] .slice.apply (arguments);
if (typeof args [0] == 'object' && '__call__' in args [0]) {
return args [0] .__call__ .apply (args [1], args.slice (2));
}
else {
return args [0] .apply (args [1], args.slice (2));
}
};
__all__.__call__ = __call__;
__nest__ (__all__, '', __init__ (__all__.org.transcrypt.__base__));
var __envir__ = __all__.__envir__;
__nest__ (__all__, '', __init__ (__all__.org.transcrypt.__standard__));
var Exception = __all__.Exception;
var IterableError = __all__.IterableError;
var StopIteration = __all__.StopIteration;
var ValueError = __all__.ValueError;
var KeyError = __all__.KeyError;
var AssertionError = __all__.AssertionError;
var NotImplementedError = __all__.NotImplementedError;
var IndexError = __all__.IndexError;
var AttributeError = __all__.AttributeError;
var py_TypeError = __all__.py_TypeError;
var Warning = __all__.Warning;
var UserWarning = __all__.UserWarning;
var DeprecationWarning = __all__.DeprecationWarning;
var RuntimeWarning = __all__.RuntimeWarning;
var __sort__ = __all__.__sort__;
var sorted = __all__.sorted;
var map = __all__.map;
var filter = __all__.filter;
__all__.print = __all__.__terminal__.print;
__all__.input = __all__.__terminal__.input;
var __terminal__ = __all__.__terminal__;
var print = __all__.print;
var input = __all__.input;
__envir__.executor_name = __envir__.transpiler_name;
var __main__ = {__file__: ''};
__all__.main = __main__;
var __except__ = null;
__all__.__except__ = __except__;
var __kwargtrans__ = function (anObject) {
anObject.__kwargtrans__ = null;
anObject.constructor = Object;
return anObject;
}
__all__.__kwargtrans__ = __kwargtrans__;
var __globals__ = function (anObject) {
if (isinstance (anObject, dict)) {
return anObject;
}
else {
return dict (anObject)
}
}
__all__.__globals__ = __globals__
var __super__ = function (aClass, methodName) {
for (var index = 0; index < aClass.__bases__.length; index++) {
var base = aClass.__bases__ [index];
if (methodName in base) {
return base [methodName];
}
}
throw new Exception ('Superclass method not found');
}
__all__.__super__ = __super__
var property = function (getter, setter) {
if (!setter) {
setter = function () {};
}
return {get: function () {return getter (this)}, set: function (value) {setter (this, value)}, enumerable: true};
}
__all__.property = property;
var __setProperty__ = function (anObject, name, descriptor) {
if (!anObject.hasOwnProperty (name)) {
Object.defineProperty (anObject, name, descriptor);
}
}
__all__.__setProperty__ = __setProperty__
function assert (condition, message) {
if (!condition) {
throw AssertionError (message, new Error ());
}
}
__all__.assert = assert;
var __merge__ = function (object0, object1) {
var result = {};
for (var attrib in object0) {
result [attrib] = object0 [attrib];
}
for (var attrib in object1) {
result [attrib] = object1 [attrib];
}
return result;
};
__all__.__merge__ = __merge__;
var dir = function (obj) {
var aList = [];
for (var aKey in obj) {
aList.push (aKey.startsWith ('py_') ? aKey.slice (3) : aKey);
}
aList.sort ();
return aList;
};
__all__.dir = dir;
var setattr = function (obj, name, value) {
obj [name] = value;
};
__all__.setattr = setattr;
var getattr = function (obj, name) {
return name in obj ? obj [name] : obj ['py_' + name];
};
__all__.getattr = getattr;
var hasattr = function (obj, name) {
try {
return name in obj || 'py_' + name in obj;
}
catch (exception) {
return false;
}
};
__all__.hasattr = hasattr;
var delattr = function (obj, name) {
if (name in obj) {
delete obj [name];
}
else {
delete obj ['py_' + name];
}
};
__all__.delattr = (delattr);
var __in__ = function (element, container) {
if (container === undefined || container === null) {
return false;
}
if (container.__contains__ instanceof Function) {
return container.__contains__ (element);
}
else {
return (
container.indexOf ?
container.indexOf (element) > -1 :
container.hasOwnProperty (element)
);
}
};
__all__.__in__ = __in__;
var __specialattrib__ = function (attrib) {
return (attrib.startswith ('__') && attrib.endswith ('__')) || attrib == 'constructor' || attrib.startswith ('py_');
};
__all__.__specialattrib__ = __specialattrib__;
var len = function (anObject) {
if (anObject === undefined || anObject === null) {
return 0;
}
if (anObject.__len__ instanceof Function) {
return anObject.__len__ ();
}
if (anObject.length !== undefined) {
return anObject.length;
}
var length = 0;
for (var attr in anObject) {
if (!__specialattrib__ (attr)) {
length++;
}
}
return length;
};
__all__.len = len;
function __i__ (any) {
return py_typeof (any) == dict ? any.py_keys () : any;
}
function __k__ (keyed, key) {
var result = keyed [key];
if (typeof result == 'undefined') {
if (keyed instanceof Array)
if (key == +key && key >= 0 && keyed.length > key)
return result;
else
throw IndexError (key, new Error());
else
throw KeyError (key, new Error());
}
return result;
}
function __t__ (target) {
return (
target === undefined || target === null ? false :
['boolean', 'number'] .indexOf (typeof target) >= 0 ? target :
target.__bool__ instanceof Function ? (target.__bool__ () ? target : false) :
target.__len__ instanceof Function ? (target.__len__ () !== 0 ? target : false) :
target instanceof Function ? target :
len (target) !== 0 ? target :
false
);
}
__all__.__t__ = __t__;
var float = function (any) {
if (any == 'inf') {
return Infinity;
}
else if (any == '-inf') {
return -Infinity;
}
else if (any == 'nan') {
return NaN;
}
else if (isNaN (parseFloat (any))) {
if (any === false) {
return 0;
}
else if (any === true) {
return 1;
}
else {
throw ValueError ("could not convert string to float: '" + str(any) + "'", new Error ());
}
}
else {
return +any;
}
};
float.__name__ = 'float';
float.__bases__ = [object];
__all__.float = float;
var int = function (any) {
return float (any) | 0
};
int.__name__ = 'int';
int.__bases__ = [object];
__all__.int = int;
var bool = function (any) {
return !!__t__ (any);
};
bool.__name__ = 'bool';
bool.__bases__ = [int];
__all__.bool = bool;
var py_typeof = function (anObject) {
var aType = typeof anObject;
if (aType == 'object') {
try {
return '__class__' in anObject ? anObject.__class__ : object;
}
catch (exception) {
return aType;
}
}
else {
return (
aType == 'boolean' ? bool :
aType == 'string' ? str :
aType == 'number' ? (anObject % 1 == 0 ? int : float) :
null
);
}
};
__all__.py_typeof = py_typeof;
var issubclass = function (aClass, classinfo) {
if (classinfo instanceof Array) {
for (var index = 0; index < classinfo.length; index++) {
var aClass2 = classinfo [index];
if (issubclass (aClass, aClass2)) {
return true;
}
}
return false;
}
try {
var aClass2 = aClass;
if (aClass2 == classinfo)
return true;
else {
var bases = [].slice.call (aClass2.__bases__);
while (bases.length) {
aClass2 = bases.shift ();
if (aClass2 == classinfo)
return true;
if (aClass2.__bases__.length)
bases = [].slice.call (aClass2.__bases__).concat (bases);
}
return false;
}
}
catch (exception) {
return aClass == classinfo || classinfo == object;
}
};
__all__.issubclass = issubclass;
var isinstance = function (anObject, classinfo) {
try {
return '__class__' in anObject ? issubclass (anObject.__class__, classinfo) : issubclass (py_typeof (anObject), classinfo);
}
catch (exception) {
return issubclass (py_typeof (anObject), classinfo);
}
};
__all__.isinstance = isinstance;
var callable = function (anObject) {
return anObject && typeof anObject == 'object' && '__call__' in anObject ? true : typeof anObject === 'function';
};
__all__.callable = callable;
var repr = function (anObject) {
try {
return anObject.__repr__ ();
}
catch (exception) {
try {
return anObject.__str__ ();
}
catch (exception) {
try {
if (anObject == null) {
return 'None';
}
else if (anObject.constructor == Object) {
var result = '{';
var comma = false;
for (var attrib in anObject) {
if (!__specialattrib__ (attrib)) {
if (attrib.isnumeric ()) {
var attribRepr = attrib;
}
else {
var attribRepr = '\'' + attrib + '\'';
}
if (comma) {
result += ', ';
}
else {
comma = true;
}
result += attribRepr + ': ' + repr (anObject [attrib]);
}
}
result += '}';
return result;
}
else {
return typeof anObject == 'boolean' ? anObject.toString () .capitalize () : anObject.toString ();
}
}
catch (exception) {
return '<object of type: ' + typeof anObject + '>';
}
}
}
};
__all__.repr = repr;
var chr = function (charCode) {
return String.fromCharCode (charCode);
};
__all__.chr = chr;
var ord = function (aChar) {
return aChar.charCodeAt (0);
};
__all__.ord = ord;
var max = function (nrOrSeq) {
return arguments.length == 1 ? Math.max.apply (null, nrOrSeq) : Math.max.apply (null, arguments);
};
__all__.max = max;
var min = function (nrOrSeq) {
return arguments.length == 1 ? Math.min.apply (null, nrOrSeq) : Math.min.apply (null, arguments);
};
__all__.min = min;
var abs = Math.abs;
__all__.abs = abs;
var round = function (number, ndigits) {
if (ndigits) {
var scale = Math.pow (10, ndigits);
number *= scale;
}
var rounded = Math.round (number);
if (rounded - number == 0.5 && rounded % 2) {
rounded -= 1;
}
if (ndigits) {
rounded /= scale;
}
return rounded;
};
__all__.round = round;
function __jsUsePyNext__ () {
try {
var result = this.__next__ ();
return {value: result, done: false};
}
catch (exception) {
return {value: undefined, done: true};
}
}
function __pyUseJsNext__ () {
var result = this.next ();
if (result.done) {
throw StopIteration (new Error ());
}
else {
return result.value;
}
}
function py_iter (iterable) {
if (typeof iterable == 'string' || '__iter__' in iterable) {
var result = iterable.__iter__ ();
result.next = __jsUsePyNext__;
}
else if ('selector' in iterable) {
var result = list (iterable) .__iter__ ();
result.next = __jsUsePyNext__;
}
else if ('next' in iterable) {
var result = iterable
if (! ('__next__' in result)) {
result.__next__ = __pyUseJsNext__;
}
}
else if (Symbol.iterator in iterable) {
var result = iterable [Symbol.iterator] ();
result.__next__ = __pyUseJsNext__;
}
else {
throw IterableError (new Error ());
}
result [Symbol.iterator] = function () {return result;};
return result;
}
function py_next (iterator) {
try {
var result = iterator.__next__ ();
}
catch (exception) {
var result = iterator.next ();
if (result.done) {
throw StopIteration (new Error ());
}
else {
return result.value;
}
}
if (result == undefined) {
throw StopIteration (new Error ());
}
else {
return result;
}
}
function __PyIterator__ (iterable) {
this.iterable = iterable;
this.index = 0;
}
__PyIterator__.prototype.__next__ = function () {
if (this.index < this.iterable.length) {
return this.iterable [this.index++];
}
else {
throw StopIteration (new Error ());
}
};
function __JsIterator__ (iterable) {
this.iterable = iterable;
this.index = 0;
}
__JsIterator__.prototype.next = function () {
if (this.index < this.iterable.py_keys.length) {
return {value: this.index++, done: false};
}
else {
return {value: undefined, done: true};
}
};
var py_reversed = function (iterable) {
iterable = iterable.slice ();
iterable.reverse ();
return iterable;
};
__all__.py_reversed = py_reversed;
var zip = function () {
var args = [] .slice.call (arguments);
for (var i = 0; i < args.length; i++) {
if (typeof args [i] == 'string') {
args [i] = args [i] .split ('');
}
else if (!Array.isArray (args [i])) {
args [i] = Array.from (args [i]);
}
}
var shortest = args.length == 0 ? [] : args.reduce (
function (array0, array1) {
return array0.length < array1.length ? array0 : array1;
}
);
return shortest.map (
function (current, index) {
return args.map (
function (current) {
return current [index];
}
);