windows python 2 doesn't provide inet_pton
This commit is contained in:
parent
ffca68fc86
commit
333865ea34
1 changed files with 10 additions and 2 deletions
|
|
@ -42,8 +42,7 @@ from jinja2 import FileSystemLoader
|
||||||
from .signals import message_flashed
|
from .signals import message_flashed
|
||||||
from .globals import session, _request_ctx_stack, _app_ctx_stack, \
|
from .globals import session, _request_ctx_stack, _app_ctx_stack, \
|
||||||
current_app, request
|
current_app, request
|
||||||
from ._compat import string_types, text_type
|
from ._compat import string_types, text_type, PY2
|
||||||
|
|
||||||
|
|
||||||
# sentinel
|
# sentinel
|
||||||
_missing = object()
|
_missing = object()
|
||||||
|
|
@ -1002,12 +1001,21 @@ def total_seconds(td):
|
||||||
def is_ip(value):
|
def is_ip(value):
|
||||||
"""Determine if the given string is an IP address.
|
"""Determine if the given string is an IP address.
|
||||||
|
|
||||||
|
Python 2 on Windows doesn't provide ``inet_pton``, so this only
|
||||||
|
checks IPv4 addresses in that environment.
|
||||||
|
|
||||||
:param value: value to check
|
:param value: value to check
|
||||||
:type value: str
|
:type value: str
|
||||||
|
|
||||||
:return: True if string is an IP address
|
:return: True if string is an IP address
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
|
if PY2 and os.name == 'nt':
|
||||||
|
try:
|
||||||
|
socket.inet_aton(value)
|
||||||
|
return True
|
||||||
|
except socket.error:
|
||||||
|
return False
|
||||||
|
|
||||||
for family in (socket.AF_INET, socket.AF_INET6):
|
for family in (socket.AF_INET, socket.AF_INET6):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue