# Path: dockit/backends/base.py
# class BaseDocumentStorage(BaseStorage):
#     """
#     The :class:`~dockit.backends.base.BaseDocumentStorage` class provides an interface
#     for implementing document storage backends.
#     """
#     
#     _connections = DOCUMENT_BACKEND_CONNECTIONS
#     _threaded_connections = THREADED_DOCUMENT_BACKEND_CONNECTIONS
#     
#     def get_query(self, query_index):
#         """
#         return an implemented `BaseDocumentQuerySet` that contains all the documents
#         """
#         raise NotImplementedError
#     
#     def register_document(self, document):
#         """
#         is called for every document registered in the system
#         """
#         pass
#     
#     def save(self, doc_class, collection, data):
#         """
#         stores the given primitive data in the specified collection
#         """
#         raise NotImplementedError
#     
#     def get(self, doc_class, collection, doc_id):
#         """
#         returns the primitive data for the document belonging in the specified collection
#         """
#         raise NotImplementedError
#     
#     def delete(self, doc_class, collection, doc_id):
#         """
#         deletes the given document from the specified collection
#         """
#         raise NotImplementedError
#     
#     def get_id(self, data):
#         """
#         returns the id from the primitive data
#         """
#         return data.get(self.get_id_field_name())
#     
#     def get_id_field_name(self):
#         """
#         returns a string representing the primary key field name
#         """
#         raise NotImplementedError
# 
# class BaseIndexStorage(BaseStorage):
#     """
#     The :class:`~dockit.backends.base.BaseIndexStorage` class provides an interface
#     for implementing index storage backends.
#     """
#     
#     _connections = INDEX_BACKEND_CONNECTIONS
#     _threaded_connections = THREADED_INDEX_BACKEND_CONNECTIONS
#     
#     _indexers = dict()
#     
#     @classmethod
#     def register_indexer(cls, index_cls, *names):
#         for name in names:
#             cls._indexers[name] = index_cls
#     
#     @classmethod
#     def get_indexer(cls, name):
#         return cls._indexers[name]
#     
#     def _get_indexer_for_operation(self, document, op):
#         indexer = self.get_indexer(op.operation)
#         return indexer(document, op)
#     
#     def register_index(self, query_index):
#         """
#         register the query index with this backend
#         """
#         raise NotImplementedError
#     
#     def destroy_index(self, query_index):
#         """
#         release the query index with this backend
#         """
#         raise NotImplementedError
#     
#     def get_query(self, query_index):
#         """
#         returns an implemented `BaseDocumentQuerySet` representing the query index
#         """
#         raise NotImplementedError
#     
#     def register_document(self, document):
#         """
#         is called for every document registered in the system
#         """
#         pass
#     
#     def on_save(self, doc_class, collection, doc_id, data):
#         """
#         is called for every document save
#         """
#         raise NotImplementedError
#     
#     def on_delete(self, doc_class, collection, doc_id):
#         """
#         is called for every document delete
#         """
#         raise NotImplementedError
# 
# Path: dockit/backends/queryset.py
# class BaseDocumentQuery(object):
#     """
#     Implemented by the backend to execute a certain index
#     """
#     def __init__(self, query_index, backend=None):
#         self.query_index = query_index
#         self._backend = backend
#     
#     @property
#     def document(self):
#         return self.query_index.document
#     
#     @property
#     def backend(self):
#         if self._backend:
#             return self._backend
#         return self.document._meta.get_index_backend_for_read(self.query_index)
#     
#     def _get_indexer_for_operation(self, document, op):
#         return self.backend._get_indexer_for_operation(document, op)
#     
#     def __len__(self):
#         raise NotImplementedError
#     
#     def count(self):
#         return self.__len__()
#     
#     def exists(self):
#         return bool(self.__len__())
#     
#     def delete(self):
#         raise NotImplementedError
#     
#     def get(self, **kwargs):
#         filter_operations = self.query_index._parse_kwargs(kwargs)
#         return self.get_from_filter_operations(filter_operations)
#     
#     def get_from_filter_operations(self, filter_operations):
#         raise NotImplementedError
#     
#     def values(self, *limit_to, **kwargs):
#         raise NotImplementedError
#     
#     def __getitem__(self, val):
#         raise NotImplementedError
#     
#     def __nonzero__(self):
#         raise NotImplementedError


from pymongo import Connection
    from bson.objectid import ObjectId
    from pymongo.objectid import ObjectId
from dockit.backends.base import BaseDocumentStorage, BaseIndexStorage
from dockit.backends.queryset import BaseDocumentQuery
try:
except ImportError:


class ValuesResultClass(dict):
    def __getitem__(self, key):
        try:
            return dict.__getitem__(self, key)
        except KeyError:
            if key == 'pk':
                return dict.__getitem__(self, '_id')
            raise


