Ivalidators
BaseArgs
¶
A class defining a group of related parameters passed to an action.
Simplifies action definitions if there are many possible arguments, and allows for additional validation based on the collection of parameters.
Source code in ckantools/validators/ivalidators.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
validate()
¶
Additional validation.
Source code in ckantools/validators/ivalidators.py
98 99 100 101 | |
list_of_dicts_validator(value, context)
¶
Validates that the value passed can be a list of dicts, either because it is or because it is once it's been parsed as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
the value |
required | |
context
|
the context |
required |
Returns:
| Type | Description |
|---|---|
|
the value as a list of dicts |
Source code in ckantools/validators/ivalidators.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
list_of_strings(delimiter=',')
¶
Creates a converter/validator function which when given a value return a list or raises an error if a list can't be created from the value. If the value passed in is a list already it is returned with no modifications, if it's a string then the delimiter is used to split the string and the result is returned. If the value is neither a list or a string then an error is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delimiter
|
the string to delimit the value on, if it's a string; defaults to a comma |
','
|
Returns:
| Type | Description |
|---|---|
|
a list |
Source code in ckantools/validators/ivalidators.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
list_validator(value, context)
¶
Checks that the given value is a list. If it is then it is allowed to pass, if not an Invalid error is raised. If the value is a string then we attempt to parse it as a JSON serialised list and raise an exception if we can't.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
the value to check |
required | |
context
|
the context in which to check |
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in ckantools/validators/ivalidators.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
object_validator(object_class)
¶
Creates a validator to check a JSON dict against a class inheriting from BaseArgs. If valid, it also loads that JSON dict as an instance of the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_class
|
type
|
a class inheriting from BaseArgs |
required |
Returns:
| Type | Description |
|---|---|
|
a validator instance |
Source code in ckantools/validators/ivalidators.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |