extended_data.primitives.formats.hcl

Utilities for decoding and encoding HCL2 data.

Module Contents

Functions

_is_hcl_identifier

Return whether the given string can be emitted as a bare HCL identifier.

_strip_hcl_parser_quotes

Remove one parser-added string-literal layer when present.

_normalize_hcl_value

Normalize raw python-hcl2 output into plain Python data.

_serialize_hcl_key

Serialize a mapping key for HCL object and attribute contexts.

_serialize_hcl_label

Serialize a block label as a quoted HCL string.

_serialize_hcl_scalar

Serialize a supported scalar value to HCL.

_with_trailing_comma

Append a trailing comma to the last line of a rendered value.

_mapping_looks_like_block_body

Heuristically determine whether a mapping is a block body.

_extract_block_instance

Extract labels and a body mapping from a block-list item.

_looks_like_generic_labeled_block_instance

Return whether a generic block item looks like a labeled block.

_is_hcl_block_list

Determine whether a list of mappings should be emitted as HCL blocks.

_serialize_hcl_list

Serialize a list value in HCL syntax.

_serialize_hcl_object

Serialize a mapping as an HCL object value.

_serialize_hcl_value

Serialize a supported HCL value.

_serialize_hcl_body

Serialize an HCL body mapping.

decode_hcl2

Decodes HCL2 data into a Python object.

encode_hcl2

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.

extended_data.primitives.formats.hcl.encode_hcl2(data: Any) str

Encode plain Terraform-style data into an HCL2 string.

Args: data (Any): The Python object to encode.

Returns: str: The encoded HCL2 string.