code: def build_xml(rows: list[tuple[str, str, set[str | None]]]) -> None:
      cnt = Counter(
          outcome for _, _, outcomes in rows for outcome in outcomes
      )
      timestamp = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
  
      # We could have used ElementTree but it feels like overkill here
      print('<?xml version="1.0" encoding="utf-8"?>')
      print("<testsuites>")
      print(
          '<testsuite name="distributed" '
          f'errors="{cnt["ERROR"]}" failures="{cnt["FAILED"] + cnt[None]}" '
          f'skipped="{cnt["SKIPPED"] + cnt["XFAIL"]}" tests="{sum(cnt.values())}" '
          f'time="0.0" timestamp="{timestamp}" hostname="">'
      )
  
      for clsname, tname, outcomes in rows:
          clsname = html.escape(clsname)
          tname = html.escape(tname)
          print(
              f'<testcase classname="{clsname}" name="{tname}" time="0.0"',
              end="",
          )
          if outcomes == {"PASSED"}:
              print(" />")
          elif outcomes == {"FAILED"}:
              print('><failure message=""></failure></testcase>')
          elif outcomes == {None}:
              print(
                  '><failure message="pytest-timeout exceeded"></failure></testcase>'
              )
          elif outcomes == {"ERROR"}:
              print(
                  '><error message="failed on setup"></error></testcase>'
              )
          elif outcomes == {"PASSED", "ERROR"}:
              print(
                  '><error message="failed on teardown"></error></testcase>'
              )
          elif outcomes == {"FAILED", "ERROR"}:
              print(
                  '><failure message=""></failure></testcase>\n'
                  f'<testcase classname="{clsname}" name="{tname}" time="0.0">'
                  '<error message="failed on teardown"></error></testcase>'
              )
          elif outcomes == {"SKIPPED"}:
              print(
                  '><skipped type="pytest.skip" message="skip"></skipped></testcase>'
              )
          elif outcomes == {"XFAIL"}:
              print(
                  '><skipped type="pytest.xfail" message="xfail"></skipped></testcase>'
              )
          else:  # pragma: nocover
              # This should be unreachable. We would normally raise ValueError, except
              # that a crash in this script would be pretty much invisible.
              print(
                  f' />\n<testcase classname="parse_stdout" name="build_xml" time="0.0">'
                  f'><failure message="Unexpected {outcomes=}"></failure></testcase>'
              )
  
      print("</testsuite>")
      print("</testsuites>")
  
file_path: distributed/continuous_integration/scripts/parse_stdout.py
imports: from __future__ import annotations
  import html
  import re
  import sys
  from collections import Counter, defaultdict
  from collections.abc import Iterable
  from datetime import datetime
label_desc: Use image node_id 2 for calling a global function with example usage: build_xml(rows) without return types