From bafa7d23b78a678961e791fe84bf3c8338ee15ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Tue, 13 Feb 2018 14:06:17 +0100 Subject: [PATCH] Move the login decode function to the parent class. --- matrix/api.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/matrix/api.py b/matrix/api.py index a6ecb1d..e0e39f7 100644 --- a/matrix/api.py +++ b/matrix/api.py @@ -247,6 +247,20 @@ class MatrixMessage(): except Exception as error: return (False, error) + def _decode(self, server, object_hook): + try: + event = json.loads( + self.response.body, + encoding='utf-8', + object_hook=object_hook + ) + self.event = event + + return (True, None) + + except json.decoder.JSONDecodeError as error: + return (False, error) + class MatrixLoginMessage(MatrixMessage): def __init__(self, client, user, password, device_name, device_id=None): @@ -272,18 +286,7 @@ class MatrixLoginMessage(MatrixMessage): server ) - try: - event = json.loads( - self.response.body, - encoding='utf-8', - object_hook=object_hook - ) - self.event = event - - return (True, None) - - except json.decoder.JSONDecodeError as error: - return (False, error) + return self._decode(server, object_hook) class MatrixSyncMessage(MatrixMessage):