MCPcopy
hub / github.com/encode/uvicorn / get_local_addr

Function get_local_addr

uvicorn/protocols/utils.py:30–44  ·  view source on GitHub ↗
(transport: asyncio.Transport)

Source from the content-addressed store, hash-verified

28
29
30def get_local_addr(transport: asyncio.Transport) -> tuple[str, int | None] | None:
31 socket_info: socket.socket | None = transport.get_extra_info("socket")
32 if socket_info is not None:
33 info = socket_info.getsockname()
34 if isinstance(info, tuple):
35 return (str(info[0]), int(info[1]))
36 if isinstance(info, str):
37 return (info, None)
38 return None
39 info = transport.get_extra_info("sockname")
40 if info is not None and isinstance(info, list | tuple) and len(info) == 2:
41 return (str(info[0]), int(info[1]))
42 if isinstance(info, str):
43 return (info, None)
44 return None
45
46
47def is_ssl(transport: asyncio.Transport) -> bool:

Callers 7

connection_madeMethod · 0.90
connection_madeMethod · 0.90
connection_madeMethod · 0.90
connection_madeMethod · 0.90
connection_madeMethod · 0.90
test_get_local_addrFunction · 0.90

Calls 2

getsocknameMethod · 0.80
get_extra_infoMethod · 0.45

Tested by 2

test_get_local_addrFunction · 0.72