MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / format_address

Function format_address

mitmproxy/utils/human.py:81–99  ·  view source on GitHub ↗

This function accepts IPv4/IPv6 tuples and returns the formatted address string with port number

(address: tuple | None)

Source from the content-addressed store, hash-verified

79
80@functools.lru_cache
81def format_address(address: tuple | None) -> str:
82 """
83 This function accepts IPv4/IPv6 tuples and
84 returns the formatted address string with port number
85 """
86 if address is None:
87 return "<no address>"
88 try:
89 host = ipaddress.ip_address(address[0])
90 if host.is_unspecified:
91 return f"*:{address[1]}"
92 if isinstance(host, ipaddress.IPv4Address):
93 return f"{host}:{address[1]}"
94 # If IPv6 is mapped to IPv4
95 elif host.ipv4_mapped:
96 return f"{host.ipv4_mapped}:{address[1]}"
97 return f"[{host}]:{address[1]}"
98 except ValueError:
99 return f"{address[0]}:{address[1]}"

Callers

nothing calls this directly

Calls 1

ip_addressMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…