# 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


import os
import sqlite3
import binascii
from .aql_utils import open_file

        except ErrorDataFileFormatInvalid:
            if not force and not self._is_aql_db(filename):
                raise

            os.remove(filename)
            conn = self._open_connection(filename)

        self._load_ids(conn)

        self.connection = conn

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

    def close(self):

        if self.connection is not None:
            self.connection.close()
            self.connection = None

        self.id2key.clear()
        self.key2id.clear()

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

    @staticmethod
    def _is_aql_db(filename):

        magic_tag = b".AQL.DB."


# 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_sql_data_file.py
import os
import sqlite3
import binascii
from .aql_utils import open_file


        except ErrorDataFileFormatInvalid:
            if not force and not self._is_aql_db(filename):
                raise

            os.remove(filename)
            conn = self._open_connection(filename)

        self._load_ids(conn)

        self.connection = conn

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

    def close(self):

        if self.connection is not None:
            self.connection.close()
            self.connection = None

        self.id2key.clear()
        self.key2id.clear()

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

    @staticmethod
    def _is_aql_db(filename):

        magic_tag = b".AQL.DB."


        with open_file(filename, read=True, binary=True) as f: