def get_redirect()

in scripts/linkchecker.py [0:0]


def get_redirect(path):
    """Check if the path exists in the redirect database.

    NOTE: We do NOT check if the redirect target is there or not. We do an
    **exact** matching for redirection entries.
    :returns: The redirect target if any, or None if not found.
    """
    global REDIRECTS

    def _check_redirect(t):
        for key, value in REDIRECTS.items():
            if key == t:  # EXACT MATCH
                return value
        return None

    # NOTE: anchor is ignored, can be a future todo
    parts = path.split("#")
    target = parts[0]
    if not target.endswith("/"):
        target += "/"

    new_target = _check_redirect(target)
    last_target = new_target
    while new_target:
        new_target = _check_redirect(new_target)
        if new_target is None:
            break
        last_target = new_target

    return last_target