diff --git a/jsonschema.py b/jsonschema.py index 388c502..bde99c3 100644 --- a/jsonschema.py +++ b/jsonschema.py @@ -931,19 +931,19 @@ def is_email(instance): return bool(re.match(pattern, instance)) -@FormatChecker.cls_checks("ip-address") -def is_ip_address(instance): +@FormatChecker.cls_checks("ipv4") +def is_ipv4(instance): """ Check whether the instance is a valid IP address. :argument str instance: the instance to check :rtype: bool - >>> is_ip_address("192.168.0.1") + >>> is_ipv4("192.168.0.1") True - >>> is_ip_address("::1") + >>> is_ipv4("::1") False - >>> is_ip_address("256.256.256.256") + >>> is_ipv4("256.256.256.256") False """ @@ -1033,6 +1033,11 @@ def is_regex(instance): return False +draft4_format_checker = FormatChecker() +draft3_format_checker = FormatChecker() +draft3_format_checker.checkers['ip-address'] = is_ipv4 + + if webcolors is not None: def is_css_color_code(instance): try: @@ -1042,7 +1047,7 @@ if webcolors is not None: return True - @FormatChecker.cls_checks("color") + @draft3_format_checker.checks("color") def is_css21_color(instance): if instance.lower() in webcolors.css21_names_to_hex: return True diff --git a/tests.py b/tests.py index 713bbce..d7d6433 100644 --- a/tests.py +++ b/tests.py @@ -18,7 +18,8 @@ except ImportError: from jsonschema import ( PY3, SchemaError, UnknownType, ValidationError, ErrorTree, - Draft3Validator, Draft4Validator, FormatChecker, RefResolver, validate + Draft3Validator, Draft4Validator, FormatChecker, draft3_format_checker, + draft4_format_checker, RefResolver, validate ) @@ -129,6 +130,7 @@ class TestDraft3( TestCase, BytesMixin, DecimalMixin, AnyTypeMixin, FormatMixin, BigNumMixin, ): validator_class = Draft3Validator + validator_kwargs = {"format_checker" : draft3_format_checker} # TODO: we're in need of more meta schema tests def test_invalid_properties(self): @@ -143,6 +145,7 @@ class TestDraft3( @load_json_cases("json/tests/draft4/*.json") class TestDraft4(TestCase, BytesMixin, DecimalMixin, FormatMixin, BigNumMixin): validator_class = Draft4Validator + validator_kwargs = {"format_checker" : draft4_format_checker} # TODO: we're in need of more meta schema tests def test_invalid_properties(self):