Beispiel #1
0
    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))
Beispiel #2
0
 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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
    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
Beispiel #6
0
 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
Beispiel #7
0
 def newdict(self, module=False, instance=False):
     return W_DictObject.allocate_and_init_instance(self,
                                                    module=module,
                                                    instance=instance)
Beispiel #8
0
 def copy(self, w_dict):
     storage = self._make_unicode_dict(w_dict)
     strategy = self.space.fromcache(UnicodeDictStrategy)
     return W_DictObject(strategy.space, strategy, storage)
Beispiel #9
0
 def copy(self, w_dict):
     dstorage = self.unerase(w_dict.dstorage)
     return W_DictObject(self.space, self, self.get_empty_storage())
Beispiel #10
0
 def copy(self, w_dict):
     dstorage = self.unerase(w_dict.dstorage)
     return W_DictObject(self.space, self,
             self.erase((dstorage[0][:], dstorage[1][:])))