Do not raise exception if passed bytes

This commit is contained in:
Daniel A. Wozniak 2018-08-27 16:21:52 -07:00
parent e371ad99eb
commit 376019ff18
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61

View file

@ -37,7 +37,10 @@ def inet_pton(address_family, ip_string):
# This will catch IP Addresses such as 10.1.2
if address_family == socket.AF_INET:
try:
ipaddress.ip_address(six.u(ip_string))
if isinstance(ip_string, six.binary_type):
ipaddress.ip_address(six.u(ip_string))
else:
ipaddress.ip_address(ip_string)
except ValueError:
raise socket.error('illegal IP address string passed to inet_pton')
return socket.inet_aton(ip_string)