If file is not already at 'path', then download from 'url' and put it
    there.

    If md5sum is provided, and 'path' exists, check that file matches the
    md5sum.  If not, re-download.
17462
def ensure_file(url, path, md5sum=None):
    

    if not os.path.isfile(path) or (md5sum and md5sum != file_md5(path)):
        download_file(url, path)
1220856
def _downloadfile(self, url, fname):
        '''  '''

        print("The file %s need to be download - Wait\n " %
              (fname.split('/')[-1]))
        urllib.urlretrieve(url, fname, self._report)
        print("\n The download of the file %s has succeded \n " %
              (fname.split('/')[-1]))
91423
def is_downloaded(self):
        
        if self.file_path is None:
            return False
        return os.path.exists(self.file_path)
604410
def _md5_sum_file(path):
    
    with Path(path).open('rb') as fhandle:
        md5sum = hashlib.md5()
        while True:
            data = fhandle.read(8192)
            if not data:
                break
            md5sum.update(data)
    return md5sum.hexdigest()
180610
def is_downloaded(self, file_path):
        
        if os.path.exists(file_path):
            self.chatbot.logger.info('File is already downloaded')
            return True

        return False
1048218
def _get_md5sum(self, fpath):
        """"""
        try:
            current_md5 = hashlib.md5()
            if isinstance(fpath, six.string_types) and os.path.exists(fpath):
                with open(fpath, "rb") as fh:
                    for chunk in self._read_chunks(fh):
                        current_md5.update(chunk)

            elif (fpath.__class__.__name__ in ["StringIO", "StringO"] or
                  isinstance(fpath, IOBase)):
                for chunk in self._read_chunks(fpath):
                    current_md5.update(chunk)
            else:
                return ""
            return current_md5.hexdigest()
        except Exception:
            msg = ("Failed to calculate the image's md5sum")
            LOG.error(msg)
            raise exception.SDKImageOperationError(rs=3)
861096
def download(self, filepath, version=None):
        '''
        
        '''

        version = _process_version(self, version)

        dirname, filename = os.path.split(
            os.path.abspath(os.path.expanduser(filepath)))

        assert os.path.isdir(dirname), 'Directory  not found: "{}"'.format(
            dirname)

        local = OSFS(dirname)

        version_hash = self.get_version_hash(version)

        # version_check returns true if fp's hash is current as of read
        def version_check(chk):
            return chk['checksum'] == version_hash

        if os.path.exists(filepath):
            if version_check(self.api.hash_file(filepath)):
                return

        read_path = self.get_version_path(version)

        with data_file._choose_read_fs(
                self.authority,
                self.api.cache,
                read_path,
                version_check,
                self.api.hash_file) as read_fs:

            fs.utils.copyfile(
                read_fs,
                read_path,
                local,
                filename)
658213
def check_datafile_present_and_download(path, backup_url=None):
    
    path = Path(path)
    if path.is_file(): return True
    if backup_url is None: return False
    logg.info('try downloading from url\n' + backup_url + '\n' +
              '... this may take a while but only happens once')
    if not path.parent.is_dir():
        logg.info('creating directory', str(path.parent) + '/', 'for saving data')
        path.parent.mkdir(parents=True)
    from urllib.request import urlretrieve
    urlretrieve(backup_url, str(path), reporthook=download_progress)
    logg.info('')
    return True
208292
def _download(self, dstFile):
        
        for attempt in retry(predicate=lambda e: isinstance(e, HTTPError) and e.code == 400):
            with attempt:
                with closing(urlopen(self.url)) as content:
                    buf = content.read()
        contentHash = hashlib.md5(buf)
        assert contentHash.hexdigest() == self.contentHash
        dstFile.write(buf)
299226
def download(url, filename, overwrite = False):
	'''  '''

	from requests import get
	from os.path import exists

	debug('Downloading ' + unicode(url) + '...')
	data = get(url)
	if data.status_code == 200:
		if not exists(filename) or overwrite:
			f = open(filename, 'wb')
			f.write(data.content)
			f.close()
		return True
	return False
514869
def download(self, output_dir, url, overwrite):
        
        tmp = self.url2tmp(output_dir, url)
        if os.path.isfile(tmp) and not overwrite:
            logging.info("File {0} already exists. Skipping download.".format(tmp))
            return tmp
        f = open(tmp, 'wb')
        logging.info("Downloading {0}".format(url))
        res = requests.get(url, stream=True)
        if res.status_code != 200:
            # failed to download, cleanup and raise exception
            f.close()
            os.remove(tmp)
            error = "{0}\n\nFailed to download < {0} >".format(res.content, url)
            raise IOError(error)
        for block in res.iter_content(1024):
            f.write(block)
        f.close()
        return tmp
1298101
def _download(self, resource):
    """"""
    if isinstance(resource, six.string_types):
      resource = resource_lib.Resource(url=resource)
    url = resource.url
    if url in self._sizes_checksums:
      expected_sha256 = self._sizes_checksums[url][1]
      download_path = self._get_final_dl_path(url, expected_sha256)
      if not self._force_download and resource.exists_locally(download_path):
        logging.info('URL %s already downloaded: reusing %s.',
                     url, download_path)
        self._recorded_sizes_checksums[url] = self._sizes_checksums[url]
        return promise.Promise.resolve(download_path)
    # There is a slight difference between downloader and extractor here:
    # the extractor manages its own temp directory, while the DownloadManager
    # manages the temp directory of downloader.
    download_dir_path = os.path.join(
        self._download_dir,
        '%s.tmp.%s' % (resource_lib.get_dl_dirname(url), uuid.uuid4().hex))
    tf.io.gfile.makedirs(download_dir_path)
    logging.info('Downloading %s into %s...', url, download_dir_path)

    def callback(val):
      checksum, dl_size = val
      return self._handle_download_result(
          resource, download_dir_path, checksum, dl_size)
    return self._downloader.download(url, download_dir_path).then(callback)
1161245
def __download(self, url):
        
        local_filename = urllib.parse.quote_plus(url)
        local_filepath = os.path.join(self.__local_download_dir_warc, local_filename)

        if os.path.isfile(local_filepath) and self.__reuse_previously_downloaded_files:
            self.__logger.info("found local file %s, not downloading again due to configuration", local_filepath)
            return local_filepath
        else:
            # cleanup
            try:
                os.remove(local_filepath)
            except OSError:
                pass

            # download
            self.__logger.info('downloading %s (local: %s)', url, local_filepath)
            urllib.request.urlretrieve(url, local_filepath, reporthook=self.__on_download_progress_update)
            self.__logger.info('download completed, local file: %s', local_filepath)
            return local_filepath
559651
def md5sum(path):
    

    if path is None or len(path) == 0 or not os.path.exists(path):
        return None

    try:
        with open(path + '.md5sum') as f:
            md5 = f.read()
            if len(md5) == 32:
                return md5
    # Unicode error is when user rename an image to .md5sum ....
    except (OSError, UnicodeDecodeError):
        pass

    try:
        m = hashlib.md5()
        with open(path, 'rb') as f:
            while True:
                buf = f.read(128)
                if not buf:
                    break
                m.update(buf)
        digest = m.hexdigest()
    except OSError as e:
        log.error("Can't create digest of %s: %s", path, str(e))
        return None

    try:
        with open('{}.md5sum'.format(path), 'w+') as f:
            f.write(digest)
    except OSError as e:
        log.error("Can't write digest of %s: %s", path, str(e))

    return digest
277536
def download(self, path, file):
        """"""

        resp = self._sendRequest("GET", path)
        if resp.status_code == 200:
            with open(file, "wb") as f:
                f.write(resp.content)
        else:
            raise YaDiskException(resp.status_code, resp.content)
391830
def maybe_download(url, filename):
  """"""
  if not os.path.exists(WORK_DIRECTORY):
    os.mkdir(WORK_DIRECTORY)
  filepath = os.path.join(WORK_DIRECTORY, filename)
  if not os.path.exists(filepath):
    filepath, _ = request.urlretrieve(url + filename, filepath)
    statinfo = os.stat(filepath)
    print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
  return filepath
1257587
def download_file(save_path, file_url):
    

    r = requests.get(file_url)  # create HTTP response object

    with open(save_path, 'wb') as f:
        f.write(r.content)

    return save_path