# Path: muninn/_compat.py
# def dictkeys(d):
#     return list(d.keys())
# 
# def dictvalues(d):
#     return list(d.values())
# 
# Path: muninn/function.py
# class Prototype(object):
#     def __init__(self, name, argument_types=(), return_type=None):
#         self.name = name
#         self.argument_types = argument_types
#         self.return_type = return_type
# 
#         self._id = "%s(%s)" % (self.name, ",".join(imap(lambda type: type.name(), self.argument_types)))
#         if self.return_type is not None:
#             self._id += " " + self.return_type.name()
# 
#     @property
#     def id(self):
#         return self._id
# 
#     @property
#     def arity(self):
#         return len(self.argument_types)
# 
#     def _argument_types_equal(self, other):
#         if self.arity != other.arity:
#             return False
# 
#         for type_self, type_other in izip(self.argument_types, other.argument_types):
#             if type_self is not type_other:
#                 return False
#         return True
# 
#     def __eq__(self, other):
#         return self.name == other.name and self._argument_types_equal(other) and self.return_type is other.return_type
# 
#     def __ne__(self, other):
#         return not self == other
# 
#     def __str__(self):
#         return self.id
# 
#     def __repr__(self):
#         return "Prototype(name=%r, argument_types=%r, return_type=%r)" % (self.name, self.argument_types,
#                                                                           self.return_type)
# 
#     def __hash__(self):
#         return hash(self.id)
# 
# Path: muninn/struct.py
# class Struct(object):
#     def __init__(self, data=None):
#         super(Struct, self).__init__()
#         if data is not None:
#             for key in data:
#                 if type(data[key]) == dict:
#                     self[key] = Struct(data[key])
#                 else:
#                     self[key] = data[key]
# 
#     def __getitem__(self, key):
#         try:
#             return getattr(self, key)
#         except AttributeError:
#             raise KeyError(key)
# 
#     def __setitem__(self, key, value):
#         setattr(self, key, value)
# 
#     def __delitem__(self, key):
#         try:
#             return delattr(self, key)
#         except AttributeError:
#             raise KeyError(key)
# 
#     def __contains__(self, key):
#         return hasattr(self, key)
# 
#     def __len__(self):
#         return len(vars(self))
# 
#     def __iter__(self):
#         return iter(vars(self))
# 
#     def __repr__(self):
#         return "Struct(%r)" % vars(self)
# 
#     def update(self, other):
#         '''update a struct, using the same semantics as dict.update()'''
#         for key in other:
#             other_item = other[key]
#             if isinstance(other_item, Struct):
#                 if key not in self:
#                     self[key] = Struct()
#                 else:
#                     if not isinstance(self[key], Struct):
#                         raise Error('Incompatible structs: %s vs %s' % (self, other))
#                 self[key].update(other_item)
#             else:
#                 self[key] = other_item


from muninn._compat import dictkeys, dictvalues
from muninn.exceptions import *
from muninn.function import Prototype
from muninn.schema import *
from muninn.struct import Struct
import os
import re
import datetime
import functools
import uuid
    import pysqlite2.dbapi2 as dbapi2
    import sqlite3.dbapi2 as dbapi2
import muninn.config as config
import muninn.database.sql as sql
import muninn.database.blobgeometry as blobgeometry
import muninn.geometry as geometry
    def delete_product_properties(self, uuid):
        with self._connection:
            self._delete_product_properties(uuid)

    @translate_sqlite_errors
    def derived_products(self, uuid):
        with self._connection:
            return self._derived_products(uuid)

    @translate_sqlite_errors
    def destroy(self):
        # Each table is deleted in a separate transaction, such that the exception that is raised when a table does not
        # exist can be ignored (this requires the transaction to be rolled back).
        self._drop_tables()

    @translate_sqlite_errors
    def disconnect(self):
        """Drop the connection to the database in order to free up resources. The connection will be re-established
        automatically when required."""
        self._connection.close()

    def exists(self):
        if not os.path.isfile(self._connection_string):
            return False
        with self._connection:
            query = "SELECT name FROM sqlite_master WHERE type='table' AND name=%s" % (self._placeholder(),)
            parameters = (self._core_table_name,)
            cursor = self._connection.cursor()
            try:
                cursor.execute(query, parameters)

