fs.mode¶
Abstract I/O mode container.
Mode strings are used in in open
and
openbin
.
- class fs.mode.Mode(mode: str)[source]¶
An abstraction for I/O modes.
A mode object provides properties that can be used to interrogate the mode strings used when opening files.
Example
>>> mode = Mode('rb') >>> mode.reading True >>> mode.writing False >>> mode.binary True >>> mode.text False
- __init__(mode: str) None [source]¶
Create a new
Mode
instance.- Parameters:
- Raises:
ValueError – If the mode string is invalid.
- to_platform() str [source]¶
Get a mode string for the current platform.
Currently, this just removes the ‘x’ on PY2 because PY2 doesn’t support exclusive mode.
- to_platform_bin() str [source]¶
Get a binary mode string for the current platform.
This removes the ‘t’ and adds a ‘b’ if needed.
- validate(_valid_chars: Union[Set[Text], FrozenSet[Text]] = frozenset({'+', 'a', 'b', 'r', 't', 'w', 'x'})) None [source]¶
Validate the mode string.
- Raises:
ValueError – if the mode contains invalid chars.
- validate_bin() None [source]¶
Validate a mode for opening a binary file.
- Raises:
ValueError – if the mode contains invalid chars.