class_docstr: Manages the download and extraction of files, as well as caching.
  
  Downloaded files are cached under `download_dir`. The file name of downloaded
   files follows pattern "{sanitized_url}{content_checksum}.{ext}". Eg:
   'cs.toronto.edu_kriz_cifar-100-pythonJDF[...]I.tar.gz'.
  
  While a file is being downloaded, it is placed into a directory following a
  similar but different pattern:
  "{sanitized_url}{url_checksum}.tmp.{uuid}".
  
  When a file is downloaded, a "{fname}.INFO.json" file is created next to it.
  This INFO file contains the following information:
  {"dataset_names": ["name1", "name2"],
   "urls": ["http://url.of/downloaded_file"]}
  
  Extracted files/dirs are stored under `extract_dir`. The file name or
  directory name is the same as the original name, prefixed with the extraction
  method. E.g.
   "{extract_dir}/TAR_GZ.cs.toronto.edu_kriz_cifar-100-pythonJDF[...]I.tar.gz".
  
  The function members accept either plain value, or values wrapped into list
  or dict. Giving a data structure will parallelize the downloads.
  
  Example of usage:
  
  ```
  # Sequential download: str -> str
  train_dir = dl_manager.download_and_extract('https://abc.org/train.tar.gz')
  test_dir = dl_manager.download_and_extract('https://abc.org/test.tar.gz')
  
  # Parallel download: list -> list
  image_files = dl_manager.download(
      ['https://a.org/1.jpg', 'https://a.org/2.jpg', ...])
  
  # Parallel download: dict -> dict
  data_dirs = dl_manager.download_and_extract({
     'train': 'https://abc.org/train.zip',
     'test': 'https://abc.org/test.zip',
  })
  data_dirs['train']
  data_dirs['test']
  ```
  
  For more customization on the download/extraction (ex: passwords, output_name,
  ...), you can pass a `tfds.download.Resource` as argument.
class_docstr_tok: ["Manages","the","download","and","extraction","of","files",",","as","well","as","caching",".","Downloaded","files","are","cached","under","`","download_dir","`",".","The","file","name","of","downloaded","files","follows","pattern","``","{","sanitized_url","}","{","content_checksum","}",".","{","ext","}","''",".","Eg",":","'cs.toronto.edu_kriz_cifar-100-pythonJDF","[","...","]","I.tar.gz","'",".","While","a","file","is","being","downloaded",",","it","is","placed","into","a","directory","following","a","similar","but","different","pattern",":","''","{","sanitized_url","}","{","url_checksum","}",".tmp.","{","uuid","}","''",".","When","a","file","is","downloaded",",","a","``","{","fname","}",".INFO.json","''","file","is","created","next","to","it",".","This","INFO","file","contains","the","following","information",":","{","``","dataset_names","''",":","[","``","name1","''",",","``","name2","''","]",",","``","urls","''",":","[","``","http",":","\/\/url.of\/downloaded_file","''","]","}","Extracted","files\/dirs","are","stored","under","`","extract_dir","`",".","The","file","name","or","directory","name","is","the","same","as","the","original","name",",","prefixed","with","the","extraction","method",".","E.g",".","``","{","extract_dir","}","\/TAR_GZ.cs.toronto.edu_kriz_cifar-100-pythonJDF","[","...","]","I.tar.gz","''",".","The","function","members","accept","either","plain","value",",","or","values","wrapped","into","list","or","dict",".","Giving","a","data","structure","will","parallelize","the","downloads",".","Example","of","usage",":","``","`","#","Sequential","download",":","str","-",">","str","train_dir","=","dl_manager.download_and_extract","(","'https",":","\/\/abc.org\/train.tar.gz","'",")","test_dir","=","dl_manager.download_and_extract","(","'https",":","\/\/abc.org\/test.tar.gz","'",")","#","Parallel","download",":","list","-",">","list","image_files","=","dl_manager.download","(","[","'https",":","\/\/a.org\/1.jpg","'",",","'https",":","\/\/a.org\/2.jpg","'",",","...","]",")","#","Parallel","download",":","dict","-",">","dict","data_dirs","=","dl_manager.download_and_extract","(","{","'train","'",":","'https",":","\/\/abc.org\/train.zip","'",",","'test","'",":","'https",":","\/\/abc.org\/test.zip","'",",","}",")","data_dirs","[","'train","'","]","data_dirs","[","'test","'","]","``","`","For","more","customization","on","the","download\/extraction","(","ex",":","passwords",",","output_name",",","...",")",",","you","can","pass","a","`","tfds.download.Resource","`","as","argument","."]
docstr: Download manager constructor.
  
  Args:
    download_dir: Path to directory where downloads are stored.
    extract_dir: Path to directory where artifacts are extracted.
    manual_dir: Path to manually downloaded/extracted data directory.
    manual_dir_instructions: Human readable instructions on how to prepare
      contents of the manual_dir for this dataset.
    url_infos: Urls info for the checksums.
    dataset_name: Name of dataset this instance will be used for. If provided,
      downloads will contain which datasets they were used for.
    force_download: If True, always [re]download.
    force_extraction: If True, always [re]extract.
    force_checksums_validation: If True, raises an error if an URL do not have
      checksums.
    register_checksums: If True, dl checksums aren't checked, but stored into
      file.
    register_checksums_path: Path were to save checksums. Should be set if
      register_checksums is True.
    verify_ssl: `bool`, defaults to True. If True, will verify certificate
      when downloading dataset.
    max_simultaneous_downloads: `int`, optional max number of simultaneous
      downloads.
  
  Raises:
    FileNotFoundError: Raised if the register_checksums_path does not exist.
