ini2toml.types

class ini2toml.types.CommentKey[source]

Bases: HiddenKey

class ini2toml.types.Commented(value: T | NotGiven = NotGiven.NOT_GIVEN, comment: str | None = None)[source]

Bases: Generic[T]

as_commented_list() CommentedList[T][source]
comment_only()[source]
has_comment()[source]
value_or(fallback: S) T | S[source]
class ini2toml.types.CommentedKV(data: Sequence[Commented[List[Tuple[str, T]]]] = ())[source]

Bases: Generic[T], UserList

as_dict() dict[source]
find(key: str) Tuple[int, int] | None[source]
insert_line(i, values: Iterable[Tuple[str, T]], comment: str | None = None)[source]
to_ir() IntermediateRepr[source]

CommentedKV are usually intended to represent INI options, while IntermediateRepr are usually intended to represent INI sections. Therefore this function allows “promoting” an option-equivalent to a section-equivalent representation.

class ini2toml.types.CommentedList(data: Sequence[Commented[List[T]]] = ())[source]

Bases: Generic[T], UserList

as_list() list[source]
insert_line(i, values: Iterable[T], comment: str | None = None)[source]
class ini2toml.types.HiddenKey[source]

Bases: object

class ini2toml.types.IntermediateRepr(elements: Mapping[str | HiddenKey | Tuple[str | HiddenKey, ...], Any] = mappingproxy({}), order: Sequence[str | HiddenKey | Tuple[str | HiddenKey, ...]] = (), inline_comment: str = '', **kwargs)[source]

Bases: MutableMapping

append(key: str | HiddenKey | Tuple[str | HiddenKey, ...], value: Any)[source]

Simulate the position-aware collections.abc.MutableMapping.append() method, but also require a key to be specified.

copy() R[source]
index(key: str | HiddenKey | Tuple[str | HiddenKey, ...]) int[source]

Find the position of key

insert(position: int, key: str | HiddenKey | Tuple[str | HiddenKey, ...], value: Any)[source]

Simulate the position-aware collections.abc.MutableMapping.insert() method, but also require a key to be specified.

rename(old_key: str | HiddenKey | Tuple[str | HiddenKey, ...], new_key: str | HiddenKey | Tuple[str | HiddenKey, ...], ignore_missing=False)[source]

This method renames an existing key, without changing its position. Notice that new_key cannot be already present, and that trying to rename a non-pre-existing key will also result in error (unless ignore_missing=True).

replace_first_remove_others(existing_keys: Sequence[str | HiddenKey | Tuple[str | HiddenKey, ...]], new_key: str | HiddenKey | Tuple[str | HiddenKey, ...], value: Any)[source]

Find the first key in existing_keys that existing in the intermediate representation, and replaces it with new_key (similar to replace()). All the other keys in existing_keys are removed and the value of new_key is set to value.

class ini2toml.types.Profile(*args, **kwargs)[source]

Bases: Protocol

help_text: str
intermediate_processors: List[Callable[[R], R]]
name: str
post_processors: List[Callable[[str], str]]
pre_processors: List[Callable[[str], str]]
class ini2toml.types.ProfileAugmentation(*args, **kwargs)[source]

Bases: Protocol

active_by_default: bool
fn(profile: Profile)[source]
help_text: str
is_active(explicitly_active: bool | None = None) bool[source]

explicitly_active is a tree-state variable: True if the user explicitly asked for the augmentation, False if the user explicitly denied the augmentation, or None otherwise.

name: str
class ini2toml.types.Translator(*args, **kwargs)[source]

Bases: Protocol

augment_profiles(fn: Callable[[Profile], None], active_by_default: bool = False, name: str = '', help_text: str = '')[source]

Register a profile augmentation function (see Core Concepts). The keyword name and help_text can be used to customise the description featured in ini2toml’s CLI, but when these arguments are not given (or empty strings), name is taken from fn.__name__ and help_text is taken from fn.__doc__ (docstring).

class ini2toml.types.WhitespaceKey[source]

Bases: HiddenKey