class_docstr: Base for image providers: handle pathname and filename & URLs
class_docstr_tok: ["Base","for","image","providers",":","handle","pathname","and","filename","&","URLs"]
docstr: Cache a file that needs to be HTTP downloaded
  
  Return True if the file has been cached
docstr_tok: ["Cache","a","file","that","needs","to","be","HTTP","downloaded","Return","True","if","the","file","has","been","cached"]
code: def cache_file(self):
      """Cache a file that needs to be HTTP downloaded
  
      Return True if the file has been cached
      """
      if self.__cacheing_tried:
          return self.__is_cached
      self.__cacheing_tried = True
      #
      # Check to see if the pathname can be accessed as a directory
      # If so, handle normally
      #
      path = self.get_pathname()
      if len(path) == 0:
          filename = self.get_filename()
          if os.path.exists(filename):
              return False
          parsed_path = urllib.parse.urlparse(filename)
          url = filename
          if len(parsed_path.scheme) < 2:
              raise IOError(
                  "Test for access to file failed. File: %s" % filename
              )
      elif os.path.exists(path):
          return False
      else:
          parsed_path = urllib.parse.urlparse(path)
          url = "/".join((path, self.get_filename()))
          #
          # Scheme length == 0 means no scheme
          # Scheme length == 1 - probably DOS drive letter
          #
          if len(parsed_path.scheme) < 2:
              raise IOError(
                  "Test for access to directory failed. Directory: %s"
                  % path
              )
      if parsed_path.scheme == "file":
          self.__cached_file = url2pathname(path)
      elif is_numpy_file(self.__filename):
          #
          # urlretrieve uses the suffix of the path component of the URL
          # to name the temporary file, so we replicate that behavior
          #
          temp_dir = (
              cellprofiler_core.preferences.get_temporary_directory()
          )
          tempfd, temppath = tempfile.mkstemp(
              suffix=".npy", dir=temp_dir
          )
          self.__cached_file = temppath
          try:
              url = generate_presigned_url(url)
              self.__cached_file, headers = urllib.request.urlretrieve(
                  url, filename=temppath
              )
          finally:
              os.close(tempfd)
      else:
          from ....pipeline import ImageFile
  
          image_file = self.get_image_file()
          rdr_class = get_image_reader_class(
              image_file, volume=self.__volume
          )
          if (
              not rdr_class.supports_url()
              and parsed_path.scheme.lower() != "omero"
          ):
              cached_file = download_to_temp_file(image_file.url)
              if cached_file is None:
                  return False
              self.__cached_file = pathname2url(cached_file)
              self.__image_file = ImageFile(self.__cached_file)
          else:
              return False
      self.__is_cached = True
      return True
  
imports: import atexit
  import hashlib
  import logging
  import os
  import tempfile
  import urllib.parse
  import urllib.request
  import weakref
  import numpy
  import cellprofiler_core.preferences
  from .._abstract_image import AbstractImage
  from ..._image import Image
  from ....reader import get_image_reader, get_image_reader_class
  from ....utilities.image import is_numpy_file, download_to_temp_file
  from ....utilities.image import is_matlab_file
  from ....utilities.image import loadmat
  from ....utilities.image import load_data_file
  from ....utilities.image import generate_presigned_url
  from ....constants.image import FILE_SCHEME, PASSTHROUGH_SCHEMES
  from ....utilities.pathname import pathname2url, url2pathname
label_desc: Use image node_id 14 for calling the FileImage obj's underlying member method code with example usage: obj.cache_file() and returns: True, self, False, False, False, False