<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _runhook(ui, repo, hooktype, filename, kwargs):
 """Run the hook in `filename` and return its result."""

    hname = hooktype + ".autohooks." + os.path.basename(filename)
    if filename.lower().endswith(".py"):
        try:
            mod = mercurial.extensions.loadpath(filename,
                "hghook.%s" % hname)
        except Exception:
            ui.write(_("loading %s hook failed:\n") % hname)
            raise
        return mercurial.hook._pythonhook(ui, repo, hooktype, hname,
            getattr(mod, hooktype.replace("-", "_")), kwargs, True)
    elif filename.lower().endswith(".sh"):
        return mercurial.hook._exthook(ui, repo, hname, filename, kwargs, True)
    return False