Esempio n. 1
0
 def to_dict(self):
     """See _D2File.to_dict.__doc__."""
     _dict = obj_to_dict(self, exclude=('_reader', ))
     if self.stash:
         _dict['stash'] = [page.copy() for page in self.stash]
         for page in _dict['stash']:
             page['items'] = to_dict_list(page['items'])
     return _dict
Esempio n. 2
0
    def to_dict(self):
        """Dumps self to dictionary.

        :return: A dictionary with excluded private attributes such as _reader.
        :rtype: dict
        """
        item_dict = obj_to_dict(self, exclude=('_reader',))
        if self.socketed_items:
            item_dict['socketed_items'] = to_dict_list(self.socketed_items)
        item_dict['name'] = self.name
        return item_dict
Esempio n. 3
0
    def to_dict(self):
        """See _D2File.to_dict.__doc__."""
        _dict = obj_to_dict(self, exclude=('_reader', '_rbit_reader'))
        _dict['char_class'] = self.char_class
        _dict['is_hardcore'] = self.is_hardcore
        _dict['is_died'] = self.is_died
        _dict['is_expansion'] = self.is_expansion
        _dict['is_ladder'] = self.is_ladder

        if self.items:
            _dict['items'] = to_dict_list(self.items)
        if self.corpse_items:
            _dict['corpse_items'] = to_dict_list(self.corpse_items)
        if self.merc_items:
            _dict['merc_items'] = to_dict_list(self.merc_items)
        if self.golem_item:
            _dict['golem_item'] = self.golem_item.to_dict()

        return _dict
Esempio n. 4
0
def test_obj_to_dict_stash_file(stash_file, exclude):
    stash, _ = stash_file
    stash_dict = obj_to_dict(stash, exclude=exclude)
    assert isinstance(stash_dict, dict)
    assert all(field not in stash_dict for field in exclude)
Esempio n. 5
0
def test_obj_to_dict_d2s_file(d2s_file, exclude):
    d2s, _ = d2s_file
    d2s_dict = obj_to_dict(d2s, exclude=exclude)
    assert isinstance(d2s_dict, dict)
    assert all(field not in d2s_dict for field in exclude)