NativeFormatter

class dictIO.formatter.NativeFormatter

Bases: Formatter

Formatter to serialize a dict into a string in dictIO native file format.

__init__() None

Define default configuration for NativeFormatter.

Methods

__init__()

Define default configuration for NativeFormatter.

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, ...])

Format a dict or list object.

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)

Insert back all block comments.

insert_includes(s_dict, s)

Insert back all include directives.

insert_line_comments(s_dict, s)

Insert back all line directives.

make_default_block_comment([block_comment])

Create the default block comment (header) for files in dictIO native file format.

remove_trailing_spaces(s)

Remove trailing spaces from all lines.

to_string(arg)

Create a string representation of the passed in dict in dictIO native file format.

format_bool(arg: bool) str

Format a boolean.

Parameters:

arg (bool) – the boolean value to be formatted

Returns:

the formatted string representation of the passed in boolean value

Return type:

str

format_dict(arg: MutableMapping[Any, Any] | MutableSequence[Any] | Any, tab_len: int = 4, level: int = 0, sep: str = ' ', items_per_line: int = 10, end: str = '\n', ancestry: type[MutableMapping[Any, Any] | MutableSequence[Any]] = MutableMapping) str

Format a dict or list object.

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_none() str

Format None.

Returns:

the formatted string representation of None

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

Return type:

str

insert_block_comments(s_dict: SDict[K, V], s: str) str

Insert back all block comments.

Replaces all BLOCKCOMMENT placeholders in s with the actual block_comments saved in dict str s is expected to contain the SDict’s block_content containing block comment placeholders to substitute (BLOCKCOMMENT… BLOCKCOMMENT…)

insert_includes(s_dict: SDict[K, V], s: str) str

Insert back all include directives.

insert_line_comments(s_dict: SDict[K, V], s: str) str

Insert back all line directives.

make_default_block_comment(block_comment: str = '') str

Create the default block comment (header) for files in dictIO native file format.

remove_trailing_spaces(s: str) str

Remove trailing spaces from all lines.

Reads all lines from the passed in string, removes trailing spaces from each line and returns a new string with trailing spaces removed.

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

Create a string representation of the passed in dict in dictIO native file format.

Parameters:

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

Returns:

string representation of the dict in dictIO native file format

Return type:

str