Permalink
Feb 26, 2018
Feb 3, 2018
Feb 3, 2018
Jan 15, 2018
Feb 26, 2018
Feb 26, 2018
Feb 26, 2018
May 29, 2017
Feb 26, 2018
Mar 7, 2018
Mar 7, 2018
Nov 21, 2015
Mar 7, 2018
Feb 26, 2018
Feb 26, 2018
Mar 7, 2018
Feb 26, 2018
Feb 26, 2018
Feb 26, 2018
Mar 7, 2018
Feb 26, 2018
Feb 26, 2018
Feb 26, 2018
May 28, 2016
Feb 26, 2018
Feb 26, 2018
Feb 26, 2018
Feb 26, 2018
Mar 7, 2018
Feb 26, 2018
Mar 23, 2018
Feb 9, 2018
Feb 26, 2018
May 27, 2018
Feb 3, 2018
Feb 26, 2018
Feb 26, 2018
May 28, 2016
Feb 26, 2018
Mar 7, 2018
Feb 26, 2018
Mar 7, 2018
Nov 9, 2015
Feb 26, 2018
Feb 26, 2018
Mar 7, 2018
Mar 7, 2018
Feb 26, 2018
Mar 7, 2018
Feb 26, 2018
Mar 7, 2018
Feb 26, 2018
Nov 21, 2015
Feb 26, 2018
Mar 7, 2018
Feb 26, 2018
Feb 26, 2018
Feb 3, 2018
Jun 28, 2018
Feb 11, 2018
Feb 12, 2018
Mar 7, 2018
Feb 26, 2018
Newer
100644
822 lines (706 sloc)
22.8 KB
16
var setitem = dict.__setitem__,
17
i = $keys.length
18
while(i--){setitem($keys[i], $values[i])}
30
var $key_iterator = function(d) {
31
this.d = d
32
this.current = 0
33
this.iter = new $item_generator(d)
34
}
35
$key_iterator.prototype.length = function(){return this.iter.items.length}
36
$key_iterator.prototype.next = function(){return this.iter.next()[0]}
37
38
var $value_iterator = function(d) {
39
this.d = d
40
this.current = 0
41
this.iter = new $item_generator(d)
42
}
43
$value_iterator.prototype.length = function(){return this.iter.items.length}
44
$value_iterator.prototype.next = function(){return this.iter.next()[1]}
55
if(val === undefined){val = _b_.NotImplemented}
56
else if(val === null){val = $N}
57
this.items.push([attr, val])
63
var items = []
64
for(var k in d.$numeric_dict){
65
items.push([parseFloat(k), d.$numeric_dict[k]])
83
}
84
85
var $item_iterator = function(d) {
86
this.d = d
87
this.current = 0
88
this.iter = new $item_generator(d)
89
}
90
$item_iterator.prototype.length = function(){return this.iter.items.length}
91
$item_iterator.prototype.next = function(){
92
return _b_.tuple.$factory(this.iter.next())
93
}
95
var $copy_dict = function(left, right){
96
var _l = new $item_generator(right).as_list(),
97
si = dict.__setitem__,
98
i = _l.length
99
while(i--){si(left, _l[i][0], _l[i][1])}
102
function toSet(items){
103
// Build a set from the iteration on items
104
var res = []
105
while(true){
106
try{res.push(items.next())}
107
catch(err){break}
108
}
119
__iter__: function(){items.iter.i = 0; return res},
120
__len__: function(){return items.length()},
121
__next__: function(){
144
var $ = $B.args("__contains__", 2, {self: null, item: null},
145
["self", "item"], arguments, {}, null, null),
152
case "string":
153
return self.$string_dict[item] !== undefined
154
case "number":
155
return self.$numeric_dict[item] !== undefined
164
// If the key is an object, its hash must be in the dict keys but the
165
// key itself must compare equal to the key associated with the hash
166
// For instance :
167
//
168
// class X:
169
// def __hash__(self): return hash('u')
181
var $ = $B.args("__eq__", 2, {self: null, arg: null},
182
["self", "arg"], arguments, {}, null, null),
193
if(self.$string_dict[arg] === undefined){
194
throw KeyError.$factory(_b_.str.$factory(arg))
195
}
196
delete self.$string_dict[arg]
197
delete self.$str_hash[str_hash(arg)]
198
return $N
200
if(self.$numeric_dict[arg] === undefined){
201
throw KeyError.$factory(_b_.str.$factory(arg))
202
}
203
delete self.$numeric_dict[arg]
204
return $N
219
var $ = $B.args("__eq__", 2, {self: null, other: null},
220
["self", "other"], arguments, {}, null, null),
226
if(self.$jsobj){self = jsobj2dict(self.$jsobj)}
227
if(other.$jsobj){other = jsobj2dict(other.$jsobj)}
231
if((self.$numeric_dict.length != other.$numeric_dict.length) ||
232
(self.$string_dict.length != other.$string_dict.length) ||
233
(self.$object_dict.length != other.$object_dict.length)){
234
return false
249
if(!$B.rich_comp("__eq__", other.$object_dict[k][1],
250
self.$object_dict[k][1])){
260
var $ = $B.args("__getitem__", 2, {self: null, arg: null},
261
["self", "arg"], arguments, {}, null, null),
266
if(!self.$jsobj.hasOwnProperty(arg)){
267
throw _b_.KeyError.$factory(str.$factory(arg))
268
}else if(self.$jsobj[arg] === undefined){
269
return _b_.NotImplemented
270
}else if(self.$jsobj[arg] === null){return $N}
277
if(self.$string_dict[arg] !== undefined){
278
return self.$string_dict[arg]
279
}
280
break
282
if(self.$numeric_dict[arg] !== undefined){
283
return self.$numeric_dict[arg]
284
}
303
// An object with the same hash is already stored
304
// Lookup should fail if equality raises an exception
305
_eq(self.$object_dict[_key][0])
320
var args = []
321
for(var i = 1; i < arguments.length; i++){args.push(arguments[i])}
322
323
switch(args.length){
324
case 0:
325
return
326
case 1:
327
var obj = args[0]
328
if(Array.isArray(obj)){
329
var i = obj.length,
330
si = dict.__setitem__
332
return $N
333
}else if(obj.$nat === undefined && isinstance(obj, dict)){
334
$copy_dict(self, obj)
335
return $N
336
}
338
if(obj.__class__ === $B.JSObject){
339
// convert a JSObject into a Python dictionary
341
// Attribute $jsobj is used to update the original JS object
342
// when the dictionary is modified
343
self.$jsobj = obj.js
344
return $N
345
}
346
}
348
var $ns = $B.args("dict", 0, {}, [], args, {}, "args", "kw"),
349
args = $ns["args"],
350
kw = $ns["kw"]
361
var src = args[0],
362
i = src.length - 1,
363
si = dict.__setitem__
364
while(i-- > 0){si(self, src[i - 1][0], src[i - 1][1])}
401
for(var k in self.$numeric_dict){_count++}
402
for(var k in self.$string_dict){_count++}
403
for(var k in self.$object_dict){_count += self.$object_dict[k].length}
416
$numeric_dict : {},
417
$object_dict : {},
418
$string_dict : {},
419
$str_hash: {}
420
}
421
}
422
440
items.forEach(function(item){
441
if((!self.$jsobj && item[1] === self) ||
442
(self.$jsobj && item[1] === self.$jsobj)){
458
["self", "key", "value"], arguments, {}, null, null)
459
return dict.$setitem($.self, $.key, $.value)
460
}
467
// If class attribute __init__ or __new__ are reset,
468
// the factory function has to change
469
self.$jsobj.$factory = $B.$instance_creator(self.$jsobj)
470
}
471
}else{
479
self.$string_dict[key] = value
480
self.$str_hash[str_hash(key)] = key
481
return $N
489
var _key = hash(key),
490
_eq = function(other){return $B.rich_comp("__eq__", key, other)}
504
// An object with the same hash is already stored
505
// Lookup should fail if equality raises an exception
506
_eq(self.$object_dict[_key][0])
507
}
508
self.$object_dict[_key] = [key, value]
523
self.$numeric_dict = {}
524
self.$string_dict = {}
525
self.$str_hash = {}
526
self.$object_dict = {}
550
var $ = $B.args("fromkeys", 3, {cls: null, keys: null, value: null},
551
["cls", "keys", "value"], arguments, {value: _b_.None}, null, null),
564
if(klass === dict){dict.__setitem__(res, key, value)}
565
else{_b_.getattr(res, "__setitem__")(key, value)}
577
var $ = $B.args("get", 3, {self: null, key: null, _default: null},
578
["self", "key", "_default"], arguments, {_default: $N}, null, null)
581
catch(err){
582
if(_b_.isinstance(err, _b_.KeyError)){return $._default}
583
else{throw err}
584
}
585
}
586
591
var _len = arguments.length - 1,
592
_msg = "items() takes no arguments (" + _len + " given)"
602
var _len = arguments.length - 1,
603
_msg = "keys() takes no arguments (" + _len + " given)"
611
var $ = $B.args("pop", 3, {self: null, key: null, _default: null},
612
["self", "key", "_default"], arguments, {_default: $N}, null, null),
646
var $ = $B.args("setdefault", 3, {self: null, key: null, _default: null},
647
["self", "key", "_default"], arguments, {_default: $N}, null, null),
654
if(_default === undefined){_default = $N}
655
dict.__setitem__(self, key, _default)
662
var $ = $B.args("update", 1, {"self": null}, ["self"], arguments,
663
{}, "args", "kw"),
664
self = $.self,
665
args = $.args,
666
kw = $.kw
667
668
if(args.length > 0){
669
var o = args[0]
670
if(isinstance(o, dict)){
671
if(o.$jsobj){o = jsobj2dict(o)}
672
$copy_dict(self, o)
673
}else if(hasattr(o, "__getitem__") && hasattr(o, "keys")){
674
var _keys = _b_.list.$factory(getattr(o, "keys")()),
691
var _len = arguments.length - 1,
692
_msg = "values() takes no arguments (" + _len + " given)"
694
}
695
return $iterator_wrapper(new $value_iterator(self), $dict_valuesDict)
696
}
697
713
stop = args.length - 1,
714
si = dict.__setitem__
715
while(i++ < stop){
716
var item = args[i]
718
case 'string':
719
res.$string_dict[item[0]] = item[1]
720
res.$str_hash[str_hash(item[0])] = item[0]
721
break
722
case 'number':
723
res.$numeric_dict[item[0]] = item[1]
724
break
725
default:
726
si(res, item[0], item[1])
727
break
737
res.$string_dict[attr] = kw[attr]
738
res.$str_hash[str_hash(attr)] = attr
739
break
741
res.$numeric_dict[attr] = kw[attr]
742
break
743
default:
744
si(res, attr, kw[attr])
745
break
749
}else if(args.$jsobj){
750
res.$jsobj = {}
751
for(var attr in args.$jsobj){res.$jsobj[attr] = args.$jsobj[attr]}
752
return res
765
// This must be done after set_func_names, otherwise dict.fromkeys doesn't
766
// have the attribute $infos
767
dict.fromkeys = _b_.classmethod.$factory(dict.fromkeys)
768
771
$B.$dict_length = dict.__len__
772
$B.$dict_getitem = dict.__getitem__
773
$B.$dict_get = dict.get
774
$B.$dict_set = dict.__setitem__
775
$B.$dict_contains = dict.__contains__
776
$B.$dict_items = function(d) { return new $item_generator(d).as_list() }
777
$B.$copy_dict = $copy_dict // copy from right to left
782
var mappingproxy = $B.make_class("mappingproxy",
783
function(obj){
784
var res = obj_dict(obj)
785
res.__class__ = mappingproxy
786
return res
787
}
788
)
791
throw _b_.TypeError.$factory("'mappingproxy' object does not support " +
792
"item assignment")
814
if(klass !== undefined && klass.$native){
815
throw _b_.AttributeError.$factory(klass.__name__ +