# Path: BAC0/core/io/IOExceptions.py
# class RemovedPointException(Exception):
#     """
#     When defining a device from DB it may not be identical to the
#     actual device.
#     """
# 
#     pass
# 
# class NoResponseFromController(Exception):
#     """
#     This exception is used when trying to read or write and there is not answer.
#     """
# 
#     pass


import pickle
import os.path
import sqlite3
import contextlib
    import pandas as pd
    from pandas.io import sql
    from pandas.core.base import DataError
        from pandas import Timestamp
        from pandas.lib import Timestamp
from ..core.io.IOExceptions import RemovedPointException, NoResponseFromController
            )
        else:
            return df

    def save(self, filename=None, resampling=None):
        """
        Save the point histories to sqlite3 database.
        Save the device object properties to a pickle file so the device can be reloaded.

        Resampling : valid Pandas resampling frequency. If 0 or False, dataframe will not be resampled on save.
        """
        if not _PANDAS:
            self._log.error("Pandas is required to save to SQLite.")
            return

        if filename:
            if ".db" in filename:
                filename = filename.split(".")[0]
            self.properties.db_name = filename
        else:
            self.properties.db_name = "Device_{}".format(self.properties.device_id)

        if resampling is None:
            resampling = self.properties.save_resampling

        # Does file exist? If so, append data

        def _df_to_backup():
            try:
                return self.backup_histories_df(resampling=resampling)

# Path: BAC0/core/io/IOExceptions.py
# class RemovedPointException(Exception):
#     """
#     When defining a device from DB it may not be identical to the
#     actual device.
#     """
# 
#     pass
# 
# class NoResponseFromController(Exception):
#     """
#     This exception is used when trying to read or write and there is not answer.
#     """
# 
#     pass


# Path: BAC0/db/sql.py
import pickle
import os.path
import sqlite3
import contextlib
    import pandas as pd
    from pandas.io import sql
    from pandas.core.base import DataError
        from pandas import Timestamp
        from pandas.lib import Timestamp
from ..core.io.IOExceptions import RemovedPointException, NoResponseFromController

            )
        else:
            return df

    def save(self, filename=None, resampling=None):
        """
        Save the point histories to sqlite3 database.
        Save the device object properties to a pickle file so the device can be reloaded.

        Resampling : valid Pandas resampling frequency. If 0 or False, dataframe will not be resampled on save.
        """
        if not _PANDAS:
            self._log.error("Pandas is required to save to SQLite.")
            return

        if filename:
            if ".db" in filename:
                filename = filename.split(".")[0]
            self.properties.db_name = filename
        else:
            self.properties.db_name = "Device_{}".format(self.properties.device_id)

        if resampling is None:
            resampling = self.properties.save_resampling

        # Does file exist? If so, append data

        def _df_to_backup():
            try:
                return self.backup_histories_df(resampling=resampling)

            except (DataError, NoResponseFromController):