# Path: elevator/db.py
# class DatabaseOptions(dict):
#     def __init__(self, *args, **kwargs):
#         self['create_if_missing'] = True
#         self['error_if_exists'] = False
#         self['bloom_filter_bits'] = 10  # Value recommended by leveldb doc
#         self['paranoid_checks'] = False
#         self['lru_cache_size'] = 512 * (1 << 20)  # 512 Mo
#         self['write_buffer_size'] = 4 * (1 << 20)  # 4 Mo
#         self['block_size'] = 4096
#         self['max_open_files'] = 1000
# 
#         for key, value in kwargs.iteritems():
#             if key in self:
#                 self[key] = value
# 
# Path: elevator/message.py
# class ResponseContent(tuple):
#     """Handler objects for responses messages
# 
#     Format:
#     {
#         'meta': {
#             'status': 1|0|-1,
#             'err_code': null|0|1|[...],
#             'err_msg': '',
#         },
#         'datas': [...],
#     }
#     """
#     def __new__(cls, *args, **kwargs):
#         response = {
#             'datas': cls._format_datas(kwargs['datas']),
#         }
#         activity_logger.debug('<Response ' + str(response['datas']) + '>')
#         msg = msgpack.packb(response)
# 
#         if kwargs.pop('compression', False) is True:
#             msg = lz4.dumps(msg)
# 
#         return msg
# 
#     @classmethod
#     def _format_datas(cls, datas):
#         if datas and not isinstance(datas, (tuple, list)):
#             datas = [datas]
#         return datas
# 
# class ResponseHeader(dict):
#     def __new__(cls, *args, **kwargs):
#         header = {
#             'status': kwargs.pop('status'),
#             'err_code': kwargs.pop('err_code', None),
#             'err_msg': kwargs.pop('err_msg', None),
#             'compression': kwargs.pop('compression', False)
#         }
#         activity_logger.debug('<ResponseHeader ' + str(header) + '>')
# 
#         for key, value in kwargs.iteritems():
#             header.update({key: value})
# 
#         return msgpack.packb(header)
# 
# Path: elevator/constants.py
# KEY_ERROR = 1
# 
# TYPE_ERROR = 0
# 
# DATABASE_ERROR = 6
# 
# VALUE_ERROR = 2
# 
# RUNTIME_ERROR = 4
# 
# SIGNAL_ERROR = 7
# 
# SUCCESS_STATUS = 1
# 
# FAILURE_STATUS = -1
# 
# WARNING_STATUS = -2
# 
# SIGNAL_BATCH_PUT = 1
# 
# SIGNAL_BATCH_DELETE = 0
# 
# Path: elevator/utils/patterns.py
# def destructurate(container):
#     try:
#         return container[0], container[1:]
#     except (KeyError, AttributeError):
#         raise DestructurationError("Can't destructurate a non-sequence container")
# 
# Path: elevator/helpers/internals.py
# def failure(err_code, err_msg):
#     """Returns a formatted error status and content"""
#     return (FAILURE_STATUS, [err_code, err_msg])
# 
# def success(content=None):
#     """Returns a formatted success status and content"""
#     return (SUCCESS_STATUS, content)


import plyvel
import logging
import time
from .db import DatabaseOptions
from .message import ResponseContent, ResponseHeader
from .constants import KEY_ERROR, TYPE_ERROR, DATABASE_ERROR,\
                       VALUE_ERROR, RUNTIME_ERROR, SIGNAL_ERROR,\
                       SUCCESS_STATUS, FAILURE_STATUS, WARNING_STATUS,\
                       SIGNAL_BATCH_PUT, SIGNAL_BATCH_DELETE
from .utils.patterns import destructurate
from .helpers.internals import failure, success
            'MGET': self.MGet,
            'PING': self.Ping,
            'DBCONNECT': self.DBConnect,
            'DBMOUNT': self.DBMount,
            'DBUMOUNT': self.DBUmount,
            'DBCREATE': self.DBCreate,
            'DBDROP': self.DBDrop,
            'DBLIST': self.DBList,
            'DBREPAIR': self.DBRepair,
        }
        self.context = {}

    def Get(self, db, key, *args, **kwargs):
        """
        Handles GET message command.
        Executes a Get operation over the plyvel backend.

        db      =>      LevelDB object
        *args   =>      (key) to fetch
        """
        value = db.get(key)

        if not value:
            error_msg = "Key %r does not exist" % key
            errors_logger.exception(error_msg)
            return failure(KEY_ERROR, error_msg)
        else:
            return success(value)

    def MGet(self, db, keys, *args, **kwargs):

