# Path: bamboo/config/db.py
# class Database(object):
#     """Container for the MongoDB client."""
# 
#     # MongoDB client default host and port
#     __client__ = MongoClient('localhost', 27017, w=1, j=False)
#     __db__ = None
# 
#     @classmethod
#     def create_db(cls, db_name):
#         """Create a database `db_name`.
# 
#         :param cls: The class to set a client on.
#         :param db_name: The name of the collection to create.
#         """
#         cls.__db__ = cls.__client__[db_name]
# 
#     @classmethod
#     def client(cls):
#         """Return the database client."""
#         return cls.__client__
# 
#     @classmethod
#     def db(cls, name=None):
#         """Create the database if it has not been created.
# 
#         If name is provided, create a new database.
# 
#         :param cls: The class to set the database for.
#         :param name: The name of the database to create, default None.
#         :returns: The created database.
#         """
#         if not cls.__db__ or name:
#             cls.create_db(name or settings.DATABASE_NAME)
#         return cls.__db__
# 
# Path: bamboo/core/frame.py
# BAMBOO_RESERVED_KEYS = [
#     DATASET_ID,
#     INDEX,
#     PARENT_DATASET_ID,
# ]
# 
# Path: bamboo/lib/decorators.py
# class classproperty(property):
#     """Declare properties for classes."""
# 
#     def __get__(self, cls, owner):
#         return self.fget.__get__(None, owner)()
# 
# Path: bamboo/lib/mongo.py
# def dict_for_mongo(_dict):
#     """Encode all keys in `_dict` for MongoDB."""
#     for key, value in _dict.items():
#         if _is_invalid_for_mongo(key):
#             del _dict[key]
#             key = key_for_mongo(key)
# 
#         if isinstance(value, list):
#             _dict[key] = [dict_for_mongo(obj) if isinstance(obj, dict) else obj
#                           for obj in value]
#         elif isinstance(value, dict):
#             _dict[key] = dict_for_mongo(value)
#         else:
#             _dict[key] = value_for_mongo(value)
# 
#     return _dict
# 
# def remove_mongo_reserved_keys(_dict):
#     """Remove any keys reserved for MongoDB from `_dict`.
# 
#     Check for `MONGO_ID` in stored dictionary.  If found replace
#     with unprefixed, if not found remove reserved key from dictionary.
# 
#     Args:
# 
#     :param _dict: Dictionary to remove reserved keys from.
# 
#     :returns: Dictionary with reserved keys removed.
#     """
#     if _dict.get(MONGO_ID_ENCODED):
#         _dict[MONGO_ID] = _dict.pop(MONGO_ID_ENCODED)
#     else:
#         # remove mongo reserved keys
#         del _dict[MONGO_ID]
# 
#     return _dict


from bamboo.config.db import Database
from bamboo.core.frame import BAMBOO_RESERVED_KEYS
from bamboo.lib.decorators import classproperty
from bamboo.lib.mongo import dict_for_mongo, remove_mongo_reserved_keys
    STATE_PENDING = 'pending'
    STATE_READY = 'ready'

    @property
    def state(self):
        return self.record[self.STATE]

    @property
    def error_message(self):
        return self.record.get(self.ERROR_MESSAGE)

    @property
    def is_pending(self):
        return self.state == self.STATE_PENDING

    @property
    def is_ready(self):
        return self.state == self.STATE_READY

    @property
    def record_ready(self):
        return self.record is not None and self.state == self.STATE_READY

    @property
    def clean_record(self):
        """Remove reserved keys from records."""
        _dict = {
            key: value for (key, value) in self.record.items() if not key in
            BAMBOO_RESERVED_KEYS
        }

# Path: bamboo/config/db.py
# class Database(object):
#     """Container for the MongoDB client."""
# 
#     # MongoDB client default host and port
#     __client__ = MongoClient('localhost', 27017, w=1, j=False)
#     __db__ = None
# 
#     @classmethod
#     def create_db(cls, db_name):
#         """Create a database `db_name`.
# 
#         :param cls: The class to set a client on.
#         :param db_name: The name of the collection to create.
#         """
#         cls.__db__ = cls.__client__[db_name]
# 
#     @classmethod
#     def client(cls):
#         """Return the database client."""
#         return cls.__client__
# 
#     @classmethod
#     def db(cls, name=None):
#         """Create the database if it has not been created.
# 
#         If name is provided, create a new database.
# 
#         :param cls: The class to set the database for.
#         :param name: The name of the database to create, default None.
#         :returns: The created database.
#         """
#         if not cls.__db__ or name:
#             cls.create_db(name or settings.DATABASE_NAME)
#         return cls.__db__
# 
# Path: bamboo/core/frame.py
# BAMBOO_RESERVED_KEYS = [
#     DATASET_ID,
#     INDEX,
#     PARENT_DATASET_ID,
# ]
# 
# Path: bamboo/lib/decorators.py
# class classproperty(property):
#     """Declare properties for classes."""
# 
#     def __get__(self, cls, owner):
#         return self.fget.__get__(None, owner)()
# 
# Path: bamboo/lib/mongo.py
# def dict_for_mongo(_dict):
#     """Encode all keys in `_dict` for MongoDB."""
#     for key, value in _dict.items():
#         if _is_invalid_for_mongo(key):
#             del _dict[key]
#             key = key_for_mongo(key)
# 
#         if isinstance(value, list):
#             _dict[key] = [dict_for_mongo(obj) if isinstance(obj, dict) else obj
#                           for obj in value]
#         elif isinstance(value, dict):
#             _dict[key] = dict_for_mongo(value)
#         else:
#             _dict[key] = value_for_mongo(value)
# 
#     return _dict
# 
# def remove_mongo_reserved_keys(_dict):
#     """Remove any keys reserved for MongoDB from `_dict`.
# 
#     Check for `MONGO_ID` in stored dictionary.  If found replace
#     with unprefixed, if not found remove reserved key from dictionary.
# 
#     Args:
# 
#     :param _dict: Dictionary to remove reserved keys from.
# 
#     :returns: Dictionary with reserved keys removed.
#     """
#     if _dict.get(MONGO_ID_ENCODED):
#         _dict[MONGO_ID] = _dict.pop(MONGO_ID_ENCODED)
#     else:
#         # remove mongo reserved keys
#         del _dict[MONGO_ID]
# 
#     return _dict


# Path: bamboo/models/abstract_model.py
from bamboo.config.db import Database
from bamboo.core.frame import BAMBOO_RESERVED_KEYS
from bamboo.lib.decorators import classproperty
from bamboo.lib.mongo import dict_for_mongo, remove_mongo_reserved_keys

    STATE_PENDING = 'pending'
    STATE_READY = 'ready'

    @property
    def state(self):
        return self.record[self.STATE]

    @property
    def error_message(self):
        return self.record.get(self.ERROR_MESSAGE)

    @property
    def is_pending(self):
        return self.state == self.STATE_PENDING

    @property
    def is_ready(self):
        return self.state == self.STATE_READY

    @property
    def record_ready(self):
        return self.record is not None and self.state == self.STATE_READY

    @property
    def clean_record(self):
        """Remove reserved keys from records."""
        _dict = {
            key: value for (key, value) in self.record.items() if not key in
            BAMBOO_RESERVED_KEYS
        }

        return remove_mongo_reserved_keys(_dict)