Skip to content

Fix anchored regexes and ipv6 format on Windows #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def validate_patternProperties(self, patternProperties, instance, schema):

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

Expand Down Expand Up @@ -346,7 +346,7 @@ def validate_uniqueItems(self, uI, instance, schema):
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):
Expand Down Expand Up @@ -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")
Expand Down