# Path: elevator/db.py
# class DatabaseOptions(dict):
#     def __init__(self, *args, **kwargs):
#         self['create_if_missing'] = True
#         self['error_if_exists'] = False
#         self['bloom_filter_bits'] = 10  # Value recommended by leveldb doc
#         self['paranoid_checks'] = False
#         self['lru_cache_size'] = 512 * (1 << 20)  # 512 Mo
#         self['write_buffer_size'] = 4 * (1 << 20)  # 4 Mo
#         self['block_size'] = 4096
#         self['max_open_files'] = 1000
# 
#         for key, value in kwargs.iteritems():
#             if key in self:
#                 self[key] = value
# 
# Path: elevator/message.py
# class ResponseContent(tuple):
#     """Handler objects for responses messages
# 
#     Format:
#     {
#         'meta': {
#             'status': 1|0|-1,
#             'err_code': null|0|1|[...],
#             'err_msg': '',
#         },
#         'datas': [...],
#     }
#     """
#     def __new__(cls, *args, **kwargs):
#         response = {
#             'datas': cls._format_datas(kwargs['datas']),
#         }
#         activity_logger.debug('<Response ' + str(response['datas']) + '>')
#         msg = msgpack.packb(response)
# 
#         if kwargs.pop('compression', False) is True:
#             msg = lz4.dumps(msg)
# 
#         return msg
# 
#     @classmethod
#     def _format_datas(cls, datas):
#         if datas and not isinstance(datas, (tuple, list)):
#             datas = [datas]
#         return datas
# 
# class ResponseHeader(dict):
#     def __new__(cls, *args, **kwargs):
#         header = {
#             'status': kwargs.pop('status'),
#             'err_code': kwargs.pop('err_code', None),
#             'err_msg': kwargs.pop('err_msg', None),
#             'compression': kwargs.pop('compression', False)
#         }
#         activity_logger.debug('<ResponseHeader ' + str(header) + '>')
# 
#         for key, value in kwargs.iteritems():
#             header.update({key: value})
# 
#         return msgpack.packb(header)
# 
# Path: elevator/constants.py
# KEY_ERROR = 1
# 
# TYPE_ERROR = 0
# 
# DATABASE_ERROR = 6
# 
# VALUE_ERROR = 2
# 
# RUNTIME_ERROR = 4
# 
# SIGNAL_ERROR = 7
# 
# SUCCESS_STATUS = 1
# 
# FAILURE_STATUS = -1
# 
# WARNING_STATUS = -2
# 
# SIGNAL_BATCH_PUT = 1
# 
# SIGNAL_BATCH_DELETE = 0
# 
# Path: elevator/utils/patterns.py
# def destructurate(container):
#     try:
#         return container[0], container[1:]
#     except (KeyError, AttributeError):
#         raise DestructurationError("Can't destructurate a non-sequence container")
# 
# Path: elevator/helpers/internals.py
# def failure(err_code, err_msg):
#     """Returns a formatted error status and content"""
#     return (FAILURE_STATUS, [err_code, err_msg])
# 
# def success(content=None):
#     """Returns a formatted success status and content"""
#     return (SUCCESS_STATUS, content)


# Path: elevator/api.py
import plyvel
import logging
import time
from .db import DatabaseOptions
from .message import ResponseContent, ResponseHeader
from .constants import KEY_ERROR, TYPE_ERROR, DATABASE_ERROR,\
                       VALUE_ERROR, RUNTIME_ERROR, SIGNAL_ERROR,\
                       SUCCESS_STATUS, FAILURE_STATUS, WARNING_STATUS,\
                       SIGNAL_BATCH_PUT, SIGNAL_BATCH_DELETE
from .utils.patterns import destructurate
from .helpers.internals import failure, success

            'MGET': self.MGet,
            'PING': self.Ping,
            'DBCONNECT': self.DBConnect,
            'DBMOUNT': self.DBMount,
            'DBUMOUNT': self.DBUmount,
            'DBCREATE': self.DBCreate,
            'DBDROP': self.DBDrop,
            'DBLIST': self.DBList,
            'DBREPAIR': self.DBRepair,
        }
        self.context = {}

    def Get(self, db, key, *args, **kwargs):
        """
        Handles GET message command.
        Executes a Get operation over the plyvel backend.

        db      =>      LevelDB object
        *args   =>      (key) to fetch
        """
        value = db.get(key)

        if not value:
            error_msg = "Key %r does not exist" % key
            errors_logger.exception(error_msg)
            return failure(KEY_ERROR, error_msg)
        else:
            return success(value)

    def MGet(self, db, keys, *args, **kwargs):

        status = SUCCESS_STATUS