parser_interface#
- tools.parser_interface.argspec(func)[source]#
DESCRIPTION:
This function collects the attributes for a specified Callable object and returns a SimpleNamespace object containing the argspec attributes.
- Parameters:
- func:
Callable A Python Callable function from which to collect the respective allowable arguments.
- func:
- Returns:
- argspec_obj:
SimpleNamespace A Python SimpleNamespace object containing the Callable function object allowable arguments.
- argspec_obj:
- Return type:
SimpleNamespace
- tools.parser_interface.dict_formatter(in_dict)[source]#
DESCRIPTION:
This function formats a Python dictionary; all UNICODE and data-type conversions are performed within this function.
- Parameters:
- in_dict:
Dict A standalone Python dictionary to be formatted.
- in_dict:
- Returns:
- out_dict:
Dict A standalone Python dictionary which has been formatted.
- out_dict:
- Return type:
Dict
- tools.parser_interface.dict_key_case(dict_in, lowercase=False, uppercase=False)[source]#
DESCRIPTION:
This function appends either lower-, upper-, or both lower- and uppercase key and value pairs to the Python dictionary specified upon entry.
- Parameters:
- dict_in:
Dict A Python dictionary to be updated.
- dict_in:
- Keywords:
- lower:
bool, optional A Python boolean valued variable specifying whether to append lowercase key and value pairs to the Python dictionary specified upon entry.
- upper:
bool, optional A Python boolean valued variable specifying whether to append uppercase key and value pairs to the Python dictionary specified upon entry.
- lower:
- Returns:
- dict_out:
Dict An updated Python dictionary; if both lowercase and uppercase are False upon entry, dict_in specified upon entry is returned.
- dict_out:
- Return type:
Dict
- tools.parser_interface.dict_key_remove(dict_in, key)[source]#
DESCRIPTION:
This function attempts to remove a Python dictionary key and value pair.
- Parameters:
- dict_in:
Dict A Python dictionary to be parsed.
- key:
str A Python string indicating the dictionary key within the Python dictionary (see above).
- dict_in:
- Returns:
- dict_in:
Dict A Python dictionary from which the specified key and value pair has been removed (if present in the Python dictionary on entry).
- dict_in:
- Return type:
Dict
- tools.parser_interface.dict_key_value(dict_in, key, force=False, max_value=False, min_value=False, index_value=None, no_split=False)[source]#
DESCRIPTION:
This function ingests a Python dictionary and a dictionary key and return the value(s) corresponding to the respective dictionary key; if the optional variable force is True and the dictionary key does not exist within the Python dictionary, the function will return NoneType.
- Parameters:
- dict_in:
Dict A Python dictionary to be parsed.
- key:
str A Python string indicating the dictionary key within the Python dictionary (see above).
- dict_in:
- Keywords:
- force:
str, optional A Python boolean variable; if True and in the absence of the respective dictionary key within the Python dictionary, NoneType is returned.
- max_value:
bool, optional A Python boolean variable; if True, and a Python list yielded via the Python dictionary key, the maximum value within the Python list will be returned; the default value is False.
- min_value:
bool, optional A Python boolean variable; if True, and a Python list yielded via the Python dictionary key, the minimum value within the Python list will be returned; the default value is False.
- index_value:
int, optional A Python integer defining the index within the Python list (as yielded by the Python dictionary key) to return; the default value is NoneType.
- no_split:
bool, optional A Python boolean variable; if True and if a string, the string will not be split into and returned as a comma-delimited list.
- force:
- Returns:
- value:
Union[List, Any] A list of values collected from the ingested Python dictionary and the respective dictionary key if no_split is False; a string otherwise.
- value:
- Raises:
- ParserInterfaceError:
raised if both minimum and maximum values of a list are requested; only minimum or only maximum may be requested upon entry.
raised if the keyword argument combinations passed upon entry are incorrect.
- Return type:
Union[List,Any]
- tools.parser_interface.dict_merge(dict1, dict2, lowercase=False, uppercase=False)[source]#
DESCRIPTION:
This function merges two Python dictionaries and returns a generator containing the merged Python dictionary relative to the checks within the function.
- Parameters:
- dict1:
Dict A Python dictionary to be merged.
- dict2:
Dict A Python dictionary to be merged.
- dict1:
- Keywords:
- lower:
bool, optional A Python boolean valued variable specifying whether to append lowercase key and value pairs to the Python dictionary specified upon entry.
- upper:
bool, optional A Python boolean valued variable specifying whether to append uppercase key and value pairs to the Python dictionary specified upon entry.
- lower:
- Yields:
Generator:A Python Generator containing the contents of dict1 and dict2.
- Return type:
Generator
- tools.parser_interface.dict_replace_value(in_dict, old, new)[source]#
DESCRIPTION:
This function replaces strings within a (nested) Python dictionary and returns the updated (nested) Python dictionary; this function adapted from https://tinyurl.com/dict-value-replace.
- Parameters:
- in_dict:
Dict A (nested) Python dictionary containing Python strings to be replaced/updated.
- old:
str A Python string value specifying the Python string instance to be replaced.
- new:
str A Python string value specifying the Python string to replace the value specified by the old attribute.
- in_dict:
- Returns:
- out_dict:
Dict A (nested) Python dictionary updated in accordance within the attributes specified by the old and new attributes; otherwise this Python dictionary is identical to that defined by in_dict.
- out_dict:
- Return type:
Dict
- tools.parser_interface.dict_toobject(in_dict)[source]#
DESCRIPTION:
This funcction converts and returns the Python dictionary in_dict, specified upon entry, to a Python Namespace out_obj.
- Parameters:
- in_dict:
Dict A Python dictionary containing the attribute key and value pairs to be cast as a Python Namespace.
- in_dict:
- Returns:
- out_obj:
SimpleNamespace A Python SimpleNamespace defined by casting the Python dictionary in_dict specified upon input to the respective Python SimpleNamespace.
- out_obj:
- Return type:
SimpleNamespace
- tools.parser_interface.enviro_get(envvar)[source]#
DESCRIPTION:
This function retrieves the environment variable corresponding to the specified string; if the environment variable is not defined, NoneType is returned.
- Parameters:
- envvar:
str A Python string specifying the environment variable name.
- envvar:
- Returns:
- envvarval:
Union[bool, float, int, str] A Python type that contains the query for the environment variable.
- envvarval:
- Return type:
Union[bool,float,int,str]
- tools.parser_interface.enviro_set(envvar, value)[source]#
DESCRIPTION:
This function defines the environment variable corresponding to the supported specified value.
- Parameters:
- envvar:
str A Python string specifying the environment variable name.
- value:
Union[Any] A Python value specifying the value of the environment variable.
- envvar:
- Return type:
None
- tools.parser_interface.f90_bool(value)[source]#
DESCRIPTION:
This method will transform boolean type values to a FORTRAN 90 boolean format; if the variable value specified upon entry is not of boolean format the value is returned unaltered.
- Parameters:
- value:
Any A Python variable to be evaluated as a boolean type value; if a boolean type the corresponding value is returned as a FORTRAN 90 boolean format.
- value:
- Returns:
- value:
Any An evaluated Python variable; if value was boolean type upon entry the returned value is of FORTRAN 90 boolean format; if not, the unaltered input value is returned.
- value:
- Return type:
Any
- tools.parser_interface.find_commonprefix(strings_list)[source]#
DESCRIPTION:
This function returns the common prefix from a list of strings.
- Parameters:
- strings_list:
List A Python list of strings
- strings_list:
- Returns:
- common_prefix:
str A Python string specifying the common prefix determined from a list of Python strings; NoneType if a common prefix cannot be determined.
- common_prefix:
- Return type:
str
- tools.parser_interface.handler(func, handle=<function <lambda>>, return_none=False, raise_exception=False, *args, **kwargs)[source]#
DESCRIPTION:
This method permits exceptions to raised (i.e., handled) within Python list comprehensions.
- Parameters:
- func:
Callable A Python function, often nested within a Python list comprehension, to be evaluated.
- handle:
Callable A Python lambda function to be evaluated within the list comprehension.
- func:
- Keywords:
- return_none:
bool, optional A Python boolean valued variable specifying whether to return None if an exception is encountered.
- raise_exception:
bool, optional A Python boolean values variable specifying to whether to raise the exception encountered while evaluating the function within the Python list comprehension.
- return_none:
- Returns:
- value:
Union[Any, None, Exception] A Python variable type containing the returned expression from the Python list evaluation of a function (func).
- value:
- Return type:
Union[Any,None,Exception]
- tools.parser_interface.import_func(app_obj)[source]#
DESCRIPTION:
This function imports a Python function in accordance with the attributes collected from the SimpleNamespace object.
- Parameters:
- app_obj:
SimpleNamespace A Python SimpleNamespace object containing the attributes for the respective Callable object to return.
- app_obj:
- Returns:
- func:
Union[None, Callable] A Python Callable object containing the requested function; if the function cannot be determined, NoneType is returned.
- func:
- Return type:
Optional[Callable]
- tools.parser_interface.list_get_type(in_list, dtype)[source]#
DESCRIPTION:
This function parses a list and returns a list of values in accordance with the specified data type.
- Parameters:
- in_list:
List A Python list containing values possibly of various data types.
- dtype:
str A Python string specifying the data type to be sought.
- in_list:
- Returns:
- var_list:
List A Python list contain values collected from the input list but of the specified data type.
- var_list:
- Return type:
List
- tools.parser_interface.list_replace_value(in_list, old, new)[source]#
DESCRIPTION:
This function replaces strings within a Python list and returns the updated Python list; this function adapted from https://tinyurl.com/list-value-replace.
- Parameters:
- in_list:
List A Python list containing Python strings to be replaced/updated.
- old:
str A Python string value specifying the Python string instance to be replaced.
- new:
str A Python string value specifying the Python string to replace the value specified by the old attribute.
- in_list:
- Returns:
- out_list:
List A Python list updated in accordance within the attributes specified by the old and new attributes; otherwise this Python list is identical to that defined by in_list.
- out_list:
- Return type:
List
- tools.parser_interface.match_list(in_list, match_string, exact=False)[source]#
DESCRIPTION:
This function ingests a Python list and a Python string and matches, either exact or partial, are sought for the string within the provided; if exact is True upon entry, the matching Python string is returned if a match is found; otherwise NoneType is returned; if exact is False upon entry, a list of matching Python strings is returned.
- Parameters:
- in_list:
List A Python list of strings within matches will be sought.
- match_string:
str A Python string for which to search for matches within the ingested list.
- in_list:
- Keywords:
- exact:
bool, optional A Python boolean variable; if True, a Python string will be returned assuming a match is made; if False, a Python list of strings matching match_string will be returned assuming matches can be made.
- exact:
- Returns:
- match_chk:
bool A Python boolean variable indicating whether a match (or matches) has (have) been made.
- match_str:
str A Python string (if exact is True upon entry) or a Python list of strings (if exact is False upon entry) containing all matches to the input match string; if no matches can be found, either NoneType (if exact is True upon entry) or an empty list (if exact is False upon entry) is returned.
- match_chk:
- Return type:
Tuple[bool,str]
- tools.parser_interface.object_append(object_in, object_key, dict_in)[source]#
DESCRIPTION:
This function appends the contents of Python dictionary to specified object key.
- Parameters:
- object_in:
SimpleNamespace A Python SimpleNamespace or object to be appended.
- object_key:
str A Python string value specifying the input Python object attribute.
- dict_in:
Dict A Python dictionary containing the key and value pairs to append to the input Python object.
- object_in:
- Returns:
- object_out:
SimpleNamespace A Python SimpleNamespace or object containing the appended input Python dictionary key and value pairs relative to the specified Python object attribute.
- object_out:
- Return type:
SimpleNamespace
- tools.parser_interface.object_compare(obj1, obj2)[source]#
DESCRIPTION:
This function compares two Python SimpleNamespaces or objects.
- Parameters:
- obj1:
Union[SimpleNamespace, object] A Python SimpleNamespace or object against which to compare with another SimpleNamespace or object.
- obj2:
Union[SimpleNamespace, object] A Python SimpleNamespace or object to compare to obj1 (above).
- obj1:
- Returns:
- compare:
bool A Python boolean variable specifying whether the respective Python objects are identical.
- compare:
- Return type:
bool
- tools.parser_interface.object_deepcopy(object_in)[source]#
DESCRIPTION:
This function ingests a Python object and returns a deep copy of the respective object.
- Parameters:
- object_in:
Union[SimpleNamespace, object] A Python object for which to create a deep copy.
- object_in:
- Returns:
- object_out:
Union[SimpleNamespace, object] A Python object which is a deep copy of the specified input object object_in.
- object_out:
- Return type:
Union[SimpleNamespace,object]
- tools.parser_interface.object_define()[source]#
DESCRIPTION:
This function defines an empty Python SimpleNamespace object.
- Returns:
- empty_obj:
SimpleNamespace An empty Python SimpleNamespace object.
- empty_obj:
- Return type:
SimpleNamespace
- tools.parser_interface.object_getattr(object_in, key, force=False)[source]#
DESCRIPTION:
This function ingests a Python object and a Python attribute and returns the value of the respective attribute; if force is True and the Python object attribute does not exist, this function returns NoneType.
- Parameters:
- object_in:
Union[SimpleNamespace, object] A Python SimpleNamespace or object within which to search for attributes.
- key:
str A Python string value specifying the attribute to seek.
- object_in:
- Keywords:
- force:
bool, optional A Python boolean variable; if True and in the absence of the respective attribute within the Python object, NoneType is returned.
- force:
- Returns:
- value:
Any The result of the respective attribute search.
- value:
- Raises:
- ParserInterfaceError:
raised if force is False and the Python object attribute does not exist.
- Return type:
Any
- tools.parser_interface.object_hasattr(object_in, key)[source]#
DESCRIPTION:
This function checks whether a Python object contains an attribute and returns an appropriate boolean value indicating the result of the inquiry.
- Parameters:
- object_in:
Union[SimpleNamespace, object] A Python SimpleNamespace or object within which to inquire about attributes.
- key:
str A Python string value specifying the attribute to inquire about.
- object_in:
- Returns:
- chk_attr:
bool A Python boolean value containing the result of the attribute inquiry.
- chk_attr:
- Return type:
bool
- tools.parser_interface.object_setattr(object_in, key, value)[source]#
DESCRIPTION:
This function ingests a Python SimpleNamespace or object and a Python key and value pair and defines the attributes for the respective SimpleNamespace or object.
- Parameters:
- object_in:
Union[SimpleNamespace, object] A Python SimpleNamespace or object within which to search for attributes.
- key:
str A Python string value specifying the attribute to define.
- value:
Any A Python variable value specifying the value to accompany the Python object attribute (key).
- object_in:
- Returns:
- object_out:
Union[SimpleNamespace, object] A Python SimpleNamespace or object containing the specified key and value pair (e.g., attribute).
- object_out:
- Return type:
Union[SimpleNamespace,object]
- tools.parser_interface.object_todict(object_in)[source]#
DESCRIPTION:
This function ingests a Python SimpleNamespace or object and returns a Python dictionary containing the contents of the SimpleNamespace or object.
- Parameters:
- object_in:
Union[SimpleNamespace, object] A Python SimpleNamespace or object containing specified content.
- object_in:
- Returns:
- dict_out:
Dict A Python dictionary containing the contents of the Python SimpleNamespace or object.
- dict_out:
- Return type:
Dict
- tools.parser_interface.str_to_bool(string)[source]#
DESCRIPTION:
This function converts a Python string to it’s corresponding boolean value; if a JSONDecodeError exception is encountered, NoneType is returned.
- Parameters:
- string:
str A Python string for which to convert to a corresponding boolean value.
- string:
- Returns:
- boolval:
bool A Python boolean valued variable containing the boolean value corresponding to the Python string specified upon entry; if a JSONDecodeError is encounterd, NoneType is returned.
- boolval:
- Return type:
bool
- tools.parser_interface.string_parser(in_list, remove_comma=False)[source]#
DESCRIPTION:
This function ingests a Python list of variables and returns a Python list of appropriately formatted values.
- Parameters:
- in_list:
List A Python list of variable values to be formatted.
- in_list:
- Keywords:
- remove_comma:
bool, optional A Python boolean variable specifying to remove any comma string occurances in the returned list (see out_list).
- remove_comma:
- Returns:
- out_list:
List A Python list of appropriately formatted variable values.
- out_list:
- Return type:
List
- tools.parser_interface.true_or_false(argval)[source]#
DESCRIPTION:
This function checks whether an argument is a Boolean-type value; if so, this function defines the appropriate Python boolean-type; otherwise, this function returns NoneType.
- Parameters:
- argval:
Any A value corresponding to an argument.
- argval:
- Returns:
- pytype:
Union[bool, None] A Python boolean-type value if the argument is a boolean variable; otherwise, NoneType.
- pytype:
- Return type:
Optional[bool]
- tools.parser_interface.unique_list(in_list)[source]#
DESCRIPTION:
This function ingests a list, possibly with duplicate values, and returns a list of only unique values.
- Parameters:
- in_list:
List A N-dimensional Python list containing strings.
- in_list:
- Returns:
- out_list:
List A Python list containing only uniquely-valued strings.
- out_list:
- Return type:
List
- tools.parser_interface.update_dict(default_dict, base_dict, update_none=False)[source]#
DESCRIPTION:
This function reads Python dictionaries containing default key and value pairs (default_dict) and a base (optional or changed values) Python dictionary containing key and value pairs (base_dict); the output Python dictionary output_dict is initialized with the base Python dictionary; any key and value pairs within default_dict which are not in output_dict are updated with those from default_dict.
- Parameters:
- default_dict:
Dict A Python dictionary containing default key and value pairs; this Python dictionary contains all possible key and value pairs to compute the output dictionary (output_dict).
- base_dict:
Dict A Python dictionary containing either optional or changed key and value pairs; this Python dictionary is used to initialize the output Python dictionary output_dict.
- default_dict:
- Keywords:
- update_none:
bool, optional A Python boolean valued variable specifying whether to update the output Python dictionary output_dict with None-type value occurances within the default Python dictionary default_dict.
- update_none:
- Returns:
- output_dict:
Dict A Python dictionary containing the respective attributes from the base and default Python dictionaries, base_dict and default_dict respectively.
- output_dict:
- Return type:
Dict