FoamFormatter

class dictIO.formatter.FoamFormatter

Bases: NativeFormatter

Formatter to serialize a dict into a string in OpenFOAM dictionary format.

__init__() → None

Define default configuration for FoamFormatter.

Return type:

None

Methods

__init__()

Define default configuration for FoamFormatter.

add_double_quotes(arg)

Add double quotes to a string.

add_single_quotes(arg)

Add single quotes to a string.

format_bool(arg)

Format a boolean.

format_dict(arg[, tab_len, level, sep, ...])

Serialize a mapping, sequence, or scalar value.

format_empty_string(arg)

Format an empty string.

format_expression_string(arg)

Format an expression.

format_float(arg)

Format a floating point number.

format_int(arg)

Format an integer.

format_key(arg)

Format a key.

format_multi_word_string(arg)

Format a multi word string.

format_none()

Format None.

format_reference_string(arg)

Format a reference.

format_single_word_string(arg)

Format a single word string.

format_string(arg)

Format a string.

format_string_with_nested_string(arg)

Format a string that contains a nested string.

format_value(arg)

Format a single value.

format_values(arg)

Format multiple values.

get_formatter([target_file])

Return a Formatter instance matching the type of the target file to be formatted (factory method).

insert_block_comments(s_dict, s)

Replace block-comment placeholders with their original text.

insert_includes(s_dict, s)

Replace include placeholders with their source directives.

insert_line_comments(s_dict, s)

Replace line-comment placeholders with their original comments.

make_default_block_comment([block_comment])

Ensure an OpenFOAM header precedes the supplied block comment.

remove_trailing_spaces(s)

Remove trailing spaces from all lines.

to_string(arg)

Create a string representation of the passed in dict in OpenFOAM dictionary format.

format_empty_string(arg: str) → str

Format an empty string.

Parameters:

arg (str) – the empty string to be formatted

Returns:

the formatted empty string

Return type:

str

format_expression_string(arg: str) → str

Format an expression.

Parameters:

arg (str) – the expression to be formatted

Returns:

the formatted expression

Return type:

str

format_multi_word_string(arg: str) → str

Format a multi word string.

Parameters:

arg (str) – the multi word string to be formatted

Returns:

the formatted multi word string

Return type:

str

format_string_with_nested_string(arg: str) → str

Format a string that contains a nested string.

Parameters:

arg (str) – the string with a nested string to be formatted

Returns:

the formatted string with a nested string

Raises:

ValueError – If the input does not contain a nested quote.

Return type:

str

make_default_block_comment(block_comment: str = '') → str

Ensure an OpenFOAM header precedes the supplied block comment.

Parameters:

block_comment (str) – Existing block comment. If it contains a C++ marker and the OpenFOAM header, leave it unchanged. If it has no C++ marker, prepend the default OpenFOAM header. Defaults to “”.

Returns:

Block comment with the OpenFOAM header prepended when needed.

Return type:

str

to_string(arg: MutableMapping[K, V]) → str

Create a string representation of the passed in dict in OpenFOAM dictionary format.

Parameters:

arg (MutableMapping[K, V]) – dict to be formatted

Returns:

string representation of the dict in OpenFOAM dictionary format

Return type:

str