enforce the type requirement

This commit is contained in:
Jean-Paul Calderone 2020-10-22 07:17:52 -04:00
parent c8b9a0265a
commit e3b1d4f536
1 changed files with 7 additions and 0 deletions

View File

@ -21,6 +21,9 @@ from twisted.web import (
resource,
template,
)
from twisted.web.iweb import (
IRequest,
)
from twisted.web.template import (
tags,
)
@ -163,6 +166,10 @@ def get_root(req):
:return: A string like ``../../..`` with the correct number of segments to
reach the root.
"""
if not IRequest.providedBy(req):
raise TypeError(
"get_root requires IRequest provider, got {!r}".format(req),
)
depth = len(req.prepath) + len(req.postpath)
link = "/".join([".."] * depth)
return link