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]¶
CommentedKV
are usually intended to represent INI options, whileIntermediateRepr
are 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 akey
to 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 akey
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 (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_keys
that existing in the intermediate representation, and replaces it withnew_key
(similar toreplace()
). All the other keys inexisting_keys
are removed and the value ofnew_key
is 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
name
andhelp_text
can be used to customise the description featured inini2toml
’s CLI, but when these arguments are not given (or empty strings),name
is taken fromfn.__name__
andhelp_text
is taken fromfn.__doc__
(docstring).