CodePlayground/lib/brython_stdlib.min.js

8 lines
3.8 MiB
JavaScript
Raw Normal View History

2021-04-02 22:04:53 +02:00
/**
* Minified by jsDelivr using Terser v5.3.5.
* Original file: /npm/brython@3.9.1/brython_stdlib.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
__BRYTHON__.use_VFS=!0;var scripts={$timestamp:1609776975559,array:[".js",'var $module = (function($B){\n\nvar _b_ = $B.builtins,\n $s = [],\n i\nfor(var $b in _b_){$s.push(\'var \' + $b +\' = _b_["\'+$b+\'"]\')}\neval($s.join(\';\'))\n\nvar typecodes = {\n \'b\': Int8Array, // signed char, 1 byte\n \'B\': Uint8Array, // unsigned char, 1\n \'u\': null, // Py_UNICODE Unicode character, 2 (deprecated)\n \'h\': Int16Array, // signed short, 2\n \'H\': Uint16Array, // unsigned short, 2\n \'i\': Int16Array, // signed int, 2\n \'I\': Uint16Array, // unsigned int, 2\n \'l\': Int32Array, // signed long, 4\n \'L\': Uint32Array, // unsigned long, 4\n \'q\': null, // signed long, 8 (not implemented)\n \'Q\': null, // unsigned long, 8 (not implemented)\n \'f\': Float32Array, // float, 4\n \'d\': Float64Array // double float, 8\n}\n\nvar array = $B.make_class("array",\n function(){\n var missing = {},\n $ = $B.args("array", 2, {typecode: null, initializer: null},\n ["typecode", "initializer"], arguments, {initializer: missing},\n null, null),\n typecode = $.typecode,\n initializer = $.initializer\n if(! typecodes.hasOwnProperty(typecode)){\n throw _b_.ValueError.$factory("bad typecode (must be b, " +\n "B, u, h, H, i, I, l, L, q, Q, f or d)")\n }\n if(typecodes[typecode] === null){\n throw _b_.NotImplementedError.$factory("type code " +\n typecode + "is not implemented")\n }\n var res = {\n __class__: array,\n typecode: typecode,\n obj: null\n }\n if(initializer !== missing){\n if(Array.isArray(initializer)){\n array.fromlist(res, initializer)\n }else if(_b_.isinstance(initializer, _b_.bytes)){\n array.frombytes(res, initializer)\n }else{\n array.extend(res, initializer)\n }\n }\n return res\n }\n)\n\narray.$buffer_protocol = true\n\narray.__getitem__ = function(self, key){\n if(self.obj && self.obj[key] !== undefined){\n return self.obj[key]\n }\n throw _b_.IndexError("array index out of range")\n}\n\nvar array_iterator = $B.make_iterator_class("array_iterator")\narray.__iter__ = function(self){\n return array_iterator.$factory(self.obj)\n}\n\narray.__len__ = function(self){\n return self.obj.length\n}\n\narray.__str__ = function(self){\n $B.args("__str__", 1, {self: null},\n ["self"], arguments, {}, null, null)\n var res = "array(\'" + self.typecode + "\'"\n if(self.obj !== null){\n res += ", [" + self.obj + "]"\n }\n return res + ")"\n}\n\nfunction normalize_index(self, i){\n // return an index i between 0 and self.obj.length - 1\n if(i < 0){\n i = self.obj.length + i\n }\n if(i < 0){i = 0}\n else if(i > self.obj.length - 1){\n i = self.obj.length\n }\n return i\n}\n\narray.append = function(self, value){\n $B.args("append", 2, {self: null, value: null},\n ["self", "value"], arguments, {}, null, null)\n var pos = self.obj === null ? 0 : self.obj.length\n return array.insert(self, pos, value)\n}\n\narray.count = function(self, x){\n $B.args("count", 2, {self: null, x: null},\n ["self", "x"], arguments, {}, null, null)\n if(self.obj === null){return 0}\n return self.obj.filter(function(item){return item == x}).length\n}\n\narray.extend = function(self, iterable){\n $B.args("extend", 2, {self: null, iterable: null},\n ["self", "iterable"], arguments, {}, null, null)\n if(iterable.__class__ === array){\n if(iterable.typecode !== self.typecode){\n throw _b_.TypeError.$factory("can only extend with array " +\n "of same kind")\n }\n if(iterable.obj === null){return _b_.None}\n // create new object with length = sum of lengths\n var newobj = new typecodes[self
//# sourceMappingURL=/sm/adc660a4e2ba8ac7f2dec3855607caec4cc097d0edc6d70e5eb16db13d5b4aec.map