blob: 8978085dcc3cb2589dd0251b9edb1cdfe5871d2c [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
tierno3054f782018-04-25 16:59:53 +020018# import asyncio
tierno5c012612018-04-19 16:01:59 +020019from http import HTTPStatus
20
21__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
22
23
24class MsgException(Exception):
25 """
26 Base Exception class for all msgXXXX exceptions
27 """
28
tiernoa4eaefe2018-06-20 17:37:17 +020029 def __init__(self, message, http_code=HTTPStatus.SERVICE_UNAVAILABLE):
tierno5c012612018-04-19 16:01:59 +020030 """
31 General exception
32 :param message: descriptive text
33 :param http_code: <http.HTTPStatus> type. It contains ".value" (http error code) and ".name" (http error name
34 """
35 self.http_code = http_code
36 Exception.__init__(self, "messaging exception " + message)
37
38
39class MsgBase(object):
40 """
41 Base class for all msgXXXX classes
42 """
43
44 def __init__(self):
45 pass
46
47 def connect(self, config):
48 pass
49
50 def disconnect(self):
51 pass
52
53 def write(self, topic, key, msg):
tiernoebbf3532018-05-03 17:49:37 +020054 raise MsgException("Method 'write' not implemented")
tierno5c012612018-04-19 16:01:59 +020055
56 def read(self, topic):
tiernoebbf3532018-05-03 17:49:37 +020057 raise MsgException("Method 'read' not implemented")
tierno5c012612018-04-19 16:01:59 +020058
59 async def aiowrite(self, topic, key, msg, loop):
tiernoebbf3532018-05-03 17:49:37 +020060 raise MsgException("Method 'aiowrite' not implemented")
tierno5c012612018-04-19 16:01:59 +020061
62 async def aioread(self, topic, loop):
tiernoebbf3532018-05-03 17:49:37 +020063 raise MsgException("Method 'aioread' not implemented")