class DbException(Exception):
def __init__(self, message, http_code=HTTPStatus.NOT_FOUND):
+ # TODO change to http.HTTPStatus instead of int that allows .value and .name
self.http_code = http_code
Exception.__init__(self, "database exception " + message)
pass
def get_list(self, table, filter={}):
- pass
+ raise DbException("Method 'get_list' not implemented")
def get_one(self, table, filter={}, fail_on_empty=True, fail_on_more=True):
- pass
+ raise DbException("Method 'get_one' not implemented")
def create(self, table, indata):
- pass
+ raise DbException("Method 'create' not implemented")
def del_list(self, table, filter={}):
- pass
+ raise DbException("Method 'del_list' not implemented")
def del_one(self, table, filter={}, fail_on_empty=True):
- pass
+ raise DbException("Method 'del_one' not implemented")
pass
def mkdir(self, folder):
- pass
+ raise FsException("Method 'mkdir' not implemented")
def file_exists(self, storage):
- pass
+ raise FsException("Method 'file_exists' not implemented")
def file_size(self, storage):
- pass
+ raise FsException("Method 'file_size' not implemented")
def file_extract(self, tar_object, path):
- pass
+ raise FsException("Method 'file_extract' not implemented")
def file_open(self, storage, mode):
- pass
+ raise FsException("Method 'file_open' not implemented")
def file_delete(self, storage, ignore_non_exist=False):
- pass
+ raise FsException("Method 'file_delete' not implemented")
pass
def write(self, topic, key, msg):
- pass
+ raise MsgException("Method 'write' not implemented")
def read(self, topic):
- pass
+ raise MsgException("Method 'read' not implemented")
async def aiowrite(self, topic, key, msg, loop):
- pass
+ raise MsgException("Method 'aiowrite' not implemented")
async def aioread(self, topic, loop):
- pass
+ raise MsgException("Method 'aioread' not implemented")
def disconnect(self):
try:
- self.loop.close()
+ pass
+ # self.loop.close()
except Exception as e: # TODO refine
raise MsgException(str(e))
raise
except Exception as e: # TODO refine
raise MsgException(str(e))
+
+ async def aiowrite(self, topic, key, msg, loop=None):
+ """
+ Asyncio write. It blocks
+ :param topic: str
+ :param key: str
+ :param msg: message, can be str or yaml
+ :param loop: asyncio loop
+ :return: nothing if ok or raises an exception
+ """
+ return self.write(topic, key, msg)