INNER CODE UNIT · Python
parse_port
selkies-project/selkies · addons/turn-rest/app.py:47
def parse_port(value, fallback: int) -> int:
"""Parse a TCP/UDP port number, falling back on anything out of range."""
try:
port = int(value)
if 1 <= port <= 65535:
return port
except (TypeError, ValueError):
pass
return fallback
def parse_ttl(value, fallback: int) -> int:
"""Parse a positive credential TTL in seconds, falling back otherwise."""
try:
ttl = int(value)
if ttl > 0:
return ttl
except (TypeError, ValueError):