# Path: dockit/backends/base.py
# class BaseDocumentStorage(BaseStorage):
#     """
#     The :class:`~dockit.backends.base.BaseDocumentStorage` class provides an interface
#     for implementing document storage backends.
#     """
#     
#     _connections = DOCUMENT_BACKEND_CONNECTIONS
#     _threaded_connections = THREADED_DOCUMENT_BACKEND_CONNECTIONS
#     
#     def get_query(self, query_index):
#         """
#         return an implemented `BaseDocumentQuerySet` that contains all the documents
#         """
#         raise NotImplementedError
#     
#     def register_document(self, document):
#         """
#         is called for every document registered in the system
#         """
#         pass
#     
#     def save(self, doc_class, collection, data):
#         """
#         stores the given primitive data in the specified collection
#         """
#         raise NotImplementedError
#     
#     def get(self, doc_class, collection, doc_id):
#         """
#         returns the primitive data for the document belonging in the specified collection
#         """
#         raise NotImplementedError
#     
#     def delete(self, doc_class, collection, doc_id):
#         """
#         deletes the given document from the specified collection
#         """
#         raise NotImplementedError
#     
#     def get_id(self, data):
#         """
#         returns the id from the primitive data
#         """
#         return data.get(self.get_id_field_name())
#     
#     def get_id_field_name(self):
#         """
#         returns a string representing the primary key field name
#         """
#         raise NotImplementedError
# 
# class BaseIndexStorage(BaseStorage):
#     """
#     The :class:`~dockit.backends.base.BaseIndexStorage` class provides an interface
#     for implementing index storage backends.
#     """
#     
#     _connections = INDEX_BACKEND_CONNECTIONS
#     _threaded_connections = THREADED_INDEX_BACKEND_CONNECTIONS
#     
#     _indexers = dict()
#     
#     @classmethod
#     def register_indexer(cls, index_cls, *names):
#         for name in names:
#             cls._indexers[name] = index_cls
#     
#     @classmethod
#     def get_indexer(cls, name):
#         return cls._indexers[name]
#     
#     def _get_indexer_for_operation(self, document, op):
#         indexer = self.get_indexer(op.operation)
#         return indexer(document, op)
#     
#     def register_index(self, query_index):
#         """
#         register the query index with this backend
#         """
#         raise NotImplementedError
#     
#     def destroy_index(self, query_index):
#         """
#         release the query index with this backend
#         """
#         raise NotImplementedError
#     
#     def get_query(self, query_index):
#         """
#         returns an implemented `BaseDocumentQuerySet` representing the query index
#         """
#         raise NotImplementedError
#     
#     def register_document(self, document):
#         """
#         is called for every document registered in the system
#         """
#         pass
#     
#     def on_save(self, doc_class, collection, doc_id, data):
#         """
#         is called for every document save
#         """
#         raise NotImplementedError
#     
#     def on_delete(self, doc_class, collection, doc_id):
#         """
#         is called for every document delete
#         """
#         raise NotImplementedError
# 
# Path: dockit/backends/queryset.py
# class BaseDocumentQuery(object):
#     """
#     Implemented by the backend to execute a certain index
#     """
#     def __init__(self, query_index, backend=None):
#         self.query_index = query_index
#         self._backend = backend
#     
#     @property
#     def document(self):
#         return self.query_index.document
#     
#     @property
#     def backend(self):
#         if self._backend:
#             return self._backend
#         return self.document._meta.get_index_backend_for_read(self.query_index)
#     
#     def _get_indexer_for_operation(self, document, op):
#         return self.backend._get_indexer_for_operation(document, op)
#     
#     def __len__(self):
#         raise NotImplementedError
#     
#     def count(self):
#         return self.__len__()
#     
#     def exists(self):
#         return bool(self.__len__())
#     
#     def delete(self):
#         raise NotImplementedError
#     
#     def get(self, **kwargs):
#         filter_operations = self.query_index._parse_kwargs(kwargs)
#         return self.get_from_filter_operations(filter_operations)
#     
#     def get_from_filter_operations(self, filter_operations):
#         raise NotImplementedError
#     
#     def values(self, *limit_to, **kwargs):
#         raise NotImplementedError
#     
#     def __getitem__(self, val):
#         raise NotImplementedError
#     
#     def __nonzero__(self):
#         raise NotImplementedError


# Path: dockit/backends/mongo/backend.py
from pymongo import Connection
    from bson.objectid import ObjectId
    from pymongo.objectid import ObjectId
from dockit.backends.base import BaseDocumentStorage, BaseIndexStorage
from dockit.backends.queryset import BaseDocumentQuery

try:
except ImportError:


class ValuesResultClass(dict):
    def __getitem__(self, key):
        try:
            return dict.__getitem__(self, key)
        except KeyError:
            if key == 'pk':
                return dict.__getitem__(self, '_id')
            raise


class DocumentQuery(BaseDocumentQuery):