# Path: aql/utils/aql_utils.py
# def open_file(filename, read=True, write=False, binary=False,
#               sync=False, truncate=False, encoding=None):
# 
#     if not is_string(filename):
#         raise ErrorFileName(filename)
# 
#     if write:
#         mode = 'r+'
#     else:
#         mode = 'r'
# 
#     if binary:
#         mode += 'b'
# 
#     fd = _open_file_handle(filename, read=read, write=write,
#                            sync=sync, truncate=truncate)
#     try:
#         if sync and binary:
#             return io.open(fd, mode, 0, encoding=encoding)
#         else:
#             return io.open(fd, mode, encoding=encoding)
#     except:
#         os.close(fd)
#         raise
# 
# Path: aql/utils/aql_logging.py
# LOG_CRITICAL = logging.CRITICAL
# LOG_ERROR = logging.ERROR
# LOG_WARNING = logging.WARNING
# LOG_INFO = logging.INFO
# LOG_DEBUG = logging.DEBUG
# class LogFormatter(logging.Formatter):
#     def __init__(self, *args, **kw):
#     def format(self, record):
# def _make_aql_logger():


import os
import operator
import struct
import mmap
from .aql_utils import open_file
from .aql_logging import log_debug

    # 4 bytes (offset of data area)
    _META_TABLE_HEADER_STRUCT = struct.Struct(">L")
    _META_TABLE_HEADER_SIZE = _META_TABLE_HEADER_STRUCT.size
    _META_TABLE_HEADER_OFFSET = _KEY_OFFSET + _KEY_SIZE

    _META_TABLE_OFFSET = _META_TABLE_HEADER_OFFSET + _META_TABLE_HEADER_SIZE

    # -----------------------------------------------------------

    def __init__(self, filename, force=False):

        self.id2data = {}
        self.key2id = {}
        self.meta_end = 0
        self.data_begin = 0
        self.data_end = 0
        self.handle = None
        self.next_key = None

        self.open(filename, force=force)

    # -----------------------------------------------------------

    def open(self, filename, force=False):
        self.close()

        try:
            self.handle = _MmapFile(filename)
        except Exception as ex:

# Path: aql/utils/aql_utils.py
# def open_file(filename, read=True, write=False, binary=False,
#               sync=False, truncate=False, encoding=None):
# 
#     if not is_string(filename):
#         raise ErrorFileName(filename)
# 
#     if write:
#         mode = 'r+'
#     else:
#         mode = 'r'
# 
#     if binary:
#         mode += 'b'
# 
#     fd = _open_file_handle(filename, read=read, write=write,
#                            sync=sync, truncate=truncate)
#     try:
#         if sync and binary:
#             return io.open(fd, mode, 0, encoding=encoding)
#         else:
#             return io.open(fd, mode, encoding=encoding)
#     except:
#         os.close(fd)
#         raise
# 
# Path: aql/utils/aql_logging.py
# LOG_CRITICAL = logging.CRITICAL
# LOG_ERROR = logging.ERROR
# LOG_WARNING = logging.WARNING
# LOG_INFO = logging.INFO
# LOG_DEBUG = logging.DEBUG
# class LogFormatter(logging.Formatter):
#     def __init__(self, *args, **kw):
#     def format(self, record):
# def _make_aql_logger():


# Path: aql/utils/aql_data_file.py
import os
import operator
import struct
import mmap
from .aql_utils import open_file
from .aql_logging import log_debug


    # 4 bytes (offset of data area)
    _META_TABLE_HEADER_STRUCT = struct.Struct(">L")
    _META_TABLE_HEADER_SIZE = _META_TABLE_HEADER_STRUCT.size
    _META_TABLE_HEADER_OFFSET = _KEY_OFFSET + _KEY_SIZE

    _META_TABLE_OFFSET = _META_TABLE_HEADER_OFFSET + _META_TABLE_HEADER_SIZE

    # -----------------------------------------------------------

    def __init__(self, filename, force=False):

        self.id2data = {}
        self.key2id = {}
        self.meta_end = 0
        self.data_begin = 0
        self.data_end = 0
        self.handle = None
        self.next_key = None

        self.open(filename, force=force)

    # -----------------------------------------------------------

    def open(self, filename, force=False):
        self.close()

        try:
            self.handle = _MmapFile(filename)
        except Exception as ex:

            log_debug("mmap is not supported: %s", ex)