# 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
class ErrorDataFileChunkInvalid(Exception):

    def __init__(self):
        msg = "Data file chunk format is not valid."
        super(ErrorDataFileChunkInvalid, self).__init__(msg)

# ==============================================================================


class ErrorDataFileVersionInvalid(Exception):

    def __init__(self):
        msg = "Data file version is changed."
        super(ErrorDataFileVersionInvalid, self).__init__(msg)

# ==============================================================================


class ErrorDataFileCorrupted(Exception):

    def __init__(self):
        msg = "Data file is corrupted"
        super(ErrorDataFileCorrupted, self).__init__(msg)

# ==============================================================================


class _MmapFile(object):

    def __init__(self, filename):

# 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

class ErrorDataFileChunkInvalid(Exception):

    def __init__(self):
        msg = "Data file chunk format is not valid."
        super(ErrorDataFileChunkInvalid, self).__init__(msg)

# ==============================================================================


class ErrorDataFileVersionInvalid(Exception):

    def __init__(self):
        msg = "Data file version is changed."
        super(ErrorDataFileVersionInvalid, self).__init__(msg)

# ==============================================================================


class ErrorDataFileCorrupted(Exception):

    def __init__(self):
        msg = "Data file is corrupted"
        super(ErrorDataFileCorrupted, self).__init__(msg)

# ==============================================================================


class _MmapFile(object):

    def __init__(self, filename):

        stream = open_file(filename, write=True, binary=True, sync=False)