import re


def _resolve_hdf5_path(files, path):
    """Resolve a HDF5 external link. Return the referred node (group or
    dataset), or None if it does not exist.

    Arguments:
      * files: a dict {type: file_handle}.
      * path: a string like "{type}/path/to/node" where `type` is one of
        `kwx`, `raw.kwd`, etc.

    """
    nodes = path.split('/')
    path_ext = '/' + '/'.join(nodes[1:])
    type = nodes[0]
    pattern = r'\{([a-zA-Z\._]+)\}'
    assert re.match(pattern, type)
    r = re.search(pattern, type)
    assert r
    type = r.group(1)
    # Resolve the link.
    file = files.get(type, None)
    if file:
        return file.getNode(path_ext)
    else:
        return None