nomenclate.core.configurator module¶
- class nomenclate.core.configurator.BaseFormatter[source]
Bases:
object
- converts = {'accepted_input_type': None, 'accepted_return_type': None}
- static format_result(input)[source]
- class nomenclate.core.configurator.ConfigEntryFormatter[source]
Bases:
object
- static add_preceding_dict(config_entry, query_path, preceding_depth)[source]
Adds the preceeding config keys to the config_entry to simulate the original full path to the config entry
- Parameters
config_entry – object, the entry that was requested and returned from the config
query_path – (str, list(str)), the original path to the config_entry
preceding_depth – int, the depth to which we are recreating the preceding config keys
- Returns
dict, simulated config to n * preceding_depth
- format_query_result(query_result, query_path, return_type=<class 'list'>, preceding_depth=None)[source]
Formats the query result based on the return type requested.
- Parameters
query_result – (dict or str or list), yaml query result
query_path – (str, list(str)), representing query path
return_type – type, return type of object user desires
preceding_depth – int, the depth to which we want to encapsulate back up config tree -1 : defaults to entire tree
- Returns
(dict, OrderedDict, str, list), specified return type
- format_with_handler(query_result, return_type)[source]
Uses the callable handler to format the query result to the desired return type
- Parameters
query_result – the result value of our query
return_type – desired return type
- Returns
type, the query value as the return type requested
- static get_handler(query_result_type, return_type)[source]
Find the appropriate return type handler to convert the query result to the desired return type
- Parameters
query_result_type – type, desired return type
return_type – type, actual return type
- Returns
callable, function that will handle the conversion
- class nomenclate.core.configurator.ConfigParse(data: Optional[dict] = None, config_filename: Optional[str] = None)[source]
Bases:
object
Responsible for finding + loading the configuration file contents then transmuting any config queries. It can also be simply set from a dictionary.
- config_entry_handler = <nomenclate.core.configurator.ConfigEntryFormatter object>
- create_user_config()[source]
- get(query_path=None, return_type=<class 'list'>, preceding_depth: Optional[int] = None)[source]
Traverses the list of query paths to find the data requested
- Parameters
query_path – (list(str), str), list of query path branches or query string Default behavior: returns list(str) of possible config headers
return_type – (list, str, dict, OrderedDict), desired return type for the data
preceding_depth – int, returns a dictionary containing the data that traces back up the path for x depth -1: for the full traversal back up the path None: is default for no traversal
- Returns
(list, str, dict, OrderedDict), the type specified from return_type
- Raises
exceptions.ResourceNotFoundError: if the query path is invalid
- set_from_dict(data: dict)[source]
Set the config from a dictionary to allow for non-config file based real time modifications to the config. :param data: dict, the input data that will override the current config settings.
- set_from_file(config_filename)[source]
Loads from file and caches all data from the config file in the form of an OrderedDict to self.data
- Parameters
config_filepath – str, the full filepath to the config file
- Returns
bool, success status
- classmethod validate_config_file(config_filename: str)[source]
- class nomenclate.core.configurator.DictToList[source]
Bases:
nomenclate.core.configurator.BaseFormatter
- converts = {'accepted_input_type': <class 'dict'>, 'accepted_return_type': <class 'list'>}
- static format_result(input)[source]
Always sorted for order
- class nomenclate.core.configurator.DictToOrderedDict[source]
Bases:
nomenclate.core.configurator.BaseFormatter
- converts = {'accepted_input_type': <class 'dict'>, 'accepted_return_type': <class 'collections.OrderedDict'>}
- static format_result(input)[source]
From: http://stackoverflow.com/questions/13062300/convert-a-dict-to-sorted-dict-in-python
- class nomenclate.core.configurator.DictToString[source]
Bases:
nomenclate.core.configurator.BaseFormatter
- converts = {'accepted_input_type': <class 'dict'>, 'accepted_return_type': <class 'str'>}
- static format_result(input)[source]
- class nomenclate.core.configurator.FormatterRegistry(name, bases, dct)[source]
Bases:
type
Factory class responsible for registering all input type to type conversions. E.G. - String -> List, Dict -> String etc.
- CONVERSION_TABLE = {<class 'str'>: {<class 'list'>: <class 'nomenclate.core.configurator.StringToList'>}, <class 'dict'>: {<class 'str'>: <class 'nomenclate.core.configurator.DictToString'>, <class 'list'>: <class 'nomenclate.core.configurator.DictToList'>, <class 'collections.OrderedDict'>: <class 'nomenclate.core.configurator.DictToOrderedDict'>}, <class 'collections.OrderedDict'>: {<class 'list'>: <class 'nomenclate.core.configurator.OrderedDictToList'>}, <class 'NoneType'>: {<class 'dict'>: <class 'nomenclate.core.configurator.NoneToDict'>}, <class 'list'>: {<class 'str'>: <class 'nomenclate.core.configurator.ListToString'>}, <class 'int'>: {<class 'list'>: <class 'nomenclate.core.configurator.IntToList'>}}
- classmethod get_by_take_and_return_type(input_type, return_type)[source]
- class nomenclate.core.configurator.IntToList[source]
Bases:
nomenclate.core.configurator.BaseFormatter
- converts = {'accepted_input_type': <class 'int'>, 'accepted_return_type': <class 'list'>}
- static format_result(input)[source]
- class nomenclate.core.configurator.ListToString[source]
Bases:
nomenclate.core.configurator.BaseFormatter
- converts = {'accepted_input_type': <class 'list'>, 'accepted_return_type': <class 'str'>}
- static format_result(input)[source]
- class nomenclate.core.configurator.NoneToDict[source]
Bases:
nomenclate.core.configurator.BaseFormatter
- converts = {'accepted_input_type': <class 'NoneType'>, 'accepted_return_type': <class 'dict'>}
- static format_result(input)[source]
From: http://stackoverflow.com/questions/13062300/convert-a-dict-to-sorted-dict-in-python
- class nomenclate.core.configurator.OrderedDictToList[source]
Bases:
nomenclate.core.configurator.BaseFormatter
- converts = {'accepted_input_type': <class 'collections.OrderedDict'>, 'accepted_return_type': <class 'list'>}
- static format_result(input)[source]
From: http://stackoverflow.com/questions/13062300/convert-a-dict-to-sorted-dict-in-python