backend.field_handlers
Handles registering field attributes for spock classes -- deals with the recursive nature of dependencies
#
RegisterFieldTemplate Objectsclass RegisterFieldTemplate(ABC)
Base class for handing different field types
Once the configuration dictionary has been assembled from the config file and the command line then we need to map these values to the correct spock classes -- seeing as different types need to be handled differently and recursive calls might be needed (when referencing other spock classes) classes derived from RegisterFieldTemplate handle the logic for making sure the argument dictionary passes to the instantiation of each spock class is correct
Attributes:
special_keys
- dictionary to check special keys_salt
- salt used for cryptograpy_key
- key used for cryptography_env_resolver
- class used to resolve environmental variables_crypto_resolver
- class used to resolve cryptographic variables
#
__init__def __init__(salt: str, key: ByteString)
Init call for RegisterFieldTemplate class
Arguments:
salt
- salt used for cryptograpykey
- key used for cryptography
#
__call__def __call__(attr_space: AttributeSpace, builder_space: BuilderSpace)
Call method for RegisterFieldTemplate
Handles calling the correct method for the type of the attribute
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
_is_attribute_in_config_argumentsdef _is_attribute_in_config_arguments(attr_space: AttributeSpace, builder_space: BuilderSpace)
Checks if an attribute is in the configuration file or keyword arguments dictionary
Will recurse spock classes as dependencies might be defined in the configs class
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- map of the read/cmd-line parameter dictionary to general or class level arguments
Returns:
boolean if in dictionary
#
_is_attribute_optional@staticmethoddef _is_attribute_optional(attribute: Type[Attribute])
Checks if an attribute is allowed to be optional
Arguments:
attribute
- current attribute class
Returns:
boolean if the optional state is allowed
#
handle_optional_attribute_valuedef handle_optional_attribute_value(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles setting an optional value with its default
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
RegisterEnum Objectsclass RegisterEnum(RegisterFieldTemplate)
Class that registers enum types
Attributes:
special_keys
- dictionary to check special keys_salt
- salt used for cryptograpy_key
- key used for cryptography_env_resolver
- class used to resolve environmental variables_crypto_resolver
- class used to resolve cryptographic variables
#
__init__def __init__(salt: str, key: ByteString)
Init call to RegisterEnum
Arguments:
salt
- salt used for cryptograpykey
- key used for cryptography
#
handle_attribute_from_configdef handle_attribute_from_config(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles getting the attribute set value when the Enum is made up of spock classes
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_typedef handle_optional_attribute_type(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles falling back on the optional default for a type based attribute
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_valuedef handle_optional_attribute_value(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles setting an optional value with its default
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
_handle_and_register_enumdef _handle_and_register_enum(enum_cls, attr_space: AttributeSpace, builder_space: BuilderSpace)
Recurse the enum in case there are nested type definitions
Arguments:
enum_cls
- current enum classattr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
RegisterCallableField Objectsclass RegisterCallableField(RegisterFieldTemplate)
Class that registers callable types
Attributes:
special_keys
- dictionary to check special keys_salt
- salt used for cryptograpy_key
- key used for cryptography_env_resolver
- class used to resolve environmental variables_crypto_resolver
- class used to resolve cryptographic variables
#
__init__def __init__(salt: str, key: ByteString)
Init call to RegisterSimpleField
Arguments:
salt
- salt used for cryptograpykey
- key used for cryptography
#
handle_attribute_from_configdef handle_attribute_from_config(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles setting a simple attribute when it is a spock class type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_typedef handle_optional_attribute_type(attr_space: AttributeSpace, builder_space: BuilderSpace)
Not implemented for this type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
Raises:
_SpockNotOptionalError
#
RegisterGenericAliasCallableField Objectsclass RegisterGenericAliasCallableField(RegisterFieldTemplate)
Class that registers Dicts containing callable types
Attributes:
special_keys
- dictionary to check special keys_salt
- salt used for cryptograpy_key
- key used for cryptography_env_resolver
- class used to resolve environmental variables_crypto_resolver
- class used to resolve cryptographic variables
#
__init__def __init__(salt: str, key: ByteString)
Init call to RegisterSimpleField
Arguments:
salt
- salt used for cryptograpykey
- key used for cryptography
#
handle_attribute_from_configdef handle_attribute_from_config(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles setting a simple attribute when it is a spock class type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_typedef handle_optional_attribute_type(attr_space: AttributeSpace, builder_space: BuilderSpace)
Not implemented for this type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
Raises:
_SpockNotOptionalError
#
RegisterSimpleField Objectsclass RegisterSimpleField(RegisterFieldTemplate)
Class that registers basic python types
Attributes:
special_keys
- dictionary to check special keys_salt
- salt used for cryptograpy_key
- key used for cryptography_env_resolver
- class used to resolve environmental variables_crypto_resolver
- class used to resolve cryptographic variables
#
__init__def __init__(salt: str, key: ByteString)
Init call to RegisterSimpleField
Arguments:
salt
- salt used for cryptograpykey
- key used for cryptography
#
handle_attribute_from_configdef handle_attribute_from_config(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles setting a simple attribute from a config file
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_typedef handle_optional_attribute_type(attr_space: AttributeSpace, builder_space: BuilderSpace)
Not implemented for this type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
Raises:
_SpockNotOptionalError
#
handle_optional_attribute_valuedef handle_optional_attribute_value(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles setting the attribute from default if optional
Also checks for clashes with special keys
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
register_special_keydef register_special_key(attr_space: AttributeSpace)
Registers a special key if it is found in the attribute metadata
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpace
#
RegisterTuneCls Objectsclass RegisterTuneCls(RegisterFieldTemplate)
Class that registers spock tune classes
Attributes:
special_keys
- dictionary to check special keys_salt
- salt used for cryptograpy_key
- key used for cryptography_env_resolver
- class used to resolve environmental variables_crypto_resolver
- class used to resolve cryptographic variables
#
__init__def __init__(salt: str, key: ByteString)
Init call to RegisterTuneCls
Arguments:
salt
- salt used for cryptograpykey
- key used for cryptography
#
_attr_type@staticmethoddef _attr_type(attr_space: AttributeSpace)
Gets the attribute type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpace
Returns:
the type of the attribute
#
handle_attribute_from_configdef handle_attribute_from_config(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles when the spock tune class is made up of spock classes
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_valuedef handle_optional_attribute_value(attr_space: AttributeSpace, builder_space: BuilderSpace)
Not implemented for this type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
Raises:
_SpockNotOptionalError
#
handle_optional_attribute_typedef handle_optional_attribute_type(attr_space: AttributeSpace, builder_space: BuilderSpace)
Not implemented for this type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
Raises:
_SpockNotOptionalError
#
RegisterSpockCls Objectsclass RegisterSpockCls(RegisterFieldTemplate)
Class that registers attributes within a spock class
Might be called recursively so it has methods to deal with spock classes when invoked via the call method
Attributes:
special_keys
- dictionary to check special keys_salt
- salt used for cryptograpy_key
- key used for cryptography_env_resolver
- class used to resolve environmental variables_crypto_resolver
- class used to resolve cryptographic variables
#
__init__def __init__(salt: str, key: ByteString)
Init call to RegisterSpockCls
Arguments:
salt
- salt used for cryptograpykey
- key used for cryptography
#
_attr_type@staticmethoddef _attr_type(attr_space: AttributeSpace)
Gets the attribute type
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpace
Returns:
the type of the attribute
#
handle_attribute_from_configdef handle_attribute_from_config(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles when the attribute is made up of a spock class or classes
Calls the recurse_generate function which handles nesting of spock classes
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_valuedef handle_optional_attribute_value(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles when the falling back onto the default for the attribute of spock class type and the field value already exits within the attr_space
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
handle_optional_attribute_typedef handle_optional_attribute_type(attr_space: AttributeSpace, builder_space: BuilderSpace)
Handles when the falling back onto the default for the attribute of spock class type
Calls the recurse_generate function which handles nesting of spock classes -- to make sure the attr_space.field value is defined
Arguments:
attr_space
- holds information about a single attribute that is mapped to a ConfigSpacebuilder_space
- named_tuple containing the arguments and spock_space
#
_find_callables@classmethoddef _find_callables(cls, typed: _T)
Attempts to find callables nested in Lists, Tuples, or Dicts
Arguments:
typed
- input type
Returns:
boolean if callables are found
#
recurse_generate@classmethoddef recurse_generate(cls, spock_cls: _C, builder_space: BuilderSpace, salt: str, key: ByteString)
Call on a spock classes to iterate through the attrs attributes and handle each based on type and optionality
Triggers a recursive call when an attribute refers to another spock classes
Arguments:
spock_cls
- current spock class that is being handledbuilder_space
- named_tuple containing the arguments and spock_spacesalt
- salt used for cryptograpykey
- key used for cryptography
Returns:
tuple of the instantiated spock class, the dictionary of special keys, and the info tuple of the original class and attempted payload