# HG changeset patch # User Goffi # Date 1632929948 -7200 # Node ID db13f5c768a0161745e0969efdf04cbf5c4fcc3e # Parent 792a2e902ee952c8bd6bfd2d19a050dabbfd0c90 server: `checkRedirection`: fix range variable + type hints + arg name: - fix wrong variable used for range - add type hints - use a better argument to show that a URL path is used and not a whole URL diff -r 792a2e902ee9 -r db13f5c768a0 libervia/server/server.py --- a/libervia/server/server.py Wed Sep 29 17:39:06 2021 +0200 +++ b/libervia/server/server.py Wed Sep 29 17:39:08 2021 +0200 @@ -1717,23 +1717,23 @@ ) ) - def checkRedirection(self, vhost_root, url): + def checkRedirection(self, vhost_root: LiberviaRootResource, url_path: str) -> str: """check is a part of the URL prefix is redirected then replace it - @param vhost_root(web_resource.Resource): root of this virtual host - @param url(unicode): url to check - @return (unicode): possibly redirected URL which should link to the same location + @param vhost_root: root of this virtual host + @param url_path: path of the url to check + @return: possibly redirected URL which should link to the same location """ inv_redirections = vhost_root.inv_redirections - url_parts = url.strip("/").split("/") - for idx in range(len(url), 0, -1): + url_parts = url_path.strip("/").split("/") + for idx in range(len(url_parts), 0, -1): test_url = "/" + "/".join(url_parts[:idx]) if test_url in inv_redirections: rem_url = url_parts[idx:] return os.path.join( "/", "/".join([inv_redirections[test_url]] + rem_url) ) - return url + return url_path ## Sessions ##