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 getdict(w_self, space): # returning a dict-proxy! from pypy.objspace.std.dictproxyobject import DictProxyStrategy from pypy.objspace.std.dictmultiobject import W_DictObject if w_self.lazyloaders: w_self._cleanup_() # force un-lazification strategy = space.fromcache(DictProxyStrategy) storage = strategy.erase(w_self) return W_DictObject(space, strategy, storage)
def attach_dict_strategy(space): # this is needed for modules which do e.g. "isinstance(w_obj, # W_DictMultiObject)", like _hpy_universal. Make sure that the # annotator sees a concrete class, like W_DictObject, else lots of # operations are blocked. from pypy.objspace.std.dictmultiobject import W_DictObject, ObjectDictStrategy strategy = ObjectDictStrategy(space) storage = strategy.get_empty_storage() w_obj = W_DictObject(space, strategy, storage)
def from_values_and_jsonmap(space, values_w, jsonmap): if not objectmodel.we_are_translated(): assert len(values_w) == len(jsonmap.get_keys_in_order()) assert len(values_w) != 0 debug.make_sure_not_resized(values_w) strategy = jsonmap.strategy_instance if strategy is None: jsonmap.strategy_instance = strategy = JsonDictStrategy(space, jsonmap) storage = strategy.erase(values_w) return W_DictObject(space, strategy, storage)
def getdict(self, space): w_dict = self._get_mapdict_map().read(self, "dict", SPECIAL) if w_dict is not None: assert isinstance(w_dict, W_DictMultiObject) return w_dict strategy = space.fromcache(MapDictStrategy) storage = strategy.erase(self) w_dict = W_DictObject(space, strategy, storage) flag = self._get_mapdict_map().write(self, "dict", SPECIAL, w_dict) assert flag return w_dict
def get_impl(self): strategy = self.StrategyClass(self.fakespace) storage = strategy.get_empty_storage() w_dict = self.fakespace.allocate_instance(W_DictObject, None) W_DictObject.__init__(w_dict, self.fakespace, strategy, storage) return w_dict
def newdict(self, module=False, instance=False): return W_DictObject.allocate_and_init_instance(self, module=module, instance=instance)
def copy(self, w_dict): storage = self._make_unicode_dict(w_dict) strategy = self.space.fromcache(UnicodeDictStrategy) return W_DictObject(strategy.space, strategy, storage)
def copy(self, w_dict): dstorage = self.unerase(w_dict.dstorage) return W_DictObject(self.space, self, self.get_empty_storage())
def copy(self, w_dict): dstorage = self.unerase(w_dict.dstorage) return W_DictObject(self.space, self, self.erase((dstorage[0][:], dstorage[1][:])))