INNER CODE UNIT · Python

format_ice_host

selkies-project/selkies · addons/turn-rest/app.py:87

def format_ice_host(host: str) -> str:
    """Bracket a bare IPv6 literal so it is valid inside a TURN URI."""
    if host and ":" in host and not (host.startswith("[") and host.endswith("]")):
        return f"[{host}]"
    return host


def random_username(length: int = 16) -> str:
    """A random lowercase-alphanumeric username for anonymous requests."""
    alphabet = string.ascii_lowercase + string.digits
    return ''.join(secrets.choice(alphabet) for _ in range(length))


def get_param(name: str, json_payload: Any) -> Optional[Any]:
    """Read a request parameter from query/form values, then the JSON body."""
    value = request.values.get(name)
    if value is not None:
        return value

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…