Skip to content

Commit

Permalink
Merge pull request #96 from jtpereyda/windows-build-fix
Browse files Browse the repository at this point in the history
Fix new UT on Windows
  • Loading branch information
jtpereyda committed Oct 13, 2016
2 parents 98c936f + 25b2b24 commit 5ce9021
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions unit_tests/test_socket_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@
TEST_ERR_NO_NON_LOOPBACK_IPV4 = 'No local non-loopback IPv4 address found.'


def bytes_or_unicode_to_unicode(s):
if isinstance(s, bytes):
return s.decode('utf-8')
else:
return s


def get_local_non_loopback_ipv4_addresses_info():
for interface in netifaces.interfaces():
# Not all interfaces have an IPv4 address:
if netifaces.AF_INET in netifaces.ifaddresses(interface):
# Some interfaces have multiple IPv4 addresses:
for address_info in netifaces.ifaddresses(interface)[netifaces.AF_INET]:
address_object = ipaddress.IPv4Address(unicode(address_info['addr'], 'utf-8'))
if not address_object.is_loopback:
# netifaces gives unicode strings in Windows, byte strings in Linux:
address_str = bytes_or_unicode_to_unicode(address_info['addr'])
if not ipaddress.IPv4Address(address_str).is_loopback:
yield address_info


Expand Down

0 comments on commit 5ce9021

Please sign in to comment.