# Path: debian/elevator/usr/share/pyshared/elevator/db.py
# class DatabaseOptions(dict):
#     def __init__(self, *args, **kwargs):
#         self['create_if_missing'] = True
#         self['error_if_exists'] = False
#         self['paranoid_checks'] = False
#         self['block_cache_size'] = 8 * (2 << 20)
#         self['write_buffer_size'] = 2 * (2 << 20)
#         self['block_size'] = 4096
#         self['max_open_files'] = 1000
# 
#         for key, value in kwargs.iteritems():
#             if key in self:
#                 self[key] = value
# 
# Path: debian/elevator/usr/share/pyshared/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


import leveldb
import logging
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
            errors_logger.exception(error_msg)
            return failure(TYPE_ERROR, error_msg)

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

        db      =>      LevelDB object
        *args   =>      (key) to delete from backend

        """
        return success(db.Delete(key))

    def Range(self, db, key_from, key_to, *args, **kwargs):
        """Returns the Range of key/value between
        `key_from and `key_to`"""
        # Operate over a snapshot in order to return
        # a consistent state of the db
        db_snapshot = db.CreateSnapshot()
        value = list(db_snapshot.RangeIter(key_from, key_to))

        return success(value)

    def Slice(self, db, key_from, offset, *args, **kwargs):
        """Returns a slice of the db. `offset` keys,
        starting a `key_from`"""
        # Operates over a snapshot in order to return
        # a consistent state of the db
        db_snapshot = db.CreateSnapshot()

# Path: debian/elevator/usr/share/pyshared/elevator/db.py
# class DatabaseOptions(dict):
#     def __init__(self, *args, **kwargs):
#         self['create_if_missing'] = True
#         self['error_if_exists'] = False
#         self['paranoid_checks'] = False
#         self['block_cache_size'] = 8 * (2 << 20)
#         self['write_buffer_size'] = 2 * (2 << 20)
#         self['block_size'] = 4096
#         self['max_open_files'] = 1000
# 
#         for key, value in kwargs.iteritems():
#             if key in self:
#                 self[key] = value
# 
# Path: debian/elevator/usr/share/pyshared/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: debian/elevator/usr/share/pyshared/elevator/api.py
import leveldb
import logging
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

            errors_logger.exception(error_msg)
            return failure(TYPE_ERROR, error_msg)

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

        db      =>      LevelDB object
        *args   =>      (key) to delete from backend

        """
        return success(db.Delete(key))

    def Range(self, db, key_from, key_to, *args, **kwargs):
        """Returns the Range of key/value between
        `key_from and `key_to`"""
        # Operate over a snapshot in order to return
        # a consistent state of the db
        db_snapshot = db.CreateSnapshot()
        value = list(db_snapshot.RangeIter(key_from, key_to))

        return success(value)

    def Slice(self, db, key_from, offset, *args, **kwargs):
        """Returns a slice of the db. `offset` keys,
        starting a `key_from`"""
        # Operates over a snapshot in order to return
        # a consistent state of the db
        db_snapshot = db.CreateSnapshot()

        it = db_snapshot.RangeIter(key_from)