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
816 lines (700 sloc)
22.6 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])}
399
for(var k in self.$numeric_dict){_count++}
400
for(var k in self.$string_dict){_count++}
401
for(var k in self.$object_dict){_count += self.$object_dict[k].length}
414
$numeric_dict : {},
415
$object_dict : {},
416
$string_dict : {},
417
$str_hash: {}
418
}
419
}
420
438
items.forEach(function(item){
439
if((!self.$jsobj && item[1] === self) ||
440
(self.$jsobj && item[1] === self.$jsobj)){
456
["self", "key", "value"], arguments, {}, null, null)
457
return dict.$setitem($.self, $.key, $.value)
458
}
465
// If class attribute __init__ or __new__ are reset,
466
// the factory function has to change
467
self.$jsobj.$factory = $B.$instance_creator(self.$jsobj)
468
}
469
}else{
477
self.$string_dict[key] = value
478
self.$str_hash[str_hash(key)] = key
479
return $N
487
var _key = hash(key),
488
_eq = function(other){return $B.rich_comp("__eq__", key, other)}
502
// An object with the same hash is already stored
503
// Lookup should fail if equality raises an exception
504
_eq(self.$object_dict[_key][0])
505
}
506
self.$object_dict[_key] = [key, value]
521
self.$numeric_dict = {}
522
self.$string_dict = {}
523
self.$str_hash = {}
524
self.$object_dict = {}
548
var $ = $B.args("fromkeys", 3, {cls: null, keys: null, value: null},
549
["cls", "keys", "value"], arguments, {value: _b_.None}, null, null),
561
if(klass === dict){dict.__setitem__(res, key, value)}
562
else{_b_.getattr(res, "__setitem__")(key, value)}
573
var $ = $B.args("get", 3, {self: null, key: null, _default: null},
574
["self", "key", "_default"], arguments, {_default: $N}, null, null)
577
catch(err){
578
if(_b_.isinstance(err, _b_.KeyError)){return $._default}
579
else{throw err}
580
}
581
}
582
587
var _len = arguments.length - 1,
588
_msg = "items() takes no arguments (" + _len + " given)"
598
var _len = arguments.length - 1,
599
_msg = "keys() takes no arguments (" + _len + " given)"
607
var $ = $B.args("pop", 3, {self: null, key: null, _default: null},
608
["self", "key", "_default"], arguments, {_default: $N}, null, null),
640
var $ = $B.args("setdefault", 3, {self: null, key: null, _default: null},
641
["self", "key", "_default"], arguments, {_default: $N}, null, null),
648
if(_default === undefined){_default = $N}
649
dict.__setitem__(self, key, _default)
656
var $ = $B.args("update", 1, {"self": null}, ["self"], arguments,
657
{}, "args", "kw"),
658
self = $.self,
659
args = $.args,
660
kw = $.kw
661
662
if(args.length > 0){
663
var o = args[0]
664
if(isinstance(o, dict)){
665
if(o.$jsobj){o = jsobj2dict(o)}
666
$copy_dict(self, o)
667
}else if(hasattr(o, "__getitem__") && hasattr(o, "keys")){
668
var _keys = _b_.list.$factory(getattr(o, "keys")()),
685
var _len = arguments.length - 1,
686
_msg = "values() takes no arguments (" + _len + " given)"
688
}
689
return $iterator_wrapper(new $value_iterator(self), $dict_valuesDict)
690
}
691
707
stop = args.length - 1,
708
si = dict.__setitem__
709
while(i++ < stop){
710
var item = args[i]
712
case 'string':
713
res.$string_dict[item[0]] = item[1]
714
res.$str_hash[str_hash(item[0])] = item[0]
715
break
716
case 'number':
717
res.$numeric_dict[item[0]] = item[1]
718
break
719
default:
720
si(res, item[0], item[1])
721
break
731
res.$string_dict[attr] = kw[attr]
732
res.$str_hash[str_hash(attr)] = attr
733
break
735
res.$numeric_dict[attr] = kw[attr]
736
break
737
default:
738
si(res, attr, kw[attr])
739
break
743
}else if(args.$jsobj){
744
res.$jsobj = {}
745
for(var attr in args.$jsobj){res.$jsobj[attr] = args.$jsobj[attr]}
746
return res
759
// This must be done after set_func_names, otherwise dict.fromkeys doesn't
760
// have the attribute $infos
761
dict.fromkeys = _b_.classmethod.$factory(dict.fromkeys)
762
765
$B.$dict_length = dict.__len__
766
$B.$dict_getitem = dict.__getitem__
767
$B.$dict_get = dict.get
768
$B.$dict_set = dict.__setitem__
769
$B.$dict_contains = dict.__contains__
770
$B.$dict_items = function(d) { return new $item_generator(d).as_list() }
771
$B.$copy_dict = $copy_dict // copy from right to left
776
var mappingproxy = $B.make_class("mappingproxy",
777
function(obj){
778
var res = obj_dict(obj)
779
res.__class__ = mappingproxy
780
return res
781
}
782
)
785
throw _b_.TypeError.$factory("'mappingproxy' object does not support " +
786
"item assignment")
808
if(klass !== undefined && klass.$native){
809
throw _b_.AttributeError.$factory(klass.__name__ +