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