diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2018-09-26 15:17:56 +0000 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2018-10-05 23:33:33 +0000 |
commit | f9600749453db5dec58bd1bbfd967e16b1578a24 (patch) | |
tree | 22e0f6e8f773483ad12828d92f4bf8d1496fbe70 /buildscripts/idl/idl/ast.py | |
parent | 2db04b524dc5e2121b74829814db7c8e84e5696d (diff) | |
download | mongo-f9600749453db5dec58bd1bbfd967e16b1578a24.tar.gz |
SERVER-37168 Add validators for IDL fields
Diffstat (limited to 'buildscripts/idl/idl/ast.py')
-rw-r--r-- | buildscripts/idl/idl/ast.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/buildscripts/idl/idl/ast.py b/buildscripts/idl/idl/ast.py index e5eda3b8426..7b2c85fda1f 100644 --- a/buildscripts/idl/idl/ast.py +++ b/buildscripts/idl/idl/ast.py @@ -92,6 +92,30 @@ class Struct(common.SourceLocation): super(Struct, self).__init__(file_name, line, column) +class Validator(common.SourceLocation): + """ + An instance of a validator for a field. + + The validator must include at least one of the defined validation predicates. + If more than one is included, they must ALL evaluate to true. + """ + + # pylint: disable=too-many-instance-attributes + + def __init__(self, file_name, line, column): + # type: (unicode, int, int) -> None + """Construct a Validator.""" + # Don't lint gt/lt as bad attribute names. + # pylint: disable=C0103 + self.gt = None # type: Optional[Union[int, float]] + self.lt = None # type: Optional[Union[int, float]] + self.gte = None # type: Optional[Union[int, float]] + self.lte = None # type: Optional[Union[int, float]] + self.callback = None # type: Optional[unicode] + + super(Validator, self).__init__(file_name, line, column) + + class Field(common.SourceLocation): """ An instance of a field in a struct. @@ -139,6 +163,9 @@ class Field(common.SourceLocation): self.serialize_op_msg_request_only = False # type: bool self.constructed = False # type: bool + # Validation rules. + self.validator = None # type: Optional[Validator] + super(Field, self).__init__(file_name, line, column) |