ConfigIO¶
- class upsilonconf.io.ConfigIO[source]¶
Interface for reading/writing configurations to/from files.
Added in version 0.5.0.
- abstract property extensions: Sequence[str]¶
Collection of extensions that are supported by this IO.
- property default_ext: str¶
Default extension for this IO.
- abstract read_from(stream: TextIO) Dict[str, Any] [source]¶
Read configuration from a file-like object.
- Parameters:
- streamTextIO
Readable character stream (file-like object).
- Returns:
- configdict
A dictionary representing the configuration in the stream.
- Raises:
- TypeError
If the implementation does not support reading from a stream.
- parse_value(val: str) bool | int | float | str | list | Dict[str, Any] [source]¶
Parse string representing a value for a configuration without key.
Added in version 0.8.0.
- Parameters:
- valstr
The string representing the value.
- Returns:
- objany basic type
The value object represented by val.
- read(path: Path | str, encoding: str = 'utf-8') Dict[str, Any] [source]¶
Read configuration from a file.
- Parameters:
- pathPath
Path to a readable text file.
- encodingstr, optional
The character encoding to use for the given file.
- Returns:
- configdict
A dictionary representing the configuration in the file.
- load_config(path: Path | str, key_mods: Mapping[str, str] | None = None, frozen: bool = False) ConfigurationBase [source]¶
Load configuration from a file.
Deprecated since version 0.8.0: ConfigIO.load_config will be replaced by ConfigurationBase.load
- Parameters:
- pathPath or str
Path to a readable text file on disk.
- key_modsdict, optional
A mapping from key patterns to their respective replacement. With multiple patterns, longer patterns are replaced first.
- frozenbool, optional
If
True
, an immutable configuration object will be created. IfFalse
(the default), a mutable configuration object is returned.
- Returns:
- configConfigurationBase
A configuration object with the values as provided in the file.
See also
ConfigurationBase.from_dict
method used for key modifications
PlainConfiguration
mutable configuration type
FrozenConfiguration
immutable configuration type
- abstract write_to(stream: TextIO, conf: Mapping[str, Any]) None [source]¶
Write configuration to a file-like object.
- Parameters:
- streamTextIO
Writeable character stream (file-like object).
- confMapping
A dictionary representing the configuration to be written.
- Raises:
- TypeError
If the implementation does not support writing to a stream.
- write(conf: Mapping[str, Any], path: Path | str, encoding: str = 'utf-8') None [source]¶
Write configuration to a file.
- Parameters:
- confMapping
A dictionary representing the configuration to be written.
- pathPath or str
Path to a writeable text file.
- encodingstr, optional
The character encoding to use for the given file.
- save_config(config: ConfigurationBase, path: Path | str, key_mods: Mapping[str, str] | None = None) None [source]¶
Save configuration to a file.
Deprecated since version 0.8.0: ConfigIO.save_config will be replaced by ConfigurationBase.save
- Parameters:
- configConfigurationBase
The configuration object to save.
- pathPath or str
Path to a writeable location on disk.
- key_modsdict, optional
A mapping from key patterns to their respective replacement. With multiple patterns, longer patterns are replaced first.
See also
ConfigurationBase.to_dict
method used for key modifications