blob: 5ba8f710407b413a945835be7f8985a9ebf18560 [file] [log] [blame]
tierno87858ca2018-10-08 16:30:15 +02001# -*- coding: utf-8 -*-
2
3# Copyright 2018 Telefonica S.A.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
tierno5c012612018-04-19 16:01:59 +020017
tierno5c012612018-04-19 16:01:59 +020018from http import HTTPStatus
19
20__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
21
22
23class MsgException(Exception):
24 """
25 Base Exception class for all msgXXXX exceptions
26 """
27
tiernoa4eaefe2018-06-20 17:37:17 +020028 def __init__(self, message, http_code=HTTPStatus.SERVICE_UNAVAILABLE):
tierno5c012612018-04-19 16:01:59 +020029 """
30 General exception
31 :param message: descriptive text
32 :param http_code: <http.HTTPStatus> type. It contains ".value" (http error code) and ".name" (http error name
33 """
34 self.http_code = http_code
35 Exception.__init__(self, "messaging exception " + message)
36
37
38class MsgBase(object):
39 """
40 Base class for all msgXXXX classes
41 """
42
43 def __init__(self):
44 pass
45
46 def connect(self, config):
47 pass
48
49 def disconnect(self):
50 pass
51
52 def write(self, topic, key, msg):
tierno136f2952018-10-19 13:01:03 +020053 raise MsgException("Method 'write' not implemented", http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
tierno5c012612018-04-19 16:01:59 +020054
55 def read(self, topic):
tierno136f2952018-10-19 13:01:03 +020056 raise MsgException("Method 'read' not implemented", http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
tierno5c012612018-04-19 16:01:59 +020057
Benjamin Diaz48b78e12018-10-18 17:55:12 -030058 async def aiowrite(self, topic, key, msg, loop=None):
tierno136f2952018-10-19 13:01:03 +020059 raise MsgException("Method 'aiowrite' not implemented", http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
tierno5c012612018-04-19 16:01:59 +020060
Benjamin Diaz48b78e12018-10-18 17:55:12 -030061 async def aioread(self, topic, loop=None, callback=None, aiocallback=None, **kwargs):
tierno136f2952018-10-19 13:01:03 +020062 raise MsgException("Method 'aioread' not implemented", http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
63