ini2toml.types¶
- class ini2toml.types.Commented(value: T | NotGiven = NotGiven.NOT_GIVEN, comment: str | None = None)[source]¶
Bases:
Generic[T]- as_commented_list() CommentedList[T][source]¶
- class ini2toml.types.CommentedKV(data: Sequence[Commented[List[Tuple[str, T]]]] = ())[source]¶
-
- to_ir() IntermediateRepr[source]¶
CommentedKVare usually intended to represent INI options, whileIntermediateReprare usually intended to represent INI sections. Therefore this function allows “promoting” an option-equivalent to a section-equivalent representation.
- 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 akeyto be specified.
- insert(position: int, key: str | HiddenKey | Tuple[str | HiddenKey, ...], value: Any)[source]¶
Simulate the position-aware
collections.abc.MutableMapping.insert()method, but also require akeyto 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_keycannot be already present, and that trying to rename a non-pre-existing key will also result in error (unlessignore_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_keysthat existing in the intermediate representation, and replaces it withnew_key(similar toreplace()). All the other keys inexisting_keysare removed and the value ofnew_keyis set tovalue.
- class ini2toml.types.ProfileAugmentation(*args, **kwargs)[source]¶
Bases:
Protocol
- 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
nameandhelp_textcan be used to customise the description featured inini2toml’s CLI, but when these arguments are not given (or empty strings),nameis taken fromfn.__name__andhelp_textis taken fromfn.__doc__(docstring).