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: Validates/records checksums and renames final downloaded path.
code: def _register_or_validate_checksums(
      self,
      path: epath.Path,
      url: str,
      expected_url_info: Optional[checksums.UrlInfo],
      computed_url_info: Optional[checksums.UrlInfo],
      checksum_path: Optional[epath.Path],
      url_path: epath.Path,
  ) -> epath.Path:
      """Validates/records checksums and renames final downloaded path."""
      # `path` can be:
      # * Manually downloaded
      # * (cached) checksum_path
      # * (cached) url_path
      # * `tmp_dir/file` (downloaded path)
  
      if computed_url_info:
          # Used both in `.downloaded_size` and `_record_url_infos()`
          self._recorded_url_infos[url] = computed_url_info
  
      if self._register_checksums:
          if not computed_url_info:
              raise ValueError(
                  f"Cannot register checksums for {url}: no computed checksum. "
                  "--register_checksums with manually downloaded data not supported."
              )
          # Note:
          # * We save even if `expected_url_info == computed_url_info` as
          #   `expected_url_info` might have been loaded from another dataset.
          # * `register_checksums_path` was validated in `__init__` so this
          #   shouldn't fail.
          self._record_url_infos()
  
          # Checksum path should now match the new registered checksum (even if
          # checksums were previously registered)
          expected_url_info = computed_url_info
          checksum_path = self._get_dl_path(
              url, computed_url_info.checksum
          )
      else:
          # Eventually validate checksums
          # Note:
          # * If path is cached at `url_path` but cached
          #   `computed_url_info != expected_url_info`, a new download has
          #   been triggered (as _get_cached_path returns None)
          # * If path was downloaded but checksums don't match expected, then
          #   the download isn't cached (re-running build will retrigger a new
          #   download). This is expected as it might mean the downloaded file
          #   was corrupted. Note: The tmp file isn't deleted to allow inspection.
          _validate_checksums(
              url=url,
              path=path,
              expected_url_info=expected_url_info,
              computed_url_info=computed_url_info,
              force_checksums_validation=self._force_checksums_validation,
          )
  
      return self._rename_and_get_final_dl_path(
          url=url,
          path=path,
          expected_url_info=expected_url_info,
          computed_url_info=computed_url_info,
          checksum_path=checksum_path,
          url_path=url_path,
      )
  
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 10 for calling the DownloadManager obj's underlying member method code with example usage: obj._register_or_validate_checksums(path, url, expected_url_info, computed_url_info, checksum_path, url_path) and returns: self