Pastebin
Paste #2003: py2js
< previous paste - next paste>
Pasted by chrivers
/* Python 'str' type */
var str = __inherit(object);
str.__name__ = 'str';
str.prototype.__class__ = str;
str.prototype.MARK = "str";
str.prototype.__init__ = function(s) {
if (!defined(s)) {
this._obj = '';
} else {
if (typeof(s) === "string") {
this._obj = s;
} else if (defined(s.toString)) {
this._obj = s.toString();
} else if (defined(s.__str__)) {
this._obj = js(s.__str__());
} else
this._obj = js(s);
}
};
...
/* Python 'iter' type */
var iter = __inherit(object);
iter.prototype.MARK = "iter";
iter.prototype.__init__ = function(obj) {
this._index = 0;
if (obj instanceof Array) {
this._seq = obj;
} else if (typeof(obj) === "string") {
this._seq = obj.split("");
} else if (obj.__class__ == iter) {
this._seq = obj._seq;
} else if (defined(obj.__iter__)) {
this._seq = obj.__iter__()._seq;
} else {
throw new py_builtins.TypeError("object is not iterable");
}
}
...
/* Python 'list' type */
var list = __inherit(object);
list.__name__ = 'list';
list.prototype.__class__ = list;
list.prototype.MARK = "iter";
list.prototype.__init__ = function(seq) {
// print("LIST INIT", seq);
if (!defined(seq)) {
this._items = [];
this._len = 0;
} else {
this._items = copy(iter.__call__(seq));
// print(" items", this._items);
this._len = -1;
}
};
New Paste
Go to most recent paste.