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() ]
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() ]
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))
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() ]
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)
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)
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)
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)
def values(self, w_dict): return [ unwrap_cell(self.space, w_value) for w_value in self.unerase(w_dict.dstorage).dict_w.itervalues() ]
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)
def wrapvalue(space, value): return unwrap_cell(space, value)
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)
def values(self, w_dict): iterator = self.unerase(w_dict.dstorage).itervalues return [unwrap_cell(self.space, cell) for cell in iterator()]
def getitem_str(self, w_dict, key): cell = self.getdictvalue_no_unwrapping(w_dict, key) return unwrap_cell(self.space, cell)
def getvalue(self, space): return unwrap_cell(space, self.cell)