44@validator
55def ipv4 (value ):
66 """
7- Return whether or not given value is a valid IP version 4 address.
7+ Return whether a given value is a valid IP version 4 address.
88
99 This validator is based on `WTForms IPAddress validator`_
1010
@@ -32,7 +32,7 @@ def ipv4(value):
3232@validator
3333def ipv4_cidr (value ):
3434 """
35- Return whether or not given value is a valid CIDR-notated IP version 4
35+ Return whether a given value is a valid CIDR-notated IP version 4
3636 address range.
3737
3838 This validator is based on RFC4632 3.1.
@@ -57,7 +57,7 @@ def ipv4_cidr(value):
5757@validator
5858def ipv6 (value ):
5959 """
60- Return whether or not given value is a valid IP version 6 address
60+ Return whether a given value is a valid IP version 6 address
6161 (including IPv4-mapped IPv6 addresses).
6262
6363 This validator is based on `WTForms IPAddress validator`_.
@@ -112,17 +112,21 @@ def ipv6(value):
112112 if not 0 <= num <= 65536 :
113113 return False
114114
115- if count_blank < 2 :
115+ if count_blank == 0 and len ( ipv6_groups ) == max_groups :
116116 return True
117- elif count_blank == 2 and not ipv6_groups [0 ] and not ipv6_groups [1 ]:
117+ elif count_blank == 1 and ipv6_groups [- 1 ] and ipv6_groups [0 ]:
118+ return True
119+ elif count_blank == 2 and ((ipv6_groups [0 ] and not ipv6_groups [- 1 ]) or (not ipv6_groups [0 ] and ipv6_groups [- 1 ])):
120+ return True
121+ elif count_blank == 3 and len (ipv6_groups ) == 3 :
118122 return True
119123 return False
120124
121125
122126@validator
123127def ipv6_cidr (value ):
124128 """
125- Returns whether or not given value is a valid CIDR-notated IP version 6
129+ Returns whether a given value is a valid CIDR-notated IP version 6
126130 address range.
127131
128132 This validator is based on RFC4632 3.1.
0 commit comments