class_docstr: Special custom remote allowing to obtain files from archives
  
  Archives must be under annex'ed themselves.
docstr: Given a key, yield akey, afile pairs
  
  if `sorted`, then first those which have extracted version in local
  cache will be yielded
  
  Gets determined based on urls for datalad archives
  
  Made "generators all the way" as an exercise but also to delay any
  checks etc until really necessary.
code: def _gen_akey_afiles(self, key, sorted=False, unique_akeys=True):
      """Given a key, yield akey, afile pairs
  
      if `sorted`, then first those which have extracted version in local
      cache will be yielded
  
      Gets determined based on urls for datalad archives
  
      Made "generators all the way" as an exercise but also to delay any
      checks etc until really necessary.
      """
      # we will need all URLs anyways later on ATM, so lets list() them
      # Anyways here we have a single scheme (archive) so there is not
      # much optimization possible
      urls = list(self.gen_URLS(key))
  
      akey_afiles = [
          self._parse_url(url)[:2] for url in urls  # skip size
      ]
  
      if unique_akeys:
          akey_afiles = unique(akey_afiles, key=itemgetter(0))
  
      if not sorted:
          for pair in akey_afiles:
              yield pair
          return
  
      # Otherwise we will go through each one
  
      # multiple URLs are available so we need to figure out which one
      # would be most efficient to "deal with"
      akey_afile_paths = (
          (
              (akey, afile),
              self.get_contentlocation(
                  akey, absolute=True, verify_exists=False
              ),
          )
          for akey, afile in akey_afiles
      )
  
      # by default get_contentlocation would return empty result for a key
      # which is not available locally.  But we could still have extracted
      # archive in the cache.  So we need pretty much get first all possible
      # and then only remove those which aren't present locally.  So
      # verify_exists was added
      yielded = set()
      akey_afile_paths_ = []
  
      # utilize cache to check which archives might already be present in the
      # cache
      for akey_afile, akey_path in akey_afile_paths:
          if akey_path and self.cache[akey_path].is_extracted:
              yield akey_afile
              yielded.add(akey_afile)
          akey_afile_paths_.append((akey_afile, akey_path))
  
      # replace generators with already collected ones into a list.  The idea
      # that in many cases we don't even need to create a full list and that
      # initial single yield would be enough, thus we don't need to check
      # locations etc for every possible hit
      akey_afile_paths = akey_afile_paths_
  
      # if not present in the cache -- check which are present
      # locally and choose that one to use, so it would get extracted
      for akey_afile, akey_path in akey_afile_paths:
          if akey_path and op.exists(akey_path):
              yielded.add(akey_afile)
              yield akey_afile
  
      # So no archive is present either in the cache or originally under
      # annex XXX some kind of a heuristic I guess is to use last_url ;-)
      if (
          self._last_url
          and self._last_url in urls
          and (len(urls) == len(akey_afiles))
      ):
          akey_afile, _ = akey_afile_paths[urls.index(self._last_url)]
          yielded.add(akey_afile)
          yield akey_afile
  
      for akey_afile, _ in akey_afile_paths:
          if akey_afile not in yielded:
              yield akey_afile
  
imports: import logging
  import os
  import os.path
  import shutil
  from operator import itemgetter
  from pathlib import Path
  from urllib.parse import urlparse
  from annexremote import UnsupportedRequest
  from datalad.consts import ARCHIVES_SPECIAL_REMOTE
  from datalad.customremotes import RemoteError
  from datalad.customremotes.main import main
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.archives import ArchivesCache
  from datalad.support.cache import DictCache
  from datalad.support.exceptions import CapturedException
  from datalad.support.locking import lock_if_check_fails
  from datalad.support.network import URL
  from datalad.utils import ensure_bytes, get_dataset_root, getpwd, unique, unlink
  from .base import AnnexCustomRemote
label_desc: Use image node_id 6 for calling the ArchiveAnnexCustomRemote obj's underlying member method code with example usage: obj._gen_akey_afiles(key, sorted, unique_akeys) without return types