Debian Codegraph @

ipaserver/custodia/message/common.py

raw
1 # Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
2 from __future__ import absolute_import
3
4 from ipaserver.custodia.log import getLogger
5
6 logger = getLogger(__name__)
7
8
9 class InvalidMessage(Exception):
10 """Invalid Message.
11
12 This exception is raised when a message cannot be parsed
13 or validated.
14 """
15 def __init__(self, message=None):
16 logger.debug(message)
17 super(InvalidMessage, self).__init__(message)
18
19
20 class UnknownMessageType(Exception):
21 """Unknown Message Type.
22
23 This exception is raised when a message is of an unknown
24 type.
25 """
26 def __init__(self, message=None):
27 logger.debug(message)
28 super(UnknownMessageType, self).__init__(message)
29
30
31 class UnallowedMessage(Exception):
32 """Unallowed Message.
33
34 This exception is raise when the message type is know but
35 is not allowed.
36 """
37 def __init__(self, message=None):
38 logger.debug(message)
39 super(UnallowedMessage, self).__init__(message)
40
41
42 class MessageHandler:
43
44 def __init__(self, request):
45 self.req = request
46 self.name = None
47 self.payload = None
48 self.msg_type = None
49
50 def parse(self, msg, name):
51 """Parses the message.
52
53 :param req: the original request
54 :param msg: a decoded json string with the incoming message
55
56 :raises InvalidMessage: if the message cannot be parsed or validated
57 """
58
59 raise NotImplementedError
60
61 def reply(self, output):
62 """Generates a reply.
63
64 :param req: the original request
65 :param output: a Python object that can be converted to JSON
66 """
67
68 raise NotImplementedError