Move the login decode function to the parent class.

This commit is contained in:
poljar (Damir Jelić) 2018-02-13 14:06:17 +01:00
parent d045bc4368
commit bafa7d23b7

View file

@ -247,6 +247,20 @@ class MatrixMessage():
except Exception as error: except Exception as error:
return (False, 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): class MatrixLoginMessage(MatrixMessage):
def __init__(self, client, user, password, device_name, device_id=None): def __init__(self, client, user, password, device_name, device_id=None):
@ -272,18 +286,7 @@ class MatrixLoginMessage(MatrixMessage):
server server
) )
try: return self._decode(server, object_hook)
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 MatrixSyncMessage(MatrixMessage): class MatrixSyncMessage(MatrixMessage):