class_docstr: Base class for the downloaders
class_docstr_tok: ["Base","class","for","the","downloaders"]
docstr: Verify that download finished correctly
docstr_tok: ["Verify","that","download","finished","correctly"]
code: def _verify_download(
      self, url, downloaded_size, target_size, file_=None, content=None
  ):
      """Verify that download finished correctly"""
  
      if (
          (
              self.authenticator
              and downloaded_size < self._DOWNLOAD_SIZE_TO_VERIFY_AUTH
          )
          and hasattr(self.authenticator, "failure_re")
          and self.authenticator.failure_re
      ):
          assert hasattr(
              self.authenticator, "check_for_auth_failure"
          ), (
              "%s has failure_re defined but no check_for_auth_failure"
              % self.authenticator
          )
  
          if file_:
              # just read bytes and pass to check_for_auth_failure which
              # will then encode regex into bytes (assuming utf-8 though)
              with open(file_, "rb") as fp:
                  content = fp.read(self._DOWNLOAD_SIZE_TO_VERIFY_AUTH)
          else:
              assert content is not None
  
          self.authenticator.check_for_auth_failure(
              content, "Download of the url %s has failed: " % url
          )
  
      if target_size and target_size != downloaded_size:
          raise (
              IncompleteDownloadError
              if target_size > downloaded_size
              else UnaccountedDownloadError
          )(
              "Downloaded size %d differs from originally announced %d"
              % (downloaded_size, target_size)
          )
  
imports: import msgpack
  import os
  import sys
  import time
  from abc import ABCMeta, abstractmethod
  import os.path
  from os.path import exists, join, isdir
  from ..None import cfg
  from ..ui import ui
  from ..utils import auto_repr, ensure_unicode, unlink
  from .credentials import CompositeCredential
  from datalad.downloaders import CREDENTIAL_TYPES
  from ..support.exceptions import AccessDeniedError, AccessPermissionExpiredError, AnonymousAccessDeniedError, CapturedException, DownloadError, IncompleteDownloadError, UnaccountedDownloadError
  from ..support.locking import InterProcessLock, try_lock, try_lock_informatively
  from logging import getLogger
label_desc: Use image node_id 8 for calling the BaseDownloader obj's underlying member method code with example usage: obj._verify_download(url, downloaded_size, target_size, file_, content) without return types