lib/location.py: python3 fixes
This commit is contained in:
parent
f9a1ff5b2a
commit
ac1be8305b
1 changed files with 6 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ precise location description.
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
|
|
@ -35,12 +36,15 @@ def is_ip(ip_addr):
|
||||||
Check if `ip_addr` looks like an IP Address
|
Check if `ip_addr` looks like an IP Address
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
ip_addr = ip_addr.encode("utf-8")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET, ip_addr.encode("utf-8"))
|
socket.inet_pton(socket.AF_INET, ip_addr)
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error:
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET6, ip_addr.encode("utf-8"))
|
socket.inet_pton(socket.AF_INET6, ip_addr)
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue