Remove duplication
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user