# -*- coding: utf-8 -*-1# This program is free software; you can redistribute it and/or modify2# it under the terms of the GNU General Public License as published by3# the Free Software Foundation; either version 2 of the License, or4# (at your option) any later version.5#6# This program is distributed in the hope that it will be useful,7# but WITHOUT ANY WARRANTY; without even the implied warranty of8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9# GNU General Public License for more details.10#11# You should have received a copy of the GNU General Public License12# along with this program; if not, write to the Free Software13# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,14# MA 02110-1301, USA.15#16# Author: Mauro Soria1718from lib.utils.common import lstrip_once192021def clean_path(path: str, keep_queries: bool = False, keep_fragment: bool = False) -> str:22if not keep_fragment:23path = path.split("#")[0]24if not keep_queries:25path = path.split("?")[0]2627return path282930def parse_path(value: str) -> str:31try:32scheme, url = value.split("//", 1)33if (34scheme and (not scheme.endswith(":") or "/" in scheme)35or url.startswith("/")36):37raise ValueError3839return "/".join(url.split("/")[1:])40except Exception:41return lstrip_once(value, "/")424344