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
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
Mar 7, 2018
Feb 26, 2018
Feb 26, 2018
Feb 9, 2018
Feb 26, 2018
Mar 7, 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
Feb 11, 2018
Feb 12, 2018
Mar 7, 2018
Feb 26, 2018
Newer
100644
816 lines (701 sloc)
22.6 KB
15
var setitem = dict.__setitem__,
16
i = $keys.length
17
while(i--){setitem($keys[i], $values[i])}
29
var $key_iterator = function(d) {
30
this.d = d
31
this.current = 0
32
this.iter = new $item_generator(d)
33
}
34
$key_iterator.prototype.length = function(){return this.iter.items.length}
35
$key_iterator.prototype.next = function(){return this.iter.next()[0]}
36
37
var $value_iterator = function(d) {
38
this.d = d
39
this.current = 0
40
this.iter = new $item_generator(d)
41
}
42
$value_iterator.prototype.length = function(){return this.iter.items.length}
43
$value_iterator.prototype.next = function(){return this.iter.next()[1]}
54
if(val === undefined){val = _b_.NotImplemented}
55
else if(val === null){val = $N}
56
this.items.push([attr, val])
62
var items = []
63
for(var k in d.$numeric_dict){
64
items.push([parseFloat(k), d.$numeric_dict[k]])
82
}
83
84
var $item_iterator = function(d) {
85
this.d = d
86
this.current = 0
87
this.iter = new $item_generator(d)
88
}
89
$item_iterator.prototype.length = function(){return this.iter.items.length}
90
$item_iterator.prototype.next = function(){
91
return _b_.tuple.$factory(this.iter.next())
92
}
94
var $copy_dict = function(left, right){
95
var _l = new $item_generator(right).as_list(),
96
si = dict.__setitem__,
97
i = _l.length
98
while(i--){si(left, _l[i][0], _l[i][1])}
101
function toSet(items){
102
// Build a set from the iteration on items
103
var res = []
104
while(true){
105
try{res.push(items.next())}
106
catch(err){break}
107
}
118
__iter__: function(){items.iter.i = 0; return res},
119
__len__: function(){return items.length()},
120
__next__: function(){
143
var $ = $B.args("__contains__", 2, {self: null, item: null},
144
["self", "item"], arguments, {}, null, null),
151
case "string":
152
return self.$string_dict[item] !== undefined
153
case "number":
154
return self.$numeric_dict[item] !== undefined
163
// If the key is an object, its hash must be in the dict keys but the
164
// key itself must compare equal to the key associated with the hash
165
// For instance :
166
//
167
// class X:
168
// def __hash__(self): return hash('u')
170
// a = {'u': 'a', X(): 'b'}
171
// assert set(a.values())=={'a', 'b'}
172
// assert not X() in a
180
var $ = $B.args("__eq__", 2, {self: null, arg: null},
181
["self", "arg"], arguments, {}, null, null),
192
if(self.$string_dict[arg] === undefined){
193
throw KeyError.$factory(_b_.str.$factory(arg))
194
}
195
delete self.$string_dict[arg]
196
delete self.$str_hash[str_hash(arg)]
197
return $N
199
if(self.$numeric_dict[arg] === undefined){
200
throw KeyError.$factory(_b_.str.$factory(arg))
201
}
202
delete self.$numeric_dict[arg]
203
return $N
218
var $ = $B.args("__eq__", 2, {self: null, other: null},
219
["self", "other"], arguments, {}, null, null),
225
if(self.$jsobj){self = jsobj2dict(self.$jsobj)}
226
if(other.$jsobj){other = jsobj2dict(other.$jsobj)}
230
if((self.$numeric_dict.length != other.$numeric_dict.length) ||
231
(self.$string_dict.length != other.$string_dict.length) ||
232
(self.$object_dict.length != other.$object_dict.length)){
233
return false
248
if(!$B.rich_comp("__eq__", other.$object_dict[k][1],
249
self.$object_dict[k][1])){
259
var $ = $B.args("__getitem__", 2, {self: null, arg: null},
260
["self", "arg"], arguments, {}, null, null),
265
if(!self.$jsobj.hasOwnProperty(arg)){
266
throw _b_.KeyError.$factory(str.$factory(arg))
267
}else if(self.$jsobj[arg] === undefined){
268
return _b_.NotImplemented
269
}else if(self.$jsobj[arg] === null){return $N}
276
if(self.$string_dict[arg] !== undefined){
277
return self.$string_dict[arg]
278
}
279
break
281
if(self.$numeric_dict[arg] !== undefined){
282
return self.$numeric_dict[arg]
283
}
302
// An object with the same hash is already stored
303
// Lookup should fail if equality raises an exception
304
_eq(self.$object_dict[_key][0])
319
var args = []
320
for(var i = 1; i < arguments.length; i++){args.push(arguments[i])}
321
322
switch(args.length){
323
case 0:
324
return
325
case 1:
326
var obj = args[0]
327
if(Array.isArray(obj)){
328
var i = obj.length,
329
si = dict.__setitem__
330
while(i-- > 0){si(self, obj[i-1][0], obj[i-1][1])}
331
return $N
332
}else if(obj.$nat === undefined && isinstance(obj, dict)){
333
$copy_dict(self, obj)
334
return $N
335
}
337
if(obj.__class__ === $B.JSObject){
338
// convert a JSObject into a Python dictionary
340
// Attribute $jsobj is used to update the original JS object
341
// when the dictionary is modified
342
self.$jsobj = obj.js
343
return $N
344
}
345
}
347
var $ns = $B.args("dict", 0, {}, [], args, {}, "args", "kw"),
348
args = $ns["args"],
349
kw = $ns["kw"]
360
var src = args[0],
361
i = src.length - 1,
362
si = dict.__setitem__
363
while(i-- > 0){si(self, src[i - 1][0], src[i - 1][1])}
400
for (var k in self.$numeric_dict){_count++}
401
for (var k in self.$string_dict){_count++}
415
$numeric_dict : {},
416
$object_dict : {},
417
$string_dict : {},
418
$str_hash: {}
419
}
420
}
421
439
items.forEach(function(item){
440
if((!self.$jsobj && item[1] === self) ||
441
(self.$jsobj && item[1] === self.$jsobj)){
456
var $ = $B.args("__setitem__", 3, {self: null, key: null, value: null},
457
["self", "key", "value"], arguments, {}, null, null),
464
self.$jsobj[key] = $B.pyobj2jsobj(value)
465
if(key=="__init__" || key=="__new__"){
466
// If class attribute __init__ or __new__ are reset,
467
// the factory function has to change
468
self.$jsobj.$factory = $B.$instance_creator(self.$jsobj)
469
}
470
}else{
478
self.$string_dict[key] = value
479
self.$str_hash[str_hash(key)] = key
480
return $N
488
var _key = hash(key),
489
_eq = function(other){return $B.rich_comp("__eq__", key, other)}
503
// An object with the same hash is already stored
504
// Lookup should fail if equality raises an exception
505
_eq(self.$object_dict[_key][0])
506
}
507
self.$object_dict[_key] = [key, value]
522
self.$numeric_dict = {}
523
self.$string_dict = {}
524
self.$str_hash = {}
525
self.$object_dict = {}
549
var $ = $B.args("fromkeys", 3, {cls: null, keys: null, value: null},
550
["cls", "keys", "value"], arguments, {value: _b_.None}, null, null),
563
if(klass === dict){dict.__setitem__(res, key, value)}
564
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
767
$B.$dict_length = dict.__len__
768
$B.$dict_getitem = dict.__getitem__
769
$B.$dict_get = dict.get
770
$B.$dict_set = dict.__setitem__
771
$B.$dict_contains = dict.__contains__
772
$B.$dict_items = function(d) { return new $item_generator(d).as_list() }
773
$B.$copy_dict = $copy_dict // copy from right to left
778
var mappingproxy = $B.make_class("mappingproxy",
779
function(obj){
780
var res = obj_dict(obj)
781
res.__class__ = mappingproxy
782
return res
783
}
784
)
787
throw _b_.TypeError.$factory("'mappingproxy' object does not support " +
788
"item assignment")
808
if(klass !== undefined && klass.$native){
809
throw _b_.AttributeError.$factory(klass.__name__ +