summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonschema.py41
1 files changed, 21 insertions, 20 deletions
diff --git a/jsonschema.py b/jsonschema.py
index ee8a235..8bb6e7b 100644
--- a/jsonschema.py
+++ b/jsonschema.py
@@ -230,7 +230,7 @@ class Draft3Validator(object):
for pattern, subschema in iteritems(patternProperties):
for k, v in iteritems(instance):
- if re.match(pattern, k):
+ if re.search(pattern, k):
for error in self.iter_errors(v, subschema):
yield error
@@ -346,7 +346,7 @@ class Draft3Validator(object):
yield ValidationError("%r has non-unique elements" % instance)
def validate_pattern(self, patrn, instance, schema):
- if self.is_type(instance, "string") and not re.match(patrn, instance):
+ if self.is_type(instance, "string") and not re.search(patrn, instance):
yield ValidationError("%r does not match %r" % (instance, patrn))
def validate_format(self, format, instance, schema):
@@ -710,28 +710,29 @@ def is_ip_address(instance):
return False
-@FormatChecker.cls_checks("ipv6")
-def is_ipv6(instance):
- """
- Check whether the instance is a valid IPv6 address.
+if hasattr(socket, "inet_pton"):
+ @FormatChecker.cls_checks("ipv6")
+ def is_ipv6(instance):
+ """
+ Check whether the instance is a valid IPv6 address.
- :argument str instance: the instance to check
- :rtype: bool
+ :argument str instance: the instance to check
+ :rtype: bool
- >>> is_ipv6("::1")
- True
- >>> is_ipv6("192.168.0.1")
- False
- >>> is_ipv6("1:1:1:1:1:1:1:1:1")
- False
+ >>> is_ipv6("::1")
+ True
+ >>> is_ipv6("192.168.0.1")
+ False
+ >>> is_ipv6("1:1:1:1:1:1:1:1:1")
+ False
- """
+ """
- try:
- socket.inet_pton(socket.AF_INET6, instance)
- return True
- except socket.error:
- return False
+ try:
+ socket.inet_pton(socket.AF_INET6, instance)
+ return True
+ except socket.error:
+ return False
@FormatChecker.cls_checks("host-name")