anyconfig.ioinfo
¶
Functions for value objects represent inputs and outputs.
New in version 0.9.5.
- Add functions to make and process input and output object holding some attributes like input and output type (path, stream or pathlib.Path object), path, opener, etc.
-
anyconfig.ioinfo.
guess_io_type
(obj)¶ Guess input or output type of
obj
.Parameters: obj – a path string, a pathlib.Path or a file / file-like object Returns: IOInfo type defined in anyconfig.globals.IOI_TYPES >>> apath = "/path/to/a_conf.ext" >>> assert guess_io_type(apath) == IOI_PATH_STR
>>> from anyconfig.compat import pathlib >>> if pathlib is not None: ... assert guess_io_type(pathlib.Path(apath)) == IOI_PATH_OBJ >>> assert guess_io_type(open(__file__)) == IOI_STREAM
-
anyconfig.ioinfo.
inspect_io_obj
(obj)¶ Parameters: obj – a path string, a pathlib.Path or a file / file-like object Returns: A tuple of (objtype, objpath, objopener) Raises: UnknownFileTypeError
-
anyconfig.ioinfo.
make
(obj, forced_type=None)¶ Parameters: - obj – a path string, a pathlib.Path or a file / file-like object
- prs – A list of processor classes
- forced_type – Forced processor type or processor object
Returns: Namedtuple object represents a kind of input object such as a file / file-like object, path string or pathlib.Path object
Raises: ValueError, UnknownProcessorTypeError, UnknownFileTypeError