# Path: dbcollection/core/exceptions.py
# class GoogleDriveFileIdDoesNotExist(Exception):
#     """Google drive's file id does not exist."""
#     pass
# 
# class InvalidURLDownloadSource(Exception):
#     """The url source is invalid/undefined."""
#     pass
# 
# class MD5HashNotEqual(Exception):
#     """The MD5 hashes are not equal."""
#     pass
# 
# class URLDoesNotExist(Exception):
#     """URL path does not exist."""
#     pass


import os
import hashlib
import shutil
import tempfile
import requests
import patoolib
import progressbar
from dbcollection.core.exceptions import (
    GoogleDriveFileIdDoesNotExist,
    InvalidURLDownloadSource,
    MD5HashNotEqual,
    URLDoesNotExist,
)
        Returns
        ------
        str
            File name + path of the temporary file.

        """
        filename_dir = os.path.dirname(filename)
        (fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=filename, dir=filename_dir)
        os.close(fd)
        os.unlink(tmpfile)
        return tmpfile

    def md5_checksum(self, filename, md5hash):
        """Check file integrity using a checksum.

        Parameters
        ----------
        filename : str
            File path + name of the downloaded url.
        md5hash : str
            Md5 hash string.

        Raises
        ------
        MD5HashNotEqual
            MD5 hash checksum do not match.

        """
        file_hash = self.get_file_hash(filename)
        if not file_hash == md5hash:

# Path: dbcollection/core/exceptions.py
# class GoogleDriveFileIdDoesNotExist(Exception):
#     """Google drive's file id does not exist."""
#     pass
# 
# class InvalidURLDownloadSource(Exception):
#     """The url source is invalid/undefined."""
#     pass
# 
# class MD5HashNotEqual(Exception):
#     """The MD5 hashes are not equal."""
#     pass
# 
# class URLDoesNotExist(Exception):
#     """URL path does not exist."""
#     pass


# Path: dbcollection/utils/url.py
import os
import hashlib
import shutil
import tempfile
import requests
import patoolib
import progressbar
from dbcollection.core.exceptions import (
    GoogleDriveFileIdDoesNotExist,
    InvalidURLDownloadSource,
    MD5HashNotEqual,
    URLDoesNotExist,
)

        Returns
        ------
        str
            File name + path of the temporary file.

        """
        filename_dir = os.path.dirname(filename)
        (fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=filename, dir=filename_dir)
        os.close(fd)
        os.unlink(tmpfile)
        return tmpfile

    def md5_checksum(self, filename, md5hash):
        """Check file integrity using a checksum.

        Parameters
        ----------
        filename : str
            File path + name of the downloaded url.
        md5hash : str
            Md5 hash string.

        Raises
        ------
        MD5HashNotEqual
            MD5 hash checksum do not match.

        """
        file_hash = self.get_file_hash(filename)
        if not file_hash == md5hash:

            raise MD5HashNotEqual("MD5 checksums do not match: {} != {}".format(md5hash, file_hash))