# 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
        unpacked_properties = Struct()
        schema = self._namespace_schema(namespace)
        for identifier, value in zip(description, values):
            if value is not None or not schema.is_optional(identifier):
                unpacked_properties[identifier] = value
        return unpacked_properties

    def _untag(self, uuid, tags=None):
        if tags is None:
            query = "DELETE FROM %s WHERE uuid = %s" % (self._tag_table_name, self._placeholder())
            parameters = (uuid,)
        else:
            query = "DELETE FROM %s WHERE uuid = %s AND tag IN (%s)" % \
                    (self._tag_table_name, self._placeholder(), ','.join(self._placeholder() * len(tags)))
            parameters = [uuid] + list(tags)

        cursor = self._connection.cursor()
        try:
            cursor.execute(query, parameters)
        finally:
            cursor.close()

    def _update_namespace_properties(self, uuid, name, properties):
        self._validate_namespace_properties(name, properties, partial=True)
        assert uuid is not None and getattr(properties, "uuid", uuid) == uuid

        # Split the properties into a list of (database) field names and a list of values. This assumes the database
        # field that corresponds to a given property has the same name. If the backend uses different field names, the
        # required translation can be performed here. Values can also be translated if necessary.
        properties_dict = vars(properties)

# 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

        unpacked_properties = Struct()
        schema = self._namespace_schema(namespace)
        for identifier, value in zip(description, values):
            if value is not None or not schema.is_optional(identifier):
                unpacked_properties[identifier] = value
        return unpacked_properties

    def _untag(self, uuid, tags=None):
        if tags is None:
            query = "DELETE FROM %s WHERE uuid = %s" % (self._tag_table_name, self._placeholder())
            parameters = (uuid,)
        else:
            query = "DELETE FROM %s WHERE uuid = %s AND tag IN (%s)" % \
                    (self._tag_table_name, self._placeholder(), ','.join(self._placeholder() * len(tags)))
            parameters = [uuid] + list(tags)

        cursor = self._connection.cursor()
        try:
            cursor.execute(query, parameters)
        finally:
            cursor.close()

    def _update_namespace_properties(self, uuid, name, properties):
        self._validate_namespace_properties(name, properties, partial=True)
        assert uuid is not None and getattr(properties, "uuid", uuid) == uuid

        # Split the properties into a list of (database) field names and a list of values. This assumes the database
        # field that corresponds to a given property has the same name. If the backend uses different field names, the
        # required translation can be performed here. Values can also be translated if necessary.
        properties_dict = vars(properties)

        fields, parameters = dictkeys(properties_dict), dictvalues(properties_dict)