Skip to content

Commit 7f2950e

Browse files
committed
Merge pull request #58 from gazpachoking/fixes
Fix anchored regexes and ipv6 format on Windows
2 parents b5341be + 13c8e3a commit 7f2950e

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

jsonschema.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def validate_patternProperties(self, patternProperties, instance, schema):
230230

231231
for pattern, subschema in iteritems(patternProperties):
232232
for k, v in iteritems(instance):
233-
if re.match(pattern, k):
233+
if re.search(pattern, k):
234234
for error in self.iter_errors(v, subschema):
235235
yield error
236236

@@ -346,7 +346,7 @@ def validate_uniqueItems(self, uI, instance, schema):
346346
yield ValidationError("%r has non-unique elements" % instance)
347347

348348
def validate_pattern(self, patrn, instance, schema):
349-
if self.is_type(instance, "string") and not re.match(patrn, instance):
349+
if self.is_type(instance, "string") and not re.search(patrn, instance):
350350
yield ValidationError("%r does not match %r" % (instance, patrn))
351351

352352
def validate_format(self, format, instance, schema):
@@ -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)