extended_data.primitives.formats.hcl¶
Utilities for decoding and encoding HCL2 data.
Module Contents¶
Functions¶
Return whether the given string can be emitted as a bare HCL identifier. |
|
Remove one parser-added string-literal layer when present. |
|
Normalize raw python-hcl2 output into plain Python data. |
|
Serialize a mapping key for HCL object and attribute contexts. |
|
Serialize a block label as a quoted HCL string. |
|
Serialize a supported scalar value to HCL. |
|
Append a trailing comma to the last line of a rendered value. |
|
Heuristically determine whether a mapping is a block body. |
|
Extract labels and a body mapping from a block-list item. |
|
Return whether a generic block item looks like a labeled block. |
|
Determine whether a list of mappings should be emitted as HCL blocks. |
|
Serialize a list value in HCL syntax. |
|
Serialize a mapping as an HCL object value. |
|
Serialize a supported HCL value. |
|
Serialize an HCL body mapping. |
|
Decodes HCL2 data into a Python object. |
|
Encode plain Terraform-style data into an HCL2 string. |
Data¶
API¶
- extended_data.primitives.formats.hcl._HCL_METADATA_KEYS = 'frozenset(...)'¶
- extended_data.primitives.formats.hcl._HCL_ONE_LABEL_BLOCKS = 'frozenset(...)'¶
- extended_data.primitives.formats.hcl._HCL_TWO_LABEL_BLOCKS = 'frozenset(...)'¶
- extended_data.primitives.formats.hcl._HCL_UNLABELED_BLOCKS = 'frozenset(...)'¶
- extended_data.primitives.formats.hcl._IDENTIFIER_CHARS = 'frozenset(...)'¶
- extended_data.primitives.formats.hcl._QUOTED_STRING_MIN_LENGTH = 2¶
- extended_data.primitives.formats.hcl._is_hcl_identifier(value: str) bool¶
Return whether the given string can be emitted as a bare HCL identifier.
- extended_data.primitives.formats.hcl._strip_hcl_parser_quotes(value: str) str¶
Remove one parser-added string-literal layer when present.
- extended_data.primitives.formats.hcl._normalize_hcl_value(value: Any) Any¶
Normalize raw python-hcl2 output into plain Python data.
- extended_data.primitives.formats.hcl._serialize_hcl_key(key: Any) str¶
Serialize a mapping key for HCL object and attribute contexts.
- extended_data.primitives.formats.hcl._serialize_hcl_label(label: Any) str¶
Serialize a block label as a quoted HCL string.
- extended_data.primitives.formats.hcl._serialize_hcl_scalar(value: Any) str¶
Serialize a supported scalar value to HCL.
- extended_data.primitives.formats.hcl._with_trailing_comma(rendered: str) str¶
Append a trailing comma to the last line of a rendered value.
- extended_data.primitives.formats.hcl._mapping_looks_like_block_body(value: collections.abc.Mapping[Any, Any]) bool¶
Heuristically determine whether a mapping is a block body.
- extended_data.primitives.formats.hcl._extract_block_instance(block_name: str, instance: Any) tuple[list[str], collections.abc.Mapping[str, Any]]¶
Extract labels and a body mapping from a block-list item.
- extended_data.primitives.formats.hcl._looks_like_generic_labeled_block_instance(instance: Any) bool¶
Return whether a generic block item looks like a labeled block.
- extended_data.primitives.formats.hcl._is_hcl_block_list(block_name: str, value: Any) bool¶
Determine whether a list of mappings should be emitted as HCL blocks.
- extended_data.primitives.formats.hcl._serialize_hcl_list(values: list[Any], indent_level: int) str¶
Serialize a list value in HCL syntax.
- extended_data.primitives.formats.hcl._serialize_hcl_object(mapping: collections.abc.Mapping[str, Any], indent_level: int) str¶
Serialize a mapping as an HCL object value.
- extended_data.primitives.formats.hcl._serialize_hcl_value(value: Any, indent_level: int) str¶
Serialize a supported HCL value.
- extended_data.primitives.formats.hcl._serialize_hcl_body(mapping: collections.abc.Mapping[str, Any], indent_level: int) str¶
Serialize an HCL body mapping.
- extended_data.primitives.formats.hcl.decode_hcl2(hcl2_data: str | memoryview | bytes | bytearray) Any¶
Decodes HCL2 data into a Python object.
Args: hcl2_data (str | memoryview | bytes | bytearray): The HCL2 data to decode.
Returns: Any: The decoded Python object.
Raises: ParseError If the HCL2 data cannot be decoded. UnexpectedToken If the HCL2 data cannot be parsed.