FlexibleIO¶
- class upsilonconf.io.FlexibleIO(ext_io_map: Mapping[str, ConfigIO], default_ext: str | None = None)[source]¶
IO for selecting IOs based on file extensions.
This IO keeps a mapping from file extensions to their corresponding IOs. Whenever a file needs to be read/written, the file extension is used to retrieve the correct IO and forward the read/write operation.
Added in version 0.5.0.
Deprecated since version 0.7.0: FlexibleIO will be removed in a future version in favour of ExtensionIO.
- Parameters:
- ext_io_mapMapping[str, ConfigIO]
A
dict
-like object mapping extensions to the corresponding IO. The file extension should include the starting period (.
).- default_extstr, optional
The extension (and corresponding IO) to use when no information on the file-extension is available. If not specified, the first key in ext_io_map is used.
- property extensions¶
Collection of extensions that are supported by this IO.
- update(ext: str, config_io: ConfigIO) None [source]¶
Add or update the IO for an extension.
- Parameters:
- extstr
The file extension to add IO for. Extensions should include the starting period (
.
).- config_ioConfigIO
The IO to use for files with extension ext.
- Raises:
- ValueError
If ext does not start with a period (
.
).
- read_from(stream)[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.
- read(path, encoding='utf-8')[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.