code: def parselinenos(spec: str, total: int) -> list[int]:
      """Parse a line number spec (such as "1,2,4-6") and return a list of
      wanted line numbers.
      """
      items = []
      parts = spec.split(",")
      for part in parts:
          try:
              begend = part.strip().split("-")
              if begend == ["", ""]:
                  raise ValueError
              if len(begend) == 1:
                  items.append(int(begend[0]) - 1)
              elif len(begend) == 2:
                  start = int(
                      begend[0] or 1
                  )  # left half open (cf. -10)
                  end = int(
                      begend[1] or max(start, total)
                  )  # right half open (cf. 10-)
                  if start > end:  # invalid range (cf. 10-1)
                      raise ValueError
                  items.extend(range(start - 1, end))
              else:
                  raise ValueError
          except ValueError as exc:
              msg = f"invalid line number spec: {spec!r}"
              raise ValueError(msg) from exc
  
      return items
  
imports: from __future__ import annotations
  import hashlib
  import os
  import posixpath
  import re
  from importlib import import_module
  from os import path
  from typing import IO, Any
  from urllib.parse import parse_qsl, quote_plus, urlencode, urlsplit, urlunsplit
  from sphinx.errors import ExtensionError, FiletypeNotFoundError
  from sphinx.locale import __
  from sphinx.util import display
  from sphinx.util import exceptions
  from sphinx.util import http_date
  from sphinx.util import index_entries
  from sphinx.util import logging
  from sphinx.util import osutil
  from sphinx.util.console import strip_colors
  from sphinx.util.matching import patfilter
  from sphinx.util.nodes import caption_ref_re, explicit_title_re, nested_parse_with_titles, split_explicit_title
  from sphinx.util.osutil import SEP, copyfile, copytimes, ensuredir, make_filename, mtimes_of_files, os_path, relative_uri
label_desc: Use image node_id 5 for calling a global function with example usage: parselinenos(spec, total) and returns: items