# Path: muninn/_compat.py
# def dictkeys(d):
#     return list(d.keys())
# 
# def dictvalues(d):
#     return list(d.values())
# 
# Path: muninn/function.py
# class Prototype(object):
#     def __init__(self, name, argument_types=(), return_type=None):
#         self.name = name
#         self.argument_types = argument_types
#         self.return_type = return_type
# 
#         self._id = "%s(%s)" % (self.name, ",".join(imap(lambda type: type.name(), self.argument_types)))
#         if self.return_type is not None:
#             self._id += " " + self.return_type.name()
# 
#     @property
#     def id(self):
#         return self._id
# 
#     @property
#     def arity(self):
#         return len(self.argument_types)
# 
#     def _argument_types_equal(self, other):
#         if self.arity != other.arity:
#             return False
# 
#         for type_self, type_other in izip(self.argument_types, other.argument_types):
#             if type_self is not type_other:
#                 return False
#         return True
# 
#     def __eq__(self, other):
#         return self.name == other.name and self._argument_types_equal(other) and self.return_type is other.return_type
# 
#     def __ne__(self, other):
#         return not self == other
# 
#     def __str__(self):
#         return self.id
# 
#     def __repr__(self):
#         return "Prototype(name=%r, argument_types=%r, return_type=%r)" % (self.name, self.argument_types,
#                                                                           self.return_type)
# 
#     def __hash__(self):
#         return hash(self.id)
# 
# Path: muninn/struct.py
# class Struct(object):
#     def __init__(self, data=None):
#         super(Struct, self).__init__()
#         if data is not None:
#             for key in data:
#                 if type(data[key]) == dict:
#                     self[key] = Struct(data[key])
#                 else:
#                     self[key] = data[key]
# 
#     def __getitem__(self, key):
#         try:
#             return getattr(self, key)
#         except AttributeError:
#             raise KeyError(key)
# 
#     def __setitem__(self, key, value):
#         setattr(self, key, value)
# 
#     def __delitem__(self, key):
#         try:
#             return delattr(self, key)
#         except AttributeError:
#             raise KeyError(key)
# 
#     def __contains__(self, key):
#         return hasattr(self, key)
# 
#     def __len__(self):
#         return len(vars(self))
# 
#     def __iter__(self):
#         return iter(vars(self))
# 
#     def __repr__(self):
#         return "Struct(%r)" % vars(self)
# 
#     def update(self, other):
#         '''update a struct, using the same semantics as dict.update()'''
#         for key in other:
#             other_item = other[key]
#             if isinstance(other_item, Struct):
#                 if key not in self:
#                     self[key] = Struct()
#                 else:
#                     if not isinstance(self[key], Struct):
#                         raise Error('Incompatible structs: %s vs %s' % (self, other))
#                 self[key].update(other_item)
#             else:
#                 self[key] = other_item


# Path: muninn/database/sqlite.py
from muninn._compat import dictkeys, dictvalues
from muninn.exceptions import *
from muninn.function import Prototype
from muninn.schema import *
from muninn.struct import Struct
import os
import re
import datetime
import functools
import uuid
    import pysqlite2.dbapi2 as dbapi2
    import sqlite3.dbapi2 as dbapi2
import muninn.config as config
import muninn.database.sql as sql
import muninn.database.blobgeometry as blobgeometry
import muninn.geometry as geometry

    def delete_product_properties(self, uuid):
        with self._connection:
            self._delete_product_properties(uuid)

    @translate_sqlite_errors
    def derived_products(self, uuid):
        with self._connection:
            return self._derived_products(uuid)

    @translate_sqlite_errors
    def destroy(self):
        # Each table is deleted in a separate transaction, such that the exception that is raised when a table does not
        # exist can be ignored (this requires the transaction to be rolled back).
        self._drop_tables()

    @translate_sqlite_errors
    def disconnect(self):
        """Drop the connection to the database in order to free up resources. The connection will be re-established
        automatically when required."""
        self._connection.close()

    def exists(self):
        if not os.path.isfile(self._connection_string):
            return False
        with self._connection:
            query = "SELECT name FROM sqlite_master WHERE type='table' AND name=%s" % (self._placeholder(),)
            parameters = (self._core_table_name,)
            cursor = self._connection.cursor()
            try:
                cursor.execute(query, parameters)

                return len(cursor.fetchall()) != 0