MCPcopy Index your code
hub / github.com/python/cpython / _inet_paton

Function _inet_paton

Lib/ssl.py:329–361  ·  view source on GitHub ↗

Try to convert an IP address to packed binary form Supports IPv4 addresses on all platforms and IPv6 on platforms with IPv6 support.

(ipname)

Source from the content-addressed store, hash-verified

327
328
329def _inet_paton(ipname):
330 """Try to convert an IP address to packed binary form
331
332 Supports IPv4 addresses on all platforms and IPv6 on platforms with IPv6
333 support.
334 """
335 # inet_aton() also accepts strings like '1', '127.1', some also trailing
336 # data like '127.0.0.1 whatever'.
337 try:
338 addr = _socket.inet_aton(ipname)
339 except OSError:
340 # not an IPv4 address
341 pass
342 else:
343 if _socket.inet_ntoa(addr) == ipname:
344 # only accept injective ipnames
345 return addr
346 else:
347 # refuse for short IPv4 notation and additional trailing data
348 raise ValueError(
349 "{!r} is not a quad-dotted IPv4 address.".format(ipname)
350 )
351
352 try:
353 return _socket.inet_pton(_socket.AF_INET6, ipname)
354 except OSError:
355 raise ValueError("{!r} is neither an IPv4 nor an IP6 "
356 "address.".format(ipname))
357 except AttributeError:
358 # AF_INET6 not available
359 pass
360
361 raise ValueError("{!r} is not an IPv4 address.".format(ipname))
362
363
364def _ipaddress_match(cert_ipaddress, host_ip):

Callers 1

_ipaddress_matchFunction · 0.85

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…