enforce the type requirement
This commit is contained in:
parent
c8b9a0265a
commit
e3b1d4f536
|
@ -21,6 +21,9 @@ from twisted.web import (
|
||||||
resource,
|
resource,
|
||||||
template,
|
template,
|
||||||
)
|
)
|
||||||
|
from twisted.web.iweb import (
|
||||||
|
IRequest,
|
||||||
|
)
|
||||||
from twisted.web.template import (
|
from twisted.web.template import (
|
||||||
tags,
|
tags,
|
||||||
)
|
)
|
||||||
|
@ -163,6 +166,10 @@ def get_root(req):
|
||||||
:return: A string like ``../../..`` with the correct number of segments to
|
:return: A string like ``../../..`` with the correct number of segments to
|
||||||
reach the root.
|
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)
|
depth = len(req.prepath) + len(req.postpath)
|
||||||
link = "/".join([".."] * depth)
|
link = "/".join([".."] * depth)
|
||||||
return link
|
return link
|
||||||
|
|
Loading…
Reference in New Issue