Skip to content

Commit 82aa0a8

Browse files
committed
Don't add ipv6 format checker if socket.inet_pton is not available
1 parent b5341be commit 82aa0a8

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

jsonschema.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -710,28 +710,29 @@ def is_ip_address(instance):
710710
return False
711711

712712

713-
@FormatChecker.cls_checks("ipv6")
714-
def is_ipv6(instance):
715-
"""
716-
Check whether the instance is a valid IPv6 address.
713+
if hasattr(socket, "inet_pton"):
714+
@FormatChecker.cls_checks("ipv6")
715+
def is_ipv6(instance):
716+
"""
717+
Check whether the instance is a valid IPv6 address.
717718
718-
:argument str instance: the instance to check
719-
:rtype: bool
719+
:argument str instance: the instance to check
720+
:rtype: bool
720721
721-
>>> is_ipv6("::1")
722-
True
723-
>>> is_ipv6("192.168.0.1")
724-
False
725-
>>> is_ipv6("1:1:1:1:1:1:1:1:1")
726-
False
722+
>>> is_ipv6("::1")
723+
True
724+
>>> is_ipv6("192.168.0.1")
725+
False
726+
>>> is_ipv6("1:1:1:1:1:1:1:1:1")
727+
False
727728
728-
"""
729+
"""
729730

730-
try:
731-
socket.inet_pton(socket.AF_INET6, instance)
732-
return True
733-
except socket.error:
734-
return False
731+
try:
732+
socket.inet_pton(socket.AF_INET6, instance)
733+
return True
734+
except socket.error:
735+
return False
735736

736737

737738
@FormatChecker.cls_checks("host-name")

0 commit comments

Comments
 (0)