From b5341be6120e47d20da38afc1183db35d7b31fd5 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 3 Feb 2013 16:44:21 -0500 Subject: [PATCH] Remove duplication --- docs/validate.rst | 11 +++++++++++ jsonschema.py | 19 ++----------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/docs/validate.rst b/docs/validate.rst index ab14a63..a0664fd 100644 --- a/docs/validate.rst +++ b/docs/validate.rst @@ -183,6 +183,7 @@ be enabled by hooking in a format-checking object into an :class:`IValidator`. .. autoclass:: FormatChecker :members: + :exclude-members: cls_checks .. attribute:: checkers @@ -191,6 +192,16 @@ be enabled by hooking in a format-checking object into an :class:`IValidator`. for all checkers using the :meth:`FormatChecker.checks` or :meth:`FormatChecker.cls_checks` decorators respectively. + .. method:: cls_checks(format) + + Register a decorated function as *globally* validating a new format. + + Any instance created after this function is called will pick up the + supplied checker. + + :argument str format: the format that the decorated function will check + + There are a number of default checkers that :class:`FormatChecker`\s know how to validate. Their names can be viewed by inspecting the diff --git a/jsonschema.py b/jsonschema.py index 39b93d5..ee8a235 100644 --- a/jsonschema.py +++ b/jsonschema.py @@ -517,23 +517,6 @@ class FormatChecker(object): else: self.checkers = dict((k, self.checkers[k]) for k in formats) - @classmethod - def cls_checks(cls, format): - """ - Register a decorated function as *globally* validating a new format. - - Any instance created after this function is called will pick up the - supplied checker. - - :argument str format: the format that the decorated function will check - - """ - - def _checks(func): - cls.checkers[format] = func - return func - return _checks - def checks(self, format): """ Register a decorated function as validating a new format. @@ -547,6 +530,8 @@ class FormatChecker(object): return func return _checks + cls_checks = classmethod(checks) + def conforms(self, instance, format): """ Check whether the instance conforms to the given format.