mirror of
https://github.com/chubin/wttr.in.git
synced 2025-08-14 07:48:24 +02:00
lib/location.py: python3 fixes
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user