msticpy.common.utility.types module
Utility classes and functions.
- class msticpy.common.utility.types.ImportPlaceholder(name, required_pkgs)
Bases:
objectPlaceholder class for optional imports.
Initialize class with imported item name and reqd. packages.
- Parameters:
name (str)
required_pkgs (list[str])
- class msticpy.common.utility.types.ParseableEnum
Bases:
objectMix-in class for parseable Enum sub-classes.
- parse(value)
Return enumeration matching (case-insensitive) string value.
- Parameters:
self (Self)
value (str)
- Return type:
Enum | None
- class msticpy.common.utility.types.SingletonArgsClass(wrapped_cls)
Bases:
SingletonClassSingletonArgs decorator class.
Notes
Using this decorator on a class enforces the following behavior:
First instantiation of class will work as normal
Subsequent attempts with the same set/values of kwargs will just return the original class
Instantiation of the class with a different set of kwargs will instantiate a new class.
The class method current() will always return the last instance of the class.
Instantiate the class wrapper.
- Parameters:
wrapped_cls (type[Any])
- current()
Return the current instance of the wrapped class.
- Parameters:
self (Self)
- Return type:
object
- class msticpy.common.utility.types.SingletonClass(wrapped_cls)
Bases:
objectSingleton decorator class.
Notes
Using this decorator on a class enforces the following behavior:
First instantiation of class will work as normal
Subsequent attempts with the same set/values of kwargs will just return the original class
The class method current() will always return the last instance of the class.
Instantiate the class wrapper.
- Parameters:
wrapped_cls (type[Any])
- current()
Return the current instance of the wrapped class.
- Parameters:
self (Self)
- Return type:
object
- msticpy.common.utility.types.arg_to_list(arg, delims=',; ')
Convert an optional list/str/str with delims into a list.
- Parameters:
arg (Union[str, list[str]]) – A string, delimited string or list
delims (str, optional) – The default delimiters to use, by default “,; “
- Returns:
List of string components
- Return type:
list[str]
- Raises:
TypeError – If arg is not a string or list
- msticpy.common.utility.types.check_kwarg(arg_name, legal_args)
Check argument names against a list.
- Parameters:
arg_name (str) – Argument to check
legal_args (list[str]) – List of possible arguments.
- Raises:
NameError – If the argument is not legal. If the arg_name is a close match to one or more, legal_args these are returned in the exception.
- Return type:
None
- msticpy.common.utility.types.check_kwargs(supplied_args, legal_args)
Check all kwargs names against a list.
- Parameters:
supplied_args (dict[str, Any]) – Arguments to check
legal_args (list[str]) – List of possible arguments.
- Raises:
NameError – If any of the arguments are not legal. If the an arg is a close match to one or more legal_args, these are returned in the exception.
- Return type:
None
- msticpy.common.utility.types.checked_kwargs(legal_args)
Decorate function to check kwargs names against legal arg names.
- Parameters:
legal_args (Iterable[str]) – Iterable of possible arguments.
- Raises:
NameError – If any of the arguments are not legal. If the an arg is a close match to one or more legal_args, these are returned in the exception.
Notes
The checking is done against the union of legal_args and any named arguments of the wrapped function.
- msticpy.common.utility.types.collapse_dicts(*dicts)
Merge multiple dictionaries - later dicts have higher precedence.
- Parameters:
dicts (dict)
- Return type:
dict
- msticpy.common.utility.types.enum_parse(enum_cls, value)
Try to parse a string value to an Enum member.
- Parameters:
enum_cls (EnumType) – The Enum type to check against
value (str) – The enum value to parse
- Returns:
The enumeration value matching value or None
- Return type:
Optional[EnumType]
- Raises:
TypeError – If something other than an Enum subclass is passed.