vcorelib.target package#

Submodules#

vcorelib.target.evaluation module#

A module for target-evaluation interfaces.

class vcorelib.target.evaluation.DynamicTargetEvaluator(original: str, pattern: Pattern[str], keys: List[str], markers: List[Tuple[int, int]])[source]#

Bases: TargetEvaluatorInterface

A regular expression configured to match as many groups as in the provided keys. When the pattern matches some data, the names of the keys can become associated with the data that was matched inside each group.

compile_key(key: str, values: Dict[str, str | int]) str[source]#

Process the key based on substitution data.

class vcorelib.target.evaluation.TargetEvaluatorInterface(original: str, keys: List[str], markers: List[Tuple[int, int]])[source]#

Bases: ABC

An interface for evaluating targets.

compile(values: Dict[str, str | int]) str[source]#

Build a string from this target with values replaced for keys that appeared in the original string.

abstract compile_key(key: str, values: Dict[str, str | int]) str[source]#

Process the key based on substitution data.

class vcorelib.target.evaluation.TargetInterface(data: str)[source]#

Bases: ABC, Generic[T]

A generic interface for target implementations.

compile(substitutions: Dict[str, str | int] = None) str[source]#

Attempt to get a target literal from this target and optional substitutions.

dynamic_end = '}'#
dynamic_start = '{'#
classmethod is_literal(data: str) bool[source]#

Determine if a target is guaranteed to be literal or not.

abstract classmethod parse(data: str) T | None[source]#

Obtain an expression target-evaluator from provided string data. If data doesn’t contain any target-evaluation syntax, return None.

classmethod segment_count(data: str) int[source]#

Count the number of dynamic segments and validate syntax.

vcorelib.target.expression module#

A module implementing expression evaluation for targets.

class vcorelib.target.expression.ExpressionTarget(data: str)[source]#

Bases: TargetInterface[ExpressionTargetEvaluator]

A class for evaluating expressions based on substitution data.

compile_match(target: Target, data: str) str | None[source]#

If a target matches provided data, compile our expression and return the result.

classmethod parse(data: str) ExpressionTargetEvaluator | None[source]#

Obtain an expression target-evaluator from provided string data. If data doesn’t contain any target-evaluation syntax, return None.

class vcorelib.target.expression.ExpressionTargetEvaluator(original: str, keys: List[str], markers: List[Tuple[int, int]])[source]#

Bases: TargetEvaluatorInterface

An interface for evaluating expression targets.

compile_key(key: str, values: Dict[str, str | int]) str[source]#

Process the key based on substitution data.

vcorelib.target.resolver module#

Implements management of target objects.

class vcorelib.target.resolver.TargetResolution(result: TargetMatch, data: Any | None = None)[source]#

Bases: NamedTuple

A return type for the target resolver.

data: Any | None#

Alias for field number 1

result: TargetMatch#

Alias for field number 0

class vcorelib.target.resolver.TargetResolver[source]#

Bases: object

A class for registering target prototypes that can be used to match incoming data.

evaluate(data: str) TargetResolution[source]#

Find the target that matches data, if one can be found.

evaluate_all(data: Iterable[str]) Iterator[TargetResolution | str][source]#

Evaluate all targets and optionally enforce that they all matched.

register(data: str, value: Any = None) bool[source]#

Register a target to this resolver. If it is ever resolved in evaluation, value will be returned. Return whether or not any target was registered.

Module contents#

A module defining an interface for dynamic task targets.

class vcorelib.target.Target(data: str)[source]#

Bases: TargetInterface[DynamicTargetEvaluator]

An interface for string targets that may encode data substitutions or otherwise be matched to only a single, literal string.

evaluate(data: str) TargetMatch[source]#

Attempt to match this target with some string data.

classmethod parse(data: str) DynamicTargetEvaluator | None[source]#

Obtain a compiled target evaluator if data is a dynamic target, else None.

valid = '[a-zA-Z0-9-_.]+'#
class vcorelib.target.TargetMatch(matched: bool, substitutions: _Optional[Substitutions] = None)[source]#

Bases: NamedTuple

An encapsulation of results when attempting to patch a target name to a pattern. If a target was matched and had keyword substitutions, the actual values used will be set as match data.

get(data: str) str[source]#

Get data for keys that matched the target.

matched: bool#

Alias for field number 0

substitutions: Dict[str, str | int] | None#

Alias for field number 1