runway.lookups.handlers.base module¶
Base class for lookup handlers.
- class runway.lookups.handlers.base.ContextTypeVar¶
Type variable for context type.
alias of TypeVar(‘ContextTypeVar’, CfnginContext, RunwayContext, CfnginContext | RunwayContext)
- class runway.lookups.handlers.base.LookupHandler[source]¶
Bases:
ABC,Generic[ContextTypeVar]Base class for lookup handlers.
- classmethod dependencies(_lookup_query: VariableValue) set[str][source]¶
Calculate any dependencies required to perform this lookup.
Note that lookup_query may not be (completely) resolved at this time.
- classmethod format_results(value: Any, get: str | None = None, load: str | None = None, transform: Literal['bool', 'str'] | None = None, **kwargs: Any) Any[source]¶
Format results to be returned by a lookup.
- Parameters:
value – Data collected by the Lookup.
get – Nested value to get from a dictionary like object.
load – Parser to use to parse a formatted string before the
getandtransformmethod.transform – Convert the final value to a different data type before returning it.
**kwargs – Arbitrary keyword arguments.
- Raises:
TypeError – If
getis provided but the value value is not a dictionary like object.
Runs the following actions in order:
load()ifloadis provided.runway.util.MutableMap.find()ordict.get()depending on the data type ifgetis provided.Convert null value string to
NoneTypeobject. This includes string values of “None” and “null”. This conversion is case insensitive.transform()iftransformis provided.
- abstract classmethod handle(value: str, context: ContextTypeVar, *, provider: Provider, **_kwargs: Any) Any[source]¶
- abstract classmethod handle(value: str, context: ContextTypeVar, **_kwargs: Any) Any
Perform the lookup.
- Parameters:
value – Parameter(s) given to the lookup.
context – The current context object.
provider – CFNgin AWS provider.
- classmethod load(value: Any, parser: str | None = None, **kwargs: Any) Any[source]¶
Load a formatted string or object into a python data type.
First action taken in
format_results(). If a lookup needs to handling loading data to process it before it entersformat_results(), is should useargs.pop('load')to prevent the data from being loaded twice.- Parameters:
value – What is being loaded.
parser – Name of the parser to use.
**kwargs – Arbitrary keyword arguments.
- Returns:
The loaded value.
- classmethod parse(value: str) tuple[str, ParsedArgsTypeDef][source]¶
Parse the value passed to a lookup in a standardized way.
- Parameters:
value – The raw value passed to a lookup.
- Returns:
The lookup query and a dict of arguments
- classmethod transform(value: Any, *, to_type: Literal['bool', 'str'] | None = 'str', **kwargs: Any) Any[source]¶
Transform the result of a lookup into another datatype.
Last action taken in
format_results(). If a lookup needs to handling transforming the data in a way that the base class can’t support it should overwrite this method of the base class to register different transform methods.- Parameters:
value – What is to be transformed.
to_type – The type the value will be transformed into.
**kwargs – Arbitrary keyword arguments.
- Returns:
The transformed value.
- class runway.lookups.handlers.base.ParsedArgsTypeDef[source]¶
Bases:
TypedDictPartial type definition for the args returned by
LookupHandler.parse().This class can be subclassed to model all expected arguments if needed.