code: def check_download_external_url(
      url, failed_str, success_str, d, url_final=None, check_mtime=True
  ):
      fpath = opj(d, get_url_straight_filename(url))
      providers = get_test_providers(
          url
      )  # url for check of credentials
      provider = providers.get_provider(url)
      downloader = provider.get_downloader(url)
  
      # we will load/fetch binary blobs
      success_bytes, failed_bytes = None, None
      if success_str is not None:
          success_bytes = success_str.encode()
      if failed_str is not None:
          failed_bytes = failed_str.encode()
  
      # Download way
      with swallow_outputs() as cmo:
          downloaded_path = downloader.download(url, path=d)
      assert_equal(fpath, downloaded_path)
      content = read_file(fpath, decode=False)
      if success_bytes is not None:
          assert_in(success_bytes, content)
      if failed_str is not None:
          assert_false(failed_bytes in content)
  
      # And if we specify size
      for s in [1, 2]:
          with swallow_outputs() as cmo:
              downloaded_path_ = downloader.download(
                  url, path=d, size=s, overwrite=True
              )
          # should not be affected
          assert_equal(downloaded_path, downloaded_path_)
          content_ = read_file(fpath, decode=False)
          assert_equal(len(content_), s)
          assert_equal(content_, content[:s])
  
      # Fetch way
      content = downloader.fetch(url, decode=False)
      if success_bytes is not None:
          assert_in(success_bytes, content)
      if failed_bytes is not None:
          assert_false(failed_bytes in content)
  
      # And if we specify size
      for s in [1, 2]:
          with swallow_outputs() as cmo:
              content_ = downloader.fetch(url, size=s, decode=False)
          assert_equal(len(content_), s)
          assert_equal(content_, content[:s])
  
      # Verify status
      status = downloader.get_status(url)
      assert isinstance(status, FileStatus)
      if not url.startswith("ftp://") and check_mtime:
          # TODO introduce support for mtime into requests_ftp?
          assert status.mtime
      assert status.size
  
      # Verify possible redirections
      if url_final is None:
          url_final = url
      assert_equal(downloader.get_target_url(url), url_final)
  
imports: import builtins
  import os
  import re
  import time
  from calendar import timegm
  from os.path import join
  from datalad.downloaders.tests.utils import get_test_providers
  from datalad.support.network import download_url, get_url_straight_filename
  from datalad.utils import ensure_unicode
  from ...support.exceptions import AccessFailedError
  from ..base import BaseDownloader, DownloadError, IncompleteDownloadError, NoneAuthenticator
  from ..credentials import LORIS_Token, Token, UserPassword
  from ..http import HTMLFormAuthenticator, HTTPBaseAuthenticator, HTTPBearerTokenAuthenticator, HTTPDownloader, process_www_authenticate
  from unittest.mock import patch
  from ...support.exceptions import AccessDeniedError, AnonymousAccessDeniedError
  from ...support.network import get_url_disposition_filename
  from ...support.status import FileStatus
  from ...tests.utils_pytest import SkipTest, assert_equal, assert_false, assert_greater, assert_in, assert_not_in, assert_raises, known_failure_githubci_win, ok_file_has_content, serve_path_via_http, skip_if, skip_if_no_network, swallow_logs, swallow_outputs, use_cassette, with_fake_cookies_db, with_memory_keyring, with_tempfile, with_testsui, with_tree, without_http_proxy
  from ...utils import read_file
label_desc: Use image node_id 7 for calling a global function with example usage: check_download_external_url(url, failed_str, success_str, d, url_final, check_mtime) without return types