Mercurial > libervia-web
changeset 1458:db13f5c768a0
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
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 29 Sep 2021 17:39:08 +0200 |
parents | 792a2e902ee9 |
children | 47db314e60ca |
files | libervia/server/server.py |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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 ##