Schema
KoshSchema
Bases: object
Source code in kosh/schema.py
__init__(required={}, optional={})
Schema for Kosh objects
Parameters:
Name | Type | Description | Default |
---|---|---|---|
required |
dict
|
Dictionary of required keys and their validation function(s). |
{}
|
optional |
dict Validation functions must be pickable. If multiple validation functions are provided (in a list), then the attribute is valid if ANY function return True. Validation function must return True, False | raise an Exception.
|
Dictionary of optional keys and their validation function(s) |
{}
|
Source code in kosh/schema.py
__str__()
validate(obj)
validate an object through a schema Checks that the obj has all the required attribute and that both required and present optional attributes pass validation functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
str
|
object to validate |
required |
Returns:
Type | Description |
---|---|
True if validates "rtype: bool |
Raises:
Type | Description |
---|---|
ValueError
|
obj does not validate through the schema |
Source code in kosh/schema.py
validate_attribute(attribute, value)
validate_attribute validates a value for a specific attribute
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute |
str
|
attribute to validate |
required |
value |
any
|
value to validate |
required |
Returns:
Type | Description |
---|---|
True or False "rtype: bool |
Source code in kosh/schema.py
auto_valid(validation)
auto_valid converts class type to their 'isinstance' function in the future other keyword maybe added to the list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
validation |
type
|
class def or type |
required |
Returns:
Type | Description |
---|---|
function
|
isinstance lambda function or validation function |
Source code in kosh/schema.py
validate_value(value, validation)
validate_value Validates a value for a given validation function (or list of)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
any
|
value to validate |
required |
validation |
callable
|
validation function (or list of) |
required |
Returns:
Type | Description |
---|---|
bool
|
True if validates |
Raises:
Type | Description |
---|---|
ValueError
|
value does not vaidate |