import re
import inspect


def _get_task_path(wrapped, instance) -> str:
    """Get the synthetic URL path for a task, based on the `wrapt` parameters."""
    funcname = wrapped.__name__
    if funcname.startswith("_") and not funcname.endswith("_"):
        funcname = re.sub(r"^_+", repl="", string=funcname, count=1)

    if instance is None:
        return funcname
    else:
        if inspect.isclass(instance):
            return "/".join([instance.__name__, funcname])
        else:
            return "/".join([instance.__class__.__name__, funcname])