specfile.value_parser
Node
class Node(ABC)
Base class for all nodes.
StringLiteral
class StringLiteral(Node)
Node representing string literal.
ShellExpansion
class ShellExpansion(Node)
Node representing shell expansion, e.g. %(whoami).
ExpressionExpansion
class ExpressionExpansion(ShellExpansion)
Node representing expression expansion, e.g. %[1+1].
MacroSubstitution
class MacroSubstitution(Node)
Node representing macro substitution, e.g. %version.
EnclosedMacroSubstitution
class EnclosedMacroSubstitution(Node)
Node representing macro substitution enclosed in brackets, e.g. %{?dist}.
ConditionalMacroExpansion
class ConditionalMacroExpansion(Node)
Node representing conditional macro expansion, e.g. %{?prerel:0.}.
BuiltinMacro
class BuiltinMacro(Node)
Node representing built-in macro, e.g. %{quote:Ancient Greek}.
ValueParser
class ValueParser()
flatten
@classmethod
def flatten(cls, nodes: List[Node]) -> Generator[Node, None, None]
Generator that yields flattened nodes. Conditional macro expansions are treated as if their conditions were true and their bodies are flattened.
Arguments:
nodes
- List of nodes to be flattened.
Yields:
Individual nodes.
parse
@classmethod
def parse(cls, value: str) -> List[Node]
Parses a value into a list of nodes.
Follows the parsing logic of expandMacro()
from rpm/rpmio/macro.c in RPM source.
Arguments:
value
- Value string to parse.
Returns:
Parsed value as a list of nodes.
Raises:
UnterminatedMacroException
- If there is a macro that doesn't end.
construct_regex
@classmethod
def construct_regex(
cls,
value: str,
modifiable_entities: Set[str],
flippable_entities: Set[str],
context: Optional["Specfile"] = None
) -> Tuple[Pattern, Template, Set[str]]
Parses the given value and constructs a regex that allows matching substrings of a different, but similar value to macro substitutions representing modifiable entities, and to modifiable substrings of the original value. Also constructs a corresponding template that allows updating the original value.
For example, for nodes representing the string "1.%{version_minor}", assuming "version_minor" is a local macro definition (thus a modifiable entity), the resulting regex would be "^(?P<sub_0>).(?P<version_minor>.+?)$", and the corresponding template would be "${sub_0}.%{version_minor}". If a requested new value would be a match to this regex, the "version_minor" macro definition could be modified with the matching substring and the final value could be determined by performing a substitution on the template with groupdict of the match.
Arguments:
value
- Value string to parse.modifiable_entities
- Names of modifiable entities, i.e. local macro definitions and tags.flippable_entities
- Names of entities that can be enabled/disabled, i.e. macro definitions. Must be a subset of modifiable_entities.context
-Specfile
instance that defines the context for macro expansions.
Returns:
Tuple in the form of (constructed regex, corresponding template, entities to flip).