Skip to content

Utils

anyuri._utils

normalize_url

normalize_url(http_uri)

Normalize an HTTP URI by resolving '..' and '.' segments in the path.

Source code in src/anyuri/_utils.py
 6
 7
 8
 9
10
def normalize_url(http_uri: str) -> str:
    """Normalize an HTTP URI by resolving '..' and '.' segments in the path."""
    parsed = urlparse(http_uri)
    resolved = urljoin(http_uri, parsed.path)
    return urlunparse(parsed._replace(path=urlparse(resolved).path))

uri_to_path

uri_to_path(file_uri)

Convert a file:// URI to a local filesystem path.

Source code in src/anyuri/_utils.py
13
14
15
16
17
18
19
20
21
22
def uri_to_path(file_uri: str) -> str:
    """Convert a file:// URI to a local filesystem path."""
    parsed = urlparse(file_uri)
    if parsed.scheme != "file":
        raise ValueError(f"Unsupported scheme: {parsed.scheme!r}")
    path_str = unquote(parsed.path)
    # Windows: "/C:/..." → "C:/..."
    if os.name == "nt" and path_str.startswith("/") and len(path_str) > 2 and path_str[2] == ":":
        path_str = path_str[1:]
    return os.path.normpath(Path(path_str))