class_docstr: Supports download and file check for Baidu Cloud links
class_docstr_tok: ["Supports","download","and","file","check","for","Baidu","Cloud","links"]
docstr: As paddle model stores all files in tar files, we need to extract them
  and get the newly extracted folder path. This function rewrites the base
  function to support the following situations:
  
  1. If the tar file is not downloaded, it will download the tar file,
      extract it to the target folder, delete the downloaded tar file,
      and return the folder path.
  2. If the extracted target folder is present, and all the necessary model
      files are present (specified in _TAR_FILE_NAME_LIST), it will
      return the folder path.
  3. If the tar file is downloaded, but the extracted target folder is not
      present (or it doesn't contain the necessary files in _TAR_FILE_NAME_LIST),
      it will extract the tar file to the target folder, delete the tar file,
      and return the folder path.
docstr_tok: ["As","paddle","model","stores","all","files","in","tar","files",",","we","need","to","extract","them","and","get","the","newly","extracted","folder","path",".","This","function","rewrites","the","base","function","to","support","the","following","situations",":","1",".","If","the","tar","file","is","not","downloaded",",","it","will","download","the","tar","file",",","extract","it","to","the","target","folder",",","delete","the","downloaded","tar","file",",","and","return","the","folder","path",".","2",".","If","the","extracted","target","folder","is","present",",","and","all","the","necessary","model","files","are","present","(","specified","in","_TAR_FILE_NAME_LIST",")",",","it","will","return","the","folder","path",".","3",".","If","the","tar","file","is","downloaded",",","but","the","extracted","target","folder","is","not","present","(","or","it","does","n't","contain","the","necessary","files","in","_TAR_FILE_NAME_LIST",")",",","it","will","extract","the","tar","file","to","the","target","folder",",","delete","the","tar","file",",","and","return","the","folder","path","."]
code: def _get_local_path(
      self,
      path: str,
      force: bool = False,
      cache_dir: Optional[str] = None,
      **kwargs: Any,
  ) -> str:
      """
      As paddle model stores all files in tar files, we need to extract them
      and get the newly extracted folder path. This function rewrites the base
      function to support the following situations:
  
      1. If the tar file is not downloaded, it will download the tar file,
          extract it to the target folder, delete the downloaded tar file,
          and return the folder path.
      2. If the extracted target folder is present, and all the necessary model
          files are present (specified in _TAR_FILE_NAME_LIST), it will
          return the folder path.
      3. If the tar file is downloaded, but the extracted target folder is not
          present (or it doesn't contain the necessary files in _TAR_FILE_NAME_LIST),
          it will extract the tar file to the target folder, delete the tar file,
          and return the folder path.
  
      """
      self._check_kwargs(kwargs)
      if (
          force
          or path not in self.cache_map
          or not os.path.exists(self.cache_map[path])
      ):
          logger = logging.getLogger(__name__)
          parsed_url = urlparse(path)
          dirname = os.path.join(
              get_cache_dir(cache_dir),
              os.path.dirname(parsed_url.path.lstrip("/")),
          )
          filename = path.split("/")[-1]
          if len(filename) > self.MAX_FILENAME_LEN:
              filename = filename[:100] + "_" + uuid.uuid4().hex
  
          cached = os.path.join(dirname, filename)
  
          if is_cached_folder_exists_and_valid(cached):
              # When the cached folder exists and valid, we don't need to redownload
              # the tar file.
              self.cache_map[path] = _get_untar_directory(cached)
  
          else:
              with file_lock(cached):
                  if not os.path.isfile(cached):
                      logger.info("Downloading {} ...".format(path))
                      cached = download(
                          path, dirname, filename=filename
                      )
  
                  if path.endswith(".tar"):
                      model_dir = _untar_model_weights(cached)
                      try:
                          os.remove(
                              cached
                          )  # remove the redundant tar file
                          # TODO: remove the .lock file .
                      except:
                          logger.warning(
                              f"Not able to remove the cached tar file {cached}"
                          )
  
              logger.info("URL {} cached in {}".format(path, model_dir))
              self.cache_map[path] = model_dir
  
      return self.cache_map[path]
  
imports: import os
  import logging
  from typing import Any, Optional
  from urllib.parse import urlparse
  import tarfile
  import uuid
  from iopath.common.file_io import PathHandler
  from iopath.common.file_io import HTTPURLHandler
  from iopath.common.file_io import get_cache_dir, file_lock
  from iopath.common.download import download
  from ..base_catalog import PathManager
label_desc: Use image node_id 3 for calling the PaddleModelURLHandler obj's underlying member method code with example usage: obj._get_local_path(path, force, cache_dir) and returns: self