示例#1
0
 def items(self, w_dict):
     space = self.space
     w_type = self.unerase(w_dict.dstorage)
     return [
         space.newtuple([_wrapkey(space, key),
                         unwrap_cell(space, w_value)])
         for (key, w_value) in w_type.dict_w.iteritems()
     ]
示例#2
0
 def items(self, w_dict):
     space = self.space
     return [
         space.newtuple([space.wrap(key),
                         unwrap_cell(self.space, w_value)])
         for (key,
              w_value) in self.unerase(w_dict.dstorage).dict_w.iteritems()
     ]
示例#3
0
文件: celldict.py 项目: Mu-L/pypy
    def copy(self, w_dict):
        strategy = self.space.fromcache(BytesDictStrategy)
        str_dict = strategy.unerase(strategy.get_empty_storage())

        d = self.unerase(w_dict.dstorage)
        for key, cell in d.iteritems():
            str_dict[key] = unwrap_cell(self.space, cell)
        return W_DictObject(strategy.space, strategy, strategy.erase(str_dict))
示例#4
0
 def items(self, w_dict):
     space = self.space
     iterator = self.unerase(w_dict.dstorage).iteritems
     return [
         space.newtuple(
             [_wrapkey(space, key),
              unwrap_cell(self.space, cell)]) for key, cell in iterator()
     ]
示例#5
0
文件: celldict.py 项目: zcxowwww/pypy
 def switch_to_object_strategy(self, w_dict):
     space = self.space
     d = self.unerase(w_dict.dstorage)
     strategy = space.fromcache(ObjectDictStrategy)
     d_new = strategy.unerase(strategy.get_empty_storage())
     for key, cell in d.iteritems():
         d_new[_wrapkey(space, key)] = unwrap_cell(self.space, cell)
     w_dict.set_strategy(strategy)
     w_dict.dstorage = strategy.erase(d_new)
示例#6
0
文件: celldict.py 项目: zcxowwww/pypy
 def setdefault(self, w_dict, w_key, w_default):
     space = self.space
     if space.is_w(space.type(w_key), space.w_text):
         key = space.text_w(w_key)
         cell = self.getdictvalue_no_unwrapping(w_dict, key)
         w_result = unwrap_cell(self.space, cell)
         if w_result is not None:
             return w_result
         self._setitem_str_cell_known(cell, w_dict, key, w_default)
         return w_default
     else:
         self.switch_to_object_strategy(w_dict)
         return w_dict.setdefault(w_key, w_default)
示例#7
0
 def setdefault(self, w_dict, w_key, w_default):
     space = self.space
     key = self.try_unwrap_key(space, w_key)
     if key is not None:
         cell = self.getdictvalue_no_unwrapping(w_dict, key)
         w_result = unwrap_cell(self.space, cell)
         if w_result is not None:
             return w_result
         self._setitem_str_cell_known(cell, w_dict, key, w_default)
         return w_default
     else:
         self.switch_to_object_strategy(w_dict)
         return w_dict.setdefault(w_key, w_default)
示例#8
0
文件: celldict.py 项目: Mu-L/pypy
 def switch_to_object_strategy(self, w_dict):
     space = self.space
     d = self.unerase(w_dict.dstorage)
     strategy = space.fromcache(ObjectDictStrategy)
     d_new = strategy.unerase(strategy.get_empty_storage())
     for key, cell in d.iteritems():
         d_new[_wrapkey(space, key)] = unwrap_cell(self.space, cell)
     if self.caches is not None:
         for cache in self.caches.itervalues():
             cache.cell = None
             cache.valid = False
         self.caches = None
     w_dict.set_strategy(strategy)
     w_dict.dstorage = strategy.erase(d_new)
示例#9
0
 def values(self, w_dict):
     return [
         unwrap_cell(self.space, w_value)
         for w_value in self.unerase(w_dict.dstorage).dict_w.itervalues()
     ]
示例#10
0
 def next_entry(self):
     for key, w_value in self.iterator:
         return (self.space.wrap(key), unwrap_cell(self.space, w_value))
     else:
         return (None, None)
示例#11
0
文件: celldict.py 项目: zcxowwww/pypy
 def wrapvalue(space, value):
     return unwrap_cell(space, value)
示例#12
0
文件: celldict.py 项目: zcxowwww/pypy
 def popitem(self, w_dict):
     space = self.space
     d = self.unerase(w_dict.dstorage)
     key, cell = d.popitem()
     self.mutated()
     return _wrapkey(space, key), unwrap_cell(self.space, cell)
示例#13
0
文件: celldict.py 项目: zcxowwww/pypy
 def values(self, w_dict):
     iterator = self.unerase(w_dict.dstorage).itervalues
     return [unwrap_cell(self.space, cell) for cell in iterator()]
示例#14
0
文件: celldict.py 项目: zcxowwww/pypy
 def getitem_str(self, w_dict, key):
     cell = self.getdictvalue_no_unwrapping(w_dict, key)
     return unwrap_cell(self.space, cell)
示例#15
0
文件: celldict.py 项目: Mu-L/pypy
 def getvalue(self, space):
     return unwrap_cell(space, self.cell)