code: def __init__(
      self,
      *,
      download_dir: epath.PathLike,
      extract_dir: Optional[epath.PathLike] = None,
      manual_dir: Optional[epath.PathLike] = None,
      manual_dir_instructions: Optional[str] = None,
      url_infos: Optional[Dict[str, checksums.UrlInfo]] = None,
      dataset_name: Optional[str] = None,
      force_download: bool = False,
      force_extraction: bool = False,
      force_checksums_validation: bool = False,
      register_checksums: bool = False,
      register_checksums_path: Optional[epath.PathLike] = None,
      verify_ssl: bool = True,
      max_simultaneous_downloads: Optional[int] = None,
  ):
      """Download manager constructor.
  
      Args:
        download_dir: Path to directory where downloads are stored.
        extract_dir: Path to directory where artifacts are extracted.
        manual_dir: Path to manually downloaded/extracted data directory.
        manual_dir_instructions: Human readable instructions on how to prepare
          contents of the manual_dir for this dataset.
        url_infos: Urls info for the checksums.
        dataset_name: Name of dataset this instance will be used for. If provided,
          downloads will contain which datasets they were used for.
        force_download: If True, always [re]download.
        force_extraction: If True, always [re]extract.
        force_checksums_validation: If True, raises an error if an URL do not have
          checksums.
        register_checksums: If True, dl checksums aren't checked, but stored into
          file.
        register_checksums_path: Path were to save checksums. Should be set if
          register_checksums is True.
        verify_ssl: `bool`, defaults to True. If True, will verify certificate
          when downloading dataset.
        max_simultaneous_downloads: `int`, optional max number of simultaneous
          downloads.
  
      Raises:
        FileNotFoundError: Raised if the register_checksums_path does not exist.
      """
      if register_checksums:
          if not register_checksums_path:
              raise ValueError(
                  "When register_checksums=True, register_checksums_path should be"
                  " set."
              )
          register_checksums_path = epath.Path(register_checksums_path)
          if not register_checksums_path.exists():
              # Create the file here to make sure user has write access before
              # starting downloads.
              register_checksums_path.touch()
          else:
              # Make sure the user has write access before downloading any files.
              # (e.g. TFDS installed by admin)
              register_checksums_path.write_text(
                  register_checksums_path.read_text()
              )
  
      download_dir = epath.Path(download_dir).expanduser()
      if extract_dir:
          extract_dir = epath.Path(extract_dir).expanduser()
      else:
          extract_dir = download_dir / "extracted"
      if manual_dir:
          manual_dir = epath.Path(manual_dir).expanduser()
  
      self._download_dir: epath.Path = download_dir
      self._extract_dir: epath.Path = extract_dir
      self._manual_dir: Optional[
          epath.Path
      ] = manual_dir  # pytype: disable=annotation-type-mismatch  # attribute-variable-annotations
      self._manual_dir_instructions = utils.dedent(
          manual_dir_instructions
      )
      self._download_dir.mkdir(parents=True, exist_ok=True)
      self._extract_dir.mkdir(parents=True, exist_ok=True)
  
      self._force_download = force_download
      self._force_extraction = force_extraction
      self._force_checksums_validation = force_checksums_validation
      self._register_checksums = register_checksums
      self._register_checksums_path = register_checksums_path
      self._verify_ssl = verify_ssl
      self._max_simultaneous_downloads = max_simultaneous_downloads
      self._dataset_name = dataset_name
  
      # All known URLs: {url: UrlInfo(size=, checksum=)}
      self._url_infos = checksums.get_all_url_infos()
      if url_infos is not None:
          self._url_infos.update(url_infos)
  
      # To record what is being used: {url: UrlInfo(size, checksum, filename)}
      self._recorded_url_infos: Dict[str, checksums.UrlInfo] = {}
      # These attributes are lazy-initialized since they must be cleared when this
      # object is pickled for Beam. They are then recreated on each worker.
      self.__downloader = None
      self.__extractor = None
      # Executor to avoid blocking other download/extractions when running I/O
      # operations (reading/renaming download file).
      # Only use a single thread as the read/ops are locked by the
      # `build_synchronize_decorator`.
      # Note: This thread is in additions of the download and extraction
      # executors threads.
      self._executor = concurrent.futures.ThreadPoolExecutor(1)
  
imports: from __future__ import annotations
  import concurrent.futures
  import dataclasses
  import functools
  import hashlib
  import typing
  from typing import Any, Dict, Iterator, Optional, Tuple, Union
  import uuid
  from absl import logging
  from etils import epath
  import promise
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.download import checksums
  from tensorflow_datasets.core.download import downloader
  from tensorflow_datasets.core.download import extractor
  from tensorflow_datasets.core.download import kaggle
  from tensorflow_datasets.core.download import resource
  from tensorflow_datasets.core.download import util
  from tensorflow_datasets.core.utils import shard_utils
  from tensorflow_datasets.core.utils import tree_utils
  from tensorflow_datasets.core.utils import type_utils
label_desc: Use image node_id 1 to create a new DownloadManager object from inherited base classes: object with example: obj = DownloadManager()