comparison libervia/server/server.py @ 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
comparison
equal deleted inserted replaced
1457:792a2e902ee9 1458:db13f5c768a0
1715 query, 1715 query,
1716 fragment, 1716 fragment,
1717 ) 1717 )
1718 ) 1718 )
1719 1719
1720 def checkRedirection(self, vhost_root, url): 1720 def checkRedirection(self, vhost_root: LiberviaRootResource, url_path: str) -> str:
1721 """check is a part of the URL prefix is redirected then replace it 1721 """check is a part of the URL prefix is redirected then replace it
1722 1722
1723 @param vhost_root(web_resource.Resource): root of this virtual host 1723 @param vhost_root: root of this virtual host
1724 @param url(unicode): url to check 1724 @param url_path: path of the url to check
1725 @return (unicode): possibly redirected URL which should link to the same location 1725 @return: possibly redirected URL which should link to the same location
1726 """ 1726 """
1727 inv_redirections = vhost_root.inv_redirections 1727 inv_redirections = vhost_root.inv_redirections
1728 url_parts = url.strip("/").split("/") 1728 url_parts = url_path.strip("/").split("/")
1729 for idx in range(len(url), 0, -1): 1729 for idx in range(len(url_parts), 0, -1):
1730 test_url = "/" + "/".join(url_parts[:idx]) 1730 test_url = "/" + "/".join(url_parts[:idx])
1731 if test_url in inv_redirections: 1731 if test_url in inv_redirections:
1732 rem_url = url_parts[idx:] 1732 rem_url = url_parts[idx:]
1733 return os.path.join( 1733 return os.path.join(
1734 "/", "/".join([inv_redirections[test_url]] + rem_url) 1734 "/", "/".join([inv_redirections[test_url]] + rem_url)
1735 ) 1735 )
1736 return url 1736 return url_path
1737 1737
1738 ## Sessions ## 1738 ## Sessions ##
1739 1739
1740 def purgeSession(self, request): 1740 def purgeSession(self, request):
1741 """helper method to purge a session during request handling""" 1741 """helper method to purge a session during request handling"""