From e3b1d4f536029fa383cde5746b37af862ac8c72b Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 22 Oct 2020 07:17:52 -0400 Subject: [PATCH] enforce the type requirement --- src/allmydata/web/common.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index bcdf21581..d970cc918 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -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