MCPcopy
hub / github.com/python-trio/trio / bind

Method bind

src/trio/testing/_fake_net.py:279–298  ·  view source on GitHub ↗
(self, addr: object)

Source from the content-addressed store, hash-verified

277 ################################################################
278
279 async def bind(self, addr: object) -> None:
280 self._check_closed()
281 if self._binding is not None:
282 _fake_err(errno.EINVAL)
283 await trio.lowlevel.checkpoint()
284 ip_str, port, *_ = await self._resolve_address_nocp(addr, local=True)
285 assert _ == [], "TODO: handle other values?"
286
287 ip = ipaddress.ip_address(ip_str)
288 assert _family_for(ip) == self.family
289 # We convert binds to INET_ANY into binds to localhost
290 if ip == ipaddress.ip_address("0.0.0.0"):
291 ip = ipaddress.ip_address("127.0.0.1")
292 elif ip == ipaddress.ip_address("::"):
293 ip = ipaddress.ip_address("::1")
294 if port == 0:
295 port = next(self._fake_net._auto_port_iter)
296 binding = UDPBinding(local=UDPEndpoint(ip, port))
297 self._fake_net._bind(binding, self)
298 self._binding = binding
299
300 async def connect(self, peer: object) -> NoReturn:
301 raise NotImplementedError("FakeNet does not (yet) support connected sockets")

Callers 1

_sendmsgMethod · 0.95

Calls 7

_check_closedMethod · 0.95
_resolve_address_nocpMethod · 0.95
_fake_errFunction · 0.85
_family_forFunction · 0.85
UDPBindingClass · 0.85
UDPEndpointClass · 0.85
_bindMethod · 0.80

Tested by

no test coverage detected