<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse_failed_targets(test_registry, junit_xml_path, error_handler):
 """Parses junit xml reports and maps targets to the set of individual tests that failed. Targets with no failed tests are omitted from the returned mapping and failed tests with no identifiable owning target are keyed under `None`. :param test_registry: A registry of tests that were run. :type test_registry: :class:`RegistryOfTests` :param string junit_xml_path: A path to a file or directory containing test junit xml reports to analyze. :param error_handler: An error handler that will be called with any junit xml parsing errors. :type error_handler: callable that accepts a single :class:`ParseError` argument. :returns: A mapping from targets to the set of individual tests that failed. Any failed tests that belong to no identifiable target will be mapped to `None`. :rtype: dict from :class:`pants.build_graph.target.Target` to a set of :class:`Test` """

  failed_targets = defaultdict(set)

  def parse_junit_xml_file(path):
    try:
      xml = XmlParser.from_file(path)
      failures = int(xml.get_attribute('testsuite', 'failures'))
      errors = int(xml.get_attribute('testsuite', 'errors'))
      if failures or errors:
        for testcase in xml.parsed.getElementsByTagName('testcase'):
          test_failed = testcase.getElementsByTagName('failure')
          test_errored = testcase.getElementsByTagName('error')
          if test_failed or test_errored:
            test = Test(classname=testcase.getAttribute('classname'),
                        methodname=testcase.getAttribute('name'))
            target = test_registry.get_owning_target(test)
            failed_targets[target].add(test)
    except (XmlParser.XmlError, ValueError) as e:
      error_handler(ParseError(path, e))

  if os.path.isdir(junit_xml_path):
    for root, _, files in safe_walk(junit_xml_path):
      for junit_xml_file in fnmatch.filter(files, 'TEST-*.xml'):
        parse_junit_xml_file(os.path.join(root, junit_xml_file))
  else:
    parse_junit_xml_file(junit_xml_path)

  return dict(failed_targets)