Skip to content

Utils

pyvider.rpcplugin.transport.unix.utils

Unix Domain Socket utilities and helper functions.

This module provides utility functions for Unix domain socket path normalization and other common operations.

Functions

normalize_unix_path

normalize_unix_path(path: str) -> str

Standardized Unix socket path normalization, handling: - unix: prefix - unix:/ prefix - unix:// prefix - Multiple leading slashes

Returns a clean path suitable for socket operations.

Source code in pyvider/rpcplugin/transport/unix/utils.py
def normalize_unix_path(path: str) -> str:
    """
    Standardized Unix socket path normalization, handling:
    - unix: prefix
    - unix:/ prefix
    - unix:// prefix
    - Multiple leading slashes

    Returns a clean path suitable for socket operations.
    """

    # Handle unix: prefix formats
    if path.startswith("unix:"):
        path = path[5:]  # Remove 'unix:'

    # Handle multiple leading slashes
    if path.startswith("//"):
        # Split by / and rebuild with single leading slash
        parts = [p for p in path.split("/") if p]
        path = "/" + "/".join(parts)
    elif path.startswith("/"):
        # Keep absolute paths as-is
        pass
    # Relative paths remain unchanged

    return path