File: _validator.py

package info (click to toggle)
python-asdf 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,032 kB
  • sloc: python: 24,068; makefile: 123
file content (56 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import abc


class Validator(abc.ABC):
    """
    Abstract base class for plugins that handle custom validators
    in ASDF schemas.
    """

    @abc.abstractproperty
    def schema_property(self):
        """
        Name of the schema property used to invoke this validator.
        """

    @abc.abstractproperty
    def tags(self):
        """
        Get the YAML tags that are appropriate to this validator.
        URI patterns are permitted, see `asdf.util.uri_match` for details.

        Returns
        -------
        iterable of str
            Tag URIs or URI patterns.
        """

    @abc.abstractmethod
    def validate(self, schema_property_value, node, schema):
        """
        Validate the given node from the ASDF tree.

        Parameters
        ----------
        schema_property_value : object
            The value assigned to the schema property associated with this
            valdiator.

        node : asdf.tagged.Tagged
            A tagged node from the tree.  Guaranteed to bear a tag that
            matches one of the URIs returned by this validator's tags property.

        schema : dict
            The schema object that contains the property that triggered
            the validation.  Typically implementations of this method do
            not need to make use of this object, but sometimes the behavior
            of a validator depends on other schema properties.  An example is
            the built-in "additionalProperties" property, which needs to know
            the contents of the "properties" property in order to determine
            which node properties are additional.

        Yields
        ------
        asdf.exceptions.ValidationError
            Yield an instance of ValidationError for each error present in the node.
        """