def _check_valid_remote_asset()

in tools/validator.py [0:0]


  def _check_valid_remote_asset(self, remote_archive: str) -> None:
    """Checks whether the remote archive contains valid SavedModel files.

    Args:
      remote_archive: URL pointing to the remote archive.

    Raises:
      MarkdownDocumentationError:
        - if the remote file is no valid tarfile.
        - if a file name within the tarfile is invalid since it e.g. starts with
          a dot.
        - if no saved_model.pb(txt) file is contained in the archive.
        - if the contained saved_model.pb(txt) file cannot be loaded into a
          SavedModel proto.
    """
    valid_saved_model_proto_found = False
    with urllib.request.urlopen(remote_archive) as url_contents:
      try:
        with tarfile.open(fileobj=url_contents, mode="r|gz") as tar:
          for tar_member in tar:
            if not tar_member.isfile():
              continue
            normalized_path = os.path.normpath(tar_member.name)  # Strip './'.
            normalized_name = os.path.basename(normalized_path)
            _validate_file_name(normalized_path)
            if normalized_name == tf.saved_model.SAVED_MODEL_FILENAME_PB:
              _check_that_saved_model_pb_parses(tar, tar_member)
              valid_saved_model_proto_found = True
            elif normalized_name == tf.saved_model.SAVED_MODEL_FILENAME_PBTXT:
              _check_that_saved_model_pbtxt_parses(tar, tar_member)
              valid_saved_model_proto_found = True
      except tarfile.ReadError as e:
        raise MarkdownDocumentationError(f"Could not read tarfile: {e}") from e
      if not valid_saved_model_proto_found:
        raise MarkdownDocumentationError(
            f"The model from {remote_archive} does not contain a valid "
            "saved_model.pb or saved_model.pbtxt file. Please make sure that "
            "the asset-path metadata points to a valid TF2 SavedModel or a TF1 "
            "Hub module as described on "
            "https://www.tensorflow.org/hub/exporting_tf2_saved_model.")