2019-05-07 06:02:21 +09:00
|
|
|
import json
|
|
|
|
|
|
|
|
from abc import ABCMeta
|
|
|
|
|
|
|
|
|
2019-08-18 18:54:13 +09:00
|
|
|
class YandexMusicObject:
|
2019-05-07 06:02:21 +09:00
|
|
|
__metaclass__ = ABCMeta
|
|
|
|
_id_attrs = ()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.to_dict())
|
|
|
|
|
2019-05-15 05:38:15 +09:00
|
|
|
def __repr__(self):
|
|
|
|
return str(self)
|
|
|
|
|
2019-05-07 06:02:21 +09:00
|
|
|
def __getitem__(self, item):
|
|
|
|
return self.__dict__[item]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def de_json(cls, data, client):
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
data = data.copy()
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
def to_json(self):
|
|
|
|
return json.dumps(self.to_dict())
|
|
|
|
|
|
|
|
def to_dict(self):
|
|
|
|
data = dict()
|
Добавлены основные тесты для следующих классов: Album, Artist, Chart, Counts, Genre, Label, PermissionAlerts, PromoCodeStatus, Restrictions, Settings, Station, StatuonResult, Status, Track.
Исправлены фикстуры и сравнения для вышеперечисленных классов.
Отрефакторен restrictions.py.
Исправлен баг в .to_dict() методе, связанный с десериализцией объектов списков и словарей.
2019-11-09 00:24:54 +09:00
|
|
|
|
|
|
|
def _handle_value(val):
|
|
|
|
return val.to_dict() if hasattr(val, 'to_dict') else val
|
|
|
|
|
2019-05-07 06:02:21 +09:00
|
|
|
for key, value in self.__dict__.items():
|
|
|
|
if key in ('client',
|
|
|
|
'_id_attrs'):
|
|
|
|
continue
|
|
|
|
|
Добавлены основные тесты для следующих классов: Album, Artist, Chart, Counts, Genre, Label, PermissionAlerts, PromoCodeStatus, Restrictions, Settings, Station, StatuonResult, Status, Track.
Исправлены фикстуры и сравнения для вышеперечисленных классов.
Отрефакторен restrictions.py.
Исправлен баг в .to_dict() методе, связанный с десериализцией объектов списков и словарей.
2019-11-09 00:24:54 +09:00
|
|
|
data[key] = _handle_value(value)
|
|
|
|
if isinstance(value, list):
|
|
|
|
data[key] = [_handle_value(item) for item in value]
|
|
|
|
if isinstance(value, dict):
|
|
|
|
data[key] = {k: _handle_value(v) for k, v in value.items()}
|
2019-05-07 06:02:21 +09:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
if isinstance(other, self.__class__):
|
|
|
|
return self._id_attrs == other._id_attrs
|
|
|
|
return super(YandexMusicObject, self).__eq__(other)
|
|
|
|
|
|
|
|
def __hash__(self):
|
|
|
|
if self._id_attrs:
|
|
|
|
return hash((self.__class__, self._id_attrs))
|
|
|
|
return super(YandexMusicObject, self).__hash__()
|