YAMLSpec
YAMLSpec(spec, path='', filename='')
Class for decoding and accessing specification data from YAML.
| PARAMETER | DESCRIPTION |
|---|---|
spec
|
The YAML specification data or file name.
TYPE:
|
path
|
The path for a sub-specification within the YAML data, using dot notation. "" indicates the top level.
TYPE:
|
get(key, default_value=None, required=False, value_type=None)
Get a value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
value_type
|
The expected type of the value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not of the expected type. |
get_bool(key, default_value=False, required=False)
Get a boolean value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
The boolean value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a boolean. |
get_dict(key, key_type=None, value_type=None, default_value=None, required=False)
Get a dictionary value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
key_type
|
The expected type of the dictionary keys.
TYPE:
|
value_type
|
The expected type of the dictionary values.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
The dictionary value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a dictionary or if any key or value is not of the expected type. |
get_float(key, default_value=0.0, required=False)
Get a float value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The float value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a float. |
get_int(key, default_value=0, required=False)
Get an integer value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The integer value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not an integer. |
get_list(key, item_type=None, default_value=None, required=False)
Get a list value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
item_type
|
The expected type of the list elements.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list
|
The list value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a list or if any element is not of the expected type. |
get_optional_int(key, default_value=None)
Get an optional integer value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
The integer value, or None if not found. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the value is not an integer. |
get_optional_str(key, default_value=None)
Get an optional string value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The string value, or None if not found. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the value is not a string. |
get_palette(key, default_value=None, required=False)
Get a Palette value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Palette
|
The Palette value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a valid Palette specification. |
get_spec(key)
Get a nested YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
YAMLSpec
|
The nested YAML specification. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a dictionary or keys are not strings. |
get_spec_list(key, allow_single=False)
Get a list of nested YAML specifications.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
allow_single
|
Whether to allow a single specification instead of a list.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[YAMLSpec]
|
The list of nested YAML specifications. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a a valid specification or list of specifications. |
get_str(key, default_value='', required=False)
Get a string value from the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get.
TYPE:
|
default_value
|
The default value to return if the key is not found.
TYPE:
|
required
|
Whether the key is required.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The string value. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the key is required but not found. |
TypeError
|
If the value is not a string. |
get_type(key)
Get the type of a value in the YAML specification.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key to get the type for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type | None
|
The type of the value, or None if the key does not exist. |
unknown_keys()
Return list of unknown keys in the YAML specification.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of keys that have not been accessed. |