Renamed from Libremsonic to Sublime Music

This commit is contained in:
Sumner Evans
2019-10-19 20:09:11 -06:00
parent c82373aaab
commit 2c2bc9380d
39 changed files with 74 additions and 74 deletions

View File

@@ -0,0 +1,33 @@
"""
Defines the base class for API objects.
"""
from enum import Enum
from typing import Any, Dict
from sublime.from_json import from_json as _from_json
class APIObject:
@classmethod
def from_json(cls, data):
return _from_json(cls, data)
def get(self, field, default=None):
return getattr(self, field, default)
def __repr__(self):
if isinstance(self, Enum):
return super().__repr__()
if isinstance(self, str):
return self
annotations: Dict[str, Any] = self.get('__annotations__', {})
typename = type(self).__name__
fieldstr = ' '.join(
[
f'{field}={getattr(self, field)!r}'
for field in annotations.keys()
if hasattr(self, field) and getattr(self, field) is not None
])
return f'<{typename} {fieldstr}>'