diff options
Diffstat (limited to 'vk/user.py')
-rw-r--r-- | vk/user.py | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -9,31 +9,33 @@ from enum import Enum from .last_seen import LastSeen + def _parse_last_seen(x): if isinstance(x, LastSeen): return x - elif isinstance(x, Mapping): + if isinstance(x, Mapping): return LastSeen.from_api_response(x) - else: - raise TypeError() + raise TypeError() + def _parse_bool(x): if isinstance(x, str): if str(True) == x: return True - elif str(False) == x: + if str(False) == x: return False - else: - raise ValueError() - else: - return bool(x) + raise ValueError() + return bool(x) + def _parse_hidden(x): return _parse_bool(x) + def _parse_online_flag(x): return _parse_bool(x) + class UserField(Enum): UID = 'id' FIRST_NAME = 'first_name' @@ -48,6 +50,7 @@ class UserField(Enum): def __str__(self): return self.value + class DeactivationReason(Enum): DELETED = 'deleted' BANNED = 'banned' @@ -55,9 +58,11 @@ class DeactivationReason(Enum): def __str__(self): return self.value + def _parse_deactivated(s): return DeactivationReason(s) + class User(Hashable, MutableMapping): @staticmethod def from_api_response(source): |