mirror of
https://github.com/chubin/wttr.in.git
synced 2025-08-13 23:38: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
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import socket
|
||||
@ -35,12 +36,15 @@ def is_ip(ip_addr):
|
||||
Check if `ip_addr` looks like an IP Address
|
||||
"""
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
ip_addr = ip_addr.encode("utf-8")
|
||||
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET, ip_addr.encode("utf-8"))
|
||||
socket.inet_pton(socket.AF_INET, ip_addr)
|
||||
return True
|
||||
except socket.error:
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, ip_addr.encode("utf-8"))
|
||||
socket.inet_pton(socket.AF_INET6, ip_addr)
|
||||
return True
|
||||
except socket.error:
|
||||
return False
|
||||
|
Reference in New Issue
Block a user