code: def download(
      url, fname=None, dirname=None, overwrite=False, retries=5
  ):
      """Download an given URL
  
      Parameters
      ----------
  
      url : str
          URL to download
      fname : str, optional
          filename of the downloaded file. If None, then will guess a filename
          from url.
      dirname : str, optional
          output directory name. If None, then guess from fname or use the current
          directory
      overwrite : bool, optional
          Default is false, which means skipping download if the local file
          exists. If true, then download the url to overwrite the local file if
          exists.
      retries : integer, default 5
          The number of times to attempt the download in case of failure or non 200 return codes
  
      Returns
      -------
      str
          The filename of the downloaded file
      """
  
      assert retries >= 0, "Number of retries should be at least 0"
  
      if fname is None:
          fname = url.split("/")[-1]
  
      if dirname is None:
          dirname = os.path.dirname(fname)
      else:
          fname = os.path.join(dirname, fname)
      if dirname != "":
          if not os.path.exists(dirname):
              try:
                  logging.info("create directory %s", dirname)
                  os.makedirs(dirname)
              except OSError as exc:
                  if exc.errno != errno.EEXIST:
                      raise OSError("failed to create " + dirname)
  
      if not overwrite and os.path.exists(fname):
          logging.info("%s exists, skipping download", fname)
          return fname
  
      while retries + 1 > 0:
          # Disable pyling too broad Exception
          # pylint: disable=W0703
          try:
              r = requests.get(url, stream=True)
              assert r.status_code == 200, f"failed to open {url}"
              with open(fname, "wb") as f:
                  for chunk in r.iter_content(chunk_size=1024):
                      if chunk:  # filter out keep-alive new chunks
                          f.write(chunk)
                  break
          except Exception as e:
              retries -= 1
              if retries <= 0:
                  raise e
  
              print(
                  "download failed, retrying, {} attempt{} left".format(
                      retries, "s" if retries > 1 else ""
                  )
              )
      logging.info("downloaded %s into %s successfully", url, fname)
      return fname
  
imports: import logging
  import argparse
  import requests
  import errno
  import os
label_desc: Use image node_id 1 for calling a global function with example usage: download(url, fname, dirname, overwrite, retries) and returns: fname, fname