diff options
| author | Simo Sorce <simo@redhat.com> | 2015-04-16 16:44:51 -0400 |
|---|---|---|
| committer | Simo Sorce <simo@redhat.com> | 2015-04-20 16:07:14 -0400 |
| commit | b9e31bf1cc44bdfeaf0454dadb578c4dbb8d588b (patch) | |
| tree | 5abfb99f7669f49cdece5c3b15c632130aaf42f4 /custodia/message/common.py | |
| parent | f77b0158f87a13efc1d315b1bcb58cccf4406e88 (diff) | |
| download | custodia-b9e31bf1cc44bdfeaf0454dadb578c4dbb8d588b.tar.gz custodia-b9e31bf1cc44bdfeaf0454dadb578c4dbb8d588b.tar.xz custodia-b9e31bf1cc44bdfeaf0454dadb578c4dbb8d588b.zip | |
Move message parsing and validation
Create a message module to deal with message types and validation.
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'custodia/message/common.py')
| -rw-r--r-- | custodia/message/common.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/custodia/message/common.py b/custodia/message/common.py new file mode 100644 index 0000000..89deb59 --- /dev/null +++ b/custodia/message/common.py @@ -0,0 +1,55 @@ +# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file + + +class InvalidMessage(Exception): + """Invalid Message. + + This exception is raised when a message cannot be parsed + or validated. + """ + pass + + +class UnknownMessageType(Exception): + """Unknown Message Type. + + This exception is raised when a message is of an unknown + type. + """ + pass + + +class UnallowedMessage(Exception): + """Unallowed Message. + + This exception is raise when the message type is know but + is not allowed. + """ + pass + + +class MessageHandler(object): + + def __init__(self, request): + self.req = request + self.payload = None + + def parse(self, msg): + """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 |
