# Path: huacaya/storage/base.py
# class BucketBase(object):
#     def drop(self):
#         raise NotImplementedError
# 
#     def put(self, entity):
#         raise NotImplementedError
# 
#     def get(self, stub):
#         raise NotImplementedError
# 
#     def delete(self, stub):
#         raise NotImplementedError
# 
#     def update(self, entity):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get(item)
# 
# class StorageBase(object):
#     def create_bucket(self, name, index=()):
#         raise NotImplementedError
# 
#     def get_bucket(self, name):
#         raise NotImplementedError
# 
#     def drop(self, bucket):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get_bucket(item)


from .base import BucketBase, StorageBase
from pymongo.errors import OperationFailure
    def get_object(self, key):
        obj = self._collection.find_one({'key': key}, {'_id': False, 'key': False})
        if obj:
            return obj['content']

    def delete_object(self, key):
        self._collection.remove({'key': key})

    def find(self, fields):
        find_fields = {'content.%s' % k: v for k, v in fields.items()}
        for doc in self._collection.find(find_fields):
            yield doc

    def find_one(self, fields):
        find_fields = {'content.%s' % k: v for k, v in fields.items()}
        return self._collection.find_one(find_fields)

    def __getitem__(self, item):
        return self.get_object(item)

    def __contains__(self, item):
        return self._collection.find({'key': item}).count() > 0

    def __iter__(self):
        for doc in self._collection.find(fields={'key': True, '_id': False}):
            yield doc['key']

    def keys(self):
        return list(self)


# Path: huacaya/storage/base.py
# class BucketBase(object):
#     def drop(self):
#         raise NotImplementedError
# 
#     def put(self, entity):
#         raise NotImplementedError
# 
#     def get(self, stub):
#         raise NotImplementedError
# 
#     def delete(self, stub):
#         raise NotImplementedError
# 
#     def update(self, entity):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get(item)
# 
# class StorageBase(object):
#     def create_bucket(self, name, index=()):
#         raise NotImplementedError
# 
#     def get_bucket(self, name):
#         raise NotImplementedError
# 
#     def drop(self, bucket):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get_bucket(item)


# Path: huacaya/storage/mongo.py
from .base import BucketBase, StorageBase
from pymongo.errors import OperationFailure

    def get_object(self, key):
        obj = self._collection.find_one({'key': key}, {'_id': False, 'key': False})
        if obj:
            return obj['content']

    def delete_object(self, key):
        self._collection.remove({'key': key})

    def find(self, fields):
        find_fields = {'content.%s' % k: v for k, v in fields.items()}
        for doc in self._collection.find(find_fields):
            yield doc

    def find_one(self, fields):
        find_fields = {'content.%s' % k: v for k, v in fields.items()}
        return self._collection.find_one(find_fields)

    def __getitem__(self, item):
        return self.get_object(item)

    def __contains__(self, item):
        return self._collection.find({'key': item}).count() > 0

    def __iter__(self):
        for doc in self._collection.find(fields={'key': True, '_id': False}):
            yield doc['key']

    def keys(self):
        return list(self)


class MongoStorage(StorageBase):