# Path: sacredboard/app/data/errors.py
# class DataSourceError(Exception):
#     """Error when accessing the data source."""
# 
#     def __init__(self, *args, **kwargs):
#         """Error when accessing the data source."""
#         Exception.__init__(self, *args, **kwargs)
# 
# Path: sacredboard/app/data/pymongo/mongocursor.py
# class MongoDbCursor(Cursor):
#     """Implements Cursor for mongodb."""
# 
#     def __init__(self, mongodb_cursor):
#         """Initialize a MongoDB cursor."""
#         self.mongodb_cursor = mongodb_cursor
# 
#     def count(self):
#         """Return the number of items in this cursor."""
#         return self.mongodb_cursor.count()
# 
#     def __iter__(self):
#         """Iterate over runs."""
#         return self.mongodb_cursor


import pymongo
from pymongo.errors import InvalidName
from sacredboard.app.data import DataSourceError
from .mongocursor import MongoDbCursor
            cursor = cursor.limit(limit)
        return MongoDbCursor(cursor)

    def delete_record(self, collection_name, query):
        """Delete record matching the given MongoDB query."""
        return self._get_collection(collection_name).remove(query)

    def _get_database(self, database_name):
        """
        Get PyMongo client pointing to the current database.

        :return: MongoDB client of the current database.
        :raise DataSourceError
        """
        try:
            return self._client[database_name]
        except InvalidName as ex:
            raise DataSourceError("Cannot connect to database %s!"
                                  % self._database) from ex

    def _get_collection(self, collection_name):
        """
        Get PyMongo client pointing to the current DB and the given collection.

        :return: MongoDB client of the current database and given collection.
        :raise DataSourceError
        """
        try:
            return self._database[collection_name]
        except InvalidName as ex:

# Path: sacredboard/app/data/errors.py
# class DataSourceError(Exception):
#     """Error when accessing the data source."""
# 
#     def __init__(self, *args, **kwargs):
#         """Error when accessing the data source."""
#         Exception.__init__(self, *args, **kwargs)
# 
# Path: sacredboard/app/data/pymongo/mongocursor.py
# class MongoDbCursor(Cursor):
#     """Implements Cursor for mongodb."""
# 
#     def __init__(self, mongodb_cursor):
#         """Initialize a MongoDB cursor."""
#         self.mongodb_cursor = mongodb_cursor
# 
#     def count(self):
#         """Return the number of items in this cursor."""
#         return self.mongodb_cursor.count()
# 
#     def __iter__(self):
#         """Iterate over runs."""
#         return self.mongodb_cursor


# Path: sacredboard/app/data/pymongo/genericdao.py
import pymongo
from pymongo.errors import InvalidName
from sacredboard.app.data import DataSourceError
from .mongocursor import MongoDbCursor

            cursor = cursor.limit(limit)
        return MongoDbCursor(cursor)

    def delete_record(self, collection_name, query):
        """Delete record matching the given MongoDB query."""
        return self._get_collection(collection_name).remove(query)

    def _get_database(self, database_name):
        """
        Get PyMongo client pointing to the current database.

        :return: MongoDB client of the current database.
        :raise DataSourceError
        """
        try:
            return self._client[database_name]
        except InvalidName as ex:
            raise DataSourceError("Cannot connect to database %s!"
                                  % self._database) from ex

    def _get_collection(self, collection_name):
        """
        Get PyMongo client pointing to the current DB and the given collection.

        :return: MongoDB client of the current database and given collection.
        :raise DataSourceError
        """
        try:
            return self._database[collection_name]
        except InvalidName as ex:

            raise DataSourceError("Cannot access MongoDB collection